PDA

View Full Version : animated collapse 2.4 and mod_rewrite?



mentha
02-26-2010, 08:11 PM
1) Script Title:
Animated collapse DIV v2.4

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

3) Describe problem:
I wish to use the script along with SEO, as in mod_rewrite, so visitors/google can access my site through other URLS and have the DIV opened that the URL asks for (for example 'portfolio').
Unfortunately when I access through mod_rewrite, the DIV doesn't expand as planned. When I access the full url, it does.

In short:
This does NOT work: http://www.mooimentha.nl/test/portfolio/
And this does: http://www.mooimentha.nl/test/index.php?expanddiv=portfolio

The ReWrite is as follows:

RewriteRule ^portfolio/$ index.php?expanddiv=portfolio

Any help would greatly be appreciated!

[EDIT]
I just found the following line n the animatedcollapse.js:

window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=divid or divid1,divid2,etc

So it would seem I need an alternative piece/kind of script to pull the information, possibly combined with PHP? I can't seem to get my head around what to do right now...

ddadmin
02-27-2010, 11:39 AM
Try replacing the BODY of the function urlparamselect(), or:


window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=divid or divid1,divid2,etc
return (RegExp.$1!="")? RegExp.$1.split(",") : []

with the below instead:


var segments=window.location.href.split('/')
var param=segments[segments.length-1] || segments[segments.length-2]
return param || []

This should cause the script to look at the final URL segment and use that to match it against any collapsible DIV with the same value.

mentha
02-27-2010, 02:01 PM
Thanks! And I guess I could possibly combine this with an if/else if I should ever want to use the ?expanddiv=XXX as well?

mentha
02-27-2010, 02:06 PM
Unfortunately I'm getting an error:

missing ; before statement
[Break on this error] return param : []

Help? Please?


EDIT:

Well, fixed that issue all by myself *proud* to

var segments=window.location.href.split('/')
var param=segments[segments.length-1] || segments[segments.length-2]
return (param!="")? param : []

But it's still not expanding. Any thoughts?

ddadmin
02-27-2010, 08:35 PM
I've corrected my syntax error above. Taking another shot, try the below instead of the original function then:


urlparamselect:function(){
window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=divid or divid1,divid2,etc
if (RegExp.$1!="")
RegExp.$1.split(",") || []
else{
var segments=window.location.href.split('/')
var param=segments[segments.length-1] || segments[segments.length-2]
return param || []
}
},

mentha
02-27-2010, 09:24 PM
No script errors, but no automatic expanding either :( It's really odd, cuz if I add an alert in the script, I see that it does return the right data, but it's not getting picked up by the rest of the script, thus causing the lack of expanding.

Thanks for thinking along anyway!

I do think though, that once this is working properly, it might be a nice addition to the original script ;)

edit: typo

ddadmin
02-27-2010, 11:56 PM
Hmm ok can you add an alert directly below the following line inside the .js file:


var urlparamopenids=animatedcollapse.urlparamselect() //Get div ids that should be expanded based on the url (['div1','div2',etc])
alert(urlparamopenids)

Then let me know? I'll test it out.

mentha
02-28-2010, 11:51 AM
The alert shows the right information (portfolio) when using http://www.mooimentha.nl/test/portfolio/

But when using http://www.mooimentha.nl/test/index.php?expanddiv=portfolio it says 'undefined'.

(Based on the last version, with the if/else statement)

ddadmin
03-02-2010, 07:01 AM
Ah ok, try this version then:


urlparamselect:function(){
window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=divid or divid1,divid2,etc
if (RegExp.$1!="")
return RegExp.$1.split(",")
else{
var segments=window.location.href.split('/')
var param=segments[segments.length-1] || segments[segments.length-2]
return param || []
}
},

It should correct the non alert issue when the "expanddiv=xxx" option is used. Regardless though, you're still saying that even with the appropriate alert being shown, the DIV in question still does not expand for the mod_rewrite version of the URL?

mentha
03-02-2010, 08:46 PM
Yes, now the "expanddiv=xxx" option works, including expanding div.
But with the SEO version, no sliding DIV, though the alert clearly gives the right data.

To see the difference:
http://www.mooimentha.nl/test/portfolio/ <= not working
and
http://www.mooimentha.nl/test/?expanddiv=portfolio <= working