Merge branch 'master' of git://github.com/jquery/jquery into 2773_find_closest

This commit is contained in:
timmywil 2011-03-30 21:52:09 -04:00
commit 6da3885cc3
12 changed files with 188 additions and 35 deletions

2
.gitmodules vendored
View file

@ -1,6 +1,6 @@
[submodule "src/sizzle"] [submodule "src/sizzle"]
path = src/sizzle path = src/sizzle
url = git://github.com/jeresig/sizzle.git url = git://github.com/jquery/sizzle.git
[submodule "test/qunit"] [submodule "test/qunit"]
path = test/qunit path = test/qunit
url = git://github.com/jquery/qunit.git url = git://github.com/jquery/qunit.git

View file

@ -42,17 +42,15 @@ VER = sed "s/@VERSION/${JQ_VER}/"
DATE=$(shell git log -1 --pretty=format:%ad) DATE=$(shell git log -1 --pretty=format:%ad)
all: jquery min lint all: update_submodules core
core: jquery min lint
@@echo "jQuery build complete." @@echo "jQuery build complete."
${DIST_DIR}: ${DIST_DIR}:
@@mkdir -p ${DIST_DIR} @@mkdir -p ${DIST_DIR}
init: jquery: ${JQ}
@@if [ -d .git ]; then git submodule update --init --recursive; fi
jquery: init ${JQ}
jq: init ${JQ}
${JQ}: ${MODULES} | ${DIST_DIR} ${JQ}: ${MODULES} | ${DIST_DIR}
@@echo "Building" ${JQ} @@echo "Building" ${JQ}
@ -75,9 +73,9 @@ lint: jquery
echo "You must have NodeJS installed in order to test jQuery against JSLint."; \ echo "You must have NodeJS installed in order to test jQuery against JSLint."; \
fi fi
min: ${JQ_MIN} min: jquery ${JQ_MIN}
${JQ_MIN}: jquery ${JQ_MIN}: ${JQ}
@@if test ! -z ${JS_ENGINE}; then \ @@if test ! -z ${JS_ENGINE}; then \
echo "Minifying jQuery" ${JQ_MIN}; \ echo "Minifying jQuery" ${JQ_MIN}; \
${COMPILER} ${JQ} > ${JQ_MIN}.tmp; \ ${COMPILER} ${JQ} > ${JQ_MIN}.tmp; \
@ -99,6 +97,18 @@ distclean: clean
@@echo "Removing submodules" @@echo "Removing submodules"
@@rm -rf test/qunit src/sizzle @@rm -rf test/qunit src/sizzle
# change pointers for submodules and update them to what is specified in jQuery
# --merge doesn't work when doing an initial clone, thus test if we have non-existing
# submodules, then do an real update
update_submodules:
@@if [ -d .git ]; then \
if git submodule status | grep -q -E '^-'; then \
git submodule update --init --recursive; \
else \
git submodule update --init --recursive --merge; \
fi; \
fi;
# update the submodules to the latest at the most logical branch # update the submodules to the latest at the most logical branch
pull_submodules: pull_submodules:
@@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)" @@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)"
@ -107,4 +117,4 @@ pull_submodules:
pull: pull_submodules pull: pull_submodules
@@git pull ${REMOTE} ${BRANCH} @@git pull ${REMOTE} ${BRANCH}
.PHONY: all jquery lint min init jq clean .PHONY: all jquery lint min clean distclean update_submodules pull_submodules pull core

View file

@ -3,7 +3,8 @@
var ralpha = /alpha\([^)]*\)/i, var ralpha = /alpha\([^)]*\)/i,
ropacity = /opacity=([^)]*)/, ropacity = /opacity=([^)]*)/,
rdashAlpha = /-([a-z])/ig, rdashAlpha = /-([a-z])/ig,
rupper = /([A-Z])/g, // fixed for IE9, see #8346
rupper = /([A-Z]|^ms)/g,
rnumpx = /^-?\d+(?:px)?$/i, rnumpx = /^-?\d+(?:px)?$/i,
rnum = /^-?\d/, rnum = /^-?\d/,
@ -240,6 +241,28 @@ if ( !jQuery.support.opacity ) {
}; };
} }
jQuery(function() {
// This hook cannot be added until DOM ready because the support test
// for it is not run until after DOM ready
if ( !jQuery.support.reliableMarginRight ) {
jQuery.cssHooks.marginRight = {
get: function( elem, computed ) {
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
// Work around by temporarily setting element display to inline-block
var ret;
jQuery.swap( elem, { "display": "inline-block" }, function() {
if ( computed ) {
ret = curCSS( elem, "margin-right", "marginRight" );
} else {
ret = elem.style.marginRight;
}
});
return ret;
}
};
}
});
if ( document.defaultView && document.defaultView.getComputedStyle ) { if ( document.defaultView && document.defaultView.getComputedStyle ) {
getComputedStyle = function( elem, newName, name ) { getComputedStyle = function( elem, newName, name ) {
var ret, defaultView, computedStyle; var ret, defaultView, computedStyle;

View file

@ -144,7 +144,10 @@ jQuery.extend({
return function( value ) { return function( value ) {
args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value; args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
if ( !( --count ) ) { if ( !( --count ) ) {
deferred.resolveWith( deferred, args ); // Strange bug in FF4:
// Values changed onto the arguments object sometimes end up as undefined values
// outside the $.when method. Cloning the object into a fresh array solves the issue
deferred.resolveWith( deferred, sliceDeferred.call( args, 0 ) );
} }
}; };
} }

View file

@ -70,10 +70,10 @@ jQuery.event = {
} }
if ( !eventHandle ) { if ( !eventHandle ) {
elemData.handle = eventHandle = function() { elemData.handle = eventHandle = function( e ) {
// Handle the second event of a trigger and when // Handle the second event of a trigger and when
// an event is called after a page has unloaded // an event is called after a page has unloaded
return typeof jQuery !== "undefined" && !jQuery.event.triggered ? return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ?
jQuery.event.handle.apply( eventHandle.elem, arguments ) : jQuery.event.handle.apply( eventHandle.elem, arguments ) :
undefined; undefined;
}; };
@ -380,7 +380,7 @@ jQuery.event = {
target[ "on" + targetType ] = null; target[ "on" + targetType ] = null;
} }
jQuery.event.triggered = true; jQuery.event.triggered = event.type;
target[ targetType ](); target[ targetType ]();
} }
@ -391,7 +391,7 @@ jQuery.event = {
target[ "on" + targetType ] = old; target[ "on" + targetType ] = old;
} }
jQuery.event.triggered = false; jQuery.event.triggered = undefined;
} }
} }
}, },
@ -661,7 +661,7 @@ var withinElement = function( event ) {
// Chrome does something similar, the parentNode property // Chrome does something similar, the parentNode property
// can be accessed but is null. // can be accessed but is null.
if ( parent !== document && !parent.parentNode ) { if ( parent && parent !== document && !parent.parentNode ) {
return; return;
} }
// Traverse up the tree // Traverse up the tree
@ -868,19 +868,33 @@ function trigger( type, elem, args ) {
// Create "bubbling" focus and blur events // Create "bubbling" focus and blur events
if ( document.addEventListener ) { if ( document.addEventListener ) {
jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
// Attach a single capturing handler while someone wants focusin/focusout
var attaches = 0;
jQuery.event.special[ fix ] = { jQuery.event.special[ fix ] = {
setup: function() { setup: function() {
this.addEventListener( orig, handler, true ); if ( attaches++ === 0 ) {
document.addEventListener( orig, handler, true );
}
}, },
teardown: function() { teardown: function() {
this.removeEventListener( orig, handler, true ); if ( --attaches === 0 ) {
document.removeEventListener( orig, handler, true );
}
} }
}; };
function handler( e ) { function handler( donor ) {
e = jQuery.event.fix( e ); // Donor event is always a native one; fix it and switch its type.
// Let focusin/out handler cancel the donor focus/blur event.
var e = jQuery.event.fix( donor );
e.type = fix; e.type = fix;
return jQuery.event.handle.call( this, e ); e.originalEvent = {};
jQuery.event.trigger( e, null, e.target );
if ( e.isDefaultPrevented() ) {
donor.preventDefault();
}
} }
}); });
} }

View file

@ -151,7 +151,6 @@ jQuery.offset = {
this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop); this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop);
body.removeChild( container ); body.removeChild( container );
body = container = innerDiv = checkDiv = table = td = null;
jQuery.offset.initialize = jQuery.noop; jQuery.offset.initialize = jQuery.noop;
}, },
@ -181,10 +180,10 @@ jQuery.offset = {
curOffset = curElem.offset(), curOffset = curElem.offset(),
curCSSTop = jQuery.css( elem, "top" ), curCSSTop = jQuery.css( elem, "top" ),
curCSSLeft = jQuery.css( elem, "left" ), curCSSLeft = jQuery.css( elem, "left" ),
calculatePosition = (position === "absolute" && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1), calculatePosition = ((position === "absolute" || position === "fixed") && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1),
props = {}, curPosition = {}, curTop, curLeft; props = {}, curPosition = {}, curTop, curLeft;
// need to be able to calculate position if either top or left is auto and position is absolute // need to be able to calculate position if either top or left is auto and position is either absolute or fixed
if ( calculatePosition ) { if ( calculatePosition ) {
curPosition = curElem.position(); curPosition = curElem.position();
} }

@ -1 +1 @@
Subproject commit ef19279f54ba49242c6461d47577c703f4f4e80e Subproject commit f12b9309269ba7e705a99efe099f86ed1fe98d58

View file

@ -67,7 +67,8 @@
boxModel: null, boxModel: null,
inlineBlockNeedsLayout: false, inlineBlockNeedsLayout: false,
shrinkWrapBlocks: false, shrinkWrapBlocks: false,
reliableHiddenOffsets: true reliableHiddenOffsets: true,
reliableMarginRight: true
}; };
input.checked = true; input.checked = true;
@ -85,15 +86,15 @@
script = document.createElement("script"), script = document.createElement("script"),
id = "script" + jQuery.now(); id = "script" + jQuery.now();
// Make sure that the execution of code works by injecting a script
// tag with appendChild/createTextNode
// (IE doesn't support this, fails, and uses .text instead)
try { try {
script.appendChild( document.createTextNode( "window." + id + "=1;" ) ); script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
} catch(e) {} } catch(e) {}
root.insertBefore( script, root.firstChild ); root.insertBefore( script, root.firstChild );
// Make sure that the execution of code works by injecting a script
// tag with appendChild/createTextNode
// (IE doesn't support this, fails, and uses .text instead)
if ( window[ id ] ) { if ( window[ id ] ) {
_scriptEval = true; _scriptEval = true;
delete window[ id ]; delete window[ id ];
@ -102,8 +103,6 @@
} }
root.removeChild( script ); root.removeChild( script );
// release memory in IE
root = script = id = null;
} }
return _scriptEval; return _scriptEval;
@ -188,6 +187,17 @@
jQuery.support.reliableHiddenOffsets = jQuery.support.reliableHiddenOffsets && tds[0].offsetHeight === 0; jQuery.support.reliableHiddenOffsets = jQuery.support.reliableHiddenOffsets && tds[0].offsetHeight === 0;
div.innerHTML = ""; div.innerHTML = "";
// Check if div with explicit width and no margin-right incorrectly
// gets computed margin-right based on width of container. For more
// info see bug #3333
// Fails in WebKit before Feb 2011 nightlies
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
if ( document.defaultView && document.defaultView.getComputedStyle ) {
div.style.width = "1px";
div.style.marginRight = "0";
jQuery.support.reliableMarginRight = ( parseInt(document.defaultView.getComputedStyle(div, null).marginRight, 10) || 0 ) === 0;
}
body.removeChild( div ).style.display = "none"; body.removeChild( div ).style.display = "none";
div = tds = null; div = tds = null;
}); });
@ -211,8 +221,6 @@
el.setAttribute(eventName, "return;"); el.setAttribute(eventName, "return;");
isSupported = typeof el[eventName] === "function"; isSupported = typeof el[eventName] === "function";
} }
el = null;
return isSupported; return isSupported;
}; };

View file

@ -0,0 +1,30 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>bug_8316</title>
<style type="text/css" media="screen">
#elem {
background-color: #000;
height: 100px;
width: 100px;
position: fixed;
}
</style>
<script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script>
<script src="../../../src/traversing.js"></script>
<script src="../../../src/data.js"></script>
<script src="../../../src/event.js"></script>
<script src="../../../src/css.js"></script>
<script src="../../../src/offset.js"></script>
</head>
<body>
<p> Some foo text </p>
<div id="elem"></div>
</body>
</html>

View file

@ -333,3 +333,15 @@ test("internal ref to elem.runtimeStyle (bug #7608)", function () {
ok( result, "elem.runtimeStyle does not throw exception" ); ok( result, "elem.runtimeStyle does not throw exception" );
}); });
test("marginRight computed style (bug #3333)", function() {
expect(1);
var $div = jQuery("#foo");
$div.css({
width: "1px",
marginRight: 0
});
equals($div.css("marginRight"), "0px");
});

View file

@ -683,6 +683,20 @@ test("hover()", function() {
equals( times, 4, "hover handlers fired" ); equals( times, 4, "hover handlers fired" );
}); });
test("mouseover triggers mouseenter", function() {
expect(1);
var count = 0,
elem = jQuery("<a />");
elem.mouseenter(function () {
count++;
});
elem.trigger('mouseover');
equals(count, 1, "make sure mouseover triggers a mouseenter" );
elem.remove();
});
test("trigger() shortcuts", function() { test("trigger() shortcuts", function() {
expect(6); expect(6);
@ -1966,6 +1980,31 @@ test("window resize", function() {
ok( !jQuery._data(window, "__events__"), "Make sure all the events are gone." ); ok( !jQuery._data(window, "__events__"), "Make sure all the events are gone." );
}); });
test("focusin bubbles", function() {
expect(4);
var input = jQuery( '<input type="text" />' ).prependTo( "body" ),
order = 0;
jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
equals( 1, order++, "focusin on the body second" );
});
input.bind( "focusin.focusinBubblesTest", function(){
equals( 0, order++, "focusin on the element first" );
});
// DOM focus method
input[0].focus();
// jQuery trigger, which calls DOM focus
order = 0;
input[0].blur();
input.trigger( "focus" );
input.remove();
jQuery( "body" ).unbind( "focusin.focusinBubblesTest" );
});
/* /*
test("jQuery(function($) {})", function() { test("jQuery(function($) {})", function() {
stop(); stop();

View file

@ -422,6 +422,21 @@ test("offsetParent", function(){
equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
}); });
testoffset("bug_8316", function( jQuery ){
expect(2);
var tests = [
{ id:'#elem', top: 100, left: 100 }
];
jQuery.each(tests, function(){
var el = jQuery(this.id);
el.offset({ top: this.top, left: this.left});
equals(Math.round(el.offset().top), this.top);
equals(Math.round(el.offset().left), this.left);
});
});
function testoffset(name, fn) { function testoffset(name, fn) {
test(name, function() { test(name, function() {
@ -447,7 +462,7 @@ function testoffset(name, fn) {
function loadFixture() { function loadFixture() {
var src = './data/offset/' + name + '.html?' + parseInt( Math.random()*1000, 10 ), var src = './data/offset/' + name + '.html?' + parseInt( Math.random()*1000, 10 ),
iframe = jQuery('<iframe />').css({ iframe = jQuery('<iframe />').css({
width: 500, height: 500, position: 'absolute', top: -600, left: -600, visiblity: 'hidden' width: 500, height: 500, position: 'absolute', top: -600, left: -600, visibility: 'hidden'
}).appendTo('body')[0]; }).appendTo('body')[0];
iframe.contentWindow.location = src; iframe.contentWindow.location = src;
return iframe; return iframe;