var INPUTCOLOR = "0px solid #FFF"; //colore del bordo dell'input di default var INPUTERROR = "1px solid #FF9900"; var timeOutId; //Timeout di alertWin var URLSITO = 'https://www.travelandfair.net/'; var SCMD = 'dammuso_affitto'; var LANG = 'en'; var DEBUG = true; /* DEBUG ********************************/ function ja(o){ alert(JSON.stringify(o)); console.log(JSON.stringify(o)); } function sja(o){ var str = ''; for(var i in o){ if(str!='') str +=','; str += i +":" + typeof o[i]; } alert(str); } /* ALERT ********************************/ function alertSwal(ty,ti,mex,fn){ //type = warning, error, success, info, question if(fn==undefined) fn=function(){}; swal({ title: ti, text: mex, type: ty, timer: 6000}, function(confirm){ setTimeout(fn,200); }); }; function confirmSwal(mex,fn,fn2){ swal({ title: "Avviso", html: mex, type: 'warning', showCancelButton: true, confirmButtonText: 'Ok', cancelButtonText: 'Annulla' }, function(confirm){ if(confirm){ setTimeout(fn,200); }else{ setTimeout(fn2,200); } }); } function viewLoader(mex){ var ldr = document.getElementById('nonsolospinner'); var ldrdiv = document.getElementById('nonsolospinnerdiv'); getChildTag(ldr,'DIV')[0].innerHTML = mex; //ldr.firstChild.innerHTML = mex; ldr.style.display = "block"; ldrdiv.style.display = "block"; } function hideLoader(cont,dbg){ if(dbg){ if(typeof(cont)!='string') cont = JSON.stringify(cont); var ldr = document.getElementById('nonsolospinner'); ldr.firstChild.innerHTML = cont; }else{ var ldr = document.getElementById('nonsolospinner'); var ldrdiv = document.getElementById('nonsolospinnerdiv'); ldr.style.display = "none"; ldrdiv.style.display = "none"; ldr.firstChild.innerHTML = ''; } } // Eventi function addEvent(obj, evType, fn){ if(obj.addEventListener){ obj.addEventListener(evType, fn, true); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } function once(e,fn) { target = (e.currentTarget) ? e.currentTarget : e.srcElement; if(target.removeEventListener){ target.removeEventListener(e.type, fn); }else{ target.detachEvent('on'+e.type, fn); } target['on'+e.type]=null;//inline event var args = Array.prototype.slice.call(arguments); var dump = args.shift(); dump = args.shift(); fn.apply(this, args); try { var new_e = new e.constructor(e.type, e); target.dispatchEvent(new_e); }catch(err) {} } // !eventi function isMobile() { try{ document.createEvent("TouchEvent"); return true; } catch(e){ return false; } } // Form------------------- function normalizeCampo(obj){ obj.style.border = INPUTCOLOR; } function ctrlKey(e,o){ if(e.keyCode==13) document.getElementById(o).click(); } function toUri(obj){ var strUri=''; if(obj.name!="" && obj.name!=undefined){ switch(obj.type){ case 'checkbox': case 'radio': if((obj.type === 'radio' || obj.type === 'checkbox') && obj.checked) { var val=(obj.value!=='')? obj.value : '1'; strUri += '&'+obj.name+'='+encodeURIComponent(val); }else{ strUri += '&'+obj.name+'='; } break; default: strUri += '&'+obj.name+'='+encodeURIComponent(obj.value); break; } } return strUri; } function buildUri(obj){ var strUri =''; for(var n=0; n0) fields['dataId'] = []; for(var n=0; n stringify of objects //mode=mix => key= stringify for array and key=value for the rest //mode=php => key[]=val1&...key[]=valn for array and key=value for the rest if(mode==undefined) mode = 'php'; var strUri = ''; var objUri = {}; var mixUri = ''; for(var i in this.nodes){ var v = this.getValue(i); objUri[i.replace('[]','')]=v; if(v.constructor === Array){ v.forEach(function(e){ strUri += '&'+i+'='+encodeURIComponent(e); }); mixUri += '&'+encodeURIComponent(i.replace('[]',''))+'='+encodeURIComponent(JSON.stringify(v)); }else{ strUri += '&'+encodeURIComponent(i)+'='+encodeURIComponent(v); mixUri += '&'+encodeURIComponent(i)+'='+encodeURIComponent(v); } } switch(mode){ case 'json': return JSON.stringify(objUri); break; case 'mix': return mixUri; break; case 'php': return strUri; break; } } return form; } function controlForm(frm,nome,fld1,fld2,tipo){ if(tipo==undefined) tipo = ''; switch(tipo){ case "":// controlla se il campo e vuoto false (quindi ="" o =0...tanti zeri) if(frm.getValue(fld1) == false){ alertSwal('warning',nome, 'missing field',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; } return true; break; case "_":// controlla se il campo = vuoto con "" if(frm.getValue(fld1) == ""){ alertSwal('warning',nome, 'missing field',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; } return true; break; case "@": // controlla la validita del campo mail if(!indirizzoEmailValido(frm.getValue(fld1))){ alertSwal('warning',nome, 'invalid field',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; } return true; break; case "hS":// controlla se il campo autoSuggest = vuoto if(frm.getValue(fld2) == ""){ if(frm.getValue(fld1) == false){ alertSwal('warning',nome, 'missing field',frm.focus.bind(frm,fld1)); }else{ alertSwal('warning',nome, 'Non presente tra i dati disponibili',frm.focus.bind(frm,fld1)); } frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "date": if(frm.getValue(fld1) == "" || frm.getValue(fld1) == "00-00-0000"){ alertSwal('warning',nome, 'missing field',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "date<": if(frm.getValue(fld2) != "" && frm.getValue(fld1) != ""){//&& frm.getValue(fld2) != "00-00-0000" && frm.getValue(fld1) != "00-00-0000" var arr1 = frm.getValue(fld1).split("-"); var arr2 = frm.getValue(fld2).split("-"); var d1 = new Date(arr1[2],arr1[1]-1,arr1[0]); var d2 = new Date(arr2[2],arr2[1]-1,arr2[0]); var r1 = d1.getTime(); var r2 = d2.getTime(); if(r1 > r2){ alertSwal('warning',nome, 'Le date sono invertite',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; } return true; }else{ return true; } break; case "ore<": if(frm.getValue(fld2)!="" && frm.getValue(fld1)!=""){//&& frm.getValue(fld2)!="00:00" && frm.getValue(fld1)!="00:00"){ var arr1 = frm.getValue(fld1).split(":"); var arr2 = frm.getValue(fld2).split(":"); arr1[0]= parseInt(arr1[0],10); arr1[1]= parseInt(arr1[1],10); arr2[0]= parseInt(arr2[0],10); arr2[1]= parseInt(arr2[1],10); if(arr1[0] > arr2[0] || (arr1[0] == arr2[0] && arr1[1] > arr2[1])){ alertSwal('warning',nome, 'Gli orari sono invertiti',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; } return true; }else{ return true; } break; case "!-1": // controlla se il valore del campo e' !-1 if(frm.getValue(fld1)=='-1'){ alertSwal('warning',nome, 'missing field',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "=": // confronta due campi if(frm.getValue(fld2) != frm.getValue(fld1)){ alertSwal('warning',nome, "non_coincidono",frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; frm.getElement(fld2).value = ""; return false; }else{ return true; } break; case "c<": // controlla se il campo e' piu' corto di un tot if(frm.getValue(fld1).length < fld2){ alertSwal('warning',nome, "lunghezza_minima"+fld2,frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "piva": // controlla partita iva var r = new RegExp("^[0-9]{11}$"); if(!r.test(frm.getValue(fld1))){ alertSwal('warning',nome, 'Formato non valido',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "cf": // controlla codice fiscale var r = new RegExp("^[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]$"); if(!r.test(frm.getValue(fld1))){ alertSwal('warning',nome, 'Formato non valido',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "iban": // controlla IBAN var r = new RegExp("^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}$"); //var r = new RegExp("/^(?:(?:IT|SM)\d{2}[A-Z]\d{22}|CY\d{2}[A-Z]\d{23}|NL\d{2}[A-Z]{4}\d{10}|LV\d{2}[A-Z]{4}\d{13}|(?:BG|BH|GB|IE)\d{2}[A-Z]{4}\d{14}|GI\d{2}[A-Z]{4}\d{15}|RO\d{2}[A-Z]{4}\d{16}|KW\d{2}[A-Z]{4}\d{22}|MT\d{2}[A-Z]{4}\d{23}|NO\d{13}|(?:DK|FI|GL|FO)\d{16}|MK\d{17}|(?:AT|EE|KZ|LU|XK)\d{18}|(?:BA|HR|LI|CH|CR)\d{19}|(?:GE|DE|LT|ME|RS)\d{20}|IL\d{21}|(?:AD|CZ|ES|MD|SA)\d{22}|PT\d{23}|(?:BE|IS)\d{24}|(?:FR|MR|MC)\d{25}|(?:AL|DO|LB|PL)\d{26}|(?:AZ|HU)\d{27}|(?:GR|MU)\d{28})$/i"); if(!r.test(frm.getValue(fld1))){ alertSwal('warning',nome, 'Formato non valido',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; // TODO case "h": // controlla se il campo hidden = vuoto if(document.getElementById(id2).value == false){ alertWinScroll(id, 400, ""+nome+": campo mancante"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; }else{ return true; } break; case "c": // controlla se il campo e' piu' lungo di un tot if(document.getElementById(id).value.length > id2){ var c = "caratteri"; if(id2==1) c = "carattere"; alertWinScroll(id, 400, ""+nome+": il campo deve contenere un massimo di "+id2+" "+c); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; }else{ return true; } break; case "n=": // controlla se il campo e' lungo n if(document.getElementById(id).value.length != id2){ var c = "caratteri"; if(id2==1) c = "carattere"; alertWinScroll(id, 400, ""+nome+": il campo deve contenere " +id2+ " "+c); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF0000"; return false; }else{ return true; } break; case "n": // controlla se il campo e' un numero if(isNaN(document.getElementById(id).value.replace(',','.'))){ alertWin(nome+": il campo deve contenere solo numeri"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF0000"; return false; }else{ return true; } case "v>": // controlla se il valore del campo e' > di tot if(parseInt(document.getElementById(id).value)=": // controlla se il valore del campo e' >= di tot if(parseInt(document.getElementById(id).value)"+nome+": formato non valido"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; break; case "img": // controllo se il file = una img obj = document.getElementById(id); var extensions = new Array(); extensions[1] = "jpg"; extensions[0] = "jpeg"; extensions[2] = "gif"; extensions[3] = "png"; /*extensions[4] = "bmp";*/ var image_file = obj.value; var image_length = image_file.length; var pos = image_file.lastIndexOf('.') + 1; var ext = image_file.substring(pos, image_length); var final_ext = ext.toLowerCase(); for (i = 0; i < extensions.length; i++){ if(extensions[i] == final_ext){ return true; } } alertWin("Seleziona un'immagine con una delle seguenti estensioni:\n\n gif, jpeg, jpg"); return false; break; default: alertWin("tipo non riconosciuto"); return false; } } function indirizzoEmailValido(indirizzo) { if (window.RegExp) { var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)"; var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; var regnv = new RegExp(nonvalido); var regv = new RegExp(valido); if (!regnv.test(indirizzo) && regv.test(indirizzo)) return true; return false; }else { if(indirizzo.indexOf("@") >= 0) return true; return false; } } /* Data tempo ********************************/ function dataIntervalPicker(dateFrom, dateTo, pos, autoOpen, dataMin, dataMax) { // // nuova versione diverso da ncc if(dataMin==undefined || dataMin=='') dataMin=='01-01-2024'; if(dataMax==undefined || dataMax=='') dataMax=='01-01-2084'; var dateF; var dateT; if(typeof dateFrom == 'string'){ dateF = $('#'+dateFrom); }else{ dateF = $(dateFrom); }; if(typeof dateTo == 'string'){ dateT = $('#'+dateTo); }else{ dateT = $(dateTo); }; if(dateF.val()==""){var dpevent = "change";}else{var dpevent = "blur";} dateF.datepicker({ dateFormat: 'dd-mm-yy', orientation: pos, minDate: dataMin, maxDate: dataMax //debug:true //}).on('dp.change', function (ev) { }).on(dpevent, function (ev) { //$(dateF[0]).trigger("change"); try { dateT.data("DateTimePicker").destroy(); } catch (e) {} dateT.datepicker({ dateFormat: 'dd-mm-yy', orientation: pos, minDate: dateF.datepicker( "getDate" ),//ev.date, maxDate: dataMax });/*.on('change', function (ev) { $(dateT[0]).trigger("change"); });*/ if(dpevent=='change') setTimeout(function (){dateT.focus();}, 500); //$(dateT[0]).trigger("focus"); }); if(autoOpen){ dateF[0].onfocus=function(){}; dateF.blur(); dateF.focus(); } } function xdataPicker(id,open,current){ if(open==undefined) open=0;// istanzia ed apri il picker if(current==undefined) current=true;//On show, use the current date/time var obj; if(typeof id == 'string'){ obj = $('#'+id); }else{ obj = $(id); }; obj.datetimepicker({ locale:LANG, format: 'DD-MM-YYYY', icons: { time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: 'fa fa-chevron-left', next: 'fa fa-chevron-right', today: 'fa fa-screenshot', clear: 'fa fa-trash', close: 'fa fa-remove', inline: true }, ignoreReadonly: true, useCurrent:current //,debug:true }).on('dp.change', function (ev) { $(obj[0]).trigger( "change" ); //obj.trigger( "change" ); }); if(open){ obj[0].onfocus=function(){}; obj.blur(); obj.focus(); }; } function xdataPickerMin(id,open,dataF){ if($('#'+dataF).val()=="") return false; dataLim = $('#'+dataF).val().split('-'); if(open==undefined) open=0;// istanzia ed apri il picker var obj; if(typeof id == 'string'){ obj = $('#'+id); }else{ obj = $(id); }; obj.datetimepicker({ locale:LANG, format: 'DD-MM-YYYY', icons: { time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: 'fa fa-chevron-left', next: 'fa fa-chevron-right', today: 'fa fa-screenshot', clear: 'fa fa-trash', close: 'fa fa-remove', inline: true }, minDate: moment([dataLim[2],dataLim[1]-1,dataLim[0],0,0,0,0]), useCurrent: false, ignoreReadonly: true //,debug:true }).on('dp.change', function (ev) { $(obj[0]).trigger( "change" ); //obj.trigger( "change" ); }); //newDate = new Date(dataLim[2]+'-'+dataLim[1]+'-'+dataLim[0]+'T00:00:00'); //obj.data("DateTimePicker").date(newDate); if(open){ obj[0].onfocus=function(){}; obj.blur(); obj.focus(); }; } function xtimePicker(id,open,current){ if(open==undefined) open=0; if(current==undefined) current=true; var obj; if(typeof id == 'string'){ obj = $('#'+id); }else{ obj = $(id); }; obj.datetimepicker({ locale:LANG, format: 'H:mm', // use this format if you want the 24hours timepicker //format: 'h:mm A', //use this format if you want the 12hours timpiecker with AM/PM toggle icons: { time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: 'fa fa-chevron-left', next: 'fa fa-chevron-right', today: 'fa fa-screenshot', clear: 'fa fa-trash', close: 'fa fa-remove', inline: true }, useCurrent:current, //On show, use the current date/time ignoreReadonly: true //,debug:true }).on('dp.change', function (ev) { $(obj[0]).trigger( "change" ); }); if(open){ // istanzia ed apri il picker obj[0].onfocus=function(){}; obj.blur(); obj.focus(); }; } function xyearPicker(id,open,current){ if(open==undefined) open=0;// istanzia ed apri il picker if(current==undefined) current=true;//On show, use the current date/time var obj; if(typeof id == 'string'){ obj = $('#'+id); }else{ obj = $(id); }; obj.datetimepicker({ locale:LANG, format: 'DD-MM-YYYY', icons: { time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: 'fa fa-chevron-left', next: 'fa fa-chevron-right', today: 'fa fa-screenshot', clear: 'fa fa-trash', close: 'fa fa-remove', inline: true }, viewMode: 'years', defaultDate: '2001', ignoreReadonly: true, useCurrent:current //,debug:true }).on('dp.change', function (ev) { $(obj[0]).trigger( "change" ); //obj.trigger( "change" ); }); if(open){ obj[0].onfocus=function(){}; obj.blur(); obj.focus(); }; } // DOM---------------- function getChildTag(obj,tag){ var childs = Array(); var links = obj.getElementsByTagName(tag); for(var l in links){ if(links[l].nodeType==1 && childs.indexOf(links[l]) === -1){ childs.push(links[l]); } } return childs; } /************************************/ /**** Fine funzioni generiche *******/ function inviaAvaibleAll(obj){ var frm = formica(obj); var flag = true; flag = flag && controlForm(frm, "Arrival",'dataIn'); flag = flag && controlForm(frm, "Departure",'dataOut'); flag = flag && controlForm(frm, "N.PAX",'idPersone'); if(flag){ obj.onsubmit=function(){}; obj.submit(); } } function inviaMex(obj){ var frm = formica(obj); var flag = true; flag = flag && controlForm(frm, "Name",'nome'); flag = flag && controlForm(frm, "E-mail",'blabla'); flag = flag && controlForm(frm, "E-mail",'blabla','','@'); flag = flag && controlForm(frm, "Message",'mex',''); var strUri = frm.buildUri('php'); if(flag){ viewLoader('Sending email'); $.post('https://www.travelandfair.net/inviaMex',strUri,function(){},'json') .done(function(resp){ var fn = function (){ frm.getElement('nome').value = ""; if(frm.nodes['tel']) frm.getElement('tel').value = ""; frm.getElement('blabla').value = ""; if(frm.nodes['oggetto']) frm.getElement('oggetto').value = ""; frm.getElement('mex').value = ""; } if(resp.s=="ok"){ alertSwal('success',"", "Your message was sent successfully, you will be contacted soon!", fn); }else{ alertSwal('error','',"Sending error"); } }) .fail(function(){alertSwal('error','', "Connection error");}) .always(function(resp){hideLoader(resp,0);}); } } function inviaContact(obj){ var frm = formica(obj); var flag = true; flag = flag && controlForm(frm, "E-mail",'blabla'); flag = flag && controlForm(frm, "E-mail",'blabla','','@'); flag = flag && controlForm(frm, "Adults",'adulti','','_'); flag = flag && controlForm(frm, "Arrival",'dataArrivo','','_'); flag = flag && controlForm(frm, "Departure",'dataPartenza','','_'); // flag = flag && controlForm(frm, "AUTORIZZAZIONE AL TRATTAMENTO DEI DATI PERSONALI",'concedo','','_'); if(flag){ viewLoader('Sending email'); $.post('https://www.travelandfair.net/exInviaContact',frm.buildUri('php'),function(){},'json') .done(function(resp){ var fn = function (){ frm.getElement('nome').value = ""; if(frm.nodes['tel']) frm.getElement('tel').value = ""; frm.getElement('blabla').value = ""; if(frm.nodes['oggetto']) frm.getElement('oggetto').value = ""; frm.getElement('mex').value = ""; } if(resp.s=="ok"){ alertSwal('success',"", "Request submitted properly, you will be contacted soon!", fn); }else{ alertSwal('error','',"Sending error"); } }) .fail(function(){alertSwal('error','', "Connection error");}) .always(function(resp){hideLoader(resp,0);}); } } function inviaContactV(obj){ var frm = formica(obj); var flag = true; flag = flag && controlForm(frm, "E-mail",'blabla'); flag = flag && controlForm(frm, "E-mail",'blabla','','@'); if(flag){ viewLoader('Sending email'); $.post('https://www.travelandfair.net/exInviaContactV',frm.buildUri('php'),function(){},'json') .done(function(resp){ var fn = function (){ frm.getElement('nome').value = ""; if(frm.nodes['tel']) frm.getElement('tel').value = ""; frm.getElement('blabla').value = ""; if(frm.nodes['oggetto']) frm.getElement('oggetto').value = ""; frm.getElement('mex').value = ""; } if(resp.s=="ok"){ alertSwal('success',"", "Request submitted properly, you will be contacted soon!", fn); }else{ alertSwal('error','',"Sending error"); } }) .fail(function(){alertSwal('error','', "Connection error");}) .always(function(resp){hideLoader(resp,0);}); } } // Slideshow Multipla var initPhotoSwipeFromMultipleDOM = function(gallerySelector) { // parse slide data (url, title, size ...) from DOM elements // (children of gallerySelector) var parseThumbnailElements = function(el) { var thumbElements = el.children,//el.childNodes, MOD numNodes = thumbElements.length, items = [], el, childElements, thumbnailEl, size, item; for(var i = 0; i < numNodes; i++) { el = thumbElements[i]; // include only element nodes if(el.nodeType !== 1) { continue; } el = el.children[0]; // element childElements = el.children; size = el.getAttribute('data-size').split('x'); // create slide object item = { src: el.getAttribute('href'), w: parseInt(size[0], 10), h: parseInt(size[1], 10), author: el.getAttribute('data-author'), title: el.getAttribute('data-title') }; item.el = el; item.o = { src: item.src, w: item.w, h: item.h }; item.m = item.o; /*if(figureEl.children.length > 1) { //
content item.title = figureEl.children[1].innerHTML; } if(linkEl.children.length > 0) { // thumbnail element, retrieving thumbnail url item.m.src = linkEl.children[0].getAttribute('src'); } item.el = figureEl; // save link to element for getThumbBoundsFn*/ items.push(item); } return items; }; // find nearest parent element var closest = function closest(el, fn) { return el && ( fn(el) ? el : closest(el.parentNode, fn) ); }; // triggers when user clicks on thumbnail var onThumbnailsClick = function(e) { e = e || window.event; e.preventDefault ? e.preventDefault() : e.returnValue = false; var eTarget = e.target || e.srcElement; eTarget = eTarget.parentNode.parentNode; // find root element of slide /*var clickedListItem = closest(eTarget, function(el) { return (el.tagName && el.tagName.toUpperCase() === 'FIGURE'); });*/ var clickedListItem = closest(eTarget, function(el) { return el.tagName === 'A'; }); if(!clickedListItem) { return; } // find index of clicked item by looping through all child nodes // alternatively, you may define index via data- attribute var clickedGallery = clickedListItem.parentNode.parentNode, childNodes = clickedGallery.querySelectorAll("[data-item='picture']");///clickedListItem.parentNode.childNodes, var numChildNodes = childNodes.length, nodeIndex = 0, index; for (var i = 0; i < numChildNodes; i++) { if(childNodes[i].nodeType !== 1) { continue; } if(childNodes[i] === clickedListItem) { index = nodeIndex; break; } nodeIndex++; } if(index >= 0) { // open PhotoSwipe if valid index found openPhotoSwipe( index, clickedGallery ); } return false; }; // parse picture index and gallery index from URL (#&pid=1&gid=2) var photoswipeParseHash = function() { var hash = window.location.hash.substring(1), params = {}; if(hash.length < 5) { return params; } var vars = hash.split('&'); for (var i = 0; i < vars.length; i++) { if(!vars[i]) { continue; } var pair = vars[i].split('='); if(pair.length < 2) { continue; } params[pair[0]] = pair[1]; } if(params.gid) { params.gid = parseInt(params.gid, 10); } return params; }; var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) { var pswpElement = document.querySelectorAll('.pswp')[0], gallery, options, items; items = parseThumbnailElements(galleryElement); // define options (if needed) options = { // define gallery index (for URL) galleryUID: galleryElement.getAttribute('data-pswp-uid'), getThumbBoundsFn: function(index) { // See Options -> getThumbBoundsFn section of documentation for more info var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail pageYScroll = window.pageYOffset || document.documentElement.scrollTop, rect = thumbnail.getBoundingClientRect(); return {x:rect.left, y:rect.top + pageYScroll, w:rect.width}; }, addCaptionHTMLFn: function(item, captionEl, isFake) { if(!item.title) { captionEl.children[0].innerText = ''; return false; } captionEl.children[0].innerHTML = item.title + '
Photo: ' + item.author + ''; return true; } }; // PhotoSwipe opened from URL if(fromURL) { if(options.galleryPIDs) { // parse real index when custom PIDs are used // http://photoswipe.com/documentation/faq.html#custom-pid-in-url for(var j = 0; j < items.length; j++) { if(items[j].pid == index) { options.index = j; break; } } } else { // in URL indexes start from 1 options.index = parseInt(index, 10) - 1; } } else { options.index = parseInt(index, 10); } // exit if index not found if( isNaN(options.index) ) { return; } options.mainClass = 'pswp--minimal--dark'; options.barsSize = {top:0,bottom:0}; options.captionEl = true; options.fullscreenEl = true; options.shareEl = false; options.bgOpacity = 0.85; options.tapToClose = true; options.tapToToggleControls = false; if(disableAnimation) { options.showAnimationDuration = 0; } // Pass data to PhotoSwipe and initialize it gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); // see: http://photoswipe.com/documentation/responsive-images.html var realViewportWidth, useLargeImages = false, firstResize = true, imageSrcWillChange; gallery.listen('beforeResize', function() { var dpiRatio = window.devicePixelRatio ? window.devicePixelRatio : 1; dpiRatio = Math.min(dpiRatio, 2.5); realViewportWidth = gallery.viewportSize.x * dpiRatio; if(realViewportWidth >= 1200 || (!gallery.likelyTouchDevice && realViewportWidth > 800) || screen.width > 1200 ) { if(!useLargeImages) { useLargeImages = true; imageSrcWillChange = true; } } else { if(useLargeImages) { useLargeImages = false; imageSrcWillChange = true; } } if(imageSrcWillChange && !firstResize) { gallery.invalidateCurrItems(); } if(firstResize) { firstResize = false; } imageSrcWillChange = false; }); gallery.listen('gettingData', function(index, item) { if( useLargeImages ) { item.src = item.o.src; item.w = item.o.w; item.h = item.o.h; } else { item.src = item.m.src; item.w = item.m.w; item.h = item.m.h; } }); gallery.init(); /* fullscreen mode on photo click, don't close gallery on esc */ //gallery.ui.getFullscreenAPI().enter(); /* or fullscreen and close the gallery on esc let psAPI = gallery.ui.getFullscreenAPI(); psAPI.enter(); gallery.listen('close', function (name) { psAPI.exit(); });*/ }; // loop through all gallery elements and bind events var galleryElements = document.querySelectorAll( gallerySelector ); for(var i = 0, l = galleryElements.length; i < l; i++) { galleryElements[i].setAttribute('data-pswp-uid', i+1); galleryElements[i].onclick = onThumbnailsClick; } // Parse URL and open gallery if it contains #&pid=3&gid=1 var hashData = photoswipeParseHash(); if(hashData.pid && hashData.gid) { openPhotoSwipe( hashData.pid , galleryElements[ hashData.gid - 1 ], true, true ); } }; // ***************BONIFICARE*********************** /*function getPartenza(dateIt){ if(dateIt=='') return ''; var t = convDate(dateIt).split(/[-]/); var d = new Date(t[0], t[1]-1, t[2]); d = dateAdd(d, 'd', 7); d = getDate(d); return convDate(d); } UTF8 = { encode: function(s){ for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l; s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i] ); return s.join(""); }, decode: function(s){ for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l; ((a = s[i][c](0)) & 0x80) && (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ? o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "") ); return s.join(""); } }; function stripHTML(oldString) { var newString = ""; var inTag = false; for(var i = 0; i < oldString.length; i++) { if(oldString.charAt(i) == '<') inTag = true; if(oldString.charAt(i) == '>') { if(oldString.charAt(i+1)=="<"){ }else{ inTag = false; i++; } } if(!inTag) newString += oldString.charAt(i); } return newString; } function switchVal(obj){ if(obj.parentNode.lastChild.value==1){ obj.parentNode.lastChild.value = 0; obj.style.fontWeight = "normal"; obj.style.color = "white"; }else{ obj.parentNode.lastChild.value = 1; obj.style.fontWeight = "bolder"; obj.style.color = "orange"; } } function alertUtf8(str){ alert(UTF8.decode(str)); } function controlloTesto(maxWord,campo,countWord){ var i=0; campoTesto = document.getElementById(campo); if(((maxWord - campoTesto.value.length) == 0) || ((campoTesto.value.length) > maxWord )){ word = document.getElementById(countWord); word.innerHTML = 0; }else { word = document.getElementById(countWord); word.innerHTML = ""+(maxWord - campoTesto.value.length)+""; } if(campoTesto.value.length > maxWord){ wordWrite = campoTesto.value; campoTesto.value = wordWrite.substr(0,maxWord); } } function addOnScroll() { var htmlEl = document.getElementsByTagName('html')[0]; htmlEl.onscroll = function() { doSomething(); }; } function resetBorder(obj) { for(var n=0; n