Comments [0] posted: May 27, 2008 Greg O'Byrne

You've probably seen the functionality around at certain blogs where you can click on a link at the end of the post that lets you expand the blog entry to show more content. I like that functionality and dasBlog (my blog software) didn't have it so I wrote my own.

With dasBlog you can have a description for the displayed text on the main blog page and then you can click through to the full blog post, but I wanted the ability to expand and contract dynamically right on the front page.

Here is how I did it.  Feel free to take and use and modify whatever you want.  It's offered as is and public domain and yadda yadda.

First, here are the elements you need to put on your page around the content you want hidden/expanded:

<div  class="trHiderControl">
<span onclick="trReveal(this);"  trhidertoggle="false" trID="trRevealer" class="trHiderTopClick">reveal</span>
<div class="trHiderContent" trID="trHiderContent">

<!--content here-->
blah blah
<!--content here-->

</div>
<span class="trHiderBottomClick" trID="trReHider" onclick="trHider(this);">close up</span>
</div>

Set four css classes, most importantly set:

.trHiderContent
{
     display:none
}

and

.trHiderBottomClick
{
     display:none
}

Then include the file trHider.js and you're golden.  The contents of trHider.js are just two functions:

//reveal text inline.
function trReveal(oEl)
{
    if(oEl.getAttribute("trhidertoggle")=="true")
    {
        trHider(oEl);
        return;
    }
    oTopEl = oEl.parentNode;
    for(i=0; i<oTopEl.childNodes.length; i++)
    {
        if(1==oTopEl.childNodes[i].nodeType)
        {
            switch(oTopEl.childNodes[i].getAttribute("trID"))
            {
                case "trRevealer":
                    oTopEl.childNodes[i].setAttribute("trhidertoggle","true");   
                    break;
                case "trHiderContent":
                    oTopEl.childNodes[i].style.display = "block";
                    break;
                case "trReHider":
                    oTopEl.childNodes[i].style.display = "block";
                    break
                default:
                    //nothing
            }
        }
    }
}

//hide text inline
function trHider(oEl)
{
    oTopEl = oEl.parentNode;   

    for(i=0; i<oTopEl.childNodes.length; i++)
    {
        if(1==oTopEl.childNodes[i].nodeType)
        {
            switch(oTopEl.childNodes[i].getAttribute("trID"))
            {
                case "trRevealer":
                    oTopEl.childNodes[i].setAttribute("trhidertoggle","false");   
                    break;
                case "trHiderContent":
                    oTopEl.childNodes[i].style.display = "none";
                    break;
                case "trReHider":
                    oTopEl.childNodes[i].style.display = "none";
                    break
                default:
                    //nothing
            }
        }
    }
}

...and Voila', expand and contract at will.

Example:

reveal

blah blah blah blah blah

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

close up

      Comments [0]
tags: [blog | code | dasBlog | techRivet]

Comments [0] posted: Apr 12, 2008 Greg O'Byrne

This is an interesting article that talks about the pitfalls of poorly thought out game loops.

For example this simple one:

bool game_is_running = true;

while( game_is_running )
{
             update_game();
             display_game();
}

Read more: The Game Loop, by Koen Witters


      Comments [0]
tags: [code]

Comments [0] posted: Nov 26, 2007 Greg O'Byrne

kloonigames

Cool monthly experimental games from Petri Puhro.

Here's an interview with him.


      Comments [0]
tags: [code | gaming | geek]

Comments [0] posted: Sep 19, 2007 Greg O'Byrne

How difficult is it to write a compiler?

  1. Read in a source file, and create a parse tree.
  2. Turn the parse tree into an abstract syntax tree.
  3. Turn the abstract syntax tree into object code.

Sounds easy...eh.  I think I'll write one after lunch.

But food for thought, a whole new programming language was created in the space of a few weeks on multiple platforms: LOLCode!

Based on the site: I Can Has Cheez burger


      Comments [0]
tags: [code | geek | how-to]

Comments [0] posted: Aug 17, 2007 Greg O'Byrne

c-jump So this is me embracing my inner geek, but this looks really cool.

c-jump® Ski & Snowboard Race

A computer programming board game.  You play the game and learn how to program.  I think I'm gonna have to get this for the mini-rivets at home.

Discover fundamentals of computer programming by playing a board game! c-jump helps children to learn basics of programming languages, such as C, C++ and Java.

Brilliant. [rules]


      Comments [0]
tags: [code | gaming | geek]

Comments [1] posted: Aug 14, 2007 Greg O'Byrne

He who compiles wins.

Update: I thought this was somehow fairly appropriate. It kind of states that he who compiles does not care to win, he only cares to goof off...which from my experience is more true


      Comments [1]
tags: [code | computing | humor | xkcd]

Comments [0] posted: Jun 19, 2007 Greg O'Byrne

Born on Monday, drafted on Wednesday, version 1.0 rolled out on Friday.

LOLCODE.

In a remarkable example of the power of geek-hive-mind in action a new programming language burst onto the scene just last month.

The language was birthed on May 25th 2007 [linky], the site was launched on May 31st, lolcode.com and by mid June there was a v1.0 spec created, the vision of the purpose of the language was refined and there were 4 or 5 compiler projects under way for different development environments.

Incredible.

It has already found a couple of purposes. 

  1. to be funny
  2. potentially to be a entry level programming language for noobs.  Kinda a replacement for BASIC. 

Here is a little example I whipped up to whet your whistle.


HAI	
CAN HAS STDIO?

SO IM LIKE REVVRZTRIN WITH yurwrrd

	I HAS A mahwrrd!!"" 
	I HAS A yurwrrdnum!!WTF IZ LEN yurwrrd?
	BTW this is probably not the correct syntax
	
	IM IN UR LOOP WAITIN TIL yurwrrdnum IZ LESSER THAN 0	
	
		mahwrrd!!mahwrrd N  yurwrrdnum IN MAH yurwrrd
		BTW again not the right syntax
		
		NERF yurwrrdnum
	IM OUTTA YR LOOP
	
	I FOUND MAH mahwrrd
	
KTHXBYE


I HAS A yurwrrd
GIMMEH yurwrrd

VISIBLE REVVRZTRIN WITH yurwrrd
KTHXBYE

I'm not sure if I get the whole cat thing...but that's ok.


      Comments [0]
tags: [crowds | geek | humor | code | LOLCODE]

<<< Older Stuff Yo!
The 2007 Weblog Awards




Total Posts: 431
This Year: 174
This Month: 3
This Week: 3
Comments: 191


Tech blogs
Technology Blogs - Blog Top Sites Outpost

Sign In
home | about | rss
heya punk.here is where lotsa content will be
Larry says!
Larry says!