omf_web 0.9.1 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/README.md +8 -2
- data/doc/screenshot.png +0 -0
- data/example/{basic → NOT_WORKING/basic}/hello-world-wired.rb +0 -0
- data/example/{basic → NOT_WORKING/basic}/visualisation.yml +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/brooklynDemo.sq3 +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/brooklyn_gps.dat +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/brooklyn_server.rb +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/brooklyn_wimax.dat +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/sql_source.rb +0 -0
- data/example/{code → NOT_WORKING/code}/code_server.rb +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/data_sources/parse_log.rb +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/data_sources/pxe_slice-2012-06-02t02.25.00-04.00.log +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/progress_chart.yaml +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/progress_tab.yaml +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/progress_table.yaml +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/viz_server.rb +0 -0
- data/example/{gec12 → NOT_WORKING/gec12}/gec12-53.rb +0 -0
- data/example/{gec12 → NOT_WORKING/gec12}/gec12_demo.sq3 +0 -0
- data/example/{gec12 → NOT_WORKING/gec12}/gec12_demo_server.rb +0 -0
- data/example/{gec12 → NOT_WORKING/gec12}/visualization.rb +0 -0
- data/example/{incoming → NOT_WORKING/incoming}/ofpu_barchart_widget.yaml +0 -0
- data/example/{log → NOT_WORKING/log}/log_config.xml +0 -0
- data/example/{log → NOT_WORKING/log}/log_server.rb +0 -0
- data/example/{network → NOT_WORKING/network}/flow_tab.yaml +0 -0
- data/example/{network → NOT_WORKING/network}/network_server.rb +0 -0
- data/example/{text → NOT_WORKING/text}/test.md +0 -0
- data/example/{text → NOT_WORKING/text}/test.rb +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/downlink.yaml +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/power.yaml +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/snapshot.db +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/snapshot.sql +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/test.rb +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/uplink.yaml +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/viz_server.rb +0 -0
- data/example/demo/data_sources/mobile_network.rb +3 -0
- data/example/demo/data_sources/static_network.rb +54 -0
- data/example/demo/widgets/charts_tab.yaml +21 -16
- data/example/demo/widgets/linked_graphs_tab.yaml +95 -0
- data/example/demo/widgets/mobile_network_widget.yaml +1 -1
- data/example/demo/widgets/pie_chart_widget.yaml +1 -1
- data/lib/omf-web/config.ru +2 -2
- data/lib/omf-web/data_source_proxy.rb +81 -19
- data/lib/omf-web/rack/websocket_handler.rb +77 -23
- data/lib/omf-web/theme/abstract_page.rb +43 -26
- data/lib/omf-web/theme/bright/code_renderer.rb +1 -1
- data/lib/omf-web/theme/bright/page.rb +1 -0
- data/lib/omf-web/theme/bright/tabbed_renderer.rb +7 -0
- data/lib/omf-web/version.rb +7 -0
- data/lib/omf-web/widget/data_widget.rb +38 -46
- data/lib/omf-web/widget/layout/stacked_layout.rb +2 -1
- data/lib/omf-web/widget/layout/tabbed_layout.rb +1 -2
- data/{MARUKU-LICENSE → lib/omf-web/widget/text/maruku/MARUKU-LICENSE} +0 -0
- data/lib/{maruku → omf-web/widget/text/maruku}/helpers.rb +0 -0
- data/lib/{maruku → omf-web/widget/text/maruku}/input/parse_block.rb +0 -0
- data/lib/{maruku → omf-web/widget/text/maruku}/output/to_html.rb +26 -21
- data/lib/omf-web/widget/text/maruku.rb +5 -0
- data/omf_web.gemspec +2 -1
- data/share/htdocs/{js → UNUSED}/log/table.js +0 -0
- data/share/htdocs/{css → graph/css}/graph.css +0 -0
- data/share/htdocs/{image/graph → graph/img}/bar_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/donut_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/funnel.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/info.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/line_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/line_chart_fill.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/misc.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/overview.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/pie_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/scatter_plot.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/stacked_bar_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/stacked_line_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/table.png +0 -0
- data/share/htdocs/{js/graph → graph/js}/abstract_chart.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/abstract_nv_chart.js +8 -13
- data/share/htdocs/{js/graph → graph/js}/abstract_widget.js +9 -16
- data/share/htdocs/{js/graph → graph/js}/axis.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/barchart.js +2 -2
- data/share/htdocs/{js/graph → graph/js}/code_mirror.js +1 -5
- data/share/htdocs/{js/graph → graph/js}/discrete_bar_chart.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/histogram2.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/holt_winters_chart.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/line_chart3.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/line_chart_with_focus.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/map2.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/multi_barchart.js +1 -1
- data/share/htdocs/graph/js/network2.js +412 -0
- data/share/htdocs/{js/graph → graph/js}/pie_chart2.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/scatter_plot.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/table2.js +17 -20
- data/share/htdocs/js/data_source2.js +187 -60
- data/share/htdocs/js/require3.js +38 -57
- data/share/htdocs/theme/bright/css/bright.css +4 -4
- data/share/htdocs/vendor/jquery/jquery.js +9404 -0
- data/share/htdocs/vendor/osa/LICENSE.txt +11 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_arrow_green_left.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_arrow_yellow_right.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_awareness.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_camera-web.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_cloud.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_contract.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_database.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_desktop.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_desktop_imac.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-music.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-scanner.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-usb-wifi.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-usb.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-wireless-router.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_disposal.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_drive-harddisk.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_drive-optical.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_firewall.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_home.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_hub.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_iPhone.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_ics_drive.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_ics_plc.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_ics_thermometer.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_id_card.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_image-generic.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_laptop.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_lifecycle.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_lightning.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_media-flash.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_media-optical.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_media-tape.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_mobile_pda.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_padlock.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_printer.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_application.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_database.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_directory.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_distribution.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_file.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_gateway.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_identity.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_mail.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_media.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_monitor.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_proxy.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_terminal.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_web.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_site-branch.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_site-factory.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_site-head-office.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_site-neighbourhood.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_audit.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_black_hat.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue_security_specialist.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue_sysadmin.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue_tester.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue_tie.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_architect.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_business_manager.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_developer.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_operations.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_project_manager.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_service_manager.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_warning.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_large_group.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_users_blue_green.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_vpn.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_warning.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_wireless_network.svg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/.DS_Store +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/add_icon.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/alertbad_icon.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/alertgood_icon.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_disabled.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_disabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_enabled.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_enabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_enabled_hover.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_enabled_hover.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/bottom-bg.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_disabled.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_disabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_enabled.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_enabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_enabled_hover.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_enabled_hover.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/icon-remove.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/indicator.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/laptop.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/logo-bottom.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/nav-tab-arrow.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/norbit_big.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/norbit_clipart.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/progress_bar.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/right-bg.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_asc.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_asc_disabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_both.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_desc.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_desc_disabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/spinner.gif +0 -0
- data/share/htdocs/{svg → vendor/unknown/svg}/ap.svg +0 -0
- data/share/htdocs/{svg → vendor/unknown/svg}/router.svg +0 -0
- metadata +198 -216
- data/example/demo/widgets/dashboard_tab.yaml +0 -28
- data/example/demo/widgets/download_tab.yaml +0 -42
- data/example/demo/widgets/edit_tab.yaml +0 -20
- data/example/demo/widgets/generator_tab.yaml +0 -12
- data/lib/omf-oml/endpoint.rb +0 -175
- data/lib/omf-oml/indexed_table.rb +0 -57
- data/lib/omf-oml/network.rb +0 -413
- data/lib/omf-oml/oml_tuple.rb +0 -62
- data/lib/omf-oml/schema.rb +0 -191
- data/lib/omf-oml/sequel/sequel_server.rb +0 -412
- data/lib/omf-oml/sql_row.rb +0 -302
- data/lib/omf-oml/sql_source.rb +0 -131
- data/lib/omf-oml/table.rb +0 -131
- data/lib/omf-oml/tuple.rb +0 -97
- data/lib/omf_oml.rb +0 -4
- data/share/htdocs/css/coderay.css +0 -127
- data/share/htdocs/css/ie.css +0 -40
- data/share/htdocs/css/lightbox.css +0 -62
- data/share/htdocs/css/scaffold.css +0 -74
- data/share/htdocs/css/screen.css +0 -1313
- data/share/htdocs/css/search.css +0 -102
- data/share/htdocs/css/table.css +0 -538
- data/share/htdocs/css/table2.css +0 -191
- data/share/htdocs/css/welcome.css +0 -103
- data/share/htdocs/css/wfob.css +0 -171
- data/share/htdocs/css/wshow.css +0 -69
- data/share/htdocs/gec9_demo.html +0 -39
- data/share/htdocs/images +0 -1
- data/share/htdocs/js/graph/histogram.js +0 -229
- data/share/htdocs/js/graph/line_chart.js +0 -342
- data/share/htdocs/js/graph/line_chart2.js +0 -232
- data/share/htdocs/js/graph/line_chart_fc.js +0 -94
- data/share/htdocs/js/graph/map.js +0 -85
- data/share/htdocs/js/graph/network.js +0 -591
- data/share/htdocs/js/graph/network2.js +0 -318
- data/share/htdocs/js/graph/pie_chart.js +0 -130
- data/share/htdocs/js/graph/table.js +0 -94
- data/share/htdocs/js/require2.js +0 -1998
- data/share/htdocs/js/timelines.js +0 -101
- data/share/htdocs/stylesheet/grid.css +0 -31
data/share/htdocs/js/require2.js
DELETED
@@ -1,1998 +0,0 @@
|
|
1
|
-
/** vim: et:ts=4:sw=4:sts=4
|
2
|
-
* @license RequireJS 0.25.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
|
3
|
-
* Available via the MIT or new BSD license.
|
4
|
-
* see: http://github.com/jrburke/requirejs for details
|
5
|
-
*/
|
6
|
-
/*jslint strict: false, plusplus: false */
|
7
|
-
/*global window: false, navigator: false, document: false, importScripts: false,
|
8
|
-
jQuery: false, clearInterval: false, setInterval: false, self: false,
|
9
|
-
setTimeout: false, opera: false */
|
10
|
-
|
11
|
-
var requirejs, require, define;
|
12
|
-
(function () {
|
13
|
-
//Change this version number for each release.
|
14
|
-
var version = "0.25.0",
|
15
|
-
commentRegExp = /(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg,
|
16
|
-
cjsRequireRegExp = /require\(["']([^'"\s]+)["']\)/g,
|
17
|
-
currDirRegExp = /^\.\//,
|
18
|
-
jsSuffixRegExp = /\.js$/,
|
19
|
-
ostring = Object.prototype.toString,
|
20
|
-
ap = Array.prototype,
|
21
|
-
aps = ap.slice,
|
22
|
-
apsp = ap.splice,
|
23
|
-
isBrowser = !!(typeof window !== "undefined" && navigator && document),
|
24
|
-
isWebWorker = !isBrowser && typeof importScripts !== "undefined",
|
25
|
-
//PS3 indicates loaded and complete, but need to wait for complete
|
26
|
-
//specifically. Sequence is "loading", "loaded", execution,
|
27
|
-
// then "complete". The UA check is unfortunate, but not sure how
|
28
|
-
//to feature test w/o causing perf issues.
|
29
|
-
readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
|
30
|
-
/^complete$/ : /^(complete|loaded)$/,
|
31
|
-
defContextName = "_",
|
32
|
-
//Oh the tragedy, detecting opera. See the usage of isOpera for reason.
|
33
|
-
isOpera = typeof opera !== "undefined" && opera.toString() === "[object Opera]",
|
34
|
-
reqWaitIdPrefix = "_r@@",
|
35
|
-
empty = {},
|
36
|
-
contexts = {},
|
37
|
-
globalDefQueue = [],
|
38
|
-
interactiveScript = null,
|
39
|
-
isDone = false,
|
40
|
-
checkLoadedDepth = 0,
|
41
|
-
useInteractive = false,
|
42
|
-
req, cfg = {}, currentlyAddingScript, s, head, baseElement, scripts, script,
|
43
|
-
src, subPath, mainScript, dataMain, i, scrollIntervalId, setReadyState, ctx,
|
44
|
-
jQueryCheck, checkLoadedTimeoutId;
|
45
|
-
|
46
|
-
function isFunction(it) {
|
47
|
-
return ostring.call(it) === "[object Function]";
|
48
|
-
}
|
49
|
-
|
50
|
-
function isArray(it) {
|
51
|
-
return ostring.call(it) === "[object Array]";
|
52
|
-
}
|
53
|
-
|
54
|
-
/**
|
55
|
-
* Simple function to mix in properties from source into target,
|
56
|
-
* but only if target does not already have a property of the same name.
|
57
|
-
* This is not robust in IE for transferring methods that match
|
58
|
-
* Object.prototype names, but the uses of mixin here seem unlikely to
|
59
|
-
* trigger a problem related to that.
|
60
|
-
*/
|
61
|
-
function mixin(target, source, force) {
|
62
|
-
for (var prop in source) {
|
63
|
-
if (!(prop in empty) && (!(prop in target) || force)) {
|
64
|
-
target[prop] = source[prop];
|
65
|
-
}
|
66
|
-
}
|
67
|
-
return req;
|
68
|
-
}
|
69
|
-
|
70
|
-
/**
|
71
|
-
* Constructs an error with a pointer to an URL with more information.
|
72
|
-
* @param {String} id the error ID that maps to an ID on a web page.
|
73
|
-
* @param {String} message human readable error.
|
74
|
-
* @param {Error} [err] the original error, if there is one.
|
75
|
-
*
|
76
|
-
* @returns {Error}
|
77
|
-
*/
|
78
|
-
function makeError(id, msg, err) {
|
79
|
-
var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
|
80
|
-
if (err) {
|
81
|
-
e.originalError = err;
|
82
|
-
}
|
83
|
-
return e;
|
84
|
-
}
|
85
|
-
|
86
|
-
/**
|
87
|
-
* Used to set up package paths from a packagePaths or packages config object.
|
88
|
-
* @param {Object} pkgs the object to store the new package config
|
89
|
-
* @param {Array} currentPackages an array of packages to configure
|
90
|
-
* @param {String} [dir] a prefix dir to use.
|
91
|
-
*/
|
92
|
-
function configurePackageDir(pkgs, currentPackages, dir) {
|
93
|
-
var i, location, pkgObj;
|
94
|
-
|
95
|
-
for (i = 0; (pkgObj = currentPackages[i]); i++) {
|
96
|
-
pkgObj = typeof pkgObj === "string" ? { name: pkgObj } : pkgObj;
|
97
|
-
location = pkgObj.location;
|
98
|
-
|
99
|
-
//Add dir to the path, but avoid paths that start with a slash
|
100
|
-
//or have a colon (indicates a protocol)
|
101
|
-
if (dir && (!location || (location.indexOf("/") !== 0 && location.indexOf(":") === -1))) {
|
102
|
-
location = dir + "/" + (location || pkgObj.name);
|
103
|
-
}
|
104
|
-
|
105
|
-
//Create a brand new object on pkgs, since currentPackages can
|
106
|
-
//be passed in again, and config.pkgs is the internal transformed
|
107
|
-
//state for all package configs.
|
108
|
-
pkgs[pkgObj.name] = {
|
109
|
-
name: pkgObj.name,
|
110
|
-
location: location || pkgObj.name,
|
111
|
-
//Remove leading dot in main, so main paths are normalized,
|
112
|
-
//and remove any trailing .js, since different package
|
113
|
-
//envs have different conventions: some use a module name,
|
114
|
-
//some use a file name.
|
115
|
-
main: (pkgObj.main || "main")
|
116
|
-
.replace(currDirRegExp, '')
|
117
|
-
.replace(jsSuffixRegExp, '')
|
118
|
-
};
|
119
|
-
}
|
120
|
-
}
|
121
|
-
|
122
|
-
/**
|
123
|
-
* jQuery 1.4.3-1.5.x use a readyWait/ready() pairing to hold DOM
|
124
|
-
* ready callbacks, but jQuery 1.6 supports a holdReady() API instead.
|
125
|
-
* At some point remove the readyWait/ready() support and just stick
|
126
|
-
* with using holdReady.
|
127
|
-
*/
|
128
|
-
function jQueryHoldReady($, shouldHold) {
|
129
|
-
if ($.holdReady) {
|
130
|
-
$.holdReady(shouldHold);
|
131
|
-
} else if (shouldHold) {
|
132
|
-
$.readyWait += 1;
|
133
|
-
} else {
|
134
|
-
$.ready(true);
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
if (typeof define !== "undefined") {
|
139
|
-
//If a define is already in play via another AMD loader,
|
140
|
-
//do not overwrite.
|
141
|
-
return;
|
142
|
-
}
|
143
|
-
|
144
|
-
if (typeof requirejs !== "undefined") {
|
145
|
-
if (isFunction(requirejs)) {
|
146
|
-
//Do not overwrite and existing requirejs instance.
|
147
|
-
return;
|
148
|
-
} else {
|
149
|
-
cfg = requirejs;
|
150
|
-
requirejs = undefined;
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
//Allow for a require config object
|
155
|
-
if (typeof require !== "undefined" && !isFunction(require)) {
|
156
|
-
//assume it is a config object.
|
157
|
-
cfg = require;
|
158
|
-
require = undefined;
|
159
|
-
}
|
160
|
-
|
161
|
-
/**
|
162
|
-
* Creates a new context for use in require and define calls.
|
163
|
-
* Handle most of the heavy lifting. Do not want to use an object
|
164
|
-
* with prototype here to avoid using "this" in require, in case it
|
165
|
-
* needs to be used in more super secure envs that do not want this.
|
166
|
-
* Also there should not be that many contexts in the page. Usually just
|
167
|
-
* one for the default context, but could be extra for multiversion cases
|
168
|
-
* or if a package needs a special context for a dependency that conflicts
|
169
|
-
* with the standard context.
|
170
|
-
*/
|
171
|
-
function newContext(contextName) {
|
172
|
-
var context, resume,
|
173
|
-
config = {
|
174
|
-
waitSeconds: 7,
|
175
|
-
baseUrl: s.baseUrl || "./",
|
176
|
-
paths: {},
|
177
|
-
pkgs: {}
|
178
|
-
},
|
179
|
-
defQueue = [],
|
180
|
-
specified = {
|
181
|
-
"require": true,
|
182
|
-
"exports": true,
|
183
|
-
"module": true
|
184
|
-
},
|
185
|
-
urlMap = {},
|
186
|
-
defined = {},
|
187
|
-
loaded = {},
|
188
|
-
waiting = {},
|
189
|
-
waitAry = [],
|
190
|
-
waitIdCounter = 0,
|
191
|
-
managerCallbacks = {},
|
192
|
-
plugins = {},
|
193
|
-
pluginsQueue = {},
|
194
|
-
resumeDepth = 0,
|
195
|
-
normalizedWaiting = {};
|
196
|
-
|
197
|
-
/**
|
198
|
-
* Trims the . and .. from an array of path segments.
|
199
|
-
* It will keep a leading path segment if a .. will become
|
200
|
-
* the first path segment, to help with module name lookups,
|
201
|
-
* which act like paths, but can be remapped. But the end result,
|
202
|
-
* all paths that use this function should look normalized.
|
203
|
-
* NOTE: this method MODIFIES the input array.
|
204
|
-
* @param {Array} ary the array of path segments.
|
205
|
-
*/
|
206
|
-
function trimDots(ary) {
|
207
|
-
var i, part;
|
208
|
-
for (i = 0; (part = ary[i]); i++) {
|
209
|
-
if (part === ".") {
|
210
|
-
ary.splice(i, 1);
|
211
|
-
i -= 1;
|
212
|
-
} else if (part === "..") {
|
213
|
-
if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
|
214
|
-
//End of the line. Keep at least one non-dot
|
215
|
-
//path segment at the front so it can be mapped
|
216
|
-
//correctly to disk. Otherwise, there is likely
|
217
|
-
//no path mapping for a path starting with '..'.
|
218
|
-
//This can still fail, but catches the most reasonable
|
219
|
-
//uses of ..
|
220
|
-
break;
|
221
|
-
} else if (i > 0) {
|
222
|
-
ary.splice(i - 1, 2);
|
223
|
-
i -= 2;
|
224
|
-
}
|
225
|
-
}
|
226
|
-
}
|
227
|
-
}
|
228
|
-
|
229
|
-
/**
|
230
|
-
* Given a relative module name, like ./something, normalize it to
|
231
|
-
* a real name that can be mapped to a path.
|
232
|
-
* @param {String} name the relative name
|
233
|
-
* @param {String} baseName a real name that the name arg is relative
|
234
|
-
* to.
|
235
|
-
* @returns {String} normalized name
|
236
|
-
*/
|
237
|
-
function normalize(name, baseName) {
|
238
|
-
var pkgName, pkgConfig;
|
239
|
-
|
240
|
-
//Adjust any relative paths.
|
241
|
-
if (name.charAt(0) === ".") {
|
242
|
-
//If have a base name, try to normalize against it,
|
243
|
-
//otherwise, assume it is a top-level require that will
|
244
|
-
//be relative to baseUrl in the end.
|
245
|
-
if (baseName) {
|
246
|
-
if (config.pkgs[baseName]) {
|
247
|
-
//If the baseName is a package name, then just treat it as one
|
248
|
-
//name to concat the name with.
|
249
|
-
baseName = [baseName];
|
250
|
-
} else {
|
251
|
-
//Convert baseName to array, and lop off the last part,
|
252
|
-
//so that . matches that "directory" and not name of the baseName's
|
253
|
-
//module. For instance, baseName of "one/two/three", maps to
|
254
|
-
//"one/two/three.js", but we want the directory, "one/two" for
|
255
|
-
//this normalization.
|
256
|
-
baseName = baseName.split("/");
|
257
|
-
baseName = baseName.slice(0, baseName.length - 1);
|
258
|
-
}
|
259
|
-
|
260
|
-
name = baseName.concat(name.split("/"));
|
261
|
-
trimDots(name);
|
262
|
-
|
263
|
-
//Some use of packages may use a . path to reference the
|
264
|
-
//"main" module name, so normalize for that.
|
265
|
-
pkgConfig = config.pkgs[(pkgName = name[0])];
|
266
|
-
name = name.join("/");
|
267
|
-
if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
|
268
|
-
name = pkgName;
|
269
|
-
}
|
270
|
-
}
|
271
|
-
}
|
272
|
-
return name;
|
273
|
-
}
|
274
|
-
|
275
|
-
/**
|
276
|
-
* Creates a module mapping that includes plugin prefix, module
|
277
|
-
* name, and path. If parentModuleMap is provided it will
|
278
|
-
* also normalize the name via require.normalize()
|
279
|
-
*
|
280
|
-
* @param {String} name the module name
|
281
|
-
* @param {String} [parentModuleMap] parent module map
|
282
|
-
* for the module name, used to resolve relative names.
|
283
|
-
*
|
284
|
-
* @returns {Object}
|
285
|
-
*/
|
286
|
-
function makeModuleMap(name, parentModuleMap) {
|
287
|
-
var index = name ? name.indexOf("!") : -1,
|
288
|
-
prefix = null,
|
289
|
-
parentName = parentModuleMap ? parentModuleMap.name : null,
|
290
|
-
originalName = name,
|
291
|
-
normalizedName, url, pluginModule;
|
292
|
-
|
293
|
-
if (index !== -1) {
|
294
|
-
prefix = name.substring(0, index);
|
295
|
-
name = name.substring(index + 1, name.length);
|
296
|
-
}
|
297
|
-
|
298
|
-
if (prefix) {
|
299
|
-
prefix = normalize(prefix, parentName);
|
300
|
-
}
|
301
|
-
|
302
|
-
//Account for relative paths if there is a base name.
|
303
|
-
if (name) {
|
304
|
-
if (prefix) {
|
305
|
-
pluginModule = defined[prefix];
|
306
|
-
if (pluginModule) {
|
307
|
-
//Plugin is loaded, use its normalize method, otherwise,
|
308
|
-
//normalize name as usual.
|
309
|
-
if (pluginModule.normalize) {
|
310
|
-
normalizedName = pluginModule.normalize(name, function (name) {
|
311
|
-
return normalize(name, parentName);
|
312
|
-
});
|
313
|
-
} else {
|
314
|
-
normalizedName = normalize(name, parentName);
|
315
|
-
}
|
316
|
-
} else {
|
317
|
-
//Plugin is not loaded yet, so do not normalize
|
318
|
-
//the name, wait for plugin to load to see if
|
319
|
-
//it has a normalize method. To avoid possible
|
320
|
-
//ambiguity with relative names loaded from another
|
321
|
-
//plugin, use the parent's name as part of this name.
|
322
|
-
normalizedName = '__$p' + parentName + '@' + name;
|
323
|
-
}
|
324
|
-
} else {
|
325
|
-
normalizedName = normalize(name, parentName);
|
326
|
-
}
|
327
|
-
|
328
|
-
url = urlMap[normalizedName];
|
329
|
-
if (!url) {
|
330
|
-
//Calculate url for the module, if it has a name.
|
331
|
-
if (req.toModuleUrl) {
|
332
|
-
//Special logic required for a particular engine,
|
333
|
-
//like Node.
|
334
|
-
url = req.toModuleUrl(context, normalizedName, parentModuleMap);
|
335
|
-
} else {
|
336
|
-
url = context.nameToUrl(normalizedName, null, parentModuleMap);
|
337
|
-
}
|
338
|
-
|
339
|
-
//Store the URL mapping for later.
|
340
|
-
urlMap[normalizedName] = url;
|
341
|
-
}
|
342
|
-
}
|
343
|
-
|
344
|
-
return {
|
345
|
-
prefix: prefix,
|
346
|
-
name: normalizedName,
|
347
|
-
parentMap: parentModuleMap,
|
348
|
-
url: url,
|
349
|
-
originalName: originalName,
|
350
|
-
fullName: prefix ? prefix + "!" + normalizedName : normalizedName
|
351
|
-
};
|
352
|
-
}
|
353
|
-
|
354
|
-
/**
|
355
|
-
* Determine if priority loading is done. If so clear the priorityWait
|
356
|
-
*/
|
357
|
-
function isPriorityDone() {
|
358
|
-
var priorityDone = true,
|
359
|
-
priorityWait = config.priorityWait,
|
360
|
-
priorityName, i;
|
361
|
-
if (priorityWait) {
|
362
|
-
for (i = 0; (priorityName = priorityWait[i]); i++) {
|
363
|
-
if (!loaded[priorityName]) {
|
364
|
-
priorityDone = false;
|
365
|
-
break;
|
366
|
-
}
|
367
|
-
}
|
368
|
-
if (priorityDone) {
|
369
|
-
delete config.priorityWait;
|
370
|
-
}
|
371
|
-
}
|
372
|
-
return priorityDone;
|
373
|
-
}
|
374
|
-
|
375
|
-
/**
|
376
|
-
* Helper function that creates a setExports function for a "module"
|
377
|
-
* CommonJS dependency. Do this here to avoid creating a closure that
|
378
|
-
* is part of a loop.
|
379
|
-
*/
|
380
|
-
function makeSetExports(moduleObj) {
|
381
|
-
return function (exports) {
|
382
|
-
moduleObj.exports = exports;
|
383
|
-
};
|
384
|
-
}
|
385
|
-
|
386
|
-
function makeContextModuleFunc(func, relModuleMap, enableBuildCallback) {
|
387
|
-
return function () {
|
388
|
-
//A version of a require function that passes a moduleName
|
389
|
-
//value for items that may need to
|
390
|
-
//look up paths relative to the moduleName
|
391
|
-
var args = [].concat(aps.call(arguments, 0)), lastArg;
|
392
|
-
if (enableBuildCallback &&
|
393
|
-
isFunction((lastArg = args[args.length - 1]))) {
|
394
|
-
lastArg.__requireJsBuild = true;
|
395
|
-
}
|
396
|
-
args.push(relModuleMap);
|
397
|
-
return func.apply(null, args);
|
398
|
-
};
|
399
|
-
}
|
400
|
-
|
401
|
-
/**
|
402
|
-
* Helper function that creates a require function object to give to
|
403
|
-
* modules that ask for it as a dependency. It needs to be specific
|
404
|
-
* per module because of the implication of path mappings that may
|
405
|
-
* need to be relative to the module name.
|
406
|
-
*/
|
407
|
-
function makeRequire(relModuleMap, enableBuildCallback) {
|
408
|
-
var modRequire = makeContextModuleFunc(context.require, relModuleMap, enableBuildCallback);
|
409
|
-
|
410
|
-
mixin(modRequire, {
|
411
|
-
nameToUrl: makeContextModuleFunc(context.nameToUrl, relModuleMap),
|
412
|
-
toUrl: makeContextModuleFunc(context.toUrl, relModuleMap),
|
413
|
-
defined: makeContextModuleFunc(context.requireDefined, relModuleMap),
|
414
|
-
specified: makeContextModuleFunc(context.requireSpecified, relModuleMap),
|
415
|
-
ready: req.ready,
|
416
|
-
isBrowser: req.isBrowser
|
417
|
-
});
|
418
|
-
//Something used by node.
|
419
|
-
if (req.paths) {
|
420
|
-
modRequire.paths = req.paths;
|
421
|
-
}
|
422
|
-
return modRequire;
|
423
|
-
}
|
424
|
-
|
425
|
-
/**
|
426
|
-
* Used to update the normalized name for plugin-based dependencies
|
427
|
-
* after a plugin loads, since it can have its own normalization structure.
|
428
|
-
* @param {String} pluginName the normalized plugin module name.
|
429
|
-
*/
|
430
|
-
function updateNormalizedNames(pluginName) {
|
431
|
-
|
432
|
-
var oldFullName, oldModuleMap, moduleMap, fullName, callbacks,
|
433
|
-
i, j, k, depArray, existingCallbacks,
|
434
|
-
maps = normalizedWaiting[pluginName];
|
435
|
-
|
436
|
-
if (maps) {
|
437
|
-
for (i = 0; (oldModuleMap = maps[i]); i++) {
|
438
|
-
oldFullName = oldModuleMap.fullName;
|
439
|
-
moduleMap = makeModuleMap(oldModuleMap.originalName, oldModuleMap.parentMap);
|
440
|
-
fullName = moduleMap.fullName;
|
441
|
-
//Callbacks could be undefined if the same plugin!name was
|
442
|
-
//required twice in a row, so use empty array in that case.
|
443
|
-
callbacks = managerCallbacks[oldFullName] || [];
|
444
|
-
existingCallbacks = managerCallbacks[fullName];
|
445
|
-
|
446
|
-
if (fullName !== oldFullName) {
|
447
|
-
//Update the specified object, but only if it is already
|
448
|
-
//in there. In sync environments, it may not be yet.
|
449
|
-
if (oldFullName in specified) {
|
450
|
-
delete specified[oldFullName];
|
451
|
-
specified[fullName] = true;
|
452
|
-
}
|
453
|
-
|
454
|
-
//Update managerCallbacks to use the correct normalized name.
|
455
|
-
//If there are already callbacks for the normalized name,
|
456
|
-
//just add to them.
|
457
|
-
if (existingCallbacks) {
|
458
|
-
managerCallbacks[fullName] = existingCallbacks.concat(callbacks);
|
459
|
-
} else {
|
460
|
-
managerCallbacks[fullName] = callbacks;
|
461
|
-
}
|
462
|
-
delete managerCallbacks[oldFullName];
|
463
|
-
|
464
|
-
//In each manager callback, update the normalized name in the depArray.
|
465
|
-
for (j = 0; j < callbacks.length; j++) {
|
466
|
-
depArray = callbacks[j].depArray;
|
467
|
-
for (k = 0; k < depArray.length; k++) {
|
468
|
-
if (depArray[k] === oldFullName) {
|
469
|
-
depArray[k] = fullName;
|
470
|
-
}
|
471
|
-
}
|
472
|
-
}
|
473
|
-
}
|
474
|
-
}
|
475
|
-
}
|
476
|
-
|
477
|
-
delete normalizedWaiting[pluginName];
|
478
|
-
}
|
479
|
-
|
480
|
-
/*
|
481
|
-
* Queues a dependency for checking after the loader is out of a
|
482
|
-
* "paused" state, for example while a script file is being loaded
|
483
|
-
* in the browser, where it may have many modules defined in it.
|
484
|
-
*
|
485
|
-
* depName will be fully qualified, no relative . or .. path.
|
486
|
-
*/
|
487
|
-
function queueDependency(dep) {
|
488
|
-
//Make sure to load any plugin and associate the dependency
|
489
|
-
//with that plugin.
|
490
|
-
var prefix = dep.prefix,
|
491
|
-
fullName = dep.fullName;
|
492
|
-
|
493
|
-
//Do not bother if the depName is already in transit
|
494
|
-
if (specified[fullName] || fullName in defined) {
|
495
|
-
return;
|
496
|
-
}
|
497
|
-
|
498
|
-
if (prefix && !plugins[prefix]) {
|
499
|
-
//Queue up loading of the dependency, track it
|
500
|
-
//via context.plugins. Mark it as a plugin so
|
501
|
-
//that the build system will know to treat it
|
502
|
-
//special.
|
503
|
-
plugins[prefix] = undefined;
|
504
|
-
|
505
|
-
//Remember this dep that needs to have normaliztion done
|
506
|
-
//after the plugin loads.
|
507
|
-
(normalizedWaiting[prefix] || (normalizedWaiting[prefix] = []))
|
508
|
-
.push(dep);
|
509
|
-
|
510
|
-
//Register an action to do once the plugin loads, to update
|
511
|
-
//all managerCallbacks to use a properly normalized module
|
512
|
-
//name.
|
513
|
-
(managerCallbacks[prefix] ||
|
514
|
-
(managerCallbacks[prefix] = [])).push({
|
515
|
-
onDep: function (name, value) {
|
516
|
-
if (name === prefix) {
|
517
|
-
updateNormalizedNames(prefix);
|
518
|
-
}
|
519
|
-
}
|
520
|
-
});
|
521
|
-
|
522
|
-
queueDependency(makeModuleMap(prefix));
|
523
|
-
}
|
524
|
-
|
525
|
-
context.paused.push(dep);
|
526
|
-
}
|
527
|
-
|
528
|
-
function execManager(manager) {
|
529
|
-
var i, ret, waitingCallbacks, err,
|
530
|
-
cb = manager.callback,
|
531
|
-
fullName = manager.fullName,
|
532
|
-
args = [],
|
533
|
-
ary = manager.depArray;
|
534
|
-
|
535
|
-
//Call the callback to define the module, if necessary.
|
536
|
-
if (cb && isFunction(cb)) {
|
537
|
-
//Pull out the defined dependencies and pass the ordered
|
538
|
-
//values to the callback.
|
539
|
-
if (ary) {
|
540
|
-
for (i = 0; i < ary.length; i++) {
|
541
|
-
args.push(manager.deps[ary[i]]);
|
542
|
-
}
|
543
|
-
}
|
544
|
-
|
545
|
-
try {
|
546
|
-
ret = req.execCb(fullName, manager.callback, args, defined[fullName]);
|
547
|
-
} catch (e) {
|
548
|
-
err = e;
|
549
|
-
}
|
550
|
-
|
551
|
-
if (fullName) {
|
552
|
-
//If setting exports via "module" is in play,
|
553
|
-
//favor that over return value and exports. After that,
|
554
|
-
//favor a non-undefined return value over exports use.
|
555
|
-
if (manager.cjsModule && manager.cjsModule.exports !== undefined) {
|
556
|
-
ret = defined[fullName] = manager.cjsModule.exports;
|
557
|
-
} else if (ret === undefined && manager.usingExports) {
|
558
|
-
//exports already set the defined value.
|
559
|
-
ret = defined[fullName];
|
560
|
-
} else {
|
561
|
-
//Use the return value from the function.
|
562
|
-
defined[fullName] = ret;
|
563
|
-
}
|
564
|
-
}
|
565
|
-
} else if (fullName) {
|
566
|
-
//May just be an object definition for the module. Only
|
567
|
-
//worry about defining if have a module name.
|
568
|
-
ret = defined[fullName] = cb;
|
569
|
-
}
|
570
|
-
|
571
|
-
//Clean up waiting. Do this before error calls, and before
|
572
|
-
//calling back waitingCallbacks, so that bookkeeping is correct
|
573
|
-
//in the event of an error and error is reported in correct order,
|
574
|
-
//since the waitingCallbacks will likely have errors if the
|
575
|
-
//onError function does not throw.
|
576
|
-
if (waiting[manager.waitId]) {
|
577
|
-
delete waiting[manager.waitId];
|
578
|
-
manager.isDone = true;
|
579
|
-
context.waitCount -= 1;
|
580
|
-
if (context.waitCount === 0) {
|
581
|
-
//Clear the wait array used for cycles.
|
582
|
-
waitAry = [];
|
583
|
-
}
|
584
|
-
}
|
585
|
-
|
586
|
-
if (err) {
|
587
|
-
err = makeError('defineerror', 'Error evaluating ' +
|
588
|
-
'module "' + fullName + '" at location "' +
|
589
|
-
(fullName ? makeModuleMap(fullName).url : '') + '":\n' +
|
590
|
-
err + '\nfileName:' + (err.fileName || err.sourceURL) +
|
591
|
-
'\nlineNumber: ' + (err.lineNumber || err.line), err);
|
592
|
-
err.moduleName = fullName;
|
593
|
-
return req.onError(err);
|
594
|
-
}
|
595
|
-
|
596
|
-
if (fullName) {
|
597
|
-
//If anything was waiting for this module to be defined,
|
598
|
-
//notify them now.
|
599
|
-
waitingCallbacks = managerCallbacks[fullName];
|
600
|
-
if (waitingCallbacks) {
|
601
|
-
for (i = 0; i < waitingCallbacks.length; i++) {
|
602
|
-
waitingCallbacks[i].onDep(fullName, ret);
|
603
|
-
}
|
604
|
-
delete managerCallbacks[fullName];
|
605
|
-
}
|
606
|
-
}
|
607
|
-
|
608
|
-
return undefined;
|
609
|
-
}
|
610
|
-
|
611
|
-
function main(inName, depArray, callback, relModuleMap) {
|
612
|
-
var moduleMap = makeModuleMap(inName, relModuleMap),
|
613
|
-
name = moduleMap.name,
|
614
|
-
fullName = moduleMap.fullName,
|
615
|
-
uniques = {},
|
616
|
-
manager = {
|
617
|
-
//Use a wait ID because some entries are anon
|
618
|
-
//async require calls.
|
619
|
-
waitId: name || reqWaitIdPrefix + (waitIdCounter++),
|
620
|
-
depCount: 0,
|
621
|
-
depMax: 0,
|
622
|
-
prefix: moduleMap.prefix,
|
623
|
-
name: name,
|
624
|
-
fullName: fullName,
|
625
|
-
deps: {},
|
626
|
-
depArray: depArray,
|
627
|
-
callback: callback,
|
628
|
-
onDep: function (depName, value) {
|
629
|
-
if (!(depName in manager.deps)) {
|
630
|
-
manager.deps[depName] = value;
|
631
|
-
manager.depCount += 1;
|
632
|
-
if (manager.depCount === manager.depMax) {
|
633
|
-
//All done, execute!
|
634
|
-
execManager(manager);
|
635
|
-
}
|
636
|
-
}
|
637
|
-
}
|
638
|
-
},
|
639
|
-
i, depArg, depName, cjsMod;
|
640
|
-
|
641
|
-
if (fullName) {
|
642
|
-
//If module already defined for context, or already loaded,
|
643
|
-
//then leave. Also leave if jQuery is registering but it does
|
644
|
-
//not match the desired version number in the config.
|
645
|
-
if (fullName in defined || loaded[fullName] === true ||
|
646
|
-
(fullName === "jquery" && config.jQuery &&
|
647
|
-
config.jQuery !== callback().fn.jquery)) {
|
648
|
-
return;
|
649
|
-
}
|
650
|
-
|
651
|
-
//Set specified/loaded here for modules that are also loaded
|
652
|
-
//as part of a layer, where onScriptLoad is not fired
|
653
|
-
//for those cases. Do this after the inline define and
|
654
|
-
//dependency tracing is done.
|
655
|
-
specified[fullName] = true;
|
656
|
-
loaded[fullName] = true;
|
657
|
-
|
658
|
-
//If module is jQuery set up delaying its dom ready listeners.
|
659
|
-
if (fullName === "jquery" && callback) {
|
660
|
-
jQueryCheck(callback());
|
661
|
-
}
|
662
|
-
}
|
663
|
-
|
664
|
-
//Add the dependencies to the deps field, and register for callbacks
|
665
|
-
//on the dependencies.
|
666
|
-
for (i = 0; i < depArray.length; i++) {
|
667
|
-
depArg = depArray[i];
|
668
|
-
//There could be cases like in IE, where a trailing comma will
|
669
|
-
//introduce a null dependency, so only treat a real dependency
|
670
|
-
//value as a dependency.
|
671
|
-
if (depArg) {
|
672
|
-
//Split the dependency name into plugin and name parts
|
673
|
-
depArg = makeModuleMap(depArg, (name ? moduleMap : relModuleMap));
|
674
|
-
depName = depArg.fullName;
|
675
|
-
|
676
|
-
//Fix the name in depArray to be just the name, since
|
677
|
-
//that is how it will be called back later.
|
678
|
-
depArray[i] = depName;
|
679
|
-
|
680
|
-
//Fast path CommonJS standard dependencies.
|
681
|
-
if (depName === "require") {
|
682
|
-
manager.deps[depName] = makeRequire(moduleMap);
|
683
|
-
} else if (depName === "exports") {
|
684
|
-
//CommonJS module spec 1.1
|
685
|
-
manager.deps[depName] = defined[fullName] = {};
|
686
|
-
manager.usingExports = true;
|
687
|
-
} else if (depName === "module") {
|
688
|
-
//CommonJS module spec 1.1
|
689
|
-
manager.cjsModule = cjsMod = manager.deps[depName] = {
|
690
|
-
id: name,
|
691
|
-
uri: name ? context.nameToUrl(name, null, relModuleMap) : undefined,
|
692
|
-
exports: defined[fullName]
|
693
|
-
};
|
694
|
-
cjsMod.setExports = makeSetExports(cjsMod);
|
695
|
-
} else if (depName in defined && !(depName in waiting)) {
|
696
|
-
//Module already defined, no need to wait for it.
|
697
|
-
manager.deps[depName] = defined[depName];
|
698
|
-
} else if (!uniques[depName]) {
|
699
|
-
|
700
|
-
//A dynamic dependency.
|
701
|
-
manager.depMax += 1;
|
702
|
-
|
703
|
-
queueDependency(depArg);
|
704
|
-
|
705
|
-
//Register to get notification when dependency loads.
|
706
|
-
(managerCallbacks[depName] ||
|
707
|
-
(managerCallbacks[depName] = [])).push(manager);
|
708
|
-
|
709
|
-
uniques[depName] = true;
|
710
|
-
}
|
711
|
-
}
|
712
|
-
}
|
713
|
-
|
714
|
-
//Do not bother tracking the manager if it is all done.
|
715
|
-
if (manager.depCount === manager.depMax) {
|
716
|
-
//All done, execute!
|
717
|
-
execManager(manager);
|
718
|
-
} else {
|
719
|
-
waiting[manager.waitId] = manager;
|
720
|
-
waitAry.push(manager);
|
721
|
-
context.waitCount += 1;
|
722
|
-
}
|
723
|
-
}
|
724
|
-
|
725
|
-
/**
|
726
|
-
* Convenience method to call main for a define call that was put on
|
727
|
-
* hold in the defQueue.
|
728
|
-
*/
|
729
|
-
function callDefMain(args) {
|
730
|
-
main.apply(null, args);
|
731
|
-
//Mark the module loaded. Must do it here in addition
|
732
|
-
//to doing it in define in case a script does
|
733
|
-
//not call define
|
734
|
-
loaded[args[0]] = true;
|
735
|
-
}
|
736
|
-
|
737
|
-
/**
|
738
|
-
* jQuery 1.4.3+ supports ways to hold off calling
|
739
|
-
* calling jQuery ready callbacks until all scripts are loaded. Be sure
|
740
|
-
* to track it if the capability exists.. Also, since jQuery 1.4.3 does
|
741
|
-
* not register as a module, need to do some global inference checking.
|
742
|
-
* Even if it does register as a module, not guaranteed to be the precise
|
743
|
-
* name of the global. If a jQuery is tracked for this context, then go
|
744
|
-
* ahead and register it as a module too, if not already in process.
|
745
|
-
*/
|
746
|
-
jQueryCheck = function (jqCandidate) {
|
747
|
-
if (!context.jQuery) {
|
748
|
-
var $ = jqCandidate || (typeof jQuery !== "undefined" ? jQuery : null);
|
749
|
-
|
750
|
-
if ($) {
|
751
|
-
//If a specific version of jQuery is wanted, make sure to only
|
752
|
-
//use this jQuery if it matches.
|
753
|
-
if (config.jQuery && $.fn.jquery !== config.jQuery) {
|
754
|
-
return;
|
755
|
-
}
|
756
|
-
|
757
|
-
if ("holdReady" in $ || "readyWait" in $) {
|
758
|
-
context.jQuery = $;
|
759
|
-
|
760
|
-
//Manually create a "jquery" module entry if not one already
|
761
|
-
//or in process. Note this could trigger an attempt at
|
762
|
-
//a second jQuery registration, but does no harm since
|
763
|
-
//the first one wins, and it is the same value anyway.
|
764
|
-
callDefMain(["jquery", [], function () {
|
765
|
-
return jQuery;
|
766
|
-
}]);
|
767
|
-
|
768
|
-
//Ask jQuery to hold DOM ready callbacks.
|
769
|
-
if (context.scriptCount) {
|
770
|
-
jQueryHoldReady($, true);
|
771
|
-
context.jQueryIncremented = true;
|
772
|
-
}
|
773
|
-
}
|
774
|
-
}
|
775
|
-
}
|
776
|
-
};
|
777
|
-
|
778
|
-
function forceExec(manager, traced) {
|
779
|
-
if (manager.isDone) {
|
780
|
-
return undefined;
|
781
|
-
}
|
782
|
-
|
783
|
-
var fullName = manager.fullName,
|
784
|
-
depArray = manager.depArray,
|
785
|
-
depName, i;
|
786
|
-
if (fullName) {
|
787
|
-
if (traced[fullName]) {
|
788
|
-
return defined[fullName];
|
789
|
-
}
|
790
|
-
|
791
|
-
traced[fullName] = true;
|
792
|
-
}
|
793
|
-
|
794
|
-
//forceExec all of its dependencies.
|
795
|
-
for (i = 0; i < depArray.length; i++) {
|
796
|
-
//Some array members may be null, like if a trailing comma
|
797
|
-
//IE, so do the explicit [i] access and check if it has a value.
|
798
|
-
depName = depArray[i];
|
799
|
-
if (depName) {
|
800
|
-
if (!manager.deps[depName] && waiting[depName]) {
|
801
|
-
manager.onDep(depName, forceExec(waiting[depName], traced));
|
802
|
-
}
|
803
|
-
}
|
804
|
-
}
|
805
|
-
|
806
|
-
return fullName ? defined[fullName] : undefined;
|
807
|
-
}
|
808
|
-
|
809
|
-
/**
|
810
|
-
* Checks if all modules for a context are loaded, and if so, evaluates the
|
811
|
-
* new ones in right dependency order.
|
812
|
-
*
|
813
|
-
* @private
|
814
|
-
*/
|
815
|
-
function checkLoaded() {
|
816
|
-
var waitInterval = config.waitSeconds * 1000,
|
817
|
-
//It is possible to disable the wait interval by using waitSeconds of 0.
|
818
|
-
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
|
819
|
-
noLoads = "", hasLoadedProp = false, stillLoading = false, prop,
|
820
|
-
err, manager;
|
821
|
-
|
822
|
-
//If there are items still in the paused queue processing wait.
|
823
|
-
//This is particularly important in the sync case where each paused
|
824
|
-
//item is processed right away but there may be more waiting.
|
825
|
-
if (context.pausedCount > 0) {
|
826
|
-
return undefined;
|
827
|
-
}
|
828
|
-
|
829
|
-
//Determine if priority loading is done. If so clear the priority. If
|
830
|
-
//not, then do not check
|
831
|
-
if (config.priorityWait) {
|
832
|
-
if (isPriorityDone()) {
|
833
|
-
//Call resume, since it could have
|
834
|
-
//some waiting dependencies to trace.
|
835
|
-
resume();
|
836
|
-
} else {
|
837
|
-
return undefined;
|
838
|
-
}
|
839
|
-
}
|
840
|
-
|
841
|
-
//See if anything is still in flight.
|
842
|
-
for (prop in loaded) {
|
843
|
-
if (!(prop in empty)) {
|
844
|
-
hasLoadedProp = true;
|
845
|
-
if (!loaded[prop]) {
|
846
|
-
if (expired) {
|
847
|
-
noLoads += prop + " ";
|
848
|
-
} else {
|
849
|
-
stillLoading = true;
|
850
|
-
break;
|
851
|
-
}
|
852
|
-
}
|
853
|
-
}
|
854
|
-
}
|
855
|
-
|
856
|
-
//Check for exit conditions.
|
857
|
-
if (!hasLoadedProp && !context.waitCount) {
|
858
|
-
//If the loaded object had no items, then the rest of
|
859
|
-
//the work below does not need to be done.
|
860
|
-
return undefined;
|
861
|
-
}
|
862
|
-
if (expired && noLoads) {
|
863
|
-
//If wait time expired, throw error of unloaded modules.
|
864
|
-
err = makeError("timeout", "Load timeout for modules: " + noLoads);
|
865
|
-
err.requireType = "timeout";
|
866
|
-
err.requireModules = noLoads;
|
867
|
-
return req.onError(err);
|
868
|
-
}
|
869
|
-
if (stillLoading || context.scriptCount) {
|
870
|
-
//Something is still waiting to load. Wait for it, but only
|
871
|
-
//if a timeout is not already in effect.
|
872
|
-
if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
|
873
|
-
checkLoadedTimeoutId = setTimeout(function () {
|
874
|
-
checkLoadedTimeoutId = 0;
|
875
|
-
checkLoaded();
|
876
|
-
}, 50);
|
877
|
-
}
|
878
|
-
return undefined;
|
879
|
-
}
|
880
|
-
|
881
|
-
//If still have items in the waiting cue, but all modules have
|
882
|
-
//been loaded, then it means there are some circular dependencies
|
883
|
-
//that need to be broken.
|
884
|
-
//However, as a waiting thing is fired, then it can add items to
|
885
|
-
//the waiting cue, and those items should not be fired yet, so
|
886
|
-
//make sure to redo the checkLoaded call after breaking a single
|
887
|
-
//cycle, if nothing else loaded then this logic will pick it up
|
888
|
-
//again.
|
889
|
-
if (context.waitCount) {
|
890
|
-
//Cycle through the waitAry, and call items in sequence.
|
891
|
-
for (i = 0; (manager = waitAry[i]); i++) {
|
892
|
-
forceExec(manager, {});
|
893
|
-
}
|
894
|
-
|
895
|
-
//Only allow this recursion to a certain depth. Only
|
896
|
-
//triggered by errors in calling a module in which its
|
897
|
-
//modules waiting on it cannot finish loading, or some circular
|
898
|
-
//dependencies that then may add more dependencies.
|
899
|
-
//The value of 5 is a bit arbitrary. Hopefully just one extra
|
900
|
-
//pass, or two for the case of circular dependencies generating
|
901
|
-
//more work that gets resolved in the sync node case.
|
902
|
-
if (checkLoadedDepth < 5) {
|
903
|
-
checkLoadedDepth += 1;
|
904
|
-
checkLoaded();
|
905
|
-
}
|
906
|
-
}
|
907
|
-
|
908
|
-
checkLoadedDepth = 0;
|
909
|
-
|
910
|
-
//Check for DOM ready, and nothing is waiting across contexts.
|
911
|
-
req.checkReadyState();
|
912
|
-
|
913
|
-
return undefined;
|
914
|
-
}
|
915
|
-
|
916
|
-
function callPlugin(pluginName, dep) {
|
917
|
-
var name = dep.name,
|
918
|
-
fullName = dep.fullName,
|
919
|
-
load;
|
920
|
-
|
921
|
-
//Do not bother if plugin is already defined or being loaded.
|
922
|
-
if (fullName in defined || fullName in loaded) {
|
923
|
-
return;
|
924
|
-
}
|
925
|
-
|
926
|
-
if (!plugins[pluginName]) {
|
927
|
-
plugins[pluginName] = defined[pluginName];
|
928
|
-
}
|
929
|
-
|
930
|
-
//Only set loaded to false for tracking if it has not already been set.
|
931
|
-
if (!loaded[fullName]) {
|
932
|
-
loaded[fullName] = false;
|
933
|
-
}
|
934
|
-
|
935
|
-
load = function (ret) {
|
936
|
-
//Allow the build process to register plugin-loaded dependencies.
|
937
|
-
if (req.onPluginLoad) {
|
938
|
-
req.onPluginLoad(context, pluginName, name, ret);
|
939
|
-
}
|
940
|
-
|
941
|
-
execManager({
|
942
|
-
prefix: dep.prefix,
|
943
|
-
name: dep.name,
|
944
|
-
fullName: dep.fullName,
|
945
|
-
callback: function () {
|
946
|
-
return ret;
|
947
|
-
}
|
948
|
-
});
|
949
|
-
loaded[fullName] = true;
|
950
|
-
};
|
951
|
-
|
952
|
-
//Allow plugins to load other code without having to know the
|
953
|
-
//context or how to "complete" the load.
|
954
|
-
load.fromText = function (moduleName, text) {
|
955
|
-
/*jslint evil: true */
|
956
|
-
var hasInteractive = useInteractive;
|
957
|
-
|
958
|
-
//Indicate a the module is in process of loading.
|
959
|
-
context.loaded[moduleName] = false;
|
960
|
-
context.scriptCount += 1;
|
961
|
-
|
962
|
-
//Turn off interactive script matching for IE for any define
|
963
|
-
//calls in the text, then turn it back on at the end.
|
964
|
-
if (hasInteractive) {
|
965
|
-
useInteractive = false;
|
966
|
-
}
|
967
|
-
|
968
|
-
req.exec(text);
|
969
|
-
|
970
|
-
if (hasInteractive) {
|
971
|
-
useInteractive = true;
|
972
|
-
}
|
973
|
-
|
974
|
-
//Support anonymous modules.
|
975
|
-
context.completeLoad(moduleName);
|
976
|
-
};
|
977
|
-
|
978
|
-
//Use parentName here since the plugin's name is not reliable,
|
979
|
-
//could be some weird string with no path that actually wants to
|
980
|
-
//reference the parentName's path.
|
981
|
-
plugins[pluginName].load(name, makeRequire(dep.parentMap, true), load, config);
|
982
|
-
}
|
983
|
-
|
984
|
-
function loadPaused(dep) {
|
985
|
-
//Renormalize dependency if its name was waiting on a plugin
|
986
|
-
//to load, which as since loaded.
|
987
|
-
if (dep.prefix && dep.name.indexOf('__$p') === 0 && defined[dep.prefix]) {
|
988
|
-
dep = makeModuleMap(dep.originalName, dep.parentMap);
|
989
|
-
}
|
990
|
-
|
991
|
-
var pluginName = dep.prefix,
|
992
|
-
fullName = dep.fullName,
|
993
|
-
urlFetched = context.urlFetched;
|
994
|
-
|
995
|
-
//Do not bother if the dependency has already been specified.
|
996
|
-
if (specified[fullName] || loaded[fullName]) {
|
997
|
-
return;
|
998
|
-
} else {
|
999
|
-
specified[fullName] = true;
|
1000
|
-
}
|
1001
|
-
|
1002
|
-
if (pluginName) {
|
1003
|
-
//If plugin not loaded, wait for it.
|
1004
|
-
//set up callback list. if no list, then register
|
1005
|
-
//managerCallback for that plugin.
|
1006
|
-
if (defined[pluginName]) {
|
1007
|
-
callPlugin(pluginName, dep);
|
1008
|
-
} else {
|
1009
|
-
if (!pluginsQueue[pluginName]) {
|
1010
|
-
pluginsQueue[pluginName] = [];
|
1011
|
-
(managerCallbacks[pluginName] ||
|
1012
|
-
(managerCallbacks[pluginName] = [])).push({
|
1013
|
-
onDep: function (name, value) {
|
1014
|
-
if (name === pluginName) {
|
1015
|
-
var i, oldModuleMap, ary = pluginsQueue[pluginName];
|
1016
|
-
|
1017
|
-
//Now update all queued plugin actions.
|
1018
|
-
for (i = 0; i < ary.length; i++) {
|
1019
|
-
oldModuleMap = ary[i];
|
1020
|
-
//Update the moduleMap since the
|
1021
|
-
//module name may be normalized
|
1022
|
-
//differently now.
|
1023
|
-
callPlugin(pluginName,
|
1024
|
-
makeModuleMap(oldModuleMap.originalName, oldModuleMap.parentMap));
|
1025
|
-
}
|
1026
|
-
delete pluginsQueue[pluginName];
|
1027
|
-
}
|
1028
|
-
}
|
1029
|
-
});
|
1030
|
-
}
|
1031
|
-
pluginsQueue[pluginName].push(dep);
|
1032
|
-
}
|
1033
|
-
} else {
|
1034
|
-
if (!urlFetched[dep.url]) {
|
1035
|
-
req.load(context, fullName, dep.url);
|
1036
|
-
urlFetched[dep.url] = true;
|
1037
|
-
}
|
1038
|
-
}
|
1039
|
-
}
|
1040
|
-
|
1041
|
-
/**
|
1042
|
-
* Resumes tracing of dependencies and then checks if everything is loaded.
|
1043
|
-
*/
|
1044
|
-
resume = function () {
|
1045
|
-
var args, i, p;
|
1046
|
-
|
1047
|
-
resumeDepth += 1;
|
1048
|
-
|
1049
|
-
if (context.scriptCount <= 0) {
|
1050
|
-
//Synchronous envs will push the number below zero with the
|
1051
|
-
//decrement above, be sure to set it back to zero for good measure.
|
1052
|
-
//require() calls that also do not end up loading scripts could
|
1053
|
-
//push the number negative too.
|
1054
|
-
context.scriptCount = 0;
|
1055
|
-
}
|
1056
|
-
|
1057
|
-
//Make sure any remaining defQueue items get properly processed.
|
1058
|
-
while (defQueue.length) {
|
1059
|
-
args = defQueue.shift();
|
1060
|
-
if (args[0] === null) {
|
1061
|
-
return req.onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
|
1062
|
-
} else {
|
1063
|
-
callDefMain(args);
|
1064
|
-
}
|
1065
|
-
}
|
1066
|
-
|
1067
|
-
//Skip the resume of paused dependencies
|
1068
|
-
//if current context is in priority wait.
|
1069
|
-
if (!config.priorityWait || isPriorityDone()) {
|
1070
|
-
while (context.paused.length) {
|
1071
|
-
p = context.paused;
|
1072
|
-
context.pausedCount += p.length;
|
1073
|
-
//Reset paused list
|
1074
|
-
context.paused = [];
|
1075
|
-
|
1076
|
-
for (i = 0; (args = p[i]); i++) {
|
1077
|
-
loadPaused(args);
|
1078
|
-
}
|
1079
|
-
//Move the start time for timeout forward.
|
1080
|
-
context.startTime = (new Date()).getTime();
|
1081
|
-
context.pausedCount -= p.length;
|
1082
|
-
}
|
1083
|
-
}
|
1084
|
-
|
1085
|
-
//Only check if loaded when resume depth is 1. It is likely that
|
1086
|
-
//it is only greater than 1 in sync environments where a factory
|
1087
|
-
//function also then calls the callback-style require. In those
|
1088
|
-
//cases, the checkLoaded should not occur until the resume
|
1089
|
-
//depth is back at the top level.
|
1090
|
-
if (resumeDepth === 1) {
|
1091
|
-
checkLoaded();
|
1092
|
-
}
|
1093
|
-
|
1094
|
-
resumeDepth -= 1;
|
1095
|
-
|
1096
|
-
return undefined;
|
1097
|
-
};
|
1098
|
-
|
1099
|
-
//Define the context object. Many of these fields are on here
|
1100
|
-
//just to make debugging easier.
|
1101
|
-
context = {
|
1102
|
-
contextName: contextName,
|
1103
|
-
config: config,
|
1104
|
-
defQueue: defQueue,
|
1105
|
-
waiting: waiting,
|
1106
|
-
waitCount: 0,
|
1107
|
-
specified: specified,
|
1108
|
-
loaded: loaded,
|
1109
|
-
urlMap: urlMap,
|
1110
|
-
scriptCount: 0,
|
1111
|
-
urlFetched: {},
|
1112
|
-
defined: defined,
|
1113
|
-
paused: [],
|
1114
|
-
pausedCount: 0,
|
1115
|
-
plugins: plugins,
|
1116
|
-
managerCallbacks: managerCallbacks,
|
1117
|
-
makeModuleMap: makeModuleMap,
|
1118
|
-
normalize: normalize,
|
1119
|
-
/**
|
1120
|
-
* Set a configuration for the context.
|
1121
|
-
* @param {Object} cfg config object to integrate.
|
1122
|
-
*/
|
1123
|
-
configure: function (cfg) {
|
1124
|
-
var paths, prop, packages, pkgs, packagePaths, requireWait;
|
1125
|
-
|
1126
|
-
//Make sure the baseUrl ends in a slash.
|
1127
|
-
if (cfg.baseUrl) {
|
1128
|
-
if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== "/") {
|
1129
|
-
cfg.baseUrl += "/";
|
1130
|
-
}
|
1131
|
-
}
|
1132
|
-
|
1133
|
-
//Save off the paths and packages since they require special processing,
|
1134
|
-
//they are additive.
|
1135
|
-
paths = config.paths;
|
1136
|
-
packages = config.packages;
|
1137
|
-
pkgs = config.pkgs;
|
1138
|
-
|
1139
|
-
//Mix in the config values, favoring the new values over
|
1140
|
-
//existing ones in context.config.
|
1141
|
-
mixin(config, cfg, true);
|
1142
|
-
|
1143
|
-
//Adjust paths if necessary.
|
1144
|
-
if (cfg.paths) {
|
1145
|
-
for (prop in cfg.paths) {
|
1146
|
-
if (!(prop in empty)) {
|
1147
|
-
paths[prop] = cfg.paths[prop];
|
1148
|
-
}
|
1149
|
-
}
|
1150
|
-
config.paths = paths;
|
1151
|
-
}
|
1152
|
-
|
1153
|
-
packagePaths = cfg.packagePaths;
|
1154
|
-
if (packagePaths || cfg.packages) {
|
1155
|
-
//Convert packagePaths into a packages config.
|
1156
|
-
if (packagePaths) {
|
1157
|
-
for (prop in packagePaths) {
|
1158
|
-
if (!(prop in empty)) {
|
1159
|
-
configurePackageDir(pkgs, packagePaths[prop], prop);
|
1160
|
-
}
|
1161
|
-
}
|
1162
|
-
}
|
1163
|
-
|
1164
|
-
//Adjust packages if necessary.
|
1165
|
-
if (cfg.packages) {
|
1166
|
-
configurePackageDir(pkgs, cfg.packages);
|
1167
|
-
}
|
1168
|
-
|
1169
|
-
//Done with modifications, assing packages back to context config
|
1170
|
-
config.pkgs = pkgs;
|
1171
|
-
}
|
1172
|
-
|
1173
|
-
//If priority loading is in effect, trigger the loads now
|
1174
|
-
if (cfg.priority) {
|
1175
|
-
//Hold on to requireWait value, and reset it after done
|
1176
|
-
requireWait = context.requireWait;
|
1177
|
-
|
1178
|
-
//Allow tracing some require calls to allow the fetching
|
1179
|
-
//of the priority config.
|
1180
|
-
context.requireWait = false;
|
1181
|
-
|
1182
|
-
//But first, call resume to register any defined modules that may
|
1183
|
-
//be in a data-main built file before the priority config
|
1184
|
-
//call. Also grab any waiting define calls for this context.
|
1185
|
-
context.takeGlobalQueue();
|
1186
|
-
resume();
|
1187
|
-
|
1188
|
-
context.require(cfg.priority);
|
1189
|
-
|
1190
|
-
//Trigger a resume right away, for the case when
|
1191
|
-
//the script with the priority load is done as part
|
1192
|
-
//of a data-main call. In that case the normal resume
|
1193
|
-
//call will not happen because the scriptCount will be
|
1194
|
-
//at 1, since the script for data-main is being processed.
|
1195
|
-
resume();
|
1196
|
-
|
1197
|
-
//Restore previous state.
|
1198
|
-
context.requireWait = requireWait;
|
1199
|
-
config.priorityWait = cfg.priority;
|
1200
|
-
}
|
1201
|
-
|
1202
|
-
//If a deps array or a config callback is specified, then call
|
1203
|
-
//require with those args. This is useful when require is defined as a
|
1204
|
-
//config object before require.js is loaded.
|
1205
|
-
if (cfg.deps || cfg.callback) {
|
1206
|
-
context.require(cfg.deps || [], cfg.callback);
|
1207
|
-
}
|
1208
|
-
|
1209
|
-
//Set up ready callback, if asked. Useful when require is defined as a
|
1210
|
-
//config object before require.js is loaded.
|
1211
|
-
if (cfg.ready) {
|
1212
|
-
req.ready(cfg.ready);
|
1213
|
-
}
|
1214
|
-
},
|
1215
|
-
|
1216
|
-
requireDefined: function (moduleName, relModuleMap) {
|
1217
|
-
return makeModuleMap(moduleName, relModuleMap).fullName in defined;
|
1218
|
-
},
|
1219
|
-
|
1220
|
-
requireSpecified: function (moduleName, relModuleMap) {
|
1221
|
-
return makeModuleMap(moduleName, relModuleMap).fullName in specified;
|
1222
|
-
},
|
1223
|
-
|
1224
|
-
require: function (deps, callback, relModuleMap) {
|
1225
|
-
var moduleName, fullName, moduleMap;
|
1226
|
-
if (typeof deps === "string") {
|
1227
|
-
//Synchronous access to one module. If require.get is
|
1228
|
-
//available (as in the Node adapter), prefer that.
|
1229
|
-
//In this case deps is the moduleName and callback is
|
1230
|
-
//the relModuleMap
|
1231
|
-
if (req.get) {
|
1232
|
-
return req.get(context, deps, callback);
|
1233
|
-
}
|
1234
|
-
|
1235
|
-
//Just return the module wanted. In this scenario, the
|
1236
|
-
//second arg (if passed) is just the relModuleMap.
|
1237
|
-
moduleName = deps;
|
1238
|
-
relModuleMap = callback;
|
1239
|
-
|
1240
|
-
//Normalize module name, if it contains . or ..
|
1241
|
-
moduleMap = makeModuleMap(moduleName, relModuleMap);
|
1242
|
-
fullName = moduleMap.fullName;
|
1243
|
-
|
1244
|
-
if (!(fullName in defined)) {
|
1245
|
-
return req.onError(makeError("notloaded", "Module name '" +
|
1246
|
-
moduleMap.fullName +
|
1247
|
-
"' has not been loaded yet for context: " +
|
1248
|
-
contextName));
|
1249
|
-
}
|
1250
|
-
return defined[fullName];
|
1251
|
-
}
|
1252
|
-
|
1253
|
-
main(null, deps, callback, relModuleMap);
|
1254
|
-
|
1255
|
-
//If the require call does not trigger anything new to load,
|
1256
|
-
//then resume the dependency processing.
|
1257
|
-
if (!context.requireWait) {
|
1258
|
-
while (!context.scriptCount && context.paused.length) {
|
1259
|
-
//For built layers, there can be some defined
|
1260
|
-
//modules waiting for intake into the context,
|
1261
|
-
//in particular module plugins. Take them.
|
1262
|
-
context.takeGlobalQueue();
|
1263
|
-
resume();
|
1264
|
-
}
|
1265
|
-
}
|
1266
|
-
return undefined;
|
1267
|
-
},
|
1268
|
-
|
1269
|
-
/**
|
1270
|
-
* Internal method to transfer globalQueue items to this context's
|
1271
|
-
* defQueue.
|
1272
|
-
*/
|
1273
|
-
takeGlobalQueue: function () {
|
1274
|
-
//Push all the globalDefQueue items into the context's defQueue
|
1275
|
-
if (globalDefQueue.length) {
|
1276
|
-
//Array splice in the values since the context code has a
|
1277
|
-
//local var ref to defQueue, so cannot just reassign the one
|
1278
|
-
//on context.
|
1279
|
-
apsp.apply(context.defQueue,
|
1280
|
-
[context.defQueue.length - 1, 0].concat(globalDefQueue));
|
1281
|
-
globalDefQueue = [];
|
1282
|
-
}
|
1283
|
-
},
|
1284
|
-
|
1285
|
-
/**
|
1286
|
-
* Internal method used by environment adapters to complete a load event.
|
1287
|
-
* A load event could be a script load or just a load pass from a synchronous
|
1288
|
-
* load call.
|
1289
|
-
* @param {String} moduleName the name of the module to potentially complete.
|
1290
|
-
*/
|
1291
|
-
completeLoad: function (moduleName) {
|
1292
|
-
var args;
|
1293
|
-
|
1294
|
-
context.takeGlobalQueue();
|
1295
|
-
|
1296
|
-
while (defQueue.length) {
|
1297
|
-
args = defQueue.shift();
|
1298
|
-
|
1299
|
-
if (args[0] === null) {
|
1300
|
-
args[0] = moduleName;
|
1301
|
-
break;
|
1302
|
-
} else if (args[0] === moduleName) {
|
1303
|
-
//Found matching define call for this script!
|
1304
|
-
break;
|
1305
|
-
} else {
|
1306
|
-
//Some other named define call, most likely the result
|
1307
|
-
//of a build layer that included many define calls.
|
1308
|
-
callDefMain(args);
|
1309
|
-
args = null;
|
1310
|
-
}
|
1311
|
-
}
|
1312
|
-
if (args) {
|
1313
|
-
callDefMain(args);
|
1314
|
-
} else {
|
1315
|
-
//A script that does not call define(), so just simulate
|
1316
|
-
//the call for it. Special exception for jQuery dynamic load.
|
1317
|
-
callDefMain([moduleName, [],
|
1318
|
-
moduleName === "jquery" && typeof jQuery !== "undefined" ?
|
1319
|
-
function () {
|
1320
|
-
return jQuery;
|
1321
|
-
} : null]);
|
1322
|
-
}
|
1323
|
-
|
1324
|
-
//Mark the script as loaded. Note that this can be different from a
|
1325
|
-
//moduleName that maps to a define call. This line is important
|
1326
|
-
//for traditional browser scripts.
|
1327
|
-
loaded[moduleName] = true;
|
1328
|
-
|
1329
|
-
//If a global jQuery is defined, check for it. Need to do it here
|
1330
|
-
//instead of main() since stock jQuery does not register as
|
1331
|
-
//a module via define.
|
1332
|
-
jQueryCheck();
|
1333
|
-
|
1334
|
-
//Doing this scriptCount decrement branching because sync envs
|
1335
|
-
//need to decrement after resume, otherwise it looks like
|
1336
|
-
//loading is complete after the first dependency is fetched.
|
1337
|
-
//For browsers, it works fine to decrement after, but it means
|
1338
|
-
//the checkLoaded setTimeout 50 ms cost is taken. To avoid
|
1339
|
-
//that cost, decrement beforehand.
|
1340
|
-
if (req.isAsync) {
|
1341
|
-
context.scriptCount -= 1;
|
1342
|
-
}
|
1343
|
-
resume();
|
1344
|
-
if (!req.isAsync) {
|
1345
|
-
context.scriptCount -= 1;
|
1346
|
-
}
|
1347
|
-
},
|
1348
|
-
|
1349
|
-
/**
|
1350
|
-
* Converts a module name + .extension into an URL path.
|
1351
|
-
* *Requires* the use of a module name. It does not support using
|
1352
|
-
* plain URLs like nameToUrl.
|
1353
|
-
*/
|
1354
|
-
toUrl: function (moduleNamePlusExt, relModuleMap) {
|
1355
|
-
var index = moduleNamePlusExt.lastIndexOf("."),
|
1356
|
-
ext = null;
|
1357
|
-
|
1358
|
-
if (index !== -1) {
|
1359
|
-
ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
|
1360
|
-
moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
|
1361
|
-
}
|
1362
|
-
|
1363
|
-
return context.nameToUrl(moduleNamePlusExt, ext, relModuleMap);
|
1364
|
-
},
|
1365
|
-
|
1366
|
-
/**
|
1367
|
-
* Converts a module name to a file path. Supports cases where
|
1368
|
-
* moduleName may actually be just an URL.
|
1369
|
-
*/
|
1370
|
-
nameToUrl: function (moduleName, ext, relModuleMap) {
|
1371
|
-
var paths, pkgs, pkg, pkgPath, syms, i, parentModule, url,
|
1372
|
-
config = context.config;
|
1373
|
-
|
1374
|
-
//Normalize module name if have a base relative module name to work from.
|
1375
|
-
moduleName = normalize(moduleName, relModuleMap && relModuleMap.fullName);
|
1376
|
-
|
1377
|
-
//If a colon is in the URL, it indicates a protocol is used and it is just
|
1378
|
-
//an URL to a file, or if it starts with a slash or ends with .js, it is just a plain file.
|
1379
|
-
//The slash is important for protocol-less URLs as well as full paths.
|
1380
|
-
if (req.jsExtRegExp.test(moduleName)) {
|
1381
|
-
//Just a plain path, not module name lookup, so just return it.
|
1382
|
-
//Add extension if it is included. This is a bit wonky, only non-.js things pass
|
1383
|
-
//an extension, this method probably needs to be reworked.
|
1384
|
-
url = moduleName + (ext ? ext : "");
|
1385
|
-
} else {
|
1386
|
-
//A module that needs to be converted to a path.
|
1387
|
-
paths = config.paths;
|
1388
|
-
pkgs = config.pkgs;
|
1389
|
-
|
1390
|
-
syms = moduleName.split("/");
|
1391
|
-
//For each module name segment, see if there is a path
|
1392
|
-
//registered for it. Start with most specific name
|
1393
|
-
//and work up from it.
|
1394
|
-
for (i = syms.length; i > 0; i--) {
|
1395
|
-
parentModule = syms.slice(0, i).join("/");
|
1396
|
-
if (paths[parentModule]) {
|
1397
|
-
syms.splice(0, i, paths[parentModule]);
|
1398
|
-
break;
|
1399
|
-
} else if ((pkg = pkgs[parentModule])) {
|
1400
|
-
//If module name is just the package name, then looking
|
1401
|
-
//for the main module.
|
1402
|
-
if (moduleName === pkg.name) {
|
1403
|
-
pkgPath = pkg.location + '/' + pkg.main;
|
1404
|
-
} else {
|
1405
|
-
pkgPath = pkg.location;
|
1406
|
-
}
|
1407
|
-
syms.splice(0, i, pkgPath);
|
1408
|
-
break;
|
1409
|
-
}
|
1410
|
-
}
|
1411
|
-
|
1412
|
-
//Join the path parts together, then figure out if baseUrl is needed.
|
1413
|
-
url = syms.join("/") + (ext || ".js");
|
1414
|
-
url = (url.charAt(0) === '/' || url.match(/^\w+:/) ? "" : config.baseUrl) + url;
|
1415
|
-
}
|
1416
|
-
|
1417
|
-
return config.urlArgs ? url +
|
1418
|
-
((url.indexOf('?') === -1 ? '?' : '&') +
|
1419
|
-
config.urlArgs) : url;
|
1420
|
-
}
|
1421
|
-
};
|
1422
|
-
|
1423
|
-
//Make these visible on the context so can be called at the very
|
1424
|
-
//end of the file to bootstrap
|
1425
|
-
context.jQueryCheck = jQueryCheck;
|
1426
|
-
context.resume = resume;
|
1427
|
-
|
1428
|
-
return context;
|
1429
|
-
}
|
1430
|
-
|
1431
|
-
/**
|
1432
|
-
* Main entry point.
|
1433
|
-
*
|
1434
|
-
* If the only argument to require is a string, then the module that
|
1435
|
-
* is represented by that string is fetched for the appropriate context.
|
1436
|
-
*
|
1437
|
-
* If the first argument is an array, then it will be treated as an array
|
1438
|
-
* of dependency string names to fetch. An optional function callback can
|
1439
|
-
* be specified to execute when all of those dependencies are available.
|
1440
|
-
*
|
1441
|
-
* Make a local req variable to help Caja compliance (it assumes things
|
1442
|
-
* on a require that are not standardized), and to give a short
|
1443
|
-
* name for minification/local scope use.
|
1444
|
-
*/
|
1445
|
-
req = requirejs = function (deps, callback) {
|
1446
|
-
|
1447
|
-
//Find the right context, use default
|
1448
|
-
var contextName = defContextName,
|
1449
|
-
context, config;
|
1450
|
-
|
1451
|
-
// Determine if have config object in the call.
|
1452
|
-
if (!isArray(deps) && typeof deps !== "string") {
|
1453
|
-
// deps is a config object
|
1454
|
-
config = deps;
|
1455
|
-
if (isArray(callback)) {
|
1456
|
-
// Adjust args if there are dependencies
|
1457
|
-
deps = callback;
|
1458
|
-
callback = arguments[2];
|
1459
|
-
} else {
|
1460
|
-
deps = [];
|
1461
|
-
}
|
1462
|
-
}
|
1463
|
-
|
1464
|
-
if (config && config.context) {
|
1465
|
-
contextName = config.context;
|
1466
|
-
}
|
1467
|
-
|
1468
|
-
context = contexts[contextName] ||
|
1469
|
-
(contexts[contextName] = newContext(contextName));
|
1470
|
-
|
1471
|
-
if (config) {
|
1472
|
-
context.configure(config);
|
1473
|
-
}
|
1474
|
-
|
1475
|
-
return context.require(deps, callback);
|
1476
|
-
};
|
1477
|
-
|
1478
|
-
/**
|
1479
|
-
* Export require as a global, but only if it does not already exist.
|
1480
|
-
*/
|
1481
|
-
if (typeof require === "undefined") {
|
1482
|
-
require = req;
|
1483
|
-
}
|
1484
|
-
|
1485
|
-
/**
|
1486
|
-
* Global require.toUrl(), to match global require, mostly useful
|
1487
|
-
* for debugging/work in the global space.
|
1488
|
-
*/
|
1489
|
-
req.toUrl = function (moduleNamePlusExt) {
|
1490
|
-
return contexts[defContextName].toUrl(moduleNamePlusExt);
|
1491
|
-
};
|
1492
|
-
|
1493
|
-
req.version = version;
|
1494
|
-
req.isArray = isArray;
|
1495
|
-
req.isFunction = isFunction;
|
1496
|
-
req.mixin = mixin;
|
1497
|
-
//Used to filter out dependencies that are already paths.
|
1498
|
-
req.jsExtRegExp = /^\/|:|\?|\.js$/;
|
1499
|
-
s = req.s = {
|
1500
|
-
contexts: contexts,
|
1501
|
-
//Stores a list of URLs that should not get async script tag treatment.
|
1502
|
-
skipAsync: {},
|
1503
|
-
isPageLoaded: !isBrowser,
|
1504
|
-
readyCalls: []
|
1505
|
-
};
|
1506
|
-
|
1507
|
-
req.isAsync = req.isBrowser = isBrowser;
|
1508
|
-
if (isBrowser) {
|
1509
|
-
head = s.head = document.getElementsByTagName("head")[0];
|
1510
|
-
//If BASE tag is in play, using appendChild is a problem for IE6.
|
1511
|
-
//When that browser dies, this can be removed. Details in this jQuery bug:
|
1512
|
-
//http://dev.jquery.com/ticket/2709
|
1513
|
-
baseElement = document.getElementsByTagName("base")[0];
|
1514
|
-
if (baseElement) {
|
1515
|
-
head = s.head = baseElement.parentNode;
|
1516
|
-
}
|
1517
|
-
}
|
1518
|
-
|
1519
|
-
/**
|
1520
|
-
* Any errors that require explicitly generates will be passed to this
|
1521
|
-
* function. Intercept/override it if you want custom error handling.
|
1522
|
-
* @param {Error} err the error object.
|
1523
|
-
*/
|
1524
|
-
req.onError = function (err) {
|
1525
|
-
throw err;
|
1526
|
-
};
|
1527
|
-
|
1528
|
-
/**
|
1529
|
-
* Does the request to load a module for the browser case.
|
1530
|
-
* Make this a separate function to allow other environments
|
1531
|
-
* to override it.
|
1532
|
-
*
|
1533
|
-
* @param {Object} context the require context to find state.
|
1534
|
-
* @param {String} moduleName the name of the module.
|
1535
|
-
* @param {Object} url the URL to the module.
|
1536
|
-
*/
|
1537
|
-
req.load = function (context, moduleName, url) {
|
1538
|
-
var loaded = context.loaded;
|
1539
|
-
|
1540
|
-
isDone = false;
|
1541
|
-
|
1542
|
-
//Only set loaded to false for tracking if it has not already been set.
|
1543
|
-
if (!loaded[moduleName]) {
|
1544
|
-
loaded[moduleName] = false;
|
1545
|
-
}
|
1546
|
-
|
1547
|
-
context.scriptCount += 1;
|
1548
|
-
req.attach(url, context, moduleName);
|
1549
|
-
|
1550
|
-
//If tracking a jQuery, then make sure its ready callbacks
|
1551
|
-
//are put on hold to prevent its ready callbacks from
|
1552
|
-
//triggering too soon.
|
1553
|
-
if (context.jQuery && !context.jQueryIncremented) {
|
1554
|
-
jQueryHoldReady(context.jQuery, true);
|
1555
|
-
context.jQueryIncremented = true;
|
1556
|
-
}
|
1557
|
-
};
|
1558
|
-
|
1559
|
-
function getInteractiveScript() {
|
1560
|
-
var scripts, i, script;
|
1561
|
-
if (interactiveScript && interactiveScript.readyState === 'interactive') {
|
1562
|
-
return interactiveScript;
|
1563
|
-
}
|
1564
|
-
|
1565
|
-
scripts = document.getElementsByTagName('script');
|
1566
|
-
for (i = scripts.length - 1; i > -1 && (script = scripts[i]); i--) {
|
1567
|
-
if (script.readyState === 'interactive') {
|
1568
|
-
return (interactiveScript = script);
|
1569
|
-
}
|
1570
|
-
}
|
1571
|
-
|
1572
|
-
return null;
|
1573
|
-
}
|
1574
|
-
|
1575
|
-
/**
|
1576
|
-
* The function that handles definitions of modules. Differs from
|
1577
|
-
* require() in that a string for the module should be the first argument,
|
1578
|
-
* and the function to execute after dependencies are loaded should
|
1579
|
-
* return a value to define the module corresponding to the first argument's
|
1580
|
-
* name.
|
1581
|
-
*/
|
1582
|
-
define = req.def = function (name, deps, callback) {
|
1583
|
-
var node, context;
|
1584
|
-
|
1585
|
-
//Allow for anonymous functions
|
1586
|
-
if (typeof name !== 'string') {
|
1587
|
-
//Adjust args appropriately
|
1588
|
-
callback = deps;
|
1589
|
-
deps = name;
|
1590
|
-
name = null;
|
1591
|
-
}
|
1592
|
-
|
1593
|
-
//This module may not have dependencies
|
1594
|
-
if (!req.isArray(deps)) {
|
1595
|
-
callback = deps;
|
1596
|
-
deps = [];
|
1597
|
-
}
|
1598
|
-
|
1599
|
-
//If no name, and callback is a function, then figure out if it a
|
1600
|
-
//CommonJS thing with dependencies.
|
1601
|
-
if (!name && !deps.length && req.isFunction(callback)) {
|
1602
|
-
//Remove comments from the callback string,
|
1603
|
-
//look for require calls, and pull them into the dependencies,
|
1604
|
-
//but only if there are function args.
|
1605
|
-
if (callback.length) {
|
1606
|
-
callback
|
1607
|
-
.toString()
|
1608
|
-
.replace(commentRegExp, "")
|
1609
|
-
.replace(cjsRequireRegExp, function (match, dep) {
|
1610
|
-
deps.push(dep);
|
1611
|
-
});
|
1612
|
-
|
1613
|
-
//May be a CommonJS thing even without require calls, but still
|
1614
|
-
//could use exports, and module. Avoid doing exports and module
|
1615
|
-
//work though if it just needs require.
|
1616
|
-
//REQUIRES the function to expect the CommonJS variables in the
|
1617
|
-
//order listed below.
|
1618
|
-
deps = (callback.length === 1 ? ["require"] : ["require", "exports", "module"]).concat(deps);
|
1619
|
-
}
|
1620
|
-
}
|
1621
|
-
|
1622
|
-
//If in IE 6-8 and hit an anonymous define() call, do the interactive
|
1623
|
-
//work.
|
1624
|
-
if (useInteractive) {
|
1625
|
-
node = currentlyAddingScript || getInteractiveScript();
|
1626
|
-
if (!node) {
|
1627
|
-
return req.onError(makeError("interactive", "No matching script interactive for " + callback));
|
1628
|
-
}
|
1629
|
-
if (!name) {
|
1630
|
-
name = node.getAttribute("data-requiremodule");
|
1631
|
-
}
|
1632
|
-
context = contexts[node.getAttribute("data-requirecontext")];
|
1633
|
-
}
|
1634
|
-
|
1635
|
-
//Always save off evaluating the def call until the script onload handler.
|
1636
|
-
//This allows multiple modules to be in a file without prematurely
|
1637
|
-
//tracing dependencies, and allows for anonymous module support,
|
1638
|
-
//where the module name is not known until the script onload event
|
1639
|
-
//occurs. If no context, use the global queue, and get it processed
|
1640
|
-
//in the onscript load callback.
|
1641
|
-
(context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
|
1642
|
-
|
1643
|
-
return undefined;
|
1644
|
-
};
|
1645
|
-
|
1646
|
-
define.amd = {
|
1647
|
-
multiversion: true,
|
1648
|
-
plugins: true,
|
1649
|
-
jQuery: true
|
1650
|
-
};
|
1651
|
-
|
1652
|
-
/**
|
1653
|
-
* Executes the text. Normally just uses eval, but can be modified
|
1654
|
-
* to use a more environment specific call.
|
1655
|
-
* @param {String} text the text to execute/evaluate.
|
1656
|
-
*/
|
1657
|
-
req.exec = function (text) {
|
1658
|
-
return eval(text);
|
1659
|
-
};
|
1660
|
-
|
1661
|
-
/**
|
1662
|
-
* Executes a module callack function. Broken out as a separate function
|
1663
|
-
* solely to allow the build system to sequence the files in the built
|
1664
|
-
* layer in the right sequence.
|
1665
|
-
*
|
1666
|
-
* @private
|
1667
|
-
*/
|
1668
|
-
req.execCb = function (name, callback, args, exports) {
|
1669
|
-
return callback.apply(exports, args);
|
1670
|
-
};
|
1671
|
-
|
1672
|
-
/**
|
1673
|
-
* callback for script loads, used to check status of loading.
|
1674
|
-
*
|
1675
|
-
* @param {Event} evt the event from the browser for the script
|
1676
|
-
* that was loaded.
|
1677
|
-
*
|
1678
|
-
* @private
|
1679
|
-
*/
|
1680
|
-
req.onScriptLoad = function (evt) {
|
1681
|
-
//Using currentTarget instead of target for Firefox 2.0's sake. Not
|
1682
|
-
//all old browsers will be supported, but this one was easy enough
|
1683
|
-
//to support and still makes sense.
|
1684
|
-
var node = evt.currentTarget || evt.srcElement, contextName, moduleName,
|
1685
|
-
context;
|
1686
|
-
|
1687
|
-
if (evt.type === "load" || readyRegExp.test(node.readyState)) {
|
1688
|
-
//Reset interactive script so a script node is not held onto for
|
1689
|
-
//to long.
|
1690
|
-
interactiveScript = null;
|
1691
|
-
|
1692
|
-
//Pull out the name of the module and the context.
|
1693
|
-
contextName = node.getAttribute("data-requirecontext");
|
1694
|
-
moduleName = node.getAttribute("data-requiremodule");
|
1695
|
-
context = contexts[contextName];
|
1696
|
-
|
1697
|
-
contexts[contextName].completeLoad(moduleName);
|
1698
|
-
|
1699
|
-
//Clean up script binding. Favor detachEvent because of IE9
|
1700
|
-
//issue, see attachEvent/addEventListener comment elsewhere
|
1701
|
-
//in this file.
|
1702
|
-
if (node.detachEvent && !isOpera) {
|
1703
|
-
//Probably IE. If not it will throw an error, which will be
|
1704
|
-
//useful to know.
|
1705
|
-
node.detachEvent("onreadystatechange", req.onScriptLoad);
|
1706
|
-
} else {
|
1707
|
-
node.removeEventListener("load", req.onScriptLoad, false);
|
1708
|
-
}
|
1709
|
-
}
|
1710
|
-
};
|
1711
|
-
|
1712
|
-
/**
|
1713
|
-
* Attaches the script represented by the URL to the current
|
1714
|
-
* environment. Right now only supports browser loading,
|
1715
|
-
* but can be redefined in other environments to do the right thing.
|
1716
|
-
* @param {String} url the url of the script to attach.
|
1717
|
-
* @param {Object} context the context that wants the script.
|
1718
|
-
* @param {moduleName} the name of the module that is associated with the script.
|
1719
|
-
* @param {Function} [callback] optional callback, defaults to require.onScriptLoad
|
1720
|
-
* @param {String} [type] optional type, defaults to text/javascript
|
1721
|
-
*/
|
1722
|
-
req.attach = function (url, context, moduleName, callback, type) {
|
1723
|
-
var node, loaded;
|
1724
|
-
if (isBrowser) {
|
1725
|
-
//In the browser so use a script tag
|
1726
|
-
callback = callback || req.onScriptLoad;
|
1727
|
-
node = context && context.config && context.config.xhtml ?
|
1728
|
-
document.createElementNS("http://www.w3.org/1999/xhtml", "html:script") :
|
1729
|
-
document.createElement("script");
|
1730
|
-
node.type = type || "text/javascript";
|
1731
|
-
node.charset = "utf-8";
|
1732
|
-
//Use async so Gecko does not block on executing the script if something
|
1733
|
-
//like a long-polling comet tag is being run first. Gecko likes
|
1734
|
-
//to evaluate scripts in DOM order, even for dynamic scripts.
|
1735
|
-
//It will fetch them async, but only evaluate the contents in DOM
|
1736
|
-
//order, so a long-polling script tag can delay execution of scripts
|
1737
|
-
//after it. But telling Gecko we expect async gets us the behavior
|
1738
|
-
//we want -- execute it whenever it is finished downloading. Only
|
1739
|
-
//Helps Firefox 3.6+
|
1740
|
-
//Allow some URLs to not be fetched async. Mostly helps the order!
|
1741
|
-
//plugin
|
1742
|
-
node.async = !s.skipAsync[url];
|
1743
|
-
|
1744
|
-
if (context) {
|
1745
|
-
node.setAttribute("data-requirecontext", context.contextName);
|
1746
|
-
}
|
1747
|
-
node.setAttribute("data-requiremodule", moduleName);
|
1748
|
-
|
1749
|
-
//Set up load listener. Test attachEvent first because IE9 has
|
1750
|
-
//a subtle issue in its addEventListener and script onload firings
|
1751
|
-
//that do not match the behavior of all other browsers with
|
1752
|
-
//addEventListener support, which fire the onload event for a
|
1753
|
-
//script right after the script execution. See:
|
1754
|
-
//https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
|
1755
|
-
//UNFORTUNATELY Opera implements attachEvent but does not follow the script
|
1756
|
-
//script execution mode.
|
1757
|
-
if (node.attachEvent && !isOpera) {
|
1758
|
-
//Probably IE. IE (at least 6-8) do not fire
|
1759
|
-
//script onload right after executing the script, so
|
1760
|
-
//we cannot tie the anonymous define call to a name.
|
1761
|
-
//However, IE reports the script as being in "interactive"
|
1762
|
-
//readyState at the time of the define call.
|
1763
|
-
useInteractive = true;
|
1764
|
-
node.attachEvent("onreadystatechange", callback);
|
1765
|
-
} else {
|
1766
|
-
node.addEventListener("load", callback, false);
|
1767
|
-
}
|
1768
|
-
node.src = url;
|
1769
|
-
|
1770
|
-
//For some cache cases in IE 6-8, the script executes before the end
|
1771
|
-
//of the appendChild execution, so to tie an anonymous define
|
1772
|
-
//call to the module name (which is stored on the node), hold on
|
1773
|
-
//to a reference to this node, but clear after the DOM insertion.
|
1774
|
-
currentlyAddingScript = node;
|
1775
|
-
if (baseElement) {
|
1776
|
-
head.insertBefore(node, baseElement);
|
1777
|
-
} else {
|
1778
|
-
head.appendChild(node);
|
1779
|
-
}
|
1780
|
-
currentlyAddingScript = null;
|
1781
|
-
return node;
|
1782
|
-
} else if (isWebWorker) {
|
1783
|
-
//In a web worker, use importScripts. This is not a very
|
1784
|
-
//efficient use of importScripts, importScripts will block until
|
1785
|
-
//its script is downloaded and evaluated. However, if web workers
|
1786
|
-
//are in play, the expectation that a build has been done so that
|
1787
|
-
//only one script needs to be loaded anyway. This may need to be
|
1788
|
-
//reevaluated if other use cases become common.
|
1789
|
-
loaded = context.loaded;
|
1790
|
-
loaded[moduleName] = false;
|
1791
|
-
|
1792
|
-
importScripts(url);
|
1793
|
-
|
1794
|
-
//Account for anonymous modules
|
1795
|
-
context.completeLoad(moduleName);
|
1796
|
-
}
|
1797
|
-
return null;
|
1798
|
-
};
|
1799
|
-
|
1800
|
-
//Look for a data-main script attribute, which could also adjust the baseUrl.
|
1801
|
-
if (isBrowser) {
|
1802
|
-
//Figure out baseUrl. Get it from the script tag with require.js in it.
|
1803
|
-
scripts = document.getElementsByTagName("script");
|
1804
|
-
|
1805
|
-
for (i = scripts.length - 1; i > -1 && (script = scripts[i]); i--) {
|
1806
|
-
//Set the "head" where we can append children by
|
1807
|
-
//using the script's parent.
|
1808
|
-
if (!head) {
|
1809
|
-
head = script.parentNode;
|
1810
|
-
}
|
1811
|
-
|
1812
|
-
//Look for a data-main attribute to set main script for the page
|
1813
|
-
//to load. If it is there, the path to data main becomes the
|
1814
|
-
//baseUrl, if it is not already set.
|
1815
|
-
if ((dataMain = script.getAttribute('data-main'))) {
|
1816
|
-
if (!cfg.baseUrl) {
|
1817
|
-
//Pull off the directory of data-main for use as the
|
1818
|
-
//baseUrl.
|
1819
|
-
src = dataMain.split('/');
|
1820
|
-
mainScript = src.pop();
|
1821
|
-
subPath = src.length ? src.join('/') + '/' : './';
|
1822
|
-
|
1823
|
-
//Set final config.
|
1824
|
-
cfg.baseUrl = subPath;
|
1825
|
-
//Strip off any trailing .js since dataMain is now
|
1826
|
-
//like a module name.
|
1827
|
-
dataMain = mainScript.replace(jsSuffixRegExp, '');
|
1828
|
-
}
|
1829
|
-
|
1830
|
-
//Put the data-main script in the files to load.
|
1831
|
-
cfg.deps = cfg.deps ? cfg.deps.concat(dataMain) : [dataMain];
|
1832
|
-
|
1833
|
-
break;
|
1834
|
-
}
|
1835
|
-
}
|
1836
|
-
}
|
1837
|
-
|
1838
|
-
//Set baseUrl based on config.
|
1839
|
-
s.baseUrl = cfg.baseUrl;
|
1840
|
-
|
1841
|
-
//****** START page load functionality ****************
|
1842
|
-
/**
|
1843
|
-
* Sets the page as loaded and triggers check for all modules loaded.
|
1844
|
-
*/
|
1845
|
-
req.pageLoaded = function () {
|
1846
|
-
if (!s.isPageLoaded) {
|
1847
|
-
s.isPageLoaded = true;
|
1848
|
-
if (scrollIntervalId) {
|
1849
|
-
clearInterval(scrollIntervalId);
|
1850
|
-
}
|
1851
|
-
|
1852
|
-
//Part of a fix for FF < 3.6 where readyState was not set to
|
1853
|
-
//complete so libraries like jQuery that check for readyState
|
1854
|
-
//after page load where not getting initialized correctly.
|
1855
|
-
//Original approach suggested by Andrea Giammarchi:
|
1856
|
-
//http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
|
1857
|
-
//see other setReadyState reference for the rest of the fix.
|
1858
|
-
if (setReadyState) {
|
1859
|
-
document.readyState = "complete";
|
1860
|
-
}
|
1861
|
-
|
1862
|
-
req.callReady();
|
1863
|
-
}
|
1864
|
-
};
|
1865
|
-
|
1866
|
-
//See if there is nothing waiting across contexts, and if not, trigger
|
1867
|
-
//callReady.
|
1868
|
-
req.checkReadyState = function () {
|
1869
|
-
var contexts = s.contexts, prop;
|
1870
|
-
for (prop in contexts) {
|
1871
|
-
if (!(prop in empty)) {
|
1872
|
-
if (contexts[prop].waitCount) {
|
1873
|
-
return;
|
1874
|
-
}
|
1875
|
-
}
|
1876
|
-
}
|
1877
|
-
s.isDone = true;
|
1878
|
-
req.callReady();
|
1879
|
-
};
|
1880
|
-
|
1881
|
-
/**
|
1882
|
-
* Internal function that calls back any ready functions. If you are
|
1883
|
-
* integrating RequireJS with another library without require.ready support,
|
1884
|
-
* you can define this method to call your page ready code instead.
|
1885
|
-
*/
|
1886
|
-
req.callReady = function () {
|
1887
|
-
var callbacks = s.readyCalls, i, callback, contexts, context, prop;
|
1888
|
-
|
1889
|
-
if (s.isPageLoaded && s.isDone) {
|
1890
|
-
if (callbacks.length) {
|
1891
|
-
s.readyCalls = [];
|
1892
|
-
for (i = 0; (callback = callbacks[i]); i++) {
|
1893
|
-
callback();
|
1894
|
-
}
|
1895
|
-
}
|
1896
|
-
|
1897
|
-
//If jQuery with DOM ready delayed, release it now.
|
1898
|
-
contexts = s.contexts;
|
1899
|
-
for (prop in contexts) {
|
1900
|
-
if (!(prop in empty)) {
|
1901
|
-
context = contexts[prop];
|
1902
|
-
if (context.jQueryIncremented) {
|
1903
|
-
jQueryHoldReady(context.jQuery, false);
|
1904
|
-
context.jQueryIncremented = false;
|
1905
|
-
}
|
1906
|
-
}
|
1907
|
-
}
|
1908
|
-
}
|
1909
|
-
};
|
1910
|
-
|
1911
|
-
/**
|
1912
|
-
* Registers functions to call when the page is loaded
|
1913
|
-
*/
|
1914
|
-
req.ready = function (callback) {
|
1915
|
-
if (s.isPageLoaded && s.isDone) {
|
1916
|
-
callback();
|
1917
|
-
} else {
|
1918
|
-
s.readyCalls.push(callback);
|
1919
|
-
}
|
1920
|
-
return req;
|
1921
|
-
};
|
1922
|
-
|
1923
|
-
if (isBrowser) {
|
1924
|
-
if (document.addEventListener) {
|
1925
|
-
//Standards. Hooray! Assumption here that if standards based,
|
1926
|
-
//it knows about DOMContentLoaded.
|
1927
|
-
document.addEventListener("DOMContentLoaded", req.pageLoaded, false);
|
1928
|
-
window.addEventListener("load", req.pageLoaded, false);
|
1929
|
-
//Part of FF < 3.6 readystate fix (see setReadyState refs for more info)
|
1930
|
-
if (!document.readyState) {
|
1931
|
-
setReadyState = true;
|
1932
|
-
document.readyState = "loading";
|
1933
|
-
}
|
1934
|
-
} else if (window.attachEvent) {
|
1935
|
-
window.attachEvent("onload", req.pageLoaded);
|
1936
|
-
|
1937
|
-
//DOMContentLoaded approximation, as found by Diego Perini:
|
1938
|
-
//http://javascript.nwbox.com/IEContentLoaded/
|
1939
|
-
if (self === self.top) {
|
1940
|
-
scrollIntervalId = setInterval(function () {
|
1941
|
-
try {
|
1942
|
-
//From this ticket:
|
1943
|
-
//http://bugs.dojotoolkit.org/ticket/11106,
|
1944
|
-
//In IE HTML Application (HTA), such as in a selenium test,
|
1945
|
-
//javascript in the iframe can't see anything outside
|
1946
|
-
//of it, so self===self.top is true, but the iframe is
|
1947
|
-
//not the top window and doScroll will be available
|
1948
|
-
//before document.body is set. Test document.body
|
1949
|
-
//before trying the doScroll trick.
|
1950
|
-
if (document.body) {
|
1951
|
-
document.documentElement.doScroll("left");
|
1952
|
-
req.pageLoaded();
|
1953
|
-
}
|
1954
|
-
} catch (e) {}
|
1955
|
-
}, 30);
|
1956
|
-
}
|
1957
|
-
}
|
1958
|
-
|
1959
|
-
//Check if document already complete, and if so, just trigger page load
|
1960
|
-
//listeners. NOTE: does not work with Firefox before 3.6. To support
|
1961
|
-
//those browsers, manually call require.pageLoaded().
|
1962
|
-
if (document.readyState === "complete") {
|
1963
|
-
req.pageLoaded();
|
1964
|
-
}
|
1965
|
-
}
|
1966
|
-
//****** END page load functionality ****************
|
1967
|
-
|
1968
|
-
//Set up default context. If require was a configuration object, use that as base config.
|
1969
|
-
req(cfg);
|
1970
|
-
|
1971
|
-
//If modules are built into require.js, then need to make sure dependencies are
|
1972
|
-
//traced. Use a setTimeout in the browser world, to allow all the modules to register
|
1973
|
-
//themselves. In a non-browser env, assume that modules are not built into require.js,
|
1974
|
-
//which seems odd to do on the server.
|
1975
|
-
if (req.isAsync && typeof setTimeout !== "undefined") {
|
1976
|
-
ctx = s.contexts[(cfg.context || defContextName)];
|
1977
|
-
//Indicate that the script that includes require() is still loading,
|
1978
|
-
//so that require()'d dependencies are not traced until the end of the
|
1979
|
-
//file is parsed (approximated via the setTimeout call).
|
1980
|
-
ctx.requireWait = true;
|
1981
|
-
setTimeout(function () {
|
1982
|
-
ctx.requireWait = false;
|
1983
|
-
|
1984
|
-
//Any modules included with the require.js file will be in the
|
1985
|
-
//global queue, assign them to this context.
|
1986
|
-
ctx.takeGlobalQueue();
|
1987
|
-
|
1988
|
-
//Allow for jQuery to be loaded/already in the page, and if jQuery 1.4.3,
|
1989
|
-
//make sure to hold onto it for readyWait triggering.
|
1990
|
-
ctx.jQueryCheck();
|
1991
|
-
|
1992
|
-
if (!ctx.scriptCount) {
|
1993
|
-
ctx.resume();
|
1994
|
-
}
|
1995
|
-
req.checkReadyState();
|
1996
|
-
}, 0);
|
1997
|
-
}
|
1998
|
-
}());
|