Login Register

CDN Timing Issue

I'm adapting the following example from dojox to use with CDN (on a Book of Dojo page, actually). Running it yields "dojox is not defined". But putting the dojo.declare in a dojo.addOnLoad won't work either because the QueryReadStore tag needs the definition beforehand. Any clues?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>QueryReadStore Demo</title>
    <style type="text/css">
        @import "http://o.aolcdn.com/dojo/1.0.0/dijit/themes/tundra/tundra.css";
        @import "http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.css"
    </style>
    <script type="text/javascript" src="http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js"
            djConfig="parseOnLoad: true">
</script>
    <script type="text/javascript">
       dojo.require("dojo.parser");
       dojo.require("dojox.data.QueryReadStore");
       dojo.require("dijit.form.FilteringSelect");
       dojo.provide("ComboBoxReadStore");
       dojo.declare("ComboBoxReadStore", dojox.data.QueryReadStore, {
          fetch:function(request) {
             request.serverQuery = {q:request.query.name};
             // Call superclasses' fetch
             return this.inherited("fetch", arguments);
          }
       });
    </script>
</head>
<body class="tundra">
    <div dojoType="ComboBoxReadStore" jsId="store"
         url="/dojoroot/dojox/data/tests/stores/QueryReadStore.php"
         requestMethod="get">

    </div>
    State: <input id="fs" dojoType="dijit.form.FilteringSelect" store="store" pageSize="5" />
</body></html>

So you were on the right

So you were on the right path: put the dojo.declare section in an addOnLoad call. The other trick is to turn of page parsing and call it manually inside the dojo.addOnLoad callback. So, set djConfig="parseOnLoad: false" then do:
dojo.addOnLoad(function(){
       dojo.declare("ComboBoxReadStore", dojox.data.QueryReadStore, {
          fetch:function(request) {
             request.serverQuery = {q:request.query.name};
             // Call superclasses' fetch
             return this.inherited("fetch", arguments);
          }
       });
       dojo.parser.parse();
});
The other option you have is to extract the code that defines ComboBoxReadStore into a separate file, then dojo.require() it in. In that case, you will not need to use dojo.addOnLoad() in that separate file, and you do not have to manually call the parser either.

Turned of parsing works well, but...

Thank jburke. I am new here and new to dojo, so I got a lot of questions while learning it. The main reason why I registered here is because of the problem criecke documentated. I have tried your different suggestions, but the best way (for me) indeed ist to turn parsing of. The only thing is that calling the parser manually could be a problem for me in the future. You said there is a method to solve the problem and let the parser called automatically. I´m sorry, but I didn´t get it. Could you post the snipet please how to do it?
Many Thanks and Kind Regards
Flug

Flug: just make sure to put

Flug: just make sure to put all your JS code in a file that you load via dojo.require(). The file you create for your code should have a dojo.provide() to match the file name/path, and it should dojo.require() any modules it depends on.

If you load all your JavaScript via dojo.require(), all the modules will get loaded and executed before the parser runs. Once you have that set up, you can turn on automatic parsing.