X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=jquery%2Fjquery.js;h=4f92ce2bb069f0e0a73448259826a61e06ae1a49;hb=8ad487f219f716511cb8ea414439e4ac525fc9ee;hp=9cf694105487e85faee86abe03ef02b6847f44af;hpb=cb3eada739ce377f80408abe2103c95d5a016918;p=jquery.git diff --git a/jquery/jquery.js b/jquery/jquery.js index 9cf6941..4f92ce2 100644 --- a/jquery/jquery.js +++ b/jquery/jquery.js @@ -162,7 +162,7 @@ function $(a,c) { append: function() { var clone = this.size() > 1; var a = $.clean(arguments); - return this.each(function(){ + return this.domManip(function(){ for ( var i = 0; i < a.length; i++ ) { this.appendChild( clone ? a[i].cloneNode(true) : a[i] ); } @@ -181,7 +181,7 @@ function $(a,c) { prepend: function() { var clone = this.size() > 1; var a = $.clean(arguments); - return this.each(function(){ + return this.domManip(function(){ for ( var i = a.length - 1; i >= 0; i-- ) { this.insertBefore( clone ? a[i].cloneNode(true) : a[i], this.firstChild ); } @@ -430,7 +430,7 @@ $.clean = function(a) { for ( var j = 0; j < div.childNodes.length; j++ ) { r[r.length] = div.childNodes[j]; } - } else if ( a[i].length ) { + } else if ( a[i].length && !a[i].nodeType ) { for ( var k = 0; k < a[i].length; k++ ) { r[r.length] = a[i][k]; } @@ -442,6 +442,28 @@ $.clean = function(a) { return r; }; +$.fn = {}; + +/** + * A wrapper function for each() to be used by append and prepend. + * Handles cases where you're trying to modify the inner contents of + * a table, when you actually need to work with the tbody. + */ +$.fn.domManip = function(fn){ + return this.each(function(){ + var obj = this; + + if ( this.nodeName == 'TABLE' ) { + if ( !this.firstChild ) { + this.appendChild( document.createElement("tbody") ); + } + obj = this.firstChild; + } + + $.apply( obj, fn ); + }); +}; + $.g = { '': "m[2] == '*' || a.nodeName.toUpperCase() == m[2].toUpperCase()", '#': "a.getAttribute('id') && a.getAttribute('id').nodeValue == m[2]", @@ -474,7 +496,6 @@ $.g = { disabled: "a.disabled", checked: "a.checked" }, - // TODO: Write getAttribute helper ".": "$.hasWord(a,m[2])", "@": { "=": "$.attr(a,m[3]) == m[4]", @@ -489,8 +510,6 @@ $.g = { "[": "$.Select(m[2],a).length > 0" }; -$.fn = {}; - $.Select = function( t, context ) { context = context || $.context || document; if ( t.constructor != String ) { @@ -624,7 +643,7 @@ $.attr = function(o,a,v){ a = a.replace(r,function(z,b){return b.toUpperCase();}); if ( typeof v != 'undefined' ) { o[a] = v; - if ( o.setAttribute ) { + if ( o.setAttribute && a != 'disabled' ) { o.setAttribute(a,v); } } @@ -641,7 +660,7 @@ $.filter = function(t,r,not) { } while ( t.length > 0 && t.match(/^[:\\.#\\[a-zA-Z\\*]/) ) { - var re = new RegExp( "^\\[ *@([a-z0-9\\(\\)_-]+) *([~!\\|\\*$^=]*) *'?\"?([^'\"]*)'?\"? *\\]", "i" ); + var re = new RegExp( "^\\[ *@([a-z0-9\\*\\(\\)_-]+) *([~!\\|\\*$^=]*) *'?\"?([^'\"]*)'?\"? *\\]", "i" ); var m = re.exec(t); if ( m !== null ) {