X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=965c2798abd538cea0d493bceb2fbc1c4d94dc85;hb=2e544e9eb89c87b9eac6df445474d21e9be604eb;hp=d5c790007fe4b49c6276228a33b8bf45eb6600d1;hpb=3672372c1871d3626447006f0dccc4858a6aeedf;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index d5c7900..965c279 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -1,5 +1,5 @@ /* - * jQuery - New Wave Javascript + * jQuery @VERSION - New Wave Javascript * * Copyright (c) 2006 John Resig (jquery.com) * Dual licensed under the MIT (MIT-LICENSE.txt) @@ -50,8 +50,10 @@ jQuery = function(a,c) { return new jQuery(a,c); // Handle HTML strings - var m = /^[^<]*(<.+>)[^>]*$/.exec(a); - if ( m ) a = jQuery.clean( [ m[1] ] ); + 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 ? @@ -95,7 +97,10 @@ if ( typeof $ != "undefined" ) * @result [

two

] * * @example $("

Hello

").appendTo("#body") - * @desc Creates a div element (and all of its contents) dynamically, and appends it to the element with the ID of body. + * @desc Creates a div element (and all of its contents) dynamically, + * and appends it to the element with the ID of body. Internally, an + * element is created and it's innerHTML property set to the given markup. + * It is therefore both quite flexible and limited. * * @name $ * @param String expr An expression to search with, or a string of HTML to create on the fly. @@ -154,6 +159,7 @@ if ( typeof $ != "undefined" ) * behaves just like $(document).ready(), in that it should be used to wrap * all of the other $() operations on your page. While this function is, * technically, chainable - there really isn't much use for chaining against it. + * You can have as many $(document).ready events on your page as you like. * * @example $(function(){ * // Document is ready @@ -186,7 +192,7 @@ var $ = jQuery; jQuery.fn = jQuery.prototype = { /** - * The current SVN version of jQuery. + * The current version of jQuery. * * @private * @property @@ -194,7 +200,7 @@ jQuery.fn = jQuery.prototype = { * @type String * @cat Core */ - jquery: "$Rev$", + jquery: "@VERSION", /** * The number of elements currently matched. @@ -442,6 +448,17 @@ jQuery.fn = jQuery.prototype = { * $("#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. @@ -493,7 +510,7 @@ jQuery.fn = jQuery.prototype = { * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth, * borderStyle, borderBottomWidth etc. * - * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"'); + * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"'); * * @name css * @type Object @@ -644,7 +661,7 @@ jQuery.fn = jQuery.prototype = { // Insert it before the element to be wrapped this.parentNode.insertBefore( b, this ); - // Find he deepest point in the wrap structure + // Find the deepest point in the wrap structure while ( b.firstChild ) b = b.firstChild; @@ -1380,10 +1397,6 @@ jQuery.extend({ o.className += ( o.className ? " " : "" ) + c; }, remove: function(o,c){ - /* - o.className = !c ? "" : - o.className.replace( - new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");*/ if( !c ) { o.className = ""; } else { @@ -1451,14 +1464,19 @@ jQuery.extend({ }); return p == "height" ? oHeight : oWidth; - } else if ( p == "opacity" && jQuery.browser.msie ) - return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1; + } return jQuery.curCSS( e, p ); }, curCSS: function(elem, prop, force) { var ret; + + if (prop == 'opacity' && jQuery.browser.msie) + return jQuery.attr(elem.style, 'opacity'); + + if (prop == "float" || prop == "cssFloat") + prop = jQuery.browser.msie ? "styleFloat" : "cssFloat"; if (!force && elem.style[prop]) { @@ -1492,7 +1510,9 @@ jQuery.extend({ var r = []; for ( var i = 0; i < a.length; i++ ) { if ( a[i].constructor == String ) { - + // trim whitespace, otherwise indexOf won't work as expected + a[i] = jQuery.trim(a[i]); + var table = ""; if ( !a[i].indexOf("=0", + contains: "((a.firstChild && a.firstChild.nodeValue)||a.innerText||a.innerHTML).indexOf(m[3])>=0", // Visibility visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'", @@ -1561,7 +1581,7 @@ jQuery.extend({ enabled: "!a.disabled", disabled: "a.disabled", checked: "a.checked", - selected: "a.selected", + selected: "a.selected || jQuery.attr(a, 'selected')", // Form elements text: "a.type=='text'", @@ -1820,20 +1840,37 @@ jQuery.extend({ var fix = { "for": "htmlFor", "class": "className", - "float": "cssFloat", + "float": jQuery.browser.msie ? "styleFloat" : "cssFloat", + cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat", innerHTML: "innerHTML", className: "className", value: "value", disabled: "disabled", checked: "checked" }; + + // IE actually uses filters for opacity ... elem is actually elem.style + if (name == "opacity" && jQuery.browser.msie && value != undefined) { + // IE has trouble with opacity if it does not have layout + // Would prefer to check element.hasLayout first but don't have access to the element here + elem['zoom'] = 1; + if (value == 1) // Remove filter to avoid more IE weirdness + return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,""); + else + return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")"; + } else if (name == "opacity" && jQuery.browser.msie) { + return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1; + } + + // Mozilla doesn't play well with opacity 1 + if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999; if ( fix[name] ) { if ( value != undefined ) elem[fix[name]] = value; return elem[fix[name]]; - } else if( value == undefined && $.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) { + } 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 ) { + } else if ( elem.getAttribute != undefined && elem.tagName ) { // IE elem.getAttribute passes even for style if ( value != undefined ) elem.setAttribute( name, value ); return elem.getAttribute( name, 2 ); } else {