FIX: better detection of default value

This commit is contained in:
jjaffeux 2020-04-20 20:39:54 +02:00
parent f947865904
commit e49d7411e5
1 changed files with 11 additions and 5 deletions

View File

@ -112,11 +112,13 @@ export default {
function processChange(inputEvent) { function processChange(inputEvent) {
const value = inputEvent.target.value; const value = inputEvent.target.value;
const key = inputEvent.target.dataset.key; const key = inputEvent.target.dataset.key;
const delimiter = inputEvent.target.dataset.delimiter; const placeholder = placeholders[inputEvent.target.dataset.key];
const placeholderIdentifier = `${postIdentifier}${key}`; const placeholderIdentifier = `${postIdentifier}${key}`;
if (value) { if (value) {
if (value !== placeholder.default) {
$.cookie(placeholderIdentifier, value); $.cookie(placeholderIdentifier, value);
}
} else { } else {
$.removeCookie(placeholderIdentifier); $.removeCookie(placeholderIdentifier);
} }
@ -126,7 +128,7 @@ export default {
newValue = value; newValue = value;
clearButton.disabled = false; clearButton.disabled = false;
} else { } else {
newValue = `${delimiter}${key}${delimiter}`; newValue = `${placeholder.delimiter}${key}${placeholder.delimiter}`;
} }
$cooked.find(VALID_TAGS).each((index, elem) => { $cooked.find(VALID_TAGS).each((index, elem) => {
@ -139,7 +141,10 @@ export default {
let newInnnerHTML = elem.innerHTML; let newInnnerHTML = elem.innerHTML;
mapping.forEach(m => { mapping.forEach(m => {
if (m.pattern !== `${delimiter}${key}${delimiter}`) { if (
m.pattern !==
`${placeholder.delimiter}${key}${placeholder.delimiter}`
) {
m.position = m.position + diff; m.position = m.position + diff;
return; return;
} }
@ -198,7 +203,8 @@ export default {
Object.keys(placeholders).forEach(placeholderKey => { Object.keys(placeholders).forEach(placeholderKey => {
const placeholder = placeholders[placeholderKey]; const placeholder = placeholders[placeholderKey];
const placeholderIdentifier = `${postIdentifier}${placeholderKey}`; const placeholderIdentifier = `${postIdentifier}${placeholderKey}`;
const value = $.cookie(placeholderIdentifier); const value =
$.cookie(placeholderIdentifier) || placeholder.default;
if (value) { if (value) {
clearButton.disabled = false; clearButton.disabled = false;