Committer: dpetrov
LJSUP-6869: update threads expander logicU trunk/htdocs/js/commentmanage.js U trunk/htdocs/js/thread_expander.ex.js
Modified: trunk/htdocs/js/commentmanage.js =================================================================== --- trunk/htdocs/js/commentmanage.js 2010-10-13 09:10:41 UTC (rev 17553) +++ trunk/htdocs/js/commentmanage.js 2010-10-13 09:28:48 UTC (rev 17554) @@ -186,17 +186,15 @@ function removeComment (ditemid, killChildren, isS1) { if(isS1){ - var threadId = ditemid, - postid = location.href.match(/\/(\d+).html/)[1]; - url = '/__rpc_get_thread?journal=' + Site.currentJournal +'&itemid=' + postid + '&thread=' + threadId + '&single=1'; + var threadId = dItemid; - jQuery.get( url, function(result) { - for( var i = 0; i < result.length; ++i ){ - if( LJ_cmtinfo[ result[i].thread ].full ){ - jQuery("#ljcmtxt" + result[i].thread).html( result[i].html ); - } - } - }, 'json' ); + getThreadJSON(threadId, function(result) { + for( var i = 0; i < result.length; ++i ){ + if( LJ_cmtinfo[ result[i].thread ].full ){ + jQuery("#ljcmtxt" + result[i].thread).html( result[i].html ); + } + } + }); } else { var todel = document.getElementById("ljcmt" + ditemid); @@ -405,7 +403,7 @@ pos = { x: e.pageX, y: e.pageY }, postUrl = ae.href.replace(/.+talkscreen\.bml/, LiveJournal.getAjaxUrl('talkscreen')), hourglass = jQuery(e).hourglass()[0]; - + var xhr = jQuery.post(postUrl + '&jsmode=1', { confirm: 'Y', @@ -448,21 +446,39 @@ return; } } - + if(isS1){ var threadId = dItemid, - postid = location.href.match(/\/(\d+).html/)[1]; - url = '/__rpc_get_thread?journal=' + Site.currentJournal +'&itemid=' + postid + '&thread=' + threadId; + threadExpanded = !!(LJ_cmtinfo[ threadId ].oldvars && LJ_cmtinfo[ threadId ].full); + populateComments = function(result){ + for( var i = 0; i < result.length; ++i ){ + if( LJ_cmtinfo[ result[i].thread ].full ){ + setupAjax( + jQuery("#ljcmtxt" + result[i].thread).html( + ExpanderEx.prepareCommentBlock( + result[i].html, + result[ i ].thread, + !( 'oldvars' in LJ_cmtinfo[ result[i].thread ] ) + ) + )[0], isS1 ); + } + } + hourglass.hide(); + poofAt(pos); + }; - jQuery.get( url, function(result) { - for( var i = 0; i < result.length; ++i ){ - if( LJ_cmtinfo[ result[i].thread ].full ){ - setupAjax( jQuery("#ljcmtxt" + result[i].thread).html( result[i].html )[0], isS1 ); - } + getThreadJSON(threadId, function(result) { + //if comment is expanded we need to fetch it's collapsed state additionally + if( threadExpanded ) + { + getThreadJSON( threadId, function(result2){ + ExpanderEx.Collection[ threadId ] = ExpanderEx.prepareCommentBlock( result2[0].html, threadId, true ); + populateComments( result ); + }, true, true ); } - hourglass.hide(); - poofAt(pos); - }, 'json' ); + else + populateComments( result ); + }, false, !threadExpanded); } else { // modified jQuery.fn.load @@ -535,7 +551,20 @@ } } +function getThreadJSON(threadId, success, getSingle) +{ + var postid = location.href.match(/\/(\d+).html/)[1], + params = [ + 'journal=' + Site.currentJournal, + 'itemid=' + postid, + 'thread=' + threadId + ]; + if( getSingle) + params.push( 'single=1' ); + var url = '/__rpc_get_thread?' + params.join( '&' ); + jQuery.get( url, success, 'json' ); +} jQuery(function(){setupAjax( false, ("is_s1" in LJ_cmtinfo ) )}); Modified: trunk/htdocs/js/thread_expander.ex.js =================================================================== --- trunk/htdocs/js/thread_expander.ex.js 2010-10-13 09:10:41 UTC (rev 17553) +++ trunk/htdocs/js/thread_expander.ex.js 2010-10-13 09:28:48 UTC (rev 17554) @@ -75,7 +75,7 @@ continue; //this comment is already expanded ExpanderEx.Collection[ json[ i ].thread ] = jQuery( '#ljcmtxt' + json[ i ].thread ).html(); jQuery( '#ljcmtxt' + json[ i ].thread ) - .html( json[ i ].html ); + .html( ExpanderEx.prepareCommentBlock( json[ i ].html, json[ i ].thread, false ) ); this.initCommentBlock( jQuery( '#ljcmt' + json[ i ].thread )[0], json[ i ].thread ); LJ_cmtinfo[ json[ i ].thread ].parent = this.id; @@ -84,11 +84,13 @@ return true; } -ExpanderEx.prototype.collapseThread = function(){ - var ids = [ this.id ].concat( LJ_cmtinfo[ this.id ].rc ); +ExpanderEx.prototype.collapseThread = function( id ){ + var threadId = id || this.id; + this.collapseBlock( threadId ); - for( var i = 0; i < ids.length; ++i ) - this.collapseBlock( ids[ i ] ); + var children = LJ_cmtinfo[ threadId ].rc; + for( var i = 0; i < children.length; ++i ) + this.collapseThread( children[ i ] ); //do not call the code, because we do not know folding logic in all cases //this.updateParentState(); @@ -115,11 +117,16 @@ ExpanderEx.prototype.collapseBlock = function( id ) { - if( id in ExpanderEx.Collection ){ + var expander = this; + function updateBlock(id, html) + { var el_ =jQuery( '#ljcmtxt' + id ) - .html( ExpanderEx.Collection[ id ] )[0]; + .html( html )[0]; + expander.initCommentBlock( el_, id, true ); + } - this.initCommentBlock( el_, id, true ); + if( id in ExpanderEx.Collection ){ + updateBlock( id, ExpanderEx.Collection[ id ] ); delete ExpanderEx.Collection[ id ]; } } @@ -157,14 +164,25 @@ } this.loadingStateOn(); - var postid = this.url.match(/\/(\d+).html/)[1]; - var url = '/__rpc_get_thread?journal=' + Site.currentJournal +'&itemid=' + postid + '&thread=' + this.id; - - var obj = this; - jQuery.get( url, function(result) { - obj.expandThread(result); - }, 'json' ); + getThreadJSON( this.id, function(result) { + obj.expandThread(result); + }, false, false, true ); return true; } + +ExpanderEx.prepareCommentBlock = function(html, id, showExpand){ + var block = jQuery("<div>" + html + "</div>"), + selector = ''; + + if( LJ_cmtinfo[ id ].has_link > 0 ) + selector = '#' + ((showExpand ? 'collapse_' : 'expand_' ) + id); + else + selector = '#collapse_' + id + ', #expand_' + id + + block.find(selector) + .css('display', 'none'); + + return block.html(); +}