how to load js widget file in dojo ? registerModulePath is working but in 1.8 packages not working - need help immediately - dojo

Hello need help immediately,
I have web directory as
- WebContent
index.jsp
dojo
testjs
- bpl
- mywidget.js
Context path is /TestWeb/CheckDojo
script in index.jsp:
dojo.registerModulePath("testjs","/TestWeb/CheckDojo/testjs");
is working and i can do
require([ "dojo/dom", "testjs/bpl/mywidget", "dojo/domReady!"], ...
but in dojo 1.8 ,
in dojoconfig i am using
data-dojo-config="locale: en-us,
async: true,
config-tlmSiblingOfDojo: false,
packages: [{
name: 'testjs',
location: '/TestWeb/CheckDojo/testjs'
}],
parseOnLoad: true"
then in require mywidget is searched in dojo directory which is not the correct path.
what and how should i load the package ?

Look here enter link description here (module indentifiers). The documentation tells that the location is relative of the 'dojo' folder (defined in dojo.baseUrl).
You should change the code to :
data-dojo-config="locale: en-us,
async: true,
config-tlmSiblingOfDojo: false,
packages: [{
name: 'testjs',
location: '../TestWeb/CheckDojo/testjs'
}],
parseOnLoad: true"

Related

Load customized Dojo module

I am really new to Dojo so this may sound dumb.
I am using Dojo 1.7 as a hosted resource (that is, I downloaded the dojo package and put it under the source code). Then I have a customized module defined in another folder. The structure looks like this:
/
libs/
js/
dojo/
dojo.js
myPage/
myModules/
myCustomizedModule.js
index.html
I am using the "define" function to define a module in myPage/myModules/myCustomizedModule.js
In "myPage" folder, I am using index.html to require the customized module:
<script>
require(["myPage/myModules/myCustomizedModule"], function(myCustomizedModule){
// Do something.
})
</script>
However, I can't get it to work: the console reported an error:
"http://localhost/myDojoTest/libs/js/dojo/myPage/MyModules/myCustomizedModule.js 404 (Not found)".
I know this directory is not right since "myPage" folder is not under "libs/js/dojo". But it seems when using the "require" statement, instead of using the relative path of the current HTML document, the code uses the current path for the dojo.js file.
Is there anything I can do to correctly refer to my customized module?
Many thanks!
As per your requirement, you need to set up packages as indicated below
<!-- dojo configuration options -->
<!-- For Package configuration refer tutorial at http://dojotoolkit.org/documentation/tutorials/1.7/modules/ -->
<script type="text/javascript">
var dojoConfig = {
async: true,
baseUrl: "/",
tlmSiblingOfDojo: false,
packages: [
{ name: "dojo", location: "libs/js/dojo" },
{ name: "dijit", location: "libs/js/dijit" },
{ name: "dojox", location: "libs/js/dojox" },
{ name: "myModules", location: "myPage/myModules" }
]
};
</script>
You can than access dojo, dijit and myModules in require function call as.
Remember you need to precede the modules with their respective packages.
<script>
require([
//Require resources.
"dojo/store/Memory",
"myModules/myCustomizedModule"
], function(Memory, myCustomizedModule){
....
}
);
</script>
Hope it helps.

how to do dojo internationalization

1) I have webcontent/bpl/nls directory
2) resource.js -.
define({ root:
({
software: " Software"
}),
"fr": true,
"fr-ca" : true,
"en-us": true
});
I have this file inside webcontent/bpl/nls directory
3)
In index.jsp, i am using like this -
<script type="text/javascript">
var dojoConfig = {
async: true,
parseOnLoad: true,
locale: 'en-us',
baseUrl: "/",
tlmSiblingOfDojo: false,
};
require(["dojo/i18n", "dojo/i18n!bpl/nls/resource"],function(
i18n, resource
){ alert(resource.software);}
);
</script>
BUT I am getting Undefined in alert box. What is the error ? what is right procedure ? I am using dojo 1.8.
It seems you're missing the actual dictionary file for your locale. I.o.w, you would need a webcontent/bpl/nls/en-us folder with resource.js in it, having the following:
define({
software: " Software"
});
And similar ones for fr and fr-ca locales (since you declared them in your root dictionary).
See dojo docs on i18n for more details.
Cheers!

Using Durandal dojoConfig and ESRI Maps

I'm trying to get ESRI maps working with Durandal and came across this link in the Durandal docs DurandalEsri
This seems to work but now Durandal is having problems finding some of my .js files. If I leave the following dojoConfig out my scripts are found but then the maps won't work.
`var dojoConfig = {
baseUrl: './',
async: true,
tlmSiblingOfDojo: true,
parseOnLoad: false,
aliases: [['text', 'dojo/text']],
packages: [
{ name: 'esri', location: '//serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri' },
{ name: 'dojo', location: '//serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dojo' },
{ name: 'dojox', location: '//serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dojox' },
{ name: 'dijit', location: '//serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dijit' },
{ name: 'durandal', location: 'App/durandal' },
{ name: 'views', location: 'App/views' },
{ name: 'viewmodels', location: 'App/viewmodels' },
{ name: 'lib', location: 'App/lib' }
]
};`
My app structure looks like this:
App
durandal
lib
services
viewmodels
views
So in my shell.js file if I try to pass in 'lib/config' I get a 404 because it tried to find the config file at localhost/lib/config.js instead of localhost/dashboard/app/lib/config.js
If I pass 'dashboard/app/lib/config' to shell.js the file will be found, but it doesn't seem like I should have to specify the entire path, since 'durandal/system' and anything else under the 'durandal' folder get found correctly.
Any ideas???
I encountered a similar problem using AMD module loading with Esri. I solved it using a configuration similar to yours but with the following baseurl:
baseUrl: location.pathname.replace(/\/[^/]+$/, '') + '/path/to/app/main'
As described in Jeffrey Grajkowski's answer to my question here: https://stackoverflow.com/a/15390919/1014822
So for my scenario of Durandal + Esri + Dojo, I had to leave out the require.js file that is included with Durandal and use the dojo AMD loader. Unfortunately I have no idea what future problems this might cause.
More info can be found here

dojo looking for build.js in wrong path

I am trying to run my dojo project on a local Tomcat (7.0) server using Eclipse Juno 64bit as a dev environment.
I ran into a problem yesterday concerning how dojo assumes where files are stored within the source tree.
Below is a firebug log showing the issue:
304 Not Modified 23ms dojo.js (Line 295)
GET http://localhost:8080/src/dojo-18/dojo/parser.js
304 Not Modified 46ms dojo.js (Line 295)
GET http://localhost:8080/src/dojo-18/dojo/util.js
404 Not Found 24ms dojo.js (Line 295)
"NetworkError: 404 Not Found - http://localhost:8080/src/dojo-18/dojo/util.js"
The first 2 paths (and a lot before them) are loaded correctly, now the third path is incorrect, there is no util.js in the base dojo folder, I dont know why dojo would look there.
In order to solve the issue I tried describing the path better using the baseUrl property
<script>
dojoConfig = {
isDebug: true,
parseOnLoad: false,
baseUrl: './src/dojo-18/',
};
</script>
the dojo.js is referenced like this:
<script src="./src/dojo-18/dojo/dojo.js"></script>
Dojo does not look for util.js by itself, if it's doing that, you have imported a module called util by yourself, for example:
require([ "dojo/util" ], function(util) {
// This will not work because the util module does not exist
});
If you want to reference a self defined module, you have to configure the package first using dojoConfig:
<script>
dojoConfig = {
isDebug: true,
parseOnLoad: false,
baseUrl: './src/dojo-18/',
packages: [{
name: 'custom',
location: '/path/to/custom'
}]
};
</script>
Then you can reference a module in that package by using:
require([ "custom/util" ], function(util) {
// This will load the custom util module
});
In this case, the Dojo AMD loader will look for util.js inside the /path/to/custom folder, so it would become:
/path/to/custom/util.js

Make a build in dojo 1.7.2

Well, I read all about build and all about dojo. Three days nightmare and so on... Need some help.
I'm using the last version of dojo. 1.7.2 in:
</sites/somesite/scripts/dojo17>
which contains
--dojo
--dijit
--dojox
--utils
I use the following profile:
dependencies = {
stripConsole: "all",
action: "release",
optimize: "shrinksafe",
layerOptimize: "shrinksafe",
//optimize: "closure",
//layerOptimize: "closure",
//mini: true,
//localeList : 'en-us',
//cssOptimize: "comments",
//selectorEngine: "acme",
releaseName: "content7",
layers: [
{
// This is a specially named layer, literally 'dojo.js'
// adding dependencies to this layer will include the modules
// in addition to the standard dojo.js base APIs.
name: "dojo.js",
customBase : true,
dependencies: [
"dojo.fx",
"dijit.form.Button",
"dojox.gauges.AnalogGauge",
"dojox.gauges.AnalogArcIndicator",
"dojox.gauges.AnalogNeedleIndicator",
"myApp.smartmix"
]
}
],
prefixes: [
[ "dijit", "../dijit" ],
[ "dojox", "../dojox" ],
[ "myApp", "../../../myApp" ]
]
};
then i use this build script
./build.sh profile=../../../../myApp/myApp.profile.js releaseDir=../../../release
And I got the
</sites/somesite/scripts/release/content7>
which contains
--dijit
--dojo
--dojox
--myApp
NOW in my index.html file I have
<script type="text/javascript">
//<![CDATA[
var djConfig = {
parseOnLoad: true,
isDebug: false,
modulePaths: {
'myApp': '../myApp'
}
};
//]]>
</script>
<script type="text/javascript" src="scripts/release/content7/dojo/dojo.js"></script>
<script>
dojo.require('myApp.smartmix');
</script>
And YES this reduce the 230 files loaded without the build to 153 files.
BUT stills I (want to) believe that is posibble to reduce to one or 2 files.
But HOW?????
Please, some help will be appreciated!!!!
Ok, your profile is not right.
1st of all: You are using customBase, which is an advanced property for creating a minimal version of dojo core. I don't think you want that, do you? Normally, you just let dojo build its core normally, and that ends up as dojo.js in your output dir.
2nd of all: Every layer entry there will generate a minified .js file with all the files in dependencies inside it.
So, if you want your myApp stuff in a built JS file, you'll need to create a layer, and put your files in its dependencies.
Dojo will still generate all the individual files - but you don't have to deploy them. Just deploy the layer files. I usually have a layer for Dojo core, a layer for the dijit/dojox stuff I want, and then a layer for my custom JS. Then there are three JS files, which dojo will output in the dojo dir, and they are used in the HTML page.
...
layers: [
{
// this is a layer 'application', which will cache all
// dependencies to smartmix and declare smartmix in the same file
name: "../../../myApp/smartmix.js",
dependencies: [
"dojo.fx",
"dijit.form.Button",
"dojox.gauges.AnalogGauge",
"dojox.gauges.AnalogArcIndicator",
"dojox.gauges.AnalogNeedleIndicator",
"myApp.smartmix"
]
}
],
...
you will need only two requests;
<script src=..dojo.js></script>
and
<script>require(["myApp.smartmix"], function(smartmixApplication) { });</script>