add allowDuplicates option to IFrame plugin

pull/3395/head
REJack 4 years ago
parent 1b66775d4b
commit 472c1622cf

@ -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 = `<li class="nav-item" role="presentation"><a class="nav-link" data-toggle="row" id="${navId}" href="#${tabId}" role="tab" aria-controls="${tabId}" aria-selected="false">${title}</a></li>`
$(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) {

@ -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.

Loading…
Cancel
Save