-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Having a .prettierrc means anybody who uses format-on-save will automatically follow project conventions.
- Loading branch information
Showing
5 changed files
with
201 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,95 @@ | ||
// object for editor state | ||
var editor = { | ||
changed: false, | ||
submit_clicked: false, | ||
changed: false, | ||
submit_clicked: false, | ||
}; | ||
|
||
if (silicon_editor === 'codemirror') { | ||
var cm_instance; | ||
if (silicon_editor === "codemirror") { | ||
var cm_instance; | ||
} | ||
|
||
function usurp_unload(e) { | ||
e.preventDefault(); | ||
e.returnValue = ''; | ||
e.preventDefault(); | ||
e.returnValue = ""; | ||
} | ||
|
||
window.addEventListener("load", function() { | ||
// load CodeMirror instance | ||
if (silicon_editor === 'codemirror') { | ||
require.config({ | ||
baseUrl: js_modules_root | ||
}); | ||
|
||
require([ | ||
"lib/codemirror", | ||
"mode/markdown/markdown", | ||
"mode/clike/clike", | ||
"mode/css/css", | ||
"mode/diff/diff", | ||
"mode/dockerfile/dockerfile", | ||
"mode/gfm/gfm", | ||
"mode/htmlmixed/htmlmixed", | ||
"mode/jinja2/jinja2", | ||
"mode/python/python", | ||
"mode/shell/shell", | ||
"mode/sql/sql", | ||
"mode/yaml/yaml", | ||
"addon/display/fullscreen", | ||
"addon/display/panel", | ||
].map(x => `codemirror/${x}`), function(CodeMirror) { | ||
cm_instance = CodeMirror.fromTextArea(document.querySelector('#body-text'), { | ||
mode: { | ||
name: 'gfm', | ||
gitHubSpice: false, | ||
}, | ||
lineSeparator: '\n', | ||
lineWrapping: true, | ||
extraKeys: { | ||
// home/end shouldn't go to the beginning/end of paragraphs | ||
Home: 'goLineLeft', | ||
End: 'goLineRight', | ||
// do not redefine the browser history navigation keys | ||
'Alt-Left': false, | ||
'Alt-Right': false | ||
}, | ||
autofocus: true, | ||
// appears to do nothing | ||
spellcheck: true, | ||
viewportMargin: Infinity, | ||
}); | ||
}); | ||
} | ||
window.addEventListener("load", function () { | ||
// load CodeMirror instance | ||
if (silicon_editor === "codemirror") { | ||
require.config({ | ||
baseUrl: js_modules_root, | ||
}); | ||
|
||
// mark the editor as changed if there is an alert shown | ||
// (implies there was an error saving) | ||
if (document.querySelector('#alerts') !== null) { | ||
editor.changed = true; | ||
}; | ||
require([ | ||
"lib/codemirror", | ||
"mode/markdown/markdown", | ||
"mode/clike/clike", | ||
"mode/css/css", | ||
"mode/diff/diff", | ||
"mode/dockerfile/dockerfile", | ||
"mode/gfm/gfm", | ||
"mode/htmlmixed/htmlmixed", | ||
"mode/jinja2/jinja2", | ||
"mode/python/python", | ||
"mode/shell/shell", | ||
"mode/sql/sql", | ||
"mode/yaml/yaml", | ||
"addon/display/fullscreen", | ||
"addon/display/panel", | ||
].map((x) => `codemirror/${x}`), function (CodeMirror) { | ||
cm_instance = CodeMirror.fromTextArea( | ||
document.querySelector("#body-text"), | ||
{ | ||
mode: { | ||
name: "gfm", | ||
gitHubSpice: false, | ||
}, | ||
lineSeparator: "\n", | ||
lineWrapping: true, | ||
extraKeys: { | ||
// home/end shouldn't go to the beginning/end of paragraphs | ||
Home: "goLineLeft", | ||
End: "goLineRight", | ||
// do not redefine the browser history navigation keys | ||
"Alt-Left": false, | ||
"Alt-Right": false, | ||
}, | ||
autofocus: true, | ||
// appears to do nothing | ||
spellcheck: true, | ||
viewportMargin: Infinity, | ||
} | ||
); | ||
}); | ||
} | ||
|
||
// mark the editor as changed if the textarea has changed | ||
document.querySelector('#body-text') | ||
.addEventListener('input', (event) => editor.changed = true); | ||
// mark the editor as changed if there is an alert shown | ||
// (implies there was an error saving) | ||
if (document.querySelector("#alerts") !== null) { | ||
editor.changed = true; | ||
} | ||
|
||
// don't nag if the Submit button was clicked | ||
document.querySelector('#page-form').onsubmit = function() { | ||
editor.submit_clicked = true; | ||
}; | ||
// mark the editor as changed if the textarea has changed | ||
document | ||
.querySelector("#body-text") | ||
.addEventListener("input", (event) => (editor.changed = true)); | ||
|
||
window.addEventListener('beforeunload', function (e) { | ||
if (silicon_editor === 'codemirror') { | ||
// alert on changed codemirror | ||
if ((! cm_instance.isClean() && ! editor.submit_clicked)) { | ||
usurp_unload(e); | ||
} | ||
} else { | ||
// alert on changed textarea | ||
if ((editor.changed && ! editor.submit_clicked)) { | ||
usurp_unload(e); | ||
}; | ||
} | ||
}); | ||
// don't nag if the Submit button was clicked | ||
document.querySelector("#page-form").onsubmit = function () { | ||
editor.submit_clicked = true; | ||
}; | ||
|
||
window.addEventListener("beforeunload", function (e) { | ||
if (silicon_editor === "codemirror") { | ||
// alert on changed codemirror | ||
if (!cm_instance.isClean() && !editor.submit_clicked) { | ||
usurp_unload(e); | ||
} | ||
} else { | ||
// alert on changed textarea | ||
if (editor.changed && !editor.submit_clicked) { | ||
usurp_unload(e); | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
window.addEventListener("load", function() { | ||
/* Toggle nav sidebar in "mobile" mode */ | ||
document.querySelector("[data-toggle='nav-top']") | ||
.addEventListener('click', (event) => { | ||
const elements = document.querySelectorAll("[data-toggle='nav-shift']"); | ||
window.addEventListener("load", function () { | ||
/* Toggle nav sidebar in "mobile" mode */ | ||
document | ||
.querySelector("[data-toggle='nav-top']") | ||
.addEventListener("click", (event) => { | ||
const elements = document.querySelectorAll("[data-toggle='nav-shift']"); | ||
|
||
elements.forEach(function(element) { | ||
element.classList.toggle('shift'); | ||
}) | ||
}) | ||
elements.forEach(function (element) { | ||
element.classList.toggle("shift"); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.