API Docs for: 3.18.1
Show:

File: yui/js/yui.js

  1. /**
  2. The YUI module contains the components required for building the YUI seed file.
  3. This includes the script loading mechanism, a simple queue, and the core
  4. utilities for the library.
  5.  
  6. @module yui
  7. @main yui
  8. @submodule yui-base
  9. **/
  10.  
  11. /*jshint eqeqeq: false*/
  12. if (typeof YUI != 'undefined') {
  13. YUI._YUI = YUI;
  14. }
  15.  
  16. /**
  17. The YUI global namespace object. This is the constructor for all YUI instances.
  18.  
  19. This is a self-instantiable factory function, meaning you don't need to precede
  20. it with the `new` operator. You can invoke it directly like this:
  21.  
  22. YUI().use('*', function (Y) {
  23. // Y is a new YUI instance.
  24. });
  25.  
  26. But it also works like this:
  27.  
  28. var Y = YUI();
  29.  
  30. The `YUI` constructor accepts an optional config object, like this:
  31.  
  32. YUI({
  33. debug: true,
  34. combine: false
  35. }).use('node', function (Y) {
  36. // Y.Node is ready to use.
  37. });
  38.  
  39. See the API docs for the <a href="config.html">Config</a> class for the complete
  40. list of supported configuration properties accepted by the YUI constuctor.
  41.  
  42. If a global `YUI` object is already defined, the existing YUI object will not be
  43. overwritten, to ensure that defined namespaces are preserved.
  44.  
  45. Each YUI instance has full custom event support, but only if the event system is
  46. available.
  47.  
  48. @class YUI
  49. @uses EventTarget
  50. @constructor
  51. @global
  52. @param {Object} [config]* Zero or more optional configuration objects. Config
  53. values are stored in the `Y.config` property. See the
  54. <a href="config.html">Config</a> docs for the list of supported properties.
  55. **/
  56.  
  57. /*global YUI*/
  58. /*global YUI_config*/
  59. var YUI = function() {
  60. var i = 0,
  61. Y = this,
  62. args = arguments,
  63. l = args.length,
  64. instanceOf = function(o, type) {
  65. return (o && o.hasOwnProperty && (o instanceof type));
  66. },
  67. gconf = (typeof YUI_config !== 'undefined') && YUI_config;
  68.  
  69. if (!(instanceOf(Y, YUI))) {
  70. Y = new YUI();
  71. } else {
  72. // set up the core environment
  73. Y._init();
  74.  
  75. /**
  76. Master configuration that might span multiple contexts in a non-
  77. browser environment. It is applied first to all instances in all
  78. contexts.
  79.  
  80. @example
  81.  
  82. YUI.GlobalConfig = {
  83. filter: 'debug'
  84. };
  85.  
  86. YUI().use('node', function (Y) {
  87. // debug files used here
  88. });
  89.  
  90. YUI({
  91. filter: 'min'
  92. }).use('node', function (Y) {
  93. // min files used here
  94. });
  95.  
  96. @property {Object} GlobalConfig
  97. @global
  98. @static
  99. **/
  100. if (YUI.GlobalConfig) {
  101. Y.applyConfig(YUI.GlobalConfig);
  102. }
  103.  
  104. /**
  105. Page-level config applied to all YUI instances created on the
  106. current page. This is applied after `YUI.GlobalConfig` and before
  107. any instance-level configuration.
  108.  
  109. @example
  110.  
  111. // Single global var to include before YUI seed file
  112. YUI_config = {
  113. filter: 'debug'
  114. };
  115.  
  116. YUI().use('node', function (Y) {
  117. // debug files used here
  118. });
  119.  
  120. YUI({
  121. filter: 'min'
  122. }).use('node', function (Y) {
  123. // min files used here
  124. });
  125.  
  126. @property {Object} YUI_config
  127. @global
  128. **/
  129. if (gconf) {
  130. Y.applyConfig(gconf);
  131. }
  132.  
  133. // bind the specified additional modules for this instance
  134. if (!l) {
  135. Y._afterConfig();
  136. Y._setup();
  137. }
  138. }
  139.  
  140. if (l) {
  141. // Each instance can accept one or more configuration objects.
  142. // These are applied after YUI.GlobalConfig and YUI_Config,
  143. // overriding values set in those config files if there is a
  144. // matching property.
  145. for (; i < l; i++) {
  146. Y.applyConfig(args[i]);
  147. }
  148.  
  149. Y._afterConfig();
  150. Y._setup();
  151. }
  152.  
  153. Y.instanceOf = instanceOf;
  154.  
  155. return Y;
  156. };
  157.  
  158. (function() {
  159.  
  160. var proto, prop,
  161. VERSION = '@VERSION@',
  162. PERIOD = '.',
  163. BASE = 'http://yui.yahooapis.com/',
  164. /*
  165. These CSS class names can't be generated by
  166. getClassName since it is not available at the
  167. time they are being used.
  168. */
  169. DOC_LABEL = 'yui3-js-enabled',
  170. CSS_STAMP_EL = 'yui3-css-stamp',
  171. NOOP = function() {},
  172. SLICE = Array.prototype.slice,
  173. APPLY_TO_AUTH = { 'io.xdrReady': 1, // the functions applyTo
  174. 'io.xdrResponse': 1, // can call. this should
  175. 'SWF.eventHandler': 1 }, // be done at build time
  176. hasWin = (typeof window != 'undefined'),
  177. win = (hasWin) ? window : null,
  178. doc = (hasWin) ? win.document : null,
  179. docEl = doc && doc.documentElement,
  180. docClass = docEl && docEl.className,
  181. instances = {},
  182. time = new Date().getTime(),
  183. add = function(el, type, fn, capture) {
  184. if (el && el.addEventListener) {
  185. el.addEventListener(type, fn, capture);
  186. } else if (el && el.attachEvent) {
  187. el.attachEvent('on' + type, fn);
  188. }
  189. },
  190. remove = function(el, type, fn, capture) {
  191. if (el && el.removeEventListener) {
  192. // this can throw an uncaught exception in FF
  193. try {
  194. el.removeEventListener(type, fn, capture);
  195. } catch (ex) {}
  196. } else if (el && el.detachEvent) {
  197. el.detachEvent('on' + type, fn);
  198. }
  199. },
  200. handleReady = function() {
  201. YUI.Env.DOMReady = true;
  202. if (hasWin) {
  203. remove(doc, 'DOMContentLoaded', handleReady);
  204. }
  205. },
  206. handleLoad = function() {
  207. YUI.Env.windowLoaded = true;
  208. YUI.Env.DOMReady = true;
  209. if (hasWin) {
  210. remove(window, 'load', handleLoad);
  211. }
  212. },
  213. getLoader = function(Y, o) {
  214. var loader = Y.Env._loader,
  215. lCore = [ 'loader-base' ],
  216. G_ENV = YUI.Env,
  217. mods = G_ENV.mods;
  218.  
  219. if (loader) {
  220. //loader._config(Y.config);
  221. loader.ignoreRegistered = false;
  222. loader.onEnd = null;
  223. loader.data = null;
  224. loader.required = [];
  225. loader.loadType = null;
  226. } else {
  227. loader = new Y.Loader(Y.config);
  228. Y.Env._loader = loader;
  229. }
  230. if (mods && mods.loader) {
  231. lCore = [].concat(lCore, YUI.Env.loaderExtras);
  232. }
  233. YUI.Env.core = Y.Array.dedupe([].concat(YUI.Env.core, lCore));
  234.  
  235. return loader;
  236. },
  237.  
  238. clobber = function(r, s) {
  239. for (var i in s) {
  240. if (s.hasOwnProperty(i)) {
  241. r[i] = s[i];
  242. }
  243. }
  244. },
  245.  
  246. ALREADY_DONE = { success: true };
  247.  
  248. // Stamp the documentElement (HTML) with a class of "yui-loaded" to
  249. // enable styles that need to key off of JS being enabled.
  250. if (docEl && docClass.indexOf(DOC_LABEL) == -1) {
  251. if (docClass) {
  252. docClass += ' ';
  253. }
  254. docClass += DOC_LABEL;
  255. docEl.className = docClass;
  256. }
  257.  
  258. if (VERSION.indexOf('@') > -1) {
  259. VERSION = '3.5.0'; // dev time hack for cdn test
  260. }
  261.  
  262. proto = {
  263. /**
  264. Applies a new configuration object to the config of this YUI instance. This
  265. will merge new group/module definitions, and will also update the loader
  266. cache if necessary. Updating `Y.config` directly will not update the cache.
  267.  
  268. @method applyConfig
  269. @param {Object} o the configuration object.
  270. @since 3.2.0
  271. **/
  272. applyConfig: function(o) {
  273.  
  274. o = o || NOOP;
  275.  
  276. var attr,
  277. name,
  278. // detail,
  279. config = this.config,
  280. mods = config.modules,
  281. groups = config.groups,
  282. aliases = config.aliases,
  283. loader = this.Env._loader;
  284.  
  285. for (name in o) {
  286. if (o.hasOwnProperty(name)) {
  287. attr = o[name];
  288. if (mods && name == 'modules') {
  289. clobber(mods, attr);
  290. } else if (aliases && name == 'aliases') {
  291. clobber(aliases, attr);
  292. } else if (groups && name == 'groups') {
  293. clobber(groups, attr);
  294. } else if (name == 'win') {
  295. config[name] = (attr && attr.contentWindow) || attr;
  296. config.doc = config[name] ? config[name].document : null;
  297. } else if (name == '_yuid') {
  298. // preserve the guid
  299. } else {
  300. config[name] = attr;
  301. }
  302. }
  303. }
  304.  
  305. if (loader) {
  306. loader._config(o);
  307. }
  308.  
  309. },
  310.  
  311. /**
  312. Old way to apply a config to this instance (calls `applyConfig` under the
  313. hood).
  314.  
  315. @private
  316. @method _config
  317. @param {Object} o The config to apply
  318. **/
  319. _config: function(o) {
  320. this.applyConfig(o);
  321. },
  322.  
  323. /**
  324. Initializes this YUI instance.
  325.  
  326. @private
  327. @method _init
  328. **/
  329. _init: function() {
  330. var filter, el,
  331. Y = this,
  332. G_ENV = YUI.Env,
  333. Env = Y.Env,
  334. prop;
  335.  
  336. /**
  337. The version number of this YUI instance.
  338.  
  339. This value is typically updated by a script when a YUI release is built,
  340. so it may not reflect the correct version number when YUI is run from
  341. the development source tree.
  342.  
  343. @property {String} version
  344. **/
  345. Y.version = VERSION;
  346.  
  347. if (!Env) {
  348. Y.Env = {
  349. core: @YUI_CORE@,
  350. loaderExtras: ['loader-rollup', 'loader-yui3'],
  351. mods: {}, // flat module map
  352. versions: {}, // version module map
  353. base: BASE,
  354. cdn: BASE + VERSION + '/',
  355. // bootstrapped: false,
  356. _idx: 0,
  357. _used: {},
  358. _attached: {},
  359. _exported: {},
  360. _missed: [],
  361. _yidx: 0,
  362. _uidx: 0,
  363. _guidp: 'y',
  364. _loaded: {},
  365. // serviced: {},
  366. // Regex in English:
  367. // I'll start at the \b(yui).
  368. // 1. Look in the test string for "yui" or
  369. // "yui-base" or "yui-davglass" or "yui-foobar" that comes after a word break. That is, it
  370. // can't match "foyui" or "i_heart_yui". This can be anywhere in the string.
  371. // 2. After #1 must come a forward slash followed by the string matched in #1, so
  372. // "yui-base/yui-base" or "yui-pants/yui-pants".
  373. // 3. The second occurence of the #1 token can optionally be followed by "-debug" or "-min",
  374. // so "yui/yui-min", "yui/yui-debug", "yui-base/yui-base-debug". NOT "yui/yui-tshirt".
  375. // 4. This is followed by ".js", so "yui/yui.js".
  376. // 0. Going back to the beginning, now. If all that stuff in 1-4 comes after a "?" in the string,
  377. // then capture the junk between the LAST "&" and the string in 1-4. So
  378. // "blah?foo/yui/yui.js" will capture "foo/" and "blah?some/thing.js&3.3.0/build/yui-davglass/yui-davglass.js"
  379. // will capture "3.3.0/build/"
  380. //
  381. // Regex Exploded:
  382. // (?:\? Find a ?
  383. // (?:[^&]*&) followed by 0..n characters followed by an &
  384. // * in fact, find as many sets of characters followed by a & as you can
  385. // ([^&]*) capture the stuff after the last & in \1
  386. // )? but it's ok if all this ?junk&more_junk stuff isn't even there
  387. // \b( after a word break find either the string
  388. // yui(?:-\w+)? "yui" optionally followed by a -, then more characters
  389. // ) and store the yui-* string in \2
  390. // \/\2 then comes a / followed by the yui-* string in \2
  391. // (?:-(min|debug))? optionally followed by "-min" or "-debug"
  392. // .js and ending in ".js"
  393. _BASE_RE: /(?:\?(?:[^&]*&)*([^&]*))?\b(yui(?:-\w+)?)\/\2(?:-(min|debug))?\.js/,
  394. parseBasePath: function(src, pattern) {
  395. var match = src.match(pattern),
  396. path, filter;
  397.  
  398. if (match) {
  399. path = RegExp.leftContext || src.slice(0, src.indexOf(match[0]));
  400.  
  401. // this is to set up the path to the loader. The file
  402. // filter for loader should match the yui include.
  403. filter = match[3];
  404.  
  405. // extract correct path for mixed combo urls
  406. // http://yuilibrary.com/projects/yui3/ticket/2528423
  407. if (match[1]) {
  408. path += '?' + match[1];
  409. }
  410. path = {
  411. filter: filter,
  412. path: path
  413. };
  414. }
  415. return path;
  416. },
  417. getBase: G_ENV && G_ENV.getBase ||
  418. function(pattern) {
  419. var nodes = (doc && doc.getElementsByTagName('script')) || [],
  420. path = Env.cdn, parsed,
  421. i, len, src;
  422.  
  423. for (i = 0, len = nodes.length; i < len; ++i) {
  424. src = nodes[i].src;
  425. if (src) {
  426. parsed = Y.Env.parseBasePath(src, pattern);
  427. if (parsed) {
  428. filter = parsed.filter;
  429. path = parsed.path;
  430. break;
  431. }
  432. }
  433. }
  434.  
  435. // use CDN default
  436. return path;
  437. }
  438.  
  439. };
  440.  
  441. Env = Y.Env;
  442.  
  443. Env._loaded[VERSION] = {};
  444.  
  445. if (G_ENV && Y !== YUI) {
  446. Env._yidx = ++G_ENV._yidx;
  447. Env._guidp = ('yui_' + VERSION + '_' +
  448. Env._yidx + '_' + time).replace(/[^a-z0-9_]+/g, '_');
  449. } else if (YUI._YUI) {
  450.  
  451. G_ENV = YUI._YUI.Env;
  452. Env._yidx += G_ENV._yidx;
  453. Env._uidx += G_ENV._uidx;
  454.  
  455. for (prop in G_ENV) {
  456. if (!(prop in Env)) {
  457. Env[prop] = G_ENV[prop];
  458. }
  459. }
  460.  
  461. delete YUI._YUI;
  462. }
  463.  
  464. Y.id = Y.stamp(Y);
  465. instances[Y.id] = Y;
  466.  
  467. }
  468.  
  469. Y.constructor = YUI;
  470.  
  471. // configuration defaults
  472. Y.config = Y.config || {
  473. bootstrap: true,
  474. cacheUse: true,
  475. debug: true,
  476. doc: doc,
  477. fetchCSS: true,
  478. throwFail: true,
  479. useBrowserConsole: true,
  480. useNativeES5: true,
  481. win: win
  482. };
  483.  
  484. //Register the CSS stamp element
  485. if (doc && !doc.getElementById(CSS_STAMP_EL)) {
  486. el = doc.createElement('div');
  487. el.innerHTML = '<div id="' + CSS_STAMP_EL + '" style="position: absolute !important; visibility: hidden !important"></div>';
  488. YUI.Env.cssStampEl = el.firstChild;
  489. if (doc.body) {
  490. doc.body.appendChild(YUI.Env.cssStampEl);
  491. } else {
  492. docEl.insertBefore(YUI.Env.cssStampEl, docEl.firstChild);
  493. }
  494. } else if (doc && doc.getElementById(CSS_STAMP_EL) && !YUI.Env.cssStampEl) {
  495. YUI.Env.cssStampEl = doc.getElementById(CSS_STAMP_EL);
  496. }
  497.  
  498. Y.config.lang = Y.config.lang || 'en-US';
  499.  
  500. Y.config.base = YUI.config.base ||
  501. (YUI.config.defaultBase && YUI.config.root && YUI.config.defaultBase + YUI.config.root) ||
  502. Y.Env.getBase(Y.Env._BASE_RE);
  503.  
  504. if (!filter || (!('mindebug').indexOf(filter))) {
  505. filter = 'min';
  506. }
  507. filter = (filter) ? '-' + filter : filter;
  508. Y.config.loaderPath = YUI.config.loaderPath || 'loader/loader' + filter + '.js';
  509.  
  510. },
  511.  
  512. /**
  513. This method is called after all other configuration has been applied to
  514. the YUI instance.
  515.  
  516. @method _afterConfig
  517. @private
  518. **/
  519. _afterConfig: function () {
  520. var Y = this;
  521.  
  522. // We need to set up Y.config.global after the rest of the configuration
  523. // so that setting it in user configuration prevents the library from
  524. // using eval(). This is critical for Content Security Policy enabled
  525. // sites and other environments like Chrome extensions
  526. if (!Y.config.hasOwnProperty('global')) {
  527. Y.config.global = Function('return this')();
  528. }
  529. },
  530.  
  531. /**
  532. Finishes the instance setup. Attaches whatever YUI modules were defined
  533. at the time that this instance was created.
  534.  
  535. @method _setup
  536. @private
  537. **/
  538. _setup: function() {
  539. var i, Y = this,
  540. core = [],
  541. mods = YUI.Env.mods,
  542. extendedCore = Y.config.extendedCore || [],
  543. extras = Y.config.core || [].concat(YUI.Env.core).concat(extendedCore); //Clone it..
  544. for (i = 0; i < extras.length; i++) {
  545. if (mods[extras[i]]) {
  546. core.push(extras[i]);
  547. }
  548. }
  549.  
  550. Y._attach(['yui-base']);
  551. Y._attach(core);
  552.  
  553. if (Y.Loader) {
  554. getLoader(Y);
  555. }
  556.  
  557. // Y.log(Y.id + ' initialized', 'info', 'yui');
  558. },
  559.  
  560. /**
  561. Executes the named method on the specified YUI instance if that method is
  562. whitelisted.
  563.  
  564. @method applyTo
  565. @param {String} id YUI instance id.
  566. @param {String} method Name of the method to execute. For example:
  567. 'Object.keys'.
  568. @param {Array} args Arguments to apply to the method.
  569. @return {Mixed} Return value from the applied method, or `null` if the
  570. specified instance was not found or the method was not whitelisted.
  571. **/
  572. applyTo: function(id, method, args) {
  573. if (!(method in APPLY_TO_AUTH)) {
  574. this.log(method + ': applyTo not allowed', 'warn', 'yui');
  575. return null;
  576. }
  577.  
  578. var instance = instances[id], nest, m, i;
  579. if (instance) {
  580. nest = method.split('.');
  581. m = instance;
  582. for (i = 0; i < nest.length; i = i + 1) {
  583. m = m[nest[i]];
  584. if (!m) {
  585. this.log('applyTo not found: ' + method, 'warn', 'yui');
  586. }
  587. }
  588. return m && m.apply(instance, args);
  589. }
  590.  
  591. return null;
  592. },
  593.  
  594. /**
  595. Registers a YUI module and makes it available for use in a `YUI().use()` call or
  596. as a dependency for other modules.
  597.  
  598. The easiest way to create a first-class YUI module is to use
  599. <a href="http://yui.github.com/shifter/">Shifter</a>, the YUI component build
  600. tool.
  601.  
  602. Shifter will automatically wrap your module code in a `YUI.add()` call along
  603. with any configuration info required for the module.
  604.  
  605. @example
  606.  
  607. YUI.add('davglass', function (Y) {
  608. Y.davglass = function () {
  609. Y.log('Dav was here!');
  610. };
  611. }, '3.4.0', {
  612. requires: ['harley-davidson', 'mt-dew']
  613. });
  614.  
  615. @method add
  616. @param {String} name Module name.
  617. @param {Function} fn Function containing module code. This function will be
  618. executed whenever the module is attached to a specific YUI instance.
  619.  
  620. @param {YUI} fn.Y The YUI instance to which this module is attached.
  621. @param {String} fn.name Name of the module
  622.  
  623. @param {String} version Module version number. This is currently used only for
  624. informational purposes, and is not used internally by YUI.
  625.  
  626. @param {Object} [details] Module config.
  627. @param {Array} [details.requires] Array of other module names that must be
  628. attached before this module can be attached.
  629. @param {Array} [details.optional] Array of optional module names that should
  630. be attached before this module is attached if they've already been
  631. loaded. If the `loadOptional` YUI option is `true`, optional modules
  632. that have not yet been loaded will be loaded just as if they were hard
  633. requirements.
  634. @param {Array} [details.use] Array of module names that are included within
  635. or otherwise provided by this module, and which should be attached
  636. automatically when this module is attached. This makes it possible to
  637. create "virtual rollup" modules that simply attach a collection of other
  638. modules or submodules.
  639.  
  640. @return {YUI} This YUI instance.
  641. **/
  642. add: function(name, fn, version, details) {
  643. details = details || {};
  644. var env = YUI.Env,
  645. mod = {
  646. name: name,
  647. fn: fn,
  648. version: version,
  649. details: details
  650. },
  651. //Instance hash so we don't apply it to the same instance twice
  652. applied = {},
  653. loader, inst, modInfo,
  654. i, versions = env.versions;
  655.  
  656. env.mods[name] = mod;
  657. versions[version] = versions[version] || {};
  658. versions[version][name] = mod;
  659.  
  660. for (i in instances) {
  661. if (instances.hasOwnProperty(i)) {
  662. inst = instances[i];
  663. if (!applied[inst.id]) {
  664. applied[inst.id] = true;
  665. loader = inst.Env._loader;
  666. if (loader) {
  667. modInfo = loader.getModuleInfo(name);
  668. if (!modInfo || modInfo.temp) {
  669. loader.addModule(details, name);
  670. }
  671. }
  672. }
  673. }
  674. }
  675.  
  676. return this;
  677. },
  678.  
  679. /**
  680. Executes the callback function associated with each required module,
  681. attaching the module to this YUI instance.
  682.  
  683. @method _attach
  684. @param {Array} r The array of modules to attach
  685. @param {Boolean} [moot=false] If `true`, don't throw a warning if the module
  686. is not attached.
  687. @private
  688. **/
  689. _attach: function(r, moot) {
  690. var i, name, mod, details, req, use, after,
  691. mods = YUI.Env.mods,
  692. aliases = YUI.Env.aliases,
  693. Y = this, j,
  694. cache = YUI.Env._renderedMods,
  695. loader = Y.Env._loader,
  696. done = Y.Env._attached,
  697. exported = Y.Env._exported,
  698. len = r.length, loader, def, go,
  699. c = [],
  700. modArgs, esCompat, reqlen, modInfo,
  701. condition,
  702. __exports__, __imports__;
  703.  
  704. //Check for conditional modules (in a second+ instance) and add their requirements
  705. //TODO I hate this entire method, it needs to be fixed ASAP (3.5.0) ^davglass
  706. for (i = 0; i < len; i++) {
  707. name = r[i];
  708. mod = mods[name];
  709. c.push(name);
  710. if (loader && loader.conditions[name]) {
  711. for (j in loader.conditions[name]) {
  712. if (loader.conditions[name].hasOwnProperty(j)) {
  713. def = loader.conditions[name][j];
  714. go = def && ((def.ua && Y.UA[def.ua]) || (def.test && def.test(Y)));
  715. if (go) {
  716. c.push(def.name);
  717. }
  718. }
  719. }
  720. }
  721. }
  722. r = c;
  723. len = r.length;
  724.  
  725. for (i = 0; i < len; i++) {
  726. if (!done[r[i]]) {
  727. name = r[i];
  728. mod = mods[name];
  729.  
  730. if (aliases && aliases[name] && !mod) {
  731. Y._attach(aliases[name]);
  732. continue;
  733. }
  734. if (!mod) {
  735. modInfo = loader && loader.getModuleInfo(name);
  736. if (modInfo) {
  737. mod = modInfo;
  738. moot = true;
  739. }
  740.  
  741. // Y.log('no js def for: ' + name, 'info', 'yui');
  742.  
  743. //if (!loader || !loader.moduleInfo[name]) {
  744. //if ((!loader || !loader.moduleInfo[name]) && !moot) {
  745. if (!moot && name) {
  746. if ((name.indexOf('skin-') === -1) && (name.indexOf('css') === -1)) {
  747. Y.Env._missed.push(name);
  748. Y.Env._missed = Y.Array.dedupe(Y.Env._missed);
  749. Y.message('NOT loaded: ' + name, 'warn', 'yui');
  750. }
  751. }
  752. } else {
  753. done[name] = true;
  754. //Don't like this, but in case a mod was asked for once, then we fetch it
  755. //We need to remove it from the missed list ^davglass
  756. for (j = 0; j < Y.Env._missed.length; j++) {
  757. if (Y.Env._missed[j] === name) {
  758. Y.message('Found: ' + name + ' (was reported as missing earlier)', 'warn', 'yui');
  759. Y.Env._missed.splice(j, 1);
  760. }
  761. }
  762.  
  763. // Optional dependencies normally work by modifying the
  764. // dependency list of a module. If the dependency's test
  765. // passes it is added to the list. If not, it's not loaded.
  766. // This following check ensures that optional dependencies
  767. // are not attached when they were already loaded into the
  768. // page (when bundling for example)
  769. if (loader && !loader._canBeAttached(name)) {
  770. Y.log('Failed to attach module ' + name, 'warn', 'yui');
  771. return true;
  772. }
  773.  
  774. /*
  775. If it's a temp module, we need to redo it's requirements if it's already loaded
  776. since it may have been loaded by another instance and it's dependencies might
  777. have been redefined inside the fetched file.
  778. */
  779. if (loader && cache && cache[name] && cache[name].temp) {
  780. loader.getRequires(cache[name]);
  781. req = [];
  782. modInfo = loader.getModuleInfo(name);
  783. for (j in modInfo.expanded_map) {
  784. if (modInfo.expanded_map.hasOwnProperty(j)) {
  785. req.push(j);
  786. }
  787. }
  788. Y._attach(req);
  789. }
  790.  
  791. details = mod.details;
  792. req = details.requires;
  793. esCompat = details.es;
  794. use = details.use;
  795. after = details.after;
  796. //Force Intl load if there is a language (Loader logic) @todo fix this shit
  797. if (details.lang) {
  798. req = req || [];
  799. req.unshift('intl');
  800. }
  801.  
  802. if (req) {
  803. reqlen = req.length;
  804. for (j = 0; j < reqlen; j++) {
  805. if (!done[req[j]]) {
  806. if (!Y._attach(req)) {
  807. return false;
  808. }
  809. break;
  810. }
  811. }
  812. }
  813.  
  814. if (after) {
  815. for (j = 0; j < after.length; j++) {
  816. if (!done[after[j]]) {
  817. if (!Y._attach(after, true)) {
  818. return false;
  819. }
  820. break;
  821. }
  822. }
  823. }
  824.  
  825. if (mod.fn) {
  826. modArgs = [Y, name];
  827. if (esCompat) {
  828. __imports__ = {};
  829. __exports__ = {};
  830. // passing `exports` and `imports` onto the module function
  831. modArgs.push(__imports__, __exports__);
  832. if (req) {
  833. reqlen = req.length;
  834. for (j = 0; j < reqlen; j++) {
  835. __imports__[req[j]] = exported.hasOwnProperty(req[j]) ? exported[req[j]] : Y;
  836. }
  837. }
  838. }
  839. if (Y.config.throwFail) {
  840. __exports__ = mod.fn.apply(esCompat ? undefined : mod, modArgs);
  841. } else {
  842. try {
  843. __exports__ = mod.fn.apply(esCompat ? undefined : mod, modArgs);
  844. } catch (e) {
  845. Y.error('Attach error: ' + name, e, name);
  846. return false;
  847. }
  848. }
  849. if (esCompat) {
  850. // store the `exports` in case others `es` modules requires it
  851. exported[name] = __exports__;
  852.  
  853. // If an ES module is conditionally loaded and set
  854. // to be used "instead" another module, replace the
  855. // trigger module's content with the conditionally
  856. // loaded one so the values returned by require()
  857. // still makes sense
  858. condition = mod.details.condition;
  859. if (condition && condition.when === 'instead') {
  860. exported[condition.trigger] = __exports__;
  861. }
  862. }
  863. }
  864.  
  865. if (use) {
  866. for (j = 0; j < use.length; j++) {
  867. if (!done[use[j]]) {
  868. if (!Y._attach(use)) {
  869. return false;
  870. }
  871. break;
  872. }
  873. }
  874. }
  875.  
  876.  
  877.  
  878. }
  879. }
  880. }
  881.  
  882. return true;
  883. },
  884.  
  885. /**
  886. Delays the `use` callback until another event has taken place such as
  887. `window.onload`, `domready`, `contentready`, or `available`.
  888.  
  889. @private
  890. @method _delayCallback
  891. @param {Function} cb The original `use` callback.
  892. @param {String|Object} until Either an event name ('load', 'domready', etc.)
  893. or an object containing event/args keys for contentready/available.
  894. @return {Function}
  895. **/
  896. _delayCallback: function(cb, until) {
  897.  
  898. var Y = this,
  899. mod = ['event-base'];
  900.  
  901. until = (Y.Lang.isObject(until) ? until : { event: until });
  902.  
  903. if (until.event === 'load') {
  904. mod.push('event-synthetic');
  905. }
  906.  
  907. Y.log('Delaying use callback until: ' + until.event, 'info', 'yui');
  908. return function() {
  909. Y.log('Use callback fired, waiting on delay', 'info', 'yui');
  910. var args = arguments;
  911. Y._use(mod, function() {
  912. Y.log('Delayed use wrapper callback after dependencies', 'info', 'yui');
  913. Y.on(until.event, function() {
  914. args[1].delayUntil = until.event;
  915. Y.log('Delayed use callback done after ' + until.event, 'info', 'yui');
  916. cb.apply(Y, args);
  917. }, until.args);
  918. });
  919. };
  920. },
  921.  
  922. /**
  923. Attaches one or more modules to this YUI instance. When this is executed,
  924. the requirements of the desired modules are analyzed, and one of several
  925. things can happen:
  926.  
  927.  
  928. * All required modules have already been loaded, and just need to be
  929. attached to this YUI instance. In this case, the `use()` callback will
  930. be executed synchronously after the modules are attached.
  931.  
  932. * One or more modules have not yet been loaded, or the Get utility is not
  933. available, or the `bootstrap` config option is `false`. In this case,
  934. a warning is issued indicating that modules are missing, but all
  935. available modules will still be attached and the `use()` callback will
  936. be executed synchronously.
  937.  
  938. * One or more modules are missing and the Loader is not available but the
  939. Get utility is, and `bootstrap` is not `false`. In this case, the Get
  940. utility will be used to load the Loader, and we will then proceed to
  941. the following state:
  942.  
  943. * One or more modules are missing and the Loader is available. In this
  944. case, the Loader will be used to resolve the dependency tree for the
  945. missing modules and load them and their dependencies. When the Loader is
  946. finished loading modules, the `use()` callback will be executed
  947. asynchronously.
  948.  
  949. @example
  950.  
  951. // Loads and attaches dd and its dependencies.
  952. YUI().use('dd', function (Y) {
  953. // ...
  954. });
  955.  
  956. // Loads and attaches dd and node as well as all of their dependencies.
  957. YUI().use(['dd', 'node'], function (Y) {
  958. // ...
  959. });
  960.  
  961. // Attaches all modules that have already been loaded.
  962. YUI().use('*', function (Y) {
  963. // ...
  964. });
  965.  
  966. // Attaches a gallery module.
  967. YUI().use('gallery-yql', function (Y) {
  968. // ...
  969. });
  970.  
  971. // Attaches a YUI 2in3 module.
  972. YUI().use('yui2-datatable', function (Y) {
  973. // ...
  974. });
  975.  
  976. @method use
  977. @param {String|Array} modules* One or more module names to attach.
  978. @param {Function} [callback] Callback function to be executed once all
  979. specified modules and their dependencies have been attached.
  980. @param {YUI} callback.Y The YUI instance created for this sandbox.
  981. @param {Object} callback.status Object containing `success`, `msg` and
  982. `data` properties.
  983. @chainable
  984. **/
  985. use: function() {
  986. var args = SLICE.call(arguments, 0),
  987. callback = args[args.length - 1],
  988. Y = this,
  989. i = 0,
  990. name,
  991. Env = Y.Env,
  992. provisioned = true;
  993.  
  994. // The last argument supplied to use can be a load complete callback
  995. if (Y.Lang.isFunction(callback)) {
  996. args.pop();
  997. if (Y.config.delayUntil) {
  998. callback = Y._delayCallback(callback, Y.config.delayUntil);
  999. }
  1000. } else {
  1001. callback = null;
  1002. }
  1003. if (Y.Lang.isArray(args[0])) {
  1004. args = args[0];
  1005. }
  1006.  
  1007. if (Y.config.cacheUse) {
  1008. while ((name = args[i++])) {
  1009. if (!Env._attached[name]) {
  1010. provisioned = false;
  1011. break;
  1012. }
  1013. }
  1014.  
  1015. if (provisioned) {
  1016. if (args.length) {
  1017. Y.log('already provisioned: ' + args, 'info', 'yui');
  1018. }
  1019. Y._notify(callback, ALREADY_DONE, args);
  1020. return Y;
  1021. }
  1022. }
  1023.  
  1024. if (Y._loading) {
  1025. Y._useQueue = Y._useQueue || new Y.Queue();
  1026. Y._useQueue.add([args, callback]);
  1027. } else {
  1028. Y._use(args, function(Y, response) {
  1029. Y._notify(callback, response, args);
  1030. });
  1031. }
  1032.  
  1033. return Y;
  1034. },
  1035.  
  1036. /**
  1037. Sugar for loading both legacy and ES6-based YUI modules.
  1038.  
  1039. @method require
  1040. @param {String} [modules*] List of module names to import or a single
  1041. module name.
  1042. @param {Function} callback Callback that gets called once all the modules
  1043. were loaded. Each parameter of the callback is the export value of the
  1044. corresponding module in the list. If the module is a legacy YUI module,
  1045. the YUI instance is used instead of the module exports.
  1046. @example
  1047. ```
  1048. YUI().require(['es6-set'], function (Y, imports) {
  1049. var Set = imports.Set,
  1050. set = new Set();
  1051. });
  1052. ```
  1053. **/
  1054. require: function () {
  1055. var args = SLICE.call(arguments),
  1056. callback;
  1057.  
  1058. if (typeof args[args.length - 1] === 'function') {
  1059. callback = args.pop();
  1060.  
  1061. // only add the callback if one was provided
  1062. // YUI().require('foo'); is valid
  1063. args.push(function (Y) {
  1064. var i, length = args.length,
  1065. exported = Y.Env._exported,
  1066. __imports__ = {};
  1067.  
  1068. // Get only the imports requested as arguments
  1069. for (i = 0; i < length; i++) {
  1070. if (exported.hasOwnProperty(args[i])) {
  1071. __imports__[args[i]] = exported[args[i]];
  1072. }
  1073. }
  1074.  
  1075. // Using `undefined` because:
  1076. // - Using `Y.config.global` would force the value of `this` to be
  1077. // the global object even in strict mode
  1078. // - Using `Y` goes against the goal of moving away from a shared
  1079. // object and start thinking in terms of imported and exported
  1080. // objects
  1081. callback.call(undefined, Y, __imports__);
  1082. });
  1083. }
  1084. // Do not return the Y object. This makes it hard to follow this
  1085. // traditional pattern:
  1086. // var Y = YUI().use(...);
  1087. // This is a good idea in the light of ES6 modules, to avoid working
  1088. // in the global scope.
  1089. // This also leaves the door open for returning a promise, once the
  1090. // YUI loader is based on the ES6 loader which uses
  1091. // loader.import(...).then(...)
  1092. this.use.apply(this, args);
  1093. },
  1094.  
  1095. /**
  1096. Handles Loader notifications about attachment/load errors.
  1097.  
  1098. @method _notify
  1099. @param {Function} callback Callback to pass to `Y.config.loadErrorFn`.
  1100. @param {Object} response Response returned from Loader.
  1101. @param {Array} args Arguments passed from Loader.
  1102. @private
  1103. **/
  1104. _notify: function(callback, response, args) {
  1105. if (!response.success && this.config.loadErrorFn) {
  1106. this.config.loadErrorFn.call(this, this, callback, response, args);
  1107. } else if (callback) {
  1108. if (this.Env._missed && this.Env._missed.length) {
  1109. response.msg = 'Missing modules: ' + this.Env._missed.join();
  1110. response.success = false;
  1111. }
  1112. if (this.config.throwFail) {
  1113. callback(this, response);
  1114. } else {
  1115. try {
  1116. callback(this, response);
  1117. } catch (e) {
  1118. this.error('use callback error', e, args);
  1119. }
  1120. }
  1121. }
  1122. },
  1123.  
  1124. /**
  1125. Called from the `use` method queue to ensure that only one set of loading
  1126. logic is performed at a time.
  1127.  
  1128. @method _use
  1129. @param {String} args* One or more modules to attach.
  1130. @param {Function} [callback] Function to call once all required modules have
  1131. been attached.
  1132. @private
  1133. **/
  1134. _use: function(args, callback) {
  1135.  
  1136. if (!this.Array) {
  1137. this._attach(['yui-base']);
  1138. }
  1139.  
  1140. var len, loader, handleBoot,
  1141. Y = this,
  1142. G_ENV = YUI.Env,
  1143. mods = G_ENV.mods,
  1144. Env = Y.Env,
  1145. used = Env._used,
  1146. aliases = G_ENV.aliases,
  1147. queue = G_ENV._loaderQueue,
  1148. firstArg = args[0],
  1149. YArray = Y.Array,
  1150. config = Y.config,
  1151. boot = config.bootstrap,
  1152. missing = [],
  1153. i,
  1154. r = [],
  1155. ret = true,
  1156. fetchCSS = config.fetchCSS,
  1157. process = function(names, skip) {
  1158.  
  1159. var i = 0, a = [], name, len, m, req, use;
  1160.  
  1161. if (!names.length) {
  1162. return;
  1163. }
  1164.  
  1165. if (aliases) {
  1166. len = names.length;
  1167. for (i = 0; i < len; i++) {
  1168. if (aliases[names[i]] && !mods[names[i]]) {
  1169. a = [].concat(a, aliases[names[i]]);
  1170. } else {
  1171. a.push(names[i]);
  1172. }
  1173. }
  1174. names = a;
  1175. }
  1176.  
  1177. len = names.length;
  1178.  
  1179. for (i = 0; i < len; i++) {
  1180. name = names[i];
  1181. if (!skip) {
  1182. r.push(name);
  1183. }
  1184.  
  1185. // only attach a module once
  1186. if (used[name]) {
  1187. continue;
  1188. }
  1189.  
  1190. m = mods[name];
  1191. req = null;
  1192. use = null;
  1193.  
  1194. if (m) {
  1195. used[name] = true;
  1196. req = m.details.requires;
  1197. use = m.details.use;
  1198. } else {
  1199. // CSS files don't register themselves, see if it has
  1200. // been loaded
  1201. if (!G_ENV._loaded[VERSION][name]) {
  1202. missing.push(name);
  1203. } else {
  1204. used[name] = true; // probably css
  1205. }
  1206. }
  1207.  
  1208. // make sure requirements are attached
  1209. if (req && req.length) {
  1210. process(req);
  1211. }
  1212.  
  1213. // make sure we grab the submodule dependencies too
  1214. if (use && use.length) {
  1215. process(use, 1);
  1216. }
  1217. }
  1218.  
  1219. },
  1220.  
  1221. handleLoader = function(fromLoader) {
  1222. var response = fromLoader || {
  1223. success: true,
  1224. msg: 'not dynamic'
  1225. },
  1226. redo, origMissing,
  1227. ret = true,
  1228. data = response.data;
  1229.  
  1230. Y._loading = false;
  1231.  
  1232. if (data) {
  1233. origMissing = missing;
  1234. missing = [];
  1235. r = [];
  1236. process(data);
  1237. redo = missing.length;
  1238. if (redo) {
  1239. if ([].concat(missing).sort().join() ==
  1240. origMissing.sort().join()) {
  1241. redo = false;
  1242. }
  1243. }
  1244. }
  1245.  
  1246. if (redo && data) {
  1247. Y._loading = true;
  1248. Y._use(missing, function() {
  1249. Y.log('Nested use callback: ' + data, 'info', 'yui');
  1250. if (Y._attach(data)) {
  1251. Y._notify(callback, response, data);
  1252. }
  1253. });
  1254. } else {
  1255. if (data) {
  1256. // Y.log('attaching from loader: ' + data, 'info', 'yui');
  1257. ret = Y._attach(data);
  1258. }
  1259. if (ret) {
  1260. Y._notify(callback, response, args);
  1261. }
  1262. }
  1263.  
  1264. if (Y._useQueue && Y._useQueue.size() && !Y._loading) {
  1265. Y._use.apply(Y, Y._useQueue.next());
  1266. }
  1267.  
  1268. };
  1269.  
  1270. // Y.log(Y.id + ': use called: ' + a + ' :: ' + callback, 'info', 'yui');
  1271.  
  1272. // YUI().use('*'); // bind everything available
  1273. if (firstArg === '*') {
  1274. args = [];
  1275. for (i in mods) {
  1276. if (mods.hasOwnProperty(i)) {
  1277. args.push(i);
  1278. }
  1279. }
  1280. ret = Y._attach(args);
  1281. if (ret) {
  1282. handleLoader();
  1283. }
  1284. return Y;
  1285. }
  1286.  
  1287. if ((mods.loader || mods['loader-base']) && !Y.Loader) {
  1288. Y.log('Loader was found in meta, but it is not attached. Attaching..', 'info', 'yui');
  1289. Y._attach(['loader' + ((!mods.loader) ? '-base' : '')]);
  1290. }
  1291.  
  1292. // Y.log('before loader requirements: ' + args, 'info', 'yui');
  1293.  
  1294. // use loader to expand dependencies and sort the
  1295. // requirements if it is available.
  1296. if (boot && Y.Loader && args.length) {
  1297. Y.log('Using loader to expand dependencies', 'info', 'yui');
  1298. loader = getLoader(Y);
  1299. loader.require(args);
  1300. loader.ignoreRegistered = true;
  1301. loader._boot = true;
  1302. loader.calculate(null, (fetchCSS) ? null : 'js');
  1303. args = loader.sorted;
  1304. loader._boot = false;
  1305. }
  1306.  
  1307. process(args);
  1308.  
  1309. len = missing.length;
  1310.  
  1311.  
  1312. if (len) {
  1313. missing = YArray.dedupe(missing);
  1314. len = missing.length;
  1315. Y.log('Modules missing: ' + missing + ', ' + missing.length, 'info', 'yui');
  1316. }
  1317.  
  1318.  
  1319. // dynamic load
  1320. if (boot && len && Y.Loader) {
  1321. // Y.log('Using loader to fetch missing deps: ' + missing, 'info', 'yui');
  1322. Y.log('Using Loader', 'info', 'yui');
  1323. Y._loading = true;
  1324. loader = getLoader(Y);
  1325. loader.onEnd = handleLoader;
  1326. loader.context = Y;
  1327. loader.data = args;
  1328. loader.ignoreRegistered = false;
  1329. loader.require(missing);
  1330. loader.insert(null, (fetchCSS) ? null : 'js');
  1331.  
  1332. } else if (boot && len && Y.Get && !Env.bootstrapped) {
  1333.  
  1334. Y._loading = true;
  1335.  
  1336. handleBoot = function() {
  1337. Y._loading = false;
  1338. queue.running = false;
  1339. Env.bootstrapped = true;
  1340. G_ENV._bootstrapping = false;
  1341. if (Y._attach(['loader'])) {
  1342. Y._use(args, callback);
  1343. }
  1344. };
  1345.  
  1346. if (G_ENV._bootstrapping) {
  1347. Y.log('Waiting for loader', 'info', 'yui');
  1348. queue.add(handleBoot);
  1349. } else {
  1350. G_ENV._bootstrapping = true;
  1351. Y.log('Fetching loader: ' + config.base + config.loaderPath, 'info', 'yui');
  1352. Y.Get.script(config.base + config.loaderPath, {
  1353. onEnd: handleBoot
  1354. });
  1355. }
  1356.  
  1357. } else {
  1358. Y.log('Attaching available dependencies: ' + args, 'info', 'yui');
  1359. ret = Y._attach(args);
  1360. if (ret) {
  1361. handleLoader();
  1362. }
  1363. }
  1364.  
  1365. return Y;
  1366. },
  1367.  
  1368.  
  1369. /**
  1370. Utility method for safely creating namespaces if they don't already exist.
  1371. May be called statically on the YUI global object or as a method on a YUI
  1372. instance.
  1373.  
  1374. When called statically, a namespace will be created on the YUI global
  1375. object:
  1376.  
  1377. // Create `YUI.your.namespace.here` as nested objects, preserving any
  1378. // objects that already exist instead of overwriting them.
  1379. YUI.namespace('your.namespace.here');
  1380.  
  1381. When called as a method on a YUI instance, a namespace will be created on
  1382. that instance:
  1383.  
  1384. // Creates `Y.property.package`.
  1385. Y.namespace('property.package');
  1386.  
  1387. Dots in the input string cause `namespace` to create nested objects for each
  1388. token. If any part of the requested namespace already exists, the current
  1389. object will be left in place and will not be overwritten. This allows
  1390. multiple calls to `namespace` to preserve existing namespaced properties.
  1391.  
  1392. If the first token in the namespace string is "YAHOO", that token is
  1393. discarded. This is legacy behavior for backwards compatibility with YUI 2.
  1394.  
  1395. Be careful with namespace tokens. Reserved words may work in some browsers
  1396. and not others. For instance, the following will fail in some browsers
  1397. because the supported version of JavaScript reserves the word "long":
  1398.  
  1399. Y.namespace('really.long.nested.namespace');
  1400.  
  1401. Note: If you pass multiple arguments to create multiple namespaces, only the
  1402. last one created is returned from this function.
  1403.  
  1404. @method namespace
  1405. @param {String} namespace* One or more namespaces to create.
  1406. @return {Object} Reference to the last namespace object created.
  1407. **/
  1408. namespace: function() {
  1409. var a = arguments, o, i = 0, j, d, arg;
  1410.  
  1411. for (; i < a.length; i++) {
  1412. o = this; //Reset base object per argument or it will get reused from the last
  1413. arg = a[i];
  1414. if (arg.indexOf(PERIOD) > -1) { //Skip this if no "." is present
  1415. d = arg.split(PERIOD);
  1416. for (j = (d[0] == 'YAHOO') ? 1 : 0; j < d.length; j++) {
  1417. o[d[j]] = o[d[j]] || {};
  1418. o = o[d[j]];
  1419. }
  1420. } else {
  1421. o[arg] = o[arg] || {};
  1422. o = o[arg]; //Reset base object to the new object so it's returned
  1423. }
  1424. }
  1425. return o;
  1426. },
  1427.  
  1428. // this is replaced if the log module is included
  1429. log: NOOP,
  1430. message: NOOP,
  1431. // this is replaced if the dump module is included
  1432. dump: function (o) { return ''+o; },
  1433.  
  1434. /**
  1435. Reports an error.
  1436.  
  1437. The reporting mechanism is controlled by the `throwFail` configuration
  1438. attribute. If `throwFail` is falsy, the message is logged. If `throwFail` is
  1439. truthy, a JS exception is thrown.
  1440.  
  1441. If an `errorFn` is specified in the config it must return `true` to indicate
  1442. that the exception was handled and keep it from being thrown.
  1443.  
  1444. @method error
  1445. @param {String} msg Error message.
  1446. @param {Error|String} [e] JavaScript error object or an error string.
  1447. @param {String} [src] Source of the error (such as the name of the module in
  1448. which the error occurred).
  1449. @chainable
  1450. **/
  1451. error: function(msg, e, src) {
  1452. //TODO Add check for window.onerror here
  1453.  
  1454. var Y = this, ret;
  1455.  
  1456. if (Y.config.errorFn) {
  1457. ret = Y.config.errorFn.apply(Y, arguments);
  1458. }
  1459.  
  1460. if (!ret) {
  1461. throw (e || new Error(msg));
  1462. } else {
  1463. Y.message(msg, 'error', ''+src); // don't scrub this one
  1464. }
  1465.  
  1466. return Y;
  1467. },
  1468.  
  1469. /**
  1470. Generates an id string that is unique among all YUI instances in this
  1471. execution context.
  1472.  
  1473. @method guid
  1474. @param {String} [pre] Prefix.
  1475. @return {String} Unique id.
  1476. **/
  1477. guid: function(pre) {
  1478. var id = this.Env._guidp + '_' + (++this.Env._uidx);
  1479. return (pre) ? (pre + id) : id;
  1480. },
  1481.  
  1482. /**
  1483. Returns a unique id associated with the given object and (if *readOnly* is
  1484. falsy) stamps the object with that id so it can be identified in the future.
  1485.  
  1486. Stamping an object involves adding a `_yuid` property to it that contains
  1487. the object's id. One exception to this is that in Internet Explorer, DOM
  1488. nodes have a `uniqueID` property that contains a browser-generated unique
  1489. id, which will be used instead of a YUI-generated id when available.
  1490.  
  1491. @method stamp
  1492. @param {Object} o Object to stamp.
  1493. @param {Boolean} readOnly If truthy and the given object has not already
  1494. been stamped, the object will not be modified and `null` will be
  1495. returned.
  1496. @return {String} Object's unique id, or `null` if *readOnly* was truthy and
  1497. the given object was not already stamped.
  1498. **/
  1499. stamp: function(o, readOnly) {
  1500. var uid;
  1501. if (!o) {
  1502. return o;
  1503. }
  1504.  
  1505. // IE generates its own unique ID for dom nodes
  1506. // The uniqueID property of a document node returns a new ID
  1507. if (o.uniqueID && o.nodeType && o.nodeType !== 9) {
  1508. uid = o.uniqueID;
  1509. } else {
  1510. uid = (typeof o === 'string') ? o : o._yuid;
  1511. }
  1512.  
  1513. if (!uid) {
  1514. uid = this.guid();
  1515. if (!readOnly) {
  1516. try {
  1517. o._yuid = uid;
  1518. } catch (e) {
  1519. uid = null;
  1520. }
  1521. }
  1522. }
  1523. return uid;
  1524. },
  1525.  
  1526. /**
  1527. Destroys this YUI instance.
  1528.  
  1529. @method destroy
  1530. @since 3.3.0
  1531. **/
  1532. destroy: function() {
  1533. var Y = this;
  1534. if (Y.Event) {
  1535. Y.Event._unload();
  1536. }
  1537. delete instances[Y.id];
  1538. delete Y.Env;
  1539. delete Y.config;
  1540. }
  1541.  
  1542. /**
  1543. Safe `instanceof` wrapper that works around a memory leak in IE when the
  1544. object being tested is `window` or `document`.
  1545.  
  1546. Unless you are testing objects that may be `window` or `document`, you
  1547. should use the native `instanceof` operator instead of this method.
  1548.  
  1549. @method instanceOf
  1550. @param {Object} o Object to check.
  1551. @param {Object} type Class to check against.
  1552. @since 3.3.0
  1553. **/
  1554. };
  1555.  
  1556. YUI.prototype = proto;
  1557.  
  1558. // inheritance utilities are not available yet
  1559. for (prop in proto) {
  1560. if (proto.hasOwnProperty(prop)) {
  1561. YUI[prop] = proto[prop];
  1562. }
  1563. }
  1564.  
  1565. /**
  1566. Applies a configuration to all YUI instances in this execution context.
  1567.  
  1568. The main use case for this method is in "mashups" where several third-party
  1569. scripts need to write to a global YUI config, but cannot share a single
  1570. centrally-managed config object. This way they can all call
  1571. `YUI.applyConfig({})` instead of overwriting the single global config.
  1572.  
  1573. @example
  1574.  
  1575. YUI.applyConfig({
  1576. modules: {
  1577. davglass: {
  1578. fullpath: './davglass.js'
  1579. }
  1580. }
  1581. });
  1582.  
  1583. YUI.applyConfig({
  1584. modules: {
  1585. foo: {
  1586. fullpath: './foo.js'
  1587. }
  1588. }
  1589. });
  1590.  
  1591. YUI().use('davglass', function (Y) {
  1592. // Module davglass will be available here.
  1593. });
  1594.  
  1595. @method applyConfig
  1596. @param {Object} o Configuration object to apply.
  1597. @static
  1598. @since 3.5.0
  1599. **/
  1600. YUI.applyConfig = function(o) {
  1601. if (!o) {
  1602. return;
  1603. }
  1604. //If there is a GlobalConfig, apply it first to set the defaults
  1605. if (YUI.GlobalConfig) {
  1606. this.prototype.applyConfig.call(this, YUI.GlobalConfig);
  1607. }
  1608. //Apply this config to it
  1609. this.prototype.applyConfig.call(this, o);
  1610. //Reset GlobalConfig to the combined config
  1611. YUI.GlobalConfig = this.config;
  1612. };
  1613.  
  1614. // set up the environment
  1615. YUI._init();
  1616.  
  1617. if (hasWin) {
  1618. add(doc, 'DOMContentLoaded', handleReady);
  1619.  
  1620. // add a window load event at load time so we can capture
  1621. // the case where it fires before dynamic loading is
  1622. // complete.
  1623. add(window, 'load', handleLoad);
  1624. } else {
  1625. handleReady();
  1626. handleLoad();
  1627. }
  1628.  
  1629. YUI.Env.add = add;
  1630. YUI.Env.remove = remove;
  1631.  
  1632. /*global exports*/
  1633. // Support the CommonJS method for exporting our single global
  1634. if (typeof exports == 'object') {
  1635. exports.YUI = YUI;
  1636. /**
  1637. * Set a method to be called when `Get.script` is called in Node.js
  1638. * `Get` will open the file, then pass it's content and it's path
  1639. * to this method before attaching it. Commonly used for code coverage
  1640. * instrumentation. <strong>Calling this multiple times will only
  1641. * attach the last hook method</strong>. This method is only
  1642. * available in Node.js.
  1643. * @method setLoadHook
  1644. * @static
  1645. * @param {Function} fn The function to set
  1646. * @param {String} fn.data The content of the file
  1647. * @param {String} fn.path The file path of the file
  1648. */
  1649. YUI.setLoadHook = function(fn) {
  1650. YUI._getLoadHook = fn;
  1651. };
  1652. /**
  1653. * Load hook for `Y.Get.script` in Node.js, see `YUI.setLoadHook`
  1654. * @method _getLoadHook
  1655. * @private
  1656. * @param {String} data The content of the file
  1657. * @param {String} path The file path of the file
  1658. */
  1659. YUI._getLoadHook = null;
  1660. }
  1661.  
  1662. YUI.Env[VERSION] = {};
  1663. }());
  1664.  
  1665.  
  1666. /**
  1667. Config object that contains all of the configuration options for
  1668. this `YUI` instance.
  1669.  
  1670. This object is supplied by the implementer when instantiating YUI. Some
  1671. properties have default values if they are not supplied by the implementer.
  1672.  
  1673. This object should not be updated directly because some values are cached. Use
  1674. `applyConfig()` to update the config object on a YUI instance that has already
  1675. been configured.
  1676.  
  1677. @class config
  1678. @static
  1679. **/
  1680.  
  1681. /**
  1682. If `true` (the default), YUI will "bootstrap" the YUI Loader and module metadata
  1683. if they're needed to load additional dependencies and aren't already available.
  1684.  
  1685. Setting this to `false` will prevent YUI from automatically loading the Loader
  1686. and module metadata, so you will need to manually ensure that they're available
  1687. or handle dependency resolution yourself.
  1688.  
  1689. @property {Boolean} bootstrap
  1690. @default true
  1691. **/
  1692.  
  1693. /**
  1694. If `true`, `Y.log()` messages will be written to the browser's debug console
  1695. when available and when `useBrowserConsole` is also `true`.
  1696.  
  1697. @property {Boolean} debug
  1698. @default true
  1699. **/
  1700.  
  1701. /**
  1702. Log messages to the browser console if `debug` is `true` and the browser has a
  1703. supported console.
  1704.  
  1705. @property {Boolean} useBrowserConsole
  1706. @default true
  1707. **/
  1708.  
  1709. /**
  1710. A hash of log sources that should be logged. If specified, only messages from
  1711. these sources will be logged. Others will be discarded.
  1712.  
  1713. @property {Object} logInclude
  1714. @type object
  1715. **/
  1716.  
  1717. /**
  1718. A hash of log sources that should be not be logged. If specified, all sources
  1719. will be logged *except* those on this list.
  1720.  
  1721. @property {Object} logExclude
  1722. **/
  1723.  
  1724. /**
  1725. When the YUI seed file is dynamically loaded after the `window.onload` event has
  1726. fired, set this to `true` to tell YUI that it shouldn't wait for `window.onload`
  1727. to occur.
  1728.  
  1729. This ensures that components that rely on `window.onload` and the `domready`
  1730. custom event will work as expected even when YUI is dynamically injected.
  1731.  
  1732. @property {Boolean} injected
  1733. @default false
  1734. **/
  1735.  
  1736. /**
  1737. If `true`, `Y.error()` will generate or re-throw a JavaScript error. Otherwise,
  1738. errors are merely logged silently.
  1739.  
  1740. @property {Boolean} throwFail
  1741. @default true
  1742. **/
  1743.  
  1744. /**
  1745. Reference to the global object for this execution context.
  1746.  
  1747. In a browser, this is the current `window` object. In Node.js, this is the
  1748. Node.js `global` object.
  1749.  
  1750. @property {Object} global
  1751. **/
  1752.  
  1753. /**
  1754. The browser window or frame that this YUI instance should operate in.
  1755.  
  1756. When running in Node.js, this property is `undefined`, since there is no
  1757. `window` object. Use `global` to get a reference to the global object that will
  1758. work in both browsers and Node.js.
  1759.  
  1760. @property {Window} win
  1761. **/
  1762.  
  1763. /**
  1764. The browser `document` object associated with this YUI instance's `win` object.
  1765.  
  1766. When running in Node.js, this property is `undefined`, since there is no
  1767. `document` object.
  1768.  
  1769. @property {Document} doc
  1770. **/
  1771.  
  1772. /**
  1773. A list of modules that defines the YUI core (overrides the default list).
  1774.  
  1775. @property {Array} core
  1776. @type Array
  1777. @default ['get', 'features', 'intl-base', 'yui-log', 'yui-later', 'loader-base', 'loader-rollup', 'loader-yui3']
  1778. **/
  1779.  
  1780. /**
  1781. A list of languages to use in order of preference.
  1782.  
  1783. This list is matched against the list of available languages in modules that the
  1784. YUI instance uses to determine the best possible localization of language
  1785. sensitive modules.
  1786.  
  1787. Languages are represented using BCP 47 language tags, such as "en-GB" for
  1788. English as used in the United Kingdom, or "zh-Hans-CN" for simplified Chinese as
  1789. used in China. The list may be provided as a comma-separated string or as an
  1790. array.
  1791.  
  1792. @property {String|String[]} lang
  1793. **/
  1794.  
  1795. /**
  1796. Default date format.
  1797.  
  1798. @property {String} dateFormat
  1799. @deprecated Use configuration in `DataType.Date.format()` instead.
  1800. **/
  1801.  
  1802. /**
  1803. Default locale.
  1804.  
  1805. @property {String} locale
  1806. @deprecated Use `config.lang` instead.
  1807. **/
  1808.  
  1809. /**
  1810. Default generic polling interval in milliseconds.
  1811.  
  1812. @property {Number} pollInterval
  1813. @default 20
  1814. **/
  1815.  
  1816. /**
  1817. The number of dynamic `<script>` nodes to insert by default before automatically
  1818. removing them when loading scripts.
  1819.  
  1820. This applies only to script nodes because removing the node will not make the
  1821. evaluated script unavailable. Dynamic CSS nodes are not auto purged, because
  1822. removing a linked style sheet will also remove the style definitions.
  1823.  
  1824. @property {Number} purgethreshold
  1825. @default 20
  1826. **/
  1827.  
  1828. /**
  1829. Delay in milliseconds to wait after a window `resize` event before firing the
  1830. event. If another `resize` event occurs before this delay has elapsed, the
  1831. delay will start over to ensure that `resize` events are throttled.
  1832.  
  1833. @property {Number} windowResizeDelay
  1834. @default 40
  1835. **/
  1836.  
  1837. /**
  1838. Base directory for dynamic loading.
  1839.  
  1840. @property {String} base
  1841. **/
  1842.  
  1843. /**
  1844. Base URL for a dynamic combo handler. This will be used to make combo-handled
  1845. module requests if `combine` is set to `true.
  1846.  
  1847. @property {String} comboBase
  1848. @default "http://yui.yahooapis.com/combo?"
  1849. **/
  1850.  
  1851. /**
  1852. Root path to prepend to each module path when creating a combo-handled request.
  1853.  
  1854. This is updated for each YUI release to point to a specific version of the
  1855. library; for example: "3.8.0/build/".
  1856.  
  1857. @property {String} root
  1858. **/
  1859.  
  1860. /**
  1861. Filter to apply to module urls. This filter will modify the default path for all
  1862. modules.
  1863.  
  1864. The default path for the YUI library is the minified version of the files (e.g.,
  1865. event-min.js). The filter property can be a predefined filter or a custom
  1866. filter. The valid predefined filters are:
  1867.  
  1868. - **debug**: Loads debug versions of modules (e.g., event-debug.js).
  1869. - **raw**: Loads raw, non-minified versions of modules without debug logging
  1870. (e.g., event.js).
  1871.  
  1872. You can also define a custom filter, which must be an object literal containing
  1873. a search regular expression and a replacement string:
  1874.  
  1875. myFilter: {
  1876. searchExp : "-min\\.js",
  1877. replaceStr: "-debug.js"
  1878. }
  1879.  
  1880. @property {Object|String} filter
  1881. **/
  1882.  
  1883. /**
  1884. Skin configuration and customizations.
  1885.  
  1886. @property {Object} skin
  1887. @param {String} [skin.defaultSkin='sam'] Default skin name. This skin will be
  1888. applied automatically to skinnable components if not overridden by a
  1889. component-specific skin name.
  1890. @param {String} [skin.base='assets/skins/'] Default base path for a skin,
  1891. relative to Loader's `base` path.
  1892. @param {Object} [skin.overrides] Component-specific skin name overrides. Specify
  1893. a component name as the key and, as the value, a string or array of strings
  1894. for a skin or skins that should be loaded for that component instead of the
  1895. `defaultSkin`.
  1896. **/
  1897.  
  1898. /**
  1899. Hash of per-component filter specifications. If specified for a given component,
  1900. this overrides the global `filter` config.
  1901.  
  1902. @example
  1903. YUI({
  1904. modules: {
  1905. 'foo': './foo.js',
  1906. 'bar': './bar.js',
  1907. 'baz': './baz.js'
  1908. },
  1909. filters: {
  1910. 'foo': {
  1911. searchExp: '.js',
  1912. replaceStr: '-coverage.js'
  1913. }
  1914. }
  1915. }).use('foo', 'bar', 'baz', function (Y) {
  1916. // foo-coverage.js is loaded
  1917. // bar.js is loaded
  1918. // baz.js is loaded
  1919. });
  1920.  
  1921. @property {Object} filters
  1922. **/
  1923.  
  1924. /**
  1925. If `true`, YUI will use a combo handler to load multiple modules in as few
  1926. requests as possible.
  1927.  
  1928. The YUI CDN (which YUI uses by default) supports combo handling, but other
  1929. servers may not. If the server from which you're loading YUI does not support
  1930. combo handling, set this to `false`.
  1931.  
  1932. Providing a value for the `base` config property will cause `combine` to default
  1933. to `false` instead of `true`.
  1934.  
  1935. @property {Boolean} combine
  1936. @default true
  1937. */
  1938.  
  1939. /**
  1940. Array of module names that should never be dynamically loaded.
  1941.  
  1942. @property {String[]} ignore
  1943. **/
  1944.  
  1945. /**
  1946. Array of module names that should always be loaded when required, even if
  1947. already present on the page.
  1948.  
  1949. @property {String[]} force
  1950. **/
  1951.  
  1952. /**
  1953. DOM element or id that should be used as the insertion point for dynamically
  1954. added `<script>` and `<link>` nodes.
  1955.  
  1956. @property {HTMLElement|String} insertBefore
  1957. **/
  1958.  
  1959. /**
  1960. Object hash containing attributes to add to dynamically added `<script>` nodes.
  1961.  
  1962. @property {Object} jsAttributes
  1963. **/
  1964.  
  1965. /**
  1966. Object hash containing attributes to add to dynamically added `<link>` nodes.
  1967.  
  1968. @property {Object} cssAttributes
  1969. **/
  1970.  
  1971. /**
  1972. Timeout in milliseconds before a dynamic JS or CSS request will be considered a
  1973. failure. If not set, no timeout will be enforced.
  1974.  
  1975. @property {Number} timeout
  1976. **/
  1977.  
  1978. /**
  1979. A hash of module definitions to add to the list of available YUI modules. These
  1980. modules can then be dynamically loaded via the `use()` method.
  1981.  
  1982. This is a hash in which keys are module names and values are objects containing
  1983. module metadata.
  1984.  
  1985. See `Loader.addModule()` for the supported module metadata fields. Also see
  1986. `groups`, which provides a way to configure the base and combo spec for a set of
  1987. modules.
  1988.  
  1989. @example
  1990.  
  1991. modules: {
  1992. mymod1: {
  1993. requires: ['node'],
  1994. fullpath: '/mymod1/mymod1.js'
  1995. },
  1996.  
  1997. mymod2: {
  1998. requires: ['mymod1'],
  1999. fullpath: '/mymod2/mymod2.js'
  2000. },
  2001.  
  2002. mymod3: '/js/mymod3.js',
  2003. mycssmod: '/css/mycssmod.css'
  2004. }
  2005.  
  2006. @property {Object} modules
  2007. **/
  2008.  
  2009. /**
  2010. Aliases are dynamic groups of modules that can be used as shortcuts.
  2011.  
  2012. @example
  2013.  
  2014. YUI({
  2015. aliases: {
  2016. davglass: [ 'node', 'yql', 'dd' ],
  2017. mine: [ 'davglass', 'autocomplete']
  2018. }
  2019. }).use('mine', function (Y) {
  2020. // Node, YQL, DD & AutoComplete available here.
  2021. });
  2022.  
  2023. @property {Object} aliases
  2024. **/
  2025.  
  2026. /**
  2027. A hash of module group definitions.
  2028.  
  2029. For each group you can specify a list of modules and the base path and
  2030. combo spec to use when dynamically loading the modules.
  2031.  
  2032. @example
  2033.  
  2034. groups: {
  2035. yui2: {
  2036. // specify whether or not this group has a combo service
  2037. combine: true,
  2038.  
  2039. // The comboSeperator to use with this group's combo handler
  2040. comboSep: ';',
  2041.  
  2042. // The maxURLLength for this server
  2043. maxURLLength: 500,
  2044.  
  2045. // the base path for non-combo paths
  2046. base: 'http://yui.yahooapis.com/2.8.0r4/build/',
  2047.  
  2048. // the path to the combo service
  2049. comboBase: 'http://yui.yahooapis.com/combo?',
  2050.  
  2051. // a fragment to prepend to the path attribute when
  2052. // when building combo urls
  2053. root: '2.8.0r4/build/',
  2054.  
  2055. // the module definitions
  2056. modules: {
  2057. yui2_yde: {
  2058. path: "yahoo-dom-event/yahoo-dom-event.js"
  2059. },
  2060. yui2_anim: {
  2061. path: "animation/animation.js",
  2062. requires: ['yui2_yde']
  2063. }
  2064. }
  2065. }
  2066. }
  2067.  
  2068. @property {Object} groups
  2069. **/
  2070.  
  2071. /**
  2072. Path to the Loader JS file, relative to the `base` path.
  2073.  
  2074. This is used to dynamically bootstrap the Loader when it's needed and isn't yet
  2075. available.
  2076.  
  2077. @property {String} loaderPath
  2078. @default "loader/loader-min.js"
  2079. **/
  2080.  
  2081. /**
  2082. If `true`, YUI will attempt to load CSS dependencies and skins. Set this to
  2083. `false` to prevent YUI from loading any CSS, or set it to the string `"force"`
  2084. to force CSS dependencies to be loaded even if their associated JS modules are
  2085. already loaded.
  2086.  
  2087. @property {Boolean|String} fetchCSS
  2088. @default true
  2089. **/
  2090.  
  2091. /**
  2092. Default gallery version used to build gallery module urls.
  2093.  
  2094. @property {String} gallery
  2095. @since 3.1.0
  2096. **/
  2097.  
  2098. /**
  2099. Default YUI 2 version used to build YUI 2 module urls.
  2100.  
  2101. This is used for intrinsic YUI 2 support via the 2in3 project. Also see the
  2102. `2in3` config for pulling different revisions of the wrapped YUI 2 modules.
  2103.  
  2104. @property {String} yui2
  2105. @default "2.9.0"
  2106. @since 3.1.0
  2107. **/
  2108.  
  2109. /**
  2110. Revision number of YUI 2in3 modules that should be used when loading YUI 2in3.
  2111.  
  2112. @property {String} 2in3
  2113. @default "4"
  2114. @since 3.1.0
  2115. **/
  2116.  
  2117. /**
  2118. Alternate console log function that should be used in environments without a
  2119. supported native console. This function is executed with the YUI instance as its
  2120. `this` object.
  2121.  
  2122. @property {Function} logFn
  2123. @since 3.1.0
  2124. **/
  2125.  
  2126. /**
  2127. The minimum log level to log messages for. Log levels are defined
  2128. incrementally. Messages greater than or equal to the level specified will
  2129. be shown. All others will be discarded. The order of log levels in
  2130. increasing priority is:
  2131.  
  2132. debug
  2133. info
  2134. warn
  2135. error
  2136.  
  2137. @property {String} logLevel
  2138. @default 'debug'
  2139. @since 3.10.0
  2140. **/
  2141.  
  2142. /**
  2143. Callback to execute when `Y.error()` is called. It receives the error message
  2144. and a JavaScript error object if one was provided.
  2145.  
  2146. This function is executed with the YUI instance as its `this` object.
  2147.  
  2148. Returning `true` from this function will prevent an exception from being thrown.
  2149.  
  2150. @property {Function} errorFn
  2151. @param {String} errorFn.msg Error message
  2152. @param {Object} [errorFn.err] Error object (if one was provided).
  2153. @since 3.2.0
  2154. **/
  2155.  
  2156. /**
  2157. A callback to execute when Loader fails to load one or more resources.
  2158.  
  2159. This could be because of a script load failure. It could also be because a
  2160. module fails to register itself when the `requireRegistration` config is `true`.
  2161.  
  2162. If this function is defined, the `use()` callback will only be called when the
  2163. loader succeeds. Otherwise, `use()` will always executes unless there was a
  2164. JavaScript error when attaching a module.
  2165.  
  2166. @property {Function} loadErrorFn
  2167. @since 3.3.0
  2168. **/
  2169.  
  2170. /**
  2171. If `true`, Loader will expect all loaded scripts to be first-class YUI modules
  2172. that register themselves with the YUI global, and will trigger a failure if a
  2173. loaded script does not register a YUI module.
  2174.  
  2175. @property {Boolean} requireRegistration
  2176. @default false
  2177. @since 3.3.0
  2178. **/
  2179.  
  2180. /**
  2181. Cache serviced use() requests.
  2182.  
  2183. @property {Boolean} cacheUse
  2184. @default true
  2185. @since 3.3.0
  2186. @deprecated No longer used.
  2187. **/
  2188.  
  2189. /**
  2190. Whether or not YUI should use native ES5 functionality when available for
  2191. features like `Y.Array.each()`, `Y.Object()`, etc.
  2192.  
  2193. When `false`, YUI will always use its own fallback implementations instead of
  2194. relying on ES5 functionality, even when ES5 functionality is available.
  2195.  
  2196. @property {Boolean} useNativeES5
  2197. @default true
  2198. @since 3.5.0
  2199. **/
  2200.  
  2201. /**
  2202. * Leverage native JSON stringify if the browser has a native
  2203. * implementation. In general, this is a good idea. See the Known Issues
  2204. * section in the JSON user guide for caveats. The default value is true
  2205. * for browsers with native JSON support.
  2206. *
  2207. * @property useNativeJSONStringify
  2208. * @type Boolean
  2209. * @default true
  2210. * @since 3.8.0
  2211. */
  2212.  
  2213. /**
  2214. * Leverage native JSON parse if the browser has a native implementation.
  2215. * In general, this is a good idea. See the Known Issues section in the
  2216. * JSON user guide for caveats. The default value is true for browsers with
  2217. * native JSON support.
  2218. *
  2219. * @property useNativeJSONParse
  2220. * @type Boolean
  2221. * @default true
  2222. * @since 3.8.0
  2223. */
  2224.  
  2225. /**
  2226. Delay the `use` callback until a specific event has passed (`load`, `domready`, `contentready` or `available`)
  2227.  
  2228. @property {Object|String} delayUntil
  2229. @since 3.6.0
  2230. @example
  2231.  
  2232. You can use `load` or `domready` strings by default:
  2233.  
  2234. YUI({
  2235. delayUntil: 'domready'
  2236. }, function (Y) {
  2237. // This will not execute until 'domeready' occurs.
  2238. });
  2239.  
  2240. Or you can delay until a node is available (with `available` or `contentready`):
  2241.  
  2242. YUI({
  2243. delayUntil: {
  2244. event: 'available',
  2245. args : '#foo'
  2246. }
  2247. }, function (Y) {
  2248. // This will not execute until a node matching the selector "#foo" is
  2249. // available in the DOM.
  2250. });
  2251.  
  2252. **/
  2253.