From 756be7e9ae8f4f137678f0252e6230dd55fa13d8 Mon Sep 17 00:00:00 2001 From: Joakim Carlsson Kekonius Date: Fri, 30 Oct 2020 10:53:58 +0100 Subject: [PATCH] feat: adds print button without manually detaching window (#143) * feat: adds print button without detaching manually --- cosmoz-image-viewer.html.js | 2 ++ cosmoz-image-viewer.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cosmoz-image-viewer.html.js b/cosmoz-image-viewer.html.js index 610b054..c6eab2b 100644 --- a/cosmoz-image-viewer.html.js +++ b/cosmoz-image-viewer.html.js @@ -152,6 +152,8 @@ export const template = html` + + diff --git a/cosmoz-image-viewer.js b/cosmoz-image-viewer.js index a3675f2..e6fd4a3 100644 --- a/cosmoz-image-viewer.js +++ b/cosmoz-image-viewer.js @@ -263,6 +263,11 @@ class CosmozImageViewer extends translatable(PolymerElement) { _showPageNumber: { type: Boolean, computed: '_computeShowActions(showPageNumber, images.length, _elementHeight)' + }, + + _shortCutPrint: { + type: Boolean, + value: false } }; } @@ -441,6 +446,10 @@ class CosmozImageViewer extends translatable(PolymerElement) { w.addEventListener('beforeunload', globals.windowBeforeUnloadHandler); + if (this._shortCutPrint) { + w.addEventListener('afterprint', async () => await this.attach()); + } + if (w.ciw == null) { w.addEventListener('ready', () => setImages()); this._appendScriptsToWindow(windowTemplateClone.childNodes, w); @@ -493,6 +502,13 @@ class CosmozImageViewer extends translatable(PolymerElement) { async downloadPdf(urls) { return await download(urls, this.downloadFileName, this.credentials); } + async onPrintPdf() { + this._shortCutPrint = true; + await this.detach(); + await globals.window.ciw.printPage(); + this._shortCutPrint = false; + } + /** * Toggles between initial zoom level and 1.5x initial zoom level. * @returns {undefined}