0
|
1 //>>excludeStart("exclude", pragmas.exclude);
|
|
2 define([ "shoestring", "events/bind", "events/unbind" ], function(){
|
|
3 //>>excludeEnd("exclude");
|
|
4
|
|
5 /**
|
|
6 * Bind a callback to an event for the currrent set of elements, unbind after one occurence.
|
|
7 *
|
|
8 * @param {string} event The event(s) to watch for.
|
|
9 * @param {function} callback Callback to invoke on the event.
|
|
10 * @return shoestring
|
|
11 * @this shoestring
|
|
12 */
|
|
13 shoestring.fn.one = function( event, callback ){
|
|
14 var evts = event.split( " " );
|
|
15
|
|
16 return this.each(function(){
|
|
17 var thisevt, cbs = {}, $t = shoestring( this );
|
|
18
|
|
19 for( var i = 0, il = evts.length; i < il; i++ ){
|
|
20 thisevt = evts[ i ];
|
|
21
|
|
22 cbs[ thisevt ] = function( e ){
|
|
23 var $t = shoestring( this );
|
|
24
|
|
25 for( var j in cbs ) {
|
|
26 $t.unbind( j, cbs[ j ] );
|
|
27 }
|
|
28
|
|
29 return callback.apply( this, [ e ].concat( e._args ) );
|
|
30 };
|
|
31
|
|
32 $t.bind( thisevt, cbs[ thisevt ] );
|
|
33 }
|
|
34 });
|
|
35 };
|
|
36
|
|
37 //>>excludeStart("exclude", pragmas.exclude);
|
|
38 });
|
|
39 //>>excludeEnd("exclude");
|