Expandable Posts II

Since the first wasnt very... usable, here's a rewrite which is easier to implement, I think, based on Super Peek-A-Boo Posts by Hans and Ramani.

Step 0: Backup your existing template before modifying it.

Step 1: Add the following javascript code to the head of your template. You can place it just above the </head> tag.

<script type='text/javascript'>
//<![CDATA[
<!--

var peekaBtnTextOn = "Show";
var peekaBtnTextOff = "Hide";

function peekaBtn(id)
{
var div = document.getElementById(id);
var divs = div.getElementsByTagName('div');

for (var i = 0; i < divs.length; i++) {
if (divs[i].id == "expandedpost") {
var xp_div_tx = divs[i].innerHTML
var xp_div_id = "xp_" + id;

divs[i].innerHTML = '\
<input type="button" value="' + peekaBtnTextOn + '" class="XP" onclick="peekaBtnToggle(\''+ xp_div_id + '\')" />\
<div style="display: none;" id=\'' + xp_div_id + '\'><p>' + xp_div_tx + '</p></div>';
}
}
}

function peekaBtnToggle(id)
{
var div = document.getElementById(id);
if (div.style.display != "") {
div.style.display = "";
div.parentNode.getElementsByTagName('input')[0].value = peekaBtnTextOff;
} else {
div.style.display = 'none';
div.parentNode.getElementsByTagName('input')[0].value = peekaBtnTextOn;
}
}
//-->
//]]>
</script>


Tip: Changing the values of peekaBtnTextOn and peekaBtnTextOff changes the buttons' texts accordingly.

Step 2: Design the button by adding this in the <b:skin> block. Change to your liking, of course.
.XP {
font-size: 10px;
margin: 0;
padding: 0;
width: 120px;
}

Step 3: Find the includable named 'post' in your template, and change it so part of it looks like below (the colored text must be added). Note that I worked on an unmodified template.
<div class='post-body' expr:id='"post-" + data:post.id'>
<p><data:post.body/></p>
<script type='text/javascript'>peekaBtn("post-" + "<data:post.id/>")</script>
.... rest of template code ....

Step 4: In the Settings - Formatting tab, go to the bottom and enter the following post-template:
Some text go here.
<div id="expandedpost">
Peek-A-Boo'd text goes here.
</div>

That's it :-)

8 comments:

Yusunoha said...

thanks for the code, was searching for something like this ^^

reeky said...

glad to be of help sensei-kun :-)

Anonymous said...

reek, where do i need to put the 3 step in the template.? thanx

arina1992 said...

I don't understand the designing button part. Can you show me how it looks when the codes are inserted in the b:skin block?

reeky said...

@arina1992: check here -

http://reeky.anime.0lx.net/expandable-posts-ii.html

HTH

Unknown said...

Hello reeky, since I can not find your email address I will contact here to find out if you have any news about the generator link premium megaupload? thank you very much to keep me informed at: adminyoolook@gmail.com

reeky said...

@Real: I'm not working on it anymore and like I said, I'm not sure if I will work on it again. But most probably not as I've seen a number of websites making use of such script before and only a handful were nice enough to even put a link back here. How cruel.

Anonymous said...

more house md please..thanks