开发者

dojo: override anonymous function in events.js to handle events in IE9

I am using dojo 1.5 library in my project.While working on IE9,dojo.stopEvent and preventDefaul开发者_如何学JAVAt breaks to prevent browser right click action.However I got the patch on http://bugs.dojotoolkit.org/changeset/23802/dojo.

However I don't want to make changes in library itself.I am looking for writing my own code to patch this by overriding the methods of event.js.

But I am not able to override the anonymous function.

How do I solve this?

Thanks in advance.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜