]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/skins/default/media/js/osqa.main.js
be able to use the cursor caret when using the canned comments feature, include the...
[osqa.git] / forum / skins / default / media / js / osqa.main.js
index 0c532e37adbfc7da84bd61d7c26c9066311e55ad..7d6294f69c91c90b5ec12b8e4af5f77287bc6266 100644 (file)
@@ -25,10 +25,6 @@ $('html').ajaxSend(function(event, xhr, settings) {
     }\r
 });\r
 \r
-function canned_comment(post_id, comment) {\r
-    $('#comment-' + post_id + '-form textarea').val(comment);\r
-}\r
-\r
 var response_commands = {\r
     refresh_page: function() {\r
         window.location.reload(true)\r
@@ -369,7 +365,28 @@ function end_command(success) {
     }\r
 }\r
 \r
+var comment_box_cursor_position = 0;\r
+function canned_comment(post_id, comment) {\r
+    textarea = $('#comment-' + post_id + '-form textarea')\r
+\r
+    // Get the text from the beginning to the caret\r
+    textarea_start = textarea.val().substr(0, comment_box_cursor_position)\r
+\r
+    // Get the text from the caret to the end\r
+    textarea_end = textarea.val().substr(comment_box_cursor_position, textarea.val().length)\r
+\r
+    textarea.val(textarea_start + comment + textarea_endsvn );\r
+}\r
+\r
 $(function() {\r
+    $('textarea.commentBox').bind('keydown keyup mousedown mouseup mousemove', function(evt) {\r
+        comment_box_cursor_position = $(this).caret().start;\r
+    });\r
+\r
+    $('textarea.commentBox').blur(function() {\r
+        //alert(comment_box_cursor_position);\r
+    });\r
+\r
     $('a.ajax-command').live('click', function(evt) {\r
         if (running) return false;\r
 \r