Fix dirty style updating. Closes #585
This commit is contained in:
parent
e97a3ef269
commit
50d70b0de0
|
@ -9,7 +9,7 @@
|
||||||
function createSectionsEditor(style) {
|
function createSectionsEditor(style) {
|
||||||
let INC_ID = 0; // an increment id that is used by various object to track the order
|
let INC_ID = 0; // an increment id that is used by various object to track the order
|
||||||
const dirty = dirtyReporter();
|
const dirty = dirtyReporter();
|
||||||
dirty.onChange(updateTitle);
|
dirty.onChange(updateDirty);
|
||||||
|
|
||||||
const container = $('#sections');
|
const container = $('#sections');
|
||||||
const sections = [];
|
const sections = [];
|
||||||
|
@ -18,7 +18,7 @@ function createSectionsEditor(style) {
|
||||||
nameEl.addEventListener('input', () => {
|
nameEl.addEventListener('input', () => {
|
||||||
dirty.modify('name', style.name, nameEl.value);
|
dirty.modify('name', style.name, nameEl.value);
|
||||||
style.name = nameEl.value;
|
style.name = nameEl.value;
|
||||||
updateTitle();
|
updateDirty();
|
||||||
});
|
});
|
||||||
|
|
||||||
const enabledEl = $('#enabled');
|
const enabledEl = $('#enabled');
|
||||||
|
@ -413,7 +413,7 @@ function createSectionsEditor(style) {
|
||||||
nameEl.value = style.name || '';
|
nameEl.value = style.name || '';
|
||||||
enabledEl.checked = style.enabled !== false;
|
enabledEl.checked = style.enabled !== false;
|
||||||
$('#url').href = style.url || '';
|
$('#url').href = style.url || '';
|
||||||
updateTitle();
|
updateDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLivePreview() {
|
function updateLivePreview() {
|
||||||
|
@ -424,12 +424,12 @@ function createSectionsEditor(style) {
|
||||||
livePreview.update(getModel());
|
livePreview.update(getModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTitle() {
|
function updateDirty() {
|
||||||
const name = style.name;
|
const isDirty = dirty.isDirty();
|
||||||
const clean = !dirty.isDirty();
|
const name = style.id ? style.name : t('addStyleTitle');
|
||||||
const title = !style.id ? t('addStyleTitle') : name;
|
document.title = (isDirty ? '* ' : '') + name;
|
||||||
document.title = (clean ? '' : '* ') + title;
|
document.body.classList.toggle('dirty', isDirty);
|
||||||
$('#save-button').disabled = clean;
|
$('#save-button').disabled = !isDirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
function initSection({
|
function initSection({
|
||||||
|
|
|
@ -16,12 +16,7 @@ function createSourceEditor(style) {
|
||||||
$('#sections').appendChild($create('.single-editor'));
|
$('#sections').appendChild($create('.single-editor'));
|
||||||
|
|
||||||
const dirty = dirtyReporter();
|
const dirty = dirtyReporter();
|
||||||
dirty.onChange(() => {
|
dirty.onChange(updateDirty);
|
||||||
const isDirty = dirty.isDirty();
|
|
||||||
document.body.classList.toggle('dirty', isDirty);
|
|
||||||
$('#save-button').disabled = !isDirty;
|
|
||||||
updateTitle();
|
|
||||||
});
|
|
||||||
|
|
||||||
// normalize style
|
// normalize style
|
||||||
if (!style.id) setupNewStyle(style);
|
if (!style.id) setupNewStyle(style);
|
||||||
|
@ -171,16 +166,16 @@ function createSourceEditor(style) {
|
||||||
$('#name').value = style.name;
|
$('#name').value = style.name;
|
||||||
$('#enabled').checked = style.enabled;
|
$('#enabled').checked = style.enabled;
|
||||||
$('#url').href = style.url;
|
$('#url').href = style.url;
|
||||||
updateTitle();
|
updateDirty();
|
||||||
return cm.setPreprocessor((style.usercssData || {}).preprocessor);
|
return cm.setPreprocessor((style.usercssData || {}).preprocessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTitle() {
|
function updateDirty() {
|
||||||
const newTitle = (dirty.isDirty() ? '* ' : '') +
|
const isDirty = dirty.isDirty();
|
||||||
(style.id ? style.name : t('addStyleTitle'));
|
const name = style.id ? style.name : t('addStyleTitle');
|
||||||
if (document.title !== newTitle) {
|
document.title = (isDirty ? '* ' : '') + name;
|
||||||
document.title = newTitle;
|
document.body.classList.toggle('dirty', isDirty);
|
||||||
}
|
$('#save-button').disabled = !isDirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceStyle(newStyle, codeIsUpdated) {
|
function replaceStyle(newStyle, codeIsUpdated) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user