tangled
alpha
login
or
join now
j0.lol
/
bog
1
fork
atom
Blog attempt 5
1
fork
atom
overview
issues
1
pulls
pipelines
Remove redundant post-editor.js code & make more robust
j0.lol
3 months ago
8235930d
2078cdaf
+28
-57
2 changed files
expand all
collapse all
unified
split
static
css
style.css
js
post-editor.js
+4
static/css/style.css
···
769
769
border: 1px solid rebeccapurple;
770
770
border-radius: 0.3rem;
771
771
}
772
772
+
#editorPreview.error {
773
773
+
border: 1px solid red;
774
774
+
border-radius: 0;
775
775
+
}
772
776
773
777
.editorInnerWrapper {
774
778
display: flex;
+24
-57
static/js/post-editor.js
···
8
8
const editorPreview = document.querySelector("#editorPreview");
9
9
10
10
function preview(render) {
11
11
-
editorPreview.innerHTML = `
12
12
-
<h1 class="blog-head">${inputTitle.value}</h1>
13
13
-
<span class="blog-subhead"><em>${inputSubtitle.value}</em></span>
14
14
-
<p class='blog-publish'>
15
15
-
🕒 ${inputDt.value}
16
16
-
</p>
17
17
-
<hr class='frontmatter'>
18
18
-
`;
19
19
-
editorPreview.innerHTML += render;
11
11
+
if (render !== false) {
12
12
+
editorPreview.classList.remove("error");
13
13
+
editorPreview.innerHTML = `
14
14
+
<h1 class="blog-head">${inputTitle.value}</h1>
15
15
+
<span class="blog-subhead"><em>${inputSubtitle.value}</em></span>
16
16
+
<p class='blog-publish'>
17
17
+
🕒 ${inputDt.value}
18
18
+
</p>
19
19
+
<hr class='frontmatter'>
20
20
+
`;
21
21
+
editorPreview.innerHTML += render;
22
22
+
} else {
23
23
+
editorPreview.classList.add("error");
24
24
+
}
20
25
}
21
26
22
27
// Enhanced editor features
···
67
72
}
68
73
69
74
updatePreview(false);
70
70
-
highlightAll();
71
75
}
72
76
});
73
77
};
···
90
94
el.selectionStart = el.selectionEnd = caretPos;
91
95
92
96
updatePreview(false);
93
93
-
highlightAll();
94
97
});
95
98
};
96
99
···
106
109
el.selectionStart = el.selectionEnd = selectionStart - 4;
107
110
108
111
updatePreview(false);
109
109
-
highlightAll();
110
112
}
111
113
});
112
114
};
···
137
139
handleBackspace(el);
138
140
};
139
141
140
140
-
// SpeechBox web component
141
141
-
class SpeechBoxElement extends HTMLElement {
142
142
-
connectedCallback() {
143
143
-
const char = this.getAttribute("character");
144
144
-
const emotion = this.getAttribute("emotion");
145
145
-
146
146
-
const images = {
147
147
-
deer: {
148
148
-
neutral: {
149
149
-
src: "/static/speech/deer/neutral.png",
150
150
-
alt: "drawing of a deer, talking to you.",
151
151
-
},
152
152
-
happy: {
153
153
-
src: "/static/speech/deer/happy.png",
154
154
-
alt: "drawing of a happy deer.",
155
155
-
},
156
156
-
shocked: {
157
157
-
src: "/static/speech/deer/shock.png",
158
158
-
alt: "drawing of a shocked deer.",
159
159
-
},
160
160
-
worried: {
161
161
-
src: "/static/speech/deer/sad.png",
162
162
-
alt: "drawing of a sad or worried deer.",
163
163
-
},
164
164
-
},
165
165
-
you: { src: "/static/speech/you.png", alt: "drawing of you, smiling." },
166
166
-
};
167
167
-
168
168
-
const { src, alt } =
169
169
-
images[char]?.[emotion] || images[char]?.neutral || images.deer;
170
170
-
171
171
-
this.innerHTML = `
172
172
-
<div class="dialog-box">
173
173
-
<img width="120" height="120" class="raw dialog profile" src="${src}" alt="${alt}">
174
174
-
<div class="dialog speech ${char}">
175
175
-
${this.innerHTML}
176
176
-
</div>
177
177
-
</div>`;
178
178
-
}
179
179
-
}
180
180
-
181
181
-
customElements.define("speech-box", SpeechBoxElement);
182
182
-
183
142
async function syncDraft() {
184
143
const resp = await fetch(`/blog/new/sync`, {
185
144
method: "POST",
···
195
154
}),
196
155
});
197
156
198
198
-
return await resp.text();
157
157
+
if (resp.ok) {
158
158
+
return await resp.text();
159
159
+
} else {
160
160
+
return false
161
161
+
}
199
162
}
200
163
201
164
···
208
171
}),
209
172
});
210
173
211
211
-
return await resp.text();
174
174
+
if (resp.ok) {
175
175
+
return await resp.text();
176
176
+
} else {
177
177
+
return false
178
178
+
}
212
179
}
213
180
214
181
async function updatePreview(sync = false) {