X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=b0db0991a4bb1c7682c9a55ddbff65a97869fd95;hb=51a07a6a5f8b1e58fbbce6bcfe4d909a3f9ca964;hp=69628b37f64c9001e158cdb967e13724ac04294e;hpb=529203f6b576aa15201485dd8d704109aa543f0d;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 69628b3..b0db099 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -587,19 +587,17 @@ jQuery.fn = jQuery.prototype = { * and finds the deepest ancestor element within its * structure - it is that element that will en-wrap everything else. * + * This does not work with elements that contain text. Any necessary text + * must be added after the wrapping is done. + * * @example $("p").wrap("
"); * @before

Test Paragraph.

* @result

Test Paragraph.

* * @test var defaultText = 'Try them out:' * var result = $('#first').wrap('
').text(); - * ok( defaultText == result, 'Check for simple wrapping' ); - * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' ); - * - * @test var defaultText = 'Try them out:' - * var result = $('#first').wrap('
xxyy
').text() - * ok( 'xx' + defaultText + 'yy' == result, 'Check for wrapping' ); - * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' ); + * 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 @@ -617,9 +615,17 @@ jQuery.fn = jQuery.prototype = { * provided and finding the deepest ancestor element within its * structure - it is that element that will en-wrap everything else. * - * @example $("p").wrap("
"); - * @before

Test Paragraph.

- * @result

Test Paragraph.

+ * This does not work with elements that contain text. Any necessary text + * must be added after the wrapping is done. + * + * @example $("p").wrap( document.getElementById('content') ); + * @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 @@ -1165,7 +1171,7 @@ jQuery.fn = jQuery.prototype = { return this.each(function(){ var obj = this; - if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) { + if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) { var tbody = this.getElementsByTagName("tbody"); if ( !tbody.length ) { @@ -1212,7 +1218,20 @@ jQuery.fn = jQuery.prototype = { }; /** - * + * Extends the jQuery object itself. Can be used to add both static + * functions and plugin methods. + * + * @example $.fn.extend({ + * check: function() { + * this.each(function() { this.checked = true; }); + * ), + * uncheck: function() { + * this.each(function() { this.checked = false; }); + * } + * }); + * $("input[@type=checkbox]").check(); + * $("input[@type=radio]").uncheck(); + * @desc Adds two plugin methods. * * @private * @name extend @@ -1512,11 +1531,23 @@ jQuery.extend({ visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'", hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'", - // Form elements + // Form attributes enabled: "!a.disabled", disabled: "a.disabled", checked: "a.checked", - selected: "a.selected" + selected: "a.selected", + + // Form elements + text: "a.type=='text'", + radio: "a.type=='radio'", + checkbox: "a.type=='checkbox'", + file: "a.type=='file'", + password: "a.type=='password'", + submit: "a.type=='submit'", + image: "a.type=='image'", + reset: "a.type=='reset'", + button: "a.type=='button'", + input: "a.nodeName.toLowerCase()=='input'||a.nodeName.toLowerCase()=='select'||a.nodeName.toLowerCase()=='textarea'" }, ".": "jQuery.className.has(a,m[2])", "@": { @@ -1643,6 +1674,15 @@ jQuery.extend({ * @test t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] ); * @test t( "All Children of ID with no children", "#firstUL/*", [] ); * + * @test t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "area1", "select1", "select2", "select3"] ); + * @test t( "Form element :radio", ":radio", ["radio1", "radio2"] ); + * @test t( "Form element :checkbox", ":checkbox", ["check1", "check2"] ); + * @test t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] ); + * + * @test t( ":not() Existing attribute", "input:not([@name])", ["text2", "check2"]); + * @test t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]); + * @test t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]); + * * @name $.find * @type Array * @private @@ -1897,15 +1937,17 @@ jQuery.extend({ */ sibling: function(elem, pos, not) { var elems = []; - - var siblings = elem.parentNode.childNodes; - for ( var i = 0; i < siblings.length; i++ ) { - if ( not === true && siblings[i] == elem ) continue; - - if ( siblings[i].nodeType == 1 ) - elems.push( siblings[i] ); - if ( siblings[i] == elem ) - elems.n = elems.length - 1; + + if(elem) { + var siblings = elem.parentNode.childNodes; + for ( var i = 0; i < siblings.length; i++ ) { + if ( not === true && siblings[i] == elem ) continue; + + if ( siblings[i].nodeType == 1 ) + elems.push( siblings[i] ); + if ( siblings[i] == elem ) + elems.n = elems.length - 1; + } } return jQuery.extend( elems, { @@ -2631,6 +2673,10 @@ jQuery.macros = { * @before * @result "test" * + * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" ); + * @test ok( $("#foo").id() == "foo", "Check for id" ); + * @test ok( !$("head").id(), "Check for id" ); + * * @name id * @type String * @cat DOM/Attributes @@ -2657,6 +2703,9 @@ jQuery.macros = { * @before * @result "my image" * + * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" ); + * @test ok( !$("#yahoo").title(), "Check for title" ); + * * @name title * @type String * @cat DOM/Attributes @@ -2683,6 +2732,10 @@ jQuery.macros = { * @before * @result "username" * + * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" ); + * @test ok( $("#hidden1").name() == "hidden", "Check for name" ); + * @test ok( !$("#area1").name(), "Check for name" ); + * * @name name * @type String * @cat DOM/Attributes @@ -2961,7 +3014,7 @@ jQuery.macros = { * @param String expr An expression to filter the sibling Elements with * @cat DOM/Traversing */ - siblings: jQuery.sibling, + siblings: "jQuery.sibling(a, null, true)", /**