src/cm/media/js/client/c_sync.js
changeset 103 61fd17f9ab78
parent 24 c8a95e540b79
child 106 36165e7cd1f0
equal deleted inserted replaced
78:dda94db1149a 103:61fd17f9ab78
   373 	},
   373 	},
   374 	_showSingleComment : function(comment) {
   374 	_showSingleComment : function(comment) {
   375 		if (comment != null) {
   375 		if (comment != null) {
   376 			var path = gDb.getPath(comment) ;
   376 			var path = gDb.getPath(comment) ;
   377 			var topAncestorComment = path[path.length - 1] ;
   377 			var topAncestorComment = path[path.length - 1] ;
   378 			var topY = CY.get(".c-id-"+topAncestorComment.id).getY() ;
   378 			var topY = 0 ;
       
   379 			if (comment['start_wrapper'] != -1) 
       
   380 				topY = CY.get(".c-id-"+topAncestorComment.id).getY() ;
       
   381 			else 
       
   382 				topY = CY.get('document').get('scrollTop') ;
       
   383 			
   379 			this._showComments([topAncestorComment.id], topY, false) ;
   384 			this._showComments([topAncestorComment.id], topY, false) ;
   380 			// optim when browsing comments with no reply			
   385 			// optim when browsing comments with no reply			
   381 			if (topAncestorComment.replies.length > 0)
   386 			if (topAncestorComment.replies.length > 0)
   382 				this._animateTo(topY) ;
   387 				this._animateTo(topY) ;
   383 		}
   388 		}
   394 		var comment = gIComments.browse(order, whereto) ;
   399 		var comment = gIComments.browse(order, whereto) ;
   395 		if (comment != null) 
   400 		if (comment != null) 
   396 			this.showSingleComment(comment) ;
   401 			this.showSingleComment(comment) ;
   397 	},
   402 	},
   398 	
   403 	
   399 	_showComments : function(commentDbIds, topY, showingAll) {
   404 	_showComments : function(commentDbIds, topY, atDocumentTop) {
   400 		this._q.add(
   405 		this._q.add(
   401 			{fn:function() {
   406 			{fn:function() {
   402 				gShowingAllComments = showingAll ;			
   407 				gShowingAllComments = atDocumentTop ;			
   403 				gIComments.hide() ; 
   408 				gIComments.hide() ; 
   404 				var cs = CY.Array.map(commentDbIds, function(id) { return gDb.getComment(id) ; }) ;
   409 				var cs = CY.Array.map(commentDbIds, function(id) { return gDb.getComment(id) ; }) ;
   405 				var comments = gDb.getThreads(cs) ;
   410 				var comments = gDb.getThreads(cs) ;
   406 				gIComments.fetch(comments) ;
   411 				gIComments.fetch(comments) ;
   407 	
   412 	
   408 				if (commentDbIds.length > 0) {
   413 				if (commentDbIds.length > 0) {
   409 					if (!showingAll) {
   414 					if (atDocumentTop) {
       
   415 						CY.get('document').set('scrollTop', 0) ; 
       
   416 					}
       
   417 					else {
   410 						gIComments.activate(commentDbIds[0]) ;
   418 						gIComments.activate(commentDbIds[0]) ;
   411 						var scopeStart = CY.get(".c-id-"+commentDbIds[0]) ;
   419 						var scopeStart = CY.get(".c-id-"+commentDbIds[0]) ;
   412 						if (!scopeStart.inViewportRegion())
   420 						if (scopeStart && !scopeStart.inViewportRegion()) // scopeStart could be null when comment has no scope
   413 							scopeStart.scrollIntoView(true) ;
   421 							scopeStart.scrollIntoView(true) ;
   414 					}
       
   415 					else {
       
   416 						CY.get('document').set('scrollTop', 0) ; 
       
   417 					}
   422 					}
   418 				}
   423 				}
   419 				
   424 				
   420 				gIComments.setPosition([gConf['iCommentLeftPadding'], topY]) ;
   425 				gIComments.setPosition([gConf['iCommentLeftPadding'], topY]) ;
   421 	
   426 	
   450 			var allTopComments = CY.Array.map(gDb.comments, function(c){return c.id;}) ;
   455 			var allTopComments = CY.Array.map(gDb.comments, function(c){return c.id;}) ;
   451 			this.showComments(allTopComments, [0,0], true) ;
   456 			this.showComments(allTopComments, [0,0], true) ;
   452 		}, this, null) ;
   457 		}, this, null) ;
   453 	},
   458 	},
   454 
   459 
   455 	showComments : function(commentDbIds, mouseXY, showingAll) {
   460 	showScopeRemovedComments : function() {
       
   461 		checkForOpenedDialog(null, function() {
       
   462 			gShowingAllComments = true ;
       
   463 			var scopeRemovedComments = CY.Array.filter(gDb.comments, function(comment) { return (comment.start_wrapper == -1) ; }) ;
       
   464 			var scopeRemovedCommentIds = CY.Array.map(scopeRemovedComments, function(c){return c.id;}) ;
       
   465 			this.showComments(scopeRemovedCommentIds, [0,0], true) ;
       
   466 			
       
   467 		}, this, null) ;
       
   468 	},
       
   469 
       
   470 	showComments : function(commentDbIds, mouseXY, atDocumentTop) {
   456 		checkForOpenedDialog(null, function() {
   471 		checkForOpenedDialog(null, function() {
   457 			this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
   472 			this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
   458 			this._showComments(commentDbIds, mouseXY[1], showingAll) ;
   473 			this._showComments(commentDbIds, mouseXY[1], atDocumentTop) ;
   459 			this._animateTo(mouseXY[1]) ;
   474 			this._animateTo(mouseXY[1]) ;
   460 			this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
   475 			this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
   461 			this._q.run();
   476 			this._q.run();
   462 		}, this, null) ;
   477 		}, this, null) ;
   463 	},
   478 	},