From b3ccf2f2881d9ad988aba1cf3ccffb810063ab29 Mon Sep 17 00:00:00 2001 From: jeresig Date: Tue, 23 Mar 2010 12:12:16 -0400 Subject: [PATCH 01/21] Made it so that you no longer need to build jQuery in order to run the test suite (but you'll still need a checkout of QUnit and Sizzle, at least). --- src/ajax.js | 4 +- src/attributes.js | 2 +- src/core.js | 87 ++++++++++++++++++----------------------- src/css.js | 2 +- src/data.js | 2 +- src/effects.js | 4 +- src/event.js | 2 +- src/manipulation.js | 16 ++++++++ src/outro.js | 3 -- src/sizzle-jquery.js | 6 +-- src/support.js | 2 +- src/traversing.js | 64 +++++++++++++++--------------- test/index.html | 50 +++++++++++++++-------- test/unit/attributes.js | 12 ++++-- 14 files changed, 141 insertions(+), 115 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index f797e1a7..7cf280ab 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,4 +1,4 @@ -var jsc = now(), +var jsc = jQuery.now(), rscript = //gi, rselectTextarea = /select|textarea/i, rinput = /color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i, @@ -259,7 +259,7 @@ jQuery.extend({ } if ( s.cache === false && type === "GET" ) { - var ts = now(); + var ts = jQuery.now(); // try replacing _= if it is there var ret = s.url.replace(rts, "$1_=" + ts + "$2"); diff --git a/src/attributes.js b/src/attributes.js index 4f7055a6..aca9e055 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -9,7 +9,7 @@ var rclass = /[\n\t]/g, jQuery.fn.extend({ attr: function( name, value ) { - return access( this, name, value, true, jQuery.attr ); + return jQuery.access( this, name, value, true, jQuery.attr ); }, removeAttr: function( name, fn ) { diff --git a/src/core.js b/src/core.js index 699b87ac..e1a3a6df 100644 --- a/src/core.js +++ b/src/core.js @@ -1,3 +1,5 @@ +(function() { + // Define a local copy of jQuery var jQuery = function( selector, context ) { // The jQuery object is actually just the init constructor 'enhanced' @@ -11,7 +13,7 @@ var jQuery = function( selector, context ) { _$ = window.$, // Use the correct document accordingly with window argument (sandbox) - document = window.document, + //document = window.document, // A central reference to the root jQuery(document) rootjQuery, @@ -699,6 +701,39 @@ jQuery.extend({ return proxy; }, + // Mutifunctional method to get and set values to a collection + // The value/s can be optionally by executed if its a function + access: function( elems, key, value, exec, fn, pass ) { + var length = elems.length; + + // Setting many attributes + if ( typeof key === "object" ) { + for ( var k in key ) { + jQuery.access( elems, k, key[k], exec, fn, value ); + } + return elems; + } + + // Setting one attribute + if ( value !== undefined ) { + // Optionally, function values get executed if exec is true + exec = !pass && exec && jQuery.isFunction(value); + + for ( var i = 0; i < length; i++ ) { + fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass ); + } + + return elems; + } + + // Getting an attribute + return length ? fn( elems[0], key ) : undefined; + }, + + now: function() { + return (new Date()).getTime(); + }, + // Use of jQuery.browser is frowned upon. // More details: http://docs.jquery.com/Utilities/jQuery.browser uaMatch: function( ua ) { @@ -779,51 +814,7 @@ function doScrollCheck() { jQuery.ready(); } -function evalScript( i, elem ) { - if ( elem.src ) { - jQuery.ajax({ - url: elem.src, - async: false, - dataType: "script" - }); - } else { - jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); - } +// Expose jQuery to the global object +window.jQuery = window.$ = jQuery; - if ( elem.parentNode ) { - elem.parentNode.removeChild( elem ); - } -} - -// Mutifunctional method to get and set values to a collection -// The value/s can be optionally by executed if its a function -function access( elems, key, value, exec, fn, pass ) { - var length = elems.length; - - // Setting many attributes - if ( typeof key === "object" ) { - for ( var k in key ) { - access( elems, k, key[k], exec, fn, value ); - } - return elems; - } - - // Setting one attribute - if ( value !== undefined ) { - // Optionally, function values get executed if exec is true - exec = !pass && exec && jQuery.isFunction(value); - - for ( var i = 0; i < length; i++ ) { - fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass ); - } - - return elems; - } - - // Getting an attribute - return length ? fn( elems[0], key ) : undefined; -} - -function now() { - return (new Date()).getTime(); -} +})(); diff --git a/src/css.js b/src/css.js index f675e13f..ad0da646 100644 --- a/src/css.js +++ b/src/css.js @@ -21,7 +21,7 @@ var rexclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, }; jQuery.fn.css = function( name, value ) { - return access( this, name, value, true, function( elem, name, value ) { + return jQuery.access( this, name, value, true, function( elem, name, value ) { if ( value === undefined ) { return jQuery.curCSS( elem, name ); } diff --git a/src/data.js b/src/data.js index 109d5568..cddd8bde 100644 --- a/src/data.js +++ b/src/data.js @@ -1,4 +1,4 @@ -var expando = "jQuery" + now(), uuid = 0, windowData = {}; +var expando = "jQuery" + jQuery.now(), uuid = 0, windowData = {}; jQuery.extend({ cache: {}, diff --git a/src/effects.js b/src/effects.js index 97456ccc..40326e23 100644 --- a/src/effects.js +++ b/src/effects.js @@ -320,7 +320,7 @@ jQuery.fx.prototype = { // Start an animation from one number to another custom: function( from, to, unit ) { - this.startTime = now(); + this.startTime = jQuery.now(); this.start = from; this.end = to; this.unit = unit || this.unit || "px"; @@ -366,7 +366,7 @@ jQuery.fx.prototype = { // Each step of an animation step: function( gotoEnd ) { - var t = now(), done = true; + var t = jQuery.now(), done = true; if ( gotoEnd || t >= this.options.duration + this.startTime ) { this.now = this.end; diff --git a/src/event.js b/src/event.js index 173bab10..588a7979 100644 --- a/src/event.js +++ b/src/event.js @@ -554,7 +554,7 @@ jQuery.Event = function( src ) { // timeStamp is buggy for some events on Firefox(#3843) // So we won't rely on the native value - this.timeStamp = now(); + this.timeStamp = jQuery.now(); // Mark it as fixed this[ expando ] = true; diff --git a/src/manipulation.js b/src/manipulation.js index be12aa12..cb898cc3 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -584,3 +584,19 @@ jQuery.extend({ } } }); + +function evalScript( i, elem ) { + if ( elem.src ) { + jQuery.ajax({ + url: elem.src, + async: false, + dataType: "script" + }); + } else { + jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); + } + + if ( elem.parentNode ) { + elem.parentNode.removeChild( elem ); + } +} \ No newline at end of file diff --git a/src/outro.js b/src/outro.js index 5d87b7e7..7773a74f 100644 --- a/src/outro.js +++ b/src/outro.js @@ -1,4 +1 @@ -// Expose jQuery to the global object -window.jQuery = window.$ = jQuery; - })(window); diff --git a/src/sizzle-jquery.js b/src/sizzle-jquery.js index 99f4d291..f15b0825 100644 --- a/src/sizzle-jquery.js +++ b/src/sizzle-jquery.js @@ -2,6 +2,6 @@ jQuery.find = Sizzle; jQuery.expr = Sizzle.selectors; jQuery.expr[":"] = jQuery.expr.filters; jQuery.unique = Sizzle.uniqueSort; -jQuery.text = getText; -jQuery.isXMLDoc = isXML; -jQuery.contains = contains; +jQuery.text = Sizzle.getText; +jQuery.isXMLDoc = Sizzle.isXML; +jQuery.contains = Sizzle.contains; diff --git a/src/support.js b/src/support.js index befc5327..cddd3dc3 100644 --- a/src/support.js +++ b/src/support.js @@ -5,7 +5,7 @@ var root = document.documentElement, script = document.createElement("script"), div = document.createElement("div"), - id = "script" + now(); + id = "script" + jQuery.now(); div.style.display = "none"; div.innerHTML = "
a"; diff --git a/src/traversing.js b/src/traversing.js index 67760450..d485d691 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -1,37 +1,9 @@ var runtil = /Until$/, rparentsprev = /^(?:parents|prevUntil|prevAll)/, // Note: This RegExp should be improved, or likely pulled from Sizzle - rmultiselector = /,/; - -// Implement the identical functionality for filter and not -var winnow = function( elements, qualifier, keep ) { - if ( jQuery.isFunction( qualifier ) ) { - return jQuery.grep(elements, function( elem, i ) { - var retVal = !!qualifier.call( elem, i, elem ); - return retVal === keep; - }); - - } else if ( qualifier.nodeType ) { - return jQuery.grep(elements, function( elem, i ) { - return (elem === qualifier) === keep; - }); - - } else if ( typeof qualifier === "string" ) { - var filtered = jQuery.grep(elements, function( elem ) { - return elem.nodeType === 1; - }); - - if ( isSimple.test( qualifier ) ) { - return jQuery.filter(qualifier, filtered, !keep); - } else { - qualifier = jQuery.filter( qualifier, filtered ); - } - } - - return jQuery.grep(elements, function( elem, i ) { - return (jQuery.inArray( elem, qualifier ) >= 0) === keep; - }); -}; + rmultiselector = /,/, + isSimple = /^.[^:#\[\.,]*$/, + slice = Array.prototype.slice; jQuery.fn.extend({ find: function( selector ) { @@ -269,3 +241,33 @@ jQuery.extend({ return r; } }); + +// Implement the identical functionality for filter and not +function winnow( elements, qualifier, keep ) { + if ( jQuery.isFunction( qualifier ) ) { + return jQuery.grep(elements, function( elem, i ) { + var retVal = !!qualifier.call( elem, i, elem ); + return retVal === keep; + }); + + } else if ( qualifier.nodeType ) { + return jQuery.grep(elements, function( elem, i ) { + return (elem === qualifier) === keep; + }); + + } else if ( typeof qualifier === "string" ) { + var filtered = jQuery.grep(elements, function( elem ) { + return elem.nodeType === 1; + }); + + if ( isSimple.test( qualifier ) ) { + return jQuery.filter(qualifier, filtered, !keep); + } else { + qualifier = jQuery.filter( qualifier, filtered ); + } + } + + return jQuery.grep(elements, function( elem, i ) { + return (jQuery.inArray( elem, qualifier ) >= 0) === keep; + }); +}; \ No newline at end of file diff --git a/test/index.html b/test/index.html index d6d02f47..13abd97f 100644 --- a/test/index.html +++ b/test/index.html @@ -6,23 +6,39 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/unit/attributes.js b/test/unit/attributes.js index d7abbad3..21d3d94b 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -482,8 +482,10 @@ test("addClass(Function) with incoming value", function() { }); div.addClass(function(i, val) { - equals( val, old[i], "Make sure the incoming value is correct." ); - return "test"; + if ( this.id !== "_firebugConsole" ) { + equals( val, old[i], "Make sure the incoming value is correct." ); + return "test"; + } }); var pass = true; @@ -553,8 +555,10 @@ test("removeClass(Function) with incoming value", function() { }); $divs.removeClass(function(i, val) { - equals( val, old[i], "Make sure the incoming value is correct." ); - return "test"; + if ( this.id !== "_firebugConsole" ) { + equals( val, old[i], "Make sure the incoming value is correct." ); + return "test"; + } }); ok( !$divs.is('.test'), "Remove Class" ); From b64a51e136a4bcce3d0c2d5292c53d85c2d0e7de Mon Sep 17 00:00:00 2001 From: jeresig Date: Tue, 23 Mar 2010 12:19:47 -0400 Subject: [PATCH 02/21] Handle auto-running of the TestSwarm injection script in the test suite. --- test/data/testrunner.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/data/testrunner.js b/test/data/testrunner.js index 95a1b6ee..a4593407 100644 --- a/test/data/testrunner.js +++ b/test/data/testrunner.js @@ -1 +1,11 @@ jQuery.noConflict(); // Allow the test to run with other libs or jQuery's. + +// load testswarm agent +(function() { + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( !url || url.indexOf("http") !== 0 ) { + return; + } + document.write(""); +})(); From 4e5e31f29e2944ccf4bb349a4ed670f3e8c04ebf Mon Sep 17 00:00:00 2001 From: jeresig Date: Tue, 23 Mar 2010 12:31:40 -0400 Subject: [PATCH 03/21] Changed the order of the tests to run in the same order in which they're specified in the Makefile (fixed a dimensions test bug that popped up as a result). --- test/index.html | 19 ++++++++++--------- test/unit/dimensions.js | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/test/index.html b/test/index.html index 13abd97f..be1f3632 100644 --- a/test/index.html +++ b/test/index.html @@ -10,35 +10,36 @@ - - - + + + - - + + + - + + - - - + + diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index 74405cee..53977907 100644 --- a/test/unit/dimensions.js +++ b/test/unit/dimensions.js @@ -26,7 +26,7 @@ function testWidth( val ) { $div.css({ display: "", border: "", padding: "" }); - jQuery("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" }); + jQuery("#nothiddendivchild").css({ width: 20, padding: "3px", border: "2px solid #fff" }); equals(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding"); jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" }); From f502d118d1c6226ffcc8e3498d8d12fb05b2d7c5 Mon Sep 17 00:00:00 2001 From: jeresig Date: Tue, 23 Mar 2010 15:21:42 -0400 Subject: [PATCH 04/21] Update the TestSwarm URL to point to the new jQuery swarm location. --- test/data/testrunner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/testrunner.js b/test/data/testrunner.js index a4593407..a0eb3621 100644 --- a/test/data/testrunner.js +++ b/test/data/testrunner.js @@ -7,5 +7,5 @@ jQuery.noConflict(); // Allow the test to run with other libs or jQuery's. if ( !url || url.indexOf("http") !== 0 ) { return; } - document.write(""); + document.write(""); })(); From 31cfe62ed4884f0f7eff399375bf6e748738ef71 Mon Sep 17 00:00:00 2001 From: jeresig Date: Tue, 23 Mar 2010 16:22:09 -0400 Subject: [PATCH 05/21] Strip off filename and query string for JSONP Remote test. --- test/unit/ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/ajax.js b/test/unit/ajax.js index ce257f88..135e0541 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -774,7 +774,7 @@ test("jQuery.ajax() - JSONP, Remote", function() { var count = 0; function plus(){ if ( ++count == 4 ) start(); } - var base = window.location.href.replace(/\?.*$/, ""); + var base = window.location.href.replace(/[^\/]*$/, ""); stop(); From 83a97f5c21a3c8c063e05f0df40efe13069c82f2 Mon Sep 17 00:00:00 2001 From: jeresig Date: Tue, 23 Mar 2010 16:24:51 -0400 Subject: [PATCH 06/21] Update other remote test URLs as well. --- test/unit/ajax.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 135e0541..be4b3f02 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -836,7 +836,7 @@ test("jQuery.ajax() - JSONP, Remote", function() { test("jQuery.ajax() - script, Remote", function() { expect(2); - var base = window.location.href.replace(/\?.*$/, ""); + var base = window.location.href.replace(/[^\/]*$/, ""); stop(); @@ -853,7 +853,7 @@ test("jQuery.ajax() - script, Remote", function() { test("jQuery.ajax() - script, Remote with POST", function() { expect(3); - var base = window.location.href.replace(/\?.*$/, ""); + var base = window.location.href.replace(/[^\/]*$/, ""); stop(); @@ -876,7 +876,7 @@ test("jQuery.ajax() - script, Remote with POST", function() { test("jQuery.ajax() - script, Remote with scheme-less URL", function() { expect(2); - var base = window.location.href.replace(/\?.*$/, ""); + var base = window.location.href.replace(/[^\/]*$/, ""); base = base.replace(/^.*?\/\//, "//"); stop(); @@ -991,7 +991,7 @@ test("jQuery.getJSON - Using Native JSON", function() { test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() { expect(2); - var base = window.location.href.replace(/\?.*$/, ""); + var base = window.location.href.replace(/[^\/]*$/, ""); stop(); jQuery.getJSON(url(base + "data/json.php"), function(json) { From 568db29c2b1c139b641197ab61a9af77356cce11 Mon Sep 17 00:00:00 2001 From: jeresig Date: Tue, 23 Mar 2010 16:37:40 -0400 Subject: [PATCH 07/21] Make sure the offset tests work without a built jQuery file. --- test/data/offset/absolute.html | 11 ++++++++++- test/data/offset/body.html | 10 +++++++++- test/data/offset/fixed.html | 10 +++++++++- test/data/offset/relative.html | 10 +++++++++- test/data/offset/scroll.html | 10 +++++++++- test/data/offset/static.html | 10 +++++++++- test/data/offset/table.html | 10 +++++++++- 7 files changed, 64 insertions(+), 7 deletions(-) diff --git a/test/data/offset/absolute.html b/test/data/offset/absolute.html index 2a7eb73e..dc0ba22f 100644 --- a/test/data/offset/absolute.html +++ b/test/data/offset/absolute.html @@ -15,6 +15,15 @@ p.instructions { position: absolute; bottom: 0; } #positionTest { position: absolute; } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +