PageSourceSearch

https://www.ifsr-italia.org/wp-content/plugins/ifsr-soci/assets/js/frontend.js?ver=1.19.7

js ifsr-italia.org collected 2026-09-25 14:53:32 UTC 16,291 bytes, 354 lines download raw bytes

1(function () {
2    'use strict';
3
4    function ready(fn) {
5        if (document.readyState !== 'loading') { fn(); }
6        else { document.addEventListener('DOMContentLoaded', fn); }
7    }
8
9    function fitJoinPage() {
10        var page = document.querySelector('.ifsr-soci-category-page');
11        if (!page || document.body.classList.contains('wp-admin')) return;
12        var viewportWidth = document.documentElement.clientWidth;
13        page.style.setProperty('margin-left', '0', 'important');
14        page.style.setProperty('width', viewportWidth + 'px', 'important');
15        var offset = page.getBoundingClientRect().left;
16        page.style.setProperty('margin-left', (-offset) + 'px', 'important');
17    }
18
19    ready(function () {
20        fitJoinPage();
21        var resizeFrame = 0;
22        window.addEventListener('resize', function () {
23            window.cancelAnimationFrame(resizeFrame);
24            resizeFrame = window.requestAnimationFrame(fitJoinPage);
25        });
26        window.addEventListener('orientationchange', fitJoinPage);
27
28        var primaryAffiliation = document.getElementById('ifsr-appartenenza');
29        if (!primaryAffiliation) return;
30
31        var clubData = {};
32        var dataNode = document.getElementById('ifsr-club-data');
33        try {
34            clubData = dataNode ? JSON.parse(dataNode.textContent || '{}') : {};
35        } catch (e) {
36            clubData = {};
37        }
38
39        var familyTypes = ['rotary', 'rotaract', 'interact', 'innerwheel'];
40
41        function setRequired(el, required) {
42            if (!el) return;
43            el.required = !!required;
44            if (required) el.setAttribute('aria-required', 'true');
45            else el.removeAttribute('aria-required');
46        }
47
48        function clearValue(el) {
49            if (el) el.value = '';
50        }
51
52        function fillClubs(select, type) {
53            if (!select) return;
54            if (select.getAttribute('data-affiliation-type') === type) return;
55
56            select.innerHTML = '';
57            var first = document.createElement('option');
58            first.value = '';
59            first.textContent = 'Seleziona il Club';
60            select.appendChild(first);
61
62            var list = Array.isArray(clubData[type]) ? clubData[type] : [];
63            list.forEach(function (name) {
64                var option = document.createElement('option');
65                option.value = name;
66                option.textContent = name;
67                select.appendChild(option);
68            });
69
70            var other = document.createElement('option');
71            other.value = '__other__';
72            other.textContent = list.length ? 'Club non presente nell’elenco' : 'Scrivi il nome completo del Club';
73            select.appendChild(other);
74            select.setAttribute('data-affiliation-type', type);
75        }
76
77        function setupAffiliation(config) {
78            var affiliation = document.getElementById(config.affiliationId);
79            var familyFields = document.getElementById(config.familyFieldsId);
80            var scoutFields = document.getElementById(config.scoutFieldsId);
81            var clubSelect = document.getElementById(config.clubSelectId);
82            var clubOtherWrap = document.getElementById(config.clubOtherWrapId);
83            var clubOther = document.getElementById(config.clubOtherId);
84            var scoutAssociation = document.getElementById(config.scoutAssociationId);
85            var scoutAssociationOtherWrap = document.getElementById(config.scoutAssociationOtherWrapId);
86            var scoutAssociationOther = document.getElementById(config.scoutAssociationOtherId);
87            var scoutGroup = document.getElementById(config.scoutGroupId);
88            var scoutGroupLabel = document.getElementById(config.scoutGroupLabelId);
89            var otherFields = document.getElementById(config.otherFieldsId);
90            var otherInput = document.getElementById(config.otherInputId);
91
92            function isActive() {
93                return typeof config.isActive === 'function' ? config.isActive() : true;
94            }
95
96            function updateClubOther() {
97                var show = isActive() && clubSelect && clubSelect.value === '__other__';
98                if (clubOtherWrap) clubOtherWrap.hidden = !show;
99                setRequired(clubOther, show);
100                if (!show) clearValue(clubOther);
101            }
102
103            function updateScoutGroupLabel() {
104                if (!scoutGroupLabel) return;
105                var isMasci = scoutAssociation && scoutAssociation.value && scoutAssociation.value.toUpperCase() === 'MASCI';
106                scoutGroupLabel.textContent = isMasci ? ('Comunità' + (config.requireAffiliation ? ' *' : '')) : ('Gruppo Scout' + (config.requireAffiliation ? ' *' : ''));
107                if (scoutGroup) scoutGroup.placeholder = isMasci ? 'Es. Comunità MASCI Salerno' : 'Es. AGESCI Salerno 10';
108            }
109
110            function updateScoutAssociationOther() {
111                updateScoutGroupLabel();
112                var show = isActive() && scoutAssociation && scoutAssociation.value === '__other__';
113                if (scoutAssociationOtherWrap) scoutAssociationOtherWrap.hidden = !show;
114                setRequired(scoutAssociationOther, show);
115                if (!show) clearValue(scoutAssociationOther);
116            }
117
118            function clearAll() {
119                clearValue(affiliation);
120                clearValue(clubSelect);
121                clearValue(clubOther);
122                clearValue(scoutAssociation);
123                clearValue(scoutAssociationOther);
124                clearValue(scoutGroup);
125                clearValue(otherInput);
126                if (clubSelect) clubSelect.removeAttribute('data-affiliation-type');
127            }
128
129            function update() {
130                var active = isActive();
131                var type = active && affiliation ? affiliation.value : '';
132                var isFamily = familyTypes.indexOf(type) !== -1;
133                var isScout = type === 'scout';
134                var isOther = type === 'nessuna';
135
136                if (familyFields) familyFields.hidden = !isFamily;
137                if (scoutFields) scoutFields.hidden = !isScout;
138                if (otherFields) otherFields.hidden = !isOther;
139
140                setRequired(affiliation, active && !!config.requireAffiliation);
141                setRequired(clubSelect, isFamily);
142                setRequired(scoutAssociation, isScout);
143                setRequired(scoutGroup, isScout);
144                setRequired(otherInput, isOther);
145
146                if (isFamily) {
147                    fillClubs(clubSelect, type);
148                    updateClubOther();
149                    clearValue(scoutAssociation);
150                    clearValue(scoutAssociationOther);
151                    clearValue(scoutGroup);
152                    if (scoutAssociationOtherWrap) scoutAssociationOtherWrap.hidden = true;
153                    setRequired(scoutAssociationOther, false);
154                } else {
155                    if (clubOtherWrap) clubOtherWrap.hidden = true;
156                    setRequired(clubOther, false);
157                    clearValue(clubOther);
158                    if (!active || isScout || isOther) {
159                        clearValue(clubSelect);
160                            }
161                }
162
163                if (isScout) {
164                    updateScoutAssociationOther();
165                } else {
166                    if (scoutAssociationOtherWrap) scoutAssociationOtherWrap.hidden = true;
167                    setRequired(scoutAssociationOther, false);
168                    clearValue(scoutAssociationOther);
169                    if (!active || isFamily || isOther) {
170                        clearValue(scoutAssociation);
171                        clearValue(scoutGroup);
172                    }
173                }
174
175                if (!isOther) {
176                    clearValue(otherInput);
177                }
178            }
179
180            if (affiliation) affiliation.addEventListener('change', update);
181            if (clubSelect) clubSelect.addEventListener('change', updateClubOther);
182            if (scoutAssociation) scoutAssociation.addEventListener('change', updateScoutAssociationOther);
183            updateScoutGroupLabel();
184
185            return {
186                update: update,
187                clearAll: clearAll,
188                affiliation: affiliation
189            };
190        }
191
192        var primary = setupAffiliation({
193            affiliationId: 'ifsr-appartenenza',
194            familyFieldsId: 'ifsr-family-fields',
195            scoutFieldsId: 'ifsr-scout-fields',
196            clubSelectId: 'ifsr-club-nome',
197            clubOtherWrapId: 'ifsr-club-other-wrap',
198            clubOtherId: 'ifsr-club-altro',
199            scoutAssociationId: 'ifsr-scout-associazione',
200            scoutAssociationOtherWrapId: 'ifsr-scout-association-other-wrap',
201            scoutAssociationOtherId: 'ifsr-scout-associazione-altro',
202            scoutGroupId: 'ifsr-scout-gruppo',
203            scoutGroupLabelId: 'ifsr-scout-group-label',
204            otherFieldsId: 'ifsr-other-affiliation-fields',
205            otherInputId: 'ifsr-altra-appartenenza',
206            requireAffiliation: true
207        });
208
209        var familyReferenceType = document.getElementById('ifsr-familiare-appartenenza');
210
211        if (familyReferenceType) familyReferenceType.addEventListener('change', function () {
212            updateDistrictField();
213        });
214
215        var doubleToggle = document.getElementById('ifsr-doppia-appartenenza');
216        var doubleBox = document.getElementById('ifsr-double-membership-box');
217        var secondWrapper = document.getElementById('ifsr-second-membership');
218        var districtSelect = document.getElementById('ifsr-distretto-generale');
219        var districtHelp = document.getElementById('ifsr-distretto-help');
220        var districtFirstOption = document.getElementById('ifsr-distretto-prima-opzione');
221        var districtNote = document.getElementById('ifsr-distretto-nota');
222        var categoryInput = document.querySelector('input[name="categoria"]');
223        var categoryKey = categoryInput ? categoryInput.value : '';
224        var second = setupAffiliation({
225            affiliationId: 'ifsr-appartenenza-2',
226            familyFieldsId: 'ifsr-family-fields-2',
227            scoutFieldsId: 'ifsr-scout-fields-2',
228            clubSelectId: 'ifsr-club-nome-2',
229            clubOtherWrapId: 'ifsr-club-other-wrap-2',
230            clubOtherId: 'ifsr-club-altro-2',
231            scoutAssociationId: 'ifsr-scout-associazione-2',
232            scoutAssociationOtherWrapId: 'ifsr-scout-association-other-wrap-2',
233            scoutAssociationOtherId: 'ifsr-scout-associazione-altro-2',
234            scoutGroupId: 'ifsr-scout-gruppo-2',
235            scoutGroupLabelId: 'ifsr-scout-group-label-2',
236            requireAffiliation: true,
237            isActive: function () { return !!(doubleToggle && doubleToggle.checked); }
238        });
239
240        function updateDistrictField() {
241            if (!districtSelect) return;
242
243            var primaryType = primary.affiliation ? primary.affiliation.value : '';
244            var familyType = familyReferenceType ? familyReferenceType.value : '';
245            var districtAffiliationType = categoryKey === 'socio-familiare' ? familyType : primaryType;
246            var secondActive = !!(doubleToggle && doubleToggle.checked);
247            var secondType = secondActive && second.affiliation ? second.affiliation.value : '';
248            var districtRequired = categoryKey === 'socio-associato-interactiano'
249                || districtAffiliationType === 'interact'
250                || secondType === 'interact';
251            var categoryRequiresSecretariat = (categoryKey.indexOf('socio-associato-') === 0
252                && categoryKey !== 'socio-associato-interactiano')
253                || ['socio-sostenitore', 'socio-benefattore'].indexOf(categoryKey) !== -1;
254            var primaryRequiresSecretariat = ['scout', 'innerwheel'].indexOf(districtAffiliationType) !== -1;
255            var assignedBySecretariat = !districtRequired
256                && (categoryRequiresSecretariat || primaryRequiresSecretariat);
257
258            districtSelect.disabled = assignedBySecretariat;
259            setRequired(districtSelect, districtRequired);
260            if (assignedBySecretariat) {
261                districtSelect.value = '';
262                districtSelect.setAttribute('aria-disabled', 'true');
263            } else {
264                districtSelect.removeAttribute('aria-disabled');
265            }
266
267            if (districtHelp) {
268                districtHelp.textContent = districtRequired
269                    ? '(obbligatorio)'
270                    : (assignedBySecretariat ? '(attribuito dalla Segreteria)' : '(facoltativo)');
271            }
272            if (districtFirstOption) {
273                districtFirstOption.textContent = districtRequired
274                    ? 'Seleziona il Distretto di appartenenza'
275                    : (assignedBySecretariat
276                        ? 'Il Distretto sarà attribuito dalla Segreteria'
277                        : 'Seleziona il Distretto, se conosciuto');
278            }
279            if (districtNote) {
280                districtNote.hidden = !(districtRequired || assignedBySecretariat);
281                districtNote.textContent = districtRequired
282                    ? 'Per gli Interact il Distretto di appartenenza è obbligatorio.'
283                    : 'Il Distretto sarà attribuito dalla Segreteria.';
284            }
285        }
286
287        function isGeneralSecondMembershipCategory() {
288            return ['socio-sostenitore', 'socio-benefattore', 'socio-a-vita'].indexOf(categoryKey) !== -1;
289        }
290
291        function syncSecondOptions() {
292            if (!second.affiliation || second.affiliation.tagName !== 'SELECT') return;
293            var primaryType = primary.affiliation ? primary.affiliation.value : '';
294            Array.prototype.forEach.call(second.affiliation.options, function (option) {
295                if (!option.value) return;
296                var duplicate = option.value === primaryType;
297                option.hidden = duplicate;
298                option.disabled = duplicate;
299            });
300            if (second.affiliation.value === primaryType) {
301                second.affiliation.value = '';
302            }
303        }
304
305        function syncSecondMembership() {
306            var active = !!(doubleToggle && doubleToggle.checked);
307            var generalSecondMembership = isGeneralSecondMembershipCategory();
308            var primaryType = primary.affiliation ? primary.affiliation.value : '';
309            var hideDoubleMembership = primaryType === 'scout';
310            var disableDoubleMembership = hideDoubleMembership || primaryType === 'nessuna';
311
312            if (doubleBox) doubleBox.hidden = hideDoubleMembership;
313
314            if (disableDoubleMembership && doubleToggle) {
315                doubleToggle.disabled = true;
316                doubleToggle.checked = false;
317                active = false;
318            } else if (doubleToggle) {
319                doubleToggle.disabled = false;
320            }
321
322            if (secondWrapper) secondWrapper.hidden = !active;
323            if (!active) {
324                second.clearAll();
325            } else if (second.affiliation && !generalSecondMembership) {
326                second.affiliation.value = 'scout';
327            }
328
329            if (generalSecondMembership) syncSecondOptions();
330            second.update();
331        }
332
333        function updateDoubleMembership() {
334            syncSecondMembership();
335        }
336
337        if (doubleToggle) {
338            doubleToggle.addEventListener('change', updateDoubleMembership);
339            doubleToggle.addEventListener('change', updateDistrictField);
340        }
341        if (primary.affiliation) {
342            primary.affiliation.addEventListener('change', syncSecondMembership);
343            primary.affiliation.addEventListener('change', updateDistrictField);
344        }
345        if (second.affiliation) {
346            second.affiliation.addEventListener('change', updateDistrictField);
347            second.affiliation.addEventListener('change', syncSecondOptions);
348        }
349
350        primary.update();
351        updateDoubleMembership();
352        updateDistrictField();
353    });
354})();

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.