PluginProbe
Age Gate / 3.7.3
Age Gate v3.7.3
3.7.3 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 All 113 releases
age-gate / src / Resources / assets / js / admin / admin.js

admin.js in Age Gate 3.7.3, at src/Resources/assets/js/admin/admin.js

124 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import Modal from "./modules/wp-picker";
2 import { LinkPicker } from './components/LinkPicker';
3 import SimpleMDE from 'simplemde/dist/simplemde.min.js';
4 import hljs from 'highlight.js/lib/core';
5 import css from 'highlight.js/lib/languages/css';
6 import Alpine from 'alpinejs'
7 import { accordion } from "./components/Accordion";
8
9 import { Paginator } from "./components/Paginator";
10 // import './components/GreedyNav';
11 // import Bouncer from 'formbouncerjs';
12
13 global.age_gate_pagination = Paginator;
14
15 window.addEventListener('DOMContentLoaded', () => {
16 accordion();
17
18 // Array.from(document.querySelectorAll('.ag-field--paginator')).forEach(el => new Paginator(el));
19
20 // const validate = new Bouncer('.ag-settings-form');
21
22 hljs.registerLanguage('css', css);
23 document.querySelectorAll('.language-css').forEach(el => {
24 // then highlight each
25 hljs.highlightElement(el);
26 });
27
28 window.Alpine = Alpine
29 Alpine.start();
30
31 new Modal();
32 new LinkPicker;
33
34 document.querySelectorAll('[name="ag_settings[all]"]').forEach(toggle => {
35 toggle.addEventListener('change', (e) => {
36 toggle.closest('table').querySelectorAll('[type="checkbox"]').forEach(input => input.checked = toggle.checked);
37 });
38 });
39
40 document.querySelectorAll('.ag-file').forEach(file => {
41 file.addEventListener('change', (e) => file.parentNode.querySelector('.ag-file-custom').dataset.text = e.target.files[0].name )
42 });
43
44 //
45 const paramsString = window.location.search;
46
47 // console.log(paramsString);
48 const searchParams = new URLSearchParams(paramsString);
49
50 searchParams.delete('m');
51
52 console.log(searchParams.toString())
53 history.replaceState(null, '', `admin.php?${searchParams.toString() }`);
54
55 Array.from(document.querySelectorAll('.ag-rte')).forEach((editor) => {
56 const simplemde = new SimpleMDE({
57 element: editor,
58 spellChecker: false,
59 forceSync: true,
60 });
61 });
62
63 // Removed as not allowed
64 // Array.from(document.querySelectorAll('.ag-css')).forEach((editor) => {
65 // wp.codeEditor.initialize(editor, {});
66 // });
67
68 Array.from(document.querySelectorAll('.ag-form__reset')).forEach((frm) => {
69
70 // frm.addEventListener('submit', (e) => (!confirm('Are you sure?') ? e.preventDefault() : true) );
71 // async (e) => {
72 // return confirm('Are you sure?') === true;
73 // // return await Swal.fire({
74 // // title: 'Are you sure?',
75 // // text: "You won't be able to revert this!",
76 // // icon: 'warning',
77 // // showCancelButton: true,
78 // // confirmButtonColor: '#3085d6',
79 // // cancelButtonColor: '#d33',
80 // // confirmButtonText: 'Yes, delete it!'
81 // // }).then((result) => {
82 // // return result.isConfirmed
83
84
85 // // })
86 // });
87 });
88
89 Array.from(document.querySelectorAll('.ag-remove-legacy-css')).forEach((button) => {
90 console.log(button);
91 button.addEventListener('click', (e) => {
92 if (confirm('Are you sure?')) {
93 const { ajaxurl } = window;
94
95 const data = new FormData;
96 data.append('action', 'ag_clear_legacy_css');
97 data.append('nonce', e.currentTarget.dataset.id);
98
99 fetch(ajaxurl, {
100 method: 'POST',
101 body: data,
102 })
103
104 .then(r => {
105 const { status } = r;
106
107 if (status !== 200) {
108 throw new Error(status)
109 }
110
111 return r.json()
112 })
113 .then(data => {
114 window.location.reload();
115 })
116 .catch(resp => {
117 alert('Failed to execute request');
118 });
119
120 }
121 });
122 });
123 });
124