scriptygoddess RSS Feed
 
 
 
 

another revision to the show/hide script

This is in reference to this post which included a link to a revised version of the show/hide (collapsing/expanding) script. That one was designed specifically for entries. Most people use this script for their comments to, so I made a slight change to it so that you can use ONE function that will work with both.

Here's the new function. I added a new, additional variable that needs to be passed to it: type. My changes to the first revision are in bold.

<script type="text/javascript">
function showHide(entryID, entryLink, htmlObj, type) {
if (type == "comments") {
extTextDivID = ('comText' + (entryID));
extLinkDivID = ('comLink' + (entryID));
} else {
extTextDivID = ('extText' + (entryID));
extLinkDivID = ('extLink' + (entryID));
}

if( document.getElementById ) {
if( document.getElementById(extTextDivID).style.display ) {
if( entryLink != 0 ) {
document.getElementById(extTextDivID).style.display = "block";
document.getElementById(extLinkDivID).style.display = "none";
htmlObj.blur();
} else {
document.getElementById(extTextDivID).style.display = "none";
document.getElementById(extLinkDivID).style.display = "block";
}
} else {
location.href = entryLink;
return true;
}
} else {
location.href = entryLink;
return true;
}
}
</script>

For the extended entries, the prefix "ext" is used for the name of the <div> - and when the javascript function is called, 'entry' is passed in. Basically this is the same as the first updated version, except now we pass in that extra value for type, which in this case is 'entry'.

<MTEntryIfExtended>
<div id="extLink<$MTEntryID$>">
<a href="<$MTEntryPermalink$>" name="ext<$MTEntryID pad="1"$>" onclick="showHide(<$MTEntryID$>,'<$MTEntryPermalink$>',this,'entry');return false;">Read More… ?</a>
</div>
<div id="extText<$MTEntryID$>" style="display: none">
<$MTEntryMore$>
<a href="#ext<$MTEntryID pad="1"$>" onclick="showHide(<$MTEntryID$>,0,this,'entry');return true;">? All done!</a>
</div>
</MTEntryIfExtended>

Then for the comments, I changed "ext" to "com" and for type: "comments":

<MTEntryIfAllowComments>
<div id="comLink<$MTEntryID$>">
<a href="<$MTEntryPermalink$>" name="com<$MTEntryID pad="1"$>" onclick="showHide(<$MTEntryID$>,'<$MTEntryPermalink$>',this,'comments');return false;">Show Comments (<$MTEntryCommentCount$>)</a> | <a href="<$MTEntryPermalink$>#comments">Add your comment</a>
</div>
<div id="comText<$MTEntryID$>" style="display: none">
<a href="#com<$MTEntryID pad="1"$>" onclick="showHide(<$MTEntryID$>,0,this,'comments');return true;">Hide Comments</a>
| <a href="<$MTEntryPermalink$>#comments">Add your comment</a>
<MTComments>
<$MTCommentBody$>
<p>Posted by <$MTCommentAuthorLink show_email="0"$> at <$MTCommentDate$></p><br>
</MTComments>
<a href="#com<$MTEntryID pad="1"$>" onclick="showHide(<$MTEntryID$>,0,this,'comments');return true;">Hide Comments</a> | <a href="<$MTEntryPermalink$>#comments">Add your comment</a>
</div>
</MTEntryIfAllowComments>

34 Responses to “another revision to the show/hide script”

  1. 1
    marc:

    Thanks Jennifer. I'll try to place this code later this evening.

  2. 2
    Kevin:

    Wow! It's simple enough for even me to understand! ;)

  3. 3
    iagofest:

    Hi! Great site. I'm a bloggy beginner, so I was wondering if I could use the collapse/expand script for a Blogger weblog instead of MT. If so, what changes to I need to make? Please email me if you get a chance. Thanks.

  4. 4
    Jennifer:

    I don't see why you couldn't - except that it's been about two years since I blogged using blogger - so I've completely forgotten the tags (or even what functionality it has available, for that matter).

  5. 5
    Phoenix:

    OK, I posted of a problem with the show, hide script before. Seems that I cant use this with the old "Hide Anything" script from geekgrrl.

  6. 6
    Jennifer:

    Phoenix - I know what I'm doing in my version of the show/hide anything - and it uses PHP - if the version you're using from geekgrrl is different, then I can't begin to guess the specifics without seeing the code.

    The function in this current post would need to be modified to be used to show/hide anything. Looking at your source: <span id="varP1234"><a href="#my_favorite_blogs" onclick="showMore(1234,0,this);return false;">Favorite Blogs »</a><br /></span><div id="varXYZ1234" style="display: none">…I think, for a quick fix, put back the original "showMore" function you were using (prior to the fixed/revised code) - (Because you're not even calling the new one from that code anyway - and looking at your source, you're not defining any "showMore" function - which is why you're getting a javascript error when you click those side links)

  7. 7
    Jennifer:

    I should clarify - your extended entries and comments are working fine with this new code - so just ADD the original function in (so you'll have TWO functions defined - the showHide function (you currently have there) and the old showMore function…

  8. 8
    Marc Brazeau:

    I used your prior version of expandable comments and I love the functionality, but it made my text bigger and somehow a little awkward.

    Here is a page with expandable comments:

    http://www.joehilldispatch.org

    and here is one without:

    http://www.joehilldispatch.org/smallaxe

    Any thoughts?

  9. 9
    Marc Brazeau:

    I used your prior version of expandable comments and I love the functionality, but it made my text bigger and somehow a little awkward.

    Here is a page with expandable comments:

    http://www.joehilldispatch.org

    and here is one without:

    http://www.joehilldispatch.org/smallaxe

    Any thoughts?

  10. 10
    Jennifer:

    Uhm… they look the same to me… what am I looking for? (I wonder if it's a browser issue? I'm using IE on Win2K - although just for kicks, I loaded it on Mozilla, and they still looked the same… Maybe email me a screenshot of what you're seeing… :
    scripty AT scriptygoddess DOT com

  11. 11
    The Daily Post :: Weblog:
    Show / Hide
    Have implemented the show/hide script displayed at scriptygoddess. It was a quick design amendment to assist those members of the population who find overuse of extended entry extremely annoying. To view click the 'continue reading…' link as normal….

  12. 12
    Wizbang:
    Mailbag - Comment Blocks
    From the mailbag: I was wondering if you could tell me how you made your inline comments? The link you have from ScriptyGoddess has changed and shows it as expandable links. I like your style better, where each comment is…

  13. 13
    buckethead:

    Jennifer, is there a version of this hack for pMachine? I attempted to adapt it using the expand/collapse more functions for pMachine as a model, but my thumbfisted, hamfingered coding skills were not up to the task. Any help would be greatly appreciated.

  14. 14
    joatBlog:
    Show/hide (JavaScript)
    ScriptyGoddess has a new show/hide script….

  15. 15
    LissaKay, Too:
    Show/Hide Comments and Extended Entry
    I simply adore this script from scriptygoddess! I use the first version on my main blog site and I will probably change it over to this one soon. What does it do? Two things … (click the "There's More!" link…

  16. 16
    JJ:

    I think your tags are misplaced. If comments are disallowed, users won't be able to post new comments, but they won't be able to see previous comments either. That's no fun; just because the topic's closed doesn't mean the comments should be, after all.

    I suggest that users of your script move the tags to enclose the comments item or the tag that provides the comments popup.

    This is something like what I do at my own blog, although I'm still getting my site set up. Everything's messy in the extreme. =)

    Best wishes,
    JJ

  17. 17
    JJ:

    Silly me. I had a slip of the fingers there and some unparsed code slipped by. The above comment should read:

    "I think your <MTEntryIfAllowComments> tags are misplaced…"

    and

    "… move the <MTEntryIfAllowComments> tags … or the <a> tags …"

    I also forgot to thank you for a great script, too. So thanks. =)

  18. 18
    girl:

    Hi,

    is this specifically for show/hide both comments and extended entry? cos i just want a show/hide for extended entry.. not including the comments, which will remain as a popup.

    how do i modify the above to fit my needs?

  19. 19
    Chasmyn:

    I'm wondering (I'm new and know very little coding) - my blog is of course MT and I was looking for a show/hide script for my blogrolling in my sidebar? Can you tell me how I can customize this to make it so, as in this blog: http://www.fridayfishwrap.com/ ?

    She has made it so her blogrolls are collapsable and I love that, it cleans up the place. I want to categorize my blogrolls but am unsure of how to do it thus far. Any help would be appreciated - I've been searching all night :)

  20. 20
    testing new layouts:
    Thanks!
    Super thanks to Scripty Goddess for the Inline Comments and Extended Entry script!!!…

  21. 21
    ktpupp:

    I just added this script to my test blog to see how it works and I have one question/problem.

    When you click the Hide Comments or All Done links, the page goes back to the same link rather than the top of the entry. It makes it kinda hard to follow since the entry you were actually reading is not visible, just the Show… links.

    Is this behavior intentional or unavoidable?

    What I would like it to do is return the viewer to the title of the entry rather than the links for the Ext Entry or Comments.

    I'm hoping you'll have an answer for me as I know little to nothing about programming/writing scripts.

    The test page where this is showing up is as follows: http://www.sumbler.com/blog/testing

    It's not quite ready for prime time, but feel free to take a look at it! I appreciate any help and will of course give you bigtime credit when this new template/layout goes live!

    -=kt=-

  22. 22
    testing new layouts:
    Thanks!
    Welcome to the new and improved Puppy Pile! (Yes, there are no puppies here, at least for now… But that's neither here nor there.) I've spent countless hours working on the layout and design for this page to give a…

  23. 23
    The Puppy Pile!:
    Welcome and Thanks!
    Welcome to the new and improved Puppy Pile! (Yes, there are no puppies here, at least for now… But that's neither here nor there.) I've spent countless hours working on the layout and design for this page to give it…

  24. 24
    ktpupp:

    I just noticed something else happening with this script, maybe I did something wrong?

    On my main page, the "read more/all done" link only shows when there actually is an extended entry, as it should.

    On my individual entry archive pages, the "read more" shows even when there isn't an entry. I can't see anything different in my template from one page to the other…

    Anyone want to help me figure this out?

    Main page: http://www.sumbler.com/blog/

    An archive page (no ext entry but the link shows anyway: http://www.sumbler.com/blog/archives/000480.html

    Thanks for any help!

    -=kt=-

  25. 25
    Brian:

    Is it possible to apply this code to all comments at once. I'm trying to create a link on the side of my blog so that the display of all the comments on the main page can be turned off (for those that are just interested in what I have to say) or on (if you want to read the inline comments for each post)

    I can't use javascript to refer to a div class, so I'm thinking i'm stuck. Any advice is appreciated.

  26. 26
    pensamientos errantes:
    AH All done
    Well I've finally finished up work on my first skin. Click the link to be brought to the skins page, there you can check out the skin and choose it if you'd like. Been working hard on this for the…

  27. 27
    Jessi:

    Is there a way to set the comment authorlink to _blank so that the link opens in a new window? Something like ? Thanks for any help!

  28. 28
    Jessi:

    I mean something like: $ MTCommentAuthorLink $ _blank

  29. 29
    Chardy May Cosmo:

    Bless you!

  30. 30
    bookmarks:

    show/hide script…

  31. 31
    Diary::Weblog:
    「続きを読む」のスクリプト
    Winで某FireFoxを使用時に、追記部分の"show"・"hide"をしているMTのBlog(ウチもそう)では、"show"状態で、ホイールによるスクロールが効かなくなります。 そこで、下記"「続きを読む」のス…

  32. 32
    gigglechick.com:
    piece by piece.
    you can tell i'm not working today, eh? what, with the barrage of entries. anyway, i finally sat down and got the expanded entry and comments to work again… unfortunately…

  33. 33
    Dida Kutz:

    This is a great little script, and exactly what client had asked for on their MT blog. However, I'm still in the process of fully understanding CSS and am wondering what id to edit to change left alignment of the READ MORE text. Also, am i correct in assuming that I use a wildcard somewhere? TIA

  34. 34
    Dida Kutz:

    Nix my last comment- alignment OK. However, I am having an awful time styling the header now for the entres. Seems like it would be easy. Just style

    or syle h3[id]. But nooooooo. And i am posting for help on Meyer's CSS forum and still can't get a fix that works. Can anyone help me out? I know there must be a SUPER SIMPLE solution that I'm somehow reminding blind to. TIA! Site in question is http://www.omniquiti.com

Bookmarks

WordPress Resources

Meta

Random Stuff