/** * @package comments */ (function($) { $(document).ready(function () { var commentsHolder = $('.comments-holder'), commentsList = $('.comments-list', commentsHolder), noCommentsYet = $('.no-comments-yet', commentsHolder), form = $('#Form_CommentsForm'), error = $('#Form_CommentsForm_error', form).hide() // create the not comments message if it doesn't exist yet, but hide it (incase we need it) if(!noCommentsYet.length){ noCommentsYet = $('
No one has commented on this page yet.
').appendTo(commentsHolder).hide(); } /** * Validate */ form.validate({ invalidHandler : function(form, validator){ $('html, body').animate({ scrollTop: $(validator.errorList[0].element).offset().top - 30 }, 200); }, errorElement: "span", errorClass: "error", rules: { Name : { required : true }, Email : { required : true, email : true }, Comment: { required : true }, URL: { url : true } }, messages: { Name : { required : 'Plaese enter your name' }, Email : { required : 'Plaese enter your email address', email : 'Plaese enter a valid email address' }, Comment: { required : 'Plaese enter your comment' }, URL: { url : 'Please enter a valid URL' } } }); /** * Clicking one of the metalinks performs the operation via ajax * this inclues the spam and approve links */ form.submit(function (e) { // trigger validation, if there are errors add the error classes to the elements if(!form.validate().valid()){ form.find('span.error').addClass('message required'); return false; } // submit the form $(this).ajaxSubmit(function(response) { noCommentsYet.hide(); if(!commentsList.length){ commentsHolder.append("