PageSourceSearch

https://latrattoria.pt/wp-content/uploads/ac_assets/simple_popup/ue-simple-popup.js?ver=1.5.143

js latrattoria.pt collected 2026-10-06 04:26:31 UTC 15,890 bytes, 604 lines download raw bytes

1function ueSimplePopup(){
2  var g_popupId;
3  var g_objPopup;;
4  var g_objOverlay, g_objPopupWrap, g_objOpenPopup;
5  var g_isInEditor, g_showErrors, g_source, g_triggerType;
6  var g_activeClass;
7  var g_lastScrollTop, g_isOpenedOnScroll;
8  var g_cookieName;
9  var lastKeyWasShift = false;
10  
11  /**
12  * empty element id option error handle
13  */
14  function emptyIdOptionErrorHandle(dataElementId){    
15    if(g_isInEditor == 'no')
16      return(false);
17    
18    if(dataElementId != '')
19      return(false);
20    
21    if(g_showErrors == false)
22      return(false);
23    
24    var errorMessageHtml =  '<div class="uc-editor-message uc-error">Simple Popup Widget Error: Element Id option is empty. Please add Element Id to open it in popup.</div>';
25    
26    //update popup html to show error message
27    g_objPopup.html(errorMessageHtml);    
28  }
29  
30  /**
31  * no element found on the page error handle
32  */
33  function noElementFoundErrorHandle(objDataElementId, dataElementId){    
34    if(g_isInEditor == 'no')
35      return(false);
36    
37    if(objDataElementId.length)
38      return(false);
39    
40    if(g_showErrors == false)
41      return(false);
42    
43    var errorMessageHtml = '<div class="uc-editor-message uc-error">Simple Popup Widget Error: no Element found with id: "'+dataElementId+'"</div>';
44    
45    //update popup html to show error message
46    g_objPopup.html(errorMessageHtml);    
47  }
48  
49  /**
50  * click on trigger element
51  */
52  function onFoundElement(dataElementId){    
53    if(g_isInEditor == 'no')
54      return(false);
55    
56    var objPopupElement = jQuery('#'+dataElementId);
57    
58    if(!objPopupElement.length)
59      return(false);
60    
61    var successMessageHtml = '<div class="uc-editor-message uc-success">Element with id: "'+dataElementId+'" connected.</div> ';
62    
63    //update popup html to show error message
64    g_objPopupWrap.html(successMessageHtml);    
65  }
66  
67  /*
68  * show | hide connected elements in editor
69  */ 
70  function hideSectionInEditor(objDataElementId){    
71    if(g_isInEditor == 'no')
72      return(false);
73    
74    var dataHideInEditor = g_objPopup.data('hide-connected-elements');
75    
76    if(dataHideInEditor == true)
77      objDataElementId.hide();
78    
79    if(dataHideInEditor == false)
80      objDataElementId.css('display', '');    
81  }
82  
83  /**
84  * append element to popup
85  */
86  function appendElementToPopup(objDataElementId, dataElementId){    
87    if(g_isInEditor == 'yes'){
88      
89      //   onFoundElement(dataElementId);
90      
91      hideSectionInEditor(objDataElementId);
92      
93      //   return(false);
94      
95      //clone popup element
96      var objClonedElement = objDataElementId.clone();
97      
98      //append popup element to popup
99      g_objPopupWrap.append(objClonedElement);
100      
101    }else{
102      //detach popup element
103      var objDetachedElement = objDataElementId.detach();
104      
105      //append popup element to popup
106      g_objPopupWrap.append(objDetachedElement);
107      
108    }    
109  }
110  
111  /**
112  * find popup element
113  */
114  function findPopupElement(){    
115    if(g_source != 'id')
116      return(false);
117    
118    var dataElementId = g_objPopup.data('element-id');
119    
120    //if in editor and element id option is not set, show error    
121    emptyIdOptionErrorHandle(dataElementId);    
122    
123    //if in editor and element id object is not exist, show error    
124    var objDataElementId = jQuery('#'+dataElementId);
125    noElementFoundErrorHandle(objDataElementId, dataElementId);
126    
127    //detach element
128    appendElementToPopup(objDataElementId, dataElementId);        
129  }
130  
131  /**
132  * debug popup for styling  */
133  function debugPopup(){    
134    if(g_isInEditor == 'no')
135      return(false);
136    
137    var isDebugModeOn = g_objPopupWrap.data('debug');
138    
139    if(isDebugModeOn == false)
140      return(false);
141    
142    //add active class to overlay to open popup
143    g_objOverlay.addClass(g_activeClass);    
144  }
145  
146  /**
147  * init elementor elements
148  */
149  function initElementorElements(){
150    var objInnerElementorElements = g_objOverlay.find(".elementor-element");
151    
152    if(!objInnerElementorElements || objInnerElementorElements.length == 0)
153      return(false);
154    
155    objInnerElementorElements.each(function(){
156      var objElement = jQuery(this);
157      
158      if(objElement.hasClass("elementor-sticky") == true)
159        return(true)     
160      
161      elementorFrontend.elementsHandler.runReadyTrigger( objElement );   
162    });
163  }
164  
165  /**
166  * open popup
167  */
168  function openPopup(){    
169    if (document.cookie.includes("ue_simple_popup_" + g_cookieName+"=true;"))
170      return(false);
171    
172    if(g_objOverlay.hasClass(g_activeClass) == true)
173      return(false);
174    
175    //dont run in editor
176    if(g_isInEditor == 'yes')
177      return(true);
178    
179    g_objOverlay.addClass(g_activeClass);    
180    
181    jQuery('body').addClass(g_activeClass);
182    
183    //trigger elementor popup event
184    jQuery(document).trigger( 'ue_run_ready_trigger');
185    
186    //reinit inner elementor elements
187    initElementorElements();
188    
189    //for tabbing
190    enableFocusableElements();
191  }
192  
193  /**
194  * click on trigger element
195  */
196  function onOpenPopupClick(){       
197    openPopup();
198    
199    //protect from tabbing inside closed popup
200    g_objPopupWrap.attr('area-hidden', false);
201  }
202  
203  /**
204  * open popup after page load
205  */
206  function openPopupAfterLoad(){    
207    //check trigger
208    var dataTriggerLoad = g_triggerType.indexOf('load') > -1;
209    
210    if(dataTriggerLoad == false)
211      return(false);
212    
213    var loadDelay = g_objPopup.data('load-delay') * 1000;
214    
215    setTimeout(openPopup, loadDelay);    
216  }
217  
218  /**
219  * open popup after page scroll
220  */
221  function openPopupAfterPageScroll(e){    
222    //check trigger
223    var dataTriggerScroll = g_triggerType.indexOf('scroll') > -1;
224    
225    if(dataTriggerScroll == false)
226      return(false);  
227    
228    var scrollAmountFromWindowTop = jQuery(window).scrollTop();    
229    
230    //look after scroll direction
231    var dataDirection = g_objPopup.data('scroll-direction');
232    var actualDirection;
233    
234    if (scrollAmountFromWindowTop > g_lastScrollTop)
235      actualDirection = 'down';
236    else 
237      actualDirection = 'up';
238    
239    g_lastScrollTop = scrollAmountFromWindowTop;
240    
241    if(dataDirection != actualDirection)
242      return(false);
243    
244    var scrollAmountToPopupOpen = g_objPopup.data('scroll-amount'); //percents    
245    var documentHeight = parseInt(jQuery(document).height());
246    
247    //get round percent number
248    var scrollAmountFromWindowTopPercents = Math.floor(scrollAmountFromWindowTop / documentHeight * 100);
249    
250    if(dataDirection == 'down' && scrollAmountFromWindowTopPercents >= scrollAmountToPopupOpen && g_isOpenedOnScroll == false){
251      openPopup();
252      g_isOpenedOnScroll = true; //allows to open popup during scroll only one time
253    }
254    
255    if(dataDirection == 'up' && scrollAmountFromWindowTopPercents <= scrollAmountToPopupOpen && g_isOpenedOnScroll == false){
256      openPopup();
257      g_isOpenedOnScroll = true; //allows to open popup during scroll only one time
258    }
259  }
260  
261  /**
262  * exit intent trigger
263  */
264  function onExitIntent(e){    
265    var dataTriggerExit = g_triggerType.indexOf('exit') > -1;
266    
267    if(dataTriggerExit == false)
268      return(false);
269    
270    var shouldShowExitIntent = !e.toElement &&  !e.relatedTarget && e.clientY < 10;
271    
272    if (shouldShowExitIntent)     
273      openPopup();       
274  }
275  
276  /**
277  * opaen popup on hash
278  */
279  function openPopupOnHash(){    
280    var dataTriggerHash = g_triggerType.indexOf('hash') > -1;
281    
282    if(dataTriggerHash == false)
283      return(false);
284    
285    //find hash in url
286    var hash = window.location.hash;
287    
288    //remove hash char
289    hash = hash.replace("#", "");
290    
291    if(!hash)
292      return(false);
293    
294    var dataHash = g_objPopup.data('popup-hash');
295    
296    if(hash == dataHash)
297      openPopup();    
298  }
299  
300  /**
301  * make all elelemts focusasble inside popup
302  */
303  function enableFocusableElements(){
304    g_objOverlay
305    .find('[data-old-tabindex]')
306    .each(function () {
307      const oldTab = jQuery(this).attr('data-old-tabindex');
308      if (oldTab) {
309        jQuery(this).attr('tabindex', oldTab);
310      } else {
311        jQuery(this).removeAttr('tabindex');
312      }
313      jQuery(this).removeAttr('data-old-tabindex');
314    });
315  }
316  
317  /**
318  * make all elelemts unfocusasble inside popup
319  */
320  function disableFocusableElements(){
321    g_objOverlay
322    .find('a, button, input, select, textarea, [tabindex]')
323    .attr('data-old-tabindex', function () {
324      const tabindex = jQuery(this).attr('tabindex');
325      return tabindex !== undefined ? tabindex : '';
326    })
327    .attr('tabindex', -1);
328  }
329  
330  /**
331  * click on close element
332  */
333  function onClosePopupClick(){    
334    //dont run in editor
335    if(g_isInEditor == 'yes')
336      return(false);
337    
338    if(g_objOverlay.hasClass(g_activeClass) == false)
339      return(false);
340    
341    g_objOverlay.removeClass(g_activeClass);
342    
343    //protect from tabbing inside closed popup
344    g_objPopupWrap.attr('area-hidden', true);
345    
346    jQuery('body').removeClass(g_activeClass);
347    
348    //set cookie if needed
349    setCookie();
350    
351    disableFocusableElements();
352  }
353  
354  /**
355  * close from external file
356  */
357  this.ueOpenSimplePopup = function(){
358    onOpenPopupClick();
359  }
360
361  /**
362  * close from external file
363  */
364  this.ueCloseSimplePopup = function(){
365    onClosePopupClick();
366  }
367  
368  /**
369  * set cookie name
370  */
371  function setCookie(){    
372    var dataCookie = g_objPopup.data('cookie');
373    
374    if(dataCookie == false)
375      return(false);
376    
377    //get data time values in miliseconds
378    var dataCookieDays = g_objPopup.data('cookie-days') * 24 * 60 * 60 * 1000;
379    var dataCookieHours = g_objPopup.data('cookie-hours') * 60 * 60 * 1000;
380    var dataCookieMinutes = g_objPopup.data('cookie-minutes') * 60 * 1000;
381    var dataCookieSeconds = g_objPopup.data('cookie-seconds') * 1000;
382    
383    var ue_expires = new Date();
384    
385    ue_expires.setTime(ue_expires.getTime() + dataCookieDays + dataCookieHours + dataCookieMinutes + dataCookieSeconds);
386    
387    document.cookie = "ue_simple_popup_" + g_cookieName+"=true; expires=" + ue_expires.toUTCString() + ";";    
388  }
389  
390  /**
391  * on custom trigger element click
392  */
393  function onCustomTriggerElementClick(){    
394    //find if any opened popup exists
395    var objOpenedSimplePopupOverlay = jQuery('.ue-simple-popup-overlay.'+g_activeClass);
396    
397    if(!objOpenedSimplePopupOverlay.length)
398      return(false);
399    
400    //dont close popup in editor
401    if(g_isInEditor == 'yes')
402      return(false);
403    
404    objOpenedSimplePopupOverlay.removeClass(g_activeClass);
405    
406    jQuery('body').removeClass(g_activeClass);
407    
408    //set cookie if needed
409    setCookie();    
410  }
411  
412  
413  
414  /**
415  * focus on next focusable element outsite popup
416  */
417  function focusNextOutsidePopup() {
418    var $allFocusable = jQuery('a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])')
419    .filter(':visible');
420    
421    var $popupFocusable = jQuery('#' + g_popupId)
422    .find('a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])')
423    .filter(':visible');
424    
425    if ($popupFocusable.length === 0) return;
426    
427    if (lastKeyWasShift) {
428      
429      // User pressed Shift+Tab
430      var $firstInPopup = $popupFocusable.first();
431      var index = $allFocusable.index($firstInPopup);
432      var $prevOutside = $allFocusable.eq(index - 1);
433      
434      if ($prevOutside.length) {
435        $prevOutside.focus();
436      } else {
437        $allFocusable.last().focus(); // fallback
438      }
439    } else {
440      
441      // Normal Tab
442      var $lastInPopup = $popupFocusable.last();
443      var index = $allFocusable.index($lastInPopup);
444      var $nextOutside = $allFocusable.eq(index + 1);
445      
446      if ($nextOutside.length) {
447        $nextOutside.focus();
448      } else {
449        $allFocusable.first().focus(); // fallback
450      }
451    }
452    
453    lastKeyWasShift = false; // reset after handling
454  }
455  
456  /**
457  * on enter click
458  */
459  function onCloseKeyDown(e){
460    var keyCode = e.keyCode;
461    var objClosePopup = jQuery(this);
462    
463    if(keyCode == 13){      
464      onClosePopupClick();
465      g_objOpenPopup.focus();
466    }
467  }
468  
469  /**
470  * on enter click
471  */
472  function onOpenKeyDown(e){
473    var keyCode = e.keyCode;
474    var objOpenPopup = jQuery(this);
475    
476    if(keyCode == 13){
477      onOpenPopupClick();
478    }
479  }
480  
481  /**
482  * focus on next focusable element after open popup btn if popup is closed
483  */
484  function onOpenPopupBlur(){
485    //find if popup is opened
486    var isOpened = g_objOverlay.hasClass(g_activeClass);
487    
488    if(isOpened == true)
489      return(true);
490    
491    // focusNextOutsidePopup();
492  }
493  
494  function initPopup(){        
495    g_objOverlay = g_objPopup.find('.ue-simple-popup-overlay');
496    g_objPopupWrap = g_objPopup.find('.ue-simple-popup-wrapper');
497    g_objOpenPopup = g_objPopup.find('.ue-simple-popup-trigger');
498    g_isInEditor = g_objPopup.data('editor');
499    g_showErrors = g_objPopup.data('show-errors');
500    g_source = g_objPopup.data('source');
501    g_triggerType = g_objPopup.data('trigger-type');
502    g_activeClass = 'uc-active';
503    g_lastScrollTop = 0;
504    g_isOpenedOnScroll = false;
505    g_cookieName = g_popupId + '_cookieName';
506    
507    var objClosePopup = g_objPopup.find('.ue-simple-popup-close');
508    
509    //custom close element
510    var objCustomCloseElements = jQuery('.uc-close-simple-popup');
511    
512    //find popup element
513    findPopupElement();
514    
515    //debug for styling
516    debugPopup();
517    
518    //init events
519    g_objOpenPopup.on('click', onOpenPopupClick);
520    g_objOpenPopup.on('keydown', function(e){onOpenKeyDown(e)});
521    g_objOpenPopup.on('blur', onOpenPopupBlur);
522    
523    // Detect if Shift was pressed
524    jQuery(document).on('keydown', function(e) {
525      lastKeyWasShift = e.shiftKey;
526    });
527    
528    objClosePopup.on('click', onClosePopupClick);
529    objClosePopup.on('keydown', function(e){onCloseKeyDown(e)});
530    
531    objCustomCloseElements.on('click', onCustomTriggerElementClick)
532    
533    g_objOverlay.on("click", function(event){
534      
535      //close popup unless target isn't popup wrap object (not working in debug mode in editor)
536      if (!jQuery(event.target).closest(g_objPopupWrap).length)
537        onClosePopupClick();
538      
539    });
540    
541    //sets focusable elemeents to tabindex="-1"
542    disableFocusableElements();  
543    
544    //open popup after page load
545    openPopupAfterLoad();
546    
547    //open popup if popup hash exist
548    openPopupOnHash();
549    
550    var animFrameId;
551    
552    //open popup after page scroll
553    jQuery(window).on('scroll', function(){
554      
555      if (animFrameId)
556        cancelAnimationFrame(animFrameId);      
557      
558      animFrameId = requestAnimationFrame(openPopupAfterPageScroll);
559      
560    });
561    
562    //open popup before page leave    
563    jQuery(document).on('mouseout', onExitIntent);      
564  }
565  
566  var g_isInited = false;
567  
568  function checkBreakPointAndInit(dataBreakPoint){    
569    var isResponsiveViewport = window.matchMedia("(max-width: "+dataBreakPoint+"px)").matches;
570    
571    if(isResponsiveViewport == false)
572      return(false);
573    
574    if(g_isInited == true)
575      return(false);
576    
577    initPopup();
578    
579    g_isInited = true;    
580  }
581  
582  //responsive mode
583  this.initUESimplePopup = function(id){
584    //init vars
585    g_popupId = id;
586    g_objPopup = jQuery('#'+g_popupId);
587
588    var dataResponsiveMode = g_objPopup.data('responsive-mode');
589    
590    if(dataResponsiveMode == false){      
591      initPopup(); //regular mode
592      
593      return(false);      
594    }
595    
596    var dataBreakPoint = g_objPopup.data('responsive-breakpoint');
597    
598    checkBreakPointAndInit(dataBreakPoint); //responsive mode
599    
600    jQuery(window).on('resize', function(){
601      checkBreakPointAndInit(dataBreakPoint); //responsive mode
602    });    
603  }  
604}

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.