Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding comment preview

  • Loading branch information...
commit 1917084f3850d955af3e036bba646d15dd926f1e 1 parent 31e0bc0
Nibsirahsieu authored
9 modules/sfNestedComment/lib/BasesfNestedCommentActions.class.php
@@ -90,4 +90,13 @@ public function executeCommenting(sfWebRequest $request)
90 90 $comments = sfNestedCommentTools::getComments($commentableObject, $request);
91 91 return $this->renderPartial('sfNestedComment/comment_list', array('comments' => $comments));
92 92 }
  93 +
  94 + public function executePreview(sfWebRequest $request)
  95 + {
  96 + $this->forward404Unless($request->isXmlHttpRequest() && $request->isMethod('post'));
  97 + $this->setLayout(false);
  98 +
  99 + $commentText = sfNestedCommentTools::clean($request->getPostParameter('commentText'));
  100 + return $this->renderText($commentText);
  101 + }
93 102 }
12 modules/sfNestedComment/templates/_add_comment.php
... ... @@ -1,4 +1,8 @@
1 1 <?php $use_ajax = sfNestedCommentConfig::isAjaxEnabled() ?>
  2 +<?php if ($use_ajax): ?>
  3 + <?php use_stylesheet('/sfNestedCommentPlugin/css/commentPreview.css', 'last') ?>
  4 + <?php use_javascript('/sfNestedCommentPlugin/js/commentPreview.js', 'last') ?>
  5 +<?php endif; ?>
2 6
3 7 <div id="respond">
4 8 <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 @@
7 11 <div class="form-submit">
8 12 <input type="submit" value="<?php echo (__('Submit comment')) ?>" id="sumbit-comment" />
9 13 <?php if($use_ajax): ?>
  14 + <input type="button" value="Preview" id="preview-comment-button" />
10 15 <span id="add-comment-loader" style="display:none;"><?php echo image_tag('/sfNestedCommentPlugin/images/loading.gif') ?></span>
11 16 <?php endif; ?>
12 17 </div>
13   - <input type="hidden" name="referer" value="<?php echo $sf_request->getReferer() ?>" />
14 18 </form>
  19 + <?php if($use_ajax): ?>
  20 + <div class="lp-block" id="live-preview-display">
  21 + <div id="lp-comment"></div>
  22 + </div>
  23 + <?php endif; ?>
15 24 </div>
16   -
17 25 <?php if($use_ajax): ?>
18 26 <?php use_javascript('/sfNestedCommentPlugin/js/commentForm.js') ?>
19 27 <script type="text/javascript">
3  web/css/commentPreview.css
... ... @@ -0,0 +1,3 @@
  1 +.lp-block {width:96%;float:left;margin-bottom: 10px;}
  2 +#live-preview-display {background:#eee;padding:10px;}
  3 +#lp-comment {padding-top:5px;line-height:19px;}
21 web/js/commentPreview.js
... ... @@ -0,0 +1,21 @@
  1 +jQuery(document).ready(function() {
  2 + jQuery('#preview-comment-button').click(function(){
  3 + var commentBox = jQuery('#lp-comment');
  4 + var loader = jQuery('#add-comment-loader');
  5 + jQuery.ajax({
  6 + type: 'POST',
  7 + url: location.protocol + '//' + location.host + '/sfNestedComment/preview',
  8 + async: false,
  9 + data: { commentText: jQuery('#sf_nested_comment_content').val() },
  10 + beforeSend:function() { loader.show(); },
  11 + success:function(response, textStatus) {
  12 + commentBox.html(response);
  13 + loader.hide();
  14 + },
  15 + error:function(XMLHttpRequest, textStatus, errorThrown) {
  16 + loader.hide();
  17 + alert(textStatus);
  18 + }
  19 + });
  20 + });
  21 +});

0 comments on commit 1917084

Please sign in to comment.
Something went wrong with that request. Please try again.