Some code tweaks

This commit is contained in:
Rob Garrison 2019-07-24 16:32:46 -05:00
parent a023e8829c
commit d1fd94c8f3

View File

@ -174,7 +174,10 @@ preinit();
$('#preview-label').classList.toggle('hidden', !style.id); $('#preview-label').classList.toggle('hidden', !style.id);
$('#beautify').onclick = () => beautify(editor.getEditors()); $('#beautify').onclick = () => beautify(editor.getEditors());
window.addEventListener('resize', () => { debounce(rememberWindowSize, 100); detectLayout(); }); window.addEventListener('resize', () => {
debounce(rememberWindowSize, 100);
detectLayout();
});
detectLayout(); detectLayout();
editor = (usercss ? createSourceEditor : createSectionsEditor)({ editor = (usercss ? createSourceEditor : createSectionsEditor)({
style, style,
@ -494,62 +497,61 @@ function rememberWindowSize() {
} }
prefs.subscribe(['editor.linter'], (key, value) => { prefs.subscribe(['editor.linter'], (key, value) => {
if (value === '') { $('body').classList.toggle('linter-disabled', value === '');
document.body.classList.add('linter-disabled');
} else {
document.body.classList.remove('linter-disabled');
}
}); });
function fixedHeader() { function fixedHeader() {
const scrollPoint = $('#header').clientHeight - 40; const scrollPoint = $('#header').clientHeight - 40;
const linterEnabled = prefs.get('editor.linter') !== ''; const linterEnabled = prefs.get('editor.linter') !== '';
if (window.scrollY >= scrollPoint && !$('.fixed-header') && linterEnabled) { if (window.scrollY >= scrollPoint && !$('.fixed-header') && linterEnabled) {
document.body.classList.add('fixed-header'); $('body').classList.add('fixed-header');
} else if (window.scrollY < 40 && linterEnabled) { } else if (window.scrollY < 40 && linterEnabled) {
document.body.classList.remove('fixed-header'); $('body').classList.remove('fixed-header');
} }
} }
function detectLayout() { function detectLayout() {
const body = $('body');
const options = $('#options');
const lint = $('#lint');
const compact = window.innerWidth <= 850; const compact = window.innerWidth <= 850;
const shortViewportLinter = window.innerHeight < 692; const shortViewportLinter = window.innerHeight < 692;
const shortViewportNoLinter = window.innerHeight < 554; const shortViewportNoLinter = window.innerHeight < 554;
const linterEnabled = prefs.get('editor.linter') !== ''; const linterEnabled = prefs.get('editor.linter') !== '';
if (compact) { if (compact) {
document.body.classList.add('compact-layout'); body.classList.add('compact-layout');
$('#options').removeAttribute('open'); options.removeAttribute('open');
$('#options').classList.add('ignore-pref'); options.classList.add('ignore-pref');
$('#lint').removeAttribute('open'); lint.removeAttribute('open');
$('#lint').classList.add('ignore-pref'); lint.classList.add('ignore-pref');
if (!$('.usercss')) { if (!$('.usercss')) {
clearTimeout(scrollPointTimer); clearTimeout(scrollPointTimer);
scrollPointTimer = setTimeout(() => { scrollPointTimer = setTimeout(() => {
const scrollPoint = $('#header').clientHeight - 40; const scrollPoint = $('#header').clientHeight - 40;
if (window.scrollY >= scrollPoint && !$('.fixed-header') && linterEnabled) { if (window.scrollY >= scrollPoint && !$('.fixed-header') && linterEnabled) {
document.body.classList.add('fixed-header'); body.classList.add('fixed-header');
} }
}, 250); }, 250);
window.addEventListener('scroll', fixedHeader); window.addEventListener('scroll', fixedHeader);
} }
} else { } else {
document.body.classList.remove('compact-layout'); body.classList.remove('compact-layout');
document.body.classList.remove('fixed-header'); body.classList.remove('fixed-header');
window.removeEventListener('scroll', fixedHeader); window.removeEventListener('scroll', fixedHeader);
if (shortViewportLinter && linterEnabled || shortViewportNoLinter && !linterEnabled) { if (shortViewportLinter && linterEnabled || shortViewportNoLinter && !linterEnabled) {
$('#options').removeAttribute('open'); options.removeAttribute('open');
$('#options').classList.add('ignore-pref'); options.classList.add('ignore-pref');
if (prefs.get('editor.lint.expanded')) { if (prefs.get('editor.lint.expanded')) {
$('#lint').setAttribute('open', ''); lint.setAttribute('open', '');
} }
} else { } else {
$('#options').classList.remove('ignore-pref'); options.classList.remove('ignore-pref');
$('#lint').classList.remove('ignore-pref'); lint.classList.remove('ignore-pref');
if (prefs.get('editor.options.expanded')) { if (prefs.get('editor.options.expanded')) {
$('#options').setAttribute('open', ''); options.setAttribute('open', '');
} }
if (prefs.get('editor.lint.expanded')) { if (prefs.get('editor.lint.expanded')) {
$('#lint').setAttribute('open', ''); lint.setAttribute('open', '');
} }
} }
} }