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 / components / LinkPicker.js

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

72 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { on } from '../utility/on';
2
3 export class LinkPicker {
4 constructor() {
5 this.modal = document.getElementById('wp-link-wrap');
6
7 if (!this.modal) {
8 return;
9 }
10
11 this.modal.classList.add('ag_link-modal');
12 this.select = this.modal.querySelector('#wp-link-submit');
13
14 this.select.addEventListener('click', this.update);
15
16 Array.from(document.querySelectorAll('.button--link')).forEach((button) => {
17 button.addEventListener('click', this.open);
18 });
19
20
21 on('#wpwrap', 'click', '.ag-field--link .button--remove', this.clear);
22 }
23
24 open = (e) => {
25 this.input = e.target.parentNode.querySelector('input');
26 wpLink.open('wpwrap');
27 }
28
29 update = (e) => {
30 const { href } = wpLink.getAttrs();
31 this.input.value = href;
32
33 let display = this.input.parentNode.querySelector('.link-display');
34
35 if (display) {
36 display.textContent = href;
37 } else {
38 display = document.createElement('span');
39 display.className = 'link-display';
40 display.textContent = href;
41 this.input.insertAdjacentElement('afterend', display);
42 }
43
44
45 if (href) {
46 this.appendButton(e.target);
47 }
48
49 return true;
50 }
51
52 appendButton = () => {
53 if (!this.input.parentNode.querySelector('.button--remove')) {
54 const button = document.createElement('button');
55 button.type = 'button';
56 button.className = 'button button--remove';
57 button.textContent = 'Remove link';
58
59 // this.input.parentNode.appendChild(button);
60
61 this.input.insertAdjacentElement('beforebegin', button);
62 }
63 }
64
65 clear = (e) => {
66 e.target.parentNode.querySelector('input').value = '';
67
68 e.target.parentNode.removeChild(e.target.parentNode.querySelector('.link-display'));
69 e.target.parentNode.removeChild(e.target);
70 }
71 };
72