]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/skins/default/media/js/osqa.main.js
fixes OSQA-439. IE should work again. Sorry about that. Thanks for the patches...
[osqa.git] / forum / skins / default / media / js / osqa.main.js
index 39ddd3b13b830bd1860bbe56b283e77ce78e968e..79cda45e948d52adfeb4620fb8a2424cc9e782cd 100644 (file)
@@ -49,10 +49,7 @@ var response_commands = {
         }\r
     },\r
 \r
-    mark_accepted: function(id) {\r
-        $('.accepted-answer').removeClass('accepted-answer');\r
-        $('.accept-answer.on').removeClass('on');\r
-        \r
+    mark_accepted: function(id) {        \r
         var $answer = $('#answer-container-' + id);\r
         $answer.addClass('accepted-answer');\r
         $answer.find('.accept-answer').addClass('on');\r
@@ -229,12 +226,11 @@ function show_message(evt, msg, callback) {
     });\r
 }\r
 \r
-function load_prompt(evt, url) {\r
+function load_prompt(evt, el, url) {\r
     $.get(url, function(data) {\r
-        var $dialog = show_dialog({\r
-            html: data,\r
+        var doptions = {\r
+         html: data,\r
             extra_class: 'prompt',\r
-            event: evt,\r
             yes_callback: function() {\r
                 var postvars = {};\r
                 $dialog.find('input, textarea, select').each(function() {\r
@@ -248,7 +244,13 @@ function load_prompt(evt, url) {
                 }, 'json');\r
             },\r
             show_no: true\r
-        });\r
+        }\r
+\r
+        if (!el.is('.centered')) {\r
+            doptions.event = evt;\r
+        }\r
+\r
+        var $dialog = show_dialog(doptions);\r
     });\r
 }\r
 \r
@@ -294,15 +296,16 @@ $(function() {
     $('a.ajax-command').live('click', function(evt) {\r
         if (running) return false;\r
 \r
+        $('.context-menu-dropdown').slideUp('fast');\r
+\r
         var el = $(this);\r
 \r
         if (el.is('.withprompt')) {\r
-            load_prompt(evt, el.attr('href'));\r
+            load_prompt(evt, el, el.attr('href'));\r
         } else if(el.is('.confirm')) {\r
-            $dialog = show_dialog({\r
+            var doptions = {\r
                 html: messages.confirm,\r
                 extra_class: 'confirm',\r
-                event: evt,\r
                 yes_callback: function() {\r
                     start_command();\r
                     $.getJSON(el.attr('href'), function(data) {\r
@@ -315,7 +318,12 @@ $(function() {
                 yes_text: messages.yes,\r
                 show_no: true,\r
                 no_text: messages.no\r
-            });\r
+            }\r
+\r
+            if (!el.is('.centered')) {\r
+                doptions.event = evt;\r
+            }\r
+            var $dialog = show_dialog(doptions);\r
         } else {\r
             start_command();\r
             $.getJSON(el.attr('href'), function(data) {\r
@@ -335,7 +343,8 @@ $(function() {
             $dropdown.slideToggle('fast', function() {\r
                 if ($dropdown.is(':visible')) {\r
                    $dropdown.one('clickoutside', function() {\r
-                        $dropdown.slideUp('fast')\r
+                       if ($dropdown.is(':visible'))\r
+                            $dropdown.slideUp('fast');\r
                     });\r
                 }\r
             });    \r
@@ -501,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
@@ -540,7 +552,8 @@ function pickedTags(){
 \r
         var call_settings = {\r
             type:'POST',\r
-            url:url\r
+            url:url,\r
+            data: ''\r
         };\r
         if (callback !== false){\r
             call_settings.success = callback;\r
@@ -667,7 +680,7 @@ function pickedTags(){
         init: function(){\r
             collectPickedTags();\r
             setupHideIgnoredQuestionsControl();\r
-            $("#interestingTagInput, #ignoredTagInput").autocomplete("/matching_tags/", {\r
+            $("#interestingTagInput, #ignoredTagInput").autocomplete(messages.matching_tags_url, {\r
                 minChars: 1,\r
                 matchContains: true,\r
                 max: 20,\r
@@ -675,11 +688,11 @@ function pickedTags(){
                 multipleSeparator: " "*/\r
 \r
                 formatItem: function(row, i, max, value) {\r
-                    return row[1].split(".")[0] + " (" + row[1].split(".")[1] + ")";\r
+                    return row[1] + " (" + row[2] + ")";\r
                 },\r
 \r
                 formatResult: function(row, i, max, value){\r
-                    return row[0];\r
+                    return row[1];\r
                 }\r
 \r
             });\r
@@ -1043,3 +1056,43 @@ $(document).ready( function(){
     });\r
 });\r
 \r
+function yourWorkWillBeLost(e) {\r
+    if(browserTester('chrome')) {\r
+        return "Are you sure you want to leave?  Your work will be lost.";\r
+    } else if(browserTester('safari')) {\r
+        return "Are you sure you want to leave?  Your work will be lost.";\r
+    } else {\r
+        if(!e) e = window.event;\r
+        e.cancelBubble = true;\r
+        e.returnValue = 'If you leave, your work will be lost.';\r
+\r
+        if (e.stopPropagation) {\r
+            e.stopPropagation();\r
+            e.preventDefault();\r
+        }\r
+        return e;\r
+    }\r
+}\r
+\r
+function browserTester(browserString) {\r
+    return navigator.userAgent.toLowerCase().indexOf(browserString) > -1;\r
+}\r
+\r
+// Add missing IE functionality\r
+if (!window.addEventListener) {\r
+    if (window.attachEvent) {\r
+        window.addEventListener = function (type, listener, useCapture) {\r
+            window.attachEvent('on' + type, listener);\r
+        };\r
+        window.removeEventListener = function (type, listener, useCapture) {\r
+            window.detachEvent('on' + type, listener);\r
+        };\r
+    } else {\r
+        window.addEventListener = function (type, listener, useCapture) {\r
+            window['on' + type] = listener;\r
+        };\r
+        window.removeEventListener = function (type, listener, useCapture) {\r
+            window['on' + type] = null;\r
+        };\r
+    }\r
+}
\ No newline at end of file