Skip to content

Instantly share code, notes, and snippets.

@sidnei
Created April 23, 2010 19:15
Show Gist options
  • Save sidnei/377020 to your computer and use it in GitHub Desktop.
Save sidnei/377020 to your computer and use it in GitHub Desktop.
// Copyright 2005-2010 Canonical Limited. All rights reserved.
var LANDSCAPE_YUI_CONFIG = {
filter: "min",
base: "/static/yui/"
};
// If Javascript debugging is enabled, configure the YUI loader to use
// the debug versions of the Javascript files.
if (typeof LANDSCAPE_JS_DEBUG !== "undefined") {
LANDSCAPE_YUI_CONFIG.filter = "debug";
}
// Merge the module configuration of Landscape and lazr-js into a
// single one for the YUI loader.
YUI().use(function(Y){
LANDSCAPE_YUI_CONFIG.modules = Y.merge(LAZR_MODULES, LANDSCAPE_MODULES);
});
// Create a global YUI sandbox that will be shared by everyone.
var LS = YUI(LANDSCAPE_YUI_CONFIG);
if (typeof LANDSCAPE_JS_DEBUG == "undefined"){
// Load the rolled-up, minified versions of YUI and the Landscape
// modules. When they are finished loading, execute all the
// delayed callbacks registered by our customized version of
// 'use' (see below).
LS.use(function(Y) {
LS._ls_loading = [];
LS._ls_queue = [];
LS._ls_deps = ["/static/yui-all-min.js",
"/static/landscape-min.js"];
// Wrap the native 'use' function to add some smarts around our custom
// loading of the rolled-up minified files so that we delay the loader
// from firing until the rolled-up files are finished loading, in
// order to avoid loading the modules twice.
LS._yui_native_use = LS.use;
// Now replace the original 'use' function with our own.
LS.use = function() {
// If all external dependencies have been loaded, just
// call the native 'use' function directly.
if (!LS._ls_loading.length) {
LS._yui_native_use.apply(this, arguments);
} else {
// If there are things still loading, queue calls to 'use'
// until they are finished.
var ridx = arguments.length,
args = [];
while (--ridx >= 0) {
args[ridx] = arguments[ridx];
}
// Push copied arguments into the queue.
LS._ls_queue.push(args);
}
};
// For each dependency, add the filename to the loading queue,
// then use the Y.Get utility to fetch the script. When the
// script is finished loading, we'll fire the onSuccess
// handler above.
Y.Array.each(LS._ls_deps, function(value){
LS._ls_loading.push(value);
Y.Get.script(value,
{"onEnd": function() {
LS._ls_loading.pop();
// Whenever all the dependencies finishes
// loading, call all of the callbacks queued in
// the order they were registered.
if (!LS._ls_loading.length) {
Y.Array.each(LS._ls_queue, function(value){
LS._yui_native_use.apply(this, value);
});
}
},
"attributes": {"defer": "defer"}});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment