* data as the second paramter (and the handler function as the third), see
* second example.
*
- * @example $("p").bind( "click", function() {
+ * @example $("p").bind("click", function(){
* alert( $(this).text() );
- * } )
+ * });
* @before <p>Hello</p>
* @result alert("Hello")
*
- * @example var handler = function(event) {
+ * @example function handler(event) {
* alert(event.data.foo);
- * };
- * $("p").bind( "click", {foo: "bar"}, handler)
+ * }
+ * $("p").bind("click", {foo: "bar"}, handler)
* @result alert("bar")
* @desc Pass some additional data to the event handler.
*
- * @example $("form").bind( "submit", function() { return false; } )
+ * @example $("form").bind("submit", function() { return false; })
* @desc Cancel a default action and prevent it from bubbling by returning false
* from your function.
*
- * @example $("form").bind( "submit", function(event) {
+ * @example $("form").bind("submit", function(event){
* event.preventDefault();
- * } );
+ * });
* @desc Cancel only the default action by using the preventDefault method.
*
*
- * @example $("form").bind( "submit", function(event) {
+ * @example $("form").bind("submit", function(event){
* event.stopPropagation();
- * } )
+ * });
* @desc Stop only an event from bubbling by using the stopPropagation method.
*
* @name bind
* data as the second paramter (and the handler function as the third), see
* second example.
*
- * @example $("p").one( "click", function() {
+ * @example $("p").one("click", function(){
* alert( $(this).text() );
- * } )
+ * });
* @before <p>Hello</p>
* @result alert("Hello")
*
});
},
- // We're overriding the old toggle function, so
- // remember it for later
- _toggle: jQuery.fn.toggle,
-
/**
* Toggle between two function calls every other click.
* Whenever a matched element is clicked, the first specified function
* @cat Events
*/
toggle: function() {
- // save reference to arguments for access in closure
+ // Save reference to arguments for access in closure
var a = arguments;
- return typeof a[0] == "function" && typeof a[1] == "function" ? this.click(function(e) {
+
+ return this.click(function(e) {
// Figure out which function to execute
this.lastToggle = this.lastToggle == 0 ? 1 : 0;
// and execute the function
return a[this.lastToggle].apply( this, [e] ) || false;
- }) :
-
- // Otherwise, execute the old toggle function
- this._toggle.apply( this, arguments );
+ });
},
/**
* 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 <body> onload event handler,
* otherwise $(document).ready() may not fire.
*
* @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;
jQuery.event.remove(els[i-1], type);
while (--i);
}
- });
\ No newline at end of file
+ });