/** vim: et:ts=4:sw=4:sts=4 * @license requirejs 2.1.15 copyright (c) 2010-2014, the dojo foundation all rights reserved. * available via the mit or new bsd license. * see: http://github.com/jrburke/requirejs for details */ //not using strict: uneven strict support in browsers, #392, and causes //problems with requirejs.exec()/transpiler plugins that may not be strict. /*jslint regexp: true, nomen: true, sloppy: true */ /*global window, navigator, document, importscripts, settimeout, opera */ (function (global, document) { var pathname = global.location.pathname, pageurl = pathname; if (pathname.indexof(pathname) === 0) { pageurl = pathname.substr(global.ctx.length); } if(pageurl==="/"){ pageurl = "/index"; } var oajax = global.xmlhttprequest ? new xmlhttprequest() : new activexobject('microsoft.xmlhttp'); oajax.open('get', global.basepath + '/system/security/getsessionattrsandnopermits?pageurl=' + pageurl + '&t=' + new date().gettime(), false); oajax.send(); var result = function("return " + oajax.responsetext)(); if (result.redirecturl) { // 未登录, 重定向, global.location.href = window.ctx + result.redirecturl; } else { global.sessionattrsandnopermits = result; } function getcookie(c_name) { var c_start, c_end; if (document.cookie.length > 0) { c_start = document.cookie.indexof(c_name + "=") if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexof(";", c_start); if (c_end == -1) c_end = document.cookie.length; return decodeuricomponent(document.cookie.substring(c_start, c_end)); } } return "" } global.version = getcookie('gillion-res-version'); }(window, document)); var requirejs, require, define; (function (global) { var req, s, head, baseelement, datamain, src, interactivescript, currentlyaddingscript, mainscript, subpath, version = '2.1.15', commentregexp = /(\/\*([\s\s]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, cjsrequireregexp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, jssuffixregexp = /\.js$/, currdirregexp = /^\.\//, op = object.prototype, ostring = op.tostring, hasown = op.hasownproperty, ap = array.prototype, apsp = ap.splice, isbrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document), iswebworker = !isbrowser && typeof importscripts !== 'undefined', //ps3 indicates loaded and complete, but need to wait for complete //specifically. sequence is 'loading', 'loaded', execution, // then 'complete'. the ua check is unfortunate, but not sure how //to feature test w/o causing perf issues. readyregexp = isbrowser && navigator.platform === 'playstation 3' ? /^complete$/ : /^(complete|loaded)$/, defcontextname = '_', //oh the tragedy, detecting opera. see the usage of isopera for reason. isopera = typeof opera !== 'undefined' && opera.tostring() === '[object opera]', contexts = {}, cfg = {}, globaldefqueue = [], useinteractive = false; function isfunction(it) { return ostring.call(it) === '[object function]'; } function isarray(it) { return ostring.call(it) === '[object array]'; } /** * helper function for iterating over an array. if the func returns * a true value, it will break out of the loop. */ function each(ary, func) { if (ary) { var i; for (i = 0; i < ary.length; i += 1) { if (ary[i] && func(ary[i], i, ary)) { break; } } } } /** * helper function for iterating over an array backwards. if the func * returns a true value, it will break out of the loop. */ function eachreverse(ary, func) { if (ary) { var i; for (i = ary.length - 1; i > -1; i -= 1) { if (ary[i] && func(ary[i], i, ary)) { break; } } } } function hasprop(obj, prop) { return hasown.call(obj, prop); } function getown(obj, prop) { return hasprop(obj, prop) && obj[prop]; } /** * cycles over properties in an object and calls a function for each * property value. if the function returns a truthy value, then the * iteration is stopped. */ function eachprop(obj, func) { var prop; for (prop in obj) { if (hasprop(obj, prop)) { if (func(obj[prop], prop)) { break; } } } } /** * simple function to mix in properties from source into target, * but only if target does not already have a property of the same name. */ function mixin(target, source, force, deepstringmixin) { if (source) { eachprop(source, function (value, prop) { if (force || !hasprop(target, prop)) { if (deepstringmixin && typeof value === 'object' && value && !isarray(value) && !isfunction(value) && !(value instanceof regexp)) { if (!target[prop]) { target[prop] = {}; } mixin(target[prop], value, force, deepstringmixin); } else { target[prop] = value; } } }); } return target; } //similar to function.prototype.bind, but the 'this' object is specified //first, since it is easier to read/figure out what 'this' will be. function bind(obj, fn) { return function () { return fn.apply(obj, arguments); }; } function scripts() { return document.getelementsbytagname('script'); } function defaultonerror(err) { throw err; } //allow getting a global that is expressed in //dot notation, like 'a.b.c'. function getglobal(value) { if (!value) { return value; } var g = global; each(value.split('.'), function (part) { g = g[part]; }); return g; } /** * constructs an error with a pointer to an url with more information. * @param {string} id the error id that maps to an id on a web page. * @param {string} message human readable error. * @param {error} [err] the original error, if there is one. * * @returns {error} */ function makeerror(id, msg, err, requiremodules) { var e = new error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id); e.requiretype = id; e.requiremodules = requiremodules; if (err) { e.originalerror = err; } return e; } if (typeof define !== 'undefined') { //if a define is already in play via another amd loader, //do not overwrite. return; } if (typeof requirejs !== 'undefined') { if (isfunction(requirejs)) { //do not overwrite an existing requirejs instance. return; } cfg = requirejs; requirejs = undefined; } //allow for a require config object if (typeof require !== 'undefined' && !isfunction(require)) { //assume it is a config object. cfg = require; require = undefined; } function newcontext(contextname) { var incheckloaded, module, context, handlers, checkloadedtimeoutid, config = { //defaults. do not set a default for map //config to speed up normalize(), which //will run faster if there is no default. waitseconds: 7, baseurl: './', paths: {}, bundles: {}, pkgs: {}, shim: {}, config: {} }, registry = {}, //registry of just enabled modules, to speed //cycle breaking code when lots of modules //are registered, but not activated. enabledregistry = {}, undefevents = {}, defqueue = [], defined = {}, urlfetched = {}, bundlesmap = {}, requirecounter = 1, unnormalizedcounter = 1; /** * trims the . and .. from an array of path segments. * it will keep a leading path segment if a .. will become * the first path segment, to help with module name lookups, * which act like paths, but can be remapped. but the end result, * all paths that use this function should look normalized. * note: this method modifies the input array. * @param {array} ary the array of path segments. */ function trimdots(ary) { var i, part; for (i = 0; i < ary.length; i++) { part = ary[i]; if (part === '.') { ary.splice(i, 1); i -= 1; } else if (part === '..') { // if at the start, or previous value is still .., // keep them so that when converted to a path it may // still work when converted to a path, even though // as an id it is less than ideal. in larger point // releases, may be better to just kick out an error. if (i === 0 || (i == 1 && ary[2] === '..') || ary[i - 1] === '..') { continue; } else if (i > 0) { ary.splice(i - 1, 2); i -= 2; } } } } /** * given a relative module name, like ./something, normalize it to * a real name that can be mapped to a path. * @param {string} name the relative name * @param {string} basename a real name that the name arg is relative * to. * @param {boolean} applymap apply the map config to the value. should * only be done if this normalization is for a dependency id. * @returns {string} normalized name */ function normalize(name, basename, applymap) { var pkgmain, mapvalue, nameparts, i, j, namesegment, lastindex, foundmap, foundi, foundstarmap, stari, normalizedbaseparts, baseparts = (basename && basename.split('/')), map = config.map, starmap = map && map['*']; //adjust any relative paths. if (name) { name = name.split('/'); lastindex = name.length - 1; // if wanting node id compatibility, strip .js from end // of ids. have to do this here, and not in nametourl // because node allows either .js or non .js to map // to same file. if (config.nodeidcompat && jssuffixregexp.test(name[lastindex])) { name[lastindex] = name[lastindex].replace(jssuffixregexp, ''); } // starts with a '.' so need the basename if (name[0].charat(0) === '.' && baseparts) { //convert basename to array, and lop off the last part, //so that . matches that 'directory' and not name of the basename's //module. for instance, basename of 'one/two/three', maps to //'one/two/three.js', but we want the directory, 'one/two' for //this normalization. normalizedbaseparts = baseparts.slice(0, baseparts.length - 1); name = normalizedbaseparts.concat(name); } trimdots(name); name = name.join('/'); } //apply map config if available. if (applymap && map && (baseparts || starmap)) { nameparts = name.split('/'); outerloop: for (i = nameparts.length; i > 0; i -= 1) { namesegment = nameparts.slice(0, i).join('/'); if (baseparts) { //find the longest basename segment match in the config. //so, do joins on the biggest to smallest lengths of baseparts. for (j = baseparts.length; j > 0; j -= 1) { mapvalue = getown(map, baseparts.slice(0, j).join('/')); //basename segment has config, find if it has one for //this name. if (mapvalue) { mapvalue = getown(mapvalue, namesegment); if (mapvalue) { //match, update name to the new value. foundmap = mapvalue; foundi = i; break outerloop; } } } } //check for a star map match, but just hold on to it, //if there is a shorter segment match later in a matching //config, then favor over this star map. if (!foundstarmap && starmap && getown(starmap, namesegment)) { foundstarmap = getown(starmap, namesegment); stari = i; } } if (!foundmap && foundstarmap) { foundmap = foundstarmap; foundi = stari; } if (foundmap) { nameparts.splice(0, foundi, foundmap); name = nameparts.join('/'); } } // if the name points to a package's name, use // the package main instead. pkgmain = getown(config.pkgs, name); return pkgmain ? pkgmain : name; } function removescript(name) { if (isbrowser) { each(scripts(), function (scriptnode) { if (scriptnode.getattribute('data-requiremodule') === name && scriptnode.getattribute('data-requirecontext') === context.contextname) { scriptnode.parentnode.removechild(scriptnode); return true; } }); } } function haspathfallback(id) { var pathconfig = getown(config.paths, id); if (pathconfig && isarray(pathconfig) && pathconfig.length > 1) { //pop off the first array value, since it failed, and //retry pathconfig.shift(); context.require.undef(id); //custom require that does not do map translation, since //id is "absolute", already mapped/resolved. context.makerequire(null, { skipmap: true })([id]); return true; } } //turns a plugin!resource to [plugin, resource] //with the plugin being undefined if the name //did not have a plugin prefix. function splitprefix(name) { var prefix, index = name ? name.indexof('!') : -1; if (index > -1) { prefix = name.substring(0, index); name = name.substring(index + 1, name.length); } return [prefix, name]; } /** * creates a module mapping that includes plugin prefix, module * name, and path. if parentmodulemap is provided it will * also normalize the name via require.normalize() * * @param {string} name the module name * @param {string} [parentmodulemap] parent module map * for the module name, used to resolve relative names. * @param {boolean} isnormalized: is the id already normalized. * this is true if this call is done for a define() module id. * @param {boolean} applymap: apply the map config to the id. * should only be true if this map is for a dependency. * * @returns {object} */ function makemodulemap(name, parentmodulemap, isnormalized, applymap) { var url, pluginmodule, suffix, nameparts, prefix = null, parentname = parentmodulemap ? parentmodulemap.name : null, originalname = name, isdefine = true, normalizedname = ''; //if no name, then it means it is a require call, generate an //internal name. if (!name) { isdefine = false; name = '_@r' + (requirecounter += 1); } nameparts = splitprefix(name); prefix = nameparts[0]; name = nameparts[1]; if (prefix) { prefix = normalize(prefix, parentname, applymap); pluginmodule = getown(defined, prefix); } //account for relative paths if there is a base name. if (name) { if (prefix) { if (pluginmodule && pluginmodule.normalize) { //plugin is loaded, use its normalize method. normalizedname = pluginmodule.normalize(name, function (name) { return normalize(name, parentname, applymap); }); } else { // if nested plugin references, then do not try to // normalize, as it will not normalize correctly. this // places a restriction on resourceids, and the longer // term solution is not to normalize until plugins are // loaded and all normalizations to allow for async // loading of a loader plugin. but for now, fixes the // common uses. details in #1131 normalizedname = name.indexof('!') === -1 ? normalize(name, parentname, applymap) : name; } } else { //a regular module. normalizedname = normalize(name, parentname, applymap); //normalized name may be a plugin id due to map config //application in normalize. the map config values must //already be normalized, so do not need to redo that part. nameparts = splitprefix(normalizedname); prefix = nameparts[0]; normalizedname = nameparts[1]; isnormalized = true; url = context.nametourl(normalizedname); } } //if the id is a plugin id that cannot be determined if it needs //normalization, stamp it with a unique id so two matching relative //ids that may conflict can be separate. suffix = prefix && !pluginmodule && !isnormalized ? '_unnormalized' + (unnormalizedcounter += 1) : ''; return { prefix: prefix, name: normalizedname, parentmap: parentmodulemap, unnormalized: !!suffix, url: url, originalname: originalname, isdefine: isdefine, id: (prefix ? prefix + '!' + normalizedname : normalizedname) + suffix }; } function getmodule(depmap) { var id = depmap.id, mod = getown(registry, id); if (!mod) { mod = registry[id] = new context.module(depmap); } return mod; } function on(depmap, name, fn) { var id = depmap.id, mod = getown(registry, id); if (hasprop(defined, id) && (!mod || mod.defineemitcomplete)) { if (name === 'defined') { fn(defined[id]); } } else { mod = getmodule(depmap); if (mod.error && name === 'error') { fn(mod.error); } else { mod.on(name, fn); } } } function onerror(err, errback) { var ids = err.requiremodules, notified = false; if (errback) { errback(err); } else { each(ids, function (id) { var mod = getown(registry, id); if (mod) { //set error on module, so it skips timeout checks. mod.error = err; if (mod.events.error) { notified = true; mod.emit('error', err); } } }); if (!notified) { req.onerror(err); } } } /** * internal method to transfer globalqueue items to this context's * defqueue. */ function takeglobalqueue() { //push all the globaldefqueue items into the context's defqueue if (globaldefqueue.length) { //array splice in the values since the context code has a //local var ref to defqueue, so cannot just reassign the one //on context. apsp.apply(defqueue, [defqueue.length, 0].concat(globaldefqueue)); globaldefqueue = []; } } handlers = { 'require': function (mod) { if (mod.require) { return mod.require; } else { return (mod.require = context.makerequire(mod.map)); } }, 'exports': function (mod) { mod.usingexports = true; if (mod.map.isdefine) { if (mod.exports) { return (defined[mod.map.id] = mod.exports); } else { return (mod.exports = defined[mod.map.id] = {}); } } }, 'module': function (mod) { if (mod.module) { return mod.module; } else { return (mod.module = { id: mod.map.id, uri: mod.map.url, config: function () { return getown(config.config, mod.map.id) || {}; }, exports: mod.exports || (mod.exports = {}) }); } } }; function cleanregistry(id) { //clean up machinery used for waiting modules. delete registry[id]; delete enabledregistry[id]; } function breakcycle(mod, traced, processed) { var id = mod.map.id; if (mod.error) { mod.emit('error', mod.error); } else { traced[id] = true; each(mod.depmaps, function (depmap, i) { var depid = depmap.id, dep = getown(registry, depid); //only force things that have not completed //being defined, so still in the registry, //and only if it has not been matched up //in the module already. if (dep && !mod.depmatched[i] && !processed[depid]) { if (getown(traced, depid)) { mod.definedep(i, defined[depid]); mod.check(); //pass false? } else { breakcycle(dep, traced, processed); } } }); processed[id] = true; } } function checkloaded() { var err, usingpathfallback, waitinterval = config.waitseconds * 1000, //it is possible to disable the wait interval by using waitseconds of 0. expired = waitinterval && (context.starttime + waitinterval) < new date().gettime(), noloads = [], reqcalls = [], stillloading = false, needcyclecheck = true; //do not bother if this call was a result of a cycle break. if (incheckloaded) { return; } incheckloaded = true; //figure out the state of all the modules. eachprop(enabledregistry, function (mod) { var map = mod.map, modid = map.id; //skip things that are not enabled or in error state. if (!mod.enabled) { return; } if (!map.isdefine) { reqcalls.push(mod); } if (!mod.error) { //if the module should be executed, and it has not //been inited and time is up, remember it. if (!mod.inited && expired) { if (haspathfallback(modid)) { usingpathfallback = true; stillloading = true; } else { noloads.push(modid); removescript(modid); } } else if (!mod.inited && mod.fetched && map.isdefine) { stillloading = true; if (!map.prefix) { //no reason to keep looking for unfinished //loading. if the only stillloading is a //plugin resource though, keep going, //because it may be that a plugin resource //is waiting on a non-plugin cycle. return (needcyclecheck = false); } } } }); if (expired && noloads.length) { //if wait time expired, throw error of unloaded modules. err = makeerror('timeout', 'load timeout for modules: ' + noloads, null, noloads); err.contextname = context.contextname; return onerror(err); } //not expired, check for a cycle. if (needcyclecheck) { each(reqcalls, function (mod) { breakcycle(mod, {}, {}); }); } //if still waiting on loads, and the waiting load is something //other than a plugin resource, or there are still outstanding //scripts, then just try back later. if ((!expired || usingpathfallback) && stillloading) { //something is still waiting to load. wait for it, but only //if a timeout is not already in effect. if ((isbrowser || iswebworker) && !checkloadedtimeoutid) { checkloadedtimeoutid = settimeout(function () { checkloadedtimeoutid = 0; checkloaded(); }, 50); } } incheckloaded = false; } module = function (map) { this.events = getown(undefevents, map.id) || {}; this.map = map; this.shim = getown(config.shim, map.id); this.depexports = []; this.depmaps = []; this.depmatched = []; this.pluginmaps = {}; this.depcount = 0; /* this.exports this.factory this.depmaps = [], this.enabled, this.fetched */ }; module.prototype = { init: function (depmaps, factory, errback, options) { options = options || {}; //do not do more inits if already done. can happen if there //are multiple define calls for the same module. that is not //a normal, common case, but it is also not unexpected. if (this.inited) { return; } this.factory = factory; if (errback) { //register for errors on this module. this.on('error', errback); } else if (this.events.error) { //if no errback already, but there are error listeners //on this module, set up an errback to pass to the deps. errback = bind(this, function (err) { this.emit('error', err); }); } //do a copy of the dependency array, so that //source inputs are not modified. for example //"shim" deps are passed in here directly, and //doing a direct modification of the depmaps array //would affect that config. this.depmaps = depmaps && depmaps.slice(0); this.errback = errback; //indicate this module has be initialized this.inited = true; this.ignore = options.ignore; //could have option to init this module in enabled mode, //or could have been previously marked as enabled. however, //the dependencies are not known until init is called. so //if enabled previously, now trigger dependencies as enabled. if (options.enabled || this.enabled) { //enable this module and dependencies. //will call this.check() this.enable(); } else { this.check(); } }, definedep: function (i, depexports) { //because of cycles, defined callback for a given //export can be called more than once. if (!this.depmatched[i]) { this.depmatched[i] = true; this.depcount -= 1; this.depexports[i] = depexports; } }, fetch: function () { if (this.fetched) { return; } this.fetched = true; context.starttime = (new date()).gettime(); var map = this.map; //if the manager is for a plugin managed resource, //ask the plugin to load it now. if (this.shim) { context.makerequire(this.map, { enablebuildcallback: true })(this.shim.deps || [], bind(this, function () { return map.prefix ? this.callplugin() : this.load(); })); } else { //regular dependency. return map.prefix ? this.callplugin() : this.load(); } }, load: function () { var url = this.map.url; //regular dependency. if (!urlfetched[url]) { urlfetched[url] = true; context.load(this.map.id, url); } }, /** * checks if the module is ready to define itself, and if so, * define it. */ check: function () { if (!this.enabled || this.enabling) { return; } var err, cjsmodule, id = this.map.id, depexports = this.depexports, exports = this.exports, factory = this.factory; if (!this.inited) { this.fetch(); } else if (this.error) { this.emit('error', this.error); } else if (!this.defining) { //the factory could trigger another require call //that would result in checking this module to //define itself again. if already in the process //of doing that, skip this work. this.defining = true; if (this.depcount < 1 && !this.defined) { if (isfunction(factory)) { //if there is an error listener, favor passing //to that instead of throwing an error. however, //only do it for define()'d modules. require //errbacks should not be called for failures in //their callbacks (#699). however if a global //onerror is set, use that. if ((this.events.error && this.map.isdefine) || req.onerror !== defaultonerror) { try { exports = context.execcb(id, factory, depexports, exports); } catch (e) { err = e; } } else { exports = context.execcb(id, factory, depexports, exports); } // favor return value over exports. if node/cjs in play, // then will not have a return value anyway. favor // module.exports assignment over exports object. if (this.map.isdefine && exports === undefined) { cjsmodule = this.module; if (cjsmodule) { exports = cjsmodule.exports; } else if (this.usingexports) { //exports already set the defined value. exports = this.exports; } } if (err) { err.requiremap = this.map; err.requiremodules = this.map.isdefine ? [this.map.id] : null; err.requiretype = this.map.isdefine ? 'define' : 'require'; return onerror((this.error = err)); } } else { //just a literal value exports = factory; } this.exports = exports; if (this.map.isdefine && !this.ignore) { defined[id] = exports; if (req.onresourceload) { req.onresourceload(context, this.map, this.depmaps); } } //clean up cleanregistry(id); this.defined = true; } //finished the define stage. allow calling check again //to allow define notifications below in the case of a //cycle. this.defining = false; if (this.defined && !this.defineemitted) { this.defineemitted = true; this.emit('defined', this.exports); this.defineemitcomplete = true; } } }, callplugin: function () { var map = this.map, id = map.id, //map already normalized the prefix. pluginmap = makemodulemap(map.prefix); //mark this as a dependency for this plugin, so it //can be traced for cycles. this.depmaps.push(pluginmap); on(pluginmap, 'defined', bind(this, function (plugin) { var load, normalizedmap, normalizedmod, bundleid = getown(bundlesmap, this.map.id), name = this.map.name, parentname = this.map.parentmap ? this.map.parentmap.name : null, localrequire = context.makerequire(map.parentmap, { enablebuildcallback: true }); //if current map is not normalized, wait for that //normalized name to load instead of continuing. if (this.map.unnormalized) { //normalize the id if the plugin allows it. if (plugin.normalize) { name = plugin.normalize(name, function (name) { return normalize(name, parentname, true); }) || ''; } //prefix and name should already be normalized, no need //for applying map config again either. normalizedmap = makemodulemap(map.prefix + '!' + name, this.map.parentmap); on(normalizedmap, 'defined', bind(this, function (value) { this.init([], function () { return value; }, null, { enabled: true, ignore: true }); })); normalizedmod = getown(registry, normalizedmap.id); if (normalizedmod) { //mark this as a dependency for this plugin, so it //can be traced for cycles. this.depmaps.push(normalizedmap); if (this.events.error) { normalizedmod.on('error', bind(this, function (err) { this.emit('error', err); })); } normalizedmod.enable(); } return; } //if a paths config, then just load that file instead to //resolve the plugin, as it is built into that paths layer. if (bundleid) { this.map.url = context.nametourl(bundleid); this.load(); return; } load = bind(this, function (value) { this.init([], function () { return value; }, null, { enabled: true }); }); load.error = bind(this, function (err) { this.inited = true; this.error = err; err.requiremodules = [id]; //remove temp unnormalized modules for this module, //since they will never be resolved otherwise now. eachprop(registry, function (mod) { if (mod.map.id.indexof(id + '_unnormalized') === 0) { cleanregistry(mod.map.id); } }); onerror(err); }); //allow plugins to load other code without having to know the //context or how to 'complete' the load. load.fromtext = bind(this, function (text, textalt) { /*jslint evil: true */ var modulename = map.name, modulemap = makemodulemap(modulename), hasinteractive = useinteractive; //as of 2.1.0, support just passing the text, to reinforce //fromtext only being called once per resource. still //support old style of passing modulename but discard //that modulename in favor of the internal ref. if (textalt) { text = textalt; } //turn off interactive script matching for ie for any define //calls in the text, then turn it back on at the end. if (hasinteractive) { useinteractive = false; } //prime the system by creating a module instance for //it. getmodule(modulemap); //transfer any config to this other module. if (hasprop(config.config, id)) { config.config[modulename] = config.config[id]; } try { req.exec(text); } catch (e) { return onerror(makeerror('fromtexteval', 'fromtext eval for ' + id + ' failed: ' + e, e, [id])); } if (hasinteractive) { useinteractive = true; } //mark this as a dependency for the plugin //resource this.depmaps.push(modulemap); //support anonymous modules. context.completeload(modulename); //bind the value of that module to the value for this //resource id. localrequire([modulename], load); }); //use parentname here since the plugin's name is not reliable, //could be some weird string with no path that actually wants to //reference the parentname's path. plugin.load(map.name, localrequire, load, config); })); context.enable(pluginmap, this); this.pluginmaps[pluginmap.id] = pluginmap; }, enable: function () { enabledregistry[this.map.id] = this; this.enabled = true; //set flag mentioning that the module is enabling, //so that immediate calls to the defined callbacks //for dependencies do not trigger inadvertent load //with the depcount still being zero. this.enabling = true; //enable each dependency each(this.depmaps, bind(this, function (depmap, i) { var id, mod, handler; if (typeof depmap === 'string') { //dependency needs to be converted to a depmap //and wired up to this module. depmap = makemodulemap(depmap, (this.map.isdefine ? this.map : this.map.parentmap), false, !this.skipmap); this.depmaps[i] = depmap; handler = getown(handlers, depmap.id); if (handler) { this.depexports[i] = handler(this); return; } this.depcount += 1; on(depmap, 'defined', bind(this, function (depexports) { this.definedep(i, depexports); this.check(); })); if (this.errback) { on(depmap, 'error', bind(this, this.errback)); } } id = depmap.id; mod = registry[id]; //skip special modules like 'require', 'exports', 'module' //also, don't call enable if it is already enabled, //important in circular dependency cases. if (!hasprop(handlers, id) && mod && !mod.enabled) { context.enable(depmap, this); } })); //enable each plugin that is used in //a dependency eachprop(this.pluginmaps, bind(this, function (pluginmap) { var mod = getown(registry, pluginmap.id); if (mod && !mod.enabled) { context.enable(pluginmap, this); } })); this.enabling = false; this.check(); }, on: function (name, cb) { var cbs = this.events[name]; if (!cbs) { cbs = this.events[name] = []; } cbs.push(cb); }, emit: function (name, evt) { each(this.events[name], function (cb) { cb(evt); }); if (name === 'error') { //now that the error handler was triggered, remove //the listeners, since this broken module instance //can stay around for a while in the registry. delete this.events[name]; } } }; function callgetmodule(args) { //skip modules already defined. if (!hasprop(defined, args[0])) { getmodule(makemodulemap(args[0], null, true)).init(args[1], args[2]); } } function removelistener(node, func, name, iename) { //favor detachevent because of ie9 //issue, see attachevent/addeventlistener comment elsewhere //in this file. if (node.detachevent && !isopera) { //probably ie. if not it will throw an error, which will be //useful to know. if (iename) { node.detachevent(iename, func); } } else { node.removeeventlistener(name, func, false); } } /** * given an event from a script node, get the requirejs info from it, * and then removes the event listeners on the node. * @param {event} evt * @returns {object} */ function getscriptdata(evt) { //using currenttarget instead of target for firefox 2.0's sake. not //all old browsers will be supported, but this one was easy enough //to support and still makes sense. var node = evt.currenttarget || evt.srcelement; //remove the listeners once here. removelistener(node, context.onscriptload, 'load', 'onreadystatechange'); removelistener(node, context.onscripterror, 'error'); return { node: node, id: node && node.getattribute('data-requiremodule') }; } function intakedefines() { var args; //any defined modules in the global queue, intake them now. takeglobalqueue(); //make sure any remaining defqueue items get properly processed. while (defqueue.length) { args = defqueue.shift(); if (args[0] === null) { return onerror(makeerror('mismatch', 'mismatched anonymous define() module: ' + args[args.length - 1])); } else { //args are id, deps, factory. should be normalized by the //define() function. callgetmodule(args); } } } context = { config: config, contextname: contextname, registry: registry, defined: defined, urlfetched: urlfetched, defqueue: defqueue, module: module, makemodulemap: makemodulemap, nexttick: req.nexttick, onerror: onerror, /** * set a configuration for the context. * @param {object} cfg config object to integrate. */ configure: function (cfg) { //make sure the baseurl ends in a slash. if (cfg.baseurl) { if (cfg.baseurl.charat(cfg.baseurl.length - 1) !== '/') { cfg.baseurl += '/'; } } //save off the paths since they require special processing, //they are additive. var shim = config.shim, objs = { paths: true, bundles: true, config: true, map: true }; eachprop(cfg, function (value, prop) { if (objs[prop]) { if (!config[prop]) { config[prop] = {}; } mixin(config[prop], value, true, true); } else { config[prop] = value; } }); //reverse map the bundles if (cfg.bundles) { eachprop(cfg.bundles, function (value, prop) { each(value, function (v) { if (v !== prop) { bundlesmap[v] = prop; } }); }); } //merge shim if (cfg.shim) { eachprop(cfg.shim, function (value, id) { //normalize the structure if (isarray(value)) { value = { deps: value }; } if ((value.exports || value.init) && !value.exportsfn) { value.exportsfn = context.makeshimexports(value); } shim[id] = value; }); config.shim = shim; } //adjust packages if necessary. if (cfg.packages) { each(cfg.packages, function (pkgobj) { var location, name; pkgobj = typeof pkgobj === 'string' ? {name: pkgobj} : pkgobj; name = pkgobj.name; location = pkgobj.location; if (location) { config.paths[name] = pkgobj.location; } //save pointer to main module id for pkg name. //remove leading dot in main, so main paths are normalized, //and remove any trailing .js, since different package //envs have different conventions: some use a module name, //some use a file name. config.pkgs[name] = pkgobj.name + '/' + (pkgobj.main || 'main') .replace(currdirregexp, '') .replace(jssuffixregexp, ''); }); } //if there are any "waiting to execute" modules in the registry, //update the maps for them, since their info, like urls to load, //may have changed. eachprop(registry, function (mod, id) { //if module already has init called, since it is too //late to modify them, and ignore unnormalized ones //since they are transient. if (!mod.inited && !mod.map.unnormalized) { mod.map = makemodulemap(id); } }); //if a deps array or a config callback is specified, then call //require with those args. this is useful when require is defined as a //config object before require.js is loaded. if (cfg.deps || cfg.callback) { context.require(cfg.deps || [], cfg.callback); } }, makeshimexports: function (value) { function fn() { var ret; if (value.init) { ret = value.init.apply(global, arguments); } return ret || (value.exports && getglobal(value.exports)); } return fn; }, makerequire: function (relmap, options) { options = options || {}; function localrequire(deps, callback, errback) { var id, map, requiremod; if (options.enablebuildcallback && callback && isfunction(callback)) { callback.__requirejsbuild = true; } if (typeof deps === 'string') { if (isfunction(callback)) { //invalid call return onerror(makeerror('requireargs', 'invalid require call'), errback); } //if require|exports|module are requested, get the //value for them from the special handlers. caveat: //this only works while module is being defined. if (relmap && hasprop(handlers, deps)) { return handlers[deps](registry[relmap.id]); } //synchronous access to one module. if require.get is //available (as in the node adapter), prefer that. if (req.get) { return req.get(context, deps, relmap, localrequire); } //normalize module name, if it contains . or .. map = makemodulemap(deps, relmap, false, true); id = map.id; if (!hasprop(defined, id)) { return onerror(makeerror('notloaded', 'module name "' + id + '" has not been loaded yet for context: ' + contextname + (relmap ? '' : '. use require([])'))); } return defined[id]; } //grab defines waiting in the global queue. intakedefines(); //mark all the dependencies as needing to be loaded. context.nexttick(function () { //some defines could have been added since the //require call, collect them. intakedefines(); requiremod = getmodule(makemodulemap(null, relmap)); //store if map config should be applied to this require //call for dependencies. requiremod.skipmap = options.skipmap; requiremod.init(deps, callback, errback, { enabled: true }); checkloaded(); }); return localrequire; } mixin(localrequire, { isbrowser: isbrowser, /** * converts a module name + .extension into an url path. * *requires* the use of a module name. it does not support using * plain urls like nametourl. */ tourl: function (modulenameplusext) { var ext, index = modulenameplusext.lastindexof('.'), segment = modulenameplusext.split('/')[0], isrelative = segment === '.' || segment === '..'; //have a file extension alias, and it is not the //dots from a relative path. if (index !== -1 && (!isrelative || index > 1)) { ext = modulenameplusext.substring(index, modulenameplusext.length); modulenameplusext = modulenameplusext.substring(0, index); } return context.nametourl(normalize(modulenameplusext, relmap && relmap.id, true), ext, true); }, defined: function (id) { return hasprop(defined, makemodulemap(id, relmap, false, true).id); }, specified: function (id) { id = makemodulemap(id, relmap, false, true).id; return hasprop(defined, id) || hasprop(registry, id); } }); //only allow undef on top level require calls if (!relmap) { localrequire.undef = function (id) { //bind any waiting define() calls to this context, //fix for #408 takeglobalqueue(); var map = makemodulemap(id, relmap, true), mod = getown(registry, id); removescript(id); delete defined[id]; delete urlfetched[map.url]; delete undefevents[id]; //clean queued defines too. go backwards //in array so that the splices do not //mess up the iteration. eachreverse(defqueue, function (args, i) { if (args[0] === id) { defqueue.splice(i, 1); } }); if (mod) { //hold on to listeners in case the //module will be attempted to be reloaded //using a different config. if (mod.events.defined) { undefevents[id] = mod.events; } cleanregistry(id); } }; } return localrequire; }, /** * called to enable a module if it is still in the registry * awaiting enablement. a second arg, parent, the parent module, * is passed in for context, when this method is overridden by * the optimizer. not shown here to keep code compact. */ enable: function (depmap) { var mod = getown(registry, depmap.id); if (mod) { getmodule(depmap).enable(); } }, /** * internal method used by environment adapters to complete a load event. * a load event could be a script load or just a load pass from a synchronous * load call. * @param {string} modulename the name of the module to potentially complete. */ completeload: function (modulename) { var found, args, mod, shim = getown(config.shim, modulename) || {}, shexports = shim.exports; takeglobalqueue(); while (defqueue.length) { args = defqueue.shift(); if (args[0] === null) { args[0] = modulename; //if already found an anonymous module and bound it //to this name, then this is some other anon module //waiting for its completeload to fire. if (found) { break; } found = true; } else if (args[0] === modulename) { //found matching define call for this script! found = true; } callgetmodule(args); } //do this after the cycle of callgetmodule in case the result //of those calls/init calls changes the registry. mod = getown(registry, modulename); if (!found && !hasprop(defined, modulename) && mod && !mod.inited) { if (config.enforcedefine && (!shexports || !getglobal(shexports))) { if (haspathfallback(modulename)) { return; } else { return onerror(makeerror('nodefine', 'no define call for ' + modulename, null, [modulename])); } } else { //a script that does not call define(), so just simulate //the call for it. callgetmodule([modulename, (shim.deps || []), shim.exportsfn]); } } checkloaded(); }, /** * converts a module name to a file path. supports cases where * modulename may actually be just an url. * note that it **does not** call normalize on the modulename, * it is assumed to have already been normalized. this is an * internal api, not a public one. use tourl for the public api. */ nametourl: function (modulename, ext, skipext) { var paths, syms, i, parentmodule, url, parentpath, bundleid, pkgmain = getown(config.pkgs, modulename); if (pkgmain) { modulename = pkgmain; } bundleid = getown(bundlesmap, modulename); if (bundleid) { return context.nametourl(bundleid, ext, skipext); } //if a colon is in the url, it indicates a protocol is used and it is just //an url to a file, or if it starts with a slash, contains a query arg (i.e. ?) //or ends with .js, then assume the user meant to use an url and not a module id. //the slash is important for protocol-less urls as well as full paths. if (req.jsextregexp.test(modulename)) { //just a plain path, not module name lookup, so just return it. //add extension if it is included. this is a bit wonky, only non-.js things pass //an extension, this method probably needs to be reworked. url = modulename + (ext || ''); } else { //a module that needs to be converted to a path. paths = config.paths; syms = modulename.split('/'); //for each module name segment, see if there is a path //registered for it. start with most specific name //and work up from it. for (i = syms.length; i > 0; i -= 1) { parentmodule = syms.slice(0, i).join('/'); parentpath = getown(paths, parentmodule); if (parentpath) { //if an array, it means there are a few choices, //choose the one that is desired if (isarray(parentpath)) { parentpath = parentpath[0]; } syms.splice(0, i, parentpath); break; } } //join the path parts together, then figure out if baseurl is needed. url = syms.join('/'); url += (ext || (/^data\:|\?/.test(url) || skipext ? '' : '.js')); url = (url.charat(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseurl) + url; } return url + ((url.indexof('?') === -1 ? '?' : '&') + 'version=' + global.version); }, //delegates to req.load. broken out as a separate function to //allow overriding in the optimizer. load: function (id, url) { req.load(context, id, url); }, /** * executes a module callback function. broken out as a separate function * solely to allow the build system to sequence the files in the built * layer in the right sequence. * * @private */ execcb: function (name, callback, args, exports) { return callback.apply(exports, args); }, /** * callback for script loads, used to check status of loading. * * @param {event} evt the event from the browser for the script * that was loaded. */ onscriptload: function (evt) { //using currenttarget instead of target for firefox 2.0's sake. not //all old browsers will be supported, but this one was easy enough //to support and still makes sense. if (evt.type === 'load' || (readyregexp.test((evt.currenttarget || evt.srcelement).readystate))) { //reset interactive script so a script node is not held onto for //to long. interactivescript = null; //pull out the name of the module and the context. var data = getscriptdata(evt); context.completeload(data.id); } }, /** * callback for script errors. */ onscripterror: function (evt) { var data = getscriptdata(evt); if (!haspathfallback(data.id)) { return onerror(makeerror('scripterror', 'script error for: ' + data.id, evt, [data.id])); } } }; context.require = context.makerequire(); return context; } /** * main entry point. * * if the only argument to require is a string, then the module that * is represented by that string is fetched for the appropriate context. * * if the first argument is an array, then it will be treated as an array * of dependency string names to fetch. an optional function callback can * be specified to execute when all of those dependencies are available. * * make a local req variable to help caja compliance (it assumes things * on a require that are not standardized), and to give a short * name for minification/local scope use. */ req = requirejs = function (deps, callback, errback, optional) { //find the right context, use default var context, config, contextname = defcontextname; // determine if have config object in the call. if (!isarray(deps) && typeof deps !== 'string') { // deps is a config object config = deps; if (isarray(callback)) { // adjust args if there are dependencies deps = callback; callback = errback; errback = optional; } else { deps = []; } } if (config && config.context) { contextname = config.context; } context = getown(contexts, contextname); if (!context) { context = contexts[contextname] = req.s.newcontext(contextname); } if (config) { context.configure(config); } return context.require(deps, callback, errback); }; /** * support require.config() to make it easier to cooperate with other * amd loaders on globally agreed names. */ req.config = function (config) { return req(config); }; /** * execute something after the current tick * of the event loop. override for other envs * that have a better solution than settimeout. * @param {function} fn function to execute later. */ req.nexttick = typeof settimeout !== 'undefined' ? function (fn) { settimeout(fn, 4); } : function (fn) { fn(); }; /** * export require as a global, but only if it does not already exist. */ if (!require) { require = req; } req.version = version; //used to filter out dependencies that are already paths. req.jsextregexp = /^\/|:|\?|\.js$/; req.isbrowser = isbrowser; s = req.s = { contexts: contexts, newcontext: newcontext }; //create default context. req({}); //exports some context-sensitive methods on global require. each([ 'tourl', 'undef', 'defined', 'specified' ], function (prop) { //reference from contexts instead of early binding to default context, //so that during builds, the latest instance of the default context //with its config gets used. req[prop] = function () { var ctx = contexts[defcontextname]; return ctx.require[prop].apply(ctx, arguments); }; }); if (isbrowser) { head = s.head = document.getelementsbytagname('head')[0]; //if base tag is in play, using appendchild is a problem for ie6. //when that browser dies, this can be removed. details in this jquery bug: //http://dev.jquery.com/ticket/2709 baseelement = document.getelementsbytagname('base')[0]; if (baseelement) { head = s.head = baseelement.parentnode; } } /** * any errors that require explicitly generates will be passed to this * function. intercept/override it if you want custom error handling. * @param {error} err the error object. */ req.onerror = defaultonerror; /** * creates the node for the load command. only used in browser envs. */ req.createnode = function (config, modulename, url) { var node = config.xhtml ? document.createelementns('http://www.w3.org/1999/xhtml', 'html:script') : document.createelement('script'); node.type = config.scripttype || 'text/javascript'; node.charset = 'utf-8'; node.async = true; return node; }; /** * does the request to load a module for the browser case. * make this a separate function to allow other environments * to override it. * * @param {object} context the require context to find state. * @param {string} modulename the name of the module. * @param {object} url the url to the module. */ req.load = function (context, modulename, url) { var config = (context && context.config) || {}, node; if (isbrowser) { //in the browser so use a script tag node = req.createnode(config, modulename, url); node.setattribute('data-requirecontext', context.contextname); node.setattribute('data-requiremodule', modulename); //set up load listener. test attachevent first because ie9 has //a subtle issue in its addeventlistener and script onload firings //that do not match the behavior of all other browsers with //addeventlistener support, which fire the onload event for a //script right after the script execution. see: //https://connect.microsoft.com/ie/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution //unfortunately opera implements attachevent but does not follow the script //script execution mode. if (node.attachevent && //check if node.attachevent is artificially added by custom script or //natively supported by browser //read https://github.com/jrburke/requirejs/issues/187 //if we can not find [native code] then it must not natively supported. //in ie8, node.attachevent does not have tostring() //note the test for "[native code" with no closing brace, see: //https://github.com/jrburke/requirejs/issues/273 !(node.attachevent.tostring && node.attachevent.tostring().indexof('[native code') < 0) && !isopera) { //probably ie. ie (at least 6-8) do not fire //script onload right after executing the script, so //we cannot tie the anonymous define call to a name. //however, ie reports the script as being in 'interactive' //readystate at the time of the define call. useinteractive = true; node.attachevent('onreadystatechange', context.onscriptload); //it would be great to add an error handler here to catch //404s in ie9+. however, onreadystatechange will fire before //the error handler, so that does not help. if addeventlistener //is used, then ie will fire error before load, but we cannot //use that pathway given the connect.microsoft.com issue //mentioned above about not doing the 'script execute, //then fire the script load event listener before execute //next script' that other browsers do. //best hope: ie10 fixes the issues, //and then destroys all installs of ie 6-9. //node.attachevent('onerror', context.onscripterror); } else { node.addeventlistener('load', context.onscriptload, false); node.addeventlistener('error', context.onscripterror, false); } node.src = url; //for some cache cases in ie 6-8, the script executes before the end //of the appendchild execution, so to tie an anonymous define //call to the module name (which is stored on the node), hold on //to a reference to this node, but clear after the dom insertion. currentlyaddingscript = node; if (baseelement) { head.insertbefore(node, baseelement); } else { head.appendchild(node); } currentlyaddingscript = null; return node; } else if (iswebworker) { try { //in a web worker, use importscripts. this is not a very //efficient use of importscripts, importscripts will block until //its script is downloaded and evaluated. however, if web workers //are in play, the expectation that a build has been done so that //only one script needs to be loaded anyway. this may need to be //reevaluated if other use cases become common. importscripts(url); //account for anonymous modules context.completeload(modulename); } catch (e) { context.onerror(makeerror('importscripts', 'importscripts failed for ' + modulename + ' at ' + url, e, [modulename])); } } }; function getinteractivescript() { if (interactivescript && interactivescript.readystate === 'interactive') { return interactivescript; } eachreverse(scripts(), function (script) { if (script.readystate === 'interactive') { return (interactivescript = script); } }); return interactivescript; } //look for a data-main script attribute, which could also adjust the baseurl. if (isbrowser && !cfg.skipdatamain) { //figure out baseurl. get it from the script tag with require.js in it. eachreverse(scripts(), function (script) { //set the 'head' where we can append children by //using the script's parent. if (!head) { head = script.parentnode; } //look for a data-main attribute to set main script for the page //to load. if it is there, the path to data main becomes the //baseurl, if it is not already set. datamain = script.getattribute('data-main'); if (datamain) { //preserve datamain in case it is a path (i.e. contains '?') mainscript = datamain; //set final baseurl if there is not already an explicit one. if (!cfg.baseurl) { //pull off the directory of data-main for use as the //baseurl. src = mainscript.split('/'); mainscript = src.pop(); subpath = src.length ? src.join('/') + '/' : './'; cfg.baseurl = subpath; } //strip off any trailing .js since mainscript is now //like a module name. mainscript = mainscript.replace(jssuffixregexp, ''); //if mainscript is still a path, fall back to datamain if (req.jsextregexp.test(mainscript)) { mainscript = datamain; } //put the data-main script in the files to load. cfg.deps = cfg.deps ? cfg.deps.concat(mainscript) : [mainscript]; return true; } }); } /** * the function that handles definitions of modules. differs from * require() in that a string for the module should be the first argument, * and the function to execute after dependencies are loaded should * return a value to define the module corresponding to the first argument's * name. */ define = function (name, deps, callback) { var node, context; //allow for anonymous modules if (typeof name !== 'string') { //adjust args appropriately callback = deps; deps = name; name = null; } //this module may not have dependencies if (!isarray(deps)) { callback = deps; deps = null; } //if no name, and callback is a function, then figure out if it a //commonjs thing with dependencies. if (!deps && isfunction(callback)) { deps = []; //remove comments from the callback string, //look for require calls, and pull them into the dependencies, //but only if there are function args. if (callback.length) { callback .tostring() .replace(commentregexp, '') .replace(cjsrequireregexp, function (match, dep) { deps.push(dep); }); //may be a commonjs thing even without require calls, but still //could use exports, and module. avoid doing exports and module //work though if it just needs require. //requires the function to expect the commonjs variables in the //order listed below. deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps); } } //if in ie 6-8 and hit an anonymous define() call, do the interactive //work. if (useinteractive) { node = currentlyaddingscript || getinteractivescript(); if (node) { if (!name) { name = node.getattribute('data-requiremodule'); } context = contexts[node.getattribute('data-requirecontext')]; } } //always save off evaluating the def call until the script onload handler. //this allows multiple modules to be in a file without prematurely //tracing dependencies, and allows for anonymous module support, //where the module name is not known until the script onload event //occurs. if no context, use the global queue, and get it processed //in the onscript load callback. (context ? context.defqueue : globaldefqueue).push([name, deps, callback]); }; define.amd = { jquery: true }; /** * executes the text. normally just uses eval, but can be modified * to use a better, environment-specific call. only used for transpiling * loader plugins, not for plain js modules. * @param {string} text the text to execute/evaluate. */ req.exec = function (text) { /*jslint evil: true */ return eval(text); }; //set up with config info. req(cfg); }(this));