2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2008 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Map over jQuery in case of overwrite
13 var _jQuery = window.jQuery,
14 // Map over the $ in case of overwrite
17 var jQuery = window.jQuery = window.$ = function( selector, context ) {
18 // The jQuery object is actually just the init constructor 'enhanced'
19 return new jQuery.fn.init( selector, context );
22 // A simple way to check for HTML strings or ID strings
23 // (both of which we optimize for)
24 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
26 // Is it a simple selector
27 isSimple = /^.[^:#\[\.]*$/,
29 // Will speed up references to undefined, and allows munging its name.
32 jQuery.fn = jQuery.prototype = {
33 init: function( selector, context ) {
34 // Make sure that a selection was provided
35 selector = selector || document;
37 // Handle $(DOMElement)
38 if ( selector.nodeType ) {
41 this.context = selector;
44 // Handle HTML strings
45 if ( typeof selector === "string" ) {
46 // Are we dealing with HTML string or an ID?
47 var match = quickExpr.exec( selector );
49 // Verify a match, and that no context was specified for #id
50 if ( match && (match[1] || !context) ) {
52 // HANDLE: $(html) -> $(array)
54 selector = jQuery.clean( [ match[1] ], context );
58 var elem = document.getElementById( match[3] );
60 // Make sure an element was located
62 // Handle the case where IE and Opera return items
63 // by name instead of ID
64 if ( elem.id != match[3] )
65 return jQuery().find( selector );
67 // Otherwise, we inject the element directly into the jQuery object
68 var ret = jQuery( elem );
69 ret.context = document;
70 ret.selector = selector;
76 // HANDLE: $(expr, [context])
77 // (which is just equivalent to: $(content).find(expr)
79 return jQuery( context ).find( selector );
81 // HANDLE: $(function)
82 // Shortcut for document ready
83 } else if ( jQuery.isFunction( selector ) )
84 return jQuery( document ).ready( selector );
86 return this.setArray(jQuery.makeArray(selector));
89 // Start with an empty selector
92 // The current version of jQuery being used
95 // The number of elements contained in the matched element set
100 // Get the Nth element in the matched element set OR
101 // Get the whole matched element set as a clean array
102 get: function( num ) {
103 return num === undefined ?
105 // Return a 'clean' array
106 jQuery.makeArray( this ) :
108 // Return just the object
112 // Take an array of elements and push it onto the stack
113 // (returning the new matched element set)
114 pushStack: function( elems, name, selector ) {
115 // Build a new jQuery matched element set
116 var ret = jQuery( elems );
118 // Add the old object onto the stack (as a reference)
119 ret.prevObject = this;
121 ret.context = this.context;
123 if ( name === "find" )
124 ret.selector = this.selector + (this.selector ? " " : "") + selector;
126 ret.selector = this.selector + "." + name + "(" + selector + ")";
128 // Return the newly-formed element set
132 // Force the current matched set of elements to become
133 // the specified array of elements (destroying the stack in the process)
134 // You should use pushStack() in order to do this, but maintain the stack
135 setArray: function( elems ) {
136 // Resetting the length to 0, then using the native Array push
137 // is a super-fast way to populate an object with array-like properties
139 Array.prototype.push.apply( this, elems );
144 // Execute a callback for every element in the matched set.
145 // (You can seed the arguments with an array of args, but this is
146 // only used internally.)
147 each: function( callback, args ) {
148 return jQuery.each( this, callback, args );
151 // Determine the position of an element within
152 // the matched set of elements
153 index: function( elem ) {
154 // Locate the position of the desired element
155 return jQuery.inArray(
156 // If it receives a jQuery object, the first element is used
157 elem && elem.jquery ? elem[0] : elem
161 attr: function( name, value, type ) {
164 // Look for the case where we're accessing a style value
165 if ( typeof name === "string" )
166 if ( value === undefined )
167 return this[0] && jQuery[ type || "attr" ]( this[0], name );
171 options[ name ] = value;
174 // Check to see if we're setting style values
175 return this.each(function(i){
176 // Set all the styles
177 for ( name in options )
182 name, jQuery.prop( this, options[ name ], type, i, name )
187 css: function( key, value ) {
188 // ignore negative width and height values
189 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
191 return this.attr( key, value, "curCSS" );
194 text: function( text ) {
195 if ( typeof text !== "object" && text != null )
196 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
200 jQuery.each( text || this, function(){
201 jQuery.each( this.childNodes, function(){
202 if ( this.nodeType != 8 )
203 ret += this.nodeType != 1 ?
205 jQuery.fn.text( [ this ] );
212 wrapAll: function( html ) {
214 // The elements to wrap the target around
215 jQuery( html, this[0].ownerDocument )
217 .insertBefore( this[0] )
221 while ( elem.firstChild )
222 elem = elem.firstChild;
231 wrapInner: function( html ) {
232 return this.each(function(){
233 jQuery( this ).contents().wrapAll( html );
237 wrap: function( html ) {
238 return this.each(function(){
239 jQuery( this ).wrapAll( html );
244 return this.domManip(arguments, true, function(elem){
245 if (this.nodeType == 1)
246 this.appendChild( elem );
250 prepend: function() {
251 return this.domManip(arguments, true, function(elem){
252 if (this.nodeType == 1)
253 this.insertBefore( elem, this.firstChild );
258 return this.domManip(arguments, false, function(elem){
259 this.parentNode.insertBefore( elem, this );
264 return this.domManip(arguments, false, function(elem){
265 this.parentNode.insertBefore( elem, this.nextSibling );
270 return this.prevObject || jQuery( [] );
273 find: function( selector ) {
274 var elems = jQuery.map(this, function(elem){
275 return jQuery.find( selector, elem );
278 return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
279 jQuery.unique( elems ) :
280 elems, "find", selector );
283 clone: function( events ) {
285 var ret = this.map(function(){
286 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
287 // IE copies events bound via attachEvent when
288 // using cloneNode. Calling detachEvent on the
289 // clone will also remove the events from the orignal
290 // In order to get around this, we use innerHTML.
291 // Unfortunately, this means some modifications to
292 // attributes in IE that are actually only stored
293 // as properties will not be copied (such as the
294 // the name attribute on an input).
295 var clone = this.cloneNode(true),
296 container = document.createElement("div");
297 container.appendChild(clone);
298 return jQuery.clean([container.innerHTML])[0];
300 return this.cloneNode(true);
303 // Need to set the expando to null on the cloned set if it exists
304 // removeData doesn't work here, IE removes it from the original as well
305 // this is primarily for IE but the data expando shouldn't be copied over in any browser
306 var clone = ret.find("*").andSelf().each(function(){
307 if ( this[ expando ] !== undefined )
308 this[ expando ] = null;
311 // Copy the events from the original to the clone
312 if ( events === true )
313 this.find("*").andSelf().each(function(i){
314 if (this.nodeType == 3)
316 var events = jQuery.data( this, "events" );
318 for ( var type in events )
319 for ( var handler in events[ type ] )
320 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
323 // Return the cloned set
327 filter: function( selector ) {
328 return this.pushStack(
329 jQuery.isFunction( selector ) &&
330 jQuery.grep(this, function(elem, i){
331 return selector.call( elem, i );
334 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
335 return elem.nodeType === 1;
336 }) ), "filter", selector );
339 closest: function( selector ) {
340 return this.map(function(){
342 while ( cur && cur.ownerDocument ) {
343 if ( jQuery(cur).is(selector) )
345 cur = cur.parentNode;
350 not: function( selector ) {
351 if ( typeof selector === "string" )
352 // test special case where just one selector is passed in
353 if ( isSimple.test( selector ) )
354 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
356 selector = jQuery.multiFilter( selector, this );
358 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
359 return this.filter(function() {
360 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
364 add: function( selector ) {
365 return this.pushStack( jQuery.unique( jQuery.merge(
367 typeof selector === "string" ?
369 jQuery.makeArray( selector )
373 is: function( selector ) {
374 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
377 hasClass: function( selector ) {
378 return !!selector && this.is( "." + selector );
381 val: function( value ) {
382 if ( value === undefined ) {
386 if( jQuery.nodeName( elem, 'option' ) )
387 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
389 // We need to handle select boxes special
390 if ( jQuery.nodeName( elem, "select" ) ) {
391 var index = elem.selectedIndex,
393 options = elem.options,
394 one = elem.type == "select-one";
396 // Nothing was selected
400 // Loop through all the selected options
401 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
402 var option = options[ i ];
404 if ( option.selected ) {
405 // Get the specifc value for the option
406 value = jQuery(option).val();
408 // We don't need an array for one selects
412 // Multi-Selects return an array
413 values.push( value );
420 // Everything else, we just grab the value
421 return (elem.value || "").replace(/\r/g, "");
428 if ( typeof value === "number" )
431 return this.each(function(){
432 if ( this.nodeType != 1 )
435 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
436 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
437 jQuery.inArray(this.name, value) >= 0);
439 else if ( jQuery.nodeName( this, "select" ) ) {
440 var values = jQuery.makeArray(value);
442 jQuery( "option", this ).each(function(){
443 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
444 jQuery.inArray( this.text, values ) >= 0);
447 if ( !values.length )
448 this.selectedIndex = -1;
455 html: function( value ) {
456 return value === undefined ?
460 this.empty().append( value );
463 replaceWith: function( value ) {
464 return this.after( value ).remove();
468 return this.slice( i, +i + 1 );
472 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
473 "slice", Array.prototype.slice.call(arguments).join(",") );
476 map: function( callback ) {
477 return this.pushStack( jQuery.map(this, function(elem, i){
478 return callback.call( elem, i, elem );
482 andSelf: function() {
483 return this.add( this.prevObject );
486 data: function( key, value ){
487 var parts = key.split(".");
488 parts[1] = parts[1] ? "." + parts[1] : "";
490 if ( value === undefined ) {
491 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
493 if ( data === undefined && this.length )
494 data = jQuery.data( this[0], key );
496 return data == null && parts[1] ?
497 this.data( parts[0] ) :
500 return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
501 jQuery.data( this, key, value );
505 removeData: function( key ){
506 return this.each(function(){
507 jQuery.removeData( this, key );
511 domManip: function( args, table, callback ) {
513 var fragment = this[0].ownerDocument.createDocumentFragment(),
514 scripts = jQuery.clean( args, this[0].ownerDocument, fragment ),
515 first = fragment.firstChild,
516 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
519 for ( var i = 0, l = this.length; i < l; i++ )
520 callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
523 jQuery.each( scripts, evalScript );
528 function root( elem, cur ) {
529 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
530 (elem.getElementsByTagName("tbody")[0] ||
531 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
537 // Give the init function the jQuery prototype for later instantiation
538 jQuery.fn.init.prototype = jQuery.fn;
540 function evalScript( i, elem ) {
549 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
551 if ( elem.parentNode )
552 elem.parentNode.removeChild( elem );
559 jQuery.extend = jQuery.fn.extend = function() {
560 // copy reference to target object
561 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
563 // Handle a deep copy situation
564 if ( typeof target === "boolean" ) {
566 target = arguments[1] || {};
567 // skip the boolean and the target
571 // Handle case when target is a string or something (possible in deep copy)
572 if ( typeof target !== "object" && !jQuery.isFunction(target) )
575 // extend jQuery itself if only one argument is passed
581 for ( ; i < length; i++ )
582 // Only deal with non-null/undefined values
583 if ( (options = arguments[ i ]) != null )
584 // Extend the base object
585 for ( var name in options ) {
586 var src = target[ name ], copy = options[ name ];
588 // Prevent never-ending loop
589 if ( target === copy )
592 // Recurse if we're merging object values
593 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
594 target[ name ] = jQuery.extend( deep,
595 // Never move original objects, clone them
596 src || ( copy.length != null ? [ ] : { } )
599 // Don't bring in undefined values
600 else if ( copy !== undefined )
601 target[ name ] = copy;
605 // Return the modified object
609 var expando = "jQuery" + now(), uuid = 0, windowData = {},
610 // exclude the following css properties to add px
611 exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
613 defaultView = document.defaultView || {},
614 toString = Object.prototype.toString;
617 noConflict: function( deep ) {
621 window.jQuery = _jQuery;
626 // See test/unit/core.js for details concerning isFunction.
627 // Since version 1.3, DOM methods and functions like alert
628 // aren't supported. They return false on IE (#2968).
629 isFunction: function( obj ) {
630 return toString.call(obj) === "[object Function]";
633 isArray: function( obj ) {
634 return toString.call(obj) === "[object Array]";
637 // check if an element is in a (or is an) XML document
638 isXMLDoc: function( elem ) {
639 return elem.documentElement && !elem.body ||
640 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
643 // Evalulates a script in a global context
644 globalEval: function( data ) {
645 data = jQuery.trim( data );
648 // Inspired by code by Andrea Giammarchi
649 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
650 var head = document.getElementsByTagName("head")[0] || document.documentElement,
651 script = document.createElement("script");
653 script.type = "text/javascript";
654 if ( jQuery.support.scriptEval )
655 script.appendChild( document.createTextNode( data ) );
659 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
660 // This arises when a base node is used (#2709).
661 head.insertBefore( script, head.firstChild );
662 head.removeChild( script );
666 nodeName: function( elem, name ) {
667 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
672 data: function( elem, name, data ) {
673 elem = elem == window ?
677 var id = elem[ expando ];
679 // Compute a unique ID for the element
681 id = elem[ expando ] = ++uuid;
683 // Only generate the data cache if we're
684 // trying to access or manipulate it
685 if ( name && !jQuery.cache[ id ] )
686 jQuery.cache[ id ] = {};
688 // Prevent overriding the named cache with undefined values
689 if ( data !== undefined )
690 jQuery.cache[ id ][ name ] = data;
692 // Return the named cache data, or the ID for the element
694 jQuery.cache[ id ][ name ] || null :
698 removeData: function( elem, name ) {
699 elem = elem == window ?
703 var id = elem[ expando ];
705 // If we want to remove a specific section of the element's data
707 if ( jQuery.cache[ id ] ) {
708 // Remove the section of cache data
709 delete jQuery.cache[ id ][ name ];
711 // If we've removed all the data, remove the element's cache
714 for ( name in jQuery.cache[ id ] )
718 jQuery.removeData( elem );
721 // Otherwise, we want to remove all of the element's data
723 // Clean up the element expando
725 delete elem[ expando ];
727 // IE has trouble directly removing the expando
728 // but it's ok with using removeAttribute
729 if ( elem.removeAttribute )
730 elem.removeAttribute( expando );
733 // Completely remove the data cache
734 delete jQuery.cache[ id ];
738 // args is for internal usage only
739 each: function( object, callback, args ) {
740 var name, i = 0, length = object.length;
743 if ( length === undefined ) {
744 for ( name in object )
745 if ( callback.apply( object[ name ], args ) === false )
748 for ( ; i < length; )
749 if ( callback.apply( object[ i++ ], args ) === false )
752 // A special, fast, case for the most common use of each
754 if ( length === undefined ) {
755 for ( name in object )
756 if ( callback.call( object[ name ], name, object[ name ] ) === false )
759 for ( var value = object[0];
760 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
766 prop: function( elem, value, type, i, name ) {
767 // Handle executable functions
768 if ( jQuery.isFunction( value ) )
769 value = value.call( elem, i );
771 // Handle passing in a number to a CSS property
772 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
778 // internal only, use addClass("class")
779 add: function( elem, classNames ) {
780 jQuery.each((classNames || "").split(/\s+/), function(i, className){
781 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
782 elem.className += (elem.className ? " " : "") + className;
786 // internal only, use removeClass("class")
787 remove: function( elem, classNames ) {
788 if (elem.nodeType == 1)
789 elem.className = classNames !== undefined ?
790 jQuery.grep(elem.className.split(/\s+/), function(className){
791 return !jQuery.className.has( classNames, className );
796 // internal only, use hasClass("class")
797 has: function( elem, className ) {
798 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
802 // A method for quickly swapping in/out CSS properties to get correct calculations
803 swap: function( elem, options, callback ) {
805 // Remember the old values, and insert the new ones
806 for ( var name in options ) {
807 old[ name ] = elem.style[ name ];
808 elem.style[ name ] = options[ name ];
811 callback.call( elem );
813 // Revert the old values
814 for ( var name in options )
815 elem.style[ name ] = old[ name ];
818 css: function( elem, name, force ) {
819 if ( name == "width" || name == "height" ) {
820 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
823 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
824 var padding = 0, border = 0;
825 jQuery.each( which, function() {
826 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
827 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
829 val -= Math.round(padding + border);
832 if ( jQuery(elem).is(":visible") )
835 jQuery.swap( elem, props, getWH );
837 return Math.max(0, val);
840 return jQuery.curCSS( elem, name, force );
843 curCSS: function( elem, name, force ) {
844 var ret, style = elem.style;
846 // We need to handle opacity special in IE
847 if ( name == "opacity" && !jQuery.support.opacity ) {
848 ret = jQuery.attr( style, "opacity" );
855 // Make sure we're using the right name for getting the float value
856 if ( name.match( /float/i ) )
859 if ( !force && style && style[ name ] )
862 else if ( defaultView.getComputedStyle ) {
864 // Only "float" is needed here
865 if ( name.match( /float/i ) )
868 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
870 var computedStyle = defaultView.getComputedStyle( elem, null );
873 ret = computedStyle.getPropertyValue( name );
875 // We should always get a number back from opacity
876 if ( name == "opacity" && ret == "" )
879 } else if ( elem.currentStyle ) {
880 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
881 return letter.toUpperCase();
884 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
886 // From the awesome hack by Dean Edwards
887 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
889 // If we're not dealing with a regular pixel number
890 // but a number that has a weird ending, we need to convert it to pixels
891 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
892 // Remember the original values
893 var left = style.left, rsLeft = elem.runtimeStyle.left;
895 // Put in the new values to get a computed value out
896 elem.runtimeStyle.left = elem.currentStyle.left;
897 style.left = ret || 0;
898 ret = style.pixelLeft + "px";
900 // Revert the changed values
902 elem.runtimeStyle.left = rsLeft;
909 clean: function( elems, context, fragment ) {
910 context = context || document;
912 // !context.createElement fails in IE with an error but returns typeof 'object'
913 if ( typeof context.createElement === "undefined" )
914 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
916 var ret = [], scripts = [], div = context.createElement("div");
918 jQuery.each(elems, function(i, elem){
919 if ( typeof elem === "number" )
925 // Convert html string into DOM nodes
926 if ( typeof elem === "string" ) {
927 // Fix "XHTML"-style tags in all browsers
928 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
929 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
931 front + "></" + tag + ">";
934 // Trim whitespace, otherwise indexOf won't work as expected
935 var tags = jQuery.trim( elem ).toLowerCase();
938 // option or optgroup
939 !tags.indexOf("<opt") &&
940 [ 1, "<select multiple='multiple'>", "</select>" ] ||
942 !tags.indexOf("<leg") &&
943 [ 1, "<fieldset>", "</fieldset>" ] ||
945 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
946 [ 1, "<table>", "</table>" ] ||
948 !tags.indexOf("<tr") &&
949 [ 2, "<table><tbody>", "</tbody></table>" ] ||
951 // <thead> matched above
952 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
953 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
955 !tags.indexOf("<col") &&
956 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
958 // IE can't serialize <link> and <script> tags normally
959 !jQuery.support.htmlSerialize &&
960 [ 1, "div<div>", "</div>" ] ||
964 // Go to html and back, then peel off extra wrappers
965 div.innerHTML = wrap[1] + elem + wrap[2];
967 // Move to the right depth
971 // Remove IE's autoinserted <tbody> from table fragments
972 if ( !jQuery.support.tbody ) {
974 // String was a <table>, *may* have spurious <tbody>
975 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
976 div.firstChild && div.firstChild.childNodes :
978 // String was a bare <thead> or <tfoot>
979 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
983 for ( var j = tbody.length - 1; j >= 0 ; --j )
984 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
985 tbody[ j ].parentNode.removeChild( tbody[ j ] );
989 // IE completely kills leading whitespace when innerHTML is used
990 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
991 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
994 var found = div.getElementsByTagName("script");
996 while ( found.length ) {
997 scripts.push( found[0] );
998 found[0].parentNode.removeChild( found[0] );
1002 elem = jQuery.makeArray( div.childNodes );
1005 if ( elem.nodeType )
1008 ret = jQuery.merge( ret, elem );
1016 for ( var i = 0; ret[i]; i++ ) {
1018 if ( jQuery.nodeName( node, "script" ) ) {
1019 if( node.parentNode )
1020 node.parentNode.removeChild( node );
1022 if ( node.nodeType === 1 )
1023 ret = jQuery.merge( ret, node.getElementsByTagName("script"));
1024 fragment.appendChild( node );
1034 attr: function( elem, name, value ) {
1035 // don't set attributes on text and comment nodes
1036 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
1039 var notxml = !jQuery.isXMLDoc( elem ),
1040 // Whether we are setting (or getting)
1041 set = value !== undefined;
1043 // Try to normalize/fix the name
1044 name = notxml && jQuery.props[ name ] || name;
1046 // Only do all the following if this is a node (faster for style)
1047 // IE elem.getAttribute passes even for style
1048 if ( elem.tagName ) {
1050 // These attributes require special treatment
1051 var special = /href|src|style/.test( name );
1053 // Safari mis-reports the default selected property of a hidden option
1054 // Accessing the parent's selectedIndex property fixes it
1055 if ( name == "selected" )
1056 elem.parentNode.selectedIndex;
1058 // If applicable, access the attribute via the DOM 0 way
1059 if ( name in elem && notxml && !special ) {
1061 // We can't allow the type property to be changed (since it causes problems in IE)
1062 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
1063 throw "type property can't be changed";
1065 elem[ name ] = value;
1068 // browsers index elements by id/name on forms, give priority to attributes.
1069 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
1070 return elem.getAttributeNode( name ).nodeValue;
1072 return elem[ name ];
1075 if ( !jQuery.support.style && notxml && name == "style" )
1076 return jQuery.attr( elem.style, "cssText", value );
1079 // convert the value to a string (all browsers do this but IE) see #1070
1080 elem.setAttribute( name, "" + value );
1082 var attr = !jQuery.support.hrefNormalized && notxml && special
1083 // Some attributes require a special call on IE
1084 ? elem.getAttribute( name, 2 )
1085 : elem.getAttribute( name );
1087 // Non-existent attributes return null, we normalize to undefined
1088 return attr === null ? undefined : attr;
1091 // elem is actually elem.style ... set the style
1093 // IE uses filters for opacity
1094 if ( !jQuery.support.opacity && name == "opacity" ) {
1096 // IE has trouble with opacity if it does not have layout
1097 // Force it by setting the zoom level
1100 // Set the alpha filter to set the opacity
1101 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1102 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1105 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1106 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1110 name = name.replace(/-([a-z])/ig, function(all, letter){
1111 return letter.toUpperCase();
1115 elem[ name ] = value;
1117 return elem[ name ];
1120 trim: function( text ) {
1121 return (text || "").replace( /^\s+|\s+$/g, "" );
1124 makeArray: function( array ) {
1127 if( array != null ){
1128 var i = array.length;
1129 // The window, strings (and functions) also have 'length'
1130 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1134 ret[--i] = array[i];
1140 inArray: function( elem, array ) {
1141 for ( var i = 0, length = array.length; i < length; i++ )
1142 // Use === because on IE, window == document
1143 if ( array[ i ] === elem )
1149 merge: function( first, second ) {
1150 // We have to loop this way because IE & Opera overwrite the length
1151 // expando of getElementsByTagName
1152 var i = 0, elem, pos = first.length;
1153 // Also, we need to make sure that the correct elements are being returned
1154 // (IE returns comment nodes in a '*' query)
1155 if ( !jQuery.support.getAll ) {
1156 while ( (elem = second[ i++ ]) != null )
1157 if ( elem.nodeType != 8 )
1158 first[ pos++ ] = elem;
1161 while ( (elem = second[ i++ ]) != null )
1162 first[ pos++ ] = elem;
1167 unique: function( array ) {
1168 var ret = [], done = {};
1172 for ( var i = 0, length = array.length; i < length; i++ ) {
1173 var id = jQuery.data( array[ i ] );
1175 if ( !done[ id ] ) {
1177 ret.push( array[ i ] );
1188 grep: function( elems, callback, inv ) {
1191 // Go through the array, only saving the items
1192 // that pass the validator function
1193 for ( var i = 0, length = elems.length; i < length; i++ )
1194 if ( !inv != !callback( elems[ i ], i ) )
1195 ret.push( elems[ i ] );
1200 map: function( elems, callback ) {
1203 // Go through the array, translating each of the items to their
1204 // new value (or values).
1205 for ( var i = 0, length = elems.length; i < length; i++ ) {
1206 var value = callback( elems[ i ], i );
1208 if ( value != null )
1209 ret[ ret.length ] = value;
1212 return ret.concat.apply( [], ret );
1216 // Use of jQuery.browser is deprecated.
1217 // It's included for backwards compatibility and plugins,
1218 // although they should work to migrate away.
1220 var userAgent = navigator.userAgent.toLowerCase();
1222 // Figure out what browser is being used
1224 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1225 safari: /webkit/.test( userAgent ),
1226 opera: /opera/.test( userAgent ),
1227 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1228 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1231 // Check to see if the W3C box model is being used
1232 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1235 parent: function(elem){return elem.parentNode;},
1236 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1237 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1238 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1239 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1240 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1241 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1242 children: function(elem){return jQuery.sibling(elem.firstChild);},
1243 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1244 }, function(name, fn){
1245 jQuery.fn[ name ] = function( selector ) {
1246 var ret = jQuery.map( this, fn );
1248 if ( selector && typeof selector == "string" )
1249 ret = jQuery.multiFilter( selector, ret );
1251 return this.pushStack( jQuery.unique( ret ), name, selector );
1257 prependTo: "prepend",
1258 insertBefore: "before",
1259 insertAfter: "after",
1260 replaceAll: "replaceWith"
1261 }, function(name, original){
1262 jQuery.fn[ name ] = function() {
1263 var args = arguments;
1265 return this.each(function(){
1266 for ( var i = 0, length = args.length; i < length; i++ )
1267 jQuery( args[ i ] )[ original ]( this );
1273 removeAttr: function( name ) {
1274 jQuery.attr( this, name, "" );
1275 if (this.nodeType == 1)
1276 this.removeAttribute( name );
1279 addClass: function( classNames ) {
1280 jQuery.className.add( this, classNames );
1283 removeClass: function( classNames ) {
1284 jQuery.className.remove( this, classNames );
1287 toggleClass: function( classNames, state ) {
1288 if( typeof state !== "boolean" )
1289 state = !jQuery.className.has( this, classNames );
1290 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1293 remove: function( selector ) {
1294 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1295 // Prevent memory leaks
1296 jQuery( "*", this ).add([this]).each(function(){
1297 jQuery.event.remove(this);
1298 jQuery.removeData(this);
1300 if (this.parentNode)
1301 this.parentNode.removeChild( this );
1306 // Remove element nodes and prevent memory leaks
1307 jQuery( ">*", this ).remove();
1309 // Remove any remaining nodes
1310 while ( this.firstChild )
1311 this.removeChild( this.firstChild );
1313 }, function(name, fn){
1314 jQuery.fn[ name ] = function(){
1315 return this.each( fn, arguments );
1319 // Helper function used by the dimensions and offset modules
1320 function num(elem, prop) {
1321 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;