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!
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!
No OC version posted.
Of course, in common.js file, you could use the already used condition statement of:
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') {
}
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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.
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.
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.
If you have a better way of doing please let me know.
This analogy is not entirely true. common.js file still use the getURLVar method to track in the route page from JS.andrewtite wrote: ↑Tue Feb 06, 2018 3:31 amI'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.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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....
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....
Attachments
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>
<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>
Who is online
Users browsing this forum: No registered users and 71 guests