diff --git a/code/controllers/CommentingController.php b/code/controllers/CommentingController.php index 5bb0278..98da299 100644 --- a/code/controllers/CommentingController.php +++ b/code/controllers/CommentingController.php @@ -151,7 +151,7 @@ class CommentingController extends Controller { $comment->Moderated = true; $comment->write(); - return ($this->request->isAjax()) ? true : $this->redirectBack(); + return ($this->request->isAjax()) ? $comment->renderWith('CommentsInterface_singlecomment') : $this->redirectBack(); } return $this->httpError(404); @@ -172,7 +172,7 @@ class CommentingController extends Controller { $comment->Moderated = true; $comment->write(); - return ($this->request->isAjax()) ? true : $this->redirectBack(); + return ($this->request->isAjax()) ? $comment->renderWith('CommentsInterface_singlecomment') : $this->redirectBack(); } return $this->httpError(404); @@ -193,7 +193,7 @@ class CommentingController extends Controller { $comment->Moderated = true; $comment->write(); - return ($this->request->isAjax()) ? true : $this->redirectBack(); + return ($this->request->isAjax()) ? $comment->renderWith('CommentsInterface_singlecomment') : $this->redirectBack(); } return $this->httpError(404); @@ -376,12 +376,10 @@ class CommentingController extends Controller { if(Director::is_ajax()) { if(!$comment->Moderated) { - echo $comment->renderWith('CommentInterface_pendingcomment'); + return $comment->renderWith('CommentsInterface_pendingcomment'); } else { - echo $comment->renderWith('CommentInterface_singlecomment'); + return $comment->renderWith('CommentsInterface_singlecomment'); } - - return true; } $holder = Commenting::get_config_value($comment->BaseClass, 'comments_holder_id'); diff --git a/code/extensions/CommentsExtension.php b/code/extensions/CommentsExtension.php index 45c2785..d553027 100644 --- a/code/extensions/CommentsExtension.php +++ b/code/extensions/CommentsExtension.php @@ -97,6 +97,10 @@ class CommentsExtension extends DataExtension { * @see docs/en/Extending */ public function CommentsForm() { + Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/lib/jquery.form.js'); + Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/jquery.validate.pack.js'); + Requirements::javascript('comments/javascript/CommentsInterface.js'); + $interface = new SSViewer('CommentsInterface'); // detect whether we comments are enabled. By default if $CommentsForm is included diff --git a/javascript/CommentsInterface.js b/javascript/CommentsInterface.js index a0dcdff..4716223 100755 --- a/javascript/CommentsInterface.js +++ b/javascript/CommentsInterface.js @@ -1,130 +1,148 @@ /** - * @package userforms + * @package comments */ - (function($) { $(document).ready(function () { - /** - * Please note this functionality has not been finished - * this file is not loaded on your site. It is simply here - * to provide a starting point for someone to take it over - * - * @todo finish - */ - - return false; - - - - - - - - $('.comments-holder-container form').submit(function (e) { + var commentsHolder = $('.comments-holder'), + commentsList = $('.comments-list', commentsHolder), + noCommentsYet = $('.no-comments-yet', commentsHolder), + form = $('#Form_CommentsForm'), + error = $('#Form_CommentsForm_error', form).hide() - if($('.comment-holder form [name=Name]').val() && $('.comment-holder form [name=Comment]').val()) { - // remove the no comments posted text - if($('.no-comments-yet').length > 0) { - $('.no-comments-yet').remove(); - - $(this).parents(".comments-holder-container") - .find(".comments-holder") - .append("
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' } - - error.hide(); - $('#PageComments').prepend('Loading...
No one has commented on this page yet.
"); + if(commentsList.children().length == 0) { + noCommentsYet.show(); } }); } else if(link.hasClass('spam')) { if(html) { - hide.html(html); - hide.effect("highlight", {}, 1000); + comment.html(html).addClass('spam').hide().fadeIn(); } else { - hide.fadeOut(1000, function() { // Fade out the comment - var comments = hide.parent(); // Grab the comments holder - hide.remove(); // remove the comment + comment.fadeOut(1000, function() { // Fade out the comment + comment.remove(); // remove the comment if(comments.children().length == 0) { - comments.html("No one has commented on this page yet.
"); + noCommentsYet.show(); } }); }