简体   繁体   English

IE8中MooTools事件未触发

[英]MooTools events not firing in IE8

I have a Mootools asset created like so: 我有一个这样创建的Mootools资产:

// Create a new asset
var asset = new Asset.image(path, {
    title: this.language.download,
    events: {click: this.download.bind(this, link)},
});

I have a method of a MooTools object defined as such: 我有一个这样定义的MooTools对象的方法:

download: function(e) { 
    // The path to download
    console.log('download: ' + e);
},

In Firefox the console.log print shows up. 在Firefox中,显示console.log。 In IE8, however, I have no luck. 但是,在IE8中,我没有运气。 Am I missing something? 我想念什么吗?

Any tips or advice would be greatly appreciated. 任何提示或建议,将不胜感激。 TIA! TIA!

In view of further communication via email... and the fact that the issue is caused by the use of filemanager mootools plugin by cpojer (of the mootools core team), I am updating my reply to the advice given via email as well. 考虑到通过电子邮件进行的进一步交流...以及该问题是由cpojer(mootools核心团队的成员)使用filemanager mootools插件引起的,因此,我也更新了对通过电子邮件给出的建议的答复。

source code in question: http://github.com/cpojer/mootools-filemanager/raw/master/Source/FileManager.js - line 408 is the problem 有问题的源代码: http : //github.com/cpojer/mootools-filemanager/raw/master/Source/FileManager.js-第408行是问题

The reason why the original code may fail (in IE8) but i'd consider it unsafe as is anyway - is that events in mootools are UID driven per element. 原始代码可能会失败的原因(在IE8中),但无论如何我还是认为它不安全-原因是mootools中的事件是每个元素的UID驱动的。 IE - if you inject an element or pass it through a selector and possibly create it via new Element() class (tbc), it assigns it a UID against which element storage is enabled. IE-如果您注入元素或使其通过选择器并可能通过new Element()类(tbc)创建它,则会为其分配一个UID来启用元素存储。 It is possible that the chaining used in the original form results in the addEvent running before the element exists which would cause it to fail. 原始形式中使用的链接可能会导致addEvent在元素存在之前运行,这将导致其失败。 The issue here is WHY would it fail to attach the events when all tests I have conducted seem to work. 这里的问题是为什么当我进行的所有测试似乎都有效时,为什么无法附加事件。 Basically, the Asset.image code goes: 基本上,Asset.image代码为:

var image = new Image();
var element = document.id(image) || new Element('img');
element.store("foo", "bar");
alert(element.retrieve("foo") || "failed");

this DOES assign a UID and makes it available for events even before it's a member of the DOM. 这确实分配了一个UID,并使其在成为DOM成员之前就可用于事件。 tescase: http://fragged.org/dev/ie8-new-image-bug.php - does that output 'bar' for you? tescase: http ://fragged.org/dev/ie8-new-image-bug.php-这样会为您输出“ bar”吗? if so, there is no reason to suspect foul play on the order of assignment of events vs DOM insertion due to storage anyway, it could be a total manipulation issue / onclick problem. 如果是这样的话,无论如何,由于存储原因,没有理由怀疑事件分配顺序与DOM插入的不正确行为,这可能完全是操纵问题/ onclick问题。

Either way, you can try replacing the code in the class with this, аlthough I have not tested it: 无论哪种方式,您都可以尝试用此替换类中的代码,尽管我尚未对其进行测试:

var _this = this;
icons.push(new Asset.image(this.options.assetBasePath + 'disk.png', {
    title: this.language.download
    "class": 'browser-icon',
    onload: function() {
        // once the src has been set and image loaded
        // inject into DOM (hence open to manilulations) and then add the event
        this.inject(el, 'top').addEvent('click', function(e) {
            _this.tips.hide();
            e.stop();
            window.open(_this.options.baseURL + _this.normalize(_this.Directory + '/' + file.name));
        });
    }
}));

also to consider: IE has - in the past - been known to have issues with cached images being loaded up failing to trigger events if the assignment of the event is wrong way around: 还应考虑:过去,已知IE在加载缓存的图像时遇到问题,如果事件的分配方式错误,则无法触发事件:

// wrong:
var image = new Image();
image.src = 'image.jpg';
image.onload = function() { // evil, won't work if image already cached, it won't trigger
...
};

// right:
var image = new Image();
image.onload = function() { // always fires the event.
...
};
image.src = 'image.jpg';

this is just as a clue, mootools ensures the correct order of insertion vs event assignment anyway - but that does not mean that IE8 has no other similar issues to do with events. 这只是一个线索,无论如何,mootools都会确保插入与事件分配的正确顺序-但这并不意味着IE8没有其他与事件有关的类似问题。

I have tried to implement this using the two methods described. 我尝试使用描述的两种方法来实现这一点。 Neither seem to work in IE8 or IE8 with compatibility mode. 在兼容模式的IE8或IE8中似乎都不起作用。

var path = this.options.assetBasePath + 'disk.png';
var _this = this;
var icon = new Asset.image(path, {
                          /*onload: function() {
                    this.set({
                    title: _this.language.download,
                    events: {click: function() {
                                           alert('test');
                    }
                 }
            }).inject(el, 'top');
              }*/
       });
icon.set({title: _this.language.download,
     events: {click: function() {
                 alert('test');
                 }
         }
});
icon.inject(el, 'top');
icon.addClass('browser-icon');
icons.push(icon);

Both of these methods display an alert() just fine in FF but fail in IE. 这两种方法都在FF中显示alert()很好,但在IE中失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM