Friday, April 20, 2007

Peek-A-Boo Modified: Add 'Summary only' at top

Peek-A-Boo is great! but I decide to add a extra 'summary only' link at top of the full post.

There is 2 thing I will have to do.
1. backup your template. ( always, always... trust me , I know..)
2. Adding a 'top link' into html.
Add the part in highlight into html (remeber to click 'Expand widget template'):
<blockquote class='code'><em><span id='hidelink2' style='display:none'>
<p><a expr:onclick='"javascript:hideFull(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Summary only (只顯示摘要)...</a></p>
</span>

<style>#fullpost {display:none;}</style>
<p><data:post.body/></p>
<span id='showlink'>
<p><a expr:onclick='"javascript:showFull(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Read More (全文);...</a></p>
</span>
<span id='hidelink' style='display:none'>
<p><a expr:onclick='"javascript:hideFull(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Summary only...</a></p>
</span>


2. Let javascript to turn it on or off depends on current stats.
Add the part in highlite into 'hackosphere.js'


function showFull(id) {
var post = document.getElementById(id);
var spans = post.getElementsByTagName('span');
for (var i = 0; i < spans.length; i++) {
if (spans[i].id == "fullpost")
spans[i].style.display = 'inline';
if (spans[i].id == "showlink")
spans[i].style.display = 'none';
if (spans[i].id == "hidelink")
spans[i].style.display = 'inline';
if (spans[i].id == "hidelink2")
spans[i].style.display = 'inline';

}
}




function hideFull(id) {
var post = document.getElementById(id);
var spans = post.getElementsByTagName('span');
for (var i = 0; i < spans.length; i++) {
if (spans[i].id == "fullpost")
spans[i].style.display = 'none';
if (spans[i].id == "showlink")
spans[i].style.display = 'inline';
if (spans[i].id == "hidelink")
spans[i].style.display = 'none';
if (spans[i].id == "hidelink2")
spans[i].style.display = 'none';

}
post.scrollIntoView(true);
}


No comments: