chore(static): update js assets for eslint
This commit is contained in:
parent
02d1996215
commit
dfccd95d49
|
@ -22,6 +22,14 @@ module.exports = class extends Migration {
|
|||
delete result.meta;
|
||||
delete result.rss;
|
||||
|
||||
if (result.logo === '/images/logo.svg') {
|
||||
result.logo = result.logo.replace(/^\/images/, '/img');
|
||||
}
|
||||
|
||||
if (result.head.favicon === '/img/favicon.svg') {
|
||||
result.head.favicon = result.head.favicon.replace(/^\/images/, '/img');
|
||||
}
|
||||
|
||||
if (result.search && Object.prototype.hasOwnProperty.call(result.search, 'type')) {
|
||||
switch (result.search.type) {
|
||||
case 'google-cse':
|
||||
|
|
|
@ -9,7 +9,7 @@ class OutdatedBrowser extends Component {
|
|||
outdatedBrowser({
|
||||
bgColor: '#f25648',
|
||||
color: '#ffffff',
|
||||
lowerThan: 'flex'
|
||||
lowerThan: 'object-fit' // display on IE11 or below
|
||||
});
|
||||
});`;
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ module.exports = cacheComponent(RecentPosts, 'widget.recentposts', props => {
|
|||
date: date(post.date),
|
||||
dateXml: date_xml(post.date),
|
||||
thumbnail: thumbnail ? get_thumbnail(post) : null,
|
||||
// TODO: check if categories work
|
||||
categories: post.categories.map(category => ({
|
||||
name: category.name,
|
||||
url: url_for(category.path)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "../../.eslintrc.json",
|
||||
"env": {
|
||||
"browser": true,
|
||||
"jquery": true,
|
||||
"node": false
|
||||
}
|
||||
}
|
|
@ -1,35 +1,35 @@
|
|||
(function () {
|
||||
(function() {
|
||||
function $() {
|
||||
return Array.prototype.slice.call(document.querySelectorAll.apply(document, arguments));
|
||||
}
|
||||
|
||||
$('body > .navbar, body > .section, body > .footer').forEach(function (element) {
|
||||
$('body > .navbar, body > .section, body > .footer').forEach(element => {
|
||||
element.style.transition = '0s';
|
||||
element.style.opacity = '0';
|
||||
});
|
||||
document.querySelector('body > .navbar').style.transform = 'translateY(-100px)';
|
||||
['.column-main > .card',
|
||||
'.column-left > .card, .column-right-shadow > .card',
|
||||
'.column-right > .card'].map(function (selector) {
|
||||
$(selector).forEach(function (element) {
|
||||
'.column-right > .card'].forEach(selector => {
|
||||
$(selector).forEach(element => {
|
||||
element.style.transition = '0s';
|
||||
element.style.opacity = '0';
|
||||
element.style.transform = 'scale(0.8)';
|
||||
element.style.transformOrigin = 'center top';
|
||||
});
|
||||
});
|
||||
setTimeout(function () {
|
||||
$('body > .navbar, body > .section, body > .footer').forEach(function (element) {
|
||||
setTimeout(() => {
|
||||
$('body > .navbar, body > .section, body > .footer').forEach(element => {
|
||||
element.style.opacity = '1';
|
||||
element.style.transition = 'opacity 0.3s ease-out, transform 0.3s ease-out';
|
||||
});
|
||||
document.querySelector('body > .navbar').style.transform = 'translateY(0)';
|
||||
['.column-main > .card',
|
||||
'.column-left > .card, .column-right-shadow > .card',
|
||||
'.column-right > .card'].map(function (selector) {
|
||||
var i = 1;
|
||||
$(selector).forEach(function (element) {
|
||||
setTimeout(function () {
|
||||
'.column-right > .card'].forEach(selector => {
|
||||
let i = 1;
|
||||
$(selector).forEach(element => {
|
||||
setTimeout(() => {
|
||||
element.style.opacity = '1';
|
||||
element.style.transform = '';
|
||||
element.style.transition = 'opacity 0.3s ease-out, transform 0.3s ease-out';
|
||||
|
@ -38,4 +38,4 @@
|
|||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
}());
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
$(document).ready(function () {
|
||||
var $button = $('#back-to-top');
|
||||
var $footer = $('footer.footer');
|
||||
var $mainColumn = $('.column-main');
|
||||
var $leftSidebar = $('.column-left');
|
||||
var $rightSidebar = $('.column-right');
|
||||
var lastScrollTop = 0;
|
||||
var rightMargin = 20;
|
||||
var bottomMargin = 20;
|
||||
var lastState = null;
|
||||
var state = {
|
||||
$(document).ready(() => {
|
||||
const $button = $('#back-to-top');
|
||||
const $footer = $('footer.footer');
|
||||
const $mainColumn = $('.column-main');
|
||||
const $leftSidebar = $('.column-left');
|
||||
const $rightSidebar = $('.column-right');
|
||||
let lastScrollTop = 0;
|
||||
const rightMargin = 20;
|
||||
const bottomMargin = 20;
|
||||
let lastState = null;
|
||||
const state = {
|
||||
base: {
|
||||
classname: 'card has-text-centered',
|
||||
left: '',
|
||||
|
@ -18,10 +18,10 @@ $(document).ready(function () {
|
|||
}
|
||||
};
|
||||
state['desktop-hidden'] = Object.assign({}, state.base, {
|
||||
classname: state.base.classname + ' rise-up',
|
||||
classname: state.base.classname + ' rise-up'
|
||||
});
|
||||
state['desktop-visible'] = Object.assign({}, state['desktop-hidden'], {
|
||||
classname: state['desktop-hidden'].classname + ' fade-in',
|
||||
classname: state['desktop-hidden'].classname + ' fade-in'
|
||||
});
|
||||
state['desktop-dock'] = Object.assign({}, state['desktop-visible'], {
|
||||
classname: state['desktop-visible'].classname + ' fade-in',
|
||||
|
@ -33,21 +33,15 @@ $(document).ready(function () {
|
|||
right: rightMargin
|
||||
});
|
||||
state['mobile-visible'] = Object.assign({}, state['mobile-hidden'], {
|
||||
classname: state['mobile-hidden'].classname + ' rise-up',
|
||||
classname: state['mobile-hidden'].classname + ' rise-up'
|
||||
});
|
||||
|
||||
function isStateEquals(prev, next) {
|
||||
for (var prop in prev) {
|
||||
if (!next.hasOwnProperty(prop) || next[prop] !== prev[prop]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (var prop in next) {
|
||||
if (!prev.hasOwnProperty(prop) || prev[prop] !== prev[prop]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return ![].concat(Object.keys(prev), Object.keys(next)).some(key => {
|
||||
return !Object.prototype.hasOwnProperty.call(prev, key)
|
||||
|| !Object.prototype.hasOwnProperty.call(next, key)
|
||||
|| next[key] !== prev[key];
|
||||
});
|
||||
}
|
||||
|
||||
function applyState(state) {
|
||||
|
@ -55,7 +49,7 @@ $(document).ready(function () {
|
|||
return;
|
||||
}
|
||||
$button.attr('class', state.classname);
|
||||
for (let prop in state) {
|
||||
for (const prop in state) {
|
||||
if (prop === 'classname') {
|
||||
continue;
|
||||
}
|
||||
|
@ -88,7 +82,7 @@ $(document).ready(function () {
|
|||
if (!hasRightSidebar()) {
|
||||
return 0;
|
||||
}
|
||||
return Math.max.apply(null, $rightSidebar.find('.widget').map(function () {
|
||||
return Math.max.apply(null, $rightSidebar.find('.widget').map(function() {
|
||||
return $(this).offset().top + $(this).outerHeight(true);
|
||||
}));
|
||||
}
|
||||
|
@ -116,11 +110,11 @@ $(document).ready(function () {
|
|||
function update() {
|
||||
// desktop mode or tablet mode with only right sidebar enabled
|
||||
if (isDesktop() || (isTablet() && !hasLeftSidebar() && hasRightSidebar())) {
|
||||
var nextState;
|
||||
var padding = ($mainColumn.outerWidth() - $mainColumn.width()) / 2;
|
||||
var maxLeft = $(window).width() - getButtonWidth() - rightMargin;
|
||||
var maxBottom = $footer.offset().top + getButtonHeight() / 2 + bottomMargin;
|
||||
if (getScrollTop() == 0 || getScrollBottom() < getRightSidebarBottom() + padding + getButtonHeight()) {
|
||||
let nextState;
|
||||
const padding = ($mainColumn.outerWidth() - $mainColumn.width()) / 2;
|
||||
const maxLeft = $(window).width() - getButtonWidth() - rightMargin;
|
||||
const maxBottom = $footer.offset().top + (getButtonHeight() / 2) + bottomMargin;
|
||||
if (getScrollTop() === 0 || getScrollBottom() < getRightSidebarBottom() + padding + getButtonHeight()) {
|
||||
nextState = state['desktop-hidden'];
|
||||
} else if (getScrollBottom() < maxBottom) {
|
||||
nextState = state['desktop-visible'];
|
||||
|
@ -130,7 +124,7 @@ $(document).ready(function () {
|
|||
});
|
||||
}
|
||||
|
||||
var left = $mainColumn.offset().left + $mainColumn.outerWidth() + padding;
|
||||
const left = $mainColumn.offset().left + $mainColumn.outerWidth() + padding;
|
||||
nextState = Object.assign({}, nextState, {
|
||||
left: Math.min(left, maxLeft)
|
||||
});
|
||||
|
@ -150,7 +144,7 @@ $(document).ready(function () {
|
|||
$(window).resize(update);
|
||||
$(window).scroll(update);
|
||||
|
||||
$('#back-to-top').on('click', function () {
|
||||
$('#back-to-top').on('click', () => {
|
||||
$('body, html').animate({ scrollTop: 0 }, 400);
|
||||
});
|
||||
});
|
|
@ -1,8 +1,8 @@
|
|||
document.addEventListener('DOMContentLoaded', function () {
|
||||
if (typeof ($.fn.lightGallery) === 'function') {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
if (typeof $.fn.lightGallery === 'function') {
|
||||
$('.article').lightGallery({ selector: '.gallery-item' });
|
||||
}
|
||||
if (typeof ($.fn.justifiedGallery) === 'function') {
|
||||
if (typeof $.fn.justifiedGallery === 'function') {
|
||||
if ($('.justified-gallery > p > .gallery-item').length) {
|
||||
$('.justified-gallery > p > .gallery-item').unwrap();
|
||||
}
|
||||
|
|
|
@ -2,44 +2,43 @@
|
|||
* Insight search plugin
|
||||
* @author PPOffice { @link https://github.com/ppoffice }
|
||||
*/
|
||||
(function ($, CONFIG) {
|
||||
var $main = $('.ins-search');
|
||||
var $input = $main.find('.ins-search-input');
|
||||
var $wrapper = $main.find('.ins-section-wrapper');
|
||||
var $container = $main.find('.ins-section-container');
|
||||
(function($, CONFIG) {
|
||||
const $main = $('.ins-search');
|
||||
const $input = $main.find('.ins-search-input');
|
||||
const $wrapper = $main.find('.ins-section-wrapper');
|
||||
const $container = $main.find('.ins-section-container');
|
||||
$main.parent().remove('.ins-search');
|
||||
$('body').append($main);
|
||||
|
||||
function section (title) {
|
||||
function section(title) {
|
||||
return $('<section>').addClass('ins-section')
|
||||
.append($('<header>').addClass('ins-section-header').text(title));
|
||||
}
|
||||
|
||||
function searchItem (icon, title, slug, preview, url) {
|
||||
function searchItem(icon, title, slug, preview, url) {
|
||||
return $('<div>').addClass('ins-selectable').addClass('ins-search-item')
|
||||
.append($('<header>').append($('<i>').addClass('fa').addClass('fa-' + icon))
|
||||
.append($('<span>').addClass('ins-title').text(title != null && title !== '' ? title : CONFIG.TRANSLATION['UNTITLED']))
|
||||
.append($('<span>').addClass('ins-title').text(title != null && title !== '' ? title : CONFIG.TRANSLATION.UNTITLED))
|
||||
.append(slug ? $('<span>').addClass('ins-slug').text(slug) : null))
|
||||
.append(preview ? $('<p>').addClass('ins-search-preview').text(preview) : null)
|
||||
.attr('data-url', url);
|
||||
}
|
||||
|
||||
function sectionFactory (type, array) {
|
||||
var sectionTitle;
|
||||
var $searchItems;
|
||||
function sectionFactory(type, array) {
|
||||
let $searchItems;
|
||||
if (array.length === 0) return null;
|
||||
sectionTitle = CONFIG.TRANSLATION[type];
|
||||
const sectionTitle = CONFIG.TRANSLATION[type];
|
||||
switch (type) {
|
||||
case 'POSTS':
|
||||
case 'PAGES':
|
||||
$searchItems = array.map(function (item) {
|
||||
$searchItems = array.map(item => {
|
||||
// Use config.root instead of permalink to fix url issue
|
||||
return searchItem('file', item.title, null, item.text.slice(0, 150), item.link);
|
||||
});
|
||||
break;
|
||||
case 'CATEGORIES':
|
||||
case 'TAGS':
|
||||
$searchItems = array.map(function (item) {
|
||||
$searchItems = array.map(item => {
|
||||
return searchItem(type === 'CATEGORIES' ? 'folder' : 'tag', item.name, item.slug, null, item.link);
|
||||
});
|
||||
break;
|
||||
|
@ -49,10 +48,10 @@
|
|||
return section(sectionTitle).append($searchItems);
|
||||
}
|
||||
|
||||
function parseKeywords (keywords) {
|
||||
return keywords.split(' ').filter(function (keyword) {
|
||||
function parseKeywords(keywords) {
|
||||
return keywords.split(' ').filter(keyword => {
|
||||
return !!keyword;
|
||||
}).map(function (keyword) {
|
||||
}).map(keyword => {
|
||||
return keyword.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
@ -62,34 +61,38 @@
|
|||
* @param Object obj Object to be weighted
|
||||
* @param Array<String> fields Object's fields to find matches
|
||||
*/
|
||||
function filter (keywords, obj, fields) {
|
||||
var keywordArray = parseKeywords(keywords);
|
||||
var containKeywords = keywordArray.filter(function (keyword) {
|
||||
var containFields = fields.filter(function (field) {
|
||||
if (!obj.hasOwnProperty(field))
|
||||
function filter(keywords, obj, fields) {
|
||||
const keywordArray = parseKeywords(keywords);
|
||||
const containKeywords = keywordArray.filter(keyword => {
|
||||
const containFields = fields.filter(field => {
|
||||
if (!Object.prototype.hasOwnProperty.call(obj, field)) {
|
||||
return false;
|
||||
if (obj[field].toUpperCase().indexOf(keyword) > -1)
|
||||
}
|
||||
if (obj[field].toUpperCase().indexOf(keyword) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (containFields.length > 0)
|
||||
if (containFields.length > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return containKeywords.length === keywordArray.length;
|
||||
}
|
||||
|
||||
function filterFactory (keywords) {
|
||||
function filterFactory(keywords) {
|
||||
return {
|
||||
POST: function (obj) {
|
||||
post: function(obj) {
|
||||
return filter(keywords, obj, ['title', 'text']);
|
||||
},
|
||||
PAGE: function (obj) {
|
||||
page: function(obj) {
|
||||
return filter(keywords, obj, ['title', 'text']);
|
||||
},
|
||||
CATEGORY: function (obj) {
|
||||
category: function(obj) {
|
||||
return filter(keywords, obj, ['name', 'slug']);
|
||||
},
|
||||
TAG: function (obj) {
|
||||
tag: function(obj) {
|
||||
return filter(keywords, obj, ['name', 'slug']);
|
||||
}
|
||||
};
|
||||
|
@ -101,13 +104,13 @@
|
|||
* @param Array<String> fields Object's fields to find matches
|
||||
* @param Array<Integer> weights Weight of every field
|
||||
*/
|
||||
function weight (keywords, obj, fields, weights) {
|
||||
var value = 0;
|
||||
parseKeywords(keywords).forEach(function (keyword) {
|
||||
var pattern = new RegExp(keyword, 'img'); // Global, Multi-line, Case-insensitive
|
||||
fields.forEach(function (field, index) {
|
||||
if (obj.hasOwnProperty(field)) {
|
||||
var matches = obj[field].match(pattern);
|
||||
function weight(keywords, obj, fields, weights) {
|
||||
let value = 0;
|
||||
parseKeywords(keywords).forEach(keyword => {
|
||||
const pattern = new RegExp(keyword, 'img'); // Global, Multi-line, Case-insensitive
|
||||
fields.forEach((field, index) => {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, field)) {
|
||||
const matches = obj[field].match(pattern);
|
||||
value += matches ? matches.length * weights[index] : 0;
|
||||
}
|
||||
});
|
||||
|
@ -115,50 +118,50 @@
|
|||
return value;
|
||||
}
|
||||
|
||||
function weightFactory (keywords) {
|
||||
function weightFactory(keywords) {
|
||||
return {
|
||||
POST: function (obj) {
|
||||
post: function(obj) {
|
||||
return weight(keywords, obj, ['title', 'text'], [3, 1]);
|
||||
},
|
||||
PAGE: function (obj) {
|
||||
page: function(obj) {
|
||||
return weight(keywords, obj, ['title', 'text'], [3, 1]);
|
||||
},
|
||||
CATEGORY: function (obj) {
|
||||
category: function(obj) {
|
||||
return weight(keywords, obj, ['name', 'slug'], [1, 1]);
|
||||
},
|
||||
TAG: function (obj) {
|
||||
tag: function(obj) {
|
||||
return weight(keywords, obj, ['name', 'slug'], [1, 1]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function search (json, keywords) {
|
||||
var WEIGHTS = weightFactory(keywords);
|
||||
var FILTERS = filterFactory(keywords);
|
||||
var posts = json.posts;
|
||||
var pages = json.pages;
|
||||
var tags = json.tags;
|
||||
var categories = json.categories;
|
||||
function search(json, keywords) {
|
||||
const weights = weightFactory(keywords);
|
||||
const filters = filterFactory(keywords);
|
||||
const posts = json.posts;
|
||||
const pages = json.pages;
|
||||
const tags = json.tags;
|
||||
const categories = json.categories;
|
||||
return {
|
||||
posts: posts.filter(FILTERS.POST).sort(function (a, b) { return WEIGHTS.POST(b) - WEIGHTS.POST(a); }).slice(0, 5),
|
||||
pages: pages.filter(FILTERS.PAGE).sort(function (a, b) { return WEIGHTS.PAGE(b) - WEIGHTS.PAGE(a); }).slice(0, 5),
|
||||
categories: categories.filter(FILTERS.CATEGORY).sort(function (a, b) { return WEIGHTS.CATEGORY(b) - WEIGHTS.CATEGORY(a); }).slice(0, 5),
|
||||
tags: tags.filter(FILTERS.TAG).sort(function (a, b) { return WEIGHTS.TAG(b) - WEIGHTS.TAG(a); }).slice(0, 5)
|
||||
posts: posts.filter(filters.post).sort((a, b) => { return weights.post(b) - weights.post(a); }).slice(0, 5),
|
||||
pages: pages.filter(filters.page).sort((a, b) => { return weights.page(b) - weights.page(a); }).slice(0, 5),
|
||||
categories: categories.filter(filters.category).sort((a, b) => { return weights.category(b) - weights.category(a); }).slice(0, 5),
|
||||
tags: tags.filter(filters.tag).sort((a, b) => { return weights.tag(b) - weights.tag(a); }).slice(0, 5)
|
||||
};
|
||||
}
|
||||
|
||||
function searchResultToDOM (searchResult) {
|
||||
function searchResultToDOM(searchResult) {
|
||||
$container.empty();
|
||||
for (var key in searchResult) {
|
||||
for (const key in searchResult) {
|
||||
$container.append(sectionFactory(key.toUpperCase(), searchResult[key]));
|
||||
}
|
||||
}
|
||||
|
||||
function scrollTo ($item) {
|
||||
function scrollTo($item) {
|
||||
if ($item.length === 0) return;
|
||||
var wrapperHeight = $wrapper[0].clientHeight;
|
||||
var itemTop = $item.position().top - $wrapper.scrollTop();
|
||||
var itemBottom = $item[0].clientHeight + $item.position().top;
|
||||
const wrapperHeight = $wrapper[0].clientHeight;
|
||||
const itemTop = $item.position().top - $wrapper.scrollTop();
|
||||
const itemBottom = $item[0].clientHeight + $item.position().top;
|
||||
if (itemBottom > wrapperHeight + $wrapper.scrollTop()) {
|
||||
$wrapper.scrollTop(itemBottom - $wrapper[0].clientHeight);
|
||||
}
|
||||
|
@ -167,59 +170,59 @@
|
|||
}
|
||||
}
|
||||
|
||||
function selectItemByDiff (value) {
|
||||
var $items = $.makeArray($container.find('.ins-selectable'));
|
||||
var prevPosition = -1;
|
||||
$items.forEach(function (item, index) {
|
||||
function selectItemByDiff(value) {
|
||||
const $items = $.makeArray($container.find('.ins-selectable'));
|
||||
let prevPosition = -1;
|
||||
$items.forEach((item, index) => {
|
||||
if ($(item).hasClass('active')) {
|
||||
prevPosition = index;
|
||||
return;
|
||||
|
||||
}
|
||||
});
|
||||
var nextPosition = ($items.length + prevPosition + value) % $items.length;
|
||||
const nextPosition = ($items.length + prevPosition + value) % $items.length;
|
||||
$($items[prevPosition]).removeClass('active');
|
||||
$($items[nextPosition]).addClass('active');
|
||||
scrollTo($($items[nextPosition]));
|
||||
}
|
||||
|
||||
function gotoLink ($item) {
|
||||
function gotoLink($item) {
|
||||
if ($item && $item.length) {
|
||||
location.href = $item.attr('data-url');
|
||||
}
|
||||
}
|
||||
|
||||
$.getJSON(CONFIG.CONTENT_URL, function (json) {
|
||||
$.getJSON(CONFIG.CONTENT_URL, json => {
|
||||
if (location.hash.trim() === '#ins-search') {
|
||||
$main.addClass('show');
|
||||
}
|
||||
$input.on('input', function () {
|
||||
var keywords = $(this).val();
|
||||
$input.on('input', function() {
|
||||
const keywords = $(this).val();
|
||||
searchResultToDOM(search(json, keywords));
|
||||
});
|
||||
$input.trigger('input');
|
||||
});
|
||||
|
||||
var touch = false;
|
||||
$(document).on('click focus', '.navbar-main .search', function () {
|
||||
let touch = false;
|
||||
$(document).on('click focus', '.navbar-main .search', () => {
|
||||
$main.addClass('show');
|
||||
$main.find('.ins-search-input').focus();
|
||||
}).on('click touchend', '.ins-search-item', function (e) {
|
||||
}).on('click touchend', '.ins-search-item', function(e) {
|
||||
if (e.type !== 'click' && !touch) {
|
||||
return;
|
||||
}
|
||||
gotoLink($(this));
|
||||
touch = false;
|
||||
}).on('click touchend', '.ins-close', function (e) {
|
||||
}).on('click touchend', '.ins-close', e => {
|
||||
if (e.type !== 'click' && !touch) {
|
||||
return;
|
||||
}
|
||||
$('.navbar-main').css('pointer-events', 'none');
|
||||
setTimeout(function(){
|
||||
setTimeout(() => {
|
||||
$('.navbar-main').css('pointer-events', 'auto');
|
||||
}, 400);
|
||||
$main.removeClass('show');
|
||||
touch = false;
|
||||
}).on('keydown', function (e) {
|
||||
}).on('keydown', e => {
|
||||
if (!$main.hasClass('show')) return;
|
||||
switch (e.keyCode) {
|
||||
case 27: // ESC
|
||||
|
@ -228,12 +231,12 @@
|
|||
selectItemByDiff(-1); break;
|
||||
case 40: // DOWN
|
||||
selectItemByDiff(1); break;
|
||||
case 13: //ENTER
|
||||
case 13: // ENTER
|
||||
gotoLink($container.find('.ins-selectable.active').eq(0)); break;
|
||||
}
|
||||
}).on('touchstart', function (e) {
|
||||
}).on('touchstart', e => {
|
||||
touch = true;
|
||||
}).on('touchmove', function (e) {
|
||||
}).on('touchmove', e => {
|
||||
touch = false;
|
||||
});
|
||||
})(jQuery, window.INSIGHT_CONFIG);
|
||||
}(jQuery, window.INSIGHT_CONFIG));
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
(function ($) {
|
||||
/* eslint-disable node/no-unsupported-features/node-builtins */
|
||||
(function($, moment, ClipboardJS, config) {
|
||||
$('.columns .column-right-shadow').append($('.columns .column-right').children().clone());
|
||||
|
||||
$('.article img:not(".not-gallery-item")').each(function () {
|
||||
$('.article img:not(".not-gallery-item")').each(function() {
|
||||
// wrap images with link and add caption if possible
|
||||
if ($(this).parent('a').length === 0) {
|
||||
$(this).wrap('<a class="gallery-item" href="' + $(this).attr('src') + '"></a>');
|
||||
|
@ -11,13 +12,13 @@
|
|||
}
|
||||
});
|
||||
|
||||
if (typeof (moment) === 'function') {
|
||||
$('.article-meta time').each(function () {
|
||||
if (typeof moment === 'function') {
|
||||
$('.article-meta time').each(function() {
|
||||
$(this).text(moment($(this).attr('datetime')).fromNow());
|
||||
});
|
||||
}
|
||||
|
||||
$('.article > .content > table').each(function () {
|
||||
$('.article > .content > table').each(function() {
|
||||
if ($(this).width() > $(this).parent().width()) {
|
||||
$(this).wrap('<div class="table-overflow"></div>');
|
||||
}
|
||||
|
@ -34,13 +35,24 @@
|
|||
adjustNavbar();
|
||||
$(window).resize(adjustNavbar);
|
||||
|
||||
function toggleFold(codeBlock, isFolded) {
|
||||
const $toggle = $(codeBlock).find('.fold i');
|
||||
!isFolded ? $(codeBlock).removeClass('folded') : $(codeBlock).addClass('folded');
|
||||
!isFolded ? $toggle.removeClass('fa-angle-right') : $toggle.removeClass('fa-angle-down');
|
||||
!isFolded ? $toggle.addClass('fa-angle-down') : $toggle.addClass('fa-angle-right');
|
||||
}
|
||||
|
||||
function createFoldButton(fold) {
|
||||
return '<span class="fold">' + (fold === 'unfolded' ? '<i class="fas fa-angle-down"></i>' : '<i class="fas fa-angle-right"></i>') + '</span>';
|
||||
}
|
||||
|
||||
$('figure.highlight table').wrap('<div class="highlight-body">');
|
||||
if (typeof (IcarusThemeSettings) !== 'undefined' &&
|
||||
typeof (IcarusThemeSettings.article) !== 'undefined' &&
|
||||
typeof (IcarusThemeSettings.article.highlight) !== 'undefined') {
|
||||
if (typeof config !== 'undefined'
|
||||
&& typeof config.article !== 'undefined'
|
||||
&& typeof config.article.highlight !== 'undefined') {
|
||||
|
||||
$('figure.highlight').addClass('hljs');
|
||||
$('figure.highlight .code .line span').each(function () {
|
||||
$('figure.highlight .code .line span').each(function() {
|
||||
const classes = $(this).attr('class').split(/\s+/);
|
||||
if (classes.length === 1) {
|
||||
$(this).addClass('hljs-' + classes[0]);
|
||||
|
@ -48,10 +60,10 @@
|
|||
}
|
||||
});
|
||||
|
||||
if (typeof (ClipboardJS) !== 'undefined' && IcarusThemeSettings.article.highlight.clipboard) {
|
||||
$('figure.highlight').each(function () {
|
||||
var id = 'code-' + Date.now() + (Math.random() * 1000 | 0);
|
||||
var button = '<a href="javascript:;" class="copy" title="Copy" data-clipboard-target="#' + id + ' .code"><i class="fas fa-copy"></i></a>';
|
||||
if (typeof ClipboardJS !== 'undefined' && config.article.highlight.clipboard) {
|
||||
$('figure.highlight').each(function() {
|
||||
const id = 'code-' + Date.now() + (Math.random() * 1000 | 0);
|
||||
const button = '<a href="javascript:;" class="copy" title="Copy" data-clipboard-target="#' + id + ' .code"><i class="fas fa-copy"></i></a>';
|
||||
$(this).attr('id', id);
|
||||
if ($(this).find('figcaption').length) {
|
||||
$(this).find('figcaption').prepend(button);
|
||||
|
@ -59,44 +71,44 @@
|
|||
$(this).prepend('<figcaption>' + button + '</figcaption>');
|
||||
}
|
||||
});
|
||||
new ClipboardJS('.highlight .copy');
|
||||
new ClipboardJS('.highlight .copy'); // eslint-disable-line no-new
|
||||
}
|
||||
var fold = IcarusThemeSettings.article.highlight.fold;
|
||||
const fold = config.article.highlight.fold;
|
||||
if (fold.trim()) {
|
||||
var button = '<span class="fold">' + (fold === 'unfolded' ? '<i class="fas fa-angle-down"></i>' : '<i class="fas fa-angle-right"></i>') + '</span>';
|
||||
$('figure.highlight').each(function () {
|
||||
$('figure.highlight').each(function() {
|
||||
if ($(this).find('figcaption').length) {
|
||||
$(this).find('figcaption').prepend(button);
|
||||
// fold individual code block
|
||||
if ($(this).find('figcaption').find('span').length > 0) {
|
||||
const span = $(this).find('figcaption').find('span').eq(0);
|
||||
if (span[0].innerText.indexOf('>folded') > -1) {
|
||||
span[0].innerText = span[0].innerText.replace('>folded', '');
|
||||
$(this).find('figcaption').prepend(createFoldButton('folded'));
|
||||
toggleFold(this, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
$(this).find('figcaption').prepend(createFoldButton(fold));
|
||||
} else {
|
||||
$(this).prepend('<figcaption>' + button + '</figcaption>');
|
||||
$(this).prepend('<figcaption>' + createFoldButton(fold) + '</figcaption>');
|
||||
}
|
||||
});
|
||||
|
||||
function toggleFold(codeBlock, isFolded) {
|
||||
var $toggle = $(codeBlock).find('.fold i');
|
||||
!isFolded ? $(codeBlock).removeClass('folded') : $(codeBlock).addClass('folded');
|
||||
!isFolded ? $toggle.removeClass('fa-angle-right') : $toggle.removeClass('fa-angle-down');
|
||||
!isFolded ? $toggle.addClass('fa-angle-down') : $toggle.addClass('fa-angle-right');
|
||||
}
|
||||
|
||||
$('figure.highlight').each(function () {
|
||||
toggleFold(this, fold === 'folded');
|
||||
});
|
||||
$('figure.highlight figcaption .fold').click(function () {
|
||||
var $code = $(this).closest('figure.highlight');
|
||||
|
||||
$('figure.highlight figcaption .fold').click(function() {
|
||||
const $code = $(this).closest('figure.highlight');
|
||||
toggleFold($code.eq(0), !$code.hasClass('folded'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var $toc = $('#toc');
|
||||
const $toc = $('#toc');
|
||||
if ($toc.length > 0) {
|
||||
var $mask = $('<div>');
|
||||
const $mask = $('<div>');
|
||||
$mask.attr('id', 'toc-mask');
|
||||
|
||||
$('body').append($mask);
|
||||
|
||||
function toggleToc() {
|
||||
function toggleToc() { // eslint-disable-line no-inner-declarations
|
||||
$toc.toggleClass('is-active');
|
||||
$mask.toggleClass('is-active');
|
||||
}
|
||||
|
@ -137,20 +149,20 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
if (typeof (IcarusThemeSettings) !== 'undefined' &&
|
||||
typeof (IcarusThemeSettings.site.url) !== 'undefined' &&
|
||||
typeof (IcarusThemeSettings.site.external_link) !== 'undefined' &&
|
||||
IcarusThemeSettings.site.external_link.enable) {
|
||||
$('.article .content a').filter(function (i, link) {
|
||||
return link.href &&
|
||||
!$(link).attr('href').startsWith('#') &&
|
||||
link.classList.length === 0 &&
|
||||
isExternalLink(link.href,
|
||||
IcarusThemeSettings.site.url,
|
||||
IcarusThemeSettings.site.external_link.exclude);
|
||||
}).each(function (i, link) {
|
||||
if (typeof config !== 'undefined'
|
||||
&& typeof config.site.url !== 'undefined'
|
||||
&& typeof config.site.external_link !== 'undefined'
|
||||
&& config.site.external_link.enable) {
|
||||
$('.article .content a').filter((i, link) => {
|
||||
return link.href
|
||||
&& !$(link).attr('href').startsWith('#')
|
||||
&& link.classList.length === 0
|
||||
&& isExternalLink(link.href,
|
||||
config.site.url,
|
||||
config.site.external_link.exclude);
|
||||
}).each((i, link) => {
|
||||
link.relList.add('noopener');
|
||||
link.target = '_blank';
|
||||
});
|
||||
}
|
||||
})(jQuery);
|
||||
}(jQuery, window.moment, window.ClipboardJS, window.IcarusThemeSettings));
|
||||
|
|
Loading…
Reference in New Issue