]> git.openstreetmap.org Git - osqa.git/commitdiff
warning users that edits will be lost if they navigate away from the page.
authorcourt <court@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 17 Aug 2010 14:47:47 +0000 (14:47 +0000)
committercourt <court@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 17 Aug 2010 14:47:47 +0000 (14:47 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@556 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/skins/default/media/js/osqa.main.js
forum/skins/default/templates/answer_edit.html
forum/skins/default/templates/ask.html
forum/skins/default/templates/node/comments.html
forum/skins/default/templates/question.html
forum/skins/default/templates/question_edit.html

index c5d0a43e2c6f56e82a0ffa69eec70323c183ebc7..4b07d9b914d2703f32252a24158f62a4483768aa 100644 (file)
@@ -510,11 +510,14 @@ $(function() {
                 return false;\r
             });\r
 \r
-            $cancel.click(function() {\r
-                if (comment_in_form) {\r
-                    $comment = $('#comment-' + comment_in_form).slideDown('slow');\r
+            $cancel.click(function(event) {\r
+                if (confirm("You will lose all of your changes in this comment.  Do you still wish to proceed?")){\r
+                    if (comment_in_form) {\r
+                        $comment = $('#comment-' + comment_in_form).slideDown('slow');\r
+                    }\r
+                    hide_comment_form();\r
+                    cleanup_form();\r
                 }\r
-                hide_comment_form();\r
                 return false;\r
             });\r
         }\r
@@ -1053,3 +1056,14 @@ $(document).ready( function(){
     });\r
 });\r
 \r
+function yourWorkWillBeLost(e) {\r
+       if(!e) e = window.event;\r
+       e.cancelBubble = true;\r
+       e.returnValue = 'You sure you want to leave?  Your work will be lost.';\r
+\r
+       if (e.stopPropagation) {\r
+               e.stopPropagation();\r
+               e.preventDefault();\r
+       }\r
+    return e;\r
+}
\ No newline at end of file
index 137b68413c7ca6ade8f3a9587cb93f426d90f0c4..66712ac526ceff97d8f8a5175dc24e3eb715642f 100644 (file)
             $('#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);
         </script>
 {% endblock %}
         
@@ -66,7 +73,7 @@
             <div class="title-desc">
                 {{ form.summary.help_text }}
             </div>
-            <input type="submit" value="{% trans "Save edit" %}" class="submit" />
+            <input type="submit" value="{% trans "Save edit" %}" class="submit" onclick="window.removeEventListener('beforeunload', beforeUnload, true)" />
             <input type="button" value="{% trans "Cancel" %}" class="submit" onclick="history.back(-1);" />
         </form>
     </div>
index 557b072290de81501166a43f1c34f33ea28fd318..c17ea51dedf07b1d65223175881219c513c9e07a 100644 (file)
                 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] + ")";
                 },
             });
         });
 
+        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 %}";
         </script>
         <script src="{% media "/media/js/osqa.ask.js" %}" type="text/javascript"></script>
             {% if not request.user.is_authenticated %}
             <input name="ask" type="submit" value="{% trans "Login/signup to post your question" %}" class="submit" />
                        {% else %}
-            <input name="ask" type="submit" value="{% trans "Ask your question" %}" class="submit" />
+            <input name="ask" type="submit" value="{% trans "Ask your question" %}" class="submit" onclick="window.removeEventListener('beforeunload', beforeUnload, true)" />
             {% endif %}
         </form>
     </div>
index f2646a2f77543991257a3d9ccf3783d5c81131ca..87ce889dedfb537599898e31d8df015265aabf3e 100644 (file)
     {% if can_comment %}\r
     <form id="comment-{{ post.id }}-form" method="post" action="{% url comment id=post.id %}" accept-charset="utf-8">\r
         <div class="comment-form-widgets-container">\r
-            <textarea name="comment"></textarea>\r
+            <textarea name="comment" class="commentBox"></textarea>\r
             <div class="comment-form-buttons">\r
                 <span id="comment-{{ post.id }}-chars-left" class="comment-chars-left">\r
                     <span class="comments-char-left-count">{{ min_length }}|{{ max_length }}</span>\r
                     <span class="comments-chars-togo-msg">{% trans "characters needed" %}</span>\r
                     <span class="comments-chars-left-msg">{% trans "characters left" %}</span>\r
                 </span>\r
-                <input type="submit" class="comment-submit" value="{% trans " comment" %}" />\r
+                <input type="submit" class="comment-submit" value="{% trans " comment" %}" onclick="window.removeEventListener('beforeunload', beforeUnload, true)" />\r
                 <input type="submit" class="comment-cancel" value="{% trans " cancel" %}" />\r
             </div>\r
         </div>\r
index 430a304156e8069aa3677d417be0dd6d4b4b85c2..efc5f5ee189d59c90b5492c27c7a16ae7a61188f 100644 (file)
@@ -30,7 +30,7 @@
             }\r
 \r
             $('#editor').TextAreaResizer();\r
-            \r
+\r
             //toggle preview of editor\r
             var display = true;\r
             var txt = "[{% trans "hide preview" %}]";\r
                 $('#previewer').toggle();\r
                 $('#pre-collapse').text(txt);\r
             });\r
+\r
         });\r
+\r
+        function beforeUnload(e) {\r
+            if($("textarea#editor")[0].value != "") {\r
+               yourWorkWillBeLost(e);\r
+            }\r
+\r
+            $("textarea.commentBox").each(function() {\r
+               if(this.value != "") {\r
+                   yourWorkWillBeLost(e);\r
+               }\r
+            });\r
+\r
+            return false;\r
+        }\r
+        window.addEventListener('beforeunload', beforeUnload, true);\r
+\r
         </script>\r
         <noscript>\r
             <style>\r
                         value="{% trans "Answer the question" %}" \r
                         {% endif %}\r
                     {% endif %}\r
-                    class="submit" style="float:left"/>\r
+                    class="submit" style="float:left" onclick="window.removeEventListener('beforeunload', beforeUnload, true)" />\r
             {% endif %}\r
         </form>\r
     </div>\r
index 9207209956dd0a452b03aca86d70534a93643e12..25ea9bb67a91ef67bed8a03261d3e6eb04fc7a11 100644 (file)
                 $("#select_revision").click();
             });
 
+            init = $("textarea#editor")[0].value;
         });
+
+         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 init = "";
         </script>
 {% endblock %}
         
                 {{ form.summary.help_text }}
             </div>
             <div class="error" ></div>
-            <input type="submit" value="{% trans "Save edit" %}" class="submit" />
-            <input type="button" value="{% trans "Cancel" %}" class="submit" onclick="history.back(-1);" />
+            <input type="button" value="{% trans "Cancel" %}" class="submit" onclick="window.removeEventListener('beforeunload', beforeUnload, true)" />
+
         </form>
     </div>
 </div>