kibana-sinatra 0.0.1

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