[dojo-contributors] Bug or feature in bootstrap2.js?

Scott J. Miles sjmiles at turboajax.com
Wed Jun 28 12:42:13 EDT 2006


Fwiw, it may be easier in your particular case to load debug.js and
browser_debug.js directly from your script, and set djConfig.isDebug = true
*after* loading dojo.
 
Regards,
Scott J. Miles
TurboAjax Group
http://www.turboajax.com

________________________________

From: dojo-contributors-bounces at dojotoolkit.org
[mailto:dojo-contributors-bounces at dojotoolkit.org] On Behalf Of Brad Neuberg
Sent: Wednesday, June 28, 2006 4:21 AM
To: dojo-contributors
Subject: [dojo-contributors] Bug or feature in bootstrap2.js?


Hi folks; I'd like to fix some code in bootstrap2, but I want to make sure
it is a bug and not a feature :)

Here's my situation: I have an OPML file that gets loaded on the client,
such as test.opml. This OPML file has a direct line to transform it on page
load using an XSLT stylesheet:

<?xml-stylesheet type="text/xsl" href="../client/lib/hs/xslt/hyperscope.xsl"
?>

This XSLT stylesheet writes out all of my HTML, script tags, etc for the
'chrome' of my application (it's an application that presents a
user-interface for working with arbitrary OPML files). Here's a taste of
hyperscope.xsl:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
        <head>
            <title>Address Demo</title>
        
            <script type="text/javascript">
                var djConfig = { isDebug: true, disableFlashStorage: true };
            </script>
            
            <script type="text/javascript"
src="../client/lib/dojo/release/dojo/dojo.js.uncompressed.js"></script>
            <script type="text/javascript" src="address.js"></script>
.....etc
          
There's alot more written out, but the important part is notice that I load
all my JavaScript.

Here's the problem: when isDebug is true, things freak out: the page keeps
spinning forever, and I get JavaScript errors like 'dojo.lang not found'; I
don't get this if isDebug is false, but I'd like isDebug to work or else
I'll have to revert to alert() statements, and then I will really go mad :) 

I've tracked the offending problem down here in bootstrap2.js:

;(function(){
    //Don't do this work if dojo.js has already done it.
    if(typeof dj_usingBootstrap != "undefined"){
        return;
    }

    var isRhino = false;
    var isSpidermonkey = false;
    var isDashboard = false;
    if((typeof this["load"] == "function")&&(typeof this["Packages"] ==
"function")){
        isRhino = true;
    }else if(typeof this["load"] == "function"){
        isSpidermonkey  = true;
    }else if(window.widget){
        isDashboard = true;
    }

    var tmps = [];
 
if((this["djConfig"])&&((djConfig["isDebug"])||(djConfig["debugAtAllCosts"])
)){
        tmps.push("debug.js");
    }

 
if((this["djConfig"])&&(djConfig["debugAtAllCosts"])&&(!isRhino)&&(!isDashbo
ard)){
        tmps.push("browser_debug.js");
    }

    //Support compatibility packages. Right now this only allows setting one
    //compatibility package. Might need to revisit later down the line to
support
    //more than one.
    if((this["djConfig"])&&(djConfig["compat"])){
        tmps.push("compat/" + djConfig["compat"] + ".js");
    }

    var loaderRoot = djConfig["baseScriptUri"];
    if((this["djConfig"])&&(djConfig["baseLoaderUri"])){
        loaderRoot = djConfig["baseLoaderUri"];
    }

    for(var x=0; x < tmps.length; x++){
        var spath = loaderRoot+"src/"+tmps[x];
        if(isRhino||isSpidermonkey){
            load(spath);
        } else {
            try {
                alert("writing " + spath);
                document.write("<scr"+"ipt type='text/javascript'
src='"+spath+"'></scr"+"ipt>");
            } catch (e) {
                var script = document.createElement("script");
                script.src = spath;
 
document.getElementsByTagName("head")[0].appendChild(script);
            }
        }
    }
})();

Notice how this code builds up optional JS files, like debug.js; these then
get written out to the page with a document.write. One problem: what if you
are in an environment where the page is already loaded, like in my
situation, and document.writes simply create evil for you? 

The document.write freaks out my page; I'd much rather add a script tag to
the DOM. However, this code isn't documented, so I'm not sure if
document.write is a 'feature' that is fixing something, or if someone just
coded it that way for some reason. Is there person who wrote this here?

Here's what I'd like to do: change this to be what happens in the exception:

            try {
                var script = document.createElement("script");
                script.src = spath;
 
document.getElementsByTagName("head")[0].appendChild(script);
            } catch (e) {
                 // What to do with exception?   
            }


Is there a reason I can't do this? Also, what should I do with the exception
here?

Best,
  Brad






More information about the dojo-contributors mailing list