This repository was archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
DOCSP-1682 - Change default tab behavior to render inline. Added 'hid… #178
Merged
jdestefano-mongo
merged 1 commit into
mongodb:master
from
jdestefano-mongo:DOCSP-1682v2
Feb 27, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,12 @@ function showHideTabContent(currentAttrValue) { | |
class TabsSingleton { | ||
constructor(key) { | ||
this.key = key; | ||
this.tabStrip = document.querySelector('.tab-strip--singleton'); | ||
this.tabStrips = document.querySelectorAll('.tab-strip--singleton'); | ||
|
||
// Only tab sets will have a type, init and try to retrieve | ||
this.type = null; | ||
if (this.tabStrip !== null) { | ||
this.type = this.tabStrip.getAttribute('data-tab-preference'); | ||
if (this.tabStrips !== null) { | ||
this.type = this.tabStrips[0].getAttribute('data-tab-preference'); | ||
} | ||
} | ||
|
||
|
@@ -61,44 +61,47 @@ class TabsSingleton { | |
* @returns {string} The first singleton tab ID found. | ||
*/ | ||
getFirstTab() { | ||
const tabsElement = this.tabStrip.querySelector('.tab-strip__element[aria-selected=true]'); | ||
const tabsElement = this.tabStrips[0]. | ||
querySelector('.tab-strip__element[aria-selected=true]'); | ||
if (!tabsElement) { return null; } | ||
|
||
return tabsElement.getAttribute('data-tabid'); | ||
} | ||
|
||
setup() { | ||
if (!this.tabStrip) { return; } | ||
if (!this.tabStrips) { return; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
|
||
this.hideTabBars(); | ||
|
||
for (const element of this.tabStrip.querySelectorAll('[data-tabid]')) { | ||
element.onclick = (e) => { | ||
// Get the tab ID of the clicked tab | ||
const tabId = e.target.getAttribute('data-tabid'); | ||
const type = this.tabStrip.getAttribute('data-tab-preference'); | ||
|
||
// Build the pref object to set | ||
const pref = {}; | ||
pref.tabId = tabId; | ||
pref.type = type; | ||
|
||
// Check to make sure value is not null, i.e., don't do anything on "other" | ||
if (tabId) { | ||
// Save the users preference and re-render | ||
this.tabPref = pref; | ||
this.update(); | ||
|
||
e.preventDefault(); | ||
} | ||
}; | ||
for (const tabStrip of this.tabStrips) { | ||
for (const element of tabStrip.querySelectorAll('[data-tabid]')) { | ||
element.onclick = (e) => { | ||
// Get the tab ID of the clicked tab | ||
const tabId = e.target.getAttribute('data-tabid'); | ||
const type = this.tabStrips[0].getAttribute('data-tab-preference'); | ||
|
||
// Build the pref object to set | ||
const pref = {}; | ||
pref.tabId = tabId; | ||
pref.type = type; | ||
|
||
// Check to make sure value is not null, i.e., don't do anything on "other" | ||
if (tabId) { | ||
// Save the users preference and re-render | ||
this.tabPref = pref; | ||
this.update(); | ||
|
||
e.preventDefault(); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
this.update(); | ||
} | ||
|
||
update() { | ||
if (!this.tabStrip) { return; } | ||
if (!this.tabStrips) { return; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
let type = this.type; | ||
|
||
let tabPref = this.tabPref; | ||
|
@@ -107,7 +110,7 @@ class TabsSingleton { | |
// Check if current page has a one-off page specific pref | ||
tabPref = tabPref.pages; | ||
type = window.location.pathname; | ||
} else if (!this.tabStrip.querySelector(`[data-tabid="${tabPref[type]}"]`)) { | ||
} else if (!this.tabStrips[0].querySelector(`[data-tabid="${tabPref[type]}"]`)) { | ||
// If their tabPref does not exist at the top of the page use the first tab | ||
tabPref[type] = this.getFirstTab(); | ||
} | ||
|
@@ -125,29 +128,31 @@ class TabsSingleton { | |
* @returns {void} | ||
*/ | ||
showHideSelectedTab(currentAttrValue) { | ||
// Get the <a>, <li> and <ul> of the selected tab | ||
const tabLink = $(this.tabStrip.querySelector(`[data-tabid="${currentAttrValue}"]`)); | ||
const tabList = tabLink.parent('ul'); | ||
|
||
// Get the dropdown <a> and <li> for active and label management | ||
const dropdownLink = $(this.tabStrip.querySelector('.dropdown-toggle')); | ||
const dropdownListItem = $(this.tabStrip.querySelector('.dropdown')); | ||
|
||
// Set the active tab, if it's on the dropdown set it to active and change label | ||
if (tabList.hasClass('dropdown-menu')) { | ||
// Use first so text doesn't repeat if more than one set of tabs | ||
dropdownLink.text(`${tabLink.first().text()}`).append('<span class="caret"></span>'); | ||
dropdownListItem. | ||
attr('aria-selected', true). | ||
siblings(). | ||
attr('aria-selected', false); | ||
} else { | ||
// Set a non-dropdown tab to active, and change the dropdown label back to "Other" | ||
tabLink. | ||
attr('aria-selected', true). | ||
siblings(). | ||
attr('aria-selected', false); | ||
dropdownLink.text('Other ').append('<span class="caret"></span>'); | ||
for (const tabStrip of this.tabStrips) { | ||
// Get the <a>, <li> and <ul> of the selected tab | ||
const tabLink = $(tabStrip.querySelector(`[data-tabid="${currentAttrValue}"]`)); | ||
const tabList = tabLink.parent('ul'); | ||
|
||
// Get the dropdown <a> and <li> for active and label management | ||
const dropdownLink = $(tabStrip.querySelector('.dropdown-toggle')); | ||
const dropdownListItem = $(tabStrip.querySelector('.dropdown')); | ||
|
||
// Set the active tab, if it's on the dropdown set it to active and change label | ||
if (tabList.hasClass('dropdown-menu')) { | ||
// Use first so text doesn't repeat if more than one set of tabs | ||
dropdownLink.text(`${tabLink.first().text()}`).append('<span class="caret"></span>'); | ||
dropdownListItem. | ||
attr('aria-selected', true). | ||
siblings(). | ||
attr('aria-selected', false); | ||
} else { | ||
// Set a non-dropdown tab to active, and change the dropdown label back to "Other" | ||
tabLink. | ||
attr('aria-selected', true). | ||
siblings(). | ||
attr('aria-selected', false); | ||
dropdownLink.text('Other ').append('<span class="caret"></span>'); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -156,16 +161,19 @@ class TabsSingleton { | |
* @returns {void} | ||
*/ | ||
hideTabBars() { | ||
const tabBars = $('.tab-strip--singleton'); | ||
const mainTabBar = tabBars.first(); | ||
// Remove any additional tab bars | ||
tabBars.slice(1). | ||
detach(); | ||
// Position the main tab bar after the page title | ||
mainTabBar. | ||
detach(). | ||
insertAfter('h1'). | ||
first(); | ||
const isTop = document.querySelector('.tabs-top'); | ||
if (isTop) { | ||
const tabBars = $('.tab-strip--singleton'); | ||
const mainTabBar = tabBars.first(); | ||
// Remove any additional tab bars | ||
tabBars.slice(1). | ||
detach(); | ||
// Position the main tab bar after the page title | ||
mainTabBar. | ||
detach(). | ||
insertAfter('h1'). | ||
first(); | ||
} | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.tabStrips
will never benull
given the above switch toquerySelectorAll
.This should read
if (this.tabStrips.length > 0) {