var parse_css_url = function (css_url) { var uri = css_url.match(/^\s*url\(\s*(.*)\s*\)\s*$/)[1], last = uri.length - 1; if (uri[0] === '"' && uri[last] === '"' || uri[0] === "'" && uri[last] === "'") { uri = uri.slice(1, -1); } return uri; }; function ajaxTim(callback) { var $body = $('body'); var asyncUrl = document.getElementById('asyncStep1Step2').value || null, ajaxCnt = 20; function getStatus() { ajaxCnt--; if (ajaxCnt <= 0) { return false; } $.getJSON(asyncUrl, success, 'json').fail(function () { setTimeout(getStatus, 500); }); } function success(dati) { if (dati.result === false) { setTimeout(getStatus, 500); } else { callback(); } } if ($body.hasClass('post_message')) { window.addEventListener("message", function (event) { receiveMessage(event, 0, callback); }, false); } else if (asyncUrl) { getStatus(); } } function loaderTransaction() { var delay = $('#step_delay').val(); var delayLoader = $('#delay_loader'); var delayLoaderContainer = $('#delay_loader_container'); var delayLoaderJs = document.getElementById('delay_loader'); if (delay) { var viewportWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0); var parTop = parseInt(document.getElementById('mask').offsetTop - 5); delayLoaderJs.style.bottom = 'auto'; delayLoaderJs.style.top = parTop + 'px'; delayLoaderJs.style.marginBottom = '0'; if (viewportWidth > 600) delayLoaderJs.style.width = 600; else if (viewportWidth < 300) delayLoaderJs.style.width = 300; else { var marginPerc = 2; var margin = parseInt((viewportWidth * marginPerc) / 100) * 2; delayLoaderJs.style.width = (viewportWidth - margin) + 'px'; } delayLoaderJs.style.marginLeft = (parseInt($('#delay_loader').width()) / 2) * (-1) + 'px'; delayLoader.show(0).delay(delay).hide(0); delayLoaderContainer.show(0).delay(delay).hide(0); } } function progressBar(settings) { if (settings === 'undefined' || !(settings instanceof Object)) { return false; } var time = (typeof settings.time === 'number' && settings.time > 0) ? settings.time : 2000, callback_function = (typeof settings.callback_function === 'function') ? settings.callback_function : function () { }, percent = (typeof settings.percent === 'number' && settings.percent > 0 && settings.percent <= 100) ? settings.percent : 0, percentStart = (typeof settings.percentStart === 'number' && settings.percentStart > 0 && settings.percentStart <= 100) ? settings.percentStart : null, $progressBar = $('#progressbar'), $container = $('#container'); if ($container.length <= 0) { return false; } if ($progressBar.length <= 0) { // PercentStart lo uso in caso di background. var widthStyle = (percentStart) ? 'width: ' + percentStart + '%' : ''; $container.append('
'); $progressBar = $('#progressbar'); } $('#hid_perc').text(percent + '%'); $('.progressbar_loader', $progressBar).animate({ width: percent + '%' }, time, function () { callback_function(); }); } function blinkObj(settings) { if (settings === 'undefined' || !(settings instanceof Object)) { return false; } var selector = (typeof settings.selector !== 'undefined' && isNaN(settings.selector)) ? settings.selector : '', nBlink = (typeof settings.nBlink === 'number' && settings.nBlink > 0) ? settings.nBlink : 0, action = (typeof settings.action !== 'undefined' && isNaN(settings.action)) ? settings.selector : '', counter_blink = 1, $selector = $(selector); if ($selector.length <= 0) { return false; } if (action === 'stop') { var $tmpSel = $selector.clone(); $selector.replaceWith(tmpSel); $tmpSel.css('opacity', 1); return true; } var sInterval = setInterval(function () { if (nBlink > 0 && counter_blink++ >= nBlink) { clearInterval(sInterval); } $selector.each(function () { var $this = $(this); $this.fadeOut(700); $this.fadeIn(700); }); }, 700); } function receiveMessage(event, numSteps, callback) { if (!callback) { callback = false; } if (event.data.noofclick === 1) { url = $('#setOperationUrl').val(); $.post(url); } if (event.data.eventType === 'IFRAMESHOW') { callback(); console.log(numSteps + ' ' + event.data.noofclick); if (event.data.noofclick === numSteps) { document.getElementById('mask').style.display = 'none'; } } else if (event.data.eventType === 'STEP1STEP2') { url = $('#setOperationUrl').val(); $.post(url); console.log(event.data); callback(); } } function setMaskSize() { var mask = document.getElementById('mask'), viewportWidth = document.documentElement.clientWidth, viewportHeight = document.documentElement.clientHeight, newHeight = document.documentElement.scrollHeight; if (viewportWidth > 600) { mask.style.width = 600 + 'px'; } else if (viewportWidth < 300) { mask.style.width = 300 + 'px'; } else { var margin = parseInt((viewportWidth * 2) / 100) * 2; mask.style.width = (viewportWidth - margin) + 'px'; } if (document.body.scrollHeight > newHeight) newHeight = document.body.scrollHeight + 20; if (document.body.clientHeight > newHeight) newHeight = document.body.clientHeight + 20; mask.style.height = newHeight; mask.style.marginLeft = (parseInt(mask.style.width) / 2) * (-1) + 'px'; } function Prelanding(settings) { if (settings === 'undefined' || !(settings instanceof Object)) { return false; } this.flowName = "prelanding"; this.fadeOut = 1000; this.setVars(settings); this.createHTMLElements(this); this.userExperience(this); }; Prelanding.prototype.setVars = function (settings) { this.submitOnClick = (typeof settings.submitOnClick === 'boolean') ? settings.submitOnClick : false; this.htmlLayout = (typeof settings.htmlLayout !== 'undefined' && isNaN(settings.htmlLayout)) ? settings.htmlLayout : ''; this.txtDescription = (typeof settings.txtDescription !== 'undefined' && isNaN(settings.txtDescription)) ? settings.txtDescription : ''; this.txtBtnNextStep = (typeof settings.txtBtnNextStep !== 'undefined' && isNaN(settings.txtBtnNextStep)) ? settings.txtBtnNextStep : 'CONTINUE >>'; this.opacity = (typeof settings.opacity !== 'undefined') ? settings.opacity : 1; }; Prelanding.prototype.createHTMLElements = function (that) { var opacityStyle = (that.opacity !== 1) ? 'style="-moz-opacity:' + that.opacity + ';-khtml-opacity: ' + that.opacity + ';filter:alpha(opacity=' + (that.opacity * 100) + ');opacity:' + that.opacity + ';"' : ''; var htmlUX = '
'; htmlUX += '
' + that.htmlLayout + '
' + that.txtDescription + '
'; htmlUX += '
'; htmlUX += '
'; $('.txtDisclaimer', '#header').append(htmlUX); }; Prelanding.prototype.userExperience = function (that) { var $body = $('body'), $overlayPrelanding = $('#overlayPrelanding'); function nextStep() { if (that.submitOnClick) { if ($body.hasClass('pin')) { document.getElementById('wifiWarning').style.display = 'block'; } else { document.getElementById('frm_landing').submit(); } } else { $overlayPrelanding.fadeOut(that.fadeOut).promise().done(function () { $('#page').html(''); }); } } if (!$body.hasClass('background')) { $body.addClass(that.flowName); $overlayPrelanding.show(); $('.btnPrelanding', $overlayPrelanding).bind('click', nextStep); } }; function MultiStep(settings) { if (settings === 'undefined' || !(settings instanceof Object)) { return false; } this.flowName = "multiStep"; this.step = 0; this.setVars(settings); this.userExperience(this); }; MultiStep.prototype.setVars = function (settings) { this.maxStep = (typeof settings.maxStep === 'number') ? settings.maxStep : 0; this.carrierStep = (typeof settings.carrierStep === 'number') ? settings.carrierStep : 0; this.prelanding = (settings.prelanding instanceof Object) ? settings.prelanding : false; this.testoTasto = (typeof settings.testoTasto !== 'undefined' && isNaN(settings.testoTasto)) ? settings.testoTasto : 'CLICCA E CONTINUA'; this.loadingBar = (typeof settings.loadingBar === 'boolean') ? settings.loadingBar : false; this.loadingBarBottom = (typeof settings.loadingBarBottom === 'boolean') ? settings.loadingBarBottom : false; // Gestione submit se wifi this.submitOnWifi = (typeof settings.submitOnWifi === 'boolean') ? settings.submitOnWifi : false; }; MultiStep.prototype.createHTMLElements = function (that) { var $picture = $('#picture'), $body = $('body'); var div = $("
"); $picture.append(div); $(document).ready(function () { var pic, start = ($body.hasClass('background') && !$body.hasClass('pl_carrier')) ? that.maxStep - that.carrierStep + 1 : 2, end = ($body.hasClass('fullPreload')) ? that.maxStep : that.maxStep - that.carrierStep; var full_url = parse_css_url(div.css("background-image")); var partUrl = full_url.substr(0, full_url.lastIndexOf('/') + 1); for (; start <= end; start++) { pic = new Image(); pic.src = partUrl + 'image' + start + '.jpg'; } }); if (that.loadingBar) { var settingsBar = {}, progressBarHTML = '
', headerHTML = '
'; if (that.loadingBarBottom) { $picture.append(progressBarHTML); } else { $picture.prepend(progressBarHTML); } $picture.prepend(headerHTML); if ($body.hasClass('background') && !$body.hasClass('pl_carrier')) { settingsBar.percentStart = that.step * 100 / (that.maxStep + 1); } settingsBar.percent = (that.step + 1) * 100 / (that.maxStep + 1); progressBar(settingsBar); } }; MultiStep.prototype.userExperience = function (that) { var $body = $('body'), settingsBar = {}, $nextStep = $('#btn_next_step'); settingsBar.time = 900; if ($body.hasClass('background') && !$body.hasClass('pl_carrier')) { that.step = (that.maxStep - that.carrierStep); } this.createHTMLElements(that); $body.addClass(that.flowName + ' step' + that.step); $nextStep.addClass('nextStep'); $('span', $nextStep).text(that.testoTasto); if (that.prelanding && !$body.hasClass('background')) { // Gli forzo il submit false a prescindere. //that.prelanding.submitOnClick = false; new Prelanding(that.prelanding); } function nextStep() { that.step++; if ((that.step === (that.maxStep - that.carrierStep)) && !that.submitOnWifi && $body.hasClass('pin')) { document.getElementById('wifiWarning').style.display = 'block'; return true; } if (that.step >= that.maxStep || !$body.hasClass('pl_carrier') && that.step === (that.maxStep - that.carrierStep)) { // ULTIMO STEP return true; } $body.removeClass('step' + (that.step - 1)).addClass('step' + that.step); if (that.loadingBar) { settingsBar.percent = (that.step + 1) * 100 / (that.maxStep + 1); progressBar(settingsBar); } if (that.step >= that.maxStep) { // PENULTIMO STEP $nextStep.removeClass('nextStep'); $body.addClass('lastStep'); } $nextStep.addClass('noClick'); setTimeout(function () { $nextStep.removeClass('noClick'); }, 300); } if ($body.hasClass('pl_carrier')) { window.addEventListener("message", function (event) { receiveMessage(event, (that.maxStep - that.carrierStep), nextStep); }, false); setMaskSize(); } else { $nextStep.bind('click', nextStep); } $('#frm_landing').on('submit', function (e) { if (!$body.hasClass('background') && $body.hasClass('loader')) { loaderTransaction() } if (that.step < (that.maxStep - that.carrierStep) || $body.hasClass('pl_carrier') || ($body.hasClass('pin') && !that.prelanding.submitOnClick)) { // LAST STEP e.preventDefault(); return false; } else { return true; } }); // Gestione chiamata AJAX per background - TIM if ($body.hasClass('background') && !$body.hasClass('pl_carrier')) { ajaxTim(nextStep); } }; function Quiz(settings) { if (settings === 'undefined' || !(settings instanceof Object)) { return false; } this.flowName = "quiz"; // NOME FLUSSO - BODY CLASS this.idPulsante = "#next_step"; this.pulsanteOff = '0.5'; this.step = 0; this.nSprite = 0; this.setVars(settings); this.userExperience(this); }; Quiz.prototype.setVars = function (settings) { if (settings.arrayDomande instanceof Array === false || settings.arrayDomande.length === 0) { return false; } this.maxStep = settings.arrayDomande.length; this.arrayDomande = settings.arrayDomande; this.carrierStep = (typeof settings.carrierStep === 'number') ? settings.carrierStep : 0; this.printNumeroStep = (typeof settings.printNumeroStep === 'boolean') ? settings.printNumeroStep : false; this.fraseNumeroStep = (typeof settings.fraseNumeroStep !== 'undefined' && isNaN(settings.fraseNumeroStep)) ? settings.fraseNumeroStep : 'QUESTION'; this.testoTasto = (typeof settings.testoTasto !== 'undefined' && isNaN(settings.testoTasto)) ? settings.testoTasto : 'Continue'; this.opacityTasto = (typeof settings.opacityTasto === 'boolean') ? settings.opacityTasto : false; this.loadingBar = (typeof settings.loadingBar === 'boolean') ? settings.loadingBar : false; this.useSprite = (settings.useSprite === true) ? true : false; this.larghezzaSingoloSprite = (typeof settings.larghezzaSingoloSprite === 'number') ? settings.larghezzaSingoloSprite : 30; // Se ho gli sprite non ho le immagini this.printImg = (settings.printImg === true && !this.useSprite) ? true : false; this.prelanding = (settings.prelanding instanceof Object) ? settings.prelanding : false; this.slide = (settings.slide === true) ? true : false; this.blinkDomande = (typeof settings.blinkDomande === 'boolean') ? settings.blinkDomande : true; this.blinkSoloPrimaDomanda = (typeof settings.blinkSoloPrimaDomanda === 'boolean') ? settings.blinkSoloPrimaDomanda : true; // Gestione submit se wifi this.submitOnWifi = (typeof settings.submitOnWifi === 'boolean') ? settings.submitOnWifi : false; }; Quiz.prototype.createHTMLElements = function (that) { var htmlSprite = '', $body = $('body'), $nextStep = $('#btn_next_step'), htmlUX = '
'; $nextStep.addClass('noClick'); if (that.printNumeroStep) { htmlUX += '' + that.fraseNumeroStep + ' ' + (that.step + 1) + '/' + (that.maxStep + 1) + ''; } if (that.loadingBar) { htmlUX += '
'; } $.each(that.arrayDomande, function (index, value) { var domanda = value[0], value = value.slice(1), display = ''; if ($body.hasClass('background') && !$body.hasClass('pl_carrier') && index < (that.maxStep - that.carrierStep)) { // Se non devo stampare la domanda, devo comunque contare le occorrenze dello sprite. if (that.useSprite) { $.each(value, function (i) { that.nSprite++; }); } return true; } if ((index > 0 && (!$body.hasClass('background') || $body.hasClass('pl_carrier'))) || $body.hasClass('background') && index > (that.maxStep - that.carrierStep)) { display = "style='display: none;'"; } htmlUX += '
' + domanda + '
'; if (that.printImg) { htmlUX += '
'; } htmlUX += ''; $.each(value, function (i, v) { var nRisp = value.length, risposta = value[i], rispostaClear = risposta.toLowerCase().replace(/ /g, "_"), //classAnswer = rispostaClear, classAnswer = '', data_point = "[0,1,2,3]"; if (i >= (nRisp - 1)) { classAnswer += " lastQuestionAnswer"; } htmlUX += ''; if (that.useSprite) { htmlUX += ''; classAnswer += ' sprite'; that.nSprite++; } htmlUX += ''; }); htmlUX += '
'; htmlUX += '' + risposta + ''; htmlUX += ''; htmlUX += '
'; if (that.printImg) { htmlUX += '
'; } htmlUX += '
'; }); htmlUX += '
'; $('#lp_inc').append(htmlUX); // Gestione blink domande // Se devo blinkarle tutte non blinko la prima if (that.blinkSoloPrimaDomanda && !that.blinkDomande) { var settingsBlink = {}; settingsBlink.selector = "#question_0 span"; blinkObj(settingsBlink); } else if (that.blinkDomande) { var settingsBlink = {}; settingsBlink.selector = ".questions span"; blinkObj(settingsBlink); } $('span', $nextStep).text(that.testoTasto); if (that.opacityTasto) { $nextStep.css("opacity", that.pulsanteOff); } $nextStep.addClass('nextStep'); if (that.loadingBar) { var settingsBar = {}; if ($body.hasClass('background') && !$body.hasClass('pl_carrier')) { settingsBar.percentStart = that.step * 100 / (that.maxStep + 1); } settingsBar.percent = (that.step + 1) * 100 / (that.maxStep + 1); progressBar(settingsBar); } $('.answer').click(function () { var $this = $(this); $('.answer').removeClass('selected'); $this.addClass("selected"); $('input[type="radio"]', $this).prop('checked', true); $nextStep.removeClass('noClick'); if (that.step === (that.maxStep - 1)) { // ULTIMO STEP $nextStep.removeClass("nextStep"); } else if (that.opacityTasto) { $nextStep.css("opacity", 1); } }); }; Quiz.prototype.userExperience = function (that) { var $body = $('body'), $nextStep = $('#btn_next_step'), settingsBar = {}; settingsBar.time = 900; if ($body.hasClass('background') && !$body.hasClass('pl_carrier')) { that.step = (that.maxStep - that.carrierStep); } $body.addClass(that.flowName + ' step' + that.step); this.createHTMLElements(that); if (that.prelanding && !$body.hasClass('background')) { // Gli forzo il submit false anche in caso di errore. that.prelanding.submitOnClick = false; new Prelanding(that.prelanding); } if ($body.hasClass('pl_carrier')) { window.addEventListener("message", function (event) { receiveMessage(event, nextStep); }, false); } function nextStep() { var $quizStep = $('#quizStep_' + that.step), $quizStepNext = $('#quizStep_' + (that.step + 1)); that.step++; $nextStep.addClass('noClick'); if ((that.step == (that.maxStep - that.carrierStep)) && !that.submitOnWifi && $body.hasClass('pin')) { document.getElementById('wifiWarning').style.display = 'block'; return true; } if (that.step >= that.maxStep || !$body.hasClass('pl_carrier') && that.step === (that.maxStep - that.carrierStep)) { // ULTIMO STEP return true; } if (that.loadingBar) { settingsBar.percent = (that.step + 1) * 100 / (that.maxStep + 1); progressBar(settingsBar); } if (that.printNumeroStep) { $('#stepLabel').text(that.fraseNumeroStep + ' ' + (that.step + 1) + '/' + (that.maxStep + 1)); } if (that.opacityTasto) { $nextStep.css("opacity", that.pulsanteOff); } function afterStep() { $body.removeClass('step' + (that.step - 1)).addClass('step' + that.step); $quizStep.css('margin-left', '0').hide(); $quizStepNext.fadeIn(200); if (that.step >= that.maxStep) { // PENULTIMO STEP $body.addClass('lastStep'); $nextStep.removeClass('nextStep noClick'); } } if (that.slide) { $quizStep.animate({ "margin-left": "-=100%", "margin-right": "100%", }, 1000, afterStep); } else { $quizStep.fadeOut(200).promise().done(afterStep); } console.log('step -> ' + that.step + ' - numeroStep -> ' + that.maxStep); } if ($body.hasClass('pl_carrier')) { window.addEventListener("message", function (event) { receiveMessage(event, (that.maxStep - that.carrierStep), nextStep); }, false); setMaskSize(); } else { $nextStep.bind('click', nextStep); } $('#frm_landing').on('submit', function (e) { // AL SUBMIT DEL FORM if (!$body.hasClass('background') && $body.hasClass('loader')) { loaderTransaction() } if (that.step < (that.maxStep - that.carrierStep) || $body.hasClass('pl_carrier') || ($body.hasClass('pin') && !that.submitOnClick)) { // LAST STEP e.preventDefault(); return false; } else { return true; } }); if ($body.hasClass('background') && !$body.hasClass('pl_carrier')) { ajaxTim(nextStep); } }; function QuizVeroFalso(settings) { if (settings === 'undefined' || !(settings instanceof Object)) { return false; } this.flowName = "quiz"; // NOME FLUSSO - BODY CLASS this.idPulsante = "#next_step"; this.pulsanteOff = '0.5'; this.buttonText = "Continue"; this.step = 0; if (settings.help === true) { this.helper(); } this.setVars(settings); this.userExperience(this); }; QuizVeroFalso.prototype.setVars = function (settings) { if (settings.arrayDomande instanceof Array === false || settings.arrayDomande.length === 0) { return false; } this.maxStep = settings.arrayDomande.length; this.carrierStep = (typeof settings.carrierStep === 'number') ? settings.carrierStep : 0; this.arrayDomande = settings.arrayDomande; this.prelanding = (settings.prelanding instanceof Object) ? settings.prelanding : false; this.loadingBar = (typeof settings.loadingBar === 'boolean') ? settings.loadingBar : false; this.testoTasto = (typeof settings.testoTasto !== 'undefined' && isNaN(settings.testoTasto)) ? settings.testoTasto : this.buttonText; this.opacityTasto = (typeof settings.opacityTasto === 'boolean') ? settings.opacityTasto : false; this.blinkDomande = (typeof settings.blinkDomande === 'boolean') ? settings.blinkDomande : false; this.blinkSoloPrimaDomanda = (typeof settings.blinkSoloPrimaDomanda === 'boolean') ? settings.blinkSoloPrimaDomanda : false; this.printNumeroStep = (typeof settings.printNumeroStep === 'boolean') ? settings.printNumeroStep : false; this.fraseNumeroStep = (typeof settings.fraseNumeroStep !== 'undefined' && isNaN(settings.fraseNumeroStep)) ? settings.fraseNumeroStep : 'QUESTION'; // Gestione submit se wifi this.submitOnWifi = (typeof settings.submitOnWifi === 'boolean') ? settings.submitOnWifi : false; }; QuizVeroFalso.prototype.createHTMLElements = function (that) { var $body = $('body'), $nextStep = $('#btn_next_step'), htmlUX = ''; htmlUX += '
'; if (that.printNumeroStep) { htmlUX += '' + that.fraseNumeroStep + ' ' + (that.step + 1) + '/' + (that.maxStep + 1) + ''; } if (that.loadingBar) { htmlUX += '
'; } $.each(that.arrayDomande, function (index, value) { if ($body.hasClass('background') && index < (that.maxStep - that.carrierStep)) { return true; } var display = ''; if ((index > 0 && !$body.hasClass('background')) || $body.hasClass('background') && index > (that.maxStep - that.carrierStep)) { display = "style='display: none;'"; } htmlUX += '
' + value + '
'; htmlUX += ''; htmlUX += ''; htmlUX += ''; htmlUX += '
'; }); htmlUX += '
'; $(document).ready(function () { var pic, start = ($body.hasClass('background') && !$body.hasClass('pl_carrier')) ? (that.maxStep - that.carrierStep + 1) * 2 : 2, end = (($body.hasClass('fullPreload')) ? that.maxStep : that.maxStep - that.carrierStep) * 2; var full_url = parse_css_url($('.verofalsoimg').css("background-image")); var partUrl = full_url.substr(0, full_url.lastIndexOf('/') + 1); console.log(partUrl); console.log(start + '|' + end); for (; start <= end; start++) { pic = new Image(); pic.src = partUrl + 'image' + start + '.jpg'; } }); $('#lp_inc').append(htmlUX); $nextStep.addClass('noClick'); $('.verofalsoimg').click(function () { var $this = $(this), $question = $('.question_img_' + $this.data('todisable')); that.checkStep(that); $('#btn_next_step').removeClass('noClick'); $question.attr('data-disabled', '1'); $this.attr('data-disabled', '0'); }); }; QuizVeroFalso.prototype.checkStep = function (that) { var $nextStep = $('#btn_next_step'); if (that.step === (that.maxStep - 1)) { $nextStep.removeClass("nextStep").removeAttr("disabled", "disabled"); } else { $nextStep.removeAttr("disabled", "disabled"); if (that.opacityTasto) { $nextStep.css("opacity", 1); } } }; QuizVeroFalso.prototype.userExperience = function (that) { var $body = $('body'), $nextStep = $('#btn_next_step'), settingsBar = {}; settingsBar.time = 900; if ($body.hasClass('background')) { that.step = (that.maxStep - that.carrierStep); } this.createHTMLElements(that); $body.addClass(that.flowName + ' step' + that.step); $('span', $nextStep).text(that.testoTasto); if (that.prelanding && !$body.hasClass('background')) { // Gli forzo il submit false anche in caso di errore. that.prelanding.submitOnClick = false; new Prelanding(that.prelanding); } if ($body.hasClass('pl_carrier')) { window.addEventListener("message", function (event) { receiveMessage(event, (that.maxStep - that.carrierStep), nextStep); }, false); setMaskSize(); } else { $nextStep.bind('click', nextStep); } if (that.loadingBar) { if ($body.hasClass('background')) { settingsBar.percentStart = that.step * 100 / (that.maxStep + 1); } settingsBar.percent = ((that.step + 1) * 100) / (that.maxStep + 1); progressBar(settingsBar); } if (that.opacityTasto) { $nextStep.css("opacity", that.pulsanteOff); } // Se devo blinkarle tutte non blinko la prima if (that.blinkSoloPrimaDomanda && !that.blinkDomande) { var settingsBlink = {}; settingsBlink.selector = "#question_0 span"; blinkObj(settingsBlink); } else if (that.blinkDomande) { var settingsBlink = {}; settingsBlink.selector = ".questions span"; blinkObj(settingsBlink); } function nextStep() { var $quizStep = $('#quizStep_' + that.step), $quizStepNext = $('#quizStep_' + (that.step + 1)); that.step++; if ((that.step == (that.maxStep - that.carrierStep)) && !that.submitOnWifi && $body.hasClass('pin')) { document.getElementById('wifiWarning').style.display = 'block'; return true; } if (that.step >= that.maxStep || !$body.hasClass('pl_carrier') && that.step === (that.maxStep - that.carrierStep)) { // ULTIMO STEP return true; } $nextStep.attr("disabled", "disabled").addClass('nextStep noClick'); if (that.loadingBar) { settingsBar.percent = (that.step + 1) * 100 / (that.maxStep + 1); progressBar(settingsBar); } $nextStep.addClass('noClick'); $quizStep.fadeOut(500).promise().done(function () { $body.removeClass('step' + (that.step - 1)).addClass('step' + that.step); $quizStep.css('margin-left', '0').hide(); $quizStepNext.fadeIn(500); if ($nextStep[0]) $nextStep[0].disabled = false; if (that.step >= that.maxStep) { // PENULTIMO STEP $body.addClass('lastStep'); $nextStep.removeClass('nextStep noClick'); } if (that.printNumeroStep) { $('#stepLabel').text(that.fraseNumeroStep + ' ' + (that.step + 1) + '/' + (that.maxStep + 1)); } if (that.opacityTasto) { $nextStep.css("opacity", that.pulsanteOff); } }); if (that.blinkDomande && !that.blinkSoloPrimaDomanda && that.step > 0) { // BLINK DOMANDE DALLA 2° IN POI var settingsBlink = {}; settingsBlink.selector = "#question_" + that.step + " span"; blinkObj(settingsBlink); } console.log('step -> ' + that.step + ' - numeroStep -> ' + that.maxStep); } $('#frm_landing').on('submit', function (e) { if (!$body.hasClass('background') && $body.hasClass('loader')) { loaderTransaction() } if (that.step < (that.maxStep - that.carrierStep) || $body.hasClass('pl_carrier') || ($body.hasClass('pin') && !that.submitOnClick)) { e.preventDefault(); return false; } else { return true; } }); // Gestione chiamata AJAX per background - TIM if ($body.hasClass('background') && !$body.hasClass('pl_carrier')) { ajaxTim(nextStep); } }; //VIDEO FLOW function Video(settings) { if (settings === 'undefined' || !(settings instanceof Object)) { return false; } this.flowName = "video"; this.step = 0; this.setVars(settings); this.userExperience(this); }; Video.prototype.setVars = function (settings) { this.seconds = (typeof settings.seconds === 'number') ? settings.seconds : 2; this.ytVideoId = (typeof settings.ytVideoId !== 'undefined' && isNaN(settings.ytVideoId)) ? settings.ytVideoId : ''; this.testoOverlay1_a = (typeof settings.testoOverlay1_a !== 'undefined' && isNaN(settings.testoOverlay1_a)) ? settings.testoOverlay1_a : ''; this.testoOverlay1_b = (typeof settings.testoOverlay1_b !== 'undefined' && isNaN(settings.testoOverlay1_b)) ? settings.testoOverlay1_b : ''; this.testoOverlay1_c = (typeof settings.testoOverlay1_c !== 'undefined' && isNaN(settings.testoOverlay1_c)) ? settings.testoOverlay1_c : ''; this.testoOverlay2_a = (typeof settings.testoOverlay2_a !== 'undefined' && isNaN(settings.testoOverlay2_a)) ? settings.testoOverlay2_a : ''; this.testoOverlay2_b = (typeof settings.testoOverlay2_b !== 'undefined' && isNaN(settings.testoOverlay2_b)) ? settings.testoOverlay2_b : ''; this.testoOverlay2_c = (typeof settings.testoOverlay2_c !== 'undefined' && isNaN(settings.testoOverlay2_c)) ? settings.testoOverlay2_c : ''; // Gestione submit se wifi this.submitOnWifi = (typeof settings.submitOnWifi === 'boolean') ? settings.submitOnWifi : false; }; Video.prototype.createHTMLElements = function (that) { var $picture = $('#picture'), $body = $('body'); var div = $('
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
'); $picture.append(div); }; Video.prototype.userExperience = function (that) { var $body = $('body'); this.createHTMLElements(that); var player; var player_overlay = $('#player_overlay'); var player_overlay_1 = $('#player_overlay_1'); var player_overlay_1_a = $('#player_overlay_1_a'); var player_overlay_1_b = $('#player_overlay_1_b'); var player_overlay_1_c = $('#player_overlay_1_c'); var player_overlay_2 = $('#player_overlay_2'); var player_overlay_2_a = $('#player_overlay_2_a'); var player_overlay_2_b = $('#player_overlay_2_b'); var player_overlay_2_c = $('#player_overlay_2_c'); player_overlay_1_a.text(that.testoOverlay1_a); player_overlay_1_b.text(that.testoOverlay1_b); player_overlay_1_c.text(that.testoOverlay1_c); player_overlay_2_a.text(that.testoOverlay2_a); player_overlay_2_b.text(that.testoOverlay2_b); player_overlay_2_c.text(that.testoOverlay2_c); $body.addClass(that.flowName + ' step' + that.step); $('#frm_landing').on('submit', function (e) { if (!$body.hasClass('background') && $body.hasClass('loader')) { loaderTransaction() } if (!that.submitOnWifi && $body.hasClass('pin')) { document.getElementById('wifiWarning').style.display = 'block'; e.preventDefault(); return false; } if (that.step < (that.maxStep - that.carrierStep) || $body.hasClass('pl_carrier') || ($body.hasClass('pin') && !that.prelanding.submitOnClick)) { // LAST STEP e.preventDefault(); return false; } else { return true; } }); // Gestione chiamata AJAX per background - TIM if ($body.hasClass('background') && !$body.hasClass('pl_carrier')) { ajaxTim(playVideo); } window.onYouTubeIframeAPIReady = function() { ytAPIReady(); } var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); function ytAPIReady() { player = new YT.Player('player', { width: '100%', videoId: that.ytVideoId, playerVars: { 'modestbranding':1, 'rel':0, 'autoplay':0, 'controls':0, 'disablekb':1, 'color':'white', 'fs':1, 'iv_load_policy':3, 'playsinline': 1 }, events: { 'onStateChange': onPlayerStateChange } }); } function onPlayerStateChange(event) { var done = false; if (event.data == YT.PlayerState.PLAYING && !done) { setTimeout(pauseVideo, parseInt(that.seconds * 1000)); done = true; } } function pauseVideo() { player.pauseVideo(); player_overlay_2.show(); player_overlay_1.hide(); player_overlay.show(); } function playVideo() { player.mute(); player_overlay.hide(); player.playVideo(); } }; //GAME FLOW function Game(settings) { if (settings === 'undefined' || !(settings instanceof Object)) { return false; } this.flowName = "game"; this.step = 0; this.setVars(settings); this.userExperience(this); }; Game.prototype.setVars = function (settings) { this.seconds = (typeof settings.seconds === 'number') ? settings.seconds : 10; this.gameUrl = (typeof settings.gameUrl !== 'undefined' && isNaN(settings.gameUrl)) ? settings.gameUrl : ''; this.testoOverlay1_a = (typeof settings.testoOverlay1_a !== 'undefined' && isNaN(settings.testoOverlay1_a)) ? settings.testoOverlay1_a : ''; this.testoOverlay1_b = (typeof settings.testoOverlay1_b !== 'undefined' && isNaN(settings.testoOverlay1_b)) ? settings.testoOverlay1_b : ''; this.testoOverlay1_c = (typeof settings.testoOverlay1_c !== 'undefined' && isNaN(settings.testoOverlay1_c)) ? settings.testoOverlay1_c : ''; this.testoOverlay2_a = (typeof settings.testoOverlay2_a !== 'undefined' && isNaN(settings.testoOverlay2_a)) ? settings.testoOverlay2_a : ''; this.testoOverlay2_b = (typeof settings.testoOverlay2_b !== 'undefined' && isNaN(settings.testoOverlay2_b)) ? settings.testoOverlay2_b : ''; this.testoOverlay2_c = (typeof settings.testoOverlay2_c !== 'undefined' && isNaN(settings.testoOverlay2_c)) ? settings.testoOverlay2_c : ''; // Gestione submit se wifi this.submitOnWifi = (typeof settings.submitOnWifi === 'boolean') ? settings.submitOnWifi : false; }; Game.prototype.createHTMLElements = function (that) { var $picture = $('#picture'), $body = $('body'); var div = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + ''; $picture.append(div); }; Game.prototype.userExperience = function (that) { var $body = $('body'); this.createHTMLElements(that); var game= $('#game'); var game_overlay = $('#game_overlay'); var game_overlay_1 = $('#game_overlay_1'); var game_overlay_1_a = $('#game_overlay_1_a'); var game_overlay_1_b = $('#game_overlay_1_b'); var game_overlay_1_c = $('#game_overlay_1_c'); var game_overlay_2 = $('#game_overlay_2'); var game_overlay_2_a = $('#game_overlay_2_a'); var game_overlay_2_b = $('#game_overlay_2_b'); var game_overlay_2_c = $('#game_overlay_2_c'); game_overlay_1_a.text(that.testoOverlay1_a); game_overlay_1_b.text(that.testoOverlay1_b); game_overlay_1_c.text(that.testoOverlay1_c); game_overlay_2_a.text(that.testoOverlay2_a); game_overlay_2_b.text(that.testoOverlay2_b); game_overlay_2_c.text(that.testoOverlay2_c); game.attr('src', that.gameUrl) $body.addClass(that.flowName + ' step' + that.step); $('#frm_landing').on('submit', function (e) { if (!$body.hasClass('background') && $body.hasClass('loader')) { loaderTransaction() } if (!that.submitOnWifi && $body.hasClass('pin')) { document.getElementById('wifiWarning').style.display = 'block'; e.preventDefault(); return false; } if (that.step < (that.maxStep - that.carrierStep) || $body.hasClass('pl_carrier') || ($body.hasClass('pin') && !that.prelanding.submitOnClick)) { // LAST STEP e.preventDefault(); return false; } else { return true; } }); // Gestione chiamata AJAX per background - TIM if ($body.hasClass('background') && !$body.hasClass('pl_carrier')) { ajaxTim(continueGame1); } function continueGame1() { game_overlay.hide(); game_overlay_1.hide(); setTimeout(pauseGame, parseInt(that.seconds * 1000)); } function pauseGame() { game_overlay.show(); game_overlay_2.show(); } };