From 5e356c5f635d45f0241854d9f43f38b2f0bd44f9 Mon Sep 17 00:00:00 2001 From: olOwOlo <26087907+olOwOlo@users.noreply.github.com> Date: Tue, 10 Jul 2018 01:41:34 +0800 Subject: [PATCH] style(*): google js style & trim whitespace --- layouts/404.html | 6 +- layouts/_default/baseof.html | 2 +- layouts/_default/section.html | 8 +- layouts/_default/single.html | 2 +- layouts/_default/taxonomy.html | 26 +-- layouts/_default/terms.html | 32 +-- layouts/index.html | 14 +- layouts/partials/comments.html | 122 ++++++------ layouts/partials/footer.html | 12 +- layouts/partials/head.html | 22 +- layouts/partials/post/reward.html | 6 +- layouts/partials/post/toc.html | 4 +- layouts/partials/scripts.html | 78 ++++---- layouts/post/single.html | 34 ++-- layouts/post/summary.html | 10 +- src/js/even.js | 321 +++++++++++++++--------------- src/js/main.js | 20 +- 17 files changed, 362 insertions(+), 357 deletions(-) diff --git a/layouts/404.html b/layouts/404.html index fcf2b37..171fe09 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -1,6 +1,6 @@ -{{ define "title" }}404 page not found - {{ .Site.Title }}{{ end }} +{{- define "title" }}404 page not found - {{ .Site.Title }}{{ end -}} -{{ define "content" }} +{{- define "content" -}}

/* 404 page not found. */

@@ -15,4 +15,4 @@ var errorEmoji = emojiArray[Math.floor(Math.random() * emojiArray.length)]; errorEmojiContainer.appendChild(document.createTextNode(errorEmoji)); -{{ end }} +{{- end -}} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 0693148..c9cb88b 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,5 +1,5 @@ {{ if ne .Site.Params.version "3.x" -}} -{{ errorf "\n\nThere are two possible situations that led to this error:\n 1. You haven't copied the config.toml yet. See https://github.com/olOwOlo/hugo-theme-even#installation \n 2. You have an incompatible update. See https://github.com/olOwOlo/hugo-theme-even/blob/master/CHANGELOG.md#300 \n\n有两种可能的情况会导致这个错误发生:\n 1. 你还没有复制 config.toml 参考 https://github.com/olOwOlo/hugo-theme-even/blob/master/README-zh.md#installation \n 2. 你进行了一次不兼容的更新 参考 https://github.com/olOwOlo/hugo-theme-even/blob/master/CHANGELOG.md#300 \n" -}} + {{ errorf "\n\nThere are two possible situations that led to this error:\n 1. You haven't copied the config.toml yet. See https://github.com/olOwOlo/hugo-theme-even#installation \n 2. You have an incompatible update. See https://github.com/olOwOlo/hugo-theme-even/blob/master/CHANGELOG.md#300 \n\n有两种可能的情况会导致这个错误发生:\n 1. 你还没有复制 config.toml 参考 https://github.com/olOwOlo/hugo-theme-even/blob/master/README-zh.md#installation \n 2. 你进行了一次不兼容的更新 参考 https://github.com/olOwOlo/hugo-theme-even/blob/master/CHANGELOG.md#300 \n" -}} {{ end -}} diff --git a/layouts/_default/section.html b/layouts/_default/section.html index fbe80f1..2b159e4 100644 --- a/layouts/_default/section.html +++ b/layouts/_default/section.html @@ -1,6 +1,6 @@ -{{ define "title" }}{{ T "archive" }} - {{ .Site.Title }}{{ end }} +{{- define "title" }}{{ T "archive" }} - {{ .Site.Title }}{{ end -}} -{{ define "content"}} +{{- define "content" }} {{- $paginator := .Paginate .Data.Pages.ByDate.Reverse .Site.Params.archivePaginate }}
{{- if and (not $paginator.HasPrev) .Site.Params.showArchiveCount }} @@ -14,7 +14,7 @@ {{- range $index, $element := $paginator.Pages -}} {{- $thisYear := $element.Date.Format "2006" }} {{- $lastElement := $index | add -1 | index $paginator.Pages }} - {{ if or (eq $index 0) ( ne ($lastElement.Date.Format "2006") $thisYear ) }} + {{- if or (eq $index 0) ( ne ($lastElement.Date.Format "2006") $thisYear ) }}

{{ $thisYear }}

@@ -47,4 +47,4 @@ {{- end }} -{{ end }} +{{- end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index a1c30fd..96fe3bf 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,7 +1,7 @@ {{ define "content" -}}
- {{ .Content }} + {{ .Content }}
{{- end }} \ No newline at end of file diff --git a/layouts/_default/taxonomy.html b/layouts/_default/taxonomy.html index d0c8d43..2be015a 100644 --- a/layouts/_default/taxonomy.html +++ b/layouts/_default/taxonomy.html @@ -1,21 +1,21 @@ -{{ define "title" }}{{ .Title }} · {{ .Site.Title }}{{ end }} +{{- define "title" }}{{ .Title }} · {{ .Site.Title }}{{ end -}} -{{ define "content"}} -{{ $paginator := .Paginate .Data.Pages.ByDate.Reverse .Site.Params.archivePaginate }} +{{- define "content" }} +{{- $paginator := .Paginate .Data.Pages.ByDate.Reverse .Site.Params.archivePaginate -}}
- {{ if not $paginator.HasPrev }} - {{ if eq .Data.Plural "tags" }} + {{ if not $paginator.HasPrev -}} + {{ if eq .Data.Plural "tags" -}}

{{ .Title }}

- {{ else if eq .Data.Plural "categories" }} + {{- else if eq .Data.Plural "categories" -}}

{{ .Title }}

- {{ end }} - {{ end }} + {{- end }} + {{- end }} - {{ range $paginator.Pages }} + {{ range $paginator.Pages -}}
{{ .Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} @@ -26,21 +26,21 @@
- {{ end }} + {{- end }}
-{{ end }} +{{- end }} diff --git a/layouts/_default/terms.html b/layouts/_default/terms.html index 04b98f8..08498f6 100644 --- a/layouts/_default/terms.html +++ b/layouts/_default/terms.html @@ -1,44 +1,44 @@ -{{ define "title" }}{{ T .Data.Plural }} - {{ .Site.Title }}{{ end }} +{{- define "title" }}{{ T .Data.Plural }} - {{ .Site.Title }}{{ end -}} -{{ define "content" }} +{{- define "content" -}} {{ $name := .Data.Plural -}} {{ $terms := .Data.Terms.ByCount -}} {{ $length := len $terms -}} - {{ if eq $name "categories" }} + {{ if eq $name "categories" -}}
- {{ if eq $length 0 }} + {{ if eq $length 0 -}} {{ T "zeroCategoryCounter" }} - {{ else }} + {{- else -}} {{ T "categoryCounter" $length }} - {{ end }} + {{- end }}
- {{ range $key, $value := $terms }} + {{ range $key, $value := $terms -}} {{ $value.Term }} {{ len $value.Pages }} - {{ end }} + {{ end -}}
- {{ else if eq $name "tags" }} + {{- else if eq $name "tags" -}}
- {{ if eq $length 0 }} + {{ if eq $length 0 -}} {{ T "zeroTagCounter" }} - {{ else }} + {{- else -}} {{ T "tagCounter" $length }} - {{ end }} + {{- end }}
- {{ range $key, $value := $terms }} + {{- range $key, $value := $terms }} {{ $value.Term }} {{ len $value.Pages }} - {{ end }} + {{ end -}}
- {{ end }} -{{ end }} \ No newline at end of file + {{- end }} +{{- end }} \ No newline at end of file diff --git a/layouts/index.html b/layouts/index.html index 26d6869..9d013f2 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,24 +1,24 @@ -{{ define "content" }} +{{- define "content" -}}
{{/* (index .Site.Paginate) */}} - {{ $paginator := .Paginate (where (where .Data.Pages "Type" "post") ".Params.hiddenfromhomepage" "!=" true) }} - {{ range $paginator.Pages }} + {{- $paginator := .Paginate (where (where .Data.Pages "Type" "post") ".Params.hiddenfromhomepage" "!=" true) }} + {{- range $paginator.Pages -}} {{ .Render "summary" }} - {{ end }} + {{ end -}}
-{{ end }} \ No newline at end of file +{{- end -}} \ No newline at end of file diff --git a/layouts/partials/comments.html b/layouts/partials/comments.html index 440240a..cac3546 100644 --- a/layouts/partials/comments.html +++ b/layouts/partials/comments.html @@ -1,4 +1,4 @@ -{{ if and .IsPage (ne .Params.comment false) }} +{{ if and .IsPage (ne .Params.comment false) -}} {{- if .Site.DisqusShortname -}}
@@ -34,76 +34,76 @@ {{- if .Site.Params.livereUID -}} -
- - -
+ e.parentNode.insertBefore(j, e); + })(document, 'script'); + + +
{{- end -}} {{- if .Site.Params.gitment.owner -}} -
- {{ if .Site.Params.publicCDN.enable -}} - {{ .Site.Params.publicCDN.gitmentCSS | safeHTML }} - {{ .Site.Params.publicCDN.gitmentJS | safeHTML }} - {{- else -}} - - - {{- end }} - - - {{- end }} +
+ {{ if .Site.Params.publicCDN.enable -}} + {{ .Site.Params.publicCDN.gitmentCSS | safeHTML }} + {{ .Site.Params.publicCDN.gitmentJS | safeHTML }} + {{- else -}} + + + {{- end }} + + + {{- end -}} {{- if .Site.Params.gitalk.owner -}} -
- {{ if .Site.Params.publicCDN.enable -}} - {{ .Site.Params.publicCDN.gitalkCSS | safeHTML }} - {{ .Site.Params.publicCDN.gitalkJS | safeHTML }} - {{- else -}} - - - {{- end }} - - +
+ {{ if .Site.Params.publicCDN.enable -}} + {{ .Site.Params.publicCDN.gitalkCSS | safeHTML }} + {{ .Site.Params.publicCDN.gitalkJS | safeHTML }} + {{- else -}} + + + {{- end }} + + {{- end }} {{- end }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index b6a1fa5..5cb72f4 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -26,13 +26,13 @@ {{- end }} @@ -40,7 +40,7 @@ {{- $current := now.Format "2006" }} © - {{ if ne .Site.Params.since $current }} + {{ if ne .Site.Params.since $current -}} {{ .Site.Params.since }} - {{ end }} {{- $current }} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 9b5c840..b38f160 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -14,16 +14,16 @@ {{- if .Description -}} -{{ else if .IsPage }} +{{- else if .IsPage -}} -{{ else if .Site.Params.description }} +{{- else if .Site.Params.description -}} {{- end -}} {{- if .Keywords -}} {{ $length := len .Keywords | add -1 -}} -{{ else if .Site.Params.keywords }} +{{- else if .Site.Params.keywords -}} {{ $length := len .Site.Params.keywords | add -1 -}} {{- end }} @@ -37,10 +37,10 @@ -{{ if .RSSLink -}} +{{- if .RSSLink }} -{{ end -}} +{{- end -}} @@ -50,15 +50,15 @@ -{{- if .Site.Params.debug }} +{{- if .Site.Params.debug -}} -{{- end }} +{{- end -}} -{{ if .Site.Params.busuanzi.enable -}} +{{- if .Site.Params.busuanzi.enable -}} -{{- end }} +{{- end -}} @@ -66,10 +66,10 @@ {{ if .Site.Params.fancybox }}{{ .Site.Params.publicCDN.fancyboxCSS | safeHTML }}{{ end }} {{- else -}} {{ if .Site.Params.fancybox }}{{ end }} -{{- end }} +{{- end -}} -{{ range .Site.Params.customCSS }} +{{ range .Site.Params.customCSS -}} {{ end }} diff --git a/layouts/partials/post/reward.html b/layouts/partials/post/reward.html index 3242854..baceac7 100644 --- a/layouts/partials/post/reward.html +++ b/layouts/partials/post/reward.html @@ -1,16 +1,16 @@ -{{ if or .Params.reward (and .Site.Params.reward.enable (ne .Params.reward false)) }} +{{ if or .Params.reward (and .Site.Params.reward.enable (ne .Params.reward false)) -}}
{{ $qrCode := .Site.Params.reward }} - {{ with $qrCode.wechat }} + {{ with $qrCode.wechat -}} {{- end }} - {{ with $qrCode.alipay }} + {{ with $qrCode.alipay -}}
diff --git a/src/js/even.js b/src/js/even.js index 1711fa7..e8f8b33 100644 --- a/src/js/even.js +++ b/src/js/even.js @@ -1,264 +1,269 @@ -'use strict' +'use strict'; -const Even = {} +const Even = {}; -Even.backToTop = function () { - const $backToTop = $('#back-to-top') +Even.backToTop = function() { + const $backToTop = $('#back-to-top'); - $(window).scroll(function () { + $(window).scroll(function() { if ($(window).scrollTop() > 100) { - $backToTop.fadeIn(1000) + $backToTop.fadeIn(1000); } else { - $backToTop.fadeOut(1000) + $backToTop.fadeOut(1000); } - }) + }); - $backToTop.click(function () { - $('body,html').animate({ scrollTop: 0 }) - }) -} + $backToTop.click(function() { + $('body,html').animate({scrollTop: 0}); + }); +}; -Even.mobileNavbar = function () { - const $mobileNav = $('#mobile-navbar') - const $mobileNavIcon = $('.mobile-navbar-icon') +Even.mobileNavbar = function() { + const $mobileNav = $('#mobile-navbar'); + const $mobileNavIcon = $('.mobile-navbar-icon'); const slideout = new Slideout({ 'panel': document.getElementById('mobile-panel'), 'menu': document.getElementById('mobile-menu'), 'padding': 180, - 'tolerance': 70 - }) - slideout.disableTouch() + 'tolerance': 70, + }); + slideout.disableTouch(); - $mobileNavIcon.click(function () { - slideout.toggle() - }) + $mobileNavIcon.click(function() { + slideout.toggle(); + }); - slideout.on('beforeopen', function () { - $mobileNav.addClass('fixed-open') - $mobileNavIcon.addClass('icon-click').removeClass('icon-out') - }) + slideout.on('beforeopen', function() { + $mobileNav.addClass('fixed-open'); + $mobileNavIcon.addClass('icon-click').removeClass('icon-out'); + }); - slideout.on('beforeclose', function () { - $mobileNav.removeClass('fixed-open') - $mobileNavIcon.addClass('icon-out').removeClass('icon-click') - }) + slideout.on('beforeclose', function() { + $mobileNav.removeClass('fixed-open'); + $mobileNavIcon.addClass('icon-out').removeClass('icon-click'); + }); - $('#mobile-panel').on('touchend', function () { - slideout.isOpen() && $mobileNavIcon.click() - }) -} + $('#mobile-panel').on('touchend', function() { + slideout.isOpen() && $mobileNavIcon.click(); + }); +}; -Even._initToc = function () { - const SPACING = 20 - const $toc = $('.post-toc') - const $footer = $('.post-footer') +Even._initToc = function() { + const SPACING = 20; + const $toc = $('.post-toc'); + const $footer = $('.post-footer'); if ($toc.length) { - const minScrollTop = $toc.offset().top - SPACING - const maxScrollTop = $footer.offset().top - $toc.height() - SPACING + const minScrollTop = $toc.offset().top - SPACING; + const maxScrollTop = $footer.offset().top - $toc.height() - SPACING; const tocState = { start: { 'position': 'absolute', - 'top': minScrollTop + 'top': minScrollTop, }, process: { 'position': 'fixed', - 'top': SPACING + 'top': SPACING, }, end: { 'position': 'absolute', - 'top': maxScrollTop - } - } + 'top': maxScrollTop, + }, + }; - $(window).scroll(function () { - const scrollTop = $(window).scrollTop() + $(window).scroll(function() { + const scrollTop = $(window).scrollTop(); if (scrollTop < minScrollTop) { - $toc.css(tocState.start) + $toc.css(tocState.start); } else if (scrollTop > maxScrollTop) { - $toc.css(tocState.end) + $toc.css(tocState.end); } else { - $toc.css(tocState.process) + $toc.css(tocState.process); } - }) + }); } - const HEADERFIX = 30 - const $toclink = $('.toc-link') - const $headerlink = $('.headerlink') - const $tocLinkLis = $('.post-toc-content li') + const HEADERFIX = 30; + const $toclink = $('.toc-link'); + const $headerlink = $('.headerlink'); + const $tocLinkLis = $('.post-toc-content li'); - const headerlinkTop = $.map($headerlink, function (link) { - return $(link).offset().top - }) + const headerlinkTop = $.map($headerlink, function(link) { + return $(link).offset().top; + }); - const headerLinksOffsetForSearch = $.map(headerlinkTop, function (offset) { - return offset - HEADERFIX - }) + const headerLinksOffsetForSearch = $.map(headerlinkTop, function(offset) { + return offset - HEADERFIX; + }); - const searchActiveTocIndex = function (array, target) { + const searchActiveTocIndex = function(array, target) { for (let i = 0; i < array.length - 1; i++) { - if (target > array[i] && target <= array[i + 1]) return i + if (target > array[i] && target <= array[i + 1]) return i; } - if (target > array[array.length - 1]) return array.length - 1 - return -1 - } + if (target > array[array.length - 1]) return array.length - 1; + return -1; + }; - $(window).scroll(function () { - const scrollTop = $(window).scrollTop() - const activeTocIndex = searchActiveTocIndex(headerLinksOffsetForSearch, scrollTop) + $(window).scroll(function() { + const scrollTop = $(window).scrollTop(); + const activeTocIndex = searchActiveTocIndex(headerLinksOffsetForSearch, scrollTop); - $($toclink).removeClass('active') - $($tocLinkLis).removeClass('has-active') + $($toclink).removeClass('active'); + $($tocLinkLis).removeClass('has-active'); if (activeTocIndex !== -1) { - $($toclink[activeTocIndex]).addClass('active') - let ancestor = $toclink[activeTocIndex].parentNode + $($toclink[activeTocIndex]).addClass('active'); + let ancestor = $toclink[activeTocIndex].parentNode; while (ancestor.tagName !== 'NAV') { - $(ancestor).addClass('has-active') - ancestor = ancestor.parentNode.parentNode + $(ancestor).addClass('has-active'); + ancestor = ancestor.parentNode.parentNode; } } - }) -} + }); +}; -Even.fancybox = function () { +Even.fancybox = function() { if ($.fancybox) { - $('.post-content').each(function () { - $(this).find('img').each(function () { - $(this).wrap(``) - }) - }) + $('.post-content').each(function() { + $(this).find('img').each(function() { + $(this).wrap(``); + }); + }); $('.fancybox').fancybox({ selector: '.fancybox', - protect: true - }) + protect: true, + }); } -} +}; -Even.highlight = function () { - const blocks = document.querySelectorAll('pre code') +Even.highlight = function() { + const blocks = document.querySelectorAll('pre code'); for (let i = 0; i < blocks.length; i++) { - const block = blocks[i] - const rootElement = block.parentElement - const lineCodes = block.innerHTML.split(/\n/) - if (lineCodes[lineCodes.length - 1] === '') lineCodes.pop() - const lineLength = lineCodes.length + const block = blocks[i]; + const rootElement = block.parentElement; + const lineCodes = block.innerHTML.split(/\n/); + if (lineCodes[lineCodes.length - 1] === '') lineCodes.pop(); + const lineLength = lineCodes.length; - let codeLineHtml = '' + let codeLineHtml = ''; for (let i = 0; i < lineLength; i++) { - codeLineHtml += `
${i + 1}
` + codeLineHtml += `
${i + 1}
`; } - let codeHtml = '' + let codeHtml = ''; for (let i = 0; i < lineLength; i++) { - codeHtml += `
${lineCodes[i]}
` + codeHtml += `
${lineCodes[i]}
`; } - block.className += ' highlight' - const figure = document.createElement('figure') - figure.className = block.className - figure.innerHTML = `
${codeLineHtml}
${codeHtml}
` + block.className += ' highlight'; + const figure = document.createElement('figure'); + figure.className = block.className; + figure.innerHTML = `
${codeLineHtml}
${codeHtml}
`; - rootElement.parentElement.replaceChild(figure, rootElement) + rootElement.parentElement.replaceChild(figure, rootElement); } -} +}; Even.chroma = function() { - const blocks = document.querySelectorAll('.highlight > .chroma') + const blocks = document.querySelectorAll('.highlight > .chroma'); for (let i = 0; i < blocks.length; i++) { - const block = blocks[i] - const afterHighLight = block.querySelector('pre.chroma > code') - const lang = afterHighLight ? afterHighLight.className : '' - block.className += ' ' + lang + const block = blocks[i]; + const afterHighLight = block.querySelector('pre.chroma > code'); + const lang = afterHighLight ? afterHighLight.className : ''; + block.className += ' ' + lang; } -} +}; -Even.toc = function () { - const tocContainer = document.getElementById('post-toc') +Even.toc = function() { + const tocContainer = document.getElementById('post-toc'); if (tocContainer !== null) { - const toc = document.getElementById('TableOfContents') + const toc = document.getElementById('TableOfContents'); if (toc === null) { // toc = true, but there are no headings - tocContainer.parentNode.removeChild(tocContainer) + tocContainer.parentNode.removeChild(tocContainer); } else { - this._refactorToc(toc) - this._linkToc() - this._initToc() + this._refactorToc(toc); + this._linkToc(); + this._initToc(); } } -} +}; -Even._refactorToc = function (toc) { +Even._refactorToc = function(toc) { // when headings do not start with `h1` - const oldTocList = toc.children[0] - let newTocList = oldTocList - let temp - while (newTocList.children.length === 1 && (temp = newTocList.children[0].children[0]).tagName === 'UL') newTocList = temp + const oldTocList = toc.children[0]; + let newTocList = oldTocList; + let temp; + while (newTocList.children.length === 1 + && (temp = newTocList.children[0].children[0]).tagName === 'UL') { + newTocList = temp; + } - if (newTocList !== oldTocList) toc.replaceChild(newTocList, oldTocList) -} + if (newTocList !== oldTocList) toc.replaceChild(newTocList, oldTocList); +}; -Even._linkToc = function () { - const links = document.querySelectorAll('#TableOfContents a:first-child') - for (let i = 0; i < links.length; i++) links[i].className += ' toc-link' +Even._linkToc = function() { + const links = document.querySelectorAll('#TableOfContents a:first-child'); + for (let i = 0; i < links.length; i++) links[i].className += ' toc-link'; for (let num = 1; num <= 6; num++) { - const headers = document.querySelectorAll('.post-content>h' + num) + const headers = document.querySelectorAll('.post-content>h' + num); for (let i = 0; i < headers.length; i++) { - const header = headers[i] - header.innerHTML = `${header.innerHTML}` + const header = headers[i]; + header.innerHTML = `${header.innerHTML}`; } } -} +}; -Even.flowchart = function () { - if (!window.flowchart) return +Even.flowchart = function() { + if (!window.flowchart) return; - const blocks = document.querySelectorAll('pre code.language-flowchart') + const blocks = document.querySelectorAll('pre code.language-flowchart'); for (let i = 0; i < blocks.length; i++) { - if (!window.hljs && i % 2 === 0) continue + if (!window.hljs && i % 2 === 0) continue; - const block = blocks[i] + const block = blocks[i]; const rootElement = window.hljs ? block.parentElement - : block.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement + : block.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement; - const container = document.createElement('div') - const id = `js-flowchart-diagrams-${i}` - container.id = id - container.className = 'align-center' - rootElement.parentElement.replaceChild(container, rootElement) + const container = document.createElement('div'); + const id = `js-flowchart-diagrams-${i}`; + container.id = id; + container.className = 'align-center'; + rootElement.parentElement.replaceChild(container, rootElement); - const diagram = flowchart.parse(block.childNodes[0].nodeValue) - diagram.drawSVG(id, window.flowchartDiagramsOptions ? window.flowchartDiagramsOptions : {}) + const diagram = flowchart.parse(block.childNodes[0].nodeValue); + diagram.drawSVG(id, window.flowchartDiagramsOptions ? window.flowchartDiagramsOptions : {}); } -} +}; -Even.sequence = function () { - if (!window.Diagram) return +Even.sequence = function() { + if (!window.Diagram) return; - const blocks = document.querySelectorAll('pre code.language-sequence') + const blocks = document.querySelectorAll('pre code.language-sequence'); for (let i = 0; i < blocks.length; i++) { - if (!window.hljs && i % 2 === 0) continue + if (!window.hljs && i % 2 === 0) continue; - const block = blocks[i] + const block = blocks[i]; const rootElement = window.hljs ? block.parentElement - : block.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement + : block.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement; - const container = document.createElement('div') - const id = `js-sequence-diagrams-${i}` - container.id = id - container.className = 'align-center' - rootElement.parentElement.replaceChild(container, rootElement) + const container = document.createElement('div'); + const id = `js-sequence-diagrams-${i}`; + container.id = id; + container.className = 'align-center'; + rootElement.parentElement.replaceChild(container, rootElement); - const diagram = Diagram.parse(block.childNodes[0].nodeValue) - diagram.drawSVG(id, window.sequenceDiagramsOptions ? window.sequenceDiagramsOptions : {theme: 'simple'}) + const diagram = Diagram.parse(block.childNodes[0].nodeValue); + diagram.drawSVG(id, window.sequenceDiagramsOptions + ? window.sequenceDiagramsOptions + : {theme: 'simple'}); } -} +}; export {Even} diff --git a/src/js/main.js b/src/js/main.js index 64c44ca..1dd8566 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -3,19 +3,19 @@ import {Even} from './even.js' import '../css/style.scss' $(document).ready(function () { - Even.backToTop() - Even.mobileNavbar() - Even.toc() - Even.fancybox() -}) + Even.backToTop(); + Even.mobileNavbar(); + Even.toc(); + Even.fancybox(); +}); -Even.flowchart() -Even.sequence() +Even.flowchart(); +Even.sequence(); if (window.hljs) { - hljs.initHighlighting() - Even.highlight() + hljs.initHighlighting(); + Even.highlight(); } else { - Even.chroma() + Even.chroma(); }