Skip to content

Commit 92f31b1

Browse files
committed
Better save function.
1 parent 2c09a49 commit 92f31b1

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

scripts/app.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ async function init() {
55
$titleSub = document.getElementById('titleSub')
66

77
const settingsDefault = {
8-
subtitle: 'DISCIPLINE EQUALS FREEDOM',
98
titleMain: 'GET AFTER IT',
109
titleSub: 'STANDBY TO GET SOME',
11-
colorBackground: '#101318',
12-
colorText: '#222830',
10+
colorBackground: 'rgba(16, 19, 24, 1)',
11+
colorText: 'rgba(34, 40, 48, 1)',
1312
}
1413

1514
let settings = { ...settingsDefault }
@@ -26,7 +25,7 @@ async function init() {
2625
function saveOptions() {
2726
return new Promise((resolve, reject) => {
2827
for (const key of Object.keys(settings)) {
29-
console.log(`settings[key]:`, settings[key])
28+
console.log(`settings[${key}]:`, settings[key])
3029
settings[key] = settings[key].trim()
3130
if (typeof settings[key] !== 'string' || !settings[key] || settings[key] === '') {
3231
settings[key] = 'UNDEFINED'
@@ -51,7 +50,6 @@ async function init() {
5150
e.preventDefault()
5251
e.stopPropagation()
5352
console.log(`Editing:`, key)
54-
console.log(`e:`, e.target)
5553
e.target.contentEditable = true
5654
e.target.focus()
5755
document.execCommand('selectAll',false,null)
@@ -62,7 +60,6 @@ async function init() {
6260
return async (e) => {
6361
e.preventDefault()
6462
console.log(`Blured:`, key)
65-
console.log(`e:`, e)
6663
let text = e.target.innerText.trim()
6764
if (typeof text !== 'string' || text === '' || !text) {
6865
text = settingsDefault[key]
@@ -112,12 +109,9 @@ async function init() {
112109
parent: pickerParentColorText,
113110
color: settings.colorText,
114111
})
115-
116112
function pickerOnChange(key) {
117-
return async (color) => {
113+
return (color) => {
118114
setColorForKey(key, color.rgbaString)
119-
settings[key] = color.rgbaString
120-
await saveOptions()
121115
}
122116
}
123117
function pickerOnDone(key) {
@@ -129,10 +123,11 @@ async function init() {
129123

130124
pickerColorBackground.onChange = pickerOnChange('colorBackground')
131125
pickerColorBackground.onDone = pickerOnDone('colorBackground')
126+
pickerColorBackground.onClose = pickerOnDone('colorBackground')
127+
132128
pickerColorText.onChange = pickerOnChange('colorText')
133129
pickerColorText.onDone = pickerOnDone('colorText')
134-
135-
// onDone is similar to onChange, but only called when you click 'Ok'.
130+
pickerColorText.onClose = pickerOnDone('colorText')
136131
}
137132

138133
$main.addEventListener('dblclick', openOptions)

0 commit comments

Comments
 (0)