diff --git a/build/js/IFrame.js b/build/js/IFrame.js
index 15e68699a..cc7a7d904 100644
--- a/build/js/IFrame.js
+++ b/build/js/IFrame.js
@@ -49,6 +49,7 @@ const Default = {
autoIframeMode: true,
autoItemActive: true,
autoShowNewTab: true,
+ allowDuplicates: false,
loadingScreen: true,
useNavbarItems: true,
scrollOffset: 40,
@@ -85,8 +86,13 @@ class IFrame {
}
createTab(title, link, uniqueName, autoOpen) {
- const tabId = `panel-${uniqueName}-${Math.floor(Math.random() * 1000)}`
- const navId = `tab-${uniqueName}-${Math.floor(Math.random() * 1000)}`
+ let tabId = `panel-${uniqueName}`
+ let navId = `tab-${uniqueName}`
+
+ if (this._config.allowDuplicates) {
+ tabId += `-${Math.floor(Math.random() * 1000)}`
+ navId += `-${Math.floor(Math.random() * 1000)}`
+ }
const newNavItem = `
${title}`
$(SELECTOR_TAB_NAVBAR_NAV).append(unescape(escape(newNavItem)))
@@ -134,7 +140,21 @@ class IFrame {
return
}
- this.createTab(title, link, link.replace('.html', '').replace('./', '').replace(/["&'./=?[\]]/gi, '-').replace(/(--)/gi, ''), autoOpen)
+ const uniqueName = link.replace('.html', '').replace('./', '').replace(/["&'./=?[\]]/gi, '-').replace(/(--)/gi, '')
+ const navId = `tab-${uniqueName}`
+
+ // eslint-disable-next-line no-console
+ console.log($(`#${navId}`))
+ // eslint-disable-next-line no-console
+ console.log(!this._config.allowDuplicates && $(`#${navId}`).length === 0)
+
+ if (!this._config.allowDuplicates && $(`#${navId}`).length > 0) {
+ return this.switchTab(`#${navId}`)
+ }
+
+ if ((!this._config.allowDuplicates && $(`#${navId}`).length === 0) || this._config.allowDuplicates) {
+ this.createTab(title, link, uniqueName, autoOpen)
+ }
}
switchTab(item) {
diff --git a/docs/javascript/iframe.md b/docs/javascript/iframe.md
index f959c1318..40c1c8d8a 100644
--- a/docs/javascript/iframe.md
+++ b/docs/javascript/iframe.md
@@ -51,6 +51,7 @@ $('.content-wrapper').IFrame({
autoIframeMode: true,
autoItemActive: true,
autoShowNewTab: true,
+ allowDuplicates: true,
loadingScreen: 750,
useNavbarItems: true
})
@@ -69,6 +70,7 @@ $('.content-wrapper').IFrame({
|autoIframeMode | Boolean | true | Whether to automatically add `.iframe-mode` to `body` if page is loaded via iframe.
|autoItemActive | Boolean | true | Whether to automatically set the sidebar menu item active based on the active iframe.
|autoShowNewTab | Boolean | true | Whether to automatically display created tab.
+|allowDuplicates | Boolean | true | Whether to allow creation of duplicate tab/iframe.
|loadingScreen | Boolean/Number | true | [Boolean] Whether to enable iframe loading screen; [Number] Set loading screen hide delay.
|useNavbarItems | Boolean | true | Whether to open navbar menu items, instead of open only sidebar menu items.