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

View File

@ -10,27 +10,21 @@
*/
// Map over jQuery in case of overwrite
if ( 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 );
};
var _jQuery = window.jQuery,
// Map over the $ in case of overwrite
if ( window.$ )
var _$ = window.$;
_$ = window.$;
// Map the jQuery namespace to the '$' one
window.$ = jQuery;
var jQuery = window.jQuery = window.$ = function( selector, context ) {
// 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
// (both of which we optimize for)
var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/,
// Is it a simple selector
var isSimple = /^.[^:#\[\.]*$/;
isSimple = /^.[^:#\[\.]*$/;
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
@ -359,9 +353,7 @@ jQuery.fn = jQuery.prototype = {
},
is: function( selector ) {
return selector ?
jQuery.multiFilter( selector, this ).length > 0 :
false;
return !!selector && jQuery.multiFilter( selector, this ).length > 0;
},
hasClass: function( selector ) {
@ -536,7 +528,7 @@ jQuery.fn = jQuery.prototype = {
};
// 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 ) {
if ( elem.src )
@ -553,6 +545,10 @@ function evalScript( i, elem ) {
elem.parentNode.removeChild( elem );
}
function now(){
return +new Date;
}
jQuery.extend = jQuery.fn.extend = function() {
// copy reference to target object
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
@ -598,12 +594,12 @@ jQuery.extend = jQuery.fn.extend = function() {
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
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
// cache getComputedStyle
var getComputedStyle = document.defaultView && document.defaultView.getComputedStyle;
getComputedStyle = document.defaultView && document.defaultView.getComputedStyle;
jQuery.extend({
noConflict: function( deep ) {
@ -874,15 +870,15 @@ jQuery.extend({
// If the element isn't reporting its values properly in Safari
// then some display: none elements are involved
else {
var swap = [], stack = [];
var swap = [], stack = [], a = elem, i = 0;
// 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);
// Go through and make them visible, but in reverse
// (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 ] ) ) {
swap[ i ] = stack[ i ].style.display;
stack[ i ].style.display = "block";
@ -895,7 +891,7 @@ jQuery.extend({
( computedStyle && computedStyle.getPropertyValue( name ) ) || "";
// 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 )
stack[ i ].style.display = swap[ i ];
}
@ -946,7 +942,7 @@ jQuery.extend({
return;
if ( elem.constructor == Number )
elem = elem.toString();
elem += '';
// Convert html string into DOM nodes
if ( typeof elem == "string" ) {

View File

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

View File

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

View File

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