Mercurial > nebulaweb3
view 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 |
line wrap: on
line source
//>>excludeStart("exclude", pragmas.exclude); define([ "shoestring", "events/bind", "events/unbind" ], function(){ //>>excludeEnd("exclude"); /** * Bind a callback to an event for the currrent set of elements, unbind after one occurence. * * @param {string} event The event(s) to watch for. * @param {function} callback Callback to invoke on the event. * @return shoestring * @this shoestring */ shoestring.fn.one = function( event, callback ){ var evts = event.split( " " ); return this.each(function(){ var thisevt, cbs = {}, $t = shoestring( this ); for( var i = 0, il = evts.length; i < il; i++ ){ thisevt = evts[ i ]; cbs[ thisevt ] = function( e ){ var $t = shoestring( this ); for( var j in cbs ) { $t.unbind( j, cbs[ j ] ); } return callback.apply( this, [ e ].concat( e._args ) ); }; $t.bind( thisevt, cbs[ thisevt ] ); } }); }; //>>excludeStart("exclude", pragmas.exclude); }); //>>excludeEnd("exclude");