From 7448c61ee2199f6f7002e33e533cebc42b000c89 Mon Sep 17 00:00:00 2001 From: John Resig Date: Mon, 14 Aug 2006 01:46:05 +0000 Subject: [PATCH] Massive overhauls to the test suite - it is now generated dynamically, along with the documentation. --- Makefile | 34 ++++--- build/docs/docs.js | 81 +-------------- build/docs/js/doc.js | 5 +- build/docs/style/docs.xsl | 10 +- build/docs/style/style.css | 12 +++ build/js/parse.js | 69 +++++++++++++ build/test/index.html | 64 +++++++++--- build/test/js/test.js | 115 ++++++++++++++++++++++ src/event/event.js | 8 +- src/jquery/jquery.js | 197 ++++++++++++++++++++++++++++++++++--- 10 files changed, 465 insertions(+), 130 deletions(-) create mode 100644 build/js/parse.js create mode 100644 build/test/js/test.js diff --git a/Makefile b/Makefile index f0be47f6c..ed30269a5 100644 --- a/Makefile +++ b/Makefile @@ -6,14 +6,18 @@ DOCS_DIR = ${PREFIX}/docs TEST_DIR = ${PREFIX}/test DIST_DIR = ${PREFIX}/dist -MODULES = jquery event fx ajax +MODULES = ${SRC_DIR}/jquery/*\ + ${SRC_DIR}/event/*\ + ${SRC_DIR}/fx/*\ + ${SRC_DIR}/ajax/* + JQ = ${DIST_DIR}/jquery.js JQ_LITE = ${DIST_DIR}/jquery.lite.js JQ_PACK = ${DIST_DIR}/jquery.pack.js JAR = java -jar ${BUILD_DIR}/js.jar -all: jquery lite pack docs +all: jquery lite pack docs test @@echo "jQuery build complete." ${DIST_DIR}: @@ -21,32 +25,34 @@ ${DIST_DIR}: jquery: ${DIST_DIR} ${JQ} -${JQ}: +${JQ}: ${MODULES} @@echo "Building" ${JQ} - @@for f in ${MODULES}; do \ - echo " - Adding module:" $$f;\ - cat ${SRC_DIR}/$$f/$$f.js >> ${JQ};\ - done + @@mkdir -p ${DIST_DIR} + @@cat ${MODULES} > ${JQ}; @@echo ${JQ} "Built" @@echo lite: ${JQ_LITE} -${JQ_LITE}: jquery +${JQ_LITE}: ${JQ} @@echo "Building" ${JQ_LITE} + @@echo " - Removing ScriptDoc from" ${JQ} @@${JAR} ${BUILD_DIR}/build/lite.js ${JQ} ${JQ_LITE} + @@echo ${JQ_LITE} "Built" @@echo pack: ${JQ_PACK} -${JQ_PACK}: jquery +${JQ_PACK}: ${JQ} @@echo "Building" ${JQ_PACK} + @@echo " - Compressing using Packer" @@${JAR} ${BUILD_DIR}/build/pack.js ${JQ} ${JQ_PACK} + @@echo ${JQ_PACK} "Built" @@echo @@ -55,9 +61,13 @@ test: ${JQ} @@echo " - Making Test Suite Directory:" ${TEST_DIR} @@mkdir -p ${TEST_DIR} + @@mkdir -p ${TEST_DIR}/tests/ + + @@echo " - Removing any old tests" + @@rm -f ${TEST_DIR}/tests/* @@echo " - Copying over script files." - @@cp -R ${BUILD_DIR}/test/js ${TEST_DIR}/js + @@cp -nR ${BUILD_DIR}/test/js ${TEST_DIR}/js @@echo " - Compiling Test Cases" @@${JAR} ${BUILD_DIR}/test/test.js ${JQ} ${TEST_DIR} @@ -73,10 +83,10 @@ docs: ${JQ} @@mkdir -p ${DOCS_DIR}/data @@echo " - Copying over script files." - @@cp -R ${BUILD_DIR}/docs/js ${DOCS_DIR}/js + @@cp -nR ${BUILD_DIR}/docs/js ${DOCS_DIR}/js @@echo " - Copying over style files." - @@cp -R ${BUILD_DIR}/docs/style ${DOCS_DIR}/style + @@cp -nR ${BUILD_DIR}/docs/style ${DOCS_DIR}/style @@echo " - Extracting ScriptDoc from" ${JQ} @@${JAR} ${BUILD_DIR}/docs/docs.js ${JQ} ${DOCS_DIR} diff --git a/build/docs/docs.js b/build/docs/docs.js index 8186f9ddd..6e77b9435 100644 --- a/build/docs/docs.js +++ b/build/docs/docs.js @@ -1,83 +1,6 @@ -load("build/js/json.js", "build/js/xml.js", "build/js/writeFile.js"); - -var types = { - jQuery: "A jQuery object.", - Object: "A simple Javascript object. For example, it could be a String or a Number.", - String: "A string of characters.", - Number: "A numeric valid.", - Element: "The Javascript object representation of a DOM Element.", - Hash: "A Javascript object that contains key/value pairs in the form of properties and values.", - "Array<Element>": "An Array of DOM Elements.", - "Array<String>": "An Array of strings.", - Function: "A reference to a Javascript function." -}; - -var f = readFile(arguments[0]); - -var c = [], bm, m; -var blockMatch = /\/\*\*\s*((.|\n)*?)\s*\*\//g; -var paramMatch = /\@(\S+) *((.|\n)*?)(?=\n\@|!!!)/m; - -while ( bm = blockMatch.exec(f) ) { - block = bm[1].replace(/^\s*\* ?/mg,"") + "!!!"; - var ret = { params: [], examples: [] }; - - while ( m = paramMatch.exec( block ) ) { - block = block.replace( paramMatch, "" ); - - var n = m[1]; - var v = m[2] - .replace(/\s*$/g,"") - .replace(/^\s*/g,"") - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/\n/g, "
") - /*.replace(/(\s\s+)/g, function(a){ - var ret = ""; - for ( var i = 0; i < a.length; i++ ) - ret += " "; - return ret; - })*/ || 1; - - if ( n == 'param' || n == 'any' ) { - var args = v.split(/\s+/); - v = args.slice( 2, args.length ); - v = { type: args[0], name: args[1], desc: v.join(' ') }; - if ( n == 'any' ) v.any = 1; - n = "params"; - } else if ( n == 'example' ) { - v = { code: v }; - n = "examples"; - } - - if ( n == 'desc' || n == 'before' || n == 'after' || n == 'result' ) { - ret.examples[ ret.examples.length - 1 ][ n ] = v; - } else { - if ( ret[ n ] ) { - if ( ret[ n ].constructor == Array ) { - ret[ n ].push( v ); - } else { - ret[ n ] = [ ret[ n ], v ]; - } - } else { - ret[ n ] = v; - } - } - } - - ret.desc = block.replace(/\s*!!!$/,"") - .replace(//g, ">"); - //.replace(/\n\n/g, "

") - //.replace(/\n/g, " "); - - var m = /^((.|\n)*?(\.|$))/.exec( ret.desc ); - if ( m ) ret['short'] = m[1]; - - if ( ret.name ) c.push( ret ); -} +load("build/js/json.js", "build/js/xml.js", "build/js/writeFile.js", "build/js/parse.js"); +var c = parse( readFile(arguments[0]) ); var json = Object.toJSON( c ); writeFile( arguments[1] + "/data/jquery-docs-json.js", json ); diff --git a/build/docs/js/doc.js b/build/docs/js/doc.js index 8bd25b1c3..e2260d77b 100644 --- a/build/docs/js/doc.js +++ b/build/docs/js/doc.js @@ -11,7 +11,10 @@ var types = { }; $(document).ready(function(){ - $("span.tooltip").ToolTipDemo('#fff'); + $("span.tooltip").each(function(){ + if ( types[ this.innerHTML ] ) + this.title = types[ this.innerHTML ]; + }).ToolTipDemo('#fff'); $("a.name").click(function(){ $("div.more,div.short",this.parentNode.parentNode).toggle().find("div.desc",function(){ diff --git a/build/docs/style/docs.xsl b/build/docs/style/docs.xsl index 4adac376f..354b5c0a7 100644 --- a/build/docs/style/docs.xsl +++ b/build/docs/style/docs.xsl @@ -6,7 +6,7 @@ jQuery Docs - API - + @@ -18,13 +18,13 @@
  • - + ( - - + + or , @@ -60,6 +60,8 @@
  • + +

    Raw Data: JSON, JSONP, XML

    diff --git a/build/docs/style/style.css b/build/docs/style/style.css index 783d942b1..7c5554ece 100644 --- a/build/docs/style/style.css +++ b/build/docs/style/style.css @@ -126,3 +126,15 @@ ul#docs li div.example pre { padding: 5px; overflow: auto; } + +p.raw { + font-size: 11px; + color: #FFF; + margin: 5px auto; + width: 600px; + text-align: right; +} + +p.raw a { + color: #FFF; +} diff --git a/build/js/parse.js b/build/js/parse.js new file mode 100644 index 000000000..5b60b0a5b --- /dev/null +++ b/build/js/parse.js @@ -0,0 +1,69 @@ +function parse( f ) { + var c = [], bm, m; + var blockMatch = /\/\*\*\s*((.|\n)*?)\s*\*\//g; + var paramMatch = /\@(\S+) *((.|\n)*?)(?=\n\@|!!!)/m; + + while ( bm = blockMatch.exec(f) ) { + block = bm[1].replace(/^\s*\* ?/mg,"") + "!!!"; + var ret = { params: [], examples: [], tests: [] }; + + while ( m = paramMatch.exec( block ) ) { + block = block.replace( paramMatch, "" ); + + var n = m[1]; + var v = m[2] + .replace(/\s*$/g,"") + .replace(/^\s*/g,"") + .replace(/&/g, "&") + .replace(//g, ">") + //.replace(/\n/g, "
    ") + /*.replace(/(\s\s+)/g, function(a){ + var ret = ""; + for ( var i = 0; i < a.length; i++ ) + ret += " "; + return ret; + })*/ || 1; + + if ( n == 'param' || n == 'any' ) { + var args = v.split(/\s+/); + v = args.slice( 2, args.length ); + v = { type: args[0], name: args[1], desc: v.join(' ') }; + if ( n == 'any' ) v.any = 1; + n = "params"; + } else if ( n == 'example' ) { + v = { code: v }; + n = "examples"; + } else if ( n == 'test' ) { + n = "tests"; + } + + if ( n == 'desc' || n == 'before' || n == 'after' || n == 'result' ) { + ret.examples[ ret.examples.length - 1 ][ n ] = v; + } else { + if ( ret[ n ] ) { + if ( ret[ n ].constructor == Array ) { + ret[ n ].push( v ); + } else { + ret[ n ] = [ ret[ n ], v ]; + } + } else { + ret[ n ] = v; + } + } + } + + ret.desc = block.replace(/\s*!!!$/,"") + .replace(//g, ">"); + //.replace(/\n\n/g, "

    ") + //.replace(/\n/g, " "); + + var m = /^((.|\n)*?(\.|$))/.exec( ret.desc ); + if ( m ) ret['short'] = m[1]; + + if ( ret.name ) c.push( ret ); + } + + return c; +} diff --git a/build/test/index.html b/build/test/index.html index ac90376f2..dad650224 100644 --- a/build/test/index.html +++ b/build/test/index.html @@ -1,21 +1,55 @@ - + - - + + + + - +

    jQuery - Test Suite

    + + +
    + +
    + +
      diff --git a/build/test/js/test.js b/build/test/js/test.js new file mode 100644 index 000000000..e4da77b36 --- /dev/null +++ b/build/test/js/test.js @@ -0,0 +1,115 @@ +function runTests(files) { + runTest( files, 0 ); +} + +function runTest( files, num ) { + $.get(files[num],function(js){ + js = js.replace(/</g, "<").replace(/>/g, ">"); + + try { + eval(js); + } catch(e) { + Test.push( [ false, "Died on test #" + Test.length + ": " + e ] ); + } + + var good = 0, bad = 0; + var ol = document.createElement("ol"); + + var li = "", state = "pass"; + for ( var i = 0; i < Test.length; i++ ) { + var li = document.createElement("li"); + li.className = Test[i][0] ? "pass" : "fail"; + li.innerHTML = Test[i][1]; + ol.appendChild( li ); + + if ( !Test[i][0] ) { + state = "fail"; + bad++; + } else good++; + } + + var li = document.createElement("li"); + li.className = state; + + var b = document.createElement("b"); + b.innerHTML = files[num] + " (" + bad + ", " + good + ", " + Test.length + ")"; + b.onclick = function(){ + var n = this.nextSibling; + if ( jQuery.css( n, "display" ) == "none" ) + n.style.display = "block"; + else + n.style.display = "none"; + }; + li.appendChild( b ); + + li.appendChild( ol ); + + document.getElementById("tests").appendChild( li ); + + Test = []; + if ( ++num < files.length ) runTest( files, num ); + }); +} + +var Test = []; + +function ok(a, msg) { + Test.push( [ !!a, msg ] ); +} + +function cmpOK( a, c, b, msg ) { + var res; + eval( "res = (a " + c + " b)" ); + Test.push( [ res, msg ] ); +} + +function isSet(a, b, msg) { + var ret = true; + + if ( a && b && a.length == b.length ) { + for ( var i in a ) + if ( a[i] != b[i] ) + ret = false; + } else + ret = false; + + if ( !ret && console ) + console.log( msg, a, b ); + + Test.push( [ ret, msg ] ); +} + +function q() { + var r = []; + + for ( var i = 0; i < arguments.length; i++ ) + r.push( document.getElementById( arguments[i] ) ); + + return r; +} + +function t(a,b,c) { + var f = jQuery.find(b); + + var s = ""; + for ( var i = 0; i < f.length; i++ ) + s += (s && ",") + '"' + f[i].id + '"'; + + isSet(f, q.apply(q,c), a + " (" + b + ")"); +} + +function o(a) { + var li = document.createElement("li"); + li.innerHTML = a; + if ( a.indexOf("#") == 0 ) + li.className = "comment"; + else if ( a.indexOf("TODO") >= 0 ) + li.className = "todo"; + else if ( a.indexOf("not ok") == 0 ) + li.classname = "fail"; + else + li.className = "pass"; + document.getElementById("test").appendChild(li); +} + +//plan({noPlan: true}); diff --git a/src/event/event.js b/src/event/event.js index 07126cea3..34d530a6c 100644 --- a/src/event/event.js +++ b/src/event/event.js @@ -1657,9 +1657,9 @@ new function(){ jQuery.ready(); } }, 10); - } else { - // A fallback to window.onload, that will always work - jQuery.event.add( window, "load", jQuery.ready ); - } + } + + // A fallback to window.onload, that will always work + jQuery.event.add( window, "load", jQuery.ready ); }; diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index a0146c372..bdb46a82b 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -14,7 +14,18 @@ window.undefined = window.undefined; /** * Create a new jQuery Object + * + * @test ok( Array.prototype.push, "Array.push()" ); + * @test ok( Function.prototype.apply, "Function.apply()" ); + * @test ok( document.getElementById, "getElementById" ); + * @test ok( document.getElementsByTagName, "getElementsByTagName" ); + * @test ok( RegExp, "RegExp" ); + * @test ok( jQuery, "jQuery" ); + * @test ok( $, "$()" ); + * * @constructor + * @private + * @name jQuery */ function jQuery(a,c) { @@ -102,6 +113,8 @@ jQuery.fn = jQuery.prototype = { * @before * @result 2 * + * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" ); + * * @property * @name length * @type Number @@ -115,6 +128,8 @@ jQuery.fn = jQuery.prototype = { * @before * @result 2 * + * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" ); + * * @name size * @type Number * @cat Core @@ -132,6 +147,8 @@ jQuery.fn = jQuery.prototype = { * @before * @result [ ] * + * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" ); + * * @name get * @type Array * @cat Core @@ -145,6 +162,8 @@ jQuery.fn = jQuery.prototype = { * @before * @result [ ] * + * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" ); + * * @name get * @type Element * @param Number num Access the element in the Nth position. @@ -197,6 +216,14 @@ jQuery.fn = jQuery.prototype = { * @before * @result * + * @test var div = $("div"); + * div.each(function(){this.foo = 'zoo';}); + * var pass = true; + * for ( var i = 0; i < div.size(); i++ ) { + * if ( div.get(i).foo != "zoo" ) pass = false; + * } + * ok( pass, "Execute a function, Relative" ); + * * @name each * @type jQuery * @param Function fn A function to execute @@ -230,6 +257,14 @@ jQuery.fn = jQuery.prototype = { * @before * @result Test Image * + * @test var div = $("div"); + * div.attr({foo: 'baz', zoo: 'ping'}); + * var pass = true; + * for ( var i = 0; i < div.size(); i++ ) { + * if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false; + * } + * ok( pass, "Set Multiple Attributes" ); + * * @name attr * @type jQuery * @param Hash prop A set of key/value pairs to set as object properties. @@ -243,6 +278,14 @@ jQuery.fn = jQuery.prototype = { * @before * @result * + * @test var div = $("div"); + * div.attr("foo", "bar"); + * var pass = true; + * for ( var i = 0; i < div.size(); i++ ) { + * if ( div.get(i).foo != "bar" ) pass = false; + * } + * ok( pass, "Set Attribute" ); + * * @name attr * @type jQuery * @param String key The name of the property to set. @@ -742,7 +785,7 @@ jQuery.fn = jQuery.prototype = { * Extend one object with another, returning the original, * modified, object. This is a great utility for simple inheritance. * - * @name $.extend + * @name jQuery.extend * @param Object obj The object to extend * @param Object prop The object that will be merged into the first. * @type Object @@ -819,7 +862,7 @@ jQuery.extend({ * A generic iterator function, which can be used to seemlessly * iterate over both objects and arrays. * - * @name $.each + * @name jQuery.each * @param Object obj The object, or array, to iterate over. * @param Object fn The function that will be executed on every object. * @type Object @@ -1004,6 +1047,94 @@ jQuery.extend({ } ], + /** + * + * @test t( "Element Selector", "div", ["main","foo"] ); + * @test t( "Element Selector", "body", ["body"] ); + * @test t( "Element Selector", "html", ["html"] ); + * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" ); + * @test t( "Parent Element", "div div", ["foo"] ); + * + * @test t( "ID Selector", "#body", ["body"] ); + * @test t( "ID Selector w/ Element", "body#body", ["body"] ); + * @test t( "ID Selector w/ Element", "ul#first", [] ); + * + * @test t( "Class Selector", ".blog", ["mark","simon"] ); + * @test t( "Class Selector", ".blog.link", ["simon"] ); + * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] ); + * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] ); + * + * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] ); + * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] ); + * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] ); + * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] ); + * + * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] ); + * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] ); + * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] ); + * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] ); + * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] ); + * @test t( "All Children", "code > *", ["anchor1","anchor2"] ); + * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] ); + * @test t( "Adjacent", "a + a", ["groups"] ); + * @test t( "Adjacent", "a +a", ["groups"] ); + * @test t( "Adjacent", "a+ a", ["groups"] ); + * @test t( "Adjacent", "a+a", ["groups"] ); + * @test t( "Adjacent", "p + p", ["ap","en","sap"] ); + * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] ); + * @test t( "First Child", "p:first-child", ["firstp","sndp"] ); + * @test t( "Attribute Exists", "a[@title]", ["google"] ); + * @test t( "Attribute Exists", "*[@title]", ["google"] ); + * @test t( "Attribute Exists", "[@title]", ["google"] ); + * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] ); + * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] ); + * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] ); + * + * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] ); + * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] ); + * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] ); + * @test t( "First Child", "p:first-child", ["firstp","sndp"] ); + * @test t( "Last Child", "p:last-child", ["sap"] ); + * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] ); + * @test t( "Empty", "ul:empty", ["firstUL"] ); + * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] ); + * @test t( "Disabled UI Element", "input:disabled", ["text2"] ); + * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] ); + * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] ); + * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] ); + * @test t( "Element Preceded By", "p ~ div", ["foo"] ); + * @test t( "Not", "a.blog:not(.link)", ["mark"] ); + * + * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" ); + * @test t( "All Div Elements", "//div", ["main","foo"] ); + * @test t( "Absolute Path", "/html/body", ["body"] ); + * @test t( "Absolute Path w/ *", "/* /body", ["body"] ); + * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] ); + * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] ); + * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] ); + * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] ); + * @test t( "Attribute Exists", "//a[@title]", ["google"] ); + * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] ); + * @test t( "Parent Axis", "//p/..", ["main","foo"] ); + * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] ); + * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] ); + * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] ); + * + * @test t( "nth Element", "p:nth(1)", ["ap"] ); + * @test t( "First Element", "p:first", ["firstp"] ); + * @test t( "Last Element", "p:last", ["first"] ); + * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] ); + * @test t( "Odd Elements", "p:odd", ["ap","en","first"] ); + * @test t( "Position Equals", "p:eq(1)", ["ap"] ); + * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] ); + * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] ); + * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] ); + * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] ); + * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] ); + * + * @name jQuery.find + * @private + */ find: function( t, context ) { // Make sure that the context is a DOM Element if ( context && context.nodeType == undefined ) @@ -1201,7 +1332,7 @@ jQuery.extend({ * Remove the whitespace from the beginning and end of a string. * * @private - * @name $.trim + * @name jQuery.trim * @type String * @param String str The string to trim. */ @@ -1213,7 +1344,7 @@ jQuery.extend({ * All ancestors of a given element. * * @private - * @name $.parents + * @name jQuery.parents * @type Array * @param Element elem The element to find the ancestors of. */ @@ -1231,7 +1362,7 @@ jQuery.extend({ * All elements on a specified axis. * * @private - * @name $.sibling + * @name jQuery.sibling * @type Array * @param Element elem The element to find all the siblings of (including itself). */ @@ -1258,7 +1389,7 @@ jQuery.extend({ * Merge two arrays together, removing all duplicates. * * @private - * @name $.merge + * @name jQuery.merge * @type Array * @param Array a The first array to merge. * @param Array b The second array to merge. @@ -1268,22 +1399,22 @@ jQuery.extend({ // Move b over to the new array (this helps to avoid // StaticNodeList instances) - for ( var k = 0; k < b.length; k++ ) - d[k] = b[k]; + for ( var k = 0; k < a.length; k++ ) + d[k] = a[k]; // Now check for duplicates between a and b and only // add the unique items - for ( var i = 0; i < a.length; i++ ) { + for ( var i = 0; i < b.length; i++ ) { var c = true; // The collision-checking process - for ( var j = 0; j < b.length; j++ ) - if ( a[i] == b[j] ) + for ( var j = 0; j < a.length; j++ ) + if ( b[i] == a[j] ) c = false; // If the item is unique, add it if ( c ) - d.push( a[i] ); + d.push( b[i] ); } return d; @@ -1295,7 +1426,7 @@ jQuery.extend({ * array item) and 'i' (which is the index of the item in the array). * * @private - * @name $.grep + * @name jQuery.grep * @type Array * @param Array array The Array to find items in. * @param Function fn The function to process each item against. @@ -1327,7 +1458,7 @@ jQuery.extend({ * be the same size upon completion, as it was when it started. * * @private - * @name $.map + * @name jQuery.map * @type Array * @param Array array The Array to translate. * @param Function fn The function to process each item against. @@ -1346,7 +1477,7 @@ jQuery.extend({ var t = f(a[i],i); if ( t !== null && t != undefined ) { if ( t.constructor != Array ) t = [t]; - r = jQuery.merge( t, r ); + r = jQuery.merge( r, t ); } } return r; @@ -1846,6 +1977,14 @@ jQuery.macros = { * @before
      * @result
      new stuff
      * + * @test var div = $("div"); + * div.html("test"); + * var pass = true; + * for ( var i = 0; i < div.size(); i++ ) { + * if ( div.get(i).childNodes.length == 0 ) pass = false; + * } + * ok( pass, "Set HTML" ); + * * @name html * @type jQuery * @param String val Set the html contents to the specified value. @@ -2225,6 +2364,12 @@ jQuery.macros = { * @before

      Hello

      * @result [

      Hello

      ] * + * @test var pass = true, div = $("div"); + * div.show().each(function(){ + * if ( this.style.display == "none" ) pass = false; + * }); + * ok( pass, "Show" ); + * * @name show * @type jQuery * @cat Effects @@ -2242,6 +2387,12 @@ jQuery.macros = { * @before

      Hello

      * @result [

      Hello

      ] * + * var pass = true, div = $("div"); + * div.hide().each(function(){ + * if ( this.style.display != "none" ) pass = false; + * }); + * ok( pass, "Hide" ); + * * @name hide * @type jQuery * @cat Effects @@ -2277,6 +2428,14 @@ jQuery.macros = { * @example $("p").addClass("selected") * @before

      Hello

      * @result [

      Hello

      ] + * + * @test var div = $("div"); + * div.addClass("test"); + * var pass = true; + * for ( var i = 0; i < div.size(); i++ ) { + * if ( div.get(i).className.indexOf("test") == -1 ) pass = false; + * } + * ok( pass, "Add Class" ); * * @name addClass * @type jQuery @@ -2294,6 +2453,14 @@ jQuery.macros = { * @before

      Hello

      * @result [

      Hello

      ] * + * @test var div = $("div").addClass("test"); + * div.removeClass("test"); + * var pass = true; + * for ( var i = 0; i < div.size(); i++ ) { + * if ( div.get(i).className.indexOf("test") != -1 ) pass = false; + * } + * ok( pass, "Remove Class" ); + * * @name removeClass * @type jQuery * @param String class A CSS class to remove from the elements -- 2.39.5