Use classList.replace

This commit is contained in:
Mimi 2020-07-15 14:36:37 +08:00
parent f45b8c9845
commit e9addc90ca
4 changed files with 12 additions and 7 deletions

View File

@ -45,7 +45,7 @@ Please follow this Issue template to provide relevant information, such as sourc
```
### Package dependencies Information
<!-- Paste output from `npm ls --depth 0` in Hexo root dirctory (粘贴在 Hexo 根目录下 `npm ls --depth 0` 输出的信息) -->
<!-- Paste output from `npm ls --depth 0` in Hexo root directory (粘贴在 Hexo 根目录下 `npm ls --depth 0` 输出的信息) -->
```
```

View File

@ -45,7 +45,7 @@ Please follow this Issue template to provide relevant information, such as sourc
```
### Package dependencies Information
<!-- Paste output from `npm ls --depth 0` in Hexo root dirctory (粘贴在 Hexo 根目录下 `npm ls --depth 0` 输出的信息) -->
<!-- Paste output from `npm ls --depth 0` in Hexo root directory (粘贴在 Hexo 根目录下 `npm ls --depth 0` 输出的信息) -->
```
```

View File

@ -59,8 +59,7 @@ NexT.boot.registerEvents = function() {
translateY: [0, -20],
complete : () => {
// Prevent adding TOC to Overview if Overview was selected when close & open sidebar.
sidebar.classList.remove(activeClassName[1 - index]);
sidebar.classList.add(activeClassName[index]);
sidebar.classList.replace(activeClassName[1 - index], activeClassName[index]);
window.anime({
duration,
targets : panel[index],

View File

@ -6,6 +6,14 @@ HTMLElement.prototype.wrap = function(wrapper) {
wrapper.appendChild(this);
};
// https://caniuse.com/#feat=mdn-api_element_classlist_replace
if (typeof DOMTokenList.prototype.replace !== 'function') {
DOMTokenList.prototype.replace = function(remove, add) {
this.remove(remove);
this.add(add);
};
}
NexT.utils = {
/**
@ -66,9 +74,7 @@ NexT.utils = {
document.querySelectorAll('figure.highlight').forEach(element => {
element.querySelectorAll('.code .line span').forEach(span => {
span.classList.forEach(name => {
// https://caniuse.com/#feat=mdn-api_element_classlist_replace
span.classList.remove(name);
span.classList.add(`hljs-${name}`);
span.classList.replace(name, `hljs-${name}`);
});
});
if (!CONFIG.copycode) return;