Help - Search - Members - Calendar
Full Version: Displaying Extended Entries With DOM/JavaScript
Movable Type Community Forum > Additional Resources > Tips and Tricks
nf0
Aaron, your variable names rock! I love to code crazy like that.
aaronshaf

A large, awkward block of text in the midst of a list of entries frequently
 interrupts my reading as I traverse my daily blogs. I realize that authors may
 not want to use Movabletype's extended entry because of readers' impatience
 to visit an archived page. I can sympathize. Better yet, I have an updated solution to the problem.



The following code inserts the extended entry text into the document without
 leaving the current page. I hope you don't mind the variable names. Insert the
 following JavaScript in your main index template:


function ChristIsImmanentInAllThings(youBet, justInCase){

 thatsFunny = ('coconutsKillMorePeopleThanSharks' + (youBet));

 noMoreThankYou = ('thankYourMother' + (youBet));

 if( document.getElementById ) {

 if( document.getElementById(thatsFunny).style.display ) {

 if( justInCase != 0 ) {

 document.getElementById(thatsFunny).style.display = "block";

 document.getElementById(noMoreThankYou).style.display = "none";

 } else { document.getElementById(thatsFunny).style.display = "none";
 

 document.getElementById(noMoreThankYou).style.display = "block"; }

 } else { location.href = justInCase;

 return true; }

 } else { location.href = justInCase;

 return true; }

 }


Replace your current <MTEntryIfExtended> content with the following:


<MTEntryIfExtended>

 <span id="thankYourMother<$MTEntryID$>" class="extended"><a
 href="<$MTEntryLink$>#<$MTEntryID pad="1"$>"
 onclick="ChristIsImmanentInAllThings(<$MTEntryID$>,'<$MTEntryLink$>#<$MTEntryID
 pad="1"$>');return false;">Read more &raquo;</a><br
 /></span><div id="coconutsKillMorePeopleThanSharks<$MTEntryID$>"
 style="display: none"><$MTEntryMore$><a href="#<$MTEntryID
 pad="1"$>" onclick="ChristIsImmanentInAllThings(<$MTEntryID$>,0);return

 true;">&laquo; Collapse</a></div>

 </MTEntryIfExtended>



Any browser not up to par will be sent to the archived entry in its entirety. I strongly recommend removing the "collapse" link for better usability and avoiding CSS bugs. If you use the code, I would appreciate props. It's not a big deal though, I just need a job!



Aaron Shafovaloff
aarondot.comAarondot
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.