Patch.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. define("dojox/geo/openlayers/Patch", [
  2. "dojo/_base/kernel",
  3. "dojo/_base/lang", // dojo.extend getObject
  4. "dojo/_base/sniff", // dojo.isIE
  5. "dojox/gfx",
  6. "dojox/gfx/shape"
  7. ], function(dojo, lang, sniff, gfx, shape){
  8. var dgo = lang.getObject("geo.openlayers", true, dojox);
  9. dgo.Patch = {
  10. patchMethod : function(/*Object*/type, /*String*/method, /*Function*/execBefore, /*Function*/
  11. execAfter){
  12. // summary:
  13. // Patches the specified method of the given type so that the 'execBefore' (resp. 'execAfter') function is
  14. // called before (resp. after) invoking the legacy implementation.
  15. // description:
  16. // The execBefore function is invoked with the following parameter:
  17. // execBefore(method, arguments) where 'method' is the patched method name and 'arguments' the arguments received
  18. // by the legacy implementation.
  19. // The execAfter function is invoked with the following parameter:
  20. // execBefore(method, returnValue, arguments) where 'method' is the patched method name, 'returnValue' the value
  21. // returned by the legacy implementation and 'arguments' the arguments received by the legacy implementation.
  22. // type: Object: the type to patch.
  23. // method: String: the method name.
  24. // execBefore: Function: the function to execute before the legacy implementation.
  25. // execAfter: Function: the function to execute after the legacy implementation.
  26. // tags:
  27. // private
  28. var old = type.prototype[method];
  29. type.prototype[method] = function(){
  30. var callee = method;
  31. if (execBefore)
  32. execBefore.call(this, callee, arguments);
  33. var ret = old.apply(this, arguments);
  34. if (execAfter)
  35. ret = execAfter.call(this, callee, ret, arguments) || ret;
  36. return ret;
  37. };
  38. },
  39. patchGFX : function(){
  40. var vmlFixRawNodePath = function(){
  41. if (!this.rawNode.path)
  42. this.rawNode.path = {};
  43. };
  44. var vmlFixFillColors = function() {
  45. if(this.rawNode.fill && !this.rawNode.fill.colors)
  46. this.rawNode.fill.colors = {};
  47. };
  48. if (sniff.isIE <= 8) {
  49. dojox.geo.openlayers.Patch.patchMethod(gfx.Line, "setShape", vmlFixRawNodePath, null);
  50. dojox.geo.openlayers.Patch.patchMethod(gfx.Polyline, "setShape", vmlFixRawNodePath, null);
  51. dojox.geo.openlayers.Patch.patchMethod(gfx.Path, "setShape", vmlFixRawNodePath, null);
  52. dojox.geo.openlayers.Patch.patchMethod(shape.Shape, "setFill", vmlFixFillColors, null);
  53. }
  54. }
  55. };
  56. return dgo.Patch;
  57. });