PageSourceSearch

https://www.acad-ciencias.pt/wp-content/plugins/ays-popup-box/public/js/ays-pb-public.js?ver=6.3.6

js acad-ciencias.pt collected 2026-09-25 08:55:05 UTC 15,703 bytes, 449 lines download raw bytes

1(function( $ ) {
2	'use strict';
3
4	/**
5	 * All of the code for your public-facing JavaScript source
6	 * should reside in this file.
7	 *
8	 * Note: It has been assumed you will write jQuery code here, so the
9	 * $ function reference has been prepared for usage within the scope
10	 * of this function.
11	 *
12	 * This enables you to define handlers, for when the DOM is ready:
13	 *
14	 * $(function() {
15	 *
16	 * });
17	 *
18	 * When the window is loaded:
19	 *
20	 * $( window ).load(function() {
21	 *
22	 * });
23	 *
24	 * ...and/or other possibilities.
25	 *
26	 * Ideally, it is not considered best practise to attach more than a
27	 * single DOM-ready or window-load handler for a particular page.
28	 * Although scripts in the WordPress core, Plugins and Themes may be
29	 * practising this, we should strive to set a better example in our own work.
30	 */
31
32	$(document).ready(function (){
33		// Answer Sound Muter
34		$(document).on('click', '.ays_pb_music_sound', function() {
35			var $this = $(this);
36			var audioEl = $(document).find('.ays_pb_sound').get(0);
37			if($this.hasClass('ays_sound_active')){
38				audioEl.volume = 0;
39				$this.find('.ays_pb_fa_volume').remove();
40				$this.html(pbLocalizeObj.icons.volume_mute_icon);
41				$this.find('.ays_pb_fa_volume').addClass('ays_pb_fa_volume_off').removeClass('ays_pb_fa_volume');
42				$this.removeClass('ays_sound_active');
43			} else {
44				audioEl.volume = 1;
45				$this.find('.ays_pb_fa_volume_off').remove();
46				$this.html(pbLocalizeObj.icons.volume_up_icon);
47				$this.find('.ays_pb_fa_volume_off').addClass('ays_pb_fa_volume').removeClass('ays_pb_fa_volume_off');
48				$this.addClass('ays_sound_active');
49			}
50		});
51
52		$(document).on('click', '#ays_pb_dismiss_ad', function(){
53			var expTime = $(this).parent().data('dismiss');
54			var id = $(this).parent().data('id');
55
56			if(expTime != ''){
57				set_cookies('ays_pb_dismiss_ad_'+id, 'ays_pb_dismiss_ad_'+id, parseInt(expTime));
58			}else{
59				var expiryDate = new Date();
60				expiryDate.setMonth(expiryDate.getMonth() + 1);
61				set_cookies('ays_pb_dismiss_ad_'+id, 'ays_pb_dismiss_ad_'+id, expiryDate);
62			}
63			$(document).find('.ays-pb-modal-close_'+id).trigger('click');
64		});
65
66		$(document).on('click', '.asypb-cta', function(){
67			let popupContainer = $(this).closest('.ays-pb-modals');
68			if (!popupContainer) return;
69
70			// Check if conversion already updated
71			if (typeof popupContainer.attr('data-updated-conversion') != 'undefined') return
72
73			var classValue = popupContainer.attr('class');
74			var id = classValue.match(/av_pop_modals_(\d+)/)[1];
75			updatePopupConversions(id);
76
77			popupContainer.attr('data-updated-conversion', true);
78		});
79
80		function set_cookies( cname, cvalue, exdays ) {
81			var expires = 'expires=' +  (new Date(Date.now() + exdays)).toUTCString();  
82				document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';
83		}
84
85		var isMobileDevice = false;
86		if (window.innerWidth < 768) {
87			isMobileDevice = true;
88		}
89
90		$('div.ays-pb-modals').each(function() {
91			var classValue = $(this).attr('class');
92			var id = classValue.match(/av_pop_modals_(\d+)/)[1];
93			var popup = JSON.parse(atob(window.aysPopupOptions[id])).popupbox;
94			var popupOptions = JSON.parse(popup.options);
95
96			var actionType = popup.action_button_type;
97			var openDelay = popup.delay;
98			var scrollTop = popup.scroll_top;
99
100			var template = popup.view_type;
101			var height = popup.height;
102			var minHeight = popupOptions.pb_min_height;
103			var borderSize = (typeof popup.bordersize != 'undefined') ? popup.bordersize : 0;
104			var enableborderSizeMobile = (typeof popupOptions != 'undefined' && typeof popupOptions.enable_bordersize_mobile != 'undefined' && popupOptions.enable_bordersize_mobile == 'on') ? true : false;
105			if (typeof popupOptions != 'undefined' && typeof popupOptions.bordersize_mobile != 'undefined') {
106				var borderSizeMobile = popupOptions.bordersize_mobile;
107			} else {
108				var borderSizeMobile = borderSize;
109			}
110
111			if (!enableborderSizeMobile) {
112				borderSizeMobile = borderSize;
113			}
114
115			var enableFullScreen = popupOptions.enable_pb_fullscreen == 'on' ? true : false;
116
117			var closeButtonPosition = popupOptions.close_button_position;
118			var closeButtonText = popupOptions.close_button_text;
119			var closeButtonImage = popupOptions.close_button_image;
120
121			var enableOpenDelayMobile = popupOptions.enable_open_delay_mobile == 'on' ? true : false ;
122			var enableScrollTopMobile = popupOptions.enable_scroll_top_mobile == 'on' ? true : false ;
123			var enableCloseButtonPositionMobile = popupOptions.enable_close_button_position_mobile == 'on' ? true : false ;
124			var enableCloseButtonTextMobile = popupOptions.enable_close_button_text_mobile == 'on' ? true : false ;
125
126			$(document).find('.ays-pb-modal-close_'+id).on('click', function() {
127				$(document).find('input#ays-pb-modal-checkbox_' + id).trigger('change');
128			})
129
130			var formattedBorderSize = borderSize;
131			if (isMobileDevice) {
132				if (enableCloseButtonPositionMobile) {
133					closeButtonPosition = popupOptions.close_button_position_mobile;
134				}
135				if (enableCloseButtonTextMobile) {
136					closeButtonText = popupOptions.close_button_text_mobile;
137				}
138				if (enableOpenDelayMobile) {
139					openDelay = popupOptions.open_delay_mobile;
140				}
141				if (enableScrollTopMobile) {
142					scrollTop = popupOptions.scroll_top_mobile;
143				}
144				if (enableborderSizeMobile) {
145					formattedBorderSize = borderSizeMobile;
146				}
147
148				height = popupOptions.mobile_height ? popupOptions.mobile_height : popup.height;
149				enableFullScreen = false;
150			}
151
152			if (actionType == 'both' || actionType == 'pageLoaded') {
153				if (openDelay == 0 && scrollTop == 0) {
154					$(document).find('input#ays-pb-modal-checkbox_' + id).prop('checked', true);
155				}
156			}
157
158			if (enableFullScreen) {
159				height = window.innerHeight;
160			}
161			setCloseButtonPosition(template, id, height, minHeight, formattedBorderSize, enableFullScreen, closeButtonPosition, closeButtonImage);
162			setCloseButtonText(closeButtonText, closeButtonImage, id, template);
163		});
164
165		function setCloseButtonPosition(template, id, height, minHeight, borderSize, enableFullScreen, closeButtonPosition, closeButtonImage) {
166			if (template !== 'default' && template !== 'lil' && template !== 'image' && template !== 'template' && template !== 'video' && template !== 'minimal' && template !== 'image_type_img_theme' && template !== 'facebook' && template !== 'notification') {
167				return false;
168			}
169
170			var heightForPosition = height;
171			if (minHeight > height) {
172				heightForPosition = minHeight;
173			}
174
175			var closeButtonPositionValue = {};
176
177			if (template == 'default' || template == 'image_type_img_theme' || template == 'facebook') {
178				var aysConteiner       = parseInt(heightForPosition);
179				var h2Height           = $(document).find('.ays-pb-modal_' + id + ' h2').outerHeight(true);
180				var hrHeight           = $(document).find('.ays-pb-modal_' + id + ' hr').outerHeight(true);
181				var descriptionHeight  = $(document).find('.ays-pb-modal_' + id + ' .ays_pb_description').outerHeight(true);
182				var timerHeight        = $(document).find('.ays-pb-modal_' + id + ' .ays_pb_timer_' + id).outerHeight(true);
183				var customHtml         = $(document).find('.ays-pb-modal_' + id + ' .ays_content_box').outerHeight(true);
184
185				if(h2Height == undefined){
186					h2Height = 0;
187				}
188				if(hrHeight == undefined){
189					hrHeight = 0;
190				}
191				if(descriptionHeight == undefined){
192					descriptionHeight = 0;
193				}
194				if(timerHeight == undefined){
195					timerHeight = 0;
196				}
197				if(customHtml == undefined){
198					customHtml = 0;
199				}
200				var aysConteinerHeight = (h2Height + descriptionHeight + timerHeight + customHtml + hrHeight);
201				if(aysConteinerHeight < aysConteiner){
202					if(enableFullScreen){
203						aysConteinerHeight =  (aysConteiner - 75) + 'px';
204					}else{
205						aysConteinerHeight =  (aysConteiner - 55) + 'px';
206					}
207				}
208				switch(closeButtonPosition) {
209					case 'left-top':
210						closeButtonPositionValue = {top: '10px', left: '10px'};
211						break;
212					case 'left-bottom':
213						closeButtonPositionValue = {top: aysConteinerHeight, left: '10px'};
214						break;
215					case 'right-bottom':
216						closeButtonPositionValue = {top: aysConteinerHeight, right: '10px'};		
217						break;
218					default:
219						closeButtonPositionValue = {top: '10px', right: '4%'};
220						break;
221				}
222			} else if (template == 'lil') {
223				var closeButtonTop;
224				if(enableFullScreen){
225					closeButtonTop = heightForPosition - 43 + (2 * borderSize);
226				}else{
227					closeButtonTop = heightForPosition - 43 - (2 * borderSize);
228				}
229				switch(closeButtonPosition) {
230					case 'left-top':
231						closeButtonPositionValue = { top: '10px', left: '10px' };
232						break;
233					case 'left-bottom':
234						closeButtonPositionValue = { top: closeButtonTop + 'px', left: '10px' };
235						break;
236					case 'right-bottom':
237						 closeButtonPositionValue = { top: closeButtonTop + 'px', right: '40px', bottom: 'auto', left: 'auto' };
238						break;
239					default:
240						closeButtonPositionValue = { top: '10px', right: '40px' };
241						break;
242				}
243			} else if (template == 'template') {
244				var closeBttnImageExist = closeButtonImage != '';
245				switch(closeButtonPosition) {
246					case 'left-top':
247						var sidePostion = closeBttnImageExist ? 30 + 'px' : 20 + 'px';
248						closeButtonPositionValue = { top: '14px', left: sidePostion };
249						break;
250					case 'left-bottom':
251						var sidePostion = closeBttnImageExist ? 30 + 'px' : 16 + 'px';
252						closeButtonPositionValue = { bottom: '25px', left: sidePostion };
253						break;
254					case 'right-bottom':
255						var sidePostion = closeBttnImageExist ? 30 + 'px' : 16 + 'px';
256						closeButtonPositionValue = { bottom: '25px', right: sidePostion };
257						break;
258					default:
259						var sidePostion = closeBttnImageExist ? 30 + 'px' : 20 + 'px';
260						closeButtonPositionValue = { top: '14px', right: sidePostion };
261						break;
262				}
263			} else if (template == 'image' || template == 'minimal' || template == 'video') {
264				switch(closeButtonPosition) {
265					case 'left-top':
266						if (enableFullScreen) {
267							closeButtonPositionValue = { right: '97%' };
268						} else {
269							closeButtonPositionValue = {
270								top: (-25 - borderSize) + 'px',
271								left: (-borderSize) + 'px'
272							};
273						}
274						break;
275					case 'left-bottom':
276						if (enableFullScreen) {
277							closeButtonPositionValue = { top: '97%', right: '95%' };
278						} else {
279							var close_btn_pos = -15 - borderSize;
280							closeButtonPositionValue = {
281								bottom: close_btn_pos + 'px',
282								left: (-borderSize) + 'px'
283							};
284						}
285						break;
286					case 'right-bottom':
287						if (enableFullScreen) {
288							closeButtonPositionValue = { top: '97%', left: '95%' };
289						} else {
290							var close_btn_pos = -15 - borderSize;
291							closeButtonPositionValue = {
292								bottom: close_btn_pos + 'px',
293								right: (-borderSize) + 26 + 'px'
294							};
295						}
296						break;
297					default:
298						if (template == 'image' || template == 'minimal') {
299							var top = (enableFullScreen) ? (6 - borderSize) + 'px' : (-29 - borderSize) + 'px';
300							closeButtonPositionValue = {
301								top: top,
302								right: (-borderSize) + 26 + 'px'
303							};
304						}
305						if (template == 'video') {
306							if (enableFullScreen) {
307								closeButtonPositionValue = { right: '15px' };
308							} else {
309								closeButtonPositionValue = { 
310									top: (-25 - borderSize) + 'px',
311									right: (-borderSize) + 15 + 'px'
312								};
313							}
314						}
315						break;
316				}
317			} else if (template == 'notification') {
318				switch(closeButtonPosition) {
319					case 'left-top':
320						closeButtonPositionValue = {top: '0', left: '0'};
321						break;
322					case 'left-bottom':
323						closeButtonPositionValue = {bottom: '0', left: '0'};
324						break;
325					case 'right-bottom':
326						closeButtonPositionValue = {bottom: '0', right: '0'};		
327						break;
328					default:
329						closeButtonPositionValue = {top: '0', right: '0'};
330						break;
331				}
332			}
333			closeButtonPositionValue.position = 'absolute';
334			$(document).find('.ays-pb-modal_' + id + ' .ays-pb-modal-close_' + id).css(closeButtonPositionValue);
335
336		}
337
338		function setCloseButtonText(closeButtonText, closeButtonImage, id, template) {
339			var currentCloseBttnContainer = $(document).find('div.ays-pb-modal-close_' + id );
340			var defaultCloseIcon = '<svg class="ays_pb_material_close_icon" xmlns="https://www.w3.org/2000/svg" height="36px" viewBox="0 0 24 24" width="36px" fill="#000000" alt="Pop-up Close"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>';
341			var text = '';
342			var closeBttnContainerClass = '';
343
344			switch(template) {
345				case 'default':
346				case 'image_type_img_theme':
347				case 'facebook':
348				case 'notification':
349					if(closeButtonImage != ""){
350						text = "<img class='close_btn_img' src='" + closeButtonImage + "' width='30' height='30'>";
351					}else{
352						if(closeButtonText === '✕'){
353							text = defaultCloseIcon;
354						}else{
355							text = closeButtonText;
356						}
357					}
358					currentCloseBttnContainer.html(text);
359					break;
360				case 'win98':
361					text = closeButtonText;
362					currentCloseBttnContainer.find('span').html(text);
363					break;
364				case 'lil':
365					if(closeButtonImage != ""){
366						text = "<img class='close_btn_img' src='" + closeButtonImage + "' width='50' height='50'>";
367					}else{
368						text = closeButtonText;
369						if(closeButtonText != '✕'){
370							closeBttnContainerClass = 'close-lil-btn-text';
371						}
372					}
373					currentCloseBttnContainer.find('a').addClass(closeBttnContainerClass);
374					currentCloseBttnContainer.find('a').html(text);
375					break;
376				case 'image':
377				case 'template':
378				case 'minimal':
379				case 'video':
380					if(closeButtonImage != ""){
381						text = "<img class='close_btn_img' src='" + closeButtonImage + "' width='30' height='30'>";
382					}else{
383						text = closeButtonText;
384					}
385					currentCloseBttnContainer.find('div').html(text);
386					break
387			}
388		}
389
390		function updatePopupConversions(id) {
391			$.ajax({
392				url: pbLocalizeObj.ajax,
393				method: 'POST',
394				dataType: 'text',
395				data: {
396					id: id,
397					action: 'ays_increment_pb_conversions',
398				},
399			});
400		}
401	})
402
403})( jQuery );
404
405window.onload = function(){
406	var classList = document.body.classList;
407	document.ontouchmove = function(e){
408    	for( var i = 0; i < classList.length; i++ ){
409    		if( classList[i].startsWith('pb_disable_scroll_') ){
410    			if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
411                    e.preventDefault(); 
412    			}
413    			break;
414    		}
415    	}
416	}
417
418	// Handle scrollbar visibility on window resize and initial load
419	function updateScrollbarVisibility() {
420		var popups = document.querySelectorAll('.ays-pb-modal, .ays_cmd_window, .ays-pb-modal-macos, .ays_ubuntu_window, .ays_winxp_window, .ays_lil_window, .ays_image_window .ays_image_main, .ays_minimal_window .ays_minimal_main, .ays_template_window, .ays_win98_window');
421		var isMobile = window.innerWidth < 768;
422		
423		popups.forEach(function(popup) {
424			if (isMobile) {
425				if (popup.classList.contains('ays-pb-show-scrollbar-mobile')) {
426					popup.classList.add('ays-pb-show-scrollbar');
427				} else {
428					popup.classList.remove('ays-pb-show-scrollbar');
429				}
430			} else {
431				if (popup.classList.contains('ays-pb-show-scrollbar-desktop')) {
432					popup.classList.add('ays-pb-show-scrollbar');
433				} else {
434					popup.classList.remove('ays-pb-show-scrollbar');
435				}
436			}
437		});
438	}
439
440	// Update on page load
441	updateScrollbarVisibility();
442
443	// Update on window resize with debounce
444	var resizeTimer;
445	window.addEventListener('resize', function() {
446		clearTimeout(resizeTimer);
447		resizeTimer = setTimeout(updateScrollbarVisibility, 250);
448	});
449}

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.