Made a number of spacing changes to bring the code more-inline with the jQuery Core Style Guideline.

This commit is contained in:
jeresig 2009-12-21 19:58:13 -05:00
parent 36c99dc0c7
commit 61e37d4149
14 changed files with 218 additions and 130 deletions

View file

@ -241,7 +241,11 @@ jQuery.extend({
complete(); complete();
// Garbage collect // Garbage collect
window[ jsonp ] = undefined; window[ jsonp ] = undefined;
try{ delete window[ jsonp ]; } catch(e){}
try {
delete window[ jsonp ];
} catch(e) {}
if ( head ) { if ( head ) {
head.removeChild( script ); head.removeChild( script );
} }

View file

@ -213,7 +213,9 @@ jQuery.each({
}, function( name, fn ) { }, function( name, fn ) {
jQuery.fn[ name ] = function( val, state ) { jQuery.fn[ name ] = function( val, state ) {
if ( jQuery.isFunction( val ) ) { if ( jQuery.isFunction( val ) ) {
return this.each(function() { jQuery(this)[ name ]( val.call(this), state ); }); return this.each(function() {
jQuery(this)[ name ]( val.call(this), state );
});
} }
return this.each( fn, arguments ); return this.each( fn, arguments );

View file

@ -379,7 +379,10 @@ jQuery.extend({
}, },
bindReady: function() { bindReady: function() {
if ( readyBound ) { return; } if ( readyBound ) {
return;
}
readyBound = true; readyBound = true;
// Catch cases where $(document).ready() is called after the // Catch cases where $(document).ready() is called after the

View file

@ -8,6 +8,10 @@ var rexclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
rnumpx = /^-?\d+(?:px)?$/i, rnumpx = /^-?\d+(?:px)?$/i,
rnum = /^-?\d/, rnum = /^-?\d/,
cssShow = { position: "absolute", visibility: "hidden", display:"block" },
cssWidth = [ "Left", "Right" ],
cssHeight = [ "Top", "Bottom" ],
// cache check for defaultView.getComputedStyle // cache check for defaultView.getComputedStyle
getComputedStyle = document.defaultView && document.defaultView.getComputedStyle, getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
// normalize float css property // normalize float css property
@ -78,12 +82,14 @@ jQuery.extend({
css: function( elem, name, force, extra ) { css: function( elem, name, force, extra ) {
if ( name === "width" || name === "height" ) { if ( name === "width" || name === "height" ) {
var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name === "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; var val, props = cssShow, which = name === "width" ? cssWidth : cssHeight;
function getWH() { function getWH() {
val = name === "width" ? elem.offsetWidth : elem.offsetHeight; val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
if ( extra === "border" ) { return; } if ( extra === "border" ) {
return;
}
jQuery.each( which, function() { jQuery.each( which, function() {
if ( !extra ) { if ( !extra ) {

View file

@ -1,3 +1,9 @@
var fcleanup = function( nm ) {
return nm.replace(/[^\w\s\.\|`]/g, function( ch ) {
return "\\" + ch;
});
};
/* /*
* A number of helper functions used for managing events. * A number of helper functions used for managing events.
* Many of the ideas behind this code originated from * Many of the ideas behind this code originated from
@ -142,7 +148,7 @@ jQuery.event = {
var namespaces = type.split("."); var namespaces = type.split(".");
type = namespaces.shift(); type = namespaces.shift();
var all = !namespaces.length, var all = !namespaces.length,
cleaned = jQuery.map( namespaces.slice(0).sort() , function(nm){ return nm.replace(/[^\w\s\.\|`]/g, function(ch){return "\\"+ch; }); }), cleaned = jQuery.map( namespaces.slice(0).sort(), fcleanup ),
namespace = new RegExp("(^|\\.)" + cleaned.join("\\.(?:.*\\.)?") + "(\\.|$)"), namespace = new RegExp("(^|\\.)" + cleaned.join("\\.(?:.*\\.)?") + "(\\.|$)"),
special = this.special[ type ] || {}; special = this.special[ type ] || {};
@ -403,10 +409,15 @@ jQuery.event = {
thisObject = proxy; thisObject = proxy;
proxy = undefined; proxy = undefined;
} }
// FIXME: Should proxy be redefined to be applied with thisObject if defined? // FIXME: Should proxy be redefined to be applied with thisObject if defined?
proxy = proxy || function() { return fn.apply( thisObject !== undefined ? thisObject : this, arguments ); }; proxy = proxy || function() {
return fn.apply( thisObject !== undefined ? thisObject : this, arguments );
};
// Set the guid of unique handler to the same of original handler, so it can be removed // Set the guid of unique handler to the same of original handler, so it can be removed
proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++; proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++;
// So proxy can be declared as an argument // So proxy can be declared as an argument
return proxy; return proxy;
}, },

View file

@ -383,7 +383,9 @@ jQuery.extend({
elem += ''; elem += '';
} }
if ( !elem ) { return; } if ( !elem ) {
return;
}
// Convert html string into DOM nodes // Convert html string into DOM nodes
if ( typeof elem === "string" && !rhtml.test( elem ) ) { if ( typeof elem === "string" && !rhtml.test( elem ) ) {

View file

@ -1,12 +1,17 @@
if ( "getBoundingClientRect" in document.documentElement ) { if ( "getBoundingClientRect" in document.documentElement ) {
jQuery.fn.offset = function( options ) { jQuery.fn.offset = function( options ) {
var elem = this[0]; var elem = this[0];
if ( !elem || !elem.ownerDocument ) { return null; }
if ( !elem || !elem.ownerDocument ) {
return null;
}
if ( options ) { if ( options ) {
return this.each(function() { return this.each(function() {
jQuery.offset.setOffset( this, options ); jQuery.offset.setOffset( this, options );
}); });
} }
if ( elem === elem.ownerDocument.body ) { if ( elem === elem.ownerDocument.body ) {
return jQuery.offset.bodyOffset( elem ); return jQuery.offset.bodyOffset( elem );
} }
@ -15,17 +20,24 @@ if ( "getBoundingClientRect" in document.documentElement ) {
clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
top = box.top + (self.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop ) - clientTop, top = box.top + (self.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop ) - clientTop,
left = box.left + (self.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft; left = box.left + (self.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft;
return { top: top, left: left }; return { top: top, left: left };
}; };
} else { } else {
jQuery.fn.offset = function( options ) { jQuery.fn.offset = function( options ) {
var elem = this[0]; var elem = this[0];
if ( !elem || !elem.ownerDocument ) { return null; }
if ( !elem || !elem.ownerDocument ) {
return null;
}
if ( options ) { if ( options ) {
return this.each(function() { return this.each(function() {
jQuery.offset.setOffset( this, options ); jQuery.offset.setOffset( this, options );
}); });
} }
if ( elem === elem.ownerDocument.body ) { if ( elem === elem.ownerDocument.body ) {
return jQuery.offset.bodyOffset( elem ); return jQuery.offset.bodyOffset( elem );
} }
@ -39,7 +51,9 @@ if ( "getBoundingClientRect" in document.documentElement ) {
top = elem.offsetTop, left = elem.offsetLeft; top = elem.offsetTop, left = elem.offsetLeft;
while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) { while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) { break; } if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) {
break;
}
computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle; computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle;
top -= elem.scrollTop; top -= elem.scrollTop;
@ -148,7 +162,9 @@ jQuery.offset = {
jQuery.fn.extend({ jQuery.fn.extend({
position: function() { position: function() {
if ( !this[0] ) { return null; } if ( !this[0] ) {
return null;
}
var elem = this[0], var elem = this[0],
@ -189,25 +205,30 @@ jQuery.fn.extend({
// Create scrollLeft and scrollTop methods // Create scrollLeft and scrollTop methods
jQuery.each( ['Left', 'Top'], function(i, name) { jQuery.each( ["Left", "Top"], function( i, name ) {
var method = 'scroll' + name; var method = "scroll" + name;
jQuery.fn[ method ] = function(val) { jQuery.fn[ method ] = function(val) {
var elem = this[0], win; var elem = this[0], win;
if ( !elem ) { return null; } if ( !elem ) {
return null;
}
if ( val !== undefined ) { if ( val !== undefined ) {
// Set the scroll offset // Set the scroll offset
return this.each(function() { return this.each(function() {
win = getWindow( this ); win = getWindow( this );
win ? if ( win ) {
win.scrollTo( win.scrollTo(
!i ? val : jQuery(win).scrollLeft(), !i ? val : jQuery(win).scrollLeft(),
i ? val : jQuery(win).scrollTop() i ? val : jQuery(win).scrollTop()
) : );
} else {
this[ method ] = val; this[ method ] = val;
}
}); });
} else { } else {
win = getWindow( elem ); win = getWindow( elem );

View file

@ -1,18 +1,24 @@
jQuery.extend({ jQuery.extend({
queue: function( elem, type, data ) { queue: function( elem, type, data ) {
if ( !elem ) { return; } if ( !elem ) {
return;
}
type = (type || "fx") + "queue"; type = (type || "fx") + "queue";
var q = jQuery.data( elem, type ); var q = jQuery.data( elem, type );
// Speed up dequeue by getting out quickly if this is just a lookup // Speed up dequeue by getting out quickly if this is just a lookup
if ( !data ) { return q || []; } if ( !data ) {
return q || [];
}
if ( !q || jQuery.isArray(data) ) { if ( !q || jQuery.isArray(data) ) {
q = jQuery.data( elem, type, jQuery.makeArray(data) ); q = jQuery.data( elem, type, jQuery.makeArray(data) );
} else { } else {
q.push( data ); q.push( data );
} }
return q; return q;
}, },
@ -22,14 +28,20 @@ jQuery.extend({
var queue = jQuery.queue( elem, type ), fn = queue.shift(); var queue = jQuery.queue( elem, type ), fn = queue.shift();
// If the fx queue is dequeued, always remove the progress sentinel // If the fx queue is dequeued, always remove the progress sentinel
if ( fn === "inprogress" ) { fn = queue.shift(); } if ( fn === "inprogress" ) {
fn = queue.shift();
}
if ( fn ) { if ( fn ) {
// Add a progress sentinel to prevent the fx queue from being // Add a progress sentinel to prevent the fx queue from being
// automatically dequeued // automatically dequeued
if ( type === "fx" ) { queue.unshift("inprogress"); } if ( type === "fx" ) {
queue.unshift("inprogress");
}
fn.call(elem, function() { jQuery.dequeue(elem, type); }); fn.call(elem, function() {
jQuery.dequeue(elem, type);
});
} }
} }
}); });

View file

@ -157,18 +157,45 @@ jQuery.fn.extend({
}); });
jQuery.each({ jQuery.each({
parent: function(elem){var parent = elem.parentNode; return parent && parent.nodeType !== 11 ? parent : null;}, parent: function( elem ) {
parents: function(elem){return jQuery.dir(elem,"parentNode");}, var parent = elem.parentNode;
parentsUntil: function(elem,i,until){return jQuery.dir(elem,"parentNode",until);}, return parent && parent.nodeType !== 11 ? parent : null;
next: function(elem){return jQuery.nth(elem,2,"nextSibling");}, },
prev: function(elem){return jQuery.nth(elem,2,"previousSibling");}, parents: function( elem ) {
nextAll: function(elem){return jQuery.dir(elem,"nextSibling");}, return jQuery.dir( elem, "parentNode" );
prevAll: function(elem){return jQuery.dir(elem,"previousSibling");}, },
nextUntil: function(elem,i,until){return jQuery.dir(elem,"nextSibling",until);}, parentsUntil: function( elem, i, until ) {
prevUntil: function(elem,i,until){return jQuery.dir(elem,"previousSibling",until);}, return jQuery.dir( elem, "parentNode", until );
siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);}, },
children: function(elem){return jQuery.sibling(elem.firstChild);}, next: function( elem ) {
contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);} return jQuery.nth( elem, 2, "nextSibling" );
},
prev: function( elem ) {
return jQuery.nth( elem, 2, "previousSibling" );
},
nextAll: function( elem ) {
return jQuery.dir( elem, "nextSibling" );
},
prevAll: function( elem ) {
return jQuery.dir( elem, "previousSibling" );
},
nextUntil: function( elem, i, until ) {
return jQuery.dir( elem, "nextSibling", until );
},
prevUntil: function( elem, i, until ) {
return jQuery.dir( elem, "previousSibling", until );
},
siblings: function( elem ) {
return jQuery.sibling( elem.parentNode.firstChild, elem );
},
children: function( elem ) {
return jQuery.sibling( elem.firstChild );
},
contents: function( elem ) {
return jQuery.nodeName( elem, "iframe" ) ?
elem.contentDocument || elem.contentWindow.document :
jQuery.makeArray( elem.childNodes );
}
}, function( name, fn ) { }, function( name, fn ) {
jQuery.fn[ name ] = function( until, selector ) { jQuery.fn[ name ] = function( until, selector ) {
var ret = jQuery.map( this, fn, until ); var ret = jQuery.map( this, fn, until );