From 9b59b6bb395208c913ce5ce19212dd5341cfa98a Mon Sep 17 00:00:00 2001 From: court Date: Tue, 17 Aug 2010 14:47:47 +0000 Subject: [PATCH] warning users that edits will be lost if they navigate away from the page. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@556 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/skins/default/media/js/osqa.main.js | 22 +++++++++++++++---- .../skins/default/templates/answer_edit.html | 13 ++++++++--- forum/skins/default/templates/ask.html | 18 ++++++++++++--- .../default/templates/node/comments.html | 4 ++-- forum/skins/default/templates/question.html | 21 ++++++++++++++++-- .../default/templates/question_edit.html | 15 +++++++++++-- 6 files changed, 77 insertions(+), 16 deletions(-) diff --git a/forum/skins/default/media/js/osqa.main.js b/forum/skins/default/media/js/osqa.main.js index c5d0a43..4b07d9b 100644 --- a/forum/skins/default/media/js/osqa.main.js +++ b/forum/skins/default/media/js/osqa.main.js @@ -510,11 +510,14 @@ $(function() { return false; }); - $cancel.click(function() { - if (comment_in_form) { - $comment = $('#comment-' + comment_in_form).slideDown('slow'); + $cancel.click(function(event) { + if (confirm("You will lose all of your changes in this comment. Do you still wish to proceed?")){ + if (comment_in_form) { + $comment = $('#comment-' + comment_in_form).slideDown('slow'); + } + hide_comment_form(); + cleanup_form(); } - hide_comment_form(); return false; }); } @@ -1053,3 +1056,14 @@ $(document).ready( function(){ }); }); +function yourWorkWillBeLost(e) { + if(!e) e = window.event; + e.cancelBubble = true; + e.returnValue = 'You sure you want to leave? Your work will be lost.'; + + if (e.stopPropagation) { + e.stopPropagation(); + e.preventDefault(); + } + return e; +} \ No newline at end of file diff --git a/forum/skins/default/templates/answer_edit.html b/forum/skins/default/templates/answer_edit.html index 137b684..66712ac 100644 --- a/forum/skins/default/templates/answer_edit.html +++ b/forum/skins/default/templates/answer_edit.html @@ -28,9 +28,16 @@ $('#id_revision').unbind().change(function(){ $("#select_revision").click(); }); - - }); + + function beforeUnload(e) { + if($("textarea#editor")[0].value != "") { + yourWorkWillBeLost(e); + } + + return false; + } + window.addEventListener('beforeunload', beforeUnload, true); {% endblock %} @@ -66,7 +73,7 @@
{{ form.summary.help_text }}
- + diff --git a/forum/skins/default/templates/ask.html b/forum/skins/default/templates/ask.html index 557b072..c17ea51 100644 --- a/forum/skins/default/templates/ask.html +++ b/forum/skins/default/templates/ask.html @@ -39,12 +39,16 @@ max: 20, multiple: true, multipleSeparator: " ", - /*formatItem: function(row, i, max) { + + /* + formatItem: function(row, i, max) { return row.n + " ("+ row.c +")"; }, formatResult: function(row, i, max){ return row.n; - }*/ + } + */ + formatItem: function(row, i, max, value) { return row[1].split(".")[0] + " (" + row[1].split(".")[1] + ")"; }, @@ -56,6 +60,14 @@ }); }); + function beforeUnload(e) { + if($("input#id_title")[0].value != "" || $("textarea#editor")[0].value != "" || $("input#id_tags")[0].value != "") { + yourWorkWillBeLost(e); + } + return false; + } + window.addEventListener('beforeunload', beforeUnload, true); + var related_questions_url = "{% url related_questions %}"; @@ -124,7 +136,7 @@ {% if not request.user.is_authenticated %} {% else %} - + {% endif %} diff --git a/forum/skins/default/templates/node/comments.html b/forum/skins/default/templates/node/comments.html index f2646a2..87ce889 100644 --- a/forum/skins/default/templates/node/comments.html +++ b/forum/skins/default/templates/node/comments.html @@ -43,14 +43,14 @@ {% if can_comment %}
- +
{{ min_length }}|{{ max_length }} {% trans "characters needed" %} {% trans "characters left" %} - +
diff --git a/forum/skins/default/templates/question.html b/forum/skins/default/templates/question.html index 430a304..efc5f5e 100644 --- a/forum/skins/default/templates/question.html +++ b/forum/skins/default/templates/question.html @@ -30,7 +30,7 @@ } $('#editor').TextAreaResizer(); - + //toggle preview of editor var display = true; var txt = "[{% trans "hide preview" %}]"; @@ -41,7 +41,24 @@ $('#previewer').toggle(); $('#pre-collapse').text(txt); }); + }); + + function beforeUnload(e) { + if($("textarea#editor")[0].value != "") { + yourWorkWillBeLost(e); + } + + $("textarea.commentBox").each(function() { + if(this.value != "") { + yourWorkWillBeLost(e); + } + }); + + return false; + } + window.addEventListener('beforeunload', beforeUnload, true); +