PHP Classes

File: src/utils/menu-fix.js

Recommend this page to a friend!
  Classes of Maniruzzaman Akash   WP Vue Kit Plugin   src/utils/menu-fix.js   Download  
File: src/utils/menu-fix.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: WP Vue Kit Plugin
Vue.js plugin to build WordPress user interfaces
Author: By
Last change:
Date: 1 year ago
Size: 1,079 bytes
 

Contents

Class file image Download
export const pluginSlug = 'wp-vue-kit'; /** * As we are using hash based navigation, hack fix * to highlight the current selected menu * * Requires jQuery */ export function menuFix() { const $ = jQuery; const menuRoot = $('#toplevel_page_' + pluginSlug); const currentUrl = window.location.href; const currentPath = currentUrl.substr(currentUrl.indexOf('admin.php')); $('ul.wp-submenu li', menuRoot).removeClass('current'); menuRoot.on('click', 'a', function () { const self = $(this); $('ul.wp-submenu li', menuRoot).removeClass('current'); if (self.hasClass('wp-has-submenu')) { $('li.wp-first-item', menuRoot).addClass('current'); } else { self.parents('li').addClass('current'); } }); $('ul.wp-submenu a', menuRoot).each(function (index, el) { let hrefRoute = $(el).attr('href').substring($(el).attr('href').indexOf('/admin.php') + 1); if (hrefRoute === currentPath) { $(el).parent().addClass('current'); } }); } menuFix();