PageRenderTime 60ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/jquery-1.1.4.js

http://js-hotkeys.googlecode.com/
JavaScript | 2441 lines | 1626 code | 431 blank | 384 comment | 735 complexity | 45cfc448c82f5c16b8cf15aeb5af20b3 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. (function(){
  2. /*
  3. * jQuery 1.1.4 - New Wave Javascript
  4. *
  5. * Copyright (c) 2007 John Resig (jquery.com)
  6. * Dual licensed under the MIT (MIT-LICENSE.txt)
  7. * and GPL (GPL-LICENSE.txt) licenses.
  8. *
  9. * $Date: 2007-08-23 21:49:27 -0400 (Thu, 23 Aug 2007) $
  10. * $Rev: 2862 $
  11. */
  12. // Map over jQuery in case of overwrite
  13. if ( typeof jQuery != "undefined" )
  14. var _jQuery = jQuery;
  15. var jQuery = window.jQuery = function(a,c) {
  16. // If the context is global, return a new object
  17. if ( window == this || !this.init )
  18. return new jQuery(a,c);
  19. return this.init(a,c);
  20. };
  21. // Map over the $ in case of overwrite
  22. if ( typeof $ != "undefined" )
  23. var _$ = $;
  24. // Map the jQuery namespace to the '$' one
  25. window.$ = jQuery;
  26. var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
  27. jQuery.fn = jQuery.prototype = {
  28. init: function(a,c) {
  29. // Make sure that a selection was provided
  30. a = a || document;
  31. // Handle HTML strings
  32. if ( typeof a == "string" ) {
  33. var m = quickExpr.exec(a);
  34. if ( m && (m[1] || !c) ) {
  35. // HANDLE: $(html) -> $(array)
  36. if ( m[1] )
  37. a = jQuery.clean( [ m[1] ] );
  38. // HANDLE: $("#id")
  39. else {
  40. var tmp = document.getElementById( m[3] );
  41. if ( tmp )
  42. // Handle the case where IE and Opera return items
  43. // by name instead of ID
  44. if ( tmp.id != m[3] )
  45. return jQuery().find( a );
  46. else {
  47. this[0] = tmp;
  48. this.length = 1;
  49. return this;
  50. }
  51. else
  52. a = [];
  53. }
  54. // HANDLE: $(expr)
  55. } else
  56. return new jQuery( c ).find( a );
  57. // HANDLE: $(function)
  58. // Shortcut for document ready
  59. } else if ( jQuery.isFunction(a) )
  60. return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
  61. return this.setArray(
  62. // HANDLE: $(array)
  63. a.constructor == Array && a ||
  64. // HANDLE: $(arraylike)
  65. // Watch for when an array-like object is passed as the selector
  66. (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
  67. // HANDLE: $(*)
  68. [ a ] );
  69. },
  70. jquery: "1.1.4",
  71. size: function() {
  72. return this.length;
  73. },
  74. length: 0,
  75. get: function( num ) {
  76. return num == undefined ?
  77. // Return a 'clean' array
  78. jQuery.makeArray( this ) :
  79. // Return just the object
  80. this[num];
  81. },
  82. pushStack: function( a ) {
  83. var ret = jQuery(a);
  84. ret.prevObject = this;
  85. return ret;
  86. },
  87. setArray: function( a ) {
  88. this.length = 0;
  89. Array.prototype.push.apply( this, a );
  90. return this;
  91. },
  92. each: function( fn, args ) {
  93. return jQuery.each( this, fn, args );
  94. },
  95. index: function( obj ) {
  96. var pos = -1;
  97. this.each(function(i){
  98. if ( this == obj ) pos = i;
  99. });
  100. return pos;
  101. },
  102. attr: function( key, value, type ) {
  103. var obj = key;
  104. // Look for the case where we're accessing a style value
  105. if ( key.constructor == String )
  106. if ( value == undefined )
  107. return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
  108. else {
  109. obj = {};
  110. obj[ key ] = value;
  111. }
  112. // Check to see if we're setting style values
  113. return this.each(function(index){
  114. // Set all the styles
  115. for ( var prop in obj )
  116. jQuery.attr(
  117. type ? this.style : this,
  118. prop, jQuery.prop(this, obj[prop], type, index, prop)
  119. );
  120. });
  121. },
  122. css: function( key, value ) {
  123. return this.attr( key, value, "curCSS" );
  124. },
  125. text: function(e) {
  126. if ( typeof e != "object" && e != null )
  127. return this.empty().append( document.createTextNode( e ) );
  128. var t = "";
  129. jQuery.each( e || this, function(){
  130. jQuery.each( this.childNodes, function(){
  131. if ( this.nodeType != 8 )
  132. t += this.nodeType != 1 ?
  133. this.nodeValue : jQuery.fn.text([ this ]);
  134. });
  135. });
  136. return t;
  137. },
  138. wrap: function() {
  139. // The elements to wrap the target around
  140. var a, args = arguments;
  141. // Wrap each of the matched elements individually
  142. return this.each(function(){
  143. if ( !a )
  144. a = jQuery.clean(args, this.ownerDocument);
  145. // Clone the structure that we're using to wrap
  146. var b = a[0].cloneNode(true);
  147. // Insert it before the element to be wrapped
  148. this.parentNode.insertBefore( b, this );
  149. // Find the deepest point in the wrap structure
  150. while ( b.firstChild )
  151. b = b.firstChild;
  152. // Move the matched element to within the wrap structure
  153. b.appendChild( this );
  154. });
  155. },
  156. append: function() {
  157. return this.domManip(arguments, true, 1, function(a){
  158. this.appendChild( a );
  159. });
  160. },
  161. prepend: function() {
  162. return this.domManip(arguments, true, -1, function(a){
  163. this.insertBefore( a, this.firstChild );
  164. });
  165. },
  166. before: function() {
  167. return this.domManip(arguments, false, 1, function(a){
  168. this.parentNode.insertBefore( a, this );
  169. });
  170. },
  171. after: function() {
  172. return this.domManip(arguments, false, -1, function(a){
  173. this.parentNode.insertBefore( a, this.nextSibling );
  174. });
  175. },
  176. end: function() {
  177. return this.prevObject || jQuery([]);
  178. },
  179. find: function(t) {
  180. var data = jQuery.map(this, function(a){ return jQuery.find(t,a); });
  181. return this.pushStack( /[^+>] [^+>]/.test( t ) || t.indexOf("..") > -1 ?
  182. jQuery.unique( data ) : data );
  183. },
  184. clone: function(deep) {
  185. deep = deep != undefined ? deep : true;
  186. var $this = this.add(this.find("*"));
  187. if (jQuery.browser.msie) {
  188. // Need to remove events on the element and its descendants
  189. $this.each(function() {
  190. this._$events = {};
  191. for (var type in this.$events)
  192. this._$events[type] = jQuery.extend({},this.$events[type]);
  193. }).unbind();
  194. }
  195. // Do the clone
  196. var r = this.pushStack( jQuery.map( this, function(a){
  197. return a.cloneNode( deep );
  198. }) );
  199. if (jQuery.browser.msie) {
  200. $this.each(function() {
  201. // Add the events back to the original and its descendants
  202. var events = this._$events;
  203. for (var type in events)
  204. for (var handler in events[type])
  205. jQuery.event.add(this, type, events[type][handler], events[type][handler].data);
  206. this._$events = null;
  207. });
  208. }
  209. // copy form values over
  210. if (deep) {
  211. var inputs = r.add(r.find('*')).filter('select,input[@type=checkbox]');
  212. $this.filter('select,input[@type=checkbox]').each(function(i) {
  213. if (this.selectedIndex)
  214. inputs[i].selectedIndex = this.selectedIndex;
  215. if (this.checked)
  216. inputs[i].checked = true;
  217. });
  218. }
  219. // Return the cloned set
  220. return r;
  221. },
  222. filter: function(t) {
  223. return this.pushStack(
  224. jQuery.isFunction( t ) &&
  225. jQuery.grep(this, function(el, index){
  226. return t.apply(el, [index]);
  227. }) ||
  228. jQuery.multiFilter(t,this) );
  229. },
  230. not: function(t) {
  231. return this.pushStack(
  232. t.constructor == String &&
  233. jQuery.multiFilter(t, this, true) ||
  234. jQuery.grep(this, function(a) {
  235. return ( t.constructor == Array || t.jquery )
  236. ? jQuery.inArray( a, t ) < 0
  237. : a != t;
  238. })
  239. );
  240. },
  241. add: function(t) {
  242. return this.pushStack( jQuery.merge(
  243. this.get(),
  244. t.constructor == String ?
  245. jQuery(t).get() :
  246. t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
  247. t : [t] )
  248. );
  249. },
  250. is: function(expr) {
  251. return expr ? jQuery.multiFilter(expr,this).length > 0 : false;
  252. },
  253. val: function( val ) {
  254. return val == undefined ?
  255. ( this.length ? this[0].value : null ) :
  256. this.attr( "value", val );
  257. },
  258. html: function( val ) {
  259. return val == undefined ?
  260. ( this.length ? this[0].innerHTML : null ) :
  261. this.empty().append( val );
  262. },
  263. slice: function() {
  264. return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
  265. },
  266. domManip: function(args, table, dir, fn){
  267. var clone = this.length > 1, a;
  268. return this.each(function(){
  269. if ( !a ) {
  270. a = jQuery.clean(args, this.ownerDocument);
  271. if ( dir < 0 )
  272. a.reverse();
  273. }
  274. var obj = this;
  275. if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
  276. obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
  277. jQuery.each( a, function(){
  278. if ( jQuery.nodeName(this, "script") ) {
  279. if ( this.src )
  280. jQuery.ajax({ url: this.src, async: false, dataType: "script" });
  281. else
  282. jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );
  283. } else
  284. fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
  285. });
  286. });
  287. }
  288. };
  289. jQuery.extend = jQuery.fn.extend = function() {
  290. // copy reference to target object
  291. var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false;
  292. // Handle a deep copy situation
  293. if ( target.constructor == Boolean ) {
  294. deep = target;
  295. target = arguments[1] || {};
  296. }
  297. // extend jQuery itself if only one argument is passed
  298. if ( al == 1 ) {
  299. target = this;
  300. a = 0;
  301. }
  302. var prop;
  303. for ( ; a < al; a++ )
  304. // Only deal with non-null/undefined values
  305. if ( (prop = arguments[a]) != null )
  306. // Extend the base object
  307. for ( var i in prop ) {
  308. // Prevent never-ending loop
  309. if ( target == prop[i] )
  310. continue;
  311. // Recurse if we're merging object values
  312. if ( deep && typeof prop[i] == 'object' && target[i] )
  313. jQuery.extend( target[i], prop[i] );
  314. // Don't bring in undefined values
  315. else if ( prop[i] != undefined )
  316. target[i] = prop[i];
  317. }
  318. // Return the modified object
  319. return target;
  320. };
  321. jQuery.extend({
  322. noConflict: function(deep) {
  323. window.$ = _$;
  324. if ( deep )
  325. window.jQuery = _jQuery;
  326. return jQuery;
  327. },
  328. // This may seem like some crazy code, but trust me when I say that this
  329. // is the only cross-browser way to do this. --John
  330. isFunction: function( fn ) {
  331. return !!fn && typeof fn != "string" && !fn.nodeName &&
  332. fn.constructor != Array && /function/i.test( fn + "" );
  333. },
  334. // check if an element is in a XML document
  335. isXMLDoc: function(elem) {
  336. return elem.documentElement && !elem.body ||
  337. elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
  338. },
  339. // Evalulates a script in a global context
  340. // Evaluates Async. in Safari 2 :-(
  341. globalEval: function( data ) {
  342. data = jQuery.trim( data );
  343. if ( data ) {
  344. if ( window.execScript )
  345. window.execScript( data );
  346. else if ( jQuery.browser.safari )
  347. // safari doesn't provide a synchronous global eval
  348. window.setTimeout( data, 0 );
  349. else
  350. eval.call( window, data );
  351. }
  352. },
  353. nodeName: function( elem, name ) {
  354. return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
  355. },
  356. // args is for internal usage only
  357. each: function( obj, fn, args ) {
  358. if ( args ) {
  359. if ( obj.length == undefined )
  360. for ( var i in obj )
  361. fn.apply( obj[i], args );
  362. else
  363. for ( var i = 0, ol = obj.length; i < ol; i++ )
  364. if ( fn.apply( obj[i], args ) === false ) break;
  365. // A special, fast, case for the most common use of each
  366. } else {
  367. if ( obj.length == undefined )
  368. for ( var i in obj )
  369. fn.call( obj[i], i, obj[i] );
  370. else
  371. for ( var i = 0, ol = obj.length, val = obj[0];
  372. i < ol && fn.call(val,i,val) !== false; val = obj[++i] ){}
  373. }
  374. return obj;
  375. },
  376. prop: function(elem, value, type, index, prop){
  377. // Handle executable functions
  378. if ( jQuery.isFunction( value ) )
  379. value = value.call( elem, [index] );
  380. // exclude the following css properties to add px
  381. var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
  382. // Handle passing in a number to a CSS property
  383. return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
  384. value + "px" :
  385. value;
  386. },
  387. className: {
  388. // internal only, use addClass("class")
  389. add: function( elem, c ){
  390. jQuery.each( (c || "").split(/\s+/), function(i, cur){
  391. if ( !jQuery.className.has( elem.className, cur ) )
  392. elem.className += ( elem.className ? " " : "" ) + cur;
  393. });
  394. },
  395. // internal only, use removeClass("class")
  396. remove: function( elem, c ){
  397. elem.className = c != undefined ?
  398. jQuery.grep( elem.className.split(/\s+/), function(cur){
  399. return !jQuery.className.has( c, cur );
  400. }).join(" ") : "";
  401. },
  402. // internal only, use is(".class")
  403. has: function( t, c ) {
  404. return jQuery.inArray( c, (t.className || t).toString().split(/\s+/) ) > -1;
  405. }
  406. },
  407. swap: function(e,o,f) {
  408. for ( var i in o ) {
  409. e.style["old"+i] = e.style[i];
  410. e.style[i] = o[i];
  411. }
  412. f.apply( e, [] );
  413. for ( var i in o )
  414. e.style[i] = e.style["old"+i];
  415. },
  416. css: function(e,p) {
  417. if ( p == "height" || p == "width" ) {
  418. var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
  419. jQuery.each( d, function(){
  420. old["padding" + this] = 0;
  421. old["border" + this + "Width"] = 0;
  422. });
  423. jQuery.swap( e, old, function() {
  424. if ( jQuery(e).is(':visible') ) {
  425. oHeight = e.offsetHeight;
  426. oWidth = e.offsetWidth;
  427. } else {
  428. e = jQuery(e.cloneNode(true))
  429. .find(":radio").removeAttr("checked").end()
  430. .css({
  431. visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
  432. }).appendTo(e.parentNode)[0];
  433. var parPos = jQuery.css(e.parentNode,"position") || "static";
  434. if ( parPos == "static" )
  435. e.parentNode.style.position = "relative";
  436. oHeight = e.clientHeight;
  437. oWidth = e.clientWidth;
  438. if ( parPos == "static" )
  439. e.parentNode.style.position = "static";
  440. e.parentNode.removeChild(e);
  441. }
  442. });
  443. return p == "height" ? oHeight : oWidth;
  444. }
  445. return jQuery.curCSS( e, p );
  446. },
  447. curCSS: function(elem, prop, force) {
  448. var ret, stack = [], swap = [];
  449. // A helper method for determining if an element's values are broken
  450. function color(a){
  451. if ( !jQuery.browser.safari )
  452. return false;
  453. var ret = document.defaultView.getComputedStyle(a,null);
  454. return !ret || ret.getPropertyValue("color") == "";
  455. }
  456. if (prop == "opacity" && jQuery.browser.msie) {
  457. ret = jQuery.attr(elem.style, "opacity");
  458. return ret == "" ? "1" : ret;
  459. }
  460. if (prop.match(/float/i))
  461. prop = styleFloat;
  462. if (!force && elem.style[prop])
  463. ret = elem.style[prop];
  464. else if (document.defaultView && document.defaultView.getComputedStyle) {
  465. if (prop.match(/float/i))
  466. prop = "float";
  467. prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
  468. var cur = document.defaultView.getComputedStyle(elem, null);
  469. if ( cur && !color(elem) )
  470. ret = cur.getPropertyValue(prop);
  471. // If the element isn't reporting its values properly in Safari
  472. // then some display: none elements are involved
  473. else {
  474. // Locate all of the parent display: none elements
  475. for ( var a = elem; a && color(a); a = a.parentNode )
  476. stack.unshift(a);
  477. // Go through and make them visible, but in reverse
  478. // (It would be better if we knew the exact display type that they had)
  479. for ( a = 0; a < stack.length; a++ )
  480. if ( color(stack[a]) ) {
  481. swap[a] = stack[a].style.display;
  482. stack[a].style.display = "block";
  483. }
  484. // Since we flip the display style, we have to handle that
  485. // one special, otherwise get the value
  486. ret = prop == "display" && swap[stack.length-1] != null ?
  487. "none" :
  488. document.defaultView.getComputedStyle(elem,null).getPropertyValue(prop) || "";
  489. // Finally, revert the display styles back
  490. for ( a = 0; a < swap.length; a++ )
  491. if ( swap[a] != null )
  492. stack[a].style.display = swap[a];
  493. }
  494. if ( prop == "opacity" && ret == "" )
  495. ret = "1";
  496. } else if (elem.currentStyle) {
  497. var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
  498. ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
  499. }
  500. return ret;
  501. },
  502. clean: function(a, doc) {
  503. var r = [];
  504. doc = doc || document;
  505. jQuery.each( a, function(i,arg){
  506. if ( !arg ) return;
  507. if ( arg.constructor == Number )
  508. arg = arg.toString();
  509. // Convert html string into DOM nodes
  510. if ( typeof arg == "string" ) {
  511. // Trim whitespace, otherwise indexOf won't work as expected
  512. var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = [];
  513. var wrap =
  514. // option or optgroup
  515. !s.indexOf("<opt") &&
  516. [1, "<select>", "</select>"] ||
  517. !s.indexOf("<leg") &&
  518. [1, "<fieldset>", "</fieldset>"] ||
  519. s.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
  520. [1, "<table>", "</table>"] ||
  521. !s.indexOf("<tr") &&
  522. [2, "<table><tbody>", "</tbody></table>"] ||
  523. // <thead> matched above
  524. (!s.indexOf("<td") || !s.indexOf("<th")) &&
  525. [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
  526. !s.indexOf("<col") &&
  527. [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"] ||
  528. // IE can't serialize <link> and <script> tags normally
  529. jQuery.browser.msie &&
  530. [1, "div<div>", "</div>"] ||
  531. [0,"",""];
  532. // Go to html and back, then peel off extra wrappers
  533. div.innerHTML = wrap[1] + arg + wrap[2];
  534. // Move to the right depth
  535. while ( wrap[0]-- )
  536. div = div.lastChild;
  537. // Remove IE's autoinserted <tbody> from table fragments
  538. if ( jQuery.browser.msie ) {
  539. // String was a <table>, *may* have spurious <tbody>
  540. if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
  541. tb = div.firstChild && div.firstChild.childNodes;
  542. // String was a bare <thead> or <tfoot>
  543. else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
  544. tb = div.childNodes;
  545. for ( var n = tb.length-1; n >= 0 ; --n )
  546. if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
  547. tb[n].parentNode.removeChild(tb[n]);
  548. // IE completely kills leading whitespace when innerHTML is used
  549. if ( /^\s/.test(arg) )
  550. div.insertBefore( doc.createTextNode( arg.match(/^\s*/)[0] ), div.firstChild );
  551. }
  552. arg = jQuery.makeArray( div.childNodes );
  553. }
  554. if ( 0 === arg.length && (!jQuery.nodeName(arg, "form") && !jQuery.nodeName(arg, "select")) )
  555. return;
  556. if ( arg[0] == undefined || jQuery.nodeName(arg, "form") || arg.options )
  557. r.push( arg );
  558. else
  559. r = jQuery.merge( r, arg );
  560. });
  561. return r;
  562. },
  563. attr: function(elem, name, value){
  564. var fix = jQuery.isXMLDoc(elem) ? {} : jQuery.props;
  565. // Safari mis-reports the default selected property of a hidden option
  566. // Accessing the parent's selectedIndex property fixes it
  567. if ( name == "selected" && jQuery.browser.safari )
  568. elem.parentNode.selectedIndex;
  569. // Certain attributes only work when accessed via the old DOM 0 way
  570. if ( fix[name] ) {
  571. if ( value != undefined ) elem[fix[name]] = value;
  572. return elem[fix[name]];
  573. } else if ( jQuery.browser.msie && name == "style" )
  574. return jQuery.attr( elem.style, "cssText", value );
  575. else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
  576. return elem.getAttributeNode(name).nodeValue;
  577. // IE elem.getAttribute passes even for style
  578. else if ( elem.tagName ) {
  579. if ( value != undefined ) elem.setAttribute( name, value );
  580. if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) )
  581. return elem.getAttribute( name, 2 );
  582. return elem.getAttribute( name );
  583. // elem is actually elem.style ... set the style
  584. } else {
  585. // IE actually uses filters for opacity
  586. if ( name == "opacity" && jQuery.browser.msie ) {
  587. if ( value != undefined ) {
  588. // IE has trouble with opacity if it does not have layout
  589. // Force it by setting the zoom level
  590. elem.zoom = 1;
  591. // Set the alpha filter to set the opacity
  592. elem.filter = (elem.filter || "").replace(/alpha\([^)]*\)/,"") +
  593. (parseFloat(value).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
  594. }
  595. return elem.filter ?
  596. (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : "";
  597. }
  598. name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
  599. if ( value != undefined ) elem[name] = value;
  600. return elem[name];
  601. }
  602. },
  603. trim: function(t){
  604. return (t||"").replace(/^\s+|\s+$/g, "");
  605. },
  606. makeArray: function( a ) {
  607. var r = [];
  608. // Need to use typeof to fight Safari childNodes crashes
  609. if ( typeof a != "array" )
  610. for ( var i = 0, al = a.length; i < al; i++ )
  611. r.push( a[i] );
  612. else
  613. r = a.slice( 0 );
  614. return r;
  615. },
  616. inArray: function( b, a ) {
  617. for ( var i = 0, al = a.length; i < al; i++ )
  618. if ( a[i] == b )
  619. return i;
  620. return -1;
  621. },
  622. merge: function(first, second) {
  623. // We have to loop this way because IE & Opera overwrite the length
  624. // expando of getElementsByTagName
  625. // Also, we need to make sure that the correct elements are being returned
  626. // (IE returns comment nodes in a '*' query)
  627. if ( jQuery.browser.msie ) {
  628. for ( var i = 0; second[i]; i++ )
  629. if ( second[i].nodeType != 8 )
  630. first.push(second[i]);
  631. } else
  632. for ( var i = 0; second[i]; i++ )
  633. first.push(second[i]);
  634. return first;
  635. },
  636. unique: function(first) {
  637. var r = [], num = jQuery.mergeNum++;
  638. try {
  639. for ( var i = 0, fl = first.length; i < fl; i++ )
  640. if ( num != first[i].mergeNum ) {
  641. first[i].mergeNum = num;
  642. r.push(first[i]);
  643. }
  644. } catch(e) {
  645. r = first;
  646. }
  647. return r;
  648. },
  649. mergeNum: 0,
  650. grep: function(elems, fn, inv) {
  651. // If a string is passed in for the function, make a function
  652. // for it (a handy shortcut)
  653. if ( typeof fn == "string" )
  654. fn = eval("false||function(a,i){return " + fn + "}");
  655. var result = [];
  656. // Go through the array, only saving the items
  657. // that pass the validator function
  658. for ( var i = 0, el = elems.length; i < el; i++ )
  659. if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
  660. result.push( elems[i] );
  661. return result;
  662. },
  663. map: function(elems, fn) {
  664. // If a string is passed in for the function, make a function
  665. // for it (a handy shortcut)
  666. if ( typeof fn == "string" )
  667. fn = eval("false||function(a){return " + fn + "}");
  668. var result = [];
  669. // Go through the array, translating each of the items to their
  670. // new value (or values).
  671. for ( var i = 0, el = elems.length; i < el; i++ ) {
  672. var val = fn(elems[i],i);
  673. if ( val !== null && val != undefined ) {
  674. if ( val.constructor != Array ) val = [val];
  675. result = result.concat( val );
  676. }
  677. }
  678. return result;
  679. }
  680. });
  681. /*
  682. * Whether the W3C compliant box model is being used.
  683. *
  684. * @property
  685. * @name $.boxModel
  686. * @type Boolean
  687. * @cat JavaScript
  688. */
  689. var userAgent = navigator.userAgent.toLowerCase();
  690. // Figure out what browser is being used
  691. jQuery.browser = {
  692. version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
  693. safari: /webkit/.test(userAgent),
  694. opera: /opera/.test(userAgent),
  695. msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
  696. mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
  697. };
  698. var styleFloat = jQuery.browser.msie ? "styleFloat" : "cssFloat";
  699. jQuery.extend({
  700. // Check to see if the W3C box model is being used
  701. boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
  702. styleFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
  703. props: {
  704. "for": "htmlFor",
  705. "class": "className",
  706. "float": styleFloat,
  707. cssFloat: styleFloat,
  708. styleFloat: styleFloat,
  709. innerHTML: "innerHTML",
  710. className: "className",
  711. value: "value",
  712. disabled: "disabled",
  713. checked: "checked",
  714. readonly: "readOnly",
  715. selected: "selected",
  716. maxlength: "maxLength"
  717. }
  718. });
  719. jQuery.each({
  720. parent: "a.parentNode",
  721. parents: "jQuery.parents(a)",
  722. next: "jQuery.nth(a,2,'nextSibling')",
  723. prev: "jQuery.nth(a,2,'previousSibling')",
  724. siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
  725. children: "jQuery.sibling(a.firstChild)"
  726. }, function(i,n){
  727. jQuery.fn[ i ] = function(a) {
  728. var ret = jQuery.map(this,n);
  729. if ( a && typeof a == "string" )
  730. ret = jQuery.multiFilter(a,ret);
  731. return this.pushStack( jQuery.unique(ret) );
  732. };
  733. });
  734. jQuery.each({
  735. appendTo: "append",
  736. prependTo: "prepend",
  737. insertBefore: "before",
  738. insertAfter: "after"
  739. }, function(i,n){
  740. jQuery.fn[ i ] = function(){
  741. var a = arguments;
  742. return this.each(function(){
  743. for ( var j = 0, al = a.length; j < al; j++ )
  744. jQuery(a[j])[n]( this );
  745. });
  746. };
  747. });
  748. jQuery.each( {
  749. removeAttr: function( key ) {
  750. jQuery.attr( this, key, "" );
  751. this.removeAttribute( key );
  752. },
  753. addClass: function(c){
  754. jQuery.className.add(this,c);
  755. },
  756. removeClass: function(c){
  757. jQuery.className.remove(this,c);
  758. },
  759. toggleClass: function( c ){
  760. jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
  761. },
  762. remove: function(a){
  763. if ( !a || jQuery.filter( a, [this] ).r.length )
  764. this.parentNode.removeChild( this );
  765. },
  766. empty: function() {
  767. while ( this.firstChild )
  768. this.removeChild( this.firstChild );
  769. }
  770. }, function(i,n){
  771. jQuery.fn[ i ] = function() {
  772. return this.each( n, arguments );
  773. };
  774. });
  775. // DEPRECATED
  776. jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
  777. jQuery.fn[ n ] = function(num,fn) {
  778. return this.filter( ":" + n + "(" + num + ")", fn );
  779. };
  780. });
  781. jQuery.each( [ "height", "width" ], function(i,n){
  782. jQuery.fn[ n ] = function(h) {
  783. return h == undefined ?
  784. ( this.length ? jQuery.css( this[0], n ) : null ) :
  785. this.css( n, h.constructor == String ? h : h + "px" );
  786. };
  787. });
  788. var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
  789. "(?:[\\w*_-]|\\\\.)" :
  790. "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
  791. quickChild = new RegExp("^[/>]\\s*(" + chars + "+)"),
  792. quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
  793. quickClass = new RegExp("^([#.]?)(" + chars + "*)");
  794. jQuery.extend({
  795. expr: {
  796. "": "m[2]=='*'||jQuery.nodeName(a,m[2])",
  797. "#": "a.getAttribute('id')==m[2]",
  798. ":": {
  799. // Position Checks
  800. lt: "i<m[3]-0",
  801. gt: "i>m[3]-0",
  802. nth: "m[3]-0==i",
  803. eq: "m[3]-0==i",
  804. first: "i==0",
  805. last: "i==r.length-1",
  806. even: "i%2==0",
  807. odd: "i%2",
  808. // Child Checks
  809. "first-child": "a.parentNode.getElementsByTagName('*')[0]==a",
  810. "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
  811. "only-child": "!jQuery.nth(a.parentNode.lastChild,2,'previousSibling')",
  812. // Parent Checks
  813. parent: "a.firstChild",
  814. empty: "!a.firstChild",
  815. // Text Check
  816. contains: "(a.textContent||a.innerText||'').indexOf(m[3])>=0",
  817. // Visibility
  818. visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
  819. hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
  820. // Form attributes
  821. enabled: "!a.disabled",
  822. disabled: "a.disabled",
  823. checked: "a.checked",
  824. selected: "a.selected||jQuery.attr(a,'selected')",
  825. // Form elements
  826. text: "'text'==a.type",
  827. radio: "'radio'==a.type",
  828. checkbox: "'checkbox'==a.type",
  829. file: "'file'==a.type",
  830. password: "'password'==a.type",
  831. submit: "'submit'==a.type",
  832. image: "'image'==a.type",
  833. reset: "'reset'==a.type",
  834. button: '"button"==a.type||jQuery.nodeName(a,"button")',
  835. input: "/input|select|textarea|button/i.test(a.nodeName)",
  836. // :has()
  837. has: "jQuery.find(m[3],a).length"
  838. },
  839. // DEPRECATED
  840. "[": "jQuery.find(m[2],a).length"
  841. },
  842. // The regular expressions that power the parsing engine
  843. parse: [
  844. // Match: [@value='test'], [@foo]
  845. /^\[ *(@)([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
  846. // DEPRECATED
  847. // Match: [div], [div p]
  848. /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/,
  849. // Match: :contains('foo')
  850. /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
  851. // Match: :even, :last-chlid, #id, .class
  852. new RegExp("^([:.#]*)(" + chars + "+)")
  853. ],
  854. multiFilter: function( expr, elems, not ) {
  855. var old, cur = [];
  856. while ( expr && expr != old ) {
  857. old = expr;
  858. var f = jQuery.filter( expr, elems, not );
  859. expr = f.t.replace(/^\s*,\s*/, "" );
  860. cur = not ? elems = f.r : jQuery.merge( cur, f.r );
  861. }
  862. return cur;
  863. },
  864. find: function( t, context ) {
  865. // Quickly handle non-string expressions
  866. if ( typeof t != "string" )
  867. return [ t ];
  868. // Make sure that the context is a DOM Element
  869. if ( context && !context.nodeType )
  870. context = null;
  871. // Set the correct context (if none is provided)
  872. context = context || document;
  873. // DEPRECATED
  874. // Handle the common XPath // expression
  875. if ( !t.indexOf("//") ) {
  876. //context = context.documentElement;
  877. t = t.substr(2,t.length);
  878. // DEPRECATED
  879. // And the / root expression
  880. } else if ( !t.indexOf("/") && !context.ownerDocument ) {
  881. context = context.documentElement;
  882. t = t.substr(1,t.length);
  883. if ( t.indexOf("/") >= 1 )
  884. t = t.substr(t.indexOf("/"),t.length);
  885. }
  886. // Initialize the search
  887. var ret = [context], done = [], last;
  888. // Continue while a selector expression exists, and while
  889. // we're no longer looping upon ourselves
  890. while ( t && last != t ) {
  891. var r = [];
  892. last = t;
  893. // DEPRECATED
  894. t = jQuery.trim(t).replace( /^\/\//, "" );
  895. var foundToken = false;
  896. // An attempt at speeding up child selectors that
  897. // point to a specific element tag
  898. var re = quickChild;
  899. var m = re.exec(t);
  900. if ( m ) {
  901. var nodeName = m[1].toUpperCase();
  902. // Perform our own iteration and filter
  903. for ( var i = 0; ret[i]; i++ )
  904. for ( var c = ret[i].firstChild; c; c = c.nextSibling )
  905. if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName.toUpperCase()) )
  906. r.push( c );
  907. ret = r;
  908. t = t.replace( re, "" );
  909. if ( t.indexOf(" ") == 0 ) continue;
  910. foundToken = true;
  911. } else {
  912. // (.. and /) DEPRECATED
  913. re = /^((\/?\.\.)|([>\/+~]))\s*(\w*)/i;
  914. if ( (m = re.exec(t)) != null ) {
  915. r = [];
  916. var nodeName = m[4], mergeNum = jQuery.mergeNum++;
  917. m = m[1];
  918. for ( var j = 0, rl = ret.length; j < rl; j++ )
  919. if ( m.indexOf("..") < 0 ) {
  920. var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
  921. for ( ; n; n = n.nextSibling )
  922. if ( n.nodeType == 1 ) {
  923. if ( m == "~" && n.mergeNum == mergeNum ) break;
  924. if (!nodeName || n.nodeName.toUpperCase() == nodeName.toUpperCase() ) {
  925. if ( m == "~" ) n.mergeNum = mergeNum;
  926. r.push( n );
  927. }
  928. if ( m == "+" ) break;
  929. }
  930. // DEPRECATED
  931. } else
  932. r.push( ret[j].parentNode );
  933. ret = r;
  934. // And remove the token
  935. t = jQuery.trim( t.replace( re, "" ) );
  936. foundToken = true;
  937. }
  938. }
  939. // See if there's still an expression, and that we haven't already
  940. // matched a token
  941. if ( t && !foundToken ) {
  942. // Handle multiple expressions
  943. if ( !t.indexOf(",") ) {
  944. // Clean the result set
  945. if ( context == ret[0] ) ret.shift();
  946. // Merge the result sets
  947. done = jQuery.merge( done, ret );
  948. // Reset the context
  949. r = ret = [context];
  950. // Touch up the selector string
  951. t = " " + t.substr(1,t.length);
  952. } else {
  953. // Optimize for the case nodeName#idName
  954. var re2 = quickID;
  955. var m = re2.exec(t);
  956. // Re-organize the results, so that they're consistent
  957. if ( m ) {
  958. m = [ 0, m[2], m[3], m[1] ];
  959. } else {
  960. // Otherwise, do a traditional filter check for
  961. // ID, class, and element selectors
  962. re2 = quickClass;
  963. m = re2.exec(t);
  964. }
  965. m[2] = m[2].replace(/\\/g, "");
  966. var elem = ret[ret.length-1];
  967. // Try to do a global search by ID, where we can
  968. if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
  969. // Optimization for HTML document case
  970. var oid = elem.getElementById(m[2]);
  971. // Do a quick check for the existence of the actual ID attribute
  972. // to avoid selecting by the name attribute in IE
  973. // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
  974. if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
  975. oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
  976. // Do a quick check for node name (where applicable) so
  977. // that div#foo searches will be really fast
  978. ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
  979. } else {
  980. // We need to find all descendant elements
  981. for ( var i = 0; ret[i]; i++ ) {
  982. // Grab the tag name being searched for
  983. var tag = m[1] != "" || m[0] == "" ? "*" : m[2];
  984. // Handle IE7 being really dumb about <object>s
  985. if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
  986. tag = "param";
  987. r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
  988. }
  989. // It's faster to filter by class and be done with it
  990. if ( m[1] == "." )
  991. r = jQuery.classFilter( r, m[2] );
  992. // Same with ID filtering
  993. if ( m[1] == "#" ) {
  994. var tmp = [];
  995. // Try to find the element with the ID
  996. for ( var i = 0; r[i]; i++ )
  997. if ( r[i].getAttribute("id") == m[2] ) {
  998. tmp = [ r[i] ];
  999. break;
  1000. }
  1001. r = tmp;
  1002. }
  1003. ret = r;
  1004. }
  1005. t = t.replace( re2, "" );
  1006. }
  1007. }
  1008. // If a selector string still exists
  1009. if ( t ) {
  1010. // Attempt to filter it
  1011. var val = jQuery.filter(t,r);
  1012. ret = r = val.r;
  1013. t = jQuery.trim(val.t);
  1014. }
  1015. }
  1016. // An error occurred with the selector;
  1017. // just return an empty set instead
  1018. if ( t )
  1019. ret = [];
  1020. // Remove the root context
  1021. if ( ret && context == ret[0] )
  1022. ret.shift();
  1023. // And combine the results
  1024. done = jQuery.merge( done, ret );
  1025. return done;
  1026. },
  1027. classFilter: function(r,m,not){
  1028. m = " " + m + " ";
  1029. var tmp = [];
  1030. for ( var i = 0; r[i]; i++ ) {
  1031. var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
  1032. if ( !not && pass || not && !pass )
  1033. tmp.push( r[i] );
  1034. }
  1035. return tmp;
  1036. },
  1037. filter: function(t,r,not) {
  1038. var last;
  1039. // Look for common filter expressions
  1040. while ( t && t != last ) {
  1041. last = t;
  1042. var p = jQuery.parse, m;
  1043. for ( var i = 0; p[i]; i++ ) {
  1044. m = p[i].exec( t );
  1045. if ( m ) {
  1046. // Remove what we just matched
  1047. t = t.substring( m[0].length );
  1048. m[2] = m[2].replace(/\\/g, "");
  1049. break;
  1050. }
  1051. }
  1052. if ( !m )
  1053. break;
  1054. // :not() is a special case that can be optimized by
  1055. // keeping it out of the expression list
  1056. if ( m[1] == ":" && m[2] == "not" )
  1057. r = jQuery.filter(m[3], r, true).r;
  1058. // We can get a big speed boost by filtering by class here
  1059. else if ( m[1] == "." )
  1060. r = jQuery.classFilter(r, m[2], not);
  1061. else if ( m[1] == "@" ) {
  1062. var tmp = [], type = m[3];
  1063. for ( var i = 0, rl = r.length; i < rl; i++ ) {
  1064. var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
  1065. if ( z == null || /href|src|selected/.test(m[2]) )
  1066. z = jQuery.attr(a,m[2]) || '';
  1067. if ( (type == "" && !!z ||
  1068. type == "=" && z == m[5] ||
  1069. type == "!=" && z != m[5] ||
  1070. type == "^=" && z && !z.indexOf(m[5]) ||
  1071. type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
  1072. (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
  1073. tmp.push( a );
  1074. }
  1075. r = tmp;
  1076. // We can get a speed boost by handling nth-child here
  1077. } else if ( m[1] == ":" && m[2] == "nth-child" ) {
  1078. var num = jQuery.mergeNum++, tmp = [],
  1079. test = /(\d*)n\+?(\d*)/.exec(
  1080. m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
  1081. !/\D/.test(m[3]) && "n+" + m[3] || m[3]),
  1082. first = (test[1] || 1) - 0, last = test[2] - 0;
  1083. for ( var i = 0, rl = r.length; i < rl; i++ ) {
  1084. var node = r[i], parentNode = node.parentNode;
  1085. if ( num != parentNode.mergeNum ) {
  1086. var c = 1;
  1087. for ( var n = parentNode.firstChild; n; n = n.nextSibling )
  1088. if ( n.nodeType == 1 )
  1089. n.nodeIndex = c++;
  1090. parentNode.mergeNum = num;
  1091. }
  1092. var add = false;
  1093. if ( first == 1 ) {
  1094. if ( last == 0 || node.nodeIndex == last )
  1095. add = true;
  1096. } else if ( (node.nodeIndex + last) % first == 0 )
  1097. add = true;
  1098. if ( add ^ not )
  1099. tmp.push( node );
  1100. }
  1101. r = tmp;
  1102. // Otherwise, find the expression to execute
  1103. } else {
  1104. var f = jQuery.expr[m[1]];
  1105. if ( typeof f != "string" )
  1106. f = jQuery.expr[m[1]][m[2]];
  1107. // Build a custom macro to enclose it
  1108. f = eval("false||function(a,i){return " + f + "}");
  1109. // Execute it against the current filter
  1110. r = jQuery.grep( r, f, not );
  1111. }
  1112. }
  1113. // Return an array of filtered elements (r)
  1114. // and the modified expression string (t)
  1115. return { r: r, t: t };
  1116. },
  1117. parents: function( elem ){
  1118. var matched = [];
  1119. var cur = elem.parentNode;
  1120. while ( cur && cur != document ) {
  1121. matched.push( cur );
  1122. cur = cur.parentNode;
  1123. }
  1124. return matched;
  1125. },
  1126. nth: function(cur,result,dir,elem){
  1127. result = result || 1;
  1128. var num = 0;
  1129. for ( ; cur; cur = cur[dir] )
  1130. if ( cur.nodeType == 1 && ++num == result )
  1131. break;
  1132. return cur;
  1133. },
  1134. sibling: function( n, elem ) {
  1135. var r = [];
  1136. for ( ; n; n = n.nextSibling ) {
  1137. if ( n.nodeType == 1 && (!elem || n != elem) )
  1138. r.push( n );
  1139. }
  1140. return r;
  1141. }
  1142. });
  1143. /*
  1144. * A number of helper functions used for managing events.
  1145. * Many of the ideas behind this code orignated from
  1146. * Dean Edwards' addEvent library.
  1147. */
  1148. jQuery.event = {
  1149. // Bind an event to an element
  1150. // Original by Dean Edwards
  1151. add: function(element, type, handler, data) {
  1152. // For whatever reason, IE has trouble passing the window object
  1153. // around, causing it to be cloned in the process
  1154. if ( jQuery.browser.msie && element.setInterval != undefined )
  1155. element = window;
  1156. // Make sure that the function being executed has a unique ID
  1157. if ( !handler.guid )
  1158. handler.guid = this.guid++;
  1159. // if data is passed, bind to handler
  1160. if( data != undefined ) {
  1161. // Create temporary function pointer to original handler
  1162. var fn = handler;
  1163. // Create unique handler function, wrapped around original handler
  1164. handler = function() {
  1165. // Pass arguments and context to original handler
  1166. return fn.apply(this, arguments);
  1167. };
  1168. // Store data in unique handler
  1169. handler.data = data;
  1170. // Set the guid of unique handler to the same of original handler, so it can be removed
  1171. handler.guid = fn.guid;
  1172. }
  1173. // Init the element's event structure
  1174. if (!element.$events)
  1175. element.$events = {};
  1176. if (!element.$handle)
  1177. element.$handle = function() {
  1178. // returned undefined or false
  1179. var val;
  1180. // Handle the second event of a trigger and when
  1181. // an event is called after a page has unloaded
  1182. if ( typeof jQuery == "undefined" || jQuery.event.triggered )
  1183. return val;
  1184. val = jQuery.event.handle.apply(element, arguments);
  1185. return val;
  1186. };
  1187. // Get the current list of functions bound to this event
  1188. var handlers = element.$events[type];
  1189. // Init the event handler queue
  1190. if (!handlers) {
  1191. handlers = element.$events[type] = {};
  1192. // And bind the global event handler to the element
  1193. if (element.addEventListener)
  1194. element.addEventListener(type, element.$handle, false);
  1195. else
  1196. element.attachEvent("on" + type, element.$handle);
  1197. }
  1198. // Add the function to the element's handler list
  1199. handlers[handler.guid] = handler;
  1200. // Keep track of which events have been used, for global triggering
  1201. this.global[type] = true;
  1202. },
  1203. guid: 1,
  1204. global: {},
  1205. // Detach an event or set of events from an element
  1206. remove: function(element, type, handler) {
  1207. var events = element.$events, ret, index;
  1208. if ( events ) {
  1209. // type is actually an event object here
  1210. if ( type && type.type ) {
  1211. handler = type.handler;
  1212. type = type.type;
  1213. }
  1214. if ( !type ) {
  1215. for ( type in events )
  1216. this.remove( element, type );
  1217. } else if ( events[type] ) {
  1218. // remove the given handler for the given type
  1219. if ( handler )
  1220. delete events[type][handler.guid];
  1221. // remove all handlers for the given type
  1222. else
  1223. for ( handler in element.$events[type] )
  1224. delete events[type][handler];
  1225. // remove generic event handler if no more handlers exist
  1226. for ( ret in events[type] ) break;
  1227. if ( !ret ) {
  1228. if (element.removeEventListener)
  1229. element.removeEventListener(type, element.$handle, false);
  1230. else
  1231. element.detachEvent("on" + type, element.$handle);
  1232. ret = null;
  1233. delete events[type];
  1234. }
  1235. }
  1236. // Remove the expando if it's no longer used
  1237. for ( ret in events ) break;
  1238. if ( !ret )
  1239. element.$handle = element.$events = null;
  1240. }
  1241. },
  1242. trigger: function(type, data, element) {
  1243. // Clone the incoming data, if any
  1244. data = jQuery.makeArray(data || []);
  1245. // Handle a global trigger
  1246. if ( !element ) {
  1247. // Only trigger if we've ever bound an event for it
  1248. if ( this.global[type] )
  1249. jQuery("*").add([window, document]).trigger(type, data);
  1250. // Handle triggering a single element
  1251. } else {
  1252. var val, ret, fn = jQuery.isFunction( element[ type ] || null );
  1253. // Pass along a fake event
  1254. data.unshift( this.fix({ type: type, target: element }) );
  1255. // Trigger the event
  1256. if ( jQuery.isFunction( element.$handle ) )
  1257. val = element.$handle.apply( element, data );
  1258. if ( !fn && element["on"+type] && element["on"+type].apply( element, data ) === false )
  1259. val = false;
  1260. if ( fn && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) {
  1261. this.triggered = true;
  1262. element[ type ]();
  1263. }
  1264. this.triggered = false;
  1265. }
  1266. },
  1267. handle: function(event) {
  1268. // returned undefined or false
  1269. var val;
  1270. // Empty object is for triggered events with no data
  1271. event = jQuery.event.fix( event || window.event || {} );
  1272. var c = this.$events && this.$events[event.type], args = Array.prototype.slice.call( arguments, 1 );
  1273. args.unshift( event );
  1274. for ( var j in c ) {
  1275. // Pass in a reference to the handler function itself
  1276. // So that we can later remove it
  1277. args[0].handler = c[j];
  1278. args[0].data = c[j].data;
  1279. if ( c[j].apply( this, args ) === false ) {
  1280. event.preventDefault();
  1281. event.stopPropagation();
  1282. val = false;
  1283. }
  1284. }
  1285. // Clean up added properties in IE to prevent memory leak
  1286. if (jQuery.browser.msie)
  1287. event.target = event.preventDefault = event.stopPropagation =
  1288. event.handler = event.data = null;
  1289. return val;
  1290. },
  1291. fix: function(event) {
  1292. // store a copy of the original event object
  1293. // and clone to set read-only properties
  1294. var originalEvent = event;
  1295. event = jQuery.extend({}, originalEvent);
  1296. // add preventDefault and stopPropagation since
  1297. // they will not work on the clone
  1298. event.preventDefault = function() {
  1299. // if preventDefault exists run it on the original event
  1300. if (originalEvent.preventDefault)
  1301. originalEvent.preventDefault();
  1302. // otherwise set the returnValue property of the original event to false (IE)
  1303. originalEvent.returnValue = false;
  1304. };
  1305. event.stopPropagation = function() {
  1306. // if stopPropagation exists run it on the original event
  1307. if (originalEvent.stopPropagation)
  1308. originalEvent.stopPropagation();
  1309. // otherwise set the cancelBubble property of the original event to true (IE)
  1310. originalEvent.cancelBubble = true;
  1311. };
  1312. // Fix target property, if necessary
  1313. if ( !event.target && event.srcElement )
  1314. event.target = event.srcElement;
  1315. // check if target is a textnode (safari)
  1316. if (jQuery.browser.safari && event.target.nodeType == 3)
  1317. event.target = originalEvent.target.parentNode;
  1318. // Add relatedTarget, if necessary
  1319. if ( !event.relatedTarget && event.fromElement )
  1320. event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
  1321. // Calculate pageX/Y if missing and clientX/Y available
  1322. if ( event.pageX == null && event.clientX != null ) {
  1323. var e = document.documentElement, b = document.body;
  1324. event.pageX = event.clientX + (e && e.scrollLeft || b.scrollLeft || 0);
  1325. event.pageY = event.clientY + (e && e.scrollTop || b.scrollTop || 0);
  1326. }
  1327. // Add which for key events
  1328. if ( !event.which && (event.charCode || event.keyCode) )
  1329. event.which = event.charCode || event.keyCode;
  1330. // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
  1331. if ( !event.metaKey && event.ctrlKey )
  1332. event.metaKey = event.ctrlKey;
  1333. // Add which for click: 1 == left; 2 == middle; 3 == right
  1334. // Note: button is not normalized, so don't use it
  1335. if ( !event.which && event.button )
  1336. event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
  1337. return event;
  1338. }
  1339. };
  1340. jQuery.fn.extend({
  1341. bind: function( type, data, fn ) {
  1342. return type == "unload" ? this.one(type, data, fn) : this.each(function(){
  1343. jQuery.event.add( this, type, fn || data, fn && data );
  1344. });
  1345. },
  1346. one: function( type, data, fn ) {
  1347. return this.each(function(){
  1348. jQuery.event.add( this, type, function(event) {
  1349. jQuery(this).unbind(event);
  1350. return (fn || data).apply( this, arguments);
  1351. }, fn && data);
  1352. });
  1353. },
  1354. unbind: function( type, fn ) {
  1355. return this.each(function(){
  1356. jQuery.event.remove( this, type, fn );
  1357. });
  1358. },
  1359. trigger: function( type, data ) {
  1360. return this.each(function(){
  1361. jQuery.event.trigger( type, data, this );
  1362. });
  1363. },
  1364. toggle: function() {
  1365. // Save reference to arguments for access in closure
  1366. var a = arguments;
  1367. return this.click(function(e) {
  1368. // Figure out which function to execute
  1369. this.lastToggle = 0 == this.lastToggle ? 1 : 0;
  1370. // Make sure that clicks stop
  1371. e.preventDefault();
  1372. // and execute the function
  1373. return a[this.lastToggle].apply( this, [e] ) || false;
  1374. });
  1375. },
  1376. hover: function(f,g) {
  1377. // A private function for handling mouse 'hovering'
  1378. function handleHover(e) {
  1379. // Check if mouse(over|out) are still within the same parent element
  1380. var p = e.relatedTarget;
  1381. // Traverse up the tree
  1382. while ( p && p != this ) try { p = p.parentNode; } catch(e) { p = this; };
  1383. // If we actually just moused on to a sub-element, ignore it
  1384. if ( p == this ) return false;
  1385. // Execute the right function
  1386. return (e.type == "mouseover" ? f : g).apply(this, [e]);
  1387. }
  1388. // Bind the function to the two event listeners
  1389. return this.mouseover(handleHover).mouseout(handleHover);
  1390. },
  1391. ready: function(f) {
  1392. // Attach the listeners
  1393. bindReady();
  1394. // If the DOM is already ready
  1395. if ( jQuery.isReady )
  1396. // Execute the function immediately
  1397. f.apply( document, [jQuery] );
  1398. // Otherwise, remember the function for later
  1399. else
  1400. // Add the function to the wait list
  1401. jQuery.readyList.push( function() { return f.apply(this, [jQuery]); } );
  1402. return this;
  1403. }
  1404. });
  1405. jQuery.extend({
  1406. /*
  1407. * All the code that makes DOM Ready work nicely.
  1408. */
  1409. isReady: false,
  1410. readyList: [],
  1411. // Handle when the DOM is ready
  1412. ready: function() {
  1413. // Make sure that the DOM is not already loaded
  1414. if ( !jQuery.isReady ) {
  1415. // Remember that the DOM is ready
  1416. jQuery.isReady = true;
  1417. // If there are functions bound, to execute
  1418. if ( jQuery.readyList ) {
  1419. // Execute all of them
  1420. jQuery.each( jQuery.readyList, function(){
  1421. this.apply( document );
  1422. });
  1423. // Reset the list of functions
  1424. jQuery.readyList = null;
  1425. }
  1426. // Remove event listener to avoid memory leak
  1427. if ( jQuery.browser.mozilla || jQuery.browser.opera )
  1428. document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
  1429. // Remove script element used by IE hack
  1430. if( !window.frames.length ) // don't remove if frames are present (#1187)
  1431. jQuery(window).load(function(){ jQuery("#__ie_init").remove(); });
  1432. }
  1433. }
  1434. });
  1435. jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
  1436. "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
  1437. "submit,keydown,keypress,keyup,error").split(","), function(i,o){
  1438. // Handle event binding
  1439. jQuery.fn[o] = function(f){
  1440. return f ? this.bind(o, f) : this.trigger(o);
  1441. };
  1442. });
  1443. var readyBound = false;
  1444. function bindReady(){
  1445. if ( readyBound ) return;
  1446. readyBound = true;
  1447. // If Mozilla is used
  1448. if ( jQuery.browser.mozilla || jQuery.browser.opera )
  1449. // Use the handy event callback
  1450. document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
  1451. // If IE is used, use the excellent hack by Matthias Miller
  1452. // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
  1453. else if ( jQuery.browser.msie ) {
  1454. // Only works if you document.write() it
  1455. document.write("<scr" + "ipt id=__ie_init defer=true " +
  1456. "src=//:><\/script>");
  1457. // Use the defer script hack
  1458. var script = document.getElementById("__ie_init");
  1459. // script does not exist if jQuery is loaded dynamically
  1460. if ( script )
  1461. script.onreadystatechange = function() {
  1462. if ( document.readyState != "complete" ) return;
  1463. jQuery.ready();
  1464. };
  1465. // Clear from memory
  1466. script = null;
  1467. // If Safari is used
  1468. } else if ( jQuery.browser.safari )
  1469. // Continually check to see if the document.readyState is valid
  1470. jQuery.safariTimer = setInterval(function(){
  1471. // loaded and complete are both valid states
  1472. if ( document.readyState == "loaded" ||
  1473. document.readyState == "complete" ) {
  1474. // If either one are found, remove the timer
  1475. clearInterval( jQuery.safariTimer );
  1476. jQuery.safariTimer = null;
  1477. // and execute any waiting functions
  1478. jQuery.ready();
  1479. }
  1480. }, 10);
  1481. // A fallback to window.onload, that will always work
  1482. jQuery.event.add( window, "load", jQuery.ready );
  1483. }
  1484. jQuery.fn.extend({
  1485. // DEPRECATED
  1486. loadIfModified: function( url, params, callback ) {
  1487. this.load( url, params, callback, 1 );
  1488. },
  1489. load: function( url, params, callback, ifModified ) {
  1490. if ( jQuery.isFunction( url ) )
  1491. return this.bind("load", url);
  1492. callback = callback || function(){};
  1493. // Default to a GET request
  1494. var type = "GET";
  1495. // If the second parameter was provided
  1496. if ( params )
  1497. // If it's a function
  1498. if ( jQuery.isFunction( params ) ) {
  1499. // We assume that it's the callback
  1500. callback = params;
  1501. params = null;
  1502. // Otherwise, build a param string
  1503. } else {
  1504. params = jQuery.param( params );
  1505. type = "POST";
  1506. }
  1507. var self = this;
  1508. // Request the remote document
  1509. jQuery.ajax({
  1510. url: url,
  1511. type: type,
  1512. data: params,
  1513. ifModified: ifModified,
  1514. complete: function(res, status){
  1515. // If successful, inject the HTML into all the matched elements
  1516. if ( status ==

Large files files are truncated, but you can click here to view the full file