Matt? or "Thanks, can you help me tweak your javascript?"

Talk to other Pedia users about the programs, share tricks and tips or ask questions about existing features.
Post Reply
User avatar
sitenoise
Addicted to Bruji
Addicted to Bruji
Posts: 228
Joined: Fri Mar 21, 2008 12:42 pm
Contact:

Matt? or "Thanks, can you help me tweak your javascript?"

Post by sitenoise »

First of all I'd like to thank Matt for contributing his award winning dvdpedia Info View template. Nice design and functionality. But there is one thing i wish I could change, so if Matt is around and wouldn't mind, or if someone else with javascript chops would like to help ....

This concerns the behavior of the 3 boxes on the right (after <!-- BEGIN RIGHT COLUMN -->)

Presently, with the Info view window open, upon each choosing of an entry, box A opens. It does a "show" in the show/hide dance.

What I would like to change is ... if I have box B open and then click on a new dvdpedia entry, I wish it would remain showing me box B instead of closing box B and opening box A.

Here is the relevant code (as far as i know):

Head Tag:

Code: Select all

<script>
		<!--
		function HideContent(a) {
		document.getElementById(a).style.display = "none";
		}
		function ShowContent(d) {
		document.getElementById(d).style.display = "";
		}
		function ReverseContentDisplay(a , b , c ) {
		if(document.getElementById(a).style.display == "none") { 
		document.getElementById(a).style.display = "";
		}
		else 	
			{ document.getElementById(a).style.display = "none"; }
			document.getElementById(b).style.display = "none";
			document.getElementById(c).style.display = "none";
		}
		-->
		</script>
Preceding Box A

Code: Select all

<div class="columnRight" name="Film Details">
	<div class="singleCol"><span class="title">Film Details </span><span class="text rightAlign"><a href="javascript:ReverseContentDisplay('A', 'B', 'C')">Show/Hide</a></span></div>
	<div class="singleBox overflow" id="A" style="display:;">
Preceding box B

Code: Select all

<div class="columnRight" name="Product Details">
	<div class="singleCol"><span class="title">Product Information </span><span class="text rightAlign"><a href="javascript:ReverseContentDisplay('B', 'A', 'C')">Show/Hide</a></span></div>
	<div class="singleBox overflow" id="B" style="display:none;">
Preceding Box C

Code: Select all

<div class="singleCol"><span class="title">Similar Products </span><span class="text rightAlign"><a href="javascript:ReverseContentDisplay('C', 'A', 'B')">Show/Hide</a></span></div>
	<div class="singleBox overflow" id="C" style="display:none;">
User avatar
Conor
Top Dog
Posts: 5344
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: Matt? or "Thanks, can you help me tweak your javascript?"

Post by Conor »

This one is a tough one as it would require cookies between session so that the javascript could know what was the last open pane. Give the following code a try, replace the current javascript code with the one below, I added code from this site:

Code: Select all

<script>
		<!--
		function createCookie(name,value,days) {
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
		}
		
		function readCookie(name) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		}
		
		function HideContent(a) {
			document.getElementById(a).style.display = "none";
		}
		function ShowContent(d) {
			document.getElementById(d).style.display = "";
		}
		function ReverseContentDisplay(a , b , c ) {
			if (a.length > 1)
				createCookie('infoViewMattDisplayedBottom',a,999);
			else
				createCookie('infoViewMattDisplayedRight',a,999);
			
			if(document.getElementById(a).style.display == "none") { 
				document.getElementById(a).style.display = "";
			}
			else  { 
				if (a.length > 1)
					createCookie('infoViewMattDisplayedBottom',a,-1);
				else
					createCookie('infoViewMattDisplayedRight',a,-1);
				
				
			document.getElementById(a).style.display = "none"; }
			document.getElementById(b).style.display = "none";
			document.getElementById(c).style.display = "none";
		}
		
		function checkLastDisplayed() {
			var bottom = readCookie('infoViewMattDisplayedBottom');
			if (bottom)
				ShowContent(bottom);
			var left = readCookie('infoViewMattDisplayedRight');
			if (left) {
				HideContent('A');
				ShowContent(left);
			}
		}
		window.onload = checkLastDisplayed;
		-->
</script>
User avatar
sitenoise
Addicted to Bruji
Addicted to Bruji
Posts: 228
Joined: Fri Mar 21, 2008 12:42 pm
Contact:

Re: Matt? or "Thanks, can you help me tweak your javascript?"

Post by sitenoise »

Spectacular! Thank you Conor.
Post Reply