2018-06-22 10:48:00 +02:00
< template >
2018-06-25 23:43:09 +02:00
< div class = "__slate" >
2018-06-22 23:13:30 +02:00
< aside class = "api__toc" >
< div class = "api__toc__search" >
2018-06-25 22:03:03 +02:00
< input type = "search" class = "api__toc__search__field" id = "input-search" placeholder = "Search" / >
< div class = "api__toc__search__clear" id = "clear-search" title = "Clear search query" > & times ; < / div >
2018-06-22 23:13:30 +02:00
< ul class = "api__toc__search__results" > < / ul >
< / div >
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
< div id = "toc" class = "api__toc__items" role = "navigation" > < / div >
< / aside >
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
< section class = "api__content" v-html = "htmlContent" > < / section >
< / div >
< / template >
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
< script >
window . $ = window . jQuery = require ( "jquery" ) ;
require ( "jquery-ui" ) ;
require ( "jquery.tocify" ) ;
require ( "../js/jquery.highlight" ) ;
const lunr = require ( "lunr" ) ;
const md = require ( "markdown-it" ) ( )
. use ( require ( "markdown-it-anchor" ) , {
level : 1
} )
. use ( require ( "markdown-it-container" ) , "api__content__body" )
. use ( require ( "markdown-it-container" ) , "api__content__example" ) ;
export default {
2018-06-23 22:46:49 +02:00
data ( ) {
2018-06-22 23:13:30 +02:00
return {
content : { } ,
htmlContent : "" ,
searchIndex : { } ,
searchResults : { } ,
2018-06-25 16:27:00 +02:00
toc : { }
2018-06-22 23:13:30 +02:00
}
2018-06-22 10:48:00 +02:00
} ,
2018-06-22 23:13:30 +02:00
props : [ "markdownFile" ] ,
methods : {
makeToc : function ( ) {
this . toc = $ ( "#toc" ) . tocify ( {
extendPage : false ,
hashGenerator : ( text , element ) => element . prop ( "id" ) ,
hideEffectSpeed : 180 ,
highlightOffset : 60 ,
ignoreSelector : ".toc-ignore" ,
scrollHistory : false ,
2018-06-25 20:47:56 +02:00
scrollTo : 84 ,
2018-06-22 23:13:30 +02:00
selectors : "h2" ,
showEffectSpeed : 0 ,
2018-06-25 20:47:56 +02:00
smoothScroll : true ,
smoothScrollSpeed : 0 ,
2018-06-22 23:13:30 +02:00
theme : "none"
} ) . data ( "toc-tocify" ) ;
} ,
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
populateSearchIndex : function ( ) {
const component = this ;
2018-06-22 10:48:00 +02:00
2018-06-25 22:03:03 +02:00
$ ( ".api__content__body h2" ) . each ( function ( ) {
2018-06-22 23:13:30 +02:00
const title = $ ( this ) ;
const body = title . nextUntil ( "h2" ) ;
component . searchIndex . add ( {
body : body . text ( ) ,
id : title . prop ( "id" ) ,
title : title . text ( )
} ) ;
} ) ;
} ,
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
bindSearchIndex : function ( ) {
2018-06-25 23:43:09 +02:00
this . content = $ ( ".api__content" ) ;
2018-06-22 23:13:30 +02:00
this . searchResults = $ ( ".api__toc__search__results" ) ;
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
$ ( "#input-search" ) . on ( "keyup" , this . search ) ;
} ,
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
search : function ( event ) {
const component = this ;
2018-06-25 22:03:03 +02:00
const searchCancel = $ ( "#clear-search" ) ;
2018-06-22 23:13:30 +02:00
const searchElement = $ ( "#input-search" ) ;
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
component . unhighlight ( ) ;
component . searchResults . addClass ( "active" ) ;
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
// ESC clears the field
2018-06-25 22:03:03 +02:00
if ( event . keyCode === 27 ) {
searchCancel . removeClass ( "active" ) ;
searchElement . val ( "" ) ;
}
searchCancel . on ( "click" , function ( ) {
component . unhighlight ( ) ;
component . searchResults . removeClass ( "active" ) ;
searchCancel . removeClass ( "active" ) ;
searchElement . val ( "" ) ;
} ) ;
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
if ( searchElement . val ( ) ) {
const results = component . searchIndex . search ( searchElement . val ( ) ) . filter ( r => r . score > 0.0001 ) ;
2018-06-25 22:03:03 +02:00
searchCancel . addClass ( "active" ) ;
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
if ( results . length ) {
component . searchResults . empty ( ) ;
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
$ . each ( results , function ( index , result ) {
const elem = document . getElementById ( result . ref ) ;
2018-06-25 22:03:03 +02:00
component . searchResults . append ( ` <li><a href="# ${ result . ref } " title="Visit the ' ${ $ ( elem ) . text ( ) } ' section in our documentation"> ${ $ ( elem ) . text ( ) } </a></li> ` ) ;
2018-06-22 23:13:30 +02:00
} ) ;
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
component . highlight ( this ) ;
} else {
2018-06-25 23:43:09 +02:00
component . searchResults . html ( ` <li style="padding: 0.25rem 0.5rem 0.25rem 0.75rem;">No results found for <code> ${ searchElement . val ( ) } </code></li> ` ) ;
2018-06-22 23:13:30 +02:00
}
2018-06-22 10:48:00 +02:00
} else {
2018-06-22 23:13:30 +02:00
component . unhighlight ( ) ;
component . searchResults . removeClass ( "active" ) ;
2018-06-22 10:48:00 +02:00
}
2018-06-22 23:13:30 +02:00
} ,
highlight : function ( element ) {
if ( element . value ) this . content . highlight ( element . value , { element : "span" , className : "search-highlight" } ) ;
} ,
unhighlight : function ( ) {
this . content . unhighlight ( { element : "span" , className : "search-highlight" } ) ;
2018-06-22 10:48:00 +02:00
}
} ,
2018-06-22 23:13:30 +02:00
2018-06-25 08:10:15 +02:00
created : function ( ) {
this . $http . get ( this . markdownFile ) . then ( function ( response ) {
2018-06-22 23:13:30 +02:00
this . htmlContent = md . render ( response . body ) ;
this . $nextTick ( function ( ) {
this . makeToc ( ) ;
this . searchIndex = new lunr . Index ( ) ;
this . searchIndex . ref ( "id" ) ;
this . searchIndex . field ( "title" , { boost : 10 } ) ;
this . searchIndex . field ( "body" ) ;
this . searchIndex . pipeline . add ( lunr . trimmer , lunr . stopWordFilter ) ;
this . populateSearchIndex ( ) ;
this . bindSearchIndex ( ) ;
} ) ;
} ) . catch ( error => {
console . log ( "Source Markdown file, not found:" , error ) ;
} ) ;
2018-06-22 10:48:00 +02:00
} ,
2018-06-22 23:13:30 +02:00
name : "Slate"
} ;
< / script >
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
< style lang = "scss" >
@ import "../../../node_modules/highlight.js/styles/monokai-sublime" ;
@ import "../scss/init/colors" ;
@ import "../scss/init/mixins" ;
2018-06-22 10:48:00 +02:00
2018-06-25 23:43:09 +02:00
. _ _slate {
2018-06-22 23:13:30 +02:00
width : 100 % ; height : 100 % ;
position : relative ;
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
& : : after {
@ include clearfix ;
}
}
2018-06-22 10:48:00 +02:00
2018-06-25 23:43:09 +02:00
2018-06-22 23:13:30 +02:00
. api _ _toc {
width : 200 px ; height : calc ( 100 vh - 4 rem ) ; // navigation is 4rem tall
top : 4 rem ; left : 0 ; bottom : 0 ;
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
background - color : $white ;
border - right : 1 px solid rgba ( $gray , 0.3 ) ;
float : left ;
overflow - x : hidden ;
overflow - y : auto ;
position : fixed ;
z - index : 3 ;
2018-06-25 22:03:03 +02:00
}
. api _ _toc _ _search {
position : relative ;
}
. api _ _toc _ _search _ _field {
border - bottom : 1 px solid rgba ( $gray , 0.3 ) ;
font - size : 1 rem ;
line - height : 2 rem ;
padding : 0.25 rem calc ( 2 rem + 4 px ) 0.25 rem 0.5 rem ;
width : 100 % ;
}
. api _ _toc _ _search _ _clear {
width : 1.25 rem ; height : 1.25 rem ;
top : 0.6 rem ; right : 0.75 rem ;
background - color : $black ;
border - radius : 50 % ;
color : $white ;
cursor : pointer ;
font - size : 1 rem ;
line - height : 1.3 ;
position : absolute ;
text - align : center ;
transition : opacity 0.2 s ;
2018-06-22 23:13:30 +02:00
& : not ( . active ) {
2018-06-25 22:03:03 +02:00
opacity : 0 ;
visibility : hidden ;
2018-06-22 23:13:30 +02:00
}
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
& . active {
2018-06-25 22:03:03 +02:00
opacity : 1 ;
visibility : visible ;
2018-06-22 23:13:30 +02:00
}
}
2018-06-22 10:48:00 +02:00
2018-06-25 22:03:03 +02:00
. api _ _toc _ _search _ _results ,
. api _ _toc _ _items {
font - size : 0.8 rem ;
line - height : 1.33 ;
}
2018-06-22 23:13:30 +02:00
. api _ _toc _ _search _ _results {
2018-06-25 22:03:03 +02:00
list - style - type : none ;
2018-06-22 23:13:30 +02:00
& : not ( . active ) {
2018-06-25 22:03:03 +02:00
display : none ;
2018-06-22 23:13:30 +02:00
}
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
& . active {
2018-06-25 22:03:03 +02:00
background - color : rgba ( $gray , 0.3 ) ;
border - bottom : 1 px solid rgba ( $gray , 0.3 ) ;
padding - top : 0.25 rem ;
padding - bottom : 0.25 rem ;
}
2018-06-25 23:43:09 +02:00
a {
display : block ;
padding : 0.25 rem 0.5 rem 0.25 rem 0.75 rem ;
& : hover {
background - color : rgba ( $gray , 0.3 ) ;
}
}
2018-06-25 22:03:03 +02:00
}
. api _ _toc _ _items {
padding - top : 0.25 rem ;
padding - bottom : 0.25 rem ;
ul {
list - style - type : none ;
2018-06-25 23:43:09 +02:00
& : hover {
background - color : rgba ( $gray , 0.3 ) ;
}
li {
padding : 0.25 rem 0.5 rem 0.25 rem 0.75 rem ;
}
2018-06-22 23:13:30 +02:00
}
}
2018-06-22 10:48:00 +02:00
2018-06-25 22:03:03 +02:00
. tocify - focus {
background - color : rgba ( $gray , 0.3 ) ;
}
2018-06-22 10:48:00 +02:00
2018-06-22 23:13:30 +02:00
. api _ _content {
display : grid ;
float : right ;
grid - template - columns : repeat ( auto - fit , minmax ( 50 % , 1 fr ) ) ;
width : calc ( 100 % - 200 px ) ;
2018-06-25 19:52:05 +02:00
h1 {
font - size : 1.5 rem ;
margin - bottom : 0.5 rem ;
}
h2 {
font - size : 1.25 rem ;
margin - bottom : 0.5 rem ;
}
h3 {
font - size : 1.15 rem ;
margin - bottom : 0.25 rem ;
}
2018-06-25 23:43:09 +02:00
p , ol , ul {
2018-06-25 19:52:05 +02:00
font - size : 1 rem ;
line - height : 1.5 ;
margin - bottom : 1 rem ;
}
2018-06-25 23:43:09 +02:00
ol , ul {
padding - left : 1 rem ;
}
2018-06-25 19:52:05 +02:00
table {
border : 1 px solid rgba ( $white , 0.1 ) ;
border - radius : 0.3 rem ;
border - spacing : 0 ;
font - size : 0.8 rem ;
line - height : 1.33 ;
width : 100 % ;
}
thead {
display : none ;
}
th , td {
padding : 0.5 rem 1 rem 0.5 rem 0.5 rem ;
}
th {
border - bottom : 1 px solid rgba ( $white , 0.1 ) ;
}
tr : nth - child ( even ) {
background - color : rgba ( $white , 0.1 ) ;
}
2018-06-22 23:13:30 +02:00
}
. api _ _content _ _body ,
. api _ _content _ _example {
padding : 2 rem ;
}
. api _ _content _ _body {
border - bottom : 1 px solid rgba ( $gray , 0.3 ) ;
}
. api _ _content _ _example {
2018-06-25 19:52:05 +02:00
background - color : mix ( $gray , $black , 10 % ) ;
2018-06-22 23:13:30 +02:00
border - bottom : 1 px solid rgba ( $white , 0.1 ) ;
color : $white ;
2018-06-25 19:52:05 +02:00
pre {
margin - bottom : 1 rem ; padding : 1 rem ;
background - color : $black ;
border - radius : 0.3 rem ;
line - height : 1.33 ;
overflow - x : auto ;
overflow - y : hidden ;
}
2018-06-22 23:13:30 +02:00
}
< / style >