This commit is contained in:
parent
cc48355c18
commit
68dcd09364
|
@ -20,79 +20,73 @@
|
|||
{{ partial "body/photoswipe" . }}
|
||||
|
||||
{{ $masonry := resources.Get `js/masonry.pkgd.min.js` | fingerprint }}
|
||||
{{ $enquire := resources.Get `js/enquire.min.js` | fingerprint }}
|
||||
<script defer src="{{ $masonry.RelPermalink }}"></script>
|
||||
{{ $imagesloaded := resources.Get `js/imagesloaded.pkgd.min.js` | fingerprint }}
|
||||
<script defer src="{{ $imagesloaded.RelPermalink }}"></script>
|
||||
|
||||
<script>
|
||||
fetchInject([
|
||||
"{{ $masonry.RelPermalink }}",
|
||||
"{{ $imagesloaded.RelPermalink }}",
|
||||
"{{ $enquire.RelPermalink }}",
|
||||
]).then(() => {
|
||||
var $grid = $('.grid').masonry({
|
||||
itemSelector: '.grid-item',
|
||||
columnWidth: '.grid-sizer',
|
||||
percentPosition: true,
|
||||
});
|
||||
$grid.imagesLoaded().progress(function () {
|
||||
$grid.masonry();
|
||||
});
|
||||
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 }}
|
|
@ -1,15 +1,12 @@
|
|||
{{ if $.Param "enableCustomScrollbar" }}
|
||||
|
||||
{{ $customscrollbar := resources.Get `js/perfect-scrollbar.jquery.min.js` | fingerprint }}
|
||||
<script defer src="{{ $customscrollbar.RelPermalink }}"></script>
|
||||
{{ $customScrollbarStyle := resources.Get "css/perfect-scrollbar.min.css" }}
|
||||
<script defer src="{{ $customScrollbarStyle.RelPermalink }}"></script>
|
||||
|
||||
<script>
|
||||
fetchInject([
|
||||
"{{ $customscrollbar.RelPermalink }}",
|
||||
"{{ $customScrollbarStyle.RelPermalink }}",
|
||||
]).then(() => {
|
||||
var pre = $('pre');
|
||||
pre.perfectScrollbar();
|
||||
});
|
||||
var pre = $('pre');
|
||||
pre.perfectScrollbar();
|
||||
</script>
|
||||
{{ end }}
|
|
@ -68,58 +68,55 @@
|
|||
</div>
|
||||
|
||||
{{ $photoSwipe := resources.Get `js/photoswipe.min.js` | fingerprint }}
|
||||
<script defer src="{{ $photoSwipe.RelPermalink }}"></script>
|
||||
{{ $photoSwipeUi := resources.Get `js/photoswipe-ui-default.min.js` | fingerprint }}
|
||||
<script defer src="{{ $photoSwipeUi.RelPermalink }}"></script>
|
||||
{{ $photoSwipeStyle := resources.Get "css/photoswipe/photoswipe.css" }}
|
||||
<script defer src="{{ $photoSwipeStyle.RelPermalink }}"></script>
|
||||
{{ $photoSwipeSkin := resources.Get "css/photoswipe/custom-skin.css" }}
|
||||
<script defer src="{{ $photoSwipeSkin.RelPermalink }}"></script>
|
||||
|
||||
<script>
|
||||
fetchInject([
|
||||
"{{ $photoSwipe.RelPermalink }}",
|
||||
"{{ $photoSwipeUi.RelPermalink }}",
|
||||
"{{ $photoSwipeStyle.RelPermalink }}",
|
||||
"{{ $photoSwipeSkin.RelPermalink }}",
|
||||
]).then(() => {
|
||||
var pswpElement = $('.pswp')[0];
|
||||
var imgElements = $('.single__contents').find('img');
|
||||
var items = [];
|
||||
var pswpElement = $('.pswp')[0];
|
||||
var imgElements = $('.single__contents').find('img');
|
||||
var items = [];
|
||||
|
||||
imgElements.each(function (i, v) {
|
||||
$(this).click(function(e) {
|
||||
initGallery(i);
|
||||
});
|
||||
$(this).css('cursor', 'pointer');
|
||||
items.push({
|
||||
src: v.src,
|
||||
w: 0,
|
||||
h: 0,
|
||||
title: filename(v.src),
|
||||
});
|
||||
});
|
||||
imgElements.each(function (i, v) {
|
||||
$(this).click(function (e) {
|
||||
initGallery(i);
|
||||
});
|
||||
$(this).css('cursor', 'pointer');
|
||||
items.push({
|
||||
src: v.src,
|
||||
w: 0,
|
||||
h: 0,
|
||||
title: filename(v.src),
|
||||
});
|
||||
});
|
||||
|
||||
function filename(str) {
|
||||
var s = str.replace(/\\/g, '/');
|
||||
s = s.substring(s.lastIndexOf('/') + 1);
|
||||
return str ? s.replace(/[?#].+$/, '') : s.split('.')[0];
|
||||
}
|
||||
function filename(str) {
|
||||
var s = str.replace(/\\/g, '/');
|
||||
s = s.substring(s.lastIndexOf('/') + 1);
|
||||
return str ? s.replace(/[?#].+$/, '') : s.split('.')[0];
|
||||
}
|
||||
|
||||
function initGallery(index) {
|
||||
var options = { index: index };
|
||||
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
|
||||
gallery.listen('imageLoadComplete', function (index, item) {
|
||||
if (item.h < 1 || item.w < 1) {
|
||||
let img = new Image();
|
||||
img.onload = () => {
|
||||
item.w = img.width;
|
||||
item.h = img.height;
|
||||
gallery.invalidateCurrItems();
|
||||
gallery.updateSize(true);
|
||||
}
|
||||
img.src = item.src;
|
||||
function initGallery(index) {
|
||||
var options = { index: index };
|
||||
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
|
||||
gallery.listen('imageLoadComplete', function (index, item) {
|
||||
if (item.h < 1 || item.w < 1) {
|
||||
let img = new Image();
|
||||
img.onload = () => {
|
||||
item.w = img.width;
|
||||
item.h = img.height;
|
||||
gallery.invalidateCurrItems();
|
||||
gallery.updateSize(true);
|
||||
}
|
||||
})
|
||||
gallery.init();
|
||||
}
|
||||
});
|
||||
img.src = item.src;
|
||||
}
|
||||
})
|
||||
gallery.init();
|
||||
}
|
||||
</script>
|
||||
|
||||
{{ end }}
|
|
@ -1,5 +1,3 @@
|
|||
{{ $fetchinject := resources.Get "js/fetch-inject.umd.min.js" | resources.Fingerprint }}
|
||||
<script src="{{ $fetchinject.RelPermalink }}"></script>
|
||||
{{ $jquery := resources.Get "js/jquery.min.js" | resources.Fingerprint }}
|
||||
<script src="{{ $jquery.RelPermalink }}"></script>
|
||||
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
|
||||
|
|
|
@ -8,104 +8,101 @@
|
|||
</div>
|
||||
|
||||
{{ $toc := resources.Get `js/jquery.toc.min.js` | fingerprint }}
|
||||
<script defer src="{{ $toc.RelPermalink }}"></script>
|
||||
|
||||
<script>
|
||||
fetchInject([
|
||||
"{{ $toc.RelPermalink }}",
|
||||
]).then(() => {
|
||||
var navbar = $('.navbar');
|
||||
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").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');
|
||||
|
||||
$('#toc > li').each(function () {
|
||||
$(this).find('ul').css('display', 'none');
|
||||
});
|
||||
$(this).next().css('display', 'block');
|
||||
$(this).parents('ul').css('display', 'block');
|
||||
$(".single__contents :header").each(function () {
|
||||
$('.toc a').removeClass('active');
|
||||
});
|
||||
});
|
||||
$(this).addClass('active');
|
||||
|
||||
// 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');
|
||||
$('#toc > li').each(function () {
|
||||
$(this).find('ul').css('display', 'none');
|
||||
});
|
||||
$(this).next().css('display', 'block');
|
||||
$(this).parents('ul').css('display', 'block');
|
||||
});
|
||||
});
|
||||
|
||||
$(".anchor").on('mouseleave', function (e) {
|
||||
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
|
||||
});
|
||||
// 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');
|
||||
});
|
||||
|
||||
clip.on('success', function (e) {
|
||||
e.clearSelection();
|
||||
$(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
|
||||
});
|
||||
$(".anchor").on('mouseleave', function (e) {
|
||||
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
|
||||
});
|
||||
|
||||
// clipboard
|
||||
var clipInit = false;
|
||||
$('code').each(function () {
|
||||
var code = $(this),
|
||||
text = code.text();
|
||||
clip.on('success', function (e) {
|
||||
e.clearSelection();
|
||||
$(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
|
||||
});
|
||||
|
||||
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, '');
|
||||
}
|
||||
});
|
||||
// clipboard
|
||||
var clipInit = false;
|
||||
$('code').each(function () {
|
||||
var code = $(this),
|
||||
text = code.text();
|
||||
|
||||
var inPre;
|
||||
clip.on('success', function (e) {
|
||||
e.clearSelection();
|
||||
inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
|
||||
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'));
|
||||
});
|
||||
|
||||
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 }}
|
|
@ -1,41 +1,38 @@
|
|||
{{ if $.Param "enableMark" }}
|
||||
{{ $mark := resources.Get "js/jquery.mark.min.js" | fingerprint }}
|
||||
<script defer src="{{ $mark.RelPermalink }}"></script>
|
||||
|
||||
<script>
|
||||
fetchInject([
|
||||
"{{ $mark.RelPermalink }}",
|
||||
]).then(() => {
|
||||
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);
|
||||
}
|
||||
});
|
||||
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
|
||||
};
|
||||
|
||||
$("#search").on("input", mark);
|
||||
});
|
||||
$(".container").unmark({
|
||||
done: function () {
|
||||
$(".container").mark(keyword, options);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$("#search").on("input", mark);
|
||||
</script>
|
||||
{{ end }}
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
{{ partial "sidebar/site-mark" . }}
|
||||
{{ $lunr := resources.Get "js/lunr.min.js" | fingerprint }}
|
||||
<script defer src="{{ $lunr.RelPermalink }}"></script>
|
||||
|
||||
<script>
|
||||
{{ if .Site.IsMultiLingual }}
|
||||
|
@ -20,129 +21,126 @@
|
|||
{{ else }}
|
||||
var baseurl = "{{.Site.BaseURL}}";
|
||||
{{ end }}
|
||||
fetchInject([
|
||||
"{{ $lunr.RelPermalink }}",
|
||||
]).then(() => {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
var lunrIndex = null;
|
||||
var pagesIndex = null;
|
||||
var searchResults = null;
|
||||
var searchMenu = null;
|
||||
|
||||
function initLunr() {
|
||||
if (!endsWith(baseurl, "/")) {
|
||||
baseurl = baseurl + '/';
|
||||
};
|
||||
function endsWith(str, suffix) {
|
||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||
}
|
||||
|
||||
$.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');
|
||||
function initLunr() {
|
||||
if (!endsWith(baseurl, "/")) {
|
||||
baseurl = baseurl + '/';
|
||||
};
|
||||
|
||||
var that = this;
|
||||
index.forEach(function(page) {
|
||||
that.add(page);
|
||||
});
|
||||
$.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);
|
||||
});
|
||||
})
|
||||
.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];
|
||||
})
|
||||
.fail(function (jqxhr, textStatus, error) {
|
||||
var err = textStatus + ", " + error;
|
||||
console.error("Error getting Hugo index file:", err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
function search(query) {
|
||||
return lunrIndex.search(query).map(function (result) {
|
||||
return pagesIndex.filter(function (page) {
|
||||
return page.uri === result.ref;
|
||||
})[0];
|
||||
});
|
||||
}
|
||||
|
||||
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');
|
||||
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.innerText = 'No results found';
|
||||
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);
|
||||
}
|
||||
|
||||
while (searchMenu.hasChildNodes()) {
|
||||
searchMenu.removeChild(
|
||||
searchMenu.lastChild
|
||||
);
|
||||
}
|
||||
searchMenu.appendChild(content);
|
||||
});
|
||||
} else {
|
||||
var item = document.createElement('span');
|
||||
item.setAttribute('class', 'dropdown-item');
|
||||
item.innerText = 'No results found';
|
||||
content.appendChild(item);
|
||||
}
|
||||
|
||||
initLunr();
|
||||
while (searchMenu.hasChildNodes()) {
|
||||
searchMenu.removeChild(
|
||||
searchMenu.lastChild
|
||||
);
|
||||
}
|
||||
searchMenu.appendChild(content);
|
||||
}
|
||||
|
||||
$("#search").on('input', function(e) {
|
||||
if (!e.target.value) {
|
||||
$('#search-results').attr('class', 'dropdown');
|
||||
return null;
|
||||
}
|
||||
var results = search(e.target.value);
|
||||
renderSearchResults(results);
|
||||
});
|
||||
initLunr();
|
||||
|
||||
$('#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('input', 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;
|
||||
}
|
||||
$('#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 }}
|
Loading…
Reference in New Issue