2016-10-26 23:57:27 +00:00
|
|
|
import $ from 'jquery';
|
2016-11-03 09:02:16 +00:00
|
|
|
|
2017-03-31 18:21:41 +00:00
|
|
|
/* Materialize imports */
|
|
|
|
import 'materialize-css/dist/css/materialize.css';
|
|
|
|
import 'materialize-css/dist/js/materialize';
|
|
|
|
|
|
|
|
/* Global imports */
|
|
|
|
import '../_global/index';
|
2016-11-03 09:02:16 +00:00
|
|
|
|
|
|
|
/* Tools */
|
2019-01-19 21:08:29 +00:00
|
|
|
import { initExport, initFilters, initRandom } from './js/tools';
|
2016-11-03 09:02:16 +00:00
|
|
|
|
|
|
|
/* Import shortcuts */
|
2017-03-31 18:21:41 +00:00
|
|
|
import './js/shortcuts/main';
|
|
|
|
import './js/shortcuts/entry';
|
2016-10-04 13:30:05 +00:00
|
|
|
|
2017-03-31 18:21:41 +00:00
|
|
|
/* Theme style */
|
|
|
|
import './css/index.scss';
|
2016-03-08 16:02:34 +00:00
|
|
|
|
2020-01-19 11:50:08 +00:00
|
|
|
const stickyNav = () => {
|
|
|
|
const nav = $('.js-entry-nav-top');
|
|
|
|
$('[data-toggle="actions"]').click(() => {
|
|
|
|
nav.toggleClass('entry-nav-top--sticky');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-01-19 16:49:54 +00: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 08:30:18 +00:00
|
|
|
$(document).ready(() => {
|
2016-06-09 17:02:38 +00:00
|
|
|
// sideNav
|
|
|
|
$('.button-collapse').sideNav();
|
|
|
|
$('select').material_select();
|
|
|
|
$('.collapsible').collapsible({
|
|
|
|
accordion: false,
|
|
|
|
});
|
|
|
|
$('.datepicker').pickadate({
|
|
|
|
selectMonths: true,
|
|
|
|
selectYears: 15,
|
2020-03-21 20:11:01 +00:00
|
|
|
formatSubmit: 'yyyy-mm-dd',
|
|
|
|
hiddenName: false,
|
|
|
|
format: 'yyyy-mm-dd',
|
2017-03-31 18:21:41 +00:00
|
|
|
container: 'body',
|
2016-06-09 17:02:38 +00:00
|
|
|
});
|
2019-01-19 21:08:29 +00:00
|
|
|
|
2016-06-09 17:02:38 +00:00
|
|
|
initFilters();
|
|
|
|
initExport();
|
2019-01-19 21:08:29 +00:00
|
|
|
initRandom();
|
2020-01-19 11:50:08 +00:00
|
|
|
stickyNav();
|
2020-01-19 16:49:54 +00:00
|
|
|
articleScroll();
|
2015-08-04 16:39:26 +00:00
|
|
|
|
2017-12-28 22:27:45 +00:00
|
|
|
const toggleNav = (toShow, toFocus) => {
|
|
|
|
$('.nav-panel-actions').hide(100);
|
|
|
|
$(toShow).show(100);
|
|
|
|
$('.nav-panels').css('background', 'white');
|
|
|
|
$(toFocus).focus();
|
|
|
|
};
|
|
|
|
|
2016-09-28 08:30:18 +00:00
|
|
|
$('#nav-btn-add-tag').on('click', () => {
|
2016-06-09 17:02:38 +00:00
|
|
|
$('.nav-panel-add-tag').toggle(100);
|
|
|
|
$('.nav-panel-menu').addClass('hidden');
|
|
|
|
$('#tag_label').focus();
|
|
|
|
return false;
|
|
|
|
});
|
2018-12-02 11:43:05 +00:00
|
|
|
|
2016-09-28 08:30:18 +00:00
|
|
|
$('#nav-btn-add').on('click', () => {
|
2017-12-28 22:27:45 +00:00
|
|
|
toggleNav('.nav-panel-add', '#entry_url');
|
2016-06-09 17:02:38 +00:00
|
|
|
return false;
|
|
|
|
});
|
2018-12-02 11:43:05 +00:00
|
|
|
|
2017-12-28 21:54:42 +00:00
|
|
|
const materialAddForm = $('.nav-panel-add');
|
2017-11-01 11:32:14 +00:00
|
|
|
materialAddForm.on('submit', () => {
|
|
|
|
materialAddForm.addClass('disabled');
|
|
|
|
$('input#entry_url', materialAddForm).prop('readonly', true).trigger('blur');
|
|
|
|
});
|
2018-12-02 11:43:05 +00:00
|
|
|
|
2016-09-28 08:30:18 +00:00
|
|
|
$('#nav-btn-search').on('click', () => {
|
2017-12-28 22:27:45 +00:00
|
|
|
toggleNav('.nav-panel-search', '#search_entry_term');
|
2016-06-09 17:02:38 +00:00
|
|
|
return false;
|
|
|
|
});
|
2018-12-02 11:43:05 +00:00
|
|
|
|
2017-12-28 22:27:45 +00:00
|
|
|
$('.close').on('click', (e) => {
|
|
|
|
$(e.target).parent('.nav-panel-item').hide(100);
|
2017-12-28 21:54:42 +00:00
|
|
|
$('.nav-panel-actions').show(100);
|
2016-06-09 17:02:38 +00:00
|
|
|
$('.nav-panels').css('background', 'transparent');
|
|
|
|
return false;
|
|
|
|
});
|
2015-08-11 16:07:02 +00:00
|
|
|
});
|