When comment_id_key is passed as URL parameter, focus on this comment, instead of the top comment of the related thread.
authorgibus
Mon, 08 Nov 2010 12:41:44 +0100
changeset 329 00df963f91fb
parent 328 2a6033ca510e
child 330 db7616686c57
When comment_id_key is passed as URL parameter, focus on this comment, instead of the top comment of the related thread.
src/cm/media/js/client/c_icomment.js
src/cm/media/js/client/c_icomments.js
src/cm/media/js/client/c_sync.js
src/cm/media/js/site/c_text_view_comments.js
--- a/src/cm/media/js/client/c_icomment.js	Tue Nov 02 16:31:20 2010 +0100
+++ b/src/cm/media/js/client/c_icomment.js	Mon Nov 08 12:41:44 2010 +0100
@@ -423,9 +423,19 @@
 		if (gIComments.animationsEnded())
 			gIComments.whenAnimationsEnd() ;		
 	},
+	onAnimationEndFocus : function() {
+		if (!CY.Lang.isUndefined(this['animation-handle']) && !CY.Lang.isNull(this['animation-handle'])) { 
+			this['animation-handle'].detach() ;
+			this['animation-handle'] = null ;
+//			CY.log('detached...') ;
+		}
+		gIComments.signalAnimationEnd() ;
+		if (gIComments.animationsEnded())
+			gIComments.whenAnimationsEndFocus() ;		
+	},
 
 	//aa = new CY.Anim({node:gIComments._c[0].overlay.get('boundingBox'), to:{xy : [0,0]}, duration:2.0})
-	setAnimationToPosition : function(toXY) {
+	setAnimationToPosition : function(toXY, focus) {
 		var boundingBoxNode = this.overlay.get('boundingBox') ;
 		
 		// ANIMATION
@@ -435,7 +445,9 @@
 		
 		this.animation.set('to', { xy: toXY});
 		this.animation.set('duration', gPrefs.get('general','animduration')) ; // shouldn't be here really ...
-		this['animation-handle'] = this.animation.on('end', this.onAnimationEnd, this);
+    if (focus)
+    	this['animation-handle'] = this.animation.on('end', this.onAnimationEndFocus, this);
+    	this['animation-handle'] = this.animation.on('end', this.onAnimationEnd, this);
 		
 		return this.animation ;
 	},
--- a/src/cm/media/js/client/c_icomments.js	Tue Nov 02 16:31:20 2010 +0100
+++ b/src/cm/media/js/client/c_icomments.js	Mon Nov 08 12:41:44 2010 +0100
@@ -172,6 +172,31 @@
 			}
 		},
 		
+		setAnimationToPositionsAndFocus : function (y, focusCommentId) {
+			this._initAnimations();
+			var lpad = (gPrefs.get('comments','threadpad') == '1') ? gConf['iCommentThreadPadding'] : 0 ;
+
+			var nextY = y ;
+			for (var i = 0 ; i < this._c.length;i++) {
+				var iComment = this._c[i] ;
+				if (iComment.isfetched && iComment.isVisible()) {
+					var comment_path = gDb.getPath(gDb.getComment(iComment.commentId)) ;
+					var iCommentX = ((comment_path.length - 1) * lpad) + gConf['iCommentLeftPadding'] ;
+
+					if (nextY == null) {
+						var xy = iComment.getPosition() ;
+						nextY = xy[1] ;
+					}
+					
+          if (iComment.commentId == focusCommentId)
+  					this._a.push(iComment.setAnimationToPosition([iCommentX, nextY], focusCommentId)) ;
+          else
+  					this._a.push(iComment.setAnimationToPosition([iCommentX, nextY])) ;
+					nextY += iComment.getHeight() ;
+				}
+			}
+		},
+		
 // ANIMATION FUNCTIONS		
 		_initAnimations : function () {
 			this._a = [] ;
@@ -189,6 +214,17 @@
 			gSync.resume() ; 		
 		},
 		
+		whenAnimationsEndFocus : function () {
+      gGETValues = CY.JSON.parse(sv_get_params);
+      if ("comment_id_key" in gGETValues) {
+        var id_key = gGETValues["comment_id_key"];
+        var focusComment = gDb.getCommentByIdKey(id_key);
+        if (focusComment != null)
+          gIComments.getIComment(focusComment.id).overlay.focus();
+      }
+			gSync.resume();
+		},
+		
 		animationsEnded : function () {
 			return ((this._a.length == 0) || (this._a.length == this._nbEndedAnim)) ; 		
 		},
--- a/src/cm/media/js/client/c_sync.js	Tue Nov 02 16:31:20 2010 +0100
+++ b/src/cm/media/js/client/c_sync.js	Mon Nov 08 12:41:44 2010 +0100
@@ -387,6 +387,20 @@
 				this._animateTo(topY) ;
 		}
 	},
+	_showFocusSingleComment : function(topComment, focusComment) {
+		if (topComment != null) {
+			var topY = 0 ;
+			if (topComment['start_wrapper'] != -1) 
+				topY = CY.get(".c-id-"+topComment.id).getY() ;
+			else 
+				topY = CY.get('document').get('scrollTop') ;
+			
+			this._showComments([topComment.id], topY, false) ;
+			// optim when browsing comments with no reply			
+			if (topComment.replies.length > 0)
+				this._animateToAndFocus(topY, focusComment.id) ;
+		}
+	},
 
 	showSingleComment : function(comment) {
 		this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
@@ -395,6 +409,13 @@
 		this._q.run();
 	},
 	
+	showFocusSingleComment : function(topComment, focusComment) {
+		this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
+		this._showFocusSingleComment(topComment, focusComment) ;
+		this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
+		this._q.run();
+	},
+	
 	browse : function(order, whereto) { 
 		var comment = gIComments.browse(order, whereto) ;
 		if (comment != null) 
@@ -436,6 +457,14 @@
 	            ) ;
 	},
 	
+	_animateToAndFocus : function(topY, focusCommentId) {
+		this._q.add({fn:function() {
+						gIComments.setAnimationToPositionsAndFocus(topY, focusCommentId) ;
+						}},
+					{id:"animationRun", autoContinue:false, fn:CY.bind(gIComments.runAnimations, gIComments)}
+	            ) ;
+	},
+	
 	_animateToTop : function() {
 		var topPos = gIComments.getTopPosition() ;
 		if (topPos != null)
--- a/src/cm/media/js/site/c_text_view_comments.js	Tue Nov 02 16:31:20 2010 +0100
+++ b/src/cm/media/js/site/c_text_view_comments.js	Mon Nov 08 12:41:44 2010 +0100
@@ -291,7 +291,8 @@
 				if (comment != null) {
 					var path = gDb.getPath(comment) ;
 					var topParentComment = path[path.length - 1] ;
-					gSync.showSingleComment(topParentComment) ;
+          var focusComment = gDb.getCommentByIdKey(id_key);
+					gSync.showFocusSingleComment(topParentComment, focusComment) ;
 				}
 			}