Fix dirty style updating. Closes #585

This commit is contained in:
Rob Garrison 2018-11-26 17:56:16 -06:00
parent e97a3ef269
commit 50d70b0de0
2 changed files with 17 additions and 22 deletions

View File

@ -9,7 +9,7 @@
function createSectionsEditor(style) {
let INC_ID = 0; // an increment id that is used by various object to track the order
const dirty = dirtyReporter();
dirty.onChange(updateTitle);
dirty.onChange(updateDirty);
const container = $('#sections');
const sections = [];
@ -18,7 +18,7 @@ function createSectionsEditor(style) {
nameEl.addEventListener('input', () => {
dirty.modify('name', style.name, nameEl.value);
style.name = nameEl.value;
updateTitle();
updateDirty();
});
const enabledEl = $('#enabled');
@ -413,7 +413,7 @@ function createSectionsEditor(style) {
nameEl.value = style.name || '';
enabledEl.checked = style.enabled !== false;
$('#url').href = style.url || '';
updateTitle();
updateDirty();
}
function updateLivePreview() {
@ -424,12 +424,12 @@ function createSectionsEditor(style) {
livePreview.update(getModel());
}
function updateTitle() {
const name = style.name;
const clean = !dirty.isDirty();
const title = !style.id ? t('addStyleTitle') : name;
document.title = (clean ? '' : '* ') + title;
$('#save-button').disabled = clean;
function updateDirty() {
const isDirty = dirty.isDirty();
const name = style.id ? style.name : t('addStyleTitle');
document.title = (isDirty ? '* ' : '') + name;
document.body.classList.toggle('dirty', isDirty);
$('#save-button').disabled = !isDirty;
}
function initSection({

View File

@ -16,12 +16,7 @@ function createSourceEditor(style) {
$('#sections').appendChild($create('.single-editor'));
const dirty = dirtyReporter();
dirty.onChange(() => {
const isDirty = dirty.isDirty();
document.body.classList.toggle('dirty', isDirty);
$('#save-button').disabled = !isDirty;
updateTitle();
});
dirty.onChange(updateDirty);
// normalize style
if (!style.id) setupNewStyle(style);
@ -171,16 +166,16 @@ function createSourceEditor(style) {
$('#name').value = style.name;
$('#enabled').checked = style.enabled;
$('#url').href = style.url;
updateTitle();
updateDirty();
return cm.setPreprocessor((style.usercssData || {}).preprocessor);
}
function updateTitle() {
const newTitle = (dirty.isDirty() ? '* ' : '') +
(style.id ? style.name : t('addStyleTitle'));
if (document.title !== newTitle) {
document.title = newTitle;
}
function updateDirty() {
const isDirty = dirty.isDirty();
const name = style.id ? style.name : t('addStyleTitle');
document.title = (isDirty ? '* ' : '') + name;
document.body.classList.toggle('dirty', isDirty);
$('#save-button').disabled = !isDirty;
}
function replaceStyle(newStyle, codeIsUpdated) {