mootools/mootools-core — pull request #2595 by olvlvl (2014-05-15 13:57:53+00:00)
Title: Disable and Enable event type

Hi,

This pull request is a proposal to add two methods to the Events class:

- `disableEvent()`: Disable an event type, preventing it from being fired.
- `enableEvent()`: Enable a previously disabled event type so that it can be fired again.

I made a pull request some time ago to enhance the [Slider.js](https://github.com/mootools/mootools-more/blob/master/Source/Drag/Slider.js) class and complained that the `change` event was fired before the instance has finished to initialize. The solution found was to add a `silently` param:

https://github.com/mootools/mootools-more/pull/1256/files#diff-08828c563e973a6d192a5e0e3000d136R158

Recently I faced a similar issue. I have a criterion list that listen to the `change` event of its criteria so that if its value is changed the criterion fires the `change` event, which the criterion list listen to to fire its own `change` event. This works well, but problems arise when I need to reset them, because for each criterion reseted the `change` event of the criterion list is fired too. And that's really annoying since I don't want the attached list to be refresh 20 times. Then came the idea to temporarily disable the `change` event of the criterion list until all criterion have been reseted. First I used a property and `disableChangeEvent()` and `enableChangeEvent()`, but I figured that a more _global_ solution would be nicer, hence my proposal.

You'll notice in the `disableEvent()` method the example about the criterion list:

```js
var Criteria = new Class({
Implements: [ Events ],
change: function(){
this.fireEvent('change', this.getValue())
},
reset: function(){
this.disableEvent('change')
Object.each(this.criteria, function(criterion){
criterion.reset();
});
this.enableEvent('change').change()
}
});
```

I noticed that event methods are also defined in `Element.Event` but I just updated the part I needed to ask your opinion. So, what do you think?