});
window.addEventListener('hashchange', function () {
- var hash = window.location.hash.replace(/^#/, '');
+ var hash = SimpleTabMenu.getIdentifierFromHash();
var element = (hash) ? elById(hash) : null;
if (element !== null && element.classList.contains('tabMenuContent')) {
_tabMenus.forEach(function (tabMenu) {
}
});
- if (window.location.hash.match(/^#(.*)$/)) {
- var hash = RegExp.$1;
+ var hash = SimpleTabMenu.getIdentifierFromHash();
+ if (hash) {
window.setTimeout(function () {
// check if page was initially scrolled using a tab id
var tabMenuContent = elById(hash);
var returnValue = null;
if (!oldTabs) {
- var hash = window.location.hash.replace(/^#/, ''), selectTab = null;
+ var hash = TabMenuSimple.getIdentifierFromHash();
+ var selectTab = null;
if (hash !== '') {
- if (hash.match(/^(.+)\/.*$/)) {
- hash = RegExp.$1;
- }
-
selectTab = this._tabs.get(hash);
// check for parent tab menu
});
}
+ var location = window.location.href.replace(/#[^#]+$/, '');
+ if (TabMenuSimple.getIdentifierFromHash() === name) {
+ location += window.location.hash;
+ }
+ else {
+ location += '#' + name;
+ }
+
// update history
+ //noinspection JSCheckFunctionSignatures
window.history.replaceState(
undefined,
undefined,
- window.location.href.replace(/#[^#]+$/, '') + '#' + name
+ location
);
}
}
};
+ TabMenuSimple.getIdentifierFromHash = function () {
+ if (window.location.hash.match(/^#([^\/]+)+(?:\/.+)?/)) {
+ return RegExp.$1;
+ }
+
+ return '';
+ };
+
return TabMenuSimple;
});