diff options
author | jeresig <jeresig@gmail.com> | 2010-03-01 12:44:56 -0500 |
---|---|---|
committer | jeresig <jeresig@gmail.com> | 2010-03-01 12:44:56 -0500 |
commit | a18f682012ae8e63f3b43b39375b3c5ce0a561e3 (patch) | |
tree | e897c8e14067e1fd3ef7bd658f0ef91afdcf7d0a /src | |
parent | 5353c6bcc352c4d900cc76af110e56ee1e70ae0f (diff) | |
download | jquery-a18f682012ae8e63f3b43b39375b3c5ce0a561e3.tar.gz jquery-a18f682012ae8e63f3b43b39375b3c5ce0a561e3.zip |
Made some code tweaks related to running jQuery through JSLint (thanks to Lorin Larson for the JSLint run).
Diffstat (limited to 'src')
-rw-r--r-- | src/ajax.js | 12 | ||||
-rw-r--r-- | src/core.js | 2 | ||||
-rw-r--r-- | src/css.js | 53 | ||||
-rw-r--r-- | src/effects.js | 6 | ||||
-rw-r--r-- | src/event.js | 10 |
5 files changed, 45 insertions, 38 deletions
diff --git a/src/ajax.js b/src/ajax.js index 08fa08b31..e17dfa89a 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -278,8 +278,10 @@ jQuery.extend({ s.url += (rquery.test(s.url) ? "&" : "?") + s.data; } + jQuery.active++; + // Watch for a new set of requests - if ( s.global && ! jQuery.active++ ) { + if ( s.global && jQuery.active === 1 ) { jQuery.event.trigger( "ajaxStart" ); } @@ -386,7 +388,7 @@ jQuery.extend({ } if ( s.global ) { - trigger("ajaxSend", [xhr, s]); + contextTrigger("ajaxSend", [xhr, s]); } // Wait for a response to come back @@ -499,7 +501,7 @@ jQuery.extend({ // Fire the global callback if ( s.global ) { - trigger( "ajaxSuccess", [xhr, s] ); + contextTrigger( "ajaxSuccess", [xhr, s] ); } } @@ -511,7 +513,7 @@ jQuery.extend({ // The request was completed if ( s.global ) { - trigger( "ajaxComplete", [xhr, s] ); + contextTrigger( "ajaxComplete", [xhr, s] ); } // Handle the global AJAX counter @@ -520,7 +522,7 @@ jQuery.extend({ } } - function trigger(type, args) { + function contextTrigger(type, args) { (s.context ? jQuery(s.context) : jQuery.event).trigger(type, args); } diff --git a/src/core.js b/src/core.js index ba5d7f528..e2e60a9a7 100644 --- a/src/core.js +++ b/src/core.js @@ -693,7 +693,7 @@ jQuery.extend({ /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) || /(msie) ([\w.]+)/.exec( ua ) || !/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || - []; + []; return { browser: match[1] || "", version: match[2] || "0" }; }, diff --git a/src/css.js b/src/css.js index 5d31757b0..42d038a22 100644 --- a/src/css.js +++ b/src/css.js @@ -82,32 +82,13 @@ jQuery.extend({ css: function( elem, name, force, extra ) { if ( name === "width" || name === "height" ) { - var val, props = cssShow, which = name === "width" ? cssWidth : cssHeight; - - function getWH() { - val = name === "width" ? elem.offsetWidth : elem.offsetHeight; - - if ( extra === "border" ) { - return; - } - - jQuery.each( which, function() { - if ( !extra ) { - val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; - } - - if ( extra === "margin" ) { - val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0; - } else { - val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; - } - }); - } - if ( elem.offsetWidth !== 0 ) { - getWH(); + val = getWH( elem, name, extra ); + } else { - jQuery.swap( elem, props, getWH ); + jQuery.swap( elem, cssShow, function() { + val = getWH( elem, name, extra ); + }); } return Math.max(0, Math.round(val)); @@ -211,6 +192,30 @@ jQuery.extend({ } }); +function getWH( elem, name, extra ) { + var which = name === "width" ? cssWidth : cssHeight, + val = name === "width" ? elem.offsetWidth : elem.offsetHeight; + + if ( extra === "border" ) { + return val; + } + + jQuery.each( which, function() { + if ( !extra ) { + val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; + } + + if ( extra === "margin" ) { + val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0; + + } else { + val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; + } + }); + + return val; +} + if ( jQuery.expr && jQuery.expr.filters ) { jQuery.expr.filters.hidden = function( elem ) { var width = elem.offsetWidth, height = elem.offsetHeight, diff --git a/src/effects.js b/src/effects.js index 7fa734208..c84ff6a8a 100644 --- a/src/effects.js +++ b/src/effects.js @@ -443,9 +443,9 @@ jQuery.extend( jQuery.fx, { speeds: { slow: 600, - fast: 200, - // Default speed - _default: 400 + fast: 200, + // Default speed + _default: 400 }, step: { diff --git a/src/event.js b/src/event.js index b55208066..761665cb6 100644 --- a/src/event.js +++ b/src/event.js @@ -51,7 +51,7 @@ jQuery.event = { } var events = elemData.events = elemData.events || {}, - eventHandle = elemData.handle, eventHandle; + eventHandle = elemData.handle; if ( !eventHandle ) { elemData.handle = eventHandle = function() { @@ -980,10 +980,10 @@ jQuery.each(["live", "die"], function( i, name ) { if ( name === "live" ) { // bind live handler - context.each(function(){ - jQuery.event.add( this, liveConvert( type, selector ), + for ( var j = 0, l = context.length; j < l; j++ ) { + jQuery.event.add( context[j], liveConvert( type, selector ), { data: data, selector: selector, handler: fn, origType: type, origHandler: fn, preType: preType } ); - }); + } } else { // unbind live handler @@ -992,7 +992,7 @@ jQuery.each(["live", "die"], function( i, name ) { } return this; - } + }; }); function liveHandler( event ) { |