X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=e12245c05616bd63af54e03f4f5313e1de0319b8;hb=68313e77488d98d7419e87c7090d4ec9b9d4882b;hp=7a59a4ea6db6a25d763b6b3b3e3fae71ae56b403;hpb=e7669f64d88612884df27c5744558191f8e6c8b1;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 7a59a4e..e12245c 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -15,23 +15,15 @@ window.undefined = window.undefined; /** * Create a new jQuery Object * - * @test ok( Array.prototype.push, "Array.push()" ); - * ok( Function.prototype.apply, "Function.apply()" ); - * ok( document.getElementById, "getElementById" ); - * ok( document.getElementsByTagName, "getElementsByTagName" ); - * ok( RegExp, "RegExp" ); - * ok( jQuery, "jQuery" ); - * ok( $, "$()" ); - * * @constructor * @private * @name jQuery * @cat Core */ -jQuery = function(a,c) { +var jQuery = function(a,c) { // Shortcut for document ready (because $(document).each() is silly) - if ( a && typeof a == "function" && jQuery.fn.ready ) + if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function return jQuery(document).ready(a); // Make sure that a selection was provided @@ -50,30 +42,35 @@ jQuery = function(a,c) { return new jQuery(a,c); // Handle HTML strings - if ( a.constructor == String ) { + if ( typeof a == "string" ) { var m = /^[^<]*(<.+>)[^>]*$/.exec(a); if ( m ) a = jQuery.clean( [ m[1] ] ); } // Watch for when an array is passed in - this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ? + this.get( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ? // Assume that it is an array of DOM Elements jQuery.merge( a, [] ) : // Find the matching elements and save them for later jQuery.find( a, c ) ); - // See if an extra function was provided + // See if an extra function was provided var fn = arguments[ arguments.length - 1 ]; // If so, execute it in context if ( fn && typeof fn == "function" ) this.each(fn); + + return this; }; // Map over the $ in case of overwrite if ( typeof $ != "undefined" ) jQuery._$ = $; + +// Map the jQuery namespace to the '$' one +var $ = jQuery; /** * This function accepts a string containing a CSS selector, @@ -187,9 +184,6 @@ if ( typeof $ != "undefined" ) * @type jQuery */ -// Map the jQuery namespace to the '$' one -var $ = jQuery; - jQuery.fn = jQuery.prototype = { /** * The current version of jQuery. @@ -209,8 +203,6 @@ jQuery.fn = jQuery.prototype = { * @before * @result 2 * - * @test ok( $("div").length == 2, "Get Number of Elements Found" ); - * * @property * @name length * @type Number @@ -224,8 +216,6 @@ jQuery.fn = jQuery.prototype = { * @before * @result 2 * - * @test ok( $("div").size() == 2, "Get Number of Elements Found" ); - * * @name size * @type Number * @cat Core @@ -243,8 +233,6 @@ jQuery.fn = jQuery.prototype = { * @before * @result [ ] * - * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" ); - * * @name get * @type Array * @cat Core @@ -258,8 +246,6 @@ jQuery.fn = jQuery.prototype = { * @before * @result [ ] * - * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" ); - * * @name get * @type Element * @param Number num Access the element in the Nth position. @@ -320,14 +306,6 @@ 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 @@ -354,16 +332,6 @@ jQuery.fn = jQuery.prototype = { * @before
* @result -1 * - * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" ); - * ok( $([window, document]).index(document) == 1, "Check for index of elements" ); - * var inputElements = $('#radio1,#radio2,#check1,#check2'); - * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" ); - * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" ); - * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" ); - * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" ); - * ok( inputElements.index(window) == -1, "Check for not found index" ); - * ok( inputElements.index(document) == -1, "Check for not found index" ); - * * @name index * @type Number * @param Object obj Object to search for @@ -386,19 +354,6 @@ jQuery.fn = jQuery.prototype = { * @before * @result test.jpg * - * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' ); - * ok( $('#text1').attr('type') == "text", 'Check for type attribute' ); - * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' ); - * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' ); - * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' ); - * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' ); - * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' ); - * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' ); - * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' ); - * ok( $('#name').attr('name') == "name", 'Check for name attribute' ); - * ok( $('#text1').attr('name') == "action", 'Check for name attribute' ); - * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' ); - * * @name attr * @type Object * @param String name The name of the property to access. @@ -414,12 +369,6 @@ jQuery.fn = jQuery.prototype = { * @before * @result Test Image * - * @test var pass = true; - * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){ - * if ( this.getAttribute('foo') != "baz" && this.getAttribute('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. @@ -433,32 +382,6 @@ 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).getAttribute('foo') != "bar" ) pass = false; - * } - * ok( pass, "Set Attribute" ); - * - * $("#name").attr('name', 'something'); - * ok( $("#name").name() == 'something', 'Set name attribute' ); - * $("#check2").attr('checked', true); - * ok( document.getElementById('check2').checked == true, 'Set checked attribute' ); - * $("#check2").attr('checked', false); - * ok( document.getElementById('check2').checked == false, 'Set checked attribute' ); - * - * @test stop(); - * $.get('data/dashboard.xml', function(xml) { - * var titles = []; - * $('tab', xml).each(function() { - * titles.push($(this).attr('title')); - * }); - * ok( titles[0] == 'Location', 'attr() in XML context: Check first title' ); - * ok( titles[1] == 'Users', 'attr() in XML context: Check second title' ); - * start(); - * }); - * * @name attr * @type jQuery * @param String key The name of the property to set. @@ -510,8 +433,6 @@ jQuery.fn = jQuery.prototype = { * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth, * borderStyle, borderBottomWidth etc. * - * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"'); - * * @name css * @type Object * @param String name The name of the property to access. @@ -527,12 +448,6 @@ jQuery.fn = jQuery.prototype = { * @before

Test Paragraph.

* @result

Test Paragraph.

* - * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible'); - * $('#foo').css({display: 'none'}); - * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden'); - * $('#foo').css({display: 'block'}); - * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible'); - * * @name css * @type jQuery * @param Hash prop A set of key/value pairs to set as style properties. @@ -547,13 +462,6 @@ jQuery.fn = jQuery.prototype = { * @result

Test Paragraph.

* @desc Changes the color of all paragraphs to red * - * - * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible'); - * $('#foo').css('display', 'none'); - * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden'); - * $('#foo').css('display', 'block'); - * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible'); - * * @name css * @type jQuery * @param String key The name of the property to set. @@ -573,9 +481,6 @@ jQuery.fn = jQuery.prototype = { * @before

Test Paragraph.

* @result Test Paragraph. * - * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog"; - * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' ); - * * @name text * @type String * @cat DOM @@ -611,11 +516,6 @@ jQuery.fn = jQuery.prototype = { * @before

Test Paragraph.

* @result

Test Paragraph.

* - * @test var defaultText = 'Try them out:' - * var result = $('#first').wrap('
').text(); - * ok( defaultText == result, 'Check for wrapping of on-the-fly html' ); - * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); - * * @name wrap * @type jQuery * @param String html A string of HTML, that will be created on the fly and wrapped around the target. @@ -639,11 +539,6 @@ jQuery.fn = jQuery.prototype = { * @before

Test Paragraph.

* @result

Test Paragraph.

* - * @test var defaultText = 'Try them out:' - * var result = $('#first').wrap(document.getElementById('empty')).parent(); - * ok( result.is('ol'), 'Check for element wrapping' ); - * ok( result.text() == defaultText, 'Check for element wrapping' ); - * * @name wrap * @type jQuery * @param Element elem A DOM element that will be wrapped. @@ -680,10 +575,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

* @result

I would like to say: Hello

* - * @test var defaultText = 'Try them out:' - * var result = $('#first').append('buga'); - * ok( result.text() == defaultText + 'buga', 'Check if text appending works' ); - * * @name append * @type jQuery * @param String html A string of HTML, that will be created on the fly and appended to the target. @@ -699,10 +590,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

Hello * @result

I would like to say: Hello

* - * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; - * $('#sap').append(document.getElementById('first')); - * ok( expected == $('#sap').text(), "Check for appending of element" ); - * * @name append * @type jQuery * @param Element elem A DOM element that will be appended. @@ -718,10 +605,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

Hello * @result

I would like to say: Hello

* - * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; - * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]); - * ok( expected == $('#sap').text(), "Check for appending of array of elements" ); - * * @name append * @type jQuery * @param Array elems An array of elements, all of which will be appended. @@ -743,10 +626,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

* @result

HelloI would like to say:

* - * @test var defaultText = 'Try them out:' - * var result = $('#first').prepend('buga'); - * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' ); - * * @name prepend * @type jQuery * @param String html A string of HTML, that will be created on the fly and appended to the target. @@ -762,10 +641,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

Hello * @result

HelloI would like to say:

* - * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; - * $('#sap').prepend(document.getElementById('first')); - * ok( expected == $('#sap').text(), "Check for prepending of element" ); - * * @name prepend * @type jQuery * @param Element elem A DOM element that will be appended. @@ -781,10 +656,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

Hello * @result

HelloI would like to say:

* - * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; - * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]); - * ok( expected == $('#sap').text(), "Check for prepending of array of elements" ); - * * @name prepend * @type jQuery * @param Array elems An array of elements, all of which will be appended. @@ -804,10 +675,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

* @result Hello

I would like to say:

* - * @test var expected = 'This is a normal link: bugaYahoo'; - * $('#yahoo').before('buga'); - * ok( expected == $('#en').text(), 'Insert String before' ); - * * @name before * @type jQuery * @param String html A string of HTML, that will be created on the fly and appended to the target. @@ -821,10 +688,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

Hello * @result Hello

I would like to say:

* - * @test var expected = "This is a normal link: Try them out:Yahoo"; - * $('#yahoo').before(document.getElementById('first')); - * ok( expected == $('#en').text(), "Insert element before" ); - * * @name before * @type jQuery * @param Element elem A DOM element that will be appended. @@ -838,10 +701,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

Hello * @result Hello

I would like to say:

* - * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo"; - * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]); - * ok( expected == $('#en').text(), "Insert array of elements before" ); - * * @name before * @type jQuery * @param Array elems An array of elements, all of which will be appended. @@ -861,10 +720,6 @@ jQuery.fn = jQuery.prototype = { * @before

I would like to say:

* @result

I would like to say:

Hello * - * @test var expected = 'This is a normal link: Yahoobuga'; - * $('#yahoo').after('buga'); - * ok( expected == $('#en').text(), 'Insert String after' ); - * * @name after * @type jQuery * @param String html A string of HTML, that will be created on the fly and appended to the target. @@ -878,10 +733,6 @@ jQuery.fn = jQuery.prototype = { * @before Hello

I would like to say:

* @result

I would like to say:

Hello * - * @test var expected = "This is a normal link: YahooTry them out:"; - * $('#yahoo').after(document.getElementById('first')); - * ok( expected == $('#en').text(), "Insert element after" ); - * * @name after * @type jQuery * @param Element elem A DOM element that will be appended. @@ -895,10 +746,6 @@ jQuery.fn = jQuery.prototype = { * @before Hello

I would like to say:

* @result

I would like to say:

Hello * - * @test var expected = "This is a normal link: YahooTry them out:diveintomark"; - * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]); - * ok( expected == $('#en').text(), "Insert array of elements after" ); - * * @name after * @type jQuery * @param Array elems An array of elements, all of which will be appended. @@ -919,13 +766,13 @@ jQuery.fn = jQuery.prototype = { * @before

Hello, how are you?

* @result $("p").find("span").end() == [

...

] * - * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' ); - * * @name end * @type jQuery * @cat DOM/Traversing */ end: function() { + if( !(this.stack && this.stack.length) ) + return this; return this.get( this.stack.pop() ); }, @@ -941,8 +788,6 @@ jQuery.fn = jQuery.prototype = { * @before

Hello, how are you?

* @result $("p").find("span") == [ Hello ] * - * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' ); - * * @name find * @type jQuery * @param String expr An expression to search with. @@ -965,11 +810,6 @@ jQuery.fn = jQuery.prototype = { * @before Hello

, how are you?

* @result Hello

Hello, how are you?

* - * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' ); - * var clone = $('#yahoo').clone(); - * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' ); - * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' ); - * * @name clone * @type jQuery * @cat DOM/Manipulation @@ -992,14 +832,6 @@ jQuery.fn = jQuery.prototype = { * @before

Hello

How are you?

* @result $("p").filter(".selected") == [

Hello

] * - * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" ); - * @test $("input").filter(":checked",function(i){ - * ok( this == q("radio2", "check1")[i], "Filter elements, context" ); - * }); - * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){ - * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" ); - * }); - * * @name filter * @type jQuery * @param String expr An expression to search with. @@ -1031,6 +863,7 @@ jQuery.fn = jQuery.prototype = { for ( var i = 0; i < t.length; i++ ) if ( jQuery.filter(t[i],[a]).r.length ) return a; + return null; }) || t.constructor == Boolean && @@ -1065,15 +898,13 @@ jQuery.fn = jQuery.prototype = { * @before

Hello

Hello Again

* @result [

Hello

] * - * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not") - * * @name not * @type jQuery * @param String expr An expression with which to remove matching elements * @cat DOM/Traversing */ not: function(t) { - return this.pushStack( t.constructor == String ? + return this.pushStack( typeof t == "string" ? jQuery.filter(t,this,false).r : jQuery.grep(this,function(a){ return a != t; }), arguments ); }, @@ -1120,7 +951,7 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Traversing */ add: function(t) { - return this.pushStack( jQuery.merge( this, t.constructor == String ? + return this.pushStack( jQuery.merge( this, typeof t == "string" ? jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments ); }, @@ -1144,29 +975,6 @@ jQuery.fn = jQuery.prototype = { * @result false * @desc An invalid expression always returns false. * - * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' ); - * ok( !$('#form').is('div'), 'Check for element: A form is not a div' ); - * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' ); - * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' ); - * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' ); - * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' ); - * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' ); - * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' ); - * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' ); - * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' ); - * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' ); - * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' ); - * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' ); - * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' ); - * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' ); - * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' ); - * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' ); - * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' ); - * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' ); - * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' ); - * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' ); - * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' ); - * * @name is * @type Boolean * @param String expr The expression with which to filter @@ -1279,14 +1087,6 @@ jQuery.fn = jQuery.prototype = { * jQuery.extend(settings, options); * @result settings == { validate: true, limit: 5, name: "bar" } * - * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }; - * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" }; - * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" }; - * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" }; - * jQuery.extend(settings, options); - * isSet( settings, merged, "Check if extended: settings must be extended" ); - * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" ); - * * @name $.extend * @param Object obj The object to extend * @param Object prop The object that will be merged into the first. @@ -1294,8 +1094,17 @@ jQuery.fn = jQuery.prototype = { * @cat Javascript */ jQuery.extend = jQuery.fn.extend = function(obj,prop) { + // Watch for the case where null or undefined gets passed in by accident + if ( arguments.length > 1 && (prop === null || prop == undefined) ) + return obj; + + // If no property object was provided, then we're extending jQuery if ( !prop ) { prop = obj; obj = this; } + + // Extend the base object for ( var i in prop ) obj[i] = prop[i]; + + // Return the modified object return obj; }; @@ -1312,7 +1121,7 @@ jQuery.extend({ jQuery.each( jQuery.macros.axis, function(i,n){ jQuery.fn[ i ] = function(a) { var ret = jQuery.map(this,n); - if ( a && a.constructor == String ) + if ( a && typeof a == "string" ) ret = jQuery.filter(a,ret).r; return this.pushStack( ret, arguments ); }; @@ -1435,7 +1244,7 @@ jQuery.extend({ if ( p == "height" || p == "width" ) { var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"]; - for ( var i in d ) { + for ( var i=0; i"; - } else if ( !a[i].indexOf(""; - } else if ( !a[i].indexOf(""; - } - - var div = document.createElement("div"); - div.innerHTML = a[i]; - - if ( table ) { - div = div.firstChild; - if ( table != "thead" ) div = div.firstChild; - if ( table == "td" ) div = div.firstChild; - } - - for ( var j = 0; j < div.childNodes.length; j++ ) - r.push( div.childNodes[j] ); - } else if ( a[i].jquery || a[i].length && !a[i].nodeType ) - for ( var k = 0; k < a[i].length; k++ ) - r.push( a[i][k] ); - else if ( a[i] !== null ) - r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) ); + var arg = a[i]; + if ( typeof arg == "string" ) { // Convert html string into DOM nodes + // Trim whitespace, otherwise indexOf won't work as expected + var s = jQuery.trim(arg), div = document.createElement("div"), wrap = [0,"",""]; + + if ( !s.indexOf("", ""]; + else if ( !s.indexOf("", ""]; + else if ( !s.indexOf("", ""]; // tbody auto-inserted + else if ( !s.indexOf("", ""]; + + // Go to html and back, then peel off extra wrappers + div.innerHTML = wrap[1] + s + wrap[2]; + while ( wrap[0]-- ) div = div.firstChild; + arg = div.childNodes; + } + + + if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function + for ( var n = 0; n < arg.length; n++ ) // Handles Array, jQuery, DOM NodeList collections + r.push(arg[n]); + else + r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) ); } + return r; }, @@ -1593,7 +1401,7 @@ jQuery.extend({ image: "a.type=='image'", reset: "a.type=='reset'", button: "a.type=='button'", - input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)" + input: "/input|select|textarea|button/i.test(a.nodeName)" }, ".": "jQuery.className.has(a,m[2])", "@": { @@ -1612,126 +1420,12 @@ jQuery.extend({ ">|/", "jQuery.sibling(a.firstChild)", "\\+", "jQuery.sibling(a).next", "~", function(a){ - var r = []; var s = jQuery.sibling(a); - if ( s.n > 0 ) - for ( var i = s.n; i < s.length; i++ ) - r.push( s[i] ); - return r; + return s.n >= 0 ? s.slice(s.n+1) : []; } ], /** - * - * @test t( "Element Selector", "div", ["main","foo"] ); - * t( "Element Selector", "body", ["body"] ); - * t( "Element Selector", "html", ["html"] ); - * ok( $("*").size() >= 30, "Element Selector" ); - * t( "Parent Element", "div div", ["foo"] ); - * - * t( "ID Selector", "#body", ["body"] ); - * t( "ID Selector w/ Element", "body#body", ["body"] ); - * t( "ID Selector w/ Element", "ul#first", [] ); - * - * t( "Class Selector", ".blog", ["mark","simon"] ); - * t( "Class Selector", ".blog.link", ["simon"] ); - * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] ); - * t( "Parent Class Selector", "p .blog", ["mark","simon"] ); - * - * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] ); - * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] ); - * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] ); - * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] ); - * - * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] ); - * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] ); - * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] ); - * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] ); - * t( "Child w/ Class", "p > a.blog", ["mark","simon"] ); - * t( "All Children", "code > *", ["anchor1","anchor2"] ); - * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] ); - * t( "Adjacent", "a + a", ["groups"] ); - * t( "Adjacent", "a +a", ["groups"] ); - * t( "Adjacent", "a+ a", ["groups"] ); - * t( "Adjacent", "a+a", ["groups"] ); - * t( "Adjacent", "p + p", ["ap","en","sap"] ); - * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] ); - * t( "First Child", "p:first-child", ["firstp","sndp"] ); - * t( "Attribute Exists", "a[@title]", ["google"] ); - * t( "Attribute Exists", "*[@title]", ["google"] ); - * t( "Attribute Exists", "[@title]", ["google"] ); - * - * t( "Non-existing part of attribute", "[@name*=bla]", [] ); - * t( "Non-existing start of attribute", "[@name^=bla]", [] ); - * t( "Non-existing end of attribute", "[@name$=bla]", [] ); - * - * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] ); - * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] ); - * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] ); - * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] ); - * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] ); - * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] ); - * - * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] ); - * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] ); - * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] ); - * t( "First Child", "p:first-child", ["firstp","sndp"] ); - * t( "Last Child", "p:last-child", ["sap"] ); - * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] ); - * t( "Empty", "ul:empty", ["firstUL"] ); - * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] ); - * t( "Disabled UI Element", "input:disabled", ["text2"] ); - * t( "Checked UI Element", "input:checked", ["radio2","check1"] ); - * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] ); - * t( "Text Contains", "a:contains('Google')", ["google","groups"] ); - * t( "Text Contains", "a:contains('Google Groups')", ["groups"] ); - * t( "Element Preceded By", "p ~ div", ["foo"] ); - * t( "Not", "a.blog:not(.link)", ["mark"] ); - * - * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" ); - * t( "All Div Elements", "//div", ["main","foo"] ); - * t( "Absolute Path", "/html/body", ["body"] ); - * t( "Absolute Path w/ *", "/* /body", ["body"] ); - * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] ); - * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] ); - * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] ); - * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] ); - * t( "Attribute Exists", "//a[@title]", ["google"] ); - * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] ); - * t( "Parent Axis", "//p/..", ["main","foo"] ); - * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] ); - * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] ); - * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] ); - * - * t( "nth Element", "p:nth(1)", ["ap"] ); - * t( "First Element", "p:first", ["firstp"] ); - * t( "Last Element", "p:last", ["first"] ); - * t( "Even Elements", "p:even", ["firstp","sndp","sap"] ); - * t( "Odd Elements", "p:odd", ["ap","en","first"] ); - * t( "Position Equals", "p:eq(1)", ["ap"] ); - * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] ); - * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] ); - * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] ); - * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] ); - * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] ); - * - * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] ); - * - * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] ); - * t( "All Children of ID with no children", "#firstUL/*", [] ); - * - * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] ); - * t( "Form element :radio", ":radio", ["radio1", "radio2"] ); - * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] ); - * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] ); - * t( "Form element :radio:checked", ":radio:checked", ["radio2"] ); - * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] ); - * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] ); - * - * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]); - * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]); - * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]); - * * @name $.find * @type Array * @private @@ -1846,7 +1540,8 @@ jQuery.extend({ className: "className", value: "value", disabled: "disabled", - checked: "checked" + checked: "checked", + readonly: "readOnly" }; // IE actually uses filters for opacity ... elem is actually elem.style @@ -1870,7 +1565,7 @@ jQuery.extend({ return elem[fix[name]]; } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) { return elem.getAttributeNode(name).nodeValue; - } else if ( elem.getAttribute != undefined && elem.tagName ) { // IE elem.getAttribute passes even for style + } else if ( elem.tagName ) { // IE elem.getAttribute passes even for style if ( value != undefined ) elem.setAttribute( name, value ); return elem.getAttribute( name ); } else { @@ -2082,7 +1777,7 @@ jQuery.extend({ grep: function(elems, fn, inv) { // If a string is passed in for the function, make a function // for it (a handy shortcut) - if ( fn.constructor == String ) + if ( typeof fn == "string" ) fn = new Function("a","i","return " + fn); var result = []; @@ -2128,7 +1823,7 @@ jQuery.extend({ map: function(elems, fn) { // If a string is passed in for the function, make a function // for it (a handy shortcut) - if ( fn.constructor == String ) + if ( typeof fn == "string" ) fn = new Function("a","return " + fn); var result = []; @@ -2212,8 +1907,8 @@ jQuery.extend({ }, trigger: function(type,data,element) { - // Touch up the incoming data - data = data || []; + // Clone the incoming data, if any + data = $.merge([], data || []); // Handle a global trigger if ( !element ) { @@ -2233,12 +1928,12 @@ jQuery.extend({ }, handle: function(event) { - if ( typeof jQuery == "undefined" ) return; + if ( typeof jQuery == "undefined" ) return false; - event = event || jQuery.event.fix( window.event ); + event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data // If no correct event was found, fail - if ( !event ) return; + if ( !event ) return false; var returnValue = true; @@ -2255,23 +1950,46 @@ jQuery.extend({ } } + // Clean up added properties in IE to prevent memory leak + if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = null; + return returnValue; }, fix: function(event) { - if ( event ) { + // check IE + if(jQuery.browser.msie) { + // fix target property, if available + // check prevents overwriting of fake target coming from trigger + if(event.srcElement) + event.target = event.srcElement; + + // calculate pageX/Y + var e = document.documentElement, b = document.body; + event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft); + event.pageY = event.clientY + (e.scrollTop || b.scrollTop); + + // check safari and if target is a textnode + } else if(jQuery.browser.safari && event.target.nodeType == 3) { + // target is readonly, clone the event object + event = jQuery.extend({}, event); + // get parentnode from textnode + event.target = event.target.parentNode; + } + + // fix preventDefault and stopPropagation + if (!event.preventDefault) event.preventDefault = function() { this.returnValue = false; }; - + + if (!event.stopPropagation) event.stopPropagation = function() { this.cancelBubble = true; }; - } - + return event; } - } }); @@ -2683,9 +2401,6 @@ jQuery.macros = { * @before * @result "some text" * - * @test ok( $("#text1").val() == "Test", "Check for value of input element" ); - * ok( !$("#text1").val() == "", "Check for value of input element" ); - * * @name val * @type String * @cat DOM/Attributes @@ -2698,11 +2413,6 @@ jQuery.macros = { * @before * @result * - * @test document.getElementById('text1').value = "bla"; - * ok( $("#text1").val() == "bla", "Check for modified value of input element" ); - * $("#text1").val('test'); - * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" ); - * * @name val * @type jQuery * @param String val Set the property to the specified value. @@ -2729,14 +2439,6 @@ 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. @@ -2751,10 +2453,6 @@ jQuery.macros = { * @before * @result "test" * - * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" ); - * ok( $("#foo").id() == "foo", "Check for id" ); - * ok( !$("head").id(), "Check for id" ); - * * @name id * @type String * @cat DOM/Attributes @@ -2781,9 +2479,6 @@ jQuery.macros = { * @before * @result "my image" * - * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" ); - * ok( !$("#yahoo").title(), "Check for title" ); - * * @name title * @type String * @cat DOM/Attributes @@ -2810,10 +2505,6 @@ jQuery.macros = { * @before * @result "username" * - * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" ); - * ok( $("#hidden1").name() == "hidden", "Check for name" ); - * ok( !$("#area1").name(), "Check for name" ); - * * @name name * @type String * @cat DOM/Attributes @@ -3050,7 +2741,7 @@ jQuery.macros = { * * It only returns the immediately previous sibling, not all previous siblings. * - * @example $("p").previous(".selected") + * @example $("p").prev(".selected") * @before
Hello

Hello Again

And Again

* @result [
Hello
] * @@ -3069,8 +2760,6 @@ jQuery.macros = { * @before

Hello

Hello Again

And Again

* @result [

Hello

,

And Again

] * - * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); - * * @name siblings * @type jQuery * @cat DOM/Traversing @@ -3084,9 +2773,6 @@ jQuery.macros = { * @before
Hello

Hello Again

And Again

* @result [

Hello Again

] * - * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" ); - * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); - * * @name siblings * @type jQuery * @param String expr An expression to filter the sibling Elements with @@ -3103,8 +2789,6 @@ jQuery.macros = { * @before

Hello

Hello Again

And Again

* @result [ Hello Again ] * - * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" ); - * * @name children * @type jQuery * @cat DOM/Traversing @@ -3118,8 +2802,6 @@ jQuery.macros = { * @before
Hello

Hello Again

And Again

* @result [

Hello Again

] * - * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" ); - * * @name children * @type jQuery * @param String expr An expression to filter the child Elements with @@ -3153,12 +2835,6 @@ 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 @@ -3217,14 +2893,6 @@ jQuery.macros = { * @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 * @param String class A CSS class to add to the elements @@ -3241,24 +2909,6 @@ 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" ); - * - * reset(); - * - * var div = $("div").addClass("test").addClass("foo").addClass("bar"); - * div.removeClass("test").removeClass("bar").removeClass("foo"); - * var pass = true; - * for ( var i = 0; i < div.size(); i++ ) { - * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false; - * } - * ok( pass, "Remove multiple classes" ); - * * @name removeClass * @type jQuery * @param String class A CSS class to remove from the elements @@ -3269,8 +2919,8 @@ jQuery.macros = { }, /** - * Adds the specified class if it is present, removes it if it is - * not present. + * Adds the specified class if it is not present, removes it if it is + * present. * * @example $("p").toggleClass("selected") * @before

Hello

Hello Again

@@ -3367,8 +3017,6 @@ jQuery.macros = { * @cat Events */ bind: function( type, fn ) { - if ( fn.constructor == String ) - fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn); jQuery.event.add( this, type, fn ); },