Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

download.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. (function download() { //Code isolation
  27. function downloadSVGFile(evt) {
  28. var canvasCopy = Tools.svg.cloneNode(true);
  29. var styleNode = document.createElement("style");
  30. // Copy the stylesheets from the whiteboard to the exported SVG
  31. styleNode.innerHTML = Array.from(document.styleSheets)
  32. .filter(function (stylesheet) {
  33. if(stylesheet.href && (stylesheet.href.match(/boards\/tools\/.*\.css/)
  34. || stylesheet.href.match(/board\.css/))) {
  35. // This is a Stylesheet from a Tool or the Board itself, so we should include it
  36. return true;
  37. }
  38. // Not a stylesheet of the tool, so we can ignore it for export
  39. return false;
  40. })
  41. .map(function (stylesheet) {
  42. return Array.from(stylesheet.cssRules).map(
  43. function (rule) {
  44. return rule.cssText
  45. }
  46. )}
  47. ).join("\n")
  48. canvasCopy.appendChild(styleNode);
  49. downloadContent(new Blob([canvasCopy.outerHTML || new XMLSerializer().serializeToString(canvasCopy)], { type: 'image/svg+xml;charset=utf-8' }), Tools.boardName + ".svg")
  50. }
  51. function downloadContent(blob, filename){
  52. if (window.navigator.msSaveBlob) {
  53. window.navigator.msSaveBlob(blob, filename);
  54. } else {
  55. const url = URL.createObjectURL(blob);
  56. var element = document.createElement('a');
  57. element.setAttribute('href', url);
  58. element.setAttribute('download', filename);
  59. element.style.display = 'none';
  60. document.body.appendChild(element);
  61. element.click();
  62. document.body.removeChild(element);
  63. window.URL.revokeObjectURL(url);
  64. }
  65. }
  66. Tools.add({ //The new tool
  67. "name": "Download",
  68. "shortcut": "d",
  69. "listeners": {},
  70. "icon": "tools/download/download.svg",
  71. "oneTouch": true,
  72. "onstart": downloadSVGFile,
  73. "mouseCursor": "crosshair",
  74. });
  75. })(); //End of code isolation