Skip to content

Commit f94e37a

Browse files
committed
Format JS with Prettier
Having a .prettierrc means anybody who uses format-on-save will automatically follow project conventions.
1 parent 3da495e commit f94e37a

File tree

5 files changed

+201
-184
lines changed

5 files changed

+201
-184
lines changed

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false
4+
}

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode"
4+
}

silicon/static/js/edit.js

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,95 @@
11
// object for editor state
22
var editor = {
3-
changed: false,
4-
submit_clicked: false,
3+
changed: false,
4+
submit_clicked: false,
55
};
66

7-
if (silicon_editor === 'codemirror') {
8-
var cm_instance;
7+
if (silicon_editor === "codemirror") {
8+
var cm_instance;
99
}
1010

1111
function usurp_unload(e) {
12-
e.preventDefault();
13-
e.returnValue = '';
12+
e.preventDefault();
13+
e.returnValue = "";
1414
}
1515

16-
window.addEventListener("load", function() {
17-
// load CodeMirror instance
18-
if (silicon_editor === 'codemirror') {
19-
require.config({
20-
baseUrl: js_modules_root
21-
});
22-
23-
require([
24-
"lib/codemirror",
25-
"mode/markdown/markdown",
26-
"mode/clike/clike",
27-
"mode/css/css",
28-
"mode/diff/diff",
29-
"mode/dockerfile/dockerfile",
30-
"mode/gfm/gfm",
31-
"mode/htmlmixed/htmlmixed",
32-
"mode/jinja2/jinja2",
33-
"mode/python/python",
34-
"mode/shell/shell",
35-
"mode/sql/sql",
36-
"mode/yaml/yaml",
37-
"addon/display/fullscreen",
38-
"addon/display/panel",
39-
].map(x => `codemirror/${x}`), function(CodeMirror) {
40-
cm_instance = CodeMirror.fromTextArea(document.querySelector('#body-text'), {
41-
mode: {
42-
name: 'gfm',
43-
gitHubSpice: false,
44-
},
45-
lineSeparator: '\n',
46-
lineWrapping: true,
47-
extraKeys: {
48-
// home/end shouldn't go to the beginning/end of paragraphs
49-
Home: 'goLineLeft',
50-
End: 'goLineRight',
51-
// do not redefine the browser history navigation keys
52-
'Alt-Left': false,
53-
'Alt-Right': false
54-
},
55-
autofocus: true,
56-
// appears to do nothing
57-
spellcheck: true,
58-
viewportMargin: Infinity,
59-
});
60-
});
61-
}
16+
window.addEventListener("load", function () {
17+
// load CodeMirror instance
18+
if (silicon_editor === "codemirror") {
19+
require.config({
20+
baseUrl: js_modules_root,
21+
});
6222

63-
// mark the editor as changed if there is an alert shown
64-
// (implies there was an error saving)
65-
if (document.querySelector('#alerts') !== null) {
66-
editor.changed = true;
67-
};
23+
require([
24+
"lib/codemirror",
25+
"mode/markdown/markdown",
26+
"mode/clike/clike",
27+
"mode/css/css",
28+
"mode/diff/diff",
29+
"mode/dockerfile/dockerfile",
30+
"mode/gfm/gfm",
31+
"mode/htmlmixed/htmlmixed",
32+
"mode/jinja2/jinja2",
33+
"mode/python/python",
34+
"mode/shell/shell",
35+
"mode/sql/sql",
36+
"mode/yaml/yaml",
37+
"addon/display/fullscreen",
38+
"addon/display/panel",
39+
].map((x) => `codemirror/${x}`), function (CodeMirror) {
40+
cm_instance = CodeMirror.fromTextArea(
41+
document.querySelector("#body-text"),
42+
{
43+
mode: {
44+
name: "gfm",
45+
gitHubSpice: false,
46+
},
47+
lineSeparator: "\n",
48+
lineWrapping: true,
49+
extraKeys: {
50+
// home/end shouldn't go to the beginning/end of paragraphs
51+
Home: "goLineLeft",
52+
End: "goLineRight",
53+
// do not redefine the browser history navigation keys
54+
"Alt-Left": false,
55+
"Alt-Right": false,
56+
},
57+
autofocus: true,
58+
// appears to do nothing
59+
spellcheck: true,
60+
viewportMargin: Infinity,
61+
}
62+
);
63+
});
64+
}
6865

69-
// mark the editor as changed if the textarea has changed
70-
document.querySelector('#body-text')
71-
.addEventListener('input', (event) => editor.changed = true);
66+
// mark the editor as changed if there is an alert shown
67+
// (implies there was an error saving)
68+
if (document.querySelector("#alerts") !== null) {
69+
editor.changed = true;
70+
}
7271

73-
// don't nag if the Submit button was clicked
74-
document.querySelector('#page-form').onsubmit = function() {
75-
editor.submit_clicked = true;
76-
};
72+
// mark the editor as changed if the textarea has changed
73+
document
74+
.querySelector("#body-text")
75+
.addEventListener("input", (event) => (editor.changed = true));
7776

78-
window.addEventListener('beforeunload', function (e) {
79-
if (silicon_editor === 'codemirror') {
80-
// alert on changed codemirror
81-
if ((! cm_instance.isClean() && ! editor.submit_clicked)) {
82-
usurp_unload(e);
83-
}
84-
} else {
85-
// alert on changed textarea
86-
if ((editor.changed && ! editor.submit_clicked)) {
87-
usurp_unload(e);
88-
};
89-
}
90-
});
77+
// don't nag if the Submit button was clicked
78+
document.querySelector("#page-form").onsubmit = function () {
79+
editor.submit_clicked = true;
80+
};
9181

82+
window.addEventListener("beforeunload", function (e) {
83+
if (silicon_editor === "codemirror") {
84+
// alert on changed codemirror
85+
if (!cm_instance.isClean() && !editor.submit_clicked) {
86+
usurp_unload(e);
87+
}
88+
} else {
89+
// alert on changed textarea
90+
if (editor.changed && !editor.submit_clicked) {
91+
usurp_unload(e);
92+
}
93+
}
94+
});
9295
});

silicon/static/js/main.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
window.addEventListener("load", function() {
2-
/* Toggle nav sidebar in "mobile" mode */
3-
document.querySelector("[data-toggle='nav-top']")
4-
.addEventListener('click', (event) => {
5-
const elements = document.querySelectorAll("[data-toggle='nav-shift']");
1+
window.addEventListener("load", function () {
2+
/* Toggle nav sidebar in "mobile" mode */
3+
document
4+
.querySelector("[data-toggle='nav-top']")
5+
.addEventListener("click", (event) => {
6+
const elements = document.querySelectorAll("[data-toggle='nav-shift']");
67

7-
elements.forEach(function(element) {
8-
element.classList.toggle('shift');
9-
})
10-
})
8+
elements.forEach(function (element) {
9+
element.classList.toggle("shift");
10+
});
11+
});
1112
});

0 commit comments

Comments
 (0)