Collapsing is back for threaded comments.

Comment box is displayed at the end of the thread.
Comments on comments are all collapsed
This commit is contained in:
Domovoy 2012-07-29 17:13:21 +02:00
parent 10eb873f7c
commit 8ea3087342
4 changed files with 33 additions and 23 deletions

View file

@ -303,15 +303,13 @@ function localize_item(&$item){
* Recursively prepare a thread for HTML
*/
function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner) {
function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $collapse_all=false) {
$result = array();
$wall_template = 'wall_thread.tpl';
$wallwall_template = 'wallwall_thread.tpl';
$items_seen = 0;
$nb_items = count($items);
$lastcollapsed = false;
$firstcollapsed = false;
foreach($items as $item) {
// prevent private email reply to public conversation from leaking.
@ -338,6 +336,8 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$thumb = $item['thumb'];
$indent = '';
$osparkle = '';
$lastcollapsed = false;
$firstcollapsed = false;
$toplevelpost = (($item['id'] == $item['parent']) ? true : false);
$item_writeable = (($item['writable'] || $item['self']) ? true : false);
@ -463,11 +463,15 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
} else {
$indent = 'comment';
// Collapse comments
if($nb_items > 2) {
if(!$firstcollapsed && ($items_seen <= ($nb_items - 2))) {
if(($nb_items > 2) || $collapse_all) {
if($items_seen == 1) {
$firstcollapsed = true;
}
else if($items_seen == ($nb_items - 1)) {
if($collapse_all) {
if($items_seen == $nb_items)
$lastcollapsed = true;
}
else if($items_seen == ($nb_items - 2)) {
$lastcollapsed = true;
}
}
@ -524,8 +528,8 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$tmp_item = array(
// collapse comments in template. I don't like this much...
'comment_firstcollapsed' => $comment_firstcollapsed,
'comment_lastcollapsed' => $comment_lastcollapsed,
'comment_firstcollapsed' => $firstcollapsed,
'comment_lastcollapsed' => $lastcollapsed,
// template to use to render item (wall, walltowall, search)
'template' => $template,
@ -571,10 +575,16 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
call_hooks('display_item', $arr);
$item_result = $arr['output'];
if($firstcollapsed) {
$item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$nb_items),$nb_items );
$item_result['hide_text'] = t('show more');
}
$item_result['children'] = array();
if(count($item['children'])) {
$item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner);
if(!$toplevelpost && !$collapse_all)
$collapse_all = true;
$item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, $collapse_all);
}
$item_result['private'] = $item['private'];
$result[] = $item_result;
@ -799,7 +809,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false, $thr_c = fa
}
$threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $previewing);
} else {
}
else {
// Figure out how many comments each parent has

View file

@ -28,7 +28,7 @@ background: #444;
}
.wall-item-tools { background-color: #444444; background-image: none;}
.comment-wwedit-wrapper{ background-color: #444444; }
.comment-wwedit-wrapper{ background-color: #333333; }
.comment-edit-preview{ color: #000000; }
.wall-item-content-wrapper.comment { background-color: #444444; border: 0px;}
.photo-top-album-name{ background-color: #333333; }

View file

@ -1181,7 +1181,6 @@ input#dfrn-url {
.comment-wwedit-wrapper {
margin-top: 15px;
background: #f3f3f3;
margin-left: 50px;
}
.comment-edit-photo {

View file

@ -1,12 +1,10 @@
<div id="tread-wrapper-$item.id" class="tread-wrapper">
{{if $item.comment_firstcollapsed}}
<div class="hide-comments-outer">
<span id="hide-comments-total-$item.id" class="hide-comments-total">$item.num_comments</span> <span id="hide-comments-$item.id" class="hide-comments fakelink" onclick="showHideComments($item.id);">$item.hide_text</span>
</div>
<div id="collapsed-comments-$item.id" class="collapsed-comments" style="display: none;">
{{endif}}
{{if $item.comment_lastcollapsed}}</div>{{endif}}
<div id="tread-wrapper-$item.id" class="tread-wrapper">
<a name="$item.id" ></a>
<div class="wall-item-outside-wrapper $item.indent$item.previewing" id="wall-item-outside-wrapper-$item.id" >
<div class="wall-item-content-wrapper $item.indent" id="wall-item-content-wrapper-$item.id" >
@ -76,9 +74,6 @@
{{ if $item.drop.dropping }}<input type="checkbox" onclick="checkboxhighlight(this);" title="$item.drop.select" class="item-select" name="itemselected[]" value="$item.id" />{{ endif }}
<div class="wall-item-delete-end"></div>
</div>
<div class="wall-item-comment-wrapper" >
$item.comment
</div>
</div>
<div class="wall-item-wrapper-end"></div>
<div class="wall-item-like $item.indent" id="wall-item-like-$item.id">$item.like</div>
@ -88,4 +83,9 @@
{{ for $item.children as $item }}
{{ inc $item.template }}{{ endinc }}
{{ endfor }}
<div class="wall-item-comment-wrapper" >
$item.comment
</div>
</div>
{{if $item.comment_lastcollapsed}}</div>{{endif}}