X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/21fa4fe96b79ae04c0cfb32591f00185dae98be3..d51fb54019701a24740c85e85024de1fce7b0689:/forum/skins/default/media/js/osqa.main.js diff --git a/forum/skins/default/media/js/osqa.main.js b/forum/skins/default/media/js/osqa.main.js index 48de0b6..8fb4d63 100644 --- a/forum/skins/default/media/js/osqa.main.js +++ b/forum/skins/default/media/js/osqa.main.js @@ -2,6 +2,7 @@ * We do not want the CSRF protection enabled for the AJAX post requests, it causes only trouble. * Get the csrftoken cookie and pass it to the X-CSRFToken HTTP request property. */ + $('html').ajaxSend(function(event, xhr, settings) { function getCookie(name) { var cookieValue = null; @@ -18,10 +19,12 @@ $('html').ajaxSend(function(event, xhr, settings) { } return cookieValue; } - if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) { - // Only send the token to relative URLs i.e. locally. - xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); - } + try { + if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) { + // Only send the token to relative URLs i.e. locally. + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); + } + } catch (e) {} }); var response_commands = { @@ -159,7 +162,6 @@ var response_commands = { }, copy_url: function(url) { - $.copy(url); } } @@ -181,11 +183,17 @@ function show_dialog (extern) { yes_callback: default_close_function, no_text: messages.cancel, show_no: false, - close_on_clickoutside: false + close_on_clickoutside: false, + copy: false } $.extend(options, extern); + var copy_id = ''; + if (options.copy) { + copy_id = ' id="copy_clip_button"' + } + if (options.event != undefined) { options.pos = {x: options.event.pageX, y: options.event.pageY}; } @@ -197,8 +205,7 @@ function show_dialog (extern) { html += ''; } - html += '' - + ''; + html += '' + ''; $dialog = $(html); $('body').append($dialog); @@ -304,7 +311,12 @@ function load_prompt(evt, el, url) { process_ajax_response(data, evt); }, 'json'); }, - show_no: true + show_no: true, + copy: false + } + + if (el.hasClass('copy')) { + $.extend(doptions, { yes_text : 'Copy', copy: true}); } if (!el.is('.centered')) { @@ -319,7 +331,8 @@ function process_ajax_response(data, evt, callback) { if (!data.success && data['error_message'] != undefined) { show_message(evt, data.error_message, function() {if (callback) callback(true);}); end_command(false); - } else if (typeof data['commands'] != undefined){ + } + if (typeof data['commands'] != undefined){ for (var command in data.commands) { response_commands[command].apply(null, data.commands[command]) @@ -355,7 +368,28 @@ function end_command(success) { } } +var comment_box_cursor_position = 0; +function canned_comment(post_id, comment) { + textarea = $('#comment-' + post_id + '-form textarea') + + // Get the text from the beginning to the caret + textarea_start = textarea.val().substr(0, comment_box_cursor_position) + + // Get the text from the caret to the end + textarea_end = textarea.val().substr(comment_box_cursor_position, textarea.val().length) + + textarea.val(textarea_start + comment + textarea_end); +} + $(function() { + $('textarea.commentBox').bind('keydown keyup mousedown mouseup mousemove', function(evt) { + comment_box_cursor_position = $(this).caret().start; + }); + + $('textarea.commentBox').blur(function() { + //alert(comment_box_cursor_position); + }); + $('a.ajax-command').live('click', function(evt) { if (running) return false; @@ -427,7 +461,6 @@ $(function() { if ($form.length) { var $textarea = $container.find('textarea'); var textarea = $textarea.get(0); - var $csrf = $container.find('[name="csrfmiddlewaretoken"]'); var $button = $container.find('.comment-submit'); var $cancel = $container.find('.comment-cancel'); var $chars_left_message = $container.find('.comments-chars-left-msg'); @@ -556,8 +589,7 @@ $(function() { if (running) return false; var post_data = { - comment: $textarea.val(), - csrfmiddlewaretoken: $csrf.val() + comment: $textarea.val() } if (comment_in_form) { @@ -578,6 +610,14 @@ $(function() { return false; }); + // Submit comment with CTRL + Enter + $textarea.keydown(function(e) { + if (e.ctrlKey && e.keyCode == 13 && !$button.attr('disabled')) { + // console.log('submit'); + $(this).parent().find('input.comment-submit').click(); + } + }); + $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) { @@ -721,7 +761,7 @@ function pickedTags(){ tag_link.attr('rel','tag'); tag_link.attr('href', scriptUrl + $.i18n._('tags/') + tagname + '/'); tag_link.html(tagname); - var del_link = $(''); + var del_link = $(''); del_link.addClass('delete-icon'); del_link.attr('src', mediaUrl('media/images/close-small-dark.png'));