Files
edx-platform/lms/static/js/wiki/CodeMirror.init.js
Syed Ali Abbas Zaidi 5549db4d80 fix: migrate remaining eslint-config-edx (#31760)
* fix: migrate remaining eslint-config-edx

* refactor: updated eslint rules according to eslint-config-edx-es5

* refactor: add custom rules to suppress unnecessary eslint issues

* refactor: add custom rules to internal eslint configs

* fix: fix all indentation issues

* chore: update lock file
2023-03-02 16:16:50 +05:00

29 lines
1.2 KiB
JavaScript

$(document).ready(function() {
var editor = CodeMirror.fromTextArea(document.getElementById('id_content'), {
mode: 'edx_markdown',
matchBrackets: true,
theme: 'default',
lineWrapping: true,
keyMap: 'accessible'
});
// Store the inital contents so we can compare for unsaved changes
var initialContents = editor.getValue();
// The Wiki associates a label with the text area that has ID "id_content". However, when we swap in
// CodeMirror, that text area is hidden. We need to associate the label with visible CodeMirror text area
// (and there is JS code in the wiki that depends on "id_content" interact with the content, so we have
// to leave that alone).
editor.getInputField().setAttribute('id', 'id_codemirror_content');
$(".control-label[for='id_content']")[0].setAttribute('for', 'id_codemirror_content');
window.onbeforeunload = function askConfirm() { // Warn the user before they navigate away
if (editor.getValue() != initialContents) {
return 'You have made changes to the article that have not been saved yet.';
}
};
$('.btn-primary').click(function() {
initialContents = editor.getValue();
});
});