4images Forum & Community

General / Allgemeines => Programming => Topic started by: budduke on July 05, 2010, 01:19:01 AM

Title: Any javascript Gurus out there?
Post by: budduke on July 05, 2010, 01:19:01 AM
I am working on my gallery quicklist again and I have all the bugs fixed except one and I can not figure out how or if it can even be fixed so I will try to ask here...

inside the javascript the link that is in the list is considered this. variable and it is being compared with the location. variable inside the script in this area...

Code: [Select]
case "location":
//MOD modifield for 4images page number problem
var locsub = location.href.replace(/&sessionid=([0-9]|[a-z]|[A-Z])*/g,"");
var locsub = locsub.replace(/&page=[0-9]*/,"");
var current = this.find("a").filter(function() { return this.href.toLowerCase() == locsub.toLowerCase(); });
//var current = this.find("a").filter(function() { return this.href.toLowerCase() == location.href.toLowerCase(); });
//End Mod for 4images page number problem
if ( current.length ) {
current.addClass("selected").parents("ul, li").add( current.next() ).show();
}
break;

I am able to remove the sessionid and the page= from the string on the location. variable but I can not figure out how to get the sessionid out of the this. variable.
I created another variable called locsub with the sessionid and the page= removed but I can not figure out how to do it with the this. variable so that the two will become equal and highlight your location.

It really isn't a big deal but is the only bug I can not get rid of. The only time that this would happen is if the user opened a new web browser and only on the first initial links would have the sessionid in them and does not highlight where they are currently at in the list, but as soon as they click on something then the sessionid is applied and is no longer a problem.

I am re-writing the mod so it handles the $site_sess->url() better but now it adds the sessionid to the string which is giving me this little problem.
you can see what I have in the attached jpg...

Thank you for any help you can send my way, I am learning slowly :)
Title: Re: Any javascript Gurus out there?
Post by: V@no on July 05, 2010, 04:56:20 AM
I guess you do the same thing to "this.href" as to "location.href":
Code: (javascript) [Select]
case "location":
//MOD modifield for 4images page number problem
var current = this.find("a").filter(function() {
var regexp = new RegExp("(\\\?|&(amp;)?)" + urlSessName + "=[^&]+", "g"); //removing sessionid=
var cursub = this.href.replace(regexp,"");
var locsub = location.href.replace(regexp,"");
regexp = new RegExp("(\\\?|&(amp;)?)" + urlPageName + "=[^&]+", "g"); //removing page=
cursub = cursub.replace(regexp,"");
locsub = locsub.replace(regexp,"");
return cursub.toLowerCase() == locsub.toLowerCase();
});
//End Mod for 4images page number problem
if ( current.length ) {
current.addClass("selected").parents("ul, li").add( current.next() ).show();
}
break;

You'll need this before your JS script is being included (in header.html for example)
Code: (html) [Select]
<SCRIPT type="text/javascript">
var urlSessName = "<?=SESSION_NAME;?>";
var urlPageName = "<?=URL_PAGE;?>";
</SCRIPT>
Title: Re: Any javascript Gurus out there?
Post by: budduke on July 05, 2010, 03:50:08 PM
Thanks V@no !

Some day I will have to site down and try to understand the regexp better, sometimes it is confusing how it works but as long as it work who am I to complain.

I updated my mod to work with the sessions better thanks to you!