-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathOpenFigurePanelImageTool.js
46 lines (42 loc) · 1.18 KB
/
OpenFigurePanelImageTool.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
import { domHelpers } from 'substance'
import { Tool } from '../../kit'
export default class OpenFigurePanelImageTool extends Tool {
render ($$) {
let el = super.render($$)
el.append(
$$('a').ref('link')
.attr('target', '_blank')
// ATTENTION: stop propagation, otherwise infinite loop
.on('click', domHelpers.stop)
)
return el
}
getClassNames () {
return 'sc-open-figure-panel-source-tool sc-tool'
}
_onClick (e) {
e.stopPropagation()
e.preventDefault()
this._generateLink()
}
_generateLink () {
const urlResolver = this.context.urlResolver
const editorSession = this.context.editorSession
const selectionState = editorSession.getSelectionState()
const node = selectionState.node
let currentPanel = node
if (node.type === 'figure') {
const panels = node.getPanels()
const currentIndex = node.getCurrentPanelIndex()
currentPanel = panels[currentIndex]
}
const graphic = currentPanel.resolve('content')
const url = urlResolver.resolveUrl(graphic.href)
if (url) {
this.refs.link.el.attr({
'href': url
})
this.refs.link.el.click()
}
}
}