Skip to content

Commit 320955b

Browse files
committed
fix(screen-templates): close preview on tab switch (FOUR-29145)
1 parent df78e76 commit 320955b

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

resources/js/processes/screen-templates/components/MyTemplatesListing.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ export default {
252252
this.loading = false;
253253
});
254254
},
255+
mounted() {
256+
this.bindPreviewTabClose("#nav-myTemplates-tab");
257+
},
258+
beforeDestroy() {
259+
this.unbindPreviewTabClose();
260+
},
255261
methods: {
256262
handleSelectTemplate(template) {
257263
this.selectedTemplate = template;

resources/js/processes/screen-templates/components/PublicTemplatesListing.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ export default {
261261
this.apiNoResults = false;
262262
});
263263
},
264+
mounted() {
265+
this.bindPreviewTabClose("#nav-publicTemplates-tab");
266+
},
267+
beforeDestroy() {
268+
this.unbindPreviewTabClose();
269+
},
264270
methods: {
265271
handleSelectTemplate(template) {
266272
this.selectedTemplate = template;

resources/js/processes/screen-templates/mixins/templatePreviewMixin.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,33 @@ const templatePreviewMixin = {
9292
this.showTemplatePreview = false;
9393
this.selectedTemplate = null;
9494
},
95+
closePreviewFrame() {
96+
if (this.$refs?.preview?.onClose) {
97+
this.$refs.preview.onClose();
98+
return;
99+
}
100+
if (typeof this.onClose === "function") {
101+
this.onClose();
102+
}
103+
},
104+
bindPreviewTabClose(tabSelector) {
105+
if (!tabSelector || typeof $ === "undefined") {
106+
return;
107+
}
108+
this._previewTabSelector = tabSelector;
109+
this._previewTabHandler = () => {
110+
this.closePreviewFrame();
111+
};
112+
$(tabSelector).on("hide.bs.tab.templatePreview", this._previewTabHandler);
113+
},
114+
unbindPreviewTabClose() {
115+
if (!this._previewTabSelector || typeof $ === "undefined") {
116+
return;
117+
}
118+
$(this._previewTabSelector).off("hide.bs.tab.templatePreview", this._previewTabHandler);
119+
this._previewTabSelector = null;
120+
this._previewTabHandler = null;
121+
},
95122
onClose() {
96123
this.$emit('mark-selected-row', 0);
97124
this.showPreview = false;

0 commit comments

Comments
 (0)