Fix minor bugs

This commit is contained in:
Dennis Eichhorn 2019-01-13 21:39:14 +01:00
parent b20db4128c
commit 43624a45ac
5 changed files with 31 additions and 24 deletions

View File

@ -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;
}

View File

@ -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);
};
/**

View File

@ -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;
};

View File

@ -47,7 +47,7 @@
jsOMS.addClass = function (ele, cls)
{
if (!jsOMS.hasClass(ele, cls)) {
ele.className += " " + cls;
ele.className += ele.className !== '' ? " " + cls : cls;
}
};

View File

@ -171,7 +171,7 @@
jsOMS.addClass = function (ele, cls)
{
if (!jsOMS.hasClass(ele, cls)) {
ele.className += " " + cls;
ele.className += ele.className !== '' ? " " + cls : cls;
}
};