Hi, is it possible to highlight a menu element programmatically ?
I mean i'd like to highlight a specific menu item when i enter directly an url to my application.
Thanks
menu highlight
Forum rules
Please note that response time for technical support is within 3-5 business days.
Please note that response time for technical support is within 3-5 business days.
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
You need to add the id of menuitem into Ultima $.cookie. Please try;
//menu.xhtml
Code: Select all
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
var $this = PF('me');
if($this) {
var pathname = window.location.pathname;
if(pathname.indexOf('.xhtml') > 0) {
var activeLink = $this.menulinks.filter('[href^="' + pathname + '"]');
$this.expandedMenuitems = [];
$this.clearMenuState();
var item = activeLink.parent('li');
$this.addMenuitem(item.attr('id'));
addParentItems($this, item);
rc();
}
}
});
function addParentItems($this, item) {
if(item) {
var parent = item.parents('li:first');
$this.addMenuitem(parent.attr('id'));
if(!parent.parent('ul').hasClass('ultima-menu')) {
addParentItems($this, parent);
}
else {
return;
}
}
return;
}
//]]>
</script>
Code: Select all
<h:form id="menuform">
....
<p:remoteCommand name="rc" update="menuform:menu" />
<pu:menu id="menu" widgetVar="me">
...
Last edited by mert.sincan on 13 Jun 2017, 10:18, edited 1 time in total.
Github Profile: https://github.com/mertsincan
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
- I think you can add a if-check for this issue in your addParentItems method.but the first time i enter the page i get a "too much recursion" javascript error.
addParentItems method fails if the menu item has no parent items....
- Thanks for the update, but we don't think of adding this feature for now....and it will be nice to have this behaviour directly in the template, maybe piloted by a configuration variable....in order to highlight the menu item depending on the visited page.
Github Profile: https://github.com/mertsincan
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
Could you please try the following code?
//menu.xhtml
Code: Select all
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
var $this = PF('me');
if($this) {
var pathname = window.location.pathname;
if(pathname.indexOf('.xhtml') > 0) {
var activeLink = $this.menulinks.filter('[href^="' + pathname + '"]');
$this.expandedMenuitems = [];
$this.clearMenuState();
var item = activeLink.parent('li');
$this.addMenuitem(item.attr('id'));
addParentItems($this, item);
rc();
}
}
});
function addParentItems($this, item) {
if(item && item.length) {
var parent = item.parents('li:first');
$this.addMenuitem(parent.attr('id'));
if(!parent.parent('ul').hasClass('ultima-menu')) {
addParentItems($this, parent);
}
else {
return;
}
}
return;
}
//]]>
</script>
Code: Select all
<h:form id="menuform">
....
<p:remoteCommand name="rc" update="menuform:menu" />
<pu:menu id="menu" widgetVar="me">
..
Github Profile: https://github.com/mertsincan
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
Glad to hear, thanks for the update!
Github Profile: https://github.com/mertsincan
The line:aragorn wrote: ↑13 Jun 2017, 10:18Could you please try the following code?//menu.xhtmlCode: Select all
<script type="text/javascript"> //<![CDATA[ $(document).ready(function() { var $this = PF('me'); if($this) { var pathname = window.location.pathname; if(pathname.indexOf('.xhtml') > 0) { var activeLink = $this.menulinks.filter('[href^="' + pathname + '"]'); $this.expandedMenuitems = []; $this.clearMenuState(); var item = activeLink.parent('li'); $this.addMenuitem(item.attr('id')); addParentItems($this, item); rc(); } } }); function addParentItems($this, item) { if(item && item.length) { var parent = item.parents('li:first'); $this.addMenuitem(parent.attr('id')); if(!parent.parent('ul').hasClass('ultima-menu')) { addParentItems($this, parent); } else { return; } } return; } //]]> </script>
Code: Select all
<h:form id="menuform"> .... <p:remoteCommand name="rc" update="menuform:menu" /> <pu:menu id="menu" widgetVar="me"> ..
Code: Select all
rc();
If I remove that line, they start working again but the menus are not highlighted anymore when I open the page from a URL.
My menu.xhtml:
Code: Select all
...
<p:remoteCommand name="rc" update="menuform:menu" />
<pu:menu id="menu" widgetVar="me" model="#{menuView.model}" />
...
-
- Information
-
Who is online
Users browsing this forum: No registered users and 15 guests