+/**\r
+ * We do not want the CSRF protection enabled for the AJAX post requests, it causes only trouble.\r
+ * Get the csrftoken cookie and pass it to the X-CSRFToken HTTP request property.\r
+ */\r
+$('html').ajaxSend(function(event, xhr, settings) {\r
+ function getCookie(name) {\r
+ var cookieValue = null;\r
+ if (document.cookie && document.cookie != '') {\r
+ var cookies = document.cookie.split(';');\r
+ for (var i = 0; i < cookies.length; i++) {\r
+ var cookie = jQuery.trim(cookies[i]);\r
+ // Does this cookie string begin with the name we want?\r
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {\r
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ return cookieValue;\r
+ }\r
+ if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {\r
+ // Only send the token to relative URLs i.e. locally.\r
+ xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));\r
+ }\r
+});\r
+\r
var response_commands = {\r
refresh_page: function() {\r
window.location.reload(true)\r
});\r
},\r
\r
- insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url) {\r
+ award_points: function(id) {\r
+ alert('ok');\r
+ },\r
+\r
+ insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url, can_convert) {\r
var $container = $('#comments-container-' + post_id);\r
var skeleton = $('#new-comment-skeleton-' + post_id).html().toString();\r
\r
\r
$container.append(skeleton);\r
\r
+ // Show the convert comment to answer tool only if the current comment can be converted\r
+ if (can_convert == true) {\r
+ $('#comment-' + comment_id + '-convert').show();\r
+ }\r
+\r
$('#comment-' + comment_id).slideDown('slow');\r
},\r
\r
},\r
\r
mark_deleted: function(post_type, post_id) {\r
- if (post_type == 'answer') {\r
- var $answer = $('#answer-container-' + post_id);\r
- $answer.addClass('deleted');\r
- } else {\r
+ if (post_type == 'question') {\r
var $container = $('#question-table');\r
$container.addClass('deleted');\r
+ } else {\r
+ var $el = $('#' + post_type + '-container-' + post_id);\r
+ $el.addClass('deleted');\r
}\r
},\r
\r
\r
set_subscription_status: function(text) {\r
$('.subscription-status').html(text);\r
+ },\r
+\r
+ copy_url: function(url) {\r
+ $.copy(url);\r
}\r
}\r
\r
top: options.pos.y,\r
left: options.pos.x\r
});\r
-\r
+ \r
+ top_position_change = (options.dim.h / 2)\r
+ left_position_change = (options.dim.w / 2)\r
+ \r
+ new_top_position = options.pos.y - top_position_change\r
+ new_left_position = options.pos.x - left_position_change\r
+ \r
+ if (new_left_position < 0) {\r
+ left_position_change = 0\r
+ }\r
+ if (($(window).scrollTop() - new_top_position) > 0) {\r
+ top_position_change = 0\r
+ }\r
+ if ((options.event.pageY + options.dim.h) > ($(window).height() + $(window).scrollTop())) {\r
+ top_position_change = options.dim.h\r
+ }\r
+ if ((options.event.pageX + options.dim.w) > ($(window).width() + $(window).scrollLeft())) {\r
+ left_position_change = options.dim.w\r
+ }\r
+ \r
$dialog.animate({\r
- top: "-=" + (options.dim.h / 2),\r
- left: "-=" + (options.dim.w / 2),\r
+ top: "-=" + top_position_change,\r
+ left: "-=" + left_position_change,\r
width: options.dim.w,\r
height: options.dim.h\r
}, 200, function() {\r
$('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
+ var ajax_url = el.attr('href')\r
+ ajax_url = ajax_url + "?nocache=" + new Date().getTime()\r
+\r
+ $('.context-menu-dropdown').slideUp('fast');\r
+\r
if (el.is('.withprompt')) {\r
- load_prompt(evt, el, el.attr('href'));\r
+ load_prompt(evt, el, ajax_url);\r
} else if(el.is('.confirm')) {\r
var doptions = {\r
html: messages.confirm,\r
extra_class: 'confirm',\r
yes_callback: function() {\r
start_command();\r
- $.getJSON(el.attr('href'), function(data) {\r
+ $.getJSON(ajax_url, function(data) {\r
process_ajax_response(data, evt);\r
$dialog.fadeOut('fast', function() {\r
$dialog.remove();\r
var $dialog = show_dialog(doptions);\r
} else {\r
start_command();\r
- $.getJSON(el.attr('href'), function(data) {\r
+ $.getJSON(ajax_url, function(data) {\r
process_ajax_response(data, evt);\r
});\r
}\r
if ($form.length) {\r
var $textarea = $container.find('textarea');\r
var textarea = $textarea.get(0);\r
+ var $csrf = $container.find('[name="csrfmiddlewaretoken"]');\r
var $button = $container.find('.comment-submit');\r
var $cancel = $container.find('.comment-cancel');\r
var $chars_left_message = $container.find('.comments-chars-left-msg');\r
if (running) return false;\r
\r
var post_data = {\r
- comment: $textarea.val()\r
+ comment: $textarea.val(),\r
+ csrfmiddlewaretoken: $csrf.val()\r
}\r
\r
if (comment_in_form) {\r
var $previewer = $('#previewer');\r
var $container = $('#editor-metrics');\r
\r
- var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;\r
- var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;\r
+ var initial_whitespace_rExp = /^[^A-Za-zА-Яа-я0-9]+/gi;\r
+ var non_alphanumerics_rExp = rExp = /[^A-Za-zА-Яа-я0-9]+/gi;\r
var editor_interval = null;\r
\r
$editor.focus(function() {\r