Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Replace inner html #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
488 changes: 487 additions & 1 deletion dist/scrollnav.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/scrollnav.min.js.map

Large diffs are not rendered by default.

495 changes: 494 additions & 1 deletion dist/scrollnav.min.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/scrollnav.min.umd.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
"@jarmee/jest-dom-custom-matchers": "^1.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"eslint": "^5.10.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-prettier": "^3.0.0",
"husky": "^1.2.1",
"jest": "^23.6.0",
"microbundle": "^0.9.0",
"microbundle": "^0.13.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.15.3"
},
Expand Down
4 changes: 1 addition & 3 deletions src/scrollnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ function init(elem, options) {
if (this.settings.debug) {
// eslint-disable-next-line no-console
console.error(`
scrollnav build failed, options.insertLocation "${
this.settings.insertLocation
}" is not a valid option
scrollnav build failed, options.insertLocation "${this.settings.insertLocation}" is not a valid option
`);
}
return;
Expand Down
42 changes: 21 additions & 21 deletions src/util/createList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ export default function createList(data, isSubList = false) {
const suffix = isSubList ? '__sub-' : '__';
const baseClass = 'scroll-nav' + suffix;

const itemsMarkup = `
${data
.map(
item =>
`<li class="${baseClass}item" data-sn-section="${item.id}">
<a class="${baseClass}link" href="#${item.id}">${item.text}</a>
${
item.subSections && item.subSections.length
? `${createList(item.subSections, true)}`
: ''
}
</li>`
)
.join('')}
`;
let olElem = document.createElement('ol');
olElem.classList.add(baseClass + 'list');

const list = `
<ol class="${baseClass}list">
${itemsMarkup}
</ol>
`;
data.forEach(function(item) {
let liElem = document.createElement('li');
liElem.classList.add(baseClass + 'item');
liElem.setAttribute('data-sn-section', item.id);
olElem.appendChild(liElem);

return list;
let aElem = document.createElement('a');
aElem.classList.add(baseClass + 'link');
aElem.setAttribute('href', '#' + item.id);
let linkText = document.createTextNode(item.text);
aElem.appendChild(linkText);
liElem.appendChild(aElem);

if (item.subSections.length) {
let subList = createList(item.subSections, true);
liElem.appendChild(subList);
}
});

return olElem;
}
2 changes: 1 addition & 1 deletion src/util/createNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import createList from './createList';
export default function createNav(data) {
const nav = document.createElement('nav');
nav.className = 'scroll-nav';
nav.innerHTML = createList(data);
nav.appendChild(createList(data));

return nav;
}
159 changes: 86 additions & 73 deletions test/coverage/clover.xml

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions test/coverage/coverage-final.json

Large diffs are not rendered by default.

Loading