PageSourceSearch

https://y-parc.ch/themes/ypark-theme/js/custom-popup.js

js y-parc.ch collected 2026-10-04 14:39:24 UTC 5,214 bytes, 168 lines download raw bytes

1(function() {
2    'use strict';
3    
4    var surveyLoaded = false;
5    
6    // Récupérer ocale depuis PHP
7    var currentLocale = (typeof customPopupData !== 'undefined') ? customPopupData.locale : 'fr';    
8    console.log('Locale détectée:', currentLocale);
9    
10    var widgetLoaded = false;
11	var currentWidget = null;
12
13    function loadWidget(url) {
14        var script = document.createElement('script');
15        script.src = url;
16        document.head.appendChild(script);
17    }
18    
19    // Fonction pour nettoyer l'ancien widget
20    function clearWidget() {
21        // Supprimer l'ancien script SurveyMonkey s'il existe
22        if (currentWidget && currentWidget.parentNode) {
23            currentWidget.parentNode.removeChild(currentWidget);
24        }
25        
26        // Nettoyer le conteneur SurveyMonkey
27        var smContainer = document.getElementById('smcx-sdk');
28        if (smContainer) {
29            smContainer.remove();
30        }
31        
32        widgetLoaded = false;
33    }
34
35    // Fonction pour charger SurveyMonkey
36function initSurveyMonkey() {
37    if (widgetLoaded) {
38        console.log('Widget déjà chargé');
39        return;
40    }
41
42    clearWidget();
43
44    var widgetUrl;
45
46    switch(currentLocale) {
47        case 'en':
48            widgetUrl = 'https://widget.surveymonkey.com/collect/website/js/tRaiETqnLgj758hTBazgd970IOItyzs_2FKSx4sdiOlpCWct8MKdqu0BAPiww2K3xT.js';
49            break;
50        case 'fr':
51        default:
52            widgetUrl = 'https://widget.surveymonkey.com/collect/website/js/tRaiETqnLgj758hTBazgd970IOItyzs_2FKSx4sdiOlpDcMooijYYz_2BdIFrrxjRr4F.js';
53            break;
54    }
55
56    console.log('Chargement du widget SurveyMonkey:', widgetUrl);
57
58    var script = document.createElement('script');
59    script.src = widgetUrl;
60    script.async = true;
61    script.onload = function() {
62    console.log('Widget SurveyMonkey chargé avec succès pour locale:', currentLocale);
63    
64    // Attendre que SMCX crée son conteneur (avec retry)
65    var attempts = 0;
66    var maxAttempts = 20;
67    
68    var checkInterval = setInterval(function() {
69        attempts++;
70        var smcxSdk = document.getElementById('smcx-sdk');
71        var popupContent = document.querySelector('#custom-popup-overlay .custom-popup-content');
72        
73        if (smcxSdk && popupContent) {
74            console.log('Widget trouvé, déplacement dans la popup');
75            clearInterval(checkInterval);
76            popupContent.appendChild(smcxSdk);
77        } else if (attempts >= maxAttempts) {
78            console.error('Timeout - Conteneur non trouvé après', maxAttempts, 'tentatives');
79            console.error('smcx-sdk:', !!smcxSdk, 'popup-content:', !!popupContent);
80            clearInterval(checkInterval);
81        } else {
82            console.log('Tentative', attempts, '- En attente du widget...');
83        }
84    }, 200);
85};
86
87    script.onerror = function() {
88        console.error('Erreur lors du chargement du widget SurveyMonkey');
89    };
90    
91    document.head.appendChild(script);
92    currentWidget = script;
93    widgetLoaded = true;
94}
95    
96    // Fonction pour ouvrir la popup
97    function openPopup() {
98        
99        var popup = document.getElementById('custom-popup-overlay');
100        if (popup) {
101            popup.classList.add('active');
102        }
103
104	console.log('Ouverture de la popup');
105        
106        var overlay = document.getElementById('custom-popup-overlay');
107        if (!overlay) {
108            console.error('Popup overlay non trouve');
109            return;
110        }
111        
112        // Afficher la popup
113        overlay.classList.add('active');
114        document.body.classList.add('popup-open');
115        
116        // Charger SurveyMonkey
117        // loadSurveyMonkey();
118    }
119    
120    // Fonction pour fermer la popup
121    function closePopup() {
122        console.log('Fermeture de la popup');
123        
124        var overlay = document.getElementById('custom-popup-overlay');
125        if (overlay) {
126            overlay.classList.remove('active');
127            document.body.classList.remove('popup-open');
128        }
129    }
130    
131    // Initialisation
132    document.addEventListener('DOMContentLoaded', function() {
133        
134        console.log('Custom popup initialise pour locale:', currentLocale);
135
136        // Charger le widget SurveyMonkey dès le début
137        initSurveyMonkey();
138
139        var openButton = document.querySelector('.open-custom-popup');
140        if (openButton) {
141            openButton.addEventListener('click', function(e) {
142                e.preventDefault();
143                openPopup();
144            });
145        }
146
147        var closeButton = document.querySelector('.custom-popup-close');
148        if (closeButton) {
149            closeButton.addEventListener('click', closePopup);
150        }
151
152        var overlay = document.getElementById('custom-popup-overlay');
153        if (overlay) {
154            overlay.addEventListener('click', function(e) {
155                if (e.target === overlay) {
156                    closePopup();
157                }
158            });
159        }
160
161        document.addEventListener('keydown', function(e) {
162            if (e.key === 'Escape') {
163                closePopup();
164            }
165        });
166      
167    });
168})();

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.