PageRenderTime 68ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 3ms

/lib/infusion/MyInfusion.js

https://bitbucket.org/jobara/decapod-ui
JavaScript | 15861 lines | 12162 code | 1945 blank | 1754 comment | 2304 complexity | 66409466d83c657ef76ab4e66a7e40b0 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, MIT, Apache-2.0, LGPL-2.0
  1. /*!
  2. * jQuery JavaScript Library v1.6.1
  3. * http://jquery.com/
  4. *
  5. * Copyright 2011, John Resig
  6. * Dual licensed under the MIT or GPL Version 2 licenses.
  7. * http://jquery.org/license
  8. *
  9. * Includes Sizzle.js
  10. * http://sizzlejs.com/
  11. * Copyright 2011, The Dojo Foundation
  12. * Released under the MIT, BSD, and GPL Licenses.
  13. *
  14. * Date: Thu May 12 15:04:36 2011 -0400
  15. */
  16. (function( window, undefined ) {
  17. // Use the correct document accordingly with window argument (sandbox)
  18. var document = window.document,
  19. navigator = window.navigator,
  20. location = window.location;
  21. var jQuery = (function() {
  22. // Define a local copy of jQuery
  23. var jQuery = function( selector, context ) {
  24. // The jQuery object is actually just the init constructor 'enhanced'
  25. return new jQuery.fn.init( selector, context, rootjQuery );
  26. },
  27. // Map over jQuery in case of overwrite
  28. _jQuery = window.jQuery,
  29. // Map over the $ in case of overwrite
  30. _$ = window.$,
  31. // A central reference to the root jQuery(document)
  32. rootjQuery,
  33. // A simple way to check for HTML strings or ID strings
  34. // (both of which we optimize for)
  35. quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
  36. // Check if a string has a non-whitespace character in it
  37. rnotwhite = /\S/,
  38. // Used for trimming whitespace
  39. trimLeft = /^\s+/,
  40. trimRight = /\s+$/,
  41. // Check for digits
  42. rdigit = /\d/,
  43. // Match a standalone tag
  44. rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
  45. // JSON RegExp
  46. rvalidchars = /^[\],:{}\s]*$/,
  47. rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
  48. rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
  49. rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
  50. // Useragent RegExp
  51. rwebkit = /(webkit)[ \/]([\w.]+)/,
  52. ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
  53. rmsie = /(msie) ([\w.]+)/,
  54. rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
  55. // Keep a UserAgent string for use with jQuery.browser
  56. userAgent = navigator.userAgent,
  57. // For matching the engine and version of the browser
  58. browserMatch,
  59. // The deferred used on DOM ready
  60. readyList,
  61. // The ready event handler
  62. DOMContentLoaded,
  63. // Save a reference to some core methods
  64. toString = Object.prototype.toString,
  65. hasOwn = Object.prototype.hasOwnProperty,
  66. push = Array.prototype.push,
  67. slice = Array.prototype.slice,
  68. trim = String.prototype.trim,
  69. indexOf = Array.prototype.indexOf,
  70. // [[Class]] -> type pairs
  71. class2type = {};
  72. jQuery.fn = jQuery.prototype = {
  73. constructor: jQuery,
  74. init: function( selector, context, rootjQuery ) {
  75. var match, elem, ret, doc;
  76. // Handle $(""), $(null), or $(undefined)
  77. if ( !selector ) {
  78. return this;
  79. }
  80. // Handle $(DOMElement)
  81. if ( selector.nodeType ) {
  82. this.context = this[0] = selector;
  83. this.length = 1;
  84. return this;
  85. }
  86. // The body element only exists once, optimize finding it
  87. if ( selector === "body" && !context && document.body ) {
  88. this.context = document;
  89. this[0] = document.body;
  90. this.selector = selector;
  91. this.length = 1;
  92. return this;
  93. }
  94. // Handle HTML strings
  95. if ( typeof selector === "string" ) {
  96. // Are we dealing with HTML string or an ID?
  97. if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
  98. // Assume that strings that start and end with <> are HTML and skip the regex check
  99. match = [ null, selector, null ];
  100. } else {
  101. match = quickExpr.exec( selector );
  102. }
  103. // Verify a match, and that no context was specified for #id
  104. if ( match && (match[1] || !context) ) {
  105. // HANDLE: $(html) -> $(array)
  106. if ( match[1] ) {
  107. context = context instanceof jQuery ? context[0] : context;
  108. doc = (context ? context.ownerDocument || context : document);
  109. // If a single string is passed in and it's a single tag
  110. // just do a createElement and skip the rest
  111. ret = rsingleTag.exec( selector );
  112. if ( ret ) {
  113. if ( jQuery.isPlainObject( context ) ) {
  114. selector = [ document.createElement( ret[1] ) ];
  115. jQuery.fn.attr.call( selector, context, true );
  116. } else {
  117. selector = [ doc.createElement( ret[1] ) ];
  118. }
  119. } else {
  120. ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
  121. selector = (ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment).childNodes;
  122. }
  123. return jQuery.merge( this, selector );
  124. // HANDLE: $("#id")
  125. } else {
  126. elem = document.getElementById( match[2] );
  127. // Check parentNode to catch when Blackberry 4.6 returns
  128. // nodes that are no longer in the document #6963
  129. if ( elem && elem.parentNode ) {
  130. // Handle the case where IE and Opera return items
  131. // by name instead of ID
  132. if ( elem.id !== match[2] ) {
  133. return rootjQuery.find( selector );
  134. }
  135. // Otherwise, we inject the element directly into the jQuery object
  136. this.length = 1;
  137. this[0] = elem;
  138. }
  139. this.context = document;
  140. this.selector = selector;
  141. return this;
  142. }
  143. // HANDLE: $(expr, $(...))
  144. } else if ( !context || context.jquery ) {
  145. return (context || rootjQuery).find( selector );
  146. // HANDLE: $(expr, context)
  147. // (which is just equivalent to: $(context).find(expr)
  148. } else {
  149. return this.constructor( context ).find( selector );
  150. }
  151. // HANDLE: $(function)
  152. // Shortcut for document ready
  153. } else if ( jQuery.isFunction( selector ) ) {
  154. return rootjQuery.ready( selector );
  155. }
  156. if (selector.selector !== undefined) {
  157. this.selector = selector.selector;
  158. this.context = selector.context;
  159. }
  160. return jQuery.makeArray( selector, this );
  161. },
  162. // Start with an empty selector
  163. selector: "",
  164. // The current version of jQuery being used
  165. jquery: "1.6.1",
  166. // The default length of a jQuery object is 0
  167. length: 0,
  168. // The number of elements contained in the matched element set
  169. size: function() {
  170. return this.length;
  171. },
  172. toArray: function() {
  173. return slice.call( this, 0 );
  174. },
  175. // Get the Nth element in the matched element set OR
  176. // Get the whole matched element set as a clean array
  177. get: function( num ) {
  178. return num == null ?
  179. // Return a 'clean' array
  180. this.toArray() :
  181. // Return just the object
  182. ( num < 0 ? this[ this.length + num ] : this[ num ] );
  183. },
  184. // Take an array of elements and push it onto the stack
  185. // (returning the new matched element set)
  186. pushStack: function( elems, name, selector ) {
  187. // Build a new jQuery matched element set
  188. var ret = this.constructor();
  189. if ( jQuery.isArray( elems ) ) {
  190. push.apply( ret, elems );
  191. } else {
  192. jQuery.merge( ret, elems );
  193. }
  194. // Add the old object onto the stack (as a reference)
  195. ret.prevObject = this;
  196. ret.context = this.context;
  197. if ( name === "find" ) {
  198. ret.selector = this.selector + (this.selector ? " " : "") + selector;
  199. } else if ( name ) {
  200. ret.selector = this.selector + "." + name + "(" + selector + ")";
  201. }
  202. // Return the newly-formed element set
  203. return ret;
  204. },
  205. // Execute a callback for every element in the matched set.
  206. // (You can seed the arguments with an array of args, but this is
  207. // only used internally.)
  208. each: function( callback, args ) {
  209. return jQuery.each( this, callback, args );
  210. },
  211. ready: function( fn ) {
  212. // Attach the listeners
  213. jQuery.bindReady();
  214. // Add the callback
  215. readyList.done( fn );
  216. return this;
  217. },
  218. eq: function( i ) {
  219. return i === -1 ?
  220. this.slice( i ) :
  221. this.slice( i, +i + 1 );
  222. },
  223. first: function() {
  224. return this.eq( 0 );
  225. },
  226. last: function() {
  227. return this.eq( -1 );
  228. },
  229. slice: function() {
  230. return this.pushStack( slice.apply( this, arguments ),
  231. "slice", slice.call(arguments).join(",") );
  232. },
  233. map: function( callback ) {
  234. return this.pushStack( jQuery.map(this, function( elem, i ) {
  235. return callback.call( elem, i, elem );
  236. }));
  237. },
  238. end: function() {
  239. return this.prevObject || this.constructor(null);
  240. },
  241. // For internal use only.
  242. // Behaves like an Array's method, not like a jQuery method.
  243. push: push,
  244. sort: [].sort,
  245. splice: [].splice
  246. };
  247. // Give the init function the jQuery prototype for later instantiation
  248. jQuery.fn.init.prototype = jQuery.fn;
  249. jQuery.extend = jQuery.fn.extend = function() {
  250. var options, name, src, copy, copyIsArray, clone,
  251. target = arguments[0] || {},
  252. i = 1,
  253. length = arguments.length,
  254. deep = false;
  255. // Handle a deep copy situation
  256. if ( typeof target === "boolean" ) {
  257. deep = target;
  258. target = arguments[1] || {};
  259. // skip the boolean and the target
  260. i = 2;
  261. }
  262. // Handle case when target is a string or something (possible in deep copy)
  263. if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
  264. target = {};
  265. }
  266. // extend jQuery itself if only one argument is passed
  267. if ( length === i ) {
  268. target = this;
  269. --i;
  270. }
  271. for ( ; i < length; i++ ) {
  272. // Only deal with non-null/undefined values
  273. if ( (options = arguments[ i ]) != null ) {
  274. // Extend the base object
  275. for ( name in options ) {
  276. src = target[ name ];
  277. copy = options[ name ];
  278. // Prevent never-ending loop
  279. if ( target === copy ) {
  280. continue;
  281. }
  282. // Recurse if we're merging plain objects or arrays
  283. if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
  284. if ( copyIsArray ) {
  285. copyIsArray = false;
  286. clone = src && jQuery.isArray(src) ? src : [];
  287. } else {
  288. clone = src && jQuery.isPlainObject(src) ? src : {};
  289. }
  290. // Never move original objects, clone them
  291. target[ name ] = jQuery.extend( deep, clone, copy );
  292. // Don't bring in undefined values
  293. } else if ( copy !== undefined ) {
  294. target[ name ] = copy;
  295. }
  296. }
  297. }
  298. }
  299. // Return the modified object
  300. return target;
  301. };
  302. jQuery.extend({
  303. noConflict: function( deep ) {
  304. if ( window.$ === jQuery ) {
  305. window.$ = _$;
  306. }
  307. if ( deep && window.jQuery === jQuery ) {
  308. window.jQuery = _jQuery;
  309. }
  310. return jQuery;
  311. },
  312. // Is the DOM ready to be used? Set to true once it occurs.
  313. isReady: false,
  314. // A counter to track how many items to wait for before
  315. // the ready event fires. See #6781
  316. readyWait: 1,
  317. // Hold (or release) the ready event
  318. holdReady: function( hold ) {
  319. if ( hold ) {
  320. jQuery.readyWait++;
  321. } else {
  322. jQuery.ready( true );
  323. }
  324. },
  325. // Handle when the DOM is ready
  326. ready: function( wait ) {
  327. // Either a released hold or an DOMready/load event and not yet ready
  328. if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
  329. // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
  330. if ( !document.body ) {
  331. return setTimeout( jQuery.ready, 1 );
  332. }
  333. // Remember that the DOM is ready
  334. jQuery.isReady = true;
  335. // If a normal DOM Ready event fired, decrement, and wait if need be
  336. if ( wait !== true && --jQuery.readyWait > 0 ) {
  337. return;
  338. }
  339. // If there are functions bound, to execute
  340. readyList.resolveWith( document, [ jQuery ] );
  341. // Trigger any bound ready events
  342. if ( jQuery.fn.trigger ) {
  343. jQuery( document ).trigger( "ready" ).unbind( "ready" );
  344. }
  345. }
  346. },
  347. bindReady: function() {
  348. if ( readyList ) {
  349. return;
  350. }
  351. readyList = jQuery._Deferred();
  352. // Catch cases where $(document).ready() is called after the
  353. // browser event has already occurred.
  354. if ( document.readyState === "complete" ) {
  355. // Handle it asynchronously to allow scripts the opportunity to delay ready
  356. return setTimeout( jQuery.ready, 1 );
  357. }
  358. // Mozilla, Opera and webkit nightlies currently support this event
  359. if ( document.addEventListener ) {
  360. // Use the handy event callback
  361. document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
  362. // A fallback to window.onload, that will always work
  363. window.addEventListener( "load", jQuery.ready, false );
  364. // If IE event model is used
  365. } else if ( document.attachEvent ) {
  366. // ensure firing before onload,
  367. // maybe late but safe also for iframes
  368. document.attachEvent( "onreadystatechange", DOMContentLoaded );
  369. // A fallback to window.onload, that will always work
  370. window.attachEvent( "onload", jQuery.ready );
  371. // If IE and not a frame
  372. // continually check to see if the document is ready
  373. var toplevel = false;
  374. try {
  375. toplevel = window.frameElement == null;
  376. } catch(e) {}
  377. if ( document.documentElement.doScroll && toplevel ) {
  378. doScrollCheck();
  379. }
  380. }
  381. },
  382. // See test/unit/core.js for details concerning isFunction.
  383. // Since version 1.3, DOM methods and functions like alert
  384. // aren't supported. They return false on IE (#2968).
  385. isFunction: function( obj ) {
  386. return jQuery.type(obj) === "function";
  387. },
  388. isArray: Array.isArray || function( obj ) {
  389. return jQuery.type(obj) === "array";
  390. },
  391. // A crude way of determining if an object is a window
  392. isWindow: function( obj ) {
  393. return obj && typeof obj === "object" && "setInterval" in obj;
  394. },
  395. isNaN: function( obj ) {
  396. return obj == null || !rdigit.test( obj ) || isNaN( obj );
  397. },
  398. type: function( obj ) {
  399. return obj == null ?
  400. String( obj ) :
  401. class2type[ toString.call(obj) ] || "object";
  402. },
  403. isPlainObject: function( obj ) {
  404. // Must be an Object.
  405. // Because of IE, we also have to check the presence of the constructor property.
  406. // Make sure that DOM nodes and window objects don't pass through, as well
  407. if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
  408. return false;
  409. }
  410. // Not own constructor property must be Object
  411. if ( obj.constructor &&
  412. !hasOwn.call(obj, "constructor") &&
  413. !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
  414. return false;
  415. }
  416. // Own properties are enumerated firstly, so to speed up,
  417. // if last one is own, then all properties are own.
  418. var key;
  419. for ( key in obj ) {}
  420. return key === undefined || hasOwn.call( obj, key );
  421. },
  422. isEmptyObject: function( obj ) {
  423. for ( var name in obj ) {
  424. return false;
  425. }
  426. return true;
  427. },
  428. error: function( msg ) {
  429. throw msg;
  430. },
  431. parseJSON: function( data ) {
  432. if ( typeof data !== "string" || !data ) {
  433. return null;
  434. }
  435. // Make sure leading/trailing whitespace is removed (IE can't handle it)
  436. data = jQuery.trim( data );
  437. // Attempt to parse using the native JSON parser first
  438. if ( window.JSON && window.JSON.parse ) {
  439. return window.JSON.parse( data );
  440. }
  441. // Make sure the incoming data is actual JSON
  442. // Logic borrowed from http://json.org/json2.js
  443. if ( rvalidchars.test( data.replace( rvalidescape, "@" )
  444. .replace( rvalidtokens, "]" )
  445. .replace( rvalidbraces, "")) ) {
  446. return (new Function( "return " + data ))();
  447. }
  448. jQuery.error( "Invalid JSON: " + data );
  449. },
  450. // Cross-browser xml parsing
  451. // (xml & tmp used internally)
  452. parseXML: function( data , xml , tmp ) {
  453. if ( window.DOMParser ) { // Standard
  454. tmp = new DOMParser();
  455. xml = tmp.parseFromString( data , "text/xml" );
  456. } else { // IE
  457. xml = new ActiveXObject( "Microsoft.XMLDOM" );
  458. xml.async = "false";
  459. xml.loadXML( data );
  460. }
  461. tmp = xml.documentElement;
  462. if ( ! tmp || ! tmp.nodeName || tmp.nodeName === "parsererror" ) {
  463. jQuery.error( "Invalid XML: " + data );
  464. }
  465. return xml;
  466. },
  467. noop: function() {},
  468. // Evaluates a script in a global context
  469. // Workarounds based on findings by Jim Driscoll
  470. // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
  471. globalEval: function( data ) {
  472. if ( data && rnotwhite.test( data ) ) {
  473. // We use execScript on Internet Explorer
  474. // We use an anonymous function so that context is window
  475. // rather than jQuery in Firefox
  476. ( window.execScript || function( data ) {
  477. window[ "eval" ].call( window, data );
  478. } )( data );
  479. }
  480. },
  481. nodeName: function( elem, name ) {
  482. return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
  483. },
  484. // args is for internal usage only
  485. each: function( object, callback, args ) {
  486. var name, i = 0,
  487. length = object.length,
  488. isObj = length === undefined || jQuery.isFunction( object );
  489. if ( args ) {
  490. if ( isObj ) {
  491. for ( name in object ) {
  492. if ( callback.apply( object[ name ], args ) === false ) {
  493. break;
  494. }
  495. }
  496. } else {
  497. for ( ; i < length; ) {
  498. if ( callback.apply( object[ i++ ], args ) === false ) {
  499. break;
  500. }
  501. }
  502. }
  503. // A special, fast, case for the most common use of each
  504. } else {
  505. if ( isObj ) {
  506. for ( name in object ) {
  507. if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
  508. break;
  509. }
  510. }
  511. } else {
  512. for ( ; i < length; ) {
  513. if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
  514. break;
  515. }
  516. }
  517. }
  518. }
  519. return object;
  520. },
  521. // Use native String.trim function wherever possible
  522. trim: trim ?
  523. function( text ) {
  524. return text == null ?
  525. "" :
  526. trim.call( text );
  527. } :
  528. // Otherwise use our own trimming functionality
  529. function( text ) {
  530. return text == null ?
  531. "" :
  532. text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
  533. },
  534. // results is for internal usage only
  535. makeArray: function( array, results ) {
  536. var ret = results || [];
  537. if ( array != null ) {
  538. // The window, strings (and functions) also have 'length'
  539. // The extra typeof function check is to prevent crashes
  540. // in Safari 2 (See: #3039)
  541. // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
  542. var type = jQuery.type( array );
  543. if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
  544. push.call( ret, array );
  545. } else {
  546. jQuery.merge( ret, array );
  547. }
  548. }
  549. return ret;
  550. },
  551. inArray: function( elem, array ) {
  552. if ( indexOf ) {
  553. return indexOf.call( array, elem );
  554. }
  555. for ( var i = 0, length = array.length; i < length; i++ ) {
  556. if ( array[ i ] === elem ) {
  557. return i;
  558. }
  559. }
  560. return -1;
  561. },
  562. merge: function( first, second ) {
  563. var i = first.length,
  564. j = 0;
  565. if ( typeof second.length === "number" ) {
  566. for ( var l = second.length; j < l; j++ ) {
  567. first[ i++ ] = second[ j ];
  568. }
  569. } else {
  570. while ( second[j] !== undefined ) {
  571. first[ i++ ] = second[ j++ ];
  572. }
  573. }
  574. first.length = i;
  575. return first;
  576. },
  577. grep: function( elems, callback, inv ) {
  578. var ret = [], retVal;
  579. inv = !!inv;
  580. // Go through the array, only saving the items
  581. // that pass the validator function
  582. for ( var i = 0, length = elems.length; i < length; i++ ) {
  583. retVal = !!callback( elems[ i ], i );
  584. if ( inv !== retVal ) {
  585. ret.push( elems[ i ] );
  586. }
  587. }
  588. return ret;
  589. },
  590. // arg is for internal usage only
  591. map: function( elems, callback, arg ) {
  592. var value, key, ret = [],
  593. i = 0,
  594. length = elems.length,
  595. // jquery objects are treated as arrays
  596. isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
  597. // Go through the array, translating each of the items to their
  598. if ( isArray ) {
  599. for ( ; i < length; i++ ) {
  600. value = callback( elems[ i ], i, arg );
  601. if ( value != null ) {
  602. ret[ ret.length ] = value;
  603. }
  604. }
  605. // Go through every key on the object,
  606. } else {
  607. for ( key in elems ) {
  608. value = callback( elems[ key ], key, arg );
  609. if ( value != null ) {
  610. ret[ ret.length ] = value;
  611. }
  612. }
  613. }
  614. // Flatten any nested arrays
  615. return ret.concat.apply( [], ret );
  616. },
  617. // A global GUID counter for objects
  618. guid: 1,
  619. // Bind a function to a context, optionally partially applying any
  620. // arguments.
  621. proxy: function( fn, context ) {
  622. if ( typeof context === "string" ) {
  623. var tmp = fn[ context ];
  624. context = fn;
  625. fn = tmp;
  626. }
  627. // Quick check to determine if target is callable, in the spec
  628. // this throws a TypeError, but we will just return undefined.
  629. if ( !jQuery.isFunction( fn ) ) {
  630. return undefined;
  631. }
  632. // Simulated bind
  633. var args = slice.call( arguments, 2 ),
  634. proxy = function() {
  635. return fn.apply( context, args.concat( slice.call( arguments ) ) );
  636. };
  637. // Set the guid of unique handler to the same of original handler, so it can be removed
  638. proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
  639. return proxy;
  640. },
  641. // Mutifunctional method to get and set values to a collection
  642. // The value/s can be optionally by executed if its a function
  643. access: function( elems, key, value, exec, fn, pass ) {
  644. var length = elems.length;
  645. // Setting many attributes
  646. if ( typeof key === "object" ) {
  647. for ( var k in key ) {
  648. jQuery.access( elems, k, key[k], exec, fn, value );
  649. }
  650. return elems;
  651. }
  652. // Setting one attribute
  653. if ( value !== undefined ) {
  654. // Optionally, function values get executed if exec is true
  655. exec = !pass && exec && jQuery.isFunction(value);
  656. for ( var i = 0; i < length; i++ ) {
  657. fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
  658. }
  659. return elems;
  660. }
  661. // Getting an attribute
  662. return length ? fn( elems[0], key ) : undefined;
  663. },
  664. now: function() {
  665. return (new Date()).getTime();
  666. },
  667. // Use of jQuery.browser is frowned upon.
  668. // More details: http://docs.jquery.com/Utilities/jQuery.browser
  669. uaMatch: function( ua ) {
  670. ua = ua.toLowerCase();
  671. var match = rwebkit.exec( ua ) ||
  672. ropera.exec( ua ) ||
  673. rmsie.exec( ua ) ||
  674. ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
  675. [];
  676. return { browser: match[1] || "", version: match[2] || "0" };
  677. },
  678. sub: function() {
  679. function jQuerySub( selector, context ) {
  680. return new jQuerySub.fn.init( selector, context );
  681. }
  682. jQuery.extend( true, jQuerySub, this );
  683. jQuerySub.superclass = this;
  684. jQuerySub.fn = jQuerySub.prototype = this();
  685. jQuerySub.fn.constructor = jQuerySub;
  686. jQuerySub.sub = this.sub;
  687. jQuerySub.fn.init = function init( selector, context ) {
  688. if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
  689. context = jQuerySub( context );
  690. }
  691. return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
  692. };
  693. jQuerySub.fn.init.prototype = jQuerySub.fn;
  694. var rootjQuerySub = jQuerySub(document);
  695. return jQuerySub;
  696. },
  697. browser: {}
  698. });
  699. // Populate the class2type map
  700. jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
  701. class2type[ "[object " + name + "]" ] = name.toLowerCase();
  702. });
  703. browserMatch = jQuery.uaMatch( userAgent );
  704. if ( browserMatch.browser ) {
  705. jQuery.browser[ browserMatch.browser ] = true;
  706. jQuery.browser.version = browserMatch.version;
  707. }
  708. // Deprecated, use jQuery.browser.webkit instead
  709. if ( jQuery.browser.webkit ) {
  710. jQuery.browser.safari = true;
  711. }
  712. // IE doesn't match non-breaking spaces with \s
  713. if ( rnotwhite.test( "\xA0" ) ) {
  714. trimLeft = /^[\s\xA0]+/;
  715. trimRight = /[\s\xA0]+$/;
  716. }
  717. // All jQuery objects should point back to these
  718. rootjQuery = jQuery(document);
  719. // Cleanup functions for the document ready method
  720. if ( document.addEventListener ) {
  721. DOMContentLoaded = function() {
  722. document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
  723. jQuery.ready();
  724. };
  725. } else if ( document.attachEvent ) {
  726. DOMContentLoaded = function() {
  727. // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
  728. if ( document.readyState === "complete" ) {
  729. document.detachEvent( "onreadystatechange", DOMContentLoaded );
  730. jQuery.ready();
  731. }
  732. };
  733. }
  734. // The DOM ready check for Internet Explorer
  735. function doScrollCheck() {
  736. if ( jQuery.isReady ) {
  737. return;
  738. }
  739. try {
  740. // If IE is used, use the trick by Diego Perini
  741. // http://javascript.nwbox.com/IEContentLoaded/
  742. document.documentElement.doScroll("left");
  743. } catch(e) {
  744. setTimeout( doScrollCheck, 1 );
  745. return;
  746. }
  747. // and execute any waiting functions
  748. jQuery.ready();
  749. }
  750. // Expose jQuery to the global object
  751. return jQuery;
  752. })();
  753. var // Promise methods
  754. promiseMethods = "done fail isResolved isRejected promise then always pipe".split( " " ),
  755. // Static reference to slice
  756. sliceDeferred = [].slice;
  757. jQuery.extend({
  758. // Create a simple deferred (one callbacks list)
  759. _Deferred: function() {
  760. var // callbacks list
  761. callbacks = [],
  762. // stored [ context , args ]
  763. fired,
  764. // to avoid firing when already doing so
  765. firing,
  766. // flag to know if the deferred has been cancelled
  767. cancelled,
  768. // the deferred itself
  769. deferred = {
  770. // done( f1, f2, ...)
  771. done: function() {
  772. if ( !cancelled ) {
  773. var args = arguments,
  774. i,
  775. length,
  776. elem,
  777. type,
  778. _fired;
  779. if ( fired ) {
  780. _fired = fired;
  781. fired = 0;
  782. }
  783. for ( i = 0, length = args.length; i < length; i++ ) {
  784. elem = args[ i ];
  785. type = jQuery.type( elem );
  786. if ( type === "array" ) {
  787. deferred.done.apply( deferred, elem );
  788. } else if ( type === "function" ) {
  789. callbacks.push( elem );
  790. }
  791. }
  792. if ( _fired ) {
  793. deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] );
  794. }
  795. }
  796. return this;
  797. },
  798. // resolve with given context and args
  799. resolveWith: function( context, args ) {
  800. if ( !cancelled && !fired && !firing ) {
  801. // make sure args are available (#8421)
  802. args = args || [];
  803. firing = 1;
  804. try {
  805. while( callbacks[ 0 ] ) {
  806. callbacks.shift().apply( context, args );
  807. }
  808. }
  809. finally {
  810. fired = [ context, args ];
  811. firing = 0;
  812. }
  813. }
  814. return this;
  815. },
  816. // resolve with this as context and given arguments
  817. resolve: function() {
  818. deferred.resolveWith( this, arguments );
  819. return this;
  820. },
  821. // Has this deferred been resolved?
  822. isResolved: function() {
  823. return !!( firing || fired );
  824. },
  825. // Cancel
  826. cancel: function() {
  827. cancelled = 1;
  828. callbacks = [];
  829. return this;
  830. }
  831. };
  832. return deferred;
  833. },
  834. // Full fledged deferred (two callbacks list)
  835. Deferred: function( func ) {
  836. var deferred = jQuery._Deferred(),
  837. failDeferred = jQuery._Deferred(),
  838. promise;
  839. // Add errorDeferred methods, then and promise
  840. jQuery.extend( deferred, {
  841. then: function( doneCallbacks, failCallbacks ) {
  842. deferred.done( doneCallbacks ).fail( failCallbacks );
  843. return this;
  844. },
  845. always: function() {
  846. return deferred.done.apply( deferred, arguments ).fail.apply( this, arguments );
  847. },
  848. fail: failDeferred.done,
  849. rejectWith: failDeferred.resolveWith,
  850. reject: failDeferred.resolve,
  851. isRejected: failDeferred.isResolved,
  852. pipe: function( fnDone, fnFail ) {
  853. return jQuery.Deferred(function( newDefer ) {
  854. jQuery.each( {
  855. done: [ fnDone, "resolve" ],
  856. fail: [ fnFail, "reject" ]
  857. }, function( handler, data ) {
  858. var fn = data[ 0 ],
  859. action = data[ 1 ],
  860. returned;
  861. if ( jQuery.isFunction( fn ) ) {
  862. deferred[ handler ](function() {
  863. returned = fn.apply( this, arguments );
  864. if ( returned && jQuery.isFunction( returned.promise ) ) {
  865. returned.promise().then( newDefer.resolve, newDefer.reject );
  866. } else {
  867. newDefer[ action ]( returned );
  868. }
  869. });
  870. } else {
  871. deferred[ handler ]( newDefer[ action ] );
  872. }
  873. });
  874. }).promise();
  875. },
  876. // Get a promise for this deferred
  877. // If obj is provided, the promise aspect is added to the object
  878. promise: function( obj ) {
  879. if ( obj == null ) {
  880. if ( promise ) {
  881. return promise;
  882. }
  883. promise = obj = {};
  884. }
  885. var i = promiseMethods.length;
  886. while( i-- ) {
  887. obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ];
  888. }
  889. return obj;
  890. }
  891. });
  892. // Make sure only one callback list will be used
  893. deferred.done( failDeferred.cancel ).fail( deferred.cancel );
  894. // Unexpose cancel
  895. delete deferred.cancel;
  896. // Call given func if any
  897. if ( func ) {
  898. func.call( deferred, deferred );
  899. }
  900. return deferred;
  901. },
  902. // Deferred helper
  903. when: function( firstParam ) {
  904. var args = arguments,
  905. i = 0,
  906. length = args.length,
  907. count = length,
  908. deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ?
  909. firstParam :
  910. jQuery.Deferred();
  911. function resolveFunc( i ) {
  912. return function( value ) {
  913. args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
  914. if ( !( --count ) ) {
  915. // Strange bug in FF4:
  916. // Values changed onto the arguments object sometimes end up as undefined values
  917. // outside the $.when method. Cloning the object into a fresh array solves the issue
  918. deferred.resolveWith( deferred, sliceDeferred.call( args, 0 ) );
  919. }
  920. };
  921. }
  922. if ( length > 1 ) {
  923. for( ; i < length; i++ ) {
  924. if ( args[ i ] && jQuery.isFunction( args[ i ].promise ) ) {
  925. args[ i ].promise().then( resolveFunc(i), deferred.reject );
  926. } else {
  927. --count;
  928. }
  929. }
  930. if ( !count ) {
  931. deferred.resolveWith( deferred, args );
  932. }
  933. } else if ( deferred !== firstParam ) {
  934. deferred.resolveWith( deferred, length ? [ firstParam ] : [] );
  935. }
  936. return deferred.promise();
  937. }
  938. });
  939. jQuery.support = (function() {
  940. var div = document.createElement( "div" ),
  941. documentElement = document.documentElement,
  942. all,
  943. a,
  944. select,
  945. opt,
  946. input,
  947. marginDiv,
  948. support,
  949. fragment,
  950. body,
  951. bodyStyle,
  952. tds,
  953. events,
  954. eventName,
  955. i,
  956. isSupported;
  957. // Preliminary tests
  958. div.setAttribute("className", "t");
  959. div.innerHTML = " <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
  960. all = div.getElementsByTagName( "*" );
  961. a = div.getElementsByTagName( "a" )[ 0 ];
  962. // Can't get basic test support
  963. if ( !all || !all.length || !a ) {
  964. return {};
  965. }
  966. // First batch of supports tests
  967. select = document.createElement( "select" );
  968. opt = select.appendChild( document.createElement("option") );
  969. input = div.getElementsByTagName( "input" )[ 0 ];
  970. support = {
  971. // IE strips leading whitespace when .innerHTML is used
  972. leadingWhitespace: ( div.firstChild.nodeType === 3 ),
  973. // Make sure that tbody elements aren't automatically inserted
  974. // IE will insert them into empty tables
  975. tbody: !div.getElementsByTagName( "tbody" ).length,
  976. // Make sure that link elements get serialized correctly by innerHTML
  977. // This requires a wrapper element in IE
  978. htmlSerialize: !!div.getElementsByTagName( "link" ).length,
  979. // Get the style information from getAttribute
  980. // (IE uses .cssText instead)
  981. style: /top/.test( a.getAttribute("style") ),
  982. // Make sure that URLs aren't manipulated
  983. // (IE normalizes it by default)
  984. hrefNormalized: ( a.getAttribute( "href" ) === "/a" ),
  985. // Make sure that element opacity exists
  986. // (IE uses filter instead)
  987. // Use a regex to work around a WebKit issue. See #5145
  988. opacity: /^0.55$/.test( a.style.opacity ),
  989. // Verify style float existence
  990. // (IE uses styleFloat instead of cssFloat)
  991. cssFloat: !!a.style.cssFloat,
  992. // Make sure that if no value is specified for a checkbox
  993. // that it defaults to "on".
  994. // (WebKit defaults to "" instead)
  995. checkOn: ( input.value === "on" ),
  996. // Make sure that a selected-by-default option has a working selected property.
  997. // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
  998. optSelected: opt.selected,
  999. // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
  1000. getSetAttribute: div.className !== "t",
  1001. // Will be defined later
  1002. submitBubbles: true,
  1003. changeBubbles: true,
  1004. focusinBubbles: false,
  1005. deleteExpando: true,
  1006. noCloneEvent: true,
  1007. inlineBlockNeedsLayout: false,
  1008. shrinkWrapBlocks: false,
  1009. reliableMarginRight: true
  1010. };
  1011. // Make sure checked status is properly cloned
  1012. input.checked = true;
  1013. support.noCloneChecked = input.cloneNode( true ).checked;
  1014. // Make sure that the options inside disabled selects aren't marked as disabled
  1015. // (WebKit marks them as disabled)
  1016. select.disabled = true;
  1017. support.optDisabled = !opt.disabled;
  1018. // Test to see if it's possible to delete an expando from an element
  1019. // Fails in Internet Explorer
  1020. try {
  1021. delete div.test;
  1022. } catch( e ) {
  1023. support.deleteExpando = false;
  1024. }
  1025. if ( !div.addEventListener && div.attachEvent && div.fireEvent ) {
  1026. div.attachEvent( "onclick", function click() {
  1027. // Cloning a node shouldn't copy over any
  1028. // bound event handlers (IE does this)
  1029. support.noCloneEvent = false;
  1030. div.detachEvent( "onclick", click );
  1031. });
  1032. div.cloneNode( true ).fireEvent( "onclick" );
  1033. }
  1034. // Check if a radio maintains it's value
  1035. // after being appended to the DOM
  1036. input = document.createElement("input");
  1037. input.value = "t";
  1038. input.setAttribute("type", "radio");
  1039. support.radioValue = input.value === "t";
  1040. input.setAttribute("checked", "checked");
  1041. div.appendChild( input );
  1042. fragment = document.createDocumentFragment();
  1043. fragment.appendChild( div.firstChild );
  1044. // WebKit doesn't clone checked state correctly in fragments
  1045. support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
  1046. div.innerHTML = "";
  1047. // Figure out if the W3C box model works as expected
  1048. div.style.width = div.style.paddingLeft = "1px";
  1049. // We use our own, invisible, body
  1050. body = document.createElement( "body" );
  1051. bodyStyle = {
  1052. visibility: "hidden",
  1053. width: 0,
  1054. height: 0,
  1055. border: 0,
  1056. margin: 0,
  1057. // Set background to avoid IE crashes when removing (#9028)
  1058. background: "none"
  1059. };
  1060. for ( i in bodyStyle ) {
  1061. body.style[ i ] = bodyStyle[ i ];
  1062. }
  1063. body.appendChild( div );
  1064. documentElement.insertBefore( body, documentElement.firstChild );
  1065. // Check if a disconnected checkbox will retain its checked
  1066. // value of true after appended to the DOM (IE6/7)
  1067. support.appendChecked = input.checked;
  1068. support.boxModel = div.offsetWidth === 2;
  1069. if ( "zoom" in div.style ) {
  1070. // Check if natively block-level elements act like inline-block
  1071. // elements when setting their display to 'inline' and giving
  1072. // them layout
  1073. // (IE < 8 does this)
  1074. div.style.display = "inline";
  1075. div.style.zoom = 1;
  1076. support.inlineBlockNeedsLayout = ( div.offsetWidth === 2 );
  1077. // Check if elements with layout shrink-wrap their children
  1078. // (IE 6 does this)
  1079. div.style.display = "";
  1080. div.innerHTML = "<div style='width:4px;'></div>";
  1081. support.shrinkWrapBlocks = ( div.offsetWidth !== 2 );
  1082. }
  1083. div.innerHTML = "<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>";
  1084. tds = div.getElementsByTagName( "td" );
  1085. // Check if table cells still have offsetWidth/Height when they are set
  1086. // to display:none and there are still other visible table cells in a
  1087. // table row; if so, offsetWidth/Height are not reliable for use when
  1088. // determining if an element has been hidden directly using
  1089. // display:none (it is still safe to use offsets if a parent element is
  1090. // hidden; don safety goggles and see bug #4512 for more information).
  1091. // (only IE 8 fails this test)
  1092. isSupported = ( tds[ 0 ].offsetHeight === 0 );
  1093. tds[ 0 ].style.display = "";
  1094. tds[ 1 ].style.display = "none";
  1095. // Check if empty table cells still have offsetWidth/Height
  1096. // (IE < 8 fail this test)
  1097. support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
  1098. div.innerHTML = "";
  1099. // Check if div with explicit width and no margin-right incorrectly
  1100. // gets computed margin-right based on width of container. For more
  1101. // info see bug #3333
  1102. // Fails in WebKit before Feb 2011 nightlies
  1103. // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
  1104. if ( document.defaultView && document.defaultView.getComputedStyle ) {
  1105. marginDiv = document.createElement( "div" );
  1106. marginDiv.style.width = "0";
  1107. marginDiv.style.marginRight = "0";
  1108. div.appendChild( marginDiv );
  1109. support.reliableMarginRight =
  1110. ( parseInt( ( document.defaultView.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
  1111. }
  1112. // Remove the body element we added
  1113. body.innerHTML = "";
  1114. documentElement.removeChild( body );
  1115. // Technique from Juriy Zaytsev
  1116. // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
  1117. // We only care about the case where non-standard event systems
  1118. // are used, namely in IE. Short-circuiting here helps us to
  1119. // avoid an eval call (in setAttribute) which can cause CSP
  1120. // to go haywire. See: https://developer.mozilla.org/en/Security/CSP
  1121. if ( div.attachEvent ) {
  1122. for( i in {
  1123. submit: 1,
  1124. change: 1,
  1125. focusin: 1
  1126. } ) {
  1127. eventName = "on" + i;
  1128. isSupported = ( eventName in div );
  1129. if ( !isSupported ) {
  1130. div.setAttribute( eventName, "return;" );
  1131. isSupported = ( typeof div[ eventName ] === "function" );
  1132. }
  1133. support[ i + "Bubbles" ] = isSupported;
  1134. }
  1135. }
  1136. return support;
  1137. })();
  1138. // Keep track of boxModel
  1139. jQuery.boxModel = jQuery.support.boxModel;
  1140. var rbrace = /^(?:\{.*\}|\[.*\])$/,
  1141. rmultiDash = /([a-z])([A-Z])/g;
  1142. jQuery.extend({
  1143. cache: {},
  1144. // Please use with caution
  1145. uuid: 0,
  1146. // Unique for each copy of jQuery on the page
  1147. // Non-digits removed to match rinlinejQuery
  1148. expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
  1149. // The following elements throw uncatchable exceptions if you
  1150. // attempt to add expando properties to them.
  1151. noData: {
  1152. "embed": true,
  1153. // Ban all objects except for Flash (which handle expandos)
  1154. "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
  1155. "applet": true
  1156. },
  1157. hasData: function( elem ) {
  1158. elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
  1159. return !!elem && !isEmptyDataObject( elem );
  1160. },
  1161. data: function( elem, name, data, pvt /* Internal Use Only */ ) {
  1162. if ( !jQuery.acceptData( elem ) ) {
  1163. return;
  1164. }
  1165. var internalKey = jQuery.expando, getByName = typeof name === "string", thisCache,
  1166. // We have to handle DOM nodes and JS objects differently because IE6-7
  1167. // can't GC object references properly across the DOM-JS boundary
  1168. isNode = elem.nodeType,
  1169. // Only DOM nodes need the global jQuery cache; JS object data is
  1170. // attached directly to the object so GC can occur automatically
  1171. cache = isNode ? jQuery.cache : elem,
  1172. // Only defining an ID for JS objects if its cache already exists allows
  1173. // the code to shortcut on the same path as a DOM node with no cache
  1174. id = isNode ? elem[ jQuery.expando ] : elem[ jQuery.expando ] && jQuery.expando;
  1175. // Avoid doing any more work than we need to when trying to get data on an
  1176. // object that has no data at all
  1177. if ( (!id || (pvt && id && !cache[ id ][ internalKey ])) && getByName && data === undefined ) {
  1178. return;
  1179. }
  1180. if ( !id ) {
  1181. // Only DOM nodes need a new unique ID for each element since their data
  1182. // ends up in the global cache
  1183. if ( isNode ) {
  1184. elem[ jQuery.expando ] = id = ++jQuery.uuid;
  1185. } else {
  1186. id = jQuery.expando;
  1187. }
  1188. }
  1189. if ( !cache[ id ] ) {
  1190. cache[ id ] = {};
  1191. // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
  1192. // metadata on plain JS objects when the object is serialized using
  1193. // JSON.stringify
  1194. if ( !isNode ) {
  1195. cache[ id ].toJSON = jQuery.noop;
  1196. }
  1197. }
  1198. // An object can be passed to jQuery.data instead of a key/value pair; this gets
  1199. // shallow copied over onto the existing cache
  1200. if ( typeof name === "object" || typeof name === "function" ) {
  1201. if ( pvt ) {
  1202. cache[ id ][ internalKey ] = jQuery.extend(cache[ id ][ internalKey ], name);
  1203. } else {
  1204. cache[ id ] = jQuery.extend(cache[ id ], name);
  1205. }
  1206. }
  1207. thisCache = cache[ id ];
  1208. // Internal jQuery data is stored in a separate object inside the object's data
  1209. // cache in order to avoid key collisions between internal data and user-defined
  1210. // data
  1211. if ( pvt ) {
  1212. if ( !thisCache[ internalKey ] ) {
  1213. thisCache[ internalKey ] = {};
  1214. }
  1215. thisCache = thisCache[ internalKey ];
  1216. }
  1217. if ( data !== undefined ) {
  1218. thisCache[ jQuery.camelCase( name ) ] = data;
  1219. }
  1220. // TODO: This is a hack for 1.5 ONLY. It will be removed in 1.6. Users should
  1221. // not attempt to inspect the internal events object using jQuery.data, as this
  1222. // internal data object is undocumented and subject to change.
  1223. if ( name === "events" && !thisCache[name] ) {
  1224. return thisCache[ internalKey ] && thisCache[ internalKey ].events;
  1225. }
  1226. return getByName ? thisCache[ jQuery.camelCase( name ) ] : thisCache;
  1227. },
  1228. removeData: function( elem, name, pvt /* Internal Use Only */ ) {
  1229. if ( !jQuery.acceptData( elem ) ) {
  1230. return;
  1231. }
  1232. var internalKey = jQuery.expando, isNode = elem.nodeType,
  1233. // See jQuery.data for more information
  1234. cache = isNode ? jQuery.cache : elem,
  1235. // See jQuery.data for more information
  1236. id = isNode ? elem[ jQuery.expando ] : jQuery.expando;
  1237. // If there is already no cache entry for this object, there is no
  1238. // purpose in continuing
  1239. if ( !cache[ id ] ) {
  1240. return;
  1241. }
  1242. if ( name ) {
  1243. var thisCache = pvt ? cache[ id ][ internalKey ] : cache[ id ];
  1244. if ( thisCache ) {
  1245. delete thisCache[ name ];
  1246. // If there is no data left in the cache, we want to continue
  1247. // and let the cache object itself get destroyed
  1248. if ( !isEmptyDataObject(thisCache) ) {
  1249. return;
  1250. }
  1251. }
  1252. }
  1253. // See jQuery.data for more information
  1254. if ( pvt ) {
  1255. delete cache[ id ][ internalKey ];
  1256. // Don't destroy the parent cache unless the internal data object
  1257. // had been the only thing left in it
  1258. if ( !isEmptyDataObject(cache[ id ]) ) {
  1259. return;
  1260. }
  1261. }
  1262. var internalCache = cache[ id ][ internalKey ];
  1263. // Browsers that fail expando deletion also refuse to delete expandos on
  1264. // the window, but it will allow it on all other JS objects; other browsers
  1265. // don't care
  1266. if ( jQuery.support.deleteExpando || cache != window ) {
  1267. delete cache[ id ];
  1268. } else {
  1269. cache[ id ] = null;
  1270. }
  1271. // We destroyed the entire user cache at once because it's faster than
  1272. // iterating through each key, but we need to continue to persist internal
  1273. // data if it existed
  1274. if ( internalCache ) {
  1275. cache[ id ] = {};
  1276. // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
  1277. // metadata on plain JS objects when the object is serialized using
  1278. // JSON.stringify
  1279. if ( !isNode ) {
  1280. cache[ id ].toJSON = jQuery.noop;
  1281. }
  1282. cache[ id ][ internalKey ] = internalCache;
  1283. // Otherwise, we need to eliminate the expando on the node to avoid
  1284. // false lookups in the cache for entries that no longer exist
  1285. } else if ( isNode ) {
  1286. // IE does not allow us to delete expando properties from nodes,
  1287. // nor does it have a removeAttribute function on Document nodes;
  1288. // we must handle all of these cases
  1289. if ( jQuery.support.deleteExpando ) {
  1290. delete elem[ jQuery.expando ];
  1291. } else if ( elem.removeAttribute ) {
  1292. elem.removeAttribute( jQuery.expando );
  1293. } else {
  1294. elem[ jQuery.expando ] = null;
  1295. }
  1296. }
  1297. },
  1298. // For internal use only.
  1299. _data: function( elem, name, data ) {
  1300. return jQuery.data( elem, name, data, true );
  1301. },
  1302. // A method for determining if a DOM node can handle the data expando
  1303. acceptData: function( elem ) {
  1304. if ( elem.nodeName ) {
  1305. var match = jQuery.noData[ elem.nodeName.toLowerCase() ];
  1306. if ( match ) {
  1307. return !(match === true || elem.getAttribute("classid") !== match);
  1308. }
  1309. }
  1310. return true;
  1311. }
  1312. });
  1313. jQuery.fn.extend({
  1314. data: function( key, value ) {
  1315. var data = null;
  1316. if ( typeof key === "undefined" ) {
  1317. if ( this.length ) {
  1318. data = jQuery.data( this[0] );
  1319. if ( this[0].nodeType === 1 ) {
  1320. var attr = this[0].attributes, name;
  1321. for ( var i = 0, l = attr.length; i < l; i++ ) {
  1322. name = attr[i].name;
  1323. if ( name.indexOf( "data-" ) === 0 ) {
  1324. name = jQuery.camelCase( name.substring(5) );
  1325. dataAttr( this[0], name, data[ name ] );
  1326. }
  1327. }
  1328. }
  1329. }
  1330. return data;
  1331. } else if ( typeof key === "object" ) {
  1332. return this.each(function() {
  1333. jQuery.data( this, key );
  1334. });
  1335. }
  1336. var parts = key.split(".");
  1337. parts[1] = parts[1] ? "." + parts[1] : "";
  1338. if ( value === undefined ) {
  1339. data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
  1340. // Try to fetch any internally stored data first
  1341. if ( data === undefined && this.length ) {
  1342. data = jQuery.data( this[0], key );
  1343. data = dataAttr( this[0], key, data );
  1344. }
  1345. return data === undefined && parts[1] ?
  1346. this.data( parts[0] ) :
  1347. data;
  1348. } else {
  1349. return this.each(function() {
  1350. var $this = jQuery( this ),
  1351. args = [ parts[0], value ];
  1352. $this.triggerHandler( "setData" + parts[1] + "!", args );
  1353. jQuery.data( this, key, value );
  1354. $this.triggerHandler( "changeData" + parts[1] + "!", args );
  1355. });
  1356. }
  1357. },
  1358. removeData: function( key ) {
  1359. return this.each(function() {
  1360. jQuery.removeData( this, key );
  1361. });
  1362. }
  1363. });
  1364. function dataAttr( elem, key, data ) {
  1365. // If nothing was found internally, try to fetch any
  1366. // data from the HTML5 data-* attribute
  1367. if ( data === undefined && elem.nodeType === 1 ) {
  1368. var name = "data-" + key.replace( rmultiDash, "$1-$2" ).toLowerCase();
  1369. data = elem.getAttribute( name );
  1370. if ( typeof data === "string" ) {
  1371. try {
  1372. data = data === "true" ? true :
  1373. data === "false" ? false :
  1374. data === "null" ? null :
  1375. !jQuery.isNaN( data ) ? parseFloat( data ) :
  1376. rbrace.test( data ) ? jQuery.parseJSON( data ) :
  1377. data;
  1378. } catch( e ) {}
  1379. // Make sure we set the data so it isn't changed later
  1380. jQuery.data( elem, key, data );
  1381. } else {
  1382. data = undefined;
  1383. }
  1384. }
  1385. return data;
  1386. }
  1387. // TODO: This is a hack for 1.5 ONLY to allow objects with a single toJSON
  1388. // property to be considered empty objects; this property always exists in
  1389. // order to make sure JSON.stringify does not expose internal metadata
  1390. function isEmptyDataObject( obj ) {
  1391. for ( var name in obj ) {
  1392. if ( name !== "toJSON" ) {
  1393. return false;
  1394. }
  1395. }
  1396. return true;
  1397. }
  1398. function handleQueueMarkDefer( elem, type, src ) {
  1399. var deferDataKey = type + "defer",
  1400. queueDataKey = type + "queue",
  1401. markDataKey = type + "mark",
  1402. defer = jQuery.data( elem, deferDataKey, undefined, true );
  1403. if ( defer &&
  1404. ( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) &&
  1405. ( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) {
  1406. // Give room for hard-coded callbacks to fire first
  1407. // and eventually mark/queue something else on the element
  1408. setTimeout( function() {
  1409. if ( !jQuery.data( elem, queueDataKey, undefined, true ) &&
  1410. !jQuery.data( elem, markDataKey, undefined, true ) ) {
  1411. jQuery.removeData( elem, deferDataKey, true );
  1412. defer.resolve();
  1413. }
  1414. }, 0 );
  1415. }
  1416. }
  1417. jQuery.extend({
  1418. _mark: function( elem, type ) {
  1419. if ( elem ) {
  1420. type = (type || "fx") + "mark";
  1421. jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true );
  1422. }
  1423. },
  1424. _unmark: function( force, elem, type ) {
  1425. if ( force !== true ) {
  1426. type = elem;
  1427. elem = force;
  1428. force = false;
  1429. }
  1430. if ( elem ) {
  1431. type = type || "fx";
  1432. var key = type + "mark",
  1433. count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 );
  1434. if ( count ) {
  1435. jQuery.data( elem, key, count, true );
  1436. } else {
  1437. jQuery.removeData( elem, key, true );
  1438. handleQueueMarkDefer( elem, type, "mark" );
  1439. }
  1440. }
  1441. },
  1442. queue: function( elem, type, data ) {
  1443. if ( elem ) {
  1444. type = (type || "fx") + "queue";
  1445. var q = jQuery.data( elem, type, undefined, true );
  1446. // Speed up dequeue by getting out quickly if this is just a lookup
  1447. if ( data ) {
  1448. if ( !q || jQuery.isArray(data) ) {
  1449. q = jQuery.data( elem, type, jQuery.makeArray(data), true );
  1450. } else {
  1451. q.push( data );
  1452. }
  1453. }
  1454. return q || [];
  1455. }
  1456. },
  1457. dequeue: function( elem, type ) {
  1458. type = type || "fx";
  1459. var queue = jQuery.queue( elem, type ),
  1460. fn = queue.shift(),
  1461. defer;
  1462. // If the fx queue is dequeued, always remove the progress sentinel
  1463. if ( fn === "inprogress" ) {
  1464. fn = queue.shift();
  1465. }
  1466. if ( fn ) {
  1467. // Add a progress sentinel to prevent the fx queue from being
  1468. // automatically dequeued
  1469. if ( type === "fx" ) {
  1470. queue.unshift("inprogress");
  1471. }
  1472. fn.call(elem, function() {
  1473. jQuery.dequeue(elem, type);
  1474. });
  1475. }
  1476. if ( !queue.length ) {
  1477. jQuery.removeData( elem, type + "queue", true );
  1478. handleQueueMarkDefer( elem, type, "queue" );
  1479. }
  1480. }
  1481. });
  1482. jQuery.fn.extend({
  1483. queue: function( type, data ) {
  1484. if ( typeof type !== "string" ) {
  1485. data = type;
  1486. type = "fx";
  1487. }
  1488. if ( data === undefined ) {
  1489. return jQuery.queue( this[0], type );
  1490. }
  1491. return this.each(function() {
  1492. var queue = jQuery.queue( this, type, data );
  1493. if ( type === "fx" && queue[0] !== "inprogress" ) {
  1494. jQuery.dequeue( this, type );
  1495. }
  1496. });
  1497. },
  1498. dequeue: function( type ) {
  1499. return this.each(function() {
  1500. jQuery.dequeue( this, type );
  1501. });
  1502. },
  1503. // Based off of the plugin by Clint Helfers, with permission.
  1504. // http://blindsignals.com/index.php/2009/07/jquery-delay/
  1505. delay: function( time, type ) {
  1506. time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
  1507. type = type || "fx";
  1508. return this.queue( type, function() {
  1509. var elem = this;
  1510. setTimeout(function() {
  1511. jQuery.dequeue( elem, type );
  1512. }, time );
  1513. });
  1514. },
  1515. clearQueue: function( type ) {
  1516. return this.queue( type || "fx", [] );
  1517. },
  1518. // Get a promise resolved when queues of a certain type
  1519. // are emptied (fx is the type by default)
  1520. promise: function( type, object ) {
  1521. if ( typeof type !== "string" ) {
  1522. object = type;
  1523. type = undefined;
  1524. }
  1525. type = type || "fx";
  1526. var defer = jQuery.Deferred(),
  1527. elements = this,
  1528. i = elements.length,
  1529. count = 1,
  1530. deferDataKey = type + "defer",
  1531. queueDataKey = type + "queue",
  1532. markDataKey = type + "mark",
  1533. tmp;
  1534. function resolve() {
  1535. if ( !( --count ) ) {
  1536. defer.resolveWith( elements, [ elements ] );
  1537. }
  1538. }
  1539. while( i-- ) {
  1540. if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
  1541. ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
  1542. jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
  1543. jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) {
  1544. count++;
  1545. tmp.done( resolve );
  1546. }
  1547. }
  1548. resolve();
  1549. return defer.promise();
  1550. }
  1551. });
  1552. var rclass = /[\n\t\r]/g,
  1553. rspace = /\s+/,
  1554. rreturn = /\r/g,
  1555. rtype = /^(?:button|input)$/i,
  1556. rfocusable = /^(?:button|input|object|select|textarea)$/i,
  1557. rclickable = /^a(?:rea)?$/i,
  1558. rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
  1559. rinvalidChar = /\:/,
  1560. formHook, boolHook;
  1561. jQuery.fn.extend({
  1562. attr: function( name, value ) {
  1563. return jQuery.access( this, name, value, true, jQuery.attr );
  1564. },
  1565. removeAttr: function( name ) {
  1566. return this.each(function() {
  1567. jQuery.removeAttr( this, name );
  1568. });
  1569. },
  1570. prop: function( name, value ) {
  1571. return jQuery.access( this, name, value, true, jQuery.prop );
  1572. },
  1573. removeProp: function( name ) {
  1574. name = jQuery.propFix[ name ] || name;
  1575. return this.each(function() {
  1576. // try/catch handles cases where IE balks (such as removing a property on window)
  1577. try {
  1578. this[ name ] = undefined;
  1579. delete this[ name ];
  1580. } catch( e ) {}
  1581. });
  1582. },
  1583. addClass: function( value ) {
  1584. if ( jQuery.isFunction( value ) ) {
  1585. return this.each(function(i) {
  1586. var self = jQuery(this);
  1587. self.addClass( value.call(this, i, self.attr("class") || "") );
  1588. });
  1589. }
  1590. if ( value && typeof value === "string" ) {
  1591. var classNames = (value || "").split( rspace );
  1592. for ( var i = 0, l = this.length; i < l; i++ ) {
  1593. var elem = this[i];
  1594. if ( elem.nodeType === 1 ) {
  1595. if ( !elem.className ) {
  1596. elem.className = value;
  1597. } else {
  1598. var className = " " + elem.className + " ",
  1599. setClass = elem.className;
  1600. for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
  1601. if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) {
  1602. setClass += " " + classNames[c];
  1603. }
  1604. }
  1605. elem.className = jQuery.trim( setClass );
  1606. }
  1607. }
  1608. }
  1609. }
  1610. return this;
  1611. },
  1612. removeClass: function( value ) {
  1613. if ( jQuery.isFunction(value) ) {
  1614. return this.each(function(i) {
  1615. var self = jQuery(this);
  1616. self.removeClass( value.call(this, i, self.attr("class")) );
  1617. });
  1618. }
  1619. if ( (value && typeof value === "string") || value === undefined ) {
  1620. var classNames = (value || "").split( rspace );
  1621. for ( var i = 0, l = this.length; i < l; i++ ) {
  1622. var elem = this[i];
  1623. if ( elem.nodeType === 1 && elem.className ) {
  1624. if ( value ) {
  1625. var className = (" " + elem.className + " ").replace(rclass, " ");
  1626. for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
  1627. className = className.replace(" " + classNames[c] + " ", " ");
  1628. }
  1629. elem.className = jQuery.trim( className );
  1630. } else {
  1631. elem.className = "";
  1632. }
  1633. }
  1634. }
  1635. }
  1636. return this;
  1637. },
  1638. toggleClass: function( value, stateVal ) {
  1639. var type = typeof value,
  1640. isBool = typeof stateVal === "boolean";
  1641. if ( jQuery.isFunction( value ) ) {
  1642. return this.each(function(i) {
  1643. var self = jQuery(this);
  1644. self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal );
  1645. });
  1646. }
  1647. return this.each(function() {
  1648. if ( type === "string" ) {
  1649. // toggle individual class names
  1650. var className,
  1651. i = 0,
  1652. self = jQuery( this ),
  1653. state = stateVal,
  1654. classNames = value.split( rspace );
  1655. while ( (className = classNames[ i++ ]) ) {
  1656. // check each className given, space seperated list
  1657. state = isBool ? state : !self.hasClass( className );
  1658. self[ state ? "addClass" : "removeClass" ]( className );
  1659. }
  1660. } else if ( type === "undefined" || type === "boolean" ) {
  1661. if ( this.className ) {
  1662. // store className if set
  1663. jQuery._data( this, "__className__", this.className );
  1664. }
  1665. // toggle whole className
  1666. this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || "";
  1667. }
  1668. });
  1669. },
  1670. hasClass: function( selector ) {
  1671. var className = " " + selector + " ";
  1672. for ( var i = 0, l = this.length; i < l; i++ ) {
  1673. if ( (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
  1674. return true;
  1675. }
  1676. }
  1677. return false;
  1678. },
  1679. val: function( value ) {
  1680. var hooks, ret,
  1681. elem = this[0];
  1682. if ( !arguments.length ) {
  1683. if ( elem ) {
  1684. hooks = jQuery.valHooks[ elem.nodeName.toLowerCase() ] || jQuery.valHooks[ elem.type ];
  1685. if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
  1686. return ret;
  1687. }
  1688. return (elem.value || "").replace(rreturn, "");
  1689. }
  1690. return undefined;
  1691. }
  1692. var isFunction = jQuery.isFunction( value );
  1693. return this.each(function( i ) {
  1694. var self = jQuery(this), val;
  1695. if ( this.nodeType !== 1 ) {
  1696. return;
  1697. }
  1698. if ( isFunction ) {
  1699. val = value.call( this, i, self.val() );
  1700. } else {
  1701. val = value;
  1702. }
  1703. // Treat null/undefined as ""; convert numbers to string
  1704. if ( val == null ) {
  1705. val = "";
  1706. } else if ( typeof val === "number" ) {
  1707. val += "";
  1708. } else if ( jQuery.isArray( val ) ) {
  1709. val = jQuery.map(val, function ( value ) {
  1710. return value == null ? "" : value + "";
  1711. });
  1712. }
  1713. hooks = jQuery.valHooks[ this.nodeName.toLowerCase() ] || jQuery.valHooks[ this.type ];
  1714. // If set returns undefined, fall back to normal setting
  1715. if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
  1716. this.value = val;
  1717. }
  1718. });
  1719. }
  1720. });
  1721. jQuery.extend({
  1722. valHooks: {
  1723. option: {
  1724. get: function( elem ) {
  1725. // attributes.value is undefined in Blackberry 4.7 but
  1726. // uses .value. See #6932
  1727. var val = elem.attributes.value;
  1728. return !val || val.specified ? elem.value : elem.text;
  1729. }
  1730. },
  1731. select: {
  1732. get: function( elem ) {
  1733. var value,
  1734. index = elem.selectedIndex,
  1735. values = [],
  1736. options = elem.options,
  1737. one = elem.type === "select-one";
  1738. // Nothing was selected
  1739. if ( index < 0 ) {
  1740. return null;
  1741. }
  1742. // Loop through all the selected options
  1743. for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
  1744. var option = options[ i ];
  1745. // Don't return options that are disabled or in a disabled optgroup
  1746. if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
  1747. (!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) {
  1748. // Get the specific value for the option
  1749. value = jQuery( option ).val();
  1750. // We don't need an array for one selects
  1751. if ( one ) {
  1752. return value;
  1753. }
  1754. // Multi-Selects return an array
  1755. values.push( value );
  1756. }
  1757. }
  1758. // Fixes Bug #2551 -- select.val() broken in IE after form.reset()
  1759. if ( one && !values.length && options.length ) {
  1760. return jQuery( options[ index ] ).val();
  1761. }
  1762. return values;
  1763. },
  1764. set: function( elem, value ) {
  1765. var values = jQuery.makeArray( value );
  1766. jQuery(elem).find("option").each(function() {
  1767. this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;
  1768. });
  1769. if ( !values.length ) {
  1770. elem.selectedIndex = -1;
  1771. }
  1772. return values;
  1773. }
  1774. }
  1775. },
  1776. attrFn: {
  1777. val: true,
  1778. css: true,
  1779. html: true,
  1780. text: true,
  1781. data: true,
  1782. width: true,
  1783. height: true,
  1784. offset: true
  1785. },
  1786. attrFix: {
  1787. // Always normalize to ensure hook usage
  1788. tabindex: "tabIndex"
  1789. },
  1790. attr: function( elem, name, value, pass ) {
  1791. var nType = elem.nodeType;
  1792. // don't get/set attributes on text, comment and attribute nodes
  1793. if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
  1794. return undefined;
  1795. }
  1796. if ( pass && name in jQuery.attrFn ) {
  1797. return jQuery( elem )[ name ]( value );
  1798. }
  1799. // Fallback to prop when attributes are not supported
  1800. if ( !("getAttribute" in elem) ) {
  1801. return jQuery.prop( elem, name, value );
  1802. }
  1803. var ret, hooks,
  1804. notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
  1805. // Normalize the name if needed
  1806. name = notxml && jQuery.attrFix[ name ] || name;
  1807. hooks = jQuery.attrHooks[ name ];
  1808. if ( !hooks ) {
  1809. // Use boolHook for boolean attributes
  1810. if ( rboolean.test( name ) &&
  1811. (typeof value === "boolean" || value === undefined || value.toLowerCase() === name.toLowerCase()) ) {
  1812. hooks = boolHook;
  1813. // Use formHook for forms and if the name contains certain characters
  1814. } else if ( formHook && (jQuery.nodeName( elem, "form" ) || rinvalidChar.test( name )) ) {
  1815. hooks = formHook;
  1816. }
  1817. }
  1818. if ( value !== undefined ) {
  1819. if ( value === null ) {
  1820. jQuery.removeAttr( elem, name );
  1821. return undefined;
  1822. } else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) {
  1823. return ret;
  1824. } else {
  1825. elem.setAttribute( name, "" + value );
  1826. return value;
  1827. }
  1828. } else if ( hooks && "get" in hooks && notxml ) {
  1829. return hooks.get( elem, name );
  1830. } else {
  1831. ret = elem.getAttribute( name );
  1832. // Non-existent attributes return null, we normalize to undefined
  1833. return ret === null ?
  1834. undefined :
  1835. ret;
  1836. }
  1837. },
  1838. removeAttr: function( elem, name ) {
  1839. var propName;
  1840. if ( elem.nodeType === 1 ) {
  1841. name = jQuery.attrFix[ name ] || name;
  1842. if ( jQuery.support.getSetAttribute ) {
  1843. // Use removeAttribute in browsers that support it
  1844. elem.removeAttribute( name );
  1845. } else {
  1846. jQuery.attr( elem, name, "" );
  1847. elem.removeAttributeNode( elem.getAttributeNode( name ) );
  1848. }
  1849. // Set corresponding property to false for boolean attributes
  1850. if ( rboolean.test( name ) && (propName = jQuery.propFix[ name ] || name) in elem ) {
  1851. elem[ propName ] = false;
  1852. }
  1853. }
  1854. },
  1855. attrHooks: {
  1856. type: {
  1857. set: function( elem, value ) {
  1858. // We can't allow the type property to be changed (since it causes problems in IE)
  1859. if ( rtype.test( elem.nodeName ) && elem.parentNode ) {
  1860. jQuery.error( "type property can't be changed" );
  1861. } else if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
  1862. // Setting the type on a radio button after the value resets the value in IE6-9
  1863. // Reset value to it's default in case type is set after value
  1864. // This is for element creation
  1865. var val = elem.value;
  1866. elem.setAttribute( "type", value );
  1867. if ( val ) {
  1868. elem.value = val;
  1869. }
  1870. return value;
  1871. }
  1872. }
  1873. },
  1874. tabIndex: {
  1875. get: function( elem ) {
  1876. // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
  1877. // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
  1878. var attributeNode = elem.getAttributeNode("tabIndex");
  1879. return attributeNode && attributeNode.specified ?
  1880. parseInt( attributeNode.value, 10 ) :
  1881. rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
  1882. 0 :
  1883. undefined;
  1884. }
  1885. }
  1886. },
  1887. propFix: {
  1888. tabindex: "tabIndex",
  1889. readonly: "readOnly",
  1890. "for": "htmlFor",
  1891. "class": "className",
  1892. maxlength: "maxLength",
  1893. cellspacing: "cellSpacing",
  1894. cellpadding: "cellPadding",
  1895. rowspan: "rowSpan",
  1896. colspan: "colSpan",
  1897. usemap: "useMap",
  1898. frameborder: "frameBorder",
  1899. contenteditable: "contentEditable"
  1900. },
  1901. prop: function( elem, name, value ) {
  1902. var nType = elem.nodeType;
  1903. // don't get/set properties on text, comment and attribute nodes
  1904. if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
  1905. return undefined;
  1906. }
  1907. var ret, hooks,
  1908. notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
  1909. // Try to normalize/fix the name
  1910. name = notxml && jQuery.propFix[ name ] || name;
  1911. hooks = jQuery.propHooks[ name ];
  1912. if ( value !== undefined ) {
  1913. if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
  1914. return ret;
  1915. } else {
  1916. return (elem[ name ] = value);
  1917. }
  1918. } else {
  1919. if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== undefined ) {
  1920. return ret;
  1921. } else {
  1922. return elem[ name ];
  1923. }
  1924. }
  1925. },
  1926. propHooks: {}
  1927. });
  1928. // Hook for boolean attributes
  1929. boolHook = {
  1930. get: function( elem, name ) {
  1931. // Align boolean attributes with corresponding properties
  1932. return elem[ jQuery.propFix[ name ] || name ] ?
  1933. name.toLowerCase() :
  1934. undefined;
  1935. },
  1936. set: function( elem, value, name ) {
  1937. var propName;
  1938. if ( value === false ) {
  1939. // Remove boolean attributes when set to false
  1940. jQuery.removeAttr( elem, name );
  1941. } else {
  1942. // value is true since we know at this point it's type boolean and not false
  1943. // Set boolean attributes to the same name and set the DOM property
  1944. propName = jQuery.propFix[ name ] || name;
  1945. if ( propName in elem ) {
  1946. // Only set the IDL specifically if it already exists on the element
  1947. elem[ propName ] = value;
  1948. }
  1949. elem.setAttribute( name, name.toLowerCase() );
  1950. }
  1951. return name;
  1952. }
  1953. };
  1954. // Use the value property for back compat
  1955. // Use the formHook for button elements in IE6/7 (#1954)
  1956. jQuery.attrHooks.value = {
  1957. get: function( elem, name ) {
  1958. if ( formHook && jQuery.nodeName( elem, "button" ) ) {
  1959. return formHook.get( elem, name );
  1960. }
  1961. return elem.value;
  1962. },
  1963. set: function( elem, value, name ) {
  1964. if ( formHook && jQuery.nodeName( elem, "button" ) ) {
  1965. return formHook.set( elem, value, name );
  1966. }
  1967. // Does not return so that setAttribute is also used
  1968. elem.value = value;
  1969. }
  1970. };
  1971. // IE6/7 do not support getting/setting some attributes with get/setAttribute
  1972. if ( !jQuery.support.getSetAttribute ) {
  1973. // propFix is more comprehensive and contains all fixes
  1974. jQuery.attrFix = jQuery.propFix;
  1975. // Use this for any attribute on a form in IE6/7
  1976. formHook = jQuery.attrHooks.name = jQuery.valHooks.button = {
  1977. get: function( elem, name ) {
  1978. var ret;
  1979. ret = elem.getAttributeNode( name );
  1980. // Return undefined if nodeValue is empty string
  1981. return ret && ret.nodeValue !== "" ?
  1982. ret.nodeValue :
  1983. undefined;
  1984. },
  1985. set: function( elem, value, name ) {
  1986. // Check form objects in IE (multiple bugs related)
  1987. // Only use nodeValue if the attribute node exists on the form
  1988. var ret = elem.getAttributeNode( name );
  1989. if ( ret ) {
  1990. ret.nodeValue = value;
  1991. return value;
  1992. }
  1993. }
  1994. };
  1995. // Set width and height to auto instead of 0 on empty string( Bug #8150 )
  1996. // This is for removals
  1997. jQuery.each([ "width", "height" ], function( i, name ) {
  1998. jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
  1999. set: function( elem, value ) {
  2000. if ( value === "" ) {
  2001. elem.setAttribute( name, "auto" );
  2002. return value;
  2003. }
  2004. }
  2005. });
  2006. });
  2007. }
  2008. // Some attributes require a special call on IE
  2009. if ( !jQuery.support.hrefNormalized ) {
  2010. jQuery.each([ "href", "src", "width", "height" ], function( i, name ) {
  2011. jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
  2012. get: function( elem ) {
  2013. var ret = elem.getAttribute( name, 2 );
  2014. return ret === null ? undefined : ret;
  2015. }
  2016. });
  2017. });
  2018. }
  2019. if ( !jQuery.support.style ) {
  2020. jQuery.attrHooks.style = {
  2021. get: function( elem ) {
  2022. // Return undefined in the case of empty string
  2023. // Normalize to lowercase since IE uppercases css property names
  2024. return elem.style.cssText.toLowerCase() || undefined;
  2025. },
  2026. set: function( elem, value ) {
  2027. return (elem.style.cssText = "" + value);
  2028. }
  2029. };
  2030. }
  2031. // Safari mis-reports the default selected property of an option
  2032. // Accessing the parent's selectedIndex property fixes it
  2033. if ( !jQuery.support.optSelected ) {
  2034. jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, {
  2035. get: function( elem ) {
  2036. var parent = elem.parentNode;
  2037. if ( parent ) {
  2038. parent.selectedIndex;
  2039. // Make sure that it also works with optgroups, see #5701
  2040. if ( parent.parentNode ) {
  2041. parent.parentNode.selectedIndex;
  2042. }
  2043. }
  2044. }
  2045. });
  2046. }
  2047. // Radios and checkboxes getter/setter
  2048. if ( !jQuery.support.checkOn ) {
  2049. jQuery.each([ "radio", "checkbox" ], function() {
  2050. jQuery.valHooks[ this ] = {
  2051. get: function( elem ) {
  2052. // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified
  2053. return elem.getAttribute("value") === null ? "on" : elem.value;
  2054. }
  2055. };
  2056. });
  2057. }
  2058. jQuery.each([ "radio", "checkbox" ], function() {
  2059. jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], {
  2060. set: function( elem, value ) {
  2061. if ( jQuery.isArray( value ) ) {
  2062. return (elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0);
  2063. }
  2064. }
  2065. });
  2066. });
  2067. var hasOwn = Object.prototype.hasOwnProperty,
  2068. rnamespaces = /\.(.*)$/,
  2069. rformElems = /^(?:textarea|input|select)$/i,
  2070. rperiod = /\./g,
  2071. rspaces = / /g,
  2072. rescape = /[^\w\s.|`]/g,
  2073. fcleanup = function( nm ) {
  2074. return nm.replace(rescape, "\\$&");
  2075. };
  2076. /*
  2077. * A number of helper functions used for managing events.
  2078. * Many of the ideas behind this code originated from
  2079. * Dean Edwards' addEvent library.
  2080. */
  2081. jQuery.event = {
  2082. // Bind an event to an element
  2083. // Original by Dean Edwards
  2084. add: function( elem, types, handler, data ) {
  2085. if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
  2086. return;
  2087. }
  2088. if ( handler === false ) {
  2089. handler = returnFalse;
  2090. } else if ( !handler ) {
  2091. // Fixes bug #7229. Fix recommended by jdalton
  2092. return;
  2093. }
  2094. var handleObjIn, handleObj;
  2095. if ( handler.handler ) {
  2096. handleObjIn = handler;
  2097. handler = handleObjIn.handler;
  2098. }
  2099. // Make sure that the function being executed has a unique ID
  2100. if ( !handler.guid ) {
  2101. handler.guid = jQuery.guid++;
  2102. }
  2103. // Init the element's event structure
  2104. var elemData = jQuery._data( elem );
  2105. // If no elemData is found then we must be trying to bind to one of the
  2106. // banned noData elements
  2107. if ( !elemData ) {
  2108. return;
  2109. }
  2110. var events = elemData.events,
  2111. eventHandle = elemData.handle;
  2112. if ( !events ) {
  2113. elemData.events = events = {};
  2114. }
  2115. if ( !eventHandle ) {
  2116. elemData.handle = eventHandle = function( e ) {
  2117. // Discard the second event of a jQuery.event.trigger() and
  2118. // when an event is called after a page has unloaded
  2119. return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
  2120. jQuery.event.handle.apply( eventHandle.elem, arguments ) :
  2121. undefined;
  2122. };
  2123. }
  2124. // Add elem as a property of the handle function
  2125. // This is to prevent a memory leak with non-native events in IE.
  2126. eventHandle.elem = elem;
  2127. // Handle multiple events separated by a space
  2128. // jQuery(...).bind("mouseover mouseout", fn);
  2129. types = types.split(" ");
  2130. var type, i = 0, namespaces;
  2131. while ( (type = types[ i++ ]) ) {
  2132. handleObj = handleObjIn ?
  2133. jQuery.extend({}, handleObjIn) :
  2134. { handler: handler, data: data };
  2135. // Namespaced event handlers
  2136. if ( type.indexOf(".") > -1 ) {
  2137. namespaces = type.split(".");
  2138. type = namespaces.shift();
  2139. handleObj.namespace = namespaces.slice(0).sort().join(".");
  2140. } else {
  2141. namespaces = [];
  2142. handleObj.namespace = "";
  2143. }
  2144. handleObj.type = type;
  2145. if ( !handleObj.guid ) {
  2146. handleObj.guid = handler.guid;
  2147. }
  2148. // Get the current list of functions bound to this event
  2149. var handlers = events[ type ],
  2150. special = jQuery.event.special[ type ] || {};
  2151. // Init the event handler queue
  2152. if ( !handlers ) {
  2153. handlers = events[ type ] = [];
  2154. // Check for a special event handler
  2155. // Only use addEventListener/attachEvent if the special
  2156. // events handler returns false
  2157. if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
  2158. // Bind the global event handler to the element
  2159. if ( elem.addEventListener ) {
  2160. elem.addEventListener( type, eventHandle, false );
  2161. } else if ( elem.attachEvent ) {
  2162. elem.attachEvent( "on" + type, eventHandle );
  2163. }
  2164. }
  2165. }
  2166. if ( special.add ) {
  2167. special.add.call( elem, handleObj );
  2168. if ( !handleObj.handler.guid ) {
  2169. handleObj.handler.guid = handler.guid;
  2170. }
  2171. }
  2172. // Add the function to the element's handler list
  2173. handlers.push( handleObj );
  2174. // Keep track of which events have been used, for event optimization
  2175. jQuery.event.global[ type ] = true;
  2176. }
  2177. // Nullify elem to prevent memory leaks in IE
  2178. elem = null;
  2179. },
  2180. global: {},
  2181. // Detach an event or set of events from an element
  2182. remove: function( elem, types, handler, pos ) {
  2183. // don't do events on text and comment nodes
  2184. if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
  2185. return;
  2186. }
  2187. if ( handler === false ) {
  2188. handler = returnFalse;
  2189. }
  2190. var ret, type, fn, j, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType,
  2191. elemData = jQuery.hasData( elem ) && jQuery._data( elem ),
  2192. events = elemData && elemData.events;
  2193. if ( !elemData || !events ) {
  2194. return;
  2195. }
  2196. // types is actually an event object here
  2197. if ( types && types.type ) {
  2198. handler = types.handler;
  2199. types = types.type;
  2200. }
  2201. // Unbind all events for the element
  2202. if ( !types || typeof types === "string" && types.charAt(0) === "." ) {
  2203. types = types || "";
  2204. for ( type in events ) {
  2205. jQuery.event.remove( elem, type + types );
  2206. }
  2207. return;
  2208. }
  2209. // Handle multiple events separated by a space
  2210. // jQuery(...).unbind("mouseover mouseout", fn);
  2211. types = types.split(" ");
  2212. while ( (type = types[ i++ ]) ) {
  2213. origType = type;
  2214. handleObj = null;
  2215. all = type.indexOf(".") < 0;
  2216. namespaces = [];
  2217. if ( !all ) {
  2218. // Namespaced event handlers
  2219. namespaces = type.split(".");
  2220. type = namespaces.shift();
  2221. namespace = new RegExp("(^|\\.)" +
  2222. jQuery.map( namespaces.slice(0).sort(), fcleanup ).join("\\.(?:.*\\.)?") + "(\\.|$)");
  2223. }
  2224. eventType = events[ type ];
  2225. if ( !eventType ) {
  2226. continue;
  2227. }
  2228. if ( !handler ) {
  2229. for ( j = 0; j < eventType.length; j++ ) {
  2230. handleObj = eventType[ j ];
  2231. if ( all || namespace.test( handleObj.namespace ) ) {
  2232. jQuery.event.remove( elem, origType, handleObj.handler, j );
  2233. eventType.splice( j--, 1 );
  2234. }
  2235. }
  2236. continue;
  2237. }
  2238. special = jQuery.event.special[ type ] || {};
  2239. for ( j = pos || 0; j < eventType.length; j++ ) {
  2240. handleObj = eventType[ j ];
  2241. if ( handler.guid === handleObj.guid ) {
  2242. // remove the given handler for the given type
  2243. if ( all || namespace.test( handleObj.namespace ) ) {
  2244. if ( pos == null ) {
  2245. eventType.splice( j--, 1 );
  2246. }
  2247. if ( special.remove ) {
  2248. special.remove.call( elem, handleObj );
  2249. }
  2250. }
  2251. if ( pos != null ) {
  2252. break;
  2253. }
  2254. }
  2255. }
  2256. // remove generic event handler if no more handlers exist
  2257. if ( eventType.length === 0 || pos != null && eventType.length === 1 ) {
  2258. if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
  2259. jQuery.removeEvent( elem, type, elemData.handle );
  2260. }
  2261. ret = null;
  2262. delete events[ type ];
  2263. }
  2264. }
  2265. // Remove the expando if it's no longer used
  2266. if ( jQuery.isEmptyObject( events ) ) {
  2267. var handle = elemData.handle;
  2268. if ( handle ) {
  2269. handle.elem = null;
  2270. }
  2271. delete elemData.events;
  2272. delete elemData.handle;
  2273. if ( jQuery.isEmptyObject( elemData ) ) {
  2274. jQuery.removeData( elem, undefined, true );
  2275. }
  2276. }
  2277. },
  2278. // Events that are safe to short-circuit if no handlers are attached.
  2279. // Native DOM events should not be added, they may have inline handlers.
  2280. customEvent: {
  2281. "getData": true,
  2282. "setData": true,
  2283. "changeData": true
  2284. },
  2285. trigger: function( event, data, elem, onlyHandlers ) {
  2286. // Event object or event type
  2287. var type = event.type || event,
  2288. namespaces = [],
  2289. exclusive;
  2290. if ( type.indexOf("!") >= 0 ) {
  2291. // Exclusive events trigger only for the exact event (no namespaces)
  2292. type = type.slice(0, -1);
  2293. exclusive = true;
  2294. }
  2295. if ( type.indexOf(".") >= 0 ) {
  2296. // Namespaced trigger; create a regexp to match event type in handle()
  2297. namespaces = type.split(".");
  2298. type = namespaces.shift();
  2299. namespaces.sort();
  2300. }
  2301. if ( (!elem || jQuery.event.customEvent[ type ]) && !jQuery.event.global[ type ] ) {
  2302. // No jQuery handlers for this event type, and it can't have inline handlers
  2303. return;
  2304. }
  2305. // Caller can pass in an Event, Object, or just an event type string
  2306. event = typeof event === "object" ?
  2307. // jQuery.Event object
  2308. event[ jQuery.expando ] ? event :
  2309. // Object literal
  2310. new jQuery.Event( type, event ) :
  2311. // Just the event type (string)
  2312. new jQuery.Event( type );
  2313. event.type = type;
  2314. event.exclusive = exclusive;
  2315. event.namespace = namespaces.join(".");
  2316. event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)");
  2317. // triggerHandler() and global events don't bubble or run the default action
  2318. if ( onlyHandlers || !elem ) {
  2319. event.preventDefault();
  2320. event.stopPropagation();
  2321. }
  2322. // Handle a global trigger
  2323. if ( !elem ) {
  2324. // TODO: Stop taunting the data cache; remove global events and always attach to document
  2325. jQuery.each( jQuery.cache, function() {
  2326. // internalKey variable is just used to make it easier to find
  2327. // and potentially change this stuff later; currently it just
  2328. // points to jQuery.expando
  2329. var internalKey = jQuery.expando,
  2330. internalCache = this[ internalKey ];
  2331. if ( internalCache && internalCache.events && internalCache.events[ type ] ) {
  2332. jQuery.event.trigger( event, data, internalCache.handle.elem );
  2333. }
  2334. });
  2335. return;
  2336. }
  2337. // Don't do events on text and comment nodes
  2338. if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
  2339. return;
  2340. }
  2341. // Clean up the event in case it is being reused
  2342. event.result = undefined;
  2343. event.target = elem;
  2344. // Clone any incoming data and prepend the event, creating the handler arg list
  2345. data = data ? jQuery.makeArray( data ) : [];
  2346. data.unshift( event );
  2347. var cur = elem,
  2348. // IE doesn't like method names with a colon (#3533, #8272)
  2349. ontype = type.indexOf(":") < 0 ? "on" + type : "";
  2350. // Fire event on the current element, then bubble up the DOM tree
  2351. do {
  2352. var handle = jQuery._data( cur, "handle" );
  2353. event.currentTarget = cur;
  2354. if ( handle ) {
  2355. handle.apply( cur, data );
  2356. }
  2357. // Trigger an inline bound script
  2358. if ( ontype && jQuery.acceptData( cur ) && cur[ ontype ] && cur[ ontype ].apply( cur, data ) === false ) {
  2359. event.result = false;
  2360. event.preventDefault();
  2361. }
  2362. // Bubble up to document, then to window
  2363. cur = cur.parentNode || cur.ownerDocument || cur === event.target.ownerDocument && window;
  2364. } while ( cur && !event.isPropagationStopped() );
  2365. // If nobody prevented the default action, do it now
  2366. if ( !event.isDefaultPrevented() ) {
  2367. var old,
  2368. special = jQuery.event.special[ type ] || {};
  2369. if ( (!special._default || special._default.call( elem.ownerDocument, event ) === false) &&
  2370. !(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) {
  2371. // Call a native DOM method on the target with the same name name as the event.
  2372. // Can't use an .isFunction)() check here because IE6/7 fails that test.
  2373. // IE<9 dies on focus to hidden element (#1486), may want to revisit a try/catch.
  2374. try {
  2375. if ( ontype && elem[ type ] ) {
  2376. // Don't re-trigger an onFOO event when we call its FOO() method
  2377. old = elem[ ontype ];
  2378. if ( old ) {
  2379. elem[ ontype ] = null;
  2380. }
  2381. jQuery.event.triggered = type;
  2382. elem[ type ]();
  2383. }
  2384. } catch ( ieError ) {}
  2385. if ( old ) {
  2386. elem[ ontype ] = old;
  2387. }
  2388. jQuery.event.triggered = undefined;
  2389. }
  2390. }
  2391. return event.result;
  2392. },
  2393. handle: function( event ) {
  2394. event = jQuery.event.fix( event || window.event );
  2395. // Snapshot the handlers list since a called handler may add/remove events.
  2396. var handlers = ((jQuery._data( this, "events" ) || {})[ event.type ] || []).slice(0),
  2397. run_all = !event.exclusive && !event.namespace,
  2398. args = Array.prototype.slice.call( arguments, 0 );
  2399. // Use the fix-ed Event rather than the (read-only) native event
  2400. args[0] = event;
  2401. event.currentTarget = this;
  2402. for ( var j = 0, l = handlers.length; j < l; j++ ) {
  2403. var handleObj = handlers[ j ];
  2404. // Triggered event must 1) be non-exclusive and have no namespace, or
  2405. // 2) have namespace(s) a subset or equal to those in the bound event.
  2406. if ( run_all || event.namespace_re.test( handleObj.namespace ) ) {
  2407. // Pass in a reference to the handler function itself
  2408. // So that we can later remove it
  2409. event.handler = handleObj.handler;
  2410. event.data = handleObj.data;
  2411. event.handleObj = handleObj;
  2412. var ret = handleObj.handler.apply( this, args );
  2413. if ( ret !== undefined ) {
  2414. event.result = ret;
  2415. if ( ret === false ) {
  2416. event.preventDefault();
  2417. event.stopPropagation();
  2418. }
  2419. }
  2420. if ( event.isImmediatePropagationStopped() ) {
  2421. break;
  2422. }
  2423. }
  2424. }
  2425. return event.result;
  2426. },
  2427. props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
  2428. fix: function( event ) {
  2429. if ( event[ jQuery.expando ] ) {
  2430. return event;
  2431. }
  2432. // store a copy of the original event object
  2433. // and "clone" to set read-only properties
  2434. var originalEvent = event;
  2435. event = jQuery.Event( originalEvent );
  2436. for ( var i = this.props.length, prop; i; ) {
  2437. prop = this.props[ --i ];
  2438. event[ prop ] = originalEvent[ prop ];
  2439. }
  2440. // Fix target property, if necessary
  2441. if ( !event.target ) {
  2442. // Fixes #1925 where srcElement might not be defined either
  2443. event.target = event.srcElement || document;
  2444. }
  2445. // check if target is a textnode (safari)
  2446. if ( event.target.nodeType === 3 ) {
  2447. event.target = event.target.parentNode;
  2448. }
  2449. // Add relatedTarget, if necessary
  2450. if ( !event.relatedTarget && event.fromElement ) {
  2451. event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement;
  2452. }
  2453. // Calculate pageX/Y if missing and clientX/Y available
  2454. if ( event.pageX == null && event.clientX != null ) {
  2455. var eventDocument = event.target.ownerDocument || document,
  2456. doc = eventDocument.documentElement,
  2457. body = eventDocument.body;
  2458. event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
  2459. event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
  2460. }
  2461. // Add which for key events
  2462. if ( event.which == null && (event.charCode != null || event.keyCode != null) ) {
  2463. event.which = event.charCode != null ? event.charCode : event.keyCode;
  2464. }
  2465. // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
  2466. if ( !event.metaKey && event.ctrlKey ) {
  2467. event.metaKey = event.ctrlKey;
  2468. }
  2469. // Add which for click: 1 === left; 2 === middle; 3 === right
  2470. // Note: button is not normalized, so don't use it
  2471. if ( !event.which && event.button !== undefined ) {
  2472. event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
  2473. }
  2474. return event;
  2475. },
  2476. // Deprecated, use jQuery.guid instead
  2477. guid: 1E8,
  2478. // Deprecated, use jQuery.proxy instead
  2479. proxy: jQuery.proxy,
  2480. special: {
  2481. ready: {
  2482. // Make sure the ready event is setup
  2483. setup: jQuery.bindReady,
  2484. teardown: jQuery.noop
  2485. },
  2486. live: {
  2487. add: function( handleObj ) {
  2488. jQuery.event.add( this,
  2489. liveConvert( handleObj.origType, handleObj.selector ),
  2490. jQuery.extend({}, handleObj, {handler: liveHandler, guid: handleObj.handler.guid}) );
  2491. },
  2492. remove: function( handleObj ) {
  2493. jQuery.event.remove( this, liveConvert( handleObj.origType, handleObj.selector ), handleObj );
  2494. }
  2495. },
  2496. beforeunload: {
  2497. setup: function( data, namespaces, eventHandle ) {
  2498. // We only want to do this special case on windows
  2499. if ( jQuery.isWindow( this ) ) {
  2500. this.onbeforeunload = eventHandle;
  2501. }
  2502. },
  2503. teardown: function( namespaces, eventHandle ) {
  2504. if ( this.onbeforeunload === eventHandle ) {
  2505. this.onbeforeunload = null;
  2506. }
  2507. }
  2508. }
  2509. }
  2510. };
  2511. jQuery.removeEvent = document.removeEventListener ?
  2512. function( elem, type, handle ) {
  2513. if ( elem.removeEventListener ) {
  2514. elem.removeEventListener( type, handle, false );
  2515. }
  2516. } :
  2517. function( elem, type, handle ) {
  2518. if ( elem.detachEvent ) {
  2519. elem.detachEvent( "on" + type, handle );
  2520. }
  2521. };
  2522. jQuery.Event = function( src, props ) {
  2523. // Allow instantiation without the 'new' keyword
  2524. if ( !this.preventDefault ) {
  2525. return new jQuery.Event( src, props );
  2526. }
  2527. // Event object
  2528. if ( src && src.type ) {
  2529. this.originalEvent = src;
  2530. this.type = src.type;
  2531. // Events bubbling up the document may have been marked as prevented
  2532. // by a handler lower down the tree; reflect the correct value.
  2533. this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false ||
  2534. src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse;
  2535. // Event type
  2536. } else {
  2537. this.type = src;
  2538. }
  2539. // Put explicitly provided properties onto the event object
  2540. if ( props ) {
  2541. jQuery.extend( this, props );
  2542. }
  2543. // timeStamp is buggy for some events on Firefox(#3843)
  2544. // So we won't rely on the native value
  2545. this.timeStamp = jQuery.now();
  2546. // Mark it as fixed
  2547. this[ jQuery.expando ] = true;
  2548. };
  2549. function returnFalse() {
  2550. return false;
  2551. }
  2552. function returnTrue() {
  2553. return true;
  2554. }
  2555. // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
  2556. // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
  2557. jQuery.Event.prototype = {
  2558. preventDefault: function() {
  2559. this.isDefaultPrevented = returnTrue;
  2560. var e = this.originalEvent;
  2561. if ( !e ) {
  2562. return;
  2563. }
  2564. // if preventDefault exists run it on the original event
  2565. if ( e.preventDefault ) {
  2566. e.preventDefault();
  2567. // otherwise set the returnValue property of the original event to false (IE)
  2568. } else {
  2569. e.returnValue = false;
  2570. }
  2571. },
  2572. stopPropagation: function() {
  2573. this.isPropagationStopped = returnTrue;
  2574. var e = this.originalEvent;
  2575. if ( !e ) {
  2576. return;
  2577. }
  2578. // if stopPropagation exists run it on the original event
  2579. if ( e.stopPropagation ) {
  2580. e.stopPropagation();
  2581. }
  2582. // otherwise set the cancelBubble property of the original event to true (IE)
  2583. e.cancelBubble = true;
  2584. },
  2585. stopImmediatePropagation: function() {
  2586. this.isImmediatePropagationStopped = returnTrue;
  2587. this.stopPropagation();
  2588. },
  2589. isDefaultPrevented: returnFalse,
  2590. isPropagationStopped: returnFalse,
  2591. isImmediatePropagationStopped: returnFalse
  2592. };
  2593. // Checks if an event happened on an element within another element
  2594. // Used in jQuery.event.special.mouseenter and mouseleave handlers
  2595. var withinElement = function( event ) {
  2596. // Check if mouse(over|out) are still within the same parent element
  2597. var parent = event.relatedTarget;
  2598. // set the correct event type
  2599. event.type = event.data;
  2600. // Firefox sometimes assigns relatedTarget a XUL element
  2601. // which we cannot access the parentNode property of
  2602. try {
  2603. // Chrome does something similar, the parentNode property
  2604. // can be accessed but is null.
  2605. if ( parent && parent !== document && !parent.parentNode ) {
  2606. return;
  2607. }
  2608. // Traverse up the tree
  2609. while ( parent && parent !== this ) {
  2610. parent = parent.parentNode;
  2611. }
  2612. if ( parent !== this ) {
  2613. // handle event if we actually just moused on to a non sub-element
  2614. jQuery.event.handle.apply( this, arguments );
  2615. }
  2616. // assuming we've left the element since we most likely mousedover a xul element
  2617. } catch(e) { }
  2618. },
  2619. // In case of event delegation, we only need to rename the event.type,
  2620. // liveHandler will take care of the rest.
  2621. delegate = function( event ) {
  2622. event.type = event.data;
  2623. jQuery.event.handle.apply( this, arguments );
  2624. };
  2625. // Create mouseenter and mouseleave events
  2626. jQuery.each({
  2627. mouseenter: "mouseover",
  2628. mouseleave: "mouseout"
  2629. }, function( orig, fix ) {
  2630. jQuery.event.special[ orig ] = {
  2631. setup: function( data ) {
  2632. jQuery.event.add( this, fix, data && data.selector ? delegate : withinElement, orig );
  2633. },
  2634. teardown: function( data ) {
  2635. jQuery.event.remove( this, fix, data && data.selector ? delegate : withinElement );
  2636. }
  2637. };
  2638. });
  2639. // submit delegation
  2640. if ( !jQuery.support.submitBubbles ) {
  2641. jQuery.event.special.submit = {
  2642. setup: function( data, namespaces ) {
  2643. if ( !jQuery.nodeName( this, "form" ) ) {
  2644. jQuery.event.add(this, "click.specialSubmit", function( e ) {
  2645. var elem = e.target,
  2646. type = elem.type;
  2647. if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) {
  2648. trigger( "submit", this, arguments );
  2649. }
  2650. });
  2651. jQuery.event.add(this, "keypress.specialSubmit", function( e ) {
  2652. var elem = e.target,
  2653. type = elem.type;
  2654. if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) {
  2655. trigger( "submit", this, arguments );
  2656. }
  2657. });
  2658. } else {
  2659. return false;
  2660. }
  2661. },
  2662. teardown: function( namespaces ) {
  2663. jQuery.event.remove( this, ".specialSubmit" );
  2664. }
  2665. };
  2666. }
  2667. // change delegation, happens here so we have bind.
  2668. if ( !jQuery.support.changeBubbles ) {
  2669. var changeFilters,
  2670. getVal = function( elem ) {
  2671. var type = elem.type, val = elem.value;
  2672. if ( type === "radio" || type === "checkbox" ) {
  2673. val = elem.checked;
  2674. } else if ( type === "select-multiple" ) {
  2675. val = elem.selectedIndex > -1 ?
  2676. jQuery.map( elem.options, function( elem ) {
  2677. return elem.selected;
  2678. }).join("-") :
  2679. "";
  2680. } else if ( jQuery.nodeName( elem, "select" ) ) {
  2681. val = elem.selectedIndex;
  2682. }
  2683. return val;
  2684. },
  2685. testChange = function testChange( e ) {
  2686. var elem = e.target, data, val;
  2687. if ( !rformElems.test( elem.nodeName ) || elem.readOnly ) {
  2688. return;
  2689. }
  2690. data = jQuery._data( elem, "_change_data" );
  2691. val = getVal(elem);
  2692. // the current data will be also retrieved by beforeactivate
  2693. if ( e.type !== "focusout" || elem.type !== "radio" ) {
  2694. jQuery._data( elem, "_change_data", val );
  2695. }
  2696. if ( data === undefined || val === data ) {
  2697. return;
  2698. }
  2699. if ( data != null || val ) {
  2700. e.type = "change";
  2701. e.liveFired = undefined;
  2702. jQuery.event.trigger( e, arguments[1], elem );
  2703. }
  2704. };
  2705. jQuery.event.special.change = {
  2706. filters: {
  2707. focusout: testChange,
  2708. beforedeactivate: testChange,
  2709. click: function( e ) {
  2710. var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : "";
  2711. if ( type === "radio" || type === "checkbox" || jQuery.nodeName( elem, "select" ) ) {
  2712. testChange.call( this, e );
  2713. }
  2714. },
  2715. // Change has to be called before submit
  2716. // Keydown will be called before keypress, which is used in submit-event delegation
  2717. keydown: function( e ) {
  2718. var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : "";
  2719. if ( (e.keyCode === 13 && !jQuery.nodeName( elem, "textarea" ) ) ||
  2720. (e.keyCode === 32 && (type === "checkbox" || type === "radio")) ||
  2721. type === "select-multiple" ) {
  2722. testChange.call( this, e );
  2723. }
  2724. },
  2725. // Beforeactivate happens also before the previous element is blurred
  2726. // with this event you can't trigger a change event, but you can store
  2727. // information
  2728. beforeactivate: function( e ) {
  2729. var elem = e.target;
  2730. jQuery._data( elem, "_change_data", getVal(elem) );
  2731. }
  2732. },
  2733. setup: function( data, namespaces ) {
  2734. if ( this.type === "file" ) {
  2735. return false;
  2736. }
  2737. for ( var type in changeFilters ) {
  2738. jQuery.event.add( this, type + ".specialChange", changeFilters[type] );
  2739. }
  2740. return rformElems.test( this.nodeName );
  2741. },
  2742. teardown: function( namespaces ) {
  2743. jQuery.event.remove( this, ".specialChange" );
  2744. return rformElems.test( this.nodeName );
  2745. }
  2746. };
  2747. changeFilters = jQuery.event.special.change.filters;
  2748. // Handle when the input is .focus()'d
  2749. changeFilters.focus = changeFilters.beforeactivate;
  2750. }
  2751. function trigger( type, elem, args ) {
  2752. // Piggyback on a donor event to simulate a different one.
  2753. // Fake originalEvent to avoid donor's stopPropagation, but if the
  2754. // simulated event prevents default then we do the same on the donor.
  2755. // Don't pass args or remember liveFired; they apply to the donor event.
  2756. var event = jQuery.extend( {}, args[ 0 ] );
  2757. event.type = type;
  2758. event.originalEvent = {};
  2759. event.liveFired = undefined;
  2760. jQuery.event.handle.call( elem, event );
  2761. if ( event.isDefaultPrevented() ) {
  2762. args[ 0 ].preventDefault();
  2763. }
  2764. }
  2765. // Create "bubbling" focus and blur events
  2766. if ( !jQuery.support.focusinBubbles ) {
  2767. jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
  2768. // Attach a single capturing handler while someone wants focusin/focusout
  2769. var attaches = 0;
  2770. jQuery.event.special[ fix ] = {
  2771. setup: function() {
  2772. if ( attaches++ === 0 ) {
  2773. document.addEventListener( orig, handler, true );
  2774. }
  2775. },
  2776. teardown: function() {
  2777. if ( --attaches === 0 ) {
  2778. document.removeEventListener( orig, handler, true );
  2779. }
  2780. }
  2781. };
  2782. function handler( donor ) {
  2783. // Donor event is always a native one; fix it and switch its type.
  2784. // Let focusin/out handler cancel the donor focus/blur event.
  2785. var e = jQuery.event.fix( donor );
  2786. e.type = fix;
  2787. e.originalEvent = {};
  2788. jQuery.event.trigger( e, null, e.target );
  2789. if ( e.isDefaultPrevented() ) {
  2790. donor.preventDefault();
  2791. }
  2792. }
  2793. });
  2794. }
  2795. jQuery.each(["bind", "one"], function( i, name ) {
  2796. jQuery.fn[ name ] = function( type, data, fn ) {
  2797. var handler;
  2798. // Handle object literals
  2799. if ( typeof type === "object" ) {
  2800. for ( var key in type ) {
  2801. this[ name ](key, data, type[key], fn);
  2802. }
  2803. return this;
  2804. }
  2805. if ( arguments.length === 2 || data === false ) {
  2806. fn = data;
  2807. data = undefined;
  2808. }
  2809. if ( name === "one" ) {
  2810. handler = function( event ) {
  2811. jQuery( this ).unbind( event, handler );
  2812. return fn.apply( this, arguments );
  2813. };
  2814. handler.guid = fn.guid || jQuery.guid++;
  2815. } else {
  2816. handler = fn;
  2817. }
  2818. if ( type === "unload" && name !== "one" ) {
  2819. this.one( type, data, fn );
  2820. } else {
  2821. for ( var i = 0, l = this.length; i < l; i++ ) {
  2822. jQuery.event.add( this[i], type, handler, data );
  2823. }
  2824. }
  2825. return this;
  2826. };
  2827. });
  2828. jQuery.fn.extend({
  2829. unbind: function( type, fn ) {
  2830. // Handle object literals
  2831. if ( typeof type === "object" && !type.preventDefault ) {
  2832. for ( var key in type ) {
  2833. this.unbind(key, type[key]);
  2834. }
  2835. } else {
  2836. for ( var i = 0, l = this.length; i < l; i++ ) {
  2837. jQuery.event.remove( this[i], type, fn );
  2838. }
  2839. }
  2840. return this;
  2841. },
  2842. delegate: function( selector, types, data, fn ) {
  2843. return this.live( types, data, fn, selector );
  2844. },
  2845. undelegate: function( selector, types, fn ) {
  2846. if ( arguments.length === 0 ) {
  2847. return this.unbind( "live" );
  2848. } else {
  2849. return this.die( types, null, fn, selector );
  2850. }
  2851. },
  2852. trigger: function( type, data ) {
  2853. return this.each(function() {
  2854. jQuery.event.trigger( type, data, this );
  2855. });
  2856. },
  2857. triggerHandler: function( type, data ) {
  2858. if ( this[0] ) {
  2859. return jQuery.event.trigger( type, data, this[0], true );
  2860. }
  2861. },
  2862. toggle: function( fn ) {
  2863. // Save reference to arguments for access in closure
  2864. var args = arguments,
  2865. guid = fn.guid || jQuery.guid++,
  2866. i = 0,
  2867. toggler = function( event ) {
  2868. // Figure out which function to execute
  2869. var lastToggle = ( jQuery.data( this, "lastToggle" + fn.guid ) || 0 ) % i;
  2870. jQuery.data( this, "lastToggle" + fn.guid, lastToggle + 1 );
  2871. // Make sure that clicks stop
  2872. event.preventDefault();
  2873. // and execute the function
  2874. return args[ lastToggle ].apply( this, arguments ) || false;
  2875. };
  2876. // link all the functions, so any of them can unbind this click handler
  2877. toggler.guid = guid;
  2878. while ( i < args.length ) {
  2879. args[ i++ ].guid = guid;
  2880. }
  2881. return this.click( toggler );
  2882. },
  2883. hover: function( fnOver, fnOut ) {
  2884. return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
  2885. }
  2886. });
  2887. var liveMap = {
  2888. focus: "focusin",
  2889. blur: "focusout",
  2890. mouseenter: "mouseover",
  2891. mouseleave: "mouseout"
  2892. };
  2893. jQuery.each(["live", "die"], function( i, name ) {
  2894. jQuery.fn[ name ] = function( types, data, fn, origSelector /* Internal Use Only */ ) {
  2895. var type, i = 0, match, namespaces, preType,
  2896. selector = origSelector || this.selector,
  2897. context = origSelector ? this : jQuery( this.context );
  2898. if ( typeof types === "object" && !types.preventDefault ) {
  2899. for ( var key in types ) {
  2900. context[ name ]( key, data, types[key], selector );
  2901. }
  2902. return this;
  2903. }
  2904. if ( name === "die" && !types &&
  2905. origSelector && origSelector.charAt(0) === "." ) {
  2906. context.unbind( origSelector );
  2907. return this;
  2908. }
  2909. if ( data === false || jQuery.isFunction( data ) ) {
  2910. fn = data || returnFalse;
  2911. data = undefined;
  2912. }
  2913. types = (types || "").split(" ");
  2914. while ( (type = types[ i++ ]) != null ) {
  2915. match = rnamespaces.exec( type );
  2916. namespaces = "";
  2917. if ( match ) {
  2918. namespaces = match[0];
  2919. type = type.replace( rnamespaces, "" );
  2920. }
  2921. if ( type === "hover" ) {
  2922. types.push( "mouseenter" + namespaces, "mouseleave" + namespaces );
  2923. continue;
  2924. }
  2925. preType = type;
  2926. if ( liveMap[ type ] ) {
  2927. types.push( liveMap[ type ] + namespaces );
  2928. type = type + namespaces;
  2929. } else {
  2930. type = (liveMap[ type ] || type) + namespaces;
  2931. }
  2932. if ( name === "live" ) {
  2933. // bind live handler
  2934. for ( var j = 0, l = context.length; j < l; j++ ) {
  2935. jQuery.event.add( context[j], "live." + liveConvert( type, selector ),
  2936. { data: data, selector: selector, handler: fn, origType: type, origHandler: fn, preType: preType } );
  2937. }
  2938. } else {
  2939. // unbind live handler
  2940. context.unbind( "live." + liveConvert( type, selector ), fn );
  2941. }
  2942. }
  2943. return this;
  2944. };
  2945. });
  2946. function liveHandler( event ) {
  2947. var stop, maxLevel, related, match, handleObj, elem, j, i, l, data, close, namespace, ret,
  2948. elems = [],
  2949. selectors = [],
  2950. events = jQuery._data( this, "events" );
  2951. // Make sure we avoid non-left-click bubbling in Firefox (#3861) and disabled elements in IE (#6911)
  2952. if ( event.liveFired === this || !events || !events.live || event.target.disabled || event.button && event.type === "click" ) {
  2953. return;
  2954. }
  2955. if ( event.namespace ) {
  2956. namespace = new RegExp("(^|\\.)" + event.namespace.split(".").join("\\.(?:.*\\.)?") + "(\\.|$)");
  2957. }
  2958. event.liveFired = this;
  2959. var live = events.live.slice(0);
  2960. for ( j = 0; j < live.length; j++ ) {
  2961. handleObj = live[j];
  2962. if ( handleObj.origType.replace( rnamespaces, "" ) === event.type ) {
  2963. selectors.push( handleObj.selector );
  2964. } else {
  2965. live.splice( j--, 1 );
  2966. }
  2967. }
  2968. match = jQuery( event.target ).closest( selectors, event.currentTarget );
  2969. for ( i = 0, l = match.length; i < l; i++ ) {
  2970. close = match[i];
  2971. for ( j = 0; j < live.length; j++ ) {
  2972. handleObj = live[j];
  2973. if ( close.selector === handleObj.selector && (!namespace || namespace.test( handleObj.namespace )) && !close.elem.disabled ) {
  2974. elem = close.elem;
  2975. related = null;
  2976. // Those two events require additional checking
  2977. if ( handleObj.preType === "mouseenter" || handleObj.preType === "mouseleave" ) {
  2978. event.type = handleObj.preType;
  2979. related = jQuery( event.relatedTarget ).closest( handleObj.selector )[0];
  2980. // Make sure not to accidentally match a child element with the same selector
  2981. if ( related && jQuery.contains( elem, related ) ) {
  2982. related = elem;
  2983. }
  2984. }
  2985. if ( !related || related !== elem ) {
  2986. elems.push({ elem: elem, handleObj: handleObj, level: close.level });
  2987. }
  2988. }
  2989. }
  2990. }
  2991. for ( i = 0, l = elems.length; i < l; i++ ) {
  2992. match = elems[i];
  2993. if ( maxLevel && match.level > maxLevel ) {
  2994. break;
  2995. }
  2996. event.currentTarget = match.elem;
  2997. event.data = match.handleObj.data;
  2998. event.handleObj = match.handleObj;
  2999. ret = match.handleObj.origHandler.apply( match.elem, arguments );
  3000. if ( ret === false || event.isPropagationStopped() ) {
  3001. maxLevel = match.level;
  3002. if ( ret === false ) {
  3003. stop = false;
  3004. }
  3005. if ( event.isImmediatePropagationStopped() ) {
  3006. break;
  3007. }
  3008. }
  3009. }
  3010. return stop;
  3011. }
  3012. function liveConvert( type, selector ) {
  3013. return (type && type !== "*" ? type + "." : "") + selector.replace(rperiod, "`").replace(rspaces, "&");
  3014. }
  3015. jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
  3016. "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
  3017. "change select submit keydown keypress keyup error").split(" "), function( i, name ) {
  3018. // Handle event binding
  3019. jQuery.fn[ name ] = function( data, fn ) {
  3020. if ( fn == null ) {
  3021. fn = data;
  3022. data = null;
  3023. }
  3024. return arguments.length > 0 ?
  3025. this.bind( name, data, fn ) :
  3026. this.trigger( name );
  3027. };
  3028. if ( jQuery.attrFn ) {
  3029. jQuery.attrFn[ name ] = true;
  3030. }
  3031. });
  3032. /*!
  3033. * Sizzle CSS Selector Engine
  3034. * Copyright 2011, The Dojo Foundation
  3035. * Released under the MIT, BSD, and GPL Licenses.
  3036. * More information: http://sizzlejs.com/
  3037. */
  3038. (function(){
  3039. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
  3040. done = 0,
  3041. toString = Object.prototype.toString,
  3042. hasDuplicate = false,
  3043. baseHasDuplicate = true,
  3044. rBackslash = /\\/g,
  3045. rNonWord = /\W/;
  3046. // Here we check if the JavaScript engine is using some sort of
  3047. // optimization where it does not always call our comparision
  3048. // function. If that is the case, discard the hasDuplicate value.
  3049. // Thus far that includes Google Chrome.
  3050. [0, 0].sort(function() {
  3051. baseHasDuplicate = false;
  3052. return 0;
  3053. });
  3054. var Sizzle = function( selector, context, results, seed ) {
  3055. results = results || [];
  3056. context = context || document;
  3057. var origContext = context;
  3058. if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
  3059. return [];
  3060. }
  3061. if ( !selector || typeof selector !== "string" ) {
  3062. return results;
  3063. }
  3064. var m, set, checkSet, extra, ret, cur, pop, i,
  3065. prune = true,
  3066. contextXML = Sizzle.isXML( context ),
  3067. parts = [],
  3068. soFar = selector;
  3069. // Reset the position of the chunker regexp (start from head)
  3070. do {
  3071. chunker.exec( "" );
  3072. m = chunker.exec( soFar );
  3073. if ( m ) {
  3074. soFar = m[3];
  3075. parts.push( m[1] );
  3076. if ( m[2] ) {
  3077. extra = m[3];
  3078. break;
  3079. }
  3080. }
  3081. } while ( m );
  3082. if ( parts.length > 1 && origPOS.exec( selector ) ) {
  3083. if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  3084. set = posProcess( parts[0] + parts[1], context );
  3085. } else {
  3086. set = Expr.relative[ parts[0] ] ?
  3087. [ context ] :
  3088. Sizzle( parts.shift(), context );
  3089. while ( parts.length ) {
  3090. selector = parts.shift();
  3091. if ( Expr.relative[ selector ] ) {
  3092. selector += parts.shift();
  3093. }
  3094. set = posProcess( selector, set );
  3095. }
  3096. }
  3097. } else {
  3098. // Take a shortcut and set the context if the root selector is an ID
  3099. // (but not if it'll be faster if the inner selector is an ID)
  3100. if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
  3101. Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
  3102. ret = Sizzle.find( parts.shift(), context, contextXML );
  3103. context = ret.expr ?
  3104. Sizzle.filter( ret.expr, ret.set )[0] :
  3105. ret.set[0];
  3106. }
  3107. if ( context ) {
  3108. ret = seed ?
  3109. { expr: parts.pop(), set: makeArray(seed) } :
  3110. Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
  3111. set = ret.expr ?
  3112. Sizzle.filter( ret.expr, ret.set ) :
  3113. ret.set;
  3114. if ( parts.length > 0 ) {
  3115. checkSet = makeArray( set );
  3116. } else {
  3117. prune = false;
  3118. }
  3119. while ( parts.length ) {
  3120. cur = parts.pop();
  3121. pop = cur;
  3122. if ( !Expr.relative[ cur ] ) {
  3123. cur = "";
  3124. } else {
  3125. pop = parts.pop();
  3126. }
  3127. if ( pop == null ) {
  3128. pop = context;
  3129. }
  3130. Expr.relative[ cur ]( checkSet, pop, contextXML );
  3131. }
  3132. } else {
  3133. checkSet = parts = [];
  3134. }
  3135. }
  3136. if ( !checkSet ) {
  3137. checkSet = set;
  3138. }
  3139. if ( !checkSet ) {
  3140. Sizzle.error( cur || selector );
  3141. }
  3142. if ( toString.call(checkSet) === "[object Array]" ) {
  3143. if ( !prune ) {
  3144. results.push.apply( results, checkSet );
  3145. } else if ( context && context.nodeType === 1 ) {
  3146. for ( i = 0; checkSet[i] != null; i++ ) {
  3147. if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
  3148. results.push( set[i] );
  3149. }
  3150. }
  3151. } else {
  3152. for ( i = 0; checkSet[i] != null; i++ ) {
  3153. if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  3154. results.push( set[i] );
  3155. }
  3156. }
  3157. }
  3158. } else {
  3159. makeArray( checkSet, results );
  3160. }
  3161. if ( extra ) {
  3162. Sizzle( extra, origContext, results, seed );
  3163. Sizzle.uniqueSort( results );
  3164. }
  3165. return results;
  3166. };
  3167. Sizzle.uniqueSort = function( results ) {
  3168. if ( sortOrder ) {
  3169. hasDuplicate = baseHasDuplicate;
  3170. results.sort( sortOrder );
  3171. if ( hasDuplicate ) {
  3172. for ( var i = 1; i < results.length; i++ ) {
  3173. if ( results[i] === results[ i - 1 ] ) {
  3174. results.splice( i--, 1 );
  3175. }
  3176. }
  3177. }
  3178. }
  3179. return results;
  3180. };
  3181. Sizzle.matches = function( expr, set ) {
  3182. return Sizzle( expr, null, null, set );
  3183. };
  3184. Sizzle.matchesSelector = function( node, expr ) {
  3185. return Sizzle( expr, null, null, [node] ).length > 0;
  3186. };
  3187. Sizzle.find = function( expr, context, isXML ) {
  3188. var set;
  3189. if ( !expr ) {
  3190. return [];
  3191. }
  3192. for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
  3193. var match,
  3194. type = Expr.order[i];
  3195. if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
  3196. var left = match[1];
  3197. match.splice( 1, 1 );
  3198. if ( left.substr( left.length - 1 ) !== "\\" ) {
  3199. match[1] = (match[1] || "").replace( rBackslash, "" );
  3200. set = Expr.find[ type ]( match, context, isXML );
  3201. if ( set != null ) {
  3202. expr = expr.replace( Expr.match[ type ], "" );
  3203. break;
  3204. }
  3205. }
  3206. }
  3207. }
  3208. if ( !set ) {
  3209. set = typeof context.getElementsByTagName !== "undefined" ?
  3210. context.getElementsByTagName( "*" ) :
  3211. [];
  3212. }
  3213. return { set: set, expr: expr };
  3214. };
  3215. Sizzle.filter = function( expr, set, inplace, not ) {
  3216. var match, anyFound,
  3217. old = expr,
  3218. result = [],
  3219. curLoop = set,
  3220. isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );
  3221. while ( expr && set.length ) {
  3222. for ( var type in Expr.filter ) {
  3223. if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
  3224. var found, item,
  3225. filter = Expr.filter[ type ],
  3226. left = match[1];
  3227. anyFound = false;
  3228. match.splice(1,1);
  3229. if ( left.substr( left.length - 1 ) === "\\" ) {
  3230. continue;
  3231. }
  3232. if ( curLoop === result ) {
  3233. result = [];
  3234. }
  3235. if ( Expr.preFilter[ type ] ) {
  3236. match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
  3237. if ( !match ) {
  3238. anyFound = found = true;
  3239. } else if ( match === true ) {
  3240. continue;
  3241. }
  3242. }
  3243. if ( match ) {
  3244. for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
  3245. if ( item ) {
  3246. found = filter( item, match, i, curLoop );
  3247. var pass = not ^ !!found;
  3248. if ( inplace && found != null ) {
  3249. if ( pass ) {
  3250. anyFound = true;
  3251. } else {
  3252. curLoop[i] = false;
  3253. }
  3254. } else if ( pass ) {
  3255. result.push( item );
  3256. anyFound = true;
  3257. }
  3258. }
  3259. }
  3260. }
  3261. if ( found !== undefined ) {
  3262. if ( !inplace ) {
  3263. curLoop = result;
  3264. }
  3265. expr = expr.replace( Expr.match[ type ], "" );
  3266. if ( !anyFound ) {
  3267. return [];
  3268. }
  3269. break;
  3270. }
  3271. }
  3272. }
  3273. // Improper expression
  3274. if ( expr === old ) {
  3275. if ( anyFound == null ) {
  3276. Sizzle.error( expr );
  3277. } else {
  3278. break;
  3279. }
  3280. }
  3281. old = expr;
  3282. }
  3283. return curLoop;
  3284. };
  3285. Sizzle.error = function( msg ) {
  3286. throw "Syntax error, unrecognized expression: " + msg;
  3287. };
  3288. var Expr = Sizzle.selectors = {
  3289. order: [ "ID", "NAME", "TAG" ],
  3290. match: {
  3291. ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  3292. CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  3293. NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
  3294. ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,
  3295. TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
  3296. CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,
  3297. POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
  3298. PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
  3299. },
  3300. leftMatch: {},
  3301. attrMap: {
  3302. "class": "className",
  3303. "for": "htmlFor"
  3304. },
  3305. attrHandle: {
  3306. href: function( elem ) {
  3307. return elem.getAttribute( "href" );
  3308. },
  3309. type: function( elem ) {
  3310. return elem.getAttribute( "type" );
  3311. }
  3312. },
  3313. relative: {
  3314. "+": function(checkSet, part){
  3315. var isPartStr = typeof part === "string",
  3316. isTag = isPartStr && !rNonWord.test( part ),
  3317. isPartStrNotTag = isPartStr && !isTag;
  3318. if ( isTag ) {
  3319. part = part.toLowerCase();
  3320. }
  3321. for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
  3322. if ( (elem = checkSet[i]) ) {
  3323. while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
  3324. checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
  3325. elem || false :
  3326. elem === part;
  3327. }
  3328. }
  3329. if ( isPartStrNotTag ) {
  3330. Sizzle.filter( part, checkSet, true );
  3331. }
  3332. },
  3333. ">": function( checkSet, part ) {
  3334. var elem,
  3335. isPartStr = typeof part === "string",
  3336. i = 0,
  3337. l = checkSet.length;
  3338. if ( isPartStr && !rNonWord.test( part ) ) {
  3339. part = part.toLowerCase();
  3340. for ( ; i < l; i++ ) {
  3341. elem = checkSet[i];
  3342. if ( elem ) {
  3343. var parent = elem.parentNode;
  3344. checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
  3345. }
  3346. }
  3347. } else {
  3348. for ( ; i < l; i++ ) {
  3349. elem = checkSet[i];
  3350. if ( elem ) {
  3351. checkSet[i] = isPartStr ?
  3352. elem.parentNode :
  3353. elem.parentNode === part;
  3354. }
  3355. }
  3356. if ( isPartStr ) {
  3357. Sizzle.filter( part, checkSet, true );
  3358. }
  3359. }
  3360. },
  3361. "": function(checkSet, part, isXML){
  3362. var nodeCheck,
  3363. doneName = done++,
  3364. checkFn = dirCheck;
  3365. if ( typeof part === "string" && !rNonWord.test( part ) ) {
  3366. part = part.toLowerCase();
  3367. nodeCheck = part;
  3368. checkFn = dirNodeCheck;
  3369. }
  3370. checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML );
  3371. },
  3372. "~": function( checkSet, part, isXML ) {
  3373. var nodeCheck,
  3374. doneName = done++,
  3375. checkFn = dirCheck;
  3376. if ( typeof part === "string" && !rNonWord.test( part ) ) {
  3377. part = part.toLowerCase();
  3378. nodeCheck = part;
  3379. checkFn = dirNodeCheck;
  3380. }
  3381. checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML );
  3382. }
  3383. },
  3384. find: {
  3385. ID: function( match, context, isXML ) {
  3386. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  3387. var m = context.getElementById(match[1]);
  3388. // Check parentNode to catch when Blackberry 4.6 returns
  3389. // nodes that are no longer in the document #6963
  3390. return m && m.parentNode ? [m] : [];
  3391. }
  3392. },
  3393. NAME: function( match, context ) {
  3394. if ( typeof context.getElementsByName !== "undefined" ) {
  3395. var ret = [],
  3396. results = context.getElementsByName( match[1] );
  3397. for ( var i = 0, l = results.length; i < l; i++ ) {
  3398. if ( results[i].getAttribute("name") === match[1] ) {
  3399. ret.push( results[i] );
  3400. }
  3401. }
  3402. return ret.length === 0 ? null : ret;
  3403. }
  3404. },
  3405. TAG: function( match, context ) {
  3406. if ( typeof context.getElementsByTagName !== "undefined" ) {
  3407. return context.getElementsByTagName( match[1] );
  3408. }
  3409. }
  3410. },
  3411. preFilter: {
  3412. CLASS: function( match, curLoop, inplace, result, not, isXML ) {
  3413. match = " " + match[1].replace( rBackslash, "" ) + " ";
  3414. if ( isXML ) {
  3415. return match;
  3416. }
  3417. for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
  3418. if ( elem ) {
  3419. if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) {
  3420. if ( !inplace ) {
  3421. result.push( elem );
  3422. }
  3423. } else if ( inplace ) {
  3424. curLoop[i] = false;
  3425. }
  3426. }
  3427. }
  3428. return false;
  3429. },
  3430. ID: function( match ) {
  3431. return match[1].replace( rBackslash, "" );
  3432. },
  3433. TAG: function( match, curLoop ) {
  3434. return match[1].replace( rBackslash, "" ).toLowerCase();
  3435. },
  3436. CHILD: function( match ) {
  3437. if ( match[1] === "nth" ) {
  3438. if ( !match[2] ) {
  3439. Sizzle.error( match[0] );
  3440. }
  3441. match[2] = match[2].replace(/^\+|\s*/g, '');
  3442. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  3443. var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec(
  3444. match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
  3445. !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  3446. // calculate the numbers (first)n+(last) including if they are negative
  3447. match[2] = (test[1] + (test[2] || 1)) - 0;
  3448. match[3] = test[3] - 0;
  3449. }
  3450. else if ( match[2] ) {
  3451. Sizzle.error( match[0] );
  3452. }
  3453. // TODO: Move to normal caching system
  3454. match[0] = done++;
  3455. return match;
  3456. },
  3457. ATTR: function( match, curLoop, inplace, result, not, isXML ) {
  3458. var name = match[1] = match[1].replace( rBackslash, "" );
  3459. if ( !isXML && Expr.attrMap[name] ) {
  3460. match[1] = Expr.attrMap[name];
  3461. }
  3462. // Handle if an un-quoted value was used
  3463. match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" );
  3464. if ( match[2] === "~=" ) {
  3465. match[4] = " " + match[4] + " ";
  3466. }
  3467. return match;
  3468. },
  3469. PSEUDO: function( match, curLoop, inplace, result, not ) {
  3470. if ( match[1] === "not" ) {
  3471. // If we're dealing with a complex expression, or a simple one
  3472. if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
  3473. match[3] = Sizzle(match[3], null, null, curLoop);
  3474. } else {
  3475. var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  3476. if ( !inplace ) {
  3477. result.push.apply( result, ret );
  3478. }
  3479. return false;
  3480. }
  3481. } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
  3482. return true;
  3483. }
  3484. return match;
  3485. },
  3486. POS: function( match ) {
  3487. match.unshift( true );
  3488. return match;
  3489. }
  3490. },
  3491. filters: {
  3492. enabled: function( elem ) {
  3493. return elem.disabled === false && elem.type !== "hidden";
  3494. },
  3495. disabled: function( elem ) {
  3496. return elem.disabled === true;
  3497. },
  3498. checked: function( elem ) {
  3499. return elem.checked === true;
  3500. },
  3501. selected: function( elem ) {
  3502. // Accessing this property makes selected-by-default
  3503. // options in Safari work properly
  3504. if ( elem.parentNode ) {
  3505. elem.parentNode.selectedIndex;
  3506. }
  3507. return elem.selected === true;
  3508. },
  3509. parent: function( elem ) {
  3510. return !!elem.firstChild;
  3511. },
  3512. empty: function( elem ) {
  3513. return !elem.firstChild;
  3514. },
  3515. has: function( elem, i, match ) {
  3516. return !!Sizzle( match[3], elem ).length;
  3517. },
  3518. header: function( elem ) {
  3519. return (/h\d/i).test( elem.nodeName );
  3520. },
  3521. text: function( elem ) {
  3522. var attr = elem.getAttribute( "type" ), type = elem.type;
  3523. // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
  3524. // use getAttribute instead to test this case
  3525. return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );
  3526. },
  3527. radio: function( elem ) {
  3528. return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type;
  3529. },
  3530. checkbox: function( elem ) {
  3531. return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type;
  3532. },
  3533. file: function( elem ) {
  3534. return elem.nodeName.toLowerCase() === "input" && "file" === elem.type;
  3535. },
  3536. password: function( elem ) {
  3537. return elem.nodeName.toLowerCase() === "input" && "password" === elem.type;
  3538. },
  3539. submit: function( elem ) {
  3540. var name = elem.nodeName.toLowerCase();
  3541. return (name === "input" || name === "button") && "submit" === elem.type;
  3542. },
  3543. image: function( elem ) {
  3544. return elem.nodeName.toLowerCase() === "input" && "image" === elem.type;
  3545. },
  3546. reset: function( elem ) {
  3547. var name = elem.nodeName.toLowerCase();
  3548. return (name === "input" || name === "button") && "reset" === elem.type;
  3549. },
  3550. button: function( elem ) {
  3551. var name = elem.nodeName.toLowerCase();
  3552. return name === "input" && "button" === elem.type || name === "button";
  3553. },
  3554. input: function( elem ) {
  3555. return (/input|select|textarea|button/i).test( elem.nodeName );
  3556. },
  3557. focus: function( elem ) {
  3558. return elem === elem.ownerDocument.activeElement;
  3559. }
  3560. },
  3561. setFilters: {
  3562. first: function( elem, i ) {
  3563. return i === 0;
  3564. },
  3565. last: function( elem, i, match, array ) {
  3566. return i === array.length - 1;
  3567. },
  3568. even: function( elem, i ) {
  3569. return i % 2 === 0;
  3570. },
  3571. odd: function( elem, i ) {
  3572. return i % 2 === 1;
  3573. },
  3574. lt: function( elem, i, match ) {
  3575. return i < match[3] - 0;
  3576. },
  3577. gt: function( elem, i, match ) {
  3578. return i > match[3] - 0;
  3579. },
  3580. nth: function( elem, i, match ) {
  3581. return match[3] - 0 === i;
  3582. },
  3583. eq: function( elem, i, match ) {
  3584. return match[3] - 0 === i;
  3585. }
  3586. },
  3587. filter: {
  3588. PSEUDO: function( elem, match, i, array ) {
  3589. var name = match[1],
  3590. filter = Expr.filters[ name ];
  3591. if ( filter ) {
  3592. return filter( elem, i, match, array );
  3593. } else if ( name === "contains" ) {
  3594. return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0;
  3595. } else if ( name === "not" ) {
  3596. var not = match[3];
  3597. for ( var j = 0, l = not.length; j < l; j++ ) {
  3598. if ( not[j] === elem ) {
  3599. return false;
  3600. }
  3601. }
  3602. return true;
  3603. } else {
  3604. Sizzle.error( name );
  3605. }
  3606. },
  3607. CHILD: function( elem, match ) {
  3608. var type = match[1],
  3609. node = elem;
  3610. switch ( type ) {
  3611. case "only":
  3612. case "first":
  3613. while ( (node = node.previousSibling) ) {
  3614. if ( node.nodeType === 1 ) {
  3615. return false;
  3616. }
  3617. }
  3618. if ( type === "first" ) {
  3619. return true;
  3620. }
  3621. node = elem;
  3622. case "last":
  3623. while ( (node = node.nextSibling) ) {
  3624. if ( node.nodeType === 1 ) {
  3625. return false;
  3626. }
  3627. }
  3628. return true;
  3629. case "nth":
  3630. var first = match[2],
  3631. last = match[3];
  3632. if ( first === 1 && last === 0 ) {
  3633. return true;
  3634. }
  3635. var doneName = match[0],
  3636. parent = elem.parentNode;
  3637. if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
  3638. var count = 0;
  3639. for ( node = parent.firstChild; node; node = node.nextSibling ) {
  3640. if ( node.nodeType === 1 ) {
  3641. node.nodeIndex = ++count;
  3642. }
  3643. }
  3644. parent.sizcache = doneName;
  3645. }
  3646. var diff = elem.nodeIndex - last;
  3647. if ( first === 0 ) {
  3648. return diff === 0;
  3649. } else {
  3650. return ( diff % first === 0 && diff / first >= 0 );
  3651. }
  3652. }
  3653. },
  3654. ID: function( elem, match ) {
  3655. return elem.nodeType === 1 && elem.getAttribute("id") === match;
  3656. },
  3657. TAG: function( elem, match ) {
  3658. return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match;
  3659. },
  3660. CLASS: function( elem, match ) {
  3661. return (" " + (elem.className || elem.getAttribute("class")) + " ")
  3662. .indexOf( match ) > -1;
  3663. },
  3664. ATTR: function( elem, match ) {
  3665. var name = match[1],
  3666. result = Expr.attrHandle[ name ] ?
  3667. Expr.attrHandle[ name ]( elem ) :
  3668. elem[ name ] != null ?
  3669. elem[ name ] :
  3670. elem.getAttribute( name ),
  3671. value = result + "",
  3672. type = match[2],
  3673. check = match[4];
  3674. return result == null ?
  3675. type === "!=" :
  3676. type === "=" ?
  3677. value === check :
  3678. type === "*=" ?
  3679. value.indexOf(check) >= 0 :
  3680. type === "~=" ?
  3681. (" " + value + " ").indexOf(check) >= 0 :
  3682. !check ?
  3683. value && result !== false :
  3684. type === "!=" ?
  3685. value !== check :
  3686. type === "^=" ?
  3687. value.indexOf(check) === 0 :
  3688. type === "$=" ?
  3689. value.substr(value.length - check.length) === check :
  3690. type === "|=" ?
  3691. value === check || value.substr(0, check.length + 1) === check + "-" :
  3692. false;
  3693. },
  3694. POS: function( elem, match, i, array ) {
  3695. var name = match[2],
  3696. filter = Expr.setFilters[ name ];
  3697. if ( filter ) {
  3698. return filter( elem, i, match, array );
  3699. }
  3700. }
  3701. }
  3702. };
  3703. var origPOS = Expr.match.POS,
  3704. fescape = function(all, num){
  3705. return "\\" + (num - 0 + 1);
  3706. };
  3707. for ( var type in Expr.match ) {
  3708. Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
  3709. Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
  3710. }
  3711. var makeArray = function( array, results ) {
  3712. array = Array.prototype.slice.call( array, 0 );
  3713. if ( results ) {
  3714. results.push.apply( results, array );
  3715. return results;
  3716. }
  3717. return array;
  3718. };
  3719. // Perform a simple check to determine if the browser is capable of
  3720. // converting a NodeList to an array using builtin methods.
  3721. // Also verifies that the returned array holds DOM nodes
  3722. // (which is not the case in the Blackberry browser)
  3723. try {
  3724. Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
  3725. // Provide a fallback method if it does not work
  3726. } catch( e ) {
  3727. makeArray = function( array, results ) {
  3728. var i = 0,
  3729. ret = results || [];
  3730. if ( toString.call(array) === "[object Array]" ) {
  3731. Array.prototype.push.apply( ret, array );
  3732. } else {
  3733. if ( typeof array.length === "number" ) {
  3734. for ( var l = array.length; i < l; i++ ) {
  3735. ret.push( array[i] );
  3736. }
  3737. } else {
  3738. for ( ; array[i]; i++ ) {
  3739. ret.push( array[i] );
  3740. }
  3741. }
  3742. }
  3743. return ret;
  3744. };
  3745. }
  3746. var sortOrder, siblingCheck;
  3747. if ( document.documentElement.compareDocumentPosition ) {
  3748. sortOrder = function( a, b ) {
  3749. if ( a === b ) {
  3750. hasDuplicate = true;
  3751. return 0;
  3752. }
  3753. if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
  3754. return a.compareDocumentPosition ? -1 : 1;
  3755. }
  3756. return a.compareDocumentPosition(b) & 4 ? -1 : 1;
  3757. };
  3758. } else {
  3759. sortOrder = function( a, b ) {
  3760. // The nodes are identical, we can exit early
  3761. if ( a === b ) {
  3762. hasDuplicate = true;
  3763. return 0;
  3764. // Fallback to using sourceIndex (in IE) if it's available on both nodes
  3765. } else if ( a.sourceIndex && b.sourceIndex ) {
  3766. return a.sourceIndex - b.sourceIndex;
  3767. }
  3768. var al, bl,
  3769. ap = [],
  3770. bp = [],
  3771. aup = a.parentNode,
  3772. bup = b.parentNode,
  3773. cur = aup;
  3774. // If the nodes are siblings (or identical) we can do a quick check
  3775. if ( aup === bup ) {
  3776. return siblingCheck( a, b );
  3777. // If no parents were found then the nodes are disconnected
  3778. } else if ( !aup ) {
  3779. return -1;
  3780. } else if ( !bup ) {
  3781. return 1;
  3782. }
  3783. // Otherwise they're somewhere else in the tree so we need
  3784. // to build up a full list of the parentNodes for comparison
  3785. while ( cur ) {
  3786. ap.unshift( cur );
  3787. cur = cur.parentNode;
  3788. }
  3789. cur = bup;
  3790. while ( cur ) {
  3791. bp.unshift( cur );
  3792. cur = cur.parentNode;
  3793. }
  3794. al = ap.length;
  3795. bl = bp.length;
  3796. // Start walking down the tree looking for a discrepancy
  3797. for ( var i = 0; i < al && i < bl; i++ ) {
  3798. if ( ap[i] !== bp[i] ) {
  3799. return siblingCheck( ap[i], bp[i] );
  3800. }
  3801. }
  3802. // We ended someplace up the tree so do a sibling check
  3803. return i === al ?
  3804. siblingCheck( a, bp[i], -1 ) :
  3805. siblingCheck( ap[i], b, 1 );
  3806. };
  3807. siblingCheck = function( a, b, ret ) {
  3808. if ( a === b ) {
  3809. return ret;
  3810. }
  3811. var cur = a.nextSibling;
  3812. while ( cur ) {
  3813. if ( cur === b ) {
  3814. return -1;
  3815. }
  3816. cur = cur.nextSibling;
  3817. }
  3818. return 1;
  3819. };
  3820. }
  3821. // Utility function for retreiving the text value of an array of DOM nodes
  3822. Sizzle.getText = function( elems ) {
  3823. var ret = "", elem;
  3824. for ( var i = 0; elems[i]; i++ ) {
  3825. elem = elems[i];
  3826. // Get the text from text nodes and CDATA nodes
  3827. if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
  3828. ret += elem.nodeValue;
  3829. // Traverse everything else, except comment nodes
  3830. } else if ( elem.nodeType !== 8 ) {
  3831. ret += Sizzle.getText( elem.childNodes );
  3832. }
  3833. }
  3834. return ret;
  3835. };
  3836. // Check to see if the browser returns elements by name when
  3837. // querying by getElementById (and provide a workaround)
  3838. (function(){
  3839. // We're going to inject a fake input element with a specified name
  3840. var form = document.createElement("div"),
  3841. id = "script" + (new Date()).getTime(),
  3842. root = document.documentElement;
  3843. form.innerHTML = "<a name='" + id + "'/>";
  3844. // Inject it into the root element, check its status, and remove it quickly
  3845. root.insertBefore( form, root.firstChild );
  3846. // The workaround has to do additional checks after a getElementById
  3847. // Which slows things down for other browsers (hence the branching)
  3848. if ( document.getElementById( id ) ) {
  3849. Expr.find.ID = function( match, context, isXML ) {
  3850. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  3851. var m = context.getElementById(match[1]);
  3852. return m ?
  3853. m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ?
  3854. [m] :
  3855. undefined :
  3856. [];
  3857. }
  3858. };
  3859. Expr.filter.ID = function( elem, match ) {
  3860. var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  3861. return elem.nodeType === 1 && node && node.nodeValue === match;
  3862. };
  3863. }
  3864. root.removeChild( form );
  3865. // release memory in IE
  3866. root = form = null;
  3867. })();
  3868. (function(){
  3869. // Check to see if the browser returns only elements
  3870. // when doing getElementsByTagName("*")
  3871. // Create a fake element
  3872. var div = document.createElement("div");
  3873. div.appendChild( document.createComment("") );
  3874. // Make sure no comments are found
  3875. if ( div.getElementsByTagName("*").length > 0 ) {
  3876. Expr.find.TAG = function( match, context ) {
  3877. var results = context.getElementsByTagName( match[1] );
  3878. // Filter out possible comments
  3879. if ( match[1] === "*" ) {
  3880. var tmp = [];
  3881. for ( var i = 0; results[i]; i++ ) {
  3882. if ( results[i].nodeType === 1 ) {
  3883. tmp.push( results[i] );
  3884. }
  3885. }
  3886. results = tmp;
  3887. }
  3888. return results;
  3889. };
  3890. }
  3891. // Check to see if an attribute returns normalized href attributes
  3892. div.innerHTML = "<a href='#'></a>";
  3893. if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
  3894. div.firstChild.getAttribute("href") !== "#" ) {
  3895. Expr.attrHandle.href = function( elem ) {
  3896. return elem.getAttribute( "href", 2 );
  3897. };
  3898. }
  3899. // release memory in IE
  3900. div = null;
  3901. })();
  3902. if ( document.querySelectorAll ) {
  3903. (function(){
  3904. var oldSizzle = Sizzle,
  3905. div = document.createElement("div"),
  3906. id = "__sizzle__";
  3907. div.innerHTML = "<p class='TEST'></p>";
  3908. // Safari can't handle uppercase or unicode characters when
  3909. // in quirks mode.
  3910. if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
  3911. return;
  3912. }
  3913. Sizzle = function( query, context, extra, seed ) {
  3914. context = context || document;
  3915. // Only use querySelectorAll on non-XML documents
  3916. // (ID selectors don't work in non-HTML documents)
  3917. if ( !seed && !Sizzle.isXML(context) ) {
  3918. // See if we find a selector to speed up
  3919. var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );
  3920. if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {
  3921. // Speed-up: Sizzle("TAG")
  3922. if ( match[1] ) {
  3923. return makeArray( context.getElementsByTagName( query ), extra );
  3924. // Speed-up: Sizzle(".CLASS")
  3925. } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {
  3926. return makeArray( context.getElementsByClassName( match[2] ), extra );
  3927. }
  3928. }
  3929. if ( context.nodeType === 9 ) {
  3930. // Speed-up: Sizzle("body")
  3931. // The body element only exists once, optimize finding it
  3932. if ( query === "body" && context.body ) {
  3933. return makeArray( [ context.body ], extra );
  3934. // Speed-up: Sizzle("#ID")
  3935. } else if ( match && match[3] ) {
  3936. var elem = context.getElementById( match[3] );
  3937. // Check parentNode to catch when Blackberry 4.6 returns
  3938. // nodes that are no longer in the document #6963
  3939. if ( elem && elem.parentNode ) {
  3940. // Handle the case where IE and Opera return items
  3941. // by name instead of ID
  3942. if ( elem.id === match[3] ) {
  3943. return makeArray( [ elem ], extra );
  3944. }
  3945. } else {
  3946. return makeArray( [], extra );
  3947. }
  3948. }
  3949. try {
  3950. return makeArray( context.querySelectorAll(query), extra );
  3951. } catch(qsaError) {}
  3952. // qSA works strangely on Element-rooted queries
  3953. // We can work around this by specifying an extra ID on the root
  3954. // and working up from there (Thanks to Andrew Dupont for the technique)
  3955. // IE 8 doesn't work on object elements
  3956. } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
  3957. var oldContext = context,
  3958. old = context.getAttribute( "id" ),
  3959. nid = old || id,
  3960. hasParent = context.parentNode,
  3961. relativeHierarchySelector = /^\s*[+~]/.test( query );
  3962. if ( !old ) {
  3963. context.setAttribute( "id", nid );
  3964. } else {
  3965. nid = nid.replace( /'/g, "\\$&" );
  3966. }
  3967. if ( relativeHierarchySelector && hasParent ) {
  3968. context = context.parentNode;
  3969. }
  3970. try {
  3971. if ( !relativeHierarchySelector || hasParent ) {
  3972. return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra );
  3973. }
  3974. } catch(pseudoError) {
  3975. } finally {
  3976. if ( !old ) {
  3977. oldContext.removeAttribute( "id" );
  3978. }
  3979. }
  3980. }
  3981. }
  3982. return oldSizzle(query, context, extra, seed);
  3983. };
  3984. for ( var prop in oldSizzle ) {
  3985. Sizzle[ prop ] = oldSizzle[ prop ];
  3986. }
  3987. // release memory in IE
  3988. div = null;
  3989. })();
  3990. }
  3991. (function(){
  3992. var html = document.documentElement,
  3993. matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector;
  3994. if ( matches ) {
  3995. // Check to see if it's possible to do matchesSelector
  3996. // on a disconnected node (IE 9 fails this)
  3997. var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ),
  3998. pseudoWorks = false;
  3999. try {
  4000. // This should fail with an exception
  4001. // Gecko does not error, returns false instead
  4002. matches.call( document.documentElement, "[test!='']:sizzle" );
  4003. } catch( pseudoError ) {
  4004. pseudoWorks = true;
  4005. }
  4006. Sizzle.matchesSelector = function( node, expr ) {
  4007. // Make sure that attribute selectors are quoted
  4008. expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");
  4009. if ( !Sizzle.isXML( node ) ) {
  4010. try {
  4011. if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {
  4012. var ret = matches.call( node, expr );
  4013. // IE 9's matchesSelector returns false on disconnected nodes
  4014. if ( ret || !disconnectedMatch ||
  4015. // As well, disconnected nodes are said to be in a document
  4016. // fragment in IE 9, so check for that
  4017. node.document && node.document.nodeType !== 11 ) {
  4018. return ret;
  4019. }
  4020. }
  4021. } catch(e) {}
  4022. }
  4023. return Sizzle(expr, null, null, [node]).length > 0;
  4024. };
  4025. }
  4026. })();
  4027. (function(){
  4028. var div = document.createElement("div");
  4029. div.innerHTML = "<div class='test e'></div><div class='test'></div>";
  4030. // Opera can't find a second classname (in 9.6)
  4031. // Also, make sure that getElementsByClassName actually exists
  4032. if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
  4033. return;
  4034. }
  4035. // Safari caches class attributes, doesn't catch changes (in 3.2)
  4036. div.lastChild.className = "e";
  4037. if ( div.getElementsByClassName("e").length === 1 ) {
  4038. return;
  4039. }
  4040. Expr.order.splice(1, 0, "CLASS");
  4041. Expr.find.CLASS = function( match, context, isXML ) {
  4042. if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
  4043. return context.getElementsByClassName(match[1]);
  4044. }
  4045. };
  4046. // release memory in IE
  4047. div = null;
  4048. })();
  4049. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  4050. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  4051. var elem = checkSet[i];
  4052. if ( elem ) {
  4053. var match = false;
  4054. elem = elem[dir];
  4055. while ( elem ) {
  4056. if ( elem.sizcache === doneName ) {
  4057. match = checkSet[elem.sizset];
  4058. break;
  4059. }
  4060. if ( elem.nodeType === 1 && !isXML ){
  4061. elem.sizcache = doneName;
  4062. elem.sizset = i;
  4063. }
  4064. if ( elem.nodeName.toLowerCase() === cur ) {
  4065. match = elem;
  4066. break;
  4067. }
  4068. elem = elem[dir];
  4069. }
  4070. checkSet[i] = match;
  4071. }
  4072. }
  4073. }
  4074. function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  4075. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  4076. var elem = checkSet[i];
  4077. if ( elem ) {
  4078. var match = false;
  4079. elem = elem[dir];
  4080. while ( elem ) {
  4081. if ( elem.sizcache === doneName ) {
  4082. match = checkSet[elem.sizset];
  4083. break;
  4084. }
  4085. if ( elem.nodeType === 1 ) {
  4086. if ( !isXML ) {
  4087. elem.sizcache = doneName;
  4088. elem.sizset = i;
  4089. }
  4090. if ( typeof cur !== "string" ) {
  4091. if ( elem === cur ) {
  4092. match = true;
  4093. break;
  4094. }
  4095. } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  4096. match = elem;
  4097. break;
  4098. }
  4099. }
  4100. elem = elem[dir];
  4101. }
  4102. checkSet[i] = match;
  4103. }
  4104. }
  4105. }
  4106. if ( document.documentElement.contains ) {
  4107. Sizzle.contains = function( a, b ) {
  4108. return a !== b && (a.contains ? a.contains(b) : true);
  4109. };
  4110. } else if ( document.documentElement.compareDocumentPosition ) {
  4111. Sizzle.contains = function( a, b ) {
  4112. return !!(a.compareDocumentPosition(b) & 16);
  4113. };
  4114. } else {
  4115. Sizzle.contains = function() {
  4116. return false;
  4117. };
  4118. }
  4119. Sizzle.isXML = function( elem ) {
  4120. // documentElement is verified for cases where it doesn't yet exist
  4121. // (such as loading iframes in IE - #4833)
  4122. var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
  4123. return documentElement ? documentElement.nodeName !== "HTML" : false;
  4124. };
  4125. var posProcess = function( selector, context ) {
  4126. var match,
  4127. tmpSet = [],
  4128. later = "",
  4129. root = context.nodeType ? [context] : context;
  4130. // Position selectors must be done after the filter
  4131. // And so must :not(positional) so we move all PSEUDOs to the end
  4132. while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
  4133. later += match[0];
  4134. selector = selector.replace( Expr.match.PSEUDO, "" );
  4135. }
  4136. selector = Expr.relative[selector] ? selector + "*" : selector;
  4137. for ( var i = 0, l = root.length; i < l; i++ ) {
  4138. Sizzle( selector, root[i], tmpSet );
  4139. }
  4140. return Sizzle.filter( later, tmpSet );
  4141. };
  4142. // EXPOSE
  4143. jQuery.find = Sizzle;
  4144. jQuery.expr = Sizzle.selectors;
  4145. jQuery.expr[":"] = jQuery.expr.filters;
  4146. jQuery.unique = Sizzle.uniqueSort;
  4147. jQuery.text = Sizzle.getText;
  4148. jQuery.isXMLDoc = Sizzle.isXML;
  4149. jQuery.contains = Sizzle.contains;
  4150. })();
  4151. var runtil = /Until$/,
  4152. rparentsprev = /^(?:parents|prevUntil|prevAll)/,
  4153. // Note: This RegExp should be improved, or likely pulled from Sizzle
  4154. rmultiselector = /,/,
  4155. isSimple = /^.[^:#\[\.,]*$/,
  4156. slice = Array.prototype.slice,
  4157. POS = jQuery.expr.match.POS,
  4158. // methods guaranteed to produce a unique set when starting from a unique set
  4159. guaranteedUnique = {
  4160. children: true,
  4161. contents: true,
  4162. next: true,
  4163. prev: true
  4164. };
  4165. jQuery.fn.extend({
  4166. find: function( selector ) {
  4167. var self = this,
  4168. i, l;
  4169. if ( typeof selector !== "string" ) {
  4170. return jQuery( selector ).filter(function() {
  4171. for ( i = 0, l = self.length; i < l; i++ ) {
  4172. if ( jQuery.contains( self[ i ], this ) ) {
  4173. return true;
  4174. }
  4175. }
  4176. });
  4177. }
  4178. var ret = this.pushStack( "", "find", selector ),
  4179. length, n, r;
  4180. for ( i = 0, l = this.length; i < l; i++ ) {
  4181. length = ret.length;
  4182. jQuery.find( selector, this[i], ret );
  4183. if ( i > 0 ) {
  4184. // Make sure that the results are unique
  4185. for ( n = length; n < ret.length; n++ ) {
  4186. for ( r = 0; r < length; r++ ) {
  4187. if ( ret[r] === ret[n] ) {
  4188. ret.splice(n--, 1);
  4189. break;
  4190. }
  4191. }
  4192. }
  4193. }
  4194. }
  4195. return ret;
  4196. },
  4197. has: function( target ) {
  4198. var targets = jQuery( target );
  4199. return this.filter(function() {
  4200. for ( var i = 0, l = targets.length; i < l; i++ ) {
  4201. if ( jQuery.contains( this, targets[i] ) ) {
  4202. return true;
  4203. }
  4204. }
  4205. });
  4206. },
  4207. not: function( selector ) {
  4208. return this.pushStack( winnow(this, selector, false), "not", selector);
  4209. },
  4210. filter: function( selector ) {
  4211. return this.pushStack( winnow(this, selector, true), "filter", selector );
  4212. },
  4213. is: function( selector ) {
  4214. return !!selector && ( typeof selector === "string" ?
  4215. jQuery.filter( selector, this ).length > 0 :
  4216. this.filter( selector ).length > 0 );
  4217. },
  4218. closest: function( selectors, context ) {
  4219. var ret = [], i, l, cur = this[0];
  4220. // Array
  4221. if ( jQuery.isArray( selectors ) ) {
  4222. var match, selector,
  4223. matches = {},
  4224. level = 1;
  4225. if ( cur && selectors.length ) {
  4226. for ( i = 0, l = selectors.length; i < l; i++ ) {
  4227. selector = selectors[i];
  4228. if ( !matches[ selector ] ) {
  4229. matches[ selector ] = POS.test( selector ) ?
  4230. jQuery( selector, context || this.context ) :
  4231. selector;
  4232. }
  4233. }
  4234. while ( cur && cur.ownerDocument && cur !== context ) {
  4235. for ( selector in matches ) {
  4236. match = matches[ selector ];
  4237. if ( match.jquery ? match.index( cur ) > -1 : jQuery( cur ).is( match ) ) {
  4238. ret.push({ selector: selector, elem: cur, level: level });
  4239. }
  4240. }
  4241. cur = cur.parentNode;
  4242. level++;
  4243. }
  4244. }
  4245. return ret;
  4246. }
  4247. // String
  4248. var pos = POS.test( selectors ) || typeof selectors !== "string" ?
  4249. jQuery( selectors, context || this.context ) :
  4250. 0;
  4251. for ( i = 0, l = this.length; i < l; i++ ) {
  4252. cur = this[i];
  4253. while ( cur ) {
  4254. if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) {
  4255. ret.push( cur );
  4256. break;
  4257. } else {
  4258. cur = cur.parentNode;
  4259. if ( !cur || !cur.ownerDocument || cur === context || cur.nodeType === 11 ) {
  4260. break;
  4261. }
  4262. }
  4263. }
  4264. }
  4265. ret = ret.length > 1 ? jQuery.unique( ret ) : ret;
  4266. return this.pushStack( ret, "closest", selectors );
  4267. },
  4268. // Determine the position of an element within
  4269. // the matched set of elements
  4270. index: function( elem ) {
  4271. if ( !elem || typeof elem === "string" ) {
  4272. return jQuery.inArray( this[0],
  4273. // If it receives a string, the selector is used
  4274. // If it receives nothing, the siblings are used
  4275. elem ? jQuery( elem ) : this.parent().children() );
  4276. }
  4277. // Locate the position of the desired element
  4278. return jQuery.inArray(
  4279. // If it receives a jQuery object, the first element is used
  4280. elem.jquery ? elem[0] : elem, this );
  4281. },
  4282. add: function( selector, context ) {
  4283. var set = typeof selector === "string" ?
  4284. jQuery( selector, context ) :
  4285. jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ),
  4286. all = jQuery.merge( this.get(), set );
  4287. return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ?
  4288. all :
  4289. jQuery.unique( all ) );
  4290. },
  4291. andSelf: function() {
  4292. return this.add( this.prevObject );
  4293. }
  4294. });
  4295. // A painfully simple check to see if an element is disconnected
  4296. // from a document (should be improved, where feasible).
  4297. function isDisconnected( node ) {
  4298. return !node || !node.parentNode || node.parentNode.nodeType === 11;
  4299. }
  4300. jQuery.each({
  4301. parent: function( elem ) {
  4302. var parent = elem.parentNode;
  4303. return parent && parent.nodeType !== 11 ? parent : null;
  4304. },
  4305. parents: function( elem ) {
  4306. return jQuery.dir( elem, "parentNode" );
  4307. },
  4308. parentsUntil: function( elem, i, until ) {
  4309. return jQuery.dir( elem, "parentNode", until );
  4310. },
  4311. next: function( elem ) {
  4312. return jQuery.nth( elem, 2, "nextSibling" );
  4313. },
  4314. prev: function( elem ) {
  4315. return jQuery.nth( elem, 2, "previousSibling" );
  4316. },
  4317. nextAll: function( elem ) {
  4318. return jQuery.dir( elem, "nextSibling" );
  4319. },
  4320. prevAll: function( elem ) {
  4321. return jQuery.dir( elem, "previousSibling" );
  4322. },
  4323. nextUntil: function( elem, i, until ) {
  4324. return jQuery.dir( elem, "nextSibling", until );
  4325. },
  4326. prevUntil: function( elem, i, until ) {
  4327. return jQuery.dir( elem, "previousSibling", until );
  4328. },
  4329. siblings: function( elem ) {
  4330. return jQuery.sibling( elem.parentNode.firstChild, elem );
  4331. },
  4332. children: function( elem ) {
  4333. return jQuery.sibling( elem.firstChild );
  4334. },
  4335. contents: function( elem ) {
  4336. return jQuery.nodeName( elem, "iframe" ) ?
  4337. elem.contentDocument || elem.contentWindow.document :
  4338. jQuery.makeArray( elem.childNodes );
  4339. }
  4340. }, function( name, fn ) {
  4341. jQuery.fn[ name ] = function( until, selector ) {
  4342. var ret = jQuery.map( this, fn, until ),
  4343. // The variable 'args' was introduced in
  4344. // https://github.com/jquery/jquery/commit/52a0238
  4345. // to work around a bug in Chrome 10 (Dev) and should be removed when the bug is fixed.
  4346. // http://code.google.com/p/v8/issues/detail?id=1050
  4347. args = slice.call(arguments);
  4348. if ( !runtil.test( name ) ) {
  4349. selector = until;
  4350. }
  4351. if ( selector && typeof selector === "string" ) {
  4352. ret = jQuery.filter( selector, ret );
  4353. }
  4354. ret = this.length > 1 && !guaranteedUnique[ name ] ? jQuery.unique( ret ) : ret;
  4355. if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
  4356. ret = ret.reverse();
  4357. }
  4358. return this.pushStack( ret, name, args.join(",") );
  4359. };
  4360. });
  4361. jQuery.extend({
  4362. filter: function( expr, elems, not ) {
  4363. if ( not ) {
  4364. expr = ":not(" + expr + ")";
  4365. }
  4366. return elems.length === 1 ?
  4367. jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] :
  4368. jQuery.find.matches(expr, elems);
  4369. },
  4370. dir: function( elem, dir, until ) {
  4371. var matched = [],
  4372. cur = elem[ dir ];
  4373. while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) {
  4374. if ( cur.nodeType === 1 ) {
  4375. matched.push( cur );
  4376. }
  4377. cur = cur[dir];
  4378. }
  4379. return matched;
  4380. },
  4381. nth: function( cur, result, dir, elem ) {
  4382. result = result || 1;
  4383. var num = 0;
  4384. for ( ; cur; cur = cur[dir] ) {
  4385. if ( cur.nodeType === 1 && ++num === result ) {
  4386. break;
  4387. }
  4388. }
  4389. return cur;
  4390. },
  4391. sibling: function( n, elem ) {
  4392. var r = [];
  4393. for ( ; n; n = n.nextSibling ) {
  4394. if ( n.nodeType === 1 && n !== elem ) {
  4395. r.push( n );
  4396. }
  4397. }
  4398. return r;
  4399. }
  4400. });
  4401. // Implement the identical functionality for filter and not
  4402. function winnow( elements, qualifier, keep ) {
  4403. // Can't pass null or undefined to indexOf in Firefox 4
  4404. // Set to 0 to skip string check
  4405. qualifier = qualifier || 0;
  4406. if ( jQuery.isFunction( qualifier ) ) {
  4407. return jQuery.grep(elements, function( elem, i ) {
  4408. var retVal = !!qualifier.call( elem, i, elem );
  4409. return retVal === keep;
  4410. });
  4411. } else if ( qualifier.nodeType ) {
  4412. return jQuery.grep(elements, function( elem, i ) {
  4413. return (elem === qualifier) === keep;
  4414. });
  4415. } else if ( typeof qualifier === "string" ) {
  4416. var filtered = jQuery.grep(elements, function( elem ) {
  4417. return elem.nodeType === 1;
  4418. });
  4419. if ( isSimple.test( qualifier ) ) {
  4420. return jQuery.filter(qualifier, filtered, !keep);
  4421. } else {
  4422. qualifier = jQuery.filter( qualifier, filtered );
  4423. }
  4424. }
  4425. return jQuery.grep(elements, function( elem, i ) {
  4426. return (jQuery.inArray( elem, qualifier ) >= 0) === keep;
  4427. });
  4428. }
  4429. var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
  4430. rleadingWhitespace = /^\s+/,
  4431. rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
  4432. rtagName = /<([\w:]+)/,
  4433. rtbody = /<tbody/i,
  4434. rhtml = /<|&#?\w+;/,
  4435. rnocache = /<(?:script|object|embed|option|style)/i,
  4436. // checked="checked" or checked
  4437. rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
  4438. rscriptType = /\/(java|ecma)script/i,
  4439. rcleanScript = /^\s*<!(?:\[CDATA\[|\-\-)/,
  4440. wrapMap = {
  4441. option: [ 1, "<select multiple='multiple'>", "</select>" ],
  4442. legend: [ 1, "<fieldset>", "</fieldset>" ],
  4443. thead: [ 1, "<table>", "</table>" ],
  4444. tr: [ 2, "<table><tbody>", "</tbody></table>" ],
  4445. td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
  4446. col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
  4447. area: [ 1, "<map>", "</map>" ],
  4448. _default: [ 0, "", "" ]
  4449. };
  4450. wrapMap.optgroup = wrapMap.option;
  4451. wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
  4452. wrapMap.th = wrapMap.td;
  4453. // IE can't serialize <link> and <script> tags normally
  4454. if ( !jQuery.support.htmlSerialize ) {
  4455. wrapMap._default = [ 1, "div<div>", "</div>" ];
  4456. }
  4457. jQuery.fn.extend({
  4458. text: function( text ) {
  4459. if ( jQuery.isFunction(text) ) {
  4460. return this.each(function(i) {
  4461. var self = jQuery( this );
  4462. self.text( text.call(this, i, self.text()) );
  4463. });
  4464. }
  4465. if ( typeof text !== "object" && text !== undefined ) {
  4466. return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
  4467. }
  4468. return jQuery.text( this );
  4469. },
  4470. wrapAll: function( html ) {
  4471. if ( jQuery.isFunction( html ) ) {
  4472. return this.each(function(i) {
  4473. jQuery(this).wrapAll( html.call(this, i) );
  4474. });
  4475. }
  4476. if ( this[0] ) {
  4477. // The elements to wrap the target around
  4478. var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
  4479. if ( this[0].parentNode ) {
  4480. wrap.insertBefore( this[0] );
  4481. }
  4482. wrap.map(function() {
  4483. var elem = this;
  4484. while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
  4485. elem = elem.firstChild;
  4486. }
  4487. return elem;
  4488. }).append( this );
  4489. }
  4490. return this;
  4491. },
  4492. wrapInner: function( html ) {
  4493. if ( jQuery.isFunction( html ) ) {
  4494. return this.each(function(i) {
  4495. jQuery(this).wrapInner( html.call(this, i) );
  4496. });
  4497. }
  4498. return this.each(function() {
  4499. var self = jQuery( this ),
  4500. contents = self.contents();
  4501. if ( contents.length ) {
  4502. contents.wrapAll( html );
  4503. } else {
  4504. self.append( html );
  4505. }
  4506. });
  4507. },
  4508. wrap: function( html ) {
  4509. return this.each(function() {
  4510. jQuery( this ).wrapAll( html );
  4511. });
  4512. },
  4513. unwrap: function() {
  4514. return this.parent().each(function() {
  4515. if ( !jQuery.nodeName( this, "body" ) ) {
  4516. jQuery( this ).replaceWith( this.childNodes );
  4517. }
  4518. }).end();
  4519. },
  4520. append: function() {
  4521. return this.domManip(arguments, true, function( elem ) {
  4522. if ( this.nodeType === 1 ) {
  4523. this.appendChild( elem );
  4524. }
  4525. });
  4526. },
  4527. prepend: function() {
  4528. return this.domManip(arguments, true, function( elem ) {
  4529. if ( this.nodeType === 1 ) {
  4530. this.insertBefore( elem, this.firstChild );
  4531. }
  4532. });
  4533. },
  4534. before: function() {
  4535. if ( this[0] && this[0].parentNode ) {
  4536. return this.domManip(arguments, false, function( elem ) {
  4537. this.parentNode.insertBefore( elem, this );
  4538. });
  4539. } else if ( arguments.length ) {
  4540. var set = jQuery(arguments[0]);
  4541. set.push.apply( set, this.toArray() );
  4542. return this.pushStack( set, "before", arguments );
  4543. }
  4544. },
  4545. after: function() {
  4546. if ( this[0] && this[0].parentNode ) {
  4547. return this.domManip(arguments, false, function( elem ) {
  4548. this.parentNode.insertBefore( elem, this.nextSibling );
  4549. });
  4550. } else if ( arguments.length ) {
  4551. var set = this.pushStack( this, "after", arguments );
  4552. set.push.apply( set, jQuery(arguments[0]).toArray() );
  4553. return set;
  4554. }
  4555. },
  4556. // keepData is for internal use only--do not document
  4557. remove: function( selector, keepData ) {
  4558. for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
  4559. if ( !selector || jQuery.filter( selector, [ elem ] ).length ) {
  4560. if ( !keepData && elem.nodeType === 1 ) {
  4561. jQuery.cleanData( elem.getElementsByTagName("*") );
  4562. jQuery.cleanData( [ elem ] );
  4563. }
  4564. if ( elem.parentNode ) {
  4565. elem.parentNode.removeChild( elem );
  4566. }
  4567. }
  4568. }
  4569. return this;
  4570. },
  4571. empty: function() {
  4572. for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
  4573. // Remove element nodes and prevent memory leaks
  4574. if ( elem.nodeType === 1 ) {
  4575. jQuery.cleanData( elem.getElementsByTagName("*") );
  4576. }
  4577. // Remove any remaining nodes
  4578. while ( elem.firstChild ) {
  4579. elem.removeChild( elem.firstChild );
  4580. }
  4581. }
  4582. return this;
  4583. },
  4584. clone: function( dataAndEvents, deepDataAndEvents ) {
  4585. dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
  4586. deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
  4587. return this.map( function () {
  4588. return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
  4589. });
  4590. },
  4591. html: function( value ) {
  4592. if ( value === undefined ) {
  4593. return this[0] && this[0].nodeType === 1 ?
  4594. this[0].innerHTML.replace(rinlinejQuery, "") :
  4595. null;
  4596. // See if we can take a shortcut and just use innerHTML
  4597. } else if ( typeof value === "string" && !rnocache.test( value ) &&
  4598. (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
  4599. !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {
  4600. value = value.replace(rxhtmlTag, "<$1></$2>");
  4601. try {
  4602. for ( var i = 0, l = this.length; i < l; i++ ) {
  4603. // Remove element nodes and prevent memory leaks
  4604. if ( this[i].nodeType === 1 ) {
  4605. jQuery.cleanData( this[i].getElementsByTagName("*") );
  4606. this[i].innerHTML = value;
  4607. }
  4608. }
  4609. // If using innerHTML throws an exception, use the fallback method
  4610. } catch(e) {
  4611. this.empty().append( value );
  4612. }
  4613. } else if ( jQuery.isFunction( value ) ) {
  4614. this.each(function(i){
  4615. var self = jQuery( this );
  4616. self.html( value.call(this, i, self.html()) );
  4617. });
  4618. } else {
  4619. this.empty().append( value );
  4620. }
  4621. return this;
  4622. },
  4623. replaceWith: function( value ) {
  4624. if ( this[0] && this[0].parentNode ) {
  4625. // Make sure that the elements are removed from the DOM before they are inserted
  4626. // this can help fix replacing a parent with child elements
  4627. if ( jQuery.isFunction( value ) ) {
  4628. return this.each(function(i) {
  4629. var self = jQuery(this), old = self.html();
  4630. self.replaceWith( value.call( this, i, old ) );
  4631. });
  4632. }
  4633. if ( typeof value !== "string" ) {
  4634. value = jQuery( value ).detach();
  4635. }
  4636. return this.each(function() {
  4637. var next = this.nextSibling,
  4638. parent = this.parentNode;
  4639. jQuery( this ).remove();
  4640. if ( next ) {
  4641. jQuery(next).before( value );
  4642. } else {
  4643. jQuery(parent).append( value );
  4644. }
  4645. });
  4646. } else {
  4647. return this.length ?
  4648. this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) :
  4649. this;
  4650. }
  4651. },
  4652. detach: function( selector ) {
  4653. return this.remove( selector, true );
  4654. },
  4655. domManip: function( args, table, callback ) {
  4656. var results, first, fragment, parent,
  4657. value = args[0],
  4658. scripts = [];
  4659. // We can't cloneNode fragments that contain checked, in WebKit
  4660. if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) {
  4661. return this.each(function() {
  4662. jQuery(this).domManip( args, table, callback, true );
  4663. });
  4664. }
  4665. if ( jQuery.isFunction(value) ) {
  4666. return this.each(function(i) {
  4667. var self = jQuery(this);
  4668. args[0] = value.call(this, i, table ? self.html() : undefined);
  4669. self.domManip( args, table, callback );
  4670. });
  4671. }
  4672. if ( this[0] ) {
  4673. parent = value && value.parentNode;
  4674. // If we're in a fragment, just use that instead of building a new one
  4675. if ( jQuery.support.parentNode && parent && parent.nodeType === 11 && parent.childNodes.length === this.length ) {
  4676. results = { fragment: parent };
  4677. } else {
  4678. results = jQuery.buildFragment( args, this, scripts );
  4679. }
  4680. fragment = results.fragment;
  4681. if ( fragment.childNodes.length === 1 ) {
  4682. first = fragment = fragment.firstChild;
  4683. } else {
  4684. first = fragment.firstChild;
  4685. }
  4686. if ( first ) {
  4687. table = table && jQuery.nodeName( first, "tr" );
  4688. for ( var i = 0, l = this.length, lastIndex = l - 1; i < l; i++ ) {
  4689. callback.call(
  4690. table ?
  4691. root(this[i], first) :
  4692. this[i],
  4693. // Make sure that we do not leak memory by inadvertently discarding
  4694. // the original fragment (which might have attached data) instead of
  4695. // using it; in addition, use the original fragment object for the last
  4696. // item instead of first because it can end up being emptied incorrectly
  4697. // in certain situations (Bug #8070).
  4698. // Fragments from the fragment cache must always be cloned and never used
  4699. // in place.
  4700. results.cacheable || (l > 1 && i < lastIndex) ?
  4701. jQuery.clone( fragment, true, true ) :
  4702. fragment
  4703. );
  4704. }
  4705. }
  4706. if ( scripts.length ) {
  4707. jQuery.each( scripts, evalScript );
  4708. }
  4709. }
  4710. return this;
  4711. }
  4712. });
  4713. function root( elem, cur ) {
  4714. return jQuery.nodeName(elem, "table") ?
  4715. (elem.getElementsByTagName("tbody")[0] ||
  4716. elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
  4717. elem;
  4718. }
  4719. function cloneCopyEvent( src, dest ) {
  4720. if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) {
  4721. return;
  4722. }
  4723. var internalKey = jQuery.expando,
  4724. oldData = jQuery.data( src ),
  4725. curData = jQuery.data( dest, oldData );
  4726. // Switch to use the internal data object, if it exists, for the next
  4727. // stage of data copying
  4728. if ( (oldData = oldData[ internalKey ]) ) {
  4729. var events = oldData.events;
  4730. curData = curData[ internalKey ] = jQuery.extend({}, oldData);
  4731. if ( events ) {
  4732. delete curData.handle;
  4733. curData.events = {};
  4734. for ( var type in events ) {
  4735. for ( var i = 0, l = events[ type ].length; i < l; i++ ) {
  4736. jQuery.event.add( dest, type + ( events[ type ][ i ].namespace ? "." : "" ) + events[ type ][ i ].namespace, events[ type ][ i ], events[ type ][ i ].data );
  4737. }
  4738. }
  4739. }
  4740. }
  4741. }
  4742. function cloneFixAttributes( src, dest ) {
  4743. var nodeName;
  4744. // We do not need to do anything for non-Elements
  4745. if ( dest.nodeType !== 1 ) {
  4746. return;
  4747. }
  4748. // clearAttributes removes the attributes, which we don't want,
  4749. // but also removes the attachEvent events, which we *do* want
  4750. if ( dest.clearAttributes ) {
  4751. dest.clearAttributes();
  4752. }
  4753. // mergeAttributes, in contrast, only merges back on the
  4754. // original attributes, not the events
  4755. if ( dest.mergeAttributes ) {
  4756. dest.mergeAttributes( src );
  4757. }
  4758. nodeName = dest.nodeName.toLowerCase();
  4759. // IE6-8 fail to clone children inside object elements that use
  4760. // the proprietary classid attribute value (rather than the type
  4761. // attribute) to identify the type of content to display
  4762. if ( nodeName === "object" ) {
  4763. dest.outerHTML = src.outerHTML;
  4764. } else if ( nodeName === "input" && (src.type === "checkbox" || src.type === "radio") ) {
  4765. // IE6-8 fails to persist the checked state of a cloned checkbox
  4766. // or radio button. Worse, IE6-7 fail to give the cloned element
  4767. // a checked appearance if the defaultChecked value isn't also set
  4768. if ( src.checked ) {
  4769. dest.defaultChecked = dest.checked = src.checked;
  4770. }
  4771. // IE6-7 get confused and end up setting the value of a cloned
  4772. // checkbox/radio button to an empty string instead of "on"
  4773. if ( dest.value !== src.value ) {
  4774. dest.value = src.value;
  4775. }
  4776. // IE6-8 fails to return the selected option to the default selected
  4777. // state when cloning options
  4778. } else if ( nodeName === "option" ) {
  4779. dest.selected = src.defaultSelected;
  4780. // IE6-8 fails to set the defaultValue to the correct value when
  4781. // cloning other types of input fields
  4782. } else if ( nodeName === "input" || nodeName === "textarea" ) {
  4783. dest.defaultValue = src.defaultValue;
  4784. }
  4785. // Event data gets referenced instead of copied if the expando
  4786. // gets copied too
  4787. dest.removeAttribute( jQuery.expando );
  4788. }
  4789. jQuery.buildFragment = function( args, nodes, scripts ) {
  4790. var fragment, cacheable, cacheresults,
  4791. doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
  4792. // Only cache "small" (1/2 KB) HTML strings that are associated with the main document
  4793. // Cloning options loses the selected state, so don't cache them
  4794. // IE 6 doesn't like it when you put <object> or <embed> elements in a fragment
  4795. // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
  4796. if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document &&
  4797. args[0].charAt(0) === "<" && !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
  4798. cacheable = true;
  4799. cacheresults = jQuery.fragments[ args[0] ];
  4800. if ( cacheresults && cacheresults !== 1 ) {
  4801. fragment = cacheresults;
  4802. }
  4803. }
  4804. if ( !fragment ) {
  4805. fragment = doc.createDocumentFragment();
  4806. jQuery.clean( args, doc, fragment, scripts );
  4807. }
  4808. if ( cacheable ) {
  4809. jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
  4810. }
  4811. return { fragment: fragment, cacheable: cacheable };
  4812. };
  4813. jQuery.fragments = {};
  4814. jQuery.each({
  4815. appendTo: "append",
  4816. prependTo: "prepend",
  4817. insertBefore: "before",
  4818. insertAfter: "after",
  4819. replaceAll: "replaceWith"
  4820. }, function( name, original ) {
  4821. jQuery.fn[ name ] = function( selector ) {
  4822. var ret = [],
  4823. insert = jQuery( selector ),
  4824. parent = this.length === 1 && this[0].parentNode;
  4825. if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
  4826. insert[ original ]( this[0] );
  4827. return this;
  4828. } else {
  4829. for ( var i = 0, l = insert.length; i < l; i++ ) {
  4830. var elems = (i > 0 ? this.clone(true) : this).get();
  4831. jQuery( insert[i] )[ original ]( elems );
  4832. ret = ret.concat( elems );
  4833. }
  4834. return this.pushStack( ret, name, insert.selector );
  4835. }
  4836. };
  4837. });
  4838. function getAll( elem ) {
  4839. if ( "getElementsByTagName" in elem ) {
  4840. return elem.getElementsByTagName( "*" );
  4841. } else if ( "querySelectorAll" in elem ) {
  4842. return elem.querySelectorAll( "*" );
  4843. } else {
  4844. return [];
  4845. }
  4846. }
  4847. // Used in clean, fixes the defaultChecked property
  4848. function fixDefaultChecked( elem ) {
  4849. if ( elem.type === "checkbox" || elem.type === "radio" ) {
  4850. elem.defaultChecked = elem.checked;
  4851. }
  4852. }
  4853. // Finds all inputs and passes them to fixDefaultChecked
  4854. function findInputs( elem ) {
  4855. if ( jQuery.nodeName( elem, "input" ) ) {
  4856. fixDefaultChecked( elem );
  4857. } else if ( elem.getElementsByTagName ) {
  4858. jQuery.grep( elem.getElementsByTagName("input"), fixDefaultChecked );
  4859. }
  4860. }
  4861. jQuery.extend({
  4862. clone: function( elem, dataAndEvents, deepDataAndEvents ) {
  4863. var clone = elem.cloneNode(true),
  4864. srcElements,
  4865. destElements,
  4866. i;
  4867. if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) &&
  4868. (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) {
  4869. // IE copies events bound via attachEvent when using cloneNode.
  4870. // Calling detachEvent on the clone will also remove the events
  4871. // from the original. In order to get around this, we use some
  4872. // proprietary methods to clear the events. Thanks to MooTools
  4873. // guys for this hotness.
  4874. cloneFixAttributes( elem, clone );
  4875. // Using Sizzle here is crazy slow, so we use getElementsByTagName
  4876. // instead
  4877. srcElements = getAll( elem );
  4878. destElements = getAll( clone );
  4879. // Weird iteration because IE will replace the length property
  4880. // with an element if you are cloning the body and one of the
  4881. // elements on the page has a name or id of "length"
  4882. for ( i = 0; srcElements[i]; ++i ) {
  4883. cloneFixAttributes( srcElements[i], destElements[i] );
  4884. }
  4885. }
  4886. // Copy the events from the original to the clone
  4887. if ( dataAndEvents ) {
  4888. cloneCopyEvent( elem, clone );
  4889. if ( deepDataAndEvents ) {
  4890. srcElements = getAll( elem );
  4891. destElements = getAll( clone );
  4892. for ( i = 0; srcElements[i]; ++i ) {
  4893. cloneCopyEvent( srcElements[i], destElements[i] );
  4894. }
  4895. }
  4896. }
  4897. // Return the cloned set
  4898. return clone;
  4899. },
  4900. clean: function( elems, context, fragment, scripts ) {
  4901. var checkScriptType;
  4902. context = context || document;
  4903. // !context.createElement fails in IE with an error but returns typeof 'object'
  4904. if ( typeof context.createElement === "undefined" ) {
  4905. context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
  4906. }
  4907. var ret = [], j;
  4908. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  4909. if ( typeof elem === "number" ) {
  4910. elem += "";
  4911. }
  4912. if ( !elem ) {
  4913. continue;
  4914. }
  4915. // Convert html string into DOM nodes
  4916. if ( typeof elem === "string" ) {
  4917. if ( !rhtml.test( elem ) ) {
  4918. elem = context.createTextNode( elem );
  4919. } else {
  4920. // Fix "XHTML"-style tags in all browsers
  4921. elem = elem.replace(rxhtmlTag, "<$1></$2>");
  4922. // Trim whitespace, otherwise indexOf won't work as expected
  4923. var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
  4924. wrap = wrapMap[ tag ] || wrapMap._default,
  4925. depth = wrap[0],
  4926. div = context.createElement("div");
  4927. // Go to html and back, then peel off extra wrappers
  4928. div.innerHTML = wrap[1] + elem + wrap[2];
  4929. // Move to the right depth
  4930. while ( depth-- ) {
  4931. div = div.lastChild;
  4932. }
  4933. // Remove IE's autoinserted <tbody> from table fragments
  4934. if ( !jQuery.support.tbody ) {
  4935. // String was a <table>, *may* have spurious <tbody>
  4936. var hasBody = rtbody.test(elem),
  4937. tbody = tag === "table" && !hasBody ?
  4938. div.firstChild && div.firstChild.childNodes :
  4939. // String was a bare <thead> or <tfoot>
  4940. wrap[1] === "<table>" && !hasBody ?
  4941. div.childNodes :
  4942. [];
  4943. for ( j = tbody.length - 1; j >= 0 ; --j ) {
  4944. if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
  4945. tbody[ j ].parentNode.removeChild( tbody[ j ] );
  4946. }
  4947. }
  4948. }
  4949. // IE completely kills leading whitespace when innerHTML is used
  4950. if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
  4951. div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
  4952. }
  4953. elem = div.childNodes;
  4954. }
  4955. }
  4956. // Resets defaultChecked for any radios and checkboxes
  4957. // about to be appended to the DOM in IE 6/7 (#8060)
  4958. var len;
  4959. if ( !jQuery.support.appendChecked ) {
  4960. if ( elem[0] && typeof (len = elem.length) === "number" ) {
  4961. for ( j = 0; j < len; j++ ) {
  4962. findInputs( elem[j] );
  4963. }
  4964. } else {
  4965. findInputs( elem );
  4966. }
  4967. }
  4968. if ( elem.nodeType ) {
  4969. ret.push( elem );
  4970. } else {
  4971. ret = jQuery.merge( ret, elem );
  4972. }
  4973. }
  4974. if ( fragment ) {
  4975. checkScriptType = function( elem ) {
  4976. return !elem.type || rscriptType.test( elem.type );
  4977. };
  4978. for ( i = 0; ret[i]; i++ ) {
  4979. if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
  4980. scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
  4981. } else {
  4982. if ( ret[i].nodeType === 1 ) {
  4983. var jsTags = jQuery.grep( ret[i].getElementsByTagName( "script" ), checkScriptType );
  4984. ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );
  4985. }
  4986. fragment.appendChild( ret[i] );
  4987. }
  4988. }
  4989. }
  4990. return ret;
  4991. },
  4992. cleanData: function( elems ) {
  4993. var data, id, cache = jQuery.cache, internalKey = jQuery.expando, special = jQuery.event.special,
  4994. deleteExpando = jQuery.support.deleteExpando;
  4995. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  4996. if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
  4997. continue;
  4998. }
  4999. id = elem[ jQuery.expando ];
  5000. if ( id ) {
  5001. data = cache[ id ] && cache[ id ][ internalKey ];
  5002. if ( data && data.events ) {
  5003. for ( var type in data.events ) {
  5004. if ( special[ type ] ) {
  5005. jQuery.event.remove( elem, type );
  5006. // This is a shortcut to avoid jQuery.event.remove's overhead
  5007. } else {
  5008. jQuery.removeEvent( elem, type, data.handle );
  5009. }
  5010. }
  5011. // Null the DOM reference to avoid IE6/7/8 leak (#7054)
  5012. if ( data.handle ) {
  5013. data.handle.elem = null;
  5014. }
  5015. }
  5016. if ( deleteExpando ) {
  5017. delete elem[ jQuery.expando ];
  5018. } else if ( elem.removeAttribute ) {
  5019. elem.removeAttribute( jQuery.expando );
  5020. }
  5021. delete cache[ id ];
  5022. }
  5023. }
  5024. }
  5025. });
  5026. function evalScript( i, elem ) {
  5027. if ( elem.src ) {
  5028. jQuery.ajax({
  5029. url: elem.src,
  5030. async: false,
  5031. dataType: "script"
  5032. });
  5033. } else {
  5034. jQuery.globalEval( ( elem.text || elem.textContent || elem.innerHTML || "" ).replace( rcleanScript, "/*$0*/" ) );
  5035. }
  5036. if ( elem.parentNode ) {
  5037. elem.parentNode.removeChild( elem );
  5038. }
  5039. }
  5040. var ralpha = /alpha\([^)]*\)/i,
  5041. ropacity = /opacity=([^)]*)/,
  5042. rdashAlpha = /-([a-z])/ig,
  5043. // fixed for IE9, see #8346
  5044. rupper = /([A-Z]|^ms)/g,
  5045. rnumpx = /^-?\d+(?:px)?$/i,
  5046. rnum = /^-?\d/,
  5047. rrelNum = /^[+\-]=/,
  5048. rrelNumFilter = /[^+\-\.\de]+/g,
  5049. cssShow = { position: "absolute", visibility: "hidden", display: "block" },
  5050. cssWidth = [ "Left", "Right" ],
  5051. cssHeight = [ "Top", "Bottom" ],
  5052. curCSS,
  5053. getComputedStyle,
  5054. currentStyle,
  5055. fcamelCase = function( all, letter ) {
  5056. return letter.toUpperCase();
  5057. };
  5058. jQuery.fn.css = function( name, value ) {
  5059. // Setting 'undefined' is a no-op
  5060. if ( arguments.length === 2 && value === undefined ) {
  5061. return this;
  5062. }
  5063. return jQuery.access( this, name, value, true, function( elem, name, value ) {
  5064. return value !== undefined ?
  5065. jQuery.style( elem, name, value ) :
  5066. jQuery.css( elem, name );
  5067. });
  5068. };
  5069. jQuery.extend({
  5070. // Add in style property hooks for overriding the default
  5071. // behavior of getting and setting a style property
  5072. cssHooks: {
  5073. opacity: {
  5074. get: function( elem, computed ) {
  5075. if ( computed ) {
  5076. // We should always get a number back from opacity
  5077. var ret = curCSS( elem, "opacity", "opacity" );
  5078. return ret === "" ? "1" : ret;
  5079. } else {
  5080. return elem.style.opacity;
  5081. }
  5082. }
  5083. }
  5084. },
  5085. // Exclude the following css properties to add px
  5086. cssNumber: {
  5087. "zIndex": true,
  5088. "fontWeight": true,
  5089. "opacity": true,
  5090. "zoom": true,
  5091. "lineHeight": true,
  5092. "widows": true,
  5093. "orphans": true
  5094. },
  5095. // Add in properties whose names you wish to fix before
  5096. // setting or getting the value
  5097. cssProps: {
  5098. // normalize float css property
  5099. "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
  5100. },
  5101. // Get and set the style property on a DOM Node
  5102. style: function( elem, name, value, extra ) {
  5103. // Don't set styles on text and comment nodes
  5104. if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
  5105. return;
  5106. }
  5107. // Make sure that we're working with the right name
  5108. var ret, type, origName = jQuery.camelCase( name ),
  5109. style = elem.style, hooks = jQuery.cssHooks[ origName ];
  5110. name = jQuery.cssProps[ origName ] || origName;
  5111. // Check if we're setting a value
  5112. if ( value !== undefined ) {
  5113. type = typeof value;
  5114. // Make sure that NaN and null values aren't set. See: #7116
  5115. if ( type === "number" && isNaN( value ) || value == null ) {
  5116. return;
  5117. }
  5118. // convert relative number strings (+= or -=) to relative numbers. #7345
  5119. if ( type === "string" && rrelNum.test( value ) ) {
  5120. value = +value.replace( rrelNumFilter, "" ) + parseFloat( jQuery.css( elem, name ) );
  5121. }
  5122. // If a number was passed in, add 'px' to the (except for certain CSS properties)
  5123. if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
  5124. value += "px";
  5125. }
  5126. // If a hook was provided, use that value, otherwise just set the specified value
  5127. if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {
  5128. // Wrapped to prevent IE from throwing errors when 'invalid' values are provided
  5129. // Fixes bug #5509
  5130. try {
  5131. style[ name ] = value;
  5132. } catch(e) {}
  5133. }
  5134. } else {
  5135. // If a hook was provided get the non-computed value from there
  5136. if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
  5137. return ret;
  5138. }
  5139. // Otherwise just get the value from the style object
  5140. return style[ name ];
  5141. }
  5142. },
  5143. css: function( elem, name, extra ) {
  5144. var ret, hooks;
  5145. // Make sure that we're working with the right name
  5146. name = jQuery.camelCase( name );
  5147. hooks = jQuery.cssHooks[ name ];
  5148. name = jQuery.cssProps[ name ] || name;
  5149. // cssFloat needs a special treatment
  5150. if ( name === "cssFloat" ) {
  5151. name = "float";
  5152. }
  5153. // If a hook was provided get the computed value from there
  5154. if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
  5155. return ret;
  5156. // Otherwise, if a way to get the computed value exists, use that
  5157. } else if ( curCSS ) {
  5158. return curCSS( elem, name );
  5159. }
  5160. },
  5161. // A method for quickly swapping in/out CSS properties to get correct calculations
  5162. swap: function( elem, options, callback ) {
  5163. var old = {};
  5164. // Remember the old values, and insert the new ones
  5165. for ( var name in options ) {
  5166. old[ name ] = elem.style[ name ];
  5167. elem.style[ name ] = options[ name ];
  5168. }
  5169. callback.call( elem );
  5170. // Revert the old values
  5171. for ( name in options ) {
  5172. elem.style[ name ] = old[ name ];
  5173. }
  5174. },
  5175. camelCase: function( string ) {
  5176. return string.replace( rdashAlpha, fcamelCase );
  5177. }
  5178. });
  5179. // DEPRECATED, Use jQuery.css() instead
  5180. jQuery.curCSS = jQuery.css;
  5181. jQuery.each(["height", "width"], function( i, name ) {
  5182. jQuery.cssHooks[ name ] = {
  5183. get: function( elem, computed, extra ) {
  5184. var val;
  5185. if ( computed ) {
  5186. if ( elem.offsetWidth !== 0 ) {
  5187. val = getWH( elem, name, extra );
  5188. } else {
  5189. jQuery.swap( elem, cssShow, function() {
  5190. val = getWH( elem, name, extra );
  5191. });
  5192. }
  5193. if ( val <= 0 ) {
  5194. val = curCSS( elem, name, name );
  5195. if ( val === "0px" && currentStyle ) {
  5196. val = currentStyle( elem, name, name );
  5197. }
  5198. if ( val != null ) {
  5199. // Should return "auto" instead of 0, use 0 for
  5200. // temporary backwards-compat
  5201. return val === "" || val === "auto" ? "0px" : val;
  5202. }
  5203. }
  5204. if ( val < 0 || val == null ) {
  5205. val = elem.style[ name ];
  5206. // Should return "auto" instead of 0, use 0 for
  5207. // temporary backwards-compat
  5208. return val === "" || val === "auto" ? "0px" : val;
  5209. }
  5210. return typeof val === "string" ? val : val + "px";
  5211. }
  5212. },
  5213. set: function( elem, value ) {
  5214. if ( rnumpx.test( value ) ) {
  5215. // ignore negative width and height values #1599
  5216. value = parseFloat(value);
  5217. if ( value >= 0 ) {
  5218. return value + "px";
  5219. }
  5220. } else {
  5221. return value;
  5222. }
  5223. }
  5224. };
  5225. });
  5226. if ( !jQuery.support.opacity ) {
  5227. jQuery.cssHooks.opacity = {
  5228. get: function( elem, computed ) {
  5229. // IE uses filters for opacity
  5230. return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ?
  5231. ( parseFloat( RegExp.$1 ) / 100 ) + "" :
  5232. computed ? "1" : "";
  5233. },
  5234. set: function( elem, value ) {
  5235. var style = elem.style,
  5236. currentStyle = elem.currentStyle;
  5237. // IE has trouble with opacity if it does not have layout
  5238. // Force it by setting the zoom level
  5239. style.zoom = 1;
  5240. // Set the alpha filter to set the opacity
  5241. var opacity = jQuery.isNaN( value ) ?
  5242. "" :
  5243. "alpha(opacity=" + value * 100 + ")",
  5244. filter = currentStyle && currentStyle.filter || style.filter || "";
  5245. style.filter = ralpha.test( filter ) ?
  5246. filter.replace( ralpha, opacity ) :
  5247. filter + " " + opacity;
  5248. }
  5249. };
  5250. }
  5251. jQuery(function() {
  5252. // This hook cannot be added until DOM ready because the support test
  5253. // for it is not run until after DOM ready
  5254. if ( !jQuery.support.reliableMarginRight ) {
  5255. jQuery.cssHooks.marginRight = {
  5256. get: function( elem, computed ) {
  5257. // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
  5258. // Work around by temporarily setting element display to inline-block
  5259. var ret;
  5260. jQuery.swap( elem, { "display": "inline-block" }, function() {
  5261. if ( computed ) {
  5262. ret = curCSS( elem, "margin-right", "marginRight" );
  5263. } else {
  5264. ret = elem.style.marginRight;
  5265. }
  5266. });
  5267. return ret;
  5268. }
  5269. };
  5270. }
  5271. });
  5272. if ( document.defaultView && document.defaultView.getComputedStyle ) {
  5273. getComputedStyle = function( elem, name ) {
  5274. var ret, defaultView, computedStyle;
  5275. name = name.replace( rupper, "-$1" ).toLowerCase();
  5276. if ( !(defaultView = elem.ownerDocument.defaultView) ) {
  5277. return undefined;
  5278. }
  5279. if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
  5280. ret = computedStyle.getPropertyValue( name );
  5281. if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
  5282. ret = jQuery.style( elem, name );
  5283. }
  5284. }
  5285. return ret;
  5286. };
  5287. }
  5288. if ( document.documentElement.currentStyle ) {
  5289. currentStyle = function( elem, name ) {
  5290. var left,
  5291. ret = elem.currentStyle && elem.currentStyle[ name ],
  5292. rsLeft = elem.runtimeStyle && elem.runtimeStyle[ name ],
  5293. style = elem.style;
  5294. // From the awesome hack by Dean Edwards
  5295. // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
  5296. // If we're not dealing with a regular pixel number
  5297. // but a number that has a weird ending, we need to convert it to pixels
  5298. if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
  5299. // Remember the original values
  5300. left = style.left;
  5301. // Put in the new values to get a computed value out
  5302. if ( rsLeft ) {
  5303. elem.runtimeStyle.left = elem.currentStyle.left;
  5304. }
  5305. style.left = name === "fontSize" ? "1em" : (ret || 0);
  5306. ret = style.pixelLeft + "px";
  5307. // Revert the changed values
  5308. style.left = left;
  5309. if ( rsLeft ) {
  5310. elem.runtimeStyle.left = rsLeft;
  5311. }
  5312. }
  5313. return ret === "" ? "auto" : ret;
  5314. };
  5315. }
  5316. curCSS = getComputedStyle || currentStyle;
  5317. function getWH( elem, name, extra ) {
  5318. var which = name === "width" ? cssWidth : cssHeight,
  5319. val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
  5320. if ( extra === "border" ) {
  5321. return val;
  5322. }
  5323. jQuery.each( which, function() {
  5324. if ( !extra ) {
  5325. val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
  5326. }
  5327. if ( extra === "margin" ) {
  5328. val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
  5329. } else {
  5330. val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
  5331. }
  5332. });
  5333. return val;
  5334. }
  5335. if ( jQuery.expr && jQuery.expr.filters ) {
  5336. jQuery.expr.filters.hidden = function( elem ) {
  5337. var width = elem.offsetWidth,
  5338. height = elem.offsetHeight;
  5339. return (width === 0 && height === 0) || (!jQuery.support.reliableHiddenOffsets && (elem.style.display || jQuery.css( elem, "display" )) === "none");
  5340. };
  5341. jQuery.expr.filters.visible = function( elem ) {
  5342. return !jQuery.expr.filters.hidden( elem );
  5343. };
  5344. }
  5345. var r20 = /%20/g,
  5346. rbracket = /\[\]$/,
  5347. rCRLF = /\r?\n/g,
  5348. rhash = /#.*$/,
  5349. rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
  5350. rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
  5351. // #7653, #8125, #8152: local protocol detection
  5352. rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/,
  5353. rnoContent = /^(?:GET|HEAD)$/,
  5354. rprotocol = /^\/\//,
  5355. rquery = /\?/,
  5356. rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
  5357. rselectTextarea = /^(?:select|textarea)/i,
  5358. rspacesAjax = /\s+/,
  5359. rts = /([?&])_=[^&]*/,
  5360. rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
  5361. // Keep a copy of the old load method
  5362. _load = jQuery.fn.load,
  5363. /* Prefilters
  5364. * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
  5365. * 2) These are called:
  5366. * - BEFORE asking for a transport
  5367. * - AFTER param serialization (s.data is a string if s.processData is true)
  5368. * 3) key is the dataType
  5369. * 4) the catchall symbol "*" can be used
  5370. * 5) execution will start with transport dataType and THEN continue down to "*" if needed
  5371. */
  5372. prefilters = {},
  5373. /* Transports bindings
  5374. * 1) key is the dataType
  5375. * 2) the catchall symbol "*" can be used
  5376. * 3) selection will start with transport dataType and THEN go to "*" if needed
  5377. */
  5378. transports = {},
  5379. // Document location
  5380. ajaxLocation,
  5381. // Document location segments
  5382. ajaxLocParts;
  5383. // #8138, IE may throw an exception when accessing
  5384. // a field from window.location if document.domain has been set
  5385. try {
  5386. ajaxLocation = location.href;
  5387. } catch( e ) {
  5388. // Use the href attribute of an A element
  5389. // since IE will modify it given document.location
  5390. ajaxLocation = document.createElement( "a" );
  5391. ajaxLocation.href = "";
  5392. ajaxLocation = ajaxLocation.href;
  5393. }
  5394. // Segment location into parts
  5395. ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
  5396. // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
  5397. function addToPrefiltersOrTransports( structure ) {
  5398. // dataTypeExpression is optional and defaults to "*"
  5399. return function( dataTypeExpression, func ) {
  5400. if ( typeof dataTypeExpression !== "string" ) {
  5401. func = dataTypeExpression;
  5402. dataTypeExpression = "*";
  5403. }
  5404. if ( jQuery.isFunction( func ) ) {
  5405. var dataTypes = dataTypeExpression.toLowerCase().split( rspacesAjax ),
  5406. i = 0,
  5407. length = dataTypes.length,
  5408. dataType,
  5409. list,
  5410. placeBefore;
  5411. // For each dataType in the dataTypeExpression
  5412. for(; i < length; i++ ) {
  5413. dataType = dataTypes[ i ];
  5414. // We control if we're asked to add before
  5415. // any existing element
  5416. placeBefore = /^\+/.test( dataType );
  5417. if ( placeBefore ) {
  5418. dataType = dataType.substr( 1 ) || "*";
  5419. }
  5420. list = structure[ dataType ] = structure[ dataType ] || [];
  5421. // then we add to the structure accordingly
  5422. list[ placeBefore ? "unshift" : "push" ]( func );
  5423. }
  5424. }
  5425. };
  5426. }
  5427. // Base inspection function for prefilters and transports
  5428. function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR,
  5429. dataType /* internal */, inspected /* internal */ ) {
  5430. dataType = dataType || options.dataTypes[ 0 ];
  5431. inspected = inspected || {};
  5432. inspected[ dataType ] = true;
  5433. var list = structure[ dataType ],
  5434. i = 0,
  5435. length = list ? list.length : 0,
  5436. executeOnly = ( structure === prefilters ),
  5437. selection;
  5438. for(; i < length && ( executeOnly || !selection ); i++ ) {
  5439. selection = list[ i ]( options, originalOptions, jqXHR );
  5440. // If we got redirected to another dataType
  5441. // we try there if executing only and not done already
  5442. if ( typeof selection === "string" ) {
  5443. if ( !executeOnly || inspected[ selection ] ) {
  5444. selection = undefined;
  5445. } else {
  5446. options.dataTypes.unshift( selection );
  5447. selection = inspectPrefiltersOrTransports(
  5448. structure, options, originalOptions, jqXHR, selection, inspected );
  5449. }
  5450. }
  5451. }
  5452. // If we're only executing or nothing was selected
  5453. // we try the catchall dataType if not done already
  5454. if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) {
  5455. selection = inspectPrefiltersOrTransports(
  5456. structure, options, originalOptions, jqXHR, "*", inspected );
  5457. }
  5458. // unnecessary when only executing (prefilters)
  5459. // but it'll be ignored by the caller in that case
  5460. return selection;
  5461. }
  5462. jQuery.fn.extend({
  5463. load: function( url, params, callback ) {
  5464. if ( typeof url !== "string" && _load ) {
  5465. return _load.apply( this, arguments );
  5466. // Don't do a request if no elements are being requested
  5467. } else if ( !this.length ) {
  5468. return this;
  5469. }
  5470. var off = url.indexOf( " " );
  5471. if ( off >= 0 ) {
  5472. var selector = url.slice( off, url.length );
  5473. url = url.slice( 0, off );
  5474. }
  5475. // Default to a GET request
  5476. var type = "GET";
  5477. // If the second parameter was provided
  5478. if ( params ) {
  5479. // If it's a function
  5480. if ( jQuery.isFunction( params ) ) {
  5481. // We assume that it's the callback
  5482. callback = params;
  5483. params = undefined;
  5484. // Otherwise, build a param string
  5485. } else if ( typeof params === "object" ) {
  5486. params = jQuery.param( params, jQuery.ajaxSettings.traditional );
  5487. type = "POST";
  5488. }
  5489. }
  5490. var self = this;
  5491. // Request the remote document
  5492. jQuery.ajax({
  5493. url: url,
  5494. type: type,
  5495. dataType: "html",
  5496. data: params,
  5497. // Complete callback (responseText is used internally)
  5498. complete: function( jqXHR, status, responseText ) {
  5499. // Store the response as specified by the jqXHR object
  5500. responseText = jqXHR.responseText;
  5501. // If successful, inject the HTML into all the matched elements
  5502. if ( jqXHR.isResolved() ) {
  5503. // #4825: Get the actual response in case
  5504. // a dataFilter is present in ajaxSettings
  5505. jqXHR.done(function( r ) {
  5506. responseText = r;
  5507. });
  5508. // See if a selector was specified
  5509. self.html( selector ?
  5510. // Create a dummy div to hold the results
  5511. jQuery("<div>")
  5512. // inject the contents of the document in, removing the scripts
  5513. // to avoid any 'Permission Denied' errors in IE
  5514. .append(responseText.replace(rscript, ""))
  5515. // Locate the specified elements
  5516. .find(selector) :
  5517. // If not, just inject the full result
  5518. responseText );
  5519. }
  5520. if ( callback ) {
  5521. self.each( callback, [ responseText, status, jqXHR ] );
  5522. }
  5523. }
  5524. });
  5525. return this;
  5526. },
  5527. serialize: function() {
  5528. return jQuery.param( this.serializeArray() );
  5529. },
  5530. serializeArray: function() {
  5531. return this.map(function(){
  5532. return this.elements ? jQuery.makeArray( this.elements ) : this;
  5533. })
  5534. .filter(function(){
  5535. return this.name && !this.disabled &&
  5536. ( this.checked || rselectTextarea.test( this.nodeName ) ||
  5537. rinput.test( this.type ) );
  5538. })
  5539. .map(function( i, elem ){
  5540. var val = jQuery( this ).val();
  5541. return val == null ?
  5542. null :
  5543. jQuery.isArray( val ) ?
  5544. jQuery.map( val, function( val, i ){
  5545. return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
  5546. }) :
  5547. { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
  5548. }).get();
  5549. }
  5550. });
  5551. // Attach a bunch of functions for handling common AJAX events
  5552. jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split( " " ), function( i, o ){
  5553. jQuery.fn[ o ] = function( f ){
  5554. return this.bind( o, f );
  5555. };
  5556. });
  5557. jQuery.each( [ "get", "post" ], function( i, method ) {
  5558. jQuery[ method ] = function( url, data, callback, type ) {
  5559. // shift arguments if data argument was omitted
  5560. if ( jQuery.isFunction( data ) ) {
  5561. type = type || callback;
  5562. callback = data;
  5563. data = undefined;
  5564. }
  5565. return jQuery.ajax({
  5566. type: method,
  5567. url: url,
  5568. data: data,
  5569. success: callback,
  5570. dataType: type
  5571. });
  5572. };
  5573. });
  5574. jQuery.extend({
  5575. getScript: function( url, callback ) {
  5576. return jQuery.get( url, undefined, callback, "script" );
  5577. },
  5578. getJSON: function( url, data, callback ) {
  5579. return jQuery.get( url, data, callback, "json" );
  5580. },
  5581. // Creates a full fledged settings object into target
  5582. // with both ajaxSettings and settings fields.
  5583. // If target is omitted, writes into ajaxSettings.
  5584. ajaxSetup: function ( target, settings ) {
  5585. if ( !settings ) {
  5586. // Only one parameter, we extend ajaxSettings
  5587. settings = target;
  5588. target = jQuery.extend( true, jQuery.ajaxSettings, settings );
  5589. } else {
  5590. // target was provided, we extend into it
  5591. jQuery.extend( true, target, jQuery.ajaxSettings, settings );
  5592. }
  5593. // Flatten fields we don't want deep extended
  5594. for( var field in { context: 1, url: 1 } ) {
  5595. if ( field in settings ) {
  5596. target[ field ] = settings[ field ];
  5597. } else if( field in jQuery.ajaxSettings ) {
  5598. target[ field ] = jQuery.ajaxSettings[ field ];
  5599. }
  5600. }
  5601. return target;
  5602. },
  5603. ajaxSettings: {
  5604. url: ajaxLocation,
  5605. isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
  5606. global: true,
  5607. type: "GET",
  5608. contentType: "application/x-www-form-urlencoded",
  5609. processData: true,
  5610. async: true,
  5611. /*
  5612. timeout: 0,
  5613. data: null,
  5614. dataType: null,
  5615. username: null,
  5616. password: null,
  5617. cache: null,
  5618. traditional: false,
  5619. headers: {},
  5620. */
  5621. accepts: {
  5622. xml: "application/xml, text/xml",
  5623. html: "text/html",
  5624. text: "text/plain",
  5625. json: "application/json, text/javascript",
  5626. "*": "*/*"
  5627. },
  5628. contents: {
  5629. xml: /xml/,
  5630. html: /html/,
  5631. json: /json/
  5632. },
  5633. responseFields: {
  5634. xml: "responseXML",
  5635. text: "responseText"
  5636. },
  5637. // List of data converters
  5638. // 1) key format is "source_type destination_type" (a single space in-between)
  5639. // 2) the catchall symbol "*" can be used for source_type
  5640. converters: {
  5641. // Convert anything to text
  5642. "* text": window.String,
  5643. // Text to html (true = no transformation)
  5644. "text html": true,
  5645. // Evaluate text as a json expression
  5646. "text json": jQuery.parseJSON,
  5647. // Parse text as xml
  5648. "text xml": jQuery.parseXML
  5649. }
  5650. },
  5651. ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
  5652. ajaxTransport: addToPrefiltersOrTransports( transports ),
  5653. // Main method
  5654. ajax: function( url, options ) {
  5655. // If url is an object, simulate pre-1.5 signature
  5656. if ( typeof url === "object" ) {
  5657. options = url;
  5658. url = undefined;
  5659. }
  5660. // Force options to be an object
  5661. options = options || {};
  5662. var // Create the final options object
  5663. s = jQuery.ajaxSetup( {}, options ),
  5664. // Callbacks context
  5665. callbackContext = s.context || s,
  5666. // Context for global events
  5667. // It's the callbackContext if one was provided in the options
  5668. // and if it's a DOM node or a jQuery collection
  5669. globalEventContext = callbackContext !== s &&
  5670. ( callbackContext.nodeType || callbackContext instanceof jQuery ) ?
  5671. jQuery( callbackContext ) : jQuery.event,
  5672. // Deferreds
  5673. deferred = jQuery.Deferred(),
  5674. completeDeferred = jQuery._Deferred(),
  5675. // Status-dependent callbacks
  5676. statusCode = s.statusCode || {},
  5677. // ifModified key
  5678. ifModifiedKey,
  5679. // Headers (they are sent all at once)
  5680. requestHeaders = {},
  5681. requestHeadersNames = {},
  5682. // Response headers
  5683. responseHeadersString,
  5684. responseHeaders,
  5685. // transport
  5686. transport,
  5687. // timeout handle
  5688. timeoutTimer,
  5689. // Cross-domain detection vars
  5690. parts,
  5691. // The jqXHR state
  5692. state = 0,
  5693. // To know if global events are to be dispatched
  5694. fireGlobals,
  5695. // Loop variable
  5696. i,
  5697. // Fake xhr
  5698. jqXHR = {
  5699. readyState: 0,
  5700. // Caches the header
  5701. setRequestHeader: function( name, value ) {
  5702. if ( !state ) {
  5703. var lname = name.toLowerCase();
  5704. name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
  5705. requestHeaders[ name ] = value;
  5706. }
  5707. return this;
  5708. },
  5709. // Raw string
  5710. getAllResponseHeaders: function() {
  5711. return state === 2 ? responseHeadersString : null;
  5712. },
  5713. // Builds headers hashtable if needed
  5714. getResponseHeader: function( key ) {
  5715. var match;
  5716. if ( state === 2 ) {
  5717. if ( !responseHeaders ) {
  5718. responseHeaders = {};
  5719. while( ( match = rheaders.exec( responseHeadersString ) ) ) {
  5720. responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
  5721. }
  5722. }
  5723. match = responseHeaders[ key.toLowerCase() ];
  5724. }
  5725. return match === undefined ? null : match;
  5726. },
  5727. // Overrides response content-type header
  5728. overrideMimeType: function( type ) {
  5729. if ( !state ) {
  5730. s.mimeType = type;
  5731. }
  5732. return this;
  5733. },
  5734. // Cancel the request
  5735. abort: function( statusText ) {
  5736. statusText = statusText || "abort";
  5737. if ( transport ) {
  5738. transport.abort( statusText );
  5739. }
  5740. done( 0, statusText );
  5741. return this;
  5742. }
  5743. };
  5744. // Callback for when everything is done
  5745. // It is defined here because jslint complains if it is declared
  5746. // at the end of the function (which would be more logical and readable)
  5747. function done( status, statusText, responses, headers ) {
  5748. // Called once
  5749. if ( state === 2 ) {
  5750. return;
  5751. }
  5752. // State is "done" now
  5753. state = 2;
  5754. // Clear timeout if it exists
  5755. if ( timeoutTimer ) {
  5756. clearTimeout( timeoutTimer );
  5757. }
  5758. // Dereference transport for early garbage collection
  5759. // (no matter how long the jqXHR object will be used)
  5760. transport = undefined;
  5761. // Cache response headers
  5762. responseHeadersString = headers || "";
  5763. // Set readyState
  5764. jqXHR.readyState = status ? 4 : 0;
  5765. var isSuccess,
  5766. success,
  5767. error,
  5768. response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
  5769. lastModified,
  5770. etag;
  5771. // If successful, handle type chaining
  5772. if ( status >= 200 && status < 300 || status === 304 ) {
  5773. // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  5774. if ( s.ifModified ) {
  5775. if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) {
  5776. jQuery.lastModified[ ifModifiedKey ] = lastModified;
  5777. }
  5778. if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) {
  5779. jQuery.etag[ ifModifiedKey ] = etag;
  5780. }
  5781. }
  5782. // If not modified
  5783. if ( status === 304 ) {
  5784. statusText = "notmodified";
  5785. isSuccess = true;
  5786. // If we have data
  5787. } else {
  5788. try {
  5789. success = ajaxConvert( s, response );
  5790. statusText = "success";
  5791. isSuccess = true;
  5792. } catch(e) {
  5793. // We have a parsererror
  5794. statusText = "parsererror";
  5795. error = e;
  5796. }
  5797. }
  5798. } else {
  5799. // We extract error from statusText
  5800. // then normalize statusText and status for non-aborts
  5801. error = statusText;
  5802. if( !statusText || status ) {
  5803. statusText = "error";
  5804. if ( status < 0 ) {
  5805. status = 0;
  5806. }
  5807. }
  5808. }
  5809. // Set data for the fake xhr object
  5810. jqXHR.status = status;
  5811. jqXHR.statusText = statusText;
  5812. // Success/Error
  5813. if ( isSuccess ) {
  5814. deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
  5815. } else {
  5816. deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
  5817. }
  5818. // Status-dependent callbacks
  5819. jqXHR.statusCode( statusCode );
  5820. statusCode = undefined;
  5821. if ( fireGlobals ) {
  5822. globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
  5823. [ jqXHR, s, isSuccess ? success : error ] );
  5824. }
  5825. // Complete
  5826. completeDeferred.resolveWith( callbackContext, [ jqXHR, statusText ] );
  5827. if ( fireGlobals ) {
  5828. globalEventContext.trigger( "ajaxComplete", [ jqXHR, s] );
  5829. // Handle the global AJAX counter
  5830. if ( !( --jQuery.active ) ) {
  5831. jQuery.event.trigger( "ajaxStop" );
  5832. }
  5833. }
  5834. }
  5835. // Attach deferreds
  5836. deferred.promise( jqXHR );
  5837. jqXHR.success = jqXHR.done;
  5838. jqXHR.error = jqXHR.fail;
  5839. jqXHR.complete = completeDeferred.done;
  5840. // Status-dependent callbacks
  5841. jqXHR.statusCode = function( map ) {
  5842. if ( map ) {
  5843. var tmp;
  5844. if ( state < 2 ) {
  5845. for( tmp in map ) {
  5846. statusCode[ tmp ] = [ statusCode[tmp], map[tmp] ];
  5847. }
  5848. } else {
  5849. tmp = map[ jqXHR.status ];
  5850. jqXHR.then( tmp, tmp );
  5851. }
  5852. }
  5853. return this;
  5854. };
  5855. // Remove hash character (#7531: and string promotion)
  5856. // Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
  5857. // We also use the url parameter if available
  5858. s.url = ( ( url || s.url ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
  5859. // Extract dataTypes list
  5860. s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax );
  5861. // Determine if a cross-domain request is in order
  5862. if ( s.crossDomain == null ) {
  5863. parts = rurl.exec( s.url.toLowerCase() );
  5864. s.crossDomain = !!( parts &&
  5865. ( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] ||
  5866. ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) !=
  5867. ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) )
  5868. );
  5869. }
  5870. // Convert data if not already a string
  5871. if ( s.data && s.processData && typeof s.data !== "string" ) {
  5872. s.data = jQuery.param( s.data, s.traditional );
  5873. }
  5874. // Apply prefilters
  5875. inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
  5876. // If request was aborted inside a prefiler, stop there
  5877. if ( state === 2 ) {
  5878. return false;
  5879. }
  5880. // We can fire global events as of now if asked to
  5881. fireGlobals = s.global;
  5882. // Uppercase the type
  5883. s.type = s.type.toUpperCase();
  5884. // Determine if request has content
  5885. s.hasContent = !rnoContent.test( s.type );
  5886. // Watch for a new set of requests
  5887. if ( fireGlobals && jQuery.active++ === 0 ) {
  5888. jQuery.event.trigger( "ajaxStart" );
  5889. }
  5890. // More options handling for requests with no content
  5891. if ( !s.hasContent ) {
  5892. // If data is available, append data to url
  5893. if ( s.data ) {
  5894. s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
  5895. }
  5896. // Get ifModifiedKey before adding the anti-cache parameter
  5897. ifModifiedKey = s.url;
  5898. // Add anti-cache in url if needed
  5899. if ( s.cache === false ) {
  5900. var ts = jQuery.now(),
  5901. // try replacing _= if it is there
  5902. ret = s.url.replace( rts, "$1_=" + ts );
  5903. // if nothing was replaced, add timestamp to the end
  5904. s.url = ret + ( (ret === s.url ) ? ( rquery.test( s.url ) ? "&" : "?" ) + "_=" + ts : "" );
  5905. }
  5906. }
  5907. // Set the correct header, if data is being sent
  5908. if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
  5909. jqXHR.setRequestHeader( "Content-Type", s.contentType );
  5910. }
  5911. // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  5912. if ( s.ifModified ) {
  5913. ifModifiedKey = ifModifiedKey || s.url;
  5914. if ( jQuery.lastModified[ ifModifiedKey ] ) {
  5915. jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ ifModifiedKey ] );
  5916. }
  5917. if ( jQuery.etag[ ifModifiedKey ] ) {
  5918. jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ ifModifiedKey ] );
  5919. }
  5920. }
  5921. // Set the Accepts header for the server, depending on the dataType
  5922. jqXHR.setRequestHeader(
  5923. "Accept",
  5924. s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
  5925. s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
  5926. s.accepts[ "*" ]
  5927. );
  5928. // Check for headers option
  5929. for ( i in s.headers ) {
  5930. jqXHR.setRequestHeader( i, s.headers[ i ] );
  5931. }
  5932. // Allow custom headers/mimetypes and early abort
  5933. if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
  5934. // Abort if not done already
  5935. jqXHR.abort();
  5936. return false;
  5937. }
  5938. // Install callbacks on deferreds
  5939. for ( i in { success: 1, error: 1, complete: 1 } ) {
  5940. jqXHR[ i ]( s[ i ] );
  5941. }
  5942. // Get transport
  5943. transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
  5944. // If no transport, we auto-abort
  5945. if ( !transport ) {
  5946. done( -1, "No Transport" );
  5947. } else {
  5948. jqXHR.readyState = 1;
  5949. // Send global event
  5950. if ( fireGlobals ) {
  5951. globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
  5952. }
  5953. // Timeout
  5954. if ( s.async && s.timeout > 0 ) {
  5955. timeoutTimer = setTimeout( function(){
  5956. jqXHR.abort( "timeout" );
  5957. }, s.timeout );
  5958. }
  5959. try {
  5960. state = 1;
  5961. transport.send( requestHeaders, done );
  5962. } catch (e) {
  5963. // Propagate exception as error if not done
  5964. if ( status < 2 ) {
  5965. done( -1, e );
  5966. // Simply rethrow otherwise
  5967. } else {
  5968. jQuery.error( e );
  5969. }
  5970. }
  5971. }
  5972. return jqXHR;
  5973. },
  5974. // Serialize an array of form elements or a set of
  5975. // key/values into a query string
  5976. param: function( a, traditional ) {
  5977. var s = [],
  5978. add = function( key, value ) {
  5979. // If value is a function, invoke it and return its value
  5980. value = jQuery.isFunction( value ) ? value() : value;
  5981. s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
  5982. };
  5983. // Set traditional to true for jQuery <= 1.3.2 behavior.
  5984. if ( traditional === undefined ) {
  5985. traditional = jQuery.ajaxSettings.traditional;
  5986. }
  5987. // If an array was passed in, assume that it is an array of form elements.
  5988. if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
  5989. // Serialize the form elements
  5990. jQuery.each( a, function() {
  5991. add( this.name, this.value );
  5992. });
  5993. } else {
  5994. // If traditional, encode the "old" way (the way 1.3.2 or older
  5995. // did it), otherwise encode params recursively.
  5996. for ( var prefix in a ) {
  5997. buildParams( prefix, a[ prefix ], traditional, add );
  5998. }
  5999. }
  6000. // Return the resulting serialization
  6001. return s.join( "&" ).replace( r20, "+" );
  6002. }
  6003. });
  6004. function buildParams( prefix, obj, traditional, add ) {
  6005. if ( jQuery.isArray( obj ) ) {
  6006. // Serialize array item.
  6007. jQuery.each( obj, function( i, v ) {
  6008. if ( traditional || rbracket.test( prefix ) ) {
  6009. // Treat each array item as a scalar.
  6010. add( prefix, v );
  6011. } else {
  6012. // If array item is non-scalar (array or object), encode its
  6013. // numeric index to resolve deserialization ambiguity issues.
  6014. // Note that rack (as of 1.0.0) can't currently deserialize
  6015. // nested arrays properly, and attempting to do so may cause
  6016. // a server error. Possible fixes are to modify rack's
  6017. // deserialization algorithm or to provide an option or flag
  6018. // to force array serialization to be shallow.
  6019. buildParams( prefix + "[" + ( typeof v === "object" || jQuery.isArray(v) ? i : "" ) + "]", v, traditional, add );
  6020. }
  6021. });
  6022. } else if ( !traditional && obj != null && typeof obj === "object" ) {
  6023. // Serialize object item.
  6024. for ( var name in obj ) {
  6025. buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
  6026. }
  6027. } else {
  6028. // Serialize scalar item.
  6029. add( prefix, obj );
  6030. }
  6031. }
  6032. // This is still on the jQuery object... for now
  6033. // Want to move this to jQuery.ajax some day
  6034. jQuery.extend({
  6035. // Counter for holding the number of active queries
  6036. active: 0,
  6037. // Last-Modified header cache for next request
  6038. lastModified: {},
  6039. etag: {}
  6040. });
  6041. /* Handles responses to an ajax request:
  6042. * - sets all responseXXX fields accordingly
  6043. * - finds the right dataType (mediates between content-type and expected dataType)
  6044. * - returns the corresponding response
  6045. */
  6046. function ajaxHandleResponses( s, jqXHR, responses ) {
  6047. var contents = s.contents,
  6048. dataTypes = s.dataTypes,
  6049. responseFields = s.responseFields,
  6050. ct,
  6051. type,
  6052. finalDataType,
  6053. firstDataType;
  6054. // Fill responseXXX fields
  6055. for( type in responseFields ) {
  6056. if ( type in responses ) {
  6057. jqXHR[ responseFields[type] ] = responses[ type ];
  6058. }
  6059. }
  6060. // Remove auto dataType and get content-type in the process
  6061. while( dataTypes[ 0 ] === "*" ) {
  6062. dataTypes.shift();
  6063. if ( ct === undefined ) {
  6064. ct = s.mimeType || jqXHR.getResponseHeader( "content-type" );
  6065. }
  6066. }
  6067. // Check if we're dealing with a known content-type
  6068. if ( ct ) {
  6069. for ( type in contents ) {
  6070. if ( contents[ type ] && contents[ type ].test( ct ) ) {
  6071. dataTypes.unshift( type );
  6072. break;
  6073. }
  6074. }
  6075. }
  6076. // Check to see if we have a response for the expected dataType
  6077. if ( dataTypes[ 0 ] in responses ) {
  6078. finalDataType = dataTypes[ 0 ];
  6079. } else {
  6080. // Try convertible dataTypes
  6081. for ( type in responses ) {
  6082. if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
  6083. finalDataType = type;
  6084. break;
  6085. }
  6086. if ( !firstDataType ) {
  6087. firstDataType = type;
  6088. }
  6089. }
  6090. // Or just use first one
  6091. finalDataType = finalDataType || firstDataType;
  6092. }
  6093. // If we found a dataType
  6094. // We add the dataType to the list if needed
  6095. // and return the corresponding response
  6096. if ( finalDataType ) {
  6097. if ( finalDataType !== dataTypes[ 0 ] ) {
  6098. dataTypes.unshift( finalDataType );
  6099. }
  6100. return responses[ finalDataType ];
  6101. }
  6102. }
  6103. // Chain conversions given the request and the original response
  6104. function ajaxConvert( s, response ) {
  6105. // Apply the dataFilter if provided
  6106. if ( s.dataFilter ) {
  6107. response = s.dataFilter( response, s.dataType );
  6108. }
  6109. var dataTypes = s.dataTypes,
  6110. converters = {},
  6111. i,
  6112. key,
  6113. length = dataTypes.length,
  6114. tmp,
  6115. // Current and previous dataTypes
  6116. current = dataTypes[ 0 ],
  6117. prev,
  6118. // Conversion expression
  6119. conversion,
  6120. // Conversion function
  6121. conv,
  6122. // Conversion functions (transitive conversion)
  6123. conv1,
  6124. conv2;
  6125. // For each dataType in the chain
  6126. for( i = 1; i < length; i++ ) {
  6127. // Create converters map
  6128. // with lowercased keys
  6129. if ( i === 1 ) {
  6130. for( key in s.converters ) {
  6131. if( typeof key === "string" ) {
  6132. converters[ key.toLowerCase() ] = s.converters[ key ];
  6133. }
  6134. }
  6135. }
  6136. // Get the dataTypes
  6137. prev = current;
  6138. current = dataTypes[ i ];
  6139. // If current is auto dataType, update it to prev
  6140. if( current === "*" ) {
  6141. current = prev;
  6142. // If no auto and dataTypes are actually different
  6143. } else if ( prev !== "*" && prev !== current ) {
  6144. // Get the converter
  6145. conversion = prev + " " + current;
  6146. conv = converters[ conversion ] || converters[ "* " + current ];
  6147. // If there is no direct converter, search transitively
  6148. if ( !conv ) {
  6149. conv2 = undefined;
  6150. for( conv1 in converters ) {
  6151. tmp = conv1.split( " " );
  6152. if ( tmp[ 0 ] === prev || tmp[ 0 ] === "*" ) {
  6153. conv2 = converters[ tmp[1] + " " + current ];
  6154. if ( conv2 ) {
  6155. conv1 = converters[ conv1 ];
  6156. if ( conv1 === true ) {
  6157. conv = conv2;
  6158. } else if ( conv2 === true ) {
  6159. conv = conv1;
  6160. }
  6161. break;
  6162. }
  6163. }
  6164. }
  6165. }
  6166. // If we found no converter, dispatch an error
  6167. if ( !( conv || conv2 ) ) {
  6168. jQuery.error( "No conversion from " + conversion.replace(" "," to ") );
  6169. }
  6170. // If found converter is not an equivalence
  6171. if ( conv !== true ) {
  6172. // Convert with 1 or 2 converters accordingly
  6173. response = conv ? conv( response ) : conv2( conv1(response) );
  6174. }
  6175. }
  6176. }
  6177. return response;
  6178. }
  6179. var jsc = jQuery.now(),
  6180. jsre = /(\=)\?(&|$)|\?\?/i;
  6181. // Default jsonp settings
  6182. jQuery.ajaxSetup({
  6183. jsonp: "callback",
  6184. jsonpCallback: function() {
  6185. return jQuery.expando + "_" + ( jsc++ );
  6186. }
  6187. });
  6188. // Detect, normalize options and install callbacks for jsonp requests
  6189. jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
  6190. var inspectData = s.contentType === "application/x-www-form-urlencoded" &&
  6191. ( typeof s.data === "string" );
  6192. if ( s.dataTypes[ 0 ] === "jsonp" ||
  6193. s.jsonp !== false && ( jsre.test( s.url ) ||
  6194. inspectData && jsre.test( s.data ) ) ) {
  6195. var responseContainer,
  6196. jsonpCallback = s.jsonpCallback =
  6197. jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
  6198. previous = window[ jsonpCallback ],
  6199. url = s.url,
  6200. data = s.data,
  6201. replace = "$1" + jsonpCallback + "$2";
  6202. if ( s.jsonp !== false ) {
  6203. url = url.replace( jsre, replace );
  6204. if ( s.url === url ) {
  6205. if ( inspectData ) {
  6206. data = data.replace( jsre, replace );
  6207. }
  6208. if ( s.data === data ) {
  6209. // Add callback manually
  6210. url += (/\?/.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback;
  6211. }
  6212. }
  6213. }
  6214. s.url = url;
  6215. s.data = data;
  6216. // Install callback
  6217. window[ jsonpCallback ] = function( response ) {
  6218. responseContainer = [ response ];
  6219. };
  6220. // Clean-up function
  6221. jqXHR.always(function() {
  6222. // Set callback back to previous value
  6223. window[ jsonpCallback ] = previous;
  6224. // Call if it was a function and we have a response
  6225. if ( responseContainer && jQuery.isFunction( previous ) ) {
  6226. window[ jsonpCallback ]( responseContainer[ 0 ] );
  6227. }
  6228. });
  6229. // Use data converter to retrieve json after script execution
  6230. s.converters["script json"] = function() {
  6231. if ( !responseContainer ) {
  6232. jQuery.error( jsonpCallback + " was not called" );
  6233. }
  6234. return responseContainer[ 0 ];
  6235. };
  6236. // force json dataType
  6237. s.dataTypes[ 0 ] = "json";
  6238. // Delegate to script
  6239. return "script";
  6240. }
  6241. });
  6242. // Install script dataType
  6243. jQuery.ajaxSetup({
  6244. accepts: {
  6245. script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
  6246. },
  6247. contents: {
  6248. script: /javascript|ecmascript/
  6249. },
  6250. converters: {
  6251. "text script": function( text ) {
  6252. jQuery.globalEval( text );
  6253. return text;
  6254. }
  6255. }
  6256. });
  6257. // Handle cache's special case and global
  6258. jQuery.ajaxPrefilter( "script", function( s ) {
  6259. if ( s.cache === undefined ) {
  6260. s.cache = false;
  6261. }
  6262. if ( s.crossDomain ) {
  6263. s.type = "GET";
  6264. s.global = false;
  6265. }
  6266. });
  6267. // Bind script tag hack transport
  6268. jQuery.ajaxTransport( "script", function(s) {
  6269. // This transport only deals with cross domain requests
  6270. if ( s.crossDomain ) {
  6271. var script,
  6272. head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement;
  6273. return {
  6274. send: function( _, callback ) {
  6275. script = document.createElement( "script" );
  6276. script.async = "async";
  6277. if ( s.scriptCharset ) {
  6278. script.charset = s.scriptCharset;
  6279. }
  6280. script.src = s.url;
  6281. // Attach handlers for all browsers
  6282. script.onload = script.onreadystatechange = function( _, isAbort ) {
  6283. if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
  6284. // Handle memory leak in IE
  6285. script.onload = script.onreadystatechange = null;
  6286. // Remove the script
  6287. if ( head && script.parentNode ) {
  6288. head.removeChild( script );
  6289. }
  6290. // Dereference the script
  6291. script = undefined;
  6292. // Callback if not abort
  6293. if ( !isAbort ) {
  6294. callback( 200, "success" );
  6295. }
  6296. }
  6297. };
  6298. // Use insertBefore instead of appendChild to circumvent an IE6 bug.
  6299. // This arises when a base node is used (#2709 and #4378).
  6300. head.insertBefore( script, head.firstChild );
  6301. },
  6302. abort: function() {
  6303. if ( script ) {
  6304. script.onload( 0, 1 );
  6305. }
  6306. }
  6307. };
  6308. }
  6309. });
  6310. var // #5280: Internet Explorer will keep connections alive if we don't abort on unload
  6311. xhrOnUnloadAbort = window.ActiveXObject ? function() {
  6312. // Abort all pending requests
  6313. for ( var key in xhrCallbacks ) {
  6314. xhrCallbacks[ key ]( 0, 1 );
  6315. }
  6316. } : false,
  6317. xhrId = 0,
  6318. xhrCallbacks;
  6319. // Functions to create xhrs
  6320. function createStandardXHR() {
  6321. try {
  6322. return new window.XMLHttpRequest();
  6323. } catch( e ) {}
  6324. }
  6325. function createActiveXHR() {
  6326. try {
  6327. return new window.ActiveXObject( "Microsoft.XMLHTTP" );
  6328. } catch( e ) {}
  6329. }
  6330. // Create the request object
  6331. // (This is still attached to ajaxSettings for backward compatibility)
  6332. jQuery.ajaxSettings.xhr = window.ActiveXObject ?
  6333. /* Microsoft failed to properly
  6334. * implement the XMLHttpRequest in IE7 (can't request local files),
  6335. * so we use the ActiveXObject when it is available
  6336. * Additionally XMLHttpRequest can be disabled in IE7/IE8 so
  6337. * we need a fallback.
  6338. */
  6339. function() {
  6340. return !this.isLocal && createStandardXHR() || createActiveXHR();
  6341. } :
  6342. // For all other browsers, use the standard XMLHttpRequest object
  6343. createStandardXHR;
  6344. // Determine support properties
  6345. (function( xhr ) {
  6346. jQuery.extend( jQuery.support, {
  6347. ajax: !!xhr,
  6348. cors: !!xhr && ( "withCredentials" in xhr )
  6349. });
  6350. })( jQuery.ajaxSettings.xhr() );
  6351. // Create transport if the browser can provide an xhr
  6352. if ( jQuery.support.ajax ) {
  6353. jQuery.ajaxTransport(function( s ) {
  6354. // Cross domain only allowed if supported through XMLHttpRequest
  6355. if ( !s.crossDomain || jQuery.support.cors ) {
  6356. var callback;
  6357. return {
  6358. send: function( headers, complete ) {
  6359. // Get a new xhr
  6360. var xhr = s.xhr(),
  6361. handle,
  6362. i;
  6363. // Open the socket
  6364. // Passing null username, generates a login popup on Opera (#2865)
  6365. if ( s.username ) {
  6366. xhr.open( s.type, s.url, s.async, s.username, s.password );
  6367. } else {
  6368. xhr.open( s.type, s.url, s.async );
  6369. }
  6370. // Apply custom fields if provided
  6371. if ( s.xhrFields ) {
  6372. for ( i in s.xhrFields ) {
  6373. xhr[ i ] = s.xhrFields[ i ];
  6374. }
  6375. }
  6376. // Override mime type if needed
  6377. if ( s.mimeType && xhr.overrideMimeType ) {
  6378. xhr.overrideMimeType( s.mimeType );
  6379. }
  6380. // X-Requested-With header
  6381. // For cross-domain requests, seeing as conditions for a preflight are
  6382. // akin to a jigsaw puzzle, we simply never set it to be sure.
  6383. // (it can always be set on a per-request basis or even using ajaxSetup)
  6384. // For same-domain requests, won't change header if already provided.
  6385. if ( !s.crossDomain && !headers["X-Requested-With"] ) {
  6386. headers[ "X-Requested-With" ] = "XMLHttpRequest";
  6387. }
  6388. // Need an extra try/catch for cross domain requests in Firefox 3
  6389. try {
  6390. for ( i in headers ) {
  6391. xhr.setRequestHeader( i, headers[ i ] );
  6392. }
  6393. } catch( _ ) {}
  6394. // Do send the request
  6395. // This may raise an exception which is actually
  6396. // handled in jQuery.ajax (so no try/catch here)
  6397. xhr.send( ( s.hasContent && s.data ) || null );
  6398. // Listener
  6399. callback = function( _, isAbort ) {
  6400. var status,
  6401. statusText,
  6402. responseHeaders,
  6403. responses,
  6404. xml;
  6405. // Firefox throws exceptions when accessing properties
  6406. // of an xhr when a network error occured
  6407. // http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE)
  6408. try {
  6409. // Was never called and is aborted or complete
  6410. if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
  6411. // Only called once
  6412. callback = undefined;
  6413. // Do not keep as active anymore
  6414. if ( handle ) {
  6415. xhr.onreadystatechange = jQuery.noop;
  6416. if ( xhrOnUnloadAbort ) {
  6417. delete xhrCallbacks[ handle ];
  6418. }
  6419. }
  6420. // If it's an abort
  6421. if ( isAbort ) {
  6422. // Abort it manually if needed
  6423. if ( xhr.readyState !== 4 ) {
  6424. xhr.abort();
  6425. }
  6426. } else {
  6427. status = xhr.status;
  6428. responseHeaders = xhr.getAllResponseHeaders();
  6429. responses = {};
  6430. xml = xhr.responseXML;
  6431. // Construct response list
  6432. if ( xml && xml.documentElement /* #4958 */ ) {
  6433. responses.xml = xml;
  6434. }
  6435. responses.text = xhr.responseText;
  6436. // Firefox throws an exception when accessing
  6437. // statusText for faulty cross-domain requests
  6438. try {
  6439. statusText = xhr.statusText;
  6440. } catch( e ) {
  6441. // We normalize with Webkit giving an empty statusText
  6442. statusText = "";
  6443. }
  6444. // Filter status for non standard behaviors
  6445. // If the request is local and we have data: assume a success
  6446. // (success with no data won't get notified, that's the best we
  6447. // can do given current implementations)
  6448. if ( !status && s.isLocal && !s.crossDomain ) {
  6449. status = responses.text ? 200 : 404;
  6450. // IE - #1450: sometimes returns 1223 when it should be 204
  6451. } else if ( status === 1223 ) {
  6452. status = 204;
  6453. }
  6454. }
  6455. }
  6456. } catch( firefoxAccessException ) {
  6457. if ( !isAbort ) {
  6458. complete( -1, firefoxAccessException );
  6459. }
  6460. }
  6461. // Call complete if needed
  6462. if ( responses ) {
  6463. complete( status, statusText, responses, responseHeaders );
  6464. }
  6465. };
  6466. // if we're in sync mode or it's in cache
  6467. // and has been retrieved directly (IE6 & IE7)
  6468. // we need to manually fire the callback
  6469. if ( !s.async || xhr.readyState === 4 ) {
  6470. callback();
  6471. } else {
  6472. handle = ++xhrId;
  6473. if ( xhrOnUnloadAbort ) {
  6474. // Create the active xhrs callbacks list if needed
  6475. // and attach the unload handler
  6476. if ( !xhrCallbacks ) {
  6477. xhrCallbacks = {};
  6478. jQuery( window ).unload( xhrOnUnloadAbort );
  6479. }
  6480. // Add to list of active xhrs callbacks
  6481. xhrCallbacks[ handle ] = callback;
  6482. }
  6483. xhr.onreadystatechange = callback;
  6484. }
  6485. },
  6486. abort: function() {
  6487. if ( callback ) {
  6488. callback(0,1);
  6489. }
  6490. }
  6491. };
  6492. }
  6493. });
  6494. }
  6495. var elemdisplay = {},
  6496. iframe, iframeDoc,
  6497. rfxtypes = /^(?:toggle|show|hide)$/,
  6498. rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,
  6499. timerId,
  6500. fxAttrs = [
  6501. // height animations
  6502. [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
  6503. // width animations
  6504. [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
  6505. // opacity animations
  6506. [ "opacity" ]
  6507. ],
  6508. fxNow,
  6509. requestAnimationFrame = window.webkitRequestAnimationFrame ||
  6510. window.mozRequestAnimationFrame ||
  6511. window.oRequestAnimationFrame;
  6512. jQuery.fn.extend({
  6513. show: function( speed, easing, callback ) {
  6514. var elem, display;
  6515. if ( speed || speed === 0 ) {
  6516. return this.animate( genFx("show", 3), speed, easing, callback);
  6517. } else {
  6518. for ( var i = 0, j = this.length; i < j; i++ ) {
  6519. elem = this[i];
  6520. if ( elem.style ) {
  6521. display = elem.style.display;
  6522. // Reset the inline display of this element to learn if it is
  6523. // being hidden by cascaded rules or not
  6524. if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
  6525. display = elem.style.display = "";
  6526. }
  6527. // Set elements which have been overridden with display: none
  6528. // in a stylesheet to whatever the default browser style is
  6529. // for such an element
  6530. if ( display === "" && jQuery.css( elem, "display" ) === "none" ) {
  6531. jQuery._data(elem, "olddisplay", defaultDisplay(elem.nodeName));
  6532. }
  6533. }
  6534. }
  6535. // Set the display of most of the elements in a second loop
  6536. // to avoid the constant reflow
  6537. for ( i = 0; i < j; i++ ) {
  6538. elem = this[i];
  6539. if ( elem.style ) {
  6540. display = elem.style.display;
  6541. if ( display === "" || display === "none" ) {
  6542. elem.style.display = jQuery._data(elem, "olddisplay") || "";
  6543. }
  6544. }
  6545. }
  6546. return this;
  6547. }
  6548. },
  6549. hide: function( speed, easing, callback ) {
  6550. if ( speed || speed === 0 ) {
  6551. return this.animate( genFx("hide", 3), speed, easing, callback);
  6552. } else {
  6553. for ( var i = 0, j = this.length; i < j; i++ ) {
  6554. if ( this[i].style ) {
  6555. var display = jQuery.css( this[i], "display" );
  6556. if ( display !== "none" && !jQuery._data( this[i], "olddisplay" ) ) {
  6557. jQuery._data( this[i], "olddisplay", display );
  6558. }
  6559. }
  6560. }
  6561. // Set the display of the elements in a second loop
  6562. // to avoid the constant reflow
  6563. for ( i = 0; i < j; i++ ) {
  6564. if ( this[i].style ) {
  6565. this[i].style.display = "none";
  6566. }
  6567. }
  6568. return this;
  6569. }
  6570. },
  6571. // Save the old toggle function
  6572. _toggle: jQuery.fn.toggle,
  6573. toggle: function( fn, fn2, callback ) {
  6574. var bool = typeof fn === "boolean";
  6575. if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
  6576. this._toggle.apply( this, arguments );
  6577. } else if ( fn == null || bool ) {
  6578. this.each(function() {
  6579. var state = bool ? fn : jQuery(this).is(":hidden");
  6580. jQuery(this)[ state ? "show" : "hide" ]();
  6581. });
  6582. } else {
  6583. this.animate(genFx("toggle", 3), fn, fn2, callback);
  6584. }
  6585. return this;
  6586. },
  6587. fadeTo: function( speed, to, easing, callback ) {
  6588. return this.filter(":hidden").css("opacity", 0).show().end()
  6589. .animate({opacity: to}, speed, easing, callback);
  6590. },
  6591. animate: function( prop, speed, easing, callback ) {
  6592. var optall = jQuery.speed(speed, easing, callback);
  6593. if ( jQuery.isEmptyObject( prop ) ) {
  6594. return this.each( optall.complete, [ false ] );
  6595. }
  6596. // Do not change referenced properties as per-property easing will be lost
  6597. prop = jQuery.extend( {}, prop );
  6598. return this[ optall.queue === false ? "each" : "queue" ](function() {
  6599. // XXX 'this' does not always have a nodeName when running the
  6600. // test suite
  6601. if ( optall.queue === false ) {
  6602. jQuery._mark( this );
  6603. }
  6604. var opt = jQuery.extend( {}, optall ),
  6605. isElement = this.nodeType === 1,
  6606. hidden = isElement && jQuery(this).is(":hidden"),
  6607. name, val, p,
  6608. display, e,
  6609. parts, start, end, unit;
  6610. // will store per property easing and be used to determine when an animation is complete
  6611. opt.animatedProperties = {};
  6612. for ( p in prop ) {
  6613. // property name normalization
  6614. name = jQuery.camelCase( p );
  6615. if ( p !== name ) {
  6616. prop[ name ] = prop[ p ];
  6617. delete prop[ p ];
  6618. }
  6619. val = prop[ name ];
  6620. // easing resolution: per property > opt.specialEasing > opt.easing > 'swing' (default)
  6621. if ( jQuery.isArray( val ) ) {
  6622. opt.animatedProperties[ name ] = val[ 1 ];
  6623. val = prop[ name ] = val[ 0 ];
  6624. } else {
  6625. opt.animatedProperties[ name ] = opt.specialEasing && opt.specialEasing[ name ] || opt.easing || 'swing';
  6626. }
  6627. if ( val === "hide" && hidden || val === "show" && !hidden ) {
  6628. return opt.complete.call( this );
  6629. }
  6630. if ( isElement && ( name === "height" || name === "width" ) ) {
  6631. // Make sure that nothing sneaks out
  6632. // Record all 3 overflow attributes because IE does not
  6633. // change the overflow attribute when overflowX and
  6634. // overflowY are set to the same value
  6635. opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
  6636. // Set display property to inline-block for height/width
  6637. // animations on inline elements that are having width/height
  6638. // animated
  6639. if ( jQuery.css( this, "display" ) === "inline" &&
  6640. jQuery.css( this, "float" ) === "none" ) {
  6641. if ( !jQuery.support.inlineBlockNeedsLayout ) {
  6642. this.style.display = "inline-block";
  6643. } else {
  6644. display = defaultDisplay( this.nodeName );
  6645. // inline-level elements accept inline-block;
  6646. // block-level elements need to be inline with layout
  6647. if ( display === "inline" ) {
  6648. this.style.display = "inline-block";
  6649. } else {
  6650. this.style.display = "inline";
  6651. this.style.zoom = 1;
  6652. }
  6653. }
  6654. }
  6655. }
  6656. }
  6657. if ( opt.overflow != null ) {
  6658. this.style.overflow = "hidden";
  6659. }
  6660. for ( p in prop ) {
  6661. e = new jQuery.fx( this, opt, p );
  6662. val = prop[ p ];
  6663. if ( rfxtypes.test(val) ) {
  6664. e[ val === "toggle" ? hidden ? "show" : "hide" : val ]();
  6665. } else {
  6666. parts = rfxnum.exec( val );
  6667. start = e.cur();
  6668. if ( parts ) {
  6669. end = parseFloat( parts[2] );
  6670. unit = parts[3] || ( jQuery.cssNumber[ p ] ? "" : "px" );
  6671. // We need to compute starting value
  6672. if ( unit !== "px" ) {
  6673. jQuery.style( this, p, (end || 1) + unit);
  6674. start = ((end || 1) / e.cur()) * start;
  6675. jQuery.style( this, p, start + unit);
  6676. }
  6677. // If a +=/-= token was provided, we're doing a relative animation
  6678. if ( parts[1] ) {
  6679. end = ( (parts[ 1 ] === "-=" ? -1 : 1) * end ) + start;
  6680. }
  6681. e.custom( start, end, unit );
  6682. } else {
  6683. e.custom( start, val, "" );
  6684. }
  6685. }
  6686. }
  6687. // For JS strict compliance
  6688. return true;
  6689. });
  6690. },
  6691. stop: function( clearQueue, gotoEnd ) {
  6692. if ( clearQueue ) {
  6693. this.queue([]);
  6694. }
  6695. this.each(function() {
  6696. var timers = jQuery.timers,
  6697. i = timers.length;
  6698. // clear marker counters if we know they won't be
  6699. if ( !gotoEnd ) {
  6700. jQuery._unmark( true, this );
  6701. }
  6702. while ( i-- ) {
  6703. if ( timers[i].elem === this ) {
  6704. if (gotoEnd) {
  6705. // force the next step to be the last
  6706. timers[i](true);
  6707. }
  6708. timers.splice(i, 1);
  6709. }
  6710. }
  6711. });
  6712. // start the next in the queue if the last step wasn't forced
  6713. if ( !gotoEnd ) {
  6714. this.dequeue();
  6715. }
  6716. return this;
  6717. }
  6718. });
  6719. // Animations created synchronously will run synchronously
  6720. function createFxNow() {
  6721. setTimeout( clearFxNow, 0 );
  6722. return ( fxNow = jQuery.now() );
  6723. }
  6724. function clearFxNow() {
  6725. fxNow = undefined;
  6726. }
  6727. // Generate parameters to create a standard animation
  6728. function genFx( type, num ) {
  6729. var obj = {};
  6730. jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
  6731. obj[ this ] = type;
  6732. });
  6733. return obj;
  6734. }
  6735. // Generate shortcuts for custom animations
  6736. jQuery.each({
  6737. slideDown: genFx("show", 1),
  6738. slideUp: genFx("hide", 1),
  6739. slideToggle: genFx("toggle", 1),
  6740. fadeIn: { opacity: "show" },
  6741. fadeOut: { opacity: "hide" },
  6742. fadeToggle: { opacity: "toggle" }
  6743. }, function( name, props ) {
  6744. jQuery.fn[ name ] = function( speed, easing, callback ) {
  6745. return this.animate( props, speed, easing, callback );
  6746. };
  6747. });
  6748. jQuery.extend({
  6749. speed: function( speed, easing, fn ) {
  6750. var opt = speed && typeof speed === "object" ? jQuery.extend({}, speed) : {
  6751. complete: fn || !fn && easing ||
  6752. jQuery.isFunction( speed ) && speed,
  6753. duration: speed,
  6754. easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
  6755. };
  6756. opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
  6757. opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[opt.duration] : jQuery.fx.speeds._default;
  6758. // Queueing
  6759. opt.old = opt.complete;
  6760. opt.complete = function( noUnmark ) {
  6761. if ( opt.queue !== false ) {
  6762. jQuery.dequeue( this );
  6763. } else if ( noUnmark !== false ) {
  6764. jQuery._unmark( this );
  6765. }
  6766. if ( jQuery.isFunction( opt.old ) ) {
  6767. opt.old.call( this );
  6768. }
  6769. };
  6770. return opt;
  6771. },
  6772. easing: {
  6773. linear: function( p, n, firstNum, diff ) {
  6774. return firstNum + diff * p;
  6775. },
  6776. swing: function( p, n, firstNum, diff ) {
  6777. return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
  6778. }
  6779. },
  6780. timers: [],
  6781. fx: function( elem, options, prop ) {
  6782. this.options = options;
  6783. this.elem = elem;
  6784. this.prop = prop;
  6785. options.orig = options.orig || {};
  6786. }
  6787. });
  6788. jQuery.fx.prototype = {
  6789. // Simple function for setting a style value
  6790. update: function() {
  6791. if ( this.options.step ) {
  6792. this.options.step.call( this.elem, this.now, this );
  6793. }
  6794. (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
  6795. },
  6796. // Get the current size
  6797. cur: function() {
  6798. if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
  6799. return this.elem[ this.prop ];
  6800. }
  6801. var parsed,
  6802. r = jQuery.css( this.elem, this.prop );
  6803. // Empty strings, null, undefined and "auto" are converted to 0,
  6804. // complex values such as "rotate(1rad)" are returned as is,
  6805. // simple values such as "10px" are parsed to Float.
  6806. return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
  6807. },
  6808. // Start an animation from one number to another
  6809. custom: function( from, to, unit ) {
  6810. var self = this,
  6811. fx = jQuery.fx,
  6812. raf;
  6813. this.startTime = fxNow || createFxNow();
  6814. this.start = from;
  6815. this.end = to;
  6816. this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" );
  6817. this.now = this.start;
  6818. this.pos = this.state = 0;
  6819. function t( gotoEnd ) {
  6820. return self.step(gotoEnd);
  6821. }
  6822. t.elem = this.elem;
  6823. if ( t() && jQuery.timers.push(t) && !timerId ) {
  6824. // Use requestAnimationFrame instead of setInterval if available
  6825. if ( requestAnimationFrame ) {
  6826. timerId = 1;
  6827. raf = function() {
  6828. // When timerId gets set to null at any point, this stops
  6829. if ( timerId ) {
  6830. requestAnimationFrame( raf );
  6831. fx.tick();
  6832. }
  6833. };
  6834. requestAnimationFrame( raf );
  6835. } else {
  6836. timerId = setInterval( fx.tick, fx.interval );
  6837. }
  6838. }
  6839. },
  6840. // Simple 'show' function
  6841. show: function() {
  6842. // Remember where we started, so that we can go back to it later
  6843. this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
  6844. this.options.show = true;
  6845. // Begin the animation
  6846. // Make sure that we start at a small width/height to avoid any
  6847. // flash of content
  6848. this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur());
  6849. // Start by showing the element
  6850. jQuery( this.elem ).show();
  6851. },
  6852. // Simple 'hide' function
  6853. hide: function() {
  6854. // Remember where we started, so that we can go back to it later
  6855. this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
  6856. this.options.hide = true;
  6857. // Begin the animation
  6858. this.custom(this.cur(), 0);
  6859. },
  6860. // Each step of an animation
  6861. step: function( gotoEnd ) {
  6862. var t = fxNow || createFxNow(),
  6863. done = true,
  6864. elem = this.elem,
  6865. options = this.options,
  6866. i, n;
  6867. if ( gotoEnd || t >= options.duration + this.startTime ) {
  6868. this.now = this.end;
  6869. this.pos = this.state = 1;
  6870. this.update();
  6871. options.animatedProperties[ this.prop ] = true;
  6872. for ( i in options.animatedProperties ) {
  6873. if ( options.animatedProperties[i] !== true ) {
  6874. done = false;
  6875. }
  6876. }
  6877. if ( done ) {
  6878. // Reset the overflow
  6879. if ( options.overflow != null && !jQuery.support.shrinkWrapBlocks ) {
  6880. jQuery.each( [ "", "X", "Y" ], function (index, value) {
  6881. elem.style[ "overflow" + value ] = options.overflow[index];
  6882. });
  6883. }
  6884. // Hide the element if the "hide" operation was done
  6885. if ( options.hide ) {
  6886. jQuery(elem).hide();
  6887. }
  6888. // Reset the properties, if the item has been hidden or shown
  6889. if ( options.hide || options.show ) {
  6890. for ( var p in options.animatedProperties ) {
  6891. jQuery.style( elem, p, options.orig[p] );
  6892. }
  6893. }
  6894. // Execute the complete function
  6895. options.complete.call( elem );
  6896. }
  6897. return false;
  6898. } else {
  6899. // classical easing cannot be used with an Infinity duration
  6900. if ( options.duration == Infinity ) {
  6901. this.now = t;
  6902. } else {
  6903. n = t - this.startTime;
  6904. this.state = n / options.duration;
  6905. // Perform the easing function, defaults to swing
  6906. this.pos = jQuery.easing[ options.animatedProperties[ this.prop ] ]( this.state, n, 0, 1, options.duration );
  6907. this.now = this.start + ((this.end - this.start) * this.pos);
  6908. }
  6909. // Perform the next step of the animation
  6910. this.update();
  6911. }
  6912. return true;
  6913. }
  6914. };
  6915. jQuery.extend( jQuery.fx, {
  6916. tick: function() {
  6917. for ( var timers = jQuery.timers, i = 0 ; i < timers.length ; ++i ) {
  6918. if ( !timers[i]() ) {
  6919. timers.splice(i--, 1);
  6920. }
  6921. }
  6922. if ( !timers.length ) {
  6923. jQuery.fx.stop();
  6924. }
  6925. },
  6926. interval: 13,
  6927. stop: function() {
  6928. clearInterval( timerId );
  6929. timerId = null;
  6930. },
  6931. speeds: {
  6932. slow: 600,
  6933. fast: 200,
  6934. // Default speed
  6935. _default: 400
  6936. },
  6937. step: {
  6938. opacity: function( fx ) {
  6939. jQuery.style( fx.elem, "opacity", fx.now );
  6940. },
  6941. _default: function( fx ) {
  6942. if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
  6943. fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
  6944. } else {
  6945. fx.elem[ fx.prop ] = fx.now;
  6946. }
  6947. }
  6948. }
  6949. });
  6950. if ( jQuery.expr && jQuery.expr.filters ) {
  6951. jQuery.expr.filters.animated = function( elem ) {
  6952. return jQuery.grep(jQuery.timers, function( fn ) {
  6953. return elem === fn.elem;
  6954. }).length;
  6955. };
  6956. }
  6957. // Try to restore the default display value of an element
  6958. function defaultDisplay( nodeName ) {
  6959. if ( !elemdisplay[ nodeName ] ) {
  6960. var elem = jQuery( "<" + nodeName + ">" ).appendTo( "body" ),
  6961. display = elem.css( "display" );
  6962. elem.remove();
  6963. // If the simple way fails,
  6964. // get element's real default display by attaching it to a temp iframe
  6965. if ( display === "none" || display === "" ) {
  6966. // No iframe to use yet, so create it
  6967. if ( !iframe ) {
  6968. iframe = document.createElement( "iframe" );
  6969. iframe.frameBorder = iframe.width = iframe.height = 0;
  6970. }
  6971. document.body.appendChild( iframe );
  6972. // Create a cacheable copy of the iframe document on first call.
  6973. // IE and Opera will allow us to reuse the iframeDoc without re-writing the fake html
  6974. // document to it, Webkit & Firefox won't allow reusing the iframe document
  6975. if ( !iframeDoc || !iframe.createElement ) {
  6976. iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document;
  6977. iframeDoc.write( "<!doctype><html><body></body></html>" );
  6978. }
  6979. elem = iframeDoc.createElement( nodeName );
  6980. iframeDoc.body.appendChild( elem );
  6981. display = jQuery.css( elem, "display" );
  6982. document.body.removeChild( iframe );
  6983. }
  6984. // Store the correct default display
  6985. elemdisplay[ nodeName ] = display;
  6986. }
  6987. return elemdisplay[ nodeName ];
  6988. }
  6989. var rtable = /^t(?:able|d|h)$/i,
  6990. rroot = /^(?:body|html)$/i;
  6991. if ( "getBoundingClientRect" in document.documentElement ) {
  6992. jQuery.fn.offset = function( options ) {
  6993. var elem = this[0], box;
  6994. if ( options ) {
  6995. return this.each(function( i ) {
  6996. jQuery.offset.setOffset( this, options, i );
  6997. });
  6998. }
  6999. if ( !elem || !elem.ownerDocument ) {
  7000. return null;
  7001. }
  7002. if ( elem === elem.ownerDocument.body ) {
  7003. return jQuery.offset.bodyOffset( elem );
  7004. }
  7005. try {
  7006. box = elem.getBoundingClientRect();
  7007. } catch(e) {}
  7008. var doc = elem.ownerDocument,
  7009. docElem = doc.documentElement;
  7010. // Make sure we're not dealing with a disconnected DOM node
  7011. if ( !box || !jQuery.contains( docElem, elem ) ) {
  7012. return box ? { top: box.top, left: box.left } : { top: 0, left: 0 };
  7013. }
  7014. var body = doc.body,
  7015. win = getWindow(doc),
  7016. clientTop = docElem.clientTop || body.clientTop || 0,
  7017. clientLeft = docElem.clientLeft || body.clientLeft || 0,
  7018. scrollTop = win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop,
  7019. scrollLeft = win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft,
  7020. top = box.top + scrollTop - clientTop,
  7021. left = box.left + scrollLeft - clientLeft;
  7022. return { top: top, left: left };
  7023. };
  7024. } else {
  7025. jQuery.fn.offset = function( options ) {
  7026. var elem = this[0];
  7027. if ( options ) {
  7028. return this.each(function( i ) {
  7029. jQuery.offset.setOffset( this, options, i );
  7030. });
  7031. }
  7032. if ( !elem || !elem.ownerDocument ) {
  7033. return null;
  7034. }
  7035. if ( elem === elem.ownerDocument.body ) {
  7036. return jQuery.offset.bodyOffset( elem );
  7037. }
  7038. jQuery.offset.initialize();
  7039. var computedStyle,
  7040. offsetParent = elem.offsetParent,
  7041. prevOffsetParent = elem,
  7042. doc = elem.ownerDocument,
  7043. docElem = doc.documentElement,
  7044. body = doc.body,
  7045. defaultView = doc.defaultView,
  7046. prevComputedStyle = defaultView ? defaultView.getComputedStyle( elem, null ) : elem.currentStyle,
  7047. top = elem.offsetTop,
  7048. left = elem.offsetLeft;
  7049. while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
  7050. if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) {
  7051. break;
  7052. }
  7053. computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle;
  7054. top -= elem.scrollTop;
  7055. left -= elem.scrollLeft;
  7056. if ( elem === offsetParent ) {
  7057. top += elem.offsetTop;
  7058. left += elem.offsetLeft;
  7059. if ( jQuery.offset.doesNotAddBorder && !(jQuery.offset.doesAddBorderForTableAndCells && rtable.test(elem.nodeName)) ) {
  7060. top += parseFloat( computedStyle.borderTopWidth ) || 0;
  7061. left += parseFloat( computedStyle.borderLeftWidth ) || 0;
  7062. }
  7063. prevOffsetParent = offsetParent;
  7064. offsetParent = elem.offsetParent;
  7065. }
  7066. if ( jQuery.offset.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) {
  7067. top += parseFloat( computedStyle.borderTopWidth ) || 0;
  7068. left += parseFloat( computedStyle.borderLeftWidth ) || 0;
  7069. }
  7070. prevComputedStyle = computedStyle;
  7071. }
  7072. if ( prevComputedStyle.position === "relative" || prevComputedStyle.position === "static" ) {
  7073. top += body.offsetTop;
  7074. left += body.offsetLeft;
  7075. }
  7076. if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) {
  7077. top += Math.max( docElem.scrollTop, body.scrollTop );
  7078. left += Math.max( docElem.scrollLeft, body.scrollLeft );
  7079. }
  7080. return { top: top, left: left };
  7081. };
  7082. }
  7083. jQuery.offset = {
  7084. initialize: function() {
  7085. var body = document.body, container = document.createElement("div"), innerDiv, checkDiv, table, td, bodyMarginTop = parseFloat( jQuery.css(body, "marginTop") ) || 0,
  7086. html = "<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";
  7087. jQuery.extend( container.style, { position: "absolute", top: 0, left: 0, margin: 0, border: 0, width: "1px", height: "1px", visibility: "hidden" } );
  7088. container.innerHTML = html;
  7089. body.insertBefore( container, body.firstChild );
  7090. innerDiv = container.firstChild;
  7091. checkDiv = innerDiv.firstChild;
  7092. td = innerDiv.nextSibling.firstChild.firstChild;
  7093. this.doesNotAddBorder = (checkDiv.offsetTop !== 5);
  7094. this.doesAddBorderForTableAndCells = (td.offsetTop === 5);
  7095. checkDiv.style.position = "fixed";
  7096. checkDiv.style.top = "20px";
  7097. // safari subtracts parent border width here which is 5px
  7098. this.supportsFixedPosition = (checkDiv.offsetTop === 20 || checkDiv.offsetTop === 15);
  7099. checkDiv.style.position = checkDiv.style.top = "";
  7100. innerDiv.style.overflow = "hidden";
  7101. innerDiv.style.position = "relative";
  7102. this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5);
  7103. this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop);
  7104. body.removeChild( container );
  7105. jQuery.offset.initialize = jQuery.noop;
  7106. },
  7107. bodyOffset: function( body ) {
  7108. var top = body.offsetTop,
  7109. left = body.offsetLeft;
  7110. jQuery.offset.initialize();
  7111. if ( jQuery.offset.doesNotIncludeMarginInBodyOffset ) {
  7112. top += parseFloat( jQuery.css(body, "marginTop") ) || 0;
  7113. left += parseFloat( jQuery.css(body, "marginLeft") ) || 0;
  7114. }
  7115. return { top: top, left: left };
  7116. },
  7117. setOffset: function( elem, options, i ) {
  7118. var position = jQuery.css( elem, "position" );
  7119. // set position first, in-case top/left are set even on static elem
  7120. if ( position === "static" ) {
  7121. elem.style.position = "relative";
  7122. }
  7123. var curElem = jQuery( elem ),
  7124. curOffset = curElem.offset(),
  7125. curCSSTop = jQuery.css( elem, "top" ),
  7126. curCSSLeft = jQuery.css( elem, "left" ),
  7127. calculatePosition = (position === "absolute" || position === "fixed") && jQuery.inArray("auto", [curCSSTop, curCSSLeft]) > -1,
  7128. props = {}, curPosition = {}, curTop, curLeft;
  7129. // need to be able to calculate position if either top or left is auto and position is either absolute or fixed
  7130. if ( calculatePosition ) {
  7131. curPosition = curElem.position();
  7132. curTop = curPosition.top;
  7133. curLeft = curPosition.left;
  7134. } else {
  7135. curTop = parseFloat( curCSSTop ) || 0;
  7136. curLeft = parseFloat( curCSSLeft ) || 0;
  7137. }
  7138. if ( jQuery.isFunction( options ) ) {
  7139. options = options.call( elem, i, curOffset );
  7140. }
  7141. if (options.top != null) {
  7142. props.top = (options.top - curOffset.top) + curTop;
  7143. }
  7144. if (options.left != null) {
  7145. props.left = (options.left - curOffset.left) + curLeft;
  7146. }
  7147. if ( "using" in options ) {
  7148. options.using.call( elem, props );
  7149. } else {
  7150. curElem.css( props );
  7151. }
  7152. }
  7153. };
  7154. jQuery.fn.extend({
  7155. position: function() {
  7156. if ( !this[0] ) {
  7157. return null;
  7158. }
  7159. var elem = this[0],
  7160. // Get *real* offsetParent
  7161. offsetParent = this.offsetParent(),
  7162. // Get correct offsets
  7163. offset = this.offset(),
  7164. parentOffset = rroot.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset();
  7165. // Subtract element margins
  7166. // note: when an element has margin: auto the offsetLeft and marginLeft
  7167. // are the same in Safari causing offset.left to incorrectly be 0
  7168. offset.top -= parseFloat( jQuery.css(elem, "marginTop") ) || 0;
  7169. offset.left -= parseFloat( jQuery.css(elem, "marginLeft") ) || 0;
  7170. // Add offsetParent borders
  7171. parentOffset.top += parseFloat( jQuery.css(offsetParent[0], "borderTopWidth") ) || 0;
  7172. parentOffset.left += parseFloat( jQuery.css(offsetParent[0], "borderLeftWidth") ) || 0;
  7173. // Subtract the two offsets
  7174. return {
  7175. top: offset.top - parentOffset.top,
  7176. left: offset.left - parentOffset.left
  7177. };
  7178. },
  7179. offsetParent: function() {
  7180. return this.map(function() {
  7181. var offsetParent = this.offsetParent || document.body;
  7182. while ( offsetParent && (!rroot.test(offsetParent.nodeName) && jQuery.css(offsetParent, "position") === "static") ) {
  7183. offsetParent = offsetParent.offsetParent;
  7184. }
  7185. return offsetParent;
  7186. });
  7187. }
  7188. });
  7189. // Create scrollLeft and scrollTop methods
  7190. jQuery.each( ["Left", "Top"], function( i, name ) {
  7191. var method = "scroll" + name;
  7192. jQuery.fn[ method ] = function( val ) {
  7193. var elem, win;
  7194. if ( val === undefined ) {
  7195. elem = this[ 0 ];
  7196. if ( !elem ) {
  7197. return null;
  7198. }
  7199. win = getWindow( elem );
  7200. // Return the scroll offset
  7201. return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] :
  7202. jQuery.support.boxModel && win.document.documentElement[ method ] ||
  7203. win.document.body[ method ] :
  7204. elem[ method ];
  7205. }
  7206. // Set the scroll offset
  7207. return this.each(function() {
  7208. win = getWindow( this );
  7209. if ( win ) {
  7210. win.scrollTo(
  7211. !i ? val : jQuery( win ).scrollLeft(),
  7212. i ? val : jQuery( win ).scrollTop()
  7213. );
  7214. } else {
  7215. this[ method ] = val;
  7216. }
  7217. });
  7218. };
  7219. });
  7220. function getWindow( elem ) {
  7221. return jQuery.isWindow( elem ) ?
  7222. elem :
  7223. elem.nodeType === 9 ?
  7224. elem.defaultView || elem.parentWindow :
  7225. false;
  7226. }
  7227. // Create innerHeight, innerWidth, outerHeight and outerWidth methods
  7228. jQuery.each([ "Height", "Width" ], function( i, name ) {
  7229. var type = name.toLowerCase();
  7230. // innerHeight and innerWidth
  7231. jQuery.fn["inner" + name] = function() {
  7232. return this[0] ?
  7233. parseFloat( jQuery.css( this[0], type, "padding" ) ) :
  7234. null;
  7235. };
  7236. // outerHeight and outerWidth
  7237. jQuery.fn["outer" + name] = function( margin ) {
  7238. return this[0] ?
  7239. parseFloat( jQuery.css( this[0], type, margin ? "margin" : "border" ) ) :
  7240. null;
  7241. };
  7242. jQuery.fn[ type ] = function( size ) {
  7243. // Get window width or height
  7244. var elem = this[0];
  7245. if ( !elem ) {
  7246. return size == null ? null : this;
  7247. }
  7248. if ( jQuery.isFunction( size ) ) {
  7249. return this.each(function( i ) {
  7250. var self = jQuery( this );
  7251. self[ type ]( size.call( this, i, self[ type ]() ) );
  7252. });
  7253. }
  7254. if ( jQuery.isWindow( elem ) ) {
  7255. // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
  7256. // 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
  7257. var docElemProp = elem.document.documentElement[ "client" + name ];
  7258. return elem.document.compatMode === "CSS1Compat" && docElemProp ||
  7259. elem.document.body[ "client" + name ] || docElemProp;
  7260. // Get document width or height
  7261. } else if ( elem.nodeType === 9 ) {
  7262. // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
  7263. return Math.max(
  7264. elem.documentElement["client" + name],
  7265. elem.body["scroll" + name], elem.documentElement["scroll" + name],
  7266. elem.body["offset" + name], elem.documentElement["offset" + name]
  7267. );
  7268. // Get or set width or height on the element
  7269. } else if ( size === undefined ) {
  7270. var orig = jQuery.css( elem, type ),
  7271. ret = parseFloat( orig );
  7272. return jQuery.isNaN( ret ) ? orig : ret;
  7273. // Set the width or height on the element (default to pixels if value is unitless)
  7274. } else {
  7275. return this.css( type, typeof size === "string" ? size : size + "px" );
  7276. }
  7277. };
  7278. });
  7279. window.jQuery = window.$ = jQuery;
  7280. })(window);
  7281. /*!
  7282. * jQuery UI 1.8.12
  7283. *
  7284. * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
  7285. * Dual licensed under the MIT or GPL Version 2 licenses.
  7286. * http://jquery.org/license
  7287. *
  7288. * http://docs.jquery.com/UI
  7289. */
  7290. (function( $, undefined ) {
  7291. // prevent duplicate loading
  7292. // this is only a problem because we proxy existing functions
  7293. // and we don't want to double proxy them
  7294. $.ui = $.ui || {};
  7295. if ( $.ui.version ) {
  7296. return;
  7297. }
  7298. $.extend( $.ui, {
  7299. version: "1.8.12",
  7300. keyCode: {
  7301. ALT: 18,
  7302. BACKSPACE: 8,
  7303. CAPS_LOCK: 20,
  7304. COMMA: 188,
  7305. COMMAND: 91,
  7306. COMMAND_LEFT: 91, // COMMAND
  7307. COMMAND_RIGHT: 93,
  7308. CONTROL: 17,
  7309. DELETE: 46,
  7310. DOWN: 40,
  7311. END: 35,
  7312. ENTER: 13,
  7313. ESCAPE: 27,
  7314. HOME: 36,
  7315. INSERT: 45,
  7316. LEFT: 37,
  7317. MENU: 93, // COMMAND_RIGHT
  7318. NUMPAD_ADD: 107,
  7319. NUMPAD_DECIMAL: 110,
  7320. NUMPAD_DIVIDE: 111,
  7321. NUMPAD_ENTER: 108,
  7322. NUMPAD_MULTIPLY: 106,
  7323. NUMPAD_SUBTRACT: 109,
  7324. PAGE_DOWN: 34,
  7325. PAGE_UP: 33,
  7326. PERIOD: 190,
  7327. RIGHT: 39,
  7328. SHIFT: 16,
  7329. SPACE: 32,
  7330. TAB: 9,
  7331. UP: 38,
  7332. WINDOWS: 91 // COMMAND
  7333. }
  7334. });
  7335. // plugins
  7336. $.fn.extend({
  7337. _focus: $.fn.focus,
  7338. focus: function( delay, fn ) {
  7339. return typeof delay === "number" ?
  7340. this.each(function() {
  7341. var elem = this;
  7342. setTimeout(function() {
  7343. $( elem ).focus();
  7344. if ( fn ) {
  7345. fn.call( elem );
  7346. }
  7347. }, delay );
  7348. }) :
  7349. this._focus.apply( this, arguments );
  7350. },
  7351. scrollParent: function() {
  7352. var scrollParent;
  7353. if (($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
  7354. scrollParent = this.parents().filter(function() {
  7355. return (/(relative|absolute|fixed)/).test($.curCSS(this,'position',1)) && (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
  7356. }).eq(0);
  7357. } else {
  7358. scrollParent = this.parents().filter(function() {
  7359. return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
  7360. }).eq(0);
  7361. }
  7362. return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
  7363. },
  7364. zIndex: function( zIndex ) {
  7365. if ( zIndex !== undefined ) {
  7366. return this.css( "zIndex", zIndex );
  7367. }
  7368. if ( this.length ) {
  7369. var elem = $( this[ 0 ] ), position, value;
  7370. while ( elem.length && elem[ 0 ] !== document ) {
  7371. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  7372. // This makes behavior of this function consistent across browsers
  7373. // WebKit always returns auto if the element is positioned
  7374. position = elem.css( "position" );
  7375. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  7376. // IE returns 0 when zIndex is not specified
  7377. // other browsers return a string
  7378. // we ignore the case of nested elements with an explicit value of 0
  7379. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  7380. value = parseInt( elem.css( "zIndex" ), 10 );
  7381. if ( !isNaN( value ) && value !== 0 ) {
  7382. return value;
  7383. }
  7384. }
  7385. elem = elem.parent();
  7386. }
  7387. }
  7388. return 0;
  7389. },
  7390. disableSelection: function() {
  7391. return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
  7392. ".ui-disableSelection", function( event ) {
  7393. event.preventDefault();
  7394. });
  7395. },
  7396. enableSelection: function() {
  7397. return this.unbind( ".ui-disableSelection" );
  7398. }
  7399. });
  7400. $.each( [ "Width", "Height" ], function( i, name ) {
  7401. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  7402. type = name.toLowerCase(),
  7403. orig = {
  7404. innerWidth: $.fn.innerWidth,
  7405. innerHeight: $.fn.innerHeight,
  7406. outerWidth: $.fn.outerWidth,
  7407. outerHeight: $.fn.outerHeight
  7408. };
  7409. function reduce( elem, size, border, margin ) {
  7410. $.each( side, function() {
  7411. size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0;
  7412. if ( border ) {
  7413. size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0;
  7414. }
  7415. if ( margin ) {
  7416. size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0;
  7417. }
  7418. });
  7419. return size;
  7420. }
  7421. $.fn[ "inner" + name ] = function( size ) {
  7422. if ( size === undefined ) {
  7423. return orig[ "inner" + name ].call( this );
  7424. }
  7425. return this.each(function() {
  7426. $( this ).css( type, reduce( this, size ) + "px" );
  7427. });
  7428. };
  7429. $.fn[ "outer" + name] = function( size, margin ) {
  7430. if ( typeof size !== "number" ) {
  7431. return orig[ "outer" + name ].call( this, size );
  7432. }
  7433. return this.each(function() {
  7434. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  7435. });
  7436. };
  7437. });
  7438. // selectors
  7439. function visible( element ) {
  7440. return !$( element ).parents().andSelf().filter(function() {
  7441. return $.curCSS( this, "visibility" ) === "hidden" ||
  7442. $.expr.filters.hidden( this );
  7443. }).length;
  7444. }
  7445. $.extend( $.expr[ ":" ], {
  7446. data: function( elem, i, match ) {
  7447. return !!$.data( elem, match[ 3 ] );
  7448. },
  7449. focusable: function( element ) {
  7450. var nodeName = element.nodeName.toLowerCase(),
  7451. tabIndex = $.attr( element, "tabindex" );
  7452. if ( "area" === nodeName ) {
  7453. var map = element.parentNode,
  7454. mapName = map.name,
  7455. img;
  7456. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  7457. return false;
  7458. }
  7459. img = $( "img[usemap=#" + mapName + "]" )[0];
  7460. return !!img && visible( img );
  7461. }
  7462. return ( /input|select|textarea|button|object/.test( nodeName )
  7463. ? !element.disabled
  7464. : "a" == nodeName
  7465. ? element.href || !isNaN( tabIndex )
  7466. : !isNaN( tabIndex ))
  7467. // the element and all of its ancestors must be visible
  7468. && visible( element );
  7469. },
  7470. tabbable: function( element ) {
  7471. var tabIndex = $.attr( element, "tabindex" );
  7472. return ( isNaN( tabIndex ) || tabIndex >= 0 ) && $( element ).is( ":focusable" );
  7473. }
  7474. });
  7475. // support
  7476. $(function() {
  7477. var body = document.body,
  7478. div = body.appendChild( div = document.createElement( "div" ) );
  7479. $.extend( div.style, {
  7480. minHeight: "100px",
  7481. height: "auto",
  7482. padding: 0,
  7483. borderWidth: 0
  7484. });
  7485. $.support.minHeight = div.offsetHeight === 100;
  7486. $.support.selectstart = "onselectstart" in div;
  7487. // set display to none to avoid a layout bug in IE
  7488. // http://dev.jquery.com/ticket/4014
  7489. body.removeChild( div ).style.display = "none";
  7490. });
  7491. // deprecated
  7492. $.extend( $.ui, {
  7493. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  7494. plugin: {
  7495. add: function( module, option, set ) {
  7496. var proto = $.ui[ module ].prototype;
  7497. for ( var i in set ) {
  7498. proto.plugins[ i ] = proto.plugins[ i ] || [];
  7499. proto.plugins[ i ].push( [ option, set[ i ] ] );
  7500. }
  7501. },
  7502. call: function( instance, name, args ) {
  7503. var set = instance.plugins[ name ];
  7504. if ( !set || !instance.element[ 0 ].parentNode ) {
  7505. return;
  7506. }
  7507. for ( var i = 0; i < set.length; i++ ) {
  7508. if ( instance.options[ set[ i ][ 0 ] ] ) {
  7509. set[ i ][ 1 ].apply( instance.element, args );
  7510. }
  7511. }
  7512. }
  7513. },
  7514. // will be deprecated when we switch to jQuery 1.4 - use jQuery.contains()
  7515. contains: function( a, b ) {
  7516. return document.compareDocumentPosition ?
  7517. a.compareDocumentPosition( b ) & 16 :
  7518. a !== b && a.contains( b );
  7519. },
  7520. // only used by resizable
  7521. hasScroll: function( el, a ) {
  7522. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  7523. if ( $( el ).css( "overflow" ) === "hidden") {
  7524. return false;
  7525. }
  7526. var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  7527. has = false;
  7528. if ( el[ scroll ] > 0 ) {
  7529. return true;
  7530. }
  7531. // TODO: determine which cases actually cause this to happen
  7532. // if the element doesn't have the scroll set, see if it's possible to
  7533. // set the scroll
  7534. el[ scroll ] = 1;
  7535. has = ( el[ scroll ] > 0 );
  7536. el[ scroll ] = 0;
  7537. return has;
  7538. },
  7539. // these are odd functions, fix the API or move into individual plugins
  7540. isOverAxis: function( x, reference, size ) {
  7541. //Determines when x coordinate is over "b" element axis
  7542. return ( x > reference ) && ( x < ( reference + size ) );
  7543. },
  7544. isOver: function( y, x, top, left, height, width ) {
  7545. //Determines when x, y coordinates is over "b" element
  7546. return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );
  7547. }
  7548. });
  7549. })( jQuery );
  7550. /*!
  7551. * jQuery UI Widget 1.8.12
  7552. *
  7553. * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
  7554. * Dual licensed under the MIT or GPL Version 2 licenses.
  7555. * http://jquery.org/license
  7556. *
  7557. * http://docs.jquery.com/UI/Widget
  7558. */
  7559. (function( $, undefined ) {
  7560. // jQuery 1.4+
  7561. if ( $.cleanData ) {
  7562. var _cleanData = $.cleanData;
  7563. $.cleanData = function( elems ) {
  7564. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  7565. $( elem ).triggerHandler( "remove" );
  7566. }
  7567. _cleanData( elems );
  7568. };
  7569. } else {
  7570. var _remove = $.fn.remove;
  7571. $.fn.remove = function( selector, keepData ) {
  7572. return this.each(function() {
  7573. if ( !keepData ) {
  7574. if ( !selector || $.filter( selector, [ this ] ).length ) {
  7575. $( "*", this ).add( [ this ] ).each(function() {
  7576. $( this ).triggerHandler( "remove" );
  7577. });
  7578. }
  7579. }
  7580. return _remove.call( $(this), selector, keepData );
  7581. });
  7582. };
  7583. }
  7584. $.widget = function( name, base, prototype ) {
  7585. var namespace = name.split( "." )[ 0 ],
  7586. fullName;
  7587. name = name.split( "." )[ 1 ];
  7588. fullName = namespace + "-" + name;
  7589. if ( !prototype ) {
  7590. prototype = base;
  7591. base = $.Widget;
  7592. }
  7593. // create selector for plugin
  7594. $.expr[ ":" ][ fullName ] = function( elem ) {
  7595. return !!$.data( elem, name );
  7596. };
  7597. $[ namespace ] = $[ namespace ] || {};
  7598. $[ namespace ][ name ] = function( options, element ) {
  7599. // allow instantiation without initializing for simple inheritance
  7600. if ( arguments.length ) {
  7601. this._createWidget( options, element );
  7602. }
  7603. };
  7604. var basePrototype = new base();
  7605. // we need to make the options hash a property directly on the new instance
  7606. // otherwise we'll modify the options hash on the prototype that we're
  7607. // inheriting from
  7608. // $.each( basePrototype, function( key, val ) {
  7609. // if ( $.isPlainObject(val) ) {
  7610. // basePrototype[ key ] = $.extend( {}, val );
  7611. // }
  7612. // });
  7613. basePrototype.options = $.extend( true, {}, basePrototype.options );
  7614. $[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
  7615. namespace: namespace,
  7616. widgetName: name,
  7617. widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
  7618. widgetBaseClass: fullName
  7619. }, prototype );
  7620. $.widget.bridge( name, $[ namespace ][ name ] );
  7621. };
  7622. $.widget.bridge = function( name, object ) {
  7623. $.fn[ name ] = function( options ) {
  7624. var isMethodCall = typeof options === "string",
  7625. args = Array.prototype.slice.call( arguments, 1 ),
  7626. returnValue = this;
  7627. // allow multiple hashes to be passed on init
  7628. options = !isMethodCall && args.length ?
  7629. $.extend.apply( null, [ true, options ].concat(args) ) :
  7630. options;
  7631. // prevent calls to internal methods
  7632. if ( isMethodCall && options.charAt( 0 ) === "_" ) {
  7633. return returnValue;
  7634. }
  7635. if ( isMethodCall ) {
  7636. this.each(function() {
  7637. var instance = $.data( this, name ),
  7638. methodValue = instance && $.isFunction( instance[options] ) ?
  7639. instance[ options ].apply( instance, args ) :
  7640. instance;
  7641. // TODO: add this back in 1.9 and use $.error() (see #5972)
  7642. // if ( !instance ) {
  7643. // throw "cannot call methods on " + name + " prior to initialization; " +
  7644. // "attempted to call method '" + options + "'";
  7645. // }
  7646. // if ( !$.isFunction( instance[options] ) ) {
  7647. // throw "no such method '" + options + "' for " + name + " widget instance";
  7648. // }
  7649. // var methodValue = instance[ options ].apply( instance, args );
  7650. if ( methodValue !== instance && methodValue !== undefined ) {
  7651. returnValue = methodValue;
  7652. return false;
  7653. }
  7654. });
  7655. } else {
  7656. this.each(function() {
  7657. var instance = $.data( this, name );
  7658. if ( instance ) {
  7659. instance.option( options || {} )._init();
  7660. } else {
  7661. $.data( this, name, new object( options, this ) );
  7662. }
  7663. });
  7664. }
  7665. return returnValue;
  7666. };
  7667. };
  7668. $.Widget = function( options, element ) {
  7669. // allow instantiation without initializing for simple inheritance
  7670. if ( arguments.length ) {
  7671. this._createWidget( options, element );
  7672. }
  7673. };
  7674. $.Widget.prototype = {
  7675. widgetName: "widget",
  7676. widgetEventPrefix: "",
  7677. options: {
  7678. disabled: false
  7679. },
  7680. _createWidget: function( options, element ) {
  7681. // $.widget.bridge stores the plugin instance, but we do it anyway
  7682. // so that it's stored even before the _create function runs
  7683. $.data( element, this.widgetName, this );
  7684. this.element = $( element );
  7685. this.options = $.extend( true, {},
  7686. this.options,
  7687. this._getCreateOptions(),
  7688. options );
  7689. var self = this;
  7690. this.element.bind( "remove." + this.widgetName, function() {
  7691. self.destroy();
  7692. });
  7693. this._create();
  7694. this._trigger( "create" );
  7695. this._init();
  7696. },
  7697. _getCreateOptions: function() {
  7698. return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
  7699. },
  7700. _create: function() {},
  7701. _init: function() {},
  7702. destroy: function() {
  7703. this.element
  7704. .unbind( "." + this.widgetName )
  7705. .removeData( this.widgetName );
  7706. this.widget()
  7707. .unbind( "." + this.widgetName )
  7708. .removeAttr( "aria-disabled" )
  7709. .removeClass(
  7710. this.widgetBaseClass + "-disabled " +
  7711. "ui-state-disabled" );
  7712. },
  7713. widget: function() {
  7714. return this.element;
  7715. },
  7716. option: function( key, value ) {
  7717. var options = key;
  7718. if ( arguments.length === 0 ) {
  7719. // don't return a reference to the internal hash
  7720. return $.extend( {}, this.options );
  7721. }
  7722. if (typeof key === "string" ) {
  7723. if ( value === undefined ) {
  7724. return this.options[ key ];
  7725. }
  7726. options = {};
  7727. options[ key ] = value;
  7728. }
  7729. this._setOptions( options );
  7730. return this;
  7731. },
  7732. _setOptions: function( options ) {
  7733. var self = this;
  7734. $.each( options, function( key, value ) {
  7735. self._setOption( key, value );
  7736. });
  7737. return this;
  7738. },
  7739. _setOption: function( key, value ) {
  7740. this.options[ key ] = value;
  7741. if ( key === "disabled" ) {
  7742. this.widget()
  7743. [ value ? "addClass" : "removeClass"](
  7744. this.widgetBaseClass + "-disabled" + " " +
  7745. "ui-state-disabled" )
  7746. .attr( "aria-disabled", value );
  7747. }
  7748. return this;
  7749. },
  7750. enable: function() {
  7751. return this._setOption( "disabled", false );
  7752. },
  7753. disable: function() {
  7754. return this._setOption( "disabled", true );
  7755. },
  7756. _trigger: function( type, event, data ) {
  7757. var callback = this.options[ type ];
  7758. event = $.Event( event );
  7759. event.type = ( type === this.widgetEventPrefix ?
  7760. type :
  7761. this.widgetEventPrefix + type ).toLowerCase();
  7762. data = data || {};
  7763. // copy original event properties over to the new event
  7764. // this would happen if we could call $.event.fix instead of $.Event
  7765. // but we don't have a way to force an event to be fixed multiple times
  7766. if ( event.originalEvent ) {
  7767. for ( var i = $.event.props.length, prop; i; ) {
  7768. prop = $.event.props[ --i ];
  7769. event[ prop ] = event.originalEvent[ prop ];
  7770. }
  7771. }
  7772. this.element.trigger( event, data );
  7773. return !( $.isFunction(callback) &&
  7774. callback.call( this.element[0], event, data ) === false ||
  7775. event.isDefaultPrevented() );
  7776. }
  7777. };
  7778. })( jQuery );
  7779. /*!
  7780. * jQuery UI Mouse 1.8.12
  7781. *
  7782. * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
  7783. * Dual licensed under the MIT or GPL Version 2 licenses.
  7784. * http://jquery.org/license
  7785. *
  7786. * http://docs.jquery.com/UI/Mouse
  7787. *
  7788. * Depends:
  7789. * jquery.ui.widget.js
  7790. */
  7791. (function( $, undefined ) {
  7792. $.widget("ui.mouse", {
  7793. options: {
  7794. cancel: ':input,option',
  7795. distance: 1,
  7796. delay: 0
  7797. },
  7798. _mouseInit: function() {
  7799. var self = this;
  7800. this.element
  7801. .bind('mousedown.'+this.widgetName, function(event) {
  7802. return self._mouseDown(event);
  7803. })
  7804. .bind('click.'+this.widgetName, function(event) {
  7805. if (true === $.data(event.target, self.widgetName + '.preventClickEvent')) {
  7806. $.removeData(event.target, self.widgetName + '.preventClickEvent');
  7807. event.stopImmediatePropagation();
  7808. return false;
  7809. }
  7810. });
  7811. this.started = false;
  7812. },
  7813. // TODO: make sure destroying one instance of mouse doesn't mess with
  7814. // other instances of mouse
  7815. _mouseDestroy: function() {
  7816. this.element.unbind('.'+this.widgetName);
  7817. },
  7818. _mouseDown: function(event) {
  7819. // don't let more than one widget handle mouseStart
  7820. // TODO: figure out why we have to use originalEvent
  7821. event.originalEvent = event.originalEvent || {};
  7822. if (event.originalEvent.mouseHandled) { return; }
  7823. // we may have missed mouseup (out of window)
  7824. (this._mouseStarted && this._mouseUp(event));
  7825. this._mouseDownEvent = event;
  7826. var self = this,
  7827. btnIsLeft = (event.which == 1),
  7828. elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
  7829. if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
  7830. return true;
  7831. }
  7832. this.mouseDelayMet = !this.options.delay;
  7833. if (!this.mouseDelayMet) {
  7834. this._mouseDelayTimer = setTimeout(function() {
  7835. self.mouseDelayMet = true;
  7836. }, this.options.delay);
  7837. }
  7838. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  7839. this._mouseStarted = (this._mouseStart(event) !== false);
  7840. if (!this._mouseStarted) {
  7841. event.preventDefault();
  7842. return true;
  7843. }
  7844. }
  7845. // Click event may never have fired (Gecko & Opera)
  7846. if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) {
  7847. $.removeData(event.target, this.widgetName + '.preventClickEvent');
  7848. }
  7849. // these delegates are required to keep context
  7850. this._mouseMoveDelegate = function(event) {
  7851. return self._mouseMove(event);
  7852. };
  7853. this._mouseUpDelegate = function(event) {
  7854. return self._mouseUp(event);
  7855. };
  7856. $(document)
  7857. .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  7858. .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  7859. event.preventDefault();
  7860. event.originalEvent.mouseHandled = true;
  7861. return true;
  7862. },
  7863. _mouseMove: function(event) {
  7864. // IE mouseup check - mouseup happened when mouse was out of window
  7865. if ($.browser.msie && !(document.documentMode >= 9) && !event.button) {
  7866. return this._mouseUp(event);
  7867. }
  7868. if (this._mouseStarted) {
  7869. this._mouseDrag(event);
  7870. return event.preventDefault();
  7871. }
  7872. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  7873. this._mouseStarted =
  7874. (this._mouseStart(this._mouseDownEvent, event) !== false);
  7875. (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
  7876. }
  7877. return !this._mouseStarted;
  7878. },
  7879. _mouseUp: function(event) {
  7880. $(document)
  7881. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  7882. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  7883. if (this._mouseStarted) {
  7884. this._mouseStarted = false;
  7885. if (event.target == this._mouseDownEvent.target) {
  7886. $.data(event.target, this.widgetName + '.preventClickEvent', true);
  7887. }
  7888. this._mouseStop(event);
  7889. }
  7890. return false;
  7891. },
  7892. _mouseDistanceMet: function(event) {
  7893. return (Math.max(
  7894. Math.abs(this._mouseDownEvent.pageX - event.pageX),
  7895. Math.abs(this._mouseDownEvent.pageY - event.pageY)
  7896. ) >= this.options.distance
  7897. );
  7898. },
  7899. _mouseDelayMet: function(event) {
  7900. return this.mouseDelayMet;
  7901. },
  7902. // These are placeholder methods, to be overriden by extending plugin
  7903. _mouseStart: function(event) {},
  7904. _mouseDrag: function(event) {},
  7905. _mouseStop: function(event) {},
  7906. _mouseCapture: function(event) { return true; }
  7907. });
  7908. })(jQuery);
  7909. /*
  7910. * jQuery UI Position 1.8.12
  7911. *
  7912. * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
  7913. * Dual licensed under the MIT or GPL Version 2 licenses.
  7914. * http://jquery.org/license
  7915. *
  7916. * http://docs.jquery.com/UI/Position
  7917. */
  7918. (function( $, undefined ) {
  7919. $.ui = $.ui || {};
  7920. var horizontalPositions = /left|center|right/,
  7921. verticalPositions = /top|center|bottom/,
  7922. center = "center",
  7923. _position = $.fn.position,
  7924. _offset = $.fn.offset;
  7925. $.fn.position = function( options ) {
  7926. if ( !options || !options.of ) {
  7927. return _position.apply( this, arguments );
  7928. }
  7929. // make a copy, we don't want to modify arguments
  7930. options = $.extend( {}, options );
  7931. var target = $( options.of ),
  7932. targetElem = target[0],
  7933. collision = ( options.collision || "flip" ).split( " " ),
  7934. offset = options.offset ? options.offset.split( " " ) : [ 0, 0 ],
  7935. targetWidth,
  7936. targetHeight,
  7937. basePosition;
  7938. if ( targetElem.nodeType === 9 ) {
  7939. targetWidth = target.width();
  7940. targetHeight = target.height();
  7941. basePosition = { top: 0, left: 0 };
  7942. // TODO: use $.isWindow() in 1.9
  7943. } else if ( targetElem.setTimeout ) {
  7944. targetWidth = target.width();
  7945. targetHeight = target.height();
  7946. basePosition = { top: target.scrollTop(), left: target.scrollLeft() };
  7947. } else if ( targetElem.preventDefault ) {
  7948. // force left top to allow flipping
  7949. options.at = "left top";
  7950. targetWidth = targetHeight = 0;
  7951. basePosition = { top: options.of.pageY, left: options.of.pageX };
  7952. } else {
  7953. targetWidth = target.outerWidth();
  7954. targetHeight = target.outerHeight();
  7955. basePosition = target.offset();
  7956. }
  7957. // force my and at to have valid horizontal and veritcal positions
  7958. // if a value is missing or invalid, it will be converted to center
  7959. $.each( [ "my", "at" ], function() {
  7960. var pos = ( options[this] || "" ).split( " " );
  7961. if ( pos.length === 1) {
  7962. pos = horizontalPositions.test( pos[0] ) ?
  7963. pos.concat( [center] ) :
  7964. verticalPositions.test( pos[0] ) ?
  7965. [ center ].concat( pos ) :
  7966. [ center, center ];
  7967. }
  7968. pos[ 0 ] = horizontalPositions.test( pos[0] ) ? pos[ 0 ] : center;
  7969. pos[ 1 ] = verticalPositions.test( pos[1] ) ? pos[ 1 ] : center;
  7970. options[ this ] = pos;
  7971. });
  7972. // normalize collision option
  7973. if ( collision.length === 1 ) {
  7974. collision[ 1 ] = collision[ 0 ];
  7975. }
  7976. // normalize offset option
  7977. offset[ 0 ] = parseInt( offset[0], 10 ) || 0;
  7978. if ( offset.length === 1 ) {
  7979. offset[ 1 ] = offset[ 0 ];
  7980. }
  7981. offset[ 1 ] = parseInt( offset[1], 10 ) || 0;
  7982. if ( options.at[0] === "right" ) {
  7983. basePosition.left += targetWidth;
  7984. } else if ( options.at[0] === center ) {
  7985. basePosition.left += targetWidth / 2;
  7986. }
  7987. if ( options.at[1] === "bottom" ) {
  7988. basePosition.top += targetHeight;
  7989. } else if ( options.at[1] === center ) {
  7990. basePosition.top += targetHeight / 2;
  7991. }
  7992. basePosition.left += offset[ 0 ];
  7993. basePosition.top += offset[ 1 ];
  7994. return this.each(function() {
  7995. var elem = $( this ),
  7996. elemWidth = elem.outerWidth(),
  7997. elemHeight = elem.outerHeight(),
  7998. marginLeft = parseInt( $.curCSS( this, "marginLeft", true ) ) || 0,
  7999. marginTop = parseInt( $.curCSS( this, "marginTop", true ) ) || 0,
  8000. collisionWidth = elemWidth + marginLeft +
  8001. ( parseInt( $.curCSS( this, "marginRight", true ) ) || 0 ),
  8002. collisionHeight = elemHeight + marginTop +
  8003. ( parseInt( $.curCSS( this, "marginBottom", true ) ) || 0 ),
  8004. position = $.extend( {}, basePosition ),
  8005. collisionPosition;
  8006. if ( options.my[0] === "right" ) {
  8007. position.left -= elemWidth;
  8008. } else if ( options.my[0] === center ) {
  8009. position.left -= elemWidth / 2;
  8010. }
  8011. if ( options.my[1] === "bottom" ) {
  8012. position.top -= elemHeight;
  8013. } else if ( options.my[1] === center ) {
  8014. position.top -= elemHeight / 2;
  8015. }
  8016. // prevent fractions (see #5280)
  8017. position.left = Math.round( position.left );
  8018. position.top = Math.round( position.top );
  8019. collisionPosition = {
  8020. left: position.left - marginLeft,
  8021. top: position.top - marginTop
  8022. };
  8023. $.each( [ "left", "top" ], function( i, dir ) {
  8024. if ( $.ui.position[ collision[i] ] ) {
  8025. $.ui.position[ collision[i] ][ dir ]( position, {
  8026. targetWidth: targetWidth,
  8027. targetHeight: targetHeight,
  8028. elemWidth: elemWidth,
  8029. elemHeight: elemHeight,
  8030. collisionPosition: collisionPosition,
  8031. collisionWidth: collisionWidth,
  8032. collisionHeight: collisionHeight,
  8033. offset: offset,
  8034. my: options.my,
  8035. at: options.at
  8036. });
  8037. }
  8038. });
  8039. if ( $.fn.bgiframe ) {
  8040. elem.bgiframe();
  8041. }
  8042. elem.offset( $.extend( position, { using: options.using } ) );
  8043. });
  8044. };
  8045. $.ui.position = {
  8046. fit: {
  8047. left: function( position, data ) {
  8048. var win = $( window ),
  8049. over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft();
  8050. position.left = over > 0 ? position.left - over : Math.max( position.left - data.collisionPosition.left, position.left );
  8051. },
  8052. top: function( position, data ) {
  8053. var win = $( window ),
  8054. over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop();
  8055. position.top = over > 0 ? position.top - over : Math.max( position.top - data.collisionPosition.top, position.top );
  8056. }
  8057. },
  8058. flip: {
  8059. left: function( position, data ) {
  8060. if ( data.at[0] === center ) {
  8061. return;
  8062. }
  8063. var win = $( window ),
  8064. over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft(),
  8065. myOffset = data.my[ 0 ] === "left" ?
  8066. -data.elemWidth :
  8067. data.my[ 0 ] === "right" ?
  8068. data.elemWidth :
  8069. 0,
  8070. atOffset = data.at[ 0 ] === "left" ?
  8071. data.targetWidth :
  8072. -data.targetWidth,
  8073. offset = -2 * data.offset[ 0 ];
  8074. position.left += data.collisionPosition.left < 0 ?
  8075. myOffset + atOffset + offset :
  8076. over > 0 ?
  8077. myOffset + atOffset + offset :
  8078. 0;
  8079. },
  8080. top: function( position, data ) {
  8081. if ( data.at[1] === center ) {
  8082. return;
  8083. }
  8084. var win = $( window ),
  8085. over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop(),
  8086. myOffset = data.my[ 1 ] === "top" ?
  8087. -data.elemHeight :
  8088. data.my[ 1 ] === "bottom" ?
  8089. data.elemHeight :
  8090. 0,
  8091. atOffset = data.at[ 1 ] === "top" ?
  8092. data.targetHeight :
  8093. -data.targetHeight,
  8094. offset = -2 * data.offset[ 1 ];
  8095. position.top += data.collisionPosition.top < 0 ?
  8096. myOffset + atOffset + offset :
  8097. over > 0 ?
  8098. myOffset + atOffset + offset :
  8099. 0;
  8100. }
  8101. }
  8102. };
  8103. // offset setter from jQuery 1.4
  8104. if ( !$.offset.setOffset ) {
  8105. $.offset.setOffset = function( elem, options ) {
  8106. // set position first, in-case top/left are set even on static elem
  8107. if ( /static/.test( $.curCSS( elem, "position" ) ) ) {
  8108. elem.style.position = "relative";
  8109. }
  8110. var curElem = $( elem ),
  8111. curOffset = curElem.offset(),
  8112. curTop = parseInt( $.curCSS( elem, "top", true ), 10 ) || 0,
  8113. curLeft = parseInt( $.curCSS( elem, "left", true ), 10) || 0,
  8114. props = {
  8115. top: (options.top - curOffset.top) + curTop,
  8116. left: (options.left - curOffset.left) + curLeft
  8117. };
  8118. if ( 'using' in options ) {
  8119. options.using.call( elem, props );
  8120. } else {
  8121. curElem.css( props );
  8122. }
  8123. };
  8124. $.fn.offset = function( options ) {
  8125. var elem = this[ 0 ];
  8126. if ( !elem || !elem.ownerDocument ) { return null; }
  8127. if ( options ) {
  8128. return this.each(function() {
  8129. $.offset.setOffset( this, options );
  8130. });
  8131. }
  8132. return _offset.call( this );
  8133. };
  8134. }
  8135. }( jQuery ));
  8136. /**
  8137. * jQuery.ScrollTo
  8138. * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
  8139. * Dual licensed under MIT and GPL.
  8140. * Date: 5/25/2009
  8141. *
  8142. * @projectDescription Easy element scrolling using jQuery.
  8143. * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
  8144. * Works with jQuery +1.2.6. Tested on FF 2/3, IE 6/7/8, Opera 9.5/6, Safari 3, Chrome 1 on WinXP.
  8145. *
  8146. * @author Ariel Flesler
  8147. * @version 1.4.2
  8148. *
  8149. * @id jQuery.scrollTo
  8150. * @id jQuery.fn.scrollTo
  8151. * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements.
  8152. * The different options for target are:
  8153. * - A number position (will be applied to all axes).
  8154. * - A string position ('44', '100px', '+=90', etc ) will be applied to all axes
  8155. * - A jQuery/DOM element ( logically, child of the element to scroll )
  8156. * - A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
  8157. * - A hash { top:x, left:y }, x and y can be any kind of number/string like above.
  8158. * - A percentage of the container's dimension/s, for example: 50% to go to the middle.
  8159. * - The string 'max' for go-to-end.
  8160. * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.
  8161. * @param {Object,Function} settings Optional set of settings or the onAfter callback.
  8162. * @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
  8163. * @option {Number} duration The OVERALL length of the animation.
  8164. * @option {String} easing The easing method for the animation.
  8165. * @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
  8166. * @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.
  8167. * @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.
  8168. * @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
  8169. * @option {Function} onAfter Function to be called after the scrolling ends.
  8170. * @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.
  8171. * @return {jQuery} Returns the same jQuery object, for chaining.
  8172. *
  8173. * @desc Scroll to a fixed position
  8174. * @example $('div').scrollTo( 340 );
  8175. *
  8176. * @desc Scroll relatively to the actual position
  8177. * @example $('div').scrollTo( '+=340px', { axis:'y' } );
  8178. *
  8179. * @dec Scroll using a selector (relative to the scrolled element)
  8180. * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } );
  8181. *
  8182. * @ Scroll to a DOM element (same for jQuery object)
  8183. * @example var second_child = document.getElementById('container').firstChild.nextSibling;
  8184. * $('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){
  8185. * alert('scrolled!!');
  8186. * }});
  8187. *
  8188. * @desc Scroll on both axes, to different values
  8189. * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
  8190. */
  8191. ;(function( $ ){
  8192. var $scrollTo = $.scrollTo = function( target, duration, settings ){
  8193. $(window).scrollTo( target, duration, settings );
  8194. };
  8195. $scrollTo.defaults = {
  8196. axis:'xy',
  8197. duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1
  8198. };
  8199. // Returns the element that needs to be animated to scroll the window.
  8200. // Kept for backwards compatibility (specially for localScroll & serialScroll)
  8201. $scrollTo.window = function( scope ){
  8202. return $(window)._scrollable();
  8203. };
  8204. // Hack, hack, hack :)
  8205. // Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
  8206. $.fn._scrollable = function(){
  8207. return this.map(function(){
  8208. var elem = this,
  8209. isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1;
  8210. if( !isWin )
  8211. return elem;
  8212. var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
  8213. return $.browser.safari || doc.compatMode == 'BackCompat' ?
  8214. doc.body :
  8215. doc.documentElement;
  8216. });
  8217. };
  8218. $.fn.scrollTo = function( target, duration, settings ){
  8219. if( typeof duration == 'object' ){
  8220. settings = duration;
  8221. duration = 0;
  8222. }
  8223. if( typeof settings == 'function' )
  8224. settings = { onAfter:settings };
  8225. if( target == 'max' )
  8226. target = 9e9;
  8227. settings = $.extend( {}, $scrollTo.defaults, settings );
  8228. // Speed is still recognized for backwards compatibility
  8229. duration = duration || settings.speed || settings.duration;
  8230. // Make sure the settings are given right
  8231. settings.queue = settings.queue && settings.axis.length > 1;
  8232. if( settings.queue )
  8233. // Let's keep the overall duration
  8234. duration /= 2;
  8235. settings.offset = both( settings.offset );
  8236. settings.over = both( settings.over );
  8237. return this._scrollable().each(function(){
  8238. var elem = this,
  8239. $elem = $(elem),
  8240. targ = target, toff, attr = {},
  8241. win = $elem.is('html,body');
  8242. switch( typeof targ ){
  8243. // A number will pass the regex
  8244. case 'number':
  8245. case 'string':
  8246. if( /^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ) ){
  8247. targ = both( targ );
  8248. // We are done
  8249. break;
  8250. }
  8251. // Relative selector, no break!
  8252. targ = $(targ,this);
  8253. case 'object':
  8254. // DOMElement / jQuery
  8255. if( targ.is || targ.style )
  8256. // Get the real position of the target
  8257. toff = (targ = $(targ)).offset();
  8258. }
  8259. $.each( settings.axis.split(''), function( i, axis ){
  8260. var Pos = axis == 'x' ? 'Left' : 'Top',
  8261. pos = Pos.toLowerCase(),
  8262. key = 'scroll' + Pos,
  8263. old = elem[key],
  8264. max = $scrollTo.max(elem, axis);
  8265. if( toff ){// jQuery / DOMElement
  8266. attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );
  8267. // If it's a dom element, reduce the margin
  8268. if( settings.margin ){
  8269. attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
  8270. attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
  8271. }
  8272. attr[key] += settings.offset[pos] || 0;
  8273. if( settings.over[pos] )
  8274. // Scroll to a fraction of its width/height
  8275. attr[key] += targ[axis=='x'?'width':'height']() * settings.over[pos];
  8276. }else{
  8277. var val = targ[pos];
  8278. // Handle percentage values
  8279. attr[key] = val.slice && val.slice(-1) == '%' ?
  8280. parseFloat(val) / 100 * max
  8281. : val;
  8282. }
  8283. // Number or 'number'
  8284. if( /^\d+$/.test(attr[key]) )
  8285. // Check the limits
  8286. attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max );
  8287. // Queueing axes
  8288. if( !i && settings.queue ){
  8289. // Don't waste time animating, if there's no need.
  8290. if( old != attr[key] )
  8291. // Intermediate animation
  8292. animate( settings.onAfterFirst );
  8293. // Don't animate this axis again in the next iteration.
  8294. delete attr[key];
  8295. }
  8296. });
  8297. animate( settings.onAfter );
  8298. function animate( callback ){
  8299. $elem.animate( attr, duration, settings.easing, callback && function(){
  8300. callback.call(this, target, settings);
  8301. });
  8302. };
  8303. }).end();
  8304. };
  8305. // Max scrolling position, works on quirks mode
  8306. // It only fails (not too badly) on IE, quirks mode.
  8307. $scrollTo.max = function( elem, axis ){
  8308. var Dim = axis == 'x' ? 'Width' : 'Height',
  8309. scroll = 'scroll'+Dim;
  8310. if( !$(elem).is('html,body') )
  8311. return elem[scroll] - $(elem)[Dim.toLowerCase()]();
  8312. var size = 'client' + Dim,
  8313. html = elem.ownerDocument.documentElement,
  8314. body = elem.ownerDocument.body;
  8315. return Math.max( html[scroll], body[scroll] )
  8316. - Math.min( html[size] , body[size] );
  8317. };
  8318. function both( val ){
  8319. return typeof val == 'object' ? val : { top:val, left:val };
  8320. };
  8321. })( jQuery );/*!
  8322. * Fluid Infusion v1.5
  8323. *
  8324. * Infusion is distributed under the Educational Community License 2.0 and new BSD licenses:
  8325. * http://wiki.fluidproject.org/display/fluid/Fluid+Licensing
  8326. *
  8327. * For information on copyright, see the individual Infusion source code files:
  8328. * https://github.com/fluid-project/infusion/
  8329. */
  8330. /*
  8331. Copyright 2007-2010 University of Cambridge
  8332. Copyright 2007-2009 University of Toronto
  8333. Copyright 2007-2009 University of California, Berkeley
  8334. Copyright 2010-2011 Lucendo Development Ltd.
  8335. Copyright 2010 OCAD University
  8336. Copyright 2011 Charly Molter
  8337. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  8338. BSD license. You may not use this file except in compliance with one these
  8339. Licenses.
  8340. You may obtain a copy of the ECL 2.0 License and BSD License at
  8341. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  8342. */
  8343. // Declare dependencies
  8344. /*global console, window, fluid:true, fluid_1_5:true, jQuery, opera, YAHOO*/
  8345. // JSLint options
  8346. /*jslint white: true, funcinvoke: true, continue: true, jslintok: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  8347. var fluid_1_5 = fluid_1_5 || {};
  8348. var fluid = fluid || fluid_1_5;
  8349. (function ($, fluid) {
  8350. fluid.version = "Infusion 1.5";
  8351. fluid.environment = {
  8352. fluid: fluid
  8353. };
  8354. var globalObject = window || {};
  8355. var softFailure = [false];
  8356. // This function will be patched from FluidIoC.js in order to describe complex activities
  8357. fluid.describeActivity = function () {
  8358. return [];
  8359. };
  8360. /**
  8361. * Causes an error message to be logged to the console and a real runtime error to be thrown.
  8362. *
  8363. * @param {String|Error} message the error message to log
  8364. * @param ... Additional arguments
  8365. */
  8366. fluid.fail = function (message /*, ... */) { // jslint:ok - whitespace in arg list
  8367. fluid.setLogging(true);
  8368. fluid.log.apply(null, ["ASSERTION FAILED: "].concat(fluid.makeArray(arguments)).concat(fluid.describeActivity()));
  8369. if (softFailure[0]) {
  8370. throw new Error(message);
  8371. } else {
  8372. message.fail(); // Intentionally cause a browser error by invoking a nonexistent function.
  8373. }
  8374. };
  8375. fluid.pushSoftFailure = function (condition) {
  8376. if (typeof (condition) === "boolean") {
  8377. softFailure.unshift(condition);
  8378. } else if (condition === -1) {
  8379. softFailure.shift();
  8380. }
  8381. };
  8382. fluid.notrycatch = false;
  8383. // A wrapper for the try/catch/finally language feature, to aid debugging on environments
  8384. // such as IE, where any try will destroy stack information for errors
  8385. fluid.tryCatch = function (tryfun, catchfun, finallyfun) {
  8386. finallyfun = finallyfun || fluid.identity;
  8387. if (fluid.notrycatch) {
  8388. var togo = tryfun();
  8389. finallyfun();
  8390. return togo;
  8391. } else {
  8392. try {
  8393. return tryfun();
  8394. } catch (e) {
  8395. if (catchfun) {
  8396. catchfun(e);
  8397. } else {
  8398. throw (e);
  8399. }
  8400. } finally {
  8401. finallyfun();
  8402. }
  8403. }
  8404. };
  8405. // TODO: rescued from kettleCouchDB.js - clean up in time
  8406. fluid.expect = function (name, members, target) {
  8407. fluid.transform(fluid.makeArray(members), function (key) {
  8408. if (typeof target[key] === "undefined") {
  8409. fluid.fail(name + " missing required parameter " + key);
  8410. }
  8411. });
  8412. };
  8413. // Logging
  8414. var logging;
  8415. /** Returns whether logging is enabled **/
  8416. fluid.isLogging = function () {
  8417. return logging;
  8418. };
  8419. /** method to allow user to enable logging (off by default) */
  8420. fluid.setLogging = function (enabled) {
  8421. if (typeof enabled === "boolean") {
  8422. logging = enabled;
  8423. } else {
  8424. logging = false;
  8425. }
  8426. };
  8427. // On some dodgy environments (notably IE9 and recent alphas of Firebug 1.8),
  8428. // console.log/debug are incomplete function objects and need to be operated via
  8429. // this trick: http://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function
  8430. fluid.applyHostFunction = function (obj, func, args) {
  8431. if (func.apply) {
  8432. func.apply(obj, args);
  8433. } else {
  8434. var applier = Function.prototype.bind.call(func, obj);
  8435. applier.apply(obj, args);
  8436. }
  8437. };
  8438. /** Log a message to a suitable environmental console. If the standard "console"
  8439. * stream is available, the message will be sent there - otherwise either the
  8440. * YAHOO logger or the Opera "postError" stream will be used. Logging must first
  8441. * be enabled with a call to the fluid.setLogging(true) function.
  8442. */
  8443. fluid.log = function (message /*, ... */) { // jslint:ok - whitespace in arg list
  8444. if (logging) {
  8445. var arg0 = fluid.renderTimestamp(new Date()) + ": ";
  8446. var args = [arg0].concat(fluid.makeArray(arguments));
  8447. var str = args.join("");
  8448. if (typeof (console) !== "undefined") {
  8449. if (console.debug) {
  8450. fluid.applyHostFunction(console, console.debug, args);
  8451. } else if (typeof (console.log) === "function") {
  8452. fluid.applyHostFunction(console, console.log, args);
  8453. } else {
  8454. console.log(str); // this branch executes on old IE, fully synthetic console.log
  8455. }
  8456. } else if (typeof (YAHOO) !== "undefined") {
  8457. YAHOO.log(str);
  8458. } else if (typeof (opera) !== "undefined") {
  8459. opera.postError(str);
  8460. }
  8461. }
  8462. };
  8463. // Functional programming utilities.
  8464. /** A basic utility that returns its argument unchanged */
  8465. fluid.identity = function (arg) {
  8466. return arg;
  8467. };
  8468. // Framework and instantiation functions.
  8469. /** Returns true if the argument is a value other than null or undefined **/
  8470. fluid.isValue = function (value) {
  8471. return value !== undefined && value !== null;
  8472. };
  8473. /** Returns true if the argument is a primitive type **/
  8474. fluid.isPrimitive = function (value) {
  8475. var valueType = typeof (value);
  8476. return !value || valueType === "string" || valueType === "boolean" || valueType === "number" || valueType === "function";
  8477. };
  8478. /** Determines whether the supplied object is an array. The strategy used is an optimised
  8479. * approach taken from an earlier version of jQuery - detecting whether the toString() version
  8480. * of the object agrees with the textual form [object Array], or else whether the object is a
  8481. * jQuery object (the most common source of "fake arrays").
  8482. */
  8483. fluid.isArrayable = function (totest) {
  8484. return totest && (totest.jquery || Object.prototype.toString.call(totest) === "[object Array]");
  8485. };
  8486. fluid.isDOMNode = function (obj) {
  8487. // This could be more sound, but messy:
  8488. // http://stackoverflow.com/questions/384286/javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object
  8489. return obj && typeof (obj.nodeType) === "number";
  8490. };
  8491. /** Return an empty container as the same type as the argument (either an
  8492. * array or hash */
  8493. fluid.freshContainer = function (tocopy) {
  8494. return fluid.isArrayable(tocopy) ? [] : {};
  8495. };
  8496. /** Performs a deep copy (clone) of its argument **/
  8497. fluid.copy = function (tocopy) {
  8498. if (fluid.isPrimitive(tocopy)) {
  8499. return tocopy;
  8500. }
  8501. return $.extend(true, fluid.freshContainer(tocopy), tocopy);
  8502. };
  8503. /** Corrected version of jQuery makeArray that returns an empty array on undefined rather than crashing.
  8504. * We don't deal with as many pathological cases as jQuery **/
  8505. fluid.makeArray = function (arg) {
  8506. var togo = [];
  8507. if (arg !== null && arg !== undefined) {
  8508. if (fluid.isPrimitive(arg) || typeof(arg.length) !== "number") {
  8509. togo.push(arg);
  8510. }
  8511. else {
  8512. for (var i = 0; i < arg.length; ++ i) {
  8513. togo[i] = arg[i];
  8514. }
  8515. }
  8516. }
  8517. return togo;
  8518. };
  8519. function transformInternal(source, togo, key, args) {
  8520. var transit = source[key];
  8521. for (var j = 0; j < args.length - 1; ++j) {
  8522. transit = args[j + 1](transit, key);
  8523. }
  8524. togo[key] = transit;
  8525. }
  8526. /** Return a list or hash of objects, transformed by one or more functions. Similar to
  8527. * jQuery.map, only will accept an arbitrary list of transformation functions and also
  8528. * works on non-arrays.
  8529. * @param source {Array or Object} The initial container of objects to be transformed.
  8530. * @param fn1, fn2, etc. {Function} An arbitrary number of optional further arguments,
  8531. * all of type Function, accepting the signature (object, index), where object is the
  8532. * list member to be transformed, and index is its list index. Each function will be
  8533. * applied in turn to each list member, which will be replaced by the return value
  8534. * from the function.
  8535. * @return The finally transformed list, where each member has been replaced by the
  8536. * original member acted on by the function or functions.
  8537. */
  8538. fluid.transform = function (source) {
  8539. var togo = fluid.freshContainer(source);
  8540. if (fluid.isArrayable(source)) {
  8541. for (var i = 0; i < source.length; ++i) {
  8542. transformInternal(source, togo, i, arguments);
  8543. }
  8544. } else {
  8545. for (var key in source) {
  8546. transformInternal(source, togo, key, arguments);
  8547. }
  8548. }
  8549. return togo;
  8550. };
  8551. /** Better jQuery.each which works on hashes as well as having the arguments
  8552. * the right way round.
  8553. * @param source {Arrayable or Object} The container to be iterated over
  8554. * @param func {Function} A function accepting (value, key) for each iterated
  8555. * object. This function may return a value to terminate the iteration
  8556. */
  8557. fluid.each = function (source, func) {
  8558. if (fluid.isArrayable(source)) {
  8559. for (var i = 0; i < source.length; ++i) {
  8560. func(source[i], i);
  8561. }
  8562. } else {
  8563. for (var key in source) {
  8564. func(source[key], key);
  8565. }
  8566. }
  8567. };
  8568. /** Scan through a list or hash of objects, terminating on the first member which
  8569. * matches a predicate function.
  8570. * @param source {Arrayable or Object} The list or hash of objects to be searched.
  8571. * @param func {Function} A predicate function, acting on a member. A predicate which
  8572. * returns any value which is not <code>undefined</code> will terminate
  8573. * the search. The function accepts (object, index).
  8574. * @param deflt {Object} A value to be returned in the case no predicate function matches
  8575. * a list member. The default will be the natural value of <code>undefined</code>
  8576. * @return The first return value from the predicate function which is not <code>undefined</code>
  8577. */
  8578. fluid.find = function (source, func, deflt) {
  8579. var disp;
  8580. if (fluid.isArrayable(source)) {
  8581. for (var i = 0; i < source.length; ++i) {
  8582. disp = func(source[i], i);
  8583. if (disp !== undefined) {
  8584. return disp;
  8585. }
  8586. }
  8587. } else {
  8588. for (var key in source) {
  8589. disp = func(source[key], key);
  8590. if (disp !== undefined) {
  8591. return disp;
  8592. }
  8593. }
  8594. }
  8595. return deflt;
  8596. };
  8597. /** Scan through a list of objects, "accumulating" a value over them
  8598. * (may be a straightforward "sum" or some other chained computation).
  8599. * @param list {Array} The list of objects to be accumulated over.
  8600. * @param fn {Function} An "accumulation function" accepting the signature (object, total, index) where
  8601. * object is the list member, total is the "running total" object (which is the return value from the previous function),
  8602. * and index is the index number.
  8603. * @param arg {Object} The initial value for the "running total" object.
  8604. * @return {Object} the final running total object as returned from the final invocation of the function on the last list member.
  8605. */
  8606. fluid.accumulate = function (list, fn, arg) {
  8607. for (var i = 0; i < list.length; ++i) {
  8608. arg = fn(list[i], arg, i);
  8609. }
  8610. return arg;
  8611. };
  8612. /** Can through a list of objects, removing those which match a predicate. Similar to
  8613. * jQuery.grep, only acts on the list in-place by removal, rather than by creating
  8614. * a new list by inclusion.
  8615. * @param source {Array|Object} The list of objects to be scanned over.
  8616. * @param fn {Function} A predicate function determining whether an element should be
  8617. * removed. This accepts the standard signature (object, index) and returns a "truthy"
  8618. * result in order to determine that the supplied object should be removed from the list.
  8619. * @return The list, transformed by the operation of removing the matched elements. The
  8620. * supplied list is modified by this operation.
  8621. */
  8622. fluid.remove_if = function (source, fn) {
  8623. if (fluid.isArrayable(source)) {
  8624. for (var i = 0; i < source.length; ++i) {
  8625. if (fn(source[i], i)) {
  8626. source.splice(i, 1);
  8627. --i;
  8628. }
  8629. }
  8630. } else {
  8631. for (var key in source) {
  8632. if (fn(source[key], key)) {
  8633. delete source[key];
  8634. }
  8635. }
  8636. }
  8637. return source;
  8638. };
  8639. /** Accepts an object to be filtered, and a list of keys. Either all keys not present in
  8640. * the list are removed, or only keys present in the list are returned.
  8641. * @param toFilter {Array|Object} The object to be filtered - this will be modified by the operation
  8642. * @param keys {Array of String} The list of keys to operate with
  8643. * @param exclude {boolean} If <code>true</code>, the keys listed are removed rather than included
  8644. * @return the filtered object (the same object that was supplied as <code>toFilter</code>
  8645. */
  8646. fluid.filterKeys = function (toFilter, keys, exclude) {
  8647. return fluid.remove_if($.extend({}, toFilter), function (value, key) {
  8648. return exclude ^ ($.inArray(key, keys) === -1);
  8649. });
  8650. };
  8651. /** A convenience wrapper for <code>fluid.filterKeys</code> with the parameter <code>exclude</code> set to <code>true</code>
  8652. * Returns the supplied object with listed keys removed */
  8653. fluid.censorKeys = function (toCensor, keys) {
  8654. return fluid.filterKeys(toCensor, keys, true);
  8655. };
  8656. /** Return the keys in the supplied object as an array **/
  8657. fluid.keys = function (obj) {
  8658. var togo = [];
  8659. fluid.each(obj, function (value, key) {
  8660. togo.push(key);
  8661. });
  8662. return togo;
  8663. };
  8664. /**
  8665. * Searches through the supplied object, and returns <code>true</code> if the supplied value
  8666. * can be found
  8667. */
  8668. fluid.contains = function (obj, value) {
  8669. return obj ? fluid.find(obj, function (thisValue, key) {
  8670. if (value === thisValue) {
  8671. return true;
  8672. }
  8673. }) : undefined;
  8674. };
  8675. /**
  8676. * Searches through the supplied object for the first value which matches the one supplied.
  8677. * @param obj {Object} the Object to be searched through
  8678. * @param value {Object} the value to be found. This will be compared against the object's
  8679. * member using === equality.
  8680. * @return {String} The first key whose value matches the one supplied, or <code>null</code> if no
  8681. * such key is found.
  8682. */
  8683. fluid.keyForValue = function (obj, value) {
  8684. return fluid.find(obj, function (thisValue, key) {
  8685. if (value === thisValue) {
  8686. return key;
  8687. }
  8688. });
  8689. };
  8690. /**
  8691. * This method is now deprecated and will be removed in a future release of Infusion.
  8692. * See fluid.keyForValue instead.
  8693. */
  8694. fluid.findKeyInObject = fluid.keyForValue;
  8695. /** Converts an array into an object whose keys are the elements of the array, each with the value "true"
  8696. */
  8697. fluid.arrayToHash = function (array) {
  8698. var togo = {};
  8699. fluid.each(array, function (el) {
  8700. togo[el] = true;
  8701. });
  8702. return togo;
  8703. };
  8704. /**
  8705. * Clears an object or array of its contents. For objects, each property is deleted.
  8706. *
  8707. * @param {Object|Array} target the target to be cleared
  8708. */
  8709. fluid.clear = function (target) {
  8710. if (fluid.isArrayable(target)) {
  8711. target.length = 0;
  8712. } else {
  8713. for (var i in target) {
  8714. delete target[i];
  8715. }
  8716. }
  8717. };
  8718. /**
  8719. * @param boolean ascending <code>true</code> if a comparator is to be returned which
  8720. * sorts strings in descending order of length
  8721. */
  8722. fluid.compareStringLength = function (ascending) {
  8723. return ascending ? function (a, b) {
  8724. return a.length - b.length;
  8725. } : function (a, b) {
  8726. return b.length - a.length;
  8727. };
  8728. };
  8729. // Model functions
  8730. fluid.model = {}; // cannot call registerNamespace yet since it depends on fluid.model
  8731. /** Another special "marker object" representing that a distinguished
  8732. * (probably context-dependent) value should be substituted.
  8733. */
  8734. fluid.VALUE = {type: "fluid.marker", value: "VALUE"};
  8735. /** Another special "marker object" representing that no value is present (where
  8736. * signalling using the value "undefined" is not possible) */
  8737. fluid.NO_VALUE = {type: "fluid.marker", value: "NO_VALUE"};
  8738. /** A marker indicating that a value requires to be expanded after component construction begins **/
  8739. fluid.EXPAND = {type: "fluid.marker", value: "EXPAND"};
  8740. /** A marker indicating that a value requires to be expanded immediately**/
  8741. fluid.EXPAND_NOW = {type: "fluid.marker", value: "EXPAND_NOW"};
  8742. /** Determine whether an object is any marker, or a particular marker - omit the
  8743. * 2nd argument to detect any marker
  8744. */
  8745. fluid.isMarker = function (totest, type) {
  8746. if (!totest || typeof (totest) !== 'object' || totest.type !== "fluid.marker") {
  8747. return false;
  8748. }
  8749. if (!type) {
  8750. return true;
  8751. }
  8752. return totest === type;
  8753. };
  8754. /** Copy a source "model" onto a target **/
  8755. fluid.model.copyModel = function (target, source) {
  8756. fluid.clear(target);
  8757. $.extend(true, target, source);
  8758. };
  8759. /** Parse an EL expression separated by periods (.) into its component segments.
  8760. * @param {String} EL The EL expression to be split
  8761. * @return {Array of String} the component path expressions.
  8762. * TODO: This needs to be upgraded to handle (the same) escaping rules (as RSF), so that
  8763. * path segments containing periods and backslashes etc. can be processed, and be harmonised
  8764. * with the more complex implementations in fluid.pathUtil(data binding).
  8765. */
  8766. fluid.model.parseEL = function (EL) {
  8767. return EL === "" ? [] : String(EL).split('.');
  8768. };
  8769. /** Compose an EL expression from two separate EL expressions. The returned
  8770. * expression will be the one that will navigate the first expression, and then
  8771. * the second, from the value reached by the first. Either prefix or suffix may be
  8772. * the empty string **/
  8773. fluid.model.composePath = function (prefix, suffix) {
  8774. return prefix === "" ? suffix : (suffix === "" ? prefix : prefix + "." + suffix);
  8775. };
  8776. /** Compose any number of path segments, none of which may be empty **/
  8777. fluid.model.composeSegments = function () {
  8778. return fluid.makeArray(arguments).join(".");
  8779. };
  8780. /** Helpful alias for old-style API **/
  8781. fluid.path = fluid.model.composeSegments;
  8782. fluid.composePath = fluid.model.composePath;
  8783. // unsupported, NON-API function
  8784. fluid.requireDataBinding = function () {
  8785. fluid.fail("Please include DataBinding.js in order to operate complex model accessor configuration");
  8786. };
  8787. fluid.model.trundle = fluid.model.getPenultimate = fluid.requireDataBinding;
  8788. // unsupported, NON-API function
  8789. fluid.model.resolvePathSegment = function (root, segment, create, origEnv) {
  8790. if (!origEnv && root.resolvePathSegment) {
  8791. return root.resolvePathSegment(segment);
  8792. }
  8793. if (create && root[segment] === undefined) {
  8794. // This optimisation in this heavily used function has a fair effect
  8795. return root[segment] = {};
  8796. }
  8797. return root[segment];
  8798. };
  8799. // unsupported, NON-API function
  8800. fluid.model.getPenultimateSimple = function (root, EL, environment, create) {
  8801. var origEnv = environment;
  8802. var segs = fluid.model.parseEL(EL);
  8803. for (var i = 0; i < segs.length - 1; ++i) {
  8804. if (!root) {
  8805. return {root: root };
  8806. }
  8807. var segment = segs[i];
  8808. if (environment && environment[segment]) {
  8809. root = environment[segment];
  8810. environment = null;
  8811. } else {
  8812. root = fluid.model.resolvePathSegment(root, segment, create, origEnv);
  8813. }
  8814. }
  8815. return {root: root, last: segs[segs.length - 1]};
  8816. };
  8817. fluid.model.setSimple = function (root, EL, newValue, environment) {
  8818. var pen = fluid.model.getPenultimateSimple(root, EL, environment, true);
  8819. pen.root[pen.last] = newValue;
  8820. };
  8821. /** Evaluates an EL expression by fetching a dot-separated list of members
  8822. * recursively from a provided root.
  8823. * @param root The root data structure in which the EL expression is to be evaluated
  8824. * @param {string} EL The EL expression to be evaluated
  8825. * @param environment An optional "environment" which, if it contains any members
  8826. * at top level, will take priority over the root data structure.
  8827. * @return The fetched data value.
  8828. */
  8829. fluid.model.getSimple = function (root, EL, environment) {
  8830. if (EL === "" || EL === null || EL === undefined) {
  8831. return root;
  8832. }
  8833. var pen = fluid.model.getPenultimateSimple(root, EL, environment);
  8834. return pen.root ? pen.root[pen.last] : pen.root;
  8835. };
  8836. // unsupported, NON-API function
  8837. // Returns undefined to signal complex configuration which needs to be farmed out to DataBinding.js
  8838. // any other return represents an environment value AND a simple configuration we can handle here
  8839. fluid.decodeAccessorArg = function (arg3) {
  8840. return (!arg3 || arg3 === fluid.model.defaultGetConfig || arg3 === fluid.model.defaultSetConfig) ?
  8841. null : (arg3.type === "environment" ? arg3.value : undefined);
  8842. };
  8843. fluid.set = function (root, EL, newValue, config) {
  8844. var env = fluid.decodeAccessorArg(config);
  8845. if (env === undefined) {
  8846. var trundler = fluid.model.getPenultimate(root, EL, config);
  8847. trundler.root[trundler.last] = newValue;
  8848. } else {
  8849. fluid.model.setSimple(root, EL, newValue, env);
  8850. }
  8851. };
  8852. /** Evaluates an EL expression by fetching a dot-separated list of members
  8853. * recursively from a provided root.
  8854. * @param root The root data structure in which the EL expression is to be evaluated
  8855. * @param {string} EL The EL expression to be evaluated
  8856. * @param environment An optional "environment" which, if it contains any members
  8857. * at top level, will take priority over the root data structure.
  8858. * @return The fetched data value.
  8859. */
  8860. fluid.get = function (root, EL, config) {
  8861. var env = fluid.decodeAccessorArg(config);
  8862. return env === undefined ?
  8863. fluid.model.trundle(root, EL, config).root
  8864. : fluid.model.getSimple(root, EL, env);
  8865. };
  8866. // This backward compatibility will be maintained for a number of releases, probably until Fluid 2.0
  8867. fluid.model.setBeanValue = fluid.set;
  8868. fluid.model.getBeanValue = fluid.get;
  8869. fluid.getGlobalValue = function (path, env) {
  8870. if (path) {
  8871. env = env || fluid.environment;
  8872. return fluid.get(globalObject, path, {type: "environment", value: env});
  8873. }
  8874. };
  8875. /**
  8876. * Allows for the calling of a function from an EL expression "functionPath", with the arguments "args", scoped to an framework version "environment".
  8877. * @param {Object} functionPath - An EL expression
  8878. * @param {Object} args - An array of arguments to be applied to the function, specified in functionPath
  8879. * @param {Object} environment - (optional) The object to scope the functionPath to (typically the framework root for version control)
  8880. */
  8881. fluid.invokeGlobalFunction = function (functionPath, args, environment) {
  8882. var func = fluid.getGlobalValue(functionPath, environment);
  8883. if (!func) {
  8884. fluid.fail("Error invoking global function: " + functionPath + " could not be located");
  8885. } else {
  8886. return func.apply(null, args);
  8887. }
  8888. };
  8889. /** Registers a new global function at a given path (currently assumes that
  8890. * it lies within the fluid namespace)
  8891. */
  8892. fluid.registerGlobalFunction = function (functionPath, func, env) {
  8893. env = env || fluid.environment;
  8894. fluid.set(globalObject, functionPath, func, {type: "environment", value: env});
  8895. };
  8896. fluid.setGlobalValue = fluid.registerGlobalFunction;
  8897. /** Ensures that an entry in the global namespace exists **/
  8898. fluid.registerNamespace = function (naimspace, env) {
  8899. env = env || fluid.environment;
  8900. var existing = fluid.getGlobalValue(naimspace, env);
  8901. if (!existing) {
  8902. existing = {};
  8903. fluid.setGlobalValue(naimspace, existing, env);
  8904. }
  8905. return existing;
  8906. };
  8907. // stubs for two functions in FluidDebugging.js
  8908. fluid.dumpEl = fluid.identity;
  8909. fluid.renderTimestamp = fluid.identity;
  8910. /*** The Model Events system. ***/
  8911. fluid.registerNamespace("fluid.event");
  8912. fluid.generateUniquePrefix = function () {
  8913. return (Math.floor(Math.random() * 1e12)).toString(36) + "-";
  8914. };
  8915. var fluid_prefix = fluid.generateUniquePrefix();
  8916. var fluid_guid = 1;
  8917. /** Allocate an string value that will be very likely unique within this (browser) process **/
  8918. fluid.allocateGuid = function () {
  8919. return fluid_prefix + (fluid_guid++);
  8920. };
  8921. fluid.event.identifyListener = function (listener) {
  8922. if (typeof (listener) === "string") {
  8923. return listener;
  8924. }
  8925. if (!listener.$$guid) {
  8926. listener.$$guid = fluid.allocateGuid();
  8927. }
  8928. return listener.$$guid;
  8929. };
  8930. // unsupported, NON-API function
  8931. fluid.event.mapPriority = function (priority, count) {
  8932. return (priority === null || priority === undefined ? -count :
  8933. (priority === "last" ? -Number.MAX_VALUE :
  8934. (priority === "first" ? Number.MAX_VALUE : priority)));
  8935. };
  8936. // unsupported, NON-API function
  8937. fluid.event.listenerComparator = function (recA, recB) {
  8938. return recB.priority - recA.priority;
  8939. };
  8940. // unsupported, NON-API function
  8941. fluid.event.sortListeners = function (listeners) {
  8942. var togo = [];
  8943. fluid.each(listeners, function (listener) {
  8944. togo.push(listener);
  8945. });
  8946. return togo.sort(fluid.event.listenerComparator);
  8947. };
  8948. // unsupported, NON-API function
  8949. fluid.event.resolveListener = function (listener) {
  8950. if (typeof (listener) === "string") {
  8951. var listenerFunc = fluid.getGlobalValue(listener);
  8952. if (!listenerFunc) {
  8953. fluid.fail("Unable to look up name " + listener + " as a global function");
  8954. } else {
  8955. listener = listenerFunc;
  8956. }
  8957. }
  8958. return listener;
  8959. };
  8960. fluid.event.nameEvent = function (that, eventName) {
  8961. return eventName + " of " + fluid.nameComponent(that);
  8962. };
  8963. /** Construct an "event firer" object which can be used to register and deregister
  8964. * listeners, to which "events" can be fired. These events consist of an arbitrary
  8965. * function signature. General documentation on the Fluid events system is at
  8966. * http://wiki.fluidproject.org/display/fluid/The+Fluid+Event+System .
  8967. * @param {Boolean} unicast If <code>true</code>, this is a "unicast" event which may only accept
  8968. * a single listener.
  8969. * @param {Boolean} preventable If <code>true</code> the return value of each handler will
  8970. * be checked for <code>false</code> in which case further listeners will be shortcircuited, and this
  8971. * will be the return value of fire()
  8972. */
  8973. // This name will be deprecated in Fluid 2.0 for fluid.makeEventFirer (or fluid.eventFirer)
  8974. fluid.event.getEventFirer = function (unicast, preventable, name) {
  8975. var listeners = {};
  8976. var sortedListeners = [];
  8977. function fireToListeners(listeners, args, wrapper) {
  8978. fluid.log("Firing event " + name + " to list of " + listeners.length + " listeners");
  8979. for (var i = 0; i < listeners.length; ++i) {
  8980. var lisrec = listeners[i];
  8981. lisrec.listener = fluid.event.resolveListener(lisrec.listener);
  8982. var listener = lisrec.listener;
  8983. if (lisrec.predicate && !lisrec.predicate(listener, args)) {
  8984. continue;
  8985. }
  8986. var value = fluid.tryCatch(function () {
  8987. var ret = (wrapper ? wrapper(listener) : listener).apply(null, args);
  8988. if (preventable && ret === false) {
  8989. return false;
  8990. }
  8991. if (unicast) {
  8992. return ret;
  8993. }
  8994. }, function (e) { // jslint:ok - function within a loop, only invoked synchronously
  8995. fluid.log("FireEvent received exception " + e.message + " e " + e + " firing to listener " + i);
  8996. throw (e);
  8997. }); // jslint:ok - function within loop
  8998. if (value !== undefined) {
  8999. return value;
  9000. }
  9001. }
  9002. }
  9003. return {
  9004. name: name,
  9005. typeName: "fluid.event.firer",
  9006. addListener: function (listener, namespace, predicate, priority) {
  9007. if (!listener) {
  9008. return;
  9009. }
  9010. if (unicast) {
  9011. namespace = "unicast";
  9012. }
  9013. if (!namespace) {
  9014. namespace = fluid.event.identifyListener(listener);
  9015. }
  9016. listeners[namespace] = {listener: listener, predicate: predicate, priority:
  9017. fluid.event.mapPriority(priority, sortedListeners.length)};
  9018. sortedListeners = fluid.event.sortListeners(listeners);
  9019. },
  9020. removeListener: function (listener) {
  9021. if (typeof (listener) === 'string') {
  9022. delete listeners[listener];
  9023. } else if (listener.$$guid) {
  9024. delete listeners[listener.$$guid];
  9025. }
  9026. sortedListeners = fluid.event.sortListeners(listeners);
  9027. },
  9028. // NB - this method exists currently solely for the convenience of the new,
  9029. // transactional changeApplier. As it exists it is hard to imagine the function
  9030. // being helpful to any other client. We need to get more experience on the kinds
  9031. // of listeners that are useful, and ultimately factor this method away.
  9032. fireToListeners: function (listeners, args, wrapper) {
  9033. return fireToListeners(listeners, args, wrapper);
  9034. },
  9035. fire: function () {
  9036. return fireToListeners(sortedListeners, arguments);
  9037. }
  9038. };
  9039. };
  9040. fluid.makeEventFirer = fluid.event.getEventFirer;
  9041. /** Fire the specified event with supplied arguments. This call is an optimisation utility
  9042. * which handles the case where the firer has not been instantiated (presumably as a result
  9043. * of having no listeners registered
  9044. */
  9045. fluid.fireEvent = function (firer, args) {
  9046. if (firer) {
  9047. firer.fire.apply(null, fluid.makeArray(args));
  9048. }
  9049. };
  9050. // unsupported, NON-API function
  9051. fluid.event.addListenerToFirer = function (firer, value, namespace) {
  9052. if (fluid.isArrayable(value)) {
  9053. for (var i = 0; i < value.length; ++i) {
  9054. fluid.event.addListenerToFirer(firer, value[i], namespace);
  9055. }
  9056. } else if (typeof (value) === "function" || typeof (value) === "string") {
  9057. firer.addListener(value, namespace);
  9058. } else if (value && typeof (value) === "object") {
  9059. firer.addListener(value.listener, namespace || value.namespace, value.predicate, value.priority);
  9060. }
  9061. };
  9062. fluid.event.resolveListenerRecord = fluid.identity; // non-IOC passthrough
  9063. // unsupported, NON-API function
  9064. fluid.mergeListeners = function (that, events, listeners) {
  9065. fluid.each(listeners, function (value, key) {
  9066. var firer, namespace;
  9067. if (key.charAt(0) === "{") {
  9068. if (!fluid.expandOptions) {
  9069. fluid.fail("fluid.expandOptions could not be loaded - please include FluidIoC.js in order to operate IoC-driven event with descriptor " +
  9070. key);
  9071. }
  9072. firer = fluid.expandOptions(key, that);
  9073. } else {
  9074. var keydot = key.indexOf(".");
  9075. if (keydot !== -1) {
  9076. namespace = key.substring(keydot + 1);
  9077. key = key.substring(0, keydot);
  9078. }
  9079. if (!events[key]) {
  9080. fluid.fail("Listener registered for event " + key + " which is not defined for this component");
  9081. events[key] = fluid.makeEventFirer(null, null, fluid.event.nameEvent(that, key));
  9082. }
  9083. firer = events[key];
  9084. }
  9085. value = fluid.event.resolveListenerRecord(value, that, key);
  9086. fluid.event.addListenerToFirer(firer, value, namespace);
  9087. });
  9088. };
  9089. function initEvents(that, events, pass) {
  9090. fluid.each(events, function (eventSpec, eventKey) {
  9091. var isIoCEvent = eventSpec && (typeof (eventSpec) !== "string" || eventSpec.charAt(0) === "{");
  9092. var event;
  9093. if (isIoCEvent && pass === "IoC") {
  9094. if (!fluid.event.resolveEvent) {
  9095. fluid.fail("fluid.event.resolveEvent could not be loaded - please include FluidIoC.js in order to operate IoC-driven event with descriptor ",
  9096. eventSpec);
  9097. } else {
  9098. event = fluid.event.resolveEvent(that, eventKey, eventSpec);
  9099. }
  9100. } else if (pass === "flat") {
  9101. event = fluid.makeEventFirer(eventSpec === "unicast", eventSpec === "preventable", fluid.event.nameEvent(that, eventKey));
  9102. }
  9103. if (event) {
  9104. that.events[eventKey] = event;
  9105. }
  9106. });
  9107. }
  9108. // unsupported, NON-API function
  9109. fluid.instantiateFirers = function (that, options) {
  9110. that.events = {};
  9111. // TODO: manual 2-phase instantiation since we have no GINGER WORLD
  9112. initEvents(that, options.events, "flat");
  9113. initEvents(that, options.events, "IoC");
  9114. // TODO: manually expand these late so that members attached to ourselves with preInitFunction can be detected
  9115. //var listeners = fluid.expandOptions ? fluid.expandOptions(options.listeners, that) : options.listeners;
  9116. fluid.mergeListeners(that, that.events, options.listeners);
  9117. };
  9118. fluid.mergeListenerPolicy = function (target, source, key) {
  9119. // cf. triage in mergeListeners
  9120. var hasNamespace = key.charAt(0) !== "{" && key.indexOf(".") !== -1;
  9121. return hasNamespace ? (source ? source : target)
  9122. : fluid.makeArray(target).concat(fluid.makeArray(source));
  9123. };
  9124. fluid.mergeListenersPolicy = function (target, source) {
  9125. target = target || {};
  9126. fluid.each(source, function (listeners, key) {
  9127. target[key] = fluid.mergeListenerPolicy(target[key], listeners, key);
  9128. });
  9129. return target;
  9130. };
  9131. /*** DEFAULTS AND OPTIONS MERGING SYSTEM ***/
  9132. var defaultsStore = {};
  9133. var resolveGradesImpl = function (gs, gradeNames) {
  9134. gradeNames = fluid.makeArray(gradeNames);
  9135. fluid.each(gradeNames, function (gradeName) {
  9136. var options = fluid.rawDefaults(gradeName) || {};
  9137. gs.gradeHash[gradeName] = true;
  9138. gs.gradeChain.push(gradeName);
  9139. gs.optionsChain.push(options);
  9140. fluid.each(options.gradeNames, function (parent) {
  9141. if (!gs.gradeHash[parent]) {
  9142. resolveGradesImpl(gs, parent);
  9143. }
  9144. });
  9145. });
  9146. return gs;
  9147. };
  9148. // unsupported, NON-API function
  9149. fluid.resolveGradeStructure = function (gradeNames) {
  9150. var gradeStruct = {
  9151. gradeChain: [],
  9152. gradeHash: {},
  9153. optionsChain: []
  9154. };
  9155. return resolveGradesImpl(gradeStruct, gradeNames);
  9156. };
  9157. fluid.lifecycleFunctions = {
  9158. preInitFunction: true,
  9159. postInitFunction: true,
  9160. finalInitFunction: true
  9161. };
  9162. fluid.rootMergePolicy = fluid.transform(fluid.lifecycleFunctions, function () {
  9163. return fluid.mergeListenerPolicy;
  9164. });
  9165. var mergedDefaultsCache = {};
  9166. fluid.gradeNamesToKey = function (gradeNames, defaultName) {
  9167. return defaultName + "|" + fluid.makeArray(gradeNames).sort().join("|");
  9168. };
  9169. // unsupported, NON-API function
  9170. fluid.resolveGrade = function (defaults, defaultName, gradeNames) {
  9171. var mergeArgs = [defaults];
  9172. if (gradeNames) {
  9173. var gradeStruct = fluid.resolveGradeStructure(gradeNames);
  9174. mergeArgs = gradeStruct.optionsChain.reverse().concat(mergeArgs).concat({gradeNames: gradeStruct.gradeChain});
  9175. }
  9176. mergeArgs = [fluid.rootMergePolicy, {}].concat(mergeArgs);
  9177. var mergedDefaults = fluid.merge.apply(null, mergeArgs);
  9178. return mergedDefaults;
  9179. };
  9180. fluid.getGradedDefaults = function (defaults, defaultName, gradeNames) {
  9181. var key = fluid.gradeNamesToKey(gradeNames, defaultName);
  9182. var mergedDefaults = mergedDefaultsCache[key];
  9183. if (!mergedDefaults) {
  9184. mergedDefaults = mergedDefaultsCache[key] = fluid.resolveGrade(defaults, defaultName, gradeNames);
  9185. }
  9186. return mergedDefaults;
  9187. };
  9188. // unsupported, NON-API function
  9189. fluid.resolveGradedOptions = function (componentName) {
  9190. var defaults = fluid.rawDefaults(componentName);
  9191. if (!defaults) {
  9192. return defaults;
  9193. } else {
  9194. return fluid.getGradedDefaults(defaults, componentName, defaults.gradeNames);
  9195. }
  9196. };
  9197. // unsupported, NON-API function
  9198. fluid.rawDefaults = function (componentName, options) {
  9199. if (options === undefined) {
  9200. return defaultsStore[componentName];
  9201. } else {
  9202. defaultsStore[componentName] = options;
  9203. }
  9204. };
  9205. fluid.hasGrade = function (options, gradeName) {
  9206. return !options || !options.gradeNames ? false : fluid.contains(options.gradeNames, gradeName);
  9207. };
  9208. /**
  9209. * Retrieves and stores a component's default settings centrally.
  9210. * @param {boolean} (options) if true, manipulate a global option (for the head
  9211. * component) rather than instance options. NB - the use of "global options"
  9212. * is deprecated and will be removed from the framework in release 1.5
  9213. * @param {String} componentName the name of the component
  9214. * @param {Object} (optional) an container of key/value pairs to set
  9215. */
  9216. fluid.defaults = function () {
  9217. var offset = 0;
  9218. if (typeof arguments[0] === "boolean") {
  9219. offset = 1;
  9220. }
  9221. var componentName = (offset === 0 ? "" : "*.global-") + arguments[offset];
  9222. var options = arguments[offset + 1];
  9223. if (options === undefined) {
  9224. return fluid.resolveGradedOptions(componentName);
  9225. } else {
  9226. if (options && options.options) {
  9227. fluid.fail("Probable error in options structure with option named \"options\" - perhaps you meant to write these options at top level in fluid.defaults?");
  9228. }
  9229. fluid.rawDefaults(componentName, options);
  9230. if (fluid.hasGrade(options, "autoInit")) {
  9231. fluid.makeComponent(componentName, fluid.resolveGradedOptions(componentName));
  9232. }
  9233. }
  9234. };
  9235. fluid.makeComponent = function (componentName, options) {
  9236. if (!options.initFunction || !options.gradeNames) {
  9237. fluid.fail("Cannot autoInit component " + componentName + " which does not have an initFunction and gradeName defined");
  9238. }
  9239. var creator = function () {
  9240. return fluid.initComponent(componentName, arguments);
  9241. };
  9242. var existing = fluid.getGlobalValue(componentName);
  9243. if (existing) {
  9244. $.extend(creator, existing);
  9245. }
  9246. fluid.setGlobalValue(componentName, creator);
  9247. };
  9248. fluid.makeComponents = function (components, env) {
  9249. fluid.each(components, function (value, key) {
  9250. var options = {
  9251. gradeNames: fluid.makeArray(value).concat(["autoInit"])
  9252. };
  9253. fluid.defaults(key, options);
  9254. });
  9255. };
  9256. // The base system grade definitions
  9257. fluid.defaults("fluid.littleComponent", {
  9258. initFunction: "fluid.initLittleComponent",
  9259. argumentMap: {
  9260. options: 0
  9261. }
  9262. });
  9263. fluid.defaults("fluid.eventedComponent", {
  9264. gradeNames: ["fluid.littleComponent"],
  9265. mergePolicy: {
  9266. listeners: fluid.mergeListenersPolicy
  9267. }
  9268. });
  9269. fluid.preInitModelComponent = function (that) {
  9270. that.model = that.options.model || {};
  9271. that.applier = that.options.applier || (fluid.makeChangeApplier ? fluid.makeChangeApplier(that.model, that.options.changeApplierOptions) : null);
  9272. };
  9273. fluid.defaults("fluid.modelComponent", {
  9274. gradeNames: ["fluid.littleComponent"],
  9275. preInitFunction: {
  9276. namespace: "preInitModelComponent",
  9277. listener: "fluid.preInitModelComponent"
  9278. },
  9279. mergePolicy: {
  9280. model: "preserve",
  9281. applier: "nomerge"
  9282. }
  9283. });
  9284. /** Generate a name for a component for debugging purposes */
  9285. fluid.nameComponent = function (that) {
  9286. return that ? "component with typename " + that.typeName + " and id " + that.id : "[unknown component]";
  9287. };
  9288. // unsupported, NON-API function
  9289. fluid.guardCircularity = function (seenIds, source, message1, message2) {
  9290. if (source && source.id) {
  9291. if (!seenIds[source.id]) {
  9292. seenIds[source.id] = source;
  9293. } else if (seenIds[source.id] === source) {
  9294. fluid.fail("Circularity in options " + message1 + " - " + fluid.nameComponent(source)
  9295. + " has already been seen" + message2);
  9296. }
  9297. }
  9298. };
  9299. fluid.mergePolicyIs = function (policy, test) {
  9300. return typeof (policy) === "string" && $.inArray(test, policy.split(/\s*,\s*/)) !== -1;
  9301. };
  9302. // Cheapskate implementation which avoids dependency on DataBinding.js
  9303. fluid.model.mergeModel = function (target, source, applier) {
  9304. if (!fluid.isPrimitive(target)) {
  9305. var copySource = fluid.copy(source);
  9306. $.extend(true, source, target);
  9307. $.extend(true, source, copySource);
  9308. }
  9309. return source;
  9310. };
  9311. function mergeImpl(policy, basePath, target, source, thisPolicy, rec) {
  9312. if (fluid.isTracing) {
  9313. fluid.tracing.pathCount.push(basePath);
  9314. }
  9315. if (fluid.mergePolicyIs(thisPolicy, "replace")) {
  9316. fluid.clear(target);
  9317. }
  9318. fluid.guardCircularity(rec.seenIds, source, "merging", " when evaluating path " + basePath + " - please protect components from merging using the \"nomerge\" merge policy");
  9319. for (var name in source) {
  9320. var path = (basePath ? basePath + "." : "") + name;
  9321. var newPolicy = policy && typeof (policy) !== "string" ? policy[path] : policy;
  9322. var funcPolicy = typeof (newPolicy) === "function";
  9323. var thisTarget = target[name];
  9324. var thisSource = source[name];
  9325. var primitiveTarget = fluid.isPrimitive(thisTarget);
  9326. if (thisSource !== undefined) {
  9327. if (!funcPolicy && thisSource !== null && typeof (thisSource) === "object" &&
  9328. !fluid.isDOMNode(thisSource) && !thisSource.jquery && thisSource !== fluid.VALUE &&
  9329. !fluid.mergePolicyIs(newPolicy, "preserve") && !fluid.mergePolicyIs(newPolicy, "nomerge") && !fluid.mergePolicyIs(newPolicy, "noexpand")) {
  9330. if (primitiveTarget) {
  9331. target[name] = thisTarget = fluid.freshContainer(thisSource);
  9332. }
  9333. mergeImpl(policy, path, thisTarget, thisSource, newPolicy, rec);
  9334. } else {
  9335. if (funcPolicy) {
  9336. target[name] = newPolicy.call(null, thisTarget, thisSource, name);
  9337. } else if (!fluid.isValue(thisTarget) || !fluid.mergePolicyIs(newPolicy, "reverse")) {
  9338. // TODO: When "grades" are implemented, grandfather in any paired applier to perform these operations
  9339. // NB: mergePolicy of "preserve" now creates dependency on DataBinding.js
  9340. target[name] = fluid.isValue(thisTarget) && fluid.mergePolicyIs(newPolicy, "preserve") ? fluid.model.mergeModel(thisTarget, thisSource) : thisSource;
  9341. }
  9342. }
  9343. }
  9344. }
  9345. return target;
  9346. }
  9347. /** Merge a collection of options structures onto a target, following an optional policy.
  9348. * This function is typically called automatically, as a result of an invocation of
  9349. * <code>fluid.initLittleComponent</code>. The behaviour of this function is explained more fully on
  9350. * the page http://wiki.fluidproject.org/display/fluid/Options+Merging+for+Fluid+Components .
  9351. * @param policy {Object/String} A "policy object" specifiying the type of merge to be performed.
  9352. * If policy is of type {String} it should take on the value "reverse" or "replace" representing
  9353. * a static policy. If it is an
  9354. * Object, it should contain a mapping of EL paths onto these String values, representing a
  9355. * fine-grained policy. If it is an Object, the values may also themselves be EL paths
  9356. * representing that a default value is to be taken from that path.
  9357. * @param target {Object} The options structure which is to be modified by receiving the merge results.
  9358. * @param options1, options2, .... {Object} an arbitrary list of options structure which are to
  9359. * be merged "on top of" the <code>target</code>. These will not be modified.
  9360. */
  9361. fluid.merge = function (policy, target) {
  9362. var path = "";
  9363. for (var i = 2; i < arguments.length; ++i) {
  9364. var source = arguments[i];
  9365. if (source !== null && source !== undefined) {
  9366. mergeImpl(policy, path, target, source, policy ? policy[""] : null, {seenIds: {}});
  9367. }
  9368. }
  9369. if (policy && typeof (policy) !== "string") {
  9370. for (var key in policy) {
  9371. var elrh = policy[key];
  9372. if (typeof (elrh) === "string" && elrh !== "replace" && elrh !== "preserve") {
  9373. var oldValue = fluid.get(target, key);
  9374. if (oldValue === null || oldValue === undefined) {
  9375. var value = fluid.get(target, elrh);
  9376. fluid.set(target, key, value);
  9377. }
  9378. }
  9379. }
  9380. }
  9381. return target;
  9382. };
  9383. // unsupported, NON-API function
  9384. fluid.transformOptions = function (mergeArgs, transRec) {
  9385. fluid.expect("Options transformation record", ["transformer", "config"], transRec);
  9386. var transFunc = fluid.getGlobalValue(transRec.transformer);
  9387. var togo = fluid.transform(mergeArgs, function (value, key) {
  9388. return key === 0 ? value : transFunc.call(null, value, transRec.config);
  9389. });
  9390. return togo;
  9391. };
  9392. // unsupporter, NON-API function
  9393. fluid.lastTransformationRecord = function (extraArgs) {
  9394. for (var i = extraArgs.length - 1; i >= 0; --i) {
  9395. if (extraArgs[i] && extraArgs[i].transformOptions) {
  9396. return extraArgs[i].transformOptions;
  9397. }
  9398. }
  9399. };
  9400. /**
  9401. * Merges the component's declared defaults, as obtained from fluid.defaults(),
  9402. * with the user's specified overrides.
  9403. *
  9404. * @param {Object} that the instance to attach the options to
  9405. * @param {String} componentName the unique "name" of the component, which will be used
  9406. * to fetch the default options from store. By recommendation, this should be the global
  9407. * name of the component's creator function.
  9408. * @param {Object} userOptions the user-specified configuration options for this component
  9409. */
  9410. // unsupported, NON-API function
  9411. fluid.mergeComponentOptions = function (that, componentName, userOptions, localOptions) {
  9412. var defaults = fluid.defaults(componentName) || {};
  9413. var mergePolicy = $.extend({}, fluid.rootMergePolicy, defaults.mergePolicy);
  9414. var defaultGrades = defaults.gradeNames;
  9415. localOptions = defaultGrades ? {} : fluid.copy(fluid.getGradedDefaults({}, "", localOptions.gradeNames));
  9416. var mergeArgs = [mergePolicy, localOptions];
  9417. var extraArgs;
  9418. if (fluid.expandComponentOptions) {
  9419. extraArgs = fluid.expandComponentOptions(defaults, userOptions, that);
  9420. } else {
  9421. extraArgs = [defaults, userOptions];
  9422. }
  9423. var transRec = fluid.lastTransformationRecord(extraArgs);
  9424. if (transRec) {
  9425. extraArgs = fluid.transformOptions(extraArgs, transRec);
  9426. }
  9427. mergeArgs = mergeArgs.concat(extraArgs);
  9428. that.options = fluid.merge.apply(null, mergeArgs);
  9429. };
  9430. // The Fluid Component System proper
  9431. /** A special "marker object" which is recognised as one of the arguments to
  9432. * fluid.initSubcomponents. This object is recognised by reference equality -
  9433. * where it is found, it is replaced in the actual argument position supplied
  9434. * to the specific subcomponent instance, with the particular options block
  9435. * for that instance attached to the overall "that" object.
  9436. * NOTE: The use of this marker has been deprecated as of the Fluid 1.4 release in
  9437. * favour of the contextual EL path "{options}" - it will be removed in a future
  9438. * release of the framework.
  9439. */
  9440. fluid.COMPONENT_OPTIONS = {type: "fluid.marker", value: "COMPONENT_OPTIONS"};
  9441. /** Construct a dummy or "placeholder" subcomponent, that optionally provides empty
  9442. * implementations for a set of methods.
  9443. */
  9444. fluid.emptySubcomponent = function (options) {
  9445. var that = {};
  9446. options = $.makeArray(options);
  9447. var empty = function () {};
  9448. for (var i = 0; i < options.length; ++i) {
  9449. that[options[i]] = empty;
  9450. }
  9451. return that;
  9452. };
  9453. /** Compute a "nickname" given a fully qualified typename, by returning the last path
  9454. * segment.
  9455. */
  9456. fluid.computeNickName = function (typeName) {
  9457. var segs = fluid.model.parseEL(typeName);
  9458. return segs[segs.length - 1];
  9459. };
  9460. /** Create a "type tag" component with no state but simply a type name and id. The most
  9461. * minimal form of Fluid component */
  9462. fluid.typeTag = function (name) {
  9463. return name ? {
  9464. typeName: name,
  9465. id: fluid.allocateGuid()
  9466. } : null;
  9467. };
  9468. /** A combined "component and grade name" which allows type tags to be declaratively constructed
  9469. * from options material */
  9470. fluid.typeFount = function (options) {
  9471. var that = fluid.initLittleComponent("fluid.typeFount", options);
  9472. return fluid.typeTag(that.options.targetTypeName);
  9473. };
  9474. /**
  9475. * Creates a new "little component": a that-ist object with options merged into it by the framework.
  9476. * This method is a convenience for creating small objects that have options but don't require full
  9477. * View-like features such as the DOM Binder or events
  9478. *
  9479. * @param {Object} name the name of the little component to create
  9480. * @param {Object} options user-supplied options to merge with the defaults
  9481. */
  9482. // NOTE: the 3rd argument localOptions is NOT to be advertised as part of the stable API, it is present
  9483. // just to allow backward compatibility whilst grade specifications are not mandatory
  9484. fluid.initLittleComponent = function (name, options, localOptions) {
  9485. var that = fluid.typeTag(name);
  9486. // TODO: nickName must be available earlier than other merged options so that component may resolve to itself
  9487. that.nickName = options && options.nickName ? options.nickName : fluid.computeNickName(that.typeName);
  9488. localOptions = localOptions || {gradeNames: "fluid.littleComponent"};
  9489. fluid.mergeComponentOptions(that, name, options, localOptions);
  9490. fluid.initLifecycleFunctions(that);
  9491. fluid.fireEvent(that.options.preInitFunction, that);
  9492. if (fluid.hasGrade(that.options, "fluid.eventedComponent")) {
  9493. fluid.instantiateFirers(that, that.options);
  9494. }
  9495. if (!fluid.hasGrade(that.options, "autoInit")) {
  9496. fluid.clearLifecycleFunctions(that.options);
  9497. }
  9498. return that;
  9499. };
  9500. fluid.initLifecycleFunctions = function (that) {
  9501. fluid.each(fluid.lifecycleFunctions, function (func, key) {
  9502. var value = that.options[key];
  9503. if (value) {
  9504. that.options[key] = fluid.makeEventFirer(null, null, key);
  9505. fluid.event.addListenerToFirer(that.options[key], value);
  9506. }
  9507. });
  9508. };
  9509. fluid.clearLifecycleFunctions = function (options) {
  9510. fluid.each(fluid.lifecycleFunctions, function (value, key) {
  9511. delete options[key];
  9512. });
  9513. delete options.initFunction;
  9514. };
  9515. fluid.diagnoseFailedView = fluid.identity;
  9516. fluid.initComponent = function (componentName, initArgs) {
  9517. var options = fluid.defaults(componentName);
  9518. if (!options.gradeNames) {
  9519. fluid.fail("Cannot initialise component " + componentName + " which has no gradeName registered");
  9520. }
  9521. var args = [componentName].concat(fluid.makeArray(initArgs)); // TODO: support different initFunction variants
  9522. var that = fluid.invokeGlobalFunction(options.initFunction, args);
  9523. fluid.diagnoseFailedView(componentName, that, options, args);
  9524. fluid.fireEvent(that.options.postInitFunction, that);
  9525. if (fluid.initDependents) {
  9526. fluid.initDependents(that);
  9527. }
  9528. fluid.fireEvent(that.options.finalInitFunction, that);
  9529. fluid.clearLifecycleFunctions(that.options);
  9530. return that.options.returnedPath ? fluid.get(that, that.options.returnedPath) : that;
  9531. };
  9532. // unsupported, NON-API function
  9533. fluid.initSubcomponentImpl = function (that, entry, args) {
  9534. var togo;
  9535. if (typeof (entry) !== "function") {
  9536. var entryType = typeof (entry) === "string" ? entry : entry.type;
  9537. var globDef = fluid.defaults(true, entryType);
  9538. fluid.merge("reverse", that.options, globDef);
  9539. togo = entryType === "fluid.emptySubcomponent" ?
  9540. fluid.emptySubcomponent(entry.options) :
  9541. fluid.invokeGlobalFunction(entryType, args);
  9542. } else {
  9543. togo = entry.apply(null, args);
  9544. }
  9545. var returnedOptions = togo ? togo.returnedOptions : null;
  9546. if (returnedOptions) {
  9547. fluid.merge(that.options.mergePolicy, that.options, returnedOptions);
  9548. if (returnedOptions.listeners) {
  9549. fluid.mergeListeners(that, that.events, returnedOptions.listeners);
  9550. }
  9551. }
  9552. return togo;
  9553. };
  9554. /** Initialise all the "subcomponents" which are configured to be attached to
  9555. * the supplied top-level component, which share a particular "class name".
  9556. * @param {Component} that The top-level component for which sub-components are
  9557. * to be instantiated. It contains specifications for these subcomponents in its
  9558. * <code>options</code> structure.
  9559. * @param {String} className The "class name" or "category" for the subcomponents to
  9560. * be instantiated. A class name specifies an overall "function" for a class of
  9561. * subcomponents and represents a category which accept the same signature of
  9562. * instantiation arguments.
  9563. * @param {Array of Object} args The instantiation arguments to be passed to each
  9564. * constructed subcomponent. These will typically be members derived from the
  9565. * top-level <code>that</code> or perhaps globally discovered from elsewhere. One
  9566. * of these arguments may be <code>fluid.COMPONENT_OPTIONS</code> in which case this
  9567. * placeholder argument will be replaced by instance-specific options configured
  9568. * into the member of the top-level <code>options</code> structure named for the
  9569. * <code>className</code>
  9570. * @return {Array of Object} The instantiated subcomponents, one for each member
  9571. * of <code>that.options[className]</code>.
  9572. */
  9573. fluid.initSubcomponents = function (that, className, args) {
  9574. var entry = that.options[className];
  9575. if (!entry) {
  9576. return;
  9577. }
  9578. var entries = $.makeArray(entry);
  9579. var optindex = -1;
  9580. var togo = [];
  9581. args = $.makeArray(args);
  9582. for (var i = 0; i < args.length; ++i) {
  9583. if (args[i] === fluid.COMPONENT_OPTIONS) {
  9584. optindex = i;
  9585. }
  9586. }
  9587. for (i = 0; i < entries.length; ++i) {
  9588. entry = entries[i];
  9589. if (optindex !== -1) {
  9590. args[optindex] = entry.options;
  9591. }
  9592. togo[i] = fluid.initSubcomponentImpl(that, entry, args);
  9593. }
  9594. return togo;
  9595. };
  9596. fluid.initSubcomponent = function (that, className, args) {
  9597. return fluid.initSubcomponents(that, className, args)[0];
  9598. };
  9599. // Message resolution and templating
  9600. /**
  9601. * Converts a string to a regexp with the specified flags given in parameters
  9602. * @param {String} a string that has to be turned into a regular expression
  9603. * @param {String} the flags to provide to the reg exp
  9604. */
  9605. fluid.stringToRegExp = function (str, flags) {
  9606. return new RegExp(str.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"), flags);
  9607. };
  9608. /**
  9609. * Simple string template system.
  9610. * Takes a template string containing tokens in the form of "%value".
  9611. * Returns a new string with the tokens replaced by the specified values.
  9612. * Keys and values can be of any data type that can be coerced into a string. Arrays will work here as well.
  9613. *
  9614. * @param {String} template a string (can be HTML) that contains tokens embedded into it
  9615. * @param {object} values a collection of token keys and values
  9616. */
  9617. fluid.stringTemplate = function (template, values) {
  9618. var keys = fluid.keys(values);
  9619. keys = keys.sort(fluid.compareStringLength());
  9620. for (var i = 0; i < keys.length; ++i) {
  9621. var key = keys[i];
  9622. var re = fluid.stringToRegExp("%" + key, "g");
  9623. template = template.replace(re, values[key]);
  9624. }
  9625. return template;
  9626. };
  9627. fluid.messageResolver = function (options) {
  9628. var that = fluid.initLittleComponent("fluid.messageResolver", options);
  9629. that.messageBase = that.options.parseFunc(that.options.messageBase);
  9630. that.lookup = function (messagecodes) {
  9631. var resolved = fluid.messageResolver.resolveOne(that.messageBase, messagecodes);
  9632. if (resolved === undefined) {
  9633. return fluid.find(that.options.parents, function (parent) {
  9634. return parent.lookup(messagecodes);
  9635. });
  9636. } else {
  9637. return {template: resolved, resolveFunc: that.options.resolveFunc};
  9638. }
  9639. };
  9640. that.resolve = function (messagecodes, args) {
  9641. if (!messagecodes) {
  9642. return "[No messagecodes provided]";
  9643. }
  9644. messagecodes = fluid.makeArray(messagecodes);
  9645. var looked = that.lookup(messagecodes);
  9646. return looked ? looked.resolveFunc(looked.template, args) :
  9647. "[Message string for key " + messagecodes[0] + " not found]";
  9648. };
  9649. return that;
  9650. };
  9651. fluid.defaults("fluid.messageResolver", {
  9652. mergePolicy: {
  9653. messageBase: "preserve",
  9654. parents: "nomerge"
  9655. },
  9656. resolveFunc: fluid.stringTemplate,
  9657. parseFunc: fluid.identity,
  9658. messageBase: {},
  9659. parents: []
  9660. });
  9661. fluid.messageResolver.resolveOne = function (messageBase, messagecodes) {
  9662. for (var i = 0; i < messagecodes.length; ++i) {
  9663. var code = messagecodes[i];
  9664. var message = messageBase[code];
  9665. if (message !== undefined) {
  9666. return message;
  9667. }
  9668. }
  9669. };
  9670. /** Converts a data structure consisting of a mapping of keys to message strings,
  9671. * into a "messageLocator" function which maps an array of message codes, to be
  9672. * tried in sequence until a key is found, and an array of substitution arguments,
  9673. * into a substituted message string.
  9674. */
  9675. fluid.messageLocator = function (messageBase, resolveFunc) {
  9676. var resolver = fluid.messageResolver({messageBase: messageBase, resolveFunc: resolveFunc});
  9677. return function (messagecodes, args) {
  9678. return resolver.resolve(messagecodes, args);
  9679. };
  9680. };
  9681. })(jQuery, fluid_1_5);
  9682. /*
  9683. Copyright 2007-2010 University of Cambridge
  9684. Copyright 2007-2009 University of Toronto
  9685. Copyright 2010-2011 Lucendo Development Ltd.
  9686. Copyright 2010 OCAD University
  9687. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  9688. BSD license. You may not use this file except in compliance with one these
  9689. Licenses.
  9690. You may obtain a copy of the ECL 2.0 License and BSD License at
  9691. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  9692. */
  9693. /** This file contains functions which depend on the presence of a DOM document
  9694. * but which do not depend on the contents of Fluid.js **/
  9695. // Declare dependencies
  9696. /*global fluid_1_5:true, jQuery*/
  9697. // JSLint options
  9698. /*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  9699. var fluid_1_5 = fluid_1_5 || {};
  9700. (function ($, fluid) {
  9701. // Private constants.
  9702. var NAMESPACE_KEY = "fluid-scoped-data";
  9703. /**
  9704. * Gets stored state from the jQuery instance's data map.
  9705. * This function is unsupported: It is not really intended for use by implementors.
  9706. */
  9707. fluid.getScopedData = function(target, key) {
  9708. var data = $(target).data(NAMESPACE_KEY);
  9709. return data ? data[key] : undefined;
  9710. };
  9711. /**
  9712. * Stores state in the jQuery instance's data map. Unlike jQuery's version,
  9713. * accepts multiple-element jQueries.
  9714. * This function is unsupported: It is not really intended for use by implementors.
  9715. */
  9716. fluid.setScopedData = function(target, key, value) {
  9717. $(target).each(function() {
  9718. var data = $.data(this, NAMESPACE_KEY) || {};
  9719. data[key] = value;
  9720. $.data(this, NAMESPACE_KEY, data);
  9721. });
  9722. };
  9723. /** Global focus manager - makes use of "focusin" event supported in jquery 1.4.2 or later.
  9724. */
  9725. var lastFocusedElement = null;
  9726. $(document).bind("focusin", function(event){
  9727. lastFocusedElement = event.target;
  9728. });
  9729. fluid.getLastFocusedElement = function() {
  9730. return lastFocusedElement;
  9731. }
  9732. var ENABLEMENT_KEY = "enablement";
  9733. /** Queries or sets the enabled status of a control. An activatable node
  9734. * may be "disabled" in which case its keyboard bindings will be inoperable
  9735. * (but still stored) until it is reenabled again.
  9736. * This function is unsupported: It is not really intended for use by implementors.
  9737. */
  9738. fluid.enabled = function(target, state) {
  9739. target = $(target);
  9740. if (state === undefined) {
  9741. return fluid.getScopedData(target, ENABLEMENT_KEY) !== false;
  9742. }
  9743. else {
  9744. $("*", target).add(target).each(function() {
  9745. if (fluid.getScopedData(this, ENABLEMENT_KEY) !== undefined) {
  9746. fluid.setScopedData(this, ENABLEMENT_KEY, state);
  9747. }
  9748. else if (/select|textarea|input/i.test(this.nodeName)) {
  9749. $(this).prop("disabled", !state);
  9750. }
  9751. });
  9752. fluid.setScopedData(target, ENABLEMENT_KEY, state);
  9753. }
  9754. };
  9755. fluid.initEnablement = function(target) {
  9756. fluid.setScopedData(target, ENABLEMENT_KEY, true);
  9757. };
  9758. // This function is necessary since simulation of focus events by jQuery under IE
  9759. // is not sufficiently good to intercept the "focusin" binding. Any code which triggers
  9760. // focus or blur synthetically throughout the framework and client code must use this function,
  9761. // especially if correct cross-platform interaction is required with the "deadMansBlur" function.
  9762. function applyOp(node, func) {
  9763. node = $(node);
  9764. node.trigger("fluid-"+func);
  9765. node[func]();
  9766. }
  9767. $.each(["focus", "blur"], function(i, name) {
  9768. fluid[name] = function(elem) {
  9769. applyOp(elem, name);
  9770. }
  9771. });
  9772. })(jQuery, fluid_1_5);
  9773. /*
  9774. Copyright 2008-2010 University of Cambridge
  9775. Copyright 2008-2009 University of Toronto
  9776. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  9777. BSD license. You may not use this file except in compliance with one these
  9778. Licenses.
  9779. You may obtain a copy of the ECL 2.0 License and BSD License at
  9780. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  9781. */
  9782. // Declare dependencies
  9783. /*global fluid_1_5:true, jQuery */
  9784. // JSLint options
  9785. /*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  9786. var fluid_1_5 = fluid_1_5 || {};
  9787. (function ($, fluid) {
  9788. fluid.dom = fluid.dom || {};
  9789. // Node walker function for iterateDom.
  9790. var getNextNode = function (iterator) {
  9791. if (iterator.node.firstChild) {
  9792. iterator.node = iterator.node.firstChild;
  9793. iterator.depth += 1;
  9794. return iterator;
  9795. }
  9796. while (iterator.node) {
  9797. if (iterator.node.nextSibling) {
  9798. iterator.node = iterator.node.nextSibling;
  9799. return iterator;
  9800. }
  9801. iterator.node = iterator.node.parentNode;
  9802. iterator.depth -= 1;
  9803. }
  9804. return iterator;
  9805. };
  9806. /**
  9807. * Walks the DOM, applying the specified acceptor function to each element.
  9808. * There is a special case for the acceptor, allowing for quick deletion of elements and their children.
  9809. * Return "delete" from your acceptor function if you want to delete the element in question.
  9810. * Return "stop" to terminate iteration.
  9811. * Implementation note - this utility exists mainly for performance reasons. It was last tested
  9812. * carefully some time ago (around jQuery 1.2) but at that time was around 3-4x faster at raw DOM
  9813. * filtration tasks than the jQuery equivalents, which was an important source of performance loss in the
  9814. * Reorderer component. General clients of the framework should use this method with caution if at all, and
  9815. * the performance issues should be reassessed when we have time.
  9816. *
  9817. * @param {Element} node the node to start walking from
  9818. * @param {Function} acceptor the function to invoke with each DOM element
  9819. * @param {Boolean} allnodes Use <code>true</code> to call acceptor on all nodes,
  9820. * rather than just element nodes (type 1)
  9821. */
  9822. fluid.dom.iterateDom = function (node, acceptor, allNodes) {
  9823. var currentNode = {node: node, depth: 0};
  9824. var prevNode = node;
  9825. var condition;
  9826. while (currentNode.node !== null && currentNode.depth >= 0 && currentNode.depth < fluid.dom.iterateDom.DOM_BAIL_DEPTH) {
  9827. condition = null;
  9828. if (currentNode.node.nodeType === 1 || allNodes) {
  9829. condition = acceptor(currentNode.node, currentNode.depth);
  9830. }
  9831. if (condition) {
  9832. if (condition === "delete") {
  9833. currentNode.node.parentNode.removeChild(currentNode.node);
  9834. currentNode.node = prevNode;
  9835. }
  9836. else if (condition === "stop") {
  9837. return currentNode.node;
  9838. }
  9839. }
  9840. prevNode = currentNode.node;
  9841. currentNode = getNextNode(currentNode);
  9842. }
  9843. };
  9844. // Work around IE circular DOM issue. This is the default max DOM depth on IE.
  9845. // http://msdn2.microsoft.com/en-us/library/ms761392(VS.85).aspx
  9846. fluid.dom.iterateDom.DOM_BAIL_DEPTH = 256;
  9847. /**
  9848. * Checks if the specified container is actually the parent of containee.
  9849. *
  9850. * @param {Element} container the potential parent
  9851. * @param {Element} containee the child in question
  9852. */
  9853. fluid.dom.isContainer = function (container, containee) {
  9854. for (; containee; containee = containee.parentNode) {
  9855. if (container === containee) {
  9856. return true;
  9857. }
  9858. }
  9859. return false;
  9860. };
  9861. /** Return the element text from the supplied DOM node as a single String.
  9862. * Implementation note - this is a special-purpose utility used in the framework in just one
  9863. * position in the Reorderer. It only performs a "shallow" traversal of the text and was intended
  9864. * as a quick and dirty means of extracting element labels where the user had not explicitly provided one.
  9865. * It should not be used by general users of the framework and its presence here needs to be
  9866. * reassessed.
  9867. */
  9868. fluid.dom.getElementText = function (element) {
  9869. var nodes = element.childNodes;
  9870. var text = "";
  9871. for (var i = 0; i < nodes.length; ++i) {
  9872. var child = nodes[i];
  9873. if (child.nodeType === 3) {
  9874. text = text + child.nodeValue;
  9875. }
  9876. }
  9877. return text;
  9878. };
  9879. })(jQuery, fluid_1_5);
  9880. /*
  9881. Copyright 2008-2010 University of Cambridge
  9882. Copyright 2008-2009 University of Toronto
  9883. Copyright 2010 Lucendo Development Ltd.
  9884. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  9885. BSD license. You may not use this file except in compliance with one these
  9886. Licenses.
  9887. You may obtain a copy of the ECL 2.0 License and BSD License at
  9888. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  9889. */
  9890. // Declare dependencies
  9891. /*global fluid_1_5:true, jQuery*/
  9892. // JSLint options
  9893. /*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  9894. fluid_1_5 = fluid_1_5 || {};
  9895. (function ($, fluid) {
  9896. var unUnicode = /(\\u[\dabcdef]{4}|\\x[\dabcdef]{2})/g;
  9897. fluid.unescapeProperties = function (string) {
  9898. string = string.replace(unUnicode, function(match) {
  9899. var code = match.substring(2);
  9900. var parsed = parseInt(code, 16);
  9901. return String.fromCharCode(parsed);
  9902. }
  9903. );
  9904. var pos = 0;
  9905. while (true) {
  9906. var backpos = string.indexOf("\\", pos);
  9907. if (backpos === -1) {
  9908. break;
  9909. }
  9910. if (backpos === string.length - 1) {
  9911. return [string.substring(0, string.length - 1), true];
  9912. }
  9913. var replace = string.charAt(backpos + 1);
  9914. if (replace === "n") replace = "\n";
  9915. if (replace === "r") replace = "\r";
  9916. if (replace === "t") replace = "\t";
  9917. string = string.substring(0, backpos) + replace + string.substring(backpos + 2);
  9918. pos = backpos + 1;
  9919. }
  9920. return [string, false];
  9921. };
  9922. var breakPos = /[^\\][\s:=]/;
  9923. fluid.parseJavaProperties = function(text) {
  9924. // File format described at http://java.sun.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader)
  9925. var togo = {};
  9926. text = text.replace(/\r\n/g, "\n");
  9927. text = text.replace(/\r/g, "\n");
  9928. lines = text.split("\n");
  9929. var contin, key, valueComp, valueRaw, valueEsc;
  9930. for (var i = 0; i < lines.length; ++ i) {
  9931. var line = $.trim(lines[i]);
  9932. if (!line || line.charAt(0) === "#" || line.charAt(0) === '!') {
  9933. continue;
  9934. }
  9935. if (!contin) {
  9936. valueComp = "";
  9937. var breakpos = line.search(breakPos);
  9938. if (breakpos === -1) {
  9939. key = line;
  9940. valueRaw = "";
  9941. }
  9942. else {
  9943. key = $.trim(line.substring(0, breakpos + 1)); // +1 since first char is escape exclusion
  9944. valueRaw = $.trim(line.substring(breakpos + 2));
  9945. if (valueRaw.charAt(0) === ":" || valueRaw.charAt(0) === "=") {
  9946. valueRaw = $.trim(valueRaw.substring(1));
  9947. }
  9948. }
  9949. key = fluid.unescapeProperties(key)[0];
  9950. valueEsc = fluid.unescapeProperties(valueRaw);
  9951. }
  9952. else {
  9953. valueEsc = fluid.unescapeProperties(line);
  9954. }
  9955. contin = valueEsc[1];
  9956. if (!valueEsc[1]) { // this line was not a continuation line - store the value
  9957. togo[key] = valueComp + valueEsc[0];
  9958. }
  9959. else {
  9960. valueComp += valueEsc[0];
  9961. }
  9962. }
  9963. return togo;
  9964. };
  9965. /**
  9966. * Expand a message string with respect to a set of arguments, following a basic
  9967. * subset of the Java MessageFormat rules.
  9968. * http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html
  9969. *
  9970. * The message string is expected to contain replacement specifications such
  9971. * as {0}, {1}, {2}, etc.
  9972. * @param messageString {String} The message key to be expanded
  9973. * @param args {String/Array of String} An array of arguments to be substituted into the message.
  9974. * @return The expanded message string.
  9975. */
  9976. fluid.formatMessage = function (messageString, args) {
  9977. if (!args) {
  9978. return messageString;
  9979. }
  9980. if (typeof(args) === "string") {
  9981. args = [args];
  9982. }
  9983. for (var i = 0; i < args.length; ++ i) {
  9984. messageString = messageString.replace("{" + i + "}", args[i]);
  9985. }
  9986. return messageString;
  9987. };
  9988. })(jQuery, fluid_1_5);
  9989. /*
  9990. Copyright 2007-2010 University of Cambridge
  9991. Copyright 2007-2009 University of Toronto
  9992. Copyright 2007-2009 University of California, Berkeley
  9993. Copyright 2010 OCAD University
  9994. Copyright 2010-2011 Lucendo Development Ltd.
  9995. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  9996. BSD license. You may not use this file except in compliance with one these
  9997. Licenses.
  9998. You may obtain a copy of the ECL 2.0 License and BSD License at
  9999. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  10000. */
  10001. // Declare dependencies
  10002. /*global fluid:true, fluid_1_5:true, jQuery*/
  10003. // JSLint options
  10004. /*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  10005. var fluid_1_5 = fluid_1_5 || {};
  10006. var fluid = fluid || fluid_1_5;
  10007. (function ($, fluid) {
  10008. fluid.renderTimestamp = function (date) {
  10009. var zeropad = function (num, width) {
  10010. if (!width) width = 2;
  10011. var numstr = (num == undefined? "" : num.toString());
  10012. return "00000".substring(5 - width + numstr.length) + numstr;
  10013. }
  10014. return zeropad(date.getHours()) + ":" + zeropad(date.getMinutes()) + ":" + zeropad(date.getSeconds()) + "." + zeropad(date.getMilliseconds(), 3);
  10015. };
  10016. fluid.isTracing = true;
  10017. fluid.registerNamespace("fluid.tracing");
  10018. fluid.tracing.pathCount = [];
  10019. fluid.tracing.summarisePathCount = function (pathCount) {
  10020. pathCount = pathCount || fluid.tracing.pathCount;
  10021. var togo = {};
  10022. for (var i = 0; i < pathCount.length; ++ i) {
  10023. var path = pathCount[i];
  10024. if (!togo[path]) {
  10025. togo[path] = 1;
  10026. }
  10027. else {
  10028. ++togo[path];
  10029. }
  10030. }
  10031. var toReallyGo = [];
  10032. fluid.each(togo, function(el, path) {
  10033. toReallyGo.push({path: path, count: el});
  10034. });
  10035. toReallyGo.sort(function(a, b) {return b.count - a.count});
  10036. return toReallyGo;
  10037. };
  10038. fluid.tracing.condensePathCount = function (prefixes, pathCount) {
  10039. prefixes = fluid.makeArray(prefixes);
  10040. var prefixCount = {};
  10041. fluid.each(prefixes, function(prefix) {
  10042. prefixCount[prefix] = 0;
  10043. });
  10044. var togo = [];
  10045. fluid.each(pathCount, function(el) {
  10046. var path = el.path;
  10047. if (!fluid.find(prefixes, function(prefix) {
  10048. if (path.indexOf(prefix) === 0) {
  10049. prefixCount[prefix] += el.count;
  10050. return true;
  10051. }
  10052. })) {
  10053. togo.push(el);
  10054. }
  10055. });
  10056. fluid.each(prefixCount, function(count, path) {
  10057. togo.unshift({path: path, count: count});
  10058. });
  10059. return togo;
  10060. };
  10061. // Exception stripping code taken from https://github.com/emwendelin/javascript-stacktrace/blob/master/stacktrace.js
  10062. // BSD licence, see header
  10063. fluid.detectStackStyle = function (e) {
  10064. var style = "other";
  10065. var stackStyle = {
  10066. offset: 0
  10067. };
  10068. if (e["arguments"]) {
  10069. style = "chrome";
  10070. } else if (typeof window !== "undefined" && window.opera && e.stacktrace) {
  10071. style = "opera10";
  10072. } else if (e.stack) {
  10073. style = "firefox";
  10074. // Detect FireFox 4-style stacks which are 1 level less deep
  10075. stackStyle.offset = e.stack.indexOf("Trace exception") === -1? 1 : 0;
  10076. } else if (typeof window !== 'undefined' && window.opera && !('stacktrace' in e)) { //Opera 9-
  10077. style = "opera";
  10078. }
  10079. stackStyle.style = style;
  10080. return stackStyle;
  10081. };
  10082. fluid.obtainException = function() {
  10083. try {
  10084. throw new Error("Trace exception");
  10085. }
  10086. catch (e) {
  10087. return e;
  10088. }
  10089. };
  10090. var stackStyle = fluid.detectStackStyle(fluid.obtainException());
  10091. fluid.registerNamespace("fluid.exceptionDecoders");
  10092. fluid.decodeStack = function() {
  10093. if (stackStyle.style !== "firefox") {
  10094. return null;
  10095. }
  10096. var e = fluid.obtainException();
  10097. return fluid.exceptionDecoders[stackStyle.style](e);
  10098. };
  10099. fluid.exceptionDecoders.firefox = function(e) {
  10100. var lines = e.stack.replace(/(?:\n@:0)?\s+$/m, '').replace(/^\(/gm, '{anonymous}(').split('\n');
  10101. return fluid.transform(lines, function(line) {
  10102. var atind = line.indexOf("@");
  10103. return atind === -1? [line] : [line.substring(atind + 1), line.substring(0, atind)];
  10104. });
  10105. };
  10106. fluid.getCallerInfo = function(atDepth) {
  10107. atDepth = (atDepth || 3) - stackStyle.offset;
  10108. var stack = fluid.decodeStack();
  10109. return stack? stack[atDepth][0] : null;
  10110. };
  10111. function generate(c, count) {
  10112. var togo = "";
  10113. for (var i = 0; i < count; ++ i) {
  10114. togo += c;
  10115. }
  10116. return togo;
  10117. }
  10118. function printImpl(obj, small, options) {
  10119. var big = small + options.indentChars;
  10120. if (obj === null) {
  10121. return "null";
  10122. }
  10123. else if (fluid.isPrimitive(obj)) {
  10124. return JSON.stringify(obj);
  10125. }
  10126. else {
  10127. var j = [];
  10128. if (fluid.isArrayable(obj)) {
  10129. if (obj.length === 0) {
  10130. return "[]";
  10131. }
  10132. for (var i = 0; i < obj.length; ++ i) {
  10133. j[i] = printImpl(obj[i], big, options);
  10134. }
  10135. return "[\n" + big + j.join(",\n" + big) + "\n" + small + "]";
  10136. }
  10137. else {
  10138. var i = 0;
  10139. fluid.each(obj, function(value, key) {
  10140. j[i++] = JSON.stringify(key) + ": " + printImpl(value, big, options);
  10141. });
  10142. return "{\n" + big + j.join(",\n" + big) + "\n" + small + "}";
  10143. }
  10144. }
  10145. }
  10146. fluid.prettyPrintJSON = function(obj, options) {
  10147. options = $.extend({indent: 4}, options);
  10148. options.indentChars = generate(" ", options.indent);
  10149. return printImpl(obj, "", options);
  10150. }
  10151. /**
  10152. * Dumps a DOM element into a readily recognisable form for debugging - produces a
  10153. * "semi-selector" summarising its tag name, class and id, whichever are set.
  10154. *
  10155. * @param {jQueryable} element The element to be dumped
  10156. * @return A string representing the element.
  10157. */
  10158. fluid.dumpEl = function (element) {
  10159. var togo;
  10160. if (!element) {
  10161. return "null";
  10162. }
  10163. if (element.nodeType === 3 || element.nodeType === 8) {
  10164. return "[data: " + element.data + "]";
  10165. }
  10166. if (element.nodeType === 9) {
  10167. return "[document: location " + element.location + "]";
  10168. }
  10169. if (!element.nodeType && fluid.isArrayable(element)) {
  10170. togo = "[";
  10171. for (var i = 0; i < element.length; ++ i) {
  10172. togo += fluid.dumpEl(element[i]);
  10173. if (i < element.length - 1) {
  10174. togo += ", ";
  10175. }
  10176. }
  10177. return togo + "]";
  10178. }
  10179. element = $(element);
  10180. togo = element.get(0).tagName;
  10181. if (element.id) {
  10182. togo += "#" + element.id;
  10183. }
  10184. if (element.attr("class")) {
  10185. togo += "." + element.attr("class");
  10186. }
  10187. return togo;
  10188. };
  10189. })(jQuery, fluid_1_5);
  10190. /*
  10191. Copyright 2008-2010 University of Cambridge
  10192. Copyright 2008-2009 University of Toronto
  10193. Copyright 2010-2011 Lucendo Development Ltd.
  10194. Copyright 2010 OCAD University
  10195. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  10196. BSD license. You may not use this file except in compliance with one these
  10197. Licenses.
  10198. You may obtain a copy of the ECL 2.0 License and BSD License at
  10199. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  10200. */
  10201. // Declare dependencies
  10202. /*global fluid_1_5:true, jQuery*/
  10203. // JSLint options
  10204. /*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  10205. var fluid_1_5 = fluid_1_5 || {};
  10206. (function ($, fluid) {
  10207. fluid.BINDING_ROOT_KEY = "fluid-binding-root";
  10208. /** Recursively find any data stored under a given name from a node upwards
  10209. * in its DOM hierarchy **/
  10210. fluid.findData = function (elem, name) {
  10211. while (elem) {
  10212. var data = $.data(elem, name);
  10213. if (data) {
  10214. return data;
  10215. }
  10216. elem = elem.parentNode;
  10217. }
  10218. };
  10219. fluid.bindFossils = function (node, data, fossils) {
  10220. $.data(node, fluid.BINDING_ROOT_KEY, {data: data, fossils: fossils});
  10221. };
  10222. fluid.boundPathForNode = function (node, fossils) {
  10223. node = fluid.unwrap(node);
  10224. var key = node.name || node.id;
  10225. var record = fossils[key];
  10226. return record ? record.EL: null;
  10227. };
  10228. fluid.findForm = function (node) {
  10229. return fluid.findAncestor(node, function (element) {
  10230. return element.nodeName.toLowerCase() === "form";
  10231. });
  10232. };
  10233. /** A generalisation of jQuery.val to correctly handle the case of acquiring and
  10234. * setting the value of clustered radio button/checkbox sets, potentially, given
  10235. * a node corresponding to just one element.
  10236. */
  10237. fluid.value = function (nodeIn, newValue) {
  10238. var node = fluid.unwrap(nodeIn);
  10239. var multiple = false;
  10240. if (node.nodeType === undefined && node.length > 1) {
  10241. node = node[0];
  10242. multiple = true;
  10243. }
  10244. if ("input" !== node.nodeName.toLowerCase() || ! /radio|checkbox/.test(node.type)) {
  10245. // resist changes to contract of jQuery.val() in jQuery 1.5.1 (see FLUID-4113)
  10246. return newValue === undefined? $(node).val() : $(node).val(newValue);
  10247. }
  10248. var name = node.name;
  10249. if (name === undefined) {
  10250. fluid.fail("Cannot acquire value from node " + fluid.dumpEl(node) + " which does not have name attribute set");
  10251. }
  10252. var elements;
  10253. if (multiple) {
  10254. elements = nodeIn;
  10255. }
  10256. else {
  10257. elements = node.ownerDocument.getElementsByName(name);
  10258. var scope = fluid.findForm(node);
  10259. elements = $.grep(elements,
  10260. function (element) {
  10261. if (element.name !== name) {
  10262. return false;
  10263. }
  10264. return !scope || fluid.dom.isContainer(scope, element);
  10265. });
  10266. }
  10267. if (newValue !== undefined) {
  10268. if (typeof(newValue) === "boolean") {
  10269. newValue = (newValue ? "true" : "false");
  10270. }
  10271. // jQuery gets this partially right, but when dealing with radio button array will
  10272. // set all of their values to "newValue" rather than setting the checked property
  10273. // of the corresponding control.
  10274. $.each(elements, function () {
  10275. this.checked = (newValue instanceof Array ?
  10276. $.inArray(this.value, newValue) !== -1 : newValue === this.value);
  10277. });
  10278. }
  10279. else { // this part jQuery will not do - extracting value from <input> array
  10280. var checked = $.map(elements, function (element) {
  10281. return element.checked ? element.value : null;
  10282. });
  10283. return node.type === "radio" ? checked[0] : checked;
  10284. }
  10285. };
  10286. /** "Automatically" apply to whatever part of the data model is
  10287. * relevant, the changed value received at the given DOM node*/
  10288. fluid.applyBoundChange = function (node, newValue, applier) {
  10289. node = fluid.unwrap(node);
  10290. if (newValue === undefined) {
  10291. newValue = fluid.value(node);
  10292. }
  10293. if (node.nodeType === undefined && node.length > 0) {
  10294. node = node[0];
  10295. } // assume here that they share name and parent
  10296. var root = fluid.findData(node, fluid.BINDING_ROOT_KEY);
  10297. if (!root) {
  10298. fluid.fail("Bound data could not be discovered in any node above " + fluid.dumpEl(node));
  10299. }
  10300. var name = node.name;
  10301. var fossil = root.fossils[name];
  10302. if (!fossil) {
  10303. fluid.fail("No fossil discovered for name " + name + " in fossil record above " + fluid.dumpEl(node));
  10304. }
  10305. if (typeof(fossil.oldvalue) === "boolean") { // deal with the case of an "isolated checkbox"
  10306. newValue = newValue[0] ? true: false;
  10307. }
  10308. var EL = root.fossils[name].EL;
  10309. if (applier) {
  10310. applier.fireChangeRequest({path: EL, value: newValue, source: node.id});
  10311. }
  10312. else {
  10313. fluid.set(root.data, EL, newValue);
  10314. }
  10315. };
  10316. /** MODEL ACCESSOR ENGINE (trundler) **/
  10317. /** Standard strategies for resolving path segments **/
  10318. fluid.model.environmentStrategy = function (initEnvironment) {
  10319. return {
  10320. init: function () {
  10321. var environment = initEnvironment;
  10322. return function (root, segment, index) {
  10323. var togo;
  10324. if (environment && environment[segment]) {
  10325. togo = environment[segment];
  10326. }
  10327. environment = null;
  10328. return togo;
  10329. };
  10330. }
  10331. };
  10332. };
  10333. fluid.model.defaultCreatorStrategy = function (root, segment) {
  10334. if (root[segment] === undefined) {
  10335. root[segment] = {};
  10336. return root[segment];
  10337. }
  10338. };
  10339. fluid.model.defaultFetchStrategy = function (root, segment) {
  10340. return segment === "" ? root : root[segment];
  10341. };
  10342. fluid.model.funcResolverStrategy = function (root, segment) {
  10343. if (root.resolvePathSegment) {
  10344. return root.resolvePathSegment(segment);
  10345. }
  10346. };
  10347. fluid.model.defaultGetConfig = {
  10348. strategies: [fluid.model.funcResolverStrategy, fluid.model.defaultFetchStrategy]
  10349. };
  10350. fluid.model.defaultSetConfig = {
  10351. strategies: [fluid.model.funcResolverStrategy, fluid.model.defaultFetchStrategy, fluid.model.defaultCreatorStrategy]
  10352. };
  10353. // unsupported, NON-API function
  10354. fluid.model.applyStrategy = function (strategy, root, segment, index) {
  10355. if (typeof (strategy) === "function") {
  10356. return strategy(root, segment, index);
  10357. } else if (strategy && strategy.next) {
  10358. return strategy.next(root, segment, index);
  10359. }
  10360. };
  10361. // unsupported, NON-API function
  10362. fluid.model.initStrategy = function (baseStrategy, index, oldStrategies) {
  10363. return baseStrategy.init ? baseStrategy.init(oldStrategies ? oldStrategies[index] : undefined) : baseStrategy;
  10364. };
  10365. // unsupported, NON-API function
  10366. fluid.model.makeTrundler = function (root, config, oldStrategies) {
  10367. var that = {
  10368. root: root,
  10369. strategies: fluid.isArrayable(config) ? config :
  10370. fluid.transform(config.strategies, function (strategy, index) {
  10371. return fluid.model.initStrategy(strategy, index, oldStrategies);
  10372. })
  10373. };
  10374. that.trundle = function (EL, uncess) {
  10375. uncess = uncess || 0;
  10376. var newThat = fluid.model.makeTrundler(that.root, config, that.strategies);
  10377. newThat.segs = fluid.model.parseEL(EL);
  10378. newThat.index = 0;
  10379. newThat.step(newThat.segs.length - uncess);
  10380. return newThat;
  10381. };
  10382. that.next = function () {
  10383. if (!that.root) {
  10384. return;
  10385. }
  10386. var accepted;
  10387. for (var i = 0; i < that.strategies.length; ++i) {
  10388. var value = fluid.model.applyStrategy(that.strategies[i], that.root, that.segs[that.index], that.index);
  10389. if (accepted === undefined) {
  10390. accepted = value;
  10391. }
  10392. }
  10393. if (accepted === fluid.NO_VALUE) {
  10394. accepted = undefined;
  10395. }
  10396. that.root = accepted;
  10397. ++that.index;
  10398. };
  10399. that.step = function (limit) {
  10400. for (var i = 0; i < limit; ++i) {
  10401. that.next();
  10402. }
  10403. that.last = that.segs[that.index];
  10404. };
  10405. return that;
  10406. };
  10407. // unsupported, NON-API function
  10408. // core trundling recursion point
  10409. fluid.model.trundleImpl = function (trundler, EL, config, uncess) {
  10410. if (typeof (EL) === "string") {
  10411. trundler = trundler.trundle(EL, uncess);
  10412. } else {
  10413. var key = EL.type || "default";
  10414. var resolver = config.resolvers[key];
  10415. if (!resolver) {
  10416. fluid.fail("Unable to find resolver of type " + key);
  10417. }
  10418. trundler = resolver(EL, trundler) || {};
  10419. if (EL.path && trundler.trundle && trundler.root !== undefined) {
  10420. trundler = fluid.model.trundleImpl(trundler, EL.path, config, uncess);
  10421. }
  10422. }
  10423. return trundler;
  10424. };
  10425. // unsupported, NON-API function
  10426. // entry point for initially unbased trundling
  10427. fluid.model.trundle = function (root, EL, config, uncess) {
  10428. EL = EL || "";
  10429. config = config || fluid.model.defaultGetConfig;
  10430. var trundler = fluid.model.makeTrundler(root, config);
  10431. return fluid.model.trundleImpl(trundler, EL, config, uncess);
  10432. };
  10433. fluid.model.getPenultimate = function (root, EL, config) {
  10434. return fluid.model.trundle(root, EL, config, 1);
  10435. };
  10436. // Implementation notes: The EL path manipulation utilities here are somewhat more thorough
  10437. // and expensive versions of those provided in Fluid.js - there is some duplication of
  10438. // functionality. This is a tradeoff between stability and performance - the versions in
  10439. // Fluid.js are the most frequently used and do not implement escaping of characters .
  10440. // as \. and \ as \\ as the versions here. The implementations here are not quite complete
  10441. // or very performant and are left here partially as an implementation note. Problems will
  10442. // arise if clients manipulate JSON structures containing "." characters in keys as if they
  10443. // are models, treating these is best left until the cases where they occur. The now standard
  10444. // utilities fluid.path(), fluid.parseEL and fluid.composePath are the ones recommended for
  10445. // general users and their implementation can be upgraded if required.
  10446. fluid.pathUtil = {};
  10447. var getPathSegmentImpl = function (accept, path, i) {
  10448. var segment = null; // TODO: rewrite this with regexes and replaces
  10449. if (accept) {
  10450. segment = "";
  10451. }
  10452. var escaped = false;
  10453. var limit = path.length;
  10454. for (; i < limit; ++i) {
  10455. var c = path.charAt(i);
  10456. if (!escaped) {
  10457. if (c === '.') {
  10458. break;
  10459. }
  10460. else if (c === '\\') {
  10461. escaped = true;
  10462. }
  10463. else if (segment !== null) {
  10464. segment += c;
  10465. }
  10466. }
  10467. else {
  10468. escaped = false;
  10469. if (segment !== null) {
  10470. accept += c;
  10471. }
  10472. }
  10473. }
  10474. if (segment !== null) {
  10475. accept[0] = segment;
  10476. }
  10477. return i;
  10478. };
  10479. var globalAccept = []; // TODO: serious reentrancy risk here, why is this impl like this?
  10480. fluid.pathUtil.getPathSegment = function (path, i) {
  10481. getPathSegmentImpl(globalAccept, path, i);
  10482. return globalAccept[0];
  10483. };
  10484. fluid.pathUtil.getHeadPath = function (path) {
  10485. return fluid.pathUtil.getPathSegment(path, 0);
  10486. };
  10487. fluid.pathUtil.getFromHeadPath = function (path) {
  10488. var firstdot = getPathSegmentImpl(null, path, 0);
  10489. return firstdot === path.length ? null
  10490. : path.substring(firstdot + 1);
  10491. };
  10492. function lastDotIndex(path) {
  10493. // TODO: proper escaping rules
  10494. return path.lastIndexOf(".");
  10495. }
  10496. fluid.pathUtil.getToTailPath = function (path) {
  10497. var lastdot = lastDotIndex(path);
  10498. return lastdot === -1 ? null : path.substring(0, lastdot);
  10499. };
  10500. /** Returns the very last path component of a bean path */
  10501. fluid.pathUtil.getTailPath = function (path) {
  10502. var lastdot = lastDotIndex(path);
  10503. return fluid.pathUtil.getPathSegment(path, lastdot + 1);
  10504. };
  10505. var composeSegment = function (prefix, toappend) {
  10506. for (var i = 0; i < toappend.length; ++i) {
  10507. var c = toappend.charAt(i);
  10508. if (c === '.' || c === '\\' || c === '}') {
  10509. prefix += '\\';
  10510. }
  10511. prefix += c;
  10512. }
  10513. return prefix;
  10514. };
  10515. /**
  10516. * Compose a prefix and suffix EL path, where the prefix is already escaped.
  10517. * Prefix may be empty, but not null. The suffix will become escaped.
  10518. */
  10519. fluid.pathUtil.composePath = function (prefix, suffix) {
  10520. if (prefix.length !== 0) {
  10521. prefix += '.';
  10522. }
  10523. return composeSegment(prefix, suffix);
  10524. };
  10525. fluid.pathUtil.matchPath = function (spec, path) {
  10526. var togo = "";
  10527. while (true) {
  10528. if (!spec || path === "") {
  10529. break;
  10530. }
  10531. if (!path) {
  10532. return null;
  10533. }
  10534. var spechead = fluid.pathUtil.getHeadPath(spec);
  10535. var pathhead = fluid.pathUtil.getHeadPath(path);
  10536. // if we fail to match on a specific component, fail.
  10537. if (spechead !== "*" && spechead !== pathhead) {
  10538. return null;
  10539. }
  10540. togo = fluid.pathUtil.composePath(togo, pathhead);
  10541. spec = fluid.pathUtil.getFromHeadPath(spec);
  10542. path = fluid.pathUtil.getFromHeadPath(path);
  10543. }
  10544. return togo;
  10545. };
  10546. /** CHANGE APPLIER **/
  10547. fluid.model.isNullChange = function (model, request, resolverGetConfig) {
  10548. if (request.type === "ADD") {
  10549. var existing = fluid.get(model, request.path, resolverGetConfig);
  10550. if (existing === request.value) {
  10551. return true;
  10552. }
  10553. }
  10554. };
  10555. /** Applies the supplied ChangeRequest object directly to the supplied model.
  10556. */
  10557. fluid.model.applyChangeRequest = function (model, request, resolverSetConfig) {
  10558. var pen = fluid.model.getPenultimate(model, request.path, resolverSetConfig || fluid.model.defaultSetConfig);
  10559. if (request.type === "ADD" || request.type === "MERGE") {
  10560. if (request.path === "" || request.type === "MERGE") {
  10561. if (request.type === "ADD") {
  10562. fluid.clear(pen.root);
  10563. }
  10564. $.extend(true, request.path === "" ? pen.root: pen.root[pen.last], request.value);
  10565. }
  10566. else {
  10567. pen.root[pen.last] = request.value;
  10568. }
  10569. }
  10570. else if (request.type === "DELETE") {
  10571. if (request.path === "") {
  10572. fluid.clear(pen.root);
  10573. }
  10574. else {
  10575. delete pen.root[pen.last];
  10576. }
  10577. }
  10578. };
  10579. // Utility shared between changeApplier and superApplier
  10580. function bindRequestChange(that) {
  10581. that.requestChange = function (path, value, type) {
  10582. var changeRequest = {
  10583. path: path,
  10584. value: value,
  10585. type: type
  10586. };
  10587. that.fireChangeRequest(changeRequest);
  10588. };
  10589. }
  10590. fluid.makeChangeApplier = function (model, options) {
  10591. options = options || {};
  10592. var baseEvents = {
  10593. guards: fluid.event.getEventFirer(false, true, "guard event"),
  10594. postGuards: fluid.event.getEventFirer(false, true, "postGuard event"),
  10595. modelChanged: fluid.event.getEventFirer(false, false, "modelChanged event")
  10596. };
  10597. var that = {
  10598. model: model
  10599. };
  10600. function makeGuardWrapper(cullUnchanged) {
  10601. if (!cullUnchanged) {
  10602. return null;
  10603. }
  10604. var togo = function (guard) {
  10605. return function (model, changeRequest, internalApplier) {
  10606. var oldRet = guard(model, changeRequest, internalApplier);
  10607. if (oldRet === false) {
  10608. return false;
  10609. }
  10610. else {
  10611. if (fluid.model.isNullChange(model, changeRequest)) {
  10612. togo.culled = true;
  10613. return false;
  10614. }
  10615. }
  10616. };
  10617. };
  10618. return togo;
  10619. }
  10620. function wrapListener(listener, spec) {
  10621. var pathSpec = spec;
  10622. var transactional = false;
  10623. var priority = Number.MAX_VALUE;
  10624. if (typeof (spec) !== "string") {
  10625. pathSpec = spec.path;
  10626. transactional = spec.transactional;
  10627. if (spec.priority !== undefined) {
  10628. priority = spec.priority;
  10629. }
  10630. }
  10631. else {
  10632. if (pathSpec.charAt(0) === "!") {
  10633. transactional = true;
  10634. pathSpec = pathSpec.substring(1);
  10635. }
  10636. }
  10637. return function (changePath, fireSpec, accum) {
  10638. var guid = fluid.event.identifyListener(listener);
  10639. var exist = fireSpec.guids[guid];
  10640. if (!exist) {
  10641. var match = fluid.pathUtil.matchPath(pathSpec, changePath);
  10642. if (match !== null) {
  10643. var record = {
  10644. changePath: changePath,
  10645. pathSpec: pathSpec,
  10646. listener: listener,
  10647. priority: priority,
  10648. transactional: transactional
  10649. };
  10650. if (accum) {
  10651. record.accumulate = [accum];
  10652. }
  10653. fireSpec.guids[guid] = record;
  10654. var collection = transactional ? "transListeners": "listeners";
  10655. fireSpec[collection].push(record);
  10656. fireSpec.all.push(record);
  10657. }
  10658. }
  10659. else if (accum) {
  10660. if (!exist.accumulate) {
  10661. exist.accumulate = [];
  10662. }
  10663. exist.accumulate.push(accum);
  10664. }
  10665. };
  10666. }
  10667. function fireFromSpec(name, fireSpec, args, category, wrapper) {
  10668. return baseEvents[name].fireToListeners(fireSpec[category], args, wrapper);
  10669. }
  10670. function fireComparator(recA, recB) {
  10671. return recA.priority - recB.priority;
  10672. }
  10673. function prepareFireEvent(name, changePath, fireSpec, accum) {
  10674. baseEvents[name].fire(changePath, fireSpec, accum);
  10675. fireSpec.all.sort(fireComparator);
  10676. fireSpec.listeners.sort(fireComparator);
  10677. fireSpec.transListeners.sort(fireComparator);
  10678. }
  10679. function makeFireSpec() {
  10680. return {guids: {}, all: [], listeners: [], transListeners: []};
  10681. }
  10682. function getFireSpec(name, changePath) {
  10683. var fireSpec = makeFireSpec();
  10684. prepareFireEvent(name, changePath, fireSpec);
  10685. return fireSpec;
  10686. }
  10687. function fireEvent(name, changePath, args, wrapper) {
  10688. var fireSpec = getFireSpec(name, changePath);
  10689. return fireFromSpec(name, fireSpec, args, "all", wrapper);
  10690. }
  10691. function adaptListener(that, name) {
  10692. that[name] = {
  10693. addListener: function (spec, listener, namespace) {
  10694. baseEvents[name].addListener(wrapListener(listener, spec), namespace);
  10695. },
  10696. removeListener: function (listener) {
  10697. baseEvents[name].removeListener(listener);
  10698. }
  10699. };
  10700. }
  10701. adaptListener(that, "guards");
  10702. adaptListener(that, "postGuards");
  10703. adaptListener(that, "modelChanged");
  10704. function preFireChangeRequest(changeRequest) {
  10705. if (!changeRequest.type) {
  10706. changeRequest.type = "ADD";
  10707. }
  10708. }
  10709. var bareApplier = {
  10710. fireChangeRequest: function (changeRequest) {
  10711. that.fireChangeRequest(changeRequest, true);
  10712. }
  10713. };
  10714. bindRequestChange(bareApplier);
  10715. that.fireChangeRequest = function (changeRequest, defeatGuards) {
  10716. preFireChangeRequest(changeRequest);
  10717. var guardFireSpec = defeatGuards ? null : getFireSpec("guards", changeRequest.path);
  10718. if (guardFireSpec && guardFireSpec.transListeners.length > 0) {
  10719. var ation = that.initiate();
  10720. ation.fireChangeRequest(changeRequest, guardFireSpec);
  10721. ation.commit();
  10722. }
  10723. else {
  10724. if (!defeatGuards) {
  10725. // TODO: this use of "listeners" seems pointless since we have just verified that there are no transactional listeners
  10726. var prevent = fireFromSpec("guards", guardFireSpec, [model, changeRequest, bareApplier], "listeners");
  10727. if (prevent === false) {
  10728. return false;
  10729. }
  10730. }
  10731. var oldModel = model;
  10732. if (!options.thin) {
  10733. oldModel = {};
  10734. fluid.model.copyModel(oldModel, model);
  10735. }
  10736. fluid.model.applyChangeRequest(model, changeRequest, options.resolverSetConfig);
  10737. fireEvent("modelChanged", changeRequest.path, [model, oldModel, [changeRequest]]);
  10738. }
  10739. };
  10740. bindRequestChange(that);
  10741. function fireAgglomerated(eventName, formName, changes, args, accpos) {
  10742. var fireSpec = makeFireSpec();
  10743. for (var i = 0; i < changes.length; ++ i) {
  10744. prepareFireEvent(eventName, changes[i].path, fireSpec, changes[i]);
  10745. }
  10746. for (var j = 0; j < fireSpec[formName].length; ++ j) {
  10747. var spec = fireSpec[formName][j];
  10748. if (accpos) {
  10749. args[accpos] = spec.accumulate;
  10750. }
  10751. var ret = spec.listener.apply(null, args);
  10752. if (ret === false) {
  10753. return false;
  10754. }
  10755. }
  10756. }
  10757. that.initiate = function (newModel) {
  10758. var cancelled = false;
  10759. var changes = [];
  10760. if (options.thin) {
  10761. newModel = model;
  10762. }
  10763. else {
  10764. newModel = newModel || {};
  10765. fluid.model.copyModel(newModel, model);
  10766. }
  10767. // the guard in the inner world is given a private applier to "fast track"
  10768. // and glob collateral changes it requires
  10769. var internalApplier =
  10770. {fireChangeRequest: function (changeRequest) {
  10771. preFireChangeRequest(changeRequest);
  10772. fluid.model.applyChangeRequest(newModel, changeRequest, options.resolverSetConfig);
  10773. changes.push(changeRequest);
  10774. }};
  10775. bindRequestChange(internalApplier);
  10776. var ation = {
  10777. commit: function () {
  10778. var oldModel;
  10779. if (cancelled) {
  10780. return false;
  10781. }
  10782. var ret = fireAgglomerated("postGuards", "transListeners", changes, [newModel, null, internalApplier], 1);
  10783. if (ret === false) {
  10784. return false;
  10785. }
  10786. if (options.thin) {
  10787. oldModel = model;
  10788. }
  10789. else {
  10790. oldModel = {};
  10791. fluid.model.copyModel(oldModel, model);
  10792. fluid.clear(model);
  10793. fluid.model.copyModel(model, newModel);
  10794. }
  10795. fireAgglomerated("modelChanged", "all", changes, [model, oldModel, null], 2);
  10796. },
  10797. fireChangeRequest: function (changeRequest) {
  10798. preFireChangeRequest(changeRequest);
  10799. if (options.cullUnchanged && fluid.model.isNullChange(model, changeRequest, options.resolverGetConfig)) {
  10800. return;
  10801. }
  10802. var wrapper = makeGuardWrapper(options.cullUnchanged);
  10803. var prevent = fireEvent("guards", changeRequest.path, [newModel, changeRequest, internalApplier], wrapper);
  10804. if (prevent === false && !(wrapper && wrapper.culled)) {
  10805. cancelled = true;
  10806. }
  10807. if (!cancelled) {
  10808. if (!(wrapper && wrapper.culled)) {
  10809. fluid.model.applyChangeRequest(newModel, changeRequest, options.resolverSetConfig);
  10810. changes.push(changeRequest);
  10811. }
  10812. }
  10813. }
  10814. };
  10815. bindRequestChange(ation);
  10816. return ation;
  10817. };
  10818. return that;
  10819. };
  10820. fluid.makeSuperApplier = function () {
  10821. var subAppliers = [];
  10822. var that = {};
  10823. that.addSubApplier = function (path, subApplier) {
  10824. subAppliers.push({path: path, subApplier: subApplier});
  10825. };
  10826. that.fireChangeRequest = function (request) {
  10827. for (var i = 0; i < subAppliers.length; ++ i) {
  10828. var path = subAppliers[i].path;
  10829. if (request.path.indexOf(path) === 0) {
  10830. var subpath = request.path.substring(path.length + 1);
  10831. var subRequest = fluid.copy(request);
  10832. subRequest.path = subpath;
  10833. // TODO: Deal with the as yet unsupported case of an EL rvalue DAR
  10834. subAppliers[i].subApplier.fireChangeRequest(subRequest);
  10835. }
  10836. }
  10837. };
  10838. bindRequestChange(that);
  10839. return that;
  10840. };
  10841. fluid.attachModel = function (baseModel, path, model) {
  10842. var segs = fluid.model.parseEL(path);
  10843. for (var i = 0; i < segs.length - 1; ++ i) {
  10844. var seg = segs[i];
  10845. var subModel = baseModel[seg];
  10846. if (!subModel) {
  10847. baseModel[seg] = subModel = {};
  10848. }
  10849. baseModel = subModel;
  10850. }
  10851. baseModel[segs[segs.length - 1]] = model;
  10852. };
  10853. fluid.assembleModel = function (modelSpec) {
  10854. var model = {};
  10855. var superApplier = fluid.makeSuperApplier();
  10856. var togo = {model: model, applier: superApplier};
  10857. for (var path in modelSpec) {
  10858. var rec = modelSpec[path];
  10859. fluid.attachModel(model, path, rec.model);
  10860. if (rec.applier) {
  10861. superApplier.addSubApplier(path, rec.applier);
  10862. }
  10863. }
  10864. return togo;
  10865. };
  10866. })(jQuery, fluid_1_5);
  10867. /*
  10868. Copyright 2010 University of Toronto
  10869. Copyright 2010-2011 OCAD University
  10870. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  10871. BSD license. You may not use this file except in compliance with one these
  10872. Licenses.
  10873. You may obtain a copy of the ECL 2.0 License and BSD License at
  10874. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  10875. */
  10876. // Declare dependencies
  10877. /*global fluid:true, fluid_1_5:true, jQuery*/
  10878. // JSLint options
  10879. /*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  10880. var fluid_1_5 = fluid_1_5 || {};
  10881. var fluid = fluid || fluid_1_5;
  10882. (function ($) {
  10883. fluid.model = fluid.model || {};
  10884. fluid.model.transform = fluid.model.transform || {};
  10885. /******************************
  10886. * General Model Transformers *
  10887. ******************************/
  10888. fluid.model.transform.value = function (model, expandSpec, recurse) {
  10889. var val;
  10890. if (expandSpec.path) {
  10891. val = fluid.get(model, expandSpec.path);
  10892. if (typeof(val) !== "undefined") {
  10893. return val;
  10894. }
  10895. }
  10896. return typeof(expandSpec.value) === "object" ? recurse(model, expandSpec.value) : expandSpec.value;
  10897. };
  10898. fluid.model.transform.arrayValue = function (model, expandSpec, recurse) {
  10899. return fluid.makeArray(fluid.model.transform.value(model, expandSpec));
  10900. };
  10901. fluid.model.transform.count = function (model, expandSpec, recurse) {
  10902. var value = fluid.get(model, expandSpec.path);
  10903. return fluid.makeArray(value).length;
  10904. };
  10905. fluid.model.transform.firstValue = function (model, expandSpec, recurse) {
  10906. var result;
  10907. for (var i = 0; i < expandSpec.values.length; i++) {
  10908. var value = expandSpec.values[i];
  10909. if (typeof(value) === "string") {
  10910. value = fixupExpandSpec(value);
  10911. }
  10912. result = fluid.model.transform.value(model, value.expander, recurse);
  10913. if (typeof(result) !== "undefined") {
  10914. break;
  10915. }
  10916. }
  10917. return result;
  10918. };
  10919. var getOrRecurse = function (model, value, recurse) {
  10920. return typeof(value) === "string" ? fluid.get(model, value) : recurse(model, value, recurse);
  10921. };
  10922. fluid.model.transform.merge = function (model, expandSpec, recurse) {
  10923. var left = getOrRecurse(model, expandSpec.left, recurse);
  10924. var right = getOrRecurse(model, expandSpec.right, recurse);
  10925. if (typeof(left) !== "object" || typeof(right) !== "object") {
  10926. return left;
  10927. }
  10928. return fluid.merge(expandSpec.policy ? expandSpec.policy : null, {}, left, right);
  10929. };
  10930. var fixupExpandSpec = function (expandSpec) {
  10931. return {
  10932. expander: {
  10933. type: "fluid.model.transform.value",
  10934. path: expandSpec
  10935. }
  10936. };
  10937. };
  10938. var expandRule = function (model, targetPath, rule) {
  10939. var expanded = {};
  10940. for (var key in rule) {
  10941. var value = rule[key];
  10942. if (key === "expander") {
  10943. var expanderFn = fluid.getGlobalValue(value.type);
  10944. if (expanderFn) {
  10945. expanded = expanderFn.call(null, model, value, fluid.model.transformWithRules);
  10946. }
  10947. } else {
  10948. expanded[key] = fluid.model.transformWithRules(model, value);
  10949. }
  10950. }
  10951. return expanded;
  10952. };
  10953. /**
  10954. * Transforms a model based on a specified expansion rules objects.
  10955. * Rules objects take the form of:
  10956. * {
  10957. * "target.path": "value.el.path" || {
  10958. * expander: {
  10959. * type: "expander.function.path",
  10960. * ...
  10961. * }
  10962. * }
  10963. * }
  10964. *
  10965. * @param {Object} model the model to transform
  10966. * @param {Object} rules a rules object containing instructions on how to transform the model
  10967. */
  10968. fluid.model.transformWithRules = function (model, rules) {
  10969. var transformed;
  10970. rules = fluid.makeArray(rules);
  10971. fluid.each(rules, function (rulesObj) {
  10972. transformed = {};
  10973. for (var targetPath in rulesObj) {
  10974. var rule = rulesObj[targetPath];
  10975. if (typeof(rule) === "string") {
  10976. rule = fixupExpandSpec(rule);
  10977. }
  10978. var expanded = expandRule(model, targetPath, rule);
  10979. if (typeof(expanded) !== "undefined") {
  10980. fluid.set(transformed, targetPath, expanded);
  10981. }
  10982. };
  10983. model = transformed;
  10984. });
  10985. return transformed;
  10986. };
  10987. })(jQuery, fluid_1_5);
  10988. /*
  10989. Copyright 2008-2010 University of Cambridge
  10990. Copyright 2008-2010 University of Toronto
  10991. Copyright 2010-2011 Lucendo Development Ltd.
  10992. Copyright 2010-2011 OCAD University
  10993. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  10994. BSD license. You may not use this file except in compliance with one these
  10995. Licenses.
  10996. You may obtain a copy of the ECL 2.0 License and BSD License at
  10997. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  10998. */
  10999. // Declare dependencies
  11000. /*global fluid:true, fluid_1_5:true, jQuery*/
  11001. // JSLint options
  11002. /*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  11003. var fluid_1_5 = fluid_1_5 || {};
  11004. var fluid = fluid || fluid_1_5;
  11005. (function ($, fluid) {
  11006. // $().fluid("selectable", args)
  11007. // $().fluid("selectable".that()
  11008. // $().fluid("pager.pagerBar", args)
  11009. // $().fluid("reorderer", options)
  11010. /** Create a "bridge" from code written in the Fluid standard "that-ist" style,
  11011. * to the standard JQuery UI plugin architecture specified at http://docs.jquery.com/UI/Guidelines .
  11012. * Every Fluid component corresponding to the top-level standard signature (JQueryable, options)
  11013. * will automatically convert idiomatically to the JQuery UI standard via this adapter.
  11014. * Any return value which is a primitive or array type will become the return value
  11015. * of the "bridged" function - however, where this function returns a general hash
  11016. * (object) this is interpreted as forming part of the Fluid "return that" pattern,
  11017. * and the function will instead be bridged to "return this" as per JQuery standard,
  11018. * permitting chaining to occur. However, as a courtesy, the particular "this" returned
  11019. * will be augmented with a function that() which will allow the original return
  11020. * value to be retrieved if desired.
  11021. * @param {String} name The name under which the "plugin space" is to be injected into
  11022. * JQuery
  11023. * @param {Object} peer The root of the namespace corresponding to the peer object.
  11024. */
  11025. fluid.thatistBridge = function (name, peer) {
  11026. var togo = function(funcname) {
  11027. var segs = funcname.split(".");
  11028. var move = peer;
  11029. for (var i = 0; i < segs.length; ++i) {
  11030. move = move[segs[i]];
  11031. }
  11032. var args = [this];
  11033. if (arguments.length === 2) {
  11034. args = args.concat($.makeArray(arguments[1]));
  11035. }
  11036. var ret = move.apply(null, args);
  11037. this.that = function() {
  11038. return ret;
  11039. }
  11040. var type = typeof(ret);
  11041. return !ret || type === "string" || type === "number" || type === "boolean"
  11042. || ret && ret.length !== undefined? ret: this;
  11043. };
  11044. $.fn[name] = togo;
  11045. return togo;
  11046. };
  11047. fluid.thatistBridge("fluid", fluid);
  11048. fluid.thatistBridge("fluid_1_5", fluid_1_5);
  11049. /*************************************************************************
  11050. * Tabindex normalization - compensate for browser differences in naming
  11051. * and function of "tabindex" attribute and tabbing order.
  11052. */
  11053. // -- Private functions --
  11054. var normalizeTabindexName = function() {
  11055. return $.browser.msie ? "tabIndex" : "tabindex";
  11056. };
  11057. var canHaveDefaultTabindex = function(elements) {
  11058. if (elements.length <= 0) {
  11059. return false;
  11060. }
  11061. return $(elements[0]).is("a, input, button, select, area, textarea, object");
  11062. };
  11063. var getValue = function(elements) {
  11064. if (elements.length <= 0) {
  11065. return undefined;
  11066. }
  11067. if (!fluid.tabindex.hasAttr(elements)) {
  11068. return canHaveDefaultTabindex(elements) ? Number(0) : undefined;
  11069. }
  11070. // Get the attribute and return it as a number value.
  11071. var value = elements.attr(normalizeTabindexName());
  11072. return Number(value);
  11073. };
  11074. var setValue = function(elements, toIndex) {
  11075. return elements.each(function(i, item) {
  11076. $(item).attr(normalizeTabindexName(), toIndex);
  11077. });
  11078. };
  11079. // -- Public API --
  11080. /**
  11081. * Gets the value of the tabindex attribute for the first item, or sets the tabindex value of all elements
  11082. * if toIndex is specified.
  11083. *
  11084. * @param {String|Number} toIndex
  11085. */
  11086. fluid.tabindex = function(target, toIndex) {
  11087. target = $(target);
  11088. if (toIndex !== null && toIndex !== undefined) {
  11089. return setValue(target, toIndex);
  11090. } else {
  11091. return getValue(target);
  11092. }
  11093. };
  11094. /**
  11095. * Removes the tabindex attribute altogether from each element.
  11096. */
  11097. fluid.tabindex.remove = function(target) {
  11098. target = $(target);
  11099. return target.each(function(i, item) {
  11100. $(item).removeAttr(normalizeTabindexName());
  11101. });
  11102. };
  11103. /**
  11104. * Determines if an element actually has a tabindex attribute present.
  11105. */
  11106. fluid.tabindex.hasAttr = function(target) {
  11107. target = $(target);
  11108. if (target.length <= 0) {
  11109. return false;
  11110. }
  11111. var togo = target.map(
  11112. function() {
  11113. var attributeNode = this.getAttributeNode(normalizeTabindexName());
  11114. return attributeNode ? attributeNode.specified : false;
  11115. }
  11116. );
  11117. return togo.length === 1? togo[0] : togo;
  11118. };
  11119. /**
  11120. * Determines if an element either has a tabindex attribute or is naturally tab-focussable.
  11121. */
  11122. fluid.tabindex.has = function(target) {
  11123. target = $(target);
  11124. return fluid.tabindex.hasAttr(target) || canHaveDefaultTabindex(target);
  11125. };
  11126. // Keyboard navigation
  11127. // Public, static constants needed by the rest of the library.
  11128. fluid.a11y = $.a11y || {};
  11129. fluid.a11y.orientation = {
  11130. HORIZONTAL: 0,
  11131. VERTICAL: 1,
  11132. BOTH: 2
  11133. };
  11134. var UP_DOWN_KEYMAP = {
  11135. next: $.ui.keyCode.DOWN,
  11136. previous: $.ui.keyCode.UP
  11137. };
  11138. var LEFT_RIGHT_KEYMAP = {
  11139. next: $.ui.keyCode.RIGHT,
  11140. previous: $.ui.keyCode.LEFT
  11141. };
  11142. // Private functions.
  11143. var unwrap = function(element) {
  11144. return element.jquery ? element[0] : element; // Unwrap the element if it's a jQuery.
  11145. };
  11146. var makeElementsTabFocussable = function(elements) {
  11147. // If each element doesn't have a tabindex, or has one set to a negative value, set it to 0.
  11148. elements.each(function(idx, item) {
  11149. item = $(item);
  11150. if (!item.fluid("tabindex.has") || item.fluid("tabindex") < 0) {
  11151. item.fluid("tabindex", 0);
  11152. }
  11153. });
  11154. };
  11155. // Public API.
  11156. /**
  11157. * Makes all matched elements available in the tab order by setting their tabindices to "0".
  11158. */
  11159. fluid.tabbable = function(target) {
  11160. target = $(target);
  11161. makeElementsTabFocussable(target);
  11162. };
  11163. /***********************************************************************
  11164. * Selectable functionality - geometrising a set of nodes such that they
  11165. * can be navigated (by setting focus) using a set of directional keys
  11166. */
  11167. var CONTEXT_KEY = "selectionContext";
  11168. var NO_SELECTION = -32768;
  11169. var cleanUpWhenLeavingContainer = function(selectionContext) {
  11170. if (selectionContext.activeItemIndex !== NO_SELECTION) {
  11171. if (selectionContext.options.onLeaveContainer) {
  11172. selectionContext.options.onLeaveContainer(
  11173. selectionContext.selectables[selectionContext.activeItemIndex]);
  11174. } else if (selectionContext.options.onUnselect) {
  11175. selectionContext.options.onUnselect(
  11176. selectionContext.selectables[selectionContext.activeItemIndex]);
  11177. }
  11178. }
  11179. if (!selectionContext.options.rememberSelectionState) {
  11180. selectionContext.activeItemIndex = NO_SELECTION;
  11181. }
  11182. };
  11183. /**
  11184. * Does the work of selecting an element and delegating to the client handler.
  11185. */
  11186. var drawSelection = function(elementToSelect, handler) {
  11187. if (handler) {
  11188. handler(elementToSelect);
  11189. }
  11190. };
  11191. /**
  11192. * Does does the work of unselecting an element and delegating to the client handler.
  11193. */
  11194. var eraseSelection = function(selectedElement, handler) {
  11195. if (handler && selectedElement) {
  11196. handler(selectedElement);
  11197. }
  11198. };
  11199. var unselectElement = function(selectedElement, selectionContext) {
  11200. eraseSelection(selectedElement, selectionContext.options.onUnselect);
  11201. };
  11202. var selectElement = function(elementToSelect, selectionContext) {
  11203. // It's possible that we're being called programmatically, in which case we should clear any previous selection.
  11204. unselectElement(selectionContext.selectedElement(), selectionContext);
  11205. elementToSelect = unwrap(elementToSelect);
  11206. var newIndex = selectionContext.selectables.index(elementToSelect);
  11207. // Next check if the element is a known selectable. If not, do nothing.
  11208. if (newIndex === -1) {
  11209. return;
  11210. }
  11211. // Select the new element.
  11212. selectionContext.activeItemIndex = newIndex;
  11213. drawSelection(elementToSelect, selectionContext.options.onSelect);
  11214. };
  11215. var selectableFocusHandler = function(selectionContext) {
  11216. return function(evt) {
  11217. // FLUID-3590: newer browsers (FF 3.6, Webkit 4) have a form of "bug" in that they will go bananas
  11218. // on attempting to move focus off an element which has tabindex dynamically set to -1.
  11219. $(evt.target).fluid("tabindex", 0);
  11220. selectElement(evt.target, selectionContext);
  11221. // Force focus not to bubble on some browsers.
  11222. return evt.stopPropagation();
  11223. };
  11224. };
  11225. var selectableBlurHandler = function(selectionContext) {
  11226. return function(evt) {
  11227. $(evt.target).fluid("tabindex", selectionContext.options.selectablesTabindex);
  11228. unselectElement(evt.target, selectionContext);
  11229. // Force blur not to bubble on some browsers.
  11230. return evt.stopPropagation();
  11231. };
  11232. };
  11233. var reifyIndex = function(sc_that) {
  11234. var elements = sc_that.selectables;
  11235. if (sc_that.activeItemIndex >= elements.length) {
  11236. sc_that.activeItemIndex = 0;
  11237. }
  11238. if (sc_that.activeItemIndex < 0 && sc_that.activeItemIndex !== NO_SELECTION) {
  11239. sc_that.activeItemIndex = elements.length - 1;
  11240. }
  11241. if (sc_that.activeItemIndex >= 0) {
  11242. fluid.focus(elements[sc_that.activeItemIndex]);
  11243. }
  11244. };
  11245. var prepareShift = function(selectionContext) {
  11246. // FLUID-3590: FF 3.6 and Safari 4.x won't fire blur() when programmatically moving focus.
  11247. var selElm = selectionContext.selectedElement();
  11248. if (selElm) {
  11249. fluid.blur(selElm);
  11250. }
  11251. unselectElement(selectionContext.selectedElement(), selectionContext);
  11252. if (selectionContext.activeItemIndex === NO_SELECTION) {
  11253. selectionContext.activeItemIndex = -1;
  11254. }
  11255. };
  11256. var focusNextElement = function(selectionContext) {
  11257. prepareShift(selectionContext);
  11258. ++selectionContext.activeItemIndex;
  11259. reifyIndex(selectionContext);
  11260. };
  11261. var focusPreviousElement = function(selectionContext) {
  11262. prepareShift(selectionContext);
  11263. --selectionContext.activeItemIndex;
  11264. reifyIndex(selectionContext);
  11265. };
  11266. var arrowKeyHandler = function(selectionContext, keyMap, userHandlers) {
  11267. return function(evt) {
  11268. if (evt.which === keyMap.next) {
  11269. focusNextElement(selectionContext);
  11270. evt.preventDefault();
  11271. } else if (evt.which === keyMap.previous) {
  11272. focusPreviousElement(selectionContext);
  11273. evt.preventDefault();
  11274. }
  11275. };
  11276. };
  11277. var getKeyMapForDirection = function(direction) {
  11278. // Determine the appropriate mapping for next and previous based on the specified direction.
  11279. var keyMap;
  11280. if (direction === fluid.a11y.orientation.HORIZONTAL) {
  11281. keyMap = LEFT_RIGHT_KEYMAP;
  11282. }
  11283. else if (direction === fluid.a11y.orientation.VERTICAL) {
  11284. // Assume vertical in any other case.
  11285. keyMap = UP_DOWN_KEYMAP;
  11286. }
  11287. return keyMap;
  11288. };
  11289. var tabKeyHandler = function(selectionContext) {
  11290. return function(evt) {
  11291. if (evt.which !== $.ui.keyCode.TAB) {
  11292. return;
  11293. }
  11294. cleanUpWhenLeavingContainer(selectionContext);
  11295. // Catch Shift-Tab and note that focus is on its way out of the container.
  11296. if (evt.shiftKey) {
  11297. selectionContext.focusIsLeavingContainer = true;
  11298. }
  11299. };
  11300. };
  11301. var containerFocusHandler = function(selectionContext) {
  11302. return function(evt) {
  11303. var shouldOrig = selectionContext.options.autoSelectFirstItem;
  11304. var shouldSelect = typeof(shouldOrig) === "function" ?
  11305. shouldOrig() : shouldOrig;
  11306. // Override the autoselection if we're on the way out of the container.
  11307. if (selectionContext.focusIsLeavingContainer) {
  11308. shouldSelect = false;
  11309. }
  11310. // This target check works around the fact that sometimes focus bubbles, even though it shouldn't.
  11311. if (shouldSelect && evt.target === selectionContext.container.get(0)) {
  11312. if (selectionContext.activeItemIndex === NO_SELECTION) {
  11313. selectionContext.activeItemIndex = 0;
  11314. }
  11315. fluid.focus(selectionContext.selectables[selectionContext.activeItemIndex]);
  11316. }
  11317. // Force focus not to bubble on some browsers.
  11318. return evt.stopPropagation();
  11319. };
  11320. };
  11321. var containerBlurHandler = function(selectionContext) {
  11322. return function(evt) {
  11323. selectionContext.focusIsLeavingContainer = false;
  11324. // Force blur not to bubble on some browsers.
  11325. return evt.stopPropagation();
  11326. };
  11327. };
  11328. var makeElementsSelectable = function(container, defaults, userOptions) {
  11329. var options = $.extend(true, {}, defaults, userOptions);
  11330. var keyMap = getKeyMapForDirection(options.direction);
  11331. var selectableElements = options.selectableElements? options.selectableElements :
  11332. container.find(options.selectableSelector);
  11333. // Context stores the currently active item(undefined to start) and list of selectables.
  11334. var that = {
  11335. container: container,
  11336. activeItemIndex: NO_SELECTION,
  11337. selectables: selectableElements,
  11338. focusIsLeavingContainer: false,
  11339. options: options
  11340. };
  11341. that.selectablesUpdated = function(focusedItem) {
  11342. // Remove selectables from the tab order and add focus/blur handlers
  11343. if (typeof(that.options.selectablesTabindex) === "number") {
  11344. that.selectables.fluid("tabindex", that.options.selectablesTabindex);
  11345. }
  11346. that.selectables.unbind("focus." + CONTEXT_KEY);
  11347. that.selectables.unbind("blur." + CONTEXT_KEY);
  11348. that.selectables.bind("focus."+ CONTEXT_KEY, selectableFocusHandler(that));
  11349. that.selectables.bind("blur." + CONTEXT_KEY, selectableBlurHandler(that));
  11350. if (keyMap && that.options.noBubbleListeners) {
  11351. that.selectables.unbind("keydown."+CONTEXT_KEY);
  11352. that.selectables.bind("keydown."+CONTEXT_KEY, arrowKeyHandler(that, keyMap));
  11353. }
  11354. if (focusedItem) {
  11355. selectElement(focusedItem, that);
  11356. }
  11357. else {
  11358. reifyIndex(that);
  11359. }
  11360. };
  11361. that.refresh = function() {
  11362. if (!that.options.selectableSelector) {
  11363. throw("Cannot refresh selectable context which was not initialised by a selector");
  11364. }
  11365. that.selectables = container.find(options.selectableSelector);
  11366. that.selectablesUpdated();
  11367. };
  11368. that.selectedElement = function() {
  11369. return that.activeItemIndex < 0? null : that.selectables[that.activeItemIndex];
  11370. };
  11371. // Add various handlers to the container.
  11372. if (keyMap && !that.options.noBubbleListeners) {
  11373. container.keydown(arrowKeyHandler(that, keyMap));
  11374. }
  11375. container.keydown(tabKeyHandler(that));
  11376. container.focus(containerFocusHandler(that));
  11377. container.blur(containerBlurHandler(that));
  11378. that.selectablesUpdated();
  11379. return that;
  11380. };
  11381. /**
  11382. * Makes all matched elements selectable with the arrow keys.
  11383. * Supply your own handlers object with onSelect: and onUnselect: properties for custom behaviour.
  11384. * Options provide configurability, including direction: and autoSelectFirstItem:
  11385. * Currently supported directions are jQuery.a11y.directions.HORIZONTAL and VERTICAL.
  11386. */
  11387. fluid.selectable = function(target, options) {
  11388. target = $(target);
  11389. var that = makeElementsSelectable(target, fluid.selectable.defaults, options);
  11390. fluid.setScopedData(target, CONTEXT_KEY, that);
  11391. return that;
  11392. };
  11393. /**
  11394. * Selects the specified element.
  11395. */
  11396. fluid.selectable.select = function(target, toSelect) {
  11397. fluid.focus(toSelect);
  11398. };
  11399. /**
  11400. * Selects the next matched element.
  11401. */
  11402. fluid.selectable.selectNext = function(target) {
  11403. target = $(target);
  11404. focusNextElement(fluid.getScopedData(target, CONTEXT_KEY));
  11405. };
  11406. /**
  11407. * Selects the previous matched element.
  11408. */
  11409. fluid.selectable.selectPrevious = function(target) {
  11410. target = $(target);
  11411. focusPreviousElement(fluid.getScopedData(target, CONTEXT_KEY));
  11412. };
  11413. /**
  11414. * Returns the currently selected item wrapped as a jQuery object.
  11415. */
  11416. fluid.selectable.currentSelection = function(target) {
  11417. target = $(target);
  11418. var that = fluid.getScopedData(target, CONTEXT_KEY);
  11419. return $(that.selectedElement());
  11420. };
  11421. fluid.selectable.defaults = {
  11422. direction: fluid.a11y.orientation.VERTICAL,
  11423. selectablesTabindex: -1,
  11424. autoSelectFirstItem: true,
  11425. rememberSelectionState: true,
  11426. selectableSelector: ".selectable",
  11427. selectableElements: null,
  11428. onSelect: null,
  11429. onUnselect: null,
  11430. onLeaveContainer: null
  11431. };
  11432. /********************************************************************
  11433. * Activation functionality - declaratively associating actions with
  11434. * a set of keyboard bindings.
  11435. */
  11436. var checkForModifier = function(binding, evt) {
  11437. // If no modifier was specified, just return true.
  11438. if (!binding.modifier) {
  11439. return true;
  11440. }
  11441. var modifierKey = binding.modifier;
  11442. var isCtrlKeyPresent = modifierKey && evt.ctrlKey;
  11443. var isAltKeyPresent = modifierKey && evt.altKey;
  11444. var isShiftKeyPresent = modifierKey && evt.shiftKey;
  11445. return isCtrlKeyPresent || isAltKeyPresent || isShiftKeyPresent;
  11446. };
  11447. /** Constructs a raw "keydown"-facing handler, given a binding entry. This
  11448. * checks whether the key event genuinely triggers the event and forwards it
  11449. * to any "activateHandler" registered in the binding.
  11450. */
  11451. var makeActivationHandler = function(binding) {
  11452. return function(evt) {
  11453. var target = evt.target;
  11454. if (!fluid.enabled(evt.target)) {
  11455. return;
  11456. }
  11457. // The following 'if' clause works in the real world, but there's a bug in the jQuery simulation
  11458. // that causes keyboard simulation to fail in Safari, causing our tests to fail:
  11459. // http://ui.jquery.com/bugs/ticket/3229
  11460. // The replacement 'if' clause works around this bug.
  11461. // When this issue is resolved, we should revert to the original clause.
  11462. // if (evt.which === binding.key && binding.activateHandler && checkForModifier(binding, evt)) {
  11463. var code = evt.which? evt.which : evt.keyCode;
  11464. if (code === binding.key && binding.activateHandler && checkForModifier(binding, evt)) {
  11465. var event = $.Event("fluid-activate");
  11466. $(evt.target).trigger(event, [binding.activateHandler]);
  11467. if (event.isDefaultPrevented()) {
  11468. evt.preventDefault();
  11469. }
  11470. }
  11471. };
  11472. };
  11473. var makeElementsActivatable = function(elements, onActivateHandler, defaultKeys, options) {
  11474. // Create bindings for each default key.
  11475. var bindings = [];
  11476. $(defaultKeys).each(function(index, key) {
  11477. bindings.push({
  11478. modifier: null,
  11479. key: key,
  11480. activateHandler: onActivateHandler
  11481. });
  11482. });
  11483. // Merge with any additional key bindings.
  11484. if (options && options.additionalBindings) {
  11485. bindings = bindings.concat(options.additionalBindings);
  11486. }
  11487. fluid.initEnablement(elements);
  11488. // Add listeners for each key binding.
  11489. for (var i = 0; i < bindings.length; ++ i) {
  11490. var binding = bindings[i];
  11491. elements.keydown(makeActivationHandler(binding));
  11492. }
  11493. elements.bind("fluid-activate", function(evt, handler) {
  11494. handler = handler || onActivateHandler;
  11495. return handler? handler(evt): null;
  11496. });
  11497. };
  11498. /**
  11499. * Makes all matched elements activatable with the Space and Enter keys.
  11500. * Provide your own handler function for custom behaviour.
  11501. * Options allow you to provide a list of additionalActivationKeys.
  11502. */
  11503. fluid.activatable = function(target, fn, options) {
  11504. target = $(target);
  11505. makeElementsActivatable(target, fn, fluid.activatable.defaults.keys, options);
  11506. };
  11507. /**
  11508. * Activates the specified element.
  11509. */
  11510. fluid.activate = function(target) {
  11511. $(target).trigger("fluid-activate");
  11512. };
  11513. // Public Defaults.
  11514. fluid.activatable.defaults = {
  11515. keys: [$.ui.keyCode.ENTER, $.ui.keyCode.SPACE]
  11516. };
  11517. })(jQuery, fluid_1_5);
  11518. /*
  11519. Copyright 2010-2011 Lucendo Development Ltd.
  11520. Copyright 2010-2011 OCAD University
  11521. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  11522. BSD license. You may not use this file except in compliance with one these
  11523. Licenses.
  11524. You may obtain a copy of the ECL 2.0 License and BSD License at
  11525. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  11526. */
  11527. /** This file contains functions which depend on the presence of a DOM document
  11528. * and which depend on the contents of Fluid.js **/
  11529. // Declare dependencies
  11530. /*global fluid_1_5:true, jQuery*/
  11531. // JSLint options
  11532. /*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  11533. var fluid_1_5 = fluid_1_5 || {};
  11534. (function ($, fluid) {
  11535. fluid.defaults("fluid.viewComponent", {
  11536. gradeNames: ["fluid.littleComponent", "fluid.modelComponent", "fluid.eventedComponent"],
  11537. initFunction: "fluid.initView",
  11538. argumentMap: {
  11539. container: 0,
  11540. options: 1
  11541. }
  11542. });
  11543. // unsupported, NON-API function
  11544. // NOTE: this function represents a temporary strategy until we have more integrated IoC debugging.
  11545. // It preserves the current framework behaviour for the 1.4 release, but provides a more informative
  11546. // diagnostic - in fact, it is perfectly acceptable for a component's creator to return no value and
  11547. // the failure is really in assumptions in fluid.initComponent. Revisit this issue for 1.5
  11548. fluid.diagnoseFailedView = function (componentName, that, options, args) {
  11549. if (!that && fluid.hasGrade(options, "fluid.viewComponent")) {
  11550. var container = fluid.wrap(args[1]);
  11551. var message1 = "Instantiation of autoInit component with type " + componentName + " failed, since ";
  11552. if (container.length === 0) {
  11553. fluid.fail(message1 + "selector \"", args[1], "\" did not match any markup in the document");
  11554. } else {
  11555. fluid.fail(message1 + " component creator function did not return a value");
  11556. }
  11557. }
  11558. };
  11559. fluid.checkTryCatchParameter = function () {
  11560. var location = window.location || { search: "", protocol: "file:" };
  11561. var GETParams = location.search.slice(1).split('&');
  11562. return fluid.contains(GETParams, "notrycatch");
  11563. };
  11564. fluid.notrycatch = fluid.checkTryCatchParameter();
  11565. /**
  11566. * Wraps an object in a jQuery if it isn't already one. This function is useful since
  11567. * it ensures to wrap a null or otherwise falsy argument to itself, rather than the
  11568. * often unhelpful jQuery default of returning the overall document node.
  11569. *
  11570. * @param {Object} obj the object to wrap in a jQuery
  11571. * @param {jQuery} userJQuery the jQuery object to use for the wrapping, optional - use the current jQuery if absent
  11572. */
  11573. fluid.wrap = function (obj, userJQuery) {
  11574. userJQuery = userJQuery || $;
  11575. return ((!obj || obj.jquery) ? obj : userJQuery(obj));
  11576. };
  11577. /**
  11578. * If obj is a jQuery, this function will return the first DOM element within it.
  11579. *
  11580. * @param {jQuery} obj the jQuery instance to unwrap into a pure DOM element
  11581. */
  11582. fluid.unwrap = function (obj) {
  11583. return obj && obj.jquery && obj.length === 1 ? obj[0] : obj; // Unwrap the element if it's a jQuery.
  11584. };
  11585. /**
  11586. * Fetches a single container element and returns it as a jQuery.
  11587. *
  11588. * @param {String||jQuery||element} containerSpec an id string, a single-element jQuery, or a DOM element specifying a unique container
  11589. * @param {Boolean} fallible <code>true</code> if an empty container is to be reported as a valid condition
  11590. * @return a single-element jQuery of container
  11591. */
  11592. fluid.container = function (containerSpec, fallible, userJQuery) {
  11593. if (userJQuery) {
  11594. containerSpec = fluid.unwrap(containerSpec);
  11595. }
  11596. var container = fluid.wrap(containerSpec, userJQuery);
  11597. if (fallible && (!container || container.length === 0)) {
  11598. return null;
  11599. }
  11600. // Throw an exception if we've got more or less than one element.
  11601. if (!container || !container.jquery || container.length !== 1) {
  11602. if (typeof (containerSpec) !== "string") {
  11603. containerSpec = container.selector;
  11604. }
  11605. var count = container.length !== undefined ? container.length : 0;
  11606. fluid.fail((count > 1 ? "More than one (" + count + ") container elements were"
  11607. : "No container element was") + " found for selector " + containerSpec);
  11608. }
  11609. if (!fluid.isDOMNode(container[0])) {
  11610. fluid.fail("fluid.container was supplied a non-jQueryable element");
  11611. }
  11612. return container;
  11613. };
  11614. /**
  11615. * Creates a new DOM Binder instance, used to locate elements in the DOM by name.
  11616. *
  11617. * @param {Object} container the root element in which to locate named elements
  11618. * @param {Object} selectors a collection of named jQuery selectors
  11619. */
  11620. fluid.createDomBinder = function (container, selectors) {
  11621. var cache = {}, that = {};
  11622. var userJQuery = container.constructor;
  11623. function cacheKey(name, thisContainer) {
  11624. return fluid.allocateSimpleId(thisContainer) + "-" + name;
  11625. }
  11626. function record(name, thisContainer, result) {
  11627. cache[cacheKey(name, thisContainer)] = result;
  11628. }
  11629. that.locate = function (name, localContainer) {
  11630. var selector, thisContainer, togo;
  11631. selector = selectors[name];
  11632. thisContainer = localContainer ? localContainer : container;
  11633. if (!thisContainer) {
  11634. fluid.fail("DOM binder invoked for selector " + name + " without container");
  11635. }
  11636. if (!selector) {
  11637. return thisContainer;
  11638. }
  11639. if (typeof (selector) === "function") {
  11640. togo = userJQuery(selector.call(null, fluid.unwrap(thisContainer)));
  11641. } else {
  11642. togo = userJQuery(selector, thisContainer);
  11643. }
  11644. if (togo.get(0) === document) {
  11645. togo = [];
  11646. }
  11647. if (!togo.selector) {
  11648. togo.selector = selector;
  11649. togo.context = thisContainer;
  11650. }
  11651. togo.selectorName = name;
  11652. record(name, thisContainer, togo);
  11653. return togo;
  11654. };
  11655. that.fastLocate = function (name, localContainer) {
  11656. var thisContainer = localContainer ? localContainer : container;
  11657. var key = cacheKey(name, thisContainer);
  11658. var togo = cache[key];
  11659. return togo ? togo : that.locate(name, localContainer);
  11660. };
  11661. that.clear = function () {
  11662. cache = {};
  11663. };
  11664. that.refresh = function (names, localContainer) {
  11665. var thisContainer = localContainer ? localContainer : container;
  11666. if (typeof names === "string") {
  11667. names = [names];
  11668. }
  11669. if (thisContainer.length === undefined) {
  11670. thisContainer = [thisContainer];
  11671. }
  11672. for (var i = 0; i < names.length; ++i) {
  11673. for (var j = 0; j < thisContainer.length; ++j) {
  11674. that.locate(names[i], thisContainer[j]);
  11675. }
  11676. }
  11677. };
  11678. that.resolvePathSegment = that.locate;
  11679. return that;
  11680. };
  11681. /** Expect that jQuery selector query has resulted in a non-empty set of
  11682. * results. If none are found, this function will fail with a diagnostic message,
  11683. * with the supplied message prepended.
  11684. */
  11685. fluid.expectFilledSelector = function (result, message) {
  11686. if (result && result.length === 0 && result.jquery) {
  11687. fluid.fail(message + ": selector \"" + result.selector + "\" with name " + result.selectorName +
  11688. " returned no results in context " + fluid.dumpEl(result.context));
  11689. }
  11690. };
  11691. /**
  11692. * The central initialiation method called as the first act of every Fluid
  11693. * component. This function automatically merges user options with defaults,
  11694. * attaches a DOM Binder to the instance, and configures events.
  11695. *
  11696. * @param {String} componentName The unique "name" of the component, which will be used
  11697. * to fetch the default options from store. By recommendation, this should be the global
  11698. * name of the component's creator function.
  11699. * @param {jQueryable} container A specifier for the single root "container node" in the
  11700. * DOM which will house all the markup for this component.
  11701. * @param {Object} userOptions The configuration options for this component.
  11702. */
  11703. // 4th argument is NOT SUPPORTED, see comments for initLittleComponent
  11704. fluid.initView = function (componentName, containerSpec, userOptions, localOptions) {
  11705. var container = fluid.container(containerSpec, true);
  11706. fluid.expectFilledSelector(container, "Error instantiating component with name \"" + componentName);
  11707. if (!container) {
  11708. return null;
  11709. }
  11710. var that = fluid.initLittleComponent(componentName, userOptions, localOptions || {gradeNames: ["fluid.viewComponent"]});
  11711. var userJQuery = that.options.jQuery; // Do it a second time to correct for jQuery injection
  11712. if (userJQuery) {
  11713. container = fluid.container(containerSpec, true, userJQuery);
  11714. }
  11715. fluid.log("Constructing view component " + componentName + " with container " + container.constructor.expando +
  11716. (userJQuery ? " user jQuery " + userJQuery.expando : "") + " env: " + $.expando);
  11717. that.container = container;
  11718. fluid.initDomBinder(that);
  11719. return that;
  11720. };
  11721. /**
  11722. * Creates a new DOM Binder instance for the specified component and mixes it in.
  11723. *
  11724. * @param {Object} that the component instance to attach the new DOM Binder to
  11725. */
  11726. fluid.initDomBinder = function (that) {
  11727. that.dom = fluid.createDomBinder(that.container, that.options.selectors);
  11728. that.locate = that.dom.locate;
  11729. };
  11730. // DOM Utilities.
  11731. /**
  11732. * Finds the nearest ancestor of the element that passes the test
  11733. * @param {Element} element DOM element
  11734. * @param {Function} test A function which takes an element as a parameter and return true or false for some test
  11735. */
  11736. fluid.findAncestor = function (element, test) {
  11737. element = fluid.unwrap(element);
  11738. while (element) {
  11739. if (test(element)) {
  11740. return element;
  11741. }
  11742. element = element.parentNode;
  11743. }
  11744. };
  11745. /**
  11746. * Returns a jQuery object given the id of a DOM node. In the case the element
  11747. * is not found, will return an empty list.
  11748. */
  11749. fluid.jById = function (id, dokkument) {
  11750. dokkument = dokkument && dokkument.nodeType === 9 ? dokkument : document;
  11751. var element = fluid.byId(id, dokkument);
  11752. var togo = element ? $(element) : [];
  11753. togo.selector = "#" + id;
  11754. togo.context = dokkument;
  11755. return togo;
  11756. };
  11757. /**
  11758. * Returns an DOM element quickly, given an id
  11759. *
  11760. * @param {Object} id the id of the DOM node to find
  11761. * @param {Document} dokkument the document in which it is to be found (if left empty, use the current document)
  11762. * @return The DOM element with this id, or null, if none exists in the document.
  11763. */
  11764. fluid.byId = function (id, dokkument) {
  11765. dokkument = dokkument && dokkument.nodeType === 9 ? dokkument : document;
  11766. var el = dokkument.getElementById(id);
  11767. if (el) {
  11768. // Use element id property here rather than attribute, to work around FLUID-3953
  11769. if (el.id !== id) {
  11770. fluid.fail("Problem in document structure - picked up element " +
  11771. fluid.dumpEl(el) + " for id " + id +
  11772. " without this id - most likely the element has a name which conflicts with this id");
  11773. }
  11774. return el;
  11775. } else {
  11776. return null;
  11777. }
  11778. };
  11779. /**
  11780. * Returns the id attribute from a jQuery or pure DOM element.
  11781. *
  11782. * @param {jQuery||Element} element the element to return the id attribute for
  11783. */
  11784. fluid.getId = function (element) {
  11785. return fluid.unwrap(element).id;
  11786. };
  11787. /**
  11788. * Allocate an id to the supplied element if it has none already, by a simple
  11789. * scheme resulting in ids "fluid-id-nnnn" where nnnn is an increasing integer.
  11790. */
  11791. fluid.allocateSimpleId = function (element) {
  11792. var simpleId = "fluid-id-" + fluid.allocateGuid();
  11793. if (!element) {
  11794. return simpleId;
  11795. }
  11796. element = fluid.unwrap(element);
  11797. if (!element.id) {
  11798. element.id = simpleId;
  11799. }
  11800. return element.id;
  11801. };
  11802. fluid.defaults("fluid.ariaLabeller", {
  11803. labelAttribute: "aria-label",
  11804. liveRegionMarkup: "<div class=\"liveRegion fl-offScreen-hidden\" aria-live=\"polite\"></div>",
  11805. liveRegionId: "fluid-ariaLabeller-liveRegion",
  11806. events: {
  11807. generateLiveElement: "unicast"
  11808. },
  11809. listeners: {
  11810. generateLiveElement: "fluid.ariaLabeller.generateLiveElement"
  11811. }
  11812. });
  11813. fluid.ariaLabeller = function (element, options) {
  11814. var that = fluid.initView("fluid.ariaLabeller", element, options);
  11815. that.update = function (newOptions) {
  11816. newOptions = newOptions || that.options;
  11817. that.container.attr(that.options.labelAttribute, newOptions.text);
  11818. if (newOptions.dynamicLabel) {
  11819. var live = fluid.jById(that.options.liveRegionId);
  11820. if (live.length === 0) {
  11821. live = that.events.generateLiveElement.fire(that);
  11822. }
  11823. live.text(newOptions.text);
  11824. }
  11825. };
  11826. that.update();
  11827. return that;
  11828. };
  11829. fluid.ariaLabeller.generateLiveElement = function (that) {
  11830. var liveEl = $(that.options.liveRegionMarkup);
  11831. liveEl.prop("id", that.options.liveRegionId);
  11832. $("body").append(liveEl);
  11833. return liveEl;
  11834. };
  11835. var LABEL_KEY = "aria-labelling";
  11836. fluid.getAriaLabeller = function (element) {
  11837. element = $(element);
  11838. var that = fluid.getScopedData(element, LABEL_KEY);
  11839. return that;
  11840. };
  11841. /** Manages an ARIA-mediated label attached to a given DOM element. An
  11842. * aria-labelledby attribute and target node is fabricated in the document
  11843. * if they do not exist already, and a "little component" is returned exposing a method
  11844. * "update" that allows the text to be updated. */
  11845. fluid.updateAriaLabel = function (element, text, options) {
  11846. options = $.extend({}, options || {}, {text: text});
  11847. var that = fluid.getAriaLabeller(element);
  11848. if (!that) {
  11849. that = fluid.ariaLabeller(element, options);
  11850. fluid.setScopedData(element, LABEL_KEY, that);
  11851. } else {
  11852. that.update(options);
  11853. }
  11854. return that;
  11855. };
  11856. /** Sets an interation on a target control, which morally manages a "blur" for
  11857. * a possibly composite region.
  11858. * A timed blur listener is set on the control, which waits for a short period of
  11859. * time (options.delay, defaults to 150ms) to discover whether the reason for the
  11860. * blur interaction is that either a focus or click is being serviced on a nominated
  11861. * set of "exclusions" (options.exclusions, a free hash of elements or jQueries).
  11862. * If no such event is received within the window, options.handler will be called
  11863. * with the argument "control", to service whatever interaction is required of the
  11864. * blur.
  11865. */
  11866. fluid.deadMansBlur = function (control, options) {
  11867. var that = fluid.initLittleComponent("fluid.deadMansBlur", options);
  11868. that.blurPending = false;
  11869. that.lastCancel = 0;
  11870. $(control).bind("focusout", function (event) {
  11871. fluid.log("Starting blur timer for element " + fluid.dumpEl(event.target));
  11872. var now = new Date().getTime();
  11873. fluid.log("back delay: " + (now - that.lastCancel));
  11874. if (now - that.lastCancel > that.options.backDelay) {
  11875. that.blurPending = true;
  11876. }
  11877. setTimeout(function () {
  11878. if (that.blurPending) {
  11879. that.options.handler(control);
  11880. }
  11881. }, that.options.delay);
  11882. });
  11883. that.canceller = function (event) {
  11884. fluid.log("Cancellation through " + event.type + " on " + fluid.dumpEl(event.target));
  11885. that.lastCancel = new Date().getTime();
  11886. that.blurPending = false;
  11887. };
  11888. fluid.each(that.options.exclusions, function (exclusion) {
  11889. exclusion = $(exclusion);
  11890. fluid.each(exclusion, function (excludeEl) {
  11891. $(excludeEl).bind("focusin", that.canceller).
  11892. bind("fluid-focus", that.canceller).
  11893. click(that.canceller).mousedown(that.canceller);
  11894. // Mousedown is added for FLUID-4212, as a result of Chrome bug 6759, 14204
  11895. });
  11896. });
  11897. return that;
  11898. };
  11899. fluid.defaults("fluid.deadMansBlur", {
  11900. delay: 150,
  11901. backDelay: 100
  11902. });
  11903. })(jQuery, fluid_1_5);
  11904. /*
  11905. Copyright 2011 OCAD University
  11906. Copyright 2010-2011 Lucendo Development Ltd.
  11907. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  11908. BSD license. You may not use this file except in compliance with one these
  11909. Licenses.
  11910. You may obtain a copy of the ECL 2.0 License and BSD License at
  11911. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  11912. */
  11913. // Declare dependencies
  11914. /*global fluid_1_5:true, jQuery*/
  11915. // JSLint options
  11916. /*jslint white: true, funcinvoke: true, continue: true, elsecatch: true, operator: true, jslintok:true, undef: true, newcap: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  11917. var fluid_1_5 = fluid_1_5 || {};
  11918. (function ($, fluid) {
  11919. /** The Fluid "IoC System proper" - resolution of references and
  11920. * completely automated instantiation of declaratively defined
  11921. * component trees */
  11922. var inCreationMarker = "__CURRENTLY_IN_CREATION__";
  11923. // unsupported, non-API function
  11924. fluid.isFireBreak = function(component) {
  11925. return component.options && component.options["fluid.visitComponents.fireBreak"];
  11926. };
  11927. // unsupported, non-API function
  11928. fluid.visitComponentChildren = function(that, visitor, options, up, down) {
  11929. options = options || {};
  11930. for (var name in that) {
  11931. var component = that[name];
  11932. //Every component *should* have an id, but some clients may not yet be compliant
  11933. //if (component && component.typeName && !component.id) {
  11934. // fluid.fail("No id");
  11935. //}
  11936. if (!component || !component.typeName || (component.id && options.visited && options.visited[component.id])) {continue; }
  11937. if (options.visited) {
  11938. options.visited[component.id] = true;
  11939. }
  11940. if (visitor(component, name, options, up, down)) {
  11941. return true;
  11942. }
  11943. if (!fluid.isFireBreak(component) && !options.flat) {
  11944. fluid.visitComponentChildren(component, visitor, options, up, down + 1);
  11945. }
  11946. }
  11947. };
  11948. // thatStack contains an increasing list of MORE SPECIFIC thats.
  11949. var visitComponents = function(instantiator, thatStack, visitor, options) {
  11950. options = options || {
  11951. visited: {},
  11952. flat: true
  11953. };
  11954. var up = 0;
  11955. for (var i = thatStack.length - 1; i >= 0; --i) {
  11956. var that = thatStack[i];
  11957. if (fluid.isFireBreak(that)) {
  11958. return;
  11959. }
  11960. if (that.typeName) {
  11961. options.visited[that.id] = true;
  11962. var path = instantiator.idToPath[that.id] || "";
  11963. var memberName = fluid.pathUtil.getTailPath(path);
  11964. if (visitor(that, memberName, options, 0, 0)) {
  11965. return;
  11966. }
  11967. }
  11968. if (fluid.visitComponentChildren(that, visitor, options, up, 1)) {
  11969. return;
  11970. }
  11971. ++up;
  11972. }
  11973. };
  11974. // An EL segment resolver strategy that will attempt to trigger creation of
  11975. // components that it discovers along the EL path, if they have been defined but not yet
  11976. // constructed. Spring, eat your heart out! Wot no SPR-2048?
  11977. function makeGingerStrategy(instantiator, that, thatStack) {
  11978. return function(component, thisSeg) {
  11979. var atval = component[thisSeg];
  11980. if (atval === undefined) {
  11981. var parentPath = instantiator.idToPath[component.id];
  11982. atval = instantiator.pathToComponent[fluid.composePath(parentPath, thisSeg)];
  11983. // if it was not attached to the component, but it is in the instantiator, it MUST be in creation - prepare to fail
  11984. if (atval) {
  11985. atval[inCreationMarker] = true;
  11986. }
  11987. }
  11988. if (atval !== undefined) {
  11989. if (atval[inCreationMarker]) {
  11990. fluid.fail("Component " + fluid.dumpThat(atval) + " at path \"" + thisSeg
  11991. + "\" of parent " + fluid.dumpThat(component) + " cannot be used for lookup"
  11992. + " since it is still in creation. Please reorganise your dependencies so that they no longer contain circular references");
  11993. }
  11994. }
  11995. else {
  11996. if (fluid.get(component, fluid.path("options", "components", thisSeg, "type"))) {
  11997. fluid.initDependent(component, thisSeg);
  11998. atval = component[thisSeg];
  11999. }
  12000. }
  12001. return atval;
  12002. };
  12003. }
  12004. // unsupported, non-API function
  12005. fluid.dumpThat = function(that) {
  12006. return "{ typeName: \"" + that.typeName + "\" id: " + that.id + "}";
  12007. };
  12008. // unsupported, non-API function
  12009. fluid.dumpThatStack = function(thatStack, instantiator) {
  12010. var togo = fluid.transform(thatStack, function(that) {
  12011. var path = instantiator.idToPath[that.id];
  12012. return fluid.dumpThat(that) + (path? (" - path: " + path) : "");
  12013. });
  12014. return togo.join("\n");
  12015. };
  12016. // Return an array of objects describing the current activity
  12017. // unsupported, non-API function
  12018. fluid.describeActivity = function() {
  12019. return fluid.threadLocal().activityStack || [];
  12020. };
  12021. // Execute the supplied function with the specified activity description pushed onto the stack
  12022. // unsupported, non-API function
  12023. fluid.pushActivity = function(func, message) {
  12024. if (!message || fluid.notrycatch) {
  12025. return func();
  12026. }
  12027. var root = fluid.threadLocal();
  12028. if (!root.activityStack) {
  12029. root.activityStack = [];
  12030. }
  12031. var frames = fluid.makeArray(message);
  12032. frames.push("\n");
  12033. frames.unshift("\n");
  12034. root.activityStack = frames.concat(root.activityStack);
  12035. return fluid.tryCatch(func, null, function() {
  12036. root.activityStack = root.activityStack.slice(frames.length);
  12037. });
  12038. };
  12039. // Return a function wrapped by the activity of describing its activity
  12040. // unsupported, non-API function
  12041. fluid.wrapActivity = fluid.notrycatch? fluid.identity : function(func, messageSpec) {
  12042. return function() {
  12043. var args = fluid.makeArray(arguments);
  12044. var message = fluid.transform(fluid.makeArray(messageSpec), function(specEl) {
  12045. if (typeof(specEl) === "string" && specEl.indexOf("arguments.") === 0) {
  12046. var el = specEl.substring("arguments.".length);
  12047. return fluid.get(args, el);
  12048. }
  12049. else {
  12050. return specEl;
  12051. }
  12052. });
  12053. return fluid.pushActivity(function() {
  12054. return func.apply(null, args);
  12055. }, message);
  12056. };
  12057. };
  12058. var localRecordExpected = /arguments|options|container/;
  12059. function makeStackFetcher(instantiator, parentThat, localRecord, expandOptions) {
  12060. expandOptions = expandOptions || {};
  12061. var thatStack = instantiator.getFullStack(parentThat);
  12062. var fetchStrategies = [fluid.model.funcResolverStrategy, makeGingerStrategy(instantiator, parentThat, thatStack)];
  12063. var fetcher = function(parsed) {
  12064. var context = parsed.context;
  12065. if (localRecord && localRecordExpected.test(context)) {
  12066. var fetched = fluid.get(localRecord[context], parsed.path);
  12067. return (context === "arguments" || expandOptions.direct)? fetched : {
  12068. marker: context === "options"? fluid.EXPAND : fluid.EXPAND_NOW,
  12069. value: fetched
  12070. };
  12071. }
  12072. var foundComponent;
  12073. visitComponents(instantiator, thatStack, function(component, name, options, up, down) {
  12074. if (context === name || context === component.typeName || context === component.nickName) {
  12075. foundComponent = component;
  12076. if (down > 1) {
  12077. fluid.log("***WARNING: value resolution for context " + context + " found at depth " + down + ": this may not be supported in future");
  12078. }
  12079. return true; // YOUR VISIT IS AT AN END!!
  12080. }
  12081. if (fluid.get(component, fluid.path("options", "components", context, "type")) && !component[context]) {
  12082. foundComponent = fluid.get(component, context, {strategies: fetchStrategies});
  12083. return true;
  12084. }
  12085. });
  12086. if (!foundComponent && parsed.path !== "") {
  12087. var ref = fluid.renderContextReference(parsed);
  12088. fluid.log("Failed to resolve reference " + ref + ": thatStack contains\n" + fluid.dumpThatStack(thatStack, instantiator));
  12089. fluid.fail("Failed to resolve reference " + ref + " - could not match context with name "
  12090. + context + " from component leaf of type " + thatStack[thatStack.length - 1].typeName, "\ninstantiator contents: ", instantiator);
  12091. }
  12092. return fluid.get(foundComponent, parsed.path, fetchStrategies);
  12093. };
  12094. return fetcher;
  12095. }
  12096. function makeStackResolverOptions(instantiator, parentThat, localRecord, expandOptions) {
  12097. return $.extend(true, {}, fluid.defaults("fluid.resolveEnvironment"), {
  12098. fetcher: makeStackFetcher(instantiator, parentThat, localRecord, expandOptions)
  12099. });
  12100. }
  12101. // unsupported, non-API function
  12102. fluid.instantiator = function(freeInstantiator) {
  12103. // NB: We may not use the options merging framework itself here, since "withInstantiator" below
  12104. // will blow up, as it tries to resolve the instantiator which we are instantiating *NOW*
  12105. var preThat = {
  12106. options: {
  12107. "fluid.visitComponents.fireBreak": true
  12108. },
  12109. idToPath: {},
  12110. pathToComponent: {},
  12111. stackCount: 0,
  12112. nickName: "instantiator"
  12113. };
  12114. var that = fluid.typeTag("fluid.instantiator");
  12115. that = $.extend(that, preThat);
  12116. that.stack = function(count) {
  12117. return that.stackCount += count;
  12118. };
  12119. that.getThatStack = function(component) {
  12120. var path = that.idToPath[component.id] || "";
  12121. var parsed = fluid.model.parseEL(path);
  12122. var togo = fluid.transform(parsed, function(value, i) {
  12123. var parentPath = fluid.model.composeSegments.apply(null, parsed.slice(0, i + 1));
  12124. return that.pathToComponent[parentPath];
  12125. });
  12126. var root = that.pathToComponent[""];
  12127. if (root) {
  12128. togo.unshift(root);
  12129. }
  12130. return togo;
  12131. };
  12132. that.getEnvironmentalStack = function() {
  12133. var togo = [fluid.staticEnvironment];
  12134. if (!freeInstantiator) {
  12135. togo.push(fluid.threadLocal());
  12136. }
  12137. return togo;
  12138. };
  12139. that.getFullStack = function(component) {
  12140. var thatStack = component? that.getThatStack(component) : [];
  12141. return that.getEnvironmentalStack().concat(thatStack);
  12142. };
  12143. function recordComponent(component, path) {
  12144. that.idToPath[component.id] = path;
  12145. if (that.pathToComponent[path]) {
  12146. fluid.fail("Error during instantiation - path " + path + " which has just created component " + fluid.dumpThat(component)
  12147. + " has already been used for component " + fluid.dumpThat(that.pathToComponent[path]) + " - this is a circular instantiation or other oversight."
  12148. + " Please clear the component using instantiator.clearComponent() before reusing the path.");
  12149. }
  12150. that.pathToComponent[path] = component;
  12151. }
  12152. that.recordRoot = function(component) {
  12153. if (component && component.id && !that.pathToComponent[""]) {
  12154. recordComponent(component, "");
  12155. }
  12156. };
  12157. that.pushUpcomingInstantiation = function(parent, name) {
  12158. that.expectedParent = parent;
  12159. that.expectedName = name;
  12160. };
  12161. that.recordComponent = function(component) {
  12162. if (that.expectedName) {
  12163. that.recordKnownComponent(that.expectedParent, component, that.expectedName);
  12164. delete that.expectedName;
  12165. delete that.expectedParent;
  12166. }
  12167. else {
  12168. that.recordRoot(component);
  12169. }
  12170. };
  12171. that.clearComponent = function(component, name, child, options, noModTree) {
  12172. options = options || {visited: {}, flat: true};
  12173. child = child || component[name];
  12174. fluid.visitComponentChildren(child, function(gchild, gchildname) {
  12175. that.clearComponent(child, gchildname, null, options, noModTree);
  12176. }, options);
  12177. var path = that.idToPath[child.id];
  12178. delete that.idToPath[child.id];
  12179. delete that.pathToComponent[path];
  12180. if (!noModTree) {
  12181. delete component[name];
  12182. }
  12183. };
  12184. that.recordKnownComponent = function(parent, component, name) {
  12185. var parentPath = that.idToPath[parent.id] || "";
  12186. var path = fluid.model.composePath(parentPath, name);
  12187. recordComponent(component, path);
  12188. };
  12189. return that;
  12190. };
  12191. fluid.freeInstantiator = fluid.instantiator(true);
  12192. // unsupported, non-API function
  12193. fluid.argMapToDemands = function(argMap) {
  12194. var togo = [];
  12195. fluid.each(argMap, function(value, key) {
  12196. togo[value] = "{" + key + "}";
  12197. });
  12198. return togo;
  12199. };
  12200. // unsupported, non-API function
  12201. fluid.makePassArgsSpec = function(initArgs) {
  12202. return fluid.transform(initArgs, function(arg, index) {
  12203. return "{arguments}." + index;
  12204. });
  12205. };
  12206. function mergeToMergeAll(options) {
  12207. if (options && options.mergeOptions) {
  12208. options.mergeAllOptions = ["{options}"].concat(fluid.makeArray(options.mergeOptions));
  12209. }
  12210. }
  12211. function upgradeMergeOptions(demandspec) {
  12212. mergeToMergeAll(demandspec);
  12213. if (demandspec.mergeAllOptions) {
  12214. if (demandspec.options) {
  12215. fluid.fail("demandspec ", demandspec,
  12216. " is invalid - cannot specify literal options together with mergeOptions or mergeAllOptions");
  12217. }
  12218. demandspec.options = {
  12219. mergeAllOptions: demandspec.mergeAllOptions
  12220. };
  12221. }
  12222. if (demandspec.options) {
  12223. delete demandspec.options.mergeOptions;
  12224. }
  12225. }
  12226. /** Given a concrete argument list and/or options, determine the final concrete
  12227. * "invocation specification" which is coded by the supplied demandspec in the
  12228. * environment "thatStack" - the return is a package of concrete global function name
  12229. * and argument list which is suitable to be executed directly by fluid.invokeGlobalFunction.
  12230. */
  12231. // unsupported, non-API function
  12232. fluid.embodyDemands = function(instantiator, parentThat, demandspec, initArgs, options) {
  12233. options = options || {};
  12234. upgradeMergeOptions(demandspec);
  12235. var oldOptions = fluid.get(options, "componentRecord.options");
  12236. options.componentRecord = $.extend(true, {}, options.componentRecord,
  12237. fluid.censorKeys(demandspec, ["args", "funcName", "registeredFrom"]));
  12238. var mergeAllZero = fluid.get(options, "componentRecord.options.mergeAllOptions.0");
  12239. if (mergeAllZero === "{options}") {
  12240. fluid.set(options, "componentRecord.options.mergeAllOptions.0", oldOptions);
  12241. }
  12242. var demands = fluid.makeArray(demandspec.args);
  12243. var upDefaults = fluid.defaults(demandspec.funcName); // I can SEE into TIME!!
  12244. var argMap = upDefaults? upDefaults.argumentMap : null;
  12245. var inferMap = false;
  12246. if (!argMap && (upDefaults || (options && options.componentRecord)) && !options.passArgs) {
  12247. inferMap = true;
  12248. // infer that it must be a little component if we have any reason to believe it is a component
  12249. if (demands.length < 2) {
  12250. argMap = fluid.rawDefaults("fluid.littleComponent").argumentMap;
  12251. }
  12252. else {
  12253. argMap = {options: demands.length - 1}; // wild guess in the old style
  12254. }
  12255. }
  12256. options = options || {};
  12257. if (demands.length === 0) {
  12258. if (options.componentRecord && argMap) {
  12259. demands = fluid.argMapToDemands(argMap);
  12260. }
  12261. else if (options.passArgs) {
  12262. demands = fluid.makePassArgsSpec(initArgs);
  12263. }
  12264. }
  12265. var localRecord = $.extend({"arguments": initArgs}, fluid.censorKeys(options.componentRecord, ["type"]));
  12266. fluid.each(argMap, function(index, name) {
  12267. if (initArgs.length > 0) {
  12268. localRecord[name] = localRecord["arguments"][index];
  12269. }
  12270. if (demandspec[name] !== undefined && localRecord[name] === undefined) {
  12271. localRecord[name] = demandspec[name];
  12272. }
  12273. });
  12274. mergeToMergeAll(localRecord.options);
  12275. mergeToMergeAll(argMap && demands[argMap.options]);
  12276. var upstreamLocalRecord = $.extend({}, localRecord);
  12277. if (options.componentRecord.options !== undefined) {
  12278. upstreamLocalRecord.options = options.componentRecord.options;
  12279. }
  12280. var expandOptions = makeStackResolverOptions(instantiator, parentThat, localRecord);
  12281. var args = [];
  12282. if (demands) {
  12283. for (var i = 0; i < demands.length; ++i) {
  12284. var arg = demands[i];
  12285. // Weak detection since we cannot guarantee this material has not been copied
  12286. if (fluid.isMarker(arg) && arg.value === fluid.COMPONENT_OPTIONS.value) {
  12287. arg = "{options}";
  12288. // Backwards compatibility for non-users of GRADES - last-ditch chance to correct the inference
  12289. if (inferMap) {
  12290. argMap = {options: i};
  12291. }
  12292. }
  12293. if (typeof(arg) === "string") {
  12294. if (arg.charAt(0) === "@") {
  12295. var argpos = arg.substring(1);
  12296. arg = "{arguments}." + argpos;
  12297. }
  12298. }
  12299. if (!argMap || argMap.options !== i) {
  12300. // defer expansion required if it is non-pseudoarguments demands and this argument *is* the options
  12301. args[i] = fluid.expander.expandLight(arg, expandOptions);
  12302. }
  12303. else { // It is the component options
  12304. if (arg && typeof(arg) === "object" && !arg.targetTypeName) {
  12305. arg.targetTypeName = demandspec.funcName;
  12306. }
  12307. // ensure to copy the arg since it is an alias of the demand block material (FLUID-4223)
  12308. // and will be destructively expanded
  12309. args[i] = {marker: fluid.EXPAND, value: fluid.copy(arg), localRecord: upstreamLocalRecord};
  12310. }
  12311. if (args[i] && fluid.isMarker(args[i].marker, fluid.EXPAND_NOW)) {
  12312. args[i] = fluid.expander.expandLight(args[i].value, expandOptions);
  12313. }
  12314. }
  12315. }
  12316. else {
  12317. args = initArgs? initArgs : [];
  12318. }
  12319. var togo = {
  12320. args: args,
  12321. funcName: demandspec.funcName
  12322. };
  12323. return togo;
  12324. };
  12325. var aliasTable = {};
  12326. fluid.alias = function(demandingName, aliasName) {
  12327. if (aliasName) {
  12328. aliasTable[demandingName] = aliasName;
  12329. }
  12330. else {
  12331. return aliasTable[demandingName];
  12332. }
  12333. };
  12334. var dependentStore = {};
  12335. function searchDemands(demandingName, contextNames) {
  12336. var exist = dependentStore[demandingName] || [];
  12337. outer: for (var i = 0; i < exist.length; ++i) {
  12338. var rec = exist[i];
  12339. for (var j = 0; j < contextNames.length; ++j) {
  12340. if (rec.contexts[j] !== contextNames[j]) {
  12341. continue outer;
  12342. }
  12343. }
  12344. return rec.spec; // jslint:ok
  12345. }
  12346. }
  12347. var isDemandLogging = false;
  12348. fluid.setDemandLogging = function(set) {
  12349. isDemandLogging = set;
  12350. };
  12351. // unsupported, non-API function
  12352. fluid.isDemandLogging = function(demandingNames) {
  12353. return isDemandLogging && fluid.isLogging();
  12354. };
  12355. fluid.demands = function(demandingName, contextName, spec) {
  12356. var contextNames = fluid.makeArray(contextName).sort();
  12357. if (!spec) {
  12358. return searchDemands(demandingName, contextNames);
  12359. }
  12360. else if (spec.length) {
  12361. spec = {args: spec};
  12362. }
  12363. if (fluid.getCallerInfo && fluid.isDemandLogging()) {
  12364. var callerInfo = fluid.getCallerInfo(5);
  12365. if (callerInfo) {
  12366. spec.registeredFrom = callerInfo;
  12367. }
  12368. }
  12369. var exist = dependentStore[demandingName];
  12370. if (!exist) {
  12371. exist = [];
  12372. dependentStore[demandingName] = exist;
  12373. }
  12374. exist.push({contexts: contextNames, spec: spec});
  12375. };
  12376. // unsupported, non-API function
  12377. fluid.compareDemands = function(speca, specb) {
  12378. var p1 = speca.uncess - specb.uncess;
  12379. return p1 === 0? specb.intersect - speca.intersect : p1;
  12380. };
  12381. // unsupported, non-API function
  12382. fluid.locateAllDemands = function(instantiator, parentThat, demandingNames) {
  12383. var demandLogging = fluid.isDemandLogging(demandingNames);
  12384. if (demandLogging) {
  12385. fluid.log("Resolving demands for function names ", demandingNames, " in context of " +
  12386. (parentThat? "component " + parentThat.typeName : "no component"));
  12387. }
  12388. var contextNames = {};
  12389. var visited = [];
  12390. var thatStack = instantiator.getFullStack(parentThat);
  12391. visitComponents(instantiator, thatStack, function(component, xname, options, up, down) {
  12392. contextNames[component.typeName] = true;
  12393. visited.push(component);
  12394. });
  12395. if (demandLogging) {
  12396. fluid.log("Components in scope for resolution:\n" + fluid.dumpThatStack(visited, instantiator));
  12397. }
  12398. var matches = [];
  12399. for (var i = 0; i < demandingNames.length; ++i) {
  12400. var rec = dependentStore[demandingNames[i]] || [];
  12401. for (var j = 0; j < rec.length; ++j) {
  12402. var spec = rec[j];
  12403. var record = {spec: spec, intersect: 0, uncess: 0};
  12404. for (var k = 0; k < spec.contexts.length; ++k) {
  12405. record[contextNames[spec.contexts[k]]? "intersect" : "uncess"] += 2;
  12406. }
  12407. if (spec.contexts.length === 0) { // allow weak priority for contextless matches
  12408. record.intersect++;
  12409. }
  12410. // TODO: Potentially more subtle algorithm here - also ambiguity reports
  12411. matches.push(record);
  12412. }
  12413. }
  12414. matches.sort(fluid.compareDemands);
  12415. return matches;
  12416. };
  12417. // unsupported, non-API function
  12418. fluid.locateDemands = function(instantiator, parentThat, demandingNames) {
  12419. var matches = fluid.locateAllDemands(instantiator, parentThat, demandingNames);
  12420. var demandspec = matches.length === 0 || matches[0].intersect === 0? null : matches[0].spec.spec;
  12421. if (fluid.isDemandLogging(demandingNames)) {
  12422. if (demandspec) {
  12423. fluid.log("Located " + matches.length + " potential match" + (matches.length === 1? "" : "es") + ", selected best match with " + matches[0].intersect
  12424. + " matched context names: ", demandspec);
  12425. }
  12426. else {
  12427. fluid.log("No matches found for demands, using direct implementation");
  12428. }
  12429. }
  12430. return demandspec;
  12431. };
  12432. /** Determine the appropriate demand specification held in the fluid.demands environment
  12433. * relative to "thatStack" for the function name(s) funcNames.
  12434. */
  12435. // unsupported, non-API function
  12436. fluid.determineDemands = function (instantiator, parentThat, funcNames) {
  12437. funcNames = fluid.makeArray(funcNames);
  12438. var newFuncName = funcNames[0];
  12439. var demandspec = fluid.locateDemands(instantiator, parentThat, funcNames) || {};
  12440. if (demandspec.funcName) {
  12441. newFuncName = demandspec.funcName;
  12442. }
  12443. var aliasTo = fluid.alias(newFuncName);
  12444. if (aliasTo) {
  12445. newFuncName = aliasTo;
  12446. fluid.log("Following redirect from function name " + newFuncName + " to " + aliasTo);
  12447. var demandspec2 = fluid.locateDemands(instantiator, parentThat, [aliasTo]);
  12448. if (demandspec2) {
  12449. fluid.each(demandspec2, function(value, key) {
  12450. if (localRecordExpected.test(key)) {
  12451. fluid.fail("Error in demands block ", demandspec2, " - content with key \"" + key
  12452. + "\" is not supported since this demands block was resolved via an alias from \"" + newFuncName + "\"");
  12453. }
  12454. });
  12455. if (demandspec2.funcName) {
  12456. newFuncName = demandspec2.funcName;
  12457. fluid.log("Followed final inner demands to function name \"" + newFuncName + "\"");
  12458. }
  12459. }
  12460. }
  12461. return fluid.merge(null, {funcName: newFuncName, args: fluid.makeArray(demandspec.args)}, fluid.censorKeys(demandspec, ["funcName", "args"]));
  12462. };
  12463. // unsupported, non-API function
  12464. fluid.resolveDemands = function(instantiator, parentThat, funcNames, initArgs, options) {
  12465. var demandspec = fluid.determineDemands(instantiator, parentThat, funcNames);
  12466. return fluid.embodyDemands(instantiator, parentThat, demandspec, initArgs, options);
  12467. };
  12468. // TODO: make a *slightly* more performant version of fluid.invoke that perhaps caches the demands
  12469. // after the first successful invocation
  12470. fluid.invoke = function(functionName, args, that, environment) {
  12471. args = fluid.makeArray(args);
  12472. return fluid.withInstantiator(that, function(instantiator) {
  12473. var invokeSpec = fluid.resolveDemands(instantiator, that, functionName, args, {passArgs: true});
  12474. return fluid.invokeGlobalFunction(invokeSpec.funcName, invokeSpec.args, environment);
  12475. });
  12476. };
  12477. fluid.invoke = fluid.wrapActivity(fluid.invoke, [" while invoking function with name \"", "arguments.0", "\" from component", "arguments.2"]);
  12478. /** Make a function which performs only "static redispatch" of the supplied function name -
  12479. * that is, taking only account of the contents of the "static environment". Since the static
  12480. * environment is assumed to be constant, the dispatch of the call will be evaluated at the
  12481. * time this call is made, as an optimisation.
  12482. */
  12483. fluid.makeFreeInvoker = function(functionName, environment) {
  12484. var demandSpec = fluid.determineDemands(fluid.freeInstantiator, null, functionName);
  12485. return function() {
  12486. var invokeSpec = fluid.embodyDemands(fluid.freeInstantiator, null, demandSpec, fluid.makeArray(arguments), {passArgs: true});
  12487. return fluid.invokeGlobalFunction(invokeSpec.funcName, invokeSpec.args, environment);
  12488. };
  12489. };
  12490. fluid.makeInvoker = function(instantiator, that, demandspec, functionName, environment) {
  12491. demandspec = demandspec || fluid.determineDemands(instantiator, that, functionName);
  12492. return function() {
  12493. var args = fluid.makeArray(arguments);
  12494. return fluid.pushActivity(function() {
  12495. var invokeSpec = fluid.embodyDemands(instantiator, that, demandspec, args, {passArgs: true});
  12496. return fluid.invokeGlobalFunction(invokeSpec.funcName, invokeSpec.args, environment);
  12497. }, [" while invoking invoker with name " + functionName + " on component", that]);
  12498. };
  12499. };
  12500. fluid.event.listenerEngine = function(eventSpec, callback) {
  12501. var argstruc = {};
  12502. function checkFire() {
  12503. var notall = fluid.find(eventSpec, function(value, key) {
  12504. if (argstruc[key] === undefined) {
  12505. return true;
  12506. }
  12507. });
  12508. if (!notall) {
  12509. callback(argstruc);
  12510. fluid.clear(argstruc);
  12511. }
  12512. }
  12513. fluid.each(eventSpec, function(event, eventName) {
  12514. event.addListener(function() {
  12515. argstruc[eventName] = fluid.makeArray(arguments);
  12516. checkFire();
  12517. });
  12518. });
  12519. };
  12520. // unsupported, non-API function
  12521. fluid.event.dispatchListener = function(instantiator, that, listener, eventName, eventSpec, indirectArgs) {
  12522. return fluid.wrapActivity(function() {
  12523. listener = fluid.event.resolveListener(listener); // just resolves globals
  12524. var args = indirectArgs? arguments[0] : fluid.makeArray(arguments);
  12525. var demandspec = fluid.determineDemands(instantiator, that, eventName);
  12526. if (demandspec.args.length === 0 && eventSpec.args) {
  12527. demandspec.args = eventSpec.args;
  12528. }
  12529. var resolved = fluid.embodyDemands(instantiator, that, demandspec, args, {passArgs: true, componentOptions: eventSpec});
  12530. return listener.apply(null, resolved.args);
  12531. }, [" firing to listener to event named " + eventName + " of component ", that]);
  12532. };
  12533. fluid.event.resolveListenerRecord = function(lisrec, that, eventName) {
  12534. return fluid.withInstantiator(that, function(instantiator) {
  12535. var records = fluid.makeArray(lisrec);
  12536. return fluid.transform(records, function(record) {
  12537. if (fluid.isPrimitive(record)) {
  12538. record = {listener: record};
  12539. }
  12540. var listener = fluid.expandOptions(record.listener, that);
  12541. if (!listener) {
  12542. fluid.fail("Error in listener record - could not resolve reference " + record.listener + " to a listener or firer. "
  12543. + "Did you miss out \"events.\" when referring to an event firer?");
  12544. }
  12545. if (listener.typeName === "fluid.event.firer") {
  12546. listener = listener.fire;
  12547. }
  12548. record.listener = fluid.event.dispatchListener(instantiator, that, listener, eventName, record);
  12549. return record;
  12550. });
  12551. }, [ " while resolving listener record for event named " + eventName + " for component ", that]);
  12552. };
  12553. fluid.event.expandOneEvent = function(event, that) {
  12554. var origin;
  12555. if (typeof(event) === "string" && event.charAt(0) !== "{") {
  12556. // Special dispensation so we can resolve onto our own events without GINGER WORLD
  12557. origin = that.events[event];
  12558. }
  12559. else {
  12560. origin = fluid.expandOptions(event, that);
  12561. }
  12562. if (!origin || origin.typeName !== "fluid.event.firer") {
  12563. fluid.fail("Error in event specification - could not resolve base event reference ", event, " to an event firer: got ", origin);
  12564. }
  12565. return origin;
  12566. };
  12567. fluid.event.expandEvents = function(event, that) {
  12568. return typeof(event) === "string"?
  12569. fluid.event.expandOneEvent(event, that) :
  12570. fluid.transform(event, function(oneEvent) {
  12571. return fluid.event.expandOneEvent(oneEvent, that);
  12572. });
  12573. };
  12574. // unsupported, non-API function
  12575. fluid.event.resolveEvent = function(that, eventName, eventSpec) {
  12576. return fluid.withInstantiator(that, function(instantiator) {
  12577. if (typeof(eventSpec) === "string") {
  12578. eventSpec = {event: eventSpec};
  12579. }
  12580. var event = eventSpec.event || eventSpec.events;
  12581. if (!event) {
  12582. fluid.fail("Event specification for event with name " + eventName + " does not include a base event specification: ", eventSpec);
  12583. }
  12584. var origin = fluid.event.expandEvents(event, that);
  12585. var isMultiple = origin.typeName !== "fluid.event.firer";
  12586. var isComposite = eventSpec.args || isMultiple;
  12587. // If "event" is not composite, we want to share the listener list and FIRE method with the original
  12588. // If "event" is composite, we need to create a new firer. "composite" includes case where any boiling
  12589. // occurred - this was implemented wrongly in 1.4.
  12590. var firer;
  12591. if (isComposite) {
  12592. firer = fluid.event.getEventFirer(null, null, " [composite] " + fluid.event.nameEvent(that, eventName));
  12593. var dispatcher = fluid.event.dispatchListener(instantiator, that, firer.fire, eventName, eventSpec, isMultiple);
  12594. if (isMultiple) {
  12595. fluid.event.listenerEngine(origin, dispatcher);
  12596. }
  12597. else {
  12598. origin.addListener(dispatcher);
  12599. }
  12600. }
  12601. else {
  12602. firer = {typeName: "fluid.event.firer"}; // jslint:ok - already defined
  12603. firer.fire = function () {
  12604. var outerArgs = fluid.makeArray(arguments);
  12605. return fluid.applyInstantiator(instantiator, that, function () {
  12606. return origin.fire.apply(null, outerArgs);
  12607. });
  12608. };
  12609. firer.addListener = function (listener, namespace, predicate, priority) {
  12610. var dispatcher = fluid.event.dispatchListener(instantiator, that, listener, eventName, eventSpec);
  12611. origin.addListener(dispatcher, namespace, predicate, priority);
  12612. };
  12613. firer.removeListener = function (listener) {
  12614. origin.removeListener(listener);
  12615. };
  12616. }
  12617. return firer;
  12618. }, [" while resolving event with name " + eventName + " attached to component ", that]);
  12619. };
  12620. fluid.registerNamespace("fluid.expander");
  12621. /** rescue that part of a component's options which should not be subject to
  12622. * options expansion via IoC - this initially consists of "components" and "mergePolicy"
  12623. * but will be expanded by the set of paths specified as "noexpand" within "mergePolicy"
  12624. */
  12625. // unsupported, non-API function
  12626. fluid.expander.preserveFromExpansion = function(options) {
  12627. var preserve = {};
  12628. var preserveList = fluid.arrayToHash(["mergePolicy", "mergeAllOptions", "components", "invokers", "events", "listeners", "transformOptions"]);
  12629. fluid.each(options.mergePolicy, function(value, key) {
  12630. if (fluid.mergePolicyIs(value, "noexpand")) {
  12631. preserveList[key] = true;
  12632. }
  12633. });
  12634. fluid.each(preserveList, function(xvalue, path) {
  12635. var pen = fluid.model.getPenultimate(options, path);
  12636. var value = pen.root[pen.last];
  12637. delete pen.root[pen.last];
  12638. fluid.set(preserve, path, value);
  12639. });
  12640. return {
  12641. restore: function(target) {
  12642. fluid.each(preserveList, function(xvalue, path) {
  12643. var preserved = fluid.get(preserve, path);
  12644. if (preserved !== undefined) {
  12645. fluid.set(target, path, preserved);
  12646. }
  12647. });
  12648. }
  12649. };
  12650. };
  12651. /** Expand a set of component options with respect to a set of "expanders" (essentially only
  12652. * deferredCall) - This substitution is destructive since it is assumed that the options are already "live" as the
  12653. * result of environmental substitutions. Note that options contained inside "components" will not be expanded
  12654. * by this call directly to avoid linearly increasing expansion depth if this call is occuring as a result of
  12655. * "initDependents" */
  12656. // TODO: This needs to be integrated with "embodyDemands" above which makes a call to "resolveEnvironment" directly
  12657. // but with very similarly derived options (makeStackResolverOptions)
  12658. fluid.expandOptions = function(args, that, localRecord, outerExpandOptions) {
  12659. if (!args) {
  12660. return args;
  12661. }
  12662. return fluid.withInstantiator(that, function(instantiator) {
  12663. //fluid.log("expandOptions for " + that.typeName + " executing with instantiator " + instantiator.id);
  12664. var expandOptions = makeStackResolverOptions(instantiator, that, localRecord, outerExpandOptions);
  12665. expandOptions.noCopy = true; // It is still possible a model may be fetched even though it is preserved
  12666. var pres;
  12667. if (!fluid.isArrayable(args) && !fluid.isPrimitive(args)) {
  12668. pres = fluid.expander.preserveFromExpansion(args);
  12669. }
  12670. var expanded = fluid.expander.expandLight(args, expandOptions);
  12671. if (pres) {
  12672. pres.restore(expanded);
  12673. }
  12674. return expanded;
  12675. }, [" while expanding options for component of type " + that.typeName + ": ", that]);
  12676. };
  12677. // unsupported, non-API function
  12678. fluid.locateTransformationRecord = function(that) {
  12679. return fluid.withInstantiator(that, function(instantiator) {
  12680. var matches = fluid.locateAllDemands(instantiator, that, ["fluid.transformOptions"]);
  12681. return fluid.find(matches, function(match) {
  12682. return match.uncess === 0 && fluid.contains(match.spec.contexts, that.typeName)? match.spec.spec : undefined;
  12683. });
  12684. });
  12685. };
  12686. //
  12687. fluid.hashToArray = function(hash) {
  12688. var togo = [];
  12689. fluid.each(hash, function(value, key) {
  12690. togo.push(key);
  12691. });
  12692. return togo;
  12693. };
  12694. // unsupported, non-API function
  12695. fluid.localRecordExpected = ["type", "options", "arguments", "mergeOptions",
  12696. "mergeAllOptions", "createOnEvent", "priority"];
  12697. // unsupported, non-API function
  12698. fluid.checkComponentRecord = function(defaults, localRecord) {
  12699. var expected = fluid.arrayToHash(fluid.localRecordExpected);
  12700. fluid.each(defaults.argumentMap, function(value, key) {
  12701. expected[key] = true;
  12702. });
  12703. fluid.each(localRecord, function(value, key) {
  12704. if (!expected[key]) {
  12705. fluid.fail("Probable error in subcomponent record - key \"" + key +
  12706. "\" found, where the only legal options are " +
  12707. fluid.hashToArray(expected).join(", "));
  12708. }
  12709. });
  12710. };
  12711. // unsupported, non-API function
  12712. fluid.expandComponentOptions = function(defaults, userOptions, that) {
  12713. if (userOptions && userOptions.localRecord) {
  12714. fluid.checkComponentRecord(defaults, userOptions.localRecord);
  12715. }
  12716. defaults = fluid.expandOptions(fluid.copy(defaults), that);
  12717. var localRecord = {};
  12718. if (userOptions && userOptions.marker === fluid.EXPAND) {
  12719. // TODO: Somewhat perplexing... the local record itself, by any route we could get here, consists of unexpanded
  12720. // material taken from "componentOptions"
  12721. var localOptions = fluid.get(userOptions, "localRecord.options");
  12722. if (localOptions) {
  12723. if (defaults && defaults.mergePolicy) {
  12724. localOptions.mergePolicy = defaults.mergePolicy;
  12725. }
  12726. localRecord.options = fluid.expandOptions(localOptions, that);
  12727. }
  12728. localRecord["arguments"] = fluid.get(userOptions, "localRecord.arguments");
  12729. var toExpand = userOptions.value;
  12730. userOptions = fluid.expandOptions(toExpand, that, localRecord, {direct: true});
  12731. }
  12732. localRecord.directOptions = userOptions;
  12733. if (!localRecord.options) {
  12734. // Catch the case where there is no demands block and everything is in the subcomponent record -
  12735. // in this case, embodyDemands will not construct a localRecord and what the user refers to by "options"
  12736. // is really what we properly call "directOptions".
  12737. localRecord.options = userOptions;
  12738. }
  12739. var mergeOptions = (userOptions && userOptions.mergeAllOptions) || ["{directOptions}"];
  12740. var togo = fluid.transform(mergeOptions, function(path) {
  12741. // Avoid use of expandOptions in simple case to avoid infinite recursion when constructing instantiator
  12742. return path === "{directOptions}"? localRecord.directOptions : fluid.expandOptions(path, that, localRecord, {direct: true});
  12743. });
  12744. var transRec = fluid.locateTransformationRecord(that);
  12745. if (transRec) {
  12746. togo[0].transformOptions = transRec.options;
  12747. }
  12748. return [defaults].concat(togo);
  12749. };
  12750. fluid.expandComponentOptions = fluid.wrapActivity(fluid.expandComponentOptions,
  12751. [" while expanding component options ", "arguments.1.value", " with record ", "arguments.1", " for component ", "arguments.2"]);
  12752. fluid.applyInstantiator = function(userInstantiator, that, func, message) {
  12753. var root = fluid.threadLocal();
  12754. if (userInstantiator) {
  12755. var existing = root["fluid.instantiator"];
  12756. if (existing && existing !== userInstantiator) {
  12757. fluid.fail("Error in applyInstantiator: user instantiator supplied with id " + userInstantiator.id
  12758. + " which differs from that for currently active instantiation with id " + existing.id);
  12759. }
  12760. else {
  12761. root["fluid.instantiator"] = userInstantiator;
  12762. fluid.log("*** restored USER instantiator with id " + userInstantiator.id + " - STORED");
  12763. }
  12764. }
  12765. return fluid.withInstantiator(that, func, message);
  12766. };
  12767. // The case without the instantiator is from the ginger strategy - this logic is still a little ragged
  12768. fluid.initDependent = function(that, name, userInstantiator, directArgs) {
  12769. if (!that || that[name]) { return; }
  12770. fluid.log("Beginning instantiation of component with name \"" + name + "\" as child of " + fluid.dumpThat(that));
  12771. directArgs = directArgs || [];
  12772. var component = that.options.components[name];
  12773. var instance; // escape to here for debugging purposes
  12774. fluid.applyInstantiator(userInstantiator, that, function(instantiator) {
  12775. if (typeof(component) === "string") {
  12776. that[name] = fluid.expandOptions([component], that)[0]; // TODO: expose more sensible semantic for expandOptions
  12777. }
  12778. else if (component.type) {
  12779. var invokeSpec = fluid.resolveDemands(instantiator, that, [component.type, name], directArgs, {componentRecord: component});
  12780. instantiator.pushUpcomingInstantiation(that, name);
  12781. fluid.tryCatch(function() {
  12782. that[inCreationMarker] = true;
  12783. instance = fluid.initSubcomponentImpl(that, {type: invokeSpec.funcName}, invokeSpec.args);
  12784. // The existing instantiator record will be provisional, adjust it to take account of the true return
  12785. // TODO: Instantiator contents are generally extremely incomplete
  12786. var path = fluid.composePath(instantiator.idToPath[that.id] || "", name);
  12787. var existing = instantiator.pathToComponent[path];
  12788. if (existing && existing !== instance) {
  12789. instantiator.clearComponent(that, name, existing, null, true);
  12790. }
  12791. if (instance && instance.typeName && instance.id && instance !== existing) {
  12792. instantiator.recordKnownComponent(that, instance, name);
  12793. }
  12794. that[name] = instance;
  12795. }, null, function() {
  12796. delete that[inCreationMarker];
  12797. instantiator.pushUpcomingInstantiation();
  12798. });
  12799. }
  12800. else {
  12801. that[name] = component;
  12802. }
  12803. }, [" while instantiating dependent component with name \"" + name + "\" with record ", component, " as child of ", that]);
  12804. if (instance) {
  12805. fluid.log("Finished instantiation of component with name \"" + name + "\" and id " + instance.id + " as child of " + fluid.dumpThat(that));
  12806. }
  12807. };
  12808. // NON-API function
  12809. // This function is stateful and MUST NOT be called by client code
  12810. fluid.withInstantiator = function(that, func, message) {
  12811. var root = fluid.threadLocal();
  12812. var instantiator = root["fluid.instantiator"];
  12813. if (!instantiator) {
  12814. instantiator = root["fluid.instantiator"] = fluid.instantiator();
  12815. fluid.log("Created new instantiator with id " + instantiator.id + " in order to operate on component " + (that? that.typeName : "[none]"));
  12816. }
  12817. return fluid.pushActivity(function() {
  12818. return fluid.tryCatch(function() {
  12819. if (that) {
  12820. instantiator.recordComponent(that);
  12821. }
  12822. instantiator.stack(1);
  12823. //fluid.log("Instantiator stack +1 to " + instantiator.stackCount + " for " + typeName);
  12824. return func(instantiator);
  12825. }, null, function() {
  12826. var count = instantiator.stack(-1);
  12827. //fluid.log("Instantiator stack -1 to " + instantiator.stackCount + " for " + typeName);
  12828. if (count === 0) {
  12829. fluid.log("Clearing instantiator with id " + instantiator.id + " from threadLocal for end of " + (that? that.typeName : "[none]"));
  12830. delete root["fluid.instantiator"];
  12831. }
  12832. });
  12833. }, message);
  12834. };
  12835. // unsupported, non-API function
  12836. fluid.bindDeferredComponent = function(that, componentName, component, instantiator) {
  12837. var events = fluid.makeArray(component.createOnEvent);
  12838. fluid.each(events, function(eventName) {
  12839. that.events[eventName].addListener(function() {
  12840. fluid.log("Beginning instantiation of deferred component " + componentName + " due to event " + eventName);
  12841. if (that[componentName]) {
  12842. instantiator.clearComponent(that, componentName);
  12843. }
  12844. fluid.initDependent(that, componentName, instantiator);
  12845. }, null, null, component.priority);
  12846. });
  12847. };
  12848. // unsupported, non-API function
  12849. fluid.priorityForComponent = function(component) {
  12850. return component.priority? component.priority :
  12851. (component.type === "fluid.typeFount" || fluid.hasGrade(fluid.defaults(component.type), "fluid.typeFount"))?
  12852. "first" : undefined;
  12853. };
  12854. fluid.initDependents = function(that) {
  12855. var options = that.options;
  12856. var components = options.components || {};
  12857. var componentSort = {};
  12858. fluid.withInstantiator(that, function(instantiator) {
  12859. fluid.each(components, function(component, name) {
  12860. if (!component.createOnEvent) {
  12861. var priority = fluid.priorityForComponent(component);
  12862. componentSort[name] = {key: name, priority: fluid.event.mapPriority(priority, 0)};
  12863. }
  12864. else {
  12865. fluid.bindDeferredComponent(that, name, component, instantiator);
  12866. }
  12867. });
  12868. var componentList = fluid.event.sortListeners(componentSort);
  12869. fluid.each(componentList, function(entry) {
  12870. fluid.initDependent(that, entry.key);
  12871. });
  12872. var invokers = options.invokers || {};
  12873. for (var name in invokers) {
  12874. var invokerec = invokers[name];
  12875. var funcName = typeof(invokerec) === "string"? invokerec : null;
  12876. that[name] = fluid.withInstantiator(that, function(instantiator) {
  12877. fluid.log("Beginning instantiation of invoker with name \"" + name + "\" as child of " + fluid.dumpThat(that));
  12878. return fluid.makeInvoker(instantiator, that, funcName? null : invokerec, funcName);
  12879. }, [" while instantiating invoker with name \"" + name + "\" with record ", invokerec, " as child of ", that]); // jslint:ok
  12880. fluid.log("Finished instantiation of invoker with name \"" + name + "\" as child of " + fluid.dumpThat(that));
  12881. }
  12882. }, [" while instantiating dependent components for component " + that.typeName]);
  12883. };
  12884. fluid.staticEnvironment = fluid.typeTag("fluid.staticEnvironment");
  12885. fluid.staticEnvironment.environmentClass = fluid.typeTag("fluid.browser");
  12886. // fluid.environmentalRoot.environmentClass = fluid.typeTag("fluid.rhino");
  12887. var singleThreadLocal = fluid.typeTag("fluid.dynamicEnvironment");
  12888. fluid.singleThreadLocal = function() {
  12889. return singleThreadLocal;
  12890. };
  12891. // Return to the old strategy of monkey-patching this, since this is a most frequently used function within IoC
  12892. fluid.threadLocal = fluid.singleThreadLocal;
  12893. function applyLocalChange(applier, type, path, value) {
  12894. var change = {
  12895. type: type,
  12896. path: path,
  12897. value: value
  12898. };
  12899. applier.fireChangeRequest(change);
  12900. }
  12901. // unsupported, non-API function
  12902. fluid.withEnvironment = function(envAdd, func, prefix) {
  12903. prefix = prefix || "";
  12904. var root = fluid.threadLocal();
  12905. var applier = fluid.makeChangeApplier(root, {thin: true});
  12906. return fluid.tryCatch(function() {
  12907. for (var key in envAdd) {
  12908. applyLocalChange(applier, "ADD", fluid.model.composePath(prefix, key), envAdd[key]);
  12909. }
  12910. $.extend(root, envAdd);
  12911. return func();
  12912. }, null, function() {
  12913. for (var key in envAdd) { // jslint:ok duplicate "value"
  12914. // TODO: This could be much better through i) refactoring the ChangeApplier so we could naturally use "rollback" semantics
  12915. // and/or implementing this material using some form of "prototype chain"
  12916. applyLocalChange(applier, "DELETE", fluid.model.composePath(prefix, key));
  12917. }
  12918. });
  12919. };
  12920. // unsupported, non-API function
  12921. fluid.makeEnvironmentFetcher = function(prefix, directModel, elResolver) {
  12922. return function(parsed) {
  12923. var env = fluid.get(fluid.threadLocal(), prefix);
  12924. return fluid.fetchContextReference(parsed, directModel, env, elResolver);
  12925. };
  12926. };
  12927. // unsupported, non-API function
  12928. fluid.extractEL = function(string, options) {
  12929. if (options.ELstyle === "ALL") {
  12930. return string;
  12931. }
  12932. else if (options.ELstyle.length === 1) {
  12933. if (string.charAt(0) === options.ELstyle) {
  12934. return string.substring(1);
  12935. }
  12936. }
  12937. else if (options.ELstyle === "${}") {
  12938. var i1 = string.indexOf("${");
  12939. var i2 = string.lastIndexOf("}");
  12940. if (i1 === 0 && i2 !== -1) {
  12941. return string.substring(2, i2);
  12942. }
  12943. }
  12944. };
  12945. // unsupported, non-API function
  12946. fluid.extractELWithContext = function(string, options) {
  12947. var EL = fluid.extractEL(string, options);
  12948. if (EL && EL.charAt(0) === "{") {
  12949. return fluid.parseContextReference(EL, 0);
  12950. }
  12951. return EL? {path: EL} : EL;
  12952. };
  12953. fluid.parseContextReference = function(reference, index, delimiter) {
  12954. var endcpos = reference.indexOf("}", index + 1);
  12955. if (endcpos === -1) {
  12956. fluid.fail("Cannot parse context reference \"" + reference + "\": Malformed context reference without }");
  12957. }
  12958. var context = reference.substring(index + 1, endcpos);
  12959. var endpos = delimiter? reference.indexOf(delimiter, endcpos + 1) : reference.length;
  12960. var path = reference.substring(endcpos + 1, endpos);
  12961. if (path.charAt(0) === ".") {
  12962. path = path.substring(1);
  12963. }
  12964. return {context: context, path: path, endpos: endpos};
  12965. };
  12966. fluid.renderContextReference = function(parsed) {
  12967. return "{" + parsed.context + "}." + parsed.path;
  12968. };
  12969. fluid.fetchContextReference = function(parsed, directModel, env, elResolver) {
  12970. if (elResolver) {
  12971. parsed = elResolver(parsed, env);
  12972. }
  12973. var base = parsed.context? env[parsed.context] : directModel;
  12974. if (!base) {
  12975. return base;
  12976. }
  12977. return parsed.noDereference? parsed.path : fluid.get(base, parsed.path);
  12978. };
  12979. // unsupported, non-API function
  12980. fluid.resolveContextValue = function(string, options) {
  12981. if (options.bareContextRefs && string.charAt(0) === "{") {
  12982. var parsed = fluid.parseContextReference(string, 0);
  12983. return options.fetcher(parsed);
  12984. }
  12985. else if (options.ELstyle && options.ELstyle !== "${}") {
  12986. var parsed = fluid.extractELWithContext(string, options); // jslint:ok
  12987. if (parsed) {
  12988. return options.fetcher(parsed);
  12989. }
  12990. }
  12991. while (typeof(string) === "string") {
  12992. var i1 = string.indexOf("${");
  12993. var i2 = string.indexOf("}", i1 + 2);
  12994. if (i1 !== -1 && i2 !== -1) {
  12995. var parsed; // jslint:ok
  12996. if (string.charAt(i1 + 2) === "{") {
  12997. parsed = fluid.parseContextReference(string, i1 + 2, "}");
  12998. i2 = parsed.endpos;
  12999. }
  13000. else {
  13001. parsed = {path: string.substring(i1 + 2, i2)};
  13002. }
  13003. var subs = options.fetcher(parsed);
  13004. var all = (i1 === 0 && i2 === string.length - 1);
  13005. // TODO: test case for all undefined substitution
  13006. if (subs === undefined || subs === null) {
  13007. return subs;
  13008. }
  13009. string = all? subs : string.substring(0, i1) + subs + string.substring(i2 + 1);
  13010. }
  13011. else {
  13012. break;
  13013. }
  13014. }
  13015. return string;
  13016. };
  13017. fluid.resolveContextValue = fluid.wrapActivity(fluid.resolveContextValue,
  13018. [" while resolving context value ", "arguments.0"]);
  13019. function resolveEnvironmentImpl(obj, options) {
  13020. fluid.guardCircularity(options.seenIds, obj, "expansion",
  13021. " - please ensure options are not circularly connected, or protect from expansion using the \"noexpand\" policy or expander");
  13022. function recurse(arg) {
  13023. return resolveEnvironmentImpl(arg, options);
  13024. }
  13025. if (typeof(obj) === "string" && !options.noValue) {
  13026. return fluid.resolveContextValue(obj, options);
  13027. }
  13028. else if (fluid.isPrimitive(obj) || obj.nodeType !== undefined || obj.jquery) {
  13029. return obj;
  13030. }
  13031. else if (options.filter) {
  13032. return options.filter(obj, recurse, options);
  13033. }
  13034. else {
  13035. return (options.noCopy? fluid.each : fluid.transform)(obj, function(value, key) {
  13036. return resolveEnvironmentImpl(value, options);
  13037. });
  13038. }
  13039. }
  13040. fluid.defaults("fluid.resolveEnvironment", {
  13041. ELstyle: "${}",
  13042. seenIds: {},
  13043. bareContextRefs: true
  13044. });
  13045. fluid.resolveEnvironment = function(obj, options) {
  13046. // Don't create a component here since this function is itself used in the
  13047. // component expansion pathway - avoid all expansion in any case to head off FLUID-4301
  13048. options = $.extend({}, fluid.rawDefaults("fluid.resolveEnvironment"), options);
  13049. options.seenIds = {};
  13050. return resolveEnvironmentImpl(obj, options);
  13051. };
  13052. /** "light" expanders, starting with support functions for the "deferredFetcher" expander **/
  13053. fluid.expander.deferredCall = function(target, source, recurse) {
  13054. var expander = source.expander;
  13055. var args = (!expander.args || fluid.isArrayable(expander.args))? expander.args : fluid.makeArray(expander.args);
  13056. args = recurse(args);
  13057. return fluid.invokeGlobalFunction(expander.func, args);
  13058. };
  13059. fluid.deferredCall = fluid.expander.deferredCall; // put in top namespace for convenience
  13060. fluid.deferredInvokeCall = function(target, source, recurse) {
  13061. var expander = source.expander;
  13062. var args = (!expander.args || fluid.isArrayable(expander.args))? expander.args : fluid.makeArray(expander.args);
  13063. args = recurse(args);
  13064. return fluid.invoke(expander.func, args);
  13065. };
  13066. // The "noexpand" expander which simply unwraps one level of expansion and ceases.
  13067. fluid.expander.noexpand = function(target, source) {
  13068. return $.extend(target, source.expander.tree);
  13069. };
  13070. fluid.noexpand = fluid.expander.noexpand; // TODO: check naming and namespacing
  13071. // unsupported, non-API function
  13072. fluid.expander.lightFilter = function (obj, recurse, options) {
  13073. var togo;
  13074. if (fluid.isArrayable(obj)) {
  13075. togo = options.noCopy? obj : [];
  13076. fluid.each(obj, function(value, key) {togo[key] = recurse(value);});
  13077. }
  13078. else {
  13079. togo = options.noCopy? obj : {};
  13080. for (var key in obj) {
  13081. var value = obj[key];
  13082. var expander;
  13083. if (key === "expander" && !(options.expandOnly && options.expandOnly[value.type])) {
  13084. expander = fluid.getGlobalValue(value.type);
  13085. if (expander) {
  13086. return expander.call(null, togo, obj, recurse, options);
  13087. }
  13088. }
  13089. if (key !== "expander" || !expander) {
  13090. togo[key] = recurse(value);
  13091. }
  13092. }
  13093. }
  13094. return options.noCopy? obj : togo;
  13095. };
  13096. // unsupported, non-API function
  13097. fluid.expander.expandLight = function (source, expandOptions) {
  13098. var options = $.extend({}, expandOptions);
  13099. options.filter = fluid.expander.lightFilter;
  13100. return fluid.resolveEnvironment(source, options);
  13101. };
  13102. })(jQuery, fluid_1_5);
  13103. /*
  13104. Copyright 2010-2011 OCAD University
  13105. Copyright 2010-2011 Lucendo Development Ltd.
  13106. Licensed under the Educational Community License (ECL), Version 2.0 or the New
  13107. BSD license. You may not use this file except in compliance with one these
  13108. Licenses.
  13109. You may obtain a copy of the ECL 2.0 License and BSD License at
  13110. https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
  13111. */
  13112. // Declare dependencies
  13113. /*global fluid_1_5:true, jQuery*/
  13114. // JSLint options
  13115. /*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
  13116. var fluid_1_5 = fluid_1_5 || {};
  13117. (function ($, fluid) {
  13118. /** Framework-global caching state for fluid.fetchResources **/
  13119. var resourceCache = {};
  13120. var pendingClass = {};
  13121. /** Accepts a hash of structures with free keys, where each entry has either
  13122. * href/url or nodeId set - on completion, callback will be called with the populated
  13123. * structure with fetched resource text in the field "resourceText" for each
  13124. * entry. Each structure may contain "options" holding raw options to be forwarded
  13125. * to jQuery.ajax().
  13126. */
  13127. fluid.fetchResources = function(resourceSpecs, callback, options) {
  13128. var that = fluid.initLittleComponent("fluid.fetchResources", options);
  13129. that.resourceSpecs = resourceSpecs;
  13130. that.callback = callback;
  13131. that.operate = function() {
  13132. fluid.fetchResources.fetchResourcesImpl(that);
  13133. };
  13134. fluid.each(resourceSpecs, function(resourceSpec, key) {
  13135. resourceSpec.recurseFirer = fluid.event.getEventFirer(null, null, "I/O completion for resource \"" + key + "\"");
  13136. resourceSpec.recurseFirer.addListener(that.operate);
  13137. if (resourceSpec.url && !resourceSpec.href) {
  13138. resourceSpec.href = resourceSpec.url;
  13139. }
  13140. });
  13141. if (that.options.amalgamateClasses) {
  13142. fluid.fetchResources.amalgamateClasses(resourceSpecs, that.options.amalgamateClasses, that.operate);
  13143. }
  13144. that.operate();
  13145. return that;
  13146. };
  13147. /*
  13148. * This function is unsupported: It is not really intended for use by implementors.
  13149. */
  13150. // Add "synthetic" elements of *this* resourceSpec list corresponding to any
  13151. // still pending elements matching the PROLEPTICK CLASS SPECIFICATION supplied
  13152. fluid.fetchResources.amalgamateClasses = function(specs, classes, operator) {
  13153. fluid.each(classes, function(clazz) {
  13154. var pending = pendingClass[clazz];
  13155. fluid.each(pending, function(pendingrec, canon) {
  13156. specs[clazz+"!"+canon] = pendingrec;
  13157. pendingrec.recurseFirer.addListener(operator);
  13158. });
  13159. });
  13160. };
  13161. /*
  13162. * This function is unsupported: It is not really intended for use by implementors.
  13163. */
  13164. fluid.fetchResources.timeSuccessCallback = function(resourceSpec) {
  13165. if (resourceSpec.timeSuccess && resourceSpec.options && resourceSpec.options.success) {
  13166. var success = resourceSpec.options.success;
  13167. resourceSpec.options.success = function() {
  13168. var startTime = new Date();
  13169. var ret = success.apply(null, arguments);
  13170. fluid.log("External callback for URL " + resourceSpec.href + " completed - callback time: " +
  13171. (new Date().getTime() - startTime.getTime()) + "ms");
  13172. return ret;
  13173. };
  13174. }
  13175. };
  13176. // TODO: Integrate punch-through from old Engage implementation
  13177. function canonUrl(url) {
  13178. return url;
  13179. }
  13180. fluid.fetchResources.clearResourceCache = function(url) {
  13181. if (url) {
  13182. delete resourceCache[canonUrl(url)];
  13183. }
  13184. else {
  13185. fluid.clear(resourceCache);
  13186. }
  13187. };
  13188. /*
  13189. * This function is unsupported: It is not really intended for use by implementors.
  13190. */
  13191. fluid.fetchResources.handleCachedRequest = function(resourceSpec, response) {
  13192. var canon = canonUrl(resourceSpec.href);
  13193. var cached = resourceCache[canon];
  13194. if (cached.$$firer$$) {
  13195. fluid.log("Handling request for " + canon + " from cache");
  13196. var fetchClass = resourceSpec.fetchClass;
  13197. if (fetchClass && pendingClass[fetchClass]) {
  13198. fluid.log("Clearing pendingClass entry for class " + fetchClass);
  13199. delete pendingClass[fetchClass][canon];
  13200. }
  13201. resourceCache[canon] = response;
  13202. cached.fire(response);
  13203. }
  13204. };
  13205. /*
  13206. * This function is unsupported: It is not really intended for use by implementors.
  13207. */
  13208. fluid.fetchResources.completeRequest = function(thisSpec, recurseCall) {
  13209. thisSpec.queued = false;
  13210. thisSpec.completeTime = new Date();
  13211. fluid.log("Request to URL " + thisSpec.href + " completed - total elapsed time: " +
  13212. (thisSpec.completeTime.getTime() - thisSpec.initTime.getTime()) + "ms");
  13213. thisSpec.recurseFirer.fire();
  13214. };
  13215. /*
  13216. * This function is unsupported: It is not really intended for use by implementors.
  13217. */
  13218. fluid.fetchResources.makeResourceCallback = function(thisSpec) {
  13219. return {
  13220. success: function(response) {
  13221. thisSpec.resourceText = response;
  13222. thisSpec.resourceKey = thisSpec.href;
  13223. if (thisSpec.forceCache) {
  13224. fluid.fetchResources.handleCachedRequest(thisSpec, response);
  13225. }
  13226. fluid.fetchResources.completeRequest(thisSpec);
  13227. },
  13228. error: function(response, textStatus, errorThrown) {
  13229. thisSpec.fetchError = {
  13230. status: response.status,
  13231. textStatus: response.textStatus,
  13232. errorThrown: errorThrown
  13233. };
  13234. fluid.fetchResources.completeRequest(thisSpec);
  13235. }
  13236. };
  13237. };
  13238. /*
  13239. * This function is unsupported: It is not really intended for use by implementors.
  13240. */
  13241. fluid.fetchResources.issueCachedRequest = function(resourceSpec, options) {
  13242. var canon = canonUrl(resourceSpec.href);
  13243. var cached = resourceCache[canon];
  13244. if (!cached) {
  13245. fluid.log("First request for cached resource with url " + canon);
  13246. cached = fluid.event.getEventFirer(null, null, "cache notifier for resource URL " + canon);
  13247. cached.$$firer$$ = true;
  13248. resourceCache[canon] = cached;
  13249. var fetchClass = resourceSpec.fetchClass;
  13250. if (fetchClass) {
  13251. if (!pendingClass[fetchClass]) {
  13252. pendingClass[fetchClass] = {};
  13253. }
  13254. pendingClass[fetchClass][canon] = resourceSpec;
  13255. }
  13256. options.cache = false; // TODO: Getting weird "not modified" issues on Firefox
  13257. $.ajax(options);
  13258. }
  13259. else {
  13260. if (!cached.$$firer$$) {
  13261. options.success(cached);
  13262. }
  13263. else {
  13264. fluid.log("Request for cached resource which is in flight: url " + canon);
  13265. cached.addListener(function(response) {
  13266. options.success(response);
  13267. });
  13268. }
  13269. }
  13270. };
  13271. /*
  13272. * This function is unsupported: It is not really intended for use by implementors.
  13273. */
  13274. // Compose callbacks in such a way that the 2nd, marked "external" will be applied
  13275. // first if it exists, but in all cases, the first, marked internal, will be
  13276. // CALLED WITHOUT FAIL
  13277. fluid.fetchResources.composeCallbacks = function(internal, external) {
  13278. return external? function() {
  13279. try {
  13280. external.apply(null, arguments);
  13281. }
  13282. catch (e) {
  13283. fluid.log("Exception applying external fetchResources callback: " + e);
  13284. }
  13285. internal.apply(null, arguments); // call the internal callback without fail
  13286. } : internal;
  13287. };
  13288. /*
  13289. * This function is unsupported: It is not really intended for use by implementors.
  13290. */
  13291. fluid.fetchResources.composePolicy = function(target, source, key) {
  13292. return fluid.fetchResources.composeCallbacks(target, source);
  13293. };
  13294. fluid.defaults("fluid.fetchResources.issueRequest", {
  13295. mergePolicy: {
  13296. success: fluid.fetchResources.composePolicy,
  13297. error: fluid.fetchResources.composePolicy,
  13298. url: "reverse"
  13299. }
  13300. });
  13301. /*
  13302. * This function is unsupported: It is not really intended for use by implementors.
  13303. */
  13304. fluid.fetchResources.issueRequest = function(resourceSpec, key) {
  13305. var thisCallback = fluid.fetchResources.makeResourceCallback(resourceSpec);
  13306. var options = {
  13307. url: resourceSpec.href,
  13308. success: thisCallback.success,
  13309. error: thisCallback.error,
  13310. dataType: "text"};
  13311. fluid.fetchResources.timeSuccessCallback(resourceSpec);
  13312. fluid.merge(fluid.defaults("fluid.fetchResources.issueRequest").mergePolicy,
  13313. options, resourceSpec.options);
  13314. resourceSpec.queued = true;
  13315. resourceSpec.initTime = new Date();
  13316. fluid.log("Request with key " + key + " queued for " + resourceSpec.href);
  13317. if (resourceSpec.forceCache) {
  13318. fluid.fetchResources.issueCachedRequest(resourceSpec, options);
  13319. }
  13320. else {
  13321. $.ajax(options);
  13322. }
  13323. };
  13324. fluid.fetchResources.fetchResourcesImpl = function(that) {
  13325. var complete = true;
  13326. var allSync = true;
  13327. var resourceSpecs = that.resourceSpecs;
  13328. for (var key in resourceSpecs) {
  13329. var resourceSpec = resourceSpecs[key];
  13330. if (!resourceSpec.options || resourceSpec.options.async) {
  13331. allSync = false;
  13332. }
  13333. if (resourceSpec.href && !resourceSpec.completeTime) {
  13334. if (!resourceSpec.queued) {
  13335. fluid.fetchResources.issueRequest(resourceSpec, key);
  13336. }
  13337. if (resourceSpec.queued) {
  13338. complete = false;
  13339. }
  13340. }
  13341. else if (resourceSpec.nodeId && !resourceSpec.resourceText) {
  13342. var node = document.getElementById(resourceSpec.nodeId);
  13343. // upgrade this to somehow detect whether node is "armoured" somehow
  13344. // with comment or CDATA wrapping
  13345. resourceSpec.resourceText = fluid.dom.getElementText(node);
  13346. resourceSpec.resourceKey = resourceSpec.nodeId;
  13347. }
  13348. }
  13349. if (complete && that.callback && !that.callbackCalled) {
  13350. that.callbackCalled = true;
  13351. if ($.browser.mozilla && !allSync) {
  13352. // Defer this callback to avoid debugging problems on Firefox
  13353. setTimeout(function() {
  13354. that.callback(resourceSpecs);
  13355. }, 1);
  13356. }
  13357. else {
  13358. that.callback(resourceSpecs);
  13359. }
  13360. }
  13361. };
  13362. fluid.fetchResources.primeCacheFromResources = function(componentName) {
  13363. var resources = fluid.defaults(componentName).resources;
  13364. var that = {typeName: "fluid.fetchResources.primeCacheFromResources"};
  13365. var expanded = (fluid.expandOptions ? fluid.expandOptions : fluid.identity)(fluid.copy(resources), that);
  13366. fluid.fetchResources(expanded);
  13367. };
  13368. /** Utilities invoking requests for expansion **/
  13369. fluid.registerNamespace("fluid.expander");
  13370. /*
  13371. * This function is unsupported: It is not really intended for use by implementors.
  13372. */
  13373. fluid.expander.makeDefaultFetchOptions = function (successdisposer, failid, options) {
  13374. return $.extend(true, {dataType: "text"}, options, {
  13375. success: function(response, environmentdisposer) {
  13376. var json = JSON.parse(response);
  13377. environmentdisposer(successdisposer(json));
  13378. },
  13379. error: function(response, textStatus) {
  13380. fluid.log("Error fetching " + failid + ": " + textStatus);
  13381. }
  13382. });
  13383. };
  13384. /*
  13385. * This function is unsupported: It is not really intended for use by implementors.
  13386. */
  13387. fluid.expander.makeFetchExpander = function (options) {
  13388. return { expander: {
  13389. type: "fluid.expander.deferredFetcher",
  13390. href: options.url,
  13391. options: fluid.expander.makeDefaultFetchOptions(options.disposer, options.url, options.options),
  13392. resourceSpecCollector: "{resourceSpecCollector}",
  13393. fetchKey: options.fetchKey
  13394. }};
  13395. };
  13396. fluid.expander.deferredFetcher = function(target, source, recurse, expandOptions) {
  13397. var expander = source.expander;
  13398. var spec = fluid.copy(expander);
  13399. // fetch the "global" collector specified in the external environment to receive
  13400. // this resourceSpec
  13401. var collector = fluid.resolveEnvironment(expander.resourceSpecCollector, expandOptions);
  13402. delete spec.type;
  13403. delete spec.resourceSpecCollector;
  13404. delete spec.fetchKey;
  13405. var environmentdisposer = function(disposed) {
  13406. $.extend(target, disposed);
  13407. };
  13408. // replace the callback which is t