dojo: override anonymous function in events.js to handle events in IE9
Which anonymous function are you referring to?
In the past, I've gotten around similar issues by keeping the patch files for the various issues and creating scripts which patch Dojo during my build/release/deploy process as appropriate. That way at least you've got a list of patch files you know to keep an eye on when you upgrade, and if your build process can start with a clean checkout of Dojo and modify it as needed then you don't have to worry about all your devs having the same 'custom' Dojo kicking around.
FWIW I use a similar approach when I'm monkey patching code too, for example.
// Monkey patch dojo.foo
dojo.provide('my.project.monkeyPatches.foo);
dojo.require('dojo.foo');
dojo.ready(function() {
if (dojo.version.major === 1 && dojo.version.minor <= 5) {
dojo.foo.someFunc = ...;
}
else {
console.error("You should remove the monkeyPatch for dojo.foo now, it's no longer needed");
}
});
EDIT: I understand you better now. I think the only way you can do this is to do something like:
// Monkey patch dojo.foo
dojo.provide('my.project.monkeyPatches.event);
dojo.require('dojo.event');
dojo.ready(function() {
if (dojo.version.major === 1 && dojo.version.minor === 5) {
if (dojo.isIE === 9 && !dojo.isQuirks) { // Invert the if
// Copy the functions for non-IE from the event.js file
dojo.mouseButtons = { // line 291 - 300 from http://bugs.dojotoolkit.org/browser/dojo/dojo/trunk/_base/event.js?rev=23802
}
}
}
else {
console.error("You should remove the monkeyPatch for dojo.foo now, it's no longer needed");
}
});
That sucks, but I can't think of a smarter way of doing it. The way the code has been written, the function you want to call is never defined for IE9.
Personally I'd use the patch approach I talked about above, and use the build system to apply it.
精彩评论