Extension mootools : Un évènement long clic avec mootools 1.2 et whileClick

Rappel sur whileclick.js

Whileclick.js pour mootools permet d'ajouter un nouvel évènement, un peu exotique :), mais qui peut s'avérer très utile : un "whileClick".

L'évènement "whileClick" représente par cette dénomination, l'action d'un long clic avec la souris.

Vous pouvez retrouver un exemple de son utilisation ici

whileclick.js pour mootools 1.2

Cette version proposée par philodido vous permet d'utiliser cette extention avec mootools 1.2

Code source : /************************************************************
whileClick class
*************************************************************/
var whileClick = new Class ({

events : { down:null, up:null },
bindFunction: null,
element: null,
timer: null,
ms: 200,
initialize: function(element,bindFunction) {
this.element = element;
this.bindFunction = bindFunction;
var mainObj = this;
this.element.addEvent('mousedown',function(event){ mainObj.launch(event); });
},
launch: function(event) {
this.events.down = new Event(event);
this.timer = this.bindFunction.periodical(this.ms);
var mainObj = this;
document.addEvent('mouseup', function(event) { mainObj.mouseup(event); });
this.element.addEvent('mouseleave',function(event){ mainObj.mouseup(event); });
},
mouseup: function(event) {
this.events.up = new Event(event);
this.stop();
},
stop: function() {
$clear(this.timer);
}
});
/******************************************************/

/******************* Mootools Patch *******************/

Element.Events.whileClick = {
base: 'mousedown',
onAdd:{ call: function (element,fn){
new whileClick( element, fn );}
}
};