Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds print button without manually detaching window #143

Merged
merged 2 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cosmoz-image-viewer.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export const template = html`
</paper-icon-button>
<paper-icon-button class="nav" on-click="onDownloadPdf" icon="icons:file-download" title="[[ _('Download images', t) ]]">
</paper-icon-button>
<paper-icon-button class="nav" on-click="onPrintPdf" icon="icons:print" title="[[ _('Print images', t) ]]">
</paper-icon-button>
<paper-icon-button class="nav" hidden$="[[!_showFullscreen]]" on-click="openFullscreen" icon="icons:fullscreen" title="[[ _('Fullscreen image', t) ]]">
</paper-icon-button>
<paper-icon-button class="nav" hidden$="[[!showClose]]" on-click="_close" icon="icons:close" title="[[ _('Close fullscreen', t) ]]">
Expand Down
16 changes: 16 additions & 0 deletions cosmoz-image-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ class CosmozImageViewer extends translatable(PolymerElement) {
_showPageNumber: {
type: Boolean,
computed: '_computeShowActions(showPageNumber, images.length, _elementHeight)'
},

_shortCutPrint: {
type: Boolean,
value: false
}
};
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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}
Expand Down