From d14af48ba07f9424ea1d09138765216ce1bf97e2 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Mon, 21 Jul 2014 15:27:22 +0200 Subject: [PATCH 1/2] Allow downloading of presentations. --- src/styles/components/_presentation.scss | 13 +++++++--- static/js/directives/presentation.js | 30 +++++++++++++++++++++++- static/partials/presentation.html | 3 ++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/styles/components/_presentation.scss b/src/styles/components/_presentation.scss index 89138b34..3af11999 100644 --- a/src/styles/components/_presentation.scss +++ b/src/styles/components/_presentation.scss @@ -207,14 +207,21 @@ display: block; } -.presentation .thumbnail .delete { +.presentation .thumbnail .presentation-action { position: absolute; top: 1px; - right: 1px; display: none; } -.presentation .thumbnail:hover .delete { +.presentation .thumbnail .download { + left: 1px; +} + +.presentation .thumbnail .delete { + right: 1px; +} + +.presentation .thumbnail:hover .presentation-action { display: block; } diff --git a/static/js/directives/presentation.js b/static/js/directives/presentation.js index 099857cb..17160faf 100644 --- a/static/js/directives/presentation.js +++ b/static/js/directives/presentation.js @@ -53,6 +53,7 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'], this.file = null; this.handler = null; this.session = null; + this.url = null; }; BasePresentation.prototype.stop = function() { @@ -75,7 +76,6 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'], BasePresentation.call(this, scope, fileInfo, token); this.owner = owner; this.progress = 0; - this.url = null; this.presentable = false; this.downloading = true; this.uploaded = false; @@ -129,6 +129,15 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'], } }; + DownloadPresentation.prototype.browserOpen = function(target) { + target = target || "_blank"; + if (this.downloading) { + console.log("Presentation download not finished yet, not opening", this); + return; + } + $window.open(this.url, target); + }; + DownloadPresentation.prototype.close = function() { this.openCallback = null; }; @@ -176,6 +185,14 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'], callback(this.file); }; + UploadPresentation.prototype.browserOpen = function(target) { + target = target || "_blank"; + if (!this.url) { + this.url = URL.createObjectURL(this.file.file); + } + $window.open(this.url, target); + }; + UploadPresentation.prototype.close = function() { }; @@ -199,6 +216,10 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'], this.scope.$destroy(); this.scope = null; } + if (this.url) { + URL.revokeObjectURL(this.url); + this.url = null; + } this.session = null; BasePresentation.prototype.clear.call(this); }; @@ -651,6 +672,13 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'], presentation.clear(); }; + $scope.downloadPresentation = function(presentation, $event) { + if ($event) { + $event.preventDefault(); + } + presentation.browserOpen(); + }; + $scope.toggleFullscreen = function(elem) { if (BigScreen.enabled) { diff --git a/static/partials/presentation.html b/static/partials/presentation.html index 2b128b54..e19843dc 100644 --- a/static/partials/presentation.html +++ b/static/partials/presentation.html @@ -44,7 +44,8 @@ title="{{ presentation.info.name }}">
- + +
{{ presentation.info.name }}
From 7a40a6a7c563e78732e7c8f5811d3a6268b8eed0 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Mon, 21 Jul 2014 15:31:43 +0200 Subject: [PATCH 2/2] Revoke temporary URLs when closing. --- static/js/directives/pdfcanvas.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/static/js/directives/pdfcanvas.js b/static/js/directives/pdfcanvas.js index dfbac86c..9e39b925 100644 --- a/static/js/directives/pdfcanvas.js +++ b/static/js/directives/pdfcanvas.js @@ -36,6 +36,7 @@ define(['require', 'underscore', 'jquery'], function(require, _, $) { this.currentPageNumber = null; this.pendingPageNumber = null; this.renderTask = null; + this.url = null; }; PDFCanvas.prototype._close = function() { @@ -49,6 +50,10 @@ define(['require', 'underscore', 'jquery'], function(require, _, $) { this.doc.destroy(); this.doc = null; } + if (this.url) { + URL.revokeObjectURL(this.url); + this.url = null; + } this.pendingPageNumber = null; this.currentPageNumber = -1; this.maxPageNumber = -1; @@ -74,8 +79,8 @@ define(['require', 'underscore', 'jquery'], function(require, _, $) { var fp = source.file || source; if (typeof URL !== "undefined" && URL.createObjectURL) { - var url = URL.createObjectURL(fp); - this._openFile(url); + this.url = URL.createObjectURL(fp); + this._openFile(this.url); } else { var fileReader = new FileReader(); fileReader.onload = _.bind(function(evt) {