2 * jQuery @VERSION - New Wave Javascript
\r
4 * Copyright (c) 2007 John Resig (jquery.com)
\r
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
\r
6 * and GPL (GPL-LICENSE.txt) licenses.
\r
12 // Map over jQuery in case of overwrite
\r
13 if ( typeof jQuery != "undefined" )
\r
14 var _jQuery = jQuery;
\r
16 var jQuery = window.jQuery = function( selector, context ) {
\r
17 // If the context is a namespace object, return a new object
\r
18 return this instanceof jQuery ?
\r
19 this.init( selector, context ) :
\r
20 new jQuery( selector, context );
\r
23 // Map over the $ in case of overwrite
\r
24 if ( typeof $ != "undefined" )
\r
27 // Map the jQuery namespace to the '$' one
\r
30 // A simple way to check for HTML strings or ID strings
\r
31 // (both of which we optimize for)
\r
32 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
\r
34 jQuery.fn = jQuery.prototype = {
\r
35 init: function( selector, context ) {
\r
36 // Make sure that a selection was provided
\r
37 selector = selector || document;
\r
39 // Handle HTML strings
\r
40 if ( typeof selector == "string" ) {
\r
41 // Are we dealing with HTML string or an ID?
\r
42 var match = quickExpr.exec( selector );
\r
44 // Verify a match, and that no context was specified for #id
\r
45 if ( match && (match[1] || !context) ) {
\r
47 // HANDLE: $(html) -> $(array)
\r
49 selector = jQuery.clean( [ match[1] ], context );
\r
53 var elem = document.getElementById( match[3] );
\r
55 // Make sure an element was located
\r
57 // Handle the case where IE and Opera return items
\r
58 // by name instead of ID
\r
59 if ( elem.id != match[3] )
\r
60 return jQuery().find( selector );
\r
62 // Otherwise, we inject the element directly into the jQuery object
\r
73 // HANDLE: $(expr, [context])
\r
74 // (which is just equivalent to: $(content).find(expr)
\r
76 return new jQuery( context ).find( selector );
\r
78 // HANDLE: $(function)
\r
79 // Shortcut for document ready
\r
80 } else if ( jQuery.isFunction( selector ) )
\r
81 return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
\r
83 return this.setArray(
\r
85 selector.constructor == Array && selector ||
\r
87 // HANDLE: $(arraylike)
\r
88 // Watch for when an array-like object, contains DOM nodes, is passed in as the selector
\r
89 (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) ||
\r
95 // The current version of jQuery being used
\r
98 // The number of elements contained in the matched element set
\r
100 return this.length;
\r
103 // The number of elements contained in the matched element set
\r
106 // Get the Nth element in the matched element set OR
\r
107 // Get the whole matched element set as a clean array
\r
108 get: function( num ) {
\r
109 return num == undefined ?
\r
111 // Return a 'clean' array
\r
112 jQuery.makeArray( this ) :
\r
114 // Return just the object
\r
118 // Take an array of elements and push it onto the stack
\r
119 // (returning the new matched element set)
\r
120 pushStack: function( elems ) {
\r
121 // Build a new jQuery matched element set
\r
122 var ret = jQuery( elems );
\r
124 // Add the old object onto the stack (as a reference)
\r
125 ret.prevObject = this;
\r
127 // Return the newly-formed element set
\r
131 // Force the current matched set of elements to become
\r
132 // the specified array of elements (destroying the stack in the process)
\r
133 // You should use pushStack() in order to do this, but maintain the stack
\r
134 setArray: function( elems ) {
\r
135 // Resetting the length to 0, then using the native Array push
\r
136 // is a super-fast way to populate an object with array-like properties
\r
138 Array.prototype.push.apply( this, elems );
\r
143 // Execute a callback for every element in the matched set.
\r
144 // (You can seed the arguments with an array of args, but this is
\r
145 // only used internally.)
\r
146 each: function( callback, args ) {
\r
147 return jQuery.each( this, callback, args );
\r
150 // Determine the position of an element within
\r
151 // the matched set of elements
\r
152 index: function( elem ) {
\r
155 // Locate the position of the desired element
\r
156 this.each(function(i){
\r
157 if ( this == elem )
\r
164 attr: function( name, value, type ) {
\r
165 var options = name;
\r
167 // Look for the case where we're accessing a style value
\r
168 if ( name.constructor == String )
\r
169 if ( value == undefined )
\r
170 return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined;
\r
174 options[ name ] = value;
\r
177 // Check to see if we're setting style values
\r
178 return this.each(function(i){
\r
179 // Set all the styles
\r
180 for ( name in options )
\r
185 name, jQuery.prop( this, options[ name ], type, i, name )
\r
190 css: function( key, value ) {
\r
191 return this.attr( key, value, "curCSS" );
\r
194 text: function( text ) {
\r
195 if ( typeof text != "object" && text != null )
\r
196 return this.empty().append( document.createTextNode( text ) );
\r
200 jQuery.each( text || this, function(){
\r
201 jQuery.each( this.childNodes, function(){
\r
202 if ( this.nodeType != 8 )
\r
203 ret += this.nodeType != 1 ?
\r
205 jQuery.fn.text( [ this ] );
\r
212 wrapAll: function( html ) {
\r
214 // The elements to wrap the target around
\r
215 jQuery( html, this[0].ownerDocument )
\r
217 .insertBefore( this[0] )
\r
221 while ( elem.firstChild )
\r
222 elem = elem.firstChild;
\r
231 wrapInner: function( html ) {
\r
232 return this.each(function(){
\r
233 jQuery( this ).contents().wrapAll( html );
\r
237 wrap: function( html ) {
\r
238 return this.each(function(){
\r
239 jQuery( this ).wrapAll( html );
\r
243 append: function() {
\r
244 return this.domManip(arguments, true, false, function(elem){
\r
245 this.appendChild( elem );
\r
249 prepend: function() {
\r
250 return this.domManip(arguments, true, true, function(elem){
\r
251 this.insertBefore( elem, this.firstChild );
\r
255 before: function() {
\r
256 return this.domManip(arguments, false, false, function(elem){
\r
257 this.parentNode.insertBefore( elem, this );
\r
261 after: function() {
\r
262 return this.domManip(arguments, false, true, function(elem){
\r
263 this.parentNode.insertBefore( elem, this.nextSibling );
\r
268 return this.prevObject || jQuery( [] );
\r
271 find: function( selector ) {
\r
272 var elems = jQuery.map(this, function(elem){
\r
273 return jQuery.find( selector, elem );
\r
276 return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ?
\r
277 jQuery.unique( elems ) :
\r
281 clone: function( events ) {
\r
283 var ret = this.map(function(){
\r
284 return this.outerHTML ?
\r
285 jQuery( this.outerHTML )[0] :
\r
286 this.cloneNode( true );
\r
289 // Need to set the expando to null on the cloned set if it exists
\r
290 // removeData doesn't work here, IE removes it from the original as well
\r
291 // this is primarily for IE but the data expando shouldn't be copied over in any browser
\r
292 var clone = ret.find("*").andSelf().each(function(){
\r
293 if ( this[ expando ] != undefined )
\r
294 this[ expando ] = null;
\r
297 // Copy the events from the original to the clone
\r
298 if ( events === true )
\r
299 this.find("*").andSelf().each(function(i){
\r
300 var events = jQuery.data( this, "events" );
\r
302 for ( var type in events )
\r
303 for ( var handler in events[ type ] )
\r
304 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
\r
307 // Return the cloned set
\r
311 filter: function( selector ) {
\r
312 return this.pushStack(
\r
313 jQuery.isFunction( selector ) &&
\r
314 jQuery.grep(this, function(elem, i){
\r
315 return selector.call( elem, i );
\r
318 jQuery.multiFilter( selector, this ) );
\r
321 not: function( selector ) {
\r
322 return this.pushStack(
\r
323 selector.constructor == String &&
\r
324 jQuery.multiFilter( selector, this, true ) ||
\r
326 jQuery.grep(this, function(elem) {
\r
327 return selector.constructor == Array || selector.jquery ?
\r
328 jQuery.inArray( elem, selector ) < 0 :
\r
333 add: function( selector ) {
\r
334 return this.pushStack( jQuery.merge(
\r
336 selector.constructor == String ?
\r
337 jQuery( selector ).get() :
\r
338 selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?
\r
339 selector : [selector] ) );
\r
342 is: function( selector ) {
\r
344 jQuery.multiFilter( selector, this ).length > 0 :
\r
348 hasClass: function( selector ) {
\r
349 return this.is( "." + selector );
\r
352 val: function( value ) {
\r
353 if ( value == undefined ) {
\r
355 if ( this.length ) {
\r
356 var elem = this[0];
\r
358 // We need to handle select boxes special
\r
359 if ( jQuery.nodeName( elem, "select" ) ) {
\r
360 var index = elem.selectedIndex,
\r
362 options = elem.options,
\r
363 one = elem.type == "select-one";
\r
365 // Nothing was selected
\r
369 // Loop through all the selected options
\r
370 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
\r
371 var option = options[ i ];
\r
373 if ( option.selected ) {
\r
374 // Get the specifc value for the option
\r
375 value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
\r
377 // We don't need an array for one selects
\r
381 // Multi-Selects return an array
\r
382 values.push( value );
\r
388 // Everything else, we just grab the value
\r
390 return this[0].value.replace(/\r/g, "");
\r
395 return this.each(function(){
\r
396 if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )
\r
397 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
\r
398 jQuery.inArray(this.name, value) >= 0);
\r
400 else if ( jQuery.nodeName( this, "select" ) ) {
\r
401 var values = value.constructor == Array ?
\r
405 jQuery( "option", this ).each(function(){
\r
406 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
\r
407 jQuery.inArray( this.text, values ) >= 0);
\r
411 this.selectedIndex = -1;
\r
414 this.value = value;
\r
418 html: function( value ) {
\r
419 return value == undefined ?
\r
421 this[0].innerHTML :
\r
423 this.empty().append( value );
\r
426 replaceWith: function( value ) {
\r
427 return this.after( value ).remove();
\r
430 eq: function( i ) {
\r
431 return this.slice( i, i + 1 );
\r
434 slice: function() {
\r
435 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
\r
438 map: function( callback ) {
\r
439 return this.pushStack( jQuery.map(this, function(elem, i){
\r
440 return callback.call( elem, i, elem );
\r
444 andSelf: function() {
\r
445 return this.add( this.prevObject );
\r
448 domManip: function( args, table, reverse, callback ) {
\r
449 var clone = this.length > 1, elems;
\r
451 return this.each(function(){
\r
453 elems = jQuery.clean( args, this.ownerDocument );
\r
461 if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
\r
462 obj = this.getElementsByTagName("tbody")[0] || this.appendChild( document.createElement("tbody") );
\r
464 jQuery.each(elems, function(){
\r
466 this.cloneNode( true ) :
\r
469 if ( !evalScript( 0, elem ) )
\r
470 callback.call( obj, elem );
\r
476 function evalScript( i, elem ) {
\r
477 var script = jQuery.nodeName( elem, "script" );
\r
488 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
\r
490 if ( elem.parentNode )
\r
491 elem.parentNode.removeChild( elem );
\r
493 } else if ( elem.nodeType == 1 )
\r
494 jQuery( "script", elem ).each( evalScript );
\r
499 jQuery.extend = jQuery.fn.extend = function() {
\r
500 // copy reference to target object
\r
501 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
\r
503 // Handle a deep copy situation
\r
504 if ( target.constructor == Boolean ) {
\r
506 target = arguments[1] || {};
\r
509 // extend jQuery itself if only one argument is passed
\r
510 if ( length == 1 ) {
\r
515 for ( ; i < length; i++ )
\r
516 // Only deal with non-null/undefined values
\r
517 if ( (options = arguments[ i ]) != null )
\r
518 // Extend the base object
\r
519 for ( var name in options ) {
\r
520 // Prevent never-ending loop
\r
521 if ( target == options[ name ] )
\r
524 // Recurse if we're merging object values
\r
525 if ( deep && typeof options[ name ] == "object" && target[ name ] )
\r
526 jQuery.extend( target[ name ], options[ name ] );
\r
528 // Don't bring in undefined values
\r
529 else if ( options[ name ] != undefined )
\r
530 target[ name ] = options[ name ];
\r
534 // Return the modified object
\r
538 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};
\r
540 // exclude the following css properties to add px
\r
541 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
\r
544 noConflict: function( deep ) {
\r
548 window.jQuery = _jQuery;
\r
553 // This may seem like some crazy code, but trust me when I say that this
\r
554 // is the only cross-browser way to do this. --John
\r
555 isFunction: function( fn ) {
\r
556 return !!fn && typeof fn != "string" && !fn.nodeName &&
\r
557 fn.constructor != Array && /function/i.test( fn + "" );
\r
560 // check if an element is in a (or is an) XML document
\r
561 isXMLDoc: function( elem ) {
\r
562 return elem.documentElement && !elem.body ||
\r
563 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
\r
566 // Evalulates a script in a global context
\r
567 // Evaluates Async. in Safari 2 :-(
\r
568 globalEval: function( data ) {
\r
569 data = jQuery.trim( data );
\r
572 // Inspired by code by Andrea Giammarchi
\r
573 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
\r
574 var head = document.getElementsByTagName("head")[0] || document.documentElement,
\r
575 script = document.createElement("script");
\r
577 script.type = "text/javascript";
\r
578 if ( jQuery.browser.msie )
\r
579 script.text = data;
\r
581 script.appendChild( document.createTextNode( data ) );
\r
583 head.appendChild( script );
\r
584 head.removeChild( script );
\r
588 nodeName: function( elem, name ) {
\r
589 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
\r
594 data: function( elem, name, data ) {
\r
595 elem = elem == window ?
\r
599 var id = elem[ expando ];
\r
601 // Compute a unique ID for the element
\r
603 id = elem[ expando ] = ++uuid;
\r
605 // Only generate the data cache if we're
\r
606 // trying to access or manipulate it
\r
607 if ( name && !jQuery.cache[ id ] )
\r
608 jQuery.cache[ id ] = {};
\r
610 // Prevent overriding the named cache with undefined values
\r
611 if ( data != undefined )
\r
612 jQuery.cache[ id ][ name ] = data;
\r
614 // Return the named cache data, or the ID for the element
\r
616 jQuery.cache[ id ][ name ] :
\r
620 removeData: function( elem, name ) {
\r
621 elem = elem == window ?
\r
625 var id = elem[ expando ];
\r
627 // If we want to remove a specific section of the element's data
\r
629 if ( jQuery.cache[ id ] ) {
\r
630 // Remove the section of cache data
\r
631 delete jQuery.cache[ id ][ name ];
\r
633 // If we've removed all the data, remove the element's cache
\r
636 for ( name in jQuery.cache[ id ] )
\r
640 jQuery.removeData( elem );
\r
643 // Otherwise, we want to remove all of the element's data
\r
645 // Clean up the element expando
\r
647 delete elem[ expando ];
\r
649 // IE has trouble directly removing the expando
\r
650 // but it's ok with using removeAttribute
\r
651 if ( elem.removeAttribute )
\r
652 elem.removeAttribute( expando );
\r
655 // Completely remove the data cache
\r
656 delete jQuery.cache[ id ];
\r
660 // args is for internal usage only
\r
661 each: function( object, callback, args ) {
\r
663 if ( object.length == undefined )
\r
664 for ( var name in object )
\r
665 callback.apply( object[ name ], args );
\r
667 for ( var i = 0, length = object.length; i < length; i++ )
\r
668 if ( callback.apply( object[ i ], args ) === false )
\r
671 // A special, fast, case for the most common use of each
\r
673 if ( object.length == undefined )
\r
674 for ( var name in object )
\r
675 callback.call( object[ name ], name, object[ name ] );
\r
677 for ( var i = 0, length = object.length, value = object[0];
\r
678 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
\r
684 prop: function( elem, value, type, i, name ) {
\r
685 // Handle executable functions
\r
686 if ( jQuery.isFunction( value ) )
\r
687 value = value.call( elem, i );
\r
689 // Handle passing in a number to a CSS property
\r
690 return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
\r
696 // internal only, use addClass("class")
\r
697 add: function( elem, classNames ) {
\r
698 jQuery.each((classNames || "").split(/\s+/), function(i, className){
\r
699 if ( !jQuery.className.has( elem.className, className ) )
\r
700 elem.className += (elem.className ? " " : "") + className;
\r
704 // internal only, use removeClass("class")
\r
705 remove: function( elem, classNames ) {
\r
706 elem.className = classNames != undefined ?
\r
707 jQuery.grep(elem.className.split(/\s+/), function(className){
\r
708 return !jQuery.className.has( classNames, className );
\r
713 // internal only, use is(".class")
\r
714 has: function( elem, className ) {
\r
715 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
\r
719 // A method for quickly swapping in/out CSS properties to get correct calculations
\r
720 swap: function( elem, options, callback ) {
\r
721 // Remember the old values, and insert the new ones
\r
722 for ( var name in options ) {
\r
723 elem.style[ "old" + name ] = elem.style[ name ];
\r
724 elem.style[ name ] = options[ name ];
\r
727 callback.call( elem );
\r
729 // Revert the old values
\r
730 for ( var name in options )
\r
731 elem.style[ name ] = elem.style[ "old" + name ];
\r
734 css: function( elem, name ) {
\r
735 if ( name == "height" || name == "width" ) {
\r
736 var old = {}, height, width;
\r
738 // Revert the padding and border widths to get the
\r
739 // correct height/width values
\r
740 jQuery.each([ "Top", "Bottom", "Right", "Left" ], function(){
\r
741 old[ "padding" + this ] = 0;
\r
742 old[ "border" + this + "Width" ] = 0;
\r
745 // Swap out the padding/border values temporarily
\r
746 jQuery.swap( elem, old, function() {
\r
748 // If the element is visible, then the calculation is easy
\r
749 if ( jQuery( elem ).is(":visible") ) {
\r
750 height = elem.offsetHeight;
\r
751 width = elem.offsetWidth;
\r
753 // Otherwise, we need to flip out more values
\r
755 elem = jQuery( elem.cloneNode(true) )
\r
756 .find(":radio").removeAttr("checked").end()
\r
758 visibility: "hidden",
\r
759 position: "absolute",
\r
763 }).appendTo( elem.parentNode )[0];
\r
765 var position = jQuery.css( elem.parentNode, "position" ) || "static";
\r
766 if ( position == "static" )
\r
767 elem.parentNode.style.position = "relative";
\r
769 height = elem.clientHeight;
\r
770 width = elem.clientWidth;
\r
772 if ( position == "static" )
\r
773 elem.parentNode.style.position = "static";
\r
775 elem.parentNode.removeChild( elem );
\r
779 return name == "height" ?
\r
784 return jQuery.curCSS( elem, name );
\r
787 curCSS: function( elem, name, force ) {
\r
790 // A helper method for determining if an element's values are broken
\r
791 function color( elem ) {
\r
792 if ( !jQuery.browser.safari )
\r
795 var ret = document.defaultView.getComputedStyle( elem, null );
\r
796 return !ret || ret.getPropertyValue("color") == "";
\r
799 // We need to handle opacity special in IE
\r
800 if ( name == "opacity" && jQuery.browser.msie ) {
\r
801 ret = jQuery.attr( elem.style, "opacity" );
\r
808 // Make sure we're using the right name for getting the float value
\r
809 if ( name.match( /float/i ) )
\r
812 if ( !force && elem.style[ name ] )
\r
813 ret = elem.style[ name ];
\r
815 else if ( document.defaultView && document.defaultView.getComputedStyle ) {
\r
817 // Only "float" is needed here
\r
818 if ( name.match( /float/i ) )
\r
821 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
\r
823 var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
\r
825 if ( getComputedStyle && !color( elem ) )
\r
826 ret = getComputedStyle.getPropertyValue( name );
\r
828 // If the element isn't reporting its values properly in Safari
\r
829 // then some display: none elements are involved
\r
831 var swap = [], stack = [];
\r
833 // Locate all of the parent display: none elements
\r
834 for ( var a = elem; a && color(a); a = a.parentNode )
\r
837 // Go through and make them visible, but in reverse
\r
838 // (It would be better if we knew the exact display type that they had)
\r
839 for ( var i = 0; i < stack.length; i++ )
\r
840 if ( color( stack[ i ] ) ) {
\r
841 swap[ i ] = stack[ i ].style.display;
\r
842 stack[ i ].style.display = "block";
\r
845 // Since we flip the display style, we have to handle that
\r
846 // one special, otherwise get the value
\r
847 ret = name == "display" && swap[ stack.length - 1 ] != null ?
\r
849 ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || "";
\r
851 // Finally, revert the display styles back
\r
852 for ( var i = 0; i < swap.length; i++ )
\r
853 if ( swap[ i ] != null )
\r
854 stack[ i ].style.display = swap[ i ];
\r
857 // We should always get a number back from opacity
\r
858 if ( name == "opacity" && ret == "" )
\r
861 } else if ( elem.currentStyle ) {
\r
862 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
\r
863 return letter.toUpperCase();
\r
866 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
\r
868 // From the awesome hack by Dean Edwards
\r
869 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
\r
871 // If we're not dealing with a regular pixel number
\r
872 // but a number that has a weird ending, we need to convert it to pixels
\r
873 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
\r
874 // Remember the original values
\r
875 var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;
\r
877 // Put in the new values to get a computed value out
\r
878 elem.runtimeStyle.left = elem.currentStyle.left;
\r
879 elem.style.left = ret || 0;
\r
880 ret = elem.style.pixelLeft + "px";
\r
882 // Revert the changed values
\r
883 elem.style.left = style;
\r
884 elem.runtimeStyle.left = runtimeStyle;
\r
891 clean: function( elems, context ) {
\r
893 context = context || document;
\r
895 jQuery.each(elems, function(i, elem){
\r
899 if ( elem.constructor == Number )
\r
900 elem = elem.toString();
\r
902 // Convert html string into DOM nodes
\r
903 if ( typeof elem == "string" ) {
\r
904 // Fix "XHTML"-style tags in all browsers
\r
905 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
\r
906 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area)$/i) ?
\r
908 front + "></" + tag + ">";
\r
911 // Trim whitespace, otherwise indexOf won't work as expected
\r
912 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
\r
915 // option or optgroup
\r
916 !tags.indexOf("<opt") &&
\r
917 [ 1, "<select>", "</select>" ] ||
\r
919 !tags.indexOf("<leg") &&
\r
920 [ 1, "<fieldset>", "</fieldset>" ] ||
\r
922 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
\r
923 [ 1, "<table>", "</table>" ] ||
\r
925 !tags.indexOf("<tr") &&
\r
926 [ 2, "<table><tbody>", "</tbody></table>" ] ||
\r
928 // <thead> matched above
\r
929 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
\r
930 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
\r
932 !tags.indexOf("<col") &&
\r
933 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
\r
935 // IE can't serialize <link> and <script> tags normally
\r
936 jQuery.browser.msie &&
\r
937 [ 1, "div<div>", "</div>" ] ||
\r
941 // Go to html and back, then peel off extra wrappers
\r
942 div.innerHTML = wrap[1] + elem + wrap[2];
\r
944 // Move to the right depth
\r
945 while ( wrap[0]-- )
\r
946 div = div.lastChild;
\r
948 // Remove IE's autoinserted <tbody> from table fragments
\r
949 if ( jQuery.browser.msie ) {
\r
951 // String was a <table>, *may* have spurious <tbody>
\r
952 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
\r
953 div.firstChild && div.firstChild.childNodes :
\r
955 // String was a bare <thead> or <tfoot>
\r
956 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
\r
960 for ( var i = tbody.length - 1; i >= 0 ; --i )
\r
961 if ( jQuery.nodeName( tbody[ i ], "tbody" ) && !tbody[ i ].childNodes.length )
\r
962 tbody[ i ].parentNode.removeChild( tbody[ i ] );
\r
964 // IE completely kills leading whitespace when innerHTML is used
\r
965 if ( /^\s/.test( elem ) )
\r
966 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
\r
970 elem = jQuery.makeArray( div.childNodes );
\r
973 if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )
\r
976 if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )
\r
980 ret = jQuery.merge( ret, elem );
\r
987 attr: function( elem, name, value ) {
\r
988 var fix = jQuery.isXMLDoc( elem ) ?
\r
992 // Safari mis-reports the default selected property of a hidden option
\r
993 // Accessing the parent's selectedIndex property fixes it
\r
994 if ( name == "selected" && jQuery.browser.safari )
\r
995 elem.parentNode.selectedIndex;
\r
997 // Certain attributes only work when accessed via the old DOM 0 way
\r
998 if ( fix[ name ] ) {
\r
999 if ( value != undefined )
\r
1000 elem[ fix[ name ] ] = value;
\r
1002 return elem[ fix[ name ] ];
\r
1004 } else if ( jQuery.browser.msie && name == "style" )
\r
1005 return jQuery.attr( elem.style, "cssText", value );
\r
1007 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") )
\r
1008 return elem.getAttributeNode( name ).nodeValue;
\r
1010 // IE elem.getAttribute passes even for style
\r
1011 else if ( elem.tagName ) {
\r
1013 if ( value != undefined ) {
\r
1014 // We can't allow the type property to be changed (since it causes problems in IE)
\r
1015 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
\r
1016 throw "type property can't be changed";
\r
1018 elem.setAttribute( name, value );
\r
1021 if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) )
\r
1022 return elem.getAttribute( name, 2 );
\r
1024 return elem.getAttribute( name );
\r
1026 // elem is actually elem.style ... set the style
\r
1028 // IE actually uses filters for opacity
\r
1029 if ( name == "opacity" && jQuery.browser.msie ) {
\r
1030 if ( value != undefined ) {
\r
1031 // IE has trouble with opacity if it does not have layout
\r
1032 // Force it by setting the zoom level
\r
1035 // Set the alpha filter to set the opacity
\r
1036 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
\r
1037 (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
\r
1040 return elem.filter ?
\r
1041 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() :
\r
1045 name = name.replace(/-([a-z])/ig, function(all, letter){
\r
1046 return letter.toUpperCase();
\r
1049 if ( value != undefined )
\r
1050 elem[ name ] = value;
\r
1052 return elem[ name ];
\r
1056 trim: function( text ) {
\r
1057 return (text || "").replace( /^\s+|\s+$/g, "" );
\r
1060 makeArray: function( array ) {
\r
1063 // Need to use typeof to fight Safari childNodes crashes
\r
1064 if ( typeof array != "array" )
\r
1065 for ( var i = 0, length = array.length; i < length; i++ )
\r
1066 ret.push( array[ i ] );
\r
1068 ret = array.slice( 0 );
\r
1073 inArray: function( elem, array ) {
\r
1074 for ( var i = 0, length = array.length; i < length; i++ )
\r
1075 if ( array[ i ] == elem )
\r
1081 merge: function( first, second ) {
\r
1082 // We have to loop this way because IE & Opera overwrite the length
\r
1083 // expando of getElementsByTagName
\r
1085 // Also, we need to make sure that the correct elements are being returned
\r
1086 // (IE returns comment nodes in a '*' query)
\r
1087 if ( jQuery.browser.msie ) {
\r
1088 for ( var i = 0; second[ i ]; i++ )
\r
1089 if ( second[ i ].nodeType != 8 )
\r
1090 first.push( second[ i ] );
\r
1093 for ( var i = 0; second[ i ]; i++ )
\r
1094 first.push( second[ i ] );
\r
1099 unique: function( array ) {
\r
1100 var ret = [], done = {};
\r
1104 for ( var i = 0, length = array.length; i < length; i++ ) {
\r
1105 var id = jQuery.data( array[ i ] );
\r
1107 if ( !done[ id ] ) {
\r
1108 done[ id ] = true;
\r
1109 ret.push( array[ i ] );
\r
1120 grep: function( elems, callback, inv ) {
\r
1121 // If a string is passed in for the function, make a function
\r
1122 // for it (a handy shortcut)
\r
1123 if ( typeof callback == "string" )
\r
1124 callback = eval("false||function(a,i){return " + callback + "}");
\r
1128 // Go through the array, only saving the items
\r
1129 // that pass the validator function
\r
1130 for ( var i = 0, length = elems.length; i < length; i++ )
\r
1131 if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )
\r
1132 ret.push( elems[ i ] );
\r
1137 map: function( elems, callback ) {
\r
1140 // Go through the array, translating each of the items to their
\r
1141 // new value (or values).
\r
1142 for ( var i = 0, length = elems.length; i < length; i++ ) {
\r
1143 var value = callback( elems[ i ], i );
\r
1145 if ( value !== null && value != undefined ) {
\r
1146 if ( value.constructor != Array )
\r
1147 value = [ value ];
\r
1149 ret = ret.concat( value );
\r
1157 var userAgent = navigator.userAgent.toLowerCase();
\r
1159 // Figure out what browser is being used
\r
1160 jQuery.browser = {
\r
1161 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
\r
1162 safari: /webkit/.test( userAgent ),
\r
1163 opera: /opera/.test( userAgent ),
\r
1164 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
\r
1165 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
\r
1168 var styleFloat = jQuery.browser.msie ?
\r
1173 // Check to see if the W3C box model is being used
\r
1174 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
\r
1178 "class": "className",
\r
1179 "float": styleFloat,
\r
1180 cssFloat: styleFloat,
\r
1181 styleFloat: styleFloat,
\r
1182 innerHTML: "innerHTML",
\r
1183 className: "className",
\r
1185 disabled: "disabled",
\r
1186 checked: "checked",
\r
1187 readonly: "readOnly",
\r
1188 selected: "selected",
\r
1189 maxlength: "maxLength",
\r
1190 selectedIndex: "selectedIndex"
\r
1195 parent: "elem.parentNode",
\r
1196 parents: "jQuery.dir(elem,'parentNode')",
\r
1197 next: "jQuery.nth(elem,2,'nextSibling')",
\r
1198 prev: "jQuery.nth(elem,2,'previousSibling')",
\r
1199 nextAll: "jQuery.dir(elem,'nextSibling')",
\r
1200 prevAll: "jQuery.dir(elem,'previousSibling')",
\r
1201 siblings: "jQuery.sibling(elem.parentNode.firstChild,elem)",
\r
1202 children: "jQuery.sibling(elem.firstChild)",
\r
1203 contents: "jQuery.nodeName(elem,'iframe')?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes)"
\r
1204 }, function(name, fn){
\r
1205 fn = eval("false||function(elem){return " + fn + "}");
\r
1207 jQuery.fn[ name ] = function( selector ) {
\r
1208 var ret = jQuery.map( this, fn );
\r
1210 if ( selector && typeof selector == "string" )
\r
1211 ret = jQuery.multiFilter( selector, ret );
\r
1213 return this.pushStack( jQuery.unique( ret ) );
\r
1218 appendTo: "append",
\r
1219 prependTo: "prepend",
\r
1220 insertBefore: "before",
\r
1221 insertAfter: "after",
\r
1222 replaceAll: "replaceWith"
\r
1223 }, function(name, original){
\r
1224 jQuery.fn[ name ] = function() {
\r
1225 var args = arguments;
\r
1227 return this.each(function(){
\r
1228 for ( var i = 0, length = args.length; i < length; i++ )
\r
1229 jQuery( args[ i ] )[ original ]( this );
\r
1235 removeAttr: function( name ) {
\r
1236 jQuery.attr( this, name, "" );
\r
1237 this.removeAttribute( name );
\r
1240 addClass: function( classNames ) {
\r
1241 jQuery.className.add( this, classNames );
\r
1244 removeClass: function( classNames ) {
\r
1245 jQuery.className.remove( this, classNames );
\r
1248 toggleClass: function( classNames ) {
\r
1249 jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
\r
1252 remove: function( selector ) {
\r
1253 if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
\r
1254 // Prevent memory leaks
\r
1255 jQuery( "*", this ).add(this).each(function(){
\r
1256 jQuery.event.remove(this);
\r
1257 jQuery.removeData(this);
\r
1259 this.parentNode.removeChild( this );
\r
1263 empty: function() {
\r
1264 // Remove element nodes and prevent memory leaks
\r
1265 jQuery( ">*", this ).remove();
\r
1267 // Remove any remaining nodes
\r
1268 while ( this.firstChild )
\r
1269 this.removeChild( this.firstChild );
\r
1271 }, function(name, fn){
\r
1272 jQuery.fn[ name ] = function(){
\r
1273 return this.each( fn, arguments );
\r
1277 jQuery.each([ "Height", "Width" ], function(i, name){
\r
1278 var type = name.toLowerCase();
\r
1280 jQuery.fn[ type ] = function( size ) {
\r
1281 // Get window width or height
\r
1282 return this[0] == window ?
\r
1283 // Opera reports document.body.client[Width/Height] properly in both quirks and standards
\r
1284 jQuery.browser.opera && document.body[ "client" + name ] ||
\r
1286 // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
\r
1287 jQuery.browser.safari && self[ "inner" + name ] ||
\r
1289 // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
\r
1290 document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :
\r
1292 // Get document width or height
\r
1293 this[0] == document ?
\r
1294 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater (Mozilla reports scrollWidth the same as offsetWidth)
\r
1295 Math.max( document.body[ "scroll" + name ], document.body[ "offset" + name ] ) :
\r
1297 // Get or set width or height on the element
\r
1298 size == undefined ?
\r
1299 // Get width or height on the element
\r
1300 (this.length ? jQuery.css( this[0], type ) : null) :
\r
1302 // Set the width or height on the element (default to pixels if value is unitless)
\r
1303 this.css( type, size.constructor == String ? size : size + "px" );
\r