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

This commit is contained in:
timmywil 2011-03-23 15:59:33 -04:00
commit d2eafa0bb8
28 changed files with 537 additions and 448 deletions

2
.gitignore vendored
View file

@ -4,7 +4,5 @@ dist
*~ *~
*.diff *.diff
*.patch *.patch
test/qunit
src/sizzle
/*.html /*.html
.DS_Store .DS_Store

6
.gitmodules vendored Normal file
View file

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

View file

@ -1,5 +1,3 @@
V ?= 0
SRC_DIR = src SRC_DIR = src
TEST_DIR = test TEST_DIR = test
BUILD_DIR = build BUILD_DIR = build
@ -12,6 +10,7 @@ COMPILER = ${JS_ENGINE} ${BUILD_DIR}/uglify.js --unsafe
POST_COMPILER = ${JS_ENGINE} ${BUILD_DIR}/post-compile.js POST_COMPILER = ${JS_ENGINE} ${BUILD_DIR}/post-compile.js
BASE_FILES = ${SRC_DIR}/core.js\ BASE_FILES = ${SRC_DIR}/core.js\
${SRC_DIR}/deferred.js\
${SRC_DIR}/support.js\ ${SRC_DIR}/support.js\
${SRC_DIR}/data.js\ ${SRC_DIR}/data.js\
${SRC_DIR}/queue.js\ ${SRC_DIR}/queue.js\
@ -37,48 +36,21 @@ JQ = ${DIST_DIR}/jquery.js
JQ_MIN = ${DIST_DIR}/jquery.min.js JQ_MIN = ${DIST_DIR}/jquery.min.js
SIZZLE_DIR = ${SRC_DIR}/sizzle SIZZLE_DIR = ${SRC_DIR}/sizzle
QUNIT_DIR = ${TEST_DIR}/qunit
JQ_VER = $(shell cat version.txt) JQ_VER = $(shell cat version.txt)
VER = sed "s/@VERSION/${JQ_VER}/" 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}
ifeq ($(strip $(V)),0) jquery: ${JQ}
verbose = --quiet
else ifeq ($(strip $(V)),1)
verbose =
else
verbose = --verbose
endif
define clone_or_pull
-@@if test ! -d $(strip ${1})/.git; then \
echo "Cloning $(strip ${1})..."; \
git clone $(strip ${verbose}) --depth=1 $(strip ${2}) $(strip ${1}); \
else \
echo "Pulling $(strip ${1})..."; \
git --git-dir=$(strip ${1})/.git pull $(strip ${verbose}) origin master; \
fi
endef
${QUNIT_DIR}:
$(call clone_or_pull, ${QUNIT_DIR}, git://github.com/jquery/qunit.git)
${SIZZLE_DIR}:
$(call clone_or_pull, ${SIZZLE_DIR}, git://github.com/jeresig/sizzle.git)
init: ${QUNIT_DIR} ${SIZZLE_DIR}
jquery: init ${JQ}
jq: init ${JQ}
${JQ}: ${MODULES} | ${DIST_DIR} ${JQ}: ${MODULES} | ${DIST_DIR}
@@echo "Building" ${JQ} @@echo "Building" ${JQ}
@ -121,7 +93,28 @@ clean:
@@echo "Removing built copy of Sizzle" @@echo "Removing built copy of Sizzle"
@@rm -f src/selector.js @@rm -f src/selector.js
@@echo "Removing cloned directories" distclean: clean
@@echo "Removing submodules"
@@rm -rf test/qunit src/sizzle @@rm -rf test/qunit src/sizzle
.PHONY: all jquery lint min init jq clean # 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
pull_submodules:
@@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)"
@@git submodule summary
pull: pull_submodules
@@git pull ${REMOTE} ${BRANCH}
.PHONY: all jquery lint min clean distclean update_submodules pull_submodules pull core

View file

@ -7,7 +7,7 @@ var r20 = /%20/g,
rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
// #7653, #8125, #8152: local protocol detection // #7653, #8125, #8152: local protocol detection
rlocalProtocol = /(?:^file|^widget|\-extension):$/, rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/,
rnoContent = /^(?:GET|HEAD)$/, rnoContent = /^(?:GET|HEAD)$/,
rprotocol = /^\/\//, rprotocol = /^\/\//,
rquery = /\?/, rquery = /\?/,
@ -19,7 +19,7 @@ var r20 = /%20/g,
rucHeadersFunc = function( _, $1, $2 ) { rucHeadersFunc = function( _, $1, $2 ) {
return $1 + $2.toUpperCase(); return $1 + $2.toUpperCase();
}, },
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?|\/[^\/])/, rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
// Keep a copy of the old load method // Keep a copy of the old load method
_load = jQuery.fn.load, _load = jQuery.fn.load,
@ -61,7 +61,7 @@ try {
} }
// Segment location into parts // Segment location into parts
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ); ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
function addToPrefiltersOrTransports( structure ) { function addToPrefiltersOrTransports( structure ) {

View file

@ -92,11 +92,12 @@ if ( jQuery.support.ajax ) {
xhr.overrideMimeType( s.mimeType ); xhr.overrideMimeType( s.mimeType );
} }
// Requested-With header // X-Requested-With header
// Not set for crossDomain requests with no content // For cross-domain requests, seeing as conditions for a preflight are
// (see why at http://trac.dojotoolkit.org/ticket/9486) // akin to a jigsaw puzzle, we simply never set it to be sure.
// Won't change header if already provided // (it can always be set on a per-request basis or even using ajaxSetup)
if ( !( s.crossDomain && !s.hasContent ) && !headers["X-Requested-With"] ) { // For same-domain requests, won't change header if already provided.
if ( !s.crossDomain && !headers["X-Requested-With"] ) {
headers[ "X-Requested-With" ] = "XMLHttpRequest"; headers[ "X-Requested-With" ] = "XMLHttpRequest";
} }

View file

@ -50,15 +50,9 @@ var jQuery = function( selector, context ) {
// For matching the engine and version of the browser // For matching the engine and version of the browser
browserMatch, browserMatch,
// Has the ready events already been bound?
readyBound = false,
// The deferred used on DOM ready // The deferred used on DOM ready
readyList, readyList,
// Promise methods
promiseMethods = "then done fail isResolved isRejected promise".split( " " ),
// The ready event handler // The ready event handler
DOMContentLoaded, DOMContentLoaded,
@ -408,11 +402,11 @@ jQuery.extend({
}, },
bindReady: function() { bindReady: function() {
if ( readyBound ) { if ( readyList ) {
return; return;
} }
readyBound = true; readyList = jQuery._Deferred();
// Catch cases where $(document).ready() is called after the // Catch cases where $(document).ready() is called after the
// browser event has already occurred. // browser event has already occurred.
@ -792,165 +786,6 @@ jQuery.extend({
return (new Date()).getTime(); return (new Date()).getTime();
}, },
// Create a simple deferred (one callbacks list)
_Deferred: function() {
var // callbacks list
callbacks = [],
// stored [ context , args ]
fired,
// to avoid firing when already doing so
firing,
// flag to know if the deferred has been cancelled
cancelled,
// the deferred itself
deferred = {
// done( f1, f2, ...)
done: function() {
if ( !cancelled ) {
var args = arguments,
i,
length,
elem,
type,
_fired;
if ( fired ) {
_fired = fired;
fired = 0;
}
for ( i = 0, length = args.length; i < length; i++ ) {
elem = args[ i ];
type = jQuery.type( elem );
if ( type === "array" ) {
deferred.done.apply( deferred, elem );
} else if ( type === "function" ) {
callbacks.push( elem );
}
}
if ( _fired ) {
deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] );
}
}
return this;
},
// resolve with given context and args
resolveWith: function( context, args ) {
if ( !cancelled && !fired && !firing ) {
firing = 1;
try {
while( callbacks[ 0 ] ) {
callbacks.shift().apply( context, args );
}
}
finally {
fired = [ context, args ];
firing = 0;
}
}
return this;
},
// resolve with this as context and given arguments
resolve: function() {
deferred.resolveWith( jQuery.isFunction( this.promise ) ? this.promise() : this, arguments );
return this;
},
// Has this deferred been resolved?
isResolved: function() {
return !!( firing || fired );
},
// Cancel
cancel: function() {
cancelled = 1;
callbacks = [];
return this;
}
};
return deferred;
},
// Full fledged deferred (two callbacks list)
Deferred: function( func ) {
var deferred = jQuery._Deferred(),
failDeferred = jQuery._Deferred(),
promise;
// Add errorDeferred methods, then and promise
jQuery.extend( deferred, {
then: function( doneCallbacks, failCallbacks ) {
deferred.done( doneCallbacks ).fail( failCallbacks );
return this;
},
fail: failDeferred.done,
rejectWith: failDeferred.resolveWith,
reject: failDeferred.resolve,
isRejected: failDeferred.isResolved,
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function( obj ) {
if ( obj == null ) {
if ( promise ) {
return promise;
}
promise = obj = {};
}
var i = promiseMethods.length;
while( i-- ) {
obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ];
}
return obj;
}
} );
// Make sure only one callback list will be used
deferred.done( failDeferred.cancel ).fail( deferred.cancel );
// Unexpose cancel
delete deferred.cancel;
// Call given func if any
if ( func ) {
func.call( deferred, deferred );
}
return deferred;
},
// Deferred helper
when: function( object ) {
var lastIndex = arguments.length,
deferred = lastIndex <= 1 && object && jQuery.isFunction( object.promise ) ?
object :
jQuery.Deferred(),
promise = deferred.promise();
if ( lastIndex > 1 ) {
var array = slice.call( arguments, 0 ),
count = lastIndex,
iCallback = function( index ) {
return function( value ) {
array[ index ] = arguments.length > 1 ? slice.call( arguments, 0 ) : value;
if ( !( --count ) ) {
deferred.resolveWith( promise, array );
}
};
};
while( ( lastIndex-- ) ) {
object = array[ lastIndex ];
if ( object && jQuery.isFunction( object.promise ) ) {
object.promise().then( iCallback(lastIndex), deferred.reject );
} else {
--count;
}
}
if ( !count ) {
deferred.resolveWith( promise, array );
}
} else if ( deferred !== object ) {
deferred.resolve( object );
}
return promise;
},
// Use of jQuery.browser is frowned upon. // Use of jQuery.browser is frowned upon.
// More details: http://docs.jquery.com/Utilities/jQuery.browser // More details: http://docs.jquery.com/Utilities/jQuery.browser
uaMatch: function( ua ) { uaMatch: function( ua ) {
@ -989,9 +824,6 @@ jQuery.extend({
browser: {} browser: {}
}); });
// Create readyList deferred
readyList = jQuery._Deferred();
// Populate the class2type map // Populate the class2type map
jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) { jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
class2type[ "[object " + name + "]" ] = name.toLowerCase(); class2type[ "[object " + name + "]" ] = name.toLowerCase();

169
src/deferred.js Normal file
View file

@ -0,0 +1,169 @@
(function( jQuery ) {
var // Promise methods
promiseMethods = "then done fail isResolved isRejected promise".split( " " ),
// Static reference to slice
sliceDeferred = [].slice;
jQuery.extend({
// Create a simple deferred (one callbacks list)
_Deferred: function() {
var // callbacks list
callbacks = [],
// stored [ context , args ]
fired,
// to avoid firing when already doing so
firing,
// flag to know if the deferred has been cancelled
cancelled,
// the deferred itself
deferred = {
// done( f1, f2, ...)
done: function() {
if ( !cancelled ) {
var args = arguments,
i,
length,
elem,
type,
_fired;
if ( fired ) {
_fired = fired;
fired = 0;
}
for ( i = 0, length = args.length; i < length; i++ ) {
elem = args[ i ];
type = jQuery.type( elem );
if ( type === "array" ) {
deferred.done.apply( deferred, elem );
} else if ( type === "function" ) {
callbacks.push( elem );
}
}
if ( _fired ) {
deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] );
}
}
return this;
},
// resolve with given context and args
resolveWith: function( context, args ) {
if ( !cancelled && !fired && !firing ) {
// make sure args are available (#8421)
args = args || [];
firing = 1;
try {
while( callbacks[ 0 ] ) {
callbacks.shift().apply( context, args );
}
}
finally {
fired = [ context, args ];
firing = 0;
}
}
return this;
},
// resolve with this as context and given arguments
resolve: function() {
deferred.resolveWith( this, arguments );
return this;
},
// Has this deferred been resolved?
isResolved: function() {
return !!( firing || fired );
},
// Cancel
cancel: function() {
cancelled = 1;
callbacks = [];
return this;
}
};
return deferred;
},
// Full fledged deferred (two callbacks list)
Deferred: function( func ) {
var deferred = jQuery._Deferred(),
failDeferred = jQuery._Deferred(),
promise;
// Add errorDeferred methods, then and promise
jQuery.extend( deferred, {
then: function( doneCallbacks, failCallbacks ) {
deferred.done( doneCallbacks ).fail( failCallbacks );
return this;
},
fail: failDeferred.done,
rejectWith: failDeferred.resolveWith,
reject: failDeferred.resolve,
isRejected: failDeferred.isResolved,
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function( obj ) {
if ( obj == null ) {
if ( promise ) {
return promise;
}
promise = obj = {};
}
var i = promiseMethods.length;
while( i-- ) {
obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ];
}
return obj;
}
} );
// Make sure only one callback list will be used
deferred.done( failDeferred.cancel ).fail( deferred.cancel );
// Unexpose cancel
delete deferred.cancel;
// Call given func if any
if ( func ) {
func.call( deferred, deferred );
}
return deferred;
},
// Deferred helper
when: function( firstParam ) {
var args = arguments,
i = 0,
length = args.length,
count = length,
deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ?
firstParam :
jQuery.Deferred();
function resolveFunc( i ) {
return function( value ) {
args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
if ( !( --count ) ) {
deferred.resolveWith( deferred, args );
}
};
}
if ( length > 1 ) {
for( ; i < length; i++ ) {
if ( args[ i ] && jQuery.isFunction( args[ i ].promise ) ) {
args[ i ].promise().then( resolveFunc(i), deferred.reject );
} else {
--count;
}
}
if ( !count ) {
deferred.resolveWith( deferred, args );
}
} else if ( deferred !== firstParam ) {
deferred.resolveWith( deferred, length ? [ firstParam ] : [] );
}
return deferred.promise();
}
});
})( jQuery );

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

@ -261,7 +261,9 @@ jQuery.fn.extend({
} }
}); });
} else { } else {
return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ); return this.length ?
this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) :
this;
} }
}, },

1
src/sizzle Submodule

@ -0,0 +1 @@
Subproject commit ef19279f54ba49242c6461d47577c703f4f4e80e

View file

@ -6,6 +6,7 @@
<title>CSP Test Page</title> <title>CSP Test Page</title>
<script src="../src/core.js"></script> <script src="../src/core.js"></script>
<script src="../src/deferred.js"></script>
<script src="../src/support.js"></script> <script src="../src/support.js"></script>
<script src="../src/data.js"></script> <script src="../src/data.js"></script>
<script src="../src/queue.js"></script> <script src="../src/queue.js"></script>

View file

@ -16,6 +16,7 @@
#positionTest { position: absolute; } #positionTest { position: absolute; }
</style> </style>
<script src="../../../src/core.js"></script> <script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script> <script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script> <script src="../../../src/sizzle-jquery.js"></script>

View file

@ -9,6 +9,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style> </style>
<script src="../../../src/core.js"></script> <script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script> <script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script> <script src="../../../src/sizzle-jquery.js"></script>

View file

@ -13,6 +13,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style> </style>
<script src="../../../src/core.js"></script> <script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script> <script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script> <script src="../../../src/sizzle-jquery.js"></script>

View file

@ -11,6 +11,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style> </style>
<script src="../../../src/core.js"></script> <script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script> <script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script> <script src="../../../src/sizzle-jquery.js"></script>

View file

@ -14,6 +14,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style> </style>
<script src="../../../src/core.js"></script> <script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script> <script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script> <script src="../../../src/sizzle-jquery.js"></script>

View file

@ -11,6 +11,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style> </style>
<script src="../../../src/core.js"></script> <script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script> <script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script> <script src="../../../src/sizzle-jquery.js"></script>

View file

@ -11,6 +11,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style> </style>
<script src="../../../src/core.js"></script> <script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script> <script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script> <script src="../../../src/sizzle-jquery.js"></script>

View file

@ -9,6 +9,7 @@
<script src="data/testinit.js"></script> <script src="data/testinit.js"></script>
<script src="../src/core.js"></script> <script src="../src/core.js"></script>
<script src="../src/deferred.js"></script>
<script src="../src/support.js"></script> <script src="../src/support.js"></script>
<script src="../src/data.js"></script> <script src="../src/data.js"></script>
<script src="../src/queue.js"></script> <script src="../src/queue.js"></script>
@ -31,6 +32,7 @@
<script src="data/testrunner.js"></script> <script src="data/testrunner.js"></script>
<script src="unit/core.js"></script> <script src="unit/core.js"></script>
<script src="unit/deferred.js"></script>
<script src="unit/data.js"></script> <script src="unit/data.js"></script>
<script src="unit/queue.js"></script> <script src="unit/queue.js"></script>
<script src="unit/attributes.js"></script> <script src="unit/attributes.js"></script>

View file

@ -5,6 +5,7 @@
<title>jQuery Local File Test</title> <title>jQuery Local File Test</title>
<!-- Includes --> <!-- Includes -->
<script src="../src/core.js"></script> <script src="../src/core.js"></script>
<script src="../src/deferred.js"></script>
<script src="../src/support.js"></script> <script src="../src/support.js"></script>
<script src="../src/data.js"></script> <script src="../src/data.js"></script>
<script src="../src/queue.js"></script> <script src="../src/queue.js"></script>

View file

@ -16,6 +16,7 @@
div { margin-top: 10px; } div { margin-top: 10px; }
</style> </style>
<script src="../src/core.js"></script> <script src="../src/core.js"></script>
<script src="../src/deferred.js"></script>
<script src="../src/support.js"></script> <script src="../src/support.js"></script>
<script src="../src/data.js"></script> <script src="../src/data.js"></script>
<script src="../src/queue.js"></script> <script src="../src/queue.js"></script>

1
test/qunit Submodule

@ -0,0 +1 @@
Subproject commit d404faf8f587fcbe6b8907943022e6318dd51e0c

View file

@ -15,6 +15,7 @@
#expectedOutput { background-color: green } #expectedOutput { background-color: green }
</style> </style>
<script src="../src/core.js"></script> <script src="../src/core.js"></script>
<script src="../src/deferred.js"></script>
<script src="../src/support.js"></script> <script src="../src/support.js"></script>
<script src="../src/data.js"></script> <script src="../src/data.js"></script>
<script src="../src/queue.js"></script> <script src="../src/queue.js"></script>

View file

@ -492,7 +492,7 @@ test(".ajax() - hash", function() {
test("jQuery ajax - cross-domain detection", function() { test("jQuery ajax - cross-domain detection", function() {
expect( 5 ); expect( 6 );
var loc = document.location, var loc = document.location,
otherPort = loc.port === 666 ? 667 : 666, otherPort = loc.port === 666 ? 667 : 666,
@ -508,6 +508,7 @@ test("jQuery ajax - cross-domain detection", function() {
}); });
jQuery.ajax({ jQuery.ajax({
dataType: "jsonp",
url: 'app:/path', url: 'app:/path',
beforeSend: function( _ , s ) { beforeSend: function( _ , s ) {
ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" ); ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
@ -533,6 +534,15 @@ test("jQuery ajax - cross-domain detection", function() {
} }
}); });
jQuery.ajax({
dataType: "jsonp",
url: "about:blank",
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Test about:blank is detected as cross-domain" );
return false;
}
});
jQuery.ajax({ jQuery.ajax({
dataType: "jsonp", dataType: "jsonp",
url: loc.protocol + "//" + loc.host, url: loc.protocol + "//" + loc.host,

View file

@ -914,221 +914,6 @@ test("jQuery.parseJSON", function(){
} }
}); });
test("jQuery._Deferred()", function() {
expect( 10 );
var deferred,
object,
test;
deferred = jQuery._Deferred();
test = false;
deferred.done( function( value ) {
equals( value , "value" , "Test pre-resolve callback" );
test = true;
} );
deferred.resolve( "value" );
ok( test , "Test pre-resolve callbacks called right away" );
test = false;
deferred.done( function( value ) {
equals( value , "value" , "Test post-resolve callback" );
test = true;
} );
ok( test , "Test post-resolve callbacks called right away" );
deferred.cancel();
test = true;
deferred.done( function() {
ok( false , "Cancel was ignored" );
test = false;
} );
ok( test , "Test cancel" );
deferred = jQuery._Deferred().resolve();
try {
deferred.done( function() {
throw "Error";
} , function() {
ok( true , "Test deferred do not cancel on exception" );
} );
} catch( e ) {
strictEqual( e , "Error" , "Test deferred propagates exceptions");
deferred.done();
}
test = "";
deferred = jQuery._Deferred().done( function() {
test += "A";
}, function() {
test += "B";
} ).resolve();
strictEqual( test , "AB" , "Test multiple done parameters" );
test = "";
deferred.done( function() {
deferred.done( function() {
test += "C";
} );
test += "A";
}, function() {
test += "B";
} );
strictEqual( test , "ABC" , "Test done callbacks order" );
deferred = jQuery._Deferred();
deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
});
});
test("jQuery.Deferred()", function() {
expect( 10 );
jQuery.Deferred( function( defer ) {
strictEqual( this , defer , "Defer passed as this & first argument" );
this.resolve( "done" );
}).then( function( value ) {
strictEqual( value , "done" , "Passed function executed" );
});
jQuery.Deferred().resolve().then( function() {
ok( true , "Success on resolve" );
}, function() {
ok( false , "Error on resolve" );
});
jQuery.Deferred().reject().then( function() {
ok( false , "Success on reject" );
}, function() {
ok( true , "Error on reject" );
});
( new jQuery.Deferred( function( defer ) {
strictEqual( this , defer , "Defer passed as this & first argument (new)" );
this.resolve( "done" );
}) ).then( function( value ) {
strictEqual( value , "done" , "Passed function executed (new)" );
});
( new jQuery.Deferred() ).resolve().then( function() {
ok( true , "Success on resolve (new)" );
}, function() {
ok( false , "Error on resolve (new)" );
});
( new jQuery.Deferred() ).reject().then( function() {
ok( false , "Success on reject (new)" );
}, function() {
ok( true , "Error on reject (new)" );
});
var tmp = jQuery.Deferred();
strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" );
strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" );
});
test("jQuery.when()", function() {
expect( 23 );
// Some other objects
jQuery.each( {
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
"a number other than zero": 1,
"true": true,
"false": false,
"null": null,
"undefined": undefined,
"a plain object": {}
} , function( message , value ) {
ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
} ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
} );
ok( jQuery.isFunction( jQuery.when().then( function( resolveValue ) {
strictEqual( resolveValue , undefined , "Test the promise was resolved with no parameter" );
} ).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" );
var cache, i;
for( i = 1 ; i < 4 ; i++ ) {
jQuery.when( cache || jQuery.Deferred( function() {
this.resolve( i );
}) ).then( function( value ) {
strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
}, function() {
ok( false , "Fail called" );
});
}
});
test("jQuery.when() - joined", function() {
expect(8);
jQuery.when( 1, 2, 3 ).done( function( a, b, c ) {
strictEqual( a , 1 , "Test first param is first resolved value - non-observables" );
strictEqual( b , 2 , "Test second param is second resolved value - non-observables" );
strictEqual( c , 3 , "Test third param is third resolved value - non-observables" );
}).fail( function() {
ok( false , "Test the created deferred was resolved - non-observables");
});
var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ),
errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" );
jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) {
strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" );
same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" );
strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" );
}).fail( function() {
ok( false , "Test the created deferred was resolved - resolved observable");
});
jQuery.when( 1 , errorDeferred , 3 ).done( function() {
ok( false , "Test the created deferred was rejected - rejected observable");
}).fail( function( error , errorParam ) {
strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" );
strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" );
});
});
test("jQuery.sub() - Static Methods", function(){ test("jQuery.sub() - Static Methods", function(){
expect(18); expect(18);
var Subclass = jQuery.sub(); var Subclass = jQuery.sub();
@ -1143,16 +928,16 @@ test("jQuery.sub() - Static Methods", function(){
} }
}); });
Subclass.fn.extend({subClassMethod: function() { return this;}}); Subclass.fn.extend({subClassMethod: function() { return this;}});
//Test Simple Subclass //Test Simple Subclass
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true'); ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!'); ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');
same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly'); same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly');
equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods'); equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods');
//Create a SubSubclass //Create a SubSubclass
var SubSubclass = Subclass.sub(); var SubSubclass = Subclass.sub();
//Make Sure the SubSubclass inherited properly //Make Sure the SubSubclass inherited properly
ok(SubSubclass.topLevelMethod() === false, 'SubSubclass.topLevelMethod thought debug was true'); ok(SubSubclass.topLevelMethod() === false, 'SubSubclass.topLevelMethod thought debug was true');
ok(SubSubclass.config.locale == 'en_US', SubSubclass.config.locale + ' is wrong!'); ok(SubSubclass.config.locale == 'en_US', SubSubclass.config.locale + ' is wrong!');
@ -1169,7 +954,7 @@ test("jQuery.sub() - Static Methods", function(){
ok(SubSubclass.config.locale == 'es_MX', SubSubclass.config.locale + ' is wrong!'); ok(SubSubclass.config.locale == 'es_MX', SubSubclass.config.locale + ' is wrong!');
ok(SubSubclass.config.test == 'worked', 'SubSubclass.config.test is set incorrectly'); ok(SubSubclass.config.test == 'worked', 'SubSubclass.config.test is set incorrectly');
notEqual(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods'); notEqual(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods');
//This shows that the modifications to the SubSubClass did not bubble back up to it's superclass //This shows that the modifications to the SubSubClass did not bubble back up to it's superclass
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true'); ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!'); ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');

222
test/unit/deferred.js Normal file
View file

@ -0,0 +1,222 @@
module("deferred", { teardown: moduleTeardown });
test("jQuery._Deferred()", function() {
expect( 11 );
var deferred,
object,
test;
deferred = jQuery._Deferred();
test = false;
deferred.done( function( value ) {
equals( value , "value" , "Test pre-resolve callback" );
test = true;
} );
deferred.resolve( "value" );
ok( test , "Test pre-resolve callbacks called right away" );
test = false;
deferred.done( function( value ) {
equals( value , "value" , "Test post-resolve callback" );
test = true;
} );
ok( test , "Test post-resolve callbacks called right away" );
deferred.cancel();
test = true;
deferred.done( function() {
ok( false , "Cancel was ignored" );
test = false;
} );
ok( test , "Test cancel" );
deferred = jQuery._Deferred().resolve();
try {
deferred.done( function() {
throw "Error";
} , function() {
ok( true , "Test deferred do not cancel on exception" );
} );
} catch( e ) {
strictEqual( e , "Error" , "Test deferred propagates exceptions");
deferred.done();
}
test = "";
deferred = jQuery._Deferred().done( function() {
test += "A";
}, function() {
test += "B";
} ).resolve();
strictEqual( test , "AB" , "Test multiple done parameters" );
test = "";
deferred.done( function() {
deferred.done( function() {
test += "C";
} );
test += "A";
}, function() {
test += "B";
} );
strictEqual( test , "ABC" , "Test done callbacks order" );
deferred = jQuery._Deferred();
deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
});
// #8421
deferred = jQuery._Deferred();
deferred.resolveWith().done(function() {
ok( true, "Test resolveWith can be called with no argument" );
});
});
test("jQuery.Deferred()", function() {
expect( 10 );
jQuery.Deferred( function( defer ) {
strictEqual( this , defer , "Defer passed as this & first argument" );
this.resolve( "done" );
}).then( function( value ) {
strictEqual( value , "done" , "Passed function executed" );
});
jQuery.Deferred().resolve().then( function() {
ok( true , "Success on resolve" );
}, function() {
ok( false , "Error on resolve" );
});
jQuery.Deferred().reject().then( function() {
ok( false , "Success on reject" );
}, function() {
ok( true , "Error on reject" );
});
( new jQuery.Deferred( function( defer ) {
strictEqual( this , defer , "Defer passed as this & first argument (new)" );
this.resolve( "done" );
}) ).then( function( value ) {
strictEqual( value , "done" , "Passed function executed (new)" );
});
( new jQuery.Deferred() ).resolve().then( function() {
ok( true , "Success on resolve (new)" );
}, function() {
ok( false , "Error on resolve (new)" );
});
( new jQuery.Deferred() ).reject().then( function() {
ok( false , "Success on reject (new)" );
}, function() {
ok( true , "Error on reject (new)" );
});
var tmp = jQuery.Deferred();
strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" );
strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" );
});
test("jQuery.when()", function() {
expect( 23 );
// Some other objects
jQuery.each( {
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
"a number other than zero": 1,
"true": true,
"false": false,
"null": null,
"undefined": undefined,
"a plain object": {}
} , function( message , value ) {
ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
} ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
} );
ok( jQuery.isFunction( jQuery.when().then( function( resolveValue ) {
strictEqual( resolveValue , undefined , "Test the promise was resolved with no parameter" );
} ).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" );
var cache, i;
for( i = 1 ; i < 4 ; i++ ) {
jQuery.when( cache || jQuery.Deferred( function() {
this.resolve( i );
}) ).then( function( value ) {
strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
}, function() {
ok( false , "Fail called" );
});
}
});
test("jQuery.when() - joined", function() {
expect(8);
jQuery.when( 1, 2, 3 ).done( function( a, b, c ) {
strictEqual( a , 1 , "Test first param is first resolved value - non-observables" );
strictEqual( b , 2 , "Test second param is second resolved value - non-observables" );
strictEqual( c , 3 , "Test third param is third resolved value - non-observables" );
}).fail( function() {
ok( false , "Test the created deferred was resolved - non-observables");
});
var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ),
errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" );
jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) {
strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" );
same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" );
strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" );
}).fail( function() {
ok( false , "Test the created deferred was resolved - resolved observable");
});
jQuery.when( 1 , errorDeferred , 3 ).done( function() {
ok( false , "Test the created deferred was rejected - rejected observable");
}).fail( function( error , errorParam ) {
strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" );
strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" );
});
});

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

@ -739,7 +739,7 @@ test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
}); });
var testReplaceWith = function(val) { var testReplaceWith = function(val) {
expect(20); expect(21);
jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' )); jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
ok( jQuery("#replace")[0], 'Replace element with string' ); ok( jQuery("#replace")[0], 'Replace element with string' );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' ); ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
@ -800,6 +800,9 @@ var testReplaceWith = function(val) {
equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." ); equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
equals( set.length, 1, "Replace the disconnected node." ); equals( set.length, 1, "Replace the disconnected node." );
var non_existant = jQuery('#does-not-exist').replaceWith( val("<b>should not throw an error</b>") );
equals( non_existant.length, 0, "Length of non existant element." );
var $div = jQuery("<div class='replacewith'></div>").appendTo("body"); var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
// TODO: Work on jQuery(...) inline script execution // TODO: Work on jQuery(...) inline script execution
//$div.replaceWith("<div class='replacewith'></div><script>" + //$div.replaceWith("<div class='replacewith'></div><script>" +
@ -827,7 +830,7 @@ test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
test("replaceWith(Function)", function() { test("replaceWith(Function)", function() {
testReplaceWith(functionReturningObj); testReplaceWith(functionReturningObj);
expect(21); expect(22);
var y = jQuery("#yahoo")[0]; var y = jQuery("#yahoo")[0];