aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJörn Zaefferer <joern.zaefferer@gmail.com>2007-01-10 18:46:41 +0000
committerJörn Zaefferer <joern.zaefferer@gmail.com>2007-01-10 18:46:41 +0000
commitc6e6e72561979ab80aaf5ce1ab63d3dd010382a3 (patch)
tree2b4870789bb9ed253a488b36fc66719e33388692
parent7b439921c48070e7b01ebda3580e0ada01a082b5 (diff)
downloadjquery-c6e6e72561979ab80aaf5ce1ab63d3dd010382a3.tar.gz
jquery-c6e6e72561979ab80aaf5ce1ab63d3dd010382a3.zip
Modified ready to event to pass jQuery object, allowing users to avoid the ugly custom alias pattern, added examples to both ready(Function) and $(Function)
-rw-r--r--src/event/event.js17
-rw-r--r--src/jquery/jquery.js8
2 files changed, 23 insertions, 2 deletions
diff --git a/src/event/event.js b/src/event/event.js
index 4a6331670..9b5d46ea3 100644
--- a/src/event/event.js
+++ b/src/event/event.js
@@ -408,6 +408,10 @@ jQuery.fn.extend({
* and attaching a function to that. By using this method, your bound Function
* will be called the instant the DOM is ready to be read and manipulated,
* which is exactly what 99.99% of all Javascript code needs to run.
+ *
+ * There is one argument passed to the ready event handler: A reference to
+ * the jQuery function. You can name that argument whatever you like, and
+ * can therefore stick with the $ alias without risc of naming collisions.
*
* Please ensure you have no code in your &lt;body&gt; onload event handler,
* otherwise $(document).ready() may not fire.
@@ -417,21 +421,30 @@ jQuery.fn.extend({
*
* @example $(document).ready(function(){ Your code here... });
*
+ * @example jQuery(function($) {
+ * // Your code using failsafe $ alias here...
+ * });
+ * @desc Uses both the shortcut for $(document).ready() and the argument
+ * to write failsafe jQuery code using the $ alias, without relying on the
+ * global alias.
+ *
* @name ready
* @type jQuery
* @param Function fn The function to be executed when the DOM is ready.
* @cat Events
+ * @see $.noConflict()
+ * @see $(Function)
*/
ready: function(f) {
// If the DOM is already ready
if ( jQuery.isReady )
// Execute the function immediately
- f.apply( document );
+ f.apply( document, [jQuery] );
// Otherwise, remember the function for later
else {
// Add the function to the wait list
- jQuery.readyList.push( f );
+ jQuery.readyList.push( function() { return f.apply(this, [jQuery]) } );
}
return this;
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 46019bf94..ddcddce06 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -154,10 +154,18 @@ var $ = jQuery;
* });
* @desc Executes the function when the DOM is ready to be used.
*
+ * @example jQuery(function($) {
+ * // Your code using failsafe $ alias here...
+ * });
+ * @desc Uses both the shortcut for $(document).ready() and the argument
+ * to write failsafe jQuery code using the $ alias, without relying on the
+ * global alias.
+ *
* @name $
* @param Function fn The function to execute when the DOM is ready.
* @cat Core
* @type jQuery
+ * @see ready(Function)
*/
jQuery.fn = jQuery.prototype = {