Changing pagematch with javascript
Changing pagematch with javascript
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
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
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?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
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
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:
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:
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
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;");
Code: Select all
<body onload="mmItemActivateByText('Products')">
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
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?
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?
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
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
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.
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
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
yeay... it works
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.
if(_I[18])
_I[8]=_I[18];
if(_I[19])
_I[7]=_I[19];
...
...
Thanks alot for the great support.
Hello,
I'm glad it worked.
and
are functionally equivalent. The indentation here has no effect on the execution of the js code.
Cheers,
Kevin
I'm glad it worked.
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,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];
Code: Select all
if(_I[18]) _I[8]=_I[18];
Code: Select all
if(_I[18])
_I[8]=_I[18];
Cheers,
Kevin
Hey Alex,alexv420 wrote:is there any possible reason this might not work in mozilla?
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