Integrate.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Disables eval for JS (uses shapes.min.js)
  2. mxStencilRegistry.allowEval = false;
  3. // Sets defaults
  4. Graph.prototype.defaultPageVisible = false;
  5. Graph.prototype.defaultScrollbars = false;
  6. EditorUi.prototype.toolbarHeight = 0;
  7. EditorUi.prototype.footerHeight = 0;
  8. EditorUi.scratchpadHelpLink = null;
  9. // Enables action states
  10. EditorUi.prototype.isDiagramActive = function()
  11. {
  12. return true;
  13. };
  14. // Enables settings
  15. EditorUi.prototype.isSettingsEnabled = function()
  16. {
  17. return true;
  18. };
  19. // Enables scratchpad
  20. EditorUi.prototype.isScratchpadEnabled = function()
  21. {
  22. return true;
  23. };
  24. // Workaround for tainted canvas is to base64 encode the image on the server-side
  25. EditorUi.prototype.convertImageToDataUri = function(url, callback)
  26. {
  27. if (/(\.svg)$/i.test(url))
  28. {
  29. mxUtils.get(url, mxUtils.bind(this, function(req)
  30. {
  31. callback(Editor.createSvgDataUri(req.getText()));
  32. }),
  33. function()
  34. {
  35. callback(this.svgBrokenImage.src);
  36. });
  37. }
  38. else
  39. {
  40. // Workaround for tainted canvas error
  41. if (url.substring(0, PROXY_URL.length) == PROXY_URL)
  42. {
  43. mxUtils.get(url + '&base64=1', mxUtils.bind(this, function(req)
  44. {
  45. callback('data:image/png;base64,' + req.getText());
  46. }),
  47. function()
  48. {
  49. callback();
  50. });
  51. }
  52. else
  53. {
  54. var img = new Image();
  55. var self = this;
  56. if (this.crossOriginImages)
  57. {
  58. img.crossOrigin = 'anonymous';
  59. }
  60. img.onload = function()
  61. {
  62. var canvas = document.createElement('canvas');
  63. var ctx = canvas.getContext('2d');
  64. canvas.height = img.height;
  65. canvas.width = img.width;
  66. ctx.drawImage(img, 0, 0);
  67. try
  68. {
  69. callback(canvas.toDataURL());
  70. }
  71. catch (e)
  72. {
  73. callback(self.svgBrokenImage.src);
  74. }
  75. };
  76. img.onerror = function()
  77. {
  78. callback(self.svgBrokenImage.src);
  79. };
  80. img.src = url;
  81. }
  82. }
  83. };
  84. if (typeof(window.mxIntegrateCallback) === 'function')
  85. {
  86. window.mxIntegrateCallback();
  87. }