Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding comment preview

  • Loading branch information...
commit 1917084f3850d955af3e036bba646d15dd926f1e 1 parent 31e0bc0
Nibsirahsieu authored
9 modules/sfNestedComment/lib/BasesfNestedCommentActions.class.php
View
@@ -90,4 +90,13 @@ public function executeCommenting(sfWebRequest $request)
$comments = sfNestedCommentTools::getComments($commentableObject, $request);
return $this->renderPartial('sfNestedComment/comment_list', array('comments' => $comments));
}
+
+ public function executePreview(sfWebRequest $request)
+ {
+ $this->forward404Unless($request->isXmlHttpRequest() && $request->isMethod('post'));
+ $this->setLayout(false);
+
+ $commentText = sfNestedCommentTools::clean($request->getPostParameter('commentText'));
+ return $this->renderText($commentText);
+ }
}
12 modules/sfNestedComment/templates/_add_comment.php
View
@@ -1,4 +1,8 @@
<?php $use_ajax = sfNestedCommentConfig::isAjaxEnabled() ?>
+<?php if ($use_ajax): ?>
+ <?php use_stylesheet('/sfNestedCommentPlugin/css/commentPreview.css', 'last') ?>
+ <?php use_javascript('/sfNestedCommentPlugin/js/commentPreview.js', 'last') ?>
+<?php endif; ?>
<div id="respond">
<h3 id="replay-title"><?php echo __('Leave a reply') ?>&nbsp;<small><a href="#respond" id="cancel-comment-reply-link">Cancel Reply</a></small></h3>
@@ -7,13 +11,17 @@
<div class="form-submit">
<input type="submit" value="<?php echo (__('Submit comment')) ?>" id="sumbit-comment" />
<?php if($use_ajax): ?>
+ <input type="button" value="Preview" id="preview-comment-button" />
<span id="add-comment-loader" style="display:none;"><?php echo image_tag('/sfNestedCommentPlugin/images/loading.gif') ?></span>
<?php endif; ?>
</div>
- <input type="hidden" name="referer" value="<?php echo $sf_request->getReferer() ?>" />
</form>
+ <?php if($use_ajax): ?>
+ <div class="lp-block" id="live-preview-display">
+ <div id="lp-comment"></div>
+ </div>
+ <?php endif; ?>
</div>
-
<?php if($use_ajax): ?>
<?php use_javascript('/sfNestedCommentPlugin/js/commentForm.js') ?>
<script type="text/javascript">
3  web/css/commentPreview.css
View
@@ -0,0 +1,3 @@
+.lp-block {width:96%;float:left;margin-bottom: 10px;}
+#live-preview-display {background:#eee;padding:10px;}
+#lp-comment {padding-top:5px;line-height:19px;}
21 web/js/commentPreview.js
View
@@ -0,0 +1,21 @@
+jQuery(document).ready(function() {
+ jQuery('#preview-comment-button').click(function(){
+ var commentBox = jQuery('#lp-comment');
+ var loader = jQuery('#add-comment-loader');
+ jQuery.ajax({
+ type: 'POST',
+ url: location.protocol + '//' + location.host + '/sfNestedComment/preview',
+ async: false,
+ data: { commentText: jQuery('#sf_nested_comment_content').val() },
+ beforeSend:function() { loader.show(); },
+ success:function(response, textStatus) {
+ commentBox.html(response);
+ loader.hide();
+ },
+ error:function(XMLHttpRequest, textStatus, errorThrown) {
+ loader.hide();
+ alert(textStatus);
+ }
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.