_comment_form.html.erb 3.16 KB
<script type="text/javascript">
function submit_comment_form(button) {
  <% if pass_without_comment_captcha? %>
  button.form.confirm.value = 'true';
  button.disabled = true;
  button.form.submit();
  return true;
  <% else %>
  jQuery('#recaptcha-container').show();
  jQuery.colorbox({ inline : true, href : '#recaptcha-container', maxWidth : '600px', maxHeight : '300px' });
  jQuery('#confirm-captcha').unbind('click');
  jQuery('#confirm-captcha').bind('click', function() {
    jQuery.colorbox.close();
    button.form.recaptcha_response_field.value = jQuery('#recaptcha_response_field').val();
    button.form.recaptcha_challenge_field.value = jQuery('#recaptcha_challenge_field').val();
    button.form.confirm.value = 'true';
    button.disabled = true;
    button.form.submit();
  });
  <% end %>
}
</script>

<% if @comment && @comment.errors.any? && @comment.reply_of_id.blank? %>
  <%= error_messages_for :comment %>
  <script type="text/javascript">jQuery(function() { document.location.href = '#page-comment-form'; });</script>
<% end %>

<% @form_div ||= 'closed' %>

<div class="post_comment_box <%= @form_div %>">

  <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form') if display_link %>

<% unless pass_without_comment_captcha? %>
  <div id="recaptcha-container" style="display: none">
    <h3><%= _('Please type the two words below') %></h3>
    <%= recaptcha_tags(:display => { :theme => 'clean' }, :ajax => true) %>
    <% button_bar do %>
      <%= button_to_function :add, _('Confirm'), "return false", :id => "confirm-captcha" %>
      <%= button_to_function :cancel, _('Cancel'), "jQuery.colorbox.close()" %>
    <% end %>
  </div>

  <script type="text/javascript">
    jQuery(document).bind('cbox_cleanup', function() {
      jQuery('#recaptcha-container').hide();
    });
  </script>
<% end %>

<%= form_tag( url, { :class => 'comment_form' } ) do %>
  <%= required_fields_message %>

  <% unless logged_in? %>

    <%= required labelled_form_field(_('Name'), text_field(:comment, :name)) %>
    <%= required labelled_form_field(_('e-mail'), text_field(:comment, :email)) %>
    <p>
    <%= _('If you are a registered user, you can login and be automatically recognized.') %>
    </p>

  <% end %>

  <% unless pass_without_comment_captcha? %>
    <%= hidden_field_tag(:recaptcha_response_field, nil, :id => nil) %>
    <%= hidden_field_tag(:recaptcha_challenge_field, nil, :id => nil) %>
  <% end %>

  <%= labelled_form_field(_('Title'), text_field(:comment, :title)) %>
  <%= required labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %>

  <%= hidden_field_tag(:confirm, 'false') %>
  <%= hidden_field_tag(:view, params[:view])%>

  <% button_bar do %>
    <%= submit_button('add', _('Post comment'), :onclick => "submit_comment_form(this); return false") %>
    <% if cancel_triggers_hide %>
      <%= button :cancel, _('Cancel'), '', :id => 'cancel-comment' %>
    <% else %>
      <%= button('cancel', _('Cancel'), {:action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path})%>
    <% end %>
  <% end %>
<% end %>

</div><!-- end class="post_comment_box" -->

<%= javascript_include_tag 'comment_form'%>