X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=f945c24a456fd618ead9fe69ef7b0ff0b2796e0e;hb=443e41b74066782c06f799903708fb448a555294;hp=f802ae6a36b9bb43a77a6b24542b5f4911269ef4;hpb=3f6a513b7ee693dfd030cb7c9200f22cfafd2b0f;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index f802ae6..f945c24 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -2137,7 +2137,8 @@ jQuery.extend({ event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data - var returnValue = true; + // returned undefined or false + var returnValue; var c = this.events[event.type]; @@ -3230,6 +3231,39 @@ jQuery.macros = { bind: function( type, data, fn ) { jQuery.event.add( this, type, fn || data, data ); }, + + /** + * Binds a handler to a particular event (like click) for each matched element. + * The handler is executed only once for each element. Otherwise, the same rules + * as described in bind() apply. + 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. + * + * In most cases, you can define your event handlers as anonymous functions + * (see first example). In cases where that is not possible, you can pass additional + * data as the second paramter (and the handler function as the third), see + * second example. + * + * @example $("p").one( "click", function() { + * alert( $(this).text() ); + * } ) + * @before

Hello

+ * @result alert("Hello") + * + * @name one + * @type jQuery + * @param String type An event type + * @param Object data (optional) Additional data passed to the event handler as event.data + * @param Function fn A function to bind to the event on each of the set of matched elements + * @cat Events + */ + one: function( type, data, fn ) { + jQuery.event.add( this, type, function(event) { + jQuery(this).unbind(event); + return (fn || data).apply( this, arguments); + }, data); + }, /** * The opposite of bind, removes a bound event from each of the matched