Total Complexity | 8 |
Complexity/F | 1.6 |
Lines of Code | 38 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | (function ($, app) { |
||
2 | 'use strict'; |
||
3 | |||
4 | $.extend(app, { |
||
5 | MENU_CURRENT_CLASS: 'active', |
||
6 | MENU_ROOT_SELECTOR: '.navbar-nav', |
||
7 | PJAX_MENU: 'menu-current' |
||
8 | }); |
||
9 | |||
10 | |||
11 | $(document) |
||
12 | .on('pjax:end', function (event, content, options) { |
||
13 | /*if (!options.push) { |
||
14 | return; |
||
15 | }*/ |
||
16 | var currentItems = $(event.target).find('[data-' + app.PJAX_MENU + ']'); |
||
17 | if (currentItems) { |
||
18 | var selectedLinks = currentItems.data(app.PJAX_MENU); |
||
19 | options.selectedLinks = selectedLinks; |
||
20 | setCurrentMenuItem(selectedLinks); |
||
21 | } |
||
22 | }); |
||
23 | |||
24 | function setCurrentMenuItem(selectedLinks) { |
||
25 | $(app.MENU_ROOT_SELECTOR + ' li.' + app.MENU_CURRENT_CLASS).removeClass(app.MENU_CURRENT_CLASS); |
||
26 | if (!selectedLinks || !selectedLinks.length) { |
||
27 | return; |
||
28 | } |
||
29 | |||
30 | $(selectedLinks).each(function (key, currentItem) { |
||
31 | $(app.MENU_ROOT_SELECTOR + ' li[data-name="' + currentItem + '"]') |
||
32 | .addClass(app.MENU_CURRENT_CLASS) |
||
33 | .parents(app.MENU_ROOT_SELECTOR + ' li').each(function () { |
||
34 | $(this).addClass(app.MENU_CURRENT_CLASS); |
||
35 | }); |
||
36 | }); |
||
37 | } |
||
38 | })(jQuery, application); |
||
|
|||
39 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.