Fixing stuff

This commit is contained in:
Lucas Cimon
2017-11-30 01:54:19 +01:00
parent 98ffe5e6a7
commit f258f0becb
8 changed files with 106 additions and 81 deletions

View File

@@ -1,10 +1,10 @@
$(document).ready(function() {
$('.tipue_search').tipuesearch({
'show': 10,
'mode': 'json',
'showURL': false,
'descriptiveWords': 75,
'highlightEveryTerm': true,
'contentLocation': './tipue_search.json'
});
$(document).ready(() => {
$('.tipue_search').tipuesearch({
show: 10,
mode: 'json',
showURL: false,
descriptiveWords: 75,
highlightEveryTerm: true,
contentLocation: './tipue_search.json',
});
});

View File

@@ -4,75 +4,73 @@
* - true => select ONLY articles with this tag
* - false => do NOT select articles with this tag
* */
window.tagFilters = {}
(function iife() {
'strict';
function indexOf(array, predicate) {
for (var i = 0; i < array.length; i++) if (predicate(array[i])) return array[i];
}
function includes(array, value) {
return array.indexOf(value) !== -1;
};
window.tagFilters = {};
function toggleTagFilter(tag) {
var filterState = window.tagFilters[tag]
function includes(anArray, value) {
return anArray.indexOf(value) >= 0;
}
function updateArticlesVisibility() {
const includeFilters = Object.keys(window.tagFilters).filter((tagFilter) => window.tagFilters[tagFilter] === true);
const excludeFilters = Object.keys(window.tagFilters).filter((tagFilter) => window.tagFilters[tagFilter] === false);
Array.prototype.slice.call(document.getElementsByTagName('article')).forEach((article) => {
// article-excerpt: we ignore it
if (!article.dataset.tags) {
return;
}
const articleTags = JSON.parse(article.dataset.tags);
const allIncludeTags = includeFilters.every((tag) => includes(articleTags, tag));
const anyExcludeTag = excludeFilters.some((tag) => includes(articleTags, tag));
// Now implementing the core logic
let shouldDisplay = !anyExcludeTag;
if (shouldDisplay && includeFilters.length > 0) {
shouldDisplay = allIncludeTags;
}
if (shouldDisplay) {
article.classList.remove('mg-faded');
} else {
article.classList.add('mg-faded');
}
});
}
window.toggleTagFilter = function toggleTagFilter(tag) {
let filterState = window.tagFilters[tag];
if (filterState === true) {
this.classList.remove('mg-tag-filter-include');
filterState = false;
this.classList.add('mg-tag-filter-exclude');
this.title = 'Tag filter (exclude matching articles)';
this.classList.remove('mg-tag-filter-include');
filterState = false;
this.classList.add('mg-tag-filter-exclude');
this.title = 'Tag filter (exclude matching articles)';
} else if (filterState === false) {
this.classList.remove('mg-tag-filter-exclude');
filterState = undefined;
this.title = 'Tag filter (disabled)';
this.classList.remove('mg-tag-filter-exclude');
filterState = undefined;
this.title = 'Tag filter (disabled)';
} else {
filterState = true;
this.classList.add('mg-tag-filter-include');
this.title = 'Tag filter (include matching articles)';
filterState = true;
this.classList.add('mg-tag-filter-include');
this.title = 'Tag filter (include matching articles)';
}
window.tagFilters[tag] = filterState;
updateArticlesVisibility();
}
};
function toggleLangTagFilter(langs) {
var lang = this.textContent;
window.tagFilters['lang:'+lang] = undefined;
window.toggleLangTagFilter = function toggleLangTagFilter(langs) {
let lang = this.textContent;
window.tagFilters[`lang:${ lang }`] = undefined;
lang = langs[langs.indexOf(lang) + 1];
if (typeof lang === 'undefined') {
lang = 'lang'
this.title = 'Language filter (disabled)';
lang = 'lang';
this.title = 'Language filter (disabled)';
} else {
window.tagFilters['lang:'+lang] = true;
this.title = 'Language filter (include only "' + lang + '" articles)';
window.tagFilters[`lang:${ lang }`] = true;
this.title = `Language filter (include only "${ lang }" articles)`;
}
this.textContent = lang;
updateArticlesVisibility();
}
function updateArticlesVisibility() {
var includeFilters = Object.keys(window.tagFilters).filter(function (tagFilter) {
return window.tagFilters[tagFilter] === true;
});
var excludeFilters = Object.keys(window.tagFilters).filter(function (tagFilter) {
return window.tagFilters[tagFilter] === false;
});
Array.prototype.slice.call(document.getElementsByTagName('article')).forEach(function (article) {
if (!article.dataset.tags) { // article-excerpt: we ignore it
return;
}
var articleTags = JSON.parse(article.dataset.tags);
var allIncludeTags = includeFilters.every(function (tag) { return includes(articleTags, tag); });
var anyExcludeTag = excludeFilters.some(function (tag) { return includes(articleTags, tag); });
// Now implementing the core logic
var shouldDisplay = !anyExcludeTag;
if (shouldDisplay && includeFilters.length > 0) {
shouldDisplay = allIncludeTags;
}
if (shouldDisplay) {
article.classList.remove('mg-faded');
} else {
article.classList.add('mg-faded');
}
});
}
};
}());

View File

@@ -1,4 +1,4 @@
$(document).ready(function() {
$('.mg-container-social').height($('article').height());
$('#mg-panel-social').stick_in_parent({offset_top: 35});
$(document).ready(() => {
$('.mg-container-social').height($('article').height());
$('#mg-panel-social').stick_in_parent({ 'offset_top': 35 });
});