After re-factoring my code as @FlorianMargaine suggested(in the JavaScript Chat conversation) , I got something that looks like the following:
body.addEventListener( 'mousedown', action1);
function action1(){
//Start selecting event
body.addEventListener( 'mousemove', selectOver);
}
function selectOver(e){
//after the user has selected and done a mouse up event show a box:
body.addEventListener( 'mouseup', showBox );
}
function showBox(e){
//Show box
box.addEventListener( 'click', actionAlert('clicked on interface after selected text') );
}
function actionAlert(d){
alert(d);
}
The main problem is that I think that it uses a lot of CPU on the way, how can I minimize that?
I read a bit about the ability to remove the event handlers, is that the solution? and how can I integrate that solution efficiently to the code?
You should not be adding an event listener for
mouseupon everymousemove, nor should you be re- registering your mousemove each time you mousedown Instead:I’ve also added the explicit third parameter
falsetoaddEventListeneras is required by some (all?) versions of Firefox.