Changeset 5577
- Timestamp:
- 05/13/08 01:45:58 (3 months ago)
- Location:
- trunk/jquery/src
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/src/ajax.js
r5501 r5577 2 2 // Keep a copy of the old load 3 3 _load: jQuery.fn.load, 4 4 5 5 load: function( url, params, callback ) { 6 6 if ( typeof url != 'string' ) … … 72 72 }) 73 73 .filter(function(){ 74 return this.name && !this.disabled && 75 (this.checked || /select|textarea/i.test(this.nodeName) || 74 return this.name && !this.disabled && 75 (this.checked || /select|textarea/i.test(this.nodeName) || 76 76 /text|hidden|password/i.test(this.type)); 77 77 }) … … 104 104 data = null; 105 105 } 106 106 107 107 return jQuery.ajax({ 108 108 type: "GET", … … 160 160 } 161 161 }, 162 162 163 163 // Last-Modified header cache for next request 164 164 lastModified: {}, … … 249 249 // Attach handlers for all browsers 250 250 script.onload = script.onreadystatechange = function(){ 251 if ( !done && (!this.readyState || 251 if ( !done && (!this.readyState || 252 252 this.readyState == "loaded" || this.readyState == "complete") ) { 253 253 done = true; … … 302 302 return false; 303 303 } 304 304 305 305 if ( s.global ) 306 306 jQuery.event.trigger("ajaxSend", [xml, s]); … … 311 311 if ( !requestDone && xml && (xml.readyState == 4 || isTimeout == "timeout") ) { 312 312 requestDone = true; 313 313 314 314 // clear poll interval 315 315 if (ival) { … … 317 317 ival = null; 318 318 } 319 319 320 320 status = isTimeout == "timeout" && "timeout" || 321 321 !jQuery.httpSuccess( xml ) && "error" || … … 340 340 modRes = xml.getResponseHeader("Last-Modified"); 341 341 } catch(e) {} // swallow exception thrown by FF if header is not available 342 342 343 343 if ( s.ifModified && modRes ) 344 344 jQuery.lastModified[s.url] = modRes; … … 346 346 // JSONP handles its own success callback 347 347 if ( !jsonp ) 348 success(); 348 success(); 349 349 } else 350 350 jQuery.handleError(s, xml, status); … … 358 358 } 359 359 }; 360 360 361 361 if ( s.async ) { 362 362 // don't attach the handler to the request, just poll it instead 363 var ival = setInterval(onreadystatechange, 13); 363 var ival = setInterval(onreadystatechange, 13); 364 364 365 365 // Timeout checker … … 370 370 // Cancel the request 371 371 xml.abort(); 372 372 373 373 if( !requestDone ) 374 374 onreadystatechange( "timeout" ); … … 376 376 }, s.timeout); 377 377 } 378 378 379 379 // Send the data 380 380 try { … … 383 383 jQuery.handleError(s, xml, null, e); 384 384 } 385 385 386 386 // firefox 1.5 doesn't fire statechange for sync requests 387 387 if ( !s.async ) … … 411 411 jQuery.event.trigger( "ajaxStop" ); 412 412 } 413 413 414 414 // return XMLHttpRequest to allow aborting the request etc. 415 415 return xml; -
trunk/jquery/src/core.js
r5575 r5577 12 12 // Map over jQuery in case of overwrite 13 13 var _jQuery = window.jQuery, 14 // Map over the $ in case of overwrite 14 // Map over the $ in case of overwrite 15 15 _$ = window.$; 16 16 … … 27 27 isSimple = /^.[^:#\[\.]*$/, 28 28 29 // Will speed up references to undefined, and allows munging its name. 29 // Will speed up references to undefined, and allows munging its name. 30 30 undefined; 31 31 … … 79 79 } else if ( jQuery.isFunction( selector ) ) 80 80 return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector ); 81 81 82 82 return this.setArray(jQuery.makeArray(selector)); 83 83 }, 84 84 85 85 // The current version of jQuery being used 86 86 jquery: "@VERSION", … … 90 90 return this.length; 91 91 }, 92 92 93 93 // The number of elements contained in the matched element set 94 94 length: 0, … … 105 105 this[ num ]; 106 106 }, 107 107 108 108 // Take an array of elements and push it onto the stack 109 109 // (returning the new matched element set) … … 118 118 return ret; 119 119 }, 120 120 121 121 // Force the current matched set of elements to become 122 122 // the specified array of elements (destroying the stack in the process) … … 127 127 this.length = 0; 128 128 Array.prototype.push.apply( this, elems ); 129 129 130 130 return this; 131 131 }, … … 138 138 }, 139 139 140 // Determine the position of an element within 140 // Determine the position of an element within 141 141 // the matched set of elements 142 142 index: function( elem ) { … … 144 144 145 145 // Locate the position of the desired element 146 return jQuery.inArray( 146 return jQuery.inArray( 147 147 // If it receives a jQuery object, the first element is used 148 148 elem && elem.jquery ? elem[0] : elem … … 152 152 attr: function( name, value, type ) { 153 153 var options = name; 154 154 155 155 // Look for the case where we're accessing a style value 156 156 if ( name.constructor == String ) … … 162 162 options[ name ] = value; 163 163 } 164 164 165 165 // Check to see if we're setting style values 166 166 return this.each(function(i){ … … 245 245 }); 246 246 }, 247 247 248 248 before: function() { 249 249 return this.domManip(arguments, false, false, function(elem){ … … 280 280 // clone will also remove the events from the orignal 281 281 // In order to get around this, we use innerHTML. 282 // Unfortunately, this means some modifications to 283 // attributes in IE that are actually only stored 282 // Unfortunately, this means some modifications to 283 // attributes in IE that are actually only stored 284 284 // as properties will not be copied (such as the 285 285 // the name attribute on an input). … … 299 299 this[ expando ] = null; 300 300 }); 301 301 302 302 // Copy the events from the original to the clone 303 303 if ( events === true ) … … 341 341 342 342 add: function( selector ) { 343 return this.pushStack( jQuery.unique( jQuery.merge( 343 return this.pushStack( jQuery.unique( jQuery.merge( 344 344 this.get(), 345 typeof selector == 'string' ? 345 typeof selector == 'string' ? 346 346 jQuery( selector ) : 347 347 jQuery.makeArray( selector ) … … 356 356 return this.is( "." + selector ); 357 357 }, 358 358 359 359 val: function( value ) { 360 360 if ( value == undefined ) { … … 369 369 options = elem.options, 370 370 one = elem.type == "select-one"; 371 371 372 372 // Nothing was selected 373 373 if ( index < 0 ) … … 381 381 // Get the specifc value for the option 382 382 value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value; 383 383 384 384 // We don't need an array for one selects 385 385 if ( one ) 386 386 return value; 387 387 388 388 // Multi-Selects return an array 389 389 values.push( value ); 390 390 } 391 391 } 392 392 393 393 return values; 394 394 395 395 // Everything else, we just grab the value 396 396 } else … … 427 427 }); 428 428 }, 429 429 430 430 html: function( value ) { 431 431 return value == undefined ? … … 464 464 if ( value === undefined ) { 465 465 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); 466 466 467 467 if ( data === undefined && this.length ) 468 468 data = jQuery.data( this[0], key ); … … 482 482 }); 483 483 }, 484 484 485 485 domManip: function( args, table, reverse, callback ) { 486 var clone = this.length > 1, elems; 486 var clone = this.length > 1, elems; 487 487 488 488 return this.each(function(){ … … 573 573 // Extend the base object 574 574 for ( var name in options ) { 575 var src = target[ name ], copy = options[ name ]; 576 575 var src = target[ name ], copy = options[ name ]; 576 577 577 // Prevent never-ending loop 578 578 if ( target === copy ) … … 612 612 // See test/unit/core.js for details concerning this function. 613 613 isFunction: function( fn ) { 614 return !!fn && typeof fn != "string" && !fn.nodeName && 614 return !!fn && typeof fn != "string" && !fn.nodeName && 615 615 fn.constructor != Array && /function/i.test( fn + "" ); 616 616 }, 617 617 618 618 // check if an element is in a (or is an) XML document 619 619 isXMLDoc: function( elem ) { … … 646 646 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); 647 647 }, 648 648 649 649 cache: {}, 650 650 651 651 data: function( elem, name, data ) { 652 652 elem = elem == window ? … … 657 657 658 658 // Compute a unique ID for the element 659 if ( !id ) 659 if ( !id ) 660 660 id = elem[ expando ] = ++uuid; 661 661 … … 664 664 if ( name && !jQuery.cache[ id ] ) 665 665 jQuery.cache[ id ] = {}; 666 666 667 667 // Prevent overriding the named cache with undefined values 668 668 if ( data !== undefined ) 669 669 jQuery.cache[ id ][ name ] = data; 670 671 // Return the named cache data, or the ID for the element 670 671 // Return the named cache data, or the ID for the element 672 672 return name ? 673 673 jQuery.cache[ id ][ name ] : 674 674 id; 675 675 }, 676 676 677 677 removeData: function( elem, name ) { 678 678 elem = elem == window ? … … 718 718 each: function( object, callback, args ) { 719 719 var name, i = 0, length = object.length; 720 720 721 721 if ( args ) { 722 722 if ( length == undefined ) { … … 736 736 break; 737 737 } else 738 for ( var value = object[0]; 738 for ( var value = object[0]; 739 739 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){} 740 740 } … … 742 742 return object; 743 743 }, 744 744 745 745 prop: function( elem, value, type, i, name ) { 746 746 // Handle executable functions 747 747 if ( jQuery.isFunction( value ) ) 748 748 value = value.call( elem, i ); 749 749 750 750 // Handle passing in a number to a CSS property 751 751 return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ? … … 768 768 elem.className = classNames != undefined ? 769 769 jQuery.grep(elem.className.split(/\s+/), function(className){ 770 return !jQuery.className.has( classNames, className ); 770 return !jQuery.className.has( classNames, className ); 771 771 }).join(" ") : 772 772 ""; … … 798 798 if ( name == "width" || name == "height" ) { 799 799 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; 800 800 801 801 function getWH() { 802 802 val = name == "width" ? elem.offsetWidth : elem.offsetHeight; … … 808 808 val -= Math.round(padding + border); 809 809 } 810 810 811 811 if ( jQuery(elem).is(":visible") ) 812 812 getWH(); 813 813 else 814 814 jQuery.swap( elem, props, getWH ); 815 815 816 816 return Math.max(0, val); 817 817 } 818 818 819 819 return jQuery.curCSS( elem, name, force ); 820 820 }, … … 827 827 if ( !jQuery.browser.safari ) 828 828 return false; 829 829 830 830 // getComputedStyle is cached 831 831 var ret = getComputedStyle( elem, null ); … … 847 847 style.outline = save; 848 848 } 849 849 850 850 // Make sure we're using the right name for getting the float value 851 851 if ( name.match( /float/i ) ) … … 930 930 return ret; 931 931 }, 932 932 933 933 clean: function( elems, context ) { 934 934 var ret = []; 935 935 context = context || document; 936 936 // !context.createElement fails in IE with an error but returns typeof 'object' 937 if (typeof context.createElement == 'undefined') 937 if (typeof context.createElement == 'undefined') 938 938 context = context.ownerDocument || context[0] && context[0].ownerDocument || document; 939 939 … … 944 944 if ( elem.constructor == Number ) 945 945 elem += ''; 946 946 947 947 // Convert html string into DOM nodes 948 948 if ( typeof elem == "string" ) { … … 961 961 !tags.indexOf("<opt") && 962 962 [ 1, "<select multiple='multiple'>", "</select>" ] || 963 963 964 964 !tags.indexOf("<leg") && 965 965 [ 1, "<fieldset>", "</fieldset>" ] || 966 966 967 967 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) && 968 968 [ 1, "<table>", "</table>" ] || 969 969 970 970 !tags.indexOf("<tr") && 971 971 [ 2, "<table><tbody>", "</tbody></table>" ] || 972 972 973 973 // <thead> matched above 974 974 (!tags.indexOf("<td") || !tags.indexOf("<th")) && 975 975 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] || 976 976 977 977 !tags.indexOf("<col") && 978 978 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] || … … 981 981 jQuery.browser.msie && 982 982 [ 1, "div<div>", "</div>" ] || 983 983 984 984 [ 0, "", "" ]; 985 985 986 986 // Go to html and back, then peel off extra wrappers 987 987 div.innerHTML = wrap[1] + elem + wrap[2]; 988 988 989 989 // Move to the right depth 990 990 while ( wrap[0]-- ) 991 991 div = div.lastChild; 992 992 993 993 // Remove IE's autoinserted <tbody> from table fragments 994 994 if ( jQuery.browser.msie ) { 995 995 996 996 // String was a <table>, *may* have spurious <tbody> 997 997 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ? 998 998 div.firstChild && div.firstChild.childNodes : 999 999 1000 1000 // String was a bare <thead> or <tfoot> 1001 1001 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ? 1002 1002 div.childNodes : 1003 1003 []; 1004 1004 1005 1005 for ( var j = tbody.length - 1; j >= 0 ; --j ) 1006 1006 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) 1007 1007 tbody[ j ].parentNode.removeChild( tbody[ j ] ); 1008 1009 // IE completely kills leading whitespace when innerHTML is used 1010 if ( /^\s/.test( elem ) ) 1008 1009 // IE completely kills leading whitespace when innerHTML is used 1010 if ( /^\s/.test( elem ) ) 1011 1011 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild ); 1012 1012 1013 1013 } 1014 1014 1015 1015 elem = jQuery.makeArray( div.childNodes ); 1016 1016 } … … 1079 1079 elem.setAttribute( name, "" + value ); 1080 1080 1081 if ( msie && special && notxml ) 1081 if ( msie && special && notxml ) 1082 1082 return elem.getAttribute( name, 2 ); 1083 1083 … … 1093 1093 // IE has trouble with opacity if it does not have layout 1094 1094 // Force it by setting the zoom level 1095 elem.zoom = 1; 1095 elem.zoom = 1; 1096 1096 1097 1097 // Set the alpha filter to set the opacity … … 1114 1114 return elem[ name ]; 1115 1115 }, 1116 1116 1117 1117 trim: function( text ) { 1118 1118 return (text || "").replace( /^\s+|\s+$/g, "" ); … … 1225 1225 "styleFloat" : 1226 1226 "cssFloat"; 1227 1227 1228 1228 jQuery.extend({ 1229 1229 // Check to see if the W3C box model is being used 1230 1230 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat", 1231