X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=686c20d7bfd69d4b78886792a88aa2bd41ac4ea6;hb=6f7cd669597cbcf026886074fb31963fe767e2b3;hp=69628b37f64c9001e158cdb967e13724ac04294e;hpb=529203f6b576aa15201485dd8d704109aa543f0d;p=jquery.git
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 69628b3..686c20d 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,13 +443,24 @@ 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' );
*
+ * @test stop();
+ * $.get('data/dashboard.xml', function(xml) {
+ * var titles = [];
+ * $('tab', xml).each(function() {
+ * titles.push($(this).attr('title'));
+ * });
+ * ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
+ * ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
+ * start();
+ * });
+ *
* @name attr
* @type jQuery
* @param String key The name of the property to set.
@@ -493,7 +512,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 +530,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('cssFloat') == 'right', 'Modified CSS float using "cssFloat": 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 +559,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('cssFloat') == 'left', 'Modified CSS float using "cssFloat": 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
@@ -587,19 +622,17 @@ jQuery.fn = jQuery.prototype = {
* and finds the deepest ancestor element within its
* structure - it is that element that will en-wrap everything else.
*
+ * This does not work with elements that contain text. Any necessary text
+ * must be added after the wrapping is done.
+ *
* @example $("p").wrap("");
* @before
Test Paragraph.
* @result
Test Paragraph.
*
* @test var defaultText = 'Try them out:'
* var result = $('#first').wrap('
').text();
- * ok( defaultText == result, 'Check for simple wrapping' );
- * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' );
- *
- * @test var defaultText = 'Try them out:'
- * var result = $('#first').wrap('
xxyy
').text()
- * ok( 'xx' + defaultText + 'yy' == result, 'Check for wrapping' );
- * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' );
+ * 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
@@ -617,9 +650,17 @@ jQuery.fn = jQuery.prototype = {
* provided and finding the deepest ancestor element within its
* structure - it is that element that will en-wrap everything else.
*
- * @example $("p").wrap("");
- * @before
Test Paragraph.
- * @result
Test Paragraph.
+ * This does not work with elements that contain text. Any necessary text
+ * must be added after the wrapping is done.
+ *
+ * @example $("p").wrap( document.getElementById('content') );
+ * @before
Test Paragraph.
+ * @result
Test Paragraph.
+ *
+ * @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
@@ -638,7 +679,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;
@@ -970,6 +1011,12 @@ jQuery.fn = jQuery.prototype = {
* @result $("p").filter(".selected") == [