Subversion Repositories My Stuff

Rev

Rev 15 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*#######################################################################
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# Author: Andrzej Kardas
# License: GPLv3
# The full version of the licencse can be obtainted by visiting:
# http://www.gnu.org/licenses/gpl.html
#######################################################################*/

$(document).ready(function(){
        checkBoxChange();
        toggleLinkClick();
        checkboxChacked();
        var $comment;  
        var $options = {
                        success: function(data) {
                var response = $(data).find('#comments');
                $('#comments').replaceWith(response);
                $('#comment_form').find('form:first').validator().ajaxForm($options);
                checkboxChacked();
                checkBoxChange();
                toggleLinkClickSlide();
                $('#comment_form').find('textarea').val($comment);
                $('#comment_form > #comments-indicator').hide();
                $.scrollTo( '#comments', 800, {onAfter:function(){
                        $('.error').effect('pulsate');
                        $('.pagemessage').effect('pulsate');
                }
                });
                        },
                        beforeSubmit: function() {
                                $comment = $('#comment_form').find('textarea').val();
                                $('#comment_form > #comments-indicator').show();
                        }
                };
            $('#comment_form').find('form:first').validator().ajaxForm($options);
});

function checkboxChacked(){
        var form = $('#comment_form').find('form:first');
        var checkbox = form.find(':checkbox:first');
        var email = form.find(':email');
        if (checkbox.is(':checked')){
                email.attr("required", "required");
                email.attr("disabled", false);
        }else{
                email.attr("required", false);
                email.attr("required", true);
        }
}

function toggleLinkClickSlide(){
        var form = $('#comment_form').find('form:first');
        var toggle_link = $('#comments').find('a.toggle_link:first');
        var content = $('#comment_form');
        toggle_link.click(function(){
                if (toggle_link.is('.toggle_close')){
                        toggle_link.removeClass('toggle_close');
                        toggle_link.addClass('toggle_open');
                 } else if (toggle_link.is('.toggle_open')){
                        toggle_link.removeClass('toggle_open');
                        toggle_link.addClass('toggle_close');
                 }
                content.slideToggle('slow');
                var api = form.data("validator");
                api.reset();
                return false;
        });
}

function toggleLinkClick(){
        var form = $('#comment_form').find('form:first');
        var toggle_link = $('#comments').find('a.toggle_link:first');
        toggle_link.click(function(){
                var api = form.data("validator");
                api.reset();
                return false;
        });
}

function checkBoxChange(){
        var form = $('#comment_form').find('form:first');
        var email = form.find(':email');
        $('#comment_form').find(':checkbox:first').change(function(){
                if ($(this).is(':checked')) {
                        email.attr("required", "required");
                        email.attr("disabled", false);
                }else{
                        email.attr("required", false);
                        email.val("");
                        email.attr("disabled", true);
                        var api = form.data("validator");
                        api.reset(email);
                }      
        });
}