Rev 15 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14 | kardasa | 1 | /*####################################################################### |
2 | # This script is distributed in the hope that it will be useful, |
||
3 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
4 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
5 | # GNU General Public License for more details. |
||
6 | # Author: Andrzej Kardas |
||
7 | # License: GPLv3 |
||
8 | # The full version of the licencse can be obtainted by visiting: |
||
9 | # http://www.gnu.org/licenses/gpl.html |
||
10 | #######################################################################*/ |
||
11 | $(document).ready(function(){ |
||
12 | checkBoxChange(); |
||
13 | toggleLinkClick(); |
||
14 | checkboxChacked(); |
||
27 | kardasa | 15 | var $comment; |
14 | kardasa | 16 | var $options = { |
17 | success: function(data) { |
||
18 | var response = $(data).find('#comments'); |
||
19 | $('#comments').replaceWith(response); |
||
20 | $('#comment_form').find('form:first').validator().ajaxForm($options); |
||
21 | checkboxChacked(); |
||
22 | checkBoxChange(); |
||
23 | toggleLinkClickSlide(); |
||
27 | kardasa | 24 | $('#comment_form').find('textarea').val($comment); |
14 | kardasa | 25 | $('#comment_form > #comments-indicator').hide(); |
15 | kardasa | 26 | $.scrollTo( '#comments', 800, {onAfter:function(){ |
27 | $('.error').effect('pulsate'); |
||
28 | $('.pagemessage').effect('pulsate'); |
||
29 | } |
||
30 | }); |
||
14 | kardasa | 31 | }, |
32 | beforeSubmit: function() { |
||
27 | kardasa | 33 | $comment = $('#comment_form').find('textarea').val(); |
14 | kardasa | 34 | $('#comment_form > #comments-indicator').show(); |
35 | } |
||
36 | }; |
||
37 | $('#comment_form').find('form:first').validator().ajaxForm($options); |
||
38 | }); |
||
39 | |||
40 | function checkboxChacked(){ |
||
41 | var form = $('#comment_form').find('form:first'); |
||
42 | var checkbox = form.find(':checkbox:first'); |
||
43 | var email = form.find(':email'); |
||
44 | if (checkbox.is(':checked')){ |
||
45 | email.attr("required", "required"); |
||
46 | email.attr("disabled", false); |
||
47 | }else{ |
||
48 | email.attr("required", false); |
||
49 | email.attr("required", true); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | function toggleLinkClickSlide(){ |
||
54 | var form = $('#comment_form').find('form:first'); |
||
55 | var toggle_link = $('#comments').find('a.toggle_link:first'); |
||
56 | var content = $('#comment_form'); |
||
57 | toggle_link.click(function(){ |
||
58 | if (toggle_link.is('.toggle_close')){ |
||
59 | toggle_link.removeClass('toggle_close'); |
||
60 | toggle_link.addClass('toggle_open'); |
||
61 | } else if (toggle_link.is('.toggle_open')){ |
||
62 | toggle_link.removeClass('toggle_open'); |
||
63 | toggle_link.addClass('toggle_close'); |
||
64 | } |
||
65 | content.slideToggle('slow'); |
||
66 | var api = form.data("validator"); |
||
67 | api.reset(); |
||
68 | return false; |
||
69 | }); |
||
70 | } |
||
71 | |||
72 | function toggleLinkClick(){ |
||
73 | var form = $('#comment_form').find('form:first'); |
||
74 | var toggle_link = $('#comments').find('a.toggle_link:first'); |
||
75 | toggle_link.click(function(){ |
||
76 | var api = form.data("validator"); |
||
77 | api.reset(); |
||
78 | return false; |
||
79 | }); |
||
80 | } |
||
81 | |||
82 | function checkBoxChange(){ |
||
83 | var form = $('#comment_form').find('form:first'); |
||
84 | var email = form.find(':email'); |
||
85 | $('#comment_form').find(':checkbox:first').change(function(){ |
||
86 | if ($(this).is(':checked')) { |
||
87 | email.attr("required", "required"); |
||
88 | email.attr("disabled", false); |
||
89 | }else{ |
||
90 | email.attr("required", false); |
||
91 | email.val(""); |
||
92 | email.attr("disabled", true); |
||
93 | var api = form.data("validator"); |
||
94 | api.reset(email); |
||
95 | } |
||
96 | }); |
||
97 | } |