PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.7.2
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.7.2
2.7.1 2.7.2 2.7.0 2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 All 141 releases
metasync / admin / js / metasync-per-page.js

metasync-per-page.js in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.7.2, at admin/js/metasync-per-page.js

104 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Results-per-page selectors for MetaSync admin list tables.
3 *
4 * A changed page size is a normal GET navigation, not an AJAX request: the
5 * server validates and persists it before rebuilding the relevant list.
6 */
7 (function () {
8 'use strict';
9
10 var transientParams = [
11 '_wpnonce', '_wp_http_referer', 'action', 'action2', 'filter_action',
12 'item', 'item[]', 'items', 'items[]', 'id'
13 ];
14
15 function controlValue(form, param) {
16 var control = form.elements.namedItem(param);
17
18 if (!control) {
19 return null;
20 }
21
22 if (typeof control.value === 'string') {
23 return control.value.trim();
24 }
25
26 return control.length && typeof control[0].value === 'string'
27 ? control[0].value.trim()
28 : null;
29 }
30
31 function syncFormState(params, form, stateParams) {
32 stateParams.forEach(function (param) {
33 var value = controlValue(form, param);
34
35 if (value === null) {
36 return;
37 }
38
39 params.delete(param);
40 if (value !== '') {
41 params.set(param, value);
42 }
43 });
44 }
45
46 window.metasyncNavigateListState = function (form, pageKey, changedSelector) {
47 var selector = changedSelector || document.querySelector(
48 '.metasync-per-page-select[data-page-key="' + pageKey + '"]'
49 );
50
51 if (!selector) {
52 return false;
53 }
54
55 var perPageKey = selector.dataset.perPageKey;
56 var pagedParam = selector.dataset.pagedParam;
57 var stateParams = JSON.parse(selector.dataset.stateParams || '[]');
58 var params = new URL(window.location.href).searchParams;
59
60 transientParams.forEach(function (param) {
61 params.delete(param);
62 });
63 if (pageKey === 'redirections' || pageKey === '404_monitor') {
64 params.delete('s');
65 }
66
67 if (form) {
68 syncFormState(params, form, stateParams);
69 }
70
71 params.set(perPageKey, selector.value);
72 // The page size applies for this request, but only a request signed
73 // with the per-page nonce may persist it (see
74 // Metasync_Per_Page_Helper::resolve()).
75 if (window.metasyncPerPage && window.metasyncPerPage.nonces
76 && window.metasyncPerPage.nonces[pageKey]) {
77 params.set('_wpnonce', window.metasyncPerPage.nonces[pageKey]);
78 }
79 params.delete(pagedParam);
80
81 if (params.get('page') === 'searchatlas-redirections') {
82 params.set('tab', pageKey === '404_monitor' ? '404-monitor' : 'redirections');
83 }
84
85 window.location.assign('admin.php?' + params.toString());
86 return true;
87 };
88
89 document.addEventListener('change', function (event) {
90 var selector = event.target;
91
92 if (!selector.matches('.metasync-per-page-select')) {
93 return;
94 }
95
96 var pageKey = selector.dataset.pageKey;
97 if (!pageKey) {
98 return;
99 }
100
101 window.metasyncNavigateListState(selector.form, pageKey, selector);
102 });
103 }());
104