(function( window, undefined ) { if (window.loader_jquery === undefined) { window.loader_jquery = {}; } else { return; } function loader() { return this; } loader.fn = loader.prototype = { Setup : function ( options ) { for (option in options) { this[option] = options[option]; } return this; }, jQuery : function ( options ) { var jquery = options['jquery']; var path = options['path'] || this['path']; var version = options['version'] || this['version']; var callback = options['callback'] || this['callback']; var extraplugins = options['plugins'] || {}; if (callback === undefined) { throw 'You have to provide a callback when calling loader.jQuery'; } // Shortcut method: If the callback is a hash then the hash must // contain a list of plugins with their associated callbacks so we // create a new callback that loads all the requested plugins //if (typeof callback == 'object') { // var plugin_callbacks = callback; // callback = function () { // $(function () { // for (plugin in plugin_callbacks) { // $.plugin(plugin, plugin_callbacks[plugin]); // } // }); // }; //} if (window.loader_jquery[version]) { // Someone has already loaded this version, or it is in the process of being loaded var thisversion = window.loader_jquery[version]; if (thisversion['status'] == 'loaded') { jquery = thisversion['jquery']; for (name in extraplugins) { jquery.plugin(name,extraplugins[name]); } callback(thisversion['jquery']); return; } else if (thisversion['status'] == 'loading') { if (thisversion['callbacks'] === undefined) { thisversion['callbacks'] = [ callback ]; } else { thisversion['callbacks'].push(callback); } thisversion['plugins'].push(extraplugins); return; } } else { window.loader_jquery[version] = { 'status' : 'loading', 'path' : path, 'plugins' : [ this.plugins, extraplugins ], 'version' : version, 'callbacks' : [ callback ] }; } // See if we have this version of jQuery tucked away already // if (version === undefined && window.loader_jquery[version] !== undefined) { // jquery = window.loader_jquery[version]; // } // is jQuery already loaded in the parent // FIXME Using the loaded version of jQuery is causing issues so comment it out for now // if (window.jQuery !== undefined && (version === undefined || window.jQuery.fn.jquery === version)) { // Either we don't care what version of jQuery we use, or we have the // exact version we are after // jquery = window.jQuery; // } // If we don't have a jQuery yet, and no specific version was requested, load the 'latest' version if (jquery === undefined && version === undefined) { version = 'latest'; } if (jquery === undefined) { var script_tag = document.createElement('script'); script_tag.setAttribute("type","text/javascript"); script_tag.setAttribute("src", loader.fn.makeCdnUrl( "/js/jquery/" + version + "/jquery.js" )); script_tag.onload = function () { loader.fn.scriptLoadHandler() }; script_tag.onreadystatechange = function () { // Same thing but for IE if (this.readyState == 'complete' || this.readyState == 'loaded') { loader.fn.scriptLoadHandler(); } }; // Try to find the head, otherwise default to the documentElement (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag); } else { jquery = window.jQuery; loader.fn.loadPluginManager(jquery); } }, makeCdnUrl : function ( relurl ) { return (("https:" == document.location.protocol) ? "https://" : "http://") + 'sscdn.net' + relurl; }, scriptLoadHandler : function () { jquery = window.jQuery142 || window.jQuery.noConflict(true); //if (window.jQuery === undefined) { //window.jQuery = window.$ = jquery; //} // Save this version in the cache var thisversion = window.loader_jquery[jquery.fn.jquery]; thisversion['jquery'] = jquery; loader.fn.loadPluginManager(jquery); }, loadPluginManager : function (jquery) { var thisversion = window.loader_jquery[jquery.fn.jquery]; if (jquery.plugin === undefined) { jquery.ajax({ url: loader.fn.makeCdnUrl('/js/jquery/' + jquery.fn.jquery + '/plugin/1.1/plugin.min.js'), dataType: 'script', success : function () { thisversion['plugin_loaded'] = 'yes'; }, error : function (XMLHttpRequest, textStatus, errorThrown) { throw new Error('Could not load ' + url); } }); } if (thisversion['config'] === undefined) { jquery.ajax({ url: loader.fn.makeCdnUrl('/js/jquery/' + jquery.fn.jquery + '/config.js'), dataType: 'script', success : function () { thisversion['config_loaded'] = 'yes'; }, error : function (XMLHttpRequest, textStatus, errorThrown) { throw new Error('Could not load ' + url); } }); } loader.fn.loadjQueryPlugins(jquery); }, loadjQueryPlugins : function (jquery) { var thisversion = window.loader_jquery[jquery.fn.jquery]; if (thisversion['plugin_loaded'] == 'failed' || thisversion['plugin_loaded'] == 'failed') { throw new Error('Failed to load plugin.js or config.js - can not continue'); } if (thisversion['plugin_loaded'] != 'yes' || typeof(thisversion['config']) != 'object') { setTimeout(function () { loader.fn.loadjQueryPlugins(jquery); jquery = null }, 100); } else { if (typeof thisversion['config'] === 'object' && typeof thisversion['config']['plugins'] === 'object') { for (name in thisversion['config']['plugins']) { var plugin = thisversion['config']['plugins'][name]; for (file in plugin['files']) { if (plugin['files'][file].substr(0,4) !== 'http' || plugin['files'][file].substr(0,1) !== '/') { plugin['files'][file] = loader.fn.makeCdnUrl('/js/jquery/' + jquery.fn.jquery + '/' + plugin['files'][file]); } } if (plugin['selectors'] === undefined) { plugin['selectors'] = ['body']; } jquery.plugin(name,plugin); } } if (typeof thisversion['plugins'] === 'object') { for (i in thisversion['plugins']) { for (name in thisversion['plugins'][i]) { var plugin = thisversion['plugins'][i][name]; for (file in plugin['files']) { if (plugin['files'][file].substr(0,4) !== 'http' || plugin['files'][file].substr(0,1) !== '/') { plugin['files'][file] = loader.fn.makeCdnUrl('/js/jquery/' + jquery.fn.jquery + '/' + plugin['files'][file]); } } jquery.plugin(name,plugin); } } } thisversion['status'] = 'loaded'; if ( thisversion['callbacks'] !== undefined ) { for (i in thisversion['callbacks']) { thisversion['callbacks'][i](jquery); } } } } }; var rootloader = new loader(); window.loader = rootloader; })(window);