From 9f8dedb09442526cfd5535119c30b712d1a5692c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Szcz=C4=99=C5=9Bniak-Szlagowski?= Date: Sat, 24 Oct 2015 02:17:27 +0100 Subject: [PATCH] Add a button to download SVG Fixes #144 --- live_editor/index.html | 6 ++++-- live_editor/scripts/app.js | 5 ++++- live_editor/scripts/controllers/main.js | 11 ++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/live_editor/index.html b/live_editor/index.html index 9cae02624f..13e77de48f 100644 --- a/live_editor/index.html +++ b/live_editor/index.html @@ -62,8 +62,10 @@
Generated diagram
- LINK TO VIEW - LINK TO EDIT + + LINK TO VIEW + LINK TO EDIT + DOWNLOAD SVG
diff --git a/live_editor/scripts/app.js b/live_editor/scripts/app.js index 3449f9c7d7..f0eed7c571 100644 --- a/live_editor/scripts/app.js +++ b/live_editor/scripts/app.js @@ -9,4 +9,7 @@ * Main module of the application. */ angular - .module('angularMermaidApp', ['ngSanitize', 'ab-base64']); + .module('angularMermaidApp', ['ngSanitize', 'ab-base64']) + .config(['$compileProvider', function ($compileProvider) { + $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|local|data):/); + }]); diff --git a/live_editor/scripts/controllers/main.js b/live_editor/scripts/controllers/main.js index 1fa907b5de..8fbace7c2f 100644 --- a/live_editor/scripts/controllers/main.js +++ b/live_editor/scripts/controllers/main.js @@ -17,7 +17,9 @@ angular.module('angularMermaidApp') 'C->> B: Response\n' + 'B->> A: Forward response\n'; - $scope.diaglink = ''; + $scope.viewlink = ''; + $scope.editlink = ''; + $scope.svglink = ''; $scope.showerror = false; $scope.checkUpdate = function() { @@ -40,9 +42,11 @@ angular.module('angularMermaidApp') mermaidnode.appendChild(document.createTextNode($sce.trustAsHtml($scope.mermaidsyntax))); mermaidholder.appendChild(mermaidnode); mermaid.init(); // jshint ignore:line + $scope.svglink = buildSVGURL(); } else { $scope.showerror = true; } + $scope.$apply(); }, 1000); }; @@ -93,4 +97,9 @@ angular.module('angularMermaidApp') function buildURL(action, code) { return absurl + '#/' + action + '/' + base64.urlencode(code); } + + function buildSVGURL() { + var svg = document.querySelector('svg').outerHTML; + return 'data:image/svg+xml;base64,' + base64.encode(svg); + } }]);