开发者

How do I replace Function create from MooTools 1.2 to 1.3?

Hi there i have this code snippet I need to get working with MooTools 1.开发者_如何学JAVA3 :

this.fn = function (e, cal) {
    var e = new Event(e);
    var el = e.target;
    var stop = false;

    while (el != document.body && el.nodeType == 1) {
        if (el == this.calendar) { stop = true; }
        this.calendars.each(function (kal) {
            if (kal.button == el || kal.els.contains(el)) { stop = true; }
        });

        if (stop) {
            e.stop();
            return false;
        }
        else { el = el.parentNode; }
    }
    this.toggle(cal);
}.create({
             'arguments': cal, 
             'bind': this, 
             'event': true 
        }); <-- THIS CREATE METHOD DOES NOT WORK

Can someone help me whit this ?


After create function was deprecated, you need to "manually" recreate the usage. In this case, you are creating a function that will be an event listener and binding it later in the code (this is Aeron Glemann's calendar).

So what you need to do, is put this function in addEvent you find directly below it, like this.

document.addEvent('mousedown', function(e, cal) {
[...]
}.bind(this));

Also, there's a removeEvent call at the begining of the function you're currently editing (the toggle function) that will no longer work since this function no longer has a name, replace it with removing all events on mousedown, worked for me.

document.removeEvents('mousedown'); 


as i said on the mootools user mailing list, i don't know about the "perfect" way, but in the meantime you can always (if you don't want to use the 1.2 compat version) inspire yourself from the implementation of the function for 1.2 compat :

https://github.com/mootools/mootools-core/blob/025adc07dc7e9851f30b3911961d43d525d83847/Source/Types/Function.js#L74

I have to admit the doc for 1.3 only mention that this method is deprecated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜