views:

267

answers:

2

I'd like to create a custom paste event that would fire either input (FF) or onbeforepaste (IE). I've read pretty much all about creating custom events in mootools, still the event does not get fired in any of the browsers.

The extension (took the docs and the 'mousewheel' event as a reference):

Element.Events.paste = {
 base: (Browser.Engine.trident) ? 'beforepaste' : 'input'
};

Call:

this.addEvent('paste', function() {... // 'this' is a textarea

It works fine when I use the non-mootools way (FF):

this.addEventListener('input', function() {...

So, what do I do wrong?

A: 

Why not just do

var eventType = Browser.Engine.trident ? 'beforepaste' : 'input';
this.addEvent(eventType, function(){ ...

This way both native browser events are catched without defining a new event that aliasses them. Seems flexible enough from what i can tell

ChrisR
A: 

I found this code on the MooTools Users group:

$extend(Element.NativeEvents, {
    'paste': 2, 'input': 2
});
Element.Events.paste = {
    base : (Browser.Engine.presto || (Browser.Engine.gecko && Browser.Engine.version < 19))? 'input': 'paste',
    condition: function(e){
        this.fireEvent('paste', e, 1);
        return false;
    }
};
moff