diff --git a/Message/Request/Request.js b/Message/Request/Request.js index 98c8997..a60d1fe 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -87,7 +87,10 @@ return jsOMS.Message.Request.BrowserType.EDGE; } else if (!!window.chrome && !!window.chrome.webstore) { return jsOMS.Message.Request.BrowserType.CHROME; - } else if ((isChrome || isOpera) && !!window.CSS) { + } else if (((typeof isChrome !== 'undefined' && isChrome) + || (typeof isOpera !== 'undefined' && isOpera)) + && !!window.CSS + ) { return jsOMS.Message.Request.BrowserType.BLINK; } diff --git a/UI/Component/Tab.js b/UI/Component/Tab.js index c7dc459..9c3cae2 100644 --- a/UI/Component/Tab.js +++ b/UI/Component/Tab.js @@ -41,7 +41,7 @@ this.bindElement(e); } } else { - const tabs = document.querySelectorAll('.tabview'), + const tabs = document.querySelectorAll('.tab'), length = !tabs ? 0 : tabs.length; for (let i = 0; i < length; ++i) { @@ -61,8 +61,6 @@ */ bindElement (e) { - this.activateTabUri(e); - const nodes = e.querySelectorAll('.tab-links li'), length = nodes.length; @@ -73,18 +71,37 @@ /* Change Tab */ /* Remove selected tab */ - fragmentString = jsOMS.ltrim(fragmentString.replace(this.parentNode.getElementsByClassName('active')[0].getElementsByTagName('label')[0].getAttribute('for'), ''), ','); - jsOMS.removeClass(this.parentNode.getElementsByClassName('active')[0], 'active'); + const oldActive = this.parentNode.getElementsByClassName('active'); + if (oldActive.length > 0) { + // find old active and remove it + fragmentString = jsOMS.trim( + fragmentString.replace(oldActive[0].getElementsByTagName('label')[0].getAttribute('for'), ''), + ',' + ); + + jsOMS.removeClass(oldActive[0], 'active'); + } + + // remove new element if new element already inside, alternatively check for existence and don't do a new push state? + // todo: here is a bug or in the uri factory. replace also replaces substrings e.g. #test-c-tab-1 gets partially replaced + // by c-tab-1. either search for #c-tab-1 or ,c-tab-1 to be certain. That's not possible because it doesn't start with `#` + fragmentString = jsOMS.trim( + fragmentString.replace(this.getElementsByTagName('label')[0].getAttribute('for'), ''), + ',' + ); + jsOMS.addClass(this, 'active'); /* Add selected tab */ - window.history.pushState(null,'', + window.history.pushState(null, '', jsOMS.Uri.UriFactory.build( '{%}#' + (fragmentString === '' ? '' : fragmentString + ',') + this.getElementsByTagName('label')[0].getAttribute('for') ) ); }); } + + this.activateTabUri(e); }; /** diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index 9d50aea..4830035 100644 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -153,24 +153,11 @@ const fragments = url.match(/\#[a-zA-Z0-9\-,]+/g), fragLength = fragments !== null ? fragments.length : 0; - for (let i = 0; i < fragLength; ++i) { + for (let i = 0; i < fragLength - 1; ++i) { + // remove all from old url url = url.replace(fragments[i], ''); } - if (fragLength > 0) { - const fragList = fragments[fragLength - 1].split(','), - fragListLength = fragList.length; - let fragListNew = []; - - for (let i = 0; i < fragListLength; ++i) { - if (!fragListNew.includes(fragList[i]) && fragList[i] !== '') { - fragListNew.push(fragList[i]); - } - } - - url += fragListNew.join(','); - } - return url; }; diff --git a/Utils/UiUtils.js b/Utils/UiUtils.js index f3445c5..a50dc84 100644 --- a/Utils/UiUtils.js +++ b/Utils/UiUtils.js @@ -47,7 +47,7 @@ jsOMS.addClass = function (ele, cls) { if (!jsOMS.hasClass(ele, cls)) { - ele.className += " " + cls; + ele.className += ele.className !== '' ? " " + cls : cls; } }; diff --git a/Utils/oLib.js b/Utils/oLib.js index 4aca28a..9c747ae 100644 --- a/Utils/oLib.js +++ b/Utils/oLib.js @@ -171,7 +171,7 @@ jsOMS.addClass = function (ele, cls) { if (!jsOMS.hasClass(ele, cls)) { - ele.className += " " + cls; + ele.className += ele.className !== '' ? " " + cls : cls; } };