2016-10-27 01:57:27 +02:00
|
|
|
import $ from 'jquery';
|
2016-11-03 10:02:16 +01:00
|
|
|
|
2017-03-31 20:21:41 +02:00
|
|
|
/* Materialize imports */
|
|
|
|
import 'materialize-css/dist/css/materialize.css';
|
|
|
|
import 'materialize-css/dist/js/materialize';
|
|
|
|
|
|
|
|
/* Global imports */
|
|
|
|
import '../_global/index';
|
2016-11-03 10:02:16 +01:00
|
|
|
|
|
|
|
/* Tools */
|
2023-07-29 12:26:44 +02:00
|
|
|
import {
|
|
|
|
initExport, initFilters, initRandom, initPreviewText,
|
|
|
|
} from './js/tools';
|
2016-11-03 10:02:16 +01:00
|
|
|
|
|
|
|
/* Import shortcuts */
|
2017-03-31 20:21:41 +02:00
|
|
|
import './js/shortcuts/main';
|
|
|
|
import './js/shortcuts/entry';
|
2016-10-04 15:30:05 +02:00
|
|
|
|
2017-03-31 20:21:41 +02:00
|
|
|
/* Theme style */
|
|
|
|
import './css/index.scss';
|
2016-03-08 17:02:34 +01:00
|
|
|
|
2020-05-06 22:20:07 +02:00
|
|
|
const mobileMaxWidth = 993;
|
|
|
|
|
2023-05-29 15:08:31 +02:00
|
|
|
(function darkTheme() {
|
2020-11-08 15:04:29 +01:00
|
|
|
const rootEl = document.querySelector('html');
|
|
|
|
const themeDom = {
|
|
|
|
darkClass: 'dark-theme',
|
|
|
|
|
|
|
|
toggleClass(el) {
|
|
|
|
return el.classList.toggle(this.darkClass);
|
|
|
|
},
|
|
|
|
|
|
|
|
addClass(el) {
|
|
|
|
return el.classList.add(this.darkClass);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeClass(el) {
|
|
|
|
return el.classList.remove(this.darkClass);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const themeCookie = {
|
|
|
|
values: {
|
|
|
|
light: 'light',
|
|
|
|
dark: 'dark',
|
|
|
|
},
|
|
|
|
|
|
|
|
name: 'theme',
|
|
|
|
|
|
|
|
getValue(isDarkTheme) {
|
|
|
|
return isDarkTheme ? this.values.dark : this.values.light;
|
|
|
|
},
|
|
|
|
|
|
|
|
setCookie(isDarkTheme) {
|
|
|
|
const value = this.getValue(isDarkTheme);
|
|
|
|
document.cookie = `${this.name}=${value};samesite=Lax;path=/;max-age=31536000`;
|
|
|
|
},
|
|
|
|
|
2020-11-19 11:38:02 +01:00
|
|
|
removeCookie() {
|
|
|
|
document.cookie = `${this.name}=auto;samesite=Lax;path=/;max-age=0`;
|
|
|
|
},
|
|
|
|
|
2020-11-08 15:04:29 +01:00
|
|
|
exists() {
|
2020-12-19 01:39:05 +01:00
|
|
|
return document.cookie.split(';').some((cookie) => cookie.trim().startsWith(`${this.name}=`));
|
2020-11-08 15:04:29 +01:00
|
|
|
},
|
|
|
|
};
|
2020-11-19 11:38:02 +01:00
|
|
|
const preferedColorScheme = {
|
|
|
|
choose() {
|
2021-02-21 22:07:23 +01:00
|
|
|
const themeCookieExists = themeCookie.exists();
|
|
|
|
if (this.isAvailable() && !themeCookieExists) {
|
2020-11-19 11:38:02 +01:00
|
|
|
const isPreferedColorSchemeDark = window.matchMedia('(prefers-color-scheme: dark)').matches === true;
|
2021-02-21 22:07:23 +01:00
|
|
|
if (!themeCookieExists) {
|
2020-11-19 11:38:02 +01:00
|
|
|
themeDom[isPreferedColorSchemeDark ? 'addClass' : 'removeClass'](rootEl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
isAvailable() {
|
|
|
|
return typeof window.matchMedia === 'function';
|
|
|
|
},
|
|
|
|
|
|
|
|
init() {
|
|
|
|
if (!this.isAvailable()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.choose();
|
|
|
|
window.matchMedia('(prefers-color-scheme: dark)').addListener(() => {
|
|
|
|
this.choose();
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
};
|
2023-05-29 15:08:31 +02:00
|
|
|
|
|
|
|
const addDarkThemeListeners = () => {
|
|
|
|
$(document).ready(() => {
|
|
|
|
const lightThemeButtons = document.querySelectorAll('.js-theme-toggle[data-theme="light"]');
|
|
|
|
[...lightThemeButtons].map((lightThemeButton) => {
|
|
|
|
lightThemeButton.addEventListener('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
themeDom.removeClass(rootEl);
|
|
|
|
themeCookie.setCookie(false);
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
const darkThemeButtons = document.querySelectorAll('.js-theme-toggle[data-theme="dark"]');
|
|
|
|
[...darkThemeButtons].map((darkThemeButton) => {
|
|
|
|
darkThemeButton.addEventListener('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
themeDom.addClass(rootEl);
|
|
|
|
themeCookie.setCookie(true);
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
const autoThemeButtons = document.querySelectorAll('.js-theme-toggle[data-theme="auto"]');
|
|
|
|
[...autoThemeButtons].map((autoThemeButton) => {
|
|
|
|
autoThemeButton.addEventListener('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
themeCookie.removeCookie();
|
|
|
|
preferedColorScheme.choose();
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
});
|
2020-11-19 11:38:02 +01:00
|
|
|
});
|
2023-05-29 15:08:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
preferedColorScheme.init();
|
|
|
|
addDarkThemeListeners();
|
|
|
|
}());
|
2020-11-08 15:04:29 +01:00
|
|
|
|
2020-01-19 12:50:08 +01:00
|
|
|
const stickyNav = () => {
|
|
|
|
const nav = $('.js-entry-nav-top');
|
|
|
|
$('[data-toggle="actions"]').click(() => {
|
|
|
|
nav.toggleClass('entry-nav-top--sticky');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-01-19 17:49:54 +01:00
|
|
|
const articleScroll = () => {
|
|
|
|
const articleEl = $('#article');
|
|
|
|
if (articleEl.length > 0) {
|
|
|
|
$(window).scroll(() => {
|
|
|
|
const s = $(window).scrollTop();
|
|
|
|
const d = $(document).height();
|
|
|
|
const c = $(window).height();
|
|
|
|
const articleElBottom = articleEl.offset().top + articleEl.height();
|
|
|
|
const scrollPercent = (s / (d - c)) * 100;
|
|
|
|
$('.progress .determinate').css('width', `${scrollPercent}%`);
|
|
|
|
const fixedActionBtn = $('.js-fixed-action-btn');
|
|
|
|
const toggleScrollDataName = 'toggle-auto';
|
|
|
|
if ((s + c) > articleElBottom) {
|
|
|
|
fixedActionBtn.data(toggleScrollDataName, true);
|
|
|
|
fixedActionBtn.openFAB();
|
|
|
|
} else if (fixedActionBtn.data(toggleScrollDataName) === true) {
|
|
|
|
fixedActionBtn.data(toggleScrollDataName, false);
|
|
|
|
fixedActionBtn.closeFAB();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-28 10:30:18 +02:00
|
|
|
$(document).ready(() => {
|
2016-06-09 19:02:38 +02:00
|
|
|
// sideNav
|
|
|
|
$('.button-collapse').sideNav();
|
|
|
|
$('select').material_select();
|
|
|
|
$('.collapsible').collapsible({
|
|
|
|
accordion: false,
|
|
|
|
});
|
|
|
|
$('.datepicker').pickadate({
|
|
|
|
selectMonths: true,
|
|
|
|
selectYears: 15,
|
2020-03-21 21:11:01 +01:00
|
|
|
formatSubmit: 'yyyy-mm-dd',
|
|
|
|
hiddenName: false,
|
|
|
|
format: 'yyyy-mm-dd',
|
2017-03-31 20:21:41 +02:00
|
|
|
container: 'body',
|
2016-06-09 19:02:38 +02:00
|
|
|
});
|
2019-01-19 22:08:29 +01:00
|
|
|
|
2020-04-21 07:58:44 +02:00
|
|
|
$('.dropdown-trigger').dropdown({ hover: false });
|
|
|
|
|
2016-06-09 19:02:38 +02:00
|
|
|
initFilters();
|
|
|
|
initExport();
|
2019-01-19 22:08:29 +01:00
|
|
|
initRandom();
|
2020-01-19 12:50:08 +01:00
|
|
|
stickyNav();
|
2020-01-19 17:49:54 +01:00
|
|
|
articleScroll();
|
2023-07-29 12:26:44 +02:00
|
|
|
initPreviewText();
|
2015-08-04 18:39:26 +02:00
|
|
|
|
2017-12-28 23:27:45 +01:00
|
|
|
const toggleNav = (toShow, toFocus) => {
|
|
|
|
$('.nav-panel-actions').hide(100);
|
|
|
|
$(toShow).show(100);
|
|
|
|
$(toFocus).focus();
|
|
|
|
};
|
|
|
|
|
2016-09-28 10:30:18 +02:00
|
|
|
$('#nav-btn-add-tag').on('click', () => {
|
2016-06-09 19:02:38 +02:00
|
|
|
$('.nav-panel-add-tag').toggle(100);
|
|
|
|
$('.nav-panel-menu').addClass('hidden');
|
2020-05-06 22:20:07 +02:00
|
|
|
if (window.innerWidth < mobileMaxWidth) {
|
|
|
|
$('.side-nav').sideNav('hide');
|
|
|
|
}
|
2016-06-09 19:02:38 +02:00
|
|
|
$('#tag_label').focus();
|
|
|
|
return false;
|
|
|
|
});
|
2018-12-02 12:43:05 +01:00
|
|
|
|
2016-09-28 10:30:18 +02:00
|
|
|
$('#nav-btn-add').on('click', () => {
|
2017-12-28 23:27:45 +01:00
|
|
|
toggleNav('.nav-panel-add', '#entry_url');
|
2016-06-09 19:02:38 +02:00
|
|
|
return false;
|
|
|
|
});
|
2018-12-02 12:43:05 +01:00
|
|
|
|
2023-07-29 12:26:44 +02:00
|
|
|
$('#config_fontsize').on('input', () => {
|
|
|
|
const value = $('#config_fontsize').val();
|
|
|
|
const css = `${value}em`;
|
|
|
|
$('#preview-content').css('font-size', css);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#config_font').on('change', () => {
|
|
|
|
const value = $('#config_font').val();
|
|
|
|
$('#preview-content').css('font-family', value);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#config_lineHeight').on('input', () => {
|
|
|
|
const value = $('#config_lineHeight').val();
|
|
|
|
const css = `${value}em`;
|
|
|
|
$('#preview-content').css('line-height', css);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#config_maxWidth').on('input', () => {
|
|
|
|
const value = $('#config_maxWidth').val();
|
|
|
|
const css = `${value}em`;
|
|
|
|
$('#preview-article').css('max-width', css);
|
|
|
|
});
|
|
|
|
|
2017-12-28 22:54:42 +01:00
|
|
|
const materialAddForm = $('.nav-panel-add');
|
2017-11-01 12:32:14 +01:00
|
|
|
materialAddForm.on('submit', () => {
|
|
|
|
materialAddForm.addClass('disabled');
|
|
|
|
$('input#entry_url', materialAddForm).prop('readonly', true).trigger('blur');
|
|
|
|
});
|
2018-12-02 12:43:05 +01:00
|
|
|
|
2016-09-28 10:30:18 +02:00
|
|
|
$('#nav-btn-search').on('click', () => {
|
2017-12-28 23:27:45 +01:00
|
|
|
toggleNav('.nav-panel-search', '#search_entry_term');
|
2016-06-09 19:02:38 +02:00
|
|
|
return false;
|
|
|
|
});
|
2018-12-02 12:43:05 +01:00
|
|
|
|
2017-12-28 23:27:45 +01:00
|
|
|
$('.close').on('click', (e) => {
|
|
|
|
$(e.target).parent('.nav-panel-item').hide(100);
|
2017-12-28 22:54:42 +01:00
|
|
|
$('.nav-panel-actions').show(100);
|
2016-06-09 19:02:38 +02:00
|
|
|
return false;
|
|
|
|
});
|
2020-04-12 16:31:12 +02:00
|
|
|
|
|
|
|
const mainCheckboxes = document.querySelectorAll('[data-js="checkboxes-toggle"]');
|
|
|
|
if (mainCheckboxes.length) {
|
|
|
|
[...mainCheckboxes].forEach((el) => {
|
|
|
|
el.addEventListener('click', () => {
|
|
|
|
const checkboxes = document.querySelectorAll(el.dataset.toggle);
|
|
|
|
[...checkboxes].forEach((checkbox) => {
|
|
|
|
const checkboxClone = checkbox;
|
|
|
|
checkboxClone.checked = el.checked;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2021-04-27 23:11:03 +02:00
|
|
|
$('form[name="form_mass_action"] input[name="tags"]').on('keydown', (e) => {
|
|
|
|
if (e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
$('form[name="form_mass_action"] button[name="tag"]').trigger('click');
|
|
|
|
}
|
|
|
|
});
|
2015-08-11 18:07:02 +02:00
|
|
|
});
|