|
1 /* |
|
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved. |
|
3 Code licensed under the BSD License: |
|
4 http://developer.yahoo.net/yui/license.txt |
|
5 version: 3.0.0 |
|
6 build: 1549 |
|
7 */ |
|
8 YUI.add('loader', function(Y) { |
|
9 |
|
10 (function() { |
|
11 /** |
|
12 * Loader dynamically loads script and css files. It includes the dependency |
|
13 * info for the version of the library in use, and will automatically pull in |
|
14 * dependencies for the modules requested. It supports rollup files and will |
|
15 * automatically use these when appropriate in order to minimize the number of |
|
16 * http connections required to load all of the dependencies. It can load the |
|
17 * files from the Yahoo! CDN, and it can utilize the combo service provided on |
|
18 * this network to reduce the number of http connections required to download |
|
19 * YUI files. |
|
20 * |
|
21 * @module loader |
|
22 */ |
|
23 |
|
24 /** |
|
25 * Loader dynamically loads script and css files. It includes the dependency |
|
26 * info for the version of the library in use, and will automatically pull in |
|
27 * dependencies for the modules requested. It supports rollup files and will |
|
28 * automatically use these when appropriate in order to minimize the number of |
|
29 * http connections required to load all of the dependencies. It can load the |
|
30 * files from the Yahoo! CDN, and it can utilize the combo service provided on |
|
31 * this network to reduce the number of http connections required to download |
|
32 * YUI files. |
|
33 * |
|
34 * While the loader can be instantiated by the end user, it normally is not. |
|
35 * @see YUI.use for the normal use case. The use function automatically will |
|
36 * pull in missing dependencies. |
|
37 * |
|
38 * @class Loader |
|
39 * @constructor |
|
40 * @param o an optional set of configuration options. Valid options: |
|
41 * <ul> |
|
42 * <li>base: |
|
43 * The base dir</li> |
|
44 * <li>secureBase: |
|
45 * The secure base dir (not implemented)</li> |
|
46 * <li>comboBase: |
|
47 * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?</li> |
|
48 * <li>root: |
|
49 * The root path to prepend to module names for the combo service. Ex: 2.5.2/build/</li> |
|
50 * <li>filter: |
|
51 * |
|
52 * A filter to apply to result urls. This filter will modify the default |
|
53 * path for all modules. The default path for the YUI library is the |
|
54 * minified version of the files (e.g., event-min.js). The filter property |
|
55 * can be a predefined filter or a custom filter. The valid predefined |
|
56 * filters are: |
|
57 * <dl> |
|
58 * <dt>DEBUG</dt> |
|
59 * <dd>Selects the debug versions of the library (e.g., event-debug.js). |
|
60 * This option will automatically include the Logger widget</dd> |
|
61 * <dt>RAW</dt> |
|
62 * <dd>Selects the non-minified version of the library (e.g., event.js).</dd> |
|
63 * </dl> |
|
64 * You can also define a custom filter, which must be an object literal |
|
65 * containing a search expression and a replace string: |
|
66 * <pre> |
|
67 * myFilter: { |
|
68 * 'searchExp': "-min\\.js", |
|
69 * 'replaceStr': "-debug.js" |
|
70 * } |
|
71 * </pre> |
|
72 * |
|
73 * </li> |
|
74 * <li>filters: per-component filter specification. If specified for a given component, this overrides the filter config</li> |
|
75 * <li>combine: |
|
76 * Use the YUI combo service to reduce the number of http connections required to load your dependencies</li> |
|
77 * <li>ignore: |
|
78 * A list of modules that should never be dynamically loaded</li> |
|
79 * <li>force: |
|
80 * A list of modules that should always be loaded when required, even if already present on the page</li> |
|
81 * <li>insertBefore: |
|
82 * Node or id for a node that should be used as the insertion point for new nodes</li> |
|
83 * <li>charset: |
|
84 * charset for dynamic nodes (deprecated, use jsAttributes or cssAttributes)</li> |
|
85 * <li>jsAttributes: object literal containing attributes to add to script nodes</li> |
|
86 * <li>cssAttributes: object literal containing attributes to add to link nodes</li> |
|
87 * <li>timeout: |
|
88 * number of milliseconds before a timeout occurs when dynamically loading nodes. in not set, there is no timeout</li> |
|
89 * <li>context: |
|
90 * execution context for all callbacks</li> |
|
91 * <li>onSuccess: |
|
92 * callback for the 'success' event</li> |
|
93 * <li>onFailure: callback for the 'failure' event</li> |
|
94 * <li>onCSS: callback for the 'CSSComplete' event. When loading YUI components with CSS |
|
95 * the CSS is loaded first, then the script. This provides a moment you can tie into to improve |
|
96 * the presentation of the page while the script is loading.</li> |
|
97 * <li>onTimeout: |
|
98 * callback for the 'timeout' event</li> |
|
99 * <li>onProgress: |
|
100 * callback executed each time a script or css file is loaded</li> |
|
101 * <li>modules: |
|
102 * A list of module definitions. See Loader.addModule for the supported module metadata</li> |
|
103 * </ul> |
|
104 */ |
|
105 |
|
106 /* |
|
107 * Global loader queue |
|
108 * @property _loaderQueue |
|
109 * @type Queue |
|
110 * @private |
|
111 */ |
|
112 YUI.Env._loaderQueue = YUI.Env._loaderQueue || new Y.Queue(); |
|
113 |
|
114 var NOT_FOUND = {}, |
|
115 GLOBAL_ENV = YUI.Env, |
|
116 GLOBAL_LOADED, |
|
117 BASE = 'base', |
|
118 CSS = 'css', |
|
119 JS = 'js', |
|
120 CSSRESET = 'cssreset', |
|
121 CSSFONTS = 'cssfonts', |
|
122 CSSGRIDS = 'cssgrids', |
|
123 CSSBASE = 'cssbase', |
|
124 CSS_AFTER = [CSSRESET, CSSFONTS, CSSGRIDS, |
|
125 'cssreset-context', 'cssfonts-context', 'cssgrids-context'], |
|
126 YUI_CSS = ['reset', 'fonts', 'grids', BASE], |
|
127 VERSION = Y.version, |
|
128 ROOT = VERSION + '/build/', |
|
129 CONTEXT = '-context', |
|
130 |
|
131 ANIMBASE = 'anim-base', |
|
132 ATTRIBUTE = 'attribute', |
|
133 ATTRIBUTEBASE = ATTRIBUTE + '-base', |
|
134 BASEBASE = 'base-base', |
|
135 DDDRAG = 'dd-drag', |
|
136 DOM = 'dom', |
|
137 DATASCHEMABASE = 'dataschema-base', |
|
138 DATASOURCELOCAL = 'datasource-local', |
|
139 DOMBASE = 'dom-base', |
|
140 DOMSTYLE = 'dom-style', |
|
141 DOMSCREEN = 'dom-screen', |
|
142 DUMP = 'dump', |
|
143 GET = 'get', |
|
144 EVENTBASE = 'event-base', |
|
145 EVENTCUSTOM = 'event-custom', |
|
146 EVENTCUSTOMBASE = 'event-custom-base', |
|
147 IOBASE = 'io-base', |
|
148 NODE = 'node', |
|
149 NODEBASE = 'node-base', |
|
150 NODESTYLE = 'node-style', |
|
151 NODESCREEN = 'node-screen', |
|
152 OOP = 'oop', |
|
153 PLUGINHOST = 'pluginhost', |
|
154 SELECTORCSS2 = 'selector-css2', |
|
155 SUBSTITUTE = 'substitute', |
|
156 WIDGET = 'widget', |
|
157 WIDGETPOSITION = 'widget-position', |
|
158 YUIBASE = 'yui-base', |
|
159 |
|
160 PLUGIN = 'plugin', |
|
161 |
|
162 META = { |
|
163 |
|
164 version: VERSION, |
|
165 |
|
166 root: ROOT, |
|
167 |
|
168 base: 'http://yui.yahooapis.com/' + ROOT, |
|
169 |
|
170 comboBase: 'http://yui.yahooapis.com/combo?', |
|
171 |
|
172 skin: { |
|
173 defaultSkin: 'sam', |
|
174 base: 'assets/skins/', |
|
175 path: 'skin.css', |
|
176 after: CSS_AFTER |
|
177 //rollup: 3 |
|
178 }, |
|
179 |
|
180 modules: { |
|
181 |
|
182 dom: { |
|
183 requires: [OOP], |
|
184 submodules: { |
|
185 |
|
186 'dom-base': { |
|
187 requires: [OOP] |
|
188 }, |
|
189 |
|
190 'dom-style': { |
|
191 requires: [DOMBASE] |
|
192 }, |
|
193 |
|
194 'dom-screen': { |
|
195 requires: [DOMBASE, DOMSTYLE] |
|
196 }, |
|
197 |
|
198 'selector-native': { |
|
199 requires: [DOMBASE] |
|
200 }, |
|
201 |
|
202 'selector-css2': { |
|
203 requires: ['selector-native'] |
|
204 }, |
|
205 |
|
206 'selector': { |
|
207 requires: [DOMBASE] |
|
208 } |
|
209 |
|
210 }, |
|
211 |
|
212 plugins: { |
|
213 'selector-css3': { |
|
214 requires: [SELECTORCSS2] |
|
215 } |
|
216 } |
|
217 }, |
|
218 |
|
219 node: { |
|
220 requires: [DOM, EVENTBASE], |
|
221 // expound: EVENT, |
|
222 |
|
223 submodules: { |
|
224 'node-base': { |
|
225 requires: [DOMBASE, SELECTORCSS2, EVENTBASE] |
|
226 }, |
|
227 |
|
228 'node-style': { |
|
229 requires: [DOMSTYLE, NODEBASE] |
|
230 }, |
|
231 |
|
232 'node-screen': { |
|
233 requires: [DOMSCREEN, NODEBASE] |
|
234 }, |
|
235 |
|
236 'node-pluginhost': { |
|
237 requires: [NODEBASE, PLUGINHOST] |
|
238 }, |
|
239 |
|
240 |
|
241 'node-event-delegate': { |
|
242 requires: [NODEBASE, 'event-delegate'] |
|
243 } |
|
244 }, |
|
245 |
|
246 plugins: { |
|
247 'node-event-simulate': { |
|
248 requires: [NODEBASE, 'event-simulate'] |
|
249 } |
|
250 } |
|
251 }, |
|
252 |
|
253 anim: { |
|
254 submodules: { |
|
255 |
|
256 'anim-base': { |
|
257 requires: [BASEBASE, NODESTYLE] |
|
258 }, |
|
259 |
|
260 'anim-color': { |
|
261 requires: [ANIMBASE] |
|
262 }, |
|
263 |
|
264 'anim-easing': { |
|
265 requires: [ANIMBASE] |
|
266 }, |
|
267 |
|
268 'anim-scroll': { |
|
269 requires: [ANIMBASE] |
|
270 }, |
|
271 |
|
272 'anim-xy': { |
|
273 requires: [ANIMBASE, NODESCREEN] |
|
274 }, |
|
275 |
|
276 'anim-curve': { |
|
277 requires: ['anim-xy'] |
|
278 }, |
|
279 |
|
280 'anim-node-plugin': { |
|
281 requires: ['node-pluginhost', ANIMBASE] |
|
282 } |
|
283 } |
|
284 }, |
|
285 |
|
286 attribute: { |
|
287 submodules: { |
|
288 'attribute-base': { |
|
289 requires: [EVENTCUSTOM] |
|
290 }, |
|
291 |
|
292 'attribute-complex': { |
|
293 requires: [ATTRIBUTEBASE] |
|
294 } |
|
295 } |
|
296 }, |
|
297 |
|
298 base: { |
|
299 submodules: { |
|
300 'base-base': { |
|
301 requires: [ATTRIBUTEBASE] |
|
302 }, |
|
303 |
|
304 'base-build': { |
|
305 requires: [BASEBASE] |
|
306 }, |
|
307 |
|
308 'base-pluginhost': { |
|
309 requires: [BASEBASE, PLUGINHOST] |
|
310 } |
|
311 } |
|
312 }, |
|
313 |
|
314 cache: { |
|
315 requires: [PLUGIN] |
|
316 }, |
|
317 |
|
318 compat: { |
|
319 requires: [NODE, DUMP, SUBSTITUTE] |
|
320 }, |
|
321 |
|
322 classnamemanager: { |
|
323 requires: [YUIBASE] |
|
324 }, |
|
325 |
|
326 collection: { |
|
327 requires: [OOP] |
|
328 }, |
|
329 |
|
330 console: { |
|
331 requires: ['yui-log', WIDGET, SUBSTITUTE], |
|
332 skinnable: true, |
|
333 plugins: { |
|
334 'console-filters': { |
|
335 requires: [PLUGIN, 'console'], |
|
336 skinnable: true |
|
337 } |
|
338 } |
|
339 }, |
|
340 |
|
341 cookie: { |
|
342 requires: [YUIBASE] |
|
343 }, |
|
344 |
|
345 dataschema:{ |
|
346 submodules: { |
|
347 'dataschema-base': { |
|
348 requires: [BASE] |
|
349 }, |
|
350 'dataschema-array': { |
|
351 requires: [DATASCHEMABASE] |
|
352 }, |
|
353 'dataschema-json': { |
|
354 requires: [DATASCHEMABASE, 'json'] |
|
355 }, |
|
356 'dataschema-text': { |
|
357 requires: [DATASCHEMABASE] |
|
358 }, |
|
359 'dataschema-xml': { |
|
360 requires: [DATASCHEMABASE] |
|
361 } |
|
362 } |
|
363 }, |
|
364 |
|
365 datasource:{ |
|
366 submodules: { |
|
367 'datasource-local': { |
|
368 requires: [BASE] |
|
369 }, |
|
370 'datasource-arrayschema': { |
|
371 requires: [DATASOURCELOCAL, PLUGIN, 'dataschema-array'] |
|
372 }, |
|
373 'datasource-cache': { |
|
374 requires: [DATASOURCELOCAL, 'cache'] |
|
375 }, |
|
376 'datasource-function': { |
|
377 requires: [DATASOURCELOCAL] |
|
378 }, |
|
379 'datasource-jsonschema': { |
|
380 requires: [DATASOURCELOCAL, PLUGIN, 'dataschema-json'] |
|
381 }, |
|
382 'datasource-polling': { |
|
383 requires: [DATASOURCELOCAL] |
|
384 }, |
|
385 'datasource-get': { |
|
386 requires: [DATASOURCELOCAL, GET] |
|
387 }, |
|
388 'datasource-textschema': { |
|
389 requires: [DATASOURCELOCAL, PLUGIN, 'dataschema-text'] |
|
390 }, |
|
391 'datasource-io': { |
|
392 requires: [DATASOURCELOCAL, IOBASE] |
|
393 }, |
|
394 'datasource-xmlschema': { |
|
395 requires: [DATASOURCELOCAL, PLUGIN, 'dataschema-xml'] |
|
396 } |
|
397 } |
|
398 }, |
|
399 |
|
400 datatype:{ |
|
401 submodules: { |
|
402 'datatype-date': { |
|
403 requires: [YUIBASE] |
|
404 }, |
|
405 'datatype-number': { |
|
406 requires: [YUIBASE] |
|
407 }, |
|
408 'datatype-xml': { |
|
409 requires: [YUIBASE] |
|
410 } |
|
411 } |
|
412 }, |
|
413 |
|
414 dd:{ |
|
415 submodules: { |
|
416 'dd-ddm-base': { |
|
417 requires: [NODE, BASE] |
|
418 }, |
|
419 'dd-ddm':{ |
|
420 requires: ['dd-ddm-base', 'event-resize'] |
|
421 }, |
|
422 'dd-ddm-drop':{ |
|
423 requires: ['dd-ddm'] |
|
424 }, |
|
425 'dd-drag':{ |
|
426 requires: ['dd-ddm-base'] |
|
427 }, |
|
428 'dd-drop':{ |
|
429 requires: ['dd-ddm-drop'] |
|
430 }, |
|
431 'dd-proxy':{ |
|
432 requires: [DDDRAG] |
|
433 }, |
|
434 'dd-constrain':{ |
|
435 requires: [DDDRAG] |
|
436 }, |
|
437 'dd-scroll':{ |
|
438 requires: [DDDRAG] |
|
439 }, |
|
440 'dd-plugin':{ |
|
441 requires: [DDDRAG], |
|
442 optional: ['dd-constrain', 'dd-proxy'] |
|
443 }, |
|
444 'dd-drop-plugin':{ |
|
445 requires: ['dd-drop'] |
|
446 } |
|
447 } |
|
448 }, |
|
449 |
|
450 dump: { |
|
451 requires: [YUIBASE] |
|
452 }, |
|
453 |
|
454 event: { |
|
455 expound: NODEBASE, |
|
456 submodules: { |
|
457 'event-base': { |
|
458 expound: NODEBASE, |
|
459 requires: [EVENTCUSTOMBASE] |
|
460 }, |
|
461 'event-delegate': { |
|
462 requires: [NODEBASE] |
|
463 }, |
|
464 'event-focus': { |
|
465 requires: [NODEBASE] |
|
466 }, |
|
467 'event-key': { |
|
468 requires: [NODEBASE] |
|
469 }, |
|
470 'event-mouseenter': { |
|
471 requires: [NODEBASE] |
|
472 }, |
|
473 'event-mousewheel': { |
|
474 requires: [NODEBASE] |
|
475 }, |
|
476 'event-resize': { |
|
477 requires: [NODEBASE] |
|
478 } |
|
479 } |
|
480 }, |
|
481 |
|
482 'event-custom': { |
|
483 submodules: { |
|
484 'event-custom-base': { |
|
485 requires: [OOP, 'yui-later'] |
|
486 }, |
|
487 'event-custom-complex': { |
|
488 requires: [EVENTCUSTOMBASE] |
|
489 } |
|
490 } |
|
491 }, |
|
492 |
|
493 'event-simulate': { |
|
494 requires: [EVENTBASE] |
|
495 }, |
|
496 |
|
497 'node-focusmanager': { |
|
498 requires: [ATTRIBUTE, NODE, PLUGIN, 'node-event-simulate', 'event-key', 'event-focus'] |
|
499 }, |
|
500 |
|
501 history: { |
|
502 requires: [NODE] |
|
503 }, |
|
504 |
|
505 imageloader: { |
|
506 requires: [BASEBASE, NODESTYLE, NODESCREEN] |
|
507 }, |
|
508 |
|
509 io:{ |
|
510 submodules: { |
|
511 |
|
512 'io-base': { |
|
513 requires: [EVENTCUSTOMBASE] |
|
514 }, |
|
515 |
|
516 'io-xdr': { |
|
517 requires: [IOBASE, 'datatype-xml'] |
|
518 }, |
|
519 |
|
520 'io-form': { |
|
521 requires: [IOBASE, NODEBASE, NODESTYLE] |
|
522 }, |
|
523 |
|
524 'io-upload-iframe': { |
|
525 requires: [IOBASE, NODEBASE] |
|
526 }, |
|
527 |
|
528 'io-queue': { |
|
529 requires: [IOBASE, 'queue-promote'] |
|
530 } |
|
531 } |
|
532 }, |
|
533 |
|
534 json: { |
|
535 submodules: { |
|
536 'json-parse': { |
|
537 requires: [YUIBASE] |
|
538 }, |
|
539 |
|
540 'json-stringify': { |
|
541 requires: [YUIBASE] |
|
542 } |
|
543 } |
|
544 }, |
|
545 |
|
546 loader: { |
|
547 requires: [GET] |
|
548 }, |
|
549 |
|
550 'node-menunav': { |
|
551 requires: [NODE, 'classnamemanager', PLUGIN, 'node-focusmanager'], |
|
552 skinnable: true |
|
553 }, |
|
554 |
|
555 oop: { |
|
556 requires: [YUIBASE] |
|
557 }, |
|
558 |
|
559 overlay: { |
|
560 requires: [WIDGET, WIDGETPOSITION, 'widget-position-ext', 'widget-stack', 'widget-stdmod'], |
|
561 skinnable: true |
|
562 }, |
|
563 |
|
564 plugin: { |
|
565 requires: [BASEBASE] |
|
566 }, |
|
567 |
|
568 pluginhost: { |
|
569 requires: [YUIBASE] |
|
570 }, |
|
571 |
|
572 profiler: { |
|
573 requires: [YUIBASE] |
|
574 }, |
|
575 |
|
576 'queue-promote': { |
|
577 requires: [YUIBASE] |
|
578 }, |
|
579 |
|
580 // deprecated package, replaced with async-queue |
|
581 'queue-run': { |
|
582 requires: [EVENTCUSTOM], |
|
583 path: 'async-queue/async-queue-min.js' |
|
584 }, |
|
585 |
|
586 'async-queue': { |
|
587 requires: [EVENTCUSTOM], |
|
588 supersedes: ['queue-run'] |
|
589 }, |
|
590 |
|
591 slider: { |
|
592 requires: [WIDGET, 'dd-constrain'], |
|
593 skinnable: true |
|
594 }, |
|
595 |
|
596 stylesheet: { |
|
597 requires: [YUIBASE] |
|
598 }, |
|
599 |
|
600 substitute: { |
|
601 optional: [DUMP] |
|
602 }, |
|
603 |
|
604 widget: { |
|
605 requires: [ATTRIBUTE, 'event-focus', BASE, NODE, 'classnamemanager'], |
|
606 plugins: { |
|
607 'widget-position': { }, |
|
608 'widget-position-ext': { |
|
609 requires: [WIDGETPOSITION] |
|
610 }, |
|
611 'widget-stack': { |
|
612 skinnable: true |
|
613 }, |
|
614 'widget-stdmod': { } |
|
615 }, |
|
616 skinnable: true |
|
617 }, |
|
618 |
|
619 yui: { |
|
620 submodules: { |
|
621 'yui-base': {}, |
|
622 get: {}, |
|
623 'yui-log': {}, |
|
624 'yui-later': {} |
|
625 } |
|
626 }, |
|
627 |
|
628 test: { |
|
629 requires: [SUBSTITUTE, NODE, 'json', 'event-simulate'] |
|
630 } |
|
631 |
|
632 } |
|
633 }, |
|
634 |
|
635 _path = Y.cached(function(dir, file, type) { |
|
636 return dir + '/' + file + '-min.' + (type || CSS); |
|
637 }), |
|
638 |
|
639 _queue = YUI.Env._loaderQueue, |
|
640 |
|
641 mods = META.modules, i, bname, mname, contextname, |
|
642 L = Y.Lang; |
|
643 |
|
644 // Create the metadata for both the regular and context-aware |
|
645 // versions of the YUI CSS foundation. |
|
646 for (i=0; i<YUI_CSS.length; i=i+1) { |
|
647 bname = YUI_CSS[i]; |
|
648 mname = CSS + bname; |
|
649 |
|
650 mods[mname] = { |
|
651 type: CSS, |
|
652 path: _path(mname, bname) |
|
653 }; |
|
654 |
|
655 // define -context module |
|
656 contextname = mname + CONTEXT; |
|
657 bname = bname + CONTEXT; |
|
658 |
|
659 mods[contextname] = { |
|
660 type: CSS, |
|
661 path: _path(mname, bname) |
|
662 }; |
|
663 |
|
664 if (mname == CSSGRIDS) { |
|
665 mods[mname].requires = [CSSFONTS]; |
|
666 mods[mname].optional = [CSSRESET]; |
|
667 mods[contextname].requires = [CSSFONTS + CONTEXT]; |
|
668 mods[contextname].optional = [CSSRESET + CONTEXT]; |
|
669 } else if (mname == CSSBASE) { |
|
670 mods[mname].after = CSS_AFTER; |
|
671 mods[contextname].after = CSS_AFTER; |
|
672 } |
|
673 } |
|
674 |
|
675 Y.Env.meta = META; |
|
676 |
|
677 GLOBAL_LOADED = GLOBAL_ENV._loaded; |
|
678 |
|
679 Y.Loader = function(o) { |
|
680 |
|
681 /** |
|
682 * Internal callback to handle multiple internal insert() calls |
|
683 * so that css is inserted prior to js |
|
684 * @property _internalCallback |
|
685 * @private |
|
686 */ |
|
687 // this._internalCallback = null; |
|
688 |
|
689 /** |
|
690 * Callback that will be executed when the loader is finished |
|
691 * with an insert |
|
692 * @method onSuccess |
|
693 * @type function |
|
694 */ |
|
695 // this.onSuccess = null; |
|
696 |
|
697 /** |
|
698 * Callback that will be executed if there is a failure |
|
699 * @method onFailure |
|
700 * @type function |
|
701 */ |
|
702 // this.onFailure = null; |
|
703 |
|
704 /** |
|
705 * Callback for the 'CSSComplete' event. When loading YUI components with CSS |
|
706 * the CSS is loaded first, then the script. This provides a moment you can tie into to improve |
|
707 * the presentation of the page while the script is loading. |
|
708 * @method onCSS |
|
709 * @type function |
|
710 */ |
|
711 // this.onCSS = null; |
|
712 |
|
713 /** |
|
714 * Callback executed each time a script or css file is loaded |
|
715 * @method onProgress |
|
716 * @type function |
|
717 */ |
|
718 // this.onProgress = null; |
|
719 |
|
720 /** |
|
721 * Callback that will be executed if a timeout occurs |
|
722 * @method onTimeout |
|
723 * @type function |
|
724 */ |
|
725 // this.onTimeout = null; |
|
726 |
|
727 /** |
|
728 * The execution context for all callbacks |
|
729 * @property context |
|
730 * @default {YUI} the YUI instance |
|
731 */ |
|
732 this.context = Y; |
|
733 |
|
734 /** |
|
735 * Data that is passed to all callbacks |
|
736 * @property data |
|
737 */ |
|
738 // this.data = null; |
|
739 |
|
740 /** |
|
741 * Node reference or id where new nodes should be inserted before |
|
742 * @property insertBefore |
|
743 * @type string|HTMLElement |
|
744 */ |
|
745 // this.insertBefore = null; |
|
746 |
|
747 /** |
|
748 * The charset attribute for inserted nodes |
|
749 * @property charset |
|
750 * @type string |
|
751 * @deprecated, use cssAttributes or jsAttributes |
|
752 */ |
|
753 // this.charset = null; |
|
754 |
|
755 /** |
|
756 * An object literal containing attributes to add to link nodes |
|
757 * @property cssAttributes |
|
758 * @type object |
|
759 */ |
|
760 // this.cssAttributes = null; |
|
761 |
|
762 /** |
|
763 * An object literal containing attributes to add to script nodes |
|
764 * @property jsAttributes |
|
765 * @type object |
|
766 */ |
|
767 // this.jsAttributes = null; |
|
768 |
|
769 /** |
|
770 * The base directory. |
|
771 * @property base |
|
772 * @type string |
|
773 * @default http://yui.yahooapis.com/[YUI VERSION]/build/ |
|
774 */ |
|
775 this.base = Y.Env.meta.base; |
|
776 |
|
777 /** |
|
778 * Base path for the combo service |
|
779 * @property comboBase |
|
780 * @type string |
|
781 * @default http://yui.yahooapis.com/combo? |
|
782 */ |
|
783 this.comboBase = Y.Env.meta.comboBase; |
|
784 |
|
785 /** |
|
786 * If configured, YUI JS resources will use the combo |
|
787 * handler |
|
788 * @property combine |
|
789 * @type boolean |
|
790 * @default true if a base dir isn't in the config |
|
791 */ |
|
792 this.combine = o.base && (o.base.indexOf( this.comboBase.substr(0, 20)) > -1); |
|
793 |
|
794 /** |
|
795 * Ignore modules registered on the YUI global |
|
796 * @property ignoreRegistered |
|
797 * @default false |
|
798 */ |
|
799 // this.ignoreRegistered = false; |
|
800 |
|
801 /** |
|
802 * Root path to prepend to module path for the combo |
|
803 * service |
|
804 * @property root |
|
805 * @type string |
|
806 * @default [YUI VERSION]/build/ |
|
807 */ |
|
808 this.root = Y.Env.meta.root; |
|
809 |
|
810 /** |
|
811 * Timeout value in milliseconds. If set, this value will be used by |
|
812 * the get utility. the timeout event will fire if |
|
813 * a timeout occurs. |
|
814 * @property timeout |
|
815 * @type int |
|
816 */ |
|
817 this.timeout = 0; |
|
818 |
|
819 /** |
|
820 * A list of modules that should not be loaded, even if |
|
821 * they turn up in the dependency tree |
|
822 * @property ignore |
|
823 * @type string[] |
|
824 */ |
|
825 // this.ignore = null; |
|
826 |
|
827 /** |
|
828 * A list of modules that should always be loaded, even |
|
829 * if they have already been inserted into the page. |
|
830 * @property force |
|
831 * @type string[] |
|
832 */ |
|
833 // this.force = null; |
|
834 |
|
835 this.forceMap = {}; |
|
836 |
|
837 /** |
|
838 * Should we allow rollups |
|
839 * @property allowRollup |
|
840 * @type boolean |
|
841 * @default true |
|
842 */ |
|
843 // this.allowRollup = true; |
|
844 |
|
845 /** |
|
846 * A filter to apply to result urls. This filter will modify the default |
|
847 * path for all modules. The default path for the YUI library is the |
|
848 * minified version of the files (e.g., event-min.js). The filter property |
|
849 * can be a predefined filter or a custom filter. The valid predefined |
|
850 * filters are: |
|
851 * <dl> |
|
852 * <dt>DEBUG</dt> |
|
853 * <dd>Selects the debug versions of the library (e.g., event-debug.js). |
|
854 * This option will automatically include the Logger widget</dd> |
|
855 * <dt>RAW</dt> |
|
856 * <dd>Selects the non-minified version of the library (e.g., event.js).</dd> |
|
857 * </dl> |
|
858 * You can also define a custom filter, which must be an object literal |
|
859 * containing a search expression and a replace string: |
|
860 * <pre> |
|
861 * myFilter: { |
|
862 * 'searchExp': "-min\\.js", |
|
863 * 'replaceStr': "-debug.js" |
|
864 * } |
|
865 * </pre> |
|
866 * @property filter |
|
867 * @type string|{searchExp: string, replaceStr: string} |
|
868 */ |
|
869 // this.filter = null; |
|
870 |
|
871 /** |
|
872 * per-component filter specification. If specified for a given component, this |
|
873 * overrides the filter config. |
|
874 * @property filters |
|
875 * @type object |
|
876 */ |
|
877 this.filters = {}; |
|
878 |
|
879 /** |
|
880 * The list of requested modules |
|
881 * @property required |
|
882 * @type {string: boolean} |
|
883 */ |
|
884 this.required = {}; |
|
885 |
|
886 /** |
|
887 * The library metadata |
|
888 * @property moduleInfo |
|
889 */ |
|
890 // this.moduleInfo = Y.merge(Y.Env.meta.moduleInfo); |
|
891 this.moduleInfo = {}; |
|
892 |
|
893 /** |
|
894 * Provides the information used to skin the skinnable components. |
|
895 * The following skin definition would result in 'skin1' and 'skin2' |
|
896 * being loaded for calendar (if calendar was requested), and |
|
897 * 'sam' for all other skinnable components: |
|
898 * |
|
899 * <code> |
|
900 * skin: { |
|
901 * |
|
902 * // The default skin, which is automatically applied if not |
|
903 * // overriden by a component-specific skin definition. |
|
904 * // Change this in to apply a different skin globally |
|
905 * defaultSkin: 'sam', |
|
906 * |
|
907 * // This is combined with the loader base property to get |
|
908 * // the default root directory for a skin. ex: |
|
909 * // http://yui.yahooapis.com/2.3.0/build/assets/skins/sam/ |
|
910 * base: 'assets/skins/', |
|
911 * |
|
912 * // The name of the rollup css file for the skin |
|
913 * path: 'skin.css', |
|
914 * |
|
915 * // The number of skinnable components requested that are |
|
916 * // required before using the rollup file rather than the |
|
917 * // individual component css files |
|
918 * rollup: 3, |
|
919 * |
|
920 * // Any component-specific overrides can be specified here, |
|
921 * // making it possible to load different skins for different |
|
922 * // components. It is possible to load more than one skin |
|
923 * // for a given component as well. |
|
924 * overrides: { |
|
925 * calendar: ['skin1', 'skin2'] |
|
926 * } |
|
927 * } |
|
928 * </code> |
|
929 * @property skin |
|
930 */ |
|
931 this.skin = Y.merge(Y.Env.meta.skin); |
|
932 |
|
933 var defaults = Y.Env.meta.modules, i, onPage = YUI.Env.mods; |
|
934 |
|
935 this._internal = true; |
|
936 for (i in defaults) { |
|
937 if (defaults.hasOwnProperty(i)) { |
|
938 this.addModule(defaults[i], i); |
|
939 } |
|
940 } |
|
941 |
|
942 for (i in onPage) { |
|
943 if (onPage.hasOwnProperty(i) && !this.moduleInfo[i] && onPage[i].details) { |
|
944 this.addModule(onPage[i].details, i); |
|
945 } |
|
946 } |
|
947 this._internal = false; |
|
948 |
|
949 /** |
|
950 * List of rollup files found in the library metadata |
|
951 * @property rollups |
|
952 */ |
|
953 // this.rollups = null; |
|
954 |
|
955 /** |
|
956 * Whether or not to load optional dependencies for |
|
957 * the requested modules |
|
958 * @property loadOptional |
|
959 * @type boolean |
|
960 * @default false |
|
961 */ |
|
962 // this.loadOptional = false; |
|
963 |
|
964 /** |
|
965 * All of the derived dependencies in sorted order, which |
|
966 * will be populated when either calculate() or insert() |
|
967 * is called |
|
968 * @property sorted |
|
969 * @type string[] |
|
970 */ |
|
971 this.sorted = []; |
|
972 |
|
973 /** |
|
974 * Set when beginning to compute the dependency tree. |
|
975 * Composed of what YUI reports to be loaded combined |
|
976 * with what has been loaded by any instance on the page |
|
977 * with the version number specified in the metadata. |
|
978 * @propery loaded |
|
979 * @type {string: boolean} |
|
980 */ |
|
981 this.loaded = GLOBAL_LOADED[VERSION]; |
|
982 |
|
983 /** |
|
984 * A list of modules to attach to the YUI instance when complete. |
|
985 * If not supplied, the sorted list of dependencies are applied. |
|
986 * @property attaching |
|
987 */ |
|
988 // this.attaching = null; |
|
989 |
|
990 /** |
|
991 * Flag to indicate the dependency tree needs to be recomputed |
|
992 * if insert is called again. |
|
993 * @property dirty |
|
994 * @type boolean |
|
995 * @default true |
|
996 */ |
|
997 this.dirty = true; |
|
998 |
|
999 /** |
|
1000 * List of modules inserted by the utility |
|
1001 * @property inserted |
|
1002 * @type {string: boolean} |
|
1003 */ |
|
1004 this.inserted = {}; |
|
1005 |
|
1006 /** |
|
1007 * List of skipped modules during insert() because the module |
|
1008 * was not defined |
|
1009 * @property skipped |
|
1010 */ |
|
1011 this.skipped = {}; |
|
1012 |
|
1013 |
|
1014 // Y.on('yui:load', this.loadNext, this); |
|
1015 |
|
1016 this._config(o); |
|
1017 |
|
1018 }; |
|
1019 |
|
1020 Y.Loader.prototype = { |
|
1021 |
|
1022 FILTER_DEFS: { |
|
1023 RAW: { |
|
1024 'searchExp': "-min\\.js", |
|
1025 'replaceStr': ".js" |
|
1026 }, |
|
1027 DEBUG: { |
|
1028 'searchExp': "-min\\.js", |
|
1029 'replaceStr': "-debug.js" |
|
1030 } |
|
1031 }, |
|
1032 |
|
1033 SKIN_PREFIX: "skin-", |
|
1034 |
|
1035 _config: function(o) { |
|
1036 |
|
1037 var i, j, val, f; |
|
1038 |
|
1039 // apply config values |
|
1040 if (o) { |
|
1041 for (i in o) { |
|
1042 if (o.hasOwnProperty(i)) { |
|
1043 val = o[i]; |
|
1044 if (i == 'require') { |
|
1045 this.require(val); |
|
1046 } else if (i == 'modules') { |
|
1047 |
|
1048 // add a hash of module definitions |
|
1049 for (j in val) { |
|
1050 if (val.hasOwnProperty(j)) { |
|
1051 this.addModule(val[j], j); |
|
1052 } |
|
1053 } |
|
1054 |
|
1055 } else { |
|
1056 this[i] = val; |
|
1057 } |
|
1058 } |
|
1059 } |
|
1060 } |
|
1061 |
|
1062 // fix filter |
|
1063 f = this.filter; |
|
1064 |
|
1065 if (L.isString(f)) { |
|
1066 f = f.toUpperCase(); |
|
1067 this.filterName = f; |
|
1068 this.filter = this.FILTER_DEFS[f]; |
|
1069 if (f == 'DEBUG') { |
|
1070 this.require('yui-log', 'dump'); |
|
1071 } |
|
1072 } |
|
1073 |
|
1074 }, |
|
1075 |
|
1076 /** |
|
1077 * Returns the skin module name for the specified skin name. If a |
|
1078 * module name is supplied, the returned skin module name is |
|
1079 * specific to the module passed in. |
|
1080 * @method formatSkin |
|
1081 * @param skin {string} the name of the skin |
|
1082 * @param mod {string} optional: the name of a module to skin |
|
1083 * @return {string} the full skin module name |
|
1084 */ |
|
1085 formatSkin: function(skin, mod) { |
|
1086 var s = this.SKIN_PREFIX + skin; |
|
1087 if (mod) { |
|
1088 s = s + "-" + mod; |
|
1089 } |
|
1090 |
|
1091 return s; |
|
1092 }, |
|
1093 |
|
1094 /* |
|
1095 * Reverses <code>formatSkin</code>, providing the skin name and |
|
1096 * module name if the string matches the pattern for skins. |
|
1097 * @method parseSkin |
|
1098 * @param mod {string} the module name to parse |
|
1099 * @return {skin: string, module: string} the parsed skin name |
|
1100 * and module name, or null if the supplied string does not match |
|
1101 * the skin pattern |
|
1102 * |
|
1103 * This isn't being used at the moment |
|
1104 * |
|
1105 */ |
|
1106 // parseSkin: function(mod) { |
|
1107 // |
|
1108 // if (mod.indexOf(this.SKIN_PREFIX) === 0) { |
|
1109 // var a = mod.split("-"); |
|
1110 // return {skin: a[1], module: a[2]}; |
|
1111 // } |
|
1112 // return null; |
|
1113 // }, |
|
1114 |
|
1115 /** |
|
1116 * Adds the skin def to the module info |
|
1117 * @method _addSkin |
|
1118 * @param skin {string} the name of the skin |
|
1119 * @param mod {string} the name of the module |
|
1120 * @param parent {string} parent module if this is a skin of a |
|
1121 * submodule or plugin |
|
1122 * @return {string} the module name for the skin |
|
1123 * @private |
|
1124 */ |
|
1125 _addSkin: function(skin, mod, parent) { |
|
1126 |
|
1127 var name = this.formatSkin(skin), |
|
1128 info = this.moduleInfo, |
|
1129 sinf = this.skin, |
|
1130 ext = info[mod] && info[mod].ext, |
|
1131 mdef, pkg; |
|
1132 |
|
1133 /* |
|
1134 // Add a module definition for the skin rollup css |
|
1135 // Y.log('ext? ' + mod + ": " + ext); |
|
1136 if (!info[name]) { |
|
1137 // Y.log('adding skin ' + name); |
|
1138 this.addModule({ |
|
1139 'name': name, |
|
1140 'type': 'css', |
|
1141 'path': sinf.base + skin + '/' + sinf.path, |
|
1142 //'supersedes': '*', |
|
1143 'after': sinf.after, |
|
1144 'rollup': sinf.rollup, |
|
1145 'ext': ext |
|
1146 }); |
|
1147 } |
|
1148 */ |
|
1149 |
|
1150 // Add a module definition for the module-specific skin css |
|
1151 if (mod) { |
|
1152 name = this.formatSkin(skin, mod); |
|
1153 if (!info[name]) { |
|
1154 mdef = info[mod]; |
|
1155 pkg = mdef.pkg || mod; |
|
1156 // Y.log('adding skin ' + name); |
|
1157 this.addModule({ |
|
1158 'name': name, |
|
1159 'type': 'css', |
|
1160 'after': sinf.after, |
|
1161 'path': (parent || pkg) + '/' + sinf.base + skin + '/' + mod + '.css', |
|
1162 'ext': ext |
|
1163 }); |
|
1164 } |
|
1165 } |
|
1166 |
|
1167 return name; |
|
1168 }, |
|
1169 |
|
1170 /** Add a new module to the component metadata. |
|
1171 * <dl> |
|
1172 * <dt>name:</dt> <dd>required, the component name</dd> |
|
1173 * <dt>type:</dt> <dd>required, the component type (js or css)</dd> |
|
1174 * <dt>path:</dt> <dd>required, the path to the script from "base"</dd> |
|
1175 * <dt>requires:</dt> <dd>array of modules required by this component</dd> |
|
1176 * <dt>optional:</dt> <dd>array of optional modules for this component</dd> |
|
1177 * <dt>supersedes:</dt> <dd>array of the modules this component replaces</dd> |
|
1178 * <dt>after:</dt> <dd>array of modules the components which, if present, should be sorted above this one</dd> |
|
1179 * <dt>rollup:</dt> <dd>the number of superseded modules required for automatic rollup</dd> |
|
1180 * <dt>fullpath:</dt> <dd>If fullpath is specified, this is used instead of the configured base + path</dd> |
|
1181 * <dt>skinnable:</dt> <dd>flag to determine if skin assets should automatically be pulled in</dd> |
|
1182 * <dt>submodules:</dt> <dd>a has of submodules</dd> |
|
1183 * </dl> |
|
1184 * @method addModule |
|
1185 * @param o An object containing the module data |
|
1186 * @param name the module name (optional), required if not in the module data |
|
1187 * @return {boolean} true if the module was added, false if |
|
1188 * the object passed in did not provide all required attributes |
|
1189 */ |
|
1190 addModule: function(o, name) { |
|
1191 |
|
1192 name = name || o.name; |
|
1193 o.name = name; |
|
1194 |
|
1195 if (!o || !o.name) { |
|
1196 return false; |
|
1197 } |
|
1198 |
|
1199 if (!o.type) { |
|
1200 o.type = JS; |
|
1201 } |
|
1202 |
|
1203 if (!o.path && !o.fullpath) { |
|
1204 // o.path = name + "/" + name + "-min." + o.type; |
|
1205 o.path = _path(name, name, o.type); |
|
1206 } |
|
1207 |
|
1208 o.ext = ('ext' in o) ? o.ext : (this._internal) ? false : true; |
|
1209 o.requires = o.requires || []; |
|
1210 |
|
1211 // Y.log('New module ' + name); |
|
1212 |
|
1213 this.moduleInfo[name] = o; |
|
1214 |
|
1215 // Handle submodule logic |
|
1216 var subs = o.submodules, i, l, sup, s, smod, plugins, plug; |
|
1217 if (subs) { |
|
1218 sup = []; |
|
1219 l = 0; |
|
1220 |
|
1221 for (i in subs) { |
|
1222 if (subs.hasOwnProperty(i)) { |
|
1223 s = subs[i]; |
|
1224 s.path = _path(name, i, o.type); |
|
1225 this.addModule(s, i); |
|
1226 sup.push(i); |
|
1227 |
|
1228 if (o.skinnable) { |
|
1229 smod = this._addSkin(this.skin.defaultSkin, i, name); |
|
1230 sup.push(smod.name); |
|
1231 } |
|
1232 |
|
1233 l++; |
|
1234 } |
|
1235 } |
|
1236 |
|
1237 o.supersedes = sup; |
|
1238 o.rollup = (l<4) ? l : Math.min(l-1, 4); |
|
1239 } |
|
1240 |
|
1241 plugins = o.plugins; |
|
1242 if (plugins) { |
|
1243 for (i in plugins) { |
|
1244 if (plugins.hasOwnProperty(i)) { |
|
1245 plug = plugins[i]; |
|
1246 plug.path = _path(name, i, o.type); |
|
1247 plug.requires = plug.requires || []; |
|
1248 // plug.requires.push(name); |
|
1249 this.addModule(plug, i); |
|
1250 if (o.skinnable) { |
|
1251 this._addSkin(this.skin.defaultSkin, i, name); |
|
1252 } |
|
1253 } |
|
1254 } |
|
1255 } |
|
1256 |
|
1257 this.dirty = true; |
|
1258 |
|
1259 return o; |
|
1260 }, |
|
1261 |
|
1262 /** |
|
1263 * Add a requirement for one or more module |
|
1264 * @method require |
|
1265 * @param what {string[] | string*} the modules to load |
|
1266 */ |
|
1267 require: function(what) { |
|
1268 var a = (typeof what === "string") ? arguments : what; |
|
1269 this.dirty = true; |
|
1270 Y.mix(this.required, Y.Array.hash(a)); |
|
1271 }, |
|
1272 |
|
1273 /** |
|
1274 * Returns an object containing properties for all modules required |
|
1275 * in order to load the requested module |
|
1276 * @method getRequires |
|
1277 * @param mod The module definition from moduleInfo |
|
1278 */ |
|
1279 getRequires: function(mod) { |
|
1280 |
|
1281 if (!mod) { |
|
1282 // Y.log('getRequires, no module'); |
|
1283 return []; |
|
1284 } |
|
1285 |
|
1286 if (!this.dirty && mod.expanded) { |
|
1287 // Y.log('already expanded'); |
|
1288 return mod.expanded; |
|
1289 } |
|
1290 |
|
1291 var i, d=[], r=mod.requires, o=mod.optional, |
|
1292 info=this.moduleInfo, m, j, add; |
|
1293 |
|
1294 for (i=0; i<r.length; i=i+1) { |
|
1295 // Y.log(mod.name + ' requiring ' + r[i]); |
|
1296 d.push(r[i]); |
|
1297 m = this.getModule(r[i]); |
|
1298 add = this.getRequires(m); |
|
1299 for (j=0;j<add.length;j=j+1) { |
|
1300 d.push(add[j]); |
|
1301 } |
|
1302 } |
|
1303 |
|
1304 // get the requirements from superseded modules, if any |
|
1305 r=mod.supersedes; |
|
1306 if (r) { |
|
1307 for (i=0; i<r.length; i=i+1) { |
|
1308 // Y.log(mod.name + ' requiring ' + r[i]); |
|
1309 d.push(r[i]); |
|
1310 m = this.getModule(r[i]); |
|
1311 add = this.getRequires(m); |
|
1312 for (j=0;j<add.length;j=j+1) { |
|
1313 d.push(add[j]); |
|
1314 } |
|
1315 } |
|
1316 } |
|
1317 |
|
1318 if (o && this.loadOptional) { |
|
1319 for (i=0; i<o.length; i=i+1) { |
|
1320 d.push(o[i]); |
|
1321 add = this.getRequires(info[o[i]]); |
|
1322 for (j=0;j<add.length;j=j+1) { |
|
1323 d.push(add[j]); |
|
1324 } |
|
1325 } |
|
1326 } |
|
1327 |
|
1328 mod.expanded = Y.Object.keys(Y.Array.hash(d)); |
|
1329 return mod.expanded; |
|
1330 }, |
|
1331 |
|
1332 |
|
1333 /** |
|
1334 * Returns a hash of module names the supplied module satisfies. |
|
1335 * @method getProvides |
|
1336 * @param name {string} The name of the module |
|
1337 * @return what this module provides |
|
1338 */ |
|
1339 getProvides: function(name) { |
|
1340 var m = this.getModule(name), o, s; |
|
1341 |
|
1342 if (!m) { |
|
1343 return NOT_FOUND; |
|
1344 } |
|
1345 |
|
1346 if (m && !m.provides) { |
|
1347 o = {}; |
|
1348 s = m.supersedes; |
|
1349 |
|
1350 if (s) { |
|
1351 Y.Array.each(s, function(v) { |
|
1352 Y.mix(o, this.getProvides(v)); |
|
1353 }, this); |
|
1354 } |
|
1355 |
|
1356 o[name] = true; |
|
1357 m.provides = o; |
|
1358 } |
|
1359 |
|
1360 return m.provides; |
|
1361 }, |
|
1362 |
|
1363 |
|
1364 /** |
|
1365 * Calculates the dependency tree, the result is stored in the sorted |
|
1366 * property |
|
1367 * @method calculate |
|
1368 * @param o optional options object |
|
1369 * @param type optional argument to prune modules |
|
1370 */ |
|
1371 calculate: function(o, type) { |
|
1372 if (o || type || this.dirty) { |
|
1373 this._config(o); |
|
1374 this._setup(); |
|
1375 this._explode(); |
|
1376 if (this.allowRollup && !this.combine) { |
|
1377 this._rollup(); |
|
1378 } |
|
1379 this._reduce(); |
|
1380 this._sort(); |
|
1381 |
|
1382 // Y.log("after calculate: " + this.sorted); |
|
1383 |
|
1384 this.dirty = false; |
|
1385 } |
|
1386 }, |
|
1387 |
|
1388 /** |
|
1389 * Investigates the current YUI configuration on the page. By default, |
|
1390 * modules already detected will not be loaded again unless a force |
|
1391 * option is encountered. Called by calculate() |
|
1392 * @method _setup |
|
1393 * @private |
|
1394 */ |
|
1395 _setup: function() { |
|
1396 |
|
1397 var info = this.moduleInfo, name, i, j, m, o, l, smod; |
|
1398 |
|
1399 // Create skin modules |
|
1400 for (name in info) { |
|
1401 if (info.hasOwnProperty(name)) { |
|
1402 m = info[name]; |
|
1403 if (m && m.skinnable) { |
|
1404 // Y.log("skinning: " + name); |
|
1405 o = this.skin.overrides; |
|
1406 if (o && o[name]) { |
|
1407 for (i=0; i<o[name].length; i=i+1) { |
|
1408 smod = this._addSkin(o[name][i], name); |
|
1409 } |
|
1410 } else { |
|
1411 smod = this._addSkin(this.skin.defaultSkin, name); |
|
1412 } |
|
1413 |
|
1414 m.requires.push(smod); |
|
1415 } |
|
1416 } |
|
1417 } |
|
1418 |
|
1419 l = Y.merge(this.inserted); // shallow clone |
|
1420 |
|
1421 // available modules |
|
1422 if (!this.ignoreRegistered) { |
|
1423 Y.mix(l, GLOBAL_ENV.mods); |
|
1424 } |
|
1425 |
|
1426 // Y.log("Already loaded stuff: " + L.dump(l, 0)); |
|
1427 |
|
1428 // add the ignore list to the list of loaded packages |
|
1429 if (this.ignore) { |
|
1430 // OU.appendArray(l, this.ignore); |
|
1431 Y.mix(l, Y.Array.hash(this.ignore)); |
|
1432 } |
|
1433 |
|
1434 // expand the list to include superseded modules |
|
1435 for (j in l) { |
|
1436 // Y.log("expanding: " + j); |
|
1437 if (l.hasOwnProperty(j)) { |
|
1438 Y.mix(l, this.getProvides(j)); |
|
1439 } |
|
1440 } |
|
1441 |
|
1442 // remove modules on the force list from the loaded list |
|
1443 if (this.force) { |
|
1444 for (i=0; i<this.force.length; i=i+1) { |
|
1445 if (this.force[i] in l) { |
|
1446 delete l[this.force[i]]; |
|
1447 } |
|
1448 } |
|
1449 } |
|
1450 |
|
1451 // Y.log("loaded expanded: " + L.dump(l, 0)); |
|
1452 |
|
1453 Y.mix(this.loaded, l); |
|
1454 |
|
1455 // this.loaded = l; |
|
1456 |
|
1457 }, |
|
1458 |
|
1459 |
|
1460 /** |
|
1461 * Inspects the required modules list looking for additional |
|
1462 * dependencies. Expands the required list to include all |
|
1463 * required modules. Called by calculate() |
|
1464 * @method _explode |
|
1465 * @private |
|
1466 */ |
|
1467 _explode: function() { |
|
1468 |
|
1469 var r = this.required, m, reqs; |
|
1470 |
|
1471 Y.Object.each(r, function(v, name) { |
|
1472 |
|
1473 m = this.getModule(name); |
|
1474 |
|
1475 var expound = m && m.expound; |
|
1476 // Y.log('exploding ' + i); |
|
1477 |
|
1478 if (m) { |
|
1479 |
|
1480 if (expound) { |
|
1481 r[expound] = this.getModule(expound); |
|
1482 reqs = this.getRequires(r[expound]); |
|
1483 Y.mix(r, Y.Array.hash(reqs)); |
|
1484 } |
|
1485 |
|
1486 reqs = this.getRequires(m); |
|
1487 |
|
1488 // Y.log('via explode: ' + reqs); |
|
1489 Y.mix(r, Y.Array.hash(reqs)); |
|
1490 } |
|
1491 |
|
1492 }, this); |
|
1493 }, |
|
1494 |
|
1495 getModule: function(name) { |
|
1496 |
|
1497 var m = this.moduleInfo[name]; |
|
1498 |
|
1499 // create the default module |
|
1500 // if (!m) { |
|
1501 // Y.log('Module does not exist: ' + name + ', creating with defaults'); |
|
1502 // m = this.addModule({ext: false}, name); |
|
1503 // } |
|
1504 |
|
1505 return m; |
|
1506 }, |
|
1507 |
|
1508 /** |
|
1509 * Look for rollup packages to determine if all of the modules a |
|
1510 * rollup supersedes are required. If so, include the rollup to |
|
1511 * help reduce the total number of connections required. Called |
|
1512 * by calculate() |
|
1513 * @method _rollup |
|
1514 * @private |
|
1515 */ |
|
1516 _rollup: function() { |
|
1517 var i, j, m, s, rollups={}, r=this.required, roll, |
|
1518 info = this.moduleInfo, rolled, c; |
|
1519 |
|
1520 // find and cache rollup modules |
|
1521 if (this.dirty || !this.rollups) { |
|
1522 for (i in info) { |
|
1523 if (info.hasOwnProperty(i)) { |
|
1524 m = this.getModule(i); |
|
1525 // if (m && m.rollup && m.supersedes) { |
|
1526 if (m && m.rollup) { |
|
1527 rollups[i] = m; |
|
1528 } |
|
1529 } |
|
1530 } |
|
1531 |
|
1532 this.rollups = rollups; |
|
1533 this.forceMap = (this.force) ? Y.Array.hash(this.force) : {}; |
|
1534 } |
|
1535 |
|
1536 // make as many passes as needed to pick up rollup rollups |
|
1537 for (;;) { |
|
1538 rolled = false; |
|
1539 |
|
1540 // go through the rollup candidates |
|
1541 for (i in rollups) { |
|
1542 |
|
1543 if (rollups.hasOwnProperty(i)) { |
|
1544 |
|
1545 // there can be only one, unless forced |
|
1546 if (!r[i] && ((!this.loaded[i]) || this.forceMap[i])) { |
|
1547 m = this.getModule(i); |
|
1548 s = m.supersedes || []; |
|
1549 roll = false; |
|
1550 |
|
1551 // @TODO remove continue |
|
1552 if (!m.rollup) { |
|
1553 continue; |
|
1554 } |
|
1555 |
|
1556 c = 0; |
|
1557 |
|
1558 // check the threshold |
|
1559 for (j=0;j<s.length;j=j+1) { |
|
1560 |
|
1561 |
|
1562 // if the superseded module is loaded, we can't load the rollup |
|
1563 // unless it has been forced |
|
1564 if (this.loaded[s[j]] && !this.forceMap[s[j]]) { |
|
1565 roll = false; |
|
1566 break; |
|
1567 // increment the counter if this module is required. if we are |
|
1568 // beyond the rollup threshold, we will use the rollup module |
|
1569 } else if (r[s[j]]) { |
|
1570 c++; |
|
1571 // Y.log("adding to thresh: " + c + ", " + s[j]); |
|
1572 roll = (c >= m.rollup); |
|
1573 if (roll) { |
|
1574 // Y.log("over thresh " + c + ", " + s[j]); |
|
1575 break; |
|
1576 } |
|
1577 } |
|
1578 } |
|
1579 |
|
1580 if (roll) { |
|
1581 // Y.log("adding rollup: " + i); |
|
1582 // add the rollup |
|
1583 r[i] = true; |
|
1584 rolled = true; |
|
1585 |
|
1586 // expand the rollup's dependencies |
|
1587 this.getRequires(m); |
|
1588 } |
|
1589 } |
|
1590 } |
|
1591 } |
|
1592 |
|
1593 // if we made it here w/o rolling up something, we are done |
|
1594 if (!rolled) { |
|
1595 break; |
|
1596 } |
|
1597 } |
|
1598 }, |
|
1599 |
|
1600 /** |
|
1601 * Remove superceded modules and loaded modules. Called by |
|
1602 * calculate() after we have the mega list of all dependencies |
|
1603 * @method _reduce |
|
1604 * @private |
|
1605 */ |
|
1606 _reduce: function() { |
|
1607 var i, j, s, m, r=this.required, type = this.loadType; |
|
1608 for (i in r) { |
|
1609 if (r.hasOwnProperty(i)) { |
|
1610 m = this.getModule(i); |
|
1611 // remove if already loaded |
|
1612 if ((this.loaded[i] && (!this.forceMap[i]) && !this.ignoreRegistered) || (type && m && m.type != type)) { |
|
1613 delete r[i]; |
|
1614 // remove anything this module supersedes |
|
1615 } else { |
|
1616 |
|
1617 s = m && m.supersedes; |
|
1618 if (s) { |
|
1619 for (j=0; j<s.length; j=j+1) { |
|
1620 if (s[j] in r) { |
|
1621 delete r[s[j]]; |
|
1622 } |
|
1623 } |
|
1624 } |
|
1625 } |
|
1626 } |
|
1627 } |
|
1628 }, |
|
1629 |
|
1630 _attach: function() { |
|
1631 // this is the full list of items the YUI needs attached, |
|
1632 // which is needed if some dependencies are already on |
|
1633 // the page without their dependencies. |
|
1634 if (this.attaching) { |
|
1635 Y.log('attaching Y supplied deps: ' + this.attaching, "info", "loader"); |
|
1636 Y._attach(this.attaching); |
|
1637 } else { |
|
1638 Y.log('attaching sorted list: ' + this.sorted, "info", "loader"); |
|
1639 Y._attach(this.sorted); |
|
1640 } |
|
1641 |
|
1642 // this._pushEvents(); |
|
1643 |
|
1644 }, |
|
1645 |
|
1646 _finish: function() { |
|
1647 _queue.running = false; |
|
1648 this._continue(); |
|
1649 }, |
|
1650 |
|
1651 _onSuccess: function() { |
|
1652 |
|
1653 Y.log('loader successful: ' + Y.id, "info", "loader"); |
|
1654 |
|
1655 this._attach(); |
|
1656 |
|
1657 var skipped = this.skipped, i, f; |
|
1658 |
|
1659 for (i in skipped) { |
|
1660 if (skipped.hasOwnProperty(i)) { |
|
1661 delete this.inserted[i]; |
|
1662 } |
|
1663 } |
|
1664 |
|
1665 this.skipped = {}; |
|
1666 |
|
1667 f = this.onSuccess; |
|
1668 |
|
1669 if (f) { |
|
1670 f.call(this.context, { |
|
1671 msg: 'success', |
|
1672 data: this.data, |
|
1673 success: true |
|
1674 }); |
|
1675 } |
|
1676 |
|
1677 this._finish(); |
|
1678 |
|
1679 }, |
|
1680 |
|
1681 _onFailure: function(o) { |
|
1682 |
|
1683 Y.log('load error: ' + o.msg + ', ' + Y.id, "error", "loader"); |
|
1684 |
|
1685 this._attach(); |
|
1686 |
|
1687 var f = this.onFailure; |
|
1688 if (f) { |
|
1689 f.call(this.context, { |
|
1690 msg: 'failure: ' + o.msg, |
|
1691 data: this.data, |
|
1692 success: false |
|
1693 }); |
|
1694 } |
|
1695 |
|
1696 this._finish(); |
|
1697 }, |
|
1698 |
|
1699 _onTimeout: function() { |
|
1700 |
|
1701 Y.log('loader timeout: ' + Y.id, "error", "loader"); |
|
1702 |
|
1703 this._attach(); |
|
1704 |
|
1705 var f = this.onTimeout; |
|
1706 if (f) { |
|
1707 f.call(this.context, { |
|
1708 msg: 'timeout', |
|
1709 data: this.data, |
|
1710 success: false |
|
1711 }); |
|
1712 } |
|
1713 |
|
1714 this._finish(); |
|
1715 }, |
|
1716 |
|
1717 /** |
|
1718 * Sorts the dependency tree. The last step of calculate() |
|
1719 * @method _sort |
|
1720 * @private |
|
1721 */ |
|
1722 _sort: function() { |
|
1723 |
|
1724 // create an indexed list |
|
1725 var s = Y.Object.keys(this.required), |
|
1726 info = this.moduleInfo, |
|
1727 loaded = this.loaded, |
|
1728 done = {}, |
|
1729 p=0, l, a, b, j, k, moved, doneKey, |
|
1730 |
|
1731 // returns true if b is not loaded, and is required |
|
1732 // directly or by means of modules it supersedes. |
|
1733 requires = Y.cached(function(mod1, mod2) { |
|
1734 |
|
1735 var m = info[mod1], i, r, after, other = info[mod2], s; |
|
1736 |
|
1737 if (loaded[mod2] || !m || !other) { |
|
1738 return false; |
|
1739 } |
|
1740 |
|
1741 r = m.expanded; |
|
1742 after = m.after; |
|
1743 |
|
1744 // check if this module requires the other directly |
|
1745 if (r && Y.Array.indexOf(r, mod2) > -1) { |
|
1746 return true; |
|
1747 } |
|
1748 |
|
1749 // check if this module should be sorted after the other |
|
1750 if (after && Y.Array.indexOf(after, mod2) > -1) { |
|
1751 return true; |
|
1752 } |
|
1753 |
|
1754 // check if this module requires one the other supersedes |
|
1755 s = info[mod2] && info[mod2].supersedes; |
|
1756 if (s) { |
|
1757 for (i=0; i<s.length; i=i+1) { |
|
1758 if (requires(mod1, s[i])) { |
|
1759 return true; |
|
1760 } |
|
1761 } |
|
1762 } |
|
1763 |
|
1764 // external css files should be sorted below yui css |
|
1765 if (m.ext && m.type == CSS && !other.ext && other.type == CSS) { |
|
1766 return true; |
|
1767 } |
|
1768 |
|
1769 return false; |
|
1770 }); |
|
1771 |
|
1772 // keep going until we make a pass without moving anything |
|
1773 for (;;) { |
|
1774 |
|
1775 l = s.length; |
|
1776 moved = false; |
|
1777 |
|
1778 // start the loop after items that are already sorted |
|
1779 for (j=p; j<l; j=j+1) { |
|
1780 |
|
1781 // check the next module on the list to see if its |
|
1782 // dependencies have been met |
|
1783 a = s[j]; |
|
1784 |
|
1785 // check everything below current item and move if we |
|
1786 // find a requirement for the current item |
|
1787 for (k=j+1; k<l; k=k+1) { |
|
1788 doneKey = a + s[k]; |
|
1789 if (!done[doneKey] && requires(a, s[k])) { |
|
1790 |
|
1791 // extract the dependency so we can move it up |
|
1792 b = s.splice(k, 1); |
|
1793 |
|
1794 // insert the dependency above the item that |
|
1795 // requires it |
|
1796 s.splice(j, 0, b[0]); |
|
1797 |
|
1798 // only swap two dependencies once to short circut |
|
1799 // circular dependencies |
|
1800 done[doneKey] = true; |
|
1801 |
|
1802 // keep working |
|
1803 moved = true; |
|
1804 |
|
1805 break; |
|
1806 } |
|
1807 } |
|
1808 |
|
1809 // jump out of loop if we moved something |
|
1810 if (moved) { |
|
1811 break; |
|
1812 // this item is sorted, move our pointer and keep going |
|
1813 } else { |
|
1814 p = p + 1; |
|
1815 } |
|
1816 } |
|
1817 |
|
1818 // when we make it here and moved is false, we are |
|
1819 // finished sorting |
|
1820 if (!moved) { |
|
1821 break; |
|
1822 } |
|
1823 |
|
1824 } |
|
1825 |
|
1826 this.sorted = s; |
|
1827 }, |
|
1828 |
|
1829 _insert: function(source, o, type) { |
|
1830 |
|
1831 // Y.log('private _insert() ' + (type || '') + ', ' + Y.id, "info", "loader"); |
|
1832 |
|
1833 // restore the state at the time of the request |
|
1834 if (source) { |
|
1835 this._config(source); |
|
1836 } |
|
1837 |
|
1838 // build the dependency list |
|
1839 this.calculate(o); // don't include type so we can process CSS and script in |
|
1840 // one pass when the type is not specified. |
|
1841 this.loadType = type; |
|
1842 |
|
1843 if (!type) { |
|
1844 |
|
1845 var self = this; |
|
1846 |
|
1847 // Y.log("trying to load css first"); |
|
1848 this._internalCallback = function() { |
|
1849 var f = self.onCSS; |
|
1850 if (f) { |
|
1851 f.call(self.context, Y); |
|
1852 } |
|
1853 self._internalCallback = null; |
|
1854 self._insert(null, null, JS); |
|
1855 }; |
|
1856 |
|
1857 // _queue.running = false; |
|
1858 this._insert(null, null, CSS); |
|
1859 |
|
1860 return; |
|
1861 } |
|
1862 |
|
1863 |
|
1864 // set a flag to indicate the load has started |
|
1865 this._loading = true; |
|
1866 |
|
1867 // flag to indicate we are done with the combo service |
|
1868 // and any additional files will need to be loaded |
|
1869 // individually |
|
1870 this._combineComplete = {}; |
|
1871 |
|
1872 |
|
1873 // start the load |
|
1874 this.loadNext(); |
|
1875 |
|
1876 }, |
|
1877 |
|
1878 _continue: function() { |
|
1879 if (!(_queue.running) && _queue.size() > 0) { |
|
1880 _queue.running = true; |
|
1881 _queue.next()(); |
|
1882 } |
|
1883 }, |
|
1884 |
|
1885 /** |
|
1886 * inserts the requested modules and their dependencies. |
|
1887 * <code>type</code> can be "js" or "css". Both script and |
|
1888 * css are inserted if type is not provided. |
|
1889 * @method insert |
|
1890 * @param o optional options object |
|
1891 * @param type {string} the type of dependency to insert |
|
1892 */ |
|
1893 insert: function(o, type) { |
|
1894 |
|
1895 Y.log('public insert() ' + (type || '') + ', ' + Y.id, "info", "loader"); |
|
1896 |
|
1897 var self = this, copy = Y.merge(this, true); |
|
1898 |
|
1899 delete copy.require; |
|
1900 delete copy.dirty; |
|
1901 |
|
1902 _queue.add(function() { |
|
1903 self._insert(copy, o, type); |
|
1904 }); |
|
1905 |
|
1906 this._continue(); |
|
1907 |
|
1908 }, |
|
1909 |
|
1910 /** |
|
1911 * Executed every time a module is loaded, and if we are in a load |
|
1912 * cycle, we attempt to load the next script. Public so that it |
|
1913 * is possible to call this if using a method other than |
|
1914 * Y.register to determine when scripts are fully loaded |
|
1915 * @method loadNext |
|
1916 * @param mname {string} optional the name of the module that has |
|
1917 * been loaded (which is usually why it is time to load the next |
|
1918 * one) |
|
1919 */ |
|
1920 loadNext: function(mname) { |
|
1921 |
|
1922 // It is possible that this function is executed due to something |
|
1923 // else one the page loading a YUI module. Only react when we |
|
1924 // are actively loading something |
|
1925 if (!this._loading) { |
|
1926 return; |
|
1927 } |
|
1928 |
|
1929 var s, len, i, m, url, self=this, type=this.loadType, fn, msg, attr, |
|
1930 callback=function(o) { |
|
1931 Y.log('Combo complete: ' + o.data, "info", "loader"); |
|
1932 this._combineComplete[type] = true; |
|
1933 |
|
1934 var c=this._combining, len=c.length, i; |
|
1935 |
|
1936 for (i=0; i<len; i=i+1) { |
|
1937 this.inserted[c[i]] = true; |
|
1938 } |
|
1939 |
|
1940 this.loadNext(o.data); |
|
1941 }, |
|
1942 onsuccess=function(o) { |
|
1943 // Y.log('loading next, just loaded' + o.data); |
|
1944 self.loadNext(o.data); |
|
1945 }; |
|
1946 |
|
1947 // @TODO this will need to handle the two phase insert when |
|
1948 // CSS support is added |
|
1949 if (this.combine && (!this._combineComplete[type])) { |
|
1950 |
|
1951 this._combining = []; |
|
1952 s=this.sorted; |
|
1953 len=s.length; |
|
1954 url=this.comboBase; |
|
1955 |
|
1956 |
|
1957 for (i=0; i<len; i=i+1) { |
|
1958 m = this.getModule(s[i]); |
|
1959 // Do not try to combine non-yui JS |
|
1960 if (m && (m.type === type) && !m.ext) { |
|
1961 url += this.root + m.path; |
|
1962 if (i < len-1) { |
|
1963 url += '&'; |
|
1964 } |
|
1965 |
|
1966 this._combining.push(s[i]); |
|
1967 } |
|
1968 } |
|
1969 |
|
1970 if (this._combining.length) { |
|
1971 |
|
1972 Y.log('Attempting to use combo: ' + this._combining, "info", "loader"); |
|
1973 |
|
1974 // if (m.type === CSS) { |
|
1975 if (type === CSS) { |
|
1976 fn = Y.Get.css; |
|
1977 attr = this.cssAttributes; |
|
1978 } else { |
|
1979 fn = Y.Get.script; |
|
1980 attr = this.jsAttributes; |
|
1981 } |
|
1982 |
|
1983 // @TODO get rid of the redundant Get code |
|
1984 fn(this._filter(url), { |
|
1985 data: this._loading, |
|
1986 onSuccess: callback, |
|
1987 onFailure: this._onFailure, |
|
1988 onTimeout: this._onTimeout, |
|
1989 insertBefore: this.insertBefore, |
|
1990 charset: this.charset, |
|
1991 attributes: attr, |
|
1992 timeout: this.timeout, |
|
1993 autopurge: false, |
|
1994 context: self |
|
1995 }); |
|
1996 |
|
1997 return; |
|
1998 |
|
1999 } else { |
|
2000 this._combineComplete[type] = true; |
|
2001 } |
|
2002 } |
|
2003 |
|
2004 if (mname) { |
|
2005 |
|
2006 // if the module that was just loaded isn't what we were expecting, |
|
2007 // continue to wait |
|
2008 if (mname !== this._loading) { |
|
2009 return; |
|
2010 } |
|
2011 |
|
2012 Y.log("loadNext executing, just loaded " + mname + ", " + Y.id, "info", "loader"); |
|
2013 |
|
2014 // The global handler that is called when each module is loaded |
|
2015 // will pass that module name to this function. Storing this |
|
2016 // data to avoid loading the same module multiple times |
|
2017 this.inserted[mname] = true; |
|
2018 this.loaded[mname] = true; |
|
2019 |
|
2020 if (this.onProgress) { |
|
2021 this.onProgress.call(this.context, { |
|
2022 name: mname, |
|
2023 data: this.data |
|
2024 }); |
|
2025 } |
|
2026 |
|
2027 |
|
2028 } |
|
2029 |
|
2030 s=this.sorted; |
|
2031 len=s.length; |
|
2032 |
|
2033 for (i=0; i<len; i=i+1) { |
|
2034 |
|
2035 // this.inserted keeps track of what the loader has loaded. |
|
2036 // move on if this item is done. |
|
2037 if (s[i] in this.inserted) { |
|
2038 // Y.log(s[i] + " alread loaded "); |
|
2039 continue; |
|
2040 } |
|
2041 |
|
2042 // Because rollups will cause multiple load notifications |
|
2043 // from Y, loadNext may be called multiple times for |
|
2044 // the same module when loading a rollup. We can safely |
|
2045 // skip the subsequent requests |
|
2046 if (s[i] === this._loading) { |
|
2047 Y.log("still loading " + s[i] + ", waiting", "info", "loader"); |
|
2048 return; |
|
2049 } |
|
2050 |
|
2051 // log("inserting " + s[i]); |
|
2052 m = this.getModule(s[i]); |
|
2053 |
|
2054 if (!m) { |
|
2055 |
|
2056 msg = "Undefined module " + s[i] + " skipped"; |
|
2057 Y.log(msg, 'warn', 'loader'); |
|
2058 this.inserted[s[i]] = true; |
|
2059 this.skipped[s[i]] = true; |
|
2060 continue; |
|
2061 |
|
2062 } |
|
2063 |
|
2064 |
|
2065 // The load type is stored to offer the possibility to load |
|
2066 // the css separately from the script. |
|
2067 if (!type || type === m.type) { |
|
2068 this._loading = s[i]; |
|
2069 Y.log("attempting to load " + s[i] + ", " + this.base, "info", "loader"); |
|
2070 |
|
2071 if (m.type === CSS) { |
|
2072 fn = Y.Get.css; |
|
2073 attr = this.cssAttributes; |
|
2074 } else { |
|
2075 fn = Y.Get.script; |
|
2076 attr = this.jsAttributes; |
|
2077 } |
|
2078 |
|
2079 url = (m.fullpath) ? this._filter(m.fullpath, s[i]) : this._url(m.path, s[i]); |
|
2080 |
|
2081 fn(url, { |
|
2082 data: s[i], |
|
2083 onSuccess: onsuccess, |
|
2084 insertBefore: this.insertBefore, |
|
2085 charset: this.charset, |
|
2086 attributes: attr, |
|
2087 onFailure: this._onFailure, |
|
2088 onTimeout: this._onTimeout, |
|
2089 timeout: this.timeout, |
|
2090 autopurge: false, |
|
2091 context: self |
|
2092 }); |
|
2093 |
|
2094 return; |
|
2095 } |
|
2096 } |
|
2097 |
|
2098 // we are finished |
|
2099 this._loading = null; |
|
2100 |
|
2101 fn = this._internalCallback; |
|
2102 |
|
2103 // internal callback for loading css first |
|
2104 if (fn) { |
|
2105 // Y.log('loader internal'); |
|
2106 this._internalCallback = null; |
|
2107 fn.call(this); |
|
2108 |
|
2109 // } else if (this.onSuccess) { |
|
2110 } else { |
|
2111 // Y.log('loader complete'); |
|
2112 // call Y.use passing this instance. Y will use the sorted |
|
2113 // dependency list. |
|
2114 this._onSuccess(); |
|
2115 } |
|
2116 |
|
2117 }, |
|
2118 |
|
2119 /** |
|
2120 * Apply filter defined for this instance to a url/path |
|
2121 * method _filter |
|
2122 * @param u {string} the string to filter |
|
2123 * @param name {string} the name of the module, if we are processing |
|
2124 * a single module as opposed to a combined url |
|
2125 * @return {string} the filtered string |
|
2126 * @private |
|
2127 */ |
|
2128 _filter: function(u, name) { |
|
2129 |
|
2130 var f = this.filter, |
|
2131 hasFilter = name && (name in this.filters), |
|
2132 modFilter = hasFilter && this.filters[name]; |
|
2133 |
|
2134 if (u) { |
|
2135 |
|
2136 if (hasFilter) { |
|
2137 f = (L.isString(modFilter)) ? this.FILTER_DEFS[modFilter.toUpperCase()] || null : modFilter; |
|
2138 } |
|
2139 |
|
2140 if (f) { |
|
2141 u = u.replace(new RegExp(f.searchExp, 'g'), f.replaceStr); |
|
2142 } |
|
2143 } |
|
2144 |
|
2145 return u; |
|
2146 |
|
2147 }, |
|
2148 |
|
2149 /** |
|
2150 * Generates the full url for a module |
|
2151 * method _url |
|
2152 * @param path {string} the path fragment |
|
2153 * @return {string} the full url |
|
2154 * @private |
|
2155 */ |
|
2156 _url: function(path, name) { |
|
2157 return this._filter((this.base || "") + path, name); |
|
2158 } |
|
2159 |
|
2160 }; |
|
2161 |
|
2162 })(); |
|
2163 |
|
2164 |
|
2165 |
|
2166 }, '3.0.0' ); |