Created
May 16, 2010 16:04
-
-
Save neonstalwart/402960 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is 'raw' javascript to load dojo, stylesheets, the app, etc. | |
// this file is all that needs to be included in the host page. | |
// this technique doesn't dojo.addOnLoad because it assumes that the | |
// app code will use dojo.addOnLoad as necessary. | |
// also, this doesn't load dojo.css as a 'reset' since it assumes that | |
// it is being loaded into an already established environment and it | |
// doesn't include loading the css for a dijit theme. | |
(function(){ | |
djConfig = { | |
afterOnLoad: true, | |
baseUrl: './', | |
modulePaths: { | |
myApp: 'src/myApp', | |
styles: 'src/styles' | |
} | |
}; | |
// setup the environment and inject dojo into the page | |
var cdn = 'http://ajax.googleapis.com/ajax/libs/dojo/1.4/', | |
dojoUrl = cdn + 'dojo/dojo.xd.js', | |
dijitCss = cdn + 'dijit/themes/dijit.css', | |
readyRE = /^(complete|loaded)$/, | |
d = document, | |
head = d.getElementsByTagName("head")[0], | |
node = d.createElement('script'); | |
// the code to add a style sheet is adapted from dijit._editor.RichText.addStyleSheet | |
function addStyleSheet(url){ | |
var sheet; | |
if(d.createStyleSheet){ | |
// IE | |
d.createStyleSheet(url); | |
} else { | |
// other browsers | |
sheet = d.createElement('link'); | |
sheet.rel = 'stylesheet'; | |
sheet.type = 'text/css'; | |
sheet.href = url; | |
head.appendChild(sheet); | |
} | |
} | |
// the script loading code is adapted from RequireJS | |
// - http://github.com/jrburke/requirejs/blob/master/require.js | |
function scriptLoad(e){ | |
var node = e.target || e.srcElement, url; | |
if (e.type == 'load' || readyRE.test(node.readyState)) { | |
url = dojo.moduleUrl('styles', 'appStyles.css').toString(); | |
addStyleSheet(dijitCss); | |
addStyleSheet(url); | |
// load the application | |
dojo.require('myApp.app'); | |
if (node.removeEventListener) { | |
// good browsers | |
node.removeEventListener('load', scriptLoad, false); | |
} else { | |
// probably IE | |
node.detachEvent('onreadystatechange', scriptLoad); | |
} | |
} | |
} | |
node.type = 'text/javascript'; | |
node.charset = 'utf-8'; | |
if(node.addEventListener){ | |
// good browsers | |
node.addEventListener('load', scriptLoad, false); | |
} | |
else{ | |
// probably IE | |
node.attachEvent('onreadystatechange', scriptLoad); | |
} | |
node.src = dojoUrl; | |
head.appendChild(node); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment