Changing pagematch with javascript

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
AndrewR
Beginner
Beginner
Posts: 4
Joined: Wed Apr 20, 2005 2:31 am

Changing pagematch with javascript

Post by AndrewR »

I need to highlight the same menu item for a few pages which are in different folders and do not have a direct link from the menu. So there is no common pattern I can use to match all the pages.

After defining the menus, is there a way to change the pagematch for a specific item? Or even better, is there a way to manually set the pagematch pattern to be used instead of the current URL before the menus are defined? Or what othe way?

Basically I want to keep the code in .js files and add a few lines of javascript to a few pages to force an item to highlight.

Thank you
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

Hi,

Have you tried the "pagematch"?

This can be aplied to either a menustyle or to a single menu item. You can specify a keyword that is contained in the url so that it will force a match even if the url is not a match.

Something like pagematch=yourkeyword; will do.

Hope this helps,
Andy
AndrewR
Beginner
Beginner
Posts: 4
Joined: Wed Apr 20, 2005 2:31 am

Post by AndrewR »

Andy wrote:Hi,

Have you tried the "pagematch"?

This can be aplied to either a menustyle or to a single menu item. You can specify a keyword that is contained in the url so that it will force a match even if the url is not a match.

Something like pagematch=yourkeyword; will do.

Hope this helps,
Andy
We bought a license and the site is already live, but a few pages dont have have a common string I can use. And moving or renaming the files is not an option. Can pagematch check for multiple strings?

If not I guess I can write additional javascript to match the current url against a list of keywords.

Do you have a sample of cross-browser reliable javascript code, to obtain the current URL and then check for a match?

Also can pagematch be made case-insensitive?

Thank you
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hello Andrew,

There are a few custom functions or plugins that you could probably use. The first one that comes to mind is this one:

http://milonic.com/mmpagehighlighter.js

I don't know how or why I remembered this (must've gotten stuck in one of those other cobwebs in my head); I searched but could find no reference to it in the forums. I'm sure it's there somewhere, if one can come up with the right keywords to search. Anyway, this plugin lets you manually specify which menu item to highlight (I believe it automatically uses the page matching colors). There are three functions that you can use to target an item by the name of the submenu it opens, the text it contains, or its item index.

(1) Download the mmpagehighlighter.js file (right-click on the link above and "Save Target As...") and read its comments to see how each function works.

(2) Load the mmpagehighlighter.js file into the page (before or after the other menu files; makes no difference).

(3) Suppose the item you want to highlight is defined thus:

Code: Select all

aI("text=Products;url=products.php?id=5;");
The text in the item is "Products". Now suppose you're on a page with a completely different url, but you want to highlight the Products menu item. In that page, You could use the <body>'s onload event to call mmItemActivateByText(), like so:

Code: Select all

<body onload="mmItemActivateByText('Products')">
That's one way anyway. I should note that this method does not really set the item's pagematch property; rather, it manually highlights the specified item using the page matching properties. Also (since you asked), this method is NOT case sensitive. If that's an absolute requirement, then we could work out another way. (BTW, as far as I know, pagematch is case sensitive already, but as I said, this method isn't really manipulating pagematch).

If that doesn't do it for you give a holler. I can think of a few other ways to do it, some of them dynamically manipulating an item's pagematch property.

Cheers,

Kevin
alexv420
Beginner
Beginner
Posts: 5
Joined: Thu Apr 21, 2005 1:02 am

Post by alexv420 »

hi guys,

i am trying to do exactly the same thing right now on an "all images" menu, and am not having any luck getting the function to work. i have posted the sample setup with the modifications that you suggest should work for this:

http://webslingerz.com/alex/milonic/index.htm

i have added the script, set a pageimage attribute on the appropriate item, and called the function onload to highlight the "milonic" button, but no love. it works using a text-only main menu, but not all images.

am i missing something?
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

This is a guess but I think it is not working with the images. If you substitute text for an image and pagebgcolor it works.

Ruth
alexv420
Beginner
Beginner
Posts: 5
Joined: Thu Apr 21, 2005 1:02 am

Post by alexv420 »

hi ruth,

that's precisely the problem. it works fine with text items, but not with image items. pagematch works as it should with image items when used normally matching against a url string (so i assume it must be possible to do what i need it to do), but i need it to work with this alternate scenario as i absolutely need to be able to specify menu highlights using a javascript variable (this site encompasses 14,000 static pages, a fledgling content management system and 24 external applications).

any ideas what could be keeping it from working using the image items?

thanks for checking this out for me :)
twing
Advanced
Advanced
Posts: 15
Joined: Wed Apr 20, 2005 7:17 am

no reply?

Post by twing »

Hi,

I'm having the same situation. I use the mmpagehighlighter.js, but the image is not swaped. Is there workaround?

Thanks,
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi alexv420 and twing,

Sorry for the confusion. I did not intend to suggest that mmpagehighlighter.js should work with menu images. I suggested it as a possible solution for Andrew's menu, which was all text.
kevin3442 wrote:...this plugin lets you manually specify which menu item to highlight (I believe it automatically uses the page matching colors).

i.e., pagecolor and pagebgcolor. I should have been more specific... sorry.

In fact, mmpagehighlighter.js, in its original form, only matches on two properties: pagecolor and pagebgcolor. This can be seen in the code for the _doHLK() function; _I[18] and _I[19] are the pagecolor and pagebgcolor menu item properties respectively.

That said, I went ahead and modified mmpagehighlighter.js to cover the other six page matching properties: pageimage, pagebgimage, pageborder, pageclass, pageseparatorimage, and pagesubimage. I'm sure Andy would make these changes himself if he wasn't already swamped, so I'm pretty sure he won't mind that I did it. You can get the updated version here (right-click the link and "Save Target As...")

How about you guys try the modified version then report back here whether it worked for you or not.

Cheers,

Kevin
alexv420
Beginner
Beginner
Posts: 5
Joined: Thu Apr 21, 2005 1:02 am

Post by alexv420 »

you sir, rock!

that is exactly what i needed, and it works like a charm using my elaborate variable setting scenario. i really appreciate your help with this issue.

cheers!
twing
Advanced
Advanced
Posts: 15
Joined: Wed Apr 20, 2005 7:17 am

Close but

Post by twing »

The image has changes, but the font color hasn't.
twing
Advanced
Advanced
Posts: 15
Joined: Wed Apr 20, 2005 7:17 am

yeay... it works

Post by twing »

It works now after I indent the code properly:
if(_I[18])
_I[8]=_I[18];
if(_I[19])
_I[7]=_I[19];
...
...

Thanks alot for the great support.
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hello,

I'm glad it worked. :D
twing wrote:The image has changes, but the font color hasn't. <...>

It works now after I indent the code properly:
if(_I[18])
_I[8]=_I[18];
if(_I[19])
_I[7]=_I[19];
I don't want to seem picky, but I'd like clarify something for any others who may end up using this... There must have been something else going on. For simple conditionals like these, indentation is incidental. In other words, with Javascript syntax,

Code: Select all

if(_I[18]) _I[8]=_I[18];
and

Code: Select all

if(_I[18]) 
  _I[8]=_I[18];
are functionally equivalent. The indentation here has no effect on the execution of the js code.

Cheers,

Kevin
alexv420
Beginner
Beginner
Posts: 5
Joined: Thu Apr 21, 2005 1:02 am

Post by alexv420 »

is there any possible reason this might not work in mozilla? it works like a charm for me in every browser but mozilla where the pagematch property does not highlight by default, but then stays highlighted as it should on mouseout, but then still reverts the font color back to the off state.
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

alexv420 wrote:is there any possible reason this might not work in mozilla?
Hey Alex,

Sorry for the delayed reply... I'm on the road. By "this" do you mean the page matching in general or the modification of mmpagehighlighter.js?

I'll try to get back to you as soon as I can, but I'll be traveling through next week, so it might be a few days before I get back into the forums.

Cheers,

Kevin
Post Reply