/**
* 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
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,
* @type jQuery
*/
-// Map the jQuery namespace to the '$' one
-var $ = jQuery;
-
jQuery.fn = jQuery.prototype = {
/**
* The current version of jQuery.
* @before <img src="test1.jpg"/> <img src="test2.jpg"/>
* @result 2
*
- * @test ok( $("div").length == 2, "Get Number of Elements Found" );
- *
* @property
* @name length
* @type Number
* @before <img src="test1.jpg"/> <img src="test2.jpg"/>
* @result 2
*
- * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
- *
* @name size
* @type Number
* @cat Core
* @before <img src="test1.jpg"/> <img src="test2.jpg"/>
* @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
*
- * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
- *
* @name get
* @type Array<Element>
* @cat Core
* @before <img src="test1.jpg"/> <img src="test2.jpg"/>
* @result [ <img src="test1.jpg"/> ]
*
- * @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.
* @before <img/> <img/>
* @result <img src="test.jpg"/> <img src="test.jpg"/>
*
- * @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
* @before <div id="foobar"></div><b></b><span id="foo"></span>
* @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
* @before <img src="test.jpg"/>
* @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.
* @before <img/>
* @result <img src="test.jpg" alt="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.
* @before <img/>
* @result <img src="test.jpg"/>
*
- * @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.
* 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.
* @before <p>Test Paragraph.</p>
* @result <p style="color:red; background:blue;">Test Paragraph.</p>
*
- * @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.
* @result <p style="color:red;">Test Paragraph.</p>
* @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.
* @before <p>Test Paragraph.</p>
* @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
* @before <p>Test Paragraph.</p>
* @result <div class='wrap'><p>Test Paragraph.</p></div>
*
- * @test var defaultText = 'Try them out:'
- * var result = $('#first').wrap('<div class="red"><span></span></div>').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.
* @before <p>Test Paragraph.</p><div id="content"></div>
* @result <div id="content"><p>Test Paragraph.</p></div>
*
- * @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.
* @before <p>I would like to say: </p>
* @result <p>I would like to say: <b>Hello</b></p>
*
- * @test var defaultText = 'Try them out:'
- * var result = $('#first').append('<b>buga</b>');
- * 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.
* @before <p>I would like to say: </p><b id="foo">Hello</b>
* @result <p>I would like to say: <b id="foo">Hello</b></p>
*
- * @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.
* @before <p>I would like to say: </p><b>Hello</b>
* @result <p>I would like to say: <b>Hello</b></p>
*
- * @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<Element> elems An array of elements, all of which will be appended.
* @before <p>I would like to say: </p>
* @result <p><b>Hello</b>I would like to say: </p>
*
- * @test var defaultText = 'Try them out:'
- * var result = $('#first').prepend('<b>buga</b>');
- * 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.
* @before <p>I would like to say: </p><b id="foo">Hello</b>
* @result <p><b id="foo">Hello</b>I would like to say: </p>
*
- * @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.
* @before <p>I would like to say: </p><b>Hello</b>
* @result <p><b>Hello</b>I would like to say: </p>
*
- * @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<Element> elems An array of elements, all of which will be appended.
* @before <p>I would like to say: </p>
* @result <b>Hello</b><p>I would like to say: </p>
*
- * @test var expected = 'This is a normal link: bugaYahoo';
- * $('#yahoo').before('<b>buga</b>');
- * 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.
* @before <p>I would like to say: </p><b id="foo">Hello</b>
* @result <b id="foo">Hello</b><p>I would like to say: </p>
*
- * @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.
* @before <p>I would like to say: </p><b>Hello</b>
* @result <b>Hello</b><p>I would like to say: </p>
*
- * @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<Element> elems An array of elements, all of which will be appended.
* @before <p>I would like to say: </p>
* @result <p>I would like to say: </p><b>Hello</b>
*
- * @test var expected = 'This is a normal link: Yahoobuga';
- * $('#yahoo').after('<b>buga</b>');
- * 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.
* @before <b id="foo">Hello</b><p>I would like to say: </p>
* @result <p>I would like to say: </p><b id="foo">Hello</b>
*
- * @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.
* @before <b>Hello</b><p>I would like to say: </p>
* @result <p>I would like to say: </p><b>Hello</b>
*
- * @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<Element> elems An array of elements, all of which will be appended.
* @before <p><span>Hello</span>, how are you?</p>
* @result $("p").find("span").end() == [ <p>...</p> ]
*
- * @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() );
},
* @before <p><span>Hello</span>, how are you?</p>
* @result $("p").find("span") == [ <span>Hello</span> ]
*
- * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
- *
* @name find
* @type jQuery
* @param String expr An expression to search with.
* @before <b>Hello</b><p>, how are you?</p>
* @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
*
- * @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
* @before <p class="selected">Hello</p><p>How are you?</p>
* @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
*
- * @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.
for ( var i = 0; i < t.length; i++ )
if ( jQuery.filter(t[i],[a]).r.length )
return a;
+ return null;
}) ||
t.constructor == Boolean &&
* @before <p>Hello</p><p id="selected">Hello Again</p>
* @result [ <p>Hello</p> ]
*
- * @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 );
},
* @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 );
},
* @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
* 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.
* @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;
};
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 );
};
if ( p == "height" || p == "width" ) {
var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
- for ( var i in d ) {
+ for ( var i=0; i<d.length; i++ ) {
old["padding" + d[i]] = 0;
old["border" + d[i] + "Width"] = 0;
}
oHeight = e.offsetHeight;
oWidth = e.offsetWidth;
} else {
- e = jQuery(e.cloneNode(true)).css({
- visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
- }).appendTo(e.parentNode)[0];
+ e = jQuery(e.cloneNode(true))
+ .find(":radio").removeAttr("checked").end()
+ .css({
+ visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
+ }).appendTo(e.parentNode)[0];
var parPos = jQuery.css(e.parentNode,"position");
if ( parPos == "" || parPos == "static" )
} else if (document.defaultView && document.defaultView.getComputedStyle) {
+ if (prop == "cssFloat" || prop == "styleFloat")
+ prop = "float";
+
prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
var cur = document.defaultView.getComputedStyle(elem, null);
return ret;
},
-
+
clean: function(a) {
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("<thead") || !a[i].indexOf("<tbody") ) {
- table = "thead";
- a[i] = "<table>" + a[i] + "</table>";
- } else if ( !a[i].indexOf("<tr") ) {
- table = "tr";
- a[i] = "<table>" + a[i] + "</table>";
- } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
- table = "td";
- a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
- }
-
- 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("<opt") ) // option or optgroup
+ wrap = [1, "<select>", "</select>"];
+ else if ( !s.indexOf("<thead") || !s.indexOf("<tbody") )
+ wrap = [1, "<table>", "</table>"];
+ else if ( !s.indexOf("<tr") )
+ wrap = [2, "<table>", "</table>"]; // tbody auto-inserted
+ else if ( !s.indexOf("<td") || !s.indexOf("<th") )
+ wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
+
+ // 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;
},
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])",
"@": {
">|/", "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]", "[@name*=bla]", [] );
- * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] );
- * t( "Non-existing end of attribute [@name$=bla]", "[@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<Element>
* @private
className: "className",
value: "value",
disabled: "disabled",
- checked: "checked"
+ checked: "checked",
+ readonly: "readOnly"
};
// IE actually uses filters for opacity ... elem is actually elem.style
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 {
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 = [];
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 = [];
},
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 ) {
},
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;
}
}
+ // 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;
}
-
}
});
* @before <input type="text" value="some text"/>
* @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
* @before <input type="text" value="some text"/>
* @result <input type="text" value="test"/>
*
- * @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.
* @before <div><input/></div>
* @result <div><b>new stuff</b></div>
*
- * @test var div = $("div");
- * div.html("<b>test</b>");
- * 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.
* @before <input type="text" id="test" value="some text"/>
* @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
* @before <img src="test.jpg" title="my image"/>
* @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
* @before <input type="text" name="username"/>
* @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
*
* It only returns the immediately previous sibling, not all previous siblings.
*
- * @example $("p").previous(".selected")
+ * @example $("p").prev(".selected")
* @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
* @result [ <div><span>Hello</span></div> ]
*
* @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
* @result [ <p>Hello</p>, <p>And Again</p> ]
*
- * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
- *
* @name siblings
* @type jQuery
* @cat DOM/Traversing
* @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
* @result [ <p class="selected">Hello Again</p> ]
*
- * @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
* @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
* @result [ <span>Hello Again</span> ]
*
- * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
- *
* @name children
* @type jQuery
* @cat DOM/Traversing
* @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
* @result [ <p class="selected">Hello Again</p> ]
*
- * @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
* @before <p style="display: none">Hello</p>
* @result [ <p style="display: block">Hello</p> ]
*
- * @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
* @before <p>Hello</p>
* @result [ <p class="selected">Hello</p> ]
*
- * @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
* @before <p class="selected">Hello</p>
* @result [ <p>Hello</p> ]
*
- * @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
},
/**
- * 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 <p>Hello</p><p class="selected">Hello Again</p>
* @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 );
},