Page 1 of 1

Active Admin Menu Item on Direct Page Access

Posted: Sat Feb 03, 2018 10:14 pm
by andrewtite
When I open a page in the admin directly, without clicking an item on the menu, the active menu item class doesn't update.
After looking around I noticed that this is controlled through common.js
Is there a way to update this based on the current page route?

I'm writing a new module at the moment that opens specific pages without using the menu and I want the active menu item to be updated.
Having trouble figuring it out.

Thanks in advance!

Re: Active Admin Menu Item on Direct Page Access

Posted: Sat Feb 03, 2018 11:03 pm
by straightlight
No OC version posted.

Of course, in common.js file, you could use the already used condition statement of:

Code: Select all

if (getURLVar('route') == 'your_path/your_controller_filename') {

}

Re: Active Admin Menu Item on Direct Page Access

Posted: Tue Feb 06, 2018 3:31 am
by andrewtite
I'm working with 3.0.
Open Cart, as I remember, used to use:
if (getURLVar('route') == 'your_path/your_controller_filename') {
...
but now all I see is:
$('#menu a[href]').on('click', function() {
sessionStorage.setItem('menu', $(this).attr('href'));
});
in common.js

I'm calling up the pages directly by the URL, not through clicking the menu, so that active variable doesn't update on page load.

Re: Active Admin Menu Item on Direct Page Access

Posted: Tue Feb 06, 2018 3:32 am
by andrewtite
I guess I could use vqmod to add a line to the common.js
If you have a better way of doing please let me know.

Re: Active Admin Menu Item on Direct Page Access

Posted: Tue Feb 06, 2018 6:23 am
by straightlight
andrewtite wrote:
Tue Feb 06, 2018 3:31 am
I'm working with 3.0.
Open Cart, as I remember, used to use:
if (getURLVar('route') == 'your_path/your_controller_filename') {
...
but now all I see is:
$('#menu a[href]').on('click', function() {
sessionStorage.setItem('menu', $(this).attr('href'));
});
in common.js

I'm calling up the pages directly by the URL, not through clicking the menu, so that active variable doesn't update on page load.
This analogy is not entirely true. common.js file still use the getURLVar method to track in the route page from JS.

Re: Active Admin Menu Item on Direct Page Access

Posted: Wed Feb 07, 2018 1:44 am
by andrewtite
I have attached the common.js file that came with 3.0, please tell me what line that is on because I don't see it.
The only thing I see that works with clicking the menu: sessionStorage.setItem('menu', $(location).attr('href'));
It doesn't seem to work when you call the page directly without click a menu item....

Re: Active Admin Menu Item on Direct Page Access

Posted: Wed Feb 07, 2018 1:59 am
by andrewtite
So my solution that seems to work is I had to add the following to a vqmod...

<operation info="Set Active Menu Item">
<search position="before"><![CDATA[<script src="view/javascript/common.js" type="text/javascript"></script>]]></search>
<add><![CDATA[
<script>
$(document).ready(function() {
var routeEa = getURLVar('route').split('/');
var MenuHrefNew = $(location).attr('href').replace(getURLVar('route'), routeEa[0]+'/'+routeEa[1]);
sessionStorage.setItem('menu', MenuHrefNew);
});
</script>
]]></add>
</operation>