Хранилища Subversion ant

Сравнить редакции

Учитывать пробелы Редакция 282 → Редакция 283

/trunk/js/jquery.js
6,8 → 6,8
* Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License
*
* Date: 2009-04-01 00:35:20 +0700 (Срд, 01 Апр 2009)
* Revision: 6303
* Date: 2009-05-12 22:43:51 +0700 (Втр, 12 Май 2009)
* Revision: 6348
*/
(function(){
 
31,7 → 31,7
 
jQuery = window.jQuery = window.$ = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return selector === undefined ?
return arguments.length === 0 ?
rootjQuery :
new jQuery.fn.init( selector, context );
},
49,12 → 49,6
// Save a reference to the core toString method
toString = Object.prototype.toString;
 
// Define the main jQuery method
jQuery = window.jQuery = window.$ = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
};
 
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
var match, elem, ret;
195,10 → 189,16
// Determine the position of an element within
// the matched set of elements
index: function( elem ) {
if ( !elem || typeof elem === "string" ) {
return jQuery.inArray( this[0],
// If it receives a string, the selector is used
// If it receives nothing, the siblings are used
elem ? jQuery( elem ) : this.parent().children() );
}
// Locate the position of the desired element
return jQuery.inArray(
// If it receives a jQuery object, the first element is used
elem && elem.jquery ? elem[0] : elem, this );
elem.jquery ? elem[0] : elem, this );
},
 
is: function( selector ) {
652,7 → 652,8
 
var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,
done = 0,
toString = Object.prototype.toString;
toString = Object.prototype.toString,
hasDuplicate = false;
 
var Sizzle = function(selector, context, results, seed) {
results = results || [];
1404,6 → 1405,7
}
 
root.removeChild( form );
root = form = null; // release memory in IE
})();
 
(function(){
1444,6 → 1446,8
return elem.getAttribute("href", 2);
};
}
 
div = null; // release memory in IE
})();
 
if ( document.querySelectorAll ) (function(){
1473,6 → 1477,8
for ( var prop in oldSizzle ) {
Sizzle[ prop ] = oldSizzle[ prop ];
}
 
div = null; // release memory in IE
})();
 
if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
1495,6 → 1501,8
return context.getElementsByClassName(match[1]);
}
};
 
div = null; // release memory in IE
})();
 
function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
1922,10 → 1930,25
},
 
toggleClass: function( classNames, state ) {
if( typeof state !== "boolean" )
state = !jQuery.className.has( this, classNames );
jQuery.className[ state ? "add" : "remove" ]( this, classNames );
var type = typeof classNames;
if ( type === "string" ) {
// toggle individual class names
var isBool = typeof state === "boolean", className, i = 0,
classNames = classNames.split( /\s+/ );
while ( (className = classNames[ i++ ]) ) {
// check each className given, space seperated list
state = isBool ? state : !jQuery.className.has( this, className );
jQuery.className[ state ? "add" : "remove" ]( this, className );
}
} else if ( type === "undefined" || type === "boolean" ) {
if ( this.className ) {
// store className if set
jQuery.data( this, "__className__", this.className );
}
// toggle whole className
this.className = this.className || classNames === false ? "" : jQuery.data( this, "__className__" ) || "";
}
}
}, function(name, fn){
jQuery.fn[ name ] = function(){
return this.each( fn, arguments );
2390,17 → 2413,20
// Bind an event to an element
// Original by Dean Edwards
add: function(elem, types, handler, data) {
if ( elem.nodeType == 3 || elem.nodeType == 8 )
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
return;
}
 
// For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process
if ( elem.setInterval && elem != window )
if ( elem.setInterval && ( elem !== window && !elem.frameElement ) ) {
elem = window;
}
 
// Make sure that the function being executed has a unique ID
if ( !handler.guid )
if ( !handler.guid ) {
handler.guid = this.guid++;
}
 
// if data is passed, bind to handler
if ( data !== undefined ) {
2430,7 → 2456,9
 
// Handle multiple events separated by a space
// jQuery(...).bind("mouseover mouseout", fn);
jQuery.each(types.split(/\s+/), function(index, type) {
types = types.split( /\s+/ );
var type, i=0;
while ( (type = types[ i++ ]) ) {
// Namespaced event handlers
var namespaces = type.split(".");
type = namespaces.shift();
2437,10 → 2465,16
handler.type = namespaces.slice().sort().join(".");
 
// Get the current list of functions bound to this event
var handlers = events[type];
var handlers = events[ type ],
special = this.special[ type ] || {};
 
if ( jQuery.event.specialAll[type] )
jQuery.event.specialAll[type].setup.call(elem, data, namespaces);
if ( special.add ) {
var modifiedHandler = special.add.call( elem, handler, data, namespaces );
if ( modifiedHandler && jQuery.isFunction( modifiedHandler ) ) {
modifiedHandler.guid = modifiedHandler.guid || handler.guid;
handler = modifiedHandler;
}
}
 
// Init the event handler queue
if (!handlers) {
2449,21 → 2483,22
// Check for a special event handler
// Only use addEventListener/attachEvent if the special
// events handler returns false
if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem, data, namespaces) === false ) {
if ( !special.setup || special.setup.call( elem, data, namespaces ) === false ) {
// Bind the global event handler to the element
if (elem.addEventListener)
if ( elem.addEventListener ) {
elem.addEventListener(type, handle, false);
else if (elem.attachEvent)
} else if ( elem.attachEvent ) {
elem.attachEvent("on" + type, handle);
}
}
}
 
// Add the function to the element's handler list
handlers[handler.guid] = handler;
 
// Keep track of which events have been used, for global triggering
jQuery.event.global[type] = true;
});
this.global[ type ] = true;
}
 
// Nullify elem to prevent memory leaks in IE
elem = null;
2475,17 → 2510,19
// Detach an event or set of events from an element
remove: function(elem, types, handler) {
// don't do events on text and comment nodes
if ( elem.nodeType == 3 || elem.nodeType == 8 )
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
return;
}
 
var events = jQuery.data(elem, "events"), ret, index;
var events = jQuery.data( elem, "events" ), ret, type;
 
if ( events ) {
// Unbind all events for the element
if ( types === undefined || (typeof types === "string" && types.charAt(0) == ".") )
for ( var type in events )
if ( types === undefined || (typeof types === "string" && types.charAt(0) === ".") ) {
for ( type in events ) {
this.remove( elem, type + (types || "") );
else {
}
} else {
// types is actually an event object here
if ( types.type ) {
handler = types.handler;
2494,48 → 2531,63
 
// Handle multiple events seperated by a space
// jQuery(...).unbind("mouseover mouseout", fn);
jQuery.each(types.split(/\s+/), function(index, type){
types = types.split(/\s+/);
var i = 0;
while ( (type = types[ i++ ]) ) {
// Namespaced event handlers
var namespaces = type.split(".");
type = namespaces.shift();
var namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)");
var all = !namespaces.length,
namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"),
special = this.special[ type ] || {};
 
if ( events[type] ) {
// remove the given handler for the given type
if ( handler )
if ( handler ) {
delete events[type][handler.guid];
 
// remove all handlers for the given type
else
for ( var handle in events[type] )
} else {
for ( var handle in events[ type ] ) {
// Handle the removal of namespaced events
if ( namespace.test(events[type][handle].type) )
if ( all || namespace.test( events[ type ][ handle ].type ) ) {
delete events[type][handle];
}
}
}
 
if ( jQuery.event.specialAll[type] )
jQuery.event.specialAll[type].teardown.call(elem, namespaces);
if ( special.remove ) {
special.remove.call( elem, namespaces );
}
 
// remove generic event handler if no more handlers exist
for ( ret in events[type] ) break;
for ( ret in events[ type ] ) {
break;
}
if ( !ret ) {
if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem, namespaces) === false ) {
if (elem.removeEventListener)
if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
if ( elem.removeEventListener ) {
elem.removeEventListener(type, jQuery.data(elem, "handle"), false);
else if (elem.detachEvent)
} else if ( elem.detachEvent ) {
elem.detachEvent("on" + type, jQuery.data(elem, "handle"));
}
}
ret = null;
delete events[type];
}
}
});
}
}
 
// Remove the expando if it's no longer used
for ( ret in events ) break;
for ( ret in events ) {
break;
}
if ( !ret ) {
var handle = jQuery.data( elem, "handle" );
if ( handle ) handle.elem = null;
if ( handle ) {
handle.elem = null;
}
jQuery.removeData( elem, "events" );
jQuery.removeData( elem, "handle" );
}
2543,9 → 2595,10
},
 
// bubbling is internal
trigger: function( event, data, elem, bubbling ) {
trigger: function( event, data, elem /*, bubbling */ ) {
// Event object or event type
var type = event.type || event;
var type = event.type || event,
bubbling = arguments[3];
 
if( !bubbling ){
event = typeof event === "object" ?
2566,18 → 2619,21
// Don't bubble custom events when global (to avoid too much overhead)
event.stopPropagation();
// Only trigger if we've ever bound an event for it
if ( this.global[type] )
if ( this.global[ type ] ) {
jQuery.each( jQuery.cache, function(){
if ( this.events && this.events[type] )
if ( this.events && this.events[type] ) {
jQuery.event.trigger( event, data, this.handle.elem );
}
});
}
}
 
// Handle triggering a single element
 
// don't do events on text and comment nodes
if ( !elem || elem.nodeType == 3 || elem.nodeType == 8 )
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
return undefined;
}
 
// Clean up in case it is reused
event.result = undefined;
2592,15 → 2648,17
 
// Trigger the event, it is assumed that "handle" is a function
var handle = jQuery.data(elem, "handle");
if ( handle )
if ( handle ) {
handle.apply( elem, data );
}
 
// Handle triggering native .onfoo handlers (and on links since we don't call .click() for links)
if ( (!elem[type] || (jQuery.nodeName(elem, 'a') && type == "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
if ( (!elem[ type ] || (jQuery.nodeName(elem, 'a') && type === "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false ) {
event.result = false;
}
 
// Trigger the native events (except for clicks on links)
if ( !bubbling && elem[type] && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
if ( !bubbling && elem[ type ] && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type === "click") ) {
this.triggered = true;
try {
elem[ type ]();
2612,9 → 2670,10
 
if ( !event.isPropagationStopped() ) {
var parent = elem.parentNode || elem.ownerDocument;
if ( parent )
if ( parent ) {
jQuery.event.trigger(event, data, parent, true);
}
}
},
 
handle: function(event) {
2655,18 → 2714,20
}
}
 
if( event.isImmediatePropagationStopped() )
if ( event.isImmediatePropagationStopped() ) {
break;
}
 
}
}
},
 
props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
 
fix: function(event) {
if ( event[expando] )
if ( event[ expando ] ) {
return event;
}
 
// store a copy of the original event object
// and "clone" to set read-only properties
2679,42 → 2740,53
}
 
// Fix target property, if necessary
if ( !event.target )
if ( !event.target ) {
event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
}
 
// check if target is a textnode (safari)
if ( event.target.nodeType == 3 )
if ( event.target.nodeType === 3 ) {
event.target = event.target.parentNode;
}
 
// Add relatedTarget, if necessary
if ( !event.relatedTarget && event.fromElement )
event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
if ( !event.relatedTarget && event.fromElement ) {
event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement;
}
 
// Calculate pageX/Y if missing and clientX/Y available
if ( event.pageX == null && event.clientX != null ) {
var doc = document.documentElement, body = document.body;
event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);
event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);
event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
}
 
// Add which for key events
if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) )
if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) ) {
event.which = event.charCode || event.keyCode;
}
 
// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
if ( !event.metaKey && event.ctrlKey )
if ( !event.metaKey && event.ctrlKey ) {
event.metaKey = event.ctrlKey;
}
 
// Add which for click: 1 == left; 2 == middle; 3 == right
// Note: button is not normalized, so don't use it
if ( !event.which && event.button )
if ( !event.which && event.button ) {
event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
}
 
return event;
},
 
proxy: function( fn, proxy ){
proxy = proxy || function(){ return fn.apply(this, arguments); };
proxy: function( fn, proxy, thisObject ) {
if ( proxy !== undefined && !jQuery.isFunction( proxy ) ) {
thisObject = proxy;
proxy = undefined;
}
// FIXME: Should proxy be redefined to be applied with thisObject if defined?
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
proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++;
// So proxy can be declared as an argument
2726,35 → 2798,39
// Make sure the ready event is setup
setup: bindReady,
teardown: function() {}
}
},
 
specialAll: {
live: {
setup: function( selector, namespaces ){
jQuery.event.add( this, namespaces[0], liveHandler );
add: function( proxy, data, namespaces ) {
jQuery.extend( proxy, data || {} );
proxy.guid += data.selector + data.live;
jQuery.event.add( this, data.live, liveHandler );
},
teardown: function( namespaces ){
 
remove: function( namespaces ) {
if ( namespaces.length ) {
var remove = 0, name = new RegExp("(^|\\.)" + namespaces[0] + "(\\.|$)");
 
jQuery.each( (jQuery.data(this, "events").live || {}), function(){
if ( name.test(this.type) )
if ( name.test(this.type) ) {
remove++;
}
});
 
if ( remove < 1 )
if ( remove < 1 ) {
jQuery.event.remove( this, namespaces[0], liveHandler );
}
}
}
}
}
};
 
jQuery.Event = function( src ){
// Allow instantiation without the 'new' keyword
if( !this.preventDefault )
if ( !this.preventDefault ) {
return new jQuery.Event(src);
}
 
// Event object
if( src && src.type ){
2761,8 → 2837,9
this.originalEvent = src;
this.type = src.type;
// Event type
}else
} else {
this.type = src;
}
 
// timeStamp is buggy for some events on Firefox(#3843)
// So we won't rely on the native value
2786,11 → 2863,13
this.isDefaultPrevented = returnTrue;
 
var e = this.originalEvent;
if( !e )
if ( !e ) {
return;
}
// if preventDefault exists run it on the original event
if (e.preventDefault)
if ( e.preventDefault ) {
e.preventDefault();
}
// otherwise set the returnValue property of the original event to false (IE)
e.returnValue = false;
},
2798,11 → 2877,13
this.isPropagationStopped = returnTrue;
 
var e = this.originalEvent;
if( !e )
if ( !e ) {
return;
}
// if stopPropagation exists run it on the original event
if (e.stopPropagation)
if ( e.stopPropagation ) {
e.stopPropagation();
}
// otherwise set the cancelBubble property of the original event to true (IE)
e.cancelBubble = true;
},
2820,9 → 2901,13
// Check if mouse(over|out) are still within the same parent element
var parent = event.relatedTarget;
// Traverse up the tree
while ( parent && parent != this )
while ( parent && parent != this ) {
// Firefox sometimes assigns relatedTarget a XUL element
// which we cannot access the parentNode property of
try { parent = parent.parentNode; }
catch(e) { parent = this; }
// assuming we've left the element since we most likely mousedover a xul element
catch(e) { break; }
}
 
if( parent != this ){
// set the correct event type
2847,19 → 2932,35
});
 
jQuery.fn.extend({
bind: function( type, data, fn ) {
return type == "unload" ? this.one(type, data, fn) : this.each(function(){
jQuery.event.add( this, type, fn || data, fn && data );
bind: function( type, data, fn, thisObject ) {
if ( jQuery.isFunction( data ) ) {
if ( fn !== undefined ) {
thisObject = fn;
}
fn = data;
data = undefined;
}
fn = thisObject === undefined ? fn : jQuery.event.proxy( fn, thisObject );
return type === "unload" ? this.one(type, data, fn, thisObject) : this.each(function() {
jQuery.event.add( this, type, fn, data );
});
},
 
one: function( type, data, fn ) {
var one = jQuery.event.proxy( fn || data, function(event) {
one: function( type, data, fn, thisObject ) {
if ( jQuery.isFunction( data ) ) {
if ( fn !== undefined ) {
thisObject = fn;
}
fn = data;
data = undefined;
}
fn = thisObject === undefined ? fn : jQuery.event.proxy( fn, thisObject );
var one = jQuery.event.proxy( fn, function( event ) {
jQuery(this).unbind(event, one);
return (fn || data).apply( this, arguments );
return fn.apply( this, arguments );
});
return this.each(function(){
jQuery.event.add( this, type, one, fn && data);
jQuery.event.add( this, type, one, data );
});
},
 
2890,8 → 2991,9
var args = arguments, i = 1;
 
// link all the functions, so any of them can unbind this click handler
while( i < args.length )
while( i < args.length ) {
jQuery.event.proxy( fn, args[i++] );
}
 
return this.click( jQuery.event.proxy( fn, function(event) {
// Figure out which function to execute
2906,7 → 3008,7
},
 
hover: function(fnOver, fnOut) {
return this.mouseenter(fnOver).mouseleave(fnOut);
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
},
 
ready: function(fn) {
2914,24 → 3016,30
bindReady();
 
// If the DOM is already ready
if ( jQuery.isReady )
if ( jQuery.isReady ) {
// Execute the function immediately
fn.call( document, jQuery );
 
// Otherwise, remember the function for later
else
} else {
// Add the function to the wait list
jQuery.readyList.push( fn );
}
 
return this;
},
 
live: function( type, fn ){
var proxy = jQuery.event.proxy( fn );
proxy.guid += this.selector + type;
 
jQuery( this.context ).bind( liveConvert(type, this.selector), this.selector, proxy );
 
live: function( type, data, fn, thisObject ) {
if ( jQuery.isFunction( data ) ) {
if ( fn !== undefined ) {
thisObject = fn;
}
fn = data;
data = undefined;
}
jQuery( this.context ).bind( liveConvert( type, this.selector ), {
data: data, selector: this.selector, live: type
}, fn, thisObject );
return this;
},
 
2942,16 → 3050,15
});
 
function liveHandler( event ){
var check = new RegExp("(^|\\.)" + event.type + "(\\.|$)"),
stop = true,
elems = [];
var stop = true, elems = [], args = arguments;
 
jQuery.each(jQuery.data(this, "events").live || [], function(i, fn){
if ( check.test(fn.type) ) {
var elem = jQuery(event.target).closest(fn.data)[0];
if ( elem )
if ( fn.live === event.type ) {
var elem = jQuery( event.target ).closest( fn.selector )[0];
if ( elem ) {
elems.push({ elem: elem, fn: fn });
}
}
});
 
elems.sort(function(a,b) {
2960,8 → 3067,10
 
jQuery.each(elems, function(){
event.currentTarget = this.elem;
if ( this.fn.call(this.elem, event, this.fn.data) === false )
event.data = this.fn.data;
if ( this.fn.apply( this.elem, args ) === false ) {
return (stop = false);
}
});
 
return stop;
2984,9 → 3093,10
// If there are functions bound, to execute
if ( jQuery.readyList ) {
// Execute all of them
jQuery.each( jQuery.readyList, function(){
this.call( document, jQuery );
});
var fn, i = 0;
while ( (fn = jQuery.readyList[ i++ ]) ) {
fn.call( document, jQuery );
}
 
// Reset the list of functions
jQuery.readyList = null;
3025,8 → 3135,10
 
// If IE and not an iframe
// continually check to see if the document is ready
if ( document.documentElement.doScroll && window == window.top ) (function(){
if ( jQuery.isReady ) return;
if ( document.documentElement.doScroll && window === window.top ) (function() {
if ( jQuery.isReady ) {
return;
}
 
try {
// If IE is used, use the trick by Diego Perini
3063,10 → 3175,12
// - http://isaacschlueter.com/2006/10/msie-memory-leaks/
// - https://bugzilla.mozilla.org/show_bug.cgi?id=252542
jQuery( window ).bind( 'unload', function(){
for ( var id in jQuery.cache )
for ( var id in jQuery.cache ) {
// Skip the window
if ( id != 1 && jQuery.cache[ id ].handle )
if ( id != 1 && jQuery.cache[ id ].handle ) {
jQuery.event.remove( jQuery.cache[ id ].handle.elem );
}
}
});
(function(){
 
3158,7 → 3272,11
document.body.appendChild( div );
jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
document.body.removeChild( div ).style.display = 'none';
div = null;
});
 
// release memory in IE
root = script = div = all = a = null;
})();
 
jQuery.props = {
3172,8 → 3290,8
};
// exclude the following css properties to add px
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
// cache defaultView
defaultView = document.defaultView || {},
// cache check for defaultView.getComputedStyle
getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
// normalize float css property
styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat";
 
3180,10 → 3298,6
jQuery.fn.css = function( name, value ) {
var options = name, isFunction = jQuery.isFunction( value );
 
// ignore negative width and height values
if ( (name == 'width' || name == 'height') && parseFloat(value) < 0 )
value = undefined;
 
if ( typeof name === "string" ) {
// Are we setting the style?
if ( value === undefined ) {
3227,6 → 3341,10
if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
return undefined;
 
// ignore negative width and height values #1599
if ( (name == 'width' || name == 'height') && parseFloat(value) < 0 )
value = undefined;
 
var style = elem.style || elem, set = value !== undefined;
 
// IE uses filters for opacity
3312,7 → 3430,7
if ( !force && style && style[ name ] ) {
ret = style[ name ];
 
} else if ( defaultView.getComputedStyle ) {
} else if ( getComputedStyle ) {
 
// Only "float" is needed here
if ( /float/i.test( name ) )
3320,7 → 3438,7
 
name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
 
var computedStyle = defaultView.getComputedStyle( elem, null );
var computedStyle = elem.ownerDocument.defaultView.getComputedStyle( elem, null );
 
if ( computedStyle )
ret = computedStyle.getPropertyValue( name );
4328,18 → 4446,18
if ( "getBoundingClientRect" in document.documentElement )
jQuery.fn.offset = function() {
var elem = this[0];
if ( !elem ) return null;
if ( !elem || !elem.ownerDocument ) return null;
if ( elem === elem.ownerDocument.body ) return jQuery.offset.bodyOffset( elem );
var box = elem.getBoundingClientRect(), doc = elem.ownerDocument, body = doc.body, docElem = doc.documentElement,
clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
top = box.top + (self.pageYOffset || jQuery.boxModel && docElem.scrollTop || body.scrollTop ) - clientTop,
left = box.left + (self.pageXOffset || jQuery.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft;
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;
return { top: top, left: left };
};
else
jQuery.fn.offset = function() {
var elem = this[0];
if ( !elem ) return null;
if ( !elem || !elem.ownerDocument ) return null;
if ( elem === elem.ownerDocument.body ) return jQuery.offset.bodyOffset( elem );
jQuery.offset.initialize();
 
4356,13 → 4474,13
if ( elem === offsetParent ) {
top += elem.offsetTop, left += elem.offsetLeft;
if ( jQuery.offset.doesNotAddBorder && !(jQuery.offset.doesAddBorderForTableAndCells && /^t(able|d|h)$/i.test(elem.tagName)) )
top += parseFloat( computedStyle.borderTopWidth, 10) || 0,
left += parseFloat( computedStyle.borderLeftWidth, 10) || 0;
top += parseFloat( computedStyle.borderTopWidth ) || 0,
left += parseFloat( computedStyle.borderLeftWidth ) || 0;
prevOffsetParent = offsetParent, offsetParent = elem.offsetParent;
}
if ( jQuery.offset.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" )
top += parseFloat( computedStyle.borderTopWidth, 10) || 0,
left += parseFloat( computedStyle.borderLeftWidth, 10) || 0;
top += parseFloat( computedStyle.borderTopWidth ) || 0,
left += parseFloat( computedStyle.borderLeftWidth ) || 0;
prevComputedStyle = computedStyle;
}
 
4379,7 → 4497,7
 
jQuery.offset = {
initialize: function() {
var body = document.body, container = document.createElement('div'), innerDiv, checkDiv, table, td, prop, bodyMarginTop = parseFloat(jQuery.curCSS(body, 'marginTop', true), 10) || 0,
var body = document.body, container = document.createElement('div'), innerDiv, checkDiv, table, td, bodyMarginTop = parseFloat( jQuery.curCSS(body, 'marginTop', true) ) || 0,
html = '<div style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;"><div></div></div><table style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;" cellpadding="0" cellspacing="0"><tr><td></td></tr></table>';
 
jQuery.extend( container.style, { position: 'absolute', top: 0, left: 0, margin: 0, border: 0, width: '1px', height: '1px', visibility: 'hidden' } );
4392,7 → 4510,7
this.doesAddBorderForTableAndCells = (td.offsetTop === 5);
 
checkDiv.style.position = 'fixed', checkDiv.style.top = '20px';
this.supportsFixedPosition = (checkDiv.offsetTop >= 15); // safari subtracts parent border width here which is 5px
this.supportsFixedPosition = (checkDiv.offsetTop === 20 || checkDiv.offsetTop === 15); // safari subtracts parent border width here which is 5px
checkDiv.style.position = '', checkDiv.style.top = '';
 
innerDiv.style.overflow = 'hidden', innerDiv.style.position = 'relative';
4402,6 → 4520,8
 
body.removeChild(container);
jQuery.offset.initialize = function(){};
body = container = innerDiv = checkDiv = table = td = null;
},
 
bodyOffset: function(body) {
4408,8 → 4528,8
jQuery.offset.initialize();
var top = body.offsetTop, left = body.offsetLeft;
if ( jQuery.offset.doesNotIncludeMarginInBodyOffset )
top += parseFloat( jQuery.curCSS(body, 'marginTop', true), 10 ) || 0,
left += parseFloat( jQuery.curCSS(body, 'marginLeft', true), 10 ) || 0;
top += parseFloat( jQuery.curCSS(body, 'marginTop', true) ) || 0,
left += parseFloat( jQuery.curCSS(body, 'marginLeft', true) ) || 0;
return { top: top, left: left };
}
};
4419,7 → 4539,7
position: function() {
if ( !this[0] ) return null;
 
var elem = this[0], left = 0, top = 0, results,
var elem = this[0],
 
// Get *real* offsetParent
offsetParent = this.offsetParent(),
4431,25 → 4551,23
// Subtract element margins
// note: when an element has margin: auto the offsetLeft and marginLeft
// are the same in Safari causing offset.left to incorrectly be 0
offset.top -= parseFloat( jQuery.curCSS(elem, 'marginTop', true), 10 ) || 0;
offset.left -= parseFloat( jQuery.curCSS(elem, 'marginLeft', true), 10 ) || 0;
offset.top -= parseFloat( jQuery.curCSS(elem, 'marginTop', true) ) || 0;
offset.left -= parseFloat( jQuery.curCSS(elem, 'marginLeft', true) ) || 0;
 
// Add offsetParent borders
parentOffset.top += parseFloat( jQuery.curCSS(offsetParent[0], 'borderTopWidth', true), 10 ) || 0;
parentOffset.left += parseFloat( jQuery.curCSS(offsetParent[0], 'borderLeftWidth', true), 10 ) || 0;
parentOffset.top += parseFloat( jQuery.curCSS(offsetParent[0], 'borderTopWidth', true) ) || 0;
parentOffset.left += parseFloat( jQuery.curCSS(offsetParent[0], 'borderLeftWidth', true) ) || 0;
 
// Subtract the two offsets
results = {
return {
top: offset.top - parentOffset.top,
left: offset.left - parentOffset.left
};
 
return results;
},
 
offsetParent: function() {
var offsetParent = this[0].offsetParent || document.body;
while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static') )
while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') === 'static') )
offsetParent = offsetParent.offsetParent;
return jQuery(offsetParent);
}
4463,24 → 4581,32
jQuery.fn[ method ] = function(val) {
if ( !this[0] ) return null;
 
var elem = this[0], win = ("scrollTo" in elem && elem.document) ? elem :
(elem.nodeName === "#document") ? elem.defaultView || elem.parentWindow :
false;
 
return val !== undefined ?
 
// Set the scroll offset
this.each(function() {
this == window || this == document ?
window.scrollTo(
!i ? val : jQuery(window).scrollLeft(),
i ? val : jQuery(window).scrollTop()
win = ("scrollTo" in this && this.document) ? this :
(this.nodeName === "#document") ? this.defaultView || this.parentWindow :
false;
win ?
win.scrollTo(
!i ? val : jQuery(win).scrollLeft(),
i ? val : jQuery(win).scrollTop()
) :
this[ method ] = val;
}) :
 
// Return the scroll offset
this[0] == window || this[0] == document ?
self[ i ? 'pageYOffset' : 'pageXOffset' ] ||
jQuery.boxModel && document.documentElement[ method ] ||
document.body[ method ] :
this[0][ method ];
win ?
win[ i ? 'pageYOffset' : 'pageXOffset' ] ||
jQuery.support.boxModel && win.document.documentElement[ method ] ||
win.document.body[ method ] :
elem[ method ];
};
});
// Create innerHeight, innerWidth, outerHeight and outerWidth methods
4504,24 → 4630,26
 
jQuery.fn[ type ] = function( size ) {
// Get window width or height
return this[0] == window ?
var elem = this[0];
if ( !elem ) return null;
return ("scrollTo" in elem && elem.document) ? // does it walk and quack like a 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 ] :
elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
elem.document.body[ "client" + name ] :
 
// Get document width or height
this[0] == document ?
(elem.nodeName === "#document") ? // is it a document
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
Math.max(
document.documentElement["client" + name],
document.body["scroll" + name], document.documentElement["scroll" + name],
document.body["offset" + name], document.documentElement["offset" + name]
elem.documentElement["client" + name],
elem.body["scroll" + name], elem.documentElement["scroll" + name],
elem.body["offset" + name], elem.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) :
jQuery.css( elem, type ) :
 
// Set the width or height on the element (default to pixels if value is unitless)
this.css( type, typeof size === "string" ? size : size + "px" );