PVII Knowledge Base
Question #293
Can I set the Pop Menu Magic 2 (PMM2) Current Marker system to automatically open to a specific menu item by matching to a specific URL parameter?
The Answer
Prepared Feb. 2010 by Gerry Jacobsen, PVIIHere's a special Pop Menu Magic 2 (PMM2) function that will check for a specific URL parameter in the page address and look for a match in the menu links, and then current mark the menu accordingly.
Here's how to deploy this tweak:
1. Open the p7PMMscripts.js file and scroll down to the end of the file, make a new line and then Copy & Paste this new function into that line:
function P7_PMMopenUrlParam(dv,param){
var i,h,s,vV,tD,k=-1,pp,a;
tD=document.getElementById(dv);
if(tD){
h=document.location.search;
if(h){
h=h.replace('?', '');
s=h.split(/[=&]/g);
if(s&&s.length) {
for(i=0;i<s.length;i+=2){
if(s[i]==param&&s[i+1]){
vV=param+'='+s[i+1];
break;
}
}
}
}
if(vV){
tA=tD.getElementsByTagName('A');
for(i=0;i<tA.length;i++){
if(tA[i].getAttribute('href')!='#'&&tA[i].search&&tA[i].search.indexOf(vV)>-1){
k=i;
break;
}
}
}
if(k>-1){
pp=tA[k].parentNode;
while(pp){
if(pp.tagName&&pp.tagName=='LI'){
P7_PMMsetClass(pp,'li_current_mark');
a=pp.getElementsByTagName('A');
if(a&&a[0]){
P7_PMMsetClass(a[0],'current_mark');
if(a[0].hasImg){
im=a[0].getElementsByTagName('IMG')[0];
im.mark=true;
im.src=im.p7imgswap[3];
}
}
}else{
if(pp==tD){
break;
}
}
pp=pp.parentNode;
}
}
}
}
2. Now we'll activate this to run automatically when the page loads. Locate this code block near the end of the P7_PMMinit() function, around line 259:
if(tM.p7opt[11]==1){
P7_PMMcurrentMark(tM);
}
}
}
p7PMMa=true;
3. Add a new line after the first } and Copy & Paste this into that new line:
P7_PMMopenUrlParam(tM.id,'myParam');
so that it now looks like this:
if(tM.p7opt[11]==1){
P7_PMMcurrentMark(tM);
}
P7_PMMopenUrlParam(tM.id,'myParam');
}
}
p7PMMa=true;
4. Change the 'myParam' text to reflect the actual parameter you wish to match, for example, if you want the system to look for deptID parameter it should look like this:
P7_PMMopenUrlParam(tM.id,'deptID');
4. Save and close the file.
When the page first loads the PMM2 system will now look at the page's URL parameters and if it finds a 'deptID' parameter it will compare the 'deptID' value in the page URL to the menu links. If it finds a menu link with a 'deptID' parameter and matching value it will current mark that link and any parents.
So, if the detail product page address is:
http://mySite.com/product.php?deptID=263&prodID=1022
the system will match to this link in the menu:
<li><a href="/department.php?deptID=263>Department 263</a></li>
