View Full Version : New Switch Content vs. Old Switch Content

04-10-2007, 06:02 PM
1) Script Title: Switch Content Script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm

3) Describe problem: Can't mimic old expandcontent() function.

I'm using this script on my page, and updated to the new script to improve the selectability of several expand content areas. I also used it to show/hide multiple images on the page with several calls in a paragraph (actually in <span>), for example:
<span onClick="expandcontent(this, 'image1')" style="cursor:hand; cursor:pointer; color: rgb(102, 51, 102);"><u>1064 nm</u>.</a>
and below it, where the image will appear this:
<div id="image1" class="switchcontent" style="border: 0px;" align="left" hspace="10" vspace="10"><img src="some.jpg" onClick="expandcontent(this, 'image1')" style="width: 600px; height: 450px;"></div>
Of course, this doesn't work anymore. But if I change the function name to the new one, it still doesn't work. What am I missing? I thought it was the block of javascript that's inserted after the tag, but this doesn't seem to help. Can you give me some advice, please?

04-10-2007, 08:22 PM
Use the sweepToggle() function, in replacement for that expandcontent() function. You don't have to use the first argument either, so:

<span onClick="sweepToggle('image1')" style="cursor:hand; cursor:pointer; color: rgb(102, 51, 102);"><u>1064 nm</u>.</a>

04-11-2007, 01:25 PM
Thanks for your reply. It gave me hope that I could get it going. It didn't work. So, looking through the code, I came to the conclusion that it hinged on the id, so I did this:
<span id="image1-title" onClick="sweepToggle()" style="cursor:hand; cursor:pointer; color: rgb(102, 51, 102);"><u>355 nm</u>,</span>The sweepToggle function argument is irrevelant; the control is all in the id. Just to clean the post up for those who want to use this on images as well, the <div> is like this:
<div id="image1" class="switchimage" style="border: 0px;" align="left" hspace="10" vspace="10"><img src="some.jpg" style="width: 600px; height: 450px;"></div>
I eliminated the onClick call to close the image because it cannot work: No id without a conflict. And the setup is this:
var image=new switchcontent("switchimage","div") //Limit scanning of switch contents to just "div" elements
image.collapsePrevious(false) //Multiple images open at any given time
collapsePrevious is set to 'false' because I have multiple images, and the other declarations are not wanted.

Still wish I could close the image by clicking in it, but, so what.

Thanks for your help.

04-11-2007, 02:07 PM
I guess the title of this thread should be changed. Maybe 'Switching images with Switch Content Script'.

04-12-2007, 12:06 PM
I don't even quite understand the question, actually. You've posted bits of code that only makes things more confusing. Can you rephrase what you're trying to accomplish?

04-12-2007, 01:19 PM
The question was how to implement this script for a one-word link to images: I used the old version of this script to expand/contract (show/hide) blocks of text and also individual images on several pages. I extensively modified one of the pages, and so updated the javascript for this tool.

In the old implementation for images, it was a simple onClick event added to the <span> tag, and I tried a simple replacement of that function, which didn't work. It's a new function in the new code, so just outlined how you could use this for images because there is no image demo shown on the script page and no mention of using the sweepToggle() function for the image control (since no one wants the little [open] box in the middle of a sentence, where a colored key word is the clickable link). I can now click on a word link and show/hide blocks of text with images either inside (with text wrap) or outside the text area simultaneously. Very nice, almost like the old one.

BTW, the new code is great for expanding/contracting multiple sections of galleries of images. Now I have the new script working for the images (example in above post) as well as the text, with the only new/old difference being that you cannot click on the image to hide it, that's all, and I'm not sure that you would want it anyway. I'm now experimenting with it to see if I can't do more with dynamic pages. The new script is really a super-great design, and is an education to read and understand.

That's what I was up to, and the reason for my post was to show others how they could do it too. I suppose that it could be added as a demo to a sentence on the script page - just thought it would be of some help.

04-12-2007, 01:28 PM
I used the old version of this script to expand/contract (show/hide) blocks of text and also individual images on several pages.
There's your problem, you tried to implement older functions, on a new script in which the functions didn't even exist.

04-12-2007, 07:28 PM
Well, it's an oversight not to work with images too. And so this thread tells how to work with them.