mainly made the code shorter:

- removed some needless if's
- replace multiple "var x" for one, comma separated declaration.
- added a local fn called now() for the (new Date)s
- fixed the indentation of a block, and a typo in a comment.
- used fn instead of prototype where possible
- jquery fx: exposed the speeds hash as jQuery.fx.speeds.

Also fixed (again) line endings
This commit is contained in:
Ariel Flesler 2008-04-29 23:34:50 +00:00
parent ea44348fdb
commit 17b1e407d1
5 changed files with 103 additions and 101 deletions

View File

@ -91,7 +91,7 @@ jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".sp
}; };
}); });
var jsc = (new Date).getTime(); var jsc = now();
jQuery.extend({ jQuery.extend({
get: function( url, data, callback, type ) { get: function( url, data, callback, type ) {
@ -211,7 +211,7 @@ jQuery.extend({
s.cache = false; s.cache = false;
if ( s.cache === false && s.type.toLowerCase() == "get" ) { if ( s.cache === false && s.type.toLowerCase() == "get" ) {
var ts = (new Date()).getTime(); var ts = now();
// try replacing _= if it is there // try replacing _= if it is there
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2"); var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
// if nothing was replaced, add timestamp to the end // if nothing was replaced, add timestamp to the end
@ -448,9 +448,9 @@ jQuery.extend({
}, },
httpData: function( r, type ) { httpData: function( r, type ) {
var ct = r.getResponseHeader("content-type"); var ct = r.getResponseHeader("content-type"),
var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0; xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
var data = xml ? r.responseXML : r.responseText; data = xml ? r.responseXML : r.responseText;
if ( xml && data.documentElement.tagName == "parsererror" ) if ( xml && data.documentElement.tagName == "parsererror" )
throw "parsererror"; throw "parsererror";

View File

@ -10,27 +10,21 @@
*/ */
// Map over jQuery in case of overwrite // Map over jQuery in case of overwrite
if ( window.jQuery ) var _jQuery = window.jQuery,
var _jQuery = window.jQuery;
var jQuery = window.jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.prototype.init( selector, context );
};
// Map over the $ in case of overwrite // Map over the $ in case of overwrite
if ( window.$ ) _$ = window.$;
var _$ = window.$;
// Map the jQuery namespace to the '$' one var jQuery = window.jQuery = window.$ = function( selector, context ) {
window.$ = jQuery; // The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
};
// A simple way to check for HTML strings or ID strings // A simple way to check for HTML strings or ID strings
// (both of which we optimize for) // (both of which we optimize for)
var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/; var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/,
// Is it a simple selector // Is it a simple selector
var isSimple = /^.[^:#\[\.]*$/; isSimple = /^.[^:#\[\.]*$/;
jQuery.fn = jQuery.prototype = { jQuery.fn = jQuery.prototype = {
init: function( selector, context ) { init: function( selector, context ) {
@ -359,9 +353,7 @@ jQuery.fn = jQuery.prototype = {
}, },
is: function( selector ) { is: function( selector ) {
return selector ? return !!selector && jQuery.multiFilter( selector, this ).length > 0;
jQuery.multiFilter( selector, this ).length > 0 :
false;
}, },
hasClass: function( selector ) { hasClass: function( selector ) {
@ -536,7 +528,7 @@ jQuery.fn = jQuery.prototype = {
}; };
// Give the init function the jQuery prototype for later instantiation // Give the init function the jQuery prototype for later instantiation
jQuery.prototype.init.prototype = jQuery.prototype; jQuery.fn.init.prototype = jQuery.fn;
function evalScript( i, elem ) { function evalScript( i, elem ) {
if ( elem.src ) if ( elem.src )
@ -553,6 +545,10 @@ function evalScript( i, elem ) {
elem.parentNode.removeChild( elem ); elem.parentNode.removeChild( elem );
} }
function now(){
return +new Date;
}
jQuery.extend = jQuery.fn.extend = function() { jQuery.extend = jQuery.fn.extend = function() {
// copy reference to target object // copy reference to target object
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options; var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
@ -598,12 +594,12 @@ jQuery.extend = jQuery.fn.extend = function() {
return target; return target;
}; };
var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {}; var expando = "jQuery" + now(), uuid = 0, windowData = {},
// exclude the following css properties to add px // exclude the following css properties to add px
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i; exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
// cache getComputedStyle // cache getComputedStyle
var getComputedStyle = document.defaultView && document.defaultView.getComputedStyle; getComputedStyle = document.defaultView && document.defaultView.getComputedStyle;
jQuery.extend({ jQuery.extend({
noConflict: function( deep ) { noConflict: function( deep ) {
@ -874,15 +870,15 @@ jQuery.extend({
// If the element isn't reporting its values properly in Safari // If the element isn't reporting its values properly in Safari
// then some display: none elements are involved // then some display: none elements are involved
else { else {
var swap = [], stack = []; var swap = [], stack = [], a = elem, i = 0;
// Locate all of the parent display: none elements // Locate all of the parent display: none elements
for ( var a = elem; a && color(a); a = a.parentNode ) for ( ; a && color(a); a = a.parentNode )
stack.unshift(a); stack.unshift(a);
// Go through and make them visible, but in reverse // Go through and make them visible, but in reverse
// (It would be better if we knew the exact display type that they had) // (It would be better if we knew the exact display type that they had)
for ( var i = 0; i < stack.length; i++ ) for ( ; i < stack.length; i++ )
if ( color( stack[ i ] ) ) { if ( color( stack[ i ] ) ) {
swap[ i ] = stack[ i ].style.display; swap[ i ] = stack[ i ].style.display;
stack[ i ].style.display = "block"; stack[ i ].style.display = "block";
@ -895,7 +891,7 @@ jQuery.extend({
( computedStyle && computedStyle.getPropertyValue( name ) ) || ""; ( computedStyle && computedStyle.getPropertyValue( name ) ) || "";
// Finally, revert the display styles back // Finally, revert the display styles back
for ( var i = 0; i < swap.length; i++ ) for ( i = 0; i < swap.length; i++ )
if ( swap[ i ] != null ) if ( swap[ i ] != null )
stack[ i ].style.display = swap[ i ]; stack[ i ].style.display = swap[ i ];
} }
@ -946,7 +942,7 @@ jQuery.extend({
return; return;
if ( elem.constructor == Number ) if ( elem.constructor == Number )
elem = elem.toString(); elem += '';
// Convert html string into DOM nodes // Convert html string into DOM nodes
if ( typeof elem == "string" ) { if ( typeof elem == "string" ) {

View File

@ -13,7 +13,7 @@ jQuery.event = {
// For whatever reason, IE has trouble passing the window object // For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process // around, causing it to be cloned in the process
if ( jQuery.browser.msie && elem.setInterval != undefined ) if ( jQuery.browser.msie && elem.setInterval )
elem = window; elem = window;
// Make sure that the function being executed has a unique ID // Make sure that the function being executed has a unique ID
@ -51,7 +51,7 @@ jQuery.event = {
// event in IE. // event in IE.
handle.elem = elem; handle.elem = elem;
// Handle multiple events seperated by a space // Handle multiple events separated by a space
// jQuery(...).bind("mouseover mouseout", fn); // jQuery(...).bind("mouseover mouseout", fn);
jQuery.each(types.split(/\s+/), function(index, type) { jQuery.each(types.split(/\s+/), function(index, type) {
// Namespaced event handlers // Namespaced event handlers
@ -190,7 +190,7 @@ jQuery.event = {
target: elem, target: elem,
preventDefault: function(){}, preventDefault: function(){},
stopPropagation: function(){}, stopPropagation: function(){},
timeStamp: +new Date timeStamp: now()
}); });
data[0][expando] = true; // no need to fix fake event data[0][expando] = true; // no need to fix fake event
} }
@ -309,7 +309,7 @@ jQuery.event = {
}; };
// Fix timeStamp // Fix timeStamp
event.timeStamp = event.timeStamp || +new Date; event.timeStamp = event.timeStamp || now();
// Fix target property, if necessary // Fix target property, if necessary
if ( !event.target ) if ( !event.target )
@ -380,7 +380,7 @@ jQuery.event = {
// If we actually just moused on to a sub-element, ignore it // If we actually just moused on to a sub-element, ignore it
if ( withinElement(event, this) ) return true; if ( withinElement(event, this) ) return true;
// Execute the right handlers by setting the event type to mouseenter // Execute the right handlers by setting the event type to mouseenter
arguments[0].type = "mouseenter"; event.type = "mouseenter";
return jQuery.event.handle.apply(this, arguments); return jQuery.event.handle.apply(this, arguments);
} }
}, },
@ -402,7 +402,7 @@ jQuery.event = {
// If we actually just moused on to a sub-element, ignore it // If we actually just moused on to a sub-element, ignore it
if ( withinElement(event, this) ) return true; if ( withinElement(event, this) ) return true;
// Execute the right handlers by setting the event type to mouseleave // Execute the right handlers by setting the event type to mouseleave
arguments[0].type = "mouseleave"; event.type = "mouseleave";
return jQuery.event.handle.apply(this, arguments); return jQuery.event.handle.apply(this, arguments);
} }
} }
@ -439,9 +439,7 @@ jQuery.fn.extend({
}, },
triggerHandler: function( type, data, fn ) { triggerHandler: function( type, data, fn ) {
if ( this[0] ) return this[0] && jQuery.event.trigger( type, data, this[0], false, fn );
return jQuery.event.trigger( type, data, this[0], false, fn );
return undefined;
}, },
toggle: function( fn ) { toggle: function( fn ) {

View File

@ -76,10 +76,10 @@ jQuery.fn.extend({
if ( this.nodeType != 1) if ( this.nodeType != 1)
return false; return false;
var opt = jQuery.extend({}, optall); var opt = jQuery.extend({}, optall), p,
var hidden = jQuery(this).is(":hidden"), self = this; hidden = jQuery(this).is(":hidden"), self = this;
for ( var p in prop ) { for ( p in prop ) {
if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden ) if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
return jQuery.isFunction(opt.complete) && opt.complete.apply(this); return jQuery.isFunction(opt.complete) && opt.complete.apply(this);
@ -180,8 +180,7 @@ jQuery.fn.extend({
}); });
var queue = function( elem, type, array ) { var queue = function( elem, type, array ) {
if ( !elem ) if ( elem ){
return undefined;
type = type || "fx"; type = type || "fx";
@ -190,6 +189,7 @@ var queue = function( elem, type, array ) {
if ( !q || array ) if ( !q || array )
q = jQuery.data( elem, type + "queue", jQuery.makeArray(array) ); q = jQuery.data( elem, type + "queue", jQuery.makeArray(array) );
}
return q; return q;
}; };
@ -218,7 +218,7 @@ jQuery.extend({
opt.duration = (opt.duration && opt.duration.constructor == Number ? opt.duration = (opt.duration && opt.duration.constructor == Number ?
opt.duration : opt.duration :
{ slow: 600, fast: 200 }[opt.duration]) || 400; jQuery.fx.speeds[opt.duration]) || 400;
// Queueing // Queueing
opt.old = opt.complete; opt.old = opt.complete;
@ -280,7 +280,7 @@ jQuery.fx.prototype = {
// Start an animation from one number to another // Start an animation from one number to another
custom: function(from, to, unit){ custom: function(from, to, unit){
this.startTime = (new Date()).getTime(); this.startTime = now();
this.start = from; this.start = from;
this.end = to; this.end = to;
this.unit = unit || this.unit || "px"; this.unit = unit || this.unit || "px";
@ -343,7 +343,7 @@ jQuery.fx.prototype = {
// Each step of an animation // Each step of an animation
step: function(gotoEnd){ step: function(gotoEnd){
var t = (new Date()).getTime(); var t = now();
if ( gotoEnd || t > this.options.duration + this.startTime ) { if ( gotoEnd || t > this.options.duration + this.startTime ) {
this.now = this.end; this.now = this.end;
@ -401,7 +401,12 @@ jQuery.fx.prototype = {
}; };
jQuery.fx.step = { jQuery.extend( jQuery.fx, {
speeds:{
slow: 600,
fast: 200
},
step: {
scrollLeft: function(fx){ scrollLeft: function(fx){
fx.elem.scrollLeft = fx.now; fx.elem.scrollLeft = fx.now;
}, },
@ -417,4 +422,5 @@ jQuery.fx.step = {
_default: function(fx){ _default: function(fx){
fx.elem.style[ fx.prop ] = fx.now + fx.unit; fx.elem.style[ fx.prop ] = fx.now + fx.unit;
} }
}; }
});

View File

@ -114,12 +114,13 @@ jQuery.extend({
t = jQuery.trim(t); t = jQuery.trim(t);
var foundToken = false; var foundToken = false,
// An attempt at speeding up child selectors that // An attempt at speeding up child selectors that
// point to a specific element tag // point to a specific element tag
var re = quickChild; re = quickChild,
var m = re.exec(t);
m = re.exec(t);
if ( m ) { if ( m ) {
nodeName = m[1].toUpperCase(); nodeName = m[1].toUpperCase();
@ -416,8 +417,8 @@ jQuery.extend({
}, },
dir: function( elem, dir ){ dir: function( elem, dir ){
var matched = []; var matched = [],
var cur = elem[dir]; cur = elem[dir];
while ( cur && cur != document ) { while ( cur && cur != document ) {
if ( cur.nodeType == 1 ) if ( cur.nodeType == 1 )
matched.push( cur ); matched.push( cur );
@ -449,3 +450,4 @@ jQuery.extend({
} }
}); });