PageSourceSearch

https://www.poste.it/assets-da/core/js/utilita.js

js poste.it collected 2026-09-24 08:26:38 UTC 37,861 bytes, 1,035 lines download raw bytes

1/*****************************************************/
2/*                                                   */
3/*  Utilita.js - (c) Poste Italiane 2022             */
4/*                                                   */
5/*****************************************************/
6
7/*  Set Browser-sniffing on/off */
8var browserCheck = true;
9/*  Set domain-sniffing on/off */
10var domainCheck = true;
11/*  Set Mediaquery-sniffing on/off */
12var mqCheck = true;
13/*  Set Debug on/off */
14var debugging = true;
15
16/* variabile usata dai timeout*/
17var timeoutObj;
18
19/* Doc. Debug var on/off - USAGE:
20 *       writeLog("----");
21 *       writeWarning("ops");
22 *       writeError("ops");
23 *       writeInfo("ops");
24 */
25
26/* Doc. Mediaquery-sniffing var on/off - USAGE:
27 *    class = 'pi-xs'
28 *            'pi-sm'
29 *            'pi-md'
30 *            'pi-lg'
31 */
32
33/* Doc. Browser-sniffing class on html var on/off
34 *    class = 'pi-mobile'
35 *            'pi-mobile pi-android'
36 *            'pi-mobile pi-ios'
37 *            'pi-firefox'
38 *            'pi-ie pi-ie-edge'
39 *            'pi-ie pi-ie10'
40 *            'pi-ie pi-ie9'
41 *            'pi-ie pi-ie8'
42 *            'pi-ie pi-ie7'
43 *            'pi-ie pi-ie6'
44 *            'pi-chrome'
45 *            'pi-opera'
46 *            'pi-safari'
47 */
48
49
50/*****************/
51/*    set log    */
52/*****************/
53function writeLog(arg) {
54    if ((typeof console != "undefined") && debugging) {
55        console.log(arg);
56    }
57}
58
59function writeError(arg) {
60    if ((typeof console != "undefined") && debugging) {
61        console.error(arg);
62    }
63}
64
65function writeInfo(arg) {
66    if ((typeof console != "undefined") && debugging) {
67        console.info(arg);
68    }
69}
70
71function writeWarning(arg) {
72    if ((typeof console != "undefined") && debugging) {
73        console.warn(arg);
74    }
75}
76
77
78/****************************/
79/* Basic function hide/show */
80/****************************/
81function show(target) {
82    $(target).addClass('show');
83}
84
85function hide(target) {
86    $(target).addClass('hide');
87}
88
89
90/*********************/
91/* Media Query check */
92/*********************/
93var mq_WindowWidth = $(window).width();
94var mq_Detect = 'nomQDetect';
95
96
97if (mqCheck) {
98    mqCheckDetection();
99}
100
101$(window).resize(function () {
102    if (mqCheck) {
103        mqCheckDetection();
104    }
105});
106
107function mqCheckDetection(mq_WindowWidth) {
108    if ((mq_WindowWidth == null) || (mq_WindowWidth == '') || (mq_WindowWidth == 'undefined')) {
109        mq_WindowWidth = $(window).width();
110    }
111    if (mq_WindowWidth < 768) {
112        if (!($('html').hasClass('pi-xs'))) {
113            $('html').removeClass('pi-sm pi-md pi-lg');
114            $('html').addClass('pi-xs');
115            writeInfo('MediaQuery Check : ' + 'xs');
116            mq_Detect = 'xs';
117            return mq_Detect;
118        }
119    } else if ((mq_WindowWidth > 767) && (mq_WindowWidth < 992)) {
120        if (!($('html').hasClass('pi-sm'))) {
121            $('html').removeClass('pi-xs pi-md pi-lg');
122            $('html').addClass('pi-sm');
123            writeInfo('MediaQuery Check : ' + 'sm');
124            mq_Detect = 'sm';
125            return mq_Detect;
126        }
127    } else if ((mq_WindowWidth > 991) && (mq_WindowWidth < 1200)) {
128        if (!($('html').hasClass('pi-md'))) {
129            $('html').removeClass('pi-xs pi-sm pi-lg');
130            $('html').addClass('pi-md');
131            writeInfo('MediaQuery Check : ' + 'md');
132            mq_Detect = 'md';
133            return mq_Detect;
134        }
135    } else if ((mq_WindowWidth > 1199)) {
136        if (!($('html').hasClass('pi-lg'))) {
137            $('html').removeClass('pi-xs pi-sm pi-md');
138            $('html').addClass('pi-lg');
139            writeInfo('MediaQuery Check : ' + 'lg');
140            mq_Detect = 'lg';
141            return mq_Detect;
142        }
143    }
144}
145
146/**************************/
147/* Sniffing pixel density */
148/**************************/
149function isHighDensity() {
150    return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 124dpi), only screen and (min-resolution: 1.3dppx), only screen and (min-resolution: 48.8dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3)').matches)) || (window.devicePixelRatio && window.devicePixelRatio > 1.3));
151}
152
153function isRetina() {
154    return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min--moz-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)').matches)) || (window.devicePixelRatio && window.devicePixelRatio >= 2)) && /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
155}
156
157
158/*****************************************/
159/* Modal ricalcolo posizione (al centro) */
160/*****************************************/
161$(function () {
162    function reposition() {
163        var modal = $(this),
164            dialog = modal.find('.modal-dialog');
165        modal.css('display', 'block');
166
167        // Dividere per due centra la modale, ma  dividere per 3 o 4 funziona meglio per gli schermi grandi
168        dialog.css("margin-top", Math.max(0, ($(window).height() - dialog.height()) / 2));
169    }
170    // Riposiziona quando la modale si mostra
171    $('.modal').on('show.bs.modal', reposition);
172    // Risposiziona al resize della finestra
173    $(window).on('resize', function () {
174        $('.modal:visible').each(reposition);
175    });
176});
177
178
179/********************/
180/* Sniffing browser */
181/********************/
182if (browserCheck) {
183    BrowserDetection();
184}
185
186function BrowserDetection() {
187    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
188        writeInfo('Mobile Browser detected');
189        //document.getElementsByTagName('html')[0].className += 'pi-mobile';
190        $('html').addClass('pi-mobile');
191        if (/Android/i.test(navigator.userAgent)) {
192            writeInfo('Android Browser detected');
193            //document.getElementsByTagName('html')[0].className += ' ' + 'pi-android';
194            $('html').addClass('pi-android');
195        } else if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
196            writeInfo('Ios Browser detected');
197            //document.getElementsByTagName('html')[0].className += ' ' + 'pi-ios';
198            $('html').addClass('pi-ios');
199        }
200    } else if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
201        var ffversion = new Number(RegExp.$1);
202        writeInfo('Firefox Browser detected');
203        //document.getElementsByTagName('html')[0].className += 'pi-firefox';
204        $('html').addClass('pi-firefox');
205
206    } else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
207        var ieversion = new Number(RegExp.$1);
208        if (ieversion == 10) {
209            // for IE10
210            //document.getElementsByTagName('html')[0].className += 'pi-ie pi-ie10';
211            $('html').addClass('pi-ie pi-ie10');
212            writeInfo('IE10 Browser detected');
213        } else if (ieversion == 9) {
214            // for IE9
215            //document.getElementsByTagName('html')[0].className += 'pi-ie pi-ie9';
216            $('html').addClass('pi-ie pi-ie9')
217            writeInfo('IE9 Browser detected');
218        } else if (ieversion == 8) {
219            // for IE8
220            //document.getElementsByTagName('html')[0].className += 'pi-ie pi-ie8';
221            $('html').addClass('pi-ie pi-ie8')
222            writeInfo('IE8 Browser detected');
223        } else if (ieversion == 7) {
224            // for IE7
225            //document.getElementsByTagName('html')[0].className += 'pi-ie pi-ie7';
226            $('html').addClass('pi-ie pi-ie7')
227            writeInfo('IE7 Browser detected');
228        } else if (ieversion == 6) {
229            // for IE6
230            //document.getElementsByTagName('html')[0].className += 'pi-ie pi-ie6';
231            $('html').addClass('pi-ie pi-ie6')
232            writeInfo('IE6 Browser detected');
233        }
234    } else if (/Trident.*rv[ :]?[1-9]{2}\./.test(navigator.userAgent)) {
235        var ieVersion = new Number(RegExp.$1);
236        //document.getElementsByTagName('html')[0].className += 'pi-ie pi-ie-edge';
237        $('html').addClass('pi-ie pi-edge');
238        writeInfo('IE > 10 Browser detected');
239    } else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
240        var chromeversion = new Number(RegExp.$1);
241        //document.getElementsByTagName('html')[0].className += 'pi-chrome';
242        $('html').addClass('pi-chrome');
243        writeInfo('Chrome Browser detected');
244    } else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
245        var oprversion = new Number(RegExp.$1);
246        //document.getElementsByTagName('html')[0].className += 'pi-opera';
247        $('html').addClass('pi-opera');
248        writeInfo('Opera Browser detected');
249    } else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
250        var safariversion = new Number(RegExp.$1);
251        //document.getElementsByTagName('html')[0].className += 'pi-safari';
252        $('html').addClass('pi-safari');
253        writeInfo('Safari Browser detected');
254    }
255}
256
257
258/*******************/
259/* Sniffing domain */
260/*******************/
261if (domainCheck) {
262    DomainDetection();
263}
264
265function DomainDetection() {
266    var myhostnamePi = window.location.hostname.split('.').reverse();
267    var myhostExtension = myhostnamePi[0]; /* estensione dominio (it/com) */
268    var myhostDomain = myhostnamePi[1]; /* primo livello */
269    var myhostSubDomain = myhostnamePi[2]; /* secondo livello */
270    var mytagHtml = document.getElementsByTagName('html')[0];
271
272
273    if (myhostDomain == "poste") {
274
275        var posteit_suffix = 'pi-domain';
276        mytagHtml.classList.add(posteit_suffix);
277
278        /* Business check */
279        if (myhostSubDomain == "business") {
280            writeLog('DomainDetection: ' + myhostSubDomain);
281            mytagHtml.classList.add(posteit_suffix + '-business');
282        }
283        /* Postepay check */
284        else if (myhostSubDomain == "postepay") {
285            writeLog('DomainDetection: ' + myhostSubDomain);
286            mytagHtml.classList.add(posteit_suffix + '-postepay');
287        }
288        /* Postevita check */
289        else if ((myhostSubDomain == "postevita") || (myhostSubDomain == "posteassicura")) {
290            writeLog('DomainDetection: ' + myhostSubDomain);
291            mytagHtml.classList.add(posteit_suffix + '-postevita');
292        }
293        /* Poste check */
294        else {
295            writeLog('DomainDetection: ' + myhostSubDomain);
296            mytagHtml.classList.add(posteit_suffix + '-posteit');
297        }
298    }
299    if (myhostDomain == "posteitaliane") {
300        /* Corporate check */
301        var posteitaliane_suffix = 'corporate-domain';
302        writeLog('DomainDetection: ' + myhostDomain);
303        mytagHtml.classList.add(posteitaliane_suffix, posteitaliane_suffix + '-posteitaliane');
304    }
305}
306
307/*******************************************************************************************/
308/* equalize element                                                                        */
309/* setta altezza di una map / array a quella maggiore, in ingresso prende il selettore css */
310/* N.B. a) utilizzare la classe .equalize-height per settare anche l'height dell'oggetto , .equalize-height-forced per forzare anche su XS */
311/* N.B. b) utilizzare la classe .equalize-forced per mantenere l'equalize anche su XS */
312/*******************************************************************************************/
313
314
315function doEqualize(sel = null) {
316
317    if ($(sel).length > 0) {
318        var heights = $(sel).map(function () {
319                return Math.ceil(this.getBoundingClientRect().height);
320            }).get(),
321
322            maxHeight = Math.max.apply(null, heights);
323
324        if ($(sel).attr('data-default-height') >= maxHeight) {
325            maxHeight = $(sel).attr('data-default-height') + "px";
326        }
327
328        $(sel).css("min-height", maxHeight);
329
330        if ($(sel).hasClass('equalize-height')) {
331            if(mq_Detect == 'xs'){
332                if($(sel).hasClass('equalize-height-forced')){
333                    $(sel).css("height", maxHeight);
334                }
335                else{
336                    $(sel).css("height", "auto");
337                }
338            }
339            else{
340                $(sel).css("height", maxHeight);
341            }
342        }
343        if ((mq_Detect == 'xs') && !($(sel).parents().hasClass('equalize-forced')) && !($(sel).parents().hasClass('content-overflow'))) {
344            $(sel).css("min-height", "auto");
345        }
346        return maxHeight;
347    }
348}
349
350function equalize(myvar) {
351    if ($(myvar).hasClass('equalize-height')) {
352        $(myvar).css("height", "auto");
353    }
354    $(myvar).css("min-height", "auto");
355    doEqualize(myvar);
356}
357
358/* ciclo equalize su elementi di una stessa riga ----- equalize(".equalize* .panel-cards") */
359function equalizeCycle(myclass, mycardclass, myfuncCallback) {
360    var mynumMaxGruppiElementiEqualize = $(myclass).length;
361    for (var i = 1; i <= mynumMaxGruppiElementiEqualize; i++) {
362        var tgtcycle = myclass + "-" + i + " " + mycardclass;
363        if ($(tgtcycle).length > 0) {
364            equalize(tgtcycle);
365        }
366    }
367    if (myfuncCallback != null){
368        myfuncCallback();
369    }
370}
371
372
373function mosaicPictureHeight(){
374    if ($('.equalize-mosaic-wrap .mosaic-picture-wrap').length > 0){
375        $('.equalize-mosaic-wrap .mosaic-picture-wrap').each(function() {
376            var myContentHeight = $(this).next('.mosaic-wrap').outerHeight();
377            var myFinalContentHeight = myContentHeight + 26 + 'px';
378            $(this).css('min-height', myFinalContentHeight);
379        });
380    }
381}
382
383
384function mypMixedCardHeight(){
385    if ($('.equalize-myp-mixedcard .myp-mixedcard').length > 0){
386        $('.equalize-myp-mixedcard .myp-mixedcard').each(function() {
387            if (mq_Detect == 'xs'){
388                $(this).removeClass('mode-ctaset').attr('data-class','mode-ctaset');
389            }
390            else{
391                if($(this).attr('data-class') != ''){
392                    $(this).addClass($(this).attr('data-class'));
393                    $(this).attr('data-class','')
394                }
395            }
396        });
397    }
398}
399
400
401/***************************/
402/* scrollToTop icon fading */
403/***************************/
404
405function iconScrollFading(myicon) {
406    var scrollTop = $(this).scrollTop();
407    $(myicon).css({
408        opacity: function () {
409            var elementHeight = $(this).parent().height(),
410                opacity = (((elementHeight / 1.8) - scrollTop) / elementHeight) * 1.8;
411            return opacity;
412        }
413    });
414}
415
416/***********/
417/* overlay */
418/***********/
419
420function overlayCreate(_options, elId = null) {
421
422    if (elId == '' || elId == undefined || elId == null) {
423        elId = 'overlay';
424    }
425
426    if (document.getElementById(elId) == null) {
427        var ovObj = document.createElement('div');
428
429        document.body.appendChild(ovObj).setAttribute('id', elId);
430        document.body.appendChild(ovObj).setAttribute('class', 'overlay');
431
432        if (_options != undefined) {
433            if (_options.ariaHidden) {
434                ovObj.setAttribute('aria-hidden', _options.ariaHidden);
435            } else {
436                //alert('aria-hidden');
437                ovObj.setAttribute('aria-hidden', 'true');
438            }
439        }else{
440            //ovObj.setAttribute('tabindex', '-1');
441            ovObj.setAttribute('aria-hidden', 'true');
442        }
443    }
444}
445
446function overlayOn(_options, elId = null) {
447    overlayCreate(_options);
448    if (elId == '' || elId == undefined || elId == null) {
449        elId = 'overlay';
450    }
451    var ol = document.getElementById(elId);
452    ol.style.display = 'block';
453    ol.removeAttribute('aria-hidden');
454    if (_options != undefined) {
455        if (_options.concealable) {
456            ol.classList.add('concealable');
457            overlayConcealable();
458        }
459        if (_options.bdNoOverflow) {
460            document.body.style.overflow = 'hidden';
461            document.getElementsByTagName('html')[0].style.overflow = 'hidden';
462
463        }
464    }
465}
466
467function overlayOff(elId = null) {
468    if (elId == '' || elId == undefined || elId == null) {
469        elId = 'overlay';
470    }
471    var ol = document.getElementById(elId);
472    ol.style.display = 'none';
473    ol.setAttribute('aria-hidden','true');
474    document.body.style.overflow = 'inherit';
475    document.getElementsByTagName('html')[0].style.overflow = 'inherit';
476    //ol.remove();
477}
478
479function overlayConcealable() {
480    $('.concealable').on('click', function () {
481        overlayOff();
482        if ($('.side-offcanvas').has('.side-offcanvas-close')) {
483            offcanvasClose();
484        };
485        $(this).removeClass('concealable');
486    });
487}
488
489
490/*************************/
491/* Menu di navigazione   */
492/*************************/
493
494var menuEltoKeepInfocus = '.close-side-offcanvas, .offcanvas-panel-sh
494ow button, .offcanvas-panel-show a, .offcanvas-panel-show input, .offcanvas-panel-show select, .offcanvas-panel-show textarea, .offcanvas-panel-show [tabindex]:not([tabindex="-1"]), .offcanvas-panel-show [role="button"]';
495
496function navSideMenu(menuObj) {
497    if ($(menuObj).length > 0) {
498        menuPanelOpn(menuObj);
499        menuBack(menuObj);
500    }
501}
502
503/* Apre i pannellli del menu relativi all'oggetto menu passato */
504var menuObjId
505function menuPanelOpn(menuObj) {
506   
507    $(menuObj + ' .menu-section li button').on('click', function () {
508        menuObjId = '#' + $(this).parents(menuObj).attr('id');
509        var pnlToshow = '#' + $(this).attr('data-menu-ctrl');
510        $(menuObjId + ' .offcanvas-panel').removeClass('offcanvas-panel-show').addClass('offcanvas-panel-hide').attr('aria-hidden', 'true');
511        $(menuObjId + ' ' + pnlToshow).removeClass('offcanvas-panel-hide').addClass('offcanvas-panel-show').removeAttr('aria-hidden');
512        
513        $(menuObjId + ' button.back-side-panel').toggleClass('hide').attr('aria-hidden', function(index, attr){
514            return attr == 'false' ? 'true' : 'false';
515        });
516
517        keepFocusIn(menuObjId, menuEltoKeepInfocus);
518
519    });
520}
521
522/* gestisce il back button all'interno dei menu */
523function menuBack(menuObj) {
524
525    $('button.back-side-panel').on('click', function () {
526
527        menuObjId = '#' + $(this).parents(menuObj).attr('id');
528        var backPnlLv = $(this).attr('data-menu-back');
529
530        $(menuObjId + ' .offcanvas-panel').removeClass('offcanvas-panel-show').addClass('offcanvas-panel-hide').attr('aria-hidden', 'true');
531        
532        $('.offcanvas-panel[data-menu-lv="' + $('#'+backPnlLv).attr('data-menu-lv') + '"]').removeClass('offcanvas-panel-hide').addClass('offcanvas-panel-show').removeAttr('aria-hidden');
533        
534        $(this).toggleClass('hide').attr('aria-hidden', function(index, attr){
535            return attr == 'false' ? 'true' : 'false';
536        });
537
538        keepFocusIn(menuObjId, menuEltoKeepInfocus);
539        
540    });
541}
542
543/* ripristina la situazione esistente sul menu all'arrivo in pagina */
544function menuReset(menuObj, initialPnl) {
545    $('#' + $(menuObj).attr('id') + ' .offcanvas-panel').addClass('offcanvas-panel-hide').removeClass('offcanvas-panel-show');
546    //$('#' + $(menuObj).attr('id') + ' .menu-content').scrollTop=0;
547    if(document.querySelector('.side-offcanvas-content.menu-content')!=null){
548        document.querySelector('.side-offcanvas-content.menu-content').scrollTop=0; 
549    }
550    if(initialPnl.substring(1) == $('#' + $(menuObj).attr('id') + ' .offcanvas-panel[data-menu-lv="0"]').attr('id')){
551        $('#' + $(menuObj).attr('id') + ' button.back-side-panel:not(.hide)').addClass('hide').attr('aria-hidden','true');
552    }else{
553        $('#' + $(menuObj).attr('id') + ' button.back-side-panel.hide').removeClass('hide').removeAttr('aria-hidden');
554    }
555    
556    $('#' + $(menuObj).attr('id') + ' ' + initialPnl).removeAttr('aria-hidden').removeClass('offcanvas-panel-hide').addClass('offcanvas-panel-show');
557}
558
559
560/********************/
561/* Gestione offcanvas */
562/********************/
563
564function offcanvasToggle(_toggleElm, _overlayOp) {
565
566    $(_toggleElm).on('click', function (e) {
567        
568        var elemClicked = $(this);
569        var mySidebar = $('#'+elemClicked.attr('aria-controls'));
570
571        e.preventDefault();
572
573        if (mySidebar.hasClass('side-offcanvas-close')){
574            overlayOn({concealable: true, bdNoOverflow: true});
575
576        }else{
577            overlayOff();
578            menuReset(mySidebar, '#' + mySidebar.find('.close-side-offcanvas')[0].getAttribute('data-menu-pnl'));
579        }
580
581        elemClicked.attr('aria-expanded', function (index, attr) {
582
583            mySidebar.toggleClass('side-offcanvas-close');
584            
585            mySidebar.attr('aria-hidden', function (index, attr) {
586                return attr == 'true' ? 'false' : 'true';
587            });
588
589            return attr == 'true' ? 'false' : 'true';
590
591        });
592
593        clearTimeout(timeoutObj);
594        timeoutObj = setTimeout(function() {
595            if(mySidebar.hasClass('side-offcanvas-close')){
596                $(elemClicked).focus();
597            }else{
598                keepFocusIn('#'+mySidebar.attr('id'), '.close-side-offcanvas, .offcanvas-panel-sh
598ow button, .offcanvas-panel-show a, .offcanvas-panel-show input, .offcanvas-panel-show select, .offcanvas-panel-show textarea, .offcanvas-panel-show [tabindex]:not([tabindex="-1"]), .offcanvas-panel-show [role="button"]');
599            }
600        }, 150);
601    });
602};
603
604
605function offcanvasClose(_closeElm) {
606
607    if (_closeElm == undefined) {
608        $('.side-offcanvas:not(.side-offcanvas-close) .close-side-offcanvas').trigger('click');
609    }
610
611    $(_closeElm).on('click', function (e) {
612       
613        e.preventDefault();
614        var offCanvasBtn = $('button.offcanvas-toggle[aria-controls=' + $(this).attr('aria-controls') + '][aria-expanded=true]');
615        
616        offCanvasBtn.trigger('click');
617        
618        if ($(this).parents('.side-offcanvas.menu-navigazione').length > 0) {
619            menuReset($(this).parents('.side-offcanvas'), '#'+$(this).attr('data-menu-pnl'));
620        }
621        
622        document.activeElement.blur();
623        
624        return;
625
626    });
627
628    return;
629
630};
631
632
633/******************/
634/* gestione focus */
635/******************/
636
637//funzione per mantenere il focus all'interno di un contenitore
638function keepFocusIn(myElFocused, focusableElements, selFirstElFocusable) {
639
640    // array degli elementi che saranno focusable all'interno di un contenitore
641    if(focusableElements == '' || focusableElements == null){
642        focusableElements = 'button, a, input, select, textarea, [tabindex]:not([tabindex="-1"]), [role="button"]';
643    }
644    
645    var inFocusContainer = document.querySelector(myElFocused); // seleziono il contenitore
646
647    if(selFirstElFocusable == '' || selFirstElFocusable == null){
648        selFirstElFocusable = inFocusContainer.querySelectorAll(focusableElements)[0];
649    }
650
651    var firstFocusableElement = selFirstElFocusable; // il primo elemento da mettere in focus nel contenitore
652    var focusableContent = inFocusContainer.querySelectorAll(focusableElements);
653    var lastFocusableElement = focusableContent[focusableContent.length - 1]; // l'ultimo elemento in focus nel contenitore
654
655    firstFocusableElement.focus();
656
657    document.addEventListener('keydown', function (e) {
658        var isTabPressed = e.key === 'Tab' || e.keyCode === 9;
659
660        if (!isTabPressed) {
661            var isEscPressed = e.key === 'Esc' ||  e.key === 'Escape' || e.keyCode === 27;
662
663            if(isEscPressed){
664                offcanvasClose();
665                document.onkeydown = null;
666            }
667            document.onkeydown = null;
668            return;
669        }
670
671        if (e.shiftKey) { // verifica se shift e' premuto nella combinazione shift + tab
672            if (document.activeElement === firstFocusableElement) {
673                e.preventDefault();
674                lastFocusableElement.focus(); // setta il focus sull'ultimo elemento focusable
675            }
676        } else { // verifica se tab e' premuto
677            if (document.activeElement === lastFocusableElement) {
678                // se il focus ha raggiunto l'ultimo elemento, lo sposto sul primo dopo la pressione del tab
679                e.preventDefault();
680                firstFocusableElement.focus(); // setta il focus sul primo elemento focusable
681            }
682        }
683    });
684
685
686}
687
688
689function focusFormMouse() {
690    var t = 'input[type="text"],input[type="password"],input[type="email"],input[type="url"],input[type="tel"],input[type="number"],input[type="search"],textarea';
691    var e;
692
693    $(document).on("keydown mousedown", function (t) {
694        e = "mousedown" === t.type
695    }).on("focusin", function (t) {
696        e && t.target && $(t.target).addClass("focus-mouse");
697    }).on("focusout", function (t) {
698        t.target && $(t.target).removeClass("focus-mouse")
699    })
700}
701
702
703function focusLabelTransition() {
704    var t = 'input[type="text"],input[type="password"],input[type="email"],input[type="url"],input[type="tel"],input[type="number"],input[type="search"],textarea';
705
706    $("body").find(t).each(function (e, t) {
707        var t = $(t),
708            n = !!t.val(),
709            i = !!t.attr("placeholder");
710        (n || i) && $("label[for='" + t.attr("id") + "']").css("transition", "none").addClass("active"), n || i || $("label[for='" + t.attr("id") + "']").removeClass("active")
711    });
712
713    var n = 'input[type="file"]';
714    var i = ($(document).on("focus", t, function (e) {
715        e = "label[for='" + $(e.target).attr("id") + "']";
716        $(e).addClass("active");
717    }).on("blur", t, function (e) {
718        var e = $(e.target),
719            t = !e.val(),
720            n = !e.attr("placeholder");
721        t && n && $("label[for='" + e.attr("id") + "']").removeClass("active")
722    }).on("change", t, function (e) { // da verificare
723        e = $(e.target);
724        i(e)
725    }), function (e) {
726        var t = $("label[for='" + e.attr("id") + "']"),
727            n = e.val().length,
728            e = !!e.attr("placeholder");
729        n || e ? t.addClass("active") : t.removeClass("active")
730    });
731
732}
733
734function labelrePosition(){
735    $('.form-group.form-group-abs .input-group').each(function() {
736            if ($(this).find('.input-group-addon:first-child:has(+ .form-control)').outerWidth() !== undefined){
737                mylabelRepos = $(this).find('.input-group-addon:first-child:has(+ .form-control)').outerWidth();
738                $(this).parent().find('.control-label').css('left',mylabelRepos + 12 +'px');
739            };
740    });
741}
742
743function focusInputGroup(){
744    $('.form-group .input-group .form-control').on('focus', function(){
745        $(this).parents('.input-group').find('.input-group-addon:not(>.form-control)').addClass('focus-siblings');
746        $(this).parents('.input-group').find('.input-group-addon:has(>.form-control) > .form-control').addClass('focus-siblings');
747        $(this).parents('.input-group:not(.input-group-otp)').find('> .form-control').addClass('focus-siblings');
748    });
749    $('.form-group .input-group:has(>.form-control) .form-control').on('focusout', function(){
750        $(this).parents('.input-group').find('.input-group-addon:not(>.form-control)').removeClass('focus-siblings');
751        $(this).parents('.input-group').find('.input-group-addon:has(>.form-control) .form-control').removeClass('focus-siblings');
752        $(this).parents('.input-group:not(.input-group-otp)').find('> .form-control').removeClass('focus-siblings');
753    });
754}
755
756function checkFileNameUpload(){
757    $('input[type="file"]').on('change',function(e){
758        var myval = (e.target.files[0].name);
759        $(this).parent('.input-upload').find('.form-control[type="text"]').attr('value',myval);
760    });
761}
762
763function focusInputUpload(){
764    $('.form-group .input-upload input[type="file"]').on('focus', function(){
765        $(this).parent('.input-upload').find('.input-group input').addClass('focus-siblings');
766        $(this).parent('.input-upload').find('.input-group-addon').addClass('focus-siblings');
767    });
768    $('.form-group .input-upload input[type="file"]').on('focusout', function(){
769        $(this).parent('.input-upload').find('.input-group input').removeClass('focus-siblings');
770        $(this).parent('.input-upload').find('.input-group-addon').removeClass('focus-siblings');
771    });
772}
773
774
775/*
776    Animazione Scroll-to accordin by url, accetta parametro in entrata che se passato viene sommato all'offset, di default NULL
777*/
778
779function animationScrollAccordion(offsetExtra = null) {
780    $('.main-pills .panel-group-accordion.panel-group-unique').not('.side-offcanvas-obj .main-pills .panel-group-accordion.panel-group-unique').on('shown.bs.collapse', function (e) {
781
782        var offset = $(this).find('.collapse.in').prev('.panel-heading');
783        if (offsetExtra == null) {
784            offsetExtra = 0;
785        }
786
787        if (offset) {
788            $('html,body').animate({
789                scrollTop: $(offset).offset().top - offsetExtra
790            }, 500);
791        }
792    });
793}
794
795/*
796    Animazione apertura e scroll-to accordin by url accordionOpenByUrl() e' richiamata al ready su start-script
797*/
798
799function accordionOpenByUrl() {
800    var myUrlHash = window.location.hash;
801    if (myUrlHash.length > 0 && myUrlHash.indexOf('#!') !== 0 && myUrlHash.indexOf('#/') !== 0){
802        if (location.hash) {
803            setTimeout(function () {
804                // accordion
805                if($('.panel-group-accordion').length > 0){
806                    if ($('#content-header-extra').css("height") !== undefined || $('#content-header-extra').css("height") !== null) {
807                        animationScrollAccordion(parseInt($('#content-header-extra').css('height')));
808                    } else {
809                        animationScrollAccordion();
810                    }
811                    if (!$('.panel-group-accordion ' + myUrlHash).hasClass('in')) {
812                        $('.panel-group-accordion .panel-heading a[href="' + myUrlHash + '"]').trigger('click');
813                    }
814                }
815                // tab
816                if($('[data-toggle="tab"]').length > 0){
817                    if($('a[href="' + myUrlHash + '"]').attr('data-toggle')=='tab'){
818                        $('a[href="' + myUrlHash + '"]').trigger('click');
819                    }
820                }
821            }, 1);
822        }
823
824    }
825}
826
827
828/**************************/
829/* Gestione Scroll ancore */
830/**************************/
831
832function anchorScrollingToFocus(myElement, extraOffset, focused) {
833    var myAnchor = $(myElement).attr('href');
834    if (myAnchor.match('#')) {
835        writeLog('anchor detected on messages link - scrolling');
836        var hash = myAnchor.substring(myAnchor.indexOf("#") + 1);
837        if ($('#' + hash).length > 0) {
838            startScrollandFocus($('#' + hash), extraOffset, focused);
839        }
840        return false;
841    } else {
842        writeLog('no anchor detected on messages link');
843    }
844}
845
846function startScrollandFocus(element, extraOffset, focused) {
847    var myoffset = element.offset().top;
848    var scrollto = myoffset - extraOffset;
849    $('html, body').animate({
850        scrollTop: scrollto
851    }, 1500, function () {
852        if (focused == true) {
853            $(element).focus();
854            writeLog('focus on input');
855        }
856    });
857}
858
859/*******************************/
860/*   List segmented control    */
861/*******************************/
862
863$('.radio-segmented-control-wrapper label.ctrl-btn').on('click', function () {
864    $(this).siblings().removeClass('active');
865    $(this).addClass('active');
866});
867
868/******************/
869/* gestione Btn toggle */ //verificare
870/******************/
871function buttonToggle() {
872    $('.btn-toggle').on('click', function () {
873
874        $(this).children('.btn').toggleClass('active');
875
876        if (!$(this).children('label').hasClass('disabled')) {
877
878            $(this).find('.btn').toggleClass('active');
879            //writeLog( $(this).find('.btn').attr('class') );
880
881
882            if ($(this).find('.btn-primary').size() > 0) {
883                $(this).find('.btn').toggleClass('btn-primary');
884            }
885            if ($(this).find('.btn-danger').size() > 0) {
886                $(this).find('.btn').toggleClass('btn-danger');
887            }
888            if ($(this).find('.btn-success').size() > 0) {
889                $(this).find('.btn').toggleClass('btn-success');
890            }
891            if ($(this).find('.btn-info').size() > 0) {
892                $(this).find('.btn').toggleClass('btn-info');
893            }
894
895            $(this).find('.btn').toggleClass('btn-default');
896
897
898        } else {
899            writeLog('disabled btn-toggle click event');
900        }
901
902    });
903}
904
905var c, currentScrollTop = 0
906
907function stickyHeader(myStickyHeader = null) {
908    if (($(myStickyHeader) != null) && ($(myStickyHeader).length > 0)) {
909
910        var a = $(window).scrollTop();
911        var b = $(myStickyHeader).outerHeight();
912        var offset = 500; //delta start per la barra extra
913        currentScrollTop = a;
914
915
916        // in presenza di barra extra
917        if ($('#content-header-extra').length > 0) {
918            if (currentScrollTop > b + offset) {
919                $(myStickyHeader).removeClass('scrollDown');
920                $(myStickyHeader).removeClass('sticky-mid');
921                $(myStickyHeader).find('a , btn').attr('tabindex','0');
922                $(myStickyHeader).attr('aria-hidden','false');
923            } else {
924                $(myStickyHeader).addClass('scrollDown');
925                $(myStickyHeader).addClass('sticky-mid');
926                $(myStickyHeader).find('a , btn').attr('tabindex','-1');
927                $(myStickyHeader).attr('aria-hidden','true');
928            }
929            $(myStickyHeader).removeClass('hide');
930        }
931        // header default in fixed
932        else {
933            $('body').css('padding-top', b);
934            if (c < currentScrollTop && a > b + b) {
935                $(myStickyHeader).addClass('scrollDown');
936                $(myStickyHeader).addClass('sticky-mid');
937            } else if (c > currentScrollTop && !(a <= b)) {
938                $(myStickyHeader).removeClass('scrollDown');
939            } else if (c > currentScrollTop && a < b + b) {
940                $(myStickyHeader).removeClass('sticky-mid');
941            }
942            c = currentScrollTop;
943        }
944    }
945}
946
947function scrollTabsCentered(myobj = null) {
948    var pos = myobj.position().left; //get left position of li
949    var myobjParent = myobj.parent('ul');
950    var currentscroll = myobjParent.scrollLeft();
951    var containerwidth = myobjParent.width();
952    var middleItem = Math.floor(myobj.outerWidth(true) / 2);
953    var diff = pos - containerwidth / 2;
954
955    pos = (currentscroll + diff + middleItem);
956
957    myobjParent.animate({
958        scrollLeft: pos
959    });
960}
961
962function collapseObjectOnMobile(mycollapseobj = null) {
963    if ($(mycollapseobj).length > 0 && (mq_Detect == "md") || (mq_Detect == "lg")) {
964        $(mycollapseobj).css('height', 'auto');
965        $(mycollapseobj).removeAttr('aria-expanded');
966        $(mycollapseobj).addClass('block-md block-lg');
967    }
968}
969
970function rangeBar() {
971    const allRanges = document.querySelectorAll(".form-range");
972    if (allRanges.length > 0) {
973        allRanges.forEach(wrap => {
974            const range = wrap.querySelector('.form-range input[type=range]');
975            const rangeBubble = wrap.querySelector('.form-range-rangeBubble');
976            const track = wrap.querySelector('.form-range-track');
977
978            range.addEventListener("input", () => {
979                setRangeBubble(range, rangeBubble, track);
980            });
981
982            setRangeBubble(range, rangeBubble, track);
983
984        });
985
986        function setRangeBubble(range, rangeBubble, track) {
987            const val = range.value;
988            const min = range.min ? range.min : 0;
989            const max = range.max ? range.max : 100;
990            const newVal = Number(((val - min) * 100) / (max - min));
991            rangeBubble.innerHTML = val;
992
993            // calcoli basati empiricamente sulle dimensioni della thumb
994            rangeBubble.style.left = 'calc(' + newVal + '% ' + ' + ' + (8 - (newVal * 0.25)) + 'px)';
995            setRangeTrack(track, range, newVal);
996        }
997
998        function setRangeTrack(track = null, range, newVal) {
999            if (track != null) {
1000                track.style.width = 'calc(' + range.value + '% ' + ' + ' + (-(range.value / 100)) + 'rem)';
1001            }
1002        }
1003    }
1004}
1005
1006function triggerHelpLink(){
1007    $('<button id="skipBtnHelp">Apri la barra di assistenza</button>').insertAfter($('a.skip-link[href="#assistenza-side"]'));
1008    $('<button id="skipMenu">Apri il menu</button>').insertAfter($('a.skip-link[href="#menu-navigazione"]'));
1009    $('a.skip-link[href="#assistenza-side"]').each(function() {
1010        $.each(this.attributes,function(i,a){
1011            if(a.name!='href'){
1012                $('button#skipBtnHelp').attr(a.name,a.value);
1013            }
1014        })
1015    });
1016    $('a.skip-link[href="#menu-navigazione"]').each(function() {
1017        $.each(this.attributes,function(i,a){
1018            if(a.name!='href'){
1019                $('button#skipMenu').attr(a.name,a.value);
1020            }
1021        })
1022    });
1023    $('a.skip-link[href="#assistenza-side"]').remove();
1024    $('a.skip-link[href="#menu-navigazione"]').remove();
1025    $('button#skipBtnHelp').on('click',function(e){
1026        e.preventDefault();
1027        $('button.offcanvas-toggle[aria-controls="assistenza-side"]').trigger('click');
1028    });
1029    $('button#skipMenu').on('click',function(e){
1030        e.preventDefault();
1031        $('button.offcanvas-toggle[aria-controls="menu-navigazione"]').trigger('click');
1032    });
1033}
1034
1035

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.