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 ( window.jQuery )
\r
14 var _jQuery = window.jQuery;
\r
16 var jQuery = window.jQuery = function( selector, context ) {
\r
17 // The jQuery object is actually just the init constructor 'enhanced'
\r
18 return new jQuery.prototype.init( selector, context );
\r
21 // Map over the $ in case of overwrite
\r
25 // Map the jQuery namespace to the '$' one
\r
28 // A simple way to check for HTML strings or ID strings
\r
29 // (both of which we optimize for)
\r
30 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
\r
32 // Is it a simple selector
\r
33 var isSimple = /^.[^:#\[\.]*$/;
\r
35 jQuery.fn = jQuery.prototype = {
\r
36 init: function( selector, context ) {
\r
37 // Make sure that a selection was provided
\r
38 selector = selector || document;
\r
40 // Handle $(DOMElement)
\r
41 if ( selector.nodeType ) {
\r
46 // Handle HTML strings
\r
47 } else if ( typeof selector == "string" ) {
\r
48 // Are we dealing with HTML string or an ID?
\r
49 var match = quickExpr.exec( selector );
\r
51 // Verify a match, and that no context was specified for #id
\r
52 if ( match && (match[1] || !context) ) {
\r
54 // HANDLE: $(html) -> $(array)
\r
56 selector = jQuery.clean( [ match[1] ], context );
\r
60 var elem = document.getElementById( match[3] );
\r
62 // Make sure an element was located
\r
64 // Handle the case where IE and Opera return items
\r
65 // by name instead of ID
\r
66 if ( elem.id != match[3] )
\r
67 return jQuery().find( selector );
\r
69 // Otherwise, we inject the element directly into the jQuery object
\r
80 // HANDLE: $(expr, [context])
\r
81 // (which is just equivalent to: $(content).find(expr)
\r
83 return new jQuery( context ).find( selector );
\r
85 // HANDLE: $(function)
\r
86 // Shortcut for document ready
\r
87 } else if ( jQuery.isFunction( selector ) )
\r
88 return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
\r
90 return this.setArray(
\r
92 selector.constructor == Array && selector ||
\r
94 // HANDLE: $(arraylike)
\r
95 // Watch for when an array-like object, contains DOM nodes, is passed in as the selector
\r
96 (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) ||
\r
102 // The current version of jQuery being used
\r
103 jquery: "@VERSION",
\r
105 // The number of elements contained in the matched element set
\r
107 return this.length;
\r
110 // The number of elements contained in the matched element set
\r
113 // Get the Nth element in the matched element set OR
\r
114 // Get the whole matched element set as a clean array
\r
115 get: function( num ) {
\r
116 return num == undefined ?
\r
118 // Return a 'clean' array
\r
119 jQuery.makeArray( this ) :
\r
121 // Return just the object
\r
125 // Take an array of elements and push it onto the stack
\r
126 // (returning the new matched element set)
\r
127 pushStack: function( elems ) {
\r
128 // Build a new jQuery matched element set
\r
129 var ret = jQuery( elems );
\r
131 // Add the old object onto the stack (as a reference)
\r
132 ret.prevObject = this;
\r
134 // Return the newly-formed element set
\r
138 // Force the current matched set of elements to become
\r
139 // the specified array of elements (destroying the stack in the process)
\r
140 // You should use pushStack() in order to do this, but maintain the stack
\r
141 setArray: function( elems ) {
\r
142 // Resetting the length to 0, then using the native Array push
\r
143 // is a super-fast way to populate an object with array-like properties
\r
145 Array.prototype.push.apply( this, elems );
\r
150 // Execute a callback for every element in the matched set.
\r
151 // (You can seed the arguments with an array of args, but this is
\r
152 // only used internally.)
\r
153 each: function( callback, args ) {
\r
154 return jQuery.each( this, callback, args );
\r
157 // Determine the position of an element within
\r
158 // the matched set of elements
\r
159 index: function( elem ) {
\r
162 // Locate the position of the desired element
\r
163 this.each(function(i){
\r
164 if ( this == elem )
\r
171 attr: function( name, value, type ) {
\r
172 var options = name;
\r
174 // Look for the case where we're accessing a style value
\r
175 if ( name.constructor == String )
\r
176 if ( value == undefined )
\r
177 return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined;
\r
181 options[ name ] = value;
\r
184 // Check to see if we're setting style values
\r
185 return this.each(function(i){
\r
186 // Set all the styles
\r
187 for ( name in options )
\r
192 name, jQuery.prop( this, options[ name ], type, i, name )
\r
197 css: function( key, value ) {
\r
198 // ignore negative width and height values
\r
199 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
\r
201 return this.attr( key, value, "curCSS" );
\r
204 text: function( text ) {
\r
205 if ( typeof text != "object" && text != null )
\r
206 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
\r
210 jQuery.each( text || this, function(){
\r
211 jQuery.each( this.childNodes, function(){
\r
212 if ( this.nodeType != 8 )
\r
213 ret += this.nodeType != 1 ?
\r
215 jQuery.fn.text( [ this ] );
\r
222 wrapAll: function( html ) {
\r
224 // The elements to wrap the target around
\r
225 jQuery( html, this[0].ownerDocument )
\r
227 .insertBefore( this[0] )
\r
231 while ( elem.firstChild )
\r
232 elem = elem.firstChild;
\r
241 wrapInner: function( html ) {
\r
242 return this.each(function(){
\r
243 jQuery( this ).contents().wrapAll( html );
\r
247 wrap: function( html ) {
\r
248 return this.each(function(){
\r
249 jQuery( this ).wrapAll( html );
\r
253 append: function() {
\r
254 return this.domManip(arguments, true, false, function(elem){
\r
255 if (this.nodeType == 1)
\r
256 this.appendChild( elem );
\r
260 prepend: function() {
\r
261 return this.domManip(arguments, true, true, function(elem){
\r
262 if (this.nodeType == 1)
\r
263 this.insertBefore( elem, this.firstChild );
\r
267 before: function() {
\r
268 return this.domManip(arguments, false, false, function(elem){
\r
269 this.parentNode.insertBefore( elem, this );
\r
273 after: function() {
\r
274 return this.domManip(arguments, false, true, function(elem){
\r
275 this.parentNode.insertBefore( elem, this.nextSibling );
\r
280 return this.prevObject || jQuery( [] );
\r
283 find: function( selector ) {
\r
284 var elems = jQuery.map(this, function(elem){
\r
285 return jQuery.find( selector, elem );
\r
288 return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ?
\r
289 jQuery.unique( elems ) :
\r
293 clone: function( events ) {
\r
295 var ret = this.map(function(){
\r
296 if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) {
\r
297 // IE copies events bound via attachEvent when
\r
298 // using cloneNode. Calling detachEvent on the
\r
299 // clone will also remove the events from the orignal
\r
300 // In order to get around this, we use innerHTML.
\r
301 // Unfortunately, this means some modifications to
\r
302 // attributes in IE that are actually only stored
\r
303 // as properties will not be copied (such as the
\r
304 // the name attribute on an input).
\r
305 var clone = this.cloneNode(true),
\r
306 container = document.createElement("div"),
\r
307 container2 = document.createElement("div");
\r
308 container.appendChild(clone);
\r
309 container2.innerHTML = container.innerHTML;
\r
310 return container2.firstChild;
\r
312 return this.cloneNode(true);
\r
315 // Need to set the expando to null on the cloned set if it exists
\r
316 // removeData doesn't work here, IE removes it from the original as well
\r
317 // this is primarily for IE but the data expando shouldn't be copied over in any browser
\r
318 var clone = ret.find("*").andSelf().each(function(){
\r
319 if ( this[ expando ] != undefined )
\r
320 this[ expando ] = null;
\r
323 // Copy the events from the original to the clone
\r
324 if ( events === true )
\r
325 this.find("*").andSelf().each(function(i){
\r
326 if (this.nodeType == 3)
\r
328 var events = jQuery.data( this, "events" );
\r
330 for ( var type in events )
\r
331 for ( var handler in events[ type ] )
\r
332 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
\r
335 // Return the cloned set
\r
339 filter: function( selector ) {
\r
340 return this.pushStack(
\r
341 jQuery.isFunction( selector ) &&
\r
342 jQuery.grep(this, function(elem, i){
\r
343 return selector.call( elem, i );
\r
346 jQuery.multiFilter( selector, this ) );
\r
349 not: function( selector ) {
\r
350 if ( selector.constructor == String )
\r
351 // test special case where just one selector is passed in
\r
352 if ( isSimple.test( selector ) )
\r
353 return this.pushStack( jQuery.multiFilter( selector, this, true ) );
\r
355 selector = jQuery.multiFilter( selector, this );
\r
357 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
\r
358 return this.filter(function() {
\r
359 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
\r
363 add: function( selector ) {
\r
364 return !selector ? this : this.pushStack( jQuery.merge(
\r
366 selector.constructor == String ?
\r
367 jQuery( selector ).get() :
\r
368 selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?
\r
369 selector : [selector] ) );
\r
372 is: function( selector ) {
\r
374 jQuery.multiFilter( selector, this ).length > 0 :
\r
378 hasClass: function( selector ) {
\r
379 return this.is( "." + selector );
\r
382 val: function( value ) {
\r
383 if ( value == undefined ) {
\r
385 if ( this.length ) {
\r
386 var elem = this[0];
\r
388 // We need to handle select boxes special
\r
389 if ( jQuery.nodeName( elem, "select" ) ) {
\r
390 var index = elem.selectedIndex,
\r
392 options = elem.options,
\r
393 one = elem.type == "select-one";
\r
395 // Nothing was selected
\r
399 // Loop through all the selected options
\r
400 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
\r
401 var option = options[ i ];
\r
403 if ( option.selected ) {
\r
404 // Get the specifc value for the option
\r
405 value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
\r
407 // We don't need an array for one selects
\r
411 // Multi-Selects return an array
\r
412 values.push( value );
\r
418 // Everything else, we just grab the value
\r
420 return (this[0].value || "").replace(/\r/g, "");
\r
427 return this.each(function(){
\r
428 if ( this.nodeType != 1 )
\r
431 if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )
\r
432 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
\r
433 jQuery.inArray(this.name, value) >= 0);
\r
435 else if ( jQuery.nodeName( this, "select" ) ) {
\r
436 var values = value.constructor == Array ?
\r
440 jQuery( "option", this ).each(function(){
\r
441 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
\r
442 jQuery.inArray( this.text, values ) >= 0);
\r
445 if ( !values.length )
\r
446 this.selectedIndex = -1;
\r
449 this.value = value;
\r
453 html: function( value ) {
\r
454 return value == undefined ?
\r
456 this[0].innerHTML :
\r
458 this.empty().append( value );
\r
461 replaceWith: function( value ) {
\r
462 return this.after( value ).remove();
\r
465 eq: function( i ) {
\r
466 return this.slice( i, i + 1 );
\r
469 slice: function() {
\r
470 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
\r
473 map: function( callback ) {
\r
474 return this.pushStack( jQuery.map(this, function(elem, i){
\r
475 return callback.call( elem, i, elem );
\r
479 andSelf: function() {
\r
480 return this.add( this.prevObject );
\r
483 domManip: function( args, table, reverse, callback ) {
\r
484 var clone = this.length > 1, elems;
\r
486 return this.each(function(){
\r
488 elems = jQuery.clean( args, this.ownerDocument );
\r
496 if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
\r
497 obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
\r
499 var scripts = jQuery( [] );
\r
501 jQuery.each(elems, function(){
\r
503 jQuery( this ).clone( true )[0] :
\r
506 // execute all scripts after the elements have been injected
\r
507 if ( jQuery.nodeName( elem, "script" ) ) {
\r
508 scripts = scripts.add( elem );
\r
510 // Remove any inner scripts for later evaluation
\r
511 if ( elem.nodeType == 1 )
\r
512 scripts = scripts.add( jQuery( "script", elem ).remove() );
\r
514 // Inject the elements into the document
\r
515 callback.call( obj, elem );
\r
519 scripts.each( evalScript );
\r
524 // Give the init function the jQuery prototype for later instantiation
\r
525 jQuery.prototype.init.prototype = jQuery.prototype;
\r
527 function evalScript( i, elem ) {
\r
536 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
\r
538 if ( elem.parentNode )
\r
539 elem.parentNode.removeChild( elem );
\r
542 jQuery.extend = jQuery.fn.extend = function() {
\r
543 // copy reference to target object
\r
544 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
\r
546 // Handle a deep copy situation
\r
547 if ( target.constructor == Boolean ) {
\r
549 target = arguments[1] || {};
\r
550 // skip the boolean and the target
\r
554 // Handle case when target is a string or something (possible in deep copy)
\r
555 if ( typeof target != "object" && typeof target != "function" )
\r
558 // extend jQuery itself if only one argument is passed
\r
559 if ( length == 1 ) {
\r
564 for ( ; i < length; i++ )
\r
565 // Only deal with non-null/undefined values
\r
566 if ( (options = arguments[ i ]) != null )
\r
567 // Extend the base object
\r
568 for ( var name in options ) {
\r
569 // Prevent never-ending loop
\r
570 if ( target === options[ name ] )
\r
573 // Recurse if we're merging object values
\r
574 if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )
\r
575 target[ name ] = jQuery.extend( target[ name ], options[ name ] );
\r
577 // Don't bring in undefined values
\r
578 else if ( options[ name ] != undefined )
\r
579 target[ name ] = options[ name ];
\r
583 // Return the modified object
\r
587 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};
\r
589 // exclude the following css properties to add px
\r
590 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
\r
593 noConflict: function( deep ) {
\r
597 window.jQuery = _jQuery;
\r
602 // See test/unit/core.js for details concerning this function.
\r
603 isFunction: function( fn ) {
\r
604 return !!fn && typeof fn != "string" && !fn.nodeName &&
\r
605 fn.constructor != Array && /function/i.test( fn + "" );
\r
608 // check if an element is in a (or is an) XML document
\r
609 isXMLDoc: function( elem ) {
\r
610 return elem.documentElement && !elem.body ||
\r
611 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
\r
614 // Evalulates a script in a global context
\r
615 globalEval: function( data ) {
\r
616 data = jQuery.trim( data );
\r
619 // Inspired by code by Andrea Giammarchi
\r
620 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
\r
621 var head = document.getElementsByTagName("head")[0] || document.documentElement,
\r
622 script = document.createElement("script");
\r
624 script.type = "text/javascript";
\r
625 if ( jQuery.browser.msie )
\r
626 script.text = data;
\r
628 script.appendChild( document.createTextNode( data ) );
\r
630 head.appendChild( script );
\r
631 head.removeChild( script );
\r
635 nodeName: function( elem, name ) {
\r
636 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
\r
641 data: function( elem, name, data ) {
\r
642 elem = elem == window ?
\r
646 var id = elem[ expando ];
\r
648 // Compute a unique ID for the element
\r
650 id = elem[ expando ] = ++uuid;
\r
652 // Only generate the data cache if we're
\r
653 // trying to access or manipulate it
\r
654 if ( name && !jQuery.cache[ id ] )
\r
655 jQuery.cache[ id ] = {};
\r
657 // Prevent overriding the named cache with undefined values
\r
658 if ( data != undefined )
\r
659 jQuery.cache[ id ][ name ] = data;
\r
661 // Return the named cache data, or the ID for the element
\r
663 jQuery.cache[ id ][ name ] :
\r
667 removeData: function( elem, name ) {
\r
668 elem = elem == window ?
\r
672 var id = elem[ expando ];
\r
674 // If we want to remove a specific section of the element's data
\r
676 if ( jQuery.cache[ id ] ) {
\r
677 // Remove the section of cache data
\r
678 delete jQuery.cache[ id ][ name ];
\r
680 // If we've removed all the data, remove the element's cache
\r
683 for ( name in jQuery.cache[ id ] )
\r
687 jQuery.removeData( elem );
\r
690 // Otherwise, we want to remove all of the element's data
\r
692 // Clean up the element expando
\r
694 delete elem[ expando ];
\r
696 // IE has trouble directly removing the expando
\r
697 // but it's ok with using removeAttribute
\r
698 if ( elem.removeAttribute )
\r
699 elem.removeAttribute( expando );
\r
702 // Completely remove the data cache
\r
703 delete jQuery.cache[ id ];
\r
707 // args is for internal usage only
\r
708 each: function( object, callback, args ) {
\r
710 if ( object.length == undefined ) {
\r
711 for ( var name in object )
\r
712 if ( callback.apply( object[ name ], args ) === false )
\r
715 for ( var i = 0, length = object.length; i < length; i++ )
\r
716 if ( callback.apply( object[ i ], args ) === false )
\r
719 // A special, fast, case for the most common use of each
\r
721 if ( object.length == undefined ) {
\r
722 for ( var name in object )
\r
723 if ( callback.call( object[ name ], name, object[ name ] ) === false )
\r
726 for ( var i = 0, length = object.length, value = object[0];
\r
727 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
\r
733 prop: function( elem, value, type, i, name ) {
\r
734 // Handle executable functions
\r
735 if ( jQuery.isFunction( value ) )
\r
736 value = value.call( elem, i );
\r
738 // Handle passing in a number to a CSS property
\r
739 return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
\r
745 // internal only, use addClass("class")
\r
746 add: function( elem, classNames ) {
\r
747 jQuery.each((classNames || "").split(/\s+/), function(i, className){
\r
748 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
\r
749 elem.className += (elem.className ? " " : "") + className;
\r
753 // internal only, use removeClass("class")
\r
754 remove: function( elem, classNames ) {
\r
755 if (elem.nodeType == 1)
\r
756 elem.className = classNames != undefined ?
\r
757 jQuery.grep(elem.className.split(/\s+/), function(className){
\r
758 return !jQuery.className.has( classNames, className );
\r
763 // internal only, use is(".class")
\r
764 has: function( elem, className ) {
\r
765 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
\r
769 // A method for quickly swapping in/out CSS properties to get correct calculations
\r
770 swap: function( elem, options, callback ) {
\r
772 // Remember the old values, and insert the new ones
\r
773 for ( var name in options ) {
\r
774 old[ name ] = elem.style[ name ];
\r
775 elem.style[ name ] = options[ name ];
\r
778 callback.call( elem );
\r
780 // Revert the old values
\r
781 for ( var name in options )
\r
782 elem.style[ name ] = old[ name ];
\r
785 css: function( elem, name, force ) {
\r
786 if ( name == "width" || name == "height" ) {
\r
787 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
\r
790 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
\r
791 var padding = 0, border = 0;
\r
792 jQuery.each( which, function() {
\r
793 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
\r
794 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
\r
796 val -= Math.round(padding + border);
\r
799 if ( jQuery(elem).is(":visible") )
\r
802 jQuery.swap( elem, props, getWH );
\r
804 return Math.max(0, val);
\r
807 return jQuery.curCSS( elem, name, force );
\r
810 curCSS: function( elem, name, force ) {
\r
813 // A helper method for determining if an element's values are broken
\r
814 function color( elem ) {
\r
815 if ( !jQuery.browser.safari )
\r
818 var ret = document.defaultView.getComputedStyle( elem, null );
\r
819 return !ret || ret.getPropertyValue("color") == "";
\r
822 // We need to handle opacity special in IE
\r
823 if ( name == "opacity" && jQuery.browser.msie ) {
\r
824 ret = jQuery.attr( elem.style, "opacity" );
\r
830 // Opera sometimes will give the wrong display answer, this fixes it, see #2037
\r
831 if ( jQuery.browser.opera && name == "display" ) {
\r
832 var save = elem.style.display;
\r
833 elem.style.display = "block";
\r
834 elem.style.display = save;
\r
837 // Make sure we're using the right name for getting the float value
\r
838 if ( name.match( /float/i ) )
\r
841 if ( !force && elem.style && elem.style[ name ] )
\r
842 ret = elem.style[ name ];
\r
844 else if ( document.defaultView && document.defaultView.getComputedStyle ) {
\r
846 // Only "float" is needed here
\r
847 if ( name.match( /float/i ) )
\r
850 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
\r
852 var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
\r
854 if ( getComputedStyle && !color( elem ) )
\r
855 ret = getComputedStyle.getPropertyValue( name );
\r
857 // If the element isn't reporting its values properly in Safari
\r
858 // then some display: none elements are involved
\r
860 var swap = [], stack = [];
\r
862 // Locate all of the parent display: none elements
\r
863 for ( var a = elem; a && color(a); a = a.parentNode )
\r
866 // Go through and make them visible, but in reverse
\r
867 // (It would be better if we knew the exact display type that they had)
\r
868 for ( var i = 0; i < stack.length; i++ )
\r
869 if ( color( stack[ i ] ) ) {
\r
870 swap[ i ] = stack[ i ].style.display;
\r
871 stack[ i ].style.display = "block";
\r
874 // Since we flip the display style, we have to handle that
\r
875 // one special, otherwise get the value
\r
876 ret = name == "display" && swap[ stack.length - 1 ] != null ?
\r
878 ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || "";
\r
880 // Finally, revert the display styles back
\r
881 for ( var i = 0; i < swap.length; i++ )
\r
882 if ( swap[ i ] != null )
\r
883 stack[ i ].style.display = swap[ i ];
\r
886 // We should always get a number back from opacity
\r
887 if ( name == "opacity" && ret == "" )
\r
890 } else if ( elem.currentStyle ) {
\r
891 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
\r
892 return letter.toUpperCase();
\r
895 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
\r
897 // From the awesome hack by Dean Edwards
\r
898 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
\r
900 // If we're not dealing with a regular pixel number
\r
901 // but a number that has a weird ending, we need to convert it to pixels
\r
902 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
\r
903 // Remember the original values
\r
904 var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;
\r
906 // Put in the new values to get a computed value out
\r
907 elem.runtimeStyle.left = elem.currentStyle.left;
\r
908 elem.style.left = ret || 0;
\r
909 ret = elem.style.pixelLeft + "px";
\r
911 // Revert the changed values
\r
912 elem.style.left = style;
\r
913 elem.runtimeStyle.left = runtimeStyle;
\r
920 clean: function( elems, context ) {
\r
922 context = context || document;
\r
923 // !context.createElement fails in IE with an error but returns typeof 'object'
\r
924 if (typeof context.createElement == 'undefined')
\r
925 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
\r
927 jQuery.each(elems, function(i, elem){
\r
931 if ( elem.constructor == Number )
\r
932 elem = elem.toString();
\r
934 // Convert html string into DOM nodes
\r
935 if ( typeof elem == "string" ) {
\r
936 // Fix "XHTML"-style tags in all browsers
\r
937 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
\r
938 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
\r
940 front + "></" + tag + ">";
\r
943 // Trim whitespace, otherwise indexOf won't work as expected
\r
944 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
\r
947 // option or optgroup
\r
948 !tags.indexOf("<opt") &&
\r
949 [ 1, "<select multiple='multiple'>", "</select>" ] ||
\r
951 !tags.indexOf("<leg") &&
\r
952 [ 1, "<fieldset>", "</fieldset>" ] ||
\r
954 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
\r
955 [ 1, "<table>", "</table>" ] ||
\r
957 !tags.indexOf("<tr") &&
\r
958 [ 2, "<table><tbody>", "</tbody></table>" ] ||
\r
960 // <thead> matched above
\r
961 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
\r
962 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
\r
964 !tags.indexOf("<col") &&
\r
965 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
\r
967 // IE can't serialize <link> and <script> tags normally
\r
968 jQuery.browser.msie &&
\r
969 [ 1, "div<div>", "</div>" ] ||
\r
973 // Go to html and back, then peel off extra wrappers
\r
974 div.innerHTML = wrap[1] + elem + wrap[2];
\r
976 // Move to the right depth
\r
977 while ( wrap[0]-- )
\r
978 div = div.lastChild;
\r
980 // Remove IE's autoinserted <tbody> from table fragments
\r
981 if ( jQuery.browser.msie ) {
\r
983 // String was a <table>, *may* have spurious <tbody>
\r
984 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
\r
985 div.firstChild && div.firstChild.childNodes :
\r
987 // String was a bare <thead> or <tfoot>
\r
988 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
\r
992 for ( var j = tbody.length - 1; j >= 0 ; --j )
\r
993 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
\r
994 tbody[ j ].parentNode.removeChild( tbody[ j ] );
\r
996 // IE completely kills leading whitespace when innerHTML is used
\r
997 if ( /^\s/.test( elem ) )
\r
998 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
\r
1002 elem = jQuery.makeArray( div.childNodes );
\r
1005 if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )
\r
1008 if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )
\r
1012 ret = jQuery.merge( ret, elem );
\r
1019 attr: function( elem, name, value ) {
\r
1020 // don't set attributes on text and comment nodes
\r
1021 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
\r
1024 var fix = jQuery.isXMLDoc( elem ) ?
\r
1028 // Safari mis-reports the default selected property of a hidden option
\r
1029 // Accessing the parent's selectedIndex property fixes it
\r
1030 if ( name == "selected" && jQuery.browser.safari )
\r
1031 elem.parentNode.selectedIndex;
\r
1033 // Certain attributes only work when accessed via the old DOM 0 way
\r
1034 if ( fix[ name ] ) {
\r
1035 if ( value != undefined )
\r
1036 elem[ fix[ name ] ] = value;
\r
1038 return elem[ fix[ name ] ];
\r
1040 } else if ( jQuery.browser.msie && name == "style" )
\r
1041 return jQuery.attr( elem.style, "cssText", value );
\r
1043 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") )
\r
1044 return elem.getAttributeNode( name ).nodeValue;
\r
1046 // IE elem.getAttribute passes even for style
\r
1047 else if ( elem.tagName ) {
\r
1049 if ( value != undefined ) {
\r
1050 // We can't allow the type property to be changed (since it causes problems in IE)
\r
1051 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
\r
1052 throw "type property can't be changed";
\r
1054 // convert the value to a string (all browsers do this but IE) see #1070
\r
1055 elem.setAttribute( name, "" + value );
\r
1058 if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) )
\r
1059 return elem.getAttribute( name, 2 );
\r
1061 return elem.getAttribute( name );
\r
1063 // elem is actually elem.style ... set the style
\r
1065 // IE actually uses filters for opacity
\r
1066 if ( name == "opacity" && jQuery.browser.msie ) {
\r
1067 if ( value != undefined ) {
\r
1068 // IE has trouble with opacity if it does not have layout
\r
1069 // Force it by setting the zoom level
\r
1072 // Set the alpha filter to set the opacity
\r
1073 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
\r
1074 (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
\r
1077 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
\r
1078 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() :
\r
1082 name = name.replace(/-([a-z])/ig, function(all, letter){
\r
1083 return letter.toUpperCase();
\r
1086 if ( value != undefined )
\r
1087 elem[ name ] = value;
\r
1089 return elem[ name ];
\r
1093 trim: function( text ) {
\r
1094 return (text || "").replace( /^\s+|\s+$/g, "" );
\r
1097 makeArray: function( array ) {
\r
1100 // Need to use typeof to fight Safari childNodes crashes
\r
1101 if ( typeof array != "array" )
\r
1102 for ( var i = 0, length = array.length; i < length; i++ )
\r
1103 ret.push( array[ i ] );
\r
1105 ret = array.slice( 0 );
\r
1110 inArray: function( elem, array ) {
\r
1111 for ( var i = 0, length = array.length; i < length; i++ )
\r
1112 if ( array[ i ] == elem )
\r
1118 merge: function( first, second ) {
\r
1119 // We have to loop this way because IE & Opera overwrite the length
\r
1120 // expando of getElementsByTagName
\r
1122 // Also, we need to make sure that the correct elements are being returned
\r
1123 // (IE returns comment nodes in a '*' query)
\r
1124 if ( jQuery.browser.msie ) {
\r
1125 for ( var i = 0; second[ i ]; i++ )
\r
1126 if ( second[ i ].nodeType != 8 )
\r
1127 first.push( second[ i ] );
\r
1130 for ( var i = 0; second[ i ]; i++ )
\r
1131 first.push( second[ i ] );
\r
1136 unique: function( array ) {
\r
1137 var ret = [], done = {};
\r
1141 for ( var i = 0, length = array.length; i < length; i++ ) {
\r
1142 var id = jQuery.data( array[ i ] );
\r
1144 if ( !done[ id ] ) {
\r
1145 done[ id ] = true;
\r
1146 ret.push( array[ i ] );
\r
1157 grep: function( elems, callback, inv ) {
\r
1158 // If a string is passed in for the function, make a function
\r
1159 // for it (a handy shortcut)
\r
1160 if ( typeof callback == "string" )
\r
1161 callback = eval("false||function(a,i){return " + callback + "}");
\r
1165 // Go through the array, only saving the items
\r
1166 // that pass the validator function
\r
1167 for ( var i = 0, length = elems.length; i < length; i++ )
\r
1168 if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )
\r
1169 ret.push( elems[ i ] );
\r
1174 map: function( elems, callback ) {
\r
1177 // Go through the array, translating each of the items to their
\r
1178 // new value (or values).
\r
1179 for ( var i = 0, length = elems.length; i < length; i++ ) {
\r
1180 var value = callback( elems[ i ], i );
\r
1182 if ( value !== null && value != undefined ) {
\r
1183 if ( value.constructor != Array )
\r
1184 value = [ value ];
\r
1186 ret = ret.concat( value );
\r
1194 var userAgent = navigator.userAgent.toLowerCase();
\r
1196 // Figure out what browser is being used
\r
1197 jQuery.browser = {
\r
1198 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
\r
1199 safari: /webkit/.test( userAgent ),
\r
1200 opera: /opera/.test( userAgent ),
\r
1201 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
\r
1202 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
\r
1205 var styleFloat = jQuery.browser.msie ?
\r
1210 // Check to see if the W3C box model is being used
\r
1211 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
\r
1215 "class": "className",
\r
1216 "float": styleFloat,
\r
1217 cssFloat: styleFloat,
\r
1218 styleFloat: styleFloat,
\r
1219 innerHTML: "innerHTML",
\r
1220 className: "className",
\r
1222 disabled: "disabled",
\r
1223 checked: "checked",
\r
1224 readonly: "readOnly",
\r
1225 selected: "selected",
\r
1226 maxlength: "maxLength",
\r
1227 selectedIndex: "selectedIndex",
\r
1228 defaultValue: "defaultValue",
\r
1229 tagName: "tagName",
\r
1230 nodeName: "nodeName"
\r
1235 parent: "elem.parentNode",
\r
1236 parents: "jQuery.dir(elem,'parentNode')",
\r
1237 next: "jQuery.nth(elem,2,'nextSibling')",
\r
1238 prev: "jQuery.nth(elem,2,'previousSibling')",
\r
1239 nextAll: "jQuery.dir(elem,'nextSibling')",
\r
1240 prevAll: "jQuery.dir(elem,'previousSibling')",
\r
1241 siblings: "jQuery.sibling(elem.parentNode.firstChild,elem)",
\r
1242 children: "jQuery.sibling(elem.firstChild)",
\r
1243 contents: "jQuery.nodeName(elem,'iframe')?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes)"
\r
1244 }, function(name, fn){
\r
1245 fn = eval("false||function(elem){return " + fn + "}");
\r
1247 jQuery.fn[ name ] = function( selector ) {
\r
1248 var ret = jQuery.map( this, fn );
\r
1250 if ( selector && typeof selector == "string" )
\r
1251 ret = jQuery.multiFilter( selector, ret );
\r
1253 return this.pushStack( jQuery.unique( ret ) );
\r
1258 appendTo: "append",
\r
1259 prependTo: "prepend",
\r
1260 insertBefore: "before",
\r
1261 insertAfter: "after",
\r
1262 replaceAll: "replaceWith"
\r
1263 }, function(name, original){
\r
1264 jQuery.fn[ name ] = function() {
\r
1265 var args = arguments;
\r
1267 return this.each(function(){
\r
1268 for ( var i = 0, length = args.length; i < length; i++ )
\r
1269 jQuery( args[ i ] )[ original ]( this );
\r
1275 removeAttr: function( name ) {
\r
1276 jQuery.attr( this, name, "" );
\r
1277 if (this.nodeType == 1)
\r
1278 this.removeAttribute( name );
\r
1281 addClass: function( classNames ) {
\r
1282 jQuery.className.add( this, classNames );
\r
1285 removeClass: function( classNames ) {
\r
1286 jQuery.className.remove( this, classNames );
\r
1289 toggleClass: function( classNames ) {
\r
1290 jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
\r
1293 remove: function( selector ) {
\r
1294 if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
\r
1295 // Prevent memory leaks
\r
1296 jQuery( "*", this ).add(this).each(function(){
\r
1297 jQuery.event.remove(this);
\r
1298 jQuery.removeData(this);
\r
1300 if (this.parentNode)
\r
1301 this.parentNode.removeChild( this );
\r
1305 empty: function() {
\r
1306 // Remove element nodes and prevent memory leaks
\r
1307 jQuery( ">*", this ).remove();
\r
1309 // Remove any remaining nodes
\r
1310 while ( this.firstChild )
\r
1311 this.removeChild( this.firstChild );
\r
1313 }, function(name, fn){
\r
1314 jQuery.fn[ name ] = function(){
\r
1315 return this.each( fn, arguments );
\r
1319 jQuery.each([ "Height", "Width" ], function(i, name){
\r
1320 var type = name.toLowerCase();
\r
1322 jQuery.fn[ type ] = function( size ) {
\r
1323 // Get window width or height
\r
1324 return this[0] == window ?
\r
1325 // Opera reports document.body.client[Width/Height] properly in both quirks and standards
\r
1326 jQuery.browser.opera && document.body[ "client" + name ] ||
\r
1328 // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
\r
1329 jQuery.browser.safari && window[ "inner" + name ] ||
\r
1331 // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
\r
1332 document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :
\r
1334 // Get document width or height
\r
1335 this[0] == document ?
\r
1336 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
\r
1338 Math.max(document.body["scroll" + name], document.documentElement["scroll" + name]),
\r
1339 Math.max(document.body["offset" + name], document.documentElement["offset" + name])
\r
1342 // Get or set width or height on the element
\r
1343 size == undefined ?
\r
1344 // Get width or height on the element
\r
1345 (this.length ? jQuery.css( this[0], type ) : null) :
\r
1347 // Set the width or height on the element (default to pixels if value is unitless)
\r
1348 this.css( type, size.constructor == String ? size : size + "px" );
\r