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