Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Thursday February 8 2018 - 06:02:48

Changing pagematch with javascript


Poster: AndrewR
Dated: Wednesday April 20 2005 - 19:29:45 BST

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


Poster: Andy
Dated: Saturday April 23 2005 - 23:24:39 BST

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


Poster: AndrewR
Dated: Wednesday April 27 2005 - 2:39:43 BST

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


Poster: kevin3442
Dated: Wednesday April 27 2005 - 6:10:32 BST

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://www.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


Poster: alexv420
Dated: Tuesday May 3 2005 - 3:07:24 BST

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?


Poster: Ruth
Dated: Tuesday May 3 2005 - 5:00:46 BST

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


Poster: alexv420
Dated: Tuesday May 3 2005 - 6:45:31 BST

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 :)

no reply?


Poster: twing
Dated: Tuesday May 3 2005 - 8:28:33 BST

Hi,

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

Thanks,


Poster: kevin3442
Dated: Wednesday May 4 2005 - 0:39:21 BST

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


Poster: alexv420
Dated: Wednesday May 4 2005 - 4:23:24 BST

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!

Close but


Poster: twing
Dated: Wednesday May 4 2005 - 4:39:22 BST

The image has changes, but the font color hasn't.

yeay... it works


Poster: twing
Dated: Wednesday May 4 2005 - 8:41:35 BST

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.


Poster: kevin3442
Dated: Tuesday May 10 2005 - 1:01:58 BST

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


Poster: alexv420
Dated: Wednesday May 25 2005 - 2:53:21 BST

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.


Poster: kevin3442
Dated: Friday May 27 2005 - 3:31:52 BST

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