\r
$('div.comment-form-container').each(function() {\r
var $container = $(this);\r
- var $form = $container.find('form');\r
- var $textarea = $container.find('textarea');\r
- var textarea = $textarea.get(0);\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
- var $chars_togo_message = $container.find('.comments-chars-togo-msg');\r
- var $chars_counter = $container.find('.comments-char-left-count');\r
-\r
var $comment_tools = $container.parent().find('.comment-tools');\r
- var $add_comment_link = $comment_tools.find('.add-comment-link');\r
var $comments_container = $container.parent().find('.comments-container');\r
+ \r
+ var $form = $container.find('form');\r
\r
- var chars_limits = $chars_counter.html().split('|');\r
+ if ($form.length) {\r
+ var $textarea = $container.find('textarea');\r
+ var textarea = $textarea.get(0);\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
+ var $chars_togo_message = $container.find('.comments-chars-togo-msg');\r
+ var $chars_counter = $container.find('.comments-char-left-count');\r
\r
- var min_length = parseInt(chars_limits[0]);\r
- var max_length = parseInt(chars_limits[1]);\r
- \r
- var warn_length = max_length - 30;\r
- var current_length = 0;\r
- var comment_in_form = false;\r
- var interval = null;\r
+ var $add_comment_link = $comment_tools.find('.add-comment-link');\r
\r
- var hcheck = !($.browser.msie || $.browser.opera);\r
+ var chars_limits = $chars_counter.html().split('|');\r
\r
- $textarea.css("padding-top", 0).css("padding-bottom", 0).css("resize", "none");\r
- textarea.style.overflow = 'hidden';\r
- \r
+ var min_length = parseInt(chars_limits[0]);\r
+ var max_length = parseInt(chars_limits[1]);\r
\r
- function cleanup_form() {\r
- $textarea.val('');\r
- $textarea.css('height', 80);\r
- $chars_counter.html(max_length);\r
- $chars_left_message.removeClass('warn');\r
- comment_in_form = false;\r
- current_length = 0;\r
-\r
- $chars_left_message.hide();\r
- $chars_togo_message.show();\r
- \r
- $chars_counter.removeClass('warn');\r
- $chars_counter.html(min_length);\r
- $button.attr("disabled","disabled");\r
- \r
- interval = null;\r
- }\r
+ var warn_length = max_length - 30;\r
+ var current_length = 0;\r
+ var comment_in_form = false;\r
+ var interval = null;\r
\r
- cleanup_form();\r
+ var hcheck = !($.browser.msie || $.browser.opera);\r
\r
- function process_form_changes() {\r
- var length = $textarea.val().replace(/[ ]{2,}/g," ").length;\r
+ $textarea.css("padding-top", 0).css("padding-bottom", 0).css("resize", "none");\r
+ textarea.style.overflow = 'hidden';\r
\r
- if (current_length == length)\r
- return;\r
\r
- if (length < warn_length && current_length >= warn_length) {\r
- $chars_counter.removeClass('warn');\r
- } else if (current_length < warn_length && length >= warn_length){\r
- $chars_counter.addClass('warn');\r
- }\r
+ function cleanup_form() {\r
+ $textarea.val('');\r
+ $textarea.css('height', 80);\r
+ $chars_counter.html(max_length);\r
+ $chars_left_message.removeClass('warn');\r
+ comment_in_form = false;\r
+ current_length = 0;\r
\r
- if (length < min_length) {\r
$chars_left_message.hide();\r
$chars_togo_message.show();\r
- $chars_counter.html(min_length - length);\r
- } else {\r
- length = $textarea.val().length;\r
- $chars_togo_message.hide();\r
- $chars_left_message.show();\r
- $chars_counter.html(max_length - length);\r
- }\r
\r
- if (length > max_length || length < min_length) {\r
+ $chars_counter.removeClass('warn');\r
+ $chars_counter.html(min_length);\r
$button.attr("disabled","disabled");\r
- } else {\r
- $button.removeAttr("disabled");\r
+\r
+ interval = null;\r
}\r
\r
- var current_height = textarea.style.height;\r
- if (hcheck)\r
- textarea.style.height = "0px";\r
+ cleanup_form();\r
\r
- var h = Math.max(80, textarea.scrollHeight);\r
- textarea.style.height = current_height;\r
- $textarea.animate({height: h + 'px'}, 50);\r
+ function process_form_changes() {\r
+ var length = $textarea.val().replace(/[ ]{2,}/g," ").length;\r
\r
- current_length = length;\r
- }\r
+ if (current_length == length)\r
+ return;\r
\r
- function show_comment_form() {\r
- $container.slideDown('slow');\r
- $add_comment_link.fadeOut('slow');\r
- window.setInterval(function() {\r
- process_form_changes();\r
- }, 200);\r
- }\r
+ if (length < warn_length && current_length >= warn_length) {\r
+ $chars_counter.removeClass('warn');\r
+ } else if (current_length < warn_length && length >= warn_length){\r
+ $chars_counter.addClass('warn');\r
+ }\r
\r
- function hide_comment_form() {\r
- if (interval != null) {\r
- window.clearInterval(interval);\r
- interval = null;\r
+ if (length < min_length) {\r
+ $chars_left_message.hide();\r
+ $chars_togo_message.show();\r
+ $chars_counter.html(min_length - length);\r
+ } else {\r
+ length = $textarea.val().length;\r
+ $chars_togo_message.hide();\r
+ $chars_left_message.show();\r
+ $chars_counter.html(max_length - length);\r
+ }\r
+\r
+ if (length > max_length || length < min_length) {\r
+ $button.attr("disabled","disabled");\r
+ } else {\r
+ $button.removeAttr("disabled");\r
+ }\r
+\r
+ var current_height = textarea.style.height;\r
+ if (hcheck)\r
+ textarea.style.height = "0px";\r
+\r
+ var h = Math.max(80, textarea.scrollHeight);\r
+ textarea.style.height = current_height;\r
+ $textarea.animate({height: h + 'px'}, 50);\r
+\r
+ current_length = length;\r
}\r
- $container.slideUp('slow');\r
- $add_comment_link.fadeIn('slow');\r
- }\r
\r
- $add_comment_link.click(function(){\r
- cleanup_form();\r
- show_comment_form();\r
- return false;\r
- });\r
+ function show_comment_form() {\r
+ $container.slideDown('slow');\r
+ $add_comment_link.fadeOut('slow');\r
+ window.setInterval(function() {\r
+ process_form_changes();\r
+ }, 200);\r
+ }\r
\r
- $comment_tools.find('.show-all-comments-link').click(function() {\r
- $comments_container.find('.not_top_scorer').slideDown('slow');\r
- $(this).fadeOut('slow');\r
- $comment_tools.find('.comments-showing').fadeOut('slow');\r
- return false;\r
- });\r
+ function hide_comment_form() {\r
+ if (interval != null) {\r
+ window.clearInterval(interval);\r
+ interval = null;\r
+ }\r
+ $container.slideUp('slow');\r
+ $add_comment_link.fadeIn('slow');\r
+ }\r
+\r
+ $add_comment_link.click(function(){\r
+ cleanup_form();\r
+ show_comment_form();\r
+ return false;\r
+ });\r
+\r
+ $('#' + $comments_container.attr('id') + ' .comment-edit').live('click', function() {\r
+ var $link = $(this);\r
+ var comment_id = /comment-(\d+)-edit/.exec($link.attr('id'))[1];\r
+ var $comment = $('#comment-' + comment_id);\r
\r
- $('#' + $comments_container.attr('id') + ' .comment-edit').live('click', function() {\r
- var $link = $(this);\r
- var comment_id = /comment-(\d+)-edit/.exec($link.attr('id'))[1];\r
- var $comment = $('#comment-' + comment_id);\r
+ comment_in_form = comment_id;\r
\r
- comment_in_form = comment_id;\r
+ $.get($link.attr('href'), function(data) {\r
+ $textarea.val(data);\r
+ });\r
\r
- $.get($link.attr('href'), function(data) {\r
- $textarea.val(data);\r
+ $comment.slideUp('slow');\r
+ show_comment_form();\r
+ return false;\r
});\r
- \r
- $comment.slideUp('slow');\r
- show_comment_form();\r
- return false;\r
- });\r
\r
- $button.click(function(evt) {\r
- if (running) return false;\r
+ $button.click(function(evt) {\r
+ if (running) return false;\r
\r
- var post_data = {\r
- comment: $textarea.val()\r
- }\r
+ var post_data = {\r
+ comment: $textarea.val()\r
+ }\r
\r
- if (comment_in_form) {\r
- post_data['id'] = comment_in_form;\r
- }\r
+ if (comment_in_form) {\r
+ post_data['id'] = comment_in_form;\r
+ }\r
\r
- start_command();\r
- $.post($form.attr('action'), post_data, function(data) {\r
- process_ajax_response(data, evt, function(error) {\r
- if (!error) {\r
- cleanup_form();\r
- hide_comment_form();\r
- }\r
- });\r
+ start_command();\r
+ $.post($form.attr('action'), post_data, function(data) {\r
+ process_ajax_response(data, evt, function(error) {\r
+ if (!error) {\r
+ cleanup_form();\r
+ hide_comment_form();\r
+ }\r
+ });\r
\r
- }, "json");\r
- \r
- return false;\r
- });\r
+ }, "json");\r
\r
- $cancel.click(function() {\r
- if (comment_in_form) {\r
- $comment = $('#comment-' + comment_in_form).slideDown('slow');\r
- }\r
- hide_comment_form();\r
+ return false;\r
+ });\r
+\r
+ $cancel.click(function() {\r
+ if (comment_in_form) {\r
+ $comment = $('#comment-' + comment_in_form).slideDown('slow');\r
+ }\r
+ hide_comment_form();\r
+ return false;\r
+ });\r
+ }\r
+\r
+ $comment_tools.find('.show-all-comments-link').click(function() {\r
+ $comments_container.find('.not_top_scorer').slideDown('slow');\r
+ $(this).fadeOut('slow');\r
+ $comment_tools.find('.comments-showing').fadeOut('slow');\r
return false;\r
});\r
});\r
-\r
- \r
});\r
\r
//var scriptUrl, interestingTags, ignoredTags, tags, $;\r