X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=9f2189eb9e0bb625f8b9b8ee86f46316742d9246;hb=3b4eeab0444e7295802a4f090257ac5dac6f556a;hp=3edc3033354fa27c408a18c71bb12f13c9c364db;hpb=eff56887b164b489bb792f87770b7ba69e8f54df;p=jquery.git
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 3edc303..9f2189e 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -28,10 +28,10 @@ window.undefined = window.undefined;
* @name jQuery
* @cat Core
*/
-function jQuery(a,c) {
+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
@@ -65,9 +65,9 @@ function jQuery(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);
-}
+};
// Map over the $ in case of overwrite
if ( typeof $ != "undefined" )
@@ -203,7 +203,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 +218,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 +252,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
@@ -384,6 +384,14 @@ jQuery.fn = jQuery.prototype = {
* @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' );
*
* @name attr
* @type Object
@@ -427,6 +435,13 @@ jQuery.fn = jQuery.prototype = {
* }
* ok( pass, "Set Attribute" );
*
+ * @test $("#name").attr('name', 'something');
+ * ok( $("#name").name() == 'something', 'Set name attribute' );
+ * @test $("#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' );
+ *
* @name attr
* @type jQuery
* @param String key The name of the property to set.
@@ -572,19 +587,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
@@ -602,9 +615,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
@@ -646,6 +667,12 @@ jQuery.fn = jQuery.prototype = {
* 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" );
+ *
* @name append
* @type jQuery
* @param String html A string of HTML, that will be created on the fly and appended to the target.
@@ -954,6 +981,8 @@ jQuery.fn = jQuery.prototype = {
* @before
]
*
+ * @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
@@ -3072,6 +3193,14 @@ jQuery.macros = {
* }
* ok( pass, "Remove Class" );
*
+ * @test 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
@@ -3147,24 +3276,31 @@ jQuery.macros = {
},
/**
- * Binds a particular event (like click) to a each of a set of match elements.
- *
- * @example $("p").bind( "click", function() { alert("Hello"); } )
+ * Binds a handler to a particular event (like click) for each matched element.
+ * The event handler is passed an event object that you can use to prevent
+ * default behaviour. To stop both default action and event bubbling, your handler
+ * has to return false.
+ *
+ * @example $("p").bind( "click", function() {
+ * alert( $(this).text() );
+ * } )
* @before
Hello
- * @result [
Hello
]
- *
- * Cancel a default action and prevent it from bubbling by returning false
- * from your function.
+ * @result alert("Hello")
*
* @example $("form").bind( "submit", function() { return false; } )
+ * @desc Cancel a default action and prevent it from bubbling by returning false
+ * from your function.
*
- * Cancel a default action by using the preventDefault method.
- *
- * @example $("form").bind( "submit", function() { e.preventDefault(); } )
+ * @example $("form").bind( "submit", function(event) {
+ * event.preventDefault();
+ * } );
+ * @desc Cancel only the default action by using the preventDefault method.
*
- * Stop an event from bubbling by using the stopPropogation method.
*
- * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
+ * @example $("form").bind( "submit", function(event) {
+ * event.stopPropagation();
+ * } )
+ * @desc Stop only an event from bubbling by using the stopPropagation method.
*
* @name bind
* @type jQuery