|
@@ -0,0 +1,82 @@
|
|
1
|
+/**
|
|
2
|
+ * WHITEBOPHIR
|
|
3
|
+ *********************************************************
|
|
4
|
+ * @licstart The following is the entire license notice for the
|
|
5
|
+ * JavaScript code in this page.
|
|
6
|
+ *
|
|
7
|
+ * Copyright (C) 2020 Ophir LOJKINE
|
|
8
|
+ *
|
|
9
|
+ *
|
|
10
|
+ * The JavaScript code in this page is free software: you can
|
|
11
|
+ * redistribute it and/or modify it under the terms of the GNU
|
|
12
|
+ * General Public License (GNU GPL) as published by the Free Software
|
|
13
|
+ * Foundation, either version 3 of the License, or (at your option)
|
|
14
|
+ * any later version. The code is distributed WITHOUT ANY WARRANTY;
|
|
15
|
+ * without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
16
|
+ * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
|
|
17
|
+ *
|
|
18
|
+ * As additional permission under GNU GPL version 3 section 7, you
|
|
19
|
+ * may distribute non-source (e.g., minimized or compacted) forms of
|
|
20
|
+ * that code without the copy of the GNU GPL normally required by
|
|
21
|
+ * section 4, provided you include this license notice and a URL
|
|
22
|
+ * through which recipients can access the Corresponding Source.
|
|
23
|
+ *
|
|
24
|
+ * @licend
|
|
25
|
+ */
|
|
26
|
+
|
|
27
|
+(function download() { //Code isolation
|
|
28
|
+
|
|
29
|
+ function downloadSVGFile() {
|
|
30
|
+ var canvasCopy = Tools.svg.cloneNode(true);
|
|
31
|
+ canvasCopy.removeAttribute("style", ""); // Remove css transform
|
|
32
|
+ var styleNode = document.createElement("style");
|
|
33
|
+
|
|
34
|
+ // Copy the stylesheets from the whiteboard to the exported SVG
|
|
35
|
+ styleNode.innerHTML = Array.from(document.styleSheets)
|
|
36
|
+ .filter(function (stylesheet) {
|
|
37
|
+ if (stylesheet.href && (stylesheet.href.match(/boards\/tools\/.*\.css/)
|
|
38
|
+ || stylesheet.href.match(/board\.css/))) {
|
|
39
|
+ // This is a Stylesheet from a Tool or the Board itself, so we should include it
|
|
40
|
+ return true;
|
|
41
|
+ }
|
|
42
|
+ // Not a stylesheet of the tool, so we can ignore it for export
|
|
43
|
+ return false;
|
|
44
|
+ })
|
|
45
|
+ .map(function (stylesheet) {
|
|
46
|
+ return Array.from(stylesheet.cssRules)
|
|
47
|
+ .map(function (rule) { return rule.cssText })
|
|
48
|
+ }).join("\n")
|
|
49
|
+
|
|
50
|
+ canvasCopy.appendChild(styleNode);
|
|
51
|
+ var outerHTML = canvasCopy.outerHTML || new XMLSerializer().serializeToString(canvasCopy);
|
|
52
|
+ var blob = new Blob([outerHTML], { type: 'image/svg+xml;charset=utf-8' });
|
|
53
|
+ downloadContent(blob, Tools.boardName + ".svg");
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ function downloadContent(blob, filename) {
|
|
57
|
+ if (window.navigator.msSaveBlob) { // Internet Explorer
|
|
58
|
+ window.navigator.msSaveBlob(blob, filename);
|
|
59
|
+ } else {
|
|
60
|
+ const url = URL.createObjectURL(blob);
|
|
61
|
+ var element = document.createElement('a');
|
|
62
|
+ element.setAttribute('href', url);
|
|
63
|
+ element.setAttribute('download', filename);
|
|
64
|
+ element.style.display = 'none';
|
|
65
|
+ document.body.appendChild(element);
|
|
66
|
+ element.click();
|
|
67
|
+ document.body.removeChild(element);
|
|
68
|
+ window.URL.revokeObjectURL(url);
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ Tools.add({ //The new tool
|
|
73
|
+ "name": "Download",
|
|
74
|
+ "shortcut": "d",
|
|
75
|
+ "listeners": {},
|
|
76
|
+ "icon": "tools/download/download.svg",
|
|
77
|
+ "oneTouch": true,
|
|
78
|
+ "onstart": downloadSVGFile,
|
|
79
|
+ "mouseCursor": "crosshair",
|
|
80
|
+ });
|
|
81
|
+
|
|
82
|
+})(); //End of code isolation
|