1/** 2 * AJI ACF Conditional Fields 3 * 4 * Affiche les champs conditionnels ACF en mode "grisé" plutôt que "caché". 5 * Utilise CSS pour surcharger le comportement d'ACF. 6 * Exclut les champs dans des onglets inactifs. 7 * 8 * @package AJI_Manager 9 * @since 1.0.0 10 */ 11(function ($) { 12 'use strict'; 13 14 const INACTIVE_TAB_CLASS = 'aji-in-inactive-tab'; 15 16 /** 17 * Injecte le CSS nécessaire 18 */ 19 function injectCSS() { 20 if ($('#aji-acf-conditional-css').length) return; 21 22 const css = ` 23 /* Champs avec conditions : toujours visibles même avec acf-hidden */ 24 /* SAUF si dans un onglet inactif */ 25 .acf-field[data-conditions].acf-hidden:not(.${INACTIVE_TAB_CLASS}) { 26 display: inline-block !important; 27 visibility: visible !important; 28 position: relative; 29 } 30 31 /* Overlay grisé pour les champs dont la condition n'est pas remplie */ 32 .acf-field[data-conditions].acf-hidden:not(.${INACTIVE_TAB_CLASS})::after { 33 content: ''; 34 position: absolute; 35 top: 0; 36 left: 0; 37 right: 0; 38 bottom: 0; 39 background: rgba(255, 255, 255, 0.7); 40 pointer-events: all; 41 cursor: not-allowed; 42 z-index: 10; 43 } 44 45 /* Ne pas appliquer aux tabs, accordions, messages */ 46 .acf-field[data-conditions][data-type="tab"].acf-hidden, 47 .acf-field[data-conditions][data-type="accordion"].acf-hidden, 48 .acf-field[data-conditions][data-type="message"].acf-hidden { 49 display: none !important; 50 } 51 `; 52 53 $('<style id="aji-acf-conditional-css">').text(css).appendTo('head'); 54 } 55 56 /** 57 * Marque les champs qui sont dans des onglets inactifs 58 */ 59 function markFieldsInInactiveTabs() { 60 // Retirer toutes les marques existantes 61 $('.' + INACTIVE_TAB_CLASS).removeClass(INACTIVE_TAB_CLASS); 62 63 // Parcourir tous les groupes d'onglets 64 $('.acf-tab-wrap').each(function () { 65 const $tabWrap = $(this); 66 const $activeButton = $tabWrap.find('.acf-tab-button.active'); 67 const activeTabKey = $activeButton.attr('data-key'); 68 69 // Trouver tous les champs tab après ce tab-wrap 70 let $current = $tabWrap.next(); 71 let currentTabKey = null; 72 73 while ($current.length && !$current.hasClass('acf-tab-wrap')) { 74 if ($current.hasClass('acf-field-tab')) { 75 // C'est un marqueur de tab 76 currentTabKey = $current.attr('data-key'); 77 } else if ($current.hasClass('acf-field')) { 78 // C'est un champ normal 79 if (currentTabKey && currentTabKey !== activeTabKey) { 80 // Ce champ est dans un onglet inactif 81 $current.addClass(INACTIVE_TAB_CLASS); 82 } 83 } 84 $current = $current.next(); 85 } 86 }); 87 } 88 89 /** 90 * Initialisation 91 */ 92 function init() { 93 injectCSS(); 94 95 // Marquer les champs au chargement 96 if (typeof acf !== 'undefined') { 97 acf.addAction('ready', function () { 98 setTimeout(markFieldsInInactiveTabs, 50); 99 }); 100 101 // Re-marquer au changement d'onglet 102 acf.addAction('show_field/type=tab', function () { 103 setTimeout(markFieldsInInactiveTabs, 10); 104 }); 105 106 // Re-marquer quand un onglet conditionnel apparaît/disparaît 107 acf.addAction('hide_field/type=tab', function () { 108 setTimeout(markFieldsInInactiveTabs, 10); 109 }); 110 } 111 112 // Aussi écouter le clic sur les boutons d'onglet 113 $(document).on('click', '.acf-tab-button', function () { 114 setTimeout(markFieldsInInactiveTabs, 10); 115 }); 116 117 // Appeler aussi au chargement du script 118 setTimeout(markFieldsInInactiveTabs, 100); 119 } 120 121 // Démarrer 122 $(init); 123 124})(jQuery); 125 126
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.