libs_require_require.js.html 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>libs/require/require.js - Documentation</title>
  6. <script src="scripts/prettify/prettify.js"></script>
  7. <script src="scripts/prettify/lang-css.js"></script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
  13. </head>
  14. <body>
  15. <input type="checkbox" id="nav-trigger" class="nav-trigger" />
  16. <label for="nav-trigger" class="navicon-button x">
  17. <div class="navicon"></div>
  18. </label>
  19. <label for="nav-trigger" class="overlay"></label>
  20. <nav>
  21. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FontObject.html">FontObject</a></li><li><a href="jsPDF.html">jsPDF</a></li><li><a href="PubSub.html">PubSub</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addFont">addFont</a></li><li><a href="global.html#addMetadata">addMetadata</a></li><li><a href="global.html#addPage">addPage</a></li><li><a href="global.html#CapJoinStyles">CapJoinStyles</a></li><li><a href="global.html#circle">circle</a></li><li><a href="global.html#CssColors">CssColors</a></li><li><a href="global.html#ellipse">ellipse</a></li><li><a href="global.html#getFontList">getFontList</a></li><li><a href="global.html#html2pdf">html2pdf</a></li><li><a href="global.html#http">http</a></li><li><a href="global.html#lines">lines</a></li><li><a href="global.html#lstext">lstext</a></li><li><a href="global.html#output">output</a></li><li><a href="global.html#rect">rect</a></li><li><a href="global.html#requirejs">requirejs</a></li><li><a href="global.html#reset">reset</a></li><li><a href="global.html#roundedRect">roundedRect</a></li><li><a href="global.html#save">save</a></li><li><a href="global.html#setDisplayMode">setDisplayMode</a></li><li><a href="global.html#setDrawColor">setDrawColor</a></li><li><a href="global.html#setFillColor">setFillColor</a></li><li><a href="global.html#setFont">setFont</a></li><li><a href="global.html#setFontSize">setFontSize</a></li><li><a href="global.html#setFontStyle">setFontStyle</a></li><li><a href="global.html#setLineCap">setLineCap</a></li><li><a href="global.html#setLineJoin">setLineJoin</a></li><li><a href="global.html#setLineWidth">setLineWidth</a></li><li><a href="global.html#setPage">setPage</a></li><li><a href="global.html#setProperties">setProperties</a></li><li><a href="global.html#setTextColor">setTextColor</a></li><li><a href="global.html#text">text</a></li><li><a href="global.html#toUrl">toUrl</a></li><li><a href="global.html#triangle">triangle</a></li><li><a href="global.html#triggerEvent">triggerEvent</a></li></ul>
  22. </nav>
  23. <div id="main">
  24. <h1 class="page-title">libs/require/require.js</h1>
  25. <section>
  26. <article>
  27. <pre class="prettyprint source linenums"><code>/** vim: et:ts=4:sw=4:sts=4
  28. * @license RequireJS 2.1.15 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
  29. * Available via the MIT or new BSD license.
  30. * see: http://github.com/jrburke/requirejs for details
  31. */
  32. //Not using strict: uneven strict support in browsers, #392, and causes
  33. //problems with requirejs.exec()/transpiler plugins that may not be strict.
  34. /*jslint regexp: true, nomen: true, sloppy: true */
  35. /*global window, navigator, document, importScripts, setTimeout, opera */
  36. var requirejs, require, define;
  37. (function(global) {
  38. 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'
  39. &amp;&amp; typeof navigator !== 'undefined' &amp;&amp; window.document), isWebWorker = !isBrowser &amp;&amp; typeof importScripts !== 'undefined',
  40. //PS3 indicates loaded and complete, but need to wait for complete
  41. //specifically. Sequence is 'loading', 'loaded', execution,
  42. // then 'complete'. The UA check is unfortunate, but not sure how
  43. //to feature test w/o causing perf issues.
  44. readyRegExp = isBrowser &amp;&amp; navigator.platform === 'PLAYSTATION 3' ? /^complete$/ : /^(complete|loaded)$/, defContextName = '_',
  45. //Oh the tragedy, detecting opera. See the usage of isOpera for reason.
  46. isOpera = typeof opera !== 'undefined' &amp;&amp; opera.toString() === '[object Opera]', contexts = {}, cfg = {}, globalDefQueue = [], useInteractive = false;
  47. function isFunction(it) {
  48. return ostring.call(it) === '[object Function]';
  49. }
  50. function isArray(it) {
  51. return ostring.call(it) === '[object Array]';
  52. }
  53. /**
  54. * Helper function for iterating over an array. If the func returns
  55. * a true value, it will break out of the loop.
  56. */
  57. function each(ary,func) {
  58. if (ary) {
  59. var i;
  60. for (i = 0; i &lt; ary.length; i += 1) {
  61. if (ary[i] &amp;&amp; func(ary[i], i, ary)) {
  62. break;
  63. }
  64. }
  65. }
  66. }
  67. /**
  68. * Helper function for iterating over an array backwards. If the func
  69. * returns a true value, it will break out of the loop.
  70. */
  71. function eachReverse(ary,func) {
  72. if (ary) {
  73. var i;
  74. for (i = ary.length - 1; i > -1; i -= 1) {
  75. if (ary[i] &amp;&amp; func(ary[i], i, ary)) {
  76. break;
  77. }
  78. }
  79. }
  80. }
  81. function hasProp(obj,prop) {
  82. return hasOwn.call(obj, prop);
  83. }
  84. function getOwn(obj,prop) {
  85. return hasProp(obj, prop) &amp;&amp; obj[prop];
  86. }
  87. /**
  88. * Cycles over properties in an object and calls a function for each
  89. * property value. If the function returns a truthy value, then the
  90. * iteration is stopped.
  91. */
  92. function eachProp(obj,func) {
  93. var prop;
  94. for (prop in obj) {
  95. if (hasProp(obj, prop)) {
  96. if (func(obj[prop], prop)) {
  97. break;
  98. }
  99. }
  100. }
  101. }
  102. /**
  103. * Simple function to mix in properties from source into target,
  104. * but only if target does not already have a property of the same name.
  105. */
  106. function mixin(target,source,force,deepStringMixin) {
  107. if (source) {
  108. eachProp(source, function(value,prop) {
  109. if (force || !hasProp(target, prop)) {
  110. if (deepStringMixin &amp;&amp; typeof value === 'object' &amp;&amp; value &amp;&amp; !isArray(value) &amp;&amp; !isFunction(value) &amp;&amp; !(value instanceof RegExp)) {
  111. if (!target[prop]) {
  112. target[prop] = {};
  113. }
  114. mixin(target[prop], value, force, deepStringMixin);
  115. } else {
  116. target[prop] = value;
  117. }
  118. }
  119. });
  120. }
  121. return target;
  122. }
  123. //Similar to Function.prototype.bind, but the 'this' object is specified
  124. //first, since it is easier to read/figure out what 'this' will be.
  125. function bind(obj,fn) {
  126. return function() {
  127. return fn.apply(obj, arguments);
  128. };
  129. }
  130. function scripts() {
  131. return document.getElementsByTagName('script');
  132. }
  133. function defaultOnError(err) {
  134. throw err;
  135. }
  136. //Allow getting a global that is expressed in
  137. //dot notation, like 'a.b.c'.
  138. function getGlobal(value) {
  139. if (!value) {
  140. return value;
  141. }
  142. var g = global;
  143. each(value.split('.'), function(part) {
  144. g = g[part];
  145. });
  146. return g;
  147. }
  148. /**
  149. * Constructs an error with a pointer to an URL with more information.
  150. * @param {String} id the error ID that maps to an ID on a web page.
  151. * @param {String} message human readable error.
  152. * @param {Error} [err] the original error, if there is one.
  153. *
  154. * @returns {Error}
  155. */
  156. function makeError(id,msg,err,requireModules) {
  157. var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
  158. e.requireType = id;
  159. e.requireModules = requireModules;
  160. if (err) {
  161. e.originalError = err;
  162. }
  163. return e;
  164. }
  165. if (typeof define !== 'undefined') {
  166. //If a define is already in play via another AMD loader,
  167. //do not overwrite.
  168. return;
  169. }
  170. if (typeof requirejs !== 'undefined') {
  171. if (isFunction(requirejs)) {
  172. //Do not overwrite an existing requirejs instance.
  173. return;
  174. }
  175. cfg = requirejs;
  176. requirejs = undefined;
  177. }
  178. //Allow for a require config object
  179. if (typeof require !== 'undefined' &amp;&amp; !isFunction(require)) {
  180. //assume it is a config object.
  181. cfg = require;
  182. require = undefined;
  183. }
  184. function newContext(contextName) {
  185. var inCheckLoaded, Module, context, handlers, checkLoadedTimeoutId, config = {
  186. //Defaults. Do not set a default for map
  187. //config to speed up normalize(), which
  188. //will run faster if there is no default.
  189. waitSeconds : 7,
  190. baseUrl : './',
  191. paths : {},
  192. bundles : {},
  193. pkgs : {},
  194. shim : {},
  195. config : {}
  196. }, registry = {},
  197. //registry of just enabled modules, to speed
  198. //cycle breaking code when lots of modules
  199. //are registered, but not activated.
  200. enabledRegistry = {}, undefEvents = {}, defQueue = [], defined = {}, urlFetched = {}, bundlesMap = {}, requireCounter = 1, unnormalizedCounter = 1;
  201. /**
  202. * Trims the . and .. from an array of path segments.
  203. * It will keep a leading path segment if a .. will become
  204. * the first path segment, to help with module name lookups,
  205. * which act like paths, but can be remapped. But the end result,
  206. * all paths that use this function should look normalized.
  207. * NOTE: this method MODIFIES the input array.
  208. * @param {Array} ary the array of path segments.
  209. */
  210. function trimDots(ary) {
  211. var i, part;
  212. for (i = 0; i &lt; ary.length; i++) {
  213. part = ary[i];
  214. if (part === '.') {
  215. ary.splice(i, 1);
  216. i -= 1;
  217. } else if (part === '..') {
  218. // If at the start, or previous value is still ..,
  219. // keep them so that when converted to a path it may
  220. // still work when converted to a path, even though
  221. // as an ID it is less than ideal. In larger point
  222. // releases, may be better to just kick out an error.
  223. if (i === 0 || (i == 1 &amp;&amp; ary[2] === '..') || ary[i - 1] === '..') {
  224. continue;
  225. } else if (i > 0) {
  226. ary.splice(i - 1, 2);
  227. i -= 2;
  228. }
  229. }
  230. }
  231. }
  232. /**
  233. * Given a relative module name, like ./something, normalize it to
  234. * a real name that can be mapped to a path.
  235. * @param {String} name the relative name
  236. * @param {String} baseName a real name that the name arg is relative
  237. * to.
  238. * @param {Boolean} applyMap apply the map config to the value. Should
  239. * only be done if this normalization is for a dependency ID.
  240. * @returns {String} normalized name
  241. */
  242. function normalize(name,baseName,applyMap) {
  243. var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex, foundMap, foundI, foundStarMap, starI, normalizedBaseParts, baseParts = (baseName &amp;&amp; baseName.split('/')), map = config.map, starMap = map &amp;&amp; map['*'];
  244. //Adjust any relative paths.
  245. if (name) {
  246. name = name.split('/');
  247. lastIndex = name.length - 1;
  248. // If wanting node ID compatibility, strip .js from end
  249. // of IDs. Have to do this here, and not in nameToUrl
  250. // because node allows either .js or non .js to map
  251. // to same file.
  252. if (config.nodeIdCompat &amp;&amp; jsSuffixRegExp.test(name[lastIndex])) {
  253. name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
  254. }
  255. // Starts with a '.' so need the baseName
  256. if (name[0].charAt(0) === '.' &amp;&amp; baseParts) {
  257. //Convert baseName to array, and lop off the last part,
  258. //so that . matches that 'directory' and not name of the baseName's
  259. //module. For instance, baseName of 'one/two/three', maps to
  260. //'one/two/three.js', but we want the directory, 'one/two' for
  261. //this normalization.
  262. normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
  263. name = normalizedBaseParts.concat(name);
  264. }
  265. trimDots(name);
  266. name = name.join('/');
  267. }
  268. //Apply map config if available.
  269. if (applyMap &amp;&amp; map &amp;&amp; (baseParts || starMap)) {
  270. nameParts = name.split('/');
  271. outerLoop: for (i = nameParts.length; i > 0; i -= 1) {
  272. nameSegment = nameParts.slice(0, i).join('/');
  273. if (baseParts) {
  274. //Find the longest baseName segment match in the config.
  275. //So, do joins on the biggest to smallest lengths of baseParts.
  276. for (j = baseParts.length; j > 0; j -= 1) {
  277. mapValue = getOwn(map, baseParts.slice(0, j).join('/'));
  278. //baseName segment has config, find if it has one for
  279. //this name.
  280. if (mapValue) {
  281. mapValue = getOwn(mapValue, nameSegment);
  282. if (mapValue) {
  283. //Match, update name to the new value.
  284. foundMap = mapValue;
  285. foundI = i;
  286. break outerLoop;
  287. }
  288. }
  289. }
  290. }
  291. //Check for a star map match, but just hold on to it,
  292. //if there is a shorter segment match later in a matching
  293. //config, then favor over this star map.
  294. if (!foundStarMap &amp;&amp; starMap &amp;&amp; getOwn(starMap, nameSegment)) {
  295. foundStarMap = getOwn(starMap, nameSegment);
  296. starI = i;
  297. }
  298. }
  299. if (!foundMap &amp;&amp; foundStarMap) {
  300. foundMap = foundStarMap;
  301. foundI = starI;
  302. }
  303. if (foundMap) {
  304. nameParts.splice(0, foundI, foundMap);
  305. name = nameParts.join('/');
  306. }
  307. }
  308. // If the name points to a package's name, use
  309. // the package main instead.
  310. pkgMain = getOwn(config.pkgs, name);
  311. return pkgMain ? pkgMain : name;
  312. }
  313. function removeScript(name) {
  314. if (isBrowser) {
  315. each(scripts(), function(scriptNode) {
  316. if (scriptNode.getAttribute('data-requiremodule') === name &amp;&amp; scriptNode.getAttribute('data-requirecontext') === context.contextName) {
  317. scriptNode.parentNode.removeChild(scriptNode);
  318. return true;
  319. }
  320. });
  321. }
  322. }
  323. function hasPathFallback(id) {
  324. var pathConfig = getOwn(config.paths, id);
  325. if (pathConfig &amp;&amp; isArray(pathConfig) &amp;&amp; pathConfig.length > 1) {
  326. //Pop off the first array value, since it failed, and
  327. //retry
  328. pathConfig.shift();
  329. context.require.undef(id);
  330. //Custom require that does not do map translation, since
  331. //ID is "absolute", already mapped/resolved.
  332. context.makeRequire(null, {
  333. skipMap : true
  334. })([
  335. id
  336. ]);
  337. return true;
  338. }
  339. }
  340. //Turns a plugin!resource to [plugin, resource]
  341. //with the plugin being undefined if the name
  342. //did not have a plugin prefix.
  343. function splitPrefix(name) {
  344. var prefix, index = name ? name.indexOf('!') : -1;
  345. if (index > -1) {
  346. prefix = name.substring(0, index);
  347. name = name.substring(index + 1, name.length);
  348. }
  349. return [
  350. prefix, name
  351. ];
  352. }
  353. /**
  354. * Creates a module mapping that includes plugin prefix, module
  355. * name, and path. If parentModuleMap is provided it will
  356. * also normalize the name via require.normalize()
  357. *
  358. * @param {String} name the module name
  359. * @param {String} [parentModuleMap] parent module map
  360. * for the module name, used to resolve relative names.
  361. * @param {Boolean} isNormalized: is the ID already normalized.
  362. * This is true if this call is done for a define() module ID.
  363. * @param {Boolean} applyMap: apply the map config to the ID.
  364. * Should only be true if this map is for a dependency.
  365. *
  366. * @returns {Object}
  367. */
  368. function makeModuleMap(name,parentModuleMap,isNormalized,applyMap) {
  369. var url, pluginModule, suffix, nameParts, prefix = null, parentName = parentModuleMap ? parentModuleMap.name : null, originalName = name, isDefine = true, normalizedName = '';
  370. //If no name, then it means it is a require call, generate an
  371. //internal name.
  372. if (!name) {
  373. isDefine = false;
  374. name = '_@r' + (requireCounter += 1);
  375. }
  376. nameParts = splitPrefix(name);
  377. prefix = nameParts[0];
  378. name = nameParts[1];
  379. if (prefix) {
  380. prefix = normalize(prefix, parentName, applyMap);
  381. pluginModule = getOwn(defined, prefix);
  382. }
  383. //Account for relative paths if there is a base name.
  384. if (name) {
  385. if (prefix) {
  386. if (pluginModule &amp;&amp; pluginModule.normalize) {
  387. //Plugin is loaded, use its normalize method.
  388. normalizedName = pluginModule.normalize(name, function(name) {
  389. return normalize(name, parentName, applyMap);
  390. });
  391. } else {
  392. // If nested plugin references, then do not try to
  393. // normalize, as it will not normalize correctly. This
  394. // places a restriction on resourceIds, and the longer
  395. // term solution is not to normalize until plugins are
  396. // loaded and all normalizations to allow for async
  397. // loading of a loader plugin. But for now, fixes the
  398. // common uses. Details in #1131
  399. normalizedName = name.indexOf('!') === -1 ? normalize(name, parentName, applyMap) : name;
  400. }
  401. } else {
  402. //A regular module.
  403. normalizedName = normalize(name, parentName, applyMap);
  404. //Normalized name may be a plugin ID due to map config
  405. //application in normalize. The map config values must
  406. //already be normalized, so do not need to redo that part.
  407. nameParts = splitPrefix(normalizedName);
  408. prefix = nameParts[0];
  409. normalizedName = nameParts[1];
  410. isNormalized = true;
  411. url = context.nameToUrl(normalizedName);
  412. }
  413. }
  414. //If the id is a plugin id that cannot be determined if it needs
  415. //normalization, stamp it with a unique ID so two matching relative
  416. //ids that may conflict can be separate.
  417. suffix = prefix &amp;&amp; !pluginModule &amp;&amp; !isNormalized ? '_unnormalized' + (unnormalizedCounter += 1) : '';
  418. return {
  419. prefix : prefix,
  420. name : normalizedName,
  421. parentMap : parentModuleMap,
  422. unnormalized : !!suffix,
  423. url : url,
  424. originalName : originalName,
  425. isDefine : isDefine,
  426. id : (prefix ? prefix + '!' + normalizedName : normalizedName) + suffix
  427. };
  428. }
  429. function getModule(depMap) {
  430. var id = depMap.id, mod = getOwn(registry, id);
  431. if (!mod) {
  432. mod = registry[id] = new context.Module(depMap);
  433. }
  434. return mod;
  435. }
  436. function on(depMap,name,fn) {
  437. var id = depMap.id, mod = getOwn(registry, id);
  438. if (hasProp(defined, id) &amp;&amp; (!mod || mod.defineEmitComplete)) {
  439. if (name === 'defined') {
  440. fn(defined[id]);
  441. }
  442. } else {
  443. mod = getModule(depMap);
  444. if (mod.error &amp;&amp; name === 'error') {
  445. fn(mod.error);
  446. } else {
  447. mod.on(name, fn);
  448. }
  449. }
  450. }
  451. function onError(err,errback) {
  452. var ids = err.requireModules, notified = false;
  453. if (errback) {
  454. errback(err);
  455. } else {
  456. each(ids, function(id) {
  457. var mod = getOwn(registry, id);
  458. if (mod) {
  459. //Set error on module, so it skips timeout checks.
  460. mod.error = err;
  461. if (mod.events.error) {
  462. notified = true;
  463. mod.emit('error', err);
  464. }
  465. }
  466. });
  467. if (!notified) {
  468. req.onError(err);
  469. }
  470. }
  471. }
  472. /**
  473. * Internal method to transfer globalQueue items to this context's
  474. * defQueue.
  475. */
  476. function takeGlobalQueue() {
  477. //Push all the globalDefQueue items into the context's defQueue
  478. if (globalDefQueue.length) {
  479. //Array splice in the values since the context code has a
  480. //local var ref to defQueue, so cannot just reassign the one
  481. //on context.
  482. apsp.apply(defQueue, [
  483. defQueue.length, 0
  484. ].concat(globalDefQueue));
  485. globalDefQueue = [];
  486. }
  487. }
  488. handlers = {
  489. 'require' : function(mod) {
  490. if (mod.require) {
  491. return mod.require;
  492. } else {
  493. return (mod.require = context.makeRequire(mod.map));
  494. }
  495. },
  496. 'exports' : function(mod) {
  497. mod.usingExports = true;
  498. if (mod.map.isDefine) {
  499. if (mod.exports) {
  500. return (defined[mod.map.id] = mod.exports);
  501. } else {
  502. return (mod.exports = defined[mod.map.id] = {});
  503. }
  504. }
  505. },
  506. 'module' : function(mod) {
  507. if (mod.module) {
  508. return mod.module;
  509. } else {
  510. return (mod.module = {
  511. id : mod.map.id,
  512. uri : mod.map.url,
  513. config : function() {
  514. return getOwn(config.config, mod.map.id) || {};
  515. },
  516. exports : mod.exports || (mod.exports = {})
  517. });
  518. }
  519. }
  520. };
  521. function cleanRegistry(id) {
  522. //Clean up machinery used for waiting modules.
  523. delete registry[id];
  524. delete enabledRegistry[id];
  525. }
  526. function breakCycle(mod,traced,processed) {
  527. var id = mod.map.id;
  528. if (mod.error) {
  529. mod.emit('error', mod.error);
  530. } else {
  531. traced[id] = true;
  532. each(mod.depMaps, function(depMap,i) {
  533. var depId = depMap.id, dep = getOwn(registry, depId);
  534. //Only force things that have not completed
  535. //being defined, so still in the registry,
  536. //and only if it has not been matched up
  537. //in the module already.
  538. if (dep &amp;&amp; !mod.depMatched[i] &amp;&amp; !processed[depId]) {
  539. if (getOwn(traced, depId)) {
  540. mod.defineDep(i, defined[depId]);
  541. mod.check(); //pass false?
  542. } else {
  543. breakCycle(dep, traced, processed);
  544. }
  545. }
  546. });
  547. processed[id] = true;
  548. }
  549. }
  550. function checkLoaded() {
  551. var err, usingPathFallback, waitInterval = config.waitSeconds * 1000,
  552. //It is possible to disable the wait interval by using waitSeconds of 0.
  553. expired = waitInterval &amp;&amp; (context.startTime + waitInterval) &lt; new Date().getTime(), noLoads = [], reqCalls = [], stillLoading = false, needCycleCheck = true;
  554. //Do not bother if this call was a result of a cycle break.
  555. if (inCheckLoaded) {
  556. return;
  557. }
  558. inCheckLoaded = true;
  559. //Figure out the state of all the modules.
  560. eachProp(enabledRegistry, function(mod) {
  561. var map = mod.map, modId = map.id;
  562. //Skip things that are not enabled or in error state.
  563. if (!mod.enabled) {
  564. return;
  565. }
  566. if (!map.isDefine) {
  567. reqCalls.push(mod);
  568. }
  569. if (!mod.error) {
  570. //If the module should be executed, and it has not
  571. //been inited and time is up, remember it.
  572. if (!mod.inited &amp;&amp; expired) {
  573. if (hasPathFallback(modId)) {
  574. usingPathFallback = true;
  575. stillLoading = true;
  576. } else {
  577. noLoads.push(modId);
  578. removeScript(modId);
  579. }
  580. } else if (!mod.inited &amp;&amp; mod.fetched &amp;&amp; map.isDefine) {
  581. stillLoading = true;
  582. if (!map.prefix) {
  583. //No reason to keep looking for unfinished
  584. //loading. If the only stillLoading is a
  585. //plugin resource though, keep going,
  586. //because it may be that a plugin resource
  587. //is waiting on a non-plugin cycle.
  588. return (needCycleCheck = false);
  589. }
  590. }
  591. }
  592. });
  593. if (expired &amp;&amp; noLoads.length) {
  594. //If wait time expired, throw error of unloaded modules.
  595. err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads);
  596. err.contextName = context.contextName;
  597. return onError(err);
  598. }
  599. //Not expired, check for a cycle.
  600. if (needCycleCheck) {
  601. each(reqCalls, function(mod) {
  602. breakCycle(mod, {}, {});
  603. });
  604. }
  605. //If still waiting on loads, and the waiting load is something
  606. //other than a plugin resource, or there are still outstanding
  607. //scripts, then just try back later.
  608. if ((!expired || usingPathFallback) &amp;&amp; stillLoading) {
  609. //Something is still waiting to load. Wait for it, but only
  610. //if a timeout is not already in effect.
  611. if ((isBrowser || isWebWorker) &amp;&amp; !checkLoadedTimeoutId) {
  612. checkLoadedTimeoutId = setTimeout(function() {
  613. checkLoadedTimeoutId = 0;
  614. checkLoaded();
  615. }, 50);
  616. }
  617. }
  618. inCheckLoaded = false;
  619. }
  620. Module = function(map) {
  621. this.events = getOwn(undefEvents, map.id) || {};
  622. this.map = map;
  623. this.shim = getOwn(config.shim, map.id);
  624. this.depExports = [];
  625. this.depMaps = [];
  626. this.depMatched = [];
  627. this.pluginMaps = {};
  628. this.depCount = 0;
  629. /* this.exports this.factory
  630. this.depMaps = [],
  631. this.enabled, this.fetched
  632. */
  633. };
  634. Module.prototype = {
  635. init : function(depMaps,factory,errback,options) {
  636. options = options || {};
  637. //Do not do more inits if already done. Can happen if there
  638. //are multiple define calls for the same module. That is not
  639. //a normal, common case, but it is also not unexpected.
  640. if (this.inited) {
  641. return;
  642. }
  643. this.factory = factory;
  644. if (errback) {
  645. //Register for errors on this module.
  646. this.on('error', errback);
  647. } else if (this.events.error) {
  648. //If no errback already, but there are error listeners
  649. //on this module, set up an errback to pass to the deps.
  650. errback = bind(this, function(err) {
  651. this.emit('error', err);
  652. });
  653. }
  654. //Do a copy of the dependency array, so that
  655. //source inputs are not modified. For example
  656. //"shim" deps are passed in here directly, and
  657. //doing a direct modification of the depMaps array
  658. //would affect that config.
  659. this.depMaps = depMaps &amp;&amp; depMaps.slice(0);
  660. this.errback = errback;
  661. //Indicate this module has be initialized
  662. this.inited = true;
  663. this.ignore = options.ignore;
  664. //Could have option to init this module in enabled mode,
  665. //or could have been previously marked as enabled. However,
  666. //the dependencies are not known until init is called. So
  667. //if enabled previously, now trigger dependencies as enabled.
  668. if (options.enabled || this.enabled) {
  669. //Enable this module and dependencies.
  670. //Will call this.check()
  671. this.enable();
  672. } else {
  673. this.check();
  674. }
  675. },
  676. defineDep : function(i,depExports) {
  677. //Because of cycles, defined callback for a given
  678. //export can be called more than once.
  679. if (!this.depMatched[i]) {
  680. this.depMatched[i] = true;
  681. this.depCount -= 1;
  682. this.depExports[i] = depExports;
  683. }
  684. },
  685. fetch : function() {
  686. if (this.fetched) {
  687. return;
  688. }
  689. this.fetched = true;
  690. context.startTime = (new Date()).getTime();
  691. var map = this.map;
  692. //If the manager is for a plugin managed resource,
  693. //ask the plugin to load it now.
  694. if (this.shim) {
  695. context.makeRequire(this.map, {
  696. enableBuildCallback : true
  697. })(this.shim.deps || [], bind(this, function() {
  698. return map.prefix ? this.callPlugin() : this.load();
  699. }));
  700. } else {
  701. //Regular dependency.
  702. return map.prefix ? this.callPlugin() : this.load();
  703. }
  704. },
  705. load : function() {
  706. var url = this.map.url;
  707. //Regular dependency.
  708. if (!urlFetched[url]) {
  709. urlFetched[url] = true;
  710. context.load(this.map.id, url);
  711. }
  712. },
  713. /**
  714. * Checks if the module is ready to define itself, and if so,
  715. * define it.
  716. */
  717. check : function() {
  718. if (!this.enabled || this.enabling) {
  719. return;
  720. }
  721. var err, cjsModule, id = this.map.id, depExports = this.depExports, exports = this.exports, factory = this.factory;
  722. if (!this.inited) {
  723. this.fetch();
  724. } else if (this.error) {
  725. this.emit('error', this.error);
  726. } else if (!this.defining) {
  727. //The factory could trigger another require call
  728. //that would result in checking this module to
  729. //define itself again. If already in the process
  730. //of doing that, skip this work.
  731. this.defining = true;
  732. if (this.depCount &lt; 1 &amp;&amp; !this.defined) {
  733. if (isFunction(factory)) {
  734. //If there is an error listener, favor passing
  735. //to that instead of throwing an error. However,
  736. //only do it for define()'d modules. require
  737. //errbacks should not be called for failures in
  738. //their callbacks (#699). However if a global
  739. //onError is set, use that.
  740. if ((this.events.error &amp;&amp; this.map.isDefine) || req.onError !== defaultOnError) {
  741. try {
  742. exports = context.execCb(id, factory, depExports, exports);
  743. } catch (e) {
  744. err = e;
  745. }
  746. } else {
  747. exports = context.execCb(id, factory, depExports, exports);
  748. }
  749. // Favor return value over exports. If node/cjs in play,
  750. // then will not have a return value anyway. Favor
  751. // module.exports assignment over exports object.
  752. if (this.map.isDefine &amp;&amp; exports === undefined) {
  753. cjsModule = this.module;
  754. if (cjsModule) {
  755. exports = cjsModule.exports;
  756. } else if (this.usingExports) {
  757. //exports already set the defined value.
  758. exports = this.exports;
  759. }
  760. }
  761. if (err) {
  762. err.requireMap = this.map;
  763. err.requireModules = this.map.isDefine ? [
  764. this.map.id
  765. ] : null;
  766. err.requireType = this.map.isDefine ? 'define' : 'require';
  767. return onError((this.error = err));
  768. }
  769. } else {
  770. //Just a literal value
  771. exports = factory;
  772. }
  773. this.exports = exports;
  774. if (this.map.isDefine &amp;&amp; !this.ignore) {
  775. defined[id] = exports;
  776. if (req.onResourceLoad) {
  777. req.onResourceLoad(context, this.map, this.depMaps);
  778. }
  779. }
  780. //Clean up
  781. cleanRegistry(id);
  782. this.defined = true;
  783. }
  784. //Finished the define stage. Allow calling check again
  785. //to allow define notifications below in the case of a
  786. //cycle.
  787. this.defining = false;
  788. if (this.defined &amp;&amp; !this.defineEmitted) {
  789. this.defineEmitted = true;
  790. this.emit('defined', this.exports);
  791. this.defineEmitComplete = true;
  792. }
  793. }
  794. },
  795. callPlugin : function() {
  796. var map = this.map, id = map.id,
  797. //Map already normalized the prefix.
  798. pluginMap = makeModuleMap(map.prefix);
  799. //Mark this as a dependency for this plugin, so it
  800. //can be traced for cycles.
  801. this.depMaps.push(pluginMap);
  802. on(pluginMap, 'defined', bind(this, function(plugin) {
  803. 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, {
  804. enableBuildCallback : true
  805. });
  806. //If current map is not normalized, wait for that
  807. //normalized name to load instead of continuing.
  808. if (this.map.unnormalized) {
  809. //Normalize the ID if the plugin allows it.
  810. if (plugin.normalize) {
  811. name = plugin.normalize(name, function(name) {
  812. return normalize(name, parentName, true);
  813. }) || '';
  814. }
  815. //prefix and name should already be normalized, no need
  816. //for applying map config again either.
  817. normalizedMap = makeModuleMap(map.prefix + '!' + name, this.map.parentMap);
  818. on(normalizedMap, 'defined', bind(this, function(value) {
  819. this.init([], function() {
  820. return value;
  821. }, null, {
  822. enabled : true,
  823. ignore : true
  824. });
  825. }));
  826. normalizedMod = getOwn(registry, normalizedMap.id);
  827. if (normalizedMod) {
  828. //Mark this as a dependency for this plugin, so it
  829. //can be traced for cycles.
  830. this.depMaps.push(normalizedMap);
  831. if (this.events.error) {
  832. normalizedMod.on('error', bind(this, function(err) {
  833. this.emit('error', err);
  834. }));
  835. }
  836. normalizedMod.enable();
  837. }
  838. return;
  839. }
  840. //If a paths config, then just load that file instead to
  841. //resolve the plugin, as it is built into that paths layer.
  842. if (bundleId) {
  843. this.map.url = context.nameToUrl(bundleId);
  844. this.load();
  845. return;
  846. }
  847. load = bind(this, function(value) {
  848. this.init([], function() {
  849. return value;
  850. }, null, {
  851. enabled : true
  852. });
  853. });
  854. load.error = bind(this, function(err) {
  855. this.inited = true;
  856. this.error = err;
  857. err.requireModules = [
  858. id
  859. ];
  860. //Remove temp unnormalized modules for this module,
  861. //since they will never be resolved otherwise now.
  862. eachProp(registry, function(mod) {
  863. if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
  864. cleanRegistry(mod.map.id);
  865. }
  866. });
  867. onError(err);
  868. });
  869. //Allow plugins to load other code without having to know the
  870. //context or how to 'complete' the load.
  871. load.fromText = bind(this, function(text,textAlt) {
  872. /*jslint evil: true */
  873. var moduleName = map.name, moduleMap = makeModuleMap(moduleName), hasInteractive = useInteractive;
  874. //As of 2.1.0, support just passing the text, to reinforce
  875. //fromText only being called once per resource. Still
  876. //support old style of passing moduleName but discard
  877. //that moduleName in favor of the internal ref.
  878. if (textAlt) {
  879. text = textAlt;
  880. }
  881. //Turn off interactive script matching for IE for any define
  882. //calls in the text, then turn it back on at the end.
  883. if (hasInteractive) {
  884. useInteractive = false;
  885. }
  886. //Prime the system by creating a module instance for
  887. //it.
  888. getModule(moduleMap);
  889. //Transfer any config to this other module.
  890. if (hasProp(config.config, id)) {
  891. config.config[moduleName] = config.config[id];
  892. }
  893. try {
  894. req.exec(text);
  895. } catch (e) {
  896. return onError(makeError('fromtexteval', 'fromText eval for ' + id + ' failed: ' + e, e, [
  897. id
  898. ]));
  899. }
  900. if (hasInteractive) {
  901. useInteractive = true;
  902. }
  903. //Mark this as a dependency for the plugin
  904. //resource
  905. this.depMaps.push(moduleMap);
  906. //Support anonymous modules.
  907. context.completeLoad(moduleName);
  908. //Bind the value of that module to the value for this
  909. //resource ID.
  910. localRequire([
  911. moduleName
  912. ], load);
  913. });
  914. //Use parentName here since the plugin's name is not reliable,
  915. //could be some weird string with no path that actually wants to
  916. //reference the parentName's path.
  917. plugin.load(map.name, localRequire, load, config);
  918. }));
  919. context.enable(pluginMap, this);
  920. this.pluginMaps[pluginMap.id] = pluginMap;
  921. },
  922. enable : function() {
  923. enabledRegistry[this.map.id] = this;
  924. this.enabled = true;
  925. //Set flag mentioning that the module is enabling,
  926. //so that immediate calls to the defined callbacks
  927. //for dependencies do not trigger inadvertent load
  928. //with the depCount still being zero.
  929. this.enabling = true;
  930. //Enable each dependency
  931. each(this.depMaps, bind(this, function(depMap,i) {
  932. var id, mod, handler;
  933. if (typeof depMap === 'string') {
  934. //Dependency needs to be converted to a depMap
  935. //and wired up to this module.
  936. depMap = makeModuleMap(depMap, (this.map.isDefine ? this.map : this.map.parentMap), false, !this.skipMap);
  937. this.depMaps[i] = depMap;
  938. handler = getOwn(handlers, depMap.id);
  939. if (handler) {
  940. this.depExports[i] = handler(this);
  941. return;
  942. }
  943. this.depCount += 1;
  944. on(depMap, 'defined', bind(this, function(depExports) {
  945. this.defineDep(i, depExports);
  946. this.check();
  947. }));
  948. if (this.errback) {
  949. on(depMap, 'error', bind(this, this.errback));
  950. }
  951. }
  952. id = depMap.id;
  953. mod = registry[id];
  954. //Skip special modules like 'require', 'exports', 'module'
  955. //Also, don't call enable if it is already enabled,
  956. //important in circular dependency cases.
  957. if (!hasProp(handlers, id) &amp;&amp; mod &amp;&amp; !mod.enabled) {
  958. context.enable(depMap, this);
  959. }
  960. }));
  961. //Enable each plugin that is used in
  962. //a dependency
  963. eachProp(this.pluginMaps, bind(this, function(pluginMap) {
  964. var mod = getOwn(registry, pluginMap.id);
  965. if (mod &amp;&amp; !mod.enabled) {
  966. context.enable(pluginMap, this);
  967. }
  968. }));
  969. this.enabling = false;
  970. this.check();
  971. },
  972. on : function(name,cb) {
  973. var cbs = this.events[name];
  974. if (!cbs) {
  975. cbs = this.events[name] = [];
  976. }
  977. cbs.push(cb);
  978. },
  979. emit : function(name,evt) {
  980. each(this.events[name], function(cb) {
  981. cb(evt);
  982. });
  983. if (name === 'error') {
  984. //Now that the error handler was triggered, remove
  985. //the listeners, since this broken Module instance
  986. //can stay around for a while in the registry.
  987. delete this.events[name];
  988. }
  989. }
  990. };
  991. function callGetModule(args) {
  992. //Skip modules already defined.
  993. if (!hasProp(defined, args[0])) {
  994. getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2]);
  995. }
  996. }
  997. function removeListener(node,func,name,ieName) {
  998. //Favor detachEvent because of IE9
  999. //issue, see attachEvent/addEventListener comment elsewhere
  1000. //in this file.
  1001. if (node.detachEvent &amp;&amp; !isOpera) {
  1002. //Probably IE. If not it will throw an error, which will be
  1003. //useful to know.
  1004. if (ieName) {
  1005. node.detachEvent(ieName, func);
  1006. }
  1007. } else {
  1008. node.removeEventListener(name, func, false);
  1009. }
  1010. }
  1011. /**
  1012. * Given an event from a script node, get the requirejs info from it,
  1013. * and then removes the event listeners on the node.
  1014. * @param {Event} evt
  1015. * @returns {Object}
  1016. */
  1017. function getScriptData(evt) {
  1018. //Using currentTarget instead of target for Firefox 2.0's sake. Not
  1019. //all old browsers will be supported, but this one was easy enough
  1020. //to support and still makes sense.
  1021. var node = evt.currentTarget || evt.srcElement;
  1022. //Remove the listeners once here.
  1023. removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange');
  1024. removeListener(node, context.onScriptError, 'error');
  1025. return {
  1026. node : node,
  1027. id : node &amp;&amp; node.getAttribute('data-requiremodule')
  1028. };
  1029. }
  1030. function intakeDefines() {
  1031. var args;
  1032. //Any defined modules in the global queue, intake them now.
  1033. takeGlobalQueue();
  1034. //Make sure any remaining defQueue items get properly processed.
  1035. while (defQueue.length) {
  1036. args = defQueue.shift();
  1037. if (args[0] === null) {
  1038. return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
  1039. } else {
  1040. //args are id, deps, factory. Should be normalized by the
  1041. //define() function.
  1042. callGetModule(args);
  1043. }
  1044. }
  1045. }
  1046. context = {
  1047. config : config,
  1048. contextName : contextName,
  1049. registry : registry,
  1050. defined : defined,
  1051. urlFetched : urlFetched,
  1052. defQueue : defQueue,
  1053. Module : Module,
  1054. makeModuleMap : makeModuleMap,
  1055. nextTick : req.nextTick,
  1056. onError : onError,
  1057. /**
  1058. * Set a configuration for the context.
  1059. * @param {Object} cfg config object to integrate.
  1060. */
  1061. configure : function(cfg) {
  1062. //Make sure the baseUrl ends in a slash.
  1063. if (cfg.baseUrl) {
  1064. if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') {
  1065. cfg.baseUrl += '/';
  1066. }
  1067. }
  1068. //Save off the paths since they require special processing,
  1069. //they are additive.
  1070. var shim = config.shim, objs = {
  1071. paths : true,
  1072. bundles : true,
  1073. config : true,
  1074. map : true
  1075. };
  1076. eachProp(cfg, function(value,prop) {
  1077. if (objs[prop]) {
  1078. if (!config[prop]) {
  1079. config[prop] = {};
  1080. }
  1081. mixin(config[prop], value, true, true);
  1082. } else {
  1083. config[prop] = value;
  1084. }
  1085. });
  1086. //Reverse map the bundles
  1087. if (cfg.bundles) {
  1088. eachProp(cfg.bundles, function(value,prop) {
  1089. each(value, function(v) {
  1090. if (v !== prop) {
  1091. bundlesMap[v] = prop;
  1092. }
  1093. });
  1094. });
  1095. }
  1096. //Merge shim
  1097. if (cfg.shim) {
  1098. eachProp(cfg.shim, function(value,id) {
  1099. //Normalize the structure
  1100. if (isArray(value)) {
  1101. value = {
  1102. deps : value
  1103. };
  1104. }
  1105. if ((value.exports || value.init) &amp;&amp; !value.exportsFn) {
  1106. value.exportsFn = context.makeShimExports(value);
  1107. }
  1108. shim[id] = value;
  1109. });
  1110. config.shim = shim;
  1111. }
  1112. //Adjust packages if necessary.
  1113. if (cfg.packages) {
  1114. each(cfg.packages, function(pkgObj) {
  1115. var location, name;
  1116. pkgObj = typeof pkgObj === 'string' ? {
  1117. name : pkgObj
  1118. } : pkgObj;
  1119. name = pkgObj.name;
  1120. location = pkgObj.location;
  1121. if (location) {
  1122. config.paths[name] = pkgObj.location;
  1123. }
  1124. //Save pointer to main module ID for pkg name.
  1125. //Remove leading dot in main, so main paths are normalized,
  1126. //and remove any trailing .js, since different package
  1127. //envs have different conventions: some use a module name,
  1128. //some use a file name.
  1129. config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main').replace(currDirRegExp, '').replace(jsSuffixRegExp, '');
  1130. });
  1131. }
  1132. //If there are any "waiting to execute" modules in the registry,
  1133. //update the maps for them, since their info, like URLs to load,
  1134. //may have changed.
  1135. eachProp(registry, function(mod,id) {
  1136. //If module already has init called, since it is too
  1137. //late to modify them, and ignore unnormalized ones
  1138. //since they are transient.
  1139. if (!mod.inited &amp;&amp; !mod.map.unnormalized) {
  1140. mod.map = makeModuleMap(id);
  1141. }
  1142. });
  1143. //If a deps array or a config callback is specified, then call
  1144. //require with those args. This is useful when require is defined as a
  1145. //config object before require.js is loaded.
  1146. if (cfg.deps || cfg.callback) {
  1147. context.require(cfg.deps || [], cfg.callback);
  1148. }
  1149. },
  1150. makeShimExports : function(value) {
  1151. function fn() {
  1152. var ret;
  1153. if (value.init) {
  1154. ret = value.init.apply(global, arguments);
  1155. }
  1156. return ret || (value.exports &amp;&amp; getGlobal(value.exports));
  1157. }
  1158. return fn;
  1159. },
  1160. makeRequire : function(relMap,options) {
  1161. options = options || {};
  1162. function localRequire(deps,callback,errback) {
  1163. var id, map, requireMod;
  1164. if (options.enableBuildCallback &amp;&amp; callback &amp;&amp; isFunction(callback)) {
  1165. callback.__requireJsBuild = true;
  1166. }
  1167. if (typeof deps === 'string') {
  1168. if (isFunction(callback)) {
  1169. //Invalid call
  1170. return onError(makeError('requireargs', 'Invalid require call'), errback);
  1171. }
  1172. //If require|exports|module are requested, get the
  1173. //value for them from the special handlers. Caveat:
  1174. //this only works while module is being defined.
  1175. if (relMap &amp;&amp; hasProp(handlers, deps)) {
  1176. return handlers[deps](registry[relMap.id]);
  1177. }
  1178. //Synchronous access to one module. If require.get is
  1179. //available (as in the Node adapter), prefer that.
  1180. if (req.get) {
  1181. return req.get(context, deps, relMap, localRequire);
  1182. }
  1183. //Normalize module name, if it contains . or ..
  1184. map = makeModuleMap(deps, relMap, false, true);
  1185. id = map.id;
  1186. if (!hasProp(defined, id)) {
  1187. return onError(makeError('notloaded', 'Module name "' + id + '" has not been loaded yet for context: ' + contextName + (relMap ? '' : '. Use require([])')));
  1188. }
  1189. return defined[id];
  1190. }
  1191. //Grab defines waiting in the global queue.
  1192. intakeDefines();
  1193. //Mark all the dependencies as needing to be loaded.
  1194. context.nextTick(function() {
  1195. //Some defines could have been added since the
  1196. //require call, collect them.
  1197. intakeDefines();
  1198. requireMod = getModule(makeModuleMap(null, relMap));
  1199. //Store if map config should be applied to this require
  1200. //call for dependencies.
  1201. requireMod.skipMap = options.skipMap;
  1202. requireMod.init(deps, callback, errback, {
  1203. enabled : true
  1204. });
  1205. checkLoaded();
  1206. });
  1207. return localRequire;
  1208. }
  1209. mixin(localRequire, {
  1210. isBrowser : isBrowser,
  1211. /**
  1212. * Converts a module name + .extension into an URL path.
  1213. * *Requires* the use of a module name. It does not support using
  1214. * plain URLs like nameToUrl.
  1215. */
  1216. toUrl : function(moduleNamePlusExt) {
  1217. var ext, index = moduleNamePlusExt.lastIndexOf('.'), segment = moduleNamePlusExt.split('/')[0], isRelative = segment === '.' || segment === '..';
  1218. //Have a file extension alias, and it is not the
  1219. //dots from a relative path.
  1220. if (index !== -1 &amp;&amp; (!isRelative || index > 1)) {
  1221. ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
  1222. moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
  1223. }
  1224. return context.nameToUrl(normalize(moduleNamePlusExt, relMap &amp;&amp; relMap.id, true), ext, true);
  1225. },
  1226. defined : function(id) {
  1227. return hasProp(defined, makeModuleMap(id, relMap, false, true).id);
  1228. },
  1229. specified : function(id) {
  1230. id = makeModuleMap(id, relMap, false, true).id;
  1231. return hasProp(defined, id) || hasProp(registry, id);
  1232. }
  1233. });
  1234. //Only allow undef on top level require calls
  1235. if (!relMap) {
  1236. localRequire.undef = function(id) {
  1237. //Bind any waiting define() calls to this context,
  1238. //fix for #408
  1239. takeGlobalQueue();
  1240. var map = makeModuleMap(id, relMap, true), mod = getOwn(registry, id);
  1241. removeScript(id);
  1242. delete defined[id];
  1243. delete urlFetched[map.url];
  1244. delete undefEvents[id];
  1245. //Clean queued defines too. Go backwards
  1246. //in array so that the splices do not
  1247. //mess up the iteration.
  1248. eachReverse(defQueue, function(args,i) {
  1249. if (args[0] === id) {
  1250. defQueue.splice(i, 1);
  1251. }
  1252. });
  1253. if (mod) {
  1254. //Hold on to listeners in case the
  1255. //module will be attempted to be reloaded
  1256. //using a different config.
  1257. if (mod.events.defined) {
  1258. undefEvents[id] = mod.events;
  1259. }
  1260. cleanRegistry(id);
  1261. }
  1262. };
  1263. }
  1264. return localRequire;
  1265. },
  1266. /**
  1267. * Called to enable a module if it is still in the registry
  1268. * awaiting enablement. A second arg, parent, the parent module,
  1269. * is passed in for context, when this method is overridden by
  1270. * the optimizer. Not shown here to keep code compact.
  1271. */
  1272. enable : function(depMap) {
  1273. var mod = getOwn(registry, depMap.id);
  1274. if (mod) {
  1275. getModule(depMap).enable();
  1276. }
  1277. },
  1278. /**
  1279. * Internal method used by environment adapters to complete a load event.
  1280. * A load event could be a script load or just a load pass from a synchronous
  1281. * load call.
  1282. * @param {String} moduleName the name of the module to potentially complete.
  1283. */
  1284. completeLoad : function(moduleName) {
  1285. var found, args, mod, shim = getOwn(config.shim, moduleName) || {}, shExports = shim.exports;
  1286. takeGlobalQueue();
  1287. while (defQueue.length) {
  1288. args = defQueue.shift();
  1289. if (args[0] === null) {
  1290. args[0] = moduleName;
  1291. //If already found an anonymous module and bound it
  1292. //to this name, then this is some other anon module
  1293. //waiting for its completeLoad to fire.
  1294. if (found) {
  1295. break;
  1296. }
  1297. found = true;
  1298. } else if (args[0] === moduleName) {
  1299. //Found matching define call for this script!
  1300. found = true;
  1301. }
  1302. callGetModule(args);
  1303. }
  1304. //Do this after the cycle of callGetModule in case the result
  1305. //of those calls/init calls changes the registry.
  1306. mod = getOwn(registry, moduleName);
  1307. if (!found &amp;&amp; !hasProp(defined, moduleName) &amp;&amp; mod &amp;&amp; !mod.inited) {
  1308. if (config.enforceDefine &amp;&amp; (!shExports || !getGlobal(shExports))) {
  1309. if (hasPathFallback(moduleName)) {
  1310. return;
  1311. } else {
  1312. return onError(makeError('nodefine', 'No define call for ' + moduleName, null, [
  1313. moduleName
  1314. ]));
  1315. }
  1316. } else {
  1317. //A script that does not call define(), so just simulate
  1318. //the call for it.
  1319. callGetModule([
  1320. moduleName, (shim.deps || []), shim.exportsFn
  1321. ]);
  1322. }
  1323. }
  1324. checkLoaded();
  1325. },
  1326. /**
  1327. * Converts a module name to a file path. Supports cases where
  1328. * moduleName may actually be just an URL.
  1329. * Note that it **does not** call normalize on the moduleName,
  1330. * it is assumed to have already been normalized. This is an
  1331. * internal API, not a public one. Use toUrl for the public API.
  1332. */
  1333. nameToUrl : function(moduleName,ext,skipExt) {
  1334. var paths, syms, i, parentModule, url, parentPath, bundleId, pkgMain = getOwn(config.pkgs, moduleName);
  1335. if (pkgMain) {
  1336. moduleName = pkgMain;
  1337. }
  1338. bundleId = getOwn(bundlesMap, moduleName);
  1339. if (bundleId) {
  1340. return context.nameToUrl(bundleId, ext, skipExt);
  1341. }
  1342. //If a colon is in the URL, it indicates a protocol is used and it is just
  1343. //an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
  1344. //or ends with .js, then assume the user meant to use an url and not a module id.
  1345. //The slash is important for protocol-less URLs as well as full paths.
  1346. if (req.jsExtRegExp.test(moduleName)) {
  1347. //Just a plain path, not module name lookup, so just return it.
  1348. //Add extension if it is included. This is a bit wonky, only non-.js things pass
  1349. //an extension, this method probably needs to be reworked.
  1350. url = moduleName + (ext || '');
  1351. } else {
  1352. //A module that needs to be converted to a path.
  1353. paths = config.paths;
  1354. syms = moduleName.split('/');
  1355. //For each module name segment, see if there is a path
  1356. //registered for it. Start with most specific name
  1357. //and work up from it.
  1358. for (i = syms.length; i > 0; i -= 1) {
  1359. parentModule = syms.slice(0, i).join('/');
  1360. parentPath = getOwn(paths, parentModule);
  1361. if (parentPath) {
  1362. //If an array, it means there are a few choices,
  1363. //Choose the one that is desired
  1364. if (isArray(parentPath)) {
  1365. parentPath = parentPath[0];
  1366. }
  1367. syms.splice(0, i, parentPath);
  1368. break;
  1369. }
  1370. }
  1371. //Join the path parts together, then figure out if baseUrl is needed.
  1372. url = syms.join('/');
  1373. url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js'));
  1374. url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
  1375. }
  1376. return config.urlArgs ? url + ((url.indexOf('?') === -1 ? '?' : '&amp;') + config.urlArgs) : url;
  1377. },
  1378. //Delegates to req.load. Broken out as a separate function to
  1379. //allow overriding in the optimizer.
  1380. load : function(id,url) {
  1381. req.load(context, id, url);
  1382. },
  1383. /**
  1384. * Executes a module callback function. Broken out as a separate function
  1385. * solely to allow the build system to sequence the files in the built
  1386. * layer in the right sequence.
  1387. *
  1388. * @private
  1389. */
  1390. execCb : function(name,callback,args,exports) {
  1391. return callback.apply(exports, args);
  1392. },
  1393. /**
  1394. * callback for script loads, used to check status of loading.
  1395. *
  1396. * @param {Event} evt the event from the browser for the script
  1397. * that was loaded.
  1398. */
  1399. onScriptLoad : function(evt) {
  1400. //Using currentTarget instead of target for Firefox 2.0's sake. Not
  1401. //all old browsers will be supported, but this one was easy enough
  1402. //to support and still makes sense.
  1403. if (evt.type === 'load' || (readyRegExp.test((evt.currentTarget || evt.srcElement).readyState))) {
  1404. //Reset interactive script so a script node is not held onto for
  1405. //to long.
  1406. interactiveScript = null;
  1407. //Pull out the name of the module and the context.
  1408. var data = getScriptData(evt);
  1409. context.completeLoad(data.id);
  1410. }
  1411. },
  1412. /**
  1413. * Callback for script errors.
  1414. */
  1415. onScriptError : function(evt) {
  1416. var data = getScriptData(evt);
  1417. if (!hasPathFallback(data.id)) {
  1418. return onError(makeError('scripterror', 'Script error for: ' + data.id, evt, [
  1419. data.id
  1420. ]));
  1421. }
  1422. }
  1423. };
  1424. context.require = context.makeRequire();
  1425. return context;
  1426. }
  1427. /**
  1428. * Main entry point.
  1429. *
  1430. * If the only argument to require is a string, then the module that
  1431. * is represented by that string is fetched for the appropriate context.
  1432. *
  1433. * If the first argument is an array, then it will be treated as an array
  1434. * of dependency string names to fetch. An optional function callback can
  1435. * be specified to execute when all of those dependencies are available.
  1436. *
  1437. * Make a local req variable to help Caja compliance (it assumes things
  1438. * on a require that are not standardized), and to give a short
  1439. * name for minification/local scope use.
  1440. */
  1441. req = requirejs = function(deps,callback,errback,optional) {
  1442. //Find the right context, use default
  1443. var context, config, contextName = defContextName;
  1444. // Determine if have config object in the call.
  1445. if (!isArray(deps) &amp;&amp; typeof deps !== 'string') {
  1446. // deps is a config object
  1447. config = deps;
  1448. if (isArray(callback)) {
  1449. // Adjust args if there are dependencies
  1450. deps = callback;
  1451. callback = errback;
  1452. errback = optional;
  1453. } else {
  1454. deps = [];
  1455. }
  1456. }
  1457. if (config &amp;&amp; config.context) {
  1458. contextName = config.context;
  1459. }
  1460. context = getOwn(contexts, contextName);
  1461. if (!context) {
  1462. context = contexts[contextName] = req.s.newContext(contextName);
  1463. }
  1464. if (config) {
  1465. context.configure(config);
  1466. }
  1467. return context.require(deps, callback, errback);
  1468. };
  1469. /**
  1470. * Support require.config() to make it easier to cooperate with other
  1471. * AMD loaders on globally agreed names.
  1472. */
  1473. req.config = function(config) {
  1474. return req(config);
  1475. };
  1476. /**
  1477. * Execute something after the current tick
  1478. * of the event loop. Override for other envs
  1479. * that have a better solution than setTimeout.
  1480. * @param {Function} fn function to execute later.
  1481. */
  1482. req.nextTick = typeof setTimeout !== 'undefined' ? function(fn) {
  1483. setTimeout(fn, 4);
  1484. } : function(fn) {
  1485. fn();
  1486. };
  1487. /**
  1488. * Export require as a global, but only if it does not already exist.
  1489. */
  1490. if (!require) {
  1491. require = req;
  1492. }
  1493. req.version = version;
  1494. //Used to filter out dependencies that are already paths.
  1495. req.jsExtRegExp = /^\/|:|\?|\.js$/;
  1496. req.isBrowser = isBrowser;
  1497. s = req.s = {
  1498. contexts : contexts,
  1499. newContext : newContext
  1500. };
  1501. //Create default context.
  1502. req({});
  1503. //Exports some context-sensitive methods on global require.
  1504. each([
  1505. 'toUrl', 'undef', 'defined', 'specified'
  1506. ], function(prop) {
  1507. //Reference from contexts instead of early binding to default context,
  1508. //so that during builds, the latest instance of the default context
  1509. //with its config gets used.
  1510. req[prop] = function() {
  1511. var ctx = contexts[defContextName];
  1512. return ctx.require[prop].apply(ctx, arguments);
  1513. };
  1514. });
  1515. if (isBrowser) {
  1516. head = s.head = document.getElementsByTagName('head')[0];
  1517. //If BASE tag is in play, using appendChild is a problem for IE6.
  1518. //When that browser dies, this can be removed. Details in this jQuery bug:
  1519. //http://dev.jquery.com/ticket/2709
  1520. baseElement = document.getElementsByTagName('base')[0];
  1521. if (baseElement) {
  1522. head = s.head = baseElement.parentNode;
  1523. }
  1524. }
  1525. /**
  1526. * Any errors that require explicitly generates will be passed to this
  1527. * function. Intercept/override it if you want custom error handling.
  1528. * @param {Error} err the error object.
  1529. */
  1530. req.onError = defaultOnError;
  1531. /**
  1532. * Creates the node for the load command. Only used in browser envs.
  1533. */
  1534. req.createNode = function(config,moduleName,url) {
  1535. var node = config.xhtml ? document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') : document.createElement('script');
  1536. node.type = config.scriptType || 'text/javascript';
  1537. node.charset = 'utf-8';
  1538. node.async = true;
  1539. return node;
  1540. };
  1541. /**
  1542. * Does the request to load a module for the browser case.
  1543. * Make this a separate function to allow other environments
  1544. * to override it.
  1545. *
  1546. * @param {Object} context the require context to find state.
  1547. * @param {String} moduleName the name of the module.
  1548. * @param {Object} url the URL to the module.
  1549. */
  1550. req.load = function(context,moduleName,url) {
  1551. var config = (context &amp;&amp; context.config) || {}, node;
  1552. if (isBrowser) {
  1553. //In the browser so use a script tag
  1554. node = req.createNode(config, moduleName, url);
  1555. node.setAttribute('data-requirecontext', context.contextName);
  1556. node.setAttribute('data-requiremodule', moduleName);
  1557. //Set up load listener. Test attachEvent first because IE9 has
  1558. //a subtle issue in its addEventListener and script onload firings
  1559. //that do not match the behavior of all other browsers with
  1560. //addEventListener support, which fire the onload event for a
  1561. //script right after the script execution. See:
  1562. //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
  1563. //UNFORTUNATELY Opera implements attachEvent but does not follow the script
  1564. //script execution mode.
  1565. if (node.attachEvent &amp;&amp;
  1566. //Check if node.attachEvent is artificially added by custom script or
  1567. //natively supported by browser
  1568. //read https://github.com/jrburke/requirejs/issues/187
  1569. //if we can NOT find [native code] then it must NOT natively supported.
  1570. //in IE8, node.attachEvent does not have toString()
  1571. //Note the test for "[native code" with no closing brace, see:
  1572. //https://github.com/jrburke/requirejs/issues/273
  1573. !(node.attachEvent.toString &amp;&amp; node.attachEvent.toString().indexOf('[native code') &lt; 0) &amp;&amp; !isOpera) {
  1574. //Probably IE. IE (at least 6-8) do not fire
  1575. //script onload right after executing the script, so
  1576. //we cannot tie the anonymous define call to a name.
  1577. //However, IE reports the script as being in 'interactive'
  1578. //readyState at the time of the define call.
  1579. useInteractive = true;
  1580. node.attachEvent('onreadystatechange', context.onScriptLoad);
  1581. //It would be great to add an error handler here to catch
  1582. //404s in IE9+. However, onreadystatechange will fire before
  1583. //the error handler, so that does not help. If addEventListener
  1584. //is used, then IE will fire error before load, but we cannot
  1585. //use that pathway given the connect.microsoft.com issue
  1586. //mentioned above about not doing the 'script execute,
  1587. //then fire the script load event listener before execute
  1588. //next script' that other browsers do.
  1589. //Best hope: IE10 fixes the issues,
  1590. //and then destroys all installs of IE 6-9.
  1591. //node.attachEvent('onerror', context.onScriptError);
  1592. } else {
  1593. node.addEventListener('load', context.onScriptLoad, false);
  1594. node.addEventListener('error', context.onScriptError, false);
  1595. }
  1596. node.src = url;
  1597. //For some cache cases in IE 6-8, the script executes before the end
  1598. //of the appendChild execution, so to tie an anonymous define
  1599. //call to the module name (which is stored on the node), hold on
  1600. //to a reference to this node, but clear after the DOM insertion.
  1601. currentlyAddingScript = node;
  1602. if (baseElement) {
  1603. head.insertBefore(node, baseElement);
  1604. } else {
  1605. head.appendChild(node);
  1606. }
  1607. currentlyAddingScript = null;
  1608. return node;
  1609. } else if (isWebWorker) {
  1610. try {
  1611. //In a web worker, use importScripts. This is not a very
  1612. //efficient use of importScripts, importScripts will block until
  1613. //its script is downloaded and evaluated. However, if web workers
  1614. //are in play, the expectation that a build has been done so that
  1615. //only one script needs to be loaded anyway. This may need to be
  1616. //reevaluated if other use cases become common.
  1617. importScripts(url);
  1618. //Account for anonymous modules
  1619. context.completeLoad(moduleName);
  1620. } catch (e) {
  1621. context.onError(makeError('importscripts', 'importScripts failed for ' + moduleName + ' at ' + url, e, [
  1622. moduleName
  1623. ]));
  1624. }
  1625. }
  1626. };
  1627. function getInteractiveScript() {
  1628. if (interactiveScript &amp;&amp; interactiveScript.readyState === 'interactive') {
  1629. return interactiveScript;
  1630. }
  1631. eachReverse(scripts(), function(script) {
  1632. if (script.readyState === 'interactive') {
  1633. return (interactiveScript = script);
  1634. }
  1635. });
  1636. return interactiveScript;
  1637. }
  1638. //Look for a data-main script attribute, which could also adjust the baseUrl.
  1639. if (isBrowser &amp;&amp; !cfg.skipDataMain) {
  1640. //Figure out baseUrl. Get it from the script tag with require.js in it.
  1641. eachReverse(scripts(), function(script) {
  1642. //Set the 'head' where we can append children by
  1643. //using the script's parent.
  1644. if (!head) {
  1645. head = script.parentNode;
  1646. }
  1647. //Look for a data-main attribute to set main script for the page
  1648. //to load. If it is there, the path to data main becomes the
  1649. //baseUrl, if it is not already set.
  1650. dataMain = script.getAttribute('data-main');
  1651. if (dataMain) {
  1652. //Preserve dataMain in case it is a path (i.e. contains '?')
  1653. mainScript = dataMain;
  1654. //Set final baseUrl if there is not already an explicit one.
  1655. if (!cfg.baseUrl) {
  1656. //Pull off the directory of data-main for use as the
  1657. //baseUrl.
  1658. src = mainScript.split('/');
  1659. mainScript = src.pop();
  1660. subPath = src.length ? src.join('/') + '/' : './';
  1661. cfg.baseUrl = subPath;
  1662. }
  1663. //Strip off any trailing .js since mainScript is now
  1664. //like a module name.
  1665. mainScript = mainScript.replace(jsSuffixRegExp, '');
  1666. //If mainScript is still a path, fall back to dataMain
  1667. if (req.jsExtRegExp.test(mainScript)) {
  1668. mainScript = dataMain;
  1669. }
  1670. //Put the data-main script in the files to load.
  1671. cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [
  1672. mainScript
  1673. ];
  1674. return true;
  1675. }
  1676. });
  1677. }
  1678. /**
  1679. * The function that handles definitions of modules. Differs from
  1680. * require() in that a string for the module should be the first argument,
  1681. * and the function to execute after dependencies are loaded should
  1682. * return a value to define the module corresponding to the first argument's
  1683. * name.
  1684. */
  1685. define = function(name,deps,callback) {
  1686. var node, context;
  1687. //Allow for anonymous modules
  1688. if (typeof name !== 'string') {
  1689. //Adjust args appropriately
  1690. callback = deps;
  1691. deps = name;
  1692. name = null;
  1693. }
  1694. //This module may not have dependencies
  1695. if (!isArray(deps)) {
  1696. callback = deps;
  1697. deps = null;
  1698. }
  1699. //If no name, and callback is a function, then figure out if it a
  1700. //CommonJS thing with dependencies.
  1701. if (!deps &amp;&amp; isFunction(callback)) {
  1702. deps = [];
  1703. //Remove comments from the callback string,
  1704. //look for require calls, and pull them into the dependencies,
  1705. //but only if there are function args.
  1706. if (callback.length) {
  1707. callback.toString().replace(commentRegExp, '').replace(cjsRequireRegExp, function(match,dep) {
  1708. deps.push(dep);
  1709. });
  1710. //May be a CommonJS thing even without require calls, but still
  1711. //could use exports, and module. Avoid doing exports and module
  1712. //work though if it just needs require.
  1713. //REQUIRES the function to expect the CommonJS variables in the
  1714. //order listed below.
  1715. deps = (callback.length === 1 ? [
  1716. 'require'
  1717. ] : [
  1718. 'require', 'exports', 'module'
  1719. ]).concat(deps);
  1720. }
  1721. }
  1722. //If in IE 6-8 and hit an anonymous define() call, do the interactive
  1723. //work.
  1724. if (useInteractive) {
  1725. node = currentlyAddingScript || getInteractiveScript();
  1726. if (node) {
  1727. if (!name) {
  1728. name = node.getAttribute('data-requiremodule');
  1729. }
  1730. context = contexts[node.getAttribute('data-requirecontext')];
  1731. }
  1732. }
  1733. //Always save off evaluating the def call until the script onload handler.
  1734. //This allows multiple modules to be in a file without prematurely
  1735. //tracing dependencies, and allows for anonymous module support,
  1736. //where the module name is not known until the script onload event
  1737. //occurs. If no context, use the global queue, and get it processed
  1738. //in the onscript load callback.
  1739. (context ? context.defQueue : globalDefQueue).push([
  1740. name, deps, callback
  1741. ]);
  1742. };
  1743. define.amd = {
  1744. jQuery : true
  1745. };
  1746. /**
  1747. * Executes the text. Normally just uses eval, but can be modified
  1748. * to use a better, environment-specific call. Only used for transpiling
  1749. * loader plugins, not for plain JS modules.
  1750. * @param {String} text the text to execute/evaluate.
  1751. */
  1752. req.exec = function(text) {
  1753. /*jslint evil: true */
  1754. return eval(text);
  1755. };
  1756. //Set up with config info.
  1757. req(cfg);
  1758. }(this));</code></pre>
  1759. </article>
  1760. </section>
  1761. </div>
  1762. <br class="clear">
  1763. <footer>
  1764. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.2</a> on Sat Oct 08 2016 21:42:26 GMT+0100 (BST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
  1765. </footer>
  1766. <script>prettyPrint();</script>
  1767. <script src="scripts/linenumber.js"></script>
  1768. </body>
  1769. </html>