_comment_form.rhtml
3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<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>
<% focus_on = logged_in? ? 'title' : 'name' %>
<% 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 %>">
<h4 onclick="var d = jQuery(this).parent('.post_comment_box');
if (d.hasClass('closed')) {
d.removeClass('closed');
d.addClass('opened');
d.find('input[name=comment[title]], textarea').val('');
d.find('.comment_form input[name=comment[<%= focus_on %>]]').focus();
}">
<%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %>
</h4>
<% 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_for(@page.view_url.merge({:only_path => true})), { :class => 'comment_form' } ) do %>
<%= hidden_field_tag(:confirm, 'false') %>
<%= 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)) %>
<% button_bar do %>
<%= submit_button('add', _('Post comment'), :onclick => "submit_comment_form(this); return false") %>
<%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %>
<% end %>
<% end %>
</div><!-- end class="post_comment_box" -->