This commit is contained in:
zzossig 2019-11-05 18:22:06 +09:00
parent bb23d03b35
commit fe3c643c84
6 changed files with 303 additions and 294 deletions

View File

@ -20,73 +20,75 @@
{{ partial "body/photoswipe" . }}
{{ $masonry := resources.Get `js/masonry.pkgd.min.js` | resources.Fingerprint }}
<script src="{{ $masonry.RelPermalink }}"></script>
<script defer src="{{ $masonry.RelPermalink }}"></script>
{{ $imagesloaded := resources.Get `js/imagesloaded.pkgd.min.js` | resources.Fingerprint }}
<script src="{{ $imagesloaded.RelPermalink }}"></script>
<script defer src="{{ $imagesloaded.RelPermalink }}"></script>
<script>
var $grid = $('.grid').masonry({
itemSelector: '.grid-item',
columnWidth: '.grid-sizer',
percentPosition: true,
});
$grid.imagesLoaded().progress(function () {
$grid.masonry();
});
$(document).ready(function () {
var $grid = $('.grid').masonry({
itemSelector: '.grid-item',
columnWidth: '.grid-sizer',
percentPosition: true,
});
$grid.imagesLoaded().progress(function () {
$grid.masonry();
});
enquire.register("screen and (max-width:500px)", {
match: function () {
$('.grid-item').addClass('full');
$('.grid-sizer').addClass('full');
$('.grid-item').removeClass('half');
$('.grid-sizer').removeClass('half');
},
unmatch: function () {
$('.grid-item').addClass('half');
$('.grid-sizer').addClass('half');
$('.grid-item').removeClass('full');
$('.grid-sizer').removeClass('full');
},
}).register("screen and (max-width:700px)", {
match: function () {
$('.grid-item').addClass('half');
$('.grid-sizer').addClass('half');
$('.grid-item').removeClass('third');
$('.grid-sizer').removeClass('third');
},
unmatch: function () {
$('.grid-item').addClass('third');
$('.grid-sizer').addClass('third');
$('.grid-item').removeClass('half');
$('.grid-sizer').removeClass('half');
},
}).register("screen and (max-width:900px)", {
match: function () {
$('.grid-item').addClass('third');
$('.grid-sizer').addClass('third');
$('.grid-item').removeClass('quarter');
$('.grid-sizer').removeClass('quarter');
},
unmatch: function () {
$('.grid-item').addClass('quarter');
$('.grid-sizer').addClass('quarter');
$('.grid-item').removeClass('third');
$('.grid-sizer').removeClass('third');
},
}).register("screen and (max-width:1200px)", {
match: function () {
$('.grid-item').addClass('quarter');
$('.grid-sizer').addClass('quarter');
$('.grid-item').removeClass('fifth');
$('.grid-sizer').removeClass('fifth');
},
unmatch: function () {
$('.grid-item').addClass('fifth');
$('.grid-sizer').addClass('fifth');
$('.grid-item').removeClass('quarter');
$('.grid-sizer').removeClass('quarter');
},
});
enquire.register("screen and (max-width:500px)", {
match: function () {
$('.grid-item').addClass('full');
$('.grid-sizer').addClass('full');
$('.grid-item').removeClass('half');
$('.grid-sizer').removeClass('half');
},
unmatch: function () {
$('.grid-item').addClass('half');
$('.grid-sizer').addClass('half');
$('.grid-item').removeClass('full');
$('.grid-sizer').removeClass('full');
},
}).register("screen and (max-width:700px)", {
match: function () {
$('.grid-item').addClass('half');
$('.grid-sizer').addClass('half');
$('.grid-item').removeClass('third');
$('.grid-sizer').removeClass('third');
},
unmatch: function () {
$('.grid-item').addClass('third');
$('.grid-sizer').addClass('third');
$('.grid-item').removeClass('half');
$('.grid-sizer').removeClass('half');
},
}).register("screen and (max-width:900px)", {
match: function () {
$('.grid-item').addClass('third');
$('.grid-sizer').addClass('third');
$('.grid-item').removeClass('quarter');
$('.grid-sizer').removeClass('quarter');
},
unmatch: function () {
$('.grid-item').addClass('quarter');
$('.grid-sizer').addClass('quarter');
$('.grid-item').removeClass('third');
$('.grid-sizer').removeClass('third');
},
}).register("screen and (max-width:1200px)", {
match: function () {
$('.grid-item').addClass('quarter');
$('.grid-sizer').addClass('quarter');
$('.grid-item').removeClass('fifth');
$('.grid-sizer').removeClass('fifth');
},
unmatch: function () {
$('.grid-item').addClass('fifth');
$('.grid-sizer').addClass('fifth');
$('.grid-item').removeClass('quarter');
$('.grid-sizer').removeClass('quarter');
},
});
}
</script>
{{ end }}

View File

@ -1,12 +1,14 @@
{{ if $.Param "enableCustomScrollbar" }}
{{ $customscrollbar := resources.Get `js/perfect-scrollbar.jquery.min.js` | resources.Fingerprint }}
<script src="{{ $customscrollbar.RelPermalink }}"></script>
<script defer src="{{ $customscrollbar.RelPermalink }}"></script>
{{ $customScrollbarStyle := resources.Get "css/perfect-scrollbar.min.css" }}
<script src="{{ $customScrollbarStyle.RelPermalink }}"></script>
<script defer src="{{ $customScrollbarStyle.RelPermalink }}"></script>
<script>
var pre = $('pre');
pre.perfectScrollbar();
<script>
$(document).ready(function () {
var pre = $('pre');
pre.perfectScrollbar();
}
</script>
{{ end }}

View File

@ -1,7 +1,7 @@
{{ $jquery := resources.Get "js/jquery.min.js" | resources.Fingerprint }}
<script src="{{ $jquery.RelPermalink }}"></script>
<script async src="{{ $jquery.RelPermalink }}"></script>
{{ $clipboard := resources.Get "js/clipboard.min.js" | resources.Fingerprint }}
<script src="{{ $clipboard.RelPermalink }}"></script>
<script defer src="{{ $clipboard.RelPermalink }}"></script>
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
<script defer src="{{ $enquire.RelPermalink }}"></script>
{{ $prism := resources.Get "js/prism.min.js" | minify | resources.Fingerprint }}

View File

@ -8,101 +8,103 @@
</div>
{{ $toc := resources.Get `js/jquery.toc.min.js` | resources.Fingerprint }}
<script src="{{ $toc.RelPermalink }}"></script>
<script defer src="{{ $toc.RelPermalink }}"></script>
<script>
var navbar = $('.navbar');
$(document).ready(function () {
var navbar = $('.navbar');
$("#toc").toc({ content: ".single__contents", headings: "h1,h2,h3,h4" });
$('#toc > li').each(function () {
$(this).find('ul').css('display', 'none');
});
$('#toc a').each(function () {
$(this).click(function () {
navbar.removeClass('navbar--show');
navbar.removeClass('navbar--hide');
navbar.addClass('navbar--hide');
$(".single__contents :header").each(function () {
$('.toc a').removeClass('active');
});
$(this).addClass('active');
$('#toc > li').each(function () {
$(this).find('ul').css('display', 'none');
});
$(this).next().css('display', 'block');
$(this).parents('ul').css('display', 'block');
$("#toc").toc({ content: ".single__contents", headings: "h1,h2,h3,h4" });
$('#toc > li').each(function () {
$(this).find('ul').css('display', 'none');
});
});
$('#toc a').each(function () {
$(this).click(function () {
navbar.removeClass('navbar--show');
navbar.removeClass('navbar--hide');
navbar.addClass('navbar--hide');
// Add link button for every
var text, clip = new ClipboardJS('.anchor');
var headers = $('.single__contents :header').not('h6').not('h5');
headers.append(function (index, html) {
var element = $(this);
var url = encodeURI(document.location.origin + document.location.pathname);
var link = url + "#" + element[0].id;
return " <span class='anchor hide' data-clipboard-text='" + link + "' style='position: relative;'>" +
"<span style='font-size: 1rem; position: absolute; right: -2rem; top: 50%; transform: translateY(-50%)'>🔗</span>" +
"</span>"
;
});
headers.on('mouseenter', function () {
$(this).find('.anchor').attr('class', 'anchor');
});
headers.on('mouseleave', function () {
$(this).find('.anchor').attr('class', 'anchor hide');
});
$(".anchor").on('mouseleave', function (e) {
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
});
clip.on('success', function (e) {
e.clearSelection();
$(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
});
// clipboard
var clipInit = false;
$('code').each(function () {
var code = $(this),
text = code.text();
if (text.length > 30) {
if (!clipInit) {
var text, clip = new ClipboardJS('.copy-to-clipboard', {
text: function (trigger) {
text = $(trigger).prev('code').text();
return text.replace(/^\$\s/gm, '');
}
$(".single__contents :header").each(function () {
$('.toc a').removeClass('active');
});
$(this).addClass('active');
var inPre;
clip.on('success', function (e) {
e.clearSelection();
inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
$(e.trigger).attr('aria-label', 'Copied to clipboard!').addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
$('#toc > li').each(function () {
$(this).find('ul').css('display', 'none');
});
$(this).next().css('display', 'block');
$(this).parents('ul').css('display', 'block');
});
});
clip.on('error', function (e) {
inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
$(e.trigger).attr('aria-label', fallbackMessage(e.action)).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
$(document).one('copy', function () {
// Add link button for every
var text, clip = new ClipboardJS('.anchor');
var headers = $('.single__contents :header').not('h6').not('h5');
headers.append(function (index, html) {
var element = $(this);
var url = encodeURI(document.location.origin + document.location.pathname);
var link = url + "#" + element[0].id;
return " <span class='anchor hide' data-clipboard-text='" + link + "' style='position: relative;'>" +
"<span style='font-size: 1rem; position: absolute; right: -2rem; top: 50%; transform: translateY(-50%)'>🔗</span>" +
"</span>"
;
});
headers.on('mouseenter', function () {
$(this).find('.anchor').attr('class', 'anchor');
});
headers.on('mouseleave', function () {
$(this).find('.anchor').attr('class', 'anchor hide');
});
$(".anchor").on('mouseleave', function (e) {
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
});
clip.on('success', function (e) {
e.clearSelection();
$(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
});
// clipboard
var clipInit = false;
$('code').each(function () {
var code = $(this),
text = code.text();
if (text.length > 30) {
if (!clipInit) {
var text, clip = new ClipboardJS('.copy-to-clipboard', {
text: function (trigger) {
text = $(trigger).prev('code').text();
return text.replace(/^\$\s/gm, '');
}
});
var inPre;
clip.on('success', function (e) {
e.clearSelection();
inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
$(e.trigger).attr('aria-label', 'Copied to clipboard!').addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
});
clip.on('error', function (e) {
inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
$(e.trigger).attr('aria-label', fallbackMessage(e.action)).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
$(document).one('copy', function () {
$(e.trigger).attr('aria-label', 'Copied to clipboard!').addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
});
});
clipInit = true;
}
code.after('<span class="copy-to-clipboard" title="Copy to clipboard" />');
code.next('.copy-to-clipboard').on('mouseleave', function () {
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
});
clipInit = true;
}
code.after('<span class="copy-to-clipboard" title="Copy to clipboard" />');
code.next('.copy-to-clipboard').on('mouseleave', function () {
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
});
}
});
});
}
</script>
{{ end }}

View File

@ -1,38 +1,40 @@
{{ if $.Param "enableMark" }}
{{ $mark := resources.Get "js/jquery.mark.min.js" | resources.Fingerprint }}
<script src="{{ $mark.RelPermalink }}"></script>
<script defer src="{{ $mark.RelPermalink }}"></script>
<script>
var mark = function () {
var keyword = $("#search").val();
var options = {
"element": "mark",
"className": "",
"exclude": [],
"iframes": false,
"iframesTimeout": 5000,
"acrossElements": false,
"ignoreGroups": 0,
"each": function (node) {
},
"filter": function (textNode, foundTerm, totalCounter) {
return true;
},
"noMatch": function (term) {
},
"done": function (counter) {
},
"debug": false,
"log": window.console
$(document).ready(function () {
var mark = function () {
var keyword = $("#search").val();
var options = {
"element": "mark",
"className": "",
"exclude": [],
"iframes": false,
"iframesTimeout": 5000,
"acrossElements": false,
"ignoreGroups": 0,
"each": function (node) {
},
"filter": function (textNode, foundTerm, totalCounter) {
return true;
},
"noMatch": function (term) {
},
"done": function (counter) {
},
"debug": false,
"log": window.console
};
$(".container").unmark({
done: function () {
$(".container").mark(keyword, options);
}
});
};
$(".container").unmark({
done: function () {
$(".container").mark(keyword, options);
}
});
};
$("#search").on("input", mark);
$("#search").on("input", mark);
}
</script>
{{ end }}

View File

@ -13,7 +13,7 @@
{{ partial "sidebar/site-mark" . }}
{{ $lunr := resources.Get "js/lunr.min.js" | resources.Fingerprint }}
<script src="{{ $lunr.RelPermalink }}"></script>
<script defer src="{{ $lunr.RelPermalink }}"></script>
<script>
{{ if .Site.IsMultiLingual }}
@ -22,125 +22,126 @@
var baseurl = "{{.Site.BaseURL}}";
{{ end }}
var lunrIndex = null;
var pagesIndex = null;
var searchResults = null;
var searchMenu = null;
$(document).ready(function () {
var lunrIndex = null;
var pagesIndex = null;
var searchResults = null;
var searchMenu = null;
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function initLunr() {
if (!endsWith(baseurl, "/")) {
baseurl = baseurl + '/';
};
function initLunr() {
if (!endsWith(baseurl, "/")) {
baseurl = baseurl + '/';
};
$.getJSON(baseurl + "index.json")
.done(function (index) {
pagesIndex = index;
lunrIndex = lunr(function () {
this.ref('uri');
this.field('title');
this.field('description');
//this.field('content');
//this.field('tags');
//this.field('series');
//this.field('categories');
$.getJSON(baseurl + "index.json")
.done(function (index) {
pagesIndex = index;
lunrIndex = lunr(function () {
this.ref('uri');
this.field('title');
this.field('description');
//this.field('content');
//this.field('tags');
//this.field('series');
//this.field('categories');
var that = this;
index.forEach(function (page) {
that.add(page);
var that = this;
index.forEach(function (page) {
that.add(page);
});
});
})
.fail(function (jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
console.error("Error getting Hugo index file:", err);
});
})
.fail(function (jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
console.error("Error getting Hugo index file:", err);
});
}
}
function search(query) {
return lunrIndex.search(query).map(function (result) {
return pagesIndex.filter(function (page) {
return page.uri === result.ref;
})[0];
function search(query) {
return lunrIndex.search(query).map(function (result) {
return pagesIndex.filter(function (page) {
return page.uri === result.ref;
})[0];
});
}
function renderSearchResults(results) {
searchResults = document.getElementById('search-results');
searchMenu = document.getElementById('search-menu');
searchResults.setAttribute('class', 'dropdown is-active');
var content = document.createElement('div');
content.setAttribute('class', 'dropdown-content search-content');
if (results.length > 0) {
results.forEach(function (result) {
var item = document.createElement('a');
item.setAttribute('href', result.uri);
item.setAttribute('class', 'dropdown-item');
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">» ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
content.appendChild(item);
});
} else {
var item = document.createElement('span');
item.setAttribute('class', 'dropdown-item');
item.innerText = 'No results found';
content.appendChild(item);
}
while (searchMenu.hasChildNodes()) {
searchMenu.removeChild(
searchMenu.lastChild
);
}
searchMenu.appendChild(content);
}
initLunr();
$("#search").on('input', function (e) {
if (!e.target.value) {
$('#search-results').attr('class', 'dropdown');
return null;
}
var results = search(e.target.value);
renderSearchResults(results);
});
$('#search').on('blur', function () {
setTimeout(function () {
$('#search-results').attr('class', 'dropdown');
}, 100);
});
$('#search').on('click', function (e) {
if (!e.target.value) {
$('#search-results').attr('class', 'dropdown');
return null;
}
var results = search(e.target.value);
renderSearchResults(results);
});
$('#search').on('keydown', function (e) {
var items = $('#search-menu .dropdown-item');
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
items.removeClass('is-active');
if (e.key === 'ArrowDown') {
items.eq(activeIndex + 1).addClass('is-active');
} else if (e.key === 'ArrowUp') {
items.eq(activeIndex - 1).addClass('is-active');
} else if (e.key === 'Enter') {
var currentItemLink = items.eq(activeIndex).attr('href');
if (currentItemLink) {
location.href = currentItemLink;
}
}
});
}
function renderSearchResults(results) {
searchResults = document.getElementById('search-results');
searchMenu = document.getElementById('search-menu');
searchResults.setAttribute('class', 'dropdown is-active');
var content = document.createElement('div');
content.setAttribute('class', 'dropdown-content search-content');
if (results.length > 0) {
results.forEach(function (result) {
var item = document.createElement('a');
item.setAttribute('href', result.uri);
item.setAttribute('class', 'dropdown-item');
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">» ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
content.appendChild(item);
});
} else {
var item = document.createElement('span');
item.setAttribute('class', 'dropdown-item');
item.innerText = 'No results found';
content.appendChild(item);
}
while (searchMenu.hasChildNodes()) {
searchMenu.removeChild(
searchMenu.lastChild
);
}
searchMenu.appendChild(content);
}
initLunr();
$("#search").on('input', function (e) {
if (!e.target.value) {
$('#search-results').attr('class', 'dropdown');
return null;
}
var results = search(e.target.value);
renderSearchResults(results);
});
$('#search').on('blur', function () {
setTimeout(function () {
$('#search-results').attr('class', 'dropdown');
}, 100);
});
$('#search').on('click', function (e) {
if (!e.target.value) {
$('#search-results').attr('class', 'dropdown');
return null;
}
var results = search(e.target.value);
renderSearchResults(results);
});
$('#search').on('keydown', function (e) {
var items = $('#search-menu .dropdown-item');
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
items.removeClass('is-active');
if (e.key === 'ArrowDown') {
items.eq(activeIndex + 1).addClass('is-active');
} else if (e.key === 'ArrowUp') {
items.eq(activeIndex - 1).addClass('is-active');
} else if (e.key === 'Enter') {
var currentItemLink = items.eq(activeIndex).attr('href');
if (currentItemLink) {
location.href = currentItemLink;
}
}
});
</script>
{{ end }}