From 4a2c52d9627ca707b350e1839f595f812710ecee Mon Sep 17 00:00:00 2001 From: REJack Date: Fri, 17 Sep 2021 23:18:19 +0200 Subject: [PATCH] add allowReload option for IFrame plugin --- build/js/IFrame.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/build/js/IFrame.js b/build/js/IFrame.js index 3b68d2e76..4a587102f 100644 --- a/build/js/IFrame.js +++ b/build/js/IFrame.js @@ -53,6 +53,7 @@ const Default = { autoShowNewTab: true, autoDarkMode: false, allowDuplicates: false, + allowReload: true, loadingScreen: true, useNavbarItems: true, scrollOffset: 40, @@ -146,7 +147,7 @@ class IFrame { const navId = `tab-${uniqueName}` if (!this._config.allowDuplicates && $(`#${navId}`).length > 0) { - return this.switchTab(`#${navId}`) + return this.switchTab(`#${navId}`, this._config.allowReload) } if ((!this._config.allowDuplicates && $(`#${navId}`).length === 0) || this._config.allowDuplicates) { @@ -154,12 +155,35 @@ class IFrame { } } - switchTab(item) { + switchTab(item, reload = false) { const $item = $(item) const tabId = $item.attr('href') $(SELECTOR_TAB_EMPTY).hide() + + if (reload) { + const $loadingScreen = $(SELECTOR_TAB_LOADING) + if (this._config.loadingScreen) { + $loadingScreen.show(0, () => { + $(`${tabId} iframe`).attr('src', $(`${tabId} iframe`).attr('src')).ready(() => { + if (this._config.loadingScreen) { + if (typeof this._config.loadingScreen === 'number') { + setTimeout(() => { + $loadingScreen.fadeOut() + }, this._config.loadingScreen) + } else { + $loadingScreen.fadeOut() + } + } + }) + }) + } else { + $(`${tabId} iframe`).attr('src', $(`${tabId} iframe`).attr('src')) + } + } + $(`${SELECTOR_TAB_NAVBAR_NAV} .active`).tab('dispose').removeClass('active') + this._fixHeight() $item.tab('show')