PluginProbe
404 Solution / 4.2.0
404 Solution v4.2.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / js / behaviorTiles.js

behaviorTiles.js in 404 Solution 4.2.0, at includes/js/behaviorTiles.js

72 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Behavior Tiles — handles selection of 404 behavior option tiles.
3 */
4 (function () {
5 'use strict';
6
7 function init() {
8 var container = document.querySelector('.abj404-behavior-tiles');
9 if (!container) {
10 return;
11 }
12
13 var tiles = container.querySelectorAll('.abj404-tile');
14 var hiddenInput = container.querySelector('#dest404_behavior');
15 var customPicker = document.getElementById('abj404-custom-page-picker');
16
17 function selectTile(behavior) {
18 tiles.forEach(function (t) {
19 var isSel = t.getAttribute('data-behavior') === behavior;
20 t.classList.toggle('selected', isSel);
21 t.setAttribute('aria-checked', isSel ? 'true' : 'false');
22 });
23
24 if (hiddenInput) {
25 hiddenInput.value = behavior;
26 }
27
28 // Show/hide custom page picker and toggle required on its input
29 // so hidden required fields don't block form submission.
30 if (customPicker) {
31 var isCustom = behavior === 'custom';
32 customPicker.style.display = isCustom ? '' : 'none';
33 var pickerInput = customPicker.querySelector('[name="redirect_to_user_field"]');
34 if (pickerInput) {
35 if (isCustom) {
36 pickerInput.setAttribute('required', '');
37 } else {
38 pickerInput.removeAttribute('required');
39 }
40 }
41 }
42
43 // Mark the form as dirty so the save bar shows
44 var form = document.getElementById('admin-options-page');
45 if (form) {
46 var event = new Event('change', { bubbles: true });
47 form.dispatchEvent(event);
48 }
49 }
50
51 tiles.forEach(function (tile) {
52 tile.addEventListener('click', function () {
53 selectTile(tile.getAttribute('data-behavior'));
54 });
55
56 tile.addEventListener('keydown', function (e) {
57 if (e.key === 'Enter' || e.key === ' ') {
58 e.preventDefault();
59 selectTile(tile.getAttribute('data-behavior'));
60 }
61 });
62 });
63 }
64
65 // Initialize when DOM is ready
66 if (document.readyState === 'loading') {
67 document.addEventListener('DOMContentLoaded', init);
68 } else {
69 init();
70 }
71 })();
72