tags:

views:

128

answers:

2

I have been using Dojo hosted on Google's CDN. I just downloaded the development version so I can do some debugging. When using dojo stored locally, Firebug reports several syntax errors. They all look like this:

SyntaxError: syntax error
(no script)(""en-us"")bootstrap.js (line 601)
(no script)(""dojo.cldr"", ""number"")bootstrap.js (line 590)
(no script)(""dojo.cldr"", ""number"")loader.js (line 634)
(no script)(""./number.js"", ""dojo.number"")loader.js (line 76)
(no script)(""dojo.number"")loader.js (line 411)
(no script)(""./currency.js"", ""dojo.currency"")loader.js (line 76)
(no script)(""dojo.currency"")loader.js (line 411)
(no script)(""../dijit/form/CurrencyTextBox.js"", ""dijit.form.CurrencyTextBox"")loader.js (line 76)
(no script)(""dijit.form.CurrencyTextBox"")loader.js (line 411)
[Break on this error] (601 out of range 505)
bootstrap.js (line 601)

I know I have Dojo set up correctly throughout my layout, views, and controllers because dojo works fine if I use a CDN. I've also verified that the localpath resolves properly, which it does.

This is what the initialization looks like using CDN (this works correctly):

<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headTitle(); ?>
<?php echo $this->headLink(); ?>
<?php echo $this->headScript();
if ($this->dojo()->isEnabled()) {
    $this->dojo()->setCdnVersion('1.5')
                 ->addStyleSheetModule('dijit.themes.claro');
    echo $this->dojo();
}
?>
</head>

And this is what it looks like using the local version:

<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headTitle(); ?>
<?php echo $this->headLink(); ?>
<?php echo $this->headScript();
if ($this->dojo()->isEnabled()) {
    $this->dojo()->setLocalPath('/js/dojo/dojo.js')
                 ->addStyleSheetModule('dijit.themes.claro')
                 ->setDjConfigOption('parseOnLoad', true)
                 ->setDjConfigOption('isDebug', true);
    echo $this->dojo();
}
?>
</head>

What am I doing wrong with the localpath that is making these syntax errors occur?

A: 

I have had the exact same problem. It seems to have something to do with localization but I cannot figure out the reason.

There is a work-around, though, which will do the job in some cases: In the dijit/nls directory, create en and en-us directories and copy into them the common.js and loader.js files.

You may have to do this for more than one dijit, depending on where the dijit looks for localization files.

If you come across a better solution, MikeH, please post it here. Earlier today I posted this problem to the dojo forum and will follow up by linking to this thread. Hopefully someone will have a non-stopgap fix.

ken

KenP
I didn't have any luck looking into the locale issue, but I did finally generate a working solution today that isn't a workaround. I posted it as an answer below. I hope it helps you get things working on your end! I appreciate the input you gave as it did get me looking into this again ;-)
MikeH
Thanks MikeH. I think what I'll do is just use a built version and then do a custom build before we release, as you have it outlined below. Custom builds are definitely the way to go for a final release, since they really pair down the size and optimize for what your app requires.Just to complete this thread, here is a link from the Dojo forum that points up the problem with missing files and indicates that it is due to non-built/source versions of Dojo:http://dojo-toolkit.33424.n3.nabble.com/1-4-error-missing-files-tp327313p327313.html
KenP
A: 

It appears that you have to "build" dojo when you download the source and want to run it locally. Somehow I missed this as a requirement of using a local path version of dojo. At any rate, I was finally able to get dojo to run correctly locally by doing a custom build. I found this dojo reference very helpful:

http://docs.dojocampus.org/quickstart/custom-builds

In the util/buildscripts folder in the dojo distribution, there are several predefined build profiles as well. I suspect that you could use one of these to build the whole dojo distribution, but I figured if I'm going to this much trouble, might as well get an optimized build out of it.

My build profile ended up looking like this:

dependencies ={

   layers:  [
       {
       name: "mydojo.js",
       dependencies: [
           "dojox.grid.DataGrid",
           "dojox.Data.QueryReadStore",
           "dijit.form.ComboBox",
           "dijit.form.ValidationTextBox",
           "dijit.form.CurrencyTextBox",
           "dijit.form.PasswordTextBox",
           "dijit.form.RadioButton",
           "dijit.form.Button",
           "dijit.form.CheckBox",
           "dijit.form.DateTextBox"
       ]
       }
   ],

   prefixes: [
       [ "dijit", "../dijit" ],
       [ "dojox", "../dojox" ]
   ]

 };

I placed this in the /util/buildscripts/profiles folder, named "myProfile.profile.js".

Then, I ran the build script from /util/buildscripts:

./build.sh profile=myProfile action=release optimize=shrinksafe.keepLines layerOptimize=shrinksafe.keepLines releaseName=myRelease localeList=en-us,es-es version=0.1.dev

Copy the resulting build from /release/myRelease to your website's javascript folder, i.e. /js/myRelease/.

The important commandline options are "profile" and "action", the others are optional. You can get a full description of what each commandline option means at the url I provided above. I customized these options to my particular needs--yours may be very different and I have provided them only as an example of what mine looked like in the end. If you are on windows, instead of "build.sh", use "build.bat".

Then, to set Zend to use this build, I did the following in my layout.phtml file:

if ($this->dojo()->isEnabled()) {
        $this->dojo()->setLocalPath($this->baseUrl() . '/js/myRelease/dojo/dojo.js')
             ->addStyleSheetModule('dijit.themes.claro')
             ->setDjConfigOption('isDebug', true)
             ->setDjConfigOption('debugAtAllCosts', true)
             ->addLayer($this->baseUrl() . '/js/myRelease/dojo/mydojo.js')                
             ;
}

Using "addLayer" for the custom build is what finally got this working for me. I hope this helps save someone else a little time!

MikeH