diff options
author | Mike Greiling <mgreiling@gitlab.com> | 2017-07-05 17:20:41 +0000 |
---|---|---|
committer | Clement Ho <clemmakesapps@gmail.com> | 2017-07-05 17:20:41 +0000 |
commit | c06dad62e1004eb5b4f2251a233f740d3fa2a5c2 (patch) | |
tree | 78346e13ce069442c662bb14e7b33bb607c3f2d6 /app/assets/javascripts/signin_tabs_memoizer.js | |
parent | 11e03bf49c9dfc220c29129498996d52cd4276e2 (diff) | |
download | gitlab-ce-c06dad62e1004eb5b4f2251a233f740d3fa2a5c2.tar.gz |
Remove IIFEs around several javascript classes
Diffstat (limited to 'app/assets/javascripts/signin_tabs_memoizer.js')
-rw-r--r-- | app/assets/javascripts/signin_tabs_memoizer.js | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/app/assets/javascripts/signin_tabs_memoizer.js b/app/assets/javascripts/signin_tabs_memoizer.js index 2587facc582..3997a695d15 100644 --- a/app/assets/javascripts/signin_tabs_memoizer.js +++ b/app/assets/javascripts/signin_tabs_memoizer.js @@ -2,56 +2,54 @@ /* eslint no-new: "off" */ import AccessorUtilities from './lib/utils/accessor'; -((global) => { - /** - * Memorize the last selected tab after reloading a page. - * Does that setting the current selected tab in the localStorage - */ - class ActiveTabMemoizer { - constructor({ currentTabKey = 'current_signin_tab', tabSelector = 'ul.nav-tabs' } = {}) { - this.currentTabKey = currentTabKey; - this.tabSelector = tabSelector; - this.isLocalStorageAvailable = AccessorUtilities.isLocalStorageAccessSafe(); - - this.bootstrap(); - } - - bootstrap() { - const tabs = document.querySelectorAll(this.tabSelector); - if (tabs.length > 0) { - tabs[0].addEventListener('click', (e) => { - if (e.target && e.target.nodeName === 'A') { - const anchorName = e.target.getAttribute('href'); - this.saveData(anchorName); - } - }); - } +/** + * Memorize the last selected tab after reloading a page. + * Does that setting the current selected tab in the localStorage + */ +class ActiveTabMemoizer { + constructor({ currentTabKey = 'current_signin_tab', tabSelector = 'ul.nav-tabs' } = {}) { + this.currentTabKey = currentTabKey; + this.tabSelector = tabSelector; + this.isLocalStorageAvailable = AccessorUtilities.isLocalStorageAccessSafe(); + + this.bootstrap(); + } - this.showTab(); + bootstrap() { + const tabs = document.querySelectorAll(this.tabSelector); + if (tabs.length > 0) { + tabs[0].addEventListener('click', (e) => { + if (e.target && e.target.nodeName === 'A') { + const anchorName = e.target.getAttribute('href'); + this.saveData(anchorName); + } + }); } - showTab() { - const anchorName = this.readData(); - if (anchorName) { - const tab = document.querySelector(`${this.tabSelector} a[href="${anchorName}"]`); - if (tab) { - tab.click(); - } + this.showTab(); + } + + showTab() { + const anchorName = this.readData(); + if (anchorName) { + const tab = document.querySelector(`${this.tabSelector} a[href="${anchorName}"]`); + if (tab) { + tab.click(); } } + } - saveData(val) { - if (!this.isLocalStorageAvailable) return undefined; + saveData(val) { + if (!this.isLocalStorageAvailable) return undefined; - return window.localStorage.setItem(this.currentTabKey, val); - } + return window.localStorage.setItem(this.currentTabKey, val); + } - readData() { - if (!this.isLocalStorageAvailable) return null; + readData() { + if (!this.isLocalStorageAvailable) return null; - return window.localStorage.getItem(this.currentTabKey); - } + return window.localStorage.getItem(this.currentTabKey); } +} - global.ActiveTabMemoizer = ActiveTabMemoizer; -})(window); +window.ActiveTabMemoizer = ActiveTabMemoizer; |