-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_save.coffee
More file actions
30 lines (26 loc) · 926 Bytes
/
custom_save.coffee
File metadata and controls
30 lines (26 loc) · 926 Bytes
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
_ = require "underscore"
props = require "core/properties"
ActionTool = require "models/tools/actions/action_tool"
class CustomSaveToolView extends ActionTool.View
do: () ->
canvas = @plot_view.get_canvas_element()
curFile = location.pathname.split('/')[location.pathname.split('/').length-1]
ext = curFile.substr(curFile.lastIndexOf('.')+1)
name = curFile.replace(ext, 'png')
if canvas.msToBlob?
blob = canvas.msToBlob()
window.navigator.msSaveBlob(blob, name)
else
link = document.createElement('a')
link.href = canvas.toDataURL('image/png')
link.download = name
link.target = "_blank"
link.dispatchEvent(new MouseEvent('click'))
class CustomSaveTool extends ActionTool.Model
default_view: CustomSaveToolView
type: "CustomSaveTool"
tool_name: "Save"
icon: "bk-tool-icon-save"
module.exports =
Model: CustomSaveTool
View: CustomSaveToolView