开发者

Dojo.dnd.source stopped working when migrating to dojo 1.5 with source from google apis

I was successfully using dojo.dnd.Source with Dojo 1.4.3 loaded from my webserver. However, as it is shared hosting or for some other reason the loading was horrifyingly slow. (even something like 1min30 secs occasionally)

So I am now trying to switch to DOJO 1.5 and googleapis as source. Result is much better loading times but my problem now is that dojo.dnd is not recognized. here is the code I use for loading dojo.dnd.Source

         dojo.addOnLoad(function() {                
            dojo.require("dijit.Dialog");
            dojo.require("dojo.parser");
            dojo.require("dijit.Editor");
            dojo.require("dojo.dnd.Source");

            widgetSrcNode = new dojo.dnd.Source("admin_widgetSrcNode", {accept:["unknown"]});

The error message I'm getting is as follows: dojo.dnd is undefined http://mydomain.com/admin/somepage.php?wp=17 Line 171

-- end 开发者_Go百科of message

Line 171: widgetSrcNode = new dojo.dnd.Source("admin_widgetSrcNode", {accept:["unknown"]});

I can't see any changes in the documentation for dojo.dnd in 1.5 vs 1.4 and I have tried several djconfig options but no luck. What else can I try?


As soon as you included dojo.js in your page you got all Dojo Base immediately available. It works for any build of Dojo.

But when you use a CDN build of Dojo (Google CDN in your case), all dojo.require() calls become asynchronous. Issuing dojo.require() doesn't mean that what was required will be available in the next line. You should wait for it.

Fortunately this part is easy. Try to modify your code like that:

// require our stuff outside of dojo.ready()
dojo.require("dijit.Dialog");
dojo.require("dojo.parser");
dojo.require("dijit.Editor");
dojo.require("dojo.dnd.Source");

dojo.ready(function() {
  // DOM is loaded and required files are downloaded
  // let's create what we want
  widgetSrcNode = new dojo.dnd.Source(...);
});

Or you can always do embedded waiting:

dojo.ready(function(){
  // DOM is ready
  // require more stuff
  dojo.require("dijit.Dialog");
  dojo.require("dojo.parser");
  dojo.require("dijit.Editor");
  dojo.require("dojo.dnd.Source");

  // now wait for it
  dojo.ready(function() {                
    // let's create what we want
    widgetSrcNode = new dojo.dnd.Source(...);
  });
});

Personally I prefer the former — just simpler.

BTW, I used dojo.ready() instead of dojo.addOnLoad() purely because of my personal preferences. They are synonyms, and can be used interchangeably.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜