Author Topic: Any javascript Gurus out there?  (Read 5814 times)

0 Members and 1 Guest are viewing this topic.

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Any javascript Gurus out there?
« 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 :)
Buddy Duke
www.budduke.com

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Any javascript Gurus out there?
« Reply #1 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>
« Last Edit: July 05, 2010, 07:09:48 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: Any javascript Gurus out there?
« Reply #2 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!
Buddy Duke
www.budduke.com