-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathext-panning.js
76 lines (73 loc) · 2.03 KB
/
ext-panning.js
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
/**
* @file ext-panning.js
*
* @license MIT
*
* @copyright 2013 Luis Aguirre
*
*/
/*
This is a very basic SVG-Edit extension to let tablet/mobile devices pan without problem
*/
const name = 'panning'
const loadExtensionTranslation = async function (svgEditor) {
let translationModule
const lang = svgEditor.configObj.pref('lang')
try {
translationModule = await import(`./locale/${lang}.js`)
} catch (_error) {
console.warn(`Missing translation (${lang}) for ${name} - using 'en'`)
translationModule = await import('./locale/en.js')
}
svgEditor.i18next.addResourceBundle(lang, name, translationModule.default)
}
export default {
name,
async init () {
const svgEditor = this
await loadExtensionTranslation(svgEditor)
const {
svgCanvas
} = svgEditor
const { $id, $click } = svgCanvas
const insertAfter = (referenceNode, newNode) => {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling)
}
return {
name: svgEditor.i18next.t(`${name}:name`),
callback () {
const btitle = `${name}:buttons.0.title`
// Add the button and its handler(s)
const buttonTemplate = document.createElement('template')
buttonTemplate.innerHTML = `
<se-button id="ext-panning" title="${btitle}" src="panning.svg"></se-button>
`
insertAfter($id('tool_zoom'), buttonTemplate.content.cloneNode(true))
$click($id('ext-panning'), () => {
if (this.leftPanel.updateLeftPanel('ext-panning')) {
svgCanvas.setMode('ext-panning')
}
})
},
mouseDown () {
if (svgCanvas.getMode() === 'ext-panning') {
svgEditor.setPanning(true)
return {
started: true
}
}
return undefined
},
mouseUp () {
if (svgCanvas.getMode() === 'ext-panning') {
svgEditor.setPanning(false)
return {
keep: false,
element: null
}
}
return undefined
}
}
}
}