Răsfoiți Sursa

Ticket #1527 - Related changes in Comments.

AntonLV 8 ani în urmă
părinte
comite
2345806b52
2 a modificat fișierele cu 69 adăugiri și 66 ștergeri
  1. 57 53
      inc/js/classes/BxDolCmts.js
  2. 12 13
      template/scripts/BxBaseCmts.php

+ 57 - 53
inc/js/classes/BxDolCmts.js

@@ -28,9 +28,12 @@ function BxDolCmts (options) {
     this._sRootId = '#cmts-box-' + this._sSystem + '-' + this._iObjId;
 
     // init post comment form
-    if ($(this._sRootId + ' .cmt-post-reply form').length) {
-    	var sFormId = $(this._sRootId + ' .cmt-post-reply form').attr('id');
-    	this.cmtInitFormPost(sFormId);
+    var $this = this;
+    var sFormId = this._sRootId + ' .cmt-post-reply form';
+    if ($(sFormId).length) {
+    	$(sFormId).each(function() {
+            $this.cmtInitFormPost($(this));
+        });
     }
 
     // blink (highlight) necessary comments
@@ -40,18 +43,17 @@ function BxDolCmts (options) {
 }
 
 /*--- Main layout functionality ---*/
-BxDolCmts.prototype.cmtInitFormPost = function(sCmtFormId)
+BxDolCmts.prototype.cmtInitFormPost = function(oCmtForm)
 {
-	var $this = this;
-	var oCmtForm = $('#' + sCmtFormId);
+    var $this = this;
 
-	oCmtForm.ajaxForm({
+    oCmtForm.ajaxForm({
         dataType: "json",
         beforeSubmit: function (formData, jqForm, options) {
-        	window[$this._sObjName].cmtBeforePostSubmit(oCmtForm);
+            window[$this._sObjName].cmtBeforePostSubmit(oCmtForm);
         },
         success: function (oData) {
-        	window[$this._sObjName].cmtAfterPostSubmit(oCmtForm, oData);
+            window[$this._sObjName].cmtAfterPostSubmit(oCmtForm, oData);
         }
     });
 };
@@ -75,43 +77,45 @@ BxDolCmts.prototype.cmtShowForm = function(oElement)
 
 BxDolCmts.prototype.cmtBeforePostSubmit = function(oCmtForm)
 {
-	this._loadingInButton($(oCmtForm).children().find(':submit'), true);
+    this._loadingInButton($(oCmtForm).children().find(':submit'), true);
 };
 
 BxDolCmts.prototype.cmtAfterPostSubmit = function (oCmtForm, oData)
 {
 	var $this = this;
 	var fContinue = function() {
-		if(oData && oData.id != undefined) {
-			var iCmtId = parseInt(oData.id);
-	        if(iCmtId > 0) {
-	            $this._getCmt(oCmtForm, iCmtId);
-	            $this._getForm(undefined, parseInt(oData.parent_id), function(sForm) {
-	            	var oForm = $(sForm);
-	            	oCmtForm.parents('.cmt-reply:first').hide().html(oForm.html()).show();
-
-	            	var sFormId = oForm.find('form').attr('id');
-	            	$this.cmtInitFormPost(sFormId);
-	            });
-	        }
+            var oParent = oCmtForm.parents('.cmt-reply:first');
 
-	        return;
-		}
+            if(oData && oData.id != undefined) {
+                var iCmtId = parseInt(oData.id);
+                if(iCmtId > 0) {
+                    $this._getCmt(oCmtForm, iCmtId);
+                    $this._getForm(undefined, parseInt(oData.parent_id), function(sFormWrp) {
+                        var oFormWrp = $(sFormWrp);
+                        oParent.hide().html(oFormWrp.html()).show();
 
-		if(oData && oData.form != undefined && oData.form_id != undefined) {
-			$('#' + oData.form_id).replaceWith(oData.form);
-			$this.cmtInitFormPost(oData.form_id);
+                        $this.cmtInitFormPost(oParent.find('form'));
+                    });
+                }
 
-			return;
-		}
+                return;
+            }
+
+            if(oData && oData.form != undefined && oData.form_id != undefined) {
+                oParent.find('form').replaceWith(oData.form);
+
+                $this.cmtInitFormPost(oParent.find('form'));
+
+                return;
+            }
 	};
 
 	this._loadingInButton($(oCmtForm).children().find(':submit'), false);
 
 	if(oData && oData.msg != undefined)
-        bx_alert(oData.msg, fContinue);
-	else 
-		fContinue();	
+            bx_alert(oData.msg, fContinue);
+        else 
+            fContinue();
 };
 
 BxDolCmts.prototype.cmtInitFormEdit = function(sCmtFormId)
@@ -340,36 +344,36 @@ BxDolCmts.prototype.showImage = function(oLink, sUrl) {
 
 BxDolCmts.prototype.toggleReply = function(e, iCmtParentId)
 {
-	var $this = this;
-	var sParentId = this._sRootId + ' #cmt' + iCmtParentId;
-	var fOnShow = function() {
-		$(this).find('textarea:first').focus();
-	};
+    var $this = this;
+    var sParentId = this._sRootId + ' #cmt' + iCmtParentId;
+    var fOnShow = function() {
+        $(this).find('textarea:first').focus();
+    };
 
-	var sReplyId = sParentId + ' > .cmt-reply';
+    var sReplyId = sParentId + ' > .cmt-reply';
     if ($(sReplyId).length) {
-		$(sReplyId).bx_anim('toggle', this._sAnimationEffect, this._iAnimationSpeed, fOnShow);
-		return;
+        $(sReplyId).bx_anim('toggle', this._sAnimationEffect, this._iAnimationSpeed, fOnShow);
+        return;
     }
 
-	this._getForm(e, iCmtParentId, function(sForm) {
-		var oForm = $(sForm).hide().addClass('cmt-reply-' + $this._sPostFormPosition).addClass('cmt-reply-margin');
+    this._getForm(e, iCmtParentId, function(sForm) {
+        var oForm = $(sForm).hide().addClass('cmt-reply-' + $this._sPostFormPosition).addClass('cmt-reply-margin');
         var oFormSibling = $(sParentId + ' > ul.cmts:first');
         switch($this._sPostFormPosition) {
-        	case 'top':
-        		oFormSibling.before(oForm);
-        		break;
+            case 'top':
+                oFormSibling.before(oForm);
+                break;
 
-        	case 'bottom':
-        		oFormSibling.after(oForm);
-        		break;
+            case 'bottom':
+                oFormSibling.after(oForm);
+                break;
         }
 
         var sFormId = oForm.find('form').attr('id');
         $this.cmtInitFormPost(sFormId);
 
-    	$(sParentId).children('.cmt-reply').bx_anim('toggle', $this._sAnimationEffect, $this._iAnimationSpeed, fOnShow);    		
-	});
+        $(sParentId).children('.cmt-reply').bx_anim('toggle', $this._sAnimationEffect, $this._iAnimationSpeed, fOnShow);
+    });
 };
 
 BxDolCmts.prototype.goTo = function(oLink, sGoToId, sBlinkIds, onLoad)
@@ -584,11 +588,11 @@ BxDolCmts.prototype._getForm = function (e, iCmtParentId, onLoad)
         this._sActionsUrl,
         oData,
         function (s) {
-        	if(e)
-        		$this._loadingInContent(e, false);
+            if(e)
+                $this._loadingInContent(e, false);
 
             if(typeof onLoad == 'function')
-    			onLoad(s);
+                onLoad(s);
         }
     );
 };

+ 12 - 13
template/scripts/BxBaseCmts.php

@@ -62,7 +62,7 @@ class BxBaseCmts extends BxDolCmts
         if(empty(self::$_sTmplContentCounter))
             self::$_sTmplContentCounter = $this->_oTemplate->getHtml('comment_counter.html');
 
-        BxDolTemplate::getInstance()->addJsTranslation('_sys_txt_cmt_loading');
+        $this->_oTemplate->addJsTranslation('_sys_txt_cmt_loading');
     }
 
     /**
@@ -102,7 +102,7 @@ class BxBaseCmts extends BxDolCmts
         );
 
         $this->addCssJs();
-        return BxDolTemplate::getInstance()->_wrapInTagJsCode("var " . $this->_sJsObjName . " = new BxDolCmts(" . json_encode($aParams) . ");");
+        return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new BxDolCmts(" . json_encode($aParams) . ");");
     }
 
     /**
@@ -120,7 +120,7 @@ class BxBaseCmts extends BxDolCmts
         //add live update
 
         $sCaption = _t($this->_aT['block_comments_title'], $this->getCommentsCountAll());
-        $sContent = BxDolTemplate::getInstance()->parseHtmlByName('comments_block.html', array(
+        $sContent = $this->_oTemplate->parseHtmlByName('comments_block.html', array(
             'system' => $this->_sSystem,
             'list_anchor' => $this->getListAnchor(),
             'id' => $this->getId(),
@@ -182,7 +182,7 @@ class BxBaseCmts extends BxDolCmts
         if (!$sComment)
             return '';
 
-        return BxDolTemplate::getInstance()->parseHtmlByName('comment_block.html', array(
+        return $this->_oTemplate->parseHtmlByName('comment_block.html', array(
             'system' => $this->_sSystem,
             'id' => $this->getId(),
             'comment' => $sComment,
@@ -310,7 +310,7 @@ class BxBaseCmts extends BxDolCmts
         if(empty($sAddon))
             $sAddon = $this->getJsScript($aBp, $aDp);
 
-        return BxDolTemplate::getInstance()->parseHtmlByName('comment_search.html', array(
+        return $this->_oTemplate->parseHtmlByName('comment_search.html', array(
             'comment' => $this->getComment($iCmtId, $aBp, $aDp),
             'view_image_popup' => $this->_getViewImagePopup(), 
         )); 
@@ -333,7 +333,7 @@ class BxBaseCmts extends BxDolCmts
         if(empty($sViewLink))
             $sViewLink = '#';
 
-        return BxDolTemplate::getInstance()->parseHtmlByName('comment_live_search.html', array(
+        return $this->_oTemplate->parseHtmlByName('comment_live_search.html', array(
             'bx_if:show_icon' => array(
                 'condition' => $bAuthorIcon,
                 'content' => array(
@@ -385,7 +385,6 @@ class BxBaseCmts extends BxDolCmts
 			return '';
 
 		$sJsObject = $this->getJsObjectName();
-		$oTemplate = BxDolTemplate::getInstance();
 
 		$aComments = array_reverse($aComments);
 		$iComments = count($aComments);
@@ -402,7 +401,7 @@ class BxBaseCmts extends BxDolCmts
 	    			'condition' => $iIndex < ($iComments - 1),
 	    			'content' => array(),
 	    		),
-	    		'item' => $oTemplate->parseHtmlByName('comments_notification.html', array_merge(array(
+	    		'item' => $this->_oTemplate->parseHtmlByName('comments_notification.html', array_merge(array(
 	    			'style_prefix' => $this->_sStylePrefix,
 	    			'onclick_show' => $sShowOnClick,
 	    			'onclick_reply' => $sReplyOnClick,
@@ -417,7 +416,7 @@ class BxBaseCmts extends BxDolCmts
 			);
 		}
 
-		return $oTemplate->parseHtmlByName('popup_chain.html', array(
+		return $this->_oTemplate->parseHtmlByName('popup_chain.html', array(
 			'html_id' => $this->getNotificationId(),
 			'bx_repeat:items' => $aTmplVarsNotifs
 		));
@@ -699,7 +698,7 @@ class BxBaseCmts extends BxDolCmts
         $sMethod = '_getForm' . ucfirst($sType);
         $aForm = $this->$sMethod($iCmtParentId, $aDp);
 
-        return BxDolTemplate::getInstance()->parseHtmlByName('comment_reply_box.html', array(
+        return $this->_oTemplate->parseHtmlByName('comment_reply_box.html', array(
             'js_object' => $this->_sJsObjName,
             'style_prefix' => $this->_sStylePrefix,
             'class' => $sClass,
@@ -870,7 +869,7 @@ class BxBaseCmts extends BxDolCmts
 
         $bRoot = (int)$aBp['vparent_id'] <= 0;
 
-        $sMore = BxDolTemplate::getInstance()->parseHtmlByName('comment_more.html', array(
+        $sMore = $this->_oTemplate->parseHtmlByName('comment_more.html', array(
             'js_object' => $this->_sJsObjName,
             'style_prefix' => $this->_sStylePrefix,
             'bx_if:is_root' => array(
@@ -900,7 +899,7 @@ class BxBaseCmts extends BxDolCmts
 
     protected function _getEmpty()
     {
-        return BxDolTemplate::getInstance()->parseHtmlByName('comment_empty.html', array(
+        return $this->_oTemplate->parseHtmlByName('comment_empty.html', array(
             'style_prefix' => $this->_sStylePrefix,
             'content' => MsgBox(_t('_Empty'))
         ));
@@ -909,7 +908,7 @@ class BxBaseCmts extends BxDolCmts
     protected function _getViewImagePopup()
     {
     	$sViewImagePopupId = 'cmts-box-' . $this->_sSystem . '-' . $this->getId() . '-view-image-popup' ;
-        $sViewImagePopupContent = BxDolTemplate::getInstance()->parseHtmlByName('popup_image.html', array(
+        $sViewImagePopupContent = $this->_oTemplate->parseHtmlByName('popup_image.html', array(
     		'image_url' => ''
     	));