/*\r
- * jQuery - New Wave Javascript\r
+ * jQuery @VERSION - New Wave Javascript\r
*\r
* Copyright (c) 2006 John Resig (jquery.com)\r
* Dual licensed under the MIT (MIT-LICENSE.txt)\r
/**\r
* Create a new jQuery Object\r
*\r
- * @test ok( Array.prototype.push, "Array.push()" );\r
- * ok( Function.prototype.apply, "Function.apply()" );\r
- * ok( document.getElementById, "getElementById" );\r
- * ok( document.getElementsByTagName, "getElementsByTagName" );\r
- * ok( RegExp, "RegExp" );\r
- * ok( jQuery, "jQuery" );\r
- * ok( $, "$()" );\r
- *\r
* @constructor\r
* @private\r
* @name jQuery\r
* @cat Core\r
*/\r
-jQuery = function(a,c) {\r
+var jQuery = function(a,c) {\r
\r
// Shortcut for document ready (because $(document).each() is silly)\r
- if ( a && typeof a == "function" && jQuery.fn.ready )\r
+ if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function\r
return jQuery(document).ready(a);\r
\r
// Make sure that a selection was provided\r
- a = a || jQuery.context || document;\r
+ a = a || document;\r
\r
// Watch for when a jQuery object is passed as the selector\r
if ( a.jquery )\r
return new jQuery(a,c);\r
\r
// Handle HTML strings\r
- var m = /^[^<]*(<.+>)[^>]*$/.exec(a);\r
- if ( m ) a = jQuery.clean( [ m[1] ] );\r
+ if ( typeof a == "string" ) {\r
+ var m = /^[^<]*(<.+>)[^>]*$/.exec(a);\r
+ if ( m ) a = jQuery.clean( [ m[1] ] );\r
+ }\r
\r
// Watch for when an array is passed in\r
- this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?\r
+ this.set( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ?\r
// Assume that it is an array of DOM Elements\r
jQuery.merge( a, [] ) :\r
\r
// Find the matching elements and save them for later\r
jQuery.find( a, c ) );\r
\r
- // See if an extra function was provided\r
- var fn = arguments[ arguments.length - 1 ];\r
-\r
- // If so, execute it in context\r
- if ( fn && typeof fn == "function" )\r
- this.each(fn);\r
+ return this;\r
};\r
\r
// Map over the $ in case of overwrite\r
if ( typeof $ != "undefined" )\r
jQuery._$ = $;\r
+ \r
+// Map the jQuery namespace to the '$' one\r
+var $ = jQuery;\r
\r
/**\r
- * This function accepts a string containing a CSS selector,\r
- * basic XPath, or raw HTML, which is then used to match a set of elements.\r
- * The HTML string is different from the traditional selectors in that\r
- * it creates the DOM elements representing that HTML string, on the fly,\r
- * to be (assumedly) inserted into the document later.\r
+ * This function accepts a string containing a CSS or\r
+ * basic XPath selector which is then used to match a set of elements.\r
*\r
* The core functionality of jQuery centers around this function.\r
* Everything in jQuery is based upon this, or uses this in some way.\r
* The most basic use of this function is to pass in an expression\r
* (usually consisting of CSS or XPath), which then finds all matching\r
- * elements and remembers them for later use.\r
+ * elements.\r
*\r
* By default, $() looks for DOM elements within the context of the\r
* current HTML document.\r
* @before <p>one</p> <div><p>two</p></div> <p>three</p>\r
* @result [ <p>two</p> ]\r
*\r
- * @example $("<div><p>Hello</p></div>").appendTo("#body")\r
- * @desc Creates a div element (and all of its contents) dynamically, \r
- * and appends it to the element with the ID of body. Internally, an\r
- * element is created and it's innerHTML property set to the given markup.\r
- * It is therefore both quite flexible and limited.
+ * @example $("input:radio", document.forms[0])\r
+ * @desc Searches for all inputs of type radio within the first form in the document\r
+ *\r
+ * @example $("div", xml.responseXML)\r
+ * @desc This finds all div elements within the specified XML document.\r
*\r
* @name $\r
- * @param String expr An expression to search with, or a string of HTML to create on the fly.\r
+ * @param String expr An expression to search with\r
+ * @param Element context (optional) A DOM Element, or Document, representing the base context.\r
* @cat Core\r
* @type jQuery\r
+ * @see $(Element)\r
+ * @see $(Element<Array>)\r
*/\r
-\r
+ \r
/**\r
- * This function accepts a string containing a CSS selector, or\r
- * basic XPath, which is then used to match a set of elements with the\r
- * context of the specified DOM element, or document\r
+ * This function accepts a string of raw HTML.\r
*\r
- * @example $("div", xml.responseXML)\r
- * @desc This finds all div elements within the specified XML document.\r
+ * The HTML string is different from the traditional selectors in that\r
+ * it creates the DOM elements representing that HTML string, on the fly,\r
+ * to be (assumedly) inserted into the document later.\r
+ *\r
+ * @example $("<div><p>Hello</p></div>").appendTo("#body")\r
+ * @desc Creates a div element (and all of its contents) dynamically, \r
+ * and appends it to the element with the ID of body. Internally, an\r
+ * element is created and it's innerHTML property set to the given markup.\r
+ * It is therefore both quite flexible and limited. \r
*\r
* @name $\r
- * @param String expr An expression to search with.\r
- * @param Element context A DOM Element, or Document, representing the base context.\r
+ * @param String html A string of HTML to create on the fly.\r
* @cat Core\r
* @type jQuery\r
*/\r
* @type jQuery\r
*/\r
\r
-// Map the jQuery namespace to the '$' one\r
-var $ = jQuery;\r
-\r
jQuery.fn = jQuery.prototype = {\r
/**\r
- * The current SVN version of jQuery.\r
+ * The current version of jQuery.\r
*\r
* @private\r
* @property\r
* @type String\r
* @cat Core\r
*/\r
- jquery: "$Rev$",\r
+ jquery: "@VERSION",\r
\r
/**\r
* The number of elements currently matched.\r
* @before <img src="test1.jpg"/> <img src="test2.jpg"/>\r
* @result 2\r
*\r
- * @test ok( $("div").length == 2, "Get Number of Elements Found" );\r
- *\r
* @property\r
* @name length\r
* @type Number\r
* @before <img src="test1.jpg"/> <img src="test2.jpg"/>\r
* @result 2\r
*\r
- * @test ok( $("div").size() == 2, "Get Number of Elements Found" );\r
- *\r
* @name size\r
* @type Number\r
* @cat Core\r
* @before <img src="test1.jpg"/> <img src="test2.jpg"/>\r
* @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]\r
*\r
- * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );\r
- *\r
* @name get\r
* @type Array<Element>\r
* @cat Core\r
* @before <img src="test1.jpg"/> <img src="test2.jpg"/>\r
* @result [ <img src="test1.jpg"/> ]\r
*\r
- * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );\r
- *\r
* @name get\r
* @type Element\r
* @param Number num Access the element in the Nth position.\r
* @cat Core\r
*/\r
+ get: function( num ) {\r
+ return num == undefined ?\r
+\r
+ // Return a 'clean' array\r
+ jQuery.merge( this, [] ) :\r
\r
+ // Return just the object\r
+ this[num];\r
+ },\r
+ \r
/**\r
* Set the jQuery object to an array of elements.\r
*\r
- * @example $("img").get([ document.body ]);\r
- * @result $("img").get() == [ document.body ]\r
+ * @example $("img").set([ document.body ]);\r
+ * @result $("img").set() == [ document.body ]\r
*\r
* @private\r
- * @name get\r
+ * @name set\r
* @type jQuery\r
* @param Elements elems An array of elements\r
* @cat Core\r
*/\r
- get: function( num ) {\r
- // Watch for when an array (of elements) is passed in\r
- if ( num && num.constructor == Array ) {\r
-\r
- // Use a tricky hack to make the jQuery object\r
- // look and feel like an array\r
- this.length = 0;\r
- [].push.apply( this, num );\r
-\r
- return this;\r
- } else\r
- return num == undefined ?\r
-\r
- // Return a 'clean' array\r
- jQuery.merge( this, [] ) :\r
-\r
- // Return just the object\r
- this[num];\r
+ set: function( array ) {\r
+ // Use a tricky hack to make the jQuery object\r
+ // look and feel like an array\r
+ this.length = 0;\r
+ [].push.apply( this, array );\r
+ return this;\r
},\r
\r
/**\r
* argument representing the position of the element in the matched\r
* set.\r
*\r
- * @example $("img").each(function(){\r
- * this.src = "test.jpg";\r
- * });\r
- * @before <img/> <img/>\r
- * @result <img src="test.jpg"/> <img src="test.jpg"/>\r
- *\r
* @example $("img").each(function(i){\r
- * alert( "Image #" + i + " is " + this );\r
+ * this.src = "test" + i + ".jpg";\r
* });\r
* @before <img/> <img/>\r
- * @result <img src="test.jpg"/> <img src="test.jpg"/>\r
- *\r
- * @test var div = $("div");\r
- * div.each(function(){this.foo = 'zoo';});\r
- * var pass = true;\r
- * for ( var i = 0; i < div.size(); i++ ) {\r
- * if ( div.get(i).foo != "zoo" ) pass = false;\r
- * }\r
- * ok( pass, "Execute a function, Relative" );\r
+ * @result <img src="test0.jpg"/> <img src="test1.jpg"/>\r
+ * @desc Iterates over two images and sets their src property\r
*\r
* @name each\r
* @type jQuery\r
* @before <div id="foobar"></div><b></b><span id="foo"></span>\r
* @result -1\r
*\r
- * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );\r
- * ok( $([window, document]).index(document) == 1, "Check for index of elements" );\r
- * var inputElements = $('#radio1,#radio2,#check1,#check2');\r
- * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );\r
- * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );\r
- * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );\r
- * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );\r
- * ok( inputElements.index(window) == -1, "Check for not found index" );\r
- * ok( inputElements.index(document) == -1, "Check for not found index" );\r
- * \r
* @name index\r
* @type Number\r
* @param Object obj Object to search for\r
* @before <img src="test.jpg"/>\r
* @result test.jpg\r
*\r
- * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );\r
- * ok( $('#text1').attr('type') == "text", 'Check for type attribute' );\r
- * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );\r
- * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );\r
- * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );\r
- * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );\r
- * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );\r
- * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );\r
- * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );\r
- * ok( $('#name').attr('name') == "name", 'Check for name attribute' );\r
- * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );\r
- * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );\r
- *\r
* @name attr\r
* @type Object\r
* @param String name The name of the property to access.\r
* @before <img/>\r
* @result <img src="test.jpg" alt="Test Image"/>\r
*\r
- * @test var pass = true;\r
- * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){\r
- * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;\r
- * });\r
- * ok( pass, "Set Multiple Attributes" );\r
- *\r
* @name attr\r
* @type jQuery\r
* @param Hash prop A set of key/value pairs to set as object properties.\r
* @before <img/>\r
* @result <img src="test.jpg"/>\r
*\r
- * @test var div = $("div");\r
- * div.attr("foo", "bar");\r
- * var pass = true;\r
- * for ( var i = 0; i < div.size(); i++ ) {\r
- * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;\r
- * }\r
- * ok( pass, "Set Attribute" );\r
- *\r
- * $("#name").attr('name', 'something');\r
- * ok( $("#name").name() == 'something', 'Set name attribute' );\r
- * $("#check2").attr('checked', true);\r
- * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );\r
- * $("#check2").attr('checked', false);\r
- * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );\r
- *\r
* @name attr\r
* @type jQuery\r
* @param String key The name of the property to set.\r
* representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,\r
* borderStyle, borderBottomWidth etc.\r
*\r
- * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');\r
- *\r
* @name css\r
* @type Object\r
* @param String name The name of the property to access.\r
* @before <p>Test Paragraph.</p>\r
* @result <p style="color:red; background:blue;">Test Paragraph.</p>\r
*\r
- * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');\r
- * $('#foo').css({display: 'none'});\r
- * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');\r
- * $('#foo').css({display: 'block'});\r
- * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');\r
- * \r
* @name css\r
* @type jQuery\r
* @param Hash prop A set of key/value pairs to set as style properties.\r
* @result <p style="color:red;">Test Paragraph.</p>\r
* @desc Changes the color of all paragraphs to red\r
*\r
- *\r
- * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');\r
- * $('#foo').css('display', 'none');\r
- * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');\r
- * $('#foo').css('display', 'block');\r
- * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');\r
- *\r
* @name css\r
* @type jQuery\r
* @param String key The name of the property to set.\r
* @before <p>Test Paragraph.</p>\r
* @result Test Paragraph.\r
*\r
- * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";\r
- * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );\r
- *\r
* @name text\r
* @type String\r
* @cat DOM\r
* @before <p>Test Paragraph.</p>\r
* @result <div class='wrap'><p>Test Paragraph.</p></div>\r
* \r
- * @test var defaultText = 'Try them out:'\r
- * var result = $('#first').wrap('<div class="red"><span></span></div>').text();\r
- * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );\r
- * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );\r
- *\r
* @name wrap\r
* @type jQuery\r
* @param String html A string of HTML, that will be created on the fly and wrapped around the target.\r
* @before <p>Test Paragraph.</p><div id="content"></div>\r
* @result <div id="content"><p>Test Paragraph.</p></div>\r
*\r
- * @test var defaultText = 'Try them out:'\r
- * var result = $('#first').wrap(document.getElementById('empty')).parent();\r
- * ok( result.is('ol'), 'Check for element wrapping' );\r
- * ok( result.text() == defaultText, 'Check for element wrapping' );\r
- *\r
* @name wrap\r
* @type jQuery\r
* @param Element elem A DOM element that will be wrapped.\r
* @before <p>I would like to say: </p>\r
* @result <p>I would like to say: <b>Hello</b></p>\r
*\r
- * @test var defaultText = 'Try them out:'\r
- * var result = $('#first').append('<b>buga</b>');\r
- * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );\r
- *\r
* @name append\r
* @type jQuery\r
* @param String html A string of HTML, that will be created on the fly and appended to the target.\r
* @before <p>I would like to say: </p><b id="foo">Hello</b>\r
* @result <p>I would like to say: <b id="foo">Hello</b></p>\r
*\r
- * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";\r
- * $('#sap').append(document.getElementById('first'));\r
- * ok( expected == $('#sap').text(), "Check for appending of element" );\r
- *\r
* @name append\r
* @type jQuery\r
* @param Element elem A DOM element that will be appended.\r
* @before <p>I would like to say: </p><b>Hello</b>\r
* @result <p>I would like to say: <b>Hello</b></p>\r
*\r
- * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
- * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);\r
- * ok( expected == $('#sap').text(), "Check for appending of array of elements" );\r
- *\r
* @name append\r
* @type jQuery\r
* @param Array<Element> elems An array of elements, all of which will be appended.\r
* @before <p>I would like to say: </p>\r
* @result <p><b>Hello</b>I would like to say: </p>\r
*\r
- * @test var defaultText = 'Try them out:'\r
- * var result = $('#first').prepend('<b>buga</b>');\r
- * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );\r
- *\r
* @name prepend\r
* @type jQuery\r
* @param String html A string of HTML, that will be created on the fly and appended to the target.\r
* @before <p>I would like to say: </p><b id="foo">Hello</b>\r
* @result <p><b id="foo">Hello</b>I would like to say: </p>\r
* \r
- * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";\r
- * $('#sap').prepend(document.getElementById('first'));\r
- * ok( expected == $('#sap').text(), "Check for prepending of element" );\r
- *\r
* @name prepend\r
* @type jQuery\r
* @param Element elem A DOM element that will be appended.\r
* @before <p>I would like to say: </p><b>Hello</b>\r
* @result <p><b>Hello</b>I would like to say: </p>\r
*\r
- * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";\r
- * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);\r
- * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );\r
- *\r
* @name prepend\r
* @type jQuery\r
* @param Array<Element> elems An array of elements, all of which will be appended.\r
* @before <p>I would like to say: </p>\r
* @result <b>Hello</b><p>I would like to say: </p>\r
*\r
- * @test var expected = 'This is a normal link: bugaYahoo';\r
- * $('#yahoo').before('<b>buga</b>');\r
- * ok( expected == $('#en').text(), 'Insert String before' );\r
- *\r
* @name before\r
* @type jQuery\r
* @param String html A string of HTML, that will be created on the fly and appended to the target.\r
* @before <p>I would like to say: </p><b id="foo">Hello</b>\r
* @result <b id="foo">Hello</b><p>I would like to say: </p>\r
*\r
- * @test var expected = "This is a normal link: Try them out:Yahoo";\r
- * $('#yahoo').before(document.getElementById('first'));\r
- * ok( expected == $('#en').text(), "Insert element before" );\r
- *\r
* @name before\r
* @type jQuery\r
* @param Element elem A DOM element that will be appended.\r
* @before <p>I would like to say: </p><b>Hello</b>\r
* @result <b>Hello</b><p>I would like to say: </p>\r
*\r
- * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";\r
- * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);\r
- * ok( expected == $('#en').text(), "Insert array of elements before" );\r
- *\r
* @name before\r
* @type jQuery\r
* @param Array<Element> elems An array of elements, all of which will be appended.\r
* @before <p>I would like to say: </p>\r
* @result <p>I would like to say: </p><b>Hello</b>\r
*\r
- * @test var expected = 'This is a normal link: Yahoobuga';\r
- * $('#yahoo').after('<b>buga</b>');\r
- * ok( expected == $('#en').text(), 'Insert String after' );\r
- *\r
* @name after\r
* @type jQuery\r
* @param String html A string of HTML, that will be created on the fly and appended to the target.\r
* @before <b id="foo">Hello</b><p>I would like to say: </p>\r
* @result <p>I would like to say: </p><b id="foo">Hello</b>\r
*\r
- * @test var expected = "This is a normal link: YahooTry them out:";\r
- * $('#yahoo').after(document.getElementById('first'));\r
- * ok( expected == $('#en').text(), "Insert element after" );\r
- *\r
* @name after\r
* @type jQuery\r
* @param Element elem A DOM element that will be appended.\r
* @before <b>Hello</b><p>I would like to say: </p>\r
* @result <p>I would like to say: </p><b>Hello</b>\r
*\r
- * @test var expected = "This is a normal link: YahooTry them out:diveintomark";\r
- * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);\r
- * ok( expected == $('#en').text(), "Insert array of elements after" );\r
- *\r
* @name after\r
* @type jQuery\r
* @param Array<Element> elems An array of elements, all of which will be appended.\r
* @before <p><span>Hello</span>, how are you?</p>\r
* @result $("p").find("span").end() == [ <p>...</p> ]\r
*\r
- * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );\r
- *\r
* @name end\r
* @type jQuery\r
* @cat DOM/Traversing\r
*/\r
end: function() {\r
- return this.get( this.stack.pop() );\r
+ if( !(this.stack && this.stack.length) )\r
+ return this;\r
+ return this.set( this.stack.pop() );\r
},\r
\r
/**\r
* @before <p><span>Hello</span>, how are you?</p>\r
* @result $("p").find("span") == [ <span>Hello</span> ]\r
*\r
- * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );\r
- *\r
* @name find\r
* @type jQuery\r
* @param String expr An expression to search with.\r
find: function(t) {\r
return this.pushStack( jQuery.map( this, function(a){\r
return jQuery.find(t,a);\r
- }), arguments );\r
+ }));\r
},\r
\r
/**\r
* @before <b>Hello</b><p>, how are you?</p>\r
* @result <b>Hello</b><p><b>Hello</b>, how are you?</p>\r
*\r
- * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );\r
- * var clone = $('#yahoo').clone();\r
- * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );\r
- * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );\r
- *\r
* @name clone\r
* @type jQuery\r
* @cat DOM/Manipulation\r
clone: function(deep) {\r
return this.pushStack( jQuery.map( this, function(a){\r
return a.cloneNode( deep != undefined ? deep : true );\r
- }), arguments );\r
+ }));\r
},\r
\r
/**\r
* @before <p class="selected">Hello</p><p>How are you?</p>\r
* @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]\r
*\r
- * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );\r
- * @test $("input").filter(":checked",function(i){ \r
- * ok( this == q("radio2", "check1")[i], "Filter elements, context" );\r
- * });\r
- * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){\r
- * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );\r
- * });\r
- *\r
* @name filter\r
* @type jQuery\r
* @param String expr An expression to search with.\r
for ( var i = 0; i < t.length; i++ )\r
if ( jQuery.filter(t[i],[a]).r.length )\r
return a;\r
+ return null;\r
}) ||\r
\r
t.constructor == Boolean &&\r
typeof t == "function" &&\r
jQuery.grep( this, t ) ||\r
\r
- jQuery.filter(t,this).r, arguments );\r
+ jQuery.filter(t,this).r );\r
},\r
\r
/**\r
* @before <p>Hello</p><p id="selected">Hello Again</p>\r
* @result [ <p>Hello</p> ]\r
*\r
- * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")\r
- *\r
* @name not\r
* @type jQuery\r
* @param String expr An expression with which to remove matching elements\r
* @cat DOM/Traversing\r
*/\r
not: function(t) {\r
- return this.pushStack( t.constructor == String ?\r
+ return this.pushStack( typeof t == "string" ?\r
jQuery.filter(t,this,false).r :\r
- jQuery.grep(this,function(a){ return a != t; }), arguments );\r
+ jQuery.grep(this,function(a){ return a != t; }) );\r
},\r
\r
/**\r
* @cat DOM/Traversing\r
*/\r
add: function(t) {\r
- return this.pushStack( jQuery.merge( this, t.constructor == String ?\r
- jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );\r
+ return this.pushStack( jQuery.merge( this, typeof t == "string" ?\r
+ jQuery.find(t) : t.constructor == Array ? t : [t] ) );\r
},\r
\r
/**\r
* Checks the current selection against an expression and returns true,\r
- * if the selection fits the given expression. Does return false, if the\r
- * selection does not fit or the expression is not valid.\r
+ * if at least one element of the selection fits the given expression.\r
+ * Does return false, if no element fits or the expression is not valid.\r
*\r
* @example $("input[@type='checkbox']").parent().is("form")\r
* @before <form><input type="checkbox" /></form>\r
* @result false\r
* @desc An invalid expression always returns false.\r
*\r
- * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );\r
- * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );\r
- * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );\r
- * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );\r
- * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );\r
- * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );\r
- * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );\r
- * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );\r
- * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );\r
- * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );\r
- * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );\r
- * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );\r
- * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );\r
- * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );\r
- * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );\r
- * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );\r
- * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );\r
- * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );\r
- * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );\r
- * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );\r
- * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );\r
- * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );\r
- *\r
* @name is\r
* @type Boolean\r
* @param String expr The expression with which to filter\r
},\r
\r
/**\r
- *\r
- *\r
* @private\r
* @name domManip\r
* @param Array args\r
* @param Boolean table\r
- * @param Number int\r
+ * @param Number dir\r
* @param Function fn The function doing the DOM manipulation.\r
* @type jQuery\r
* @cat Core\r
* @type jQuery\r
* @cat Core\r
*/\r
- pushStack: function(a,args) {\r
- var fn = args && args[args.length-1];\r
- var fn2 = args && args[args.length-2];\r
- \r
- if ( fn && fn.constructor != Function ) fn = null;\r
- if ( fn2 && fn2.constructor != Function ) fn2 = null;\r
-\r
- if ( !fn ) {\r
- if ( !this.stack ) this.stack = [];\r
- this.stack.push( this.get() );\r
- this.get( a );\r
- } else {\r
- var old = this.get();\r
- this.get( a );\r
-\r
- if ( fn2 && a.length || !fn2 )\r
- this.each( fn2 || fn ).get( old );\r
- else\r
- this.get( old ).each( fn );\r
- }\r
-\r
- return this;\r
+ pushStack: function(a) {\r
+ if ( !this.stack )\r
+ this.stack = [];\r
+ this.stack.push( this.get() );\r
+ return this.set( a );\r
}\r
};\r
\r
/**\r
- * Extends the jQuery object itself. Can be used to add both static\r
- * functions and plugin methods.\r
+ * Extends the jQuery object itself. Can be used to add functions into\r
+ * the jQuery namespace and to add plugin methods (plugins).\r
* \r
- * @example $.fn.extend({\r
+ * @example jQuery.fn.extend({\r
* check: function() {\r
- * this.each(function() { this.checked = true; });\r
+ * return this.each(function() { this.checked = true; });\r
* ),\r
* uncheck: function() {\r
- * this.each(function() { this.checked = false; });\r
+ * return this.each(function() { this.checked = false; });\r
* }\r
* });\r
* $("input[@type=checkbox]").check();\r
* $("input[@type=radio]").uncheck();\r
* @desc Adds two plugin methods.\r
*\r
- * @private\r
- * @name extend\r
- * @param Object obj\r
+ * @example jQuery.extend({\r
+ * min: function(a, b) { return a < b ? a : b; },\r
+ * max: function(a, b) { return a > b ? a : b; }\r
+ * });\r
+ * @desc Adds two functions into the jQuery namespace\r
+ *\r
+ * @name $.extend\r
+ * @param Object prop The object that will be merged into the jQuery object\r
* @type Object\r
* @cat Core\r
*/\r
\r
/**\r
- * Extend one object with another, returning the original,\r
+ * Extend one object with one or more others, returning the original,\r
* modified, object. This is a great utility for simple inheritance.\r
* \r
* @example var settings = { validate: false, limit: 5, name: "foo" };\r
* var options = { validate: true, name: "bar" };\r
* jQuery.extend(settings, options);\r
* @result settings == { validate: true, limit: 5, name: "bar" }\r
+ * @desc Merge settings and options, modifying settings\r
*\r
- * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };\r
- * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };\r
- * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };\r
- * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };\r
- * jQuery.extend(settings, options);\r
- * isSet( settings, merged, "Check if extended: settings must be extended" );\r
- * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );\r
+ * @example var defaults = { validate: false, limit: 5, name: "foo" };\r
+ * var options = { validate: true, name: "bar" };\r
+ * var settings = jQuery.extend({}, defaults, options);\r
+ * @result settings == { validate: true, limit: 5, name: "bar" }\r
+ * @desc Merge defaults and options, without modifying the defaults\r
*\r
* @name $.extend\r
- * @param Object obj The object to extend\r
- * @param Object prop The object that will be merged into the first.\r
+ * @param Object target The object to extend\r
+ * @param Object prop1 The object that will be merged into the first.\r
+ * @param Object propN (optional) More objects to merge into the first\r
* @type Object\r
* @cat Javascript\r
*/\r
-jQuery.extend = jQuery.fn.extend = function(obj,prop) {\r
- if ( !prop ) { prop = obj; obj = this; }\r
- for ( var i in prop ) obj[i] = prop[i];\r
- return obj;\r
+jQuery.extend = jQuery.fn.extend = function() {\r
+ // copy reference to target object\r
+ var target = arguments[0],\r
+ a = 1;\r
+\r
+ // extend jQuery itself if only one argument is passed\r
+ if ( arguments.length == 1 ) {\r
+ target = this;\r
+ a = 0;\r
+ }\r
+ var prop;\r
+ while (prop = arguments[a++])\r
+ // Extend the base object\r
+ for ( var i in prop ) target[i] = prop[i];\r
+\r
+ // Return the modified object\r
+ return target;\r
};\r
\r
jQuery.extend({\r
jQuery.each( jQuery.macros.axis, function(i,n){\r
jQuery.fn[ i ] = function(a) {\r
var ret = jQuery.map(this,n);\r
- if ( a && a.constructor == String )\r
+ if ( a && typeof a == "string" )\r
ret = jQuery.filter(a,ret).r;\r
return this.pushStack( ret, arguments );\r
};\r
* @type Object\r
* @cat Javascript\r
*/\r
+ // args is for internal usage only\r
each: function( obj, fn, args ) {\r
if ( obj.length == undefined )\r
for ( var i in obj )\r
fn.apply( obj[i], args || [i, obj[i]] );\r
else\r
for ( var i = 0; i < obj.length; i++ )\r
- fn.apply( obj[i], args || [i, obj[i]] );\r
+ if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;\r
return obj;\r
},\r
\r
o.className += ( o.className ? " " : "" ) + c;\r
},\r
remove: function(o,c){\r
- /*\r
- o.className = !c ? "" :\r
- o.className.replace(\r
- new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");*/\r
if( !c ) {\r
o.className = "";\r
} else {\r
if ( p == "height" || p == "width" ) {\r
var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];\r
\r
- for ( var i in d ) {\r
+ for ( var i=0; i<d.length; i++ ) {\r
old["padding" + d[i]] = 0;\r
old["border" + d[i] + "Width"] = 0;\r
}\r
oHeight = e.offsetHeight;\r
oWidth = e.offsetWidth;\r
} else {\r
- e = jQuery(e.cloneNode(true)).css({\r
- visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"\r
- }).appendTo(e.parentNode)[0];\r
+ e = jQuery(e.cloneNode(true))\r
+ .find(":radio").removeAttr("checked").end()\r
+ .css({\r
+ visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"\r
+ }).appendTo(e.parentNode)[0];\r
\r
var parPos = jQuery.css(e.parentNode,"position");\r
if ( parPos == "" || parPos == "static" )\r
});\r
\r
return p == "height" ? oHeight : oWidth;\r
- } else if ( p == "opacity" && jQuery.browser.msie )\r
- return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;\r
+ }\r
\r
return jQuery.curCSS( e, p );\r
},\r
\r
curCSS: function(elem, prop, force) {\r
var ret;\r
+ \r
+ if (prop == 'opacity' && jQuery.browser.msie)\r
+ return jQuery.attr(elem.style, 'opacity');\r
+ \r
+ if (prop == "float" || prop == "cssFloat")\r
+ prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";\r
\r
if (!force && elem.style[prop]) {\r
\r
\r
} else if (document.defaultView && document.defaultView.getComputedStyle) {\r
\r
+ if (prop == "cssFloat" || prop == "styleFloat")\r
+ prop = "float";\r
+\r
prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();\r
var cur = document.defaultView.getComputedStyle(elem, null);\r
\r
\r
return ret;\r
},\r
-\r
+ \r
clean: function(a) {\r
var r = [];\r
for ( var i = 0; i < a.length; i++ ) {\r
- if ( a[i].constructor == String ) {\r
-\r
- var table = "";\r
-\r
- if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {\r
- table = "thead";\r
- a[i] = "<table>" + a[i] + "</table>";\r
- } else if ( !a[i].indexOf("<tr") ) {\r
- table = "tr";\r
- a[i] = "<table>" + a[i] + "</table>";\r
- } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {\r
- table = "td";\r
- a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";\r
- }\r
-\r
- var div = document.createElement("div");\r
- div.innerHTML = a[i];\r
-\r
- if ( table ) {\r
- div = div.firstChild;\r
- if ( table != "thead" ) div = div.firstChild;\r
- if ( table == "td" ) div = div.firstChild;\r
- }\r
-\r
- for ( var j = 0; j < div.childNodes.length; j++ )\r
- r.push( div.childNodes[j] );\r
- } else if ( a[i].jquery || a[i].length && !a[i].nodeType )\r
- for ( var k = 0; k < a[i].length; k++ )\r
- r.push( a[i][k] );\r
- else if ( a[i] !== null )\r
- r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );\r
+ var arg = a[i];\r
+ if ( typeof arg == "string" ) { // Convert html string into DOM nodes\r
+ // Trim whitespace, otherwise indexOf won't work as expected\r
+ var s = jQuery.trim(arg), div = document.createElement("div"), wrap = [0,"",""];\r
+\r
+ if ( !s.indexOf("<opt") ) // option or optgroup\r
+ wrap = [1, "<select>", "</select>"];\r
+ else if ( !s.indexOf("<thead") || !s.indexOf("<tbody") )\r
+ wrap = [1, "<table>", "</table>"];\r
+ else if ( !s.indexOf("<tr") )\r
+ wrap = [2, "<table>", "</table>"]; // tbody auto-inserted\r
+ else if ( !s.indexOf("<td") || !s.indexOf("<th") )\r
+ wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];\r
+\r
+ // Go to html and back, then peel off extra wrappers\r
+ div.innerHTML = wrap[1] + s + wrap[2];\r
+ while ( wrap[0]-- ) div = div.firstChild;\r
+ arg = div.childNodes;\r
+ } \r
+ \r
+ \r
+ if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function\r
+ for ( var n = 0; n < arg.length; n++ ) // Handles Array, jQuery, DOM NodeList collections\r
+ r.push(arg[n]);\r
+ else\r
+ r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );\r
}\r
+\r
return r;\r
},\r
\r
empty: "!a.childNodes.length",\r
\r
// Text Check\r
- contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",\r
+ contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",\r
\r
// Visibility\r
visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",\r
enabled: "!a.disabled",\r
disabled: "a.disabled",\r
checked: "a.checked",\r
- selected: "a.selected",\r
+ selected: "a.selected || jQuery.attr(a, 'selected')",\r
\r
// Form elements\r
text: "a.type=='text'",\r
image: "a.type=='image'",\r
reset: "a.type=='reset'",\r
button: "a.type=='button'",\r
- input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"\r
+ input: "/input|select|textarea|button/i.test(a.nodeName)"\r
},\r
".": "jQuery.className.has(a,m[2])",\r
"@": {\r
">|/", "jQuery.sibling(a.firstChild)",\r
"\\+", "jQuery.sibling(a).next",\r
"~", function(a){\r
- var r = [];\r
var s = jQuery.sibling(a);\r
- if ( s.n > 0 )\r
- for ( var i = s.n; i < s.length; i++ )\r
- r.push( s[i] );\r
- return r;\r
+ return s.n >= 0 ? s.slice(s.n+1) : [];\r
}\r
],\r
\r
/**\r
- *\r
- * @test t( "Element Selector", "div", ["main","foo"] );\r
- * t( "Element Selector", "body", ["body"] );\r
- * t( "Element Selector", "html", ["html"] );\r
- * ok( $("*").size() >= 30, "Element Selector" );\r
- * t( "Parent Element", "div div", ["foo"] );\r
- *\r
- * t( "ID Selector", "#body", ["body"] );\r
- * t( "ID Selector w/ Element", "body#body", ["body"] );\r
- * t( "ID Selector w/ Element", "ul#first", [] );\r
- *\r
- * t( "Class Selector", ".blog", ["mark","simon"] );\r
- * t( "Class Selector", ".blog.link", ["simon"] );\r
- * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );\r
- * t( "Parent Class Selector", "p .blog", ["mark","simon"] );\r
- *\r
- * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );\r
- * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );\r
- * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );\r
- * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );\r
- *\r
- * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );\r
- * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );\r
- * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );\r
- * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );\r
- * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );\r
- * t( "All Children", "code > *", ["anchor1","anchor2"] );\r
- * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );\r
- * t( "Adjacent", "a + a", ["groups"] );\r
- * t( "Adjacent", "a +a", ["groups"] );\r
- * t( "Adjacent", "a+ a", ["groups"] );\r
- * t( "Adjacent", "a+a", ["groups"] );\r
- * t( "Adjacent", "p + p", ["ap","en","sap"] );\r
- * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );\r
- * t( "First Child", "p:first-child", ["firstp","sndp"] );\r
- * t( "Attribute Exists", "a[@title]", ["google"] );\r
- * t( "Attribute Exists", "*[@title]", ["google"] );\r
- * t( "Attribute Exists", "[@title]", ["google"] );\r
- * \r
- * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] ); \r
- * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] ); \r
- * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] ); \r
- *\r
- * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );\r
- * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );\r
- * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );\r
- * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );\r
- * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );\r
- * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );\r
- *\r
- * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );\r
- * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );\r
- * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );\r
- * t( "First Child", "p:first-child", ["firstp","sndp"] );\r
- * t( "Last Child", "p:last-child", ["sap"] );\r
- * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );\r
- * t( "Empty", "ul:empty", ["firstUL"] );\r
- * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );\r
- * t( "Disabled UI Element", "input:disabled", ["text2"] );\r
- * t( "Checked UI Element", "input:checked", ["radio2","check1"] );\r
- * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );\r
- * t( "Text Contains", "a:contains('Google')", ["google","groups"] );\r
- * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );\r
- * t( "Element Preceded By", "p ~ div", ["foo"] );\r
- * t( "Not", "a.blog:not(.link)", ["mark"] );\r
- *\r
- * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );\r
- * t( "All Div Elements", "//div", ["main","foo"] );\r
- * t( "Absolute Path", "/html/body", ["body"] );\r
- * t( "Absolute Path w/ *", "/* /body", ["body"] );\r
- * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );\r
- * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );\r
- * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );\r
- * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );\r
- * t( "Attribute Exists", "//a[@title]", ["google"] );\r
- * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );\r
- * t( "Parent Axis", "//p/..", ["main","foo"] );\r
- * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );\r
- * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );\r
- * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );\r
- *\r
- * t( "nth Element", "p:nth(1)", ["ap"] );\r
- * t( "First Element", "p:first", ["firstp"] );\r
- * t( "Last Element", "p:last", ["first"] );\r
- * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );\r
- * t( "Odd Elements", "p:odd", ["ap","en","first"] );\r
- * t( "Position Equals", "p:eq(1)", ["ap"] );\r
- * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );\r
- * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );\r
- * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );\r
- * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );\r
- * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );\r
- *\r
- * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );\r
- *\r
- * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );\r
- * t( "All Children of ID with no children", "#firstUL/*", [] );\r
- *\r
- * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );\r
- * t( "Form element :radio", ":radio", ["radio1", "radio2"] );\r
- * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );\r
- * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );\r
- * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );\r
- * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );\r
- * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );\r
- *\r
- * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);\r
- * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);\r
- * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);\r
- *\r
* @name $.find\r
* @type Array<Element>\r
* @private\r
context = null;\r
\r
// Set the correct context (if none is provided)\r
- context = context || jQuery.context || document;\r
+ context = context || document;\r
\r
if ( t.constructor != String ) return [t];\r
\r
var fix = {\r
"for": "htmlFor",\r
"class": "className",\r
- "float": "cssFloat",\r
+ "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",\r
+ cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",\r
innerHTML: "innerHTML",\r
className: "className",\r
value: "value",\r
disabled: "disabled",\r
- checked: "checked"\r
+ checked: "checked",\r
+ readonly: "readOnly"\r
};\r
+ \r
+ // IE actually uses filters for opacity ... elem is actually elem.style\r
+ if (name == "opacity" && jQuery.browser.msie && value != undefined) {\r
+ // IE has trouble with opacity if it does not have layout\r
+ // Would prefer to check element.hasLayout first but don't have access to the element here\r
+ elem['zoom'] = 1; \r
+ if (value == 1) // Remove filter to avoid more IE weirdness\r
+ return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");\r
+ else\r
+ return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";\r
+ } else if (name == "opacity" && jQuery.browser.msie) {\r
+ return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;\r
+ }\r
+ \r
+ // Mozilla doesn't play well with opacity 1\r
+ if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;\r
\r
if ( fix[name] ) {\r
if ( value != undefined ) elem[fix[name]] = value;\r
return elem[fix[name]];\r
- } else if( value == undefined && $.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {\r
+ } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {\r
return elem.getAttributeNode(name).nodeValue;\r
- } else if ( elem.getAttribute != undefined ) {\r
+ } else if ( elem.tagName ) { // IE elem.getAttribute passes even for style\r
if ( value != undefined ) elem.setAttribute( name, value );\r
- return elem.getAttribute( name, 2 );\r
+ return elem.getAttribute( name );\r
} else {\r
name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});\r
if ( value != undefined ) elem[name] = value;\r
grep: function(elems, fn, inv) {\r
// If a string is passed in for the function, make a function\r
// for it (a handy shortcut)\r
- if ( fn.constructor == String )\r
+ if ( typeof fn == "string" )\r
fn = new Function("a","i","return " + fn);\r
\r
var result = [];\r
map: function(elems, fn) {\r
// If a string is passed in for the function, make a function\r
// for it (a handy shortcut)\r
- if ( fn.constructor == String )\r
+ if ( typeof fn == "string" )\r
fn = new Function("a","return " + fn);\r
\r
var result = [];\r
},\r
\r
trigger: function(type,data,element) {\r
- // Touch up the incoming data\r
- data = data || [];\r
+ // Clone the incoming data, if any\r
+ data = $.merge([], data || []);\r
\r
// Handle a global trigger\r
if ( !element ) {\r
},\r
\r
handle: function(event) {\r
- if ( typeof jQuery == "undefined" ) return;\r
+ if ( typeof jQuery == "undefined" ) return false;\r
\r
- event = event || jQuery.event.fix( window.event );\r
+ event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data\r
\r
// If no correct event was found, fail\r
- if ( !event ) return;\r
+ if ( !event ) return false;\r
\r
var returnValue = true;\r
\r
}\r
}\r
\r
+ // Clean up added properties in IE to prevent memory leak\r
+ if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = null;\r
+\r
return returnValue;\r
},\r
\r
fix: function(event) {\r
- if ( event ) {\r
+ // check IE\r
+ if(jQuery.browser.msie) {\r
+ // fix target property, if available\r
+ // check prevents overwriting of fake target coming from trigger\r
+ if(event.srcElement)\r
+ event.target = event.srcElement;\r
+ \r
+ // calculate pageX/Y\r
+ var e = document.documentElement, b = document.body;\r
+ event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);\r
+ event.pageY = event.clientY + (e.scrollTop || b.scrollTop);\r
+ \r
+ // check safari and if target is a textnode\r
+ } else if(jQuery.browser.safari && event.target.nodeType == 3) {\r
+ // target is readonly, clone the event object\r
+ event = jQuery.extend({}, event);\r
+ // get parentnode from textnode\r
+ event.target = event.target.parentNode;\r
+ }\r
+ \r
+ // fix preventDefault and stopPropagation\r
+ if (!event.preventDefault)\r
event.preventDefault = function() {\r
this.returnValue = false;\r
};\r
-\r
+ \r
+ if (!event.stopPropagation)\r
event.stopPropagation = function() {\r
this.cancelBubble = true;\r
};\r
- }\r
-\r
+ \r
return event;\r
}\r
-\r
}\r
});\r
\r
* This property is available before the DOM is ready, therefore you can\r
* use it to add ready events only for certain browsers.\r
*\r
- * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">\r
- * jQBrowser plugin</a> for advanced browser detection:\r
- *\r
* @example $.browser.msie\r
- * @desc returns true if the current useragent is some version of microsoft's internet explorer\r
+ * @desc Returns true if the current useragent is some version of microsoft's internet explorer\r
*\r
* @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }\r
* @desc Alerts "this is safari!" only for safari browsers\r
*\r
+ * @property\r
* @name $.browser\r
* @type Boolean\r
* @cat Javascript\r
*/\r
+ \r
+/*\r
+ * Wheather the W3C compliant box model is being used.\r
+ *\r
+ * @property\r
+ * @name $.boxModel\r
+ * @type Boolean\r
+ * @cat Javascript\r
+ */\r
new function() {\r
var b = navigator.userAgent.toLowerCase();\r
\r
* @before <input type="text" value="some text"/>\r
* @result "some text"\r
*\r
- * @test ok( $("#text1").val() == "Test", "Check for value of input element" );\r
- * ok( !$("#text1").val() == "", "Check for value of input element" );\r
- *\r
* @name val\r
* @type String\r
* @cat DOM/Attributes\r
/**\r
* Set the value of every matched element.\r
*\r
- * @example $("input").value("test");\r
+ * @example $("input").val("test");\r
* @before <input type="text" value="some text"/>\r
* @result <input type="text" value="test"/>\r
*\r
- * @test document.getElementById('text1').value = "bla";\r
- * ok( $("#text1").val() == "bla", "Check for modified value of input element" );\r
- * $("#text1").val('test');\r
- * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );\r
- *\r
* @name val\r
* @type jQuery\r
* @param String val Set the property to the specified value.\r
* @before <div><input/></div>\r
* @result <div><b>new stuff</b></div>\r
*\r
- * @test var div = $("div");\r
- * div.html("<b>test</b>");\r
- * var pass = true;\r
- * for ( var i = 0; i < div.size(); i++ ) {\r
- * if ( div.get(i).childNodes.length == 0 ) pass = false;\r
- * }\r
- * ok( pass, "Set HTML" );\r
- *\r
* @name html\r
* @type jQuery\r
* @param String val Set the html contents to the specified value.\r
* @before <input type="text" id="test" value="some text"/>\r
* @result "test"\r
*\r
- * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );\r
- * ok( $("#foo").id() == "foo", "Check for id" );\r
- * ok( !$("head").id(), "Check for id" );\r
- *\r
* @name id\r
* @type String\r
* @cat DOM/Attributes\r
* @before <img src="test.jpg" title="my image"/>\r
* @result "my image"\r
*\r
- * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );\r
- * ok( !$("#yahoo").title(), "Check for title" );\r
- *\r
* @name title\r
* @type String\r
* @cat DOM/Attributes\r
* @before <input type="text" name="username"/>\r
* @result "username"\r
*\r
- * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );\r
- * ok( $("#hidden1").name() == "hidden", "Check for name" );\r
- * ok( !$("#area1").name(), "Check for name" );\r
- *\r
* @name name\r
* @type String\r
* @cat DOM/Attributes\r
*\r
* It only returns the immediately previous sibling, not all previous siblings.\r
*\r
- * @example $("p").previous(".selected")\r
+ * @example $("p").prev(".selected")\r
* @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>\r
* @result [ <div><span>Hello</span></div> ]\r
*\r
* @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>\r
* @result [ <p>Hello</p>, <p>And Again</p> ]\r
*\r
- * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); \r
- *\r
* @name siblings\r
* @type jQuery\r
* @cat DOM/Traversing\r
* @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>\r
* @result [ <p class="selected">Hello Again</p> ]\r
*\r
- * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" ); \r
- * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );\r
- *\r
* @name siblings\r
* @type jQuery\r
* @param String expr An expression to filter the sibling Elements with\r
* @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>\r
* @result [ <span>Hello Again</span> ]\r
*\r
- * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );\r
- *\r
* @name children\r
* @type jQuery\r
* @cat DOM/Traversing\r
* @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>\r
* @result [ <p class="selected">Hello Again</p> ]\r
*\r
- * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" ); \r
- *\r
* @name children\r
* @type jQuery\r
* @param String expr An expression to filter the child Elements with\r
* @cat DOM\r
*/\r
removeAttr: function( key ) {\r
+ jQuery.attr( this, key, "" );\r
this.removeAttribute( key );\r
},\r
\r
* @before <p style="display: none">Hello</p>\r
* @result [ <p style="display: block">Hello</p> ]\r
*\r
- * @test var pass = true, div = $("div");\r
- * div.show().each(function(){\r
- * if ( this.style.display == "none" ) pass = false;\r
- * });\r
- * ok( pass, "Show" );\r
- *\r
* @name show\r
* @type jQuery\r
* @cat Effects\r
* @before <p>Hello</p>\r
* @result [ <p class="selected">Hello</p> ]\r
*\r
- * @test var div = $("div");\r
- * div.addClass("test");\r
- * var pass = true;\r
- * for ( var i = 0; i < div.size(); i++ ) {\r
- * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;\r
- * }\r
- * ok( pass, "Add Class" );\r
- *\r
* @name addClass\r
* @type jQuery\r
* @param String class A CSS class to add to the elements\r
* @before <p class="selected">Hello</p>\r
* @result [ <p>Hello</p> ]\r
*\r
- * @test var div = $("div").addClass("test");\r
- * div.removeClass("test");\r
- * var pass = true;\r
- * for ( var i = 0; i < div.size(); i++ ) {\r
- * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;\r
- * }\r
- * ok( pass, "Remove Class" );\r
- * \r
- * reset();\r
- *\r
- * var div = $("div").addClass("test").addClass("foo").addClass("bar");\r
- * div.removeClass("test").removeClass("bar").removeClass("foo");\r
- * var pass = true;\r
- * for ( var i = 0; i < div.size(); i++ ) {\r
- * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;\r
- * }\r
- * ok( pass, "Remove multiple classes" );\r
- *\r
* @name removeClass\r
* @type jQuery\r
* @param String class A CSS class to remove from the elements\r
},\r
\r
/**\r
- * Adds the specified class if it is present, removes it if it is\r
- * not present.\r
+ * Adds the specified class if it is not present, removes it if it is\r
+ * present.\r
*\r
* @example $("p").toggleClass("selected")\r
* @before <p>Hello</p><p class="selected">Hello Again</p>\r
* @cat DOM\r
*/\r
toggleClass: function( c ){\r
- jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);\r
+ jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);\r
},\r
\r
/**\r
* @cat Events\r
*/\r
bind: function( type, fn ) {\r
- if ( fn.constructor == String )\r
- fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);\r
jQuery.event.add( this, type, fn );\r
},\r
\r