瀏覽代碼

Merge branch 'download-button' of https://github.com/ChaituVR/whitebophir into download

dev_h
DanielHabenicht 4 年之前
父節點
當前提交
991c37dc56
共有 3 個文件被更改,包括 64 次插入0 次删除
  1. 1
    0
      client-data/board.html
  2. 53
    0
      client-data/tools/download/download.js
  3. 10
    0
      client-data/tools/download/download.svg

+ 1
- 0
client-data/board.html 查看文件

@@ -100,6 +100,7 @@
100 100
 	<script src="../tools/eraser/eraser.js"></script>
101 101
 	<script src="../tools/hand/hand.js"></script>
102 102
 	<script src="../tools/grid/grid.js"></script>
103
+	<script src="../tools/download/download.js"></script>
103 104
 	<script src="../tools/zoom/zoom.js"></script>
104 105
 	<script src="../js/canvascolor.js"></script>
105 106
 </body>

+ 53
- 0
client-data/tools/download/download.js 查看文件

@@ -0,0 +1,53 @@
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
+    var canvas = document.getElementById('canvas');
30
+    function downloadFile(evt) {
31
+        var styleNode = document.createElement("style");
32
+        styleNode.innerHTML = "rect { fill:none; } path, line {fill: none;stroke-linecap: round; stroke-linejoin: round;}";
33
+        canvas.appendChild(styleNode);
34
+        var element = document.createElement('a');
35
+        element.setAttribute('href', 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(canvas.outerHTML));
36
+        element.setAttribute('download', "file.svg");
37
+        element.style.display = 'none';
38
+        document.body.appendChild(element);
39
+        element.click();
40
+        document.body.removeChild(element);
41
+    }
42
+
43
+    Tools.add({ //The new tool
44
+        "name": "Download",
45
+        "shortcut": "d",
46
+        "listeners": {},
47
+        "icon": "tools/download/download.svg",
48
+        "oneTouch": true,
49
+        "onstart": downloadFile,
50
+        "mouseCursor": "crosshair",
51
+    });
52
+
53
+})(); //End of code isolation

+ 10
- 0
client-data/tools/download/download.svg 查看文件

@@ -0,0 +1,10 @@
1
+<?xml version='1.0' encoding='utf-8'?>
2
+<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
3
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 512 512">
4
+  <g>
5
+    <g>
6
+      <path d="M480.6,319c-11.3,0-20.4,9.1-20.4,20.4v120.7H51.8V339.4c0-11.3-9.1-20.4-20.4-20.4c-11.3,0-20.4,9.1-20.4,20.4v141.2    c0,11.3,9.1,20.4,20.4,20.4h449.2c11.3,0,20.4-9.1,20.4-20.4V339.4C501,328.1,491.9,319,480.6,319z"/>
7
+      <path d="m241.6,352.7c11.1,10.7 24.4,5.2 28.9,0l124.2-124.1c8-8 8-20.9 0-28.9-8-8-20.9-8-28.9,0l-89.4,89.3v-259.2c0-11.3-9.1-20.4-20.4-20.4-11.3,0-20.4,9.1-20.4,20.4v259.1l-89.4-89.3c-8-8-20.9-8-28.9,0-8,8-8,20.9 0,28.9l124.3,124.2z"/>
8
+    </g>
9
+  </g>
10
+</svg>

Loading…
取消
儲存