| 1 |
/* global jQuery, PoweredCache */ |
| 2 |
(function ($) { |
| 3 |
// Use strict mode |
| 4 |
|
| 5 |
// Define global PoweredCache object if it does not exist |
| 6 |
if (typeof window.PoweredCache !== 'object') { |
| 7 |
window.PoweredCache = {}; |
| 8 |
} |
| 9 |
|
| 10 |
PoweredCache.sideNavigation = function (element) { |
| 11 |
const button = $(element); |
| 12 |
|
| 13 |
function current(el) { |
| 14 |
const button = $(el); // eslint-disable-line no-shadow |
| 15 |
const parent = button.closest('.sui-vertical-tabs'); |
| 16 |
const wrapper = button.closest('.sui-row-with-sidenav'); |
| 17 |
const content = wrapper.find('> div[data-tab]'); |
| 18 |
const dataNav = button.data('tab'); |
| 19 |
const dataBox = wrapper.find(`div[data-tab="${dataNav}"]`); |
| 20 |
parent.find('li').removeClass('current'); |
| 21 |
button.parent().addClass('current'); |
| 22 |
// window.location.hash = el.hash; |
| 23 |
localStorage.setItem('poweredcache_current_nav', el.hash); |
| 24 |
|
| 25 |
content.hide(); |
| 26 |
dataBox.show(); |
| 27 |
} |
| 28 |
|
| 29 |
function init() { |
| 30 |
button.on('click', function (e) { |
| 31 |
current(e.target); |
| 32 |
e.preventDefault(); |
| 33 |
e.stopPropagation(); |
| 34 |
}); |
| 35 |
|
| 36 |
// auto-focus current section |
| 37 |
if (window.location.hash && $(`a[href="${window.location.hash}"]`).length) { |
| 38 |
$(`a[href^="${window.location.hash}"]`).click(); |
| 39 |
} |
| 40 |
|
| 41 |
// auto-focus last selection |
| 42 |
const lastnav = localStorage.getItem('poweredcache_current_nav'); |
| 43 |
if (lastnav && $(`a[href="${lastnav}"]`).length) { |
| 44 |
$(`a[href^="${lastnav}"]`).click(); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
init(); |
| 49 |
|
| 50 |
return this; |
| 51 |
}; |
| 52 |
|
| 53 |
$('body').ready(function () { |
| 54 |
const button = $('.sui-vertical-tab a'); |
| 55 |
|
| 56 |
PoweredCache.sideNavigation(button); |
| 57 |
}); |
| 58 |
})(jQuery); |
| 59 |
|