-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ToC component and other small tidmits.
- Loading branch information
Dan Jasnowski
committed
Jan 21, 2019
1 parent
fe904d1
commit b9c4440
Showing
8 changed files
with
149 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import TableOfContents from './components/TableOfContents.vue'; | ||
|
||
window.Vue = require('vue'); | ||
|
||
Vue.component('test', require('./components/test.vue')); | ||
Vue.component('table-of-contents', require('./components/TableOfContents.vue')); | ||
|
||
const app = new Vue({ | ||
el: '#app' | ||
components: { | ||
TableOfContents, | ||
}, | ||
el: '#app' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<template> | ||
<ul class="list-reset" v-if="links.length > 0"> | ||
<li class="mb-2" :class="link.isChild ? 'ml-2' : ''" v-for="link in links"> | ||
<a :href="link.href" class="text-grey-dark hover:text-grey-darkest">{{ link.text }}</a> | ||
</li> | ||
</ul> | ||
</template> | ||
|
||
<script> | ||
import _ from 'lodash' | ||
const anchorJS = require('anchor-js') | ||
const anchors = new anchorJS() | ||
function getHeadingText(element) { | ||
let text = '' | ||
for (var i = 0; i < element.childNodes.length; ++i) { | ||
if (element.childNodes[i].nodeType === 3) { | ||
text += element.childNodes[i].textContent; | ||
} | ||
} | ||
return text | ||
} | ||
export default { | ||
props: ['rows'], | ||
data() { | ||
return { | ||
links: [] | ||
} | ||
}, | ||
methods: { | ||
scrollTo(el) { | ||
const bounds = el.getBoundingClientRect() | ||
document.body.scrollBy(0, 200) | ||
} | ||
}, | ||
mounted() { | ||
anchors.options = { placement: 'left', class: 'text-grey-dark' } | ||
anchors.add() | ||
this.links = anchors.elements.filter((el) => _.includes(['H2', 'H3'], el.tagName)).map((el) => { | ||
return { | ||
isChild: el.tagName === 'H3', | ||
text: getHeadingText(el), | ||
href: el.querySelector('.anchorjs-link').getAttribute('href'), | ||
el: el, | ||
} | ||
}) | ||
} | ||
} | ||
</script> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"/js/app.js": "/js/app.js?id=3263d972b6665d3753f4", | ||
"/js/app.js": "/js/app.js?id=7d8a1260bea114fad785", | ||
"/css/main.css": "/css/main.css?id=c515db132c44b6aafe3e", | ||
"/js/main.js": "/js/main.js?id=82aedf2bfe414313fdbd" | ||
} |