Firefox 18 breaks mootools 1.2.5 selector engine

2019-04-28 04:10发布

问题:

Working jsfiddle example here: http://jsfiddle.net/CfJyd/

The problem only occurs in Firefox 18 that I know of.

The following html:

<div class="test">Test Div</div>
<div class="testIgnore">This should stay the same</div>

With this js:

window.addEvent('domready',function() {
    $$('.test').set('html','Only Test should update');
});

Results in this output:

Only Test should update
Only Test should update

Upgrading to Mootools 1.4.5 isn't an option at the moment because of lots of plugins that use 1.2.5, can anybody point me in the right direction on getting a fix?

回答1:

I've found the answer here: https://groups.google.com/forum/#!msg/mootools-users/W7MHwTFHYQ4/B4HcR951XQYJ

Add the following code anywhere in javascript - I added it just above mootools, and it works perfectly:

String.prototype.contains = function(string, separator){
    return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1;
};


回答2:

known bug. If I remember correctly, it's to do with the early introduction of the proposed ES harmony String.prototype.contains in Gecko, which has a different 2-nd argument to the one in 1.2.5

a quick workaround is to say do, delete Sting.prototype.contains before you load MooTools so it redefines it. Since 1.3, this has stopped being a protected prototype method and has been redefined properly. I think there may have been a bug raised on the repo by one of the FireFox guys some 6 months ago as it was imminently landing in FF 17...

See this: https://bugzilla.mozilla.org/show_bug.cgi?id=789036#c23

Even Brendan Eich was commenting on this and suggesting it may be disabled in 18.0.1 as it was adopted prematurely.



回答3:

More background information on this: MooTools 1.2.x was broken by adding String.prototype.contains

The solution is to use the workaround from the other comment or upgrade to MooTools 1.3 or 1.4