tabs shortcode added

This commit is contained in:
zzossig 2020-01-24 02:46:03 +09:00
parent 541bbd576d
commit d314aa4f85
19 changed files with 264 additions and 67 deletions

View File

@ -1056,7 +1056,7 @@ Some markdown contents
{{< /boxmd >}} {{< /boxmd >}}
``` ```
### code / codes => Tabbed code-block. indentation matters. ### code / codes => 코드를 여러 버전으로 제공할 때 쓰세요. 들여쓰기 잘못하면 이상하게 나와요.
````` `````
{{< codes java javascript >}} {{< codes java javascript >}}
@ -1072,3 +1072,31 @@ Some markdown contents
{{< /code >}} {{< /code >}}
{{< /codes >}} {{< /codes >}}
````` `````
### tab / tabs => 여러 버전의 뷰를 제공할 때 쓰세요
`````
{{< tabs Windows MacOS Ubuntu >}}
{{< tab >}}
### Windows section
```javascript
console.log('Hello World!');
```
{{< /tab >}}
{{< tab >}}
### MacOS section
Hello world!
{{< /tab >}}
{{< tab >}}
### Ubuntu section
Great!
{{< /tab >}}
{{< /tabs >}}
`````

View File

@ -1065,3 +1065,31 @@ Some markdown contents
{{< /code >}} {{< /code >}}
{{< /codes >}} {{< /codes >}}
````` `````
### tab / tabs => Tabs make it easy to explore and switch between different views
`````
{{< tabs Windows MacOS Ubuntu >}}
{{< tab >}}
### Windows section
```javascript
console.log('Hello World!');
```
{{< /tab >}}
{{< tab >}}
### MacOS section
Hello world!
{{< /tab >}}
{{< tab >}}
### Ubuntu section
Great!
{{< /tab >}}
{{< /tabs >}}
`````

View File

@ -0,0 +1,59 @@
.codetab {
position: relative;
&__links {
position: absolute;
top: 0;
left: 0;
height: 30px;
z-index: z('clipboard');
border-top-left-radius: 0.25rem;
@include flexbox();
@include align-items(center);
@include justify-content(flex-start);
@include themify($codeblock) {
background-color: themed('content-pre-header-background-color');
}
}
&__link {
height: 30px;
border: none;
outline: none;
cursor: pointer;
font-size: 13.8px;
font-family: $title-font;
text-transform: capitalize;
padding: 0.25rem 0.5rem;
&:first-child {
border-top-left-radius: 0.25rem;
}
@include transition(all, 0.2s, ease-in);
@include themify($themes) {
color: themed('navbar-title-color');
border-top: 1px solid transparent;
&.active {
border-top: 1px solid themed('content-pre-header-background-color');
}
}
@include themify($codeblock) {
background-color: themed('content-pre-header-background-color');
&.active {
background-color: themed('content-pre-background-color');
}
@include on-event {
background-color: themed('content-pre-background-color');
}
}
}
&__content {
display: none;
}
}

View File

@ -16,6 +16,7 @@
&__message { &__message {
padding: 0.5rem; padding: 0.5rem;
font-size: 18px; font-size: 18px;
line-height: 18px;
font-weight: bold; font-weight: bold;
font-family: $title-font; font-family: $title-font;
@ -26,8 +27,7 @@
&__item { &__item {
font-family: $title-font; font-family: $title-font;
font-size: 0.8rem; font-size: 0.8rem;
padding: 0.125rem; padding: 0.1rem 0.325rem 0.1rem 0.25rem;
padding-right: 0.25rem;
cursor: pointer; cursor: pointer;
border-radius: 0.25rem; border-radius: 0.25rem;
margin: 0.25rem; margin: 0.25rem;
@ -46,6 +46,10 @@
@include transition(color, 0.2s, ease); @include transition(color, 0.2s, ease);
} }
} }
svg {
margin-right: 0.25rem;
}
} }
&__dropup { &__dropup {

View File

@ -1,59 +1,58 @@
.tab { .tab {
position: relative; position: relative;
padding: 0.5rem 0;
margin: 2rem 0;
&__links { &__links {
position: absolute;
top: 0;
left: 0;
height: 30px; height: 30px;
z-index: z('clipboard');
border-top-left-radius: 0.25rem; border-top-left-radius: 0.25rem;
@include flexbox(); @include flexbox();
@include align-items(center); @include align-items(center);
@include justify-content(flex-start); @include justify-content(flex-start);
@include themify($codeblock) { @include themify($themes) {
background-color: themed('content-pre-header-background-color');
} }
} }
&__link { &__link {
height: 30px; height: 30px;
border: none;
outline: none; outline: none;
border: none;
cursor: pointer; cursor: pointer;
font-size: 13.8px; font-size: 13.8px;
font-family: $title-font; font-family: $title-font;
text-transform: capitalize; text-transform: capitalize;
padding: 0.25rem 0.5rem; padding: 0.25rem 0.5rem;
&:first-child {
border-top-left-radius: 0.25rem; border-top-left-radius: 0.25rem;
} border-top-right-radius: 0.25rem;
@include transition(all, 0.2s, ease-in);
@include themify($themes) { @include themify($themes) {
color: themed('navbar-title-color'); color: themed('navbar-title-color');
border-top: 1px solid transparent; background-color: themed('body-background-color');
&.active {
border-top: 1px solid themed('content-pre-header-background-color');
}
}
@include themify($codeblock) {
background-color: themed('content-pre-header-background-color');
&.active { &.active {
background-color: themed('content-pre-background-color'); height: 32px;
background-color: themed('body-background-color');
border: 1px solid themed('hr-color');
border-bottom: none;
} }
@include on-event { @include on-event {
background-color: themed('content-pre-background-color'); color: themed('navbar-title-hover-color');
background-color: themed('content-pre-header-background-color');
} }
} }
} }
&__content { &__content {
display: none; display: none;
padding: 0 0.5rem;
border-radius: 0.25rem;
border-top-left-radius: 0;
@include themify($themes) {
border: 1px solid themed('hr-color');
background-color: themed('body-background-color');
}
} }
} }

View File

@ -71,9 +71,11 @@ $grid_column_gap: $grid_column_gap_width + $grid_column_gap_unit;
grid-column-gap: 16px; grid-column-gap: 16px;
grid-row-gap: 0px; grid-row-gap: 0px;
@if $sidebar_position == "left" { &[data-sidebar-position="left"] {
grid-template-columns: 266px 1fr 1fr; grid-template-columns: 266px 1fr 1fr;
} @else { }
&[data-sidebar-position="right"] {
grid-template-columns: 1fr 1fr 266px; grid-template-columns: 1fr 1fr 266px;
} }
} }

View File

@ -9,8 +9,6 @@ $grid_column_gap_unit: {{ .Site.Data.grid.grid_column_gap_unit }};
$grid_navbar_height: {{ .Site.Data.grid.grid_navbar_height }}; $grid_navbar_height: {{ .Site.Data.grid.grid_navbar_height }};
$grid_row_gap: {{ .Site.Data.grid.grid_row_gap }}; $grid_row_gap: {{ .Site.Data.grid.grid_row_gap }};
$sidebar_position: {{ .Site.Params.sidebarPosition }};
$theme_light_chroma: {{ .Site.Data.skin.theme_light_chroma }}; $theme_light_chroma: {{ .Site.Data.skin.theme_light_chroma }};
$theme_dark_chroma: {{ .Site.Data.skin.theme_dark_chroma }}; $theme_dark_chroma: {{ .Site.Data.skin.theme_dark_chroma }};
$theme_hacker_chroma: {{ .Site.Data.skin.theme_hacker_chroma }}; $theme_hacker_chroma: {{ .Site.Data.skin.theme_hacker_chroma }};
@ -70,8 +68,9 @@ $cursive-font: {{ .Site.Data.font.cursive_font }};
@import 'components/donation'; @import 'components/donation';
@import 'components/box'; @import 'components/box';
@import 'components/modal'; @import 'components/modal';
@import 'components/tab'; @import 'components/codetab';
@import 'components/ie'; @import 'components/ie';
@import 'components/tab';
@import 'pages/404'; @import 'pages/404';
@import 'pages/about'; @import 'pages/about';

View File

@ -6,7 +6,7 @@ $hacker: (
title-color: #A1AD64, title-color: #A1AD64,
meta-color: #CDF5CC, meta-color: #CDF5CC,
body-color: #1FFF2A, body-color: #1FFF2A,
hr-color: #C7BA00, hr-color: #6B6B6B,
body-background-color: #151715, body-background-color: #151715,
backdrop-background-color: #111, backdrop-background-color: #111,
dropdown-border-top-color: #6B6B6B, dropdown-border-top-color: #6B6B6B,

View File

@ -3,7 +3,7 @@
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }} {{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
<script src="{{ $enquire.RelPermalink }}"></script> <script src="{{ $enquire.RelPermalink }}"></script>
<main class="main inner"> <main class="main inner" data-sidebar-position="{{ $.Param "sidebarPosition" }}">
<div class="list__main {{ if $.Param "enableSidebar" }}{{ if eq .Site.Params.sidebarPosition "left" }}mr{{ else }}lm{{ end }}{{ else }}lmr{{ end }}"> <div class="list__main {{ if $.Param "enableSidebar" }}{{ if eq .Site.Params.sidebarPosition "left" }}mr{{ else }}lm{{ end }}{{ else }}lmr{{ end }}">
{{ partial "body/breadcrumb" . }} {{ partial "body/breadcrumb" . }}
<header class="list__header"> <header class="list__header">

View File

@ -3,7 +3,7 @@
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }} {{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
<script src="{{ $enquire.RelPermalink }}"></script> <script src="{{ $enquire.RelPermalink }}"></script>
<main class="main inner"> <main class="main inner" data-sidebar-position="{{ $.Param "sidebarPosition" }}">
<div class="list__main {{ if $.Param "enableSidebar" }}{{ if eq .Site.Params.sidebarPosition "left" }}mr{{ else }}lm{{ end }}{{ else }}lmr{{ end }}"> <div class="list__main {{ if $.Param "enableSidebar" }}{{ if eq .Site.Params.sidebarPosition "left" }}mr{{ else }}lm{{ end }}{{ else }}lmr{{ end }}">
{{ partial "body/breadcrumb" . }} {{ partial "body/breadcrumb" . }}
<header class="list__header"> <header class="list__header">

View File

@ -5,7 +5,7 @@
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }} {{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
<script src="{{ $enquire.RelPermalink }}"></script> <script src="{{ $enquire.RelPermalink }}"></script>
<main class="main inner"> <main class="main inner" data-sidebar-position="{{ $.Param "sidebarPosition" }}">
<div class="list__main {{ if $.Param "enableSidebar" }}{{ if eq .Site.Params.sidebarPosition "left" }}mr{{ else }}lm{{ end }}{{ else }}lmr{{ end }}"> <div class="list__main {{ if $.Param "enableSidebar" }}{{ if eq .Site.Params.sidebarPosition "left" }}mr{{ else }}lm{{ end }}{{ else }}lmr{{ end }}">
<div class="summary__container"> <div class="summary__container">
{{ $filteredPages := .Site.RegularPages }} {{ $filteredPages := .Site.RegularPages }}

View File

@ -10,42 +10,42 @@
{{ range $.Param "share.options" }} {{ range $.Param "share.options" }}
{{ if eq (lower .) "facebook" }} {{ if eq (lower .) "facebook" }}
<a href="https://www.facebook.com/sharer/sharer.php?u={{ $ctx.Permalink | absLangURL }}" title="{{ . }}" aria-label="{{ . }}" class="donation__item" target="_blank" rel="noreferrer"> <a href="https://www.facebook.com/sharer/sharer.php?u={{ $ctx.Permalink | absLangURL }}" title="{{ . }}" aria-label="{{ . }}" class="donation__item" target="_blank" rel="noreferrer">
{{ partial "svgs/share/facebook.svg" (dict "width" 22 "height" 22) }} {{ partial "svgs/share/facebook.svg" (dict "width" 23 "height" 23) }}
{{ i18n "facebook" | default "Facebook" }} {{ i18n "facebook" | default "Facebook" }}
</a> </a>
{{ else if eq (lower .) "twitter" }} {{ else if eq (lower .) "twitter" }}
<a href="https://twitter.com/intent/tweet?text={{ $ctx.Title }}" title="{{ . }}" aria-label="{{ . }}" class="donation__item" target="_blank" rel="noreferrer"> <a href="https://twitter.com/intent/tweet?text={{ $ctx.Title }}&url={{ $ctx.Permalink | absLangURL }}{{ with $ctx.Params.tags }}&hashtags={{ delimit . "," }}{{ end }}{{ with $ctx.Params.author }}&via={{ . }}{{ end }}" title="{{ . }}" aria-label="{{ . }}" class="donation__item" target="_blank" rel="noreferrer">
{{ partial "svgs/share/twitter.svg" (dict "width" 22 "height" 22) }} {{ partial "svgs/share/twitter.svg" (dict "width" 23 "height" 23) }}
{{ i18n "twitter" | default "Twitter" }} {{ i18n "twitter" | default "Twitter" }}
</a> </a>
{{ else if eq (lower .) "reddit" }} {{ else if eq (lower .) "reddit" }}
<a href="https://www.reddit.com/submit?url={{ $ctx.Permalink | absLangURL }}&amp;title={{ $ctx.Title }}" target="_blank" rel="noreferer" title="{{ . }}" onclick="window.open('http://www.reddit.com/submit?url=' + encodeURIComponent(document.URL) + '&amp;title=' + encodeURIComponent(document.title)); return false;" class="donation__item"> <a href="https://www.reddit.com/submit?url={{ $ctx.Permalink | absLangURL }}&amp;title={{ $ctx.Title }}" target="_blank" rel="noreferer" title="{{ . }}" onclick="window.open('http://www.reddit.com/submit?url=' + encodeURIComponent(document.URL) + '&amp;title=' + encodeURIComponent(document.title)); return false;" class="donation__item">
{{ partial "svgs/share/reddit.svg" (dict "width" 22 "height" 22) }} {{ partial "svgs/share/reddit.svg" (dict "width" 23 "height" 23) }}
{{ i18n "reddit" | default "Reddit" }} {{ i18n "reddit" | default "Reddit" }}
</a> </a>
{{ else if eq (lower .) "linkedin" }} {{ else if eq (lower .) "linkedin" }}
<a href="https://www.linkedin.com/shareArticle?mini=true&url={{ $ctx.Permalink | absLangURL }}&title={{ $ctx.Title }} &summary={{ $ctx.Description }}&source={{ $site.Params.Description }}" target="_blank" rel="noreferer" title="{{ . }}" class="donation__item"> <a href="https://www.linkedin.com/shareArticle?mini=true&url={{ $ctx.Permalink | absLangURL }}&title={{ $ctx.Title }} &summary={{ $ctx.Description }}&source={{ $site.Params.Description }}" target="_blank" rel="noreferer" title="{{ . }}" class="donation__item">
{{ partial "svgs/share/linkedin.svg" (dict "width" 22 "height" 22) }} {{ partial "svgs/share/linkedin.svg" (dict "width" 23 "height" 23) }}
{{ i18n "linkedin" | default "LinkedIn" }} {{ i18n "linkedin" | default "LinkedIn" }}
</a> </a>
{{ else if eq (lower .) "tumblr" }} {{ else if eq (lower .) "tumblr" }}
<a href="http://tumblr.com/widgets/share/tool?canonicalUrl={{ $ctx.Permalink | absLangURL }}&data-title={{ $ctx.Title }}&data-content={{ $ctx.Description }}" class="donation__item" target="_blank" rel="noreferer"> <a href="http://tumblr.com/widgets/share/tool?canonicalUrl={{ $ctx.Permalink | absLangURL }}&data-title={{ $ctx.Title }}&data-content={{ $ctx.Description }}" class="donation__item" target="_blank" rel="noreferer">
{{ partial "svgs/share/tumblr.svg" (dict "width" 22 "height" 22) }} {{ partial "svgs/share/tumblr.svg" (dict "width" 23 "height" 23) }}
{{ i18n "tumblr" | default "Tumblr" }} {{ i18n "tumblr" | default "Tumblr" }}
</a> </a>
{{ else if eq (lower .) "weibo" }} {{ else if eq (lower .) "weibo" }}
<a href="javascript:void(function(){var d=document,e=encodeURIComponent,s1=window.getSelection,s2=d.getSelection,s3=d.selection,s=s1?s1():s2?s2():s3?s3.createRange().text:'',r='http://service.weibo.com/share/share.php?url='+e(d.location.href)+'&title='+e(d.title),x=function(){if(!window.open(r,'weibo','toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330'))location.href=r+'&r=1'};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})()" class="donation__item" target="_blank" rel="noreferer"> <a href="javascript:void(function(){var d=document,e=encodeURIComponent,s1=window.getSelection,s2=d.getSelection,s3=d.selection,s=s1?s1():s2?s2():s3?s3.createRange().text:'',r='http://service.weibo.com/share/share.php?url='+e(d.location.href)+'&title='+e(d.title),x=function(){if(!window.open(r,'weibo','toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330'))location.href=r+'&r=1'};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})()" class="donation__item" target="_blank" rel="noreferer">
{{ partial "svgs/share/weibo.svg" (dict "width" 22 "height" 22) }} {{ partial "svgs/share/weibo.svg" (dict "width" 23 "height" 23) }}
{{ i18n "weibo" | default "Weibo" }} {{ i18n "weibo" | default "Weibo" }}
</a> </a>
{{ else if eq (lower .) "douban" }} {{ else if eq (lower .) "douban" }}
<a href="javascript:void(function(){var d=document,e=encodeURIComponent,s1=window.getSelection,s2=d.getSelection,s3=d.selection,s=s1?s1():s2?s2():s3?s3.createRange().text:'',r='https://www.douban.com/recommend/?url='+e(d.location.href)+'&title='+e(d.title)+'&sel='+e(s)+'&v=1',w=450,h=330,x=function(){if(!window.open(r,'douban','toolbar=0,resizable=1,scrollbars=yes,status=1,width='+w+',height='+h+',left='+(screen.width-w)/2+',top='+(screen.height-h)/2))location.href=r+'&r=1'};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})()" class="donation__item" target="_blank" rel="noreferer"> <a href="javascript:void(function(){var d=document,e=encodeURIComponent,s1=window.getSelection,s2=d.getSelection,s3=d.selection,s=s1?s1():s2?s2():s3?s3.createRange().text:'',r='https://www.douban.com/recommend/?url='+e(d.location.href)+'&title='+e(d.title)+'&sel='+e(s)+'&v=1',w=450,h=330,x=function(){if(!window.open(r,'douban','toolbar=0,resizable=1,scrollbars=yes,status=1,width='+w+',height='+h+',left='+(screen.width-w)/2+',top='+(screen.height-h)/2))location.href=r+'&r=1'};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})()" class="donation__item" target="_blank" rel="noreferer">
{{ partial "svgs/share/douban.svg" (dict "width" 22 "height" 22) }} {{ partial "svgs/share/douban.svg" (dict "width" 23 "height" 23) }}
{{ i18n "douban" | default "Douban" }} {{ i18n "douban" | default "Douban" }}
</a> </a>
{{ else if eq (lower .) "line" }} {{ else if eq (lower .) "line" }}
<a href="https://social-plugins.line.me/lineit/share?url={{ $ctx.Permalink | absLangURL }}" class="donation__item" target="_blank" rel="noreferer"> <a href="https://social-plugins.line.me/lineit/share?url={{ $ctx.Permalink | absLangURL }}" class="donation__item" target="_blank" rel="noreferer">
{{ partial "svgs/share/line.svg" (dict "width" 22 "height" 22) }} {{ partial "svgs/share/line.svg" (dict "width" 23 "height" 23) }}
{{ i18n "line" | default "Line" }} {{ i18n "line" | default "Line" }}
</a> </a>
{{ end }} {{ end }}

View File

@ -105,6 +105,35 @@
// ============================================================= // =============================================================
// ========================== codetab ==========================
document.querySelectorAll('.codetab') ?
document.querySelectorAll('.codetab').forEach(function(elem, idx) {
var containerId = elem.getAttribute('id');
var containerElem = elem;
var codetabLinks = elem.querySelectorAll('.codetab__link');
var codetabContents = elem.querySelectorAll('.codetab__content');
var ids = [];
codetabLinks && codetabLinks.length > 0 ?
codetabLinks.forEach(function(link, index, self) {
link.onclick = function(e) {
for (var i = 0; i < self.length; i++) {
if (index === parseInt(i, 10)) {
if (!self[i].classList.contains('active')) {
self[i].classList.add('active');
codetabContents[i].style.display = 'block';
}
} else {
self[i].classList.remove('active');
codetabContents[i].style.display = 'none';
}
}
}
}) : null;
}) : null;
// =============================================================
// ========================= go to top ========================= // ========================= go to top =========================
var gttBtn = document.getElementById("gtt"); var gttBtn = document.getElementById("gtt");
gttBtn.style.display = "none"; gttBtn.style.display = "none";
@ -281,8 +310,6 @@
// ========================== navbar ========================== // ========================== navbar ==========================
var navbarBurgerElem = document.querySelector('.navbar__burger'); var navbarBurgerElem = document.querySelector('.navbar__burger');
var navbarMenuElem = document.querySelector('.navbar__menu'); var navbarMenuElem = document.querySelector('.navbar__menu');
console.log(navbarBurgerElem);
console.log(navbarMenuElem);
navbarBurgerElem ? navbarBurgerElem ?
navbarBurgerElem.addEventListener('click', function () { navbarBurgerElem.addEventListener('click', function () {
if (navbarBurgerElem.classList.contains('is-active')) { if (navbarBurgerElem.classList.contains('is-active')) {

View File

@ -1,4 +1,4 @@
{{ $id := substr (md5 .Inner) 0 16 }} {{ $id := substr (md5 .Inner) 0 16 }}
<div id="{{ $id }}" class="tab__content"> <div id="{{ $id }}" class="codetab__content">
{{ .Inner | markdownify }} {{ .Inner | markdownify }}
</div> </div>

View File

@ -1,8 +1,8 @@
{{ $id := substr (md5 .Inner) 0 16 }} {{ $id := substr (md5 .Inner) 0 16 }}
<div id="{{ $id }}" class="tab"> <div id="{{ $id }}" class="codetab">
<div class="tab__links"> <div class="codetab__links">
{{ range .Params }} {{ range .Params }}
<button class="tab__link" aria-label="Tab link">{{ . }}</button> <button class="codetab__link" aria-label="Tab link">{{ . }}</button>
{{ end }} {{ end }}
</div> </div>
{{ .Inner }} {{ .Inner }}
@ -13,35 +13,35 @@
var containerId = JSON.parse({{ $id | jsonify }}); var containerId = JSON.parse({{ $id | jsonify }});
var containerElem = document.getElementById(containerId); var containerElem = document.getElementById(containerId);
var tabLinks = null; var codetabLinks = null;
var tabContents = null; var codetabContents = null;
var ids = []; var ids = [];
if (containerElem) { if (containerElem) {
tabLinks = containerElem.querySelectorAll('.tab__link'); codetabLinks = containerElem.querySelectorAll('.codetab__link');
tabContents = containerElem.querySelectorAll('.tab__content'); codetabContents = containerElem.querySelectorAll('.codetab__content');
} }
for (var i = 0; i < tabContents.length; i++) { for (var i = 0; i < codetabContents.length; i++) {
ids = ids.concat(tabContents[i].getAttribute('id')); ids = ids.concat(codetabContents[i].getAttribute('id'));
tabContents[i].style.display = 'none'; codetabContents[i].style.display = 'none';
if (0 === parseInt(i, 10) && !tabContents[i].classList.contains('active')) { if (0 === parseInt(i, 10) && !codetabContents[i].classList.contains('active')) {
tabContents[i].classList.add('active'); codetabContents[i].classList.add('active');
} }
} }
for (var i = 0; i < tabLinks.length; i++) { for (var i = 0; i < codetabLinks.length; i++) {
tabLinks[i].setAttribute('id', ids[i]); codetabLinks[i].setAttribute('id', ids[i]);
if (0 === parseInt(i, 10) && !tabLinks[i].classList.contains('active')) { if (0 === parseInt(i, 10) && !codetabLinks[i].classList.contains('active')) {
tabLinks[i].classList.add('active'); codetabLinks[i].classList.add('active');
} else { } else {
tabLinks[i].classList.remove('active'); codetabLinks[i].classList.remove('active');
} }
} }
if (tabContents.length > 0) { if (codetabContents.length > 0) {
tabContents[0].style.display = 'block'; codetabContents[0].style.display = 'block';
} }
</script> </script>

View File

@ -0,0 +1,4 @@
{{ $id := substr (md5 .Inner) 0 16 }}
<div id="{{ $id }}" class="tab__content">
{{ .Inner | markdownify }}
</div>

View File

@ -0,0 +1,47 @@
{{ $id := substr (md5 .Inner) 0 16 }}
<div id="{{ $id }}" class="tab">
<div class="tab__links">
{{ range .Params }}
<button class="tab__link" aria-label="Tab link">{{ . }}</button>
{{ end }}
</div>
{{ .Inner }}
</div>
<script>
'use strict';
var containerId = JSON.parse({{ $id | jsonify }});
var containerElem = document.getElementById(containerId);
var tabLinks = null;
var tabContents = null;
var ids = [];
if (containerElem) {
tabLinks = containerElem.querySelectorAll('.tab__link');
tabContents = containerElem.querySelectorAll('.tab__content');
}
for (var i = 0; i < tabContents.length; i++) {
ids = ids.concat(tabContents[i].getAttribute('id'));
tabContents[i].style.display = 'none';
if (0 === parseInt(i, 10) && !tabContents[i].classList.contains('active')) {
tabContents[i].classList.add('active');
}
}
for (var i = 0; i < tabLinks.length; i++) {
tabLinks[i].setAttribute('id', ids[i]);
if (0 === parseInt(i, 10) && !tabLinks[i].classList.contains('active')) {
tabLinks[i].classList.add('active');
} else {
tabLinks[i].classList.remove('active');
}
}
if (tabContents.length > 0) {
tabContents[0].style.display = 'block';
}
</script>

View File

@ -1,5 +1,5 @@
{{ define "main" }} {{ define "main" }}
<main class="main showcase inner"> <main class="main showcase inner" data-sidebar-position="{{ $.Param "sidebarPosition" }}">
{{ if .Params.enableBio }} {{ if .Params.enableBio }}
<aside class="{{ if eq .Site.Params.sidebarPosition "left" }}l{{ else }}r{{ end }}"> <aside class="{{ if eq .Site.Params.sidebarPosition "left" }}l{{ else }}r{{ end }}">
<div class="showcase__bio"> <div class="showcase__bio">