Total Complexity | 5 |
Complexity/F | 1.67 |
Lines of Code | 29 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /** |
||
7 | function menuFix(slug) { |
||
8 | var $ = jQuery; |
||
9 | |||
10 | let menuRoot = $('#toplevel_page_' + slug); |
||
11 | let currentUrl = window.location.href; |
||
12 | let currentPath = currentUrl.substr( currentUrl.indexOf('admin.php') ); |
||
13 | |||
14 | menuRoot.on('click', 'a', function() { |
||
15 | var self = $(this); |
||
16 | |||
17 | $('ul.wp-submenu li', menuRoot).removeClass('current'); |
||
18 | |||
19 | if ( self.hasClass('wp-has-submenu') ) { |
||
20 | $('li.wp-first-item', menuRoot).addClass('current'); |
||
21 | } else { |
||
22 | self.parents('li').addClass('current'); |
||
23 | } |
||
24 | }); |
||
25 | |||
26 | $('ul.wp-submenu a', menuRoot).each(function(index, el) { |
||
27 | if ( $(el).attr( 'href' ) === currentPath ) { |
||
28 | $('ul.wp-submenu a', menuRoot).parent().removeClass('current'); |
||
29 | $(el).parent().addClass('current'); |
||
30 | return; |
||
|
|||
31 | } |
||
32 | }); |
||
33 | } |
||
34 | |||
35 | export default menuFix; |