From b850ab2b8e65eadd25093c81bbc67a881daa0488 Mon Sep 17 00:00:00 2001 From: John Resig Date: Sun, 21 Dec 2008 21:22:44 +0000 Subject: [PATCH] Added the new jQuery.support object and removed all uses of jQuery.browser from within jQuery itself (while simultaneously deprecating the use of jQuery.browser). --- Makefile | 1 + build.xml | 1 + src/ajax.js | 6 +-- src/core.js | 141 +++++++++-------------------------------------------- src/dimensions.js | 27 ++++++++++ src/event.js | 64 ++++++++++++------------ 6 files changed, 86 insertions(+), 154 deletions(-) diff --git a/Makefile b/Makefile index 05e8a42..c3a16b9 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ SPEED_DIR = ${PREFIX}/speed PLUG_DIR = ../plugins BASE_FILES = ${SRC_DIR}/core.js\ + ${SRC_DIR}/support.js\ ${SRC_DIR}/selector.js\ ${SRC_DIR}/event.js\ ${SRC_DIR}/ajax.js\ diff --git a/build.xml b/build.xml index 6ccb0af..ec081ce 100644 --- a/build.xml +++ b/build.xml @@ -35,6 +35,7 @@ + diff --git a/src/ajax.js b/src/ajax.js index d02d331..6c8a22e 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -459,8 +459,7 @@ jQuery.extend({ try { // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 return !xhr.status && location.protocol == "file:" || - ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223 || - jQuery.browser.safari && xhr.status === undefined; + ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223; } catch(e){} return false; }, @@ -471,8 +470,7 @@ jQuery.extend({ var xhrRes = xhr.getResponseHeader("Last-Modified"); // Firefox always returns 200. check Last-Modified date - return xhr.status == 304 || xhrRes == jQuery.lastModified[url] || - jQuery.browser.safari && xhr.status === undefined; + return xhr.status == 304 || xhrRes == jQuery.lastModified[url]; } catch(e){} return false; }, diff --git a/src/core.js b/src/core.js index ea043c8..7ddb2c5 100644 --- a/src/core.js +++ b/src/core.js @@ -285,7 +285,7 @@ jQuery.fn = jQuery.prototype = { clone: function( events ) { // Do the clone var ret = this.map(function(){ - if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { + if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) { // IE copies events bound via attachEvent when // using cloneNode. Calling detachEvent on the // clone will also remove the events from the orignal @@ -642,10 +642,10 @@ jQuery.extend({ script = document.createElement("script"); script.type = "text/javascript"; - if ( jQuery.browser.msie ) - script.text = data; - else + if ( jQuery.support.scriptEval ) script.appendChild( document.createTextNode( data ) ); + else + script.text = data; // Use insertBefore instead of appendChild to circumvent an IE6 bug. // This arises when a base node is used (#2709). @@ -834,30 +834,14 @@ jQuery.extend({ curCSS: function( elem, name, force ) { var ret, style = elem.style; - // A helper method for determining if an element's values are broken - function color( elem ) { - if ( !jQuery.browser.safari ) - return false; - - // defaultView is cached - var ret = defaultView.getComputedStyle( elem, null ); - return !ret || ret.getPropertyValue("color") == ""; - } - // We need to handle opacity special in IE - if ( name == "opacity" && jQuery.browser.msie ) { + if ( name == "opacity" && !jQuery.support.opacity ) { ret = jQuery.attr( style, "opacity" ); return ret == "" ? "1" : ret; } - // Opera sometimes will give the wrong display answer, this fixes it, see #2037 - if ( jQuery.browser.opera && name == "display" ) { - var save = style.outline; - style.outline = "0 solid black"; - style.outline = save; - } // Make sure we're using the right name for getting the float value if ( name.match( /float/i ) ) @@ -876,38 +860,9 @@ jQuery.extend({ var computedStyle = defaultView.getComputedStyle( elem, null ); - if ( computedStyle && !color( elem ) ) + if ( computedStyle ) ret = computedStyle.getPropertyValue( name ); - // If the element isn't reporting its values properly in Safari - // then some display: none elements are involved - else { - var swap = [], stack = [], a = elem, i = 0; - - // Locate all of the parent display: none elements - for ( ; a && color(a); a = a.parentNode ) - stack.unshift(a); - - // Go through and make them visible, but in reverse - // (It would be better if we knew the exact display type that they had) - for ( ; i < stack.length; i++ ) - if ( color( stack[ i ] ) ) { - swap[ i ] = stack[ i ].style.display; - stack[ i ].style.display = "block"; - } - - // Since we flip the display style, we have to handle that - // one special, otherwise get the value - ret = name == "display" && swap[ stack.length - 1 ] != null ? - "none" : - ( computedStyle && computedStyle.getPropertyValue( name ) ) || ""; - - // Finally, revert the display styles back - for ( i = 0; i < swap.length; i++ ) - if ( swap[ i ] != null ) - stack[ i ].style.display = swap[ i ]; - } - // We should always get a number back from opacity if ( name == "opacity" && ret == "" ) ret = "1"; @@ -991,7 +946,7 @@ jQuery.extend({ [ 2, "", "
" ] || // IE can't serialize and