var brave_isMobile=window.matchMedia("only screen and (max-width: 760px)").matches;var brave_isTab=window.matchMedia("screen and (max-width: 1200px) and (min-width: 760px)").matches;var brave_currentDevice=brave_isMobile?'mobile':'desktop';var brave_back_pressed=0;function brave_number_padding(num){if(num){var theNum=parseInt(num,10);return theNum<10?parseInt("0"+theNum,10):theNum}} function brave_change_slide(elementID,goto,slideWidth){var sliderMargin=-(goto*slideWidth)+'px' var theCarousel=document.getElementById('brave_carousel__slides-'+elementID);var theCarouselNav=document.getElementById('brave_carousel__navs-'+elementID);if(theCarousel){theCarousel.style.marginLeft=sliderMargin;if(theCarouselNav){var allCarouselNavs=theCarouselNav.querySelectorAll(":scope li");for(var i=0;i=0){if(!hideDays){brave_days=parseInt(timeRemaining/86400);timeRemaining=(timeRemaining%86400);} if(!hideHours){brave_hours=parseInt(timeRemaining/3600);timeRemaining=(timeRemaining%3600);} brave_minutes=parseInt(timeRemaining/60);timeRemaining=(timeRemaining%60);brave_seconds=parseInt(timeRemaining);} var daySpan=document.getElementById('brave_rem_days-'+elementID);var hourSpan=document.getElementById('brave_rem_hours-'+elementID);var minSpan=document.getElementById('brave_rem_minutes-'+elementID);var secSpan=document.getElementById('brave_rem_seconds-'+elementID);if(daySpan){daySpan.innerHTML=timeRemaining>=0?brave_days:0} if(hourSpan){hourSpan.innerHTML=timeRemaining>=0?brave_hours:0} if(minSpan){minSpan.innerHTML=timeRemaining>=0?brave_minutes:0} if(secSpan){secSpan.innerHTML=timeRemaining>=0?brave_seconds:0}} function brave_check_field_condition(event,fieldID,formID,fieldType='input'){var brave_form_conditions=brave_popup_formData&&brave_popup_formData[formID]&&brave_popup_formData[formID].conditionsMatch||{};var brave_form_cond_vals=brave_popup_formData&&brave_popup_formData[formID]&&brave_popup_formData[formID].conditionsVals||{};var conditionRules=brave_popup_formData&&brave_popup_formData[formID]&&brave_popup_formData[formID].conditions||{};var inputData=event.target.value;if(fieldType==='checkbox'){inputData='';var checkBoxes=document.querySelectorAll('#brave_form_field'+fieldID+' input');for(var index=0;index0){return} var braveFormNextStepActions=function(){brave_form_changeHeight(formID,goto);var allformSteps=document.querySelectorAll('#brave_form_'+formID+' .brave_form_fields_step');for(var i=0;i0){var ajaxurl=bravepop_global.ajaxURL;var security=document.getElementById('brave_form_security'+formID).value;var emailData={formData:JSON.stringify(emailFields),freemailAllow:JSON.stringify(brave_popup_formData[formID].freemailAllow||false),security:security,action:'bravepopup_validate_email'};brave_ajax_send(ajaxurl,emailData,function(status,sentData){var validatedData=JSON.parse(sentData);console.log('Validation response:',validatedData);var emailValidationErrors=[];if(Array.isArray(validatedData)){validatedData.forEach(function(field){if(field.validation&&field.validation.status==='invalid'&&field.validation.errorMsg){emailValidationErrors.push({id:field.ID,message:field.validation.errorMsg,type:"required"});} if(field.validation&&field.suggestionMsg){emailValidationErrors.push({id:field.ID,message:field.suggestionMsg,type:"info"});}});} if(emailValidationErrors.length>0){brave_display_form_error(emailValidationErrors);if(brave_form){brave_form.classList.remove('brave_form_form--loading');} if(brave_login_loader){brave_login_loader.classList.remove('brave_form_loading--show');}}else{braveFormNextStepActions();}});}else{braveFormNextStepActions();}} function brave_form_changeHeight(formID,goto){var changesFormHeight=brave_popup_formData[formID].changesFormHeight||false;if(changesFormHeight){var braveForm=document.getElementById('brave_element-'+formID);var parentPopupStep=braveForm.closest('.brave_popup__step');var initialHeight=brave_popup_formData[formID].heightData[0];var diffHeight=brave_popup_formData[formID].heightData[goto]-initialHeight;var newFormHeight=brave_popup_formData[formID].heightData[goto]||initialHeight;braveForm.style.height=(parseInt(newFormHeight,10))+'px';if(parentPopupStep){var parentPopupHeight=parentPopupStep.dataset.height;parentPopupStep.querySelector('.brave_popup__step__inner').style.height=(parseInt(parentPopupHeight,10)+diffHeight)+'px';}}} function brave_get_field_vals(braveForm,fieldOpts,quiz){var fieldsData=fieldOpts;var firstname_val='';for(var i=0;i0){var cookiesData={};cookiesToCheck.forEach(function(cookieName){cookiesData[cookieName]=localStorage.getItem(cookieName)?true:false;}) finalData.cookieConditions=JSON.stringify(cookiesData);} if(window.location.href.includes('brave_popup')&&window.location.href.includes('brave_preview')&&location.search.split('brave_preview=')[1]){finalData.brave_previewID=location.search.split('brave_preview=')[1];} var braveSubmitForm=function(){return brave_ajax_send(ajaxurl,finalData,function(status,sentData){if(brave_login_loader){brave_login_loader.classList.remove('brave_form_loading--show');} if(brave_form){brave_form.classList.remove('brave_form_form--loading');} if(document.querySelector('#bravepopupform_socialOptin-'+settings.formID)){document.querySelector('#bravepopupform_socialOptin-'+settings.formID).classList.remove('bravepopupform_socialOptin--loading');document.querySelector('#bravepopupform_socialOptin-'+settings.formID).classList.add('bravepopupform_socialOptin--hide');document.querySelector('#brave_element-'+settings.formID+' .brave_element__form_inner').classList.remove('brave_element__form_inner--hide');} var response=JSON.parse(sentData);console.log(status,response);if(response.error&&typeof response.error==='string'){return alert(response.error);} localStorage.setItem('brave_popup_'+settings.popupID+'_formsubmitted',true);var braveFormSubmitEvent=new CustomEvent('brave_form_submitted',{detail:{popupId:parseInt(settings.popupID,10),formId:settings.formID,formData:JSON.stringify(finalFieldsData)}});document.dispatchEvent(braveFormSubmitEvent);if(brave_form){brave_form.reset();} if(brave_popup_formData[settings.formID]&&brave_popup_formData[settings.formID].totalSteps>0){for(var findx=1;findx=brave_popup_formData[settings.formID].totalScore?'/'+brave_popup_formData[settings.formID].availableScore:'';quizShortcodes[i].innerHTML=''+brave_popup_formData[settings.formID].totalScore+''+availableScoreVal;} if(settings.quizScoring==='answer'){var availableQuesVal=showTotal&&brave_popup_formData[settings.formID].totalQuestions?'/'+brave_popup_formData[settings.formID].totalQuestions:'';quizShortcodes[i].innerHTML=''+brave_popup_formData[settings.formID].totalCorrect+''+availableQuesVal;}}}}});} var braveSubmitWithEmailValidation=function(){var emailData={formData:JSON.stringify(emailFields),freemailAllow:JSON.stringify(brave_popup_formData[settings.formID].freemailAllow||false),security:security,action:'bravepopup_validate_email'};brave_ajax_send(ajaxurl,emailData,function(status,sentData){var validatedData=JSON.parse(sentData);console.log('Validation response:',validatedData);var emailValidationErrors=[];if(Array.isArray(validatedData)){validatedData.forEach(function(field){if(field.validation&&field.validation.status==='invalid'&&field.validation.errorMsg){emailValidationErrors.push({id:field.ID,message:field.validation.errorMsg,type:"required"});} if(field.validation&&field.validation.suggestionMsg&&field.validation.suggestion){emailValidationErrors.push({id:field.ID,message:field.validation.suggestionMsg,type:"suggestion",suggestion:field.validation.suggestion});}});} if(emailValidationErrors.length>0){brave_display_form_error(emailValidationErrors);if(brave_form){brave_form.classList.remove('brave_form_form--loading');} if(brave_login_loader){brave_login_loader.classList.remove('brave_form_loading--show');}}else{braveSubmitForm();}});} if(settings.recaptcha&&grecaptcha){grecaptcha.execute(settings.recaptcha,{action:'submit'}).then(function(token){if(token){var recaptchaData={token:token,security:security,action:'bravepopup_validate_recaptcha'};brave_ajax_send(ajaxurl,recaptchaData,function(status,valid){console.log('Google Recaptcha Verified!');if(valid==='true'){if(bravepop_emailValidation&&emailFields.length>0){braveSubmitWithEmailValidation();}else{braveSubmitForm();}}else{console.error('Google Recaptcha Failed! Spammer Detected!');}});}else{console.error('Google Recaptcha Failed! Could not Fetch Token!');}});}else{if(bravepop_emailValidation&&emailFields.length>0){braveSubmitWithEmailValidation();}else{braveSubmitForm();}}}} function brave_apply_email_suggestion(fieldID,suggestion){document.querySelector('#brave_form_field'+fieldID+' input').value=suggestion;brave_dismiss_email_suggestion(fieldID);} function brave_dismiss_email_suggestion(fieldID){document.querySelector('#brave_form_field'+fieldID).classList.remove('brave_form_field--hasError','brave_form_field--hasSuggestion');} function brave_display_form_error(formErrors){if(formErrors.length>0){formErrors.forEach(function(error){if(error.fieldType&&error.fieldType==='name'){if(error.firstname){document.querySelector('#brave_form_field'+error.id).classList.add('brave_form_field--hasError-firstname');document.querySelector('#brave_form_field'+error.id+' .brave_form_field_error--firstname').innerHTML=error.message;} if(error.lastname){document.querySelector('#brave_form_field'+error.id).classList.add('brave_form_field--hasError-lastname');document.querySelector('#brave_form_field'+error.id+' .brave_form_field_error--lastname').innerHTML=error.message;}}else{document.querySelector('#brave_form_field'+error.id).classList.add('brave_form_field--hasError');document.querySelector('#brave_form_field'+error.id+' .brave_form_field_error').innerHTML=error.message;if(error.type==='suggestion'&&error.suggestion){document.querySelector('#brave_form_field'+error.id).classList.add('brave_form_field--hasSuggestion');var suggestionApplyBtn=''+bravepop_global.yes+'';var suggestionDismissBtn=''+bravepop_global.no+'';var suggestionActions='

'+suggestionApplyBtn+suggestionDismissBtn+'
' document.querySelector('#brave_form_field'+error.id+' .brave_form_field_error').setAttribute('id','brave_form_field_error--suggestion'+error.id) document.querySelector('#brave_form_field'+error.id+' .brave_form_field_error').classList.add('brave_form_field_error--suggestion');document.querySelector('#brave_form_field'+error.id+' .brave_form_field_error').innerHTML=(error.message)+suggestionActions;}}});}} function brave_validate_fields(fieldID,field){if(!field){return} if(field.type==='input'&&field.validation==='name'&&field.required){if(!field.value[0]||!field.value[1]){return{id:fieldID,type:'required',fieldType:'name',message:bravepop_global.field_required,firstname:!field.value[0]?true:false,lastname:!field.value[1]?true:false}}} if(!field.value&&field.required){return{id:fieldID,type:'required',message:bravepop_global.field_required}} if(field.required&&(field.type==='input'||field.type==='textarea'||field.type==='date')){if(field.validation!=='name'&&!field.value.trim()){return{id:fieldID,type:'required',message:bravepop_global.field_required}}} if(field.value&&field.required&&field.type==='select'&&field.value==='none'){return{id:fieldID,type:'required',message:bravepop_global.field_required}} if(field.value&&((field.type==='input'&&field.validation==='text')||field.type==='textarea'||field.type==='date')){if(brave_hasHTML(field.value)){return{id:fieldID,type:'ho_html',message:bravepop_global.no_html_allowed};}} if(field.value&&field.type==='input'&&field.validation==='number'){if(brave_isNumber(field.value)===false){return{id:fieldID,type:'invalid',message:bravepop_global.invalid_number};}} if(field.value&&field.type==='input'&&field.validation==='url'){if(brave_isURL(field.value)===false){return{id:fieldID,type:'invalid',message:bravepop_global.invalid_url};}} if(field.value&&field.type==='date'){if(brave_isDate(field.value)===false){return{id:fieldID,type:'invalid',message:bravepop_global.invalid_date};}} if(field.value&&field.type==='input'&&field.validation==='email'){if(brave_isEmail(field.value)===false){return{id:fieldID,type:'invalid',message:bravepop_global.invalid_email};}}} function brave_hasHTML(value){var doc=new DOMParser().parseFromString(value,"text/html");return Array.from(doc.body.childNodes).some(function(node){return node.nodeType===1});} function brave_isNumber(value){var numberFormat=RegExp(/^[a-zA-Z]+$/);return numberFormat.test(value)?false:true;} function brave_isEmail(value){var mailformat=RegExp(/^\w+([\.+-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+$/);return mailformat.test(value)?true:false;} function brave_isURL(value){var urlFormat=RegExp(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);return urlFormat.test(value)?true:false;} function brave_isDate(value){var dateFormat=RegExp(/\d{1,4}[-/]\d{1,2}[-/]\d{1,4}/);var dateFormatTwo=RegExp(/\d{1,4}[-/]\d{1,2}/);var matchedDate=dateFormat.test(value);if(!matchedDate){matchedDate=dateFormatTwo.test(value);} return matchedDate?true:false;} function brave_ajax_send(ajaxurl,ajaxData,callbackFunction){var array=[];Object.keys(ajaxData).forEach(function(element){array.push(encodeURIComponent(element)+"="+encodeURIComponent(ajaxData[element]))});var dataToSend=array.join("&");var request=new XMLHttpRequest();request.open('POST',ajaxurl,true);request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');request.onload=function(){if(this.status>=200&&this.status<400){callbackFunction('success',this.response);}else{callbackFunction('error',this.response);}};request.send(dataToSend);} function brave_action_step(popupID,currentStep,stepIndex){var selectedPopupStep=document.querySelector('#brave_popup_'+popupID+'__step__'+stepIndex+' .brave_popup__step__'+brave_currentDevice) var noMobileContent=selectedPopupStep&&selectedPopupStep.dataset.nomobilecontent==='true'?true:false;var currentDevice=noMobileContent?'desktop':brave_currentDevice;var selectedPopupStep=document.querySelector('#brave_popup_'+popupID+'__step__'+currentStep+' .brave_popup__step__'+currentDevice) selectedPopupStep.dataset.popopen='false';brave_open_popup(popupID,stepIndex);} function brave_init_popup(popupID,popupData){if(!popupData){return;} brave_responsiveness(null,popupID,popupData);if(popupData.forceLoad){return brave_load_popup(popupID,popupData);} var triggerType=popupData.settings&&popupData.settings.trigger&&popupData.settings.trigger.triggerType?popupData.settings.trigger.triggerType.split(','):['load'];if(popupData.settings&&popupData.settings.placement&&popupData.settings.placement.adblock_check&&window.brave_canRunAds){return console.log('Visitor Doesnt have Ad Blocked Installed! Aborting..');} if((popupData.hasDesktopEmbed||(popupData.hasMobileEmbed&&brave_currentDevice==='mobile'))&&!document.getElementById('bravepopup_embedded_'+popupID)){return console.log('Popup shortcode is not found in current page');} if(popupData.schedule&&popupData.schedule.active&&popupData.schedule.type){if(popupData.schedule.type==='days'&&popupData.schedule.days.length>0){var currentDay=new Date().getDay();if(!popupData.schedule.days.includes(currentDay)){return console.log('Popup Not Scheduled for Today!');}} if(popupData.schedule.type==='dates'&&popupData.schedule.dates.length>0){var thecurrentDate=new Date().getTime();var dateInRange=false;popupData.schedule.dates.forEach(function(date){var theTimes=[];var timeTypes=['start','end'];timeTypes.forEach(function(val){var theDate=date[val].date.split('/');var theHour=date[val].time&&date[val].time.hour?date[val].time.hour:'00';var theMinutes=date[val].time&&date[val].time.minutes?date[val].time.minutes:'00';theTimes.push(new Date(theDate[2]+'/'+theDate[1]+'/'+theDate[0]+' '+theHour+':'+theMinutes+':00').getTime());}) if(theTimes[0]thecurrentDate){dateInRange=true;}});if(!dateInRange){return console.log('Popup Not Scheduled these dates!');}}} if(popupData.settings&&popupData.settings.audience&&popupData.settings.audience.devices&&popupData.settings.audience.devices==="desktop"&&brave_currentDevice==='mobile'){return console.log('Device Settings doesnt Match');} if(popupData.settings&&popupData.settings.audience&&popupData.settings.audience.devices&&popupData.settings.audience.devices==="mobile"&&brave_currentDevice==='desktop'){return console.log('Device Settings doesnt Match');} var popVariants=brave_popup_data[popupID]&&brave_popup_data[popupID].variants?brave_popup_data[popupID].variants:false;var popupRepeatCountType=popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.repeatCountType||'lifetime';var popupRepeatDelay=popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.repeatDelay||false;var popupRepeatDelayTime=popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.repeatDelayTime?parseInt(popupData.settings.frequency.repeatDelayTime,10):false;var repeatCount=popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.repeatCount?parseInt(popupData.settings.frequency.repeatCount,10):3;var filterViewFreq=function(popID){var popupOpenCount=localStorage.getItem('brave_popup_'+popID+'_viewed');var popupOpenSessionCount=sessionStorage.getItem('brave_popup_'+popID+'_viewed');if(popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.repeat&&brave_popup_adminUser===false){if(popupRepeatCountType==='lifetime'&&parseInt(popupOpenCount,10)>=repeatCount){return'Already Viewed '+repeatCount+' Times. Hiding..';} var popupViewStat=localStorage.getItem('brave_popup_'+popID+'_view_stat');popupViewStat=popupViewStat?JSON.parse(popupViewStat):[];var thecurrentDate=new Date();var thecurrentDay=thecurrentDate.getDate();var thecurrentHour=thecurrentDate.getHours();var thecurrentMonth=thecurrentDate.getMonth();var thecurrentYear=thecurrentDate.getFullYear();var popupViewDayCount=0;var popupViewMonthCount=0;var popupView12hCount=0;var popupView6hCount=0;var popupView1hCount=0;var matchedStats=[];if(popupViewStat){popupViewStat.forEach(function(stat){var statDate=new Date(stat);var statDay=statDate.getDate();var statHour=statDate.getHours();var statMonth=statDate.getMonth();var statYear=statDate.getFullYear();if((statDay===thecurrentDay)&&(statMonth===thecurrentMonth)&&(statYear===thecurrentYear)){popupViewDayCount=popupViewDayCount+1;} if((statMonth===thecurrentMonth)&&(statYear===thecurrentYear)){popupViewMonthCount=popupViewMonthCount+1;} if((thecurrentHour-statHour)<12&&(statDay===thecurrentDay)&&(statMonth===thecurrentMonth)&&(statYear===thecurrentYear)){popupView12hCount=popupView12hCount+1;} if((thecurrentHour-statHour)<6&&(statDay===thecurrentDay)&&(statMonth===thecurrentMonth)&&(statYear===thecurrentYear)){popupView6hCount=popupView6hCount+1;} if((thecurrentHour-statHour)<1&&(statDay===thecurrentDay)&&(statMonth===thecurrentMonth)&&(statYear===thecurrentYear)){popupView1hCount=popupView1hCount+1;} if(!matchedStats.includes(stat)){matchedStats.push(stat);}})} matchedStats=matchedStats.sort();var lastViewedTime=matchedStats.length>0?matchedStats[matchedStats.length-1]:0;var viewDelayMatched=popupRepeatDelay&&popupRepeatDelayTime?(thecurrentDate.getTime()-lastViewedTime)>popupRepeatDelayTime:true;var viewCountError='Already Viewed '+repeatCount+' Times in last '+popupRepeatCountType+' Hiding..' console.log(lastViewedTime,thecurrentDate.getTime(),popupRepeatDelayTime,(thecurrentDate.getTime()-lastViewedTime)>popupRepeatDelayTime);if(viewDelayMatched){console.log(lastViewedTime,thecurrentDate.getTime(),popupRepeatDelayTime,(thecurrentDate.getTime()-lastViewedTime)>popupRepeatDelayTime);if(popupRepeatCountType==='12h'&&(parseInt(popupView12hCount,10)>=repeatCount)){return viewCountError;} if(popupRepeatCountType==='6h'&&(parseInt(popupView6hCount,10)>=repeatCount)){return viewCountError;} if(popupRepeatCountType==='1h'&&(parseInt(popupView1hCount,10)>=repeatCount)){return viewCountError;} if(popupRepeatCountType==='session'&&(parseInt(popupOpenSessionCount,10)>=repeatCount)){return viewCountError;} if(popupRepeatCountType==='day'&&(parseInt(popupViewDayCount,10)>=repeatCount)){return viewCountError;} if(popupRepeatCountType==='month'&&(parseInt(popupViewMonthCount,10)>=repeatCount)){return viewCountError;}}else{return'Repeat Delay Doesnt Match! Hiding....';}} return false;} var filterCloseFreq=function(popID){var popupCloseStat=localStorage.getItem('brave_popup_'+popID+'_closed')?JSON.parse(localStorage.getItem('brave_popup_'+popID+'_closed')):null;if(popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.close&&popupCloseStat&&popupCloseStat.closed){var popupCloseCount=popupData.settings.frequency.closeCount?popupData.settings.frequency.closeCount:2;var popupCloseFor=popupData.settings.frequency.closeFor?parseInt(popupData.settings.frequency.closeFor,10)*86400*1000:86400*1000*30;var userCloseCount=parseInt(popupCloseStat.closed,10);var userCloseDate=parseInt(popupCloseStat.closeTime,10);var currentDate=new Date().getTime();var closeTimeDiff=currentDate-userCloseDate;var closeDelayMatched=popupRepeatDelay&&popupRepeatDelayTime?(currentDate-userCloseDate)>popupRepeatDelayTime:true;console.log('##### CLOSING STATS',userCloseCount,popupCloseFor,closeTimeDiff,closeTimeDiff>=popupCloseFor,userCloseCount>=popupCloseCount,closeDelayMatched,currentDate-userCloseDate);if((closeTimeDiff<=popupCloseFor&&(userCloseCount>=popupCloseCount))||!closeDelayMatched){return'Close Time Settings Do not Match';}}} var viewFreqMatch=false;var closeFreqMatch=false;var formFreqMatch=false;goalFreqmatch=false;var hasViewFreqSetting=popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.repeat&&brave_popup_adminUser===false;var hasCloseFreqSetting=popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.close&&brave_popup_adminUser===false;var formFreqSetting=popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.formSubmit&&brave_popup_adminUser===false;var goalFreqSetting=popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.goalComplete&&brave_popup_adminUser===false;if(popVariants.length>0){popVariants.forEach(function(popID){if(!viewFreqMatch&&hasViewFreqSetting){var popViewFreqMatch=filterViewFreq(popID);if(popViewFreqMatch){viewFreqMatch=popViewFreqMatch;}} if(!closeFreqMatch&&hasCloseFreqSetting){var popCloseFreqMatch=filterCloseFreq(popID);if(popCloseFreqMatch){closeFreqMatch=popCloseFreqMatch;}} if(!formFreqMatch&&formFreqSetting&&localStorage.getItem('brave_popup_'+popID+'_formsubmitted')){formFreqMatch=true;} if(!goalFreqmatch&&goalFreqSetting&&localStorage.getItem('brave_popup_'+popID+'_goal_complete')){goalFreqmatch=true;}})}else{if(hasViewFreqSetting){viewFreqMatch=filterViewFreq(popupID);} if(hasCloseFreqSetting){closeFreqMatch=filterCloseFreq(popupID);} if(!formFreqMatch&&formFreqSetting&&localStorage.getItem('brave_popup_'+popupID+'_formsubmitted')){formFreqMatch=true;} if(!goalFreqmatch&&goalFreqSetting&&localStorage.getItem('brave_popup_'+popupID+'_goal_complete')){goalFreqmatch=true;}} if(viewFreqMatch&&hasViewFreqSetting){return console.log('[Viewed Frequency]',popupID,viewFreqMatch);;} if(closeFreqMatch&&hasCloseFreqSetting){return console.log('[Closed Frequency]',popupID,closeFreqMatch);;} if(formFreqMatch&&formFreqSetting){return console.log('[Form Frequency]',popupID,'Form in this Popup already Submitted! Hiding..');} if(goalFreqmatch&&goalFreqSetting){return console.log('[Goal Frequency]',popupID,'Popup Goal Already Completed..');} if(popupData.settings&&popupData.settings.frequency&&popupData.settings.frequency.timerEnded&&popupData.timers.length>0){const timerData=popupData.timers.find(item=>item.device===brave_currentDevice);let hasEnded=false;if(timerData&&timerData.endTime&&new Date()>new Date(timerData.endTime)&&timerData.auto===false){hasEnded=true;} if(timerData&&timerData.auto){const autoEndTime=localStorage.getItem(timerData.auto);if(new Date()>new Date(autoEndTime)){hasEnded=true;}} if(hasEnded){return console.log('Popup Countdown Timer Ended! Hiding..');}} if(popupData.settings&&popupData.settings.filters&&popupData.settings.filters.popups_before&&popupData.settings.filters.popups.length>0){var popupFilterFulfilled=false;popupData.settings.filters.popups.forEach(function(popup){if(!popupFilterFulfilled&&popup.id&&popup.action){var popupActionNegative=popup.action.includes('not_') var popActionKey=popupActionNegative?popup.action.replace('not_',''):popup.action var popupActionMatched=localStorage.getItem('brave_popup_'+popup.id+'_'+popActionKey);if(!popupActionNegative&&popupActionMatched){popupFilterFulfilled=true;} if(popupActionNegative&&!popupActionMatched){popupFilterFulfilled=true;}}}) if(!popupFilterFulfilled){return console.log('A selected Popup was not viewed before! Hiding..');}} if(popupData.settings&&popupData.settings.filters&&popupData.settings.filters.cookieFilter&&popupData.settings.filters.cookies&&popupData.settings.filters.cookies.length>0){var cookieMatched=false;popupData.settings.filters.cookies.forEach(function(cookie){if(!cookieMatched&&cookie.action==='has'&&cookie.key&&localStorage.getItem(cookie.key)){cookieMatched=true;} if(!cookieMatched&&cookie.action==='nothas'&&cookie.key&&!localStorage.getItem(cookie.key)){cookieMatched=true;} if(!cookieMatched&&cookie.action==='equal'&&cookie.key&&cookie.value&&localStorage.getItem(cookie.key)===cookie.value){cookieMatched=true;} if(!cookieMatched&&cookie.action==='notequal'&&cookie.key&&cookie.value&&localStorage.getItem(cookie.key)!==cookie.value){cookieMatched=true;}}) if(cookieMatched===false){return console.log('Visitor Cookie did not match! Hiding..');}} if(popupData.settings&&popupData.settings.filters&&((popupData.settings.filters.pages_count_filter&&popupData.settings.filters.pagecount)||(popupData.settings.filters.pages_before&&popupData.settings.filters.pages))){var viewCountLimit=parseInt(popupData.settings.filters.pagecount,10);var current_page_view_data=localStorage.getItem('brave_page_visited');current_page_view_data=current_page_view_data?JSON.parse(current_page_view_data):[];if(popupData.settings.filters.pages_count_filter&&popupData.settings.filters.pagecount&&current_page_view_data&&(current_page_view_data.length0){var pagesmatched=[];var braveMatchPageViewTime=function(timeLimit,viewTime){if(!timeLimit){return true;} if(viewTime>timeLimit){return true;}else{return false;}} var braveCheckIfViewedPageMatch=function(pageCond,checkExistence=true,timeLimit){var pageCondID=pageCond.id;var pageCondType=pageCond.type;var conditionMatched=false;current_page_view_data.forEach(function(pgView){var timeMatch=braveMatchPageViewTime(timeLimit,pgView.time);var pageMatch=pgView.PID===pageCondID&&pgView.type===pageCondType&&timeMatch;if(pageMatch&&checkExistence){conditionMatched=true;}}) return conditionMatched;} var braveCheckIfNotViewedPageMatch=function(pageCond,checkExistence=false,timeLimit){var pageCondID=pageCond.id;var pageCondType=pageCond.type;var conditionMatched=true;current_page_view_data.forEach(function(pgView){var timeMatch=braveMatchPageViewTime(timeLimit,pgView.time);var pageMatch=pgView.PID===pageCondID&&pgView.type===pageCondType&&timeMatch;if(pageMatch&&!checkExistence){conditionMatched=false;}}) return conditionMatched;} popupData.settings.filters.pages.forEach(function(pageCond){var currentTime=new Date().getTime();var timeLimit=currentTime-10800000;if(pageCond.duration==='lifetime'){timeLimit=false;} if(pageCond.duration==='1day'){timeLimit=currentTime-86400000;}if(pageCond.duration==='7days'){timeLimit=currentTime-604800000;}if(pageCond.duration==='30days'){timeLimit=currentTime-2592000000;} var condMatch=pageCond.action.includes('not_viewed')?braveCheckIfNotViewedPageMatch(pageCond,false,timeLimit):braveCheckIfViewedPageMatch(pageCond,true,timeLimit);pagesmatched.push({matched:condMatch,forced:pageCond.condition==='and'?true:false});}) pagesmatched.forEach(function(matchItm){if(matchItm.forced===true&&matchItm.matched===true){pageConditionMatch.push(true);} if(matchItm.forced===true&&matchItm.matched===false){pageConditionMatch.push(false);} if(matchItm.forced===false&&(matchItm.matched===true||matchItm.matched===false)){pageConditionMatch.push(true);}}) pageConditionMatch.forEach(function(bool){if(bool===false){viewConditionMatched=false;}}) if(!viewConditionMatched){return console.log('Visitor did not view the selected pages before to show the popup! Hiding..');}}} if(triggerType.includes('load')){brave_load_popup(popupID,popupData,'load');} if(triggerType.includes('exit')){if(brave_currentDevice==='mobile'){if(!popupData.settings.trigger.exitMobileFallback||(popupData.settings.trigger.exitMobileFallback&&popupData.settings.trigger.exitMobileFallback.type&&popupData.settings.trigger.exitMobileFallback.type==='load')){brave_load_popup(popupID,popupData,'load');} if(popupData.settings.trigger.exitMobileFallback&&popupData.settings.trigger.exitMobileFallback.type&&popupData.settings.trigger.exitMobileFallback.type==='time'){var exitMobileDelay=popupData.settings.trigger.exitMobileFallback.time||2000;setTimeout(function(){brave_load_popup(popupID,popupData,'time');},(exitMobileDelay*1000));}}else{document.addEventListener("mouseout",function(evt){if((evt.toElement===null||evt.toElement===undefined)&&(evt.relatedTarget===null)){brave_load_popup(popupID,popupData,'exit');}});}} if(triggerType.includes('scroll')||(brave_isMobile&&popupData.settings.trigger.exitMobileFallback&&popupData.settings.trigger.exitMobileFallback.type&&popupData.settings.trigger.exitMobileFallback.type==='scroll')){var currentPopup=document.getElementById('brave_popup_'+popupID+'__step__0');var noMobileContent=currentPopup&&currentPopup.classList.contains('brave_popup__step--mobile-noContent')===true?true:false;var currentDevice=noMobileContent?'desktop':brave_currentDevice;var scrollHide=popupData.settings&&popupData.settings.trigger&&popupData.settings.trigger.scrollHide?true:false;var scrollTriggerPopup=function(scrollPercent,percentLimit=20,currentPopStep,currentPopStepVisible,between=false){var scrollPercentVal=between&&percentLimit.split('-');var startScrollPercent=scrollPercentVal&&scrollPercentVal[0]&&parseInt(scrollPercentVal[0],10);var endScrollPercent=scrollPercentVal&&scrollPercentVal[1]&&parseInt(scrollPercentVal[1],10);if(brave_popup_data[popupID].userClosed){return;} if((!between&&(scrollPercent>=percentLimit))||((between&&!isNaN(startScrollPercent)&&!isNaN(endScrollPercent))&&((scrollPercent>=startScrollPercent)&&(scrollPercent<=endScrollPercent)))){if(!brave_popup_data[popupID].loaded){brave_load_popup(popupID,popupData,'scroll');}else{if(!currentPopStepVisible){brave_open_animation(popupID,0,currentDevice);currentPopStep.dataset.popopen=true;}}}else{if((between||scrollHide)&&currentPopStepVisible){brave_close_animation(popupID,0,currentDevice);currentPopStep.dataset.popopen=false;brave_popup_data[popupID].isOpen=false;}}} document.addEventListener("scroll",function(evt){var h=document.documentElement,b=document.body,st='scrollTop',sh='scrollHeight';var scrollPercent=(h[st]||b[st])/((h[sh]||b[sh])-h.clientHeight)*100;var currentPopStep=document.querySelector('#brave_popup_'+popupID+'__step__0 .brave_popup__step__'+currentDevice);var currentPopStepVisible=currentPopStep&&currentPopStep.dataset.popopen==='true'?true:false;if(brave_isMobile&&(popupData.settings.trigger.exitMobileFallback&&popupData.settings.trigger.exitMobileFallback.type&&popupData.settings.trigger.exitMobileFallback.type==='scroll')){var exitMobielScroll=popupData.settings.trigger.exitMobileFallback.scroll||15;if(scrollPercent>=exitMobielScroll){brave_load_popup(popupID,popupData,'scroll');}} if(popupData.settings&&popupData.settings.trigger.scrolltype&&popupData.settings.trigger.scrolltype!=='between'){var srollTargetAmnt=0;if(popupData.settings.trigger.scrolltype==='ten'){srollTargetAmnt=10} if(popupData.settings.trigger.scrolltype==='twenty'){srollTargetAmnt=20} if(popupData.settings.trigger.scrolltype==='thirty'){srollTargetAmnt=30} if(popupData.settings.trigger.scrolltype==='forty'){srollTargetAmnt=40} if(popupData.settings.trigger.scrolltype==='half'){srollTargetAmnt=50} if(popupData.settings.trigger.scrolltype==='sixty'){srollTargetAmnt=60} if(popupData.settings.trigger.scrolltype==='seventy'){srollTargetAmnt=70} if(popupData.settings.trigger.scrolltype==='eighty'){srollTargetAmnt=80} if(popupData.settings.trigger.scrolltype==='end'){srollTargetAmnt=95} scrollTriggerPopup(scrollPercent,srollTargetAmnt,currentPopStep,currentPopStepVisible);} if(popupData.settings&&popupData.settings.trigger&&popupData.settings.trigger.scrolltype==='between'&&popupData.settings.trigger.scrollBetween&&popupData.settings.trigger.scrollBetween.includes('-')){scrollTriggerPopup(scrollPercent,popupData.settings.trigger.scrollBetween,currentPopStep,currentPopStepVisible,true);} if(popupData.settings&&popupData.settings.trigger.scrolltype&&popupData.settings.trigger.scrollto&&popupData.settings.trigger.scrolltype==='custom'){var scrollToIDs=popupData.settings.trigger.scrollto||'';var scrolltoElms=scrollToIDs&&document.querySelectorAll(scrollToIDs);if(scrollToIDs&&scrolltoElms){for(var i=0;i-20)&&!contenthlElm.classList.contains('bravepopup_embedded__bg--active')){contenthlElm.classList.add('bravepopup_embedded__bg--active');contentElm.classList.add('bravepopup_embedded__highlight--active');} if((embeddedViewRatio<-20||embeddedViewRatio>50)&&contenthlElm.classList.contains('bravepopup_embedded__bg--active')){contenthlElm.classList.remove('bravepopup_embedded__bg--active');contentElm.classList.remove('bravepopup_embedded__highlight--active');if(popupData.settings.content.highlight){contentElm.classList.add('bravepopup_embedded__highlight--done');}}}},{passive:true});} if(triggerType.includes('click')&&popupData.settings&&popupData.settings.trigger.clickElements){var clickElms=document.querySelectorAll(popupData.settings.trigger.clickElements);if(clickElms){for(var i=0;i0){for(var i=0,len=dateFields.length;i