Results 1 to 4 of 4

Thread: Animatedcollapse and SMF [document.getElementById]

  1. #1
    Join Date
    Sep 2007
    Location
    Denmark
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Animatedcollapse and SMF [document.getElementById]

    1) Script Title:
    Animated collapse with SMF - testforum http://www.chihuahuaforum.dk/

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...edcollapse.htm

    3) Describe problem:
    Hi
    I trying to integrade this effect on a already built-in upshrink/downshrink menu header..... in SMF.
    At the moment, when you press - the header upshrink/downshrinks.....

    I want to use this nifty slide effect instead of the instant change


    but i dont know how ?

    Here's some of the code on the build in:
    Code:
    	<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
    		var current_header = ', empty($options['collapse_header']) ? 'false' : 'true', ';
    
    		function shrinkHeader(mode)
    		{';
    
    	// Guests don't have theme options!!
    	if ($context['user']['is_guest'])
    		echo '
    			document.cookie = "upshrink=" + (mode ? 1 : 0);';
    	else
    		echo '
    			smf_setThemeOption("collapse_header", mode ? 1 : 0, null, "', $context['session_id'], '");';
    
    	echo '
    			document.getElementById("upshrink").src = smf_images_url + (mode ? "/upshrink2.gif" : "/upshrink.gif");
    
    			document.getElementById("upshrinkHeader").style.display = mode ? "none" : "";
    			document.getElementById("upshrinkHeader2").style.display = mode ? "none" : "";
    
    			current_header = mode;
    		}
    	// ]]></script>';
    Further down - the "trigger" link"
    Code:
    // this is the upshrink button for the user info section
    	echo '	<a href="#" onclick="shrinkHeader(!current_header); return false;"><img id="upshrink" src="', $settings['images_url'], '/', empty($options['collapse_header']) ? 'upshrink.gif' : 'upshrink2.gif', '" alt="*" title="', $txt['upshrink_description'], '" align="bottom" style="margin: 0 1ex;" /></a>
    				</td>
    			</tr>
    			<tr id="upshrinkHeader"', empty($options['collapse_header']) ? '' : ' style="display: none;"', '>
    				<td valign="top" colspan="2">
    					<table width="100%" class="bordercolor" cellpadding="8" cellspacing="1" border="0" style="margin-top: 1px;">
    						<tr>';
    Anyone have an idea where to put in the codes ?
    I thinks it something like http://www.dynamicdrive.com/forums/s...19&postcount=2

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    The thread you pointed to addresses animating a DIV that changes content dynamically (after the page has loaded). This doesn't apply in your case if I understand how the login system works on your forum.

    In general, this script requires that the animated content be wrapped in a DIV, with the script animating that DIV itself. Based on your source, try this:

    Change the following code on your page:
    Code:
    <a href="#" onclick="shrinkHeader(!current_header); return false;"><img id="upshrink" src="http://www.chihuahuaforum.dk/Themes/fg-forum/images/upshrink.gif" alt="*" title="Vis eller skjul menu" align="bottom" style="margin: 0 1ex;" /></a>
    To this instead:

    Code:
    <a href="#" onclick="javascript:loginbox.slidedown(); return false;"><img id="upshrink" src="http://www.chihuahuaforum.dk/Themes/fg-forum/images/upshrink.gif" alt="*" title="Vis eller skjul menu" align="bottom" style="margin: 0 1ex;" /></a>
    Then, inside the Table tag that follows:

    Code:
    <tr id="upshrinkHeader">
    <td valign="top" colspan="2">
    <table width="100%" class="bordercolor" cellpadding="8" cellspacing="1" border="0" style="margin-top: 1px;">
    Wrap that entire table in a DIV tag:

    Code:
    <tr id="upshrinkHeader">
    <td valign="top" colspan="2">
    <div id="upshrinkHeader-alt">
    <table width="100%" class="bordercolor" cellpadding="8" cellspacing="1" border="0" style="margin-top: 1px;">
    "
    "
    </table>
    </div>
    You need to find out where the closing </table> tag for the table is, and add in a closing DIV tag as highlighted above.

    Finally, following the above code, initalize the script:

    Code:
    <script type="text/javascript">
    
    //Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
    var loginbox=new animatedcollapse("upshrinkHeader-alt", 1000, true)
    
    </script>
    Not tested, but on paper it looks like it should work.

  3. #3
    Join Date
    Sep 2007
    Location
    Denmark
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the quick reply !
    Well, i got the collapse effect working, theres just 2 problems....

    1.
    On the build-in up/downshrink, it "remebers" if the header is open or closed.
    So if the header is open, i will be kept open on all other pages/links i press...

    I think this is done by cookie, as show on my first quote.

    Code:
    	// We'll have to use the cookie to remember the header...
    	if ($context['user']['is_guest'])
    		$options['collapse_header'] = !empty($_COOKIE['upshrink']);
    
    	// Output any remaining HTML headers. (from mods, maybe?)
    	echo $context['html_headers'], '
    
    	<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
    		var current_header = ', empty($options['collapse_header']) ? 'false' : 'true', ';
    
    		function shrinkHeader(mode)
    		{';
    
    	// Guests don't have theme options!!
    	if ($context['user']['is_guest'])
    		echo '
    			document.cookie = "upshrink=" + (mode ? 1 : 0);';
    	else
    		echo '
    			smf_setThemeOption("collapse_header", mode ? 1 : 0, null, "', $context['session_id'], '");';
    
    	echo '
    			document.getElementById("upshrink").src = smf_images_url + (mode ? "/upshrink2.gif" : "/upshrink.gif");
    
    			document.getElementById("upshrinkHeader").style.display = mode ? "none" : "";
    			document.getElementById("upshrinkHeader2").style.display = mode ? "none" : "";
    
    			current_header = mode;
    		}
    	// ]]></script>';
    Now it collapse everytime i reload a page or press a link....

    2.
    Each time a page reload, the div is open for 1/100 of a second, making it apear flickering....
    http://www.chihuahuaforum.dk/index.php

    Strange ?

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Persistence is actually turned on already (so the state of the collapsing DIV is remembered), as enabled by the 3rd parameter when you called the script:

    Code:
    var loginbox=new animatedcollapse("upshrinkHeader-alt", 1000, true)
    Right now it only persists the same DIV that spans the same directory on your site, instead of site wide. To make it side wide, inside the .js file, add the changed in red to this line:

    Code:
    document.cookie = name+"="+value+"; path=/"
    Regarding the "flicker", there has been quite a few threads on this already. Basically, it's part of the original design of the script, so content is shown until the script is run. This prevents people with JavaScript disabled from not being able to see the content. There are a few solutions around this (if you don't mind the accessibility part) in those past threads as well (do a search).

    BTW, please note that your page is currently in violation of our usage terms, since the credit notice doesn't appear inline on the page. Please reinstate the credit notice.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •