[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 /* prevent execution of jQuery if included more than once */ 2 if(typeof window.jQuery == "undefined") { 3 /* 4 * jQuery @VERSION - New Wave Javascript 5 * 6 * Copyright (c) 2007 John Resig (jquery.com) 7 * Dual licensed under the MIT (MIT-LICENSE.txt) 8 * and GPL (GPL-LICENSE.txt) licenses. 9 * 10 * $Date: 2007/05/14 17:26:39 $ 11 * $Rev: 1897 $ 12 */ 13 14 // Global undefined variable 15 window.undefined = window.undefined; 16 17 /** 18 * Create a new jQuery Object 19 * 20 * @constructor 21 * @private 22 * @name jQuery 23 * @param String|Function|Element|Array<Element>|jQuery a selector 24 * @param jQuery|Element|Array<Element> c context 25 * @cat Core 26 */ 27 var jQuery = function(a,c) { 28 // If the context is global, return a new object 29 if ( window == this ) 30 return new jQuery(a,c); 31 32 return this.init(a,c); 33 }; 34 35 // Map over the $ in case of overwrite 36 if ( typeof $ != "undefined" ) 37 jQuery._$ = $; 38 39 // Map the jQuery namespace to the '$' one 40 var $ = jQuery; 41 42 /** 43 * This function accepts a string containing a CSS or 44 * basic XPath selector which is then used to match a set of elements. 45 * 46 * The core functionality of jQuery centers around this function. 47 * Everything in jQuery is based upon this, or uses this in some way. 48 * The most basic use of this function is to pass in an expression 49 * (usually consisting of CSS or XPath), which then finds all matching 50 * elements. 51 * 52 * By default, if no context is specified, $() looks for DOM elements within the context of the 53 * current HTML document. If you do specify a context, such as a DOM 54 * element or jQuery object, the expression will be matched against 55 * the contents of that context. 56 * 57 * See [[DOM/Traversing/Selectors]] for the allowed CSS/XPath syntax for expressions. 58 * 59 * @example $("div > p") 60 * @desc Finds all p elements that are children of a div element. 61 * @before <p>one</p> <div><p>two</p></div> <p>three</p> 62 * @result [ <p>two</p> ] 63 * 64 * @example $("input:radio", document.forms[0]) 65 * @desc Searches for all inputs of type radio within the first form in the document 66 * 67 * @example $("div", xml.responseXML) 68 * @desc This finds all div elements within the specified XML document. 69 * 70 * @name $ 71 * @param String expr An expression to search with 72 * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context 73 * @cat Core 74 * @type jQuery 75 * @see $(Element) 76 * @see $(Element<Array>) 77 */ 78 79 /** 80 * Create DOM elements on-the-fly from the provided String of raw HTML. 81 * 82 * @example $("<div><p>Hello</p></div>").appendTo("body") 83 * @desc Creates a div element (and all of its contents) dynamically, 84 * and appends it to the body element. Internally, an 85 * element is created and its innerHTML property set to the given markup. 86 * It is therefore both quite flexible and limited. 87 * 88 * @name $ 89 * @param String html A string of HTML to create on the fly. 90 * @cat Core 91 * @type jQuery 92 * @see appendTo(String) 93 */ 94 95 /** 96 * Wrap jQuery functionality around a single or multiple DOM Element(s). 97 * 98 * This function also accepts XML Documents and Window objects 99 * as valid arguments (even though they are not DOM Elements). 100 * 101 * @example $(document.body).css( "background", "black" ); 102 * @desc Sets the background color of the page to black. 103 * 104 * @example $( myForm.elements ).hide() 105 * @desc Hides all the input elements within a form 106 * 107 * @name $ 108 * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object. 109 * @cat Core 110 * @type jQuery 111 */ 112 113 /** 114 * A shorthand for $(document).ready(), allowing you to bind a function 115 * to be executed when the DOM document has finished loading. This function 116 * behaves just like $(document).ready(), in that it should be used to wrap 117 * other $() operations on your page that depend on the DOM being ready to be 118 * operated on. While this function is, technically, chainable - there really 119 * isn't much use for chaining against it. 120 * 121 * You can have as many $(document).ready events on your page as you like. 122 * 123 * See ready(Function) for details about the ready event. 124 * 125 * @example $(function(){ 126 * // Document is ready 127 * }); 128 * @desc Executes the function when the DOM is ready to be used. 129 * 130 * @example jQuery(function($) { 131 * // Your code using failsafe $ alias here... 132 * }); 133 * @desc Uses both the shortcut for $(document).ready() and the argument 134 * to write failsafe jQuery code using the $ alias, without relying on the 135 * global alias. 136 * 137 * @name $ 138 * @param Function fn The function to execute when the DOM is ready. 139 * @cat Core 140 * @type jQuery 141 * @see ready(Function) 142 */ 143 144 jQuery.fn = jQuery.prototype = { 145 /** 146 * Initialize a new jQuery object 147 * 148 * @private 149 * @name init 150 * @param String|Function|Element|Array<Element>|jQuery a selector 151 * @param jQuery|Element|Array<Element> c context 152 * @cat Core 153 */ 154 init: function(a,c) { 155 // Make sure that a selection was provided 156 a = a || document; 157 158 // HANDLE: $(function) 159 // Shortcut for document ready 160 if ( jQuery.isFunction(a) ) 161 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a ); 162 163 // Handle HTML strings 164 if ( typeof a == "string" ) { 165 // HANDLE: $(html) -> $(array) 166 var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a); 167 if ( m ) 168 a = jQuery.clean( [ m[1] ] ); 169 170 // HANDLE: $(expr) 171 else 172 return new jQuery( c ).find( a ); 173 } 174 175 return this.setArray( 176 // HANDLE: $(array) 177 a.constructor == Array && a || 178 179 // HANDLE: $(arraylike) 180 // Watch for when an array-like object is passed as the selector 181 (a.jquery || a.length && a != window && (!a.nodeType || (jQuery.browser.msie && a.elements)) && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) || 182 183 // HANDLE: $(*) 184 [ a ] ); 185 }, 186 187 /** 188 * The current version of jQuery. 189 * 190 * @private 191 * @property 192 * @name jquery 193 * @type String 194 * @cat Core 195 */ 196 jquery: "@VERSION", 197 198 /** 199 * The number of elements currently matched. The size function will return the same value. 200 * 201 * @example $("img").length; 202 * @before <img src="test1.jpg"/> <img src="test2.jpg"/> 203 * @result 2 204 * 205 * @property 206 * @name length 207 * @type Number 208 * @cat Core 209 */ 210 211 /** 212 * Get the number of elements currently matched. This returns the same 213 * number as the 'length' property of the jQuery object. 214 * 215 * @example $("img").size(); 216 * @before <img src="test1.jpg"/> <img src="test2.jpg"/> 217 * @result 2 218 * 219 * @name size 220 * @type Number 221 * @cat Core 222 */ 223 size: function() { 224 return this.length; 225 }, 226 227 length: 0, 228 229 /** 230 * Access all matched DOM elements. This serves as a backwards-compatible 231 * way of accessing all matched elements (other than the jQuery object 232 * itself, which is, in fact, an array of elements). 233 * 234 * It is useful if you need to operate on the DOM elements themselves instead of using built-in jQuery functions. 235 * 236 * @example $("img").get(); 237 * @before <img src="test1.jpg"/> <img src="test2.jpg"/> 238 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ] 239 * @desc Selects all images in the document and returns the DOM Elements as an Array 240 * 241 * @name get 242 * @type Array<Element> 243 * @cat Core 244 */ 245 246 /** 247 * Access a single matched DOM element at a specified index in the matched set. 248 * This allows you to extract the actual DOM element and operate on it 249 * directly without necessarily using jQuery functionality on it. 250 * 251 * @example $("img").get(0); 252 * @before <img src="test1.jpg"/> <img src="test2.jpg"/> 253 * @result <img src="test1.jpg"/> 254 * @desc Selects all images in the document and returns the first one 255 * 256 * @name get 257 * @type Element 258 * @param Number num Access the element in the Nth position. 259 * @cat Core 260 */ 261 get: function( num ) { 262 return num == undefined ? 263 264 // Return a 'clean' array 265 jQuery.makeArray( this ) : 266 267 // Return just the object 268 this[num]; 269 }, 270 271 /** 272 * Set the jQuery object to an array of elements, while maintaining 273 * the stack. 274 * 275 * @example $("img").pushStack([ document.body ]); 276 * @result $("img").pushStack() == [ document.body ] 277 * 278 * @private 279 * @name pushStack 280 * @type jQuery 281 * @param Elements elems An array of elements 282 * @cat Core 283 */ 284 pushStack: function( a ) { 285 var ret = jQuery(a); 286 ret.prevObject = this; 287 return ret; 288 }, 289 290 /** 291 * Set the jQuery object to an array of elements. This operation is 292 * completely destructive - be sure to use .pushStack() if you wish to maintain 293 * the jQuery stack. 294 * 295 * @example $("img").setArray([ document.body ]); 296 * @result $("img").setArray() == [ document.body ] 297 * 298 * @private 299 * @name setArray 300 * @type jQuery 301 * @param Elements elems An array of elements 302 * @cat Core 303 */ 304 setArray: function( a ) { 305 this.length = 0; 306 [].push.apply( this, a ); 307 return this; 308 }, 309 310 /** 311 * Execute a function within the context of every matched element. 312 * This means that every time the passed-in function is executed 313 * (which is once for every element matched) the 'this' keyword 314 * points to the specific DOM element. 315 * 316 * Additionally, the function, when executed, is passed a single 317 * argument representing the position of the element in the matched 318 * set (integer, zero-index). 319 * 320 * @example $("img").each(function(i){ 321 * this.src = "test" + i + ".jpg"; 322 * }); 323 * @before <img/><img/> 324 * @result <img src="test0.jpg"/><img src="test1.jpg"/> 325 * @desc Iterates over two images and sets their src property 326 * 327 * @name each 328 * @type jQuery 329 * @param Function fn A function to execute 330 * @cat Core 331 */ 332 each: function( fn, args ) { 333 return jQuery.each( this, fn, args ); 334 }, 335 336 /** 337 * Searches every matched element for the object and returns 338 * the index of the element, if found, starting with zero. 339 * Returns -1 if the object wasn't found. 340 * 341 * @example $("*").index( $('#foobar')[0] ) 342 * @before <div id="foobar"><b></b><span id="foo"></span></div> 343 * @result 0 344 * @desc Returns the index for the element with ID foobar 345 * 346 * @example $("*").index( $('#foo')[0] ) 347 * @before <div id="foobar"><b></b><span id="foo"></span></div> 348 * @result 2 349 * @desc Returns the index for the element with ID foo within another element 350 * 351 * @example $("*").index( $('#bar')[0] ) 352 * @before <div id="foobar"><b></b><span id="foo"></span></div> 353 * @result -1 354 * @desc Returns -1, as there is no element with ID bar 355 * 356 * @name index 357 * @type Number 358 * @param Element subject Object to search for 359 * @cat Core 360 */ 361 index: function( obj ) { 362 var pos = -1; 363 this.each(function(i){ 364 if ( this == obj ) pos = i; 365 }); 366 return pos; 367 }, 368 369 /** 370 * Access a property on the first matched element. 371 * This method makes it easy to retrieve a property value 372 * from the first matched element. 373 * 374 * If the element does not have an attribute with such a 375 * name, undefined is returned. 376 * 377 * @example $("img").attr("src"); 378 * @before <img src="test.jpg"/> 379 * @result test.jpg 380 * @desc Returns the src attribute from the first image in the document. 381 * 382 * @name attr 383 * @type Object 384 * @param String name The name of the property to access. 385 * @cat DOM/Attributes 386 */ 387 388 /** 389 * Set a key/value object as properties to all matched elements. 390 * 391 * This serves as the best way to set a large number of properties 392 * on all matched elements. 393 * 394 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" }); 395 * @before <img/> 396 * @result <img src="test.jpg" alt="Test Image"/> 397 * @desc Sets src and alt attributes to all images. 398 * 399 * @name attr 400 * @type jQuery 401 * @param Map properties Key/value pairs to set as object properties. 402 * @cat DOM/Attributes 403 */ 404 405 /** 406 * Set a single property to a value, on all matched elements. 407 * 408 * Note that you can't set the name property of input elements in IE. 409 * Use $(html) or .append(html) or .html(html) to create elements 410 * on the fly including the name property. 411 * 412 * @example $("img").attr("src","test.jpg"); 413 * @before <img/> 414 * @result <img src="test.jpg"/> 415 * @desc Sets src attribute to all images. 416 * 417 * @name attr 418 * @type jQuery 419 * @param String key The name of the property to set. 420 * @param Object value The value to set the property to. 421 * @cat DOM/Attributes 422 */ 423 424 /** 425 * Set a single property to a computed value, on all matched elements. 426 * 427 * Instead of supplying a string value as described 428 * [[DOM/Attributes#attr.28_key.2C_value_.29|above]], 429 * a function is provided that computes the value. 430 * 431 * @example $("img").attr("title", function() { return this.src }); 432 * @before <img src="test.jpg" /> 433 * @result <img src="test.jpg" title="test.jpg" /> 434 * @desc Sets title attribute from src attribute. 435 * 436 * @example $("img").attr("title", function(index) { return this.title + (i + 1); }); 437 * @before <img title="pic" /><img title="pic" /><img title="pic" /> 438 * @result <img title="pic1" /><img title="pic2" /><img title="pic3" /> 439 * @desc Enumerate title attribute. 440 * 441 * @name attr 442 * @type jQuery 443 * @param String key The name of the property to set. 444 * @param Function value A function returning the value to set. 445 * Scope: Current element, argument: Index of current element 446 * @cat DOM/Attributes 447 */ 448 attr: function( key, value, type ) { 449 var obj = key; 450 451 // Look for the case where we're accessing a style value 452 if ( key.constructor == String ) 453 if ( value == undefined ) 454 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined; 455 else { 456 obj = {}; 457 obj[ key ] = value; 458 } 459 460 // Check to see if we're setting style values 461 return this.each(function(index){ 462 // Set all the styles 463 for ( var prop in obj ) 464 jQuery.attr( 465 type ? this.style : this, 466 prop, jQuery.prop(this, obj[prop], type, index, prop) 467 ); 468 }); 469 }, 470 471 /** 472 * Access a style property on the first matched element. 473 * This method makes it easy to retrieve a style property value 474 * from the first matched element. 475 * 476 * @example $("p").css("color"); 477 * @before <p style="color:red;">Test Paragraph.</p> 478 * @result "red" 479 * @desc Retrieves the color style of the first paragraph 480 * 481 * @example $("p").css("font-weight"); 482 * @before <p style="font-weight: bold;">Test Paragraph.</p> 483 * @result "bold" 484 * @desc Retrieves the font-weight style of the first paragraph. 485 * 486 * @name css 487 * @type String 488 * @param String name The name of the property to access. 489 * @cat CSS 490 */ 491 492 /** 493 * Set a key/value object as style properties to all matched elements. 494 * 495 * This serves as the best way to set a large number of style properties 496 * on all matched elements. 497 * 498 * @example $("p").css({ color: "red", background: "blue" }); 499 * @before <p>Test Paragraph.</p> 500 * @result <p style="color:red; background:blue;">Test Paragraph.</p> 501 * @desc Sets color and background styles to all p elements. 502 * 503 * @name css 504 * @type jQuery 505 * @param Map properties Key/value pairs to set as style properties. 506 * @cat CSS 507 */ 508 509 /** 510 * Set a single style property to a value, on all matched elements. 511 * If a number is provided, it is automatically converted into a pixel value. 512 * 513 * @example $("p").css("color","red"); 514 * @before <p>Test Paragraph.</p> 515 * @result <p style="color:red;">Test Paragraph.</p> 516 * @desc Changes the color of all paragraphs to red 517 * 518 * @example $("p").css("left",30); 519 * @before <p>Test Paragraph.</p> 520 * @result <p style="left:30px;">Test Paragraph.</p> 521 * @desc Changes the left of all paragraphs to "30px" 522 * 523 * @name css 524 * @type jQuery 525 * @param String key The name of the property to set. 526 * @param String|Number value The value to set the property to. 527 * @cat CSS 528 */ 529 css: function( key, value ) { 530 return this.attr( key, value, "curCSS" ); 531 }, 532 533 /** 534 * Get the text contents of all matched elements. The result is 535 * a string that contains the combined text contents of all matched 536 * elements. This method works on both HTML and XML documents. 537 * 538 * @example $("p").text(); 539 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p> 540 * @result Test Paragraph.Paraparagraph 541 * @desc Gets the concatenated text of all paragraphs 542 * 543 * @name text 544 * @type String 545 * @cat DOM/Attributes 546 */ 547 548 /** 549 * Set the text contents of all matched elements. 550 * 551 * Similar to html(), but escapes HTML (replace "<" and ">" with their 552 * HTML entities). 553 * 554 * @example $("p").text("<b>Some</b> new text."); 555 * @before <p>Test Paragraph.</p> 556 * @result <p><b>Some</b> new text.</p> 557 * @desc Sets the text of all paragraphs. 558 * 559 * @example $("p").text("<b>Some</b> new text.", true); 560 * @before <p>Test Paragraph.</p> 561 * @result <p>Some new text.</p> 562 * @desc Sets the text of all paragraphs. 563 * 564 * @name text 565 * @type String 566 * @param String val The text value to set the contents of the element to. 567 * @cat DOM/Attributes 568 */ 569 text: function(e) { 570 if ( typeof e == "string" ) 571 return this.empty().append( document.createTextNode( e ) ); 572 573 var t = ""; 574 jQuery.each( e || this, function(){ 575 jQuery.each( this.childNodes, function(){ 576 if ( this.nodeType != 8 ) 577 t += this.nodeType != 1 ? 578 this.nodeValue : jQuery.fn.text([ this ]); 579 }); 580 }); 581 return t; 582 }, 583 584 /** 585 * Wrap all matched elements with a structure of other elements. 586 * This wrapping process is most useful for injecting additional 587 * stucture into a document, without ruining the original semantic 588 * qualities of a document. 589 * 590 * This works by going through the first element 591 * provided (which is generated, on the fly, from the provided HTML) 592 * and finds the deepest ancestor element within its 593 * structure - it is that element that will en-wrap everything else. 594 * 595 * This does not work with elements that contain text. Any necessary text 596 * must be added after the wrapping is done. 597 * 598 * @example $("p").wrap("<div class='wrap'></div>"); 599 * @before <p>Test Paragraph.</p> 600 * @result <div class='wrap'><p>Test Paragraph.</p></div> 601 * 602 * @name wrap 603 * @type jQuery 604 * @param String html A string of HTML, that will be created on the fly and wrapped around the target. 605 * @cat DOM/Manipulation 606 */ 607 608 /** 609 * Wrap all matched elements with a structure of other elements. 610 * This wrapping process is most useful for injecting additional 611 * stucture into a document, without ruining the original semantic 612 * qualities of a document. 613 * 614 * This works by going through the first element 615 * provided and finding the deepest ancestor element within its 616 * structure - it is that element that will en-wrap everything else. 617 * 618 * This does not work with elements that contain text. Any necessary text 619 * must be added after the wrapping is done. 620 * 621 * @example $("p").wrap( document.getElementById('content') ); 622 * @before <p>Test Paragraph.</p><div id="content"></div> 623 * @result <div id="content"><p>Test Paragraph.</p></div> 624 * 625 * @name wrap 626 * @type jQuery 627 * @param Element elem A DOM element that will be wrapped around the target. 628 * @cat DOM/Manipulation 629 */ 630 wrap: function() { 631 // The elements to wrap the target around 632 var a, args = arguments; 633 634 // Wrap each of the matched elements individually 635 return this.each(function(){ 636 if ( !a ) 637 a = jQuery.clean(args, this.ownerDocument); 638 639 // Clone the structure that we're using to wrap 640 var b = a[0].cloneNode(true); 641 642 // Insert it before the element to be wrapped 643 this.parentNode.insertBefore( b, this ); 644 645 // Find the deepest point in the wrap structure 646 while ( b.firstChild ) 647 b = b.firstChild; 648 649 // Move the matched element to within the wrap structure 650 b.appendChild( this ); 651 }); 652 }, 653 654 /** 655 * Append content to the inside of every matched element. 656 * 657 * This operation is similar to doing an appendChild to all the 658 * specified elements, adding them into the document. 659 * 660 * @example $("p").append("<b>Hello</b>"); 661 * @before <p>I would like to say: </p> 662 * @result <p>I would like to say: <b>Hello</b></p> 663 * @desc Appends some HTML to all paragraphs. 664 * 665 * @example $("p").append( $("#foo")[0] ); 666 * @before <p>I would like to say: </p><b id="foo">Hello</b> 667 * @result <p>I would like to say: <b id="foo">Hello</b></p> 668 * @desc Appends an Element to all paragraphs. 669 * 670 * @example $("p").append( $("b") ); 671 * @before <p>I would like to say: </p><b>Hello</b> 672 * @result <p>I would like to say: <b>Hello</b></p> 673 * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs. 674 * 675 * @name append 676 * @type jQuery 677 * @param <Content> content Content to append to the target 678 * @cat DOM/Manipulation 679 * @see prepend(<Content>) 680 * @see before(<Content>) 681 * @see after(<Content>) 682 */ 683 append: function() { 684 return this.domManip(arguments, true, 1, function(a){ 685 this.appendChild( a ); 686 }); 687 }, 688 689 /** 690 * Prepend content to the inside of every matched element. 691 * 692 * This operation is the best way to insert elements 693 * inside, at the beginning, of all matched elements. 694 * 695 * @example $("p").prepend("<b>Hello</b>"); 696 * @before <p>I would like to say: </p> 697 * @result <p><b>Hello</b>I would like to say: </p> 698 * @desc Prepends some HTML to all paragraphs. 699 * 700 * @example $("p").prepend( $("#foo")[0] ); 701 * @before <p>I would like to say: </p><b id="foo">Hello</b> 702 * @result <p><b id="foo">Hello</b>I would like to say: </p> 703 * @desc Prepends an Element to all paragraphs. 704 * 705 * @example $("p").prepend( $("b") ); 706 * @before <p>I would like to say: </p><b>Hello</b> 707 * @result <p><b>Hello</b>I would like to say: </p> 708 * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs. 709 * 710 * @name prepend 711 * @type jQuery 712 * @param <Content> content Content to prepend to the target. 713 * @cat DOM/Manipulation 714 * @see append(<Content>) 715 * @see before(<Content>) 716 * @see after(<Content>) 717 */ 718 prepend: function() { 719 return this.domManip(arguments, true, -1, function(a){ 720 this.insertBefore( a, this.firstChild ); 721 }); 722 }, 723 724 /** 725 * Insert content before each of the matched elements. 726 * 727 * @example $("p").before("<b>Hello</b>"); 728 * @before <p>I would like to say: </p> 729 * @result <b>Hello</b><p>I would like to say: </p> 730 * @desc Inserts some HTML before all paragraphs. 731 * 732 * @example $("p").before( $("#foo")[0] ); 733 * @before <p>I would like to say: </p><b id="foo">Hello</b> 734 * @result <b id="foo">Hello</b><p>I would like to say: </p> 735 * @desc Inserts an Element before all paragraphs. 736 * 737 * @example $("p").before( $("b") ); 738 * @before <p>I would like to say: </p><b>Hello</b> 739 * @result <b>Hello</b><p>I would like to say: </p> 740 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs. 741 * 742 * @name before 743 * @type jQuery 744 * @param <Content> content Content to insert before each target. 745 * @cat DOM/Manipulation 746 * @see append(<Content>) 747 * @see prepend(<Content>) 748 * @see after(<Content>) 749 */ 750 before: function() { 751 return this.domManip(arguments, false, 1, function(a){ 752 this.parentNode.insertBefore( a, this ); 753 }); 754 }, 755 756 /** 757 * Insert content after each of the matched elements. 758 * 759 * @example $("p").after("<b>Hello</b>"); 760 * @before <p>I would like to say: </p> 761 * @result <p>I would like to say: </p><b>Hello</b> 762 * @desc Inserts some HTML after all paragraphs. 763 * 764 * @example $("p").after( $("#foo")[0] ); 765 * @before <b id="foo">Hello</b><p>I would like to say: </p> 766 * @result <p>I would like to say: </p><b id="foo">Hello</b> 767 * @desc Inserts an Element after all paragraphs. 768 * 769 * @example $("p").after( $("b") ); 770 * @before <b>Hello</b><p>I would like to say: </p> 771 * @result <p>I would like to say: </p><b>Hello</b> 772 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs. 773 * 774 * @name after 775 * @type jQuery 776 * @param <Content> content Content to insert after each target. 777 * @cat DOM/Manipulation 778 * @see append(<Content>) 779 * @see prepend(<Content>) 780 * @see before(<Content>) 781 */ 782 after: function() { 783 return this.domManip(arguments, false, -1, function(a){ 784 this.parentNode.insertBefore( a, this.nextSibling ); 785 }); 786 }, 787 788 /** 789 * Revert the most recent 'destructive' operation, changing the set of matched elements 790 * to its previous state (right before the destructive operation). 791 * 792 * If there was no destructive operation before, an empty set is returned. 793 * 794 * A 'destructive' operation is any operation that changes the set of 795 * matched jQuery elements. These functions are: <code>add</code>, 796 * <code>children</code>, <code>clone</code>, <code>filter</code>, 797 * <code>find</code>, <code>not</code>, <code>next</code>, 798 * <code>parent</code>, <code>parents</code>, <code>prev</code> and <code>siblings</code>. 799 * 800 * @example $("p").find("span").end(); 801 * @before <p><span>Hello</span>, how are you?</p> 802 * @result [ <p>...</p> ] 803 * @desc Selects all paragraphs, finds span elements inside these, and reverts the 804 * selection back to the paragraphs. 805 * 806 * @name end 807 * @type jQuery 808 * @cat DOM/Traversing 809 */ 810 end: function() { 811 return this.prevObject || jQuery([]); 812 }, 813 814 /** 815 * Searches for all elements that match the specified expression. 816 817 * This method is a good way to find additional descendant 818 * elements with which to process. 819 * 820 * All searching is done using a jQuery expression. The expression can be 821 * written using CSS 1-3 Selector syntax, or basic XPath. 822 * 823 * @example $("p").find("span"); 824 * @before <p><span>Hello</span>, how are you?</p> 825 * @result [ <span>Hello</span> ] 826 * @desc Starts with all paragraphs and searches for descendant span 827 * elements, same as $("p span") 828 * 829 * @name find 830 * @type jQuery 831 * @param String expr An expression to search with. 832 * @cat DOM/Traversing 833 */ 834 find: function(t) { 835 return this.pushStack( jQuery.unique( jQuery.map( this, function(a){ 836 return jQuery.find(t,a); 837 }) ), t ); 838 }, 839 840 /** 841 * Clone matched DOM Elements and select the clones. 842 * 843 * This is useful for moving copies of the elements to another 844 * location in the DOM. 845 * 846 * @example $("b").clone().prependTo("p"); 847 * @before <b>Hello</b><p>, how are you?</p> 848 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p> 849 * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs. 850 * 851 * @name clone 852 * @type jQuery 853 * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself. 854 * @cat DOM/Manipulation 855 */ 856 clone: function(deep) { 857 return this.pushStack( jQuery.map( this, function(a){ 858 a = a.cloneNode( deep != undefined ? deep : true ); 859 a.$events = null; // drop $events expando to avoid firing incorrect events 860 return a; 861 }) ); 862 }, 863 864 /** 865 * Removes all elements from the set of matched elements that do not 866 * match the specified expression(s). This method is used to narrow down 867 * the results of a search. 868 * 869 * Provide a comma-separated list of expressions to apply multiple filters at once. 870 * 871 * @example $("p").filter(".selected") 872 * @before <p class="selected">Hello</p><p>How are you?</p> 873 * @result [ <p class="selected">Hello</p> ] 874 * @desc Selects all paragraphs and removes those without a class "selected". 875 * 876 * @example $("p").filter(".selected, :first") 877 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p> 878 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ] 879 * @desc Selects all paragraphs and removes those without class "selected" and being the first one. 880 * 881 * @name filter 882 * @type jQuery 883 * @param String expression Expression(s) to search with. 884 * @cat DOM/Traversing 885 */ 886 887 /** 888 * Removes all elements from the set of matched elements that do not 889 * pass the specified filter. This method is used to narrow down 890 * the results of a search. 891 * 892 * @example $("p").filter(function(index) { 893 * return $("ol", this).length == 0; 894 * }) 895 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p> 896 * @result [ <p>How are you?</p> ] 897 * @desc Remove all elements that have a child ol element 898 * 899 * @name filter 900 * @type jQuery 901 * @param Function filter A function to use for filtering 902 * @cat DOM/Traversing 903 */ 904 filter: function(t) { 905 return this.pushStack( 906 jQuery.isFunction( t ) && 907 jQuery.grep(this, function(el, index){ 908 return t.apply(el, [index]) 909 }) || 910 911 jQuery.multiFilter(t,this) ); 912 }, 913 914 /** 915 * Removes the specified Element from the set of matched elements. This 916 * method is used to remove a single Element from a jQuery object. 917 * 918 * @example $("p").not( $("#selected")[0] ) 919 * @before <p>Hello</p><p id="selected">Hello Again</p> 920 * @result [ <p>Hello</p> ] 921 * @desc Removes the element with the ID "selected" from the set of all paragraphs. 922 * 923 * @name not 924 * @type jQuery 925 * @param Element el An element to remove from the set 926 * @cat DOM/Traversing 927 */ 928 929 /** 930 * Removes elements matching the specified expression from the set 931 * of matched elements. This method is used to remove one or more 932 * elements from a jQuery object. 933 * 934 * @example $("p").not("#selected") 935 * @before <p>Hello</p><p id="selected">Hello Again</p> 936 * @result [ <p>Hello</p> ] 937 * @desc Removes the element with the ID "selected" from the set of all paragraphs. 938 * 939 * @name not 940 * @type jQuery 941 * @param String expr An expression with which to remove matching elements 942 * @cat DOM/Traversing 943 */ 944 945 /** 946 * Removes any elements inside the array of elements from the set 947 * of matched elements. This method is used to remove one or more 948 * elements from a jQuery object. 949 * 950 * Please note: the expression cannot use a reference to the 951 * element name. See the two examples below. 952 * 953 * @example $("p").not( $("div p.selected") ) 954 * @before <div><p>Hello</p><p class="selected">Hello Again</p></div> 955 * @result [ <p>Hello</p> ] 956 * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs. 957 * 958 * @name not 959 * @type jQuery 960 * @param jQuery elems A set of elements to remove from the jQuery set of matched elements. 961 * @cat DOM/Traversing 962 */ 963 not: function(t) { 964 return this.pushStack( 965 t.constructor == String && 966 jQuery.multiFilter(t, this, true) || 967 968 jQuery.grep(this, function(a) { 969 return ( t.constructor == Array || t.jquery ) 970 ? jQuery.inArray( a, t ) < 0 971 : a != t; 972 }) 973 ); 974 }, 975 976 /** 977 * Adds more elements, matched by the given expression, 978 * to the set of matched elements. 979 * 980 * @example $("p").add("span") 981 * @before (HTML) <p>Hello</p><span>Hello Again</span> 982 * @result (jQuery object matching 2 elements) [ <p>Hello</p>, <span>Hello Again</span> ] 983 * @desc Compare the above result to the result of <code>$('p')</code>, 984 * which would just result in <code><nowiki>[ <p>Hello</p> ]</nowiki></code>. 985 * Using add(), matched elements of <code>$('span')</code> are simply 986 * added to the returned jQuery-object. 987 * 988 * @name add 989 * @type jQuery 990 * @param String expr An expression whose matched elements are added 991 * @cat DOM/Traversing 992 */ 993 994 /** 995 * Adds more elements, created on the fly, to the set of 996 * matched elements. 997 * 998 * @example $("p").add("<span>Again</span>") 999 * @before <p>Hello</p> 1000 * @result [ <p>Hello</p>, <span>Again</span> ] 1001 * 1002 * @name add 1003 * @type jQuery 1004 * @param String html A string of HTML to create on the fly. 1005 * @cat DOM/Traversing 1006 */ 1007 1008 /** 1009 * Adds one or more Elements to the set of matched elements. 1010 * 1011 * @example $("p").add( document.getElementById("a") ) 1012 * @before <p>Hello</p><p><span id="a">Hello Again</span></p> 1013 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ] 1014 * 1015 * @example $("p").add( document.forms[0].elements ) 1016 * @before <p>Hello</p><p><form><input/><button/></form> 1017 * @result [ <p>Hello</p>, <input/>, <button/> ] 1018 * 1019 * @name add 1020 * @type jQuery 1021 * @param Element|Array<Element> elements One or more Elements to add 1022 * @cat DOM/Traversing 1023 */ 1024 add: function(t) { 1025 return this.pushStack( jQuery.merge( 1026 this.get(), 1027 t.constructor == String ? 1028 jQuery(t).get() : 1029 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ? 1030 t : [t] ) 1031 ); 1032 }, 1033 1034 /** 1035 * Checks the current selection against an expression and returns true, 1036 * if at least one element of the selection fits the given expression. 1037 * 1038 * Does return false, if no element fits or the expression is not valid. 1039 * 1040 * filter(String) is used internally, therefore all rules that apply there 1041 * apply here, too. 1042 * 1043 * @example $("input[@type='checkbox']").parent().is("form") 1044 * @before <form><input type="checkbox" /></form> 1045 * @result true 1046 * @desc Returns true, because the parent of the input is a form element 1047 * 1048 * @example $("input[@type='checkbox']").parent().is("form") 1049 * @before <form><p><input type="checkbox" /></p></form> 1050 * @result false 1051 * @desc Returns false, because the parent of the input is a p element 1052 * 1053 * @name is 1054 * @type Boolean 1055 * @param String expr The expression with which to filter 1056 * @cat DOM/Traversing 1057 */ 1058 is: function(expr) { 1059 return expr ? jQuery.multiFilter(expr,this).length > 0 : false; 1060 }, 1061 1062 /** 1063 * Get the content of the value attribute of the first matched element. 1064 * 1065 * Use caution when relying on this function to check the value of 1066 * multiple-select elements and checkboxes in a form. While it will 1067 * still work as intended, it may not accurately represent the value 1068 * the server will receive because these elements may send an array 1069 * of values. For more robust handling of field values, see the 1070 * [http://www.malsup.com/jquery/form/#fields fieldValue function of the Form Plugin]. 1071 * 1072 * @example $("input").val(); 1073 * @before <input type="text" value="some text"/> 1074 * @result "some text" 1075 * 1076 * @name val 1077 * @type String 1078 * @cat DOM/Attributes 1079 */ 1080 1081 /** 1082 * Set the value attribute of every matched element. 1083 * 1084 * @example $("input").val("test"); 1085 * @before <input type="text" value="some text"/> 1086 * @result <input type="text" value="test"/> 1087 * 1088 * @name val 1089 * @type jQuery 1090 * @param String val Set the property to the specified value. 1091 * @cat DOM/Attributes 1092 */ 1093 val: function( val ) { 1094 return val == undefined ? 1095 ( this.length ? this[0].value : null ) : 1096 this.attr( "value", val ); 1097 }, 1098 1099 /** 1100 * Get the html contents of the first matched element. 1101 * This property is not available on XML documents. 1102 * 1103 * @example $("div").html(); 1104 * @before <div><input/></div> 1105 * @result <input/> 1106 * 1107 * @name html 1108 * @type String 1109 * @cat DOM/Attributes 1110 */ 1111 1112 /** 1113 * Set the html contents of every matched element. 1114 * This property is not available on XML documents. 1115 * 1116 * @example $("div").html("<b>new stuff</b>"); 1117 * @before <div><input/></div> 1118 * @result <div><b>new stuff</b></div> 1119 * 1120 * @name html 1121 * @type jQuery 1122 * @param String val Set the html contents to the specified value. 1123 * @cat DOM/Attributes 1124 */ 1125 html: function( val ) { 1126 return val == undefined ? 1127 ( this.length ? this[0].innerHTML : null ) : 1128 this.empty().append( val ); 1129 }, 1130 1131 /** 1132 * @private 1133 * @name domManip 1134 * @param Array args 1135 * @param Boolean table Insert TBODY in TABLEs if one is not found. 1136 * @param Number dir If dir<0, process args in reverse order. 1137 * @param Function fn The function doing the DOM manipulation. 1138 * @type jQuery 1139 * @cat Core 1140 */ 1141 domManip: function(args, table, dir, fn){ 1142 var clone = this.length > 1, a; 1143 1144 return this.each(function(){ 1145 if ( !a ) { 1146 a = jQuery.clean(args, this.ownerDocument); 1147 if ( dir < 0 ) 1148 a.reverse(); 1149 } 1150 1151 var obj = this; 1152 1153 if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") ) 1154 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody")); 1155 1156 jQuery.each( a, function(){ 1157 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] ); 1158 }); 1159 1160 }); 1161 } 1162 }; 1163 1164 /** 1165 * Extends the jQuery object itself. Can be used to add functions into 1166 * the jQuery namespace and to [[Plugins/Authoring|add plugin methods]] (plugins). 1167 * 1168 * @example jQuery.fn.extend({ 1169 * check: function() { 1170 * return this.each(function() { this.checked = true; }); 1171 * }, 1172 * uncheck: function() { 1173 * return this.each(function() { this.checked = false; }); 1174 * } 1175 * }); 1176 * $("input[@type=checkbox]").check(); 1177 * $("input[@type=radio]").uncheck(); 1178 * @desc Adds two plugin methods. 1179 * 1180 * @example jQuery.extend({ 1181 * min: function(a, b) { return a < b ? a : b; }, 1182 * max: function(a, b) { return a > b ? a : b; } 1183 * }); 1184 * @desc Adds two functions into the jQuery namespace 1185 * 1186 * @name $.extend 1187 * @param Object prop The object that will be merged into the jQuery object 1188 * @type Object 1189 * @cat Core 1190 */ 1191 1192 /** 1193 * Extend one object with one or more others, returning the original, 1194 * modified, object. This is a great utility for simple inheritance. 1195 * 1196 * @example var settings = { validate: false, limit: 5, name: "foo" }; 1197 * var options = { validate: true, name: "bar" }; 1198 * jQuery.extend(settings, options); 1199 * @result settings == { validate: true, limit: 5, name: "bar" } 1200 * @desc Merge settings and options, modifying settings 1201 * 1202 * @example var defaults = { validate: false, limit: 5, name: "foo" }; 1203 * var options = { validate: true, name: "bar" }; 1204 * var settings = jQuery.extend({}, defaults, options); 1205 * @result settings == { validate: true, limit: 5, name: "bar" } 1206 * @desc Merge defaults and options, without modifying the defaults 1207 * 1208 * @name $.extend 1209 * @param Object target The object to extend 1210 * @param Object prop1 The object that will be merged into the first. 1211 * @param Object propN (optional) More objects to merge into the first 1212 * @type Object 1213 * @cat JavaScript 1214 */ 1215 jQuery.extend = jQuery.fn.extend = function() { 1216 // copy reference to target object 1217 var target = arguments[0], a = 1; 1218 1219 // extend jQuery itself if only one argument is passed 1220 if ( arguments.length == 1 ) { 1221 target = this; 1222 a = 0; 1223 } 1224 var prop; 1225 while ( (prop = arguments[a++]) != null ) 1226 // Extend the base object 1227 for ( var i in prop ) target[i] = prop[i]; 1228 1229 // Return the modified object 1230 return target; 1231 }; 1232 1233 jQuery.extend({ 1234 /** 1235 * Run this function to give control of the $ variable back 1236 * to whichever library first implemented it. This helps to make 1237 * sure that jQuery doesn't conflict with the $ object 1238 * of other libraries. 1239 * 1240 * By using this function, you will only be able to access jQuery 1241 * using the 'jQuery' variable. For example, where you used to do 1242 * $("div p"), you now must do jQuery("div p"). 1243 * 1244 * @example jQuery.noConflict(); 1245 * // Do something with jQuery 1246 * jQuery("div p").hide(); 1247 * // Do something with another library's $() 1248 * $("content").style.display = 'none'; 1249 * @desc Maps the original object that was referenced by $ back to $ 1250 * 1251 * @example jQuery.noConflict(); 1252 * (function($) { 1253 * $(function() { 1254 * // more code using $ as alias to jQuery 1255 * }); 1256 * })(jQuery); 1257 * // other code using $ as an alias to the other library 1258 * @desc Reverts the $ alias and then creates and executes a 1259 * function to provide the $ as a jQuery alias inside the functions 1260 * scope. Inside the function the original $ object is not available. 1261 * This works well for most plugins that don't rely on any other library. 1262 * 1263 * 1264 * @name $.noConflict 1265 * @type undefined 1266 * @cat Core 1267 */ 1268 noConflict: function() { 1269 if ( jQuery._$ ) 1270 $ = jQuery._$; 1271 return jQuery; 1272 }, 1273 1274 // This may seem like some crazy code, but trust me when I say that this 1275 // is the only cross-browser way to do this. --John 1276 isFunction: function( fn ) { 1277 return !!fn && typeof fn != "string" && !fn.nodeName && 1278 fn.constructor != Array && /function/i.test( fn + "" ); 1279 }, 1280 1281 // check if an element is in a XML document 1282 isXMLDoc: function(elem) { 1283 return elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; 1284 }, 1285 1286 nodeName: function( elem, name ) { 1287 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); 1288 }, 1289 1290 /** 1291 * A generic iterator function, which can be used to seamlessly 1292 * iterate over both objects and arrays. This function is not the same 1293 * as $().each() - which is used to iterate, exclusively, over a jQuery 1294 * object. This function can be used to iterate over anything. 1295 * 1296 * The callback has two arguments:the key (objects) or index (arrays) as first 1297 * the first, and the value as the second. 1298 * 1299 * @example $.each( [0,1,2], function(i, n){ 1300 * alert( "Item #" + i + ": " + n ); 1301 * }); 1302 * @desc This is an example of iterating over the items in an array, 1303 * accessing both the current item and its index. 1304 * 1305 * @example $.each( { name: "John", lang: "JS" }, function(i, n){ 1306 * alert( "Name: " + i + ", Value: " + n ); 1307 * }); 1308 * 1309 * @desc This is an example of iterating over the properties in an 1310 * Object, accessing both the current item and its key. 1311 * 1312 * @name $.each 1313 * @param Object obj The object, or array, to iterate over. 1314 * @param Function fn The function that will be executed on every object. 1315 * @type Object 1316 * @cat JavaScript 1317 */ 1318 // args is for internal usage only 1319 each: function( obj, fn, args ) { 1320 if ( obj.length == undefined ) 1321 for ( var i in obj ) 1322 fn.apply( obj[i], args || [i, obj[i]] ); 1323 else 1324 for ( var i = 0, ol = obj.length; i < ol; i++ ) 1325 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break; 1326 return obj; 1327 }, 1328 1329 prop: function(elem, value, type, index, prop){ 1330 // Handle executable functions 1331 if ( jQuery.isFunction( value ) ) 1332 value = value.call( elem, [index] ); 1333 1334 // exclude the following css properties to add px 1335 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i; 1336 1337 // Handle passing in a number to a CSS property 1338 return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ? 1339 value + "px" : 1340 value; 1341 }, 1342 1343 className: { 1344 // internal only, use addClass("class") 1345 add: function( elem, c ){ 1346 jQuery.each( c.split(/\s+/), function(i, cur){ 1347 if ( !jQuery.className.has( elem.className, cur ) ) 1348 elem.className += ( elem.className ? " " : "" ) + cur; 1349 }); 1350 }, 1351 1352 // internal only, use removeClass("class") 1353 remove: function( elem, c ){ 1354 elem.className = c != undefined ? 1355 jQuery.grep( elem.className.split(/\s+/), function(cur){ 1356 return !jQuery.className.has( c, cur ); 1357 }).join(" ") : ""; 1358 }, 1359 1360 // internal only, use is(".class") 1361 has: function( t, c ) { 1362 return jQuery.inArray( c, (t.className || t).toString().split(/\s+/) ) > -1; 1363 } 1364 }, 1365 1366 /** 1367 * Swap in/out style options. 1368 * @private 1369 */ 1370 swap: function(e,o,f) { 1371 for ( var i in o ) { 1372 e.style["old"+i] = e.style[i]; 1373 e.style[i] = o[i]; 1374 } 1375 f.apply( e, [] ); 1376 for ( var i in o ) 1377 e.style[i] = e.style["old"+i]; 1378 }, 1379 1380 css: function(e,p) { 1381 if ( p == "height" || p == "width" ) { 1382 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"]; 1383 1384 jQuery.each( d, function(){ 1385 old["padding" + this] = 0; 1386 old["border" + this + "Width"] = 0; 1387 }); 1388 1389 jQuery.swap( e, old, function() { 1390 if ( jQuery(e).is(':visible') ) { 1391 oHeight = e.offsetHeight; 1392 oWidth = e.offsetWidth; 1393 } else { 1394 e = jQuery(e.cloneNode(true)) 1395 .find(":radio").removeAttr("checked").end() 1396 .css({ 1397 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0" 1398 }).appendTo(e.parentNode)[0]; 1399 1400 var parPos = jQuery.css(e.parentNode,"position") || "static"; 1401 if ( parPos == "static" ) 1402 e.parentNode.style.position = "relative"; 1403 1404 oHeight = e.clientHeight; 1405 oWidth = e.clientWidth; 1406 1407 if ( parPos == "static" ) 1408 e.parentNode.style.position = "static"; 1409 1410 e.parentNode.removeChild(e); 1411 } 1412 }); 1413 1414 return p == "height" ? oHeight : oWidth; 1415 } 1416 1417 return jQuery.curCSS( e, p ); 1418 }, 1419 1420 curCSS: function(elem, prop, force) { 1421 var ret; 1422 1423 if (prop == "opacity" && jQuery.browser.msie) { 1424 ret = jQuery.attr(elem.style, "opacity"); 1425 return ret == "" ? "1" : ret; 1426 } 1427 1428 if (prop == "float" || prop == "cssFloat") 1429 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat"; 1430 1431 if (!force && elem.style[prop]) 1432 ret = elem.style[prop]; 1433 1434 else if (document.defaultView && document.defaultView.getComputedStyle) { 1435 1436 if (prop == "cssFloat" || prop == "styleFloat") 1437 prop = "float"; 1438 1439 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase(); 1440 var cur = document.defaultView.getComputedStyle(elem, null); 1441 1442 if ( cur ) 1443 ret = cur.getPropertyValue(prop); 1444 else if ( prop == "display" ) 1445 ret = "none"; 1446 else 1447 jQuery.swap(elem, { display: "block" }, function() { 1448 var c = document.defaultView.getComputedStyle(this, ""); 1449 ret = c && c.getPropertyValue(prop) || ""; 1450 }); 1451 1452 } else if (elem.currentStyle) { 1453 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();}); 1454 ret = elem.currentStyle[prop] || elem.currentStyle[newProp]; 1455 } 1456 1457 return ret; 1458 }, 1459 1460 clean: function(a, doc) { 1461 var r = []; 1462 doc = doc || document; 1463 1464 jQuery.each( a, function(i,arg){ 1465 if ( !arg ) return; 1466 1467 if ( arg.constructor == Number ) 1468 arg = arg.toString(); 1469 1470 // Convert html string into DOM nodes 1471 if ( typeof arg == "string" ) { 1472 // Trim whitespace, otherwise indexOf won't work as expected 1473 var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = []; 1474 1475 var wrap = 1476 // option or optgroup 1477 !s.indexOf("<opt") && 1478 [1, "<select>", "</select>"] || 1479 1480 !s.indexOf("<leg") && 1481 [1, "<fieldset>", "</fieldset>"] || 1482 1483 (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot") || !s.indexOf("<colg")) && 1484 [1, "<table>", "</table>"] || 1485 1486 !s.indexOf("<tr") && 1487 [2, "<table><tbody>", "</tbody></table>"] || 1488 1489 // <thead> matched above 1490 (!s.indexOf("<td") || !s.indexOf("<th")) && 1491 [3, "<table><tbody><tr>", "</tr></tbody></table>"] || 1492 1493 !s.indexOf("<col") && 1494 [2, "<table><colgroup>", "</colgroup></table>"] || 1495 1496 [0,"",""]; 1497 1498 // Go to html and back, then peel off extra wrappers 1499 div.innerHTML = wrap[1] + arg + wrap[2]; 1500 1501 // Move to the right depth 1502 while ( wrap[0]-- ) 1503 div = div.firstChild; 1504 1505 // Remove IE's autoinserted <tbody> from table fragments 1506 if ( jQuery.browser.msie ) { 1507 1508 // String was a <table>, *may* have spurious <tbody> 1509 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 ) 1510 tb = div.firstChild && div.firstChild.childNodes; 1511 1512 // String was a bare <thead> or <tfoot> 1513 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 ) 1514 tb = div.childNodes; 1515 1516 for ( var n = tb.length-1; n >= 0 ; --n ) 1517 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length ) 1518 tb[n].parentNode.removeChild(tb[n]); 1519 1520 } 1521 1522 arg = jQuery.makeArray( div.childNodes ); 1523 } 1524 1525 if ( 0 === arg.length && !jQuery(arg).is("form, select") ) 1526 return; 1527 1528 if ( arg[0] == undefined || jQuery.nodeName(arg, "form") || arg.options ) 1529 r.push( arg ); 1530 else 1531 r = jQuery.merge( r, arg ); 1532 1533 }); 1534 1535 return r; 1536 }, 1537 1538 attr: function(elem, name, value){ 1539 var fix = jQuery.isXMLDoc(elem) ? {} : { 1540 "for": "htmlFor", 1541 "class": "className", 1542 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat", 1543 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat", 1544 innerHTML: "innerHTML", 1545 className: "className", 1546 value: "value", 1547 disabled: "disabled", 1548 checked: "checked", 1549 readonly: "readOnly", 1550 selected: "selected", 1551 maxlength: "maxLength" 1552 }; 1553 1554 // IE actually uses filters for opacity ... elem is actually elem.style 1555 if ( name == "opacity" && jQuery.browser.msie ) { 1556 if ( value != undefined ) { 1557 // IE has trouble with opacity if it does not have layout 1558 // Force it by setting the zoom level 1559 elem.zoom = 1; 1560 1561 // Set the alpha filter to set the opacity 1562 elem.filter = (elem.filter || "").replace(/alpha\([^)]*\)/,"") + 1563 (parseFloat(value).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")"); 1564 } 1565 1566 return elem.filter ? 1567 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : ""; 1568 } 1569 1570 // Certain attributes only work when accessed via the old DOM 0 way 1571 if ( fix[name] ) { 1572 if ( value != undefined ) elem[fix[name]] = value; 1573 return elem[fix[name]]; 1574 1575 } else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") ) 1576 return elem.getAttributeNode(name).nodeValue; 1577 1578 // IE elem.getAttribute passes even for style 1579 else if ( elem.tagName ) { 1580 if ( value != undefined ) elem.setAttribute( name, value ); 1581 if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) ) 1582 return elem.getAttribute( name, 2 ); 1583 return elem.getAttribute( name ); 1584 1585 // elem is actually elem.style ... set the style 1586 } else { 1587 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();}); 1588 if ( value != undefined ) elem[name] = value; 1589 return elem[name]; 1590 } 1591 }, 1592 1593 /** 1594 * Remove the whitespace from the beginning and end of a string. 1595 * 1596 * @example $.trim(" hello, how are you? "); 1597 * @result "hello, how are you?" 1598 * 1599 * @name $.trim 1600 * @type String 1601 * @param String str The string to trim. 1602 * @cat JavaScript 1603 */ 1604 trim: function(t){ 1605 return t.replace(/^\s+|\s+$/g, ""); 1606 }, 1607 1608 makeArray: function( a ) { 1609 var r = []; 1610 1611 // Need to use typeof to fight Safari childNodes crashes 1612 if ( typeof a != "array" ) 1613 for ( var i = 0, al = a.length; i < al; i++ ) 1614 r.push( a[i] ); 1615 else 1616 r = a.slice( 0 ); 1617 1618 return r; 1619 }, 1620 1621 inArray: function( b, a ) { 1622 for ( var i = 0, al = a.length; i < al; i++ ) 1623 if ( a[i] == b ) 1624 return i; 1625 return -1; 1626 }, 1627 1628 /** 1629 * Merge two arrays together, removing all duplicates. 1630 * 1631 * The result is the altered first argument with 1632 * the unique elements from the second array added. 1633 * 1634 * @example $.merge( [0,1,2], [2,3,4] ) 1635 * @result [0,1,2,3,4] 1636 * @desc Merges two arrays, removing the duplicate 2 1637 * 1638 * @example var array = [3,2,1]; 1639 * $.merge( array, [4,3,2] ) 1640 * @result array == [3,2,1,4] 1641 * @desc Merges two arrays, removing the duplicates 3 and 2 1642 * 1643 * @name $.merge 1644 * @type Array 1645 * @param Array first The first array to merge, the unique elements of second added. 1646 * @param Array second The second array to merge into the first, unaltered. 1647 * @cat JavaScript 1648 */ 1649 merge: function(first, second) { 1650 // We have to loop this way because IE & Opera overwrite the length 1651 // expando of getElementsByTagName 1652 for ( var i = 0; second[i]; i++ ) 1653 first.push(second[i]); 1654 return first; 1655 }, 1656 1657 unique: function(first) { 1658 var r = [], num = jQuery.mergeNum++; 1659 1660 for ( var i = 0, fl = first.length; i < fl; i++ ) 1661 if ( num != first[i].mergeNum ) { 1662 first[i].mergeNum = num; 1663 r.push(first[i]); 1664 } 1665 1666 return r; 1667 }, 1668 1669 mergeNum: 0, 1670 1671 /** 1672 * Filter items out of an array, by using a filter function. 1673 * 1674 * The specified function will be passed two arguments: The 1675 * current array item and the index of the item in the array. The 1676 * function must return 'true' to keep the item in the array, 1677 * false to remove it. 1678 * 1679 * @example $.grep( [0,1,2], function(i){ 1680 * return i > 0; 1681 * }); 1682 * @result [1, 2] 1683 * 1684 * @name $.grep 1685 * @type Array 1686 * @param Array array The Array to find items in. 1687 * @param Function fn The function to process each item against. 1688 * @param Boolean inv Invert the selection - select the opposite of the function. 1689 * @cat JavaScript 1690 */ 1691 grep: function(elems, fn, inv) { 1692 // If a string is passed in for the function, make a function 1693 // for it (a handy shortcut) 1694 if ( typeof fn == "string" ) 1695 fn = new Function("a","i","return " + fn); 1696 1697 var result = []; 1698 1699 // Go through the array, only saving the items 1700 // that pass the validator function 1701 for ( var i = 0, el = elems.length; i < el; i++ ) 1702 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) ) 1703 result.push( elems[i] ); 1704 1705 return result; 1706 }, 1707 1708 /** 1709 * Translate all items in an array to another array of items. 1710 * 1711 * The translation function that is provided to this method is 1712 * called for each item in the array and is passed one argument: 1713 * The item to be translated. 1714 * 1715 * The function can then return the translated value, 'null' 1716 * (to remove the item), or an array of values - which will 1717 * be flattened into the full array. 1718 * 1719 * @example $.map( [0,1,2], function(i){ 1720 * return i + 4; 1721 * }); 1722 * @result [4, 5, 6] 1723 * @desc Maps the original array to a new one and adds 4 to each value. 1724 * 1725 * @example $.map( [0,1,2], function(i){ 1726 * return i > 0 ? i + 1 : null; 1727 * }); 1728 * @result [2, 3] 1729 * @desc Maps the original array to a new one and adds 1 to each 1730 * value if it is bigger then zero, otherwise it's removed- 1731 * 1732 * @example $.map( [0,1,2], function(i){ 1733 * return [ i, i + 1 ]; 1734 * }); 1735 * @result [0, 1, 1, 2, 2, 3] 1736 * @desc Maps the original array to a new one, each element is added 1737 * with it's original value and the value plus one. 1738 * 1739 * @name $.map 1740 * @type Array 1741 * @param Array array The Array to translate. 1742 * @param Function fn The function to process each item against. 1743 * @cat JavaScript 1744 */ 1745 map: function(elems, fn) { 1746 // If a string is passed in for the function, make a function 1747 // for it (a handy shortcut) 1748 if ( typeof fn == "string" ) 1749 fn = new Function("a","return " + fn); 1750 1751 var result = [], r = []; 1752 1753 // Go through the array, translating each of the items to their 1754 // new value (or values). 1755 for ( var i = 0, el = elems.length; i < el; i++ ) { 1756 var val = fn(elems[i],i); 1757 1758 if ( val !== null && val != undefined ) { 1759 if ( val.constructor != Array ) val = [val]; 1760 result = result.concat( val ); 1761 } 1762 } 1763 1764 return result; 1765 } 1766 }); 1767 1768 /** 1769 * Contains flags for the useragent, read from navigator.userAgent. 1770 * Available flags are: safari, opera, msie, mozilla 1771 * 1772 * This property is available before the DOM is ready, therefore you can 1773 * use it to add ready events only for certain browsers. 1774 * 1775 * There are situations where object detections is not reliable enough, in that 1776 * cases it makes sense to use browser detection. Simply try to avoid both! 1777 * 1778 * A combination of browser and object detection yields quite reliable results. 1779 * 1780 * @example $.browser.msie 1781 * @desc Returns true if the current useragent is some version of microsoft's internet explorer 1782 * 1783 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); } 1784 * @desc Alerts "this is safari!" only for safari browsers 1785 * 1786 * @property 1787 * @name $.browser 1788 * @type Boolean 1789 * @cat JavaScript 1790 */ 1791 1792 /* 1793 * Whether the W3C compliant box model is being used. 1794 * 1795 * @property 1796 * @name $.boxModel 1797 * @type Boolean 1798 * @cat JavaScript 1799 */ 1800 new function() { 1801 var b = navigator.userAgent.toLowerCase(); 1802 1803 // Figure out what browser is being used 1804 jQuery.browser = { 1805 version: b.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1], 1806 safari: /webkit/.test(b), 1807 opera: /opera/.test(b), 1808 msie: /msie/.test(b) && !/opera/.test(b), 1809 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b) 1810 }; 1811 1812 // Check to see if the W3C box model is being used 1813 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat"; 1814 }; 1815 1816 /** 1817 * Get a set of elements containing the unique parents of the matched 1818 * set of elements. 1819 * 1820 * You may use an optional expression to filter the set of parent elements that will match. 1821 * 1822 * @example $("p").parent() 1823 * @before <div><p>Hello</p><p>Hello</p></div> 1824 * @result [ <div><p>Hello</p><p>Hello</p></div> ] 1825 * @desc Find the parent element of each paragraph. 1826 * 1827 * @example $("p").parent(".selected") 1828 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div> 1829 * @result [ <div class="selected"><p>Hello Again</p></div> ] 1830 * @desc Find the parent element of each paragraph with a class "selected". 1831 * 1832 * @name parent 1833 * @type jQuery 1834 * @param String expr (optional) An expression to filter the parents with 1835 * @cat DOM/Traversing 1836 */ 1837 1838 /** 1839 * Get a set of elements containing the unique ancestors of the matched 1840 * set of elements (except for the root element). 1841 * 1842 * The matched elements can be filtered with an optional expression. 1843 * 1844 * @example $("span").parents() 1845 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html> 1846 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ] 1847 * @desc Find all parent elements of each span. 1848 * 1849 * @example $("span").parents("p") 1850 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html> 1851 * @result [ <p><span>Hello</span></p> ] 1852 * @desc Find all parent elements of each span that is a paragraph. 1853 * 1854 * @name parents 1855 * @type jQuery 1856 * @param String expr (optional) An expression to filter the ancestors with 1857 * @cat DOM/Traversing 1858 */ 1859 1860 /** 1861 * Get a set of elements containing the unique next siblings of each of the 1862 * matched set of elements. 1863 * 1864 * It only returns the very next sibling for each element, not all 1865 * next siblings. 1866 * 1867 * You may provide an optional expression to filter the match. 1868 * 1869 * @example $("p").next() 1870 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div> 1871 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ] 1872 * @desc Find the very next sibling of each paragraph. 1873 * 1874 * @example $("p").next(".selected") 1875 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div> 1876 * @result [ <p class="selected">Hello Again</p> ] 1877 * @desc Find the very next sibling of each paragraph that has a class "selected". 1878 * 1879 * @name next 1880 * @type jQuery 1881 * @param String expr (optional) An expression to filter the next Elements with 1882 * @cat DOM/Traversing 1883 */ 1884 1885 /** 1886 * Get a set of elements containing the unique previous siblings of each of the 1887 * matched set of elements. 1888 * 1889 * Use an optional expression to filter the matched set. 1890 * 1891 * Only the immediately previous sibling is returned, not all previous siblings. 1892 * 1893 * @example $("p").prev() 1894 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p> 1895 * @result [ <div><span>Hello Again</span></div> ] 1896 * @desc Find the very previous sibling of each paragraph. 1897 * 1898 * @example $("p").prev(".selected") 1899 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p> 1900 * @result [ <div><span>Hello</span></div> ] 1901 * @desc Find the very previous sibling of each paragraph that has a class "selected". 1902 * 1903 * @name prev 1904 * @type jQuery 1905 * @param String expr (optional) An expression to filter the previous Elements with 1906 * @cat DOM/Traversing 1907 */ 1908 1909 /** 1910 * Get a set of elements containing all of the unique siblings of each of the 1911 * matched set of elements. 1912 * 1913 * Can be filtered with an optional expressions. 1914 * 1915 * @example $("div").siblings() 1916 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p> 1917 * @result [ <p>Hello</p>, <p>And Again</p> ] 1918 * @desc Find all siblings of each div. 1919 * 1920 * @example $("div").siblings(".selected") 1921 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p> 1922 * @result [ <p class="selected">Hello Again</p> ] 1923 * @desc Find all siblings with a class "selected" of each div. 1924 * 1925 * @name siblings 1926 * @type jQuery 1927 * @param String expr (optional) An expression to filter the sibling Elements with 1928 * @cat DOM/Traversing 1929 */ 1930 1931 /** 1932 * Get a set of elements containing all of the unique children of each of the 1933 * matched set of elements. 1934 * 1935 * This set can be filtered with an optional expression that will cause 1936 * only elements matching the selector to be collected. 1937 * 1938 * @example $("div").children() 1939 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p> 1940 * @result [ <span>Hello Again</span> ] 1941 * @desc Find all children of each div. 1942 * 1943 * @example $("div").children(".selected") 1944 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div> 1945 * @result [ <p class="selected">Hello Again</p> ] 1946 * @desc Find all children with a class "selected" of each div. 1947 * 1948 * @name children 1949 * @type jQuery 1950 * @param String expr (optional) An expression to filter the child Elements with 1951 * @cat DOM/Traversing 1952 */ 1953 jQuery.each({ 1954 parent: "a.parentNode", 1955 parents: "jQuery.parents(a)", 1956 next: "jQuery.nth(a,2,'nextSibling')", 1957 prev: "jQuery.nth(a,2,'previousSibling')", 1958 siblings: "jQuery.sibling(a.parentNode.firstChild,a)", 1959 children: "jQuery.sibling(a.firstChild)" 1960 }, function(i,n){ 1961 jQuery.fn[ i ] = function(a) { 1962 var ret = jQuery.map(this,n); 1963 if ( a && typeof a == "string" ) 1964 ret = jQuery.multiFilter(a,ret); 1965 return this.pushStack( ret ); 1966 }; 1967 }); 1968 1969 /** 1970 * Append all of the matched elements to another, specified, set of elements. 1971 * This operation is, essentially, the reverse of doing a regular 1972 * $(A).append(B), in that instead of appending B to A, you're appending 1973 * A to B. 1974 * 1975 * @example $("p").appendTo("#foo"); 1976 * @before <p>I would like to say: </p><div id="foo"></div> 1977 * @result <div id="foo"><p>I would like to say: </p></div> 1978 * @desc Appends all paragraphs to the element with the ID "foo" 1979 * 1980 * @name appendTo 1981 * @type jQuery 1982 * @param <Content> content Content to append to the selected element to. 1983 * @cat DOM/Manipulation 1984 * @see append(<Content>) 1985 */ 1986 1987 /** 1988 * Prepend all of the matched elements to another, specified, set of elements. 1989 * This operation is, essentially, the reverse of doing a regular 1990 * $(A).prepend(B), in that instead of prepending B to A, you're prepending 1991 * A to B. 1992 * 1993 * @example $("p").prependTo("#foo"); 1994 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div> 1995 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div> 1996 * @desc Prepends all paragraphs to the element with the ID "foo" 1997 * 1998 * @name prependTo 1999 * @type jQuery 2000 * @param <Content> content Content to prepend to the selected element to. 2001 * @cat DOM/Manipulation 2002 * @see prepend(<Content>) 2003 */ 2004 2005 /** 2006 * Insert all of the matched elements before another, specified, set of elements. 2007 * This operation is, essentially, the reverse of doing a regular 2008 * $(A).before(B), in that instead of inserting B before A, you're inserting 2009 * A before B. 2010 * 2011 * @example $("p").insertBefore("#foo"); 2012 * @before <div id="foo">Hello</div><p>I would like to say: </p> 2013 * @result <p>I would like to say: </p><div id="foo">Hello</div> 2014 * @desc Same as $("#foo").before("p") 2015 * 2016 * @name insertBefore 2017 * @type jQuery 2018 * @param <Content> content Content to insert the selected element before. 2019 * @cat DOM/Manipulation 2020 * @see before(<Content>) 2021 */ 2022 2023 /** 2024 * Insert all of the matched elements after another, specified, set of elements. 2025 * This operation is, essentially, the reverse of doing a regular 2026 * $(A).after(B), in that instead of inserting B after A, you're inserting 2027 * A after B. 2028 * 2029 * @example $("p").insertAfter("#foo"); 2030 * @before <p>I would like to say: </p><div id="foo">Hello</div> 2031 * @result <div id="foo">Hello</div><p>I would like to say: </p> 2032 * @desc Same as $("#foo").after("p") 2033 * 2034 * @name insertAfter 2035 * @type jQuery 2036 * @param <Content> content Content to insert the selected element after. 2037 * @cat DOM/Manipulation 2038 * @see after(<Content>) 2039 */ 2040 2041 jQuery.each({ 2042 appendTo: "append", 2043 prependTo: "prepend", 2044 insertBefore: "before", 2045 insertAfter: "after" 2046 }, function(i,n){ 2047 jQuery.fn[ i ] = function(){ 2048 var a = arguments; 2049 return this.each(function(){ 2050 for ( var j = 0, al = a.length; j < al; j++ ) 2051 jQuery(a[j])[n]( this ); 2052 }); 2053 }; 2054 }); 2055 2056 /** 2057 * Remove an attribute from each of the matched elements. 2058 * 2059 * @example $("input").removeAttr("disabled") 2060 * @before <input disabled="disabled"/> 2061 * @result <input/> 2062 * 2063 * @name removeAttr 2064 * @type jQuery 2065 * @param String name The name of the attribute to remove. 2066 * @cat DOM/Attributes 2067 */ 2068 2069 /** 2070 * Adds the specified class(es) to each of the set of matched elements. 2071 * 2072 * @example $("p").addClass("selected") 2073 * @before <p>Hello</p> 2074 * @result [ <p class="selected">Hello</p> ] 2075 * 2076 * @example $("p").addClass("selected highlight") 2077 * @before <p>Hello</p> 2078 * @result [ <p class="selected highlight">Hello</p> ] 2079 * 2080 * @name addClass 2081 * @type jQuery 2082 * @param String class One or more CSS classes to add to the elements 2083 * @cat DOM/Attributes 2084 * @see removeClass(String) 2085 */ 2086 2087 /** 2088 * Removes all or the specified class(es) from the set of matched elements. 2089 * 2090 * @example $("p").removeClass() 2091 * @before <p class="selected">Hello</p> 2092 * @result [ <p>Hello</p> ] 2093 * 2094 * @example $("p").removeClass("selected") 2095 * @before <p class="selected first">Hello</p> 2096 * @result [ <p class="first">Hello</p> ] 2097 * 2098 * @example $("p").removeClass("selected highlight") 2099 * @before <p class="highlight selected first">Hello</p> 2100 * @result [ <p class="first">Hello</p> ] 2101 * 2102 * @name removeClass 2103 * @type jQuery 2104 * @param String class (optional) One or more CSS classes to remove from the elements 2105 * @cat DOM/Attributes 2106 * @see addClass(String) 2107 */ 2108 2109 /** 2110 * Adds the specified class if it is not present, removes it if it is 2111 * present. 2112 * 2113 * @example $("p").toggleClass("selected") 2114 * @before <p>Hello</p><p class="selected">Hello Again</p> 2115 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ] 2116 * 2117 * @name toggleClass 2118 * @type jQuery 2119 * @param String class A CSS class with which to toggle the elements 2120 * @cat DOM/Attributes 2121 */ 2122 2123 /** 2124 * Removes all matched elements from the DOM. This does NOT remove them from the 2125 * jQuery object, allowing you to use the matched elements further. 2126 * 2127 * Can be filtered with an optional expressions. 2128 * 2129 * @example $("p").remove(); 2130 * @before <p>Hello</p> how are <p>you?</p> 2131 * @result how are 2132 * 2133 * @example $("p").remove(".hello"); 2134 * @before <p class="hello">Hello</p> how are <p>you?</p> 2135 * @result how are <p>you?</p> 2136 * 2137 * @name remove 2138 * @type jQuery 2139 * @param String expr (optional) A jQuery expression to filter elements by. 2140 * @cat DOM/Manipulation 2141 */ 2142 2143 /** 2144 * Removes all child nodes from the set of matched elements. 2145 * 2146 * @example $("p").empty() 2147 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p> 2148 * @result [ <p></p> ] 2149 * 2150 * @name empty 2151 * @type jQuery 2152 * @cat DOM/Manipulation 2153 */ 2154 2155 jQuery.each( { 2156 removeAttr: function( key ) { 2157 jQuery.attr( this, key, "" ); 2158 this.removeAttribute( key ); 2159 }, 2160 addClass: function(c){ 2161 jQuery.className.add(this,c); 2162 }, 2163 removeClass: function(c){ 2164 jQuery.className.remove(this,c); 2165 }, 2166 toggleClass: function( c ){ 2167 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c); 2168 }, 2169 remove: function(a){ 2170 if ( !a || jQuery.filter( a, [this] ).r.length ) 2171 this.parentNode.removeChild( this ); 2172 }, 2173 empty: function() { 2174 while ( this.firstChild ) 2175 this.removeChild( this.firstChild ); 2176 } 2177 }, function(i,n){ 2178 jQuery.fn[ i ] = function() { 2179 return this.each( n, arguments ); 2180 }; 2181 }); 2182 2183 /** 2184 * Reduce the set of matched elements to a single element. 2185 * The position of the element in the set of matched elements 2186 * starts at 0 and goes to length - 1. 2187 * 2188 * @example $("p").eq(1) 2189 * @before <p>This is just a test.</p><p>So is this</p> 2190 * @result [ <p>So is this</p> ] 2191 * 2192 * @name eq 2193 * @type jQuery 2194 * @param Number pos The index of the element that you wish to limit to. 2195 * @cat Core 2196 */ 2197 2198 /** 2199 * Reduce the set of matched elements to all elements before a given position. 2200 * The position of the element in the set of matched elements 2201 * starts at 0 and goes to length - 1. 2202 * 2203 * @example $("p").lt(1) 2204 * @before <p>This is just a test.</p><p>So is this</p> 2205 * @result [ <p>This is just a test.</p> ] 2206 * 2207 * @name lt 2208 * @type jQuery 2209 * @param Number pos Reduce the set to all elements below this position. 2210 * @cat Core 2211 */ 2212 2213 /** 2214 * Reduce the set of matched elements to all elements after a given position. 2215 * The position of the element in the set of matched elements 2216 * starts at 0 and goes to length - 1. 2217 * 2218 * @example $("p").gt(0) 2219 * @before <p>This is just a test.</p><p>So is this</p> 2220 * @result [ <p>So is this</p> ] 2221 * 2222 * @name gt 2223 * @type jQuery 2224 * @param Number pos Reduce the set to all elements after this position. 2225 * @cat Core 2226 */ 2227 2228 /** 2229 * Filter the set of elements to those that contain the specified text. 2230 * 2231 * @example $("p").contains("test") 2232 * @before <p>This is just a test.</p><p>So is this</p> 2233 * @result [ <p>This is just a test.</p> ] 2234 * 2235 * @name contains 2236 * @type jQuery 2237 * @param String str The string that will be contained within the text of an element. 2238 * @cat DOM/Traversing 2239 */ 2240 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){ 2241 jQuery.fn[ n ] = function(num,fn) { 2242 return this.filter( ":" + n + "(" + num + ")", fn ); 2243 }; 2244 }); 2245 2246 /** 2247 * Get the current computed, pixel, width of the first matched element. 2248 * 2249 * @example $("p").width(); 2250 * @before <p>This is just a test.</p> 2251 * @result 300 2252 * 2253 * @name width 2254 * @type String 2255 * @cat CSS 2256 */ 2257 2258 /** 2259 * Set the CSS width of every matched element. If no explicit unit 2260 * was specified (like 'em' or '%') then "px" is added to the width. 2261 * 2262 * @example $("p").width(20); 2263 * @before <p>This is just a test.</p> 2264 * @result <p style="width:20px;">This is just a test.</p> 2265 * 2266 * @example $("p").width("20em"); 2267 * @before <p>This is just a test.</p> 2268 * @result <p style="width:20em;">This is just a test.</p> 2269 * 2270 * @name width 2271 * @type jQuery 2272 * @param String|Number val Set the CSS property to the specified value. 2273 * @cat CSS 2274 */ 2275 2276 /** 2277 * Get the current computed, pixel, height of the first matched element. 2278 * 2279 * @example $("p").height(); 2280 * @before <p>This is just a test.</p> 2281 * @result 300 2282 * 2283 * @name height 2284 * @type String 2285 * @cat CSS 2286 */ 2287 2288 /** 2289 * Set the CSS height of every matched element. If no explicit unit 2290 * was specified (like 'em' or '%') then "px" is added to the width. 2291 * 2292 * @example $("p").height(20); 2293 * @before <p>This is just a test.</p> 2294 * @result <p style="height:20px;">This is just a test.</p> 2295 * 2296 * @example $("p").height("20em"); 2297 * @before <p>This is just a test.</p> 2298 * @result <p style="height:20em;">This is just a test.</p> 2299 * 2300 * @name height 2301 * @type jQuery 2302 * @param String|Number val Set the CSS property to the specified value. 2303 * @cat CSS 2304 */ 2305 2306 jQuery.each( [ "height", "width" ], function(i,n){ 2307 jQuery.fn[ n ] = function(h) { 2308 return h == undefined ? 2309 ( this.length ? jQuery.css( this[0], n ) : null ) : 2310 this.css( n, h.constructor == String ? h : h + "px" ); 2311 }; 2312 }); 2313 jQuery.extend({ 2314 expr: { 2315 "": "m[2]=='*'||jQuery.nodeName(a,m[2])", 2316 "#": "a.getAttribute('id')==m[2]", 2317 ":": { 2318 // Position Checks 2319 lt: "i<m[3]-0", 2320 gt: "i>m[3]-0", 2321 nth: "m[3]-0==i", 2322 eq: "m[3]-0==i", 2323 first: "i==0", 2324 last: "i==r.length-1", 2325 even: "i%2==0", 2326 odd: "i%2", 2327 2328 // Child Checks 2329 "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling',a)==a", 2330 "first-child": "jQuery.nth(a.parentNode.firstChild,1,'nextSibling')==a", 2331 "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a", 2332 "only-child": "jQuery.sibling(a.parentNode.firstChild).length==1", 2333 2334 // Parent Checks 2335 parent: "a.firstChild", 2336 empty: "!a.firstChild", 2337 2338 // Text Check 2339 contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0", 2340 2341 // Visibility 2342 visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"', 2343 hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"', 2344 2345 // Form attributes 2346 enabled: "!a.disabled", 2347 disabled: "a.disabled", 2348 checked: "a.checked", 2349 selected: "a.selected||jQuery.attr(a,'selected')", 2350 2351 // Form elements 2352 text: "'text'==a.type", 2353 radio: "'radio'==a.type", 2354 checkbox: "'checkbox'==a.type", 2355 file: "'file'==a.type", 2356 password: "'password'==a.type", 2357 submit: "'submit'==a.type", 2358 image: "'image'==a.type", 2359 reset: "'reset'==a.type", 2360 button: '"button"==a.type||jQuery.nodeName(a,"button")', 2361 input: "/input|select|textarea|button/i.test(a.nodeName)" 2362 }, 2363 ".": "jQuery.className.has(a,m[2])", 2364 "@": { 2365 "=": "z==m[4]", 2366 "!=": "z!=m[4]", 2367 "^=": "z&&!z.indexOf(m[4])", 2368 "$=": "z&&z.substr(z.length - m[4].length,m[4].length)==m[4]", 2369 "*=": "z&&z.indexOf(m[4])>=0", 2370 "": "z", 2371 _resort: function(m){ 2372 return ["", m[1], m[3], m[2], m[5]]; 2373 }, 2374 _prefix: "var z=a[m[3]];if(!z||/href|src/.test(m[3]))z=jQuery.attr(a,m[3]);" 2375 }, 2376 "[": "jQuery.find(m[2],a).length" 2377 }, 2378 2379 // The regular expressions that power the parsing engine 2380 parse: [ 2381 // Match: [@value='test'], [@foo] 2382 /^\[ *(@)([\w-]+) *([!*$^=]*) *('?"?)(.*?)\4 *\]/, 2383 2384 // Match: [div], [div p] 2385 /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/, 2386 2387 // Match: :contains('foo') 2388 /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/, 2389 2390 // Match: :even, :last-chlid, #id, .class 2391 new RegExp("^([:.#]*)(" + 2392 ( jQuery.chars = "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)" ) + "+)") 2393 ], 2394 2395 token: [ 2396 /^(\/?\.\.)/, "a.parentNode", 2397 /^(>|\/)/, "jQuery.sibling(a.firstChild)", 2398 /^(\+)/, "jQuery.nth(a,2,'nextSibling')", 2399 /^(~)/, function(a){ 2400 var s = jQuery.sibling(a.parentNode.firstChild); 2401 return s.slice(jQuery.inArray(a,s) + 1); 2402 } 2403 ], 2404 2405 multiFilter: function( expr, elems, not ) { 2406 var old, cur = []; 2407 2408 while ( expr && expr != old ) { 2409 old = expr; 2410 var f = jQuery.filter( expr, elems, not ); 2411 expr = f.t.replace(/^\s*,\s*/, "" ); 2412 cur = not ? elems = f.r : jQuery.merge( cur, f.r ); 2413 } 2414 2415 return cur; 2416 }, 2417 2418 /** 2419 * @name $.find 2420 * @type Array<Element> 2421 * @private 2422 * @cat Core 2423 */ 2424 find: function( t, context ) { 2425 // Quickly handle non-string expressions 2426 if ( typeof t != "string" ) 2427 return [ t ]; 2428 2429 // Make sure that the context is a DOM Element 2430 if ( context && !context.nodeType ) 2431 context = null; 2432 2433 // Set the correct context (if none is provided) 2434 context = context || document; 2435 2436 // Handle the common XPath // expression 2437 if ( !t.indexOf("//") ) { 2438 context = context.documentElement; 2439 t = t.substr(2,t.length); 2440 2441 // And the / root expression 2442 } else if ( !t.indexOf("/") && !context.ownerDocument ) { 2443 context = context.documentElement; 2444 t = t.substr(1,t.length); 2445 if ( t.indexOf("/") >= 1 ) 2446 t = t.substr(t.indexOf("/"),t.length); 2447 } 2448 2449 // Initialize the search 2450 var ret = [context], done = [], last; 2451 2452 // Continue while a selector expression exists, and while 2453 // we're no longer looping upon ourselves 2454 while ( t && last != t ) { 2455 var r = []; 2456 last = t; 2457 2458 t = jQuery.trim(t).replace( /^\/\//, "" ); 2459 2460 var foundToken = false; 2461 2462 // An attempt at speeding up child selectors that 2463 // point to a specific element tag 2464 var re = new RegExp("^[/>]\\s*(" + jQuery.chars + "+)"); 2465 var m = re.exec(t); 2466 2467 if ( m ) { 2468 // Perform our own iteration and filter 2469 for ( var i = 0; ret[i]; i++ ) 2470 for ( var c = ret[i].firstChild; c; c = c.nextSibling ) 2471 if ( c.nodeType == 1 && ( m[1] == "*" || jQuery.nodeName(c, m[1]) ) ) 2472 r.push( c ); 2473 2474 ret = r; 2475 t = t.replace( re, "" ); 2476 if ( t.indexOf(" ") == 0 ) continue; 2477 foundToken = true; 2478 } else { 2479 // Look for pre-defined expression tokens 2480 for ( var i = 0, tl = jQuery.token.length; i < tl; i += 2 ) { 2481 // Attempt to match each, individual, token in 2482 // the specified order 2483 var re = jQuery.token[i], fn = jQuery.token[i+1]; 2484 var m = re.exec(t); 2485 2486 // If the token match was found 2487 if ( m ) { 2488 // Map it against the token's handler 2489 r = ret = jQuery.map( ret, jQuery.isFunction( fn ) ? 2490 fn : new Function( "a", "return " + fn ) ); 2491 2492 // And remove the token 2493 t = jQuery.trim( t.replace( re, "" ) ); 2494 foundToken = true; 2495 break; 2496 } 2497 } 2498 } 2499 2500 // See if there's still an expression, and that we haven't already 2501 // matched a token 2502 if ( t && !foundToken ) { 2503 // Handle multiple expressions 2504 if ( !t.indexOf(",") ) { 2505 // Clean the result set 2506 if ( context == ret[0] ) ret.shift(); 2507 2508 // Merge the result sets 2509 done = jQuery.merge( done, ret ); 2510 2511 // Reset the context 2512 r = ret = [context]; 2513 2514 // Touch up the selector string 2515 t = " " + t.substr(1,t.length); 2516 2517 } else { 2518 // Optomize for the case nodeName#idName 2519 var re2 = new RegExp("^(" + jQuery.chars + "+)(#)(" + jQuery.chars + "+)"); 2520 var m = re2.exec(t); 2521 2522 // Re-organize the results, so that they're consistent 2523 if ( m ) { 2524 m = [ 0, m[2], m[3], m[1] ]; 2525 2526 } else { 2527 // Otherwise, do a traditional filter check for 2528 // ID, class, and element selectors 2529 re2 = new RegExp("^([#.]?)(" + jQuery.chars + "*)"); 2530 m = re2.exec(t); 2531 } 2532 2533 m[2] = m[2].replace(/\\/g, ""); 2534 2535 var elem = ret[ret.length-1]; 2536 2537 // Try to do a global search by ID, where we can 2538 if ( m[1] == "#" && elem && elem.getElementById ) { 2539 // Optimization for HTML document case 2540 var oid = elem.getElementById(m[2]); 2541 2542 // Do a quick check for the existence of the actual ID attribute 2543 // to avoid selecting by the name attribute in IE 2544 // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form 2545 if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] ) 2546 oid = jQuery('[@id="'+m[2]+'"]', elem)[0]; 2547 2548 // Do a quick check for node name (where applicable) so 2549 // that div#foo searches will be really fast 2550 ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : []; 2551 } else { 2552 // We need to find all descendant elements 2553 for ( var i = 0; ret[i]; i++ ) { 2554 // Grab the tag name being searched for 2555 var tag = m[1] != "" || m[0] == "" ? "*" : m[2]; 2556 2557 // Handle IE7 being really dumb about <object>s 2558 if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" ) 2559 tag = "param"; 2560 2561 r = jQuery.merge( r, ret[i].getElementsByTagName( tag )); 2562 } 2563 2564 // It's faster to filter by class and be done with it 2565 if ( m[1] == "." ) 2566 r = jQuery.classFilter( r, m[2] ); 2567 2568 // Same with ID filtering 2569 if ( m[1] == "#" ) { 2570 var tmp = []; 2571 2572 // Try to find the element with the ID 2573 for ( var i = 0; r[i]; i++ ) 2574 if ( r[i].getAttribute("id") == m[2] ) { 2575 tmp = [ r[i] ]; 2576 break; 2577 } 2578 2579 r = tmp; 2580 } 2581 2582 ret = r; 2583 } 2584 2585 t = t.replace( re2, "" ); 2586 } 2587 2588 } 2589 2590 // If a selector string still exists 2591 if ( t ) { 2592 // Attempt to filter it 2593 var val = jQuery.filter(t,r); 2594 ret = r = val.r; 2595 t = jQuery.trim(val.t); 2596 } 2597 } 2598 2599 // An error occurred with the selector; 2600 // just return an empty set instead 2601 if ( t ) 2602 ret = []; 2603 2604 // Remove the root context 2605 if ( ret && context == ret[0] ) 2606 ret.shift(); 2607 2608 // And combine the results 2609 done = jQuery.merge( done, ret ); 2610 2611 return done; 2612 }, 2613 2614 classFilter: function(r,m,not){ 2615 m = " " + m + " "; 2616 var tmp = []; 2617 for ( var i = 0; r[i]; i++ ) { 2618 var pass = (" " + r[i].className + " ").indexOf( m ) >= 0; 2619 if ( !not && pass || not && !pass ) 2620 tmp.push( r[i] ); 2621 } 2622 return tmp; 2623 }, 2624 2625 filter: function(t,r,not) { 2626 var last; 2627 2628 // Look for common filter expressions 2629 while ( t && t != last ) { 2630 last = t; 2631 2632 var p = jQuery.parse, m; 2633 2634 for ( var i = 0; p[i]; i++ ) { 2635 m = p[i].exec( t ); 2636 2637 if ( m ) { 2638 // Remove what we just matched 2639 t = t.substring( m[0].length ); 2640 2641 // Re-organize the first match 2642 if ( jQuery.expr[ m[1] ]._resort ) 2643 m = jQuery.expr[ m[1] ]._resort( m ); 2644 2645 m[2] = m[2].replace(/\\/g, ""); 2646 2647 break; 2648 } 2649 } 2650 2651 if ( !m ) 2652 break; 2653 2654 // :not() is a special case that can be optimized by 2655 // keeping it out of the expression list 2656 if ( m[1] == ":" && m[2] == "not" ) 2657 r = jQuery.filter(m[3], r, true).r; 2658 2659 // We can get a big speed boost by filtering by class here 2660 else if ( m[1] == "." ) 2661 r = jQuery.classFilter(r, m[2], not); 2662 2663 // Otherwise, find the expression to execute 2664 else { 2665 var f = jQuery.expr[m[1]]; 2666 if ( typeof f != "string" ) 2667 f = jQuery.expr[m[1]][m[2]]; 2668 2669 // Build a custom macro to enclose it 2670 eval("f = function(a,i){" + 2671 ( jQuery.expr[ m[1] ]._prefix || "" ) + 2672 "return " + f + "}"); 2673 2674 // Execute it against the current filter 2675 r = jQuery.grep( r, f, not ); 2676 } 2677 } 2678 2679 // Return an array of filtered elements (r) 2680 // and the modified expression string (t) 2681 return { r: r, t: t }; 2682 }, 2683 2684 /** 2685 * All ancestors of a given element. 2686 * 2687 * @private 2688 * @name $.parents 2689 * @type Array<Element> 2690 * @param Element elem The element to find the ancestors of. 2691 * @cat DOM/Traversing 2692 */ 2693 parents: function( elem ){ 2694 var matched = []; 2695 var cur = elem.parentNode; 2696 while ( cur && cur != document ) { 2697 matched.push( cur ); 2698 cur = cur.parentNode; 2699 } 2700 return matched; 2701 }, 2702 2703 /** 2704 * A handy, and fast, way to traverse in a particular direction and find 2705 * a specific element. 2706 * 2707 * @private 2708 * @name $.nth 2709 * @type DOMElement 2710 * @param DOMElement cur The element to search from. 2711 * @param String|Number num The Nth result to match. Can be a number or a string (like 'even' or 'odd'). 2712 * @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling'). 2713 * @cat DOM/Traversing 2714 */ 2715 nth: function(cur,result,dir,elem){ 2716 result = result || 1; 2717 var num = 0; 2718 for ( ; cur; cur = cur[dir] ) { 2719 if ( cur.nodeType == 1 ) num++; 2720 if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem || 2721 result == "odd" && num % 2 == 1 && cur == elem ) break; 2722 } 2723 return cur; 2724 }, 2725 2726 /** 2727 * All elements on a specified axis. 2728 * 2729 * @private 2730 * @name $.sibling 2731 * @type Array 2732 * @param Element elem The element to find all the siblings of (including itself). 2733 * @cat DOM/Traversing 2734 */ 2735 sibling: function( n, elem ) { 2736 var r = []; 2737 2738 for ( ; n; n = n.nextSibling ) { 2739 if ( n.nodeType == 1 && (!elem || n != elem) ) 2740 r.push( n ); 2741 } 2742 2743 return r; 2744 } 2745 }); 2746 /* 2747 * A number of helper functions used for managing events. 2748 * Many of the ideas behind this code orignated from 2749 * Dean Edwards' addEvent library. 2750 */ 2751 jQuery.event = { 2752 2753 // Bind an event to an element 2754 // Original by Dean Edwards 2755 add: function(element, type, handler, data) { 2756 // For whatever reason, IE has trouble passing the window object 2757 // around, causing it to be cloned in the process 2758 if ( jQuery.browser.msie && element.setInterval != undefined ) 2759 element = window; 2760 2761 // if data is passed, bind to handler 2762 if( data != undefined ) { 2763 // Create temporary function pointer to original handler 2764 var fn = handler; 2765 2766 // Create unique handler function, wrapped around original handler 2767 handler = function() { 2768 // Pass arguments and context to original handler 2769 return fn.apply(this, arguments); 2770 }; 2771 2772 // Store data in unique handler 2773 handler.data = data; 2774 2775 // Set the guid of unique handler to the same of original handler, so it can be removed 2776 handler.guid = fn.guid; 2777 } 2778 2779 // Make sure that the function being executed has a unique ID 2780 if ( !handler.guid ) { 2781 handler.guid = this.guid++; 2782 // Don't forget to set guid for the original handler function 2783 if (fn) fn.guid = handler.guid; 2784 } 2785 2786 // Init the element's event structure 2787 if (!element.$events) 2788 element.$events = {}; 2789 2790 if (!element.$handle) 2791 element.$handle = function() { 2792 jQuery.event.handle.apply(element, arguments); 2793 }; 2794 2795 // Get the current list of functions bound to this event 2796 var handlers = element.$events[type]; 2797 2798 // Init the event handler queue 2799 if (!handlers) { 2800 handlers = element.$events[type] = {}; 2801 2802 // And bind the global event handler to the element 2803 if (element.addEventListener) 2804 element.addEventListener(type, element.$handle, false); 2805 else if (element.attachEvent) 2806 element.attachEvent("on" + type, element.$handle); 2807 } 2808 2809 // Add the function to the element's handler list 2810 handlers[handler.guid] = handler; 2811 2812 // Remember the function in a global list (for triggering) 2813 if (!this.global[type]) 2814 this.global[type] = []; 2815 this.global[type].push( element ); 2816 }, 2817 2818 guid: 1, 2819 global: {}, 2820 2821 // Detach an event or set of events from an element 2822 remove: function(element, type, handler) { 2823 var events = element.$events, ret; 2824 2825 if ( events ) { 2826 // type is actually an event object here 2827 if ( type && type.type ) { 2828 handler = type.handler; 2829 type = type.type; 2830 } 2831 2832 if ( !type ) { 2833 for ( type in events ) 2834 this.remove( element, type ); 2835 2836 } else if ( events[type] ) { 2837 // remove the given handler for the given type 2838 if ( handler ) 2839 delete events[type][handler.guid]; 2840 2841 // remove all handlers for the given type 2842 else 2843 for ( handler in element.$events[type] ) 2844 delete events[type][handler]; 2845 2846 // remove generic event handler if no more handlers exist 2847 for ( ret in events[type] ) break; 2848 if ( !ret ) { 2849 if (element.removeEventListener) 2850 element.removeEventListener(type, element.$handle, false); 2851 else if (element.detachEvent) 2852 element.detachEvent("on" + type, element.$handle); 2853 ret = null; 2854 delete events[type]; 2855 } 2856 } 2857 2858 // Remove the expando if it's no longer used 2859 for ( ret in events ) break; 2860 if ( !ret ) 2861 element.$handle = element.$events = null; 2862 } 2863 }, 2864 2865 trigger: function(type, data, element) { 2866 // Clone the incoming data, if any 2867 data = jQuery.makeArray(data || []); 2868 2869 // Handle a global trigger 2870 if ( !element ) 2871 jQuery.each( this.global[type] || [], function(){ 2872 jQuery.event.trigger( type, data, this ); 2873 }); 2874 2875 // Handle triggering a single element 2876 else { 2877 var val, ret, fn = jQuery.isFunction( element[ type ] || null ); 2878 2879 // Pass along a fake event 2880 data.unshift( this.fix({ type: type, target: element }) ); 2881 2882 // Trigger the event 2883 if ( (val = this.handle.apply( element, data )) !== false ) 2884 this.triggered = true; 2885 2886 if ( fn && val !== false && !jQuery.nodeName(element, 'a') ) 2887 element[ type ](); 2888 2889 this.triggered = false; 2890 } 2891 }, 2892 2893 handle: function(event) { 2894 // returned undefined or false 2895 var val; 2896 2897 // Handle the second event of a trigger and when 2898 // an event is called after a page has unloaded 2899 if ( typeof jQuery == "undefined" || jQuery.event.triggered ) 2900 return val; 2901 2902 // Empty object is for triggered events with no data 2903 event = jQuery.event.fix( event || window.event || {} ); 2904 2905 var c = this.$events && this.$events[event.type], args = [].slice.call( arguments, 1 ); 2906 args.unshift( event ); 2907 2908 for ( var j in c ) { 2909 // Pass in a reference to the handler function itself 2910 // So that we can later remove it 2911 args[0].handler = c[j]; 2912 args[0].data = c[j].data; 2913 2914 if ( c[j].apply( this, args ) === false ) { 2915 event.preventDefault(); 2916 event.stopPropagation(); 2917 val = false; 2918 } 2919 } 2920 2921 // Clean up added properties in IE to prevent memory leak 2922 if (jQuery.browser.msie) 2923 event.target = event.preventDefault = event.stopPropagation = 2924 event.handler = event.data = null; 2925 2926 return val; 2927 }, 2928 2929 fix: function(event) { 2930 // Fix target property, if necessary 2931 if ( !event.target && event.srcElement ) 2932 event.target = event.srcElement; 2933 2934 // Calculate pageX/Y if missing and clientX/Y available 2935 if ( event.pageX == undefined && event.clientX != undefined ) { 2936 var e = document.documentElement || document.body; 2937 event.pageX = event.clientX + e.scrollLeft; 2938 event.pageY = event.clientY + e.scrollTop; 2939 } 2940 2941 // check if target is a textnode (safari) 2942 if (jQuery.browser.safari && event.target.nodeType == 3) { 2943 // store a copy of the original event object 2944 // and clone because target is read only 2945 var originalEvent = event; 2946 event = jQuery.extend({}, originalEvent); 2947 2948 // get parentnode from textnode 2949 event.target = originalEvent.target.parentNode; 2950 2951 // add preventDefault and stopPropagation since 2952 // they will not work on the clone 2953 event.preventDefault = function() { 2954 return originalEvent.preventDefault(); 2955 }; 2956 event.stopPropagation = function() { 2957 return originalEvent.stopPropagation(); 2958 }; 2959 } 2960 2961 // fix preventDefault and stopPropagation 2962 if (!event.preventDefault) 2963 event.preventDefault = function() { 2964 this.returnValue = false; 2965 }; 2966 2967 if (!event.stopPropagation) 2968 event.stopPropagation = function() { 2969 this.cancelBubble = true; 2970 }; 2971 2972 return event; 2973 } 2974 }; 2975 2976 jQuery.fn.extend({ 2977 2978 /** 2979 * Binds a handler to a particular event (like click) for each matched element. 2980 * The event handler is passed an event object that you can use to prevent 2981 * default behaviour. To stop both default action and event bubbling, your handler 2982 * has to return false. 2983 * 2984 * In most cases, you can define your event handlers as anonymous functions 2985 * (see first example). In cases where that is not possible, you can pass additional 2986 * data as the second parameter (and the handler function as the third), see 2987 * second example. 2988 * 2989 * @example $("p").bind("click", function(){ 2990 * alert( $(this).text() ); 2991 * }); 2992 * @before <p>Hello</p> 2993 * @result alert("Hello") 2994 * 2995 * @example function handler(event) { 2996 * alert(event.data.foo); 2997 * } 2998 * $("p").bind("click", {foo: "bar"}, handler) 2999 * @result alert("bar") 3000 * @desc Pass some additional data to the event handler. 3001 * 3002 * @example $("form").bind("submit", function() { return false; }) 3003 * @desc Cancel a default action and prevent it from bubbling by returning false 3004 * from your function. 3005 * 3006 * @example $("form").bind("submit", function(event){ 3007 * event.preventDefault(); 3008 * }); 3009 * @desc Cancel only the default action by using the preventDefault method. 3010 * 3011 * 3012 * @example $("form").bind("submit", function(event){ 3013 * event.stopPropagation(); 3014 * }); 3015 * @desc Stop only an event from bubbling by using the stopPropagation method. 3016 * 3017 * @name bind 3018 * @type jQuery 3019 * @param String type An event type 3020 * @param Object data (optional) Additional data passed to the event handler as event.data 3021 * @param Function fn A function to bind to the event on each of the set of matched elements 3022 * @cat Events 3023 */ 3024 bind: function( type, data, fn ) { 3025 return this.each(function(){ 3026 jQuery.event.add( this, type, fn || data, fn && data ); 3027 }); 3028 }, 3029 3030 /** 3031 * Binds a handler to a particular event (like click) for each matched element. 3032 * The handler is executed only once for each element. Otherwise, the same rules 3033 * as described in bind() apply. 3034 The event handler is passed an event object that you can use to prevent 3035 * default behaviour. To stop both default action and event bubbling, your handler 3036 * has to return false. 3037 * 3038 * In most cases, you can define your event handlers as anonymous functions 3039 * (see first example). In cases where that is not possible, you can pass additional 3040 * data as the second paramter (and the handler function as the third), see 3041 * second example. 3042 * 3043 * @example $("p").one("click", function(){ 3044 * alert( $(this).text() ); 3045 * }); 3046 * @before <p>Hello</p> 3047 * @result alert("Hello") 3048 * 3049 * @name one 3050 * @type jQuery 3051 * @param String type An event type 3052 * @param Object data (optional) Additional data passed to the event handler as event.data 3053 * @param Function fn A function to bind to the event on each of the set of matched elements 3054 * @cat Events 3055 */ 3056 one: function( type, data, fn ) { 3057 return this.each(function(){ 3058 jQuery.event.add( this, type, function(event) { 3059 jQuery(this).unbind(event); 3060 return (fn || data).apply( this, arguments); 3061 }, fn && data); 3062 }); 3063 }, 3064 3065 /** 3066 * The opposite of bind, removes a bound event from each of the matched 3067 * elements. 3068 * 3069 * Without any arguments, all bound events are removed. 3070 * 3071 * If the type is provided, all bound events of that type are removed. 3072 * 3073 * If the function that was passed to bind is provided as the second argument, 3074 * only that specific event handler is removed. 3075 * 3076 * @example $("p").unbind() 3077 * @before <p onclick="alert('Hello');">Hello</p> 3078 * @result [ <p>Hello</p> ] 3079 * 3080 * @example $("p").unbind( "click" ) 3081 * @before <p onclick="alert('Hello');">Hello</p> 3082 * @result [ <p>Hello</p> ] 3083 * 3084 * @example $("p").unbind( "click", function() { alert("Hello"); } ) 3085 * @before <p onclick="alert('Hello');">Hello</p> 3086 * @result [ <p>Hello</p> ] 3087 * 3088 * @name unbind 3089 * @type jQuery 3090 * @param String type (optional) An event type 3091 * @param Function fn (optional) A function to unbind from the event on each of the set of matched elements 3092 * @cat Events 3093 */ 3094 unbind: function( type, fn ) { 3095 return this.each(function(){ 3096 jQuery.event.remove( this, type, fn ); 3097 }); 3098 }, 3099 3100 /** 3101 * Trigger a type of event on every matched element. This will also cause 3102 * the default action of the browser with the same name (if one exists) 3103 * to be executed. For example, passing 'submit' to the trigger() 3104 * function will also cause the browser to submit the form. This 3105 * default action can be prevented by returning false from one of 3106 * the functions bound to the event. 3107 * 3108 * You can also trigger custom events registered with bind. 3109 * 3110 * @example $("p").trigger("click") 3111 * @before <p click="alert('hello')">Hello</p> 3112 * @result alert('hello') 3113 * 3114 * @example $("p").click(function(event, a, b) { 3115 * // when a normal click fires, a and b are undefined 3116 * // for a trigger like below a refers too "foo" and b refers to "bar" 3117 * }).trigger("click", ["foo", "bar"]); 3118 * @desc Example of how to pass arbitrary data to an event 3119 * 3120 * @example $("p").bind("myEvent",function(event,message1,message2) { 3121 * alert(message1 + ' ' + message2); 3122 * }); 3123 * $("p").trigger("myEvent",["Hello","World"]); 3124 * @result alert('Hello World') // One for each paragraph 3125 * 3126 * @name trigger 3127 * @type jQuery 3128 * @param String type An event type to trigger. 3129 * @param Array data (optional) Additional data to pass as arguments (after the event object) to the event handler 3130 * @cat Events 3131 */ 3132 trigger: function( type, data ) { 3133 return this.each(function(){ 3134 jQuery.event.trigger( type, data, this ); 3135 }); 3136 }, 3137 3138 /** 3139 * Toggle between two function calls every other click. 3140 * Whenever a matched element is clicked, the first specified function 3141 * is fired, when clicked again, the second is fired. All subsequent 3142 * clicks continue to rotate through the two functions. 3143 * 3144 * Use unbind("click") to remove. 3145 * 3146 * @example $("p").toggle(function(){ 3147 * $(this).addClass("selected"); 3148 * },function(){ 3149 * $(this).removeClass("selected"); 3150 * }); 3151 * 3152 * @name toggle 3153 * @type jQuery 3154 * @param Function even The function to execute on every even click. 3155 * @param Function odd The function to execute on every odd click. 3156 * @cat Events 3157 */ 3158 toggle: function() { 3159 // Save reference to arguments for access in closure 3160 var a = arguments; 3161 3162 return this.click(function(e) { 3163 // Figure out which function to execute 3164 this.lastToggle = 0 == this.lastToggle ? 1 : 0; 3165 3166 // Make sure that clicks stop 3167 e.preventDefault(); 3168 3169 // and execute the function 3170 return a[this.lastToggle].apply( this, [e] ) || false; 3171 }); 3172 }, 3173 3174 /** 3175 * A method for simulating hovering (moving the mouse on, and off, 3176 * an object). This is a custom method which provides an 'in' to a 3177 * frequent task. 3178 * 3179 * Whenever the mouse cursor is moved over a matched 3180 * element, the first specified function is fired. Whenever the mouse 3181 * moves off of the element, the second specified function fires. 3182 * Additionally, checks are in place to see if the mouse is still within 3183 * the specified element itself (for example, an image inside of a div), 3184 * and if it is, it will continue to 'hover', and not move out 3185 * (a common error in using a mouseout event handler). 3186 * 3187 * @example $("p").hover(function(){ 3188 * $(this).addClass("hover"); 3189 * },function(){ 3190 * $(this).removeClass("hover"); 3191 * }); 3192 * 3193 * @name hover 3194 * @type jQuery 3195 * @param Function over The function to fire whenever the mouse is moved over a matched element. 3196 * @param Function out The function to fire whenever the mouse is moved off of a matched element. 3197 * @cat Events 3198 */ 3199 hover: function(f,g) { 3200 3201 // A private function for handling mouse 'hovering' 3202 function handleHover(e) { 3203 // Check if mouse(over|out) are still within the same parent element 3204 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; 3205 3206 // Traverse up the tree 3207 while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; }; 3208 3209 // If we actually just moused on to a sub-element, ignore it 3210 if ( p == this ) return false; 3211 3212 // Execute the right function 3213 return (e.type == "mouseover" ? f : g).apply(this, [e]); 3214 } 3215 3216 // Bind the function to the two event listeners 3217 return this.mouseover(handleHover).mouseout(handleHover); 3218 }, 3219 3220 /** 3221 * Bind a function to be executed whenever the DOM is ready to be 3222 * traversed and manipulated. This is probably the most important 3223 * function included in the event module, as it can greatly improve 3224 * the response times of your web applications. 3225 * 3226 * In a nutshell, this is a solid replacement for using window.onload, 3227 * and attaching a function to that. By using this method, your bound function 3228 * will be called the instant the DOM is ready to be read and manipulated, 3229 * which is when what 99.99% of all JavaScript code needs to run. 3230 * 3231 * There is one argument passed to the ready event handler: A reference to 3232 * the jQuery function. You can name that argument whatever you like, and 3233 * can therefore stick with the $ alias without risk of naming collisions. 3234 * 3235 * Please ensure you have no code in your <body> onload event handler, 3236 * otherwise $(document).ready() may not fire. 3237 * 3238 * You can have as many $(document).ready events on your page as you like. 3239 * The functions are then executed in the order they were added. 3240 * 3241 * @example $(document).ready(function(){ Your code here... }); 3242 * 3243 * @example jQuery(function($) { 3244 * // Your code using failsafe $ alias here... 3245 * }); 3246 * @desc Uses both the [[Core#.24.28_fn_.29|shortcut]] for $(document).ready() and the argument 3247 * to write failsafe jQuery code using the $ alias, without relying on the 3248 * global alias. 3249 * 3250 * @name ready 3251 * @type jQuery 3252 * @param Function fn The function to be executed when the DOM is ready. 3253 * @cat Events 3254 * @see $.noConflict() 3255 * @see $(Function) 3256 */ 3257 ready: function(f) { 3258 // If the DOM is already ready 3259 if ( jQuery.isReady ) 3260 // Execute the function immediately 3261 f.apply( document, [jQuery] ); 3262 3263 // Otherwise, remember the function for later 3264 else { 3265 // Add the function to the wait list 3266 jQuery.readyList.push( function() { return f.apply(this, [jQuery]) } ); 3267 } 3268 3269 return this; 3270 } 3271 }); 3272 3273 jQuery.extend({ 3274 /* 3275 * All the code that makes DOM Ready work nicely. 3276 */ 3277 isReady: false, 3278 readyList: [], 3279 3280 // Handle when the DOM is ready 3281 ready: function() { 3282 // Make sure that the DOM is not already loaded 3283 if ( !jQuery.isReady ) { 3284 // Remember that the DOM is ready 3285 jQuery.isReady = true; 3286 3287 // If there are functions bound, to execute 3288 if ( jQuery.readyList ) { 3289 // Execute all of them 3290 jQuery.each( jQuery.readyList, function(){ 3291 this.apply( document ); 3292 }); 3293 3294 // Reset the list of functions 3295 jQuery.readyList = null; 3296 } 3297 // Remove event lisenter to avoid memory leak 3298 if ( jQuery.browser.mozilla || jQuery.browser.opera ) 3299 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false ); 3300 3301 // Remove script element used by IE hack 3302 jQuery(window).load(function(){ jQuery("#__ie_init").remove(); }); 3303 } 3304 } 3305 }); 3306 3307 new function(){ 3308 3309 /** 3310 * Bind a function to the scroll event of each matched element. 3311 * 3312 * @example $("p").scroll( function() { alert("Hello"); } ); 3313 * @before <p>Hello</p> 3314 * @result <p onscroll="alert('Hello');">Hello</p> 3315 * 3316 * @name scroll 3317 * @type jQuery 3318 * @param Function fn A function to bind to the scroll event on each of the matched elements. 3319 * @cat Events 3320 */ 3321 3322 /** 3323 * Bind a function to the submit event of each matched element. 3324 * 3325 * @example $("#myform").submit( function() { 3326 * return $("input", this).val().length > 0; 3327 * } ); 3328 * @before <form id="myform"><input /></form> 3329 * @desc Prevents the form submission when the input has no value entered. 3330 * 3331 * @name submit 3332 * @type jQuery 3333 * @param Function fn A function to bind to the submit event on each of the matched elements. 3334 * @cat Events 3335 */ 3336 3337 /** 3338 * Trigger the submit event of each matched element. This causes all of the functions 3339 * that have been bound to that submit event to be executed, and calls the browser's 3340 * default submit action on the matching element(s). This default action can be prevented 3341 * by returning false from one of the functions bound to the submit event. 3342 * 3343 * Note: This does not execute the submit method of the form element! If you need to 3344 * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit(); 3345 * 3346 * @example $("form").submit(); 3347 * @desc Triggers all submit events registered to the matched form(s), and submits them. 3348 * 3349 * @name submit 3350 * @type jQuery 3351 * @cat Events 3352 */ 3353 3354 /** 3355 * Bind a function to the focus event of each matched element. 3356 * 3357 * @example $("p").focus( function() { alert("Hello"); } ); 3358 * @before <p>Hello</p> 3359 * @result <p onfocus="alert('Hello');">Hello</p> 3360 * 3361 * @name focus 3362 * @type jQuery 3363 * @param Function fn A function to bind to the focus event on each of the matched elements. 3364 * @cat Events 3365 */ 3366 3367 /** 3368 * Trigger the focus event of each matched element. This causes all of the functions 3369 * that have been bound to thet focus event to be executed. 3370 * 3371 * Note: This does not execute the focus method of the underlying elements! If you need to 3372 * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus(); 3373 * 3374 * @example $("p").focus(); 3375 * @before <p onfocus="alert('Hello');">Hello</p> 3376 * @result alert('Hello'); 3377 * 3378 * @name focus 3379 * @type jQuery 3380 * @cat Events 3381 */ 3382 3383 /** 3384 * Bind a function to the keydown event of each matched element. 3385 * 3386 * @example $("p").keydown( function() { alert("Hello"); } ); 3387 * @before <p>Hello</p> 3388 * @result <p onkeydown="alert('Hello');">Hello</p> 3389 * 3390 * @name keydown 3391 * @type jQuery 3392 * @param Function fn A function to bind to the keydown event on each of the matched elements. 3393 * @cat Events 3394 */ 3395 3396 /** 3397 * Bind a function to the dblclick event of each matched element. 3398 * 3399 * @example $("p").dblclick( function() { alert("Hello"); } ); 3400 * @before <p>Hello</p> 3401 * @result <p ondblclick="alert('Hello');">Hello</p> 3402 * 3403 * @name dblclick 3404 * @type jQuery 3405 * @param Function fn A function to bind to the dblclick event on each of the matched elements. 3406 * @cat Events 3407 */ 3408 3409 /** 3410 * Bind a function to the keypress event of each matched element. 3411 * 3412 * @example $("p").keypress( function() { alert("Hello"); } ); 3413 * @before <p>Hello</p> 3414 * @result <p onkeypress="alert('Hello');">Hello</p> 3415 * 3416 * @name keypress 3417 * @type jQuery 3418 * @param Function fn A function to bind to the keypress event on each of the matched elements. 3419 * @cat Events 3420 */ 3421 3422 /** 3423 * Bind a function to the error event of each matched element. 3424 * 3425 * @example $("p").error( function() { alert("Hello"); } ); 3426 * @before <p>Hello</p> 3427 * @result <p onerror="alert('Hello');">Hello</p> 3428 * 3429 * @name error 3430 * @type jQuery 3431 * @param Function fn A function to bind to the error event on each of the matched elements. 3432 * @cat Events 3433 */ 3434 3435 /** 3436 * Bind a function to the blur event of each matched element. 3437 * 3438 * @example $("p").blur( function() { alert("Hello"); } ); 3439 * @before <p>Hello</p> 3440 * @result <p onblur="alert('Hello');">Hello</p> 3441 * 3442 * @name blur 3443 * @type jQuery 3444 * @param Function fn A function to bind to the blur event on each of the matched elements. 3445 * @cat Events 3446 */ 3447 3448 /** 3449 * Trigger the blur event of each matched element. This causes all of the functions 3450 * that have been bound to that blur event to be executed, and calls the browser's 3451 * default blur action on the matching element(s). This default action can be prevented 3452 * by returning false from one of the functions bound to the blur event. 3453 * 3454 * Note: This does not execute the blur method of the underlying elements! If you need to 3455 * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur(); 3456 * 3457 * @example $("p").blur(); 3458 * @before <p onblur="alert('Hello');">Hello</p> 3459 * @result alert('Hello'); 3460 * 3461 * @name blur 3462 * @type jQuery 3463 * @cat Events 3464 */ 3465 3466 /** 3467 * Bind a function to the load event of each matched element. 3468 * 3469 * @example $("p").load( function() { alert("Hello"); } ); 3470 * @before <p>Hello</p> 3471 * @result <p onload="alert('Hello');">Hello</p> 3472 * 3473 * @name load 3474 * @type jQuery 3475 * @param Function fn A function to bind to the load event on each of the matched elements. 3476 * @cat Events 3477 */ 3478 3479 /** 3480 * Bind a function to the select event of each matched element. 3481 * 3482 * @example $("p").select( function() { alert("Hello"); } ); 3483 * @before <p>Hello</p> 3484 * @result <p onselect="alert('Hello');">Hello</p> 3485 * 3486 * @name select 3487 * @type jQuery 3488 * @param Function fn A function to bind to the select event on each of the matched elements. 3489 * @cat Events 3490 */ 3491 3492 /** 3493 * Trigger the select event of each matched element. This causes all of the functions 3494 * that have been bound to that select event to be executed, and calls the browser's 3495 * default select action on the matching element(s). This default action can be prevented 3496 * by returning false from one of the functions bound to the select event. 3497 * 3498 * @example $("p").select(); 3499 * @before <p onselect="alert('Hello');">Hello</p> 3500 * @result alert('Hello'); 3501 * 3502 * @name select 3503 * @type jQuery 3504 * @cat Events 3505 */ 3506 3507 /** 3508 * Bind a function to the mouseup event of each matched element. 3509 * 3510 * @example $("p").mouseup( function() { alert("Hello"); } ); 3511 * @before <p>Hello</p> 3512 * @result <p onmouseup="alert('Hello');">Hello</p> 3513 * 3514 * @name mouseup 3515 * @type jQuery 3516 * @param Function fn A function to bind to the mouseup event on each of the matched elements. 3517 * @cat Events 3518 */ 3519 3520 /** 3521 * Bind a function to the unload event of each matched element. 3522 * 3523 * @example $("p").unload( function() { alert("Hello"); } ); 3524 * @before <p>Hello</p> 3525 * @result <p onunload="alert('Hello');">Hello</p> 3526 * 3527 * @name unload 3528 * @type jQuery 3529 * @param Function fn A function to bind to the unload event on each of the matched elements. 3530 * @cat Events 3531 */ 3532 3533 /** 3534 * Bind a function to the change event of each matched element. 3535 * 3536 * @example $("p").change( function() { alert("Hello"); } ); 3537 * @before <p>Hello</p> 3538 * @result <p onchange="alert('Hello');">Hello</p> 3539 * 3540 * @name change 3541 * @type jQuery 3542 * @param Function fn A function to bind to the change event on each of the matched elements. 3543 * @cat Events 3544 */ 3545 3546 /** 3547 * Bind a function to the mouseout event of each matched element. 3548 * 3549 * @example $("p").mouseout( function() { alert("Hello"); } ); 3550 * @before <p>Hello</p> 3551 * @result <p onmouseout="alert('Hello');">Hello</p> 3552 * 3553 * @name mouseout 3554 * @type jQuery 3555 * @param Function fn A function to bind to the mouseout event on each of the matched elements. 3556 * @cat Events 3557 */ 3558 3559 /** 3560 * Bind a function to the keyup event of each matched element. 3561 * 3562 * @example $("p").keyup( function() { alert("Hello"); } ); 3563 * @before <p>Hello</p> 3564 * @result <p onkeyup="alert('Hello');">Hello</p> 3565 * 3566 * @name keyup 3567 * @type jQuery 3568 * @param Function fn A function to bind to the keyup event on each of the matched elements. 3569 * @cat Events 3570 */ 3571 3572 /** 3573 * Bind a function to the click event of each matched element. 3574 * 3575 * @example $("p").click( function() { alert("Hello"); } ); 3576 * @before <p>Hello</p> 3577 * @result <p onclick="alert('Hello');">Hello</p> 3578 * 3579 * @name click 3580 * @type jQuery 3581 * @param Function fn A function to bind to the click event on each of the matched elements. 3582 * @cat Events 3583 */ 3584 3585 /** 3586 * Trigger the click event of each matched element. This causes all of the functions 3587 * that have been bound to thet click event to be executed. 3588 * 3589 * @example $("p").click(); 3590 * @before <p onclick="alert('Hello');">Hello</p> 3591 * @result alert('Hello'); 3592 * 3593 * @name click 3594 * @type jQuery 3595 * @cat Events 3596 */ 3597 3598 /** 3599 * Bind a function to the resize event of each matched element. 3600 * 3601 * @example $("p").resize( function() { alert("Hello"); } ); 3602 * @before <p>Hello</p> 3603 * @result <p onresize="alert('Hello');">Hello</p> 3604 * 3605 * @name resize 3606 * @type jQuery 3607 * @param Function fn A function to bind to the resize event on each of the matched elements. 3608 * @cat Events 3609 */ 3610 3611 /** 3612 * Bind a function to the mousemove event of each matched element. 3613 * 3614 * @example $("p").mousemove( function() { alert("Hello"); } ); 3615 * @before <p>Hello</p> 3616 * @result <p onmousemove="alert('Hello');">Hello</p> 3617 * 3618 * @name mousemove 3619 * @type jQuery 3620 * @param Function fn A function to bind to the mousemove event on each of the matched elements. 3621 * @cat Events 3622 */ 3623 3624 /** 3625 * Bind a function to the mousedown event of each matched element. 3626 * 3627 * @example $("p").mousedown( function() { alert("Hello"); } ); 3628 * @before <p>Hello</p> 3629 * @result <p onmousedown="alert('Hello');">Hello</p> 3630 * 3631 * @name mousedown 3632 * @type jQuery 3633 * @param Function fn A function to bind to the mousedown event on each of the matched elements. 3634 * @cat Events 3635 */ 3636 3637 /** 3638 * Bind a function to the mouseover event of each matched element. 3639 * 3640 * @example $("p").mouseover( function() { alert("Hello"); } ); 3641 * @before <p>Hello</p> 3642 * @result <p onmouseover="alert('Hello');">Hello</p> 3643 * 3644 * @name mouseover 3645 * @type jQuery 3646 * @param Function fn A function to bind to the mousedown event on each of the matched elements. 3647 * @cat Events 3648 */ 3649 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + 3650 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + 3651 "submit,keydown,keypress,keyup,error").split(","), function(i,o){ 3652 3653 // Handle event binding 3654 jQuery.fn[o] = function(f){ 3655 return f ? this.bind(o, f) : this.trigger(o); 3656 }; 3657 3658 }); 3659 3660 // If Mozilla is used 3661 if ( jQuery.browser.mozilla || jQuery.browser.opera ) 3662 // Use the handy event callback 3663 document.addEventListener( "DOMContentLoaded", jQuery.ready, false ); 3664 3665 // If IE is used, use the excellent hack by Matthias Miller 3666 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited 3667 else if ( jQuery.browser.msie ) { 3668 3669 // Only works if you document.write() it 3670 document.write("<scr" + "ipt id=__ie_init defer=true " + 3671 "src=//:><\/script>"); 3672 3673 // Use the defer script hack 3674 var script = document.getElementById("__ie_init"); 3675 3676 // script does not exist if jQuery is loaded dynamically 3677 if ( script ) 3678 script.onreadystatechange = function() { 3679 if ( this.readyState != "complete" ) return; 3680 jQuery.ready(); 3681 }; 3682 3683 // Clear from memory 3684 script = null; 3685 3686 // If Safari is used 3687 } else if ( jQuery.browser.safari ) 3688 // Continually check to see if the document.readyState is valid 3689 jQuery.safariTimer = setInterval(function(){ 3690 // loaded and complete are both valid states 3691 if ( document.readyState == "loaded" || 3692 document.readyState == "complete" ) { 3693 3694 // If either one are found, remove the timer 3695 clearInterval( jQuery.safariTimer ); 3696 jQuery.safariTimer = null; 3697 3698 // and execute any waiting functions 3699 jQuery.ready(); 3700 } 3701 }, 10); 3702 3703 // A fallback to window.onload, that will always work 3704 jQuery.event.add( window, "load", jQuery.ready ); 3705 3706 }; 3707 3708 // Clean up after IE to avoid memory leaks 3709 if (jQuery.browser.msie) 3710 jQuery(window).one("unload", function() { 3711 var global = jQuery.event.global; 3712 for ( var type in global ) { 3713 var els = global[type], i = els.length; 3714 if ( i && type != 'unload' ) 3715 do 3716 jQuery.event.remove(els[i-1], type); 3717 while (--i); 3718 } 3719 }); 3720 jQuery.fn.extend({ 3721 3722 /** 3723 * Displays each of the set of matched elements if they are hidden. 3724 * 3725 * @example $("p").show() 3726 * @before <p style="display: none">Hello</p> 3727 * @result [ <p style="display: block">Hello</p> ] 3728 * 3729 * @name show 3730 * @type jQuery 3731 * @cat Effects 3732 */ 3733 3734 /** 3735 * Show all matched elements using a graceful animation and firing an 3736 * optional callback after completion. 3737 * 3738 * The height, width, and opacity of each of the matched elements 3739 * are changed dynamically according to the specified speed. 3740 * 3741 * @example $("p").show("slow"); 3742 * 3743 * @example $("p").show("slow",function(){ 3744 * alert("Animation Done."); 3745 * }); 3746 * 3747 * @name show 3748 * @type jQuery 3749 * @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). 3750 * @param Function callback (optional) A function to be executed whenever the animation completes. 3751 * @cat Effects 3752 * @see hide(String|Number,Function) 3753 */ 3754 show: function(speed,callback){ 3755 var hidden = this.filter(":hidden"); 3756 speed ? 3757 hidden.animate({ 3758 height: "show", width: "show", opacity: "show" 3759 }, speed, callback) : 3760 3761 hidden.each(function(){ 3762 this.style.display = this.oldblock ? this.oldblock : ""; 3763 if ( jQuery.css(this,"display") == "none" ) 3764 this.style.display = "block"; 3765 }); 3766 return this; 3767 }, 3768 3769 /** 3770 * Hides each of the set of matched elements if they are shown. 3771 * 3772 * @example $("p").hide() 3773 * @before <p>Hello</p> 3774 * @result [ <p style="display: none">Hello</p> ] 3775 * 3776 * @name hide 3777 * @type jQuery 3778 * @cat Effects 3779 */ 3780 3781 /** 3782 * Hide all matched elements using a graceful animation and firing an 3783 * optional callback after completion. 3784 * 3785 * The height, width, and opacity of each of the matched elements 3786 * are changed dynamically according to the specified speed. 3787 * 3788 * @example $("p").hide("slow"); 3789 * 3790 * @example $("p").hide("slow",function(){ 3791 * alert("Animation Done."); 3792 * }); 3793 * 3794 * @name hide 3795 * @type jQuery 3796 * @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). 3797 * @param Function callback (optional) A function to be executed whenever the animation completes. 3798 * @cat Effects 3799 * @see show(String|Number,Function) 3800 */ 3801 hide: function(speed,callback){ 3802 var visible = this.filter(":visible"); 3803 speed ? 3804 visible.animate({ 3805 height: "hide", width: "hide", opacity: "hide" 3806 }, speed, callback) : 3807 3808 visible.each(function(){ 3809 this.oldblock = this.oldblock || jQuery.css(this,"display"); 3810 if ( this.oldblock == "none" ) 3811 this.oldblock = "block"; 3812 this.style.display = "none"; 3813 }); 3814 return this; 3815 }, 3816 3817 // Save the old toggle function 3818 _toggle: jQuery.fn.toggle, 3819 3820 /** 3821 * Toggles each of the set of matched elements. If they are shown, 3822 * toggle makes them hidden. If they are hidden, toggle 3823 * makes them shown. 3824 * 3825 * @example $("p").toggle() 3826 * @before <p>Hello</p><p style="display: none">Hello Again</p> 3827 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ] 3828 * 3829 * @name toggle 3830 * @type jQuery 3831 * @cat Effects 3832 */ 3833 toggle: function( fn, fn2 ){ 3834 var args = arguments; 3835 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ? 3836 this._toggle( fn, fn2 ) : 3837 this.each(function(){ 3838 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ] 3839 .apply( jQuery(this), args ); 3840 }); 3841 }, 3842 3843 /** 3844 * Reveal all matched elements by adjusting their height and firing an 3845 * optional callback after completion. 3846 * 3847 * Only the height is adjusted for this animation, causing all matched 3848 * elements to be revealed in a "sliding" manner. 3849 * 3850 * @example $("p").slideDown("slow"); 3851 * 3852 * @example $("p").slideDown("slow",function(){ 3853 * alert("Animation Done."); 3854 * }); 3855 * 3856 * @name slideDown 3857 * @type jQuery 3858 * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). 3859 * @param Function callback (optional) A function to be executed whenever the animation completes. 3860 * @cat Effects 3861 * @see slideUp(String|Number,Function) 3862 * @see slideToggle(String|Number,Function) 3863 */ 3864 slideDown: function(speed,callback){ 3865 return this.filter(":hidden").animate({height: "show"}, speed, callback).end(); 3866 }, 3867 3868 /** 3869 * Hide all matched elements by adjusting their height and firing an 3870 * optional callback after completion. 3871 * 3872 * Only the height is adjusted for this animation, causing all matched 3873 * elements to be hidden in a "sliding" manner. 3874 * 3875 * @example $("p").slideUp("slow"); 3876 * 3877 * @example $("p").slideUp("slow",function(){ 3878 * alert("Animation Done."); 3879 * }); 3880 * 3881 * @name slideUp 3882 * @type jQuery 3883 * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). 3884 * @param Function callback (optional) A function to be executed whenever the animation completes. 3885 * @cat Effects 3886 * @see slideDown(String|Number,Function) 3887 * @see slideToggle(String|Number,Function) 3888 */ 3889 slideUp: function(speed,callback){ 3890 return this.filter(":visible").animate({height: "hide"}, speed, callback).end(); 3891 }, 3892 3893 /** 3894 * Toggle the visibility of all matched elements by adjusting their height and firing an 3895 * optional callback after completion. 3896 * 3897 * Only the height is adjusted for this animation, causing all matched 3898 * elements to be hidden in a "sliding" manner. 3899 * 3900 * @example $("p").slideToggle("slow"); 3901 * 3902 * @example $("p").slideToggle("slow",function(){ 3903 * alert("Animation Done."); 3904 * }); 3905 * 3906 * @name slideToggle 3907 * @type jQuery 3908 * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). 3909 * @param Function callback (optional) A function to be executed whenever the animation completes. 3910 * @cat Effects 3911 * @see slideDown(String|Number,Function) 3912 * @see slideUp(String|Number,Function) 3913 */ 3914 slideToggle: function(speed, callback){ 3915 return this.each(function(){ 3916 var state = jQuery(this).is(":hidden") ? "show" : "hide"; 3917 jQuery(this).animate({height: state}, speed, callback); 3918 }); 3919 }, 3920 3921 /** 3922 * Fade in all matched elements by adjusting their opacity and firing an 3923 * optional callback after completion. 3924 * 3925 * Only the opacity is adjusted for this animation, meaning that 3926 * all of the matched elements should already have some form of height 3927 * and width associated with them. 3928 * 3929 * @example $("p").fadeIn("slow"); 3930 * 3931 * @example $("p").fadeIn("slow",function(){ 3932 * alert("Animation Done."); 3933 * }); 3934 * 3935 * @name fadeIn 3936 * @type jQuery 3937 * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). 3938 * @param Function callback (optional) A function to be executed whenever the animation completes. 3939 * @cat Effects 3940 * @see fadeOut(String|Number,Function) 3941 * @see fadeTo(String|Number,Number,Function) 3942 */ 3943 fadeIn: function(speed, callback){ 3944 return this.filter(":hidden").animate({opacity: "show"}, speed, callback).end(); 3945 }, 3946 3947 /** 3948 * Fade out all matched elements by adjusting their opacity and firing an 3949 * optional callback after completion. 3950 * 3951 * Only the opacity is adjusted for this animation, meaning that 3952 * all of the matched elements should already have some form of height 3953 * and width associated with them. 3954 * 3955 * @example $("p").fadeOut("slow"); 3956 * 3957 * @example $("p").fadeOut("slow",function(){ 3958 * alert("Animation Done."); 3959 * }); 3960 * 3961 * @name fadeOut 3962 * @type jQuery 3963 * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). 3964 * @param Function callback (optional) A function to be executed whenever the animation completes. 3965 * @cat Effects 3966 * @see fadeIn(String|Number,Function) 3967 * @see fadeTo(String|Number,Number,Function) 3968 */ 3969 fadeOut: function(speed, callback){ 3970 return this.filter(":visible").animate({opacity: "hide"}, speed, callback).end(); 3971 }, 3972 3973 /** 3974 * Fade the opacity of all matched elements to a specified opacity and firing an 3975 * optional callback after completion. 3976 * 3977 * Only the opacity is adjusted for this animation, meaning that 3978 * all of the matched elements should already have some form of height 3979 * and width associated with them. 3980 * 3981 * @example $("p").fadeTo("slow", 0.5); 3982 * 3983 * @example $("p").fadeTo("slow", 0.5, function(){ 3984 * alert("Animation Done."); 3985 * }); 3986 * 3987 * @name fadeTo 3988 * @type jQuery 3989 * @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). 3990 * @param Number opacity The opacity to fade to (a number from 0 to 1). 3991 * @param Function callback (optional) A function to be executed whenever the animation completes. 3992 * @cat Effects 3993 * @see fadeIn(String|Number,Function) 3994 * @see fadeOut(String|Number,Function) 3995 */ 3996 fadeTo: function(speed,to,callback){ 3997 return this.animate({opacity: to}, speed, callback); 3998 }, 3999 4000 /** 4001 * A function for making your own, custom animations. The key aspect of 4002 * this function is the object of style properties that will be animated, 4003 * and to what end. Each key within the object represents a style property 4004 * that will also be animated (for example: "height", "top", or "opacity"). 4005 * 4006 * Note that properties should be specified using camel case 4007 * eg. marginLeft instead of margin-left. 4008 * 4009 * The value associated with the key represents to what end the property 4010 * will be animated. If a number is provided as the value, then the style 4011 * property will be transitioned from its current state to that new number. 4012 * Otherwise if the string "hide", "show", or "toggle" is provided, a default 4013 * animation will be constructed for that property. 4014 * 4015 * @example $("p").animate({ 4016 * height: 'toggle', opacity: 'toggle' 4017 * }, "slow"); 4018 * 4019 * @example $("p").animate({ 4020 * left: 50, opacity: 'show' 4021 * }, 500); 4022 * 4023 * @example $("p").animate({ 4024 * opacity: 'show' 4025 * }, "slow", "easein"); 4026 * @desc An example of using an 'easing' function to provide a different style of animation. This will only work if you have a plugin that provides this easing function (Only 'linear' is provided by default, with jQuery). 4027 * 4028 * @name animate 4029 * @type jQuery 4030 * @param Hash params A set of style attributes that you wish to animate, and to what end. 4031 * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). 4032 * @param String easing (optional) The name of the easing effect that you want to use (e.g. swing or linear). Defaults to "swing". 4033 * @param Function callback (optional) A function to be executed whenever the animation completes. 4034 * @cat Effects 4035 */ 4036 animate: function( prop, speed, easing, callback ) { 4037 return this.queue(function(){ 4038 4039 this.curAnim = jQuery.extend({}, prop); 4040 var opt = jQuery.speed(speed, easing, callback); 4041 4042 for ( var p in prop ) { 4043 var e = new jQuery.fx( this, opt, p ); 4044 if ( prop[p].constructor == Number ) 4045 e.custom( e.cur(), prop[p] ); 4046 else 4047 e[ prop[p] ]( prop ); 4048 } 4049 4050 }); 4051 }, 4052 4053 /** 4054 * 4055 * @private 4056 */ 4057 queue: function(type,fn){ 4058 if ( !fn ) { 4059 fn = type; 4060 type = "fx"; 4061 } 4062 4063 return this.each(function(){ 4064 if ( !this.queue ) 4065 this.queue = {}; 4066 4067 if ( !this.queue[type] ) 4068 this.queue[type] = []; 4069 4070 this.queue[type].push( fn ); 4071 4072 if ( this.queue[type].length == 1 ) 4073 fn.apply(this); 4074 }); 4075 } 4076 4077 }); 4078 4079 jQuery.extend({ 4080 4081 speed: function(speed, easing, fn) { 4082 var opt = speed && speed.constructor == Object ? speed : { 4083 complete: fn || !fn && easing || 4084 jQuery.isFunction( speed ) && speed, 4085 duration: speed, 4086 easing: fn && easing || easing && easing.constructor != Function && easing || "swing" 4087 }; 4088 4089 opt.duration = (opt.duration && opt.duration.constructor == Number ? 4090 opt.duration : 4091 { slow: 600, fast: 200 }[opt.duration]) || 400; 4092 4093 // Queueing 4094 opt.old = opt.complete; 4095 opt.complete = function(){ 4096 jQuery.dequeue(this, "fx"); 4097 if ( jQuery.isFunction( opt.old ) ) 4098 opt.old.apply( this ); 4099 }; 4100 4101 return opt; 4102 }, 4103 4104 easing: { 4105 linear: function( p, n, firstNum, diff ) { 4106 return firstNum + diff * p; 4107 }, 4108 swing: function( p, n, firstNum, diff ) { 4109 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum; 4110 } 4111 }, 4112 4113 queue: {}, 4114 4115 dequeue: function(elem,type){ 4116 type = type || "fx"; 4117 4118 if ( elem.queue && elem.queue[type] ) { 4119 // Remove self 4120 elem.queue[type].shift(); 4121 4122 // Get next function 4123 var f = elem.queue[type][0]; 4124 4125 if ( f ) f.apply( elem ); 4126 } 4127 }, 4128 4129 timers: [], 4130 4131 /* 4132 * I originally wrote fx() as a clone of moo.fx and in the process 4133 * of making it small in size the code became illegible to sane 4134 * people. You've been warned. 4135 */ 4136 4137 fx: function( elem, options, prop ){ 4138 4139 var z = this; 4140 4141 // The styles 4142 var y = elem.style; 4143 4144 if ( prop == "height" || prop == "width" ) { 4145 // Store display property 4146 var oldDisplay = jQuery.css(elem, "display"); 4147 4148 // Make sure that nothing sneaks out 4149 var oldOverflow = y.overflow; 4150 y.overflow = "hidden"; 4151 } 4152 4153 // Simple function for setting a style value 4154 z.a = function(){ 4155 if ( options.step ) 4156 options.step.apply( elem, [ z.now ] ); 4157 4158 if ( prop == "opacity" ) 4159 jQuery.attr(y, "opacity", z.now); // Let attr handle opacity 4160 else { 4161 y[prop] = parseInt(z.now) + "px"; 4162 y.display = "block"; // Set display property to block for animation 4163 } 4164 }; 4165 4166 // Figure out the maximum number to run to 4167 z.max = function(){ 4168 return parseFloat( jQuery.css(elem,prop) ); 4169 }; 4170 4171 // Get the current size 4172 z.cur = function(){ 4173 var r = parseFloat( jQuery.curCSS(elem, prop) ); 4174 return r && r > -10000 ? r : z.max(); 4175 }; 4176 4177 // Start an animation from one number to another 4178 z.custom = function(from,to){ 4179 z.startTime = (new Date()).getTime(); 4180 z.now = from; 4181 z.a(); 4182 4183 jQuery.timers.push(function(){ 4184 return z.step(from, to); 4185 }); 4186 4187 if ( jQuery.timers.length == 1 ) { 4188 var timer = setInterval(function(){ 4189 jQuery.timers = jQuery.grep( jQuery.timers, function(fn){ 4190 return fn(); 4191 }); 4192 4193 if ( !jQuery.timers.length ) 4194 clearInterval( timer ); 4195 }, 13); 4196 } 4197 }; 4198 4199 // Simple 'show' function 4200 z.show = function(){ 4201 if ( !elem.orig ) elem.orig = {}; 4202 4203 // Remember where we started, so that we can go back to it later 4204 elem.orig[prop] = jQuery.attr( elem.style, prop ); 4205 4206 options.show = true; 4207 4208 // Begin the animation 4209 z.custom(0, this.cur()); 4210 4211 // Stupid IE, look what you made me do 4212 if ( prop != "opacity" ) 4213 y[prop] = "1px"; 4214 }; 4215 4216 // Simple 'hide' function 4217 z.hide = function(){ 4218 if ( !elem.orig ) elem.orig = {}; 4219 4220 // Remember where we started, so that we can go back to it later 4221 elem.orig[prop] = jQuery.attr( elem.style, prop ); 4222 4223 options.hide = true; 4224 4225 // Begin the animation 4226 z.custom(this.cur(), 0); 4227 }; 4228 4229 //Simple 'toggle' function 4230 z.toggle = function() { 4231 if ( !elem.orig ) elem.orig = {}; 4232 4233 // Remember where we started, so that we can go back to it later 4234 elem.orig[prop] = jQuery.attr( elem.style, prop ); 4235 4236 if(oldDisplay == "none") { 4237 options.show = true; 4238 4239 // Stupid IE, look what you made me do 4240 if ( prop != "opacity" ) 4241 y[prop] = "1px"; 4242 4243 // Begin the animation 4244 z.custom(0, this.cur()); 4245 } else { 4246 options.hide = true; 4247 4248 // Begin the animation 4249 z.custom(this.cur(), 0); 4250 } 4251 }; 4252 4253 // Each step of an animation 4254 z.step = function(firstNum, lastNum){ 4255 var t = (new Date()).getTime(); 4256 4257 if (t > options.duration + z.startTime) { 4258 z.now = lastNum; 4259 z.a(); 4260 4261 if (elem.curAnim) elem.curAnim[ prop ] = true; 4262 4263 var done = true; 4264 for ( var i in elem.curAnim ) 4265 if ( elem.curAnim[i] !== true ) 4266 done = false; 4267 4268 if ( done ) { 4269 if ( oldDisplay ) { 4270 // Reset the overflow 4271 y.overflow = oldOverflow; 4272 4273 // Reset the display 4274 y.display = oldDisplay; 4275 if (jQuery.css(elem, "display") == "none") 4276 y.display = "block"; 4277 } 4278 4279 // Hide the element if the "hide" operation was done 4280 if ( options.hide ) 4281 y.display = "none"; 4282 4283 // Reset the properties, if the item has been hidden or shown 4284 if ( options.hide || options.show ) 4285 for ( var p in elem.curAnim ) 4286 jQuery.attr(y, p, elem.orig[p]); 4287 } 4288 4289 // If a callback was provided, execute it 4290 if ( done && jQuery.isFunction( options.complete ) ) 4291 // Execute the complete function 4292 options.complete.apply( elem ); 4293 4294 return false; 4295 } else { 4296 var n = t - this.startTime; 4297 // Figure out where in the animation we are and set the number 4298 var p = n / options.duration; 4299 4300 // Perform the easing function, defaults to swing 4301 z.now = jQuery.easing[options.easing](p, n, firstNum, (lastNum-firstNum), options.duration); 4302 4303 // Perform the next step of the animation 4304 z.a(); 4305 } 4306 4307 return true; 4308 }; 4309 4310 } 4311 }); 4312 jQuery.fn.extend({ 4313 4314 /** 4315 * Load HTML from a remote file and inject it into the DOM, only if it's 4316 * been modified by the server. 4317 * 4318 * @example $("#feeds").loadIfModified("feeds.html"); 4319 * @before <div id="feeds"></div> 4320 * @result <div id="feeds"><b>45</b> feeds found.</div> 4321 * 4322 * @name loadIfModified 4323 * @type jQuery 4324 * @param String url The URL of the HTML file to load. 4325 * @param Map params (optional) Key/value pairs that will be sent to the server. 4326 * @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself). 4327 * @cat Ajax 4328 */ 4329 loadIfModified: function( url, params, callback ) { 4330 this.load( url, params, callback, 1 ); 4331 }, 4332 4333 /** 4334 * Load HTML from a remote file and inject it into the DOM. 4335 * 4336 * Note: Avoid to use this to load scripts, instead use $.getScript. 4337 * IE strips script tags when there aren't any other characters in front of it. 4338 * 4339 * @example $("#feeds").load("feeds.html"); 4340 * @before <div id="feeds"></div> 4341 * @result <div id="feeds"><b>45</b> feeds found.</div> 4342 * 4343 * @example $("#feeds").load("feeds.html", 4344 * {limit: 25}, 4345 * function() { alert("The last 25 entries in the feed have been loaded"); } 4346 * ); 4347 * @desc Same as above, but with an additional parameter 4348 * and a callback that is executed when the data was loaded. 4349 * 4350 * @name load 4351 * @type jQuery 4352 * @param String url The URL of the HTML file to load. 4353 * @param Object params (optional) A set of key/value pairs that will be sent as data to the server. 4354 * @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself). 4355 * @cat Ajax 4356 */ 4357 load: function( url, params, callback, ifModified ) { 4358 if ( jQuery.isFunction( url ) ) 4359 return this.bind("load", url); 4360 4361 callback = callback || function(){}; 4362 4363 // Default to a GET request 4364 var type = "GET"; 4365 4366 // If the second parameter was provided 4367 if ( params ) 4368 // If it's a function 4369 if ( jQuery.isFunction( params ) ) { 4370 // We assume that it's the callback 4371 callback = params; 4372 params = null; 4373 4374 // Otherwise, build a param string 4375 } else { 4376 params = jQuery.param( params ); 4377 type = "POST"; 4378 } 4379 4380 var self = this; 4381 4382 // Request the remote document 4383 jQuery.ajax({ 4384 url: url, 4385 type: type, 4386 data: params, 4387 ifModified: ifModified, 4388 complete: function(res, status){ 4389 if ( status == "success" || !ifModified && status == "notmodified" ) 4390 // Inject the HTML into all the matched elements 4391 self.attr("innerHTML", res.responseText) 4392 // Execute all the scripts inside of the newly-injected HTML 4393 .evalScripts() 4394 // Execute callback 4395 .each( callback, [res.responseText, status, res] ); 4396 else 4397 callback.apply( self, [res.responseText, status, res] ); 4398 } 4399 }); 4400 return this; 4401 }, 4402 4403 /** 4404 * Serializes a set of input elements into a string of data. 4405 * This will serialize all given elements. 4406 * 4407 * A serialization similar to the form submit of a browser is 4408 * provided by the [http://www.malsup.com/jquery/form/ Form Plugin]. 4409 * It also takes multiple-selects 4410 * into account, while this method recognizes only a single option. 4411 * 4412 * @example $("input[@type=text]").serialize(); 4413 * @before <input type='text' name='name' value='John'/> 4414 * <input type='text' name='location' value='Boston'/> 4415 * @after name=John&location=Boston 4416 * @desc Serialize a selection of input elements to a string 4417 * 4418 * @name serialize 4419 * @type String 4420 * @cat Ajax 4421 */ 4422 serialize: function() { 4423 return jQuery.param( this ); 4424 }, 4425 4426 /** 4427 * Evaluate all script tags inside this jQuery. If they have a src attribute, 4428 * the script is loaded, otherwise it's content is evaluated. 4429 * 4430 * @name evalScripts 4431 * @type jQuery 4432 * @private 4433 * @cat Ajax 4434 */ 4435 evalScripts: function() { 4436 return this.find("script").each(function(){ 4437 if ( this.src ) 4438 jQuery.getScript( this.src ); 4439 else 4440 jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" ); 4441 }).end(); 4442 } 4443 4444 }); 4445 4446 // Attach a bunch of functions for handling common AJAX events 4447 4448 /** 4449 * Attach a function to be executed whenever an AJAX request begins 4450 * and there is none already active. 4451 * 4452 * @example $("#loading").ajaxStart(function(){ 4453 * $(this).show(); 4454 * }); 4455 * @desc Show a loading message whenever an AJAX request starts 4456 * (and none is already active). 4457 * 4458 * @name ajaxStart 4459 * @type jQuery 4460 * @param Function callback The function to execute. 4461 * @cat Ajax 4462 */ 4463 4464 /** 4465 * Attach a function to be executed whenever all AJAX requests have ended. 4466 * 4467 * @example $("#loading").ajaxStop(function(){ 4468 * $(this).hide(); 4469 * }); 4470 * @desc Hide a loading message after all the AJAX requests have stopped. 4471 * 4472 * @name ajaxStop 4473 * @type jQuery 4474 * @param Function callback The function to execute. 4475 * @cat Ajax 4476 */ 4477 4478 /** 4479 * Attach a function to be executed whenever an AJAX request completes. 4480 * 4481 * The XMLHttpRequest and settings used for that request are passed 4482 * as arguments to the callback. 4483 * 4484 * @example $("#msg").ajaxComplete(function(request, settings){ 4485 * $(this).append("<li>Request Complete.</li>"); 4486 * }); 4487 * @desc Show a message when an AJAX request completes. 4488 * 4489 * @name ajaxComplete 4490 * @type jQuery 4491 * @param Function callback The function to execute. 4492 * @cat Ajax 4493 */ 4494 4495 /** 4496 * Attach a function to be executed whenever an AJAX request completes 4497 * successfully. 4498 * 4499 * The XMLHttpRequest and settings used for that request are passed 4500 * as arguments to the callback. 4501 * 4502 * @example $("#msg").ajaxSuccess(function(request, settings){ 4503 * $(this).append("<li>Successful Request!</li>"); 4504 * }); 4505 * @desc Show a message when an AJAX request completes successfully. 4506 * 4507 * @name ajaxSuccess 4508 * @type jQuery 4509 * @param Function callback The function to execute. 4510 * @cat Ajax 4511 */ 4512 4513 /** 4514 * Attach a function to be executed whenever an AJAX request fails. 4515 * 4516 * The XMLHttpRequest and settings used for that request are passed 4517 * as arguments to the callback. A third argument, an exception object, 4518 * is passed if an exception occured while processing the request. 4519 * 4520 * @example $("#msg").ajaxError(function(request, settings){ 4521 * $(this).append("<li>Error requesting page " + settings.url + "</li>"); 4522 * }); 4523 * @desc Show a message when an AJAX request fails. 4524 * 4525 * @name ajaxError 4526 * @type jQuery 4527 * @param Function callback The function to execute. 4528 * @cat Ajax 4529 */ 4530 4531 /** 4532 * Attach a function to be executed before an AJAX request is sent. 4533 * 4534 * The XMLHttpRequest and settings used for that request are passed 4535 * as arguments to the callback. 4536 * 4537 * @example $("#msg").ajaxSend(function(request, settings){ 4538 * $(this).append("<li>Starting request at " + settings.url + "</li>"); 4539 * }); 4540 * @desc Show a message before an AJAX request is sent. 4541 * 4542 * @name ajaxSend 4543 * @type jQuery 4544 * @param Function callback The function to execute. 4545 * @cat Ajax 4546 */ 4547 jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){ 4548 jQuery.fn[o] = function(f){ 4549 return this.bind(o, f); 4550 }; 4551 }); 4552 4553 jQuery.extend({ 4554 4555 /** 4556 * Load a remote page using an HTTP GET request. 4557 * 4558 * This is an easy way to send a simple GET request to a server 4559 * without having to use the more complex $.ajax function. It 4560 * allows a single callback function to be specified that will 4561 * be executed when the request is complete (and only if the response 4562 * has a successful response code). If you need to have both error 4563 * and success callbacks, you may want to use $.ajax. 4564 * 4565 * @example $.get("test.cgi"); 4566 * 4567 * @example $.get("test.cgi", { name: "John", time: "2pm" } ); 4568 * 4569 * @example $.get("test.cgi", function(data){ 4570 * alert("Data Loaded: " + data); 4571 * }); 4572 * 4573 * @example $.get("test.cgi", 4574 * { name: "John", time: "2pm" }, 4575 * function(data){ 4576 * alert("Data Loaded: " + data); 4577 * } 4578 * ); 4579 * 4580 * @name $.get 4581 * @type XMLHttpRequest 4582 * @param String url The URL of the page to load. 4583 * @param Map params (optional) Key/value pairs that will be sent to the server. 4584 * @param Function callback (optional) A function to be executed whenever the data is loaded successfully. 4585 * @cat Ajax 4586 */ 4587 get: function( url, data, callback, type, ifModified ) { 4588 // shift arguments if data argument was ommited 4589 if ( jQuery.isFunction( data ) ) { 4590 callback = data; 4591 data = null; 4592 } 4593 4594 return jQuery.ajax({ 4595 type: "GET", 4596 url: url, 4597 data: data, 4598 success: callback, 4599 dataType: type, 4600 ifModified: ifModified 4601 }); 4602 }, 4603 4604 /** 4605 * Load a remote page using an HTTP GET request, only if it hasn't 4606 * been modified since it was last retrieved. 4607 * 4608 * @example $.getIfModified("test.html"); 4609 * 4610 * @example $.getIfModified("test.html", { name: "John", time: "2pm" } ); 4611 * 4612 * @example $.getIfModified("test.cgi", function(data){ 4613 * alert("Data Loaded: " + data); 4614 * }); 4615 * 4616 * @example $.getifModified("test.cgi", 4617 * { name: "John", time: "2pm" }, 4618 * function(data){ 4619 * alert("Data Loaded: " + data); 4620 * } 4621 * ); 4622 * 4623 * @name $.getIfModified 4624 * @type XMLHttpRequest 4625 * @param String url The URL of the page to load. 4626 * @param Map params (optional) Key/value pairs that will be sent to the server. 4627 * @param Function callback (optional) A function to be executed whenever the data is loaded successfully. 4628 * @cat Ajax 4629 */ 4630 getIfModified: function( url, data, callback, type ) { 4631 return jQuery.get(url, data, callback, type, 1); 4632 }, 4633 4634 /** 4635 * Loads, and executes, a remote JavaScript file using an HTTP GET request. 4636 * 4637 * Warning: Safari <= 2.0.x is unable to evaluate scripts in a global 4638 * context synchronously. If you load functions via getScript, make sure 4639 * to call them after a delay. 4640 * 4641 * @example $.getScript("test.js"); 4642 * 4643 * @example $.getScript("test.js", function(){ 4644 * alert("Script loaded and executed."); 4645 * }); 4646 * 4647 * @name $.getScript 4648 * @type XMLHttpRequest 4649 * @param String url The URL of the page to load. 4650 * @param Function callback (optional) A function to be executed whenever the data is loaded successfully. 4651 * @cat Ajax 4652 */ 4653 getScript: function( url, callback ) { 4654 return jQuery.get(url, null, callback, "script"); 4655 }, 4656 4657 /** 4658 * Load JSON data using an HTTP GET request. 4659 * 4660 * @example $.getJSON("test.js", function(json){ 4661 * alert("JSON Data: " + json.users[3].name); 4662 * }); 4663 * 4664 * @example $.getJSON("test.js", 4665 * { name: "John", time: "2pm" }, 4666 * function(json){ 4667 * alert("JSON Data: " + json.users[3].name); 4668 * } 4669 * ); 4670 * 4671 * @name $.getJSON 4672 * @type XMLHttpRequest 4673 * @param String url The URL of the page to load. 4674 * @param Map params (optional) Key/value pairs that will be sent to the server. 4675 * @param Function callback A function to be executed whenever the data is loaded successfully. 4676 * @cat Ajax 4677 */ 4678 getJSON: function( url, data, callback ) { 4679 return jQuery.get(url, data, callback, "json"); 4680 }, 4681 4682 /** 4683 * Load a remote page using an HTTP POST request. 4684 * 4685 * @example $.post("test.cgi"); 4686 * 4687 * @example $.post("test.cgi", { name: "John", time: "2pm" } ); 4688 * 4689 * @example $.post("test.cgi", function(data){ 4690 * alert("Data Loaded: " + data); 4691 * }); 4692 * 4693 * @example $.post("test.cgi", 4694 * { name: "John", time: "2pm" }, 4695 * function(data){ 4696 * alert("Data Loaded: " + data); 4697 * } 4698 * ); 4699 * 4700 * @name $.post 4701 * @type XMLHttpRequest 4702 * @param String url The URL of the page to load. 4703 * @param Map params (optional) Key/value pairs that will be sent to the server. 4704 * @param Function callback (optional) A function to be executed whenever the data is loaded successfully. 4705 * @cat Ajax 4706 */ 4707 post: function( url, data, callback, type ) { 4708 if ( jQuery.isFunction( data ) ) { 4709 callback = data; 4710 data = {}; 4711 } 4712 4713 return jQuery.ajax({ 4714 type: "POST", 4715 url: url, 4716 data: data, 4717 success: callback, 4718 dataType: type 4719 }); 4720 }, 4721 4722 /** 4723 * Set the timeout in milliseconds of all AJAX requests to a specific amount of time. 4724 * This will make all future AJAX requests timeout after a specified amount 4725 * of time. 4726 * 4727 * Set to null or 0 to disable timeouts (default). 4728 * 4729 * You can manually abort requests with the XMLHttpRequest's (returned by 4730 * all ajax functions) abort() method. 4731 * 4732 * Deprecated. Use $.ajaxSetup instead. 4733 * 4734 * @example $.ajaxTimeout( 5000 ); 4735 * @desc Make all AJAX requests timeout after 5 seconds. 4736 * 4737 * @name $.ajaxTimeout 4738 * @type undefined 4739 * @param Number time How long before an AJAX request times out, in milliseconds. 4740 * @cat Ajax 4741 */ 4742 ajaxTimeout: function( timeout ) { 4743 jQuery.ajaxSettings.timeout = timeout; 4744 }, 4745 4746 /** 4747 * Setup global settings for AJAX requests. 4748 * 4749 * See $.ajax for a description of all available options. 4750 * 4751 * @example $.ajaxSetup( { 4752 * url: "/xmlhttp/", 4753 * global: false, 4754 * type: "POST" 4755 * } ); 4756 * $.ajax({ data: myData }); 4757 * @desc Sets the defaults for AJAX requests to the url "/xmlhttp/", 4758 * disables global handlers and uses POST instead of GET. The following 4759 * AJAX requests then sends some data without having to set anything else. 4760 * 4761 * @name $.ajaxSetup 4762 * @type undefined 4763 * @param Map settings Key/value pairs to use for all AJAX requests 4764 * @cat Ajax 4765 */ 4766 ajaxSetup: function( settings ) { 4767 jQuery.extend( jQuery.ajaxSettings, settings ); 4768 }, 4769 4770 ajaxSettings: { 4771 global: true, 4772 type: "GET", 4773 timeout: 0, 4774 contentType: "application/x-www-form-urlencoded", 4775 processData: true, 4776 async: true, 4777 data: null 4778 }, 4779 4780 // Last-Modified header cache for next request 4781 lastModified: {}, 4782 4783 /** 4784 * Load a remote page using an HTTP request. 4785 * 4786 * This is jQuery's low-level AJAX implementation. See $.get, $.post etc. for 4787 * higher-level abstractions that are often easier to understand and use, 4788 * but don't offer as much functionality (such as error callbacks). 4789 * 4790 * $.ajax() returns the XMLHttpRequest that it creates. In most cases you won't 4791 * need that object to manipulate directly, but it is available if you need to 4792 * abort the request manually. 4793 * 4794 * '''Note:''' If you specify the dataType option described below, make sure 4795 * the server sends the correct MIME type in the response (eg. xml as "text/xml"). 4796 * Sending the wrong MIME type can lead to unexpected problems in your script. 4797 * See [[Specifying the Data Type for AJAX Requests]] for more information. 4798 * 4799 * Supported datatypes are (see dataType option): 4800 * 4801 * "xml": Returns a XML document that can be processed via jQuery. 4802 * 4803 * "html": Returns HTML as plain text, included script tags are evaluated. 4804 * 4805 * "script": Evaluates the response as Javascript and returns it as plain text. 4806 * 4807 * "json": Evaluates the response as JSON and returns a Javascript Object 4808 * 4809 * $.ajax() takes one argument, an object of key/value pairs, that are 4810 * used to initalize and handle the request. These are all the key/values that can 4811 * be used: 4812 * 4813 * (String) url - The URL to request. 4814 * 4815 * (String) type - The type of request to make ("POST" or "GET"), default is "GET". 4816 * 4817 * (String) dataType - The type of data that you're expecting back from 4818 * the server. No default: If the server sends xml, the responseXML, otherwise 4819 * the responseText is passed to the success callback. 4820 * 4821 * (Boolean) ifModified - Allow the request to be successful only if the 4822 * response has changed since the last request. This is done by checking the 4823 * Last-Modified header. Default value is false, ignoring the header. 4824 * 4825 * (Number) timeout - Local timeout in milliseconds to override global timeout, eg. to give a 4826 * single request a longer timeout while all others timeout after 1 second. 4827 * See $.ajaxTimeout() for global timeouts. 4828 * 4829 * (Boolean) global - Whether to trigger global AJAX event handlers for 4830 * this request, default is true. Set to false to prevent that global handlers 4831 * like ajaxStart or ajaxStop are triggered. 4832 * 4833 * (Function) error - A function to be called if the request fails. The 4834 * function gets passed tree arguments: The XMLHttpRequest object, a 4835 * string describing the type of error that occurred and an optional 4836 * exception object, if one occured. 4837 * 4838 * (Function) success - A function to be called if the request succeeds. The 4839 * function gets passed one argument: The data returned from the server, 4840 * formatted according to the 'dataType' parameter. 4841 * 4842 * (Function) complete - A function to be called when the request finishes. The 4843 * function gets passed two arguments: The XMLHttpRequest object and a 4844 * string describing the type of success of the request. 4845 * 4846 * (Object|String) data - Data to be sent to the server. Converted to a query 4847 * string, if not already a string. Is appended to the url for GET-requests. 4848 * See processData option to prevent this automatic processing. 4849 * 4850 * (String) contentType - When sending data to the server, use this content-type. 4851 * Default is "application/x-www-form-urlencoded", which is fine for most cases. 4852 * 4853 * (Boolean) processData - By default, data passed in to the data option as an object 4854 * other as string will be processed and transformed into a query string, fitting to 4855 * the default content-type "application/x-www-form-urlencoded". If you want to send 4856 * DOMDocuments, set this option to false. 4857 * 4858 * (Boolean) async - By default, all requests are sent asynchronous (set to true). 4859 * If you need synchronous requests, set this option to false. 4860 * 4861 * (Function) beforeSend - A pre-callback to set custom headers etc., the 4862 * XMLHttpRequest is passed as the only argument. 4863 * 4864 * @example $.ajax({ 4865 * type: "GET", 4866 * url: "test.js", 4867 * dataType: "script" 4868 * }) 4869 * @desc Load and execute a JavaScript file. 4870 * 4871 * @example $.ajax({ 4872 * type: "POST", 4873 * url: "some.php", 4874 * data: "name=John&location=Boston", 4875 * success: function(msg){ 4876 * alert( "Data Saved: " + msg ); 4877 * } 4878 * }); 4879 * @desc Save some data to the server and notify the user once its complete. 4880 * 4881 * @example var html = $.ajax({ 4882 * url: "some.php", 4883 * async: false 4884 * }).responseText; 4885 * @desc Loads data synchronously. Blocks the browser while the requests is active. 4886 * It is better to block user interaction by other means when synchronization is 4887 * necessary. 4888 * 4889 * @example var xmlDocument = [create xml document]; 4890 * $.ajax({ 4891 * url: "page.php", 4892 * processData: false, 4893 * data: xmlDocument, 4894 * success: handleResponse 4895 * }); 4896 * @desc Sends an xml document as data to the server. By setting the processData 4897 * option to false, the automatic conversion of data to strings is prevented. 4898 * 4899 * @name $.ajax 4900 * @type XMLHttpRequest 4901 * @param Map properties Key/value pairs to initialize the request with. 4902 * @cat Ajax 4903 * @see ajaxSetup(Map) 4904 */ 4905 ajax: function( s ) { 4906 // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout 4907 s = jQuery.extend({}, jQuery.ajaxSettings, s); 4908 4909 // if data available 4910 if ( s.data ) { 4911 // convert data if not already a string 4912 if (s.processData && typeof s.data != "string") 4913 s.data = jQuery.param(s.data); 4914 // append data to url for get requests 4915 if( s.type.toLowerCase() == "get" ) { 4916 // "?" + data or "&" + data (in case there are already params) 4917 s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data; 4918 // IE likes to send both get and post data, prevent this 4919 s.data = null; 4920 } 4921 } 4922 4923 // Watch for a new set of requests 4924 if ( s.global && ! jQuery.active++ ) 4925 jQuery.event.trigger( "ajaxStart" ); 4926 4927 var requestDone = false; 4928 4929 // Create the request object; Microsoft failed to properly 4930 // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available 4931 var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); 4932 4933 // Open the socket 4934 xml.open(s.type, s.url, s.async); 4935 4936 // Set the correct header, if data is being sent 4937 if ( s.data ) 4938 xml.setRequestHeader("Content-Type", s.contentType); 4939 4940 // Set the If-Modified-Since header, if ifModified mode. 4941 if ( s.ifModified ) 4942 xml.setRequestHeader("If-Modified-Since", 4943 jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" ); 4944 4945 // Set header so the called script knows that it's an XMLHttpRequest 4946 xml.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 4947 4948 // Allow custom headers/mimetypes 4949 if( s.beforeSend ) 4950 s.beforeSend(xml); 4951 4952 if ( s.global ) 4953 jQuery.event.trigger("ajaxSend", [xml, s]); 4954 4955 // Wait for a response to come back 4956 var onreadystatechange = function(isTimeout){ 4957 // The transfer is complete and the data is available, or the request timed out 4958 if ( xml && (xml.readyState == 4 || isTimeout == "timeout") ) { 4959 requestDone = true; 4960 4961 // clear poll interval 4962 if (ival) { 4963 clearInterval(ival); 4964 ival = null; 4965 } 4966 4967 var status; 4968 try { 4969 status = jQuery.httpSuccess( xml ) && isTimeout != "timeout" ? 4970 s.ifModified && jQuery.httpNotModified( xml, s.url ) ? "notmodified" : "success" : "error"; 4971 // Make sure that the request was successful or notmodified 4972 if ( status != "error" ) { 4973 // Cache Last-Modified header, if ifModified mode. 4974 var modRes; 4975 try { 4976 modRes = xml.getResponseHeader("Last-Modified"); 4977 } catch(e) {} // swallow exception thrown by FF if header is not available 4978 4979 if ( s.ifModified && modRes ) 4980 jQuery.lastModified[s.url] = modRes; 4981 4982 // process the data (runs the xml through httpData regardless of callback) 4983 var data = jQuery.httpData( xml, s.dataType ); 4984 4985 // If a local callback was specified, fire it and pass it the data 4986 if ( s.success ) 4987 s.success( data, status ); 4988 4989 // Fire the global callback 4990 if( s.global ) 4991 jQuery.event.trigger( "ajaxSuccess", [xml, s] ); 4992 } else 4993 jQuery.handleError(s, xml, status); 4994 } catch(e) { 4995 status = "error"; 4996 jQuery.handleError(s, xml, status, e); 4997 } 4998 4999 // The request was completed 5000 if( s.global ) 5001 jQuery.event.trigger( "ajaxComplete", [xml, s] ); 5002 5003 // Handle the global AJAX counter 5004 if ( s.global && ! --jQuery.active ) 5005 jQuery.event.trigger( "ajaxStop" ); 5006 5007 // Process result 5008 if ( s.complete ) 5009 s.complete(xml, status); 5010 5011 // Stop memory leaks 5012 if(s.async) 5013 xml = null; 5014 } 5015 }; 5016 5017 // don't attach the handler to the request, just poll it instead 5018 var ival = setInterval(onreadystatechange, 13); 5019 5020 // Timeout checker 5021 if ( s.timeout > 0 ) 5022 setTimeout(function(){ 5023 // Check to see if the request is still happening 5024 if ( xml ) { 5025 // Cancel the request 5026 xml.abort(); 5027 5028 if( !requestDone ) 5029 onreadystatechange( "timeout" ); 5030 } 5031 }, s.timeout); 5032 5033 // Send the data 5034 try { 5035 xml.send(s.data); 5036 } catch(e) { 5037 jQuery.handleError(s, xml, null, e); 5038 } 5039 5040 // firefox 1.5 doesn't fire statechange for sync requests 5041 if ( !s.async ) 5042 onreadystatechange(); 5043 5044 // return XMLHttpRequest to allow aborting the request etc. 5045 return xml; 5046 }, 5047 5048 handleError: function( s, xml, status, e ) { 5049 // If a local callback was specified, fire it 5050 if ( s.error ) s.error( xml, status, e ); 5051 5052 // Fire the global callback 5053 if ( s.global ) 5054 jQuery.event.trigger( "ajaxError", [xml, s, e] ); 5055 }, 5056 5057 // Counter for holding the number of active queries 5058 active: 0, 5059 5060 // Determines if an XMLHttpRequest was successful or not 5061 httpSuccess: function( r ) { 5062 try { 5063 return !r.status && location.protocol == "file:" || 5064 ( r.status >= 200 && r.status < 300 ) || r.status == 304 || 5065 jQuery.browser.safari && r.status == undefined; 5066 } catch(e){} 5067 return false; 5068 }, 5069 5070 // Determines if an XMLHttpRequest returns NotModified 5071 httpNotModified: function( xml, url ) { 5072 try { 5073 var xmlRes = xml.getResponseHeader("Last-Modified"); 5074 5075 // Firefox always returns 200. check Last-Modified date 5076 return xml.status == 304 || xmlRes == jQuery.lastModified[url] || 5077 jQuery.browser.safari && xml.status == undefined; 5078 } catch(e){} 5079 return false; 5080 }, 5081 5082 /* Get the data out of an XMLHttpRequest. 5083 * Return parsed XML if content-type header is "xml" and type is "xml" or omitted, 5084 * otherwise return plain text. 5085 * (String) data - The type of data that you're expecting back, 5086 * (e.g. "xml", "html", "script") 5087 */ 5088 httpData: function( r, type ) { 5089 var ct = r.getResponseHeader("content-type"); 5090 var data = !type && ct && ct.indexOf("xml") >= 0; 5091 data = type == "xml" || data ? r.responseXML : r.responseText; 5092 5093 // If the type is "script", eval it in global context 5094 if ( type == "script" ) 5095 jQuery.globalEval( data ); 5096 5097 // Get the JavaScript object, if JSON is used. 5098 if ( type == "json" ) 5099 eval( "data = " + data ); 5100 5101 // evaluate scripts within html 5102 if ( type == "html" ) 5103 jQuery("<div>").html(data).evalScripts(); 5104 5105 return data; 5106 }, 5107 5108 // Serialize an array of form elements or a set of 5109 // key/values into a query string 5110 param: function( a ) { 5111 var s = []; 5112 5113 // If an array was passed in, assume that it is an array 5114 // of form elements 5115 if ( a.constructor == Array || a.jquery ) 5116 // Serialize the form elements 5117 jQuery.each( a, function(){ 5118 s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) ); 5119 }); 5120 5121 // Otherwise, assume that it's an object of key/value pairs 5122 else 5123 // Serialize the key/values 5124 for ( var j in a ) 5125 // If the value is an array then the key names need to be repeated 5126 if ( a[j] && a[j].constructor == Array ) 5127 jQuery.each( a[j], function(){ 5128 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) ); 5129 }); 5130 else 5131 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) ); 5132 5133 // Return the resulting serialization 5134 return s.join("&"); 5135 }, 5136 5137 // evalulates a script in global context 5138 // not reliable for safari 5139 globalEval: function( data ) { 5140 if ( window.execScript ) 5141 window.execScript( data ); 5142 else if ( jQuery.browser.safari ) 5143 // safari doesn't provide a synchronous global eval 5144 window.setTimeout( data, 0 ); 5145 else 5146 eval.call( window, data ); 5147 } 5148 5149 }); 5150 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |