Skip to content
Permalink
Browse files

Added the new jQuery.support object and removed all uses of jQuery.br…

…owser from within jQuery itself (while simultaneously deprecating the use of jQuery.browser).
  • Loading branch information
jeresig committed Dec 21, 2008
1 parent 8ee1708 commit b850ab2b8e65eadd25093c81bbc67a881daa0488
Showing with 86 additions and 154 deletions.
  1. +1 −0 Makefile
  2. +1 −0 build.xml
  3. +2 −4 src/ajax.js
  4. +24 −117 src/core.js
  5. +27 −0 src/dimensions.js
  6. +31 −33 src/event.js
@@ -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\
@@ -35,6 +35,7 @@
<concat destfile="${JQ}">
<fileset dir="${SRC_DIR}" includes="intro.js" />
<fileset dir="${SRC_DIR}" includes="core.js" />
<fileset dir="${SRC_DIR}" includes="support.js" />
<fileset dir="${SRC_DIR}" includes="selector.js" />
<fileset dir="${SRC_DIR}" includes="event.js" />
<fileset dir="${SRC_DIR}" includes="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;
},
@@ -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, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||

// IE can't serialize <link> and <script> tags normally
jQuery.browser.msie &&
!jQuery.support.htmlSerialize &&
[ 1, "div<div>", "</div>" ] ||

[ 0, "", "" ];
@@ -1004,7 +959,7 @@ jQuery.extend({
div = div.lastChild;

// Remove IE's autoinserted <tbody> from table fragments
if ( jQuery.browser.msie ) {
if ( !jQuery.support.tbody ) {

// String was a <table>, *may* have spurious <tbody>
var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
@@ -1019,11 +974,11 @@ jQuery.extend({
if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
tbody[ j ].parentNode.removeChild( tbody[ j ] );

// IE completely kills leading whitespace when innerHTML is used
if ( /^\s/.test( elem ) )
div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
}

}
// IE completely kills leading whitespace when innerHTML is used
if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );

if ( fragment ) {
var found = div.getElementsByTagName("script");
@@ -1068,8 +1023,7 @@ jQuery.extend({

var notxml = !jQuery.isXMLDoc( elem ),
// Whether we are setting (or getting)
set = value !== undefined,
msie = jQuery.browser.msie;
set = value !== undefined;

// Try to normalize/fix the name
name = notxml && jQuery.props[ name ] || name;
@@ -1083,7 +1037,7 @@ jQuery.extend({

// Safari mis-reports the default selected property of a hidden option
// Accessing the parent's selectedIndex property fixes it
if ( name == "selected" && jQuery.browser.safari )
if ( name == "selected" )
elem.parentNode.selectedIndex;

// If applicable, access the attribute via the DOM 0 way
@@ -1103,14 +1057,14 @@ jQuery.extend({
return elem[ name ];
}

if ( msie && notxml && name == "style" )
if ( !jQuery.support.style && notxml && name == "style" )
return jQuery.attr( elem.style, "cssText", value );

if ( set )
// convert the value to a string (all browsers do this but IE) see #1070
elem.setAttribute( name, "" + value );

var attr = msie && notxml && special
var attr = !jQuery.support.hrefNormalized && notxml && special
// Some attributes require a special call on IE
? elem.getAttribute( name, 2 )
: elem.getAttribute( name );
@@ -1122,7 +1076,7 @@ jQuery.extend({
// elem is actually elem.style ... set the style

// IE uses filters for opacity
if ( msie && name == "opacity" ) {
if ( !jQuery.support.opacity && name == "opacity" ) {
if ( set ) {
// IE has trouble with opacity if it does not have layout
// Force it by setting the zoom level
@@ -1183,7 +1137,7 @@ jQuery.extend({
var i = 0, elem, pos = first.length;
// Also, we need to make sure that the correct elements are being returned
// (IE returns comment nodes in a '*' query)
if ( jQuery.browser.msie ) {
if ( !jQuery.support.getAll ) {
while ( (elem = second[ i++ ]) )
if ( elem.nodeType != 8 )
first[ pos++ ] = elem;
@@ -1244,6 +1198,10 @@ jQuery.extend({
}
});

// Use of jQuery.browser is deprecated.
// It's included for backwards compatibility and plugins,
// although they should work to migrate away.

var userAgent = navigator.userAgent.toLowerCase();

// Figure out what browser is being used
@@ -1255,26 +1213,8 @@ jQuery.browser = {
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};

var styleFloat = jQuery.browser.msie ?
"styleFloat" :
"cssFloat";

jQuery.extend({
// Check to see if the W3C box model is being used
boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",

props: {
"for": "htmlFor",
"class": "className",
"float": styleFloat,
cssFloat: styleFloat,
styleFloat: styleFloat,
readonly: "readOnly",
maxlength: "maxLength",
cellspacing: "cellSpacing",
rowspan: "rowSpan"
}
});
// Check to see if the W3C box model is being used
jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";

jQuery.each({
parent: function(elem){return elem.parentNode;},
@@ -1359,39 +1299,6 @@ jQuery.each({
};
});

jQuery.each([ "Height", "Width" ], function(i, name){
var type = name.toLowerCase();

jQuery.fn[ type ] = function( size ) {
// Get window width or height
return this[0] == window ?
// Opera reports document.body.client[Width/Height] properly in both quirks and standards
jQuery.browser.opera && document.body.parentNode[ "client" + name ] ||

// Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
jQuery.browser.safari && window[ "inner" + name ] ||

// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :

// Get document width or height
this[0] == document ?
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
Math.max(
Math.max(document.body["scroll" + name], document.documentElement["scroll" + name]),
Math.max(document.body["offset" + name], document.documentElement["offset" + name])
) :

// Get or set width or height on the element
size === undefined ?
// Get width or height on the element
(this.length ? jQuery.css( this[0], type ) : null) :

// Set the width or height on the element (default to pixels if value is unitless)
this.css( type, typeof size === "string" ? size : size + "px" );
};
});

// Helper function used by the dimensions and offset modules
function num(elem, prop) {
return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;
@@ -19,5 +19,32 @@ jQuery.each([ "Height", "Width" ], function(i, name){
(margin ?
num(this, "margin" + tl) + num(this, "margin" + br) : 0);
};

var type = name.toLowerCase();

jQuery.fn[ type ] = function( size ) {
// Get window width or height
return this[0] == window ?
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] ||
document.body[ "client" + name ] :

// Get document width or height
this[0] == document ?
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
Math.max(
document.documentElement["client" + name],

This comment has been minimized.

Copy link
@BoltDoggy

BoltDoggy Feb 28, 2017

Why document.documentElement.clientHeight not document.body.clientHeight?

This comment has been minimized.

Copy link
@mgol

mgol Feb 28, 2017

Member

The latter wouldn't return the window height but body height which will usually be a lot larger. It's a completely different thing.

This comment has been minimized.

Copy link
@BoltDoggy

BoltDoggy Mar 1, 2017

I think that should get document height here, like document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight. Why get window height, I don't understand.

This comment has been minimized.

Copy link
@mgol

mgol Mar 1, 2017

Member

I've looked at the wrong thing. In any case, the comment above explains the reasoning.

If you see an issue, please report an issue with a test case, don't just comment on very old commits.

document.body["scroll" + name], document.documentElement["scroll" + name],
document.body["offset" + name], document.documentElement["offset" + name]
) :

// Get or set width or height on the element
size === undefined ?
// Get width or height on the element
(this.length ? jQuery.css( this[0], type ) : null) :

// Set the width or height on the element (default to pixels if value is unitless)
this.css( type, typeof size === "string" ? size : size + "px" );
};

});

0 comments on commit b850ab2

Please sign in to comment.
You can’t perform that action at this time.