diff options
author | 2019-04-19 14:12:28 +0100 | |
---|---|---|
committer | 2019-04-19 14:12:28 +0100 | |
commit | e0f837ddd8ff434b1ef3429f6a709263350194ce (patch) | |
tree | 6f752fa2cb602d63dec09bb3f2d22ecce39d3d7c /pydis_site/static/js/wiki/edit.js | |
parent | Initial template cleanup (diff) |
Move JS into files
Diffstat (limited to 'pydis_site/static/js/wiki/edit.js')
-rw-r--r-- | pydis_site/static/js/wiki/edit.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/pydis_site/static/js/wiki/edit.js b/pydis_site/static/js/wiki/edit.js new file mode 100644 index 00000000..3c9c70a4 --- /dev/null +++ b/pydis_site/static/js/wiki/edit.js @@ -0,0 +1,62 @@ +$(document).ready(function() { + let article_edit_form = $("#article_edit_form"); + let click_time = 0; + + $("#article_edit_form :input").change(function() { + article_edit_form.data("changed",true); + }); + + if (article_edit_form.find(".alert-danger").length > 0 || article_edit_form.find(".has-error").length > 0 ) { + // Set the forms status as "changed" if there was a submission error + article_edit_form.data("changed",true); + } + + window.onbeforeunload = confirmOnPageExit; + + article_edit_form.on("submit", function (ev) { + now = Date.now(); + elapsed = now-click_time; + click_time = now; + if (elapsed < 3000) + ev.preventDefault(); + window.onbeforeunload = null; + return true; + }); + $("#id_preview").click(function () { + open_modal("previewModal"); + return true; + }); + $("#id_preview_save_changes").on("click", function (ev) { + ev.preventDefault(); + $("#id_save").trigger("click"); + }); +}); + +var confirmOnPageExit = function (e) { + if ($("#article_edit_form").data("changed")) { + e = e || window.event; + var message = "You have unsaved changes!"; + // For IE6-8 and Firefox prior to version 4 + if (e) { + e.returnValue = message; + } + // For Chrome, Safari, IE8+ and Opera 12+ + return message; + } else { + // If the form hasn't been changed, don't display the pop-up + return; + } +}; + +$(document).ready( function() { + $('.sidebar-form').each(function () { + $(this).submit( function() { + this.unsaved_article_title.value = $('#id_title').val(); + this.unsaved_article_content.value = $('#id_content').val(); + }); + }); +}); + +$(document).ready(function() { + $("#id_revision").val('{{ article.current_revision.id }}'); +}); |