X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=965c2798abd538cea0d493bceb2fbc1c4d94dc85;hb=2e544e9eb89c87b9eac6df445474d21e9be604eb;hp=9b5bf8d444600874d315a30b99266b95c081eac2;hpb=770a92a594a803486a66603a67f559ff15915d8b;p=jquery.git
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 9b5bf8d..965c279 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -1,5 +1,5 @@
/*
- * jQuery - New Wave Javascript
+ * jQuery @VERSION - New Wave Javascript
*
* Copyright (c) 2006 John Resig (jquery.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
@@ -16,12 +16,12 @@ 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
@@ -31,7 +31,7 @@ window.undefined = window.undefined;
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 (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 ?
@@ -65,7 +67,7 @@ jQuery = function(a,c) {
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);
};
@@ -95,7 +97,10 @@ if ( typeof $ != "undefined" )
* @result [
two
]
*
* @example $("
Hello
").appendTo("#body")
- * @desc Creates a div element (and all of its contents) dynamically, and appends it to the element with the ID of body.
+ * @desc Creates a div element (and all of its contents) dynamically,
+ * and appends it to the element with the ID of body. Internally, an
+ * element is created and it's innerHTML property set to the given markup.
+ * It is therefore both quite flexible and limited.
*
* @name $
* @param String expr An expression to search with, or a string of HTML to create on the fly.
@@ -154,6 +159,7 @@ if ( typeof $ != "undefined" )
* behaves just like $(document).ready(), in that it should be used to wrap
* all of the other $() operations on your page. While this function is,
* technically, chainable - there really isn't much use for chaining against it.
+ * You can have as many $(document).ready events on your page as you like.
*
* @example $(function(){
* // Document is ready
@@ -186,7 +192,7 @@ var $ = jQuery;
jQuery.fn = jQuery.prototype = {
/**
- * The current SVN version of jQuery.
+ * The current version of jQuery.
*
* @private
* @property
@@ -194,7 +200,7 @@ jQuery.fn = jQuery.prototype = {
* @type String
* @cat Core
*/
- jquery: "$Rev$",
+ jquery: "@VERSION",
/**
* The number of elements currently matched.
@@ -203,7 +209,7 @@ jQuery.fn = jQuery.prototype = {
* @before
* @result 2
*
- * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
+ * @test ok( $("div").length == 2, "Get Number of Elements Found" );
*
* @property
* @name length
@@ -218,7 +224,7 @@ jQuery.fn = jQuery.prototype = {
* @before
* @result 2
*
- * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
+ * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
*
* @name size
* @type Number
@@ -252,7 +258,7 @@ jQuery.fn = jQuery.prototype = {
* @before
* @result [ ]
*
- * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
+ * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
*
* @name get
* @type Element
@@ -349,14 +355,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 +387,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 +441,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 +510,7 @@ jQuery.fn = jQuery.prototype = {
* representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
* borderStyle, borderBottomWidth etc.
*
- * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"');
+ * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
*
* @name css
* @type Object
@@ -511,9 +528,9 @@ 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');
*
* @name css
@@ -532,9 +549,9 @@ 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');
*
* @name css
@@ -587,19 +604,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 +632,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 +661,7 @@ jQuery.fn = jQuery.prototype = {
// Insert it before the element to be wrapped
this.parentNode.insertBefore( b, this );
- // Find he deepest point in the wrap structure
+ // Find the deepest point in the wrap structure
while ( b.firstChild )
b = b.firstChild;
@@ -970,6 +993,12 @@ jQuery.fn = jQuery.prototype = {
* @result $("p").filter(".selected") == [