Page 1 of 1

Fix for Forum Post Expand/Contract Links

Posted: Mon Jun 08, 2009 9:27 pm
by McInfo
Edit: This issue has been resolved with recent forum software updates.

I noticed that the Expand/Contract links above code blocks in posts do not work (subsilver2 theme), so I tracked down the problem.

The HTML for posts has this structure. As you can see, the max-height style is applied to the "codeholder" div.

Code: Select all

<div class="postbody">
    <div class="codebox">
        <div class="codeheader"></div>
        <div class="codeholder" style="max-height: 300px;">
            <div id="cb99999" class="php"></div>
        </div>
    </div>
</div>
The Expand/Contract link calls the expandCode() Javascript function.

Code: Select all

<a onclick="expandCode('cb99999'); return false;" href="#">Expand/Contract</a>
And the expandCode() function is defined as

Code: Select all

function expandCode(id){
    var parent = document.getElementById(id);
 
    if ((typeof parent.style.maxHeight != 'undefined') && parent.style.maxHeight == ''){
        parent.style.maxHeight = '300px';
    } else {
        parent.style.maxHeight = '';
    }
}
As it is currently defined, the expandCode() function tries to change the max-height style of

Code: Select all

<div id="cb99999" class="php">
instead of its parent

Code: Select all

<div class="codeholder" style="max-height: 300px;">
Because the code block is still restrained by its parent which has a max-height of 300px, the Expand/Contract button is non-functional.

This can be fixed by adding ".parentNode" to the expandCode() function (line 2).

Code: Select all

function expandCode(id){
    var parent = document.getElementById(id).parentNode;
 
    if ((typeof parent.style.maxHeight != 'undefined') && parent.style.maxHeight == ''){
        parent.style.maxHeight = '300px';
    } else {
        parent.style.maxHeight = '';
    }
}
Edit: This post was recovered from search engine cache.

Re: Fix for Forum Post Expand/Contract Links

Posted: Tue Jun 09, 2009 11:33 am
by Benjamin
We are working on getting the code base into SVN. Once that's done we will be able to start working on changes.

Re: Fix for Forum Post Expand/Contract Links

Posted: Tue Jun 30, 2009 12:46 am
by McInfo
Until then, for a temporary fix, I will be using my Greasemonkey script.

Edit: This post was recovered from search engine cache.