X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=76f0f0e021518b51dec5c5ea4809afe948be6cef;hb=40b55adf5c22542985c3f7fc2717df9604a3d973;hp=a0d8775177dd23b61fd5955d63c589267529f78d;hpb=ca5b83c5c9619e12827f2e92adb6e6c5708df88e;p=jquery.git
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index a0d8775..76f0f0e 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -1,5 +1,5 @@
/*
- * jQuery - New Wave Javascript
+ * jQuery @VERSION - New Wave Javascript
*
* Copyright (c) 2006 John Resig (jquery.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
@@ -16,22 +16,22 @@ window.undefined = window.undefined;
* Create a new jQuery Object
*
* @test ok( Array.prototype.push, "Array.push()" );
- * @test ok( Function.prototype.apply, "Function.apply()" );
- * @test ok( document.getElementById, "getElementById" );
- * @test ok( document.getElementsByTagName, "getElementsByTagName" );
- * @test ok( RegExp, "RegExp" );
- * @test ok( jQuery, "jQuery" );
- * @test ok( $, "$()" );
+ * 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 && a.constructor == Function && jQuery.fn.ready )
+ if ( a && typeof a == "function" && jQuery.fn.ready )
return jQuery(document).ready(a);
// Make sure that a selection was provided
@@ -50,8 +50,10 @@ jQuery = function(a,c) {
return new jQuery(a,c);
// Handle HTML strings
- var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
- if ( m ) a = jQuery.clean( [ m[1] ] );
+ if ( a.constructor == 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 ?
@@ -61,12 +63,14 @@ jQuery = function(a,c) {
// 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 && fn.constructor == Function )
+ if ( fn && typeof fn == "function" )
this.each(fn);
+
+ return this;
};
// Map over the $ in case of overwrite
@@ -95,7 +99,10 @@ if ( typeof $ != "undefined" )
* @result [
two
]
*
* @example $("
Hello
").appendTo("#body")
- * @desc Creates a div element (and all of its contents) dynamically, and appends it to the element with the ID of body.
+ * @desc Creates a div element (and all of its contents) dynamically,
+ * and appends it to the element with the ID of body. Internally, an
+ * element is created and it's innerHTML property set to the given markup.
+ * It is therefore both quite flexible and limited.
*
* @name $
* @param String expr An expression to search with, or a string of HTML to create on the fly.
@@ -154,6 +161,7 @@ if ( typeof $ != "undefined" )
* behaves just like $(document).ready(), in that it should be used to wrap
* all of the other $() operations on your page. While this function is,
* technically, chainable - there really isn't much use for chaining against it.
+ * You can have as many $(document).ready events on your page as you like.
*
* @example $(function(){
* // Document is ready
@@ -186,7 +194,7 @@ var $ = jQuery;
jQuery.fn = jQuery.prototype = {
/**
- * The current SVN version of jQuery.
+ * The current version of jQuery.
*
* @private
* @property
@@ -194,7 +202,7 @@ jQuery.fn = jQuery.prototype = {
* @type String
* @cat Core
*/
- jquery: "$Rev$",
+ jquery: "@VERSION",
/**
* The number of elements currently matched.
@@ -349,14 +357,14 @@ jQuery.fn = jQuery.prototype = {
* @result -1
*
* @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
- * @test ok( $([window, document]).index(document) == 1, "Check for index of elements" );
- * @test var inputElements = $('#radio1,#radio2,#check1,#check2');
- * @test ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
- * @test ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
- * @test ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
- * @test ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
- * @test ok( inputElements.index(window) == -1, "Check for not found index" );
- * @test ok( inputElements.index(document) == -1, "Check for not found index" );
+ * 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
@@ -381,18 +389,18 @@ jQuery.fn = jQuery.prototype = {
* @result test.jpg
*
* @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
- * @test ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
- * @test ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
- * @test ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
- * @test ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
- * @test ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
- * @test ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
- * @test ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
- * @test ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
- * @test ok( $('#name').attr('name') == "name", 'Check for name attribute' );
- * @test ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
- * @test ok( $('#form').attr('action') == "formaction", 'Check for action 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.
@@ -435,12 +443,27 @@ jQuery.fn = jQuery.prototype = {
* }
* ok( pass, "Set Attribute" );
*
- * @test $("#name").attr('name', 'something');
+ * $("#name").attr('name', 'something');
* ok( $("#name").name() == 'something', 'Set name attribute' );
- * @test $("#check2").attr('checked', true);
+ * $("#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' );
+ * $("#text1").attr('readonly', true);
+ * ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
+ * $("#text1").attr('readonly', false);
+ * ok( document.getElementById('text1').readOnly == false, 'Set readonly 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
@@ -493,7 +516,7 @@ jQuery.fn = jQuery.prototype = {
* representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
* borderStyle, borderBottomWidth etc.
*
- * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"');
+ * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
*
* @name css
* @type Object
@@ -511,10 +534,18 @@ jQuery.fn = jQuery.prototype = {
* @result
Test Paragraph.
*
* @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
- * @test $('#foo').css({display: 'none'});
+ * $('#foo').css({display: 'none'});
* ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
- * @test $('#foo').css({display: 'block'});
+ * $('#foo').css({display: 'block'});
* ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
+ * $('#floatTest').css({styleFloat: 'right'});
+ * ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
+ * $('#floatTest').css({cssFloat: 'left'});
+ * ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
+ * $('#floatTest').css({'float': 'right'});
+ * ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
+ * $('#floatTest').css({'font-size': '30px'});
+ * ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
*
* @name css
* @type jQuery
@@ -532,10 +563,18 @@ jQuery.fn = jQuery.prototype = {
*
*
* @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
- * @test $('#foo').css('display', 'none');
+ * $('#foo').css('display', 'none');
* ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
- * @test $('#foo').css('display', 'block');
+ * $('#foo').css('display', 'block');
* ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
+ * $('#floatTest').css('styleFloat', 'left');
+ * ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
+ * $('#floatTest').css('cssFloat', 'right');
+ * ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
+ * $('#floatTest').css('float', 'left');
+ * ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
+ * $('#floatTest').css('font-size', '20px');
+ * ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
*
* @name css
* @type jQuery
@@ -644,7 +683,7 @@ jQuery.fn = jQuery.prototype = {
// Insert it before the element to be wrapped
this.parentNode.insertBefore( b, this );
- // Find he deepest point in the wrap structure
+ // Find the deepest point in the wrap structure
while ( b.firstChild )
b = b.firstChild;
@@ -666,12 +705,7 @@ jQuery.fn = jQuery.prototype = {
* @test var defaultText = 'Try them out:'
* var result = $('#first').append('buga');
* ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
- *
- * @test reset();
- * var expected = "Try them out: bla ";
- * $('#first').append(" ");
- * $('#first').append("bla ");
- * ok( expected == $('#first').text(), "Check for appending of spaces" );
+ * ok( $('#select3').append('').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
*
* @name append
* @type jQuery
@@ -735,6 +769,7 @@ jQuery.fn = jQuery.prototype = {
* @test var defaultText = 'Try them out:'
* var result = $('#first').prepend('buga');
* ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
+ * ok( $('#select3').prepend('').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
*
* @name prepend
* @type jQuery
@@ -982,6 +1017,12 @@ jQuery.fn = jQuery.prototype = {
* @result $("p").filter(".selected") == [
]
+ *
* @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
*
* @name not
@@ -1127,27 +1170,27 @@ jQuery.fn = jQuery.prototype = {
* @desc An invalid expression always returns false.
*
* @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
- * @test ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
- * @test ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
- * @test ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
- * @test ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
- * @test ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
- * @test ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
- * @test ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
- * @test ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
- * @test ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
- * @test ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
- * @test ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
- * @test ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
- * @test ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
- * @test ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
- * @test ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
- * @test ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
- * @test ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
- * @test ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
- * @test ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
- * @test ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
- * @test ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
+ * 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
@@ -1157,7 +1200,7 @@ jQuery.fn = jQuery.prototype = {
is: function(expr) {
return expr ? jQuery.filter(expr,this).r.length > 0 : false;
},
-
+
/**
*
*
@@ -1206,17 +1249,23 @@ jQuery.fn = jQuery.prototype = {
*/
pushStack: function(a,args) {
var fn = args && args[args.length-1];
+ var fn2 = args && args[args.length-2];
+
+ if ( fn && fn.constructor != Function ) fn = null;
+ if ( fn2 && fn2.constructor != Function ) fn2 = null;
- if ( !fn || fn.constructor != Function ) {
+ if ( !fn ) {
if ( !this.stack ) this.stack = [];
this.stack.push( this.get() );
this.get( a );
} else {
var old = this.get();
this.get( a );
- if ( fn.constructor == Function )
- this.each( fn );
- this.get( old );
+
+ if ( fn2 && a.length || !fn2 )
+ this.each( fn2 || fn ).get( old );
+ else
+ this.get( old ).each( fn );
}
return this;
@@ -1270,8 +1319,17 @@ jQuery.fn = jQuery.prototype = {
* @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;
};
@@ -1363,7 +1421,7 @@ jQuery.extend({
fn.apply( obj[i], args || [i, obj[i]] );
else
for ( var i = 0; i < obj.length; i++ )
- fn.apply( obj[i], args || [i, obj[i]] );
+ if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
return obj;
},
@@ -1373,9 +1431,18 @@ jQuery.extend({
o.className += ( o.className ? " " : "" ) + c;
},
remove: function(o,c){
- o.className = !c ? "" :
- o.className.replace(
- new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
+ if( !c ) {
+ o.className = "";
+ } else {
+ var classes = o.className.split(" ");
+ for(var i=0; i" + a[i] + "";
- } else if ( !a[i].indexOf("
" + a[i] + "";
- } else if ( !a[i].indexOf("
" + a[i] + "
";
- }
-
- 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;
- }
-
+ var arg = a[i];
+ if ( arg.constructor == 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("", ""];
+ else if ( !s.indexOf("", ""];
+ else if ( !s.indexOf("
", ""]; // tbody auto-inserted
+ else if ( !s.indexOf("