comparison default/node_modules/shoestring/src/events/one.js @ 0:1d038bc9b3d2 default tip

Up:default
author Liny <dev@neowd.com>
date Sat, 31 May 2025 09:21:51 +0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1d038bc9b3d2
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");