PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / 2.1.2
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score v2.1.2
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
powered-cache / assets / js / admin / modules / nav.js

nav.js in Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score 2.1.2, at assets/js/admin/modules/nav.js

59 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global jQuery, PoweredCache */
2 (function ($) {
3 // Use strict mode
4
5 // Define global PoweredCache object if it does not exist
6 if (typeof window.PoweredCache !== 'object') {
7 window.PoweredCache = {};
8 }
9
10 PoweredCache.sideNavigation = function (element) {
11 const button = $(element);
12
13 function current(el) {
14 const button = $(el); // eslint-disable-line no-shadow
15 const parent = button.closest('.sui-vertical-tabs');
16 const wrapper = button.closest('.sui-row-with-sidenav');
17 const content = wrapper.find('> div[data-tab]');
18 const dataNav = button.data('tab');
19 const dataBox = wrapper.find(`div[data-tab="${dataNav}"]`);
20 parent.find('li').removeClass('current');
21 button.parent().addClass('current');
22 // window.location.hash = el.hash;
23 localStorage.setItem('poweredcache_current_nav', el.hash);
24
25 content.hide();
26 dataBox.show();
27 }
28
29 function init() {
30 button.on('click', function (e) {
31 current(e.target);
32 e.preventDefault();
33 e.stopPropagation();
34 });
35
36 // auto-focus current section
37 if (window.location.hash && $(`a[href="${window.location.hash}"]`).length) {
38 $(`a[href^="${window.location.hash}"]`).click();
39 }
40
41 // auto-focus last selection
42 const lastnav = localStorage.getItem('poweredcache_current_nav');
43 if (lastnav && $(`a[href="${lastnav}"]`).length) {
44 $(`a[href^="${lastnav}"]`).click();
45 }
46 }
47
48 init();
49
50 return this;
51 };
52
53 $('body').ready(function () {
54 const button = $('.sui-vertical-tab a');
55
56 PoweredCache.sideNavigation(button);
57 });
58 })(jQuery);
59