(function($) {
"use strict";
$(document).ready(function(){
let bsaProCalendar = $(".bsa_pro_calendar");
let sid = $("#bsa_pro_space_id");
let dates = ;
let bsaCalendar = 'yes';
if ( dates && bsaCalendar === 'yes' ) {
if ( dates !== '' ) {
if ( dates !== null ) {
sid.on("change",function() {
bsaProCalendar.datepicker({
dateFormat : "yy-mm-dd",
firstDay: 0,
closeText: "Done",
prevText: "Prev",
nextText: "Next",
currentText: "Today",
monthNames: [ "January","February","March","April","May","June","July","August","September","October","November","December" ],
monthNamesShort: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
dayNames: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
dayNamesShort: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
dayNamesMin: [ "Su","Mo","Tu","We","Th","Fr","Sa" ],
weekHeader: "Wk", isRTL: true,
minDate: 0,
beforeShowDay: function(date){
let string = jQuery.datepicker.formatDate("yy-mm-dd", date);
return [ dates[sid.val()].indexOf(string) === -1, "bsaProUnavailableDate" ]
},
beforeShow: function(input, inst) {
$('#ui-datepicker-div').addClass('bsaProCalendar');
}
});
});
}
} else {
let d = new Date();
bsaProCalendar.datepicker({
dateFormat : "yy-mm-dd",
firstDay: 0,
closeText: "Done",
prevText: "Prev",
nextText: "Next",
currentText: "Today",
monthNames: [ "January","February","March","April","May","June","July","August","September","October","November","December" ],
monthNamesShort: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
dayNames: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
dayNamesShort: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
dayNamesMin: [ "Su","Mo","Tu","We","Th","Fr","Sa" ],
weekHeader: "Wk", isRTL: true,
minDate: 0,
beforeShowDay: function(date){
let string = jQuery.datepicker.formatDate("yy-mm-dd", date);
return [ (d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + (d.getDay() - 1) ).indexOf(string) === -1, "bsaProUnavailableDate" ]
},
beforeShow: function(input, inst) {
$('#ui-datepicker-div').addClass('bsaProCalendar');
}
});
}
}
let inputTitle = $("#bsa_pro_title");
let inputDesc = $("#bsa_pro_desc");
let inputButton = $("#bsa_pro_button");
let inputUrl = $("#bsa_pro_url");
inputTitle.keyup(function() { bsaPreviewInput("title"); });
inputDesc.keyup(function() { bsaPreviewInput("desc"); });
inputButton.keyup(function() { bsaPreviewInput("button"); });
inputUrl.keyup(function() { bsaPreviewInput("url"); });
sid.on("change",function() {
bsaGetBillingModels();
bsaTemplatePreview();
$(".bsaUrlSpaceId").html($("#bsa_pro_space_id").val());
});
sid.trigger("change");
});
})(jQuery);
function bsaGetBillingModels() {
(function($) {
"use strict";
let getBillingModels = $(".bsaGetBillingModels");
let bsaLoaderModels = $(".bsaLoaderModels");
getBillingModels.slideUp();
bsaLoaderModels.fadeIn(400);
setTimeout(function(){
$.post("https://beta.whatson.guide/wp-admin/admin-ajax.php", {action:"bsa_get_billing_models_callback",bsa_space_id:$("#bsa_pro_space_id").val(),bsa_order:1}, function(result) {
getBillingModels.html(result).slideDown();
bsaLoaderModels.fadeOut(400);
});
}, 700);
})(jQuery);
}
function bsaTemplatePreview() {
(function($) {
"use strict";
let bsaTemplatePreviewInner = $(".bsaTemplatePreviewInner");
let bsaLoaderPreview = $(".bsaLoaderPreview");
bsaTemplatePreviewInner.slideUp(400);
bsaLoaderPreview.fadeIn(400);
setTimeout(function(){
$.post("https://beta.whatson.guide/wp-admin/admin-ajax.php", {action:"bsa_preview_callback",bsa_space_id:$("#bsa_pro_space_id").val(),bsa_ad_id:$("#bsa_pro_ad_id").val()}, function(result) {
bsaTemplatePreviewInner.html(result).slideDown(400);
bsaGetRequiredInputs();
let inputTitle = $("#bsa_pro_title");
let inputDesc = $("#bsa_pro_desc");
let inputButton = $("#bsa_pro_button");
let inputUrl = $("#bsa_pro_url");
if ( inputTitle.val().length > 0 ) { bsaPreviewInput("title"); }
if ( inputDesc.val().length > 0 ) { bsaPreviewInput("desc"); }
if ( inputButton.val().length > 0 ) { bsaPreviewInput("button"); }
if ( inputUrl.val().length > 0 ) { bsaPreviewInput("url"); }
bsaLoaderPreview.fadeOut(400);
});
}, 700);
})(jQuery);
}
function bsaGetRequiredInputs() {
(function($) {
"use strict";
let bsaLoaderInputs = $(".bsaLoaderInputs");
bsaLoaderInputs.fadeIn(400);
$.post("https://beta.whatson.guide/wp-admin/admin-ajax.php", {action:"bsa_required_inputs_callback",bsa_space_id:$("#bsa_pro_space_id").val(),bsa_get_required_inputs:1}, function(result) {
$(".bsa_inputs_required").val($.trim(result));
if ( result.indexOf("title") !== -1 ) { // show if title required
$(".bsa_title_inputs_load").fadeIn();
} else {
$(".bsa_title_inputs_load").fadeOut();
}
if ( result.indexOf("desc") !== -1 ) { // show if description required
$(".bsa_desc_inputs_load").fadeIn();
} else {
$(".bsa_desc_inputs_load").fadeOut();
}
if ( result.indexOf("button") !== -1 ) { // show if button required
$(".bsa_button_inputs_load").fadeIn();
} else {
$(".bsa_button_inputs_load").fadeOut();
}
if ( result.indexOf("url") !== -1 ) { // show if url required
$(".bsa_url_inputs_load").fadeIn();
} else {
$(".bsa_url_inputs_load").fadeOut();
}
if ( result.indexOf("img") !== -1 ) { // show if img required
$(".bsa_img_inputs_load").fadeIn();
let bsaTemplatePreviewInner = $('.bsaTemplatePreviewInner');
if ( bsaTemplatePreviewInner.attr('data-img') ) {
$(".bsaTemplatePreviewForm .bsaProItemInner__img").css({"background-image" : "url(" + bsaTemplatePreviewInner.attr('data-img') + ")"});
}
} else {
$(".bsa_img_inputs_load").fadeOut();
}
if ( result.indexOf("html") !== -1 ) { // show if html required
$(".bsa_html_inputs_load").fadeIn();
} else {
$(".bsa_html_inputs_load").fadeOut();
}
bsaLoaderInputs.fadeOut(400);
});
})(jQuery);
}
function bsaPreviewInput(inputName) {
(function($){
"use strict";
$(document);
let input = $("#bsa_pro_" + inputName);
let sign = $(".bsa_pro_sign_" + inputName);
let limit = input.attr("maxLength");
let bsaProContainerExample = $(".bsaProContainerExample");
let exampleTitle = "Example title";
let exampleDesc = "Example description";
let exampleButton = "Example button";
let exampleUrl = "https://example.com";
sign.text(limit - input.val().length);
input.keyup(function() {
if (input.val().length > limit) {
input.val($(this).val().substring(0, limit));
}
});
if (input.val().length > 0) {
if ( inputName === "title" ) {
bsaProContainerExample.find(".bsaProItemInner__" + inputName).html(input.val());
} else if ( inputName === "desc" ) {
bsaProContainerExample.find(".bsaProItemInner__" + inputName).html(input.val());
} else if ( inputName === "button" ) {
bsaProContainerExample.find(".bsaProItemInner__" + inputName).html(input.val());
} else if ( inputName === "url" ) {
let url_protocol = (input.val().search("https") > 0 ? 'https://' : 'http://');
bsaProContainerExample.find(".bsaProItemInner__" + inputName).html(url_protocol + input.val().replace("http://","").replace("https://","").replace("www.","").split(/[/?#]/)[0]);
}
} else {
if ( inputName === "title" ) {
bsaProContainerExample.find(".bsaProItemInner__" + inputName).html(exampleTitle);
} else if ( inputName === "desc" ) {
bsaProContainerExample.find(".bsaProItemInner__" + inputName).html(exampleDesc);
} else if ( inputName === "button" ) {
bsaProContainerExample.find(".bsaProItemInner__" + inputName).html(exampleButton);
} else if ( inputName === "url" ) {
let url_protocol = (exampleUrl.search("https") > 0 ? 'https://' : 'http://');
bsaProContainerExample.find(".bsaProItemInner__" + inputName).html(url_protocol + exampleUrl.replace("http://","").replace("https://","").replace("www.","").split(/[/?#]/)[0]);
}
}
})(jQuery);
}
function bsaPreviewThumb(input) {
(function($){
"use strict";
if (input.files[0]) {
let reader = new FileReader();
reader.onload = function (e) {
$(".bsaTemplatePreviewForm .bsaProItemInner__img").css({"background-image" : "url(" + e.target.result + ")"});
};
reader.readAsDataURL(input.files[0]);
}
})(jQuery);
}
(function($){
"use strict";
let bsaProOrderingForm = $('.bsaProNewForm');
let bsaProOrderingBtn = $('.bsaProNewForm .bsaProSubmit');
bsaProOrderingBtn.on('click', function(e){
let error = null;
let bsa_pro_buyer_email = $('#bsa_pro_buyer_email').val();
if ( bsa_pro_buyer_email === '' || bsa_pro_buyer_email === ' ' || bsa_pro_buyer_email === ' ' ) {
error = 'empty';
}
if ( $('.bsa_title_inputs_load').is(':visible') && $('#bsa_pro_title').val() === '' ||
$('.bsa_desc_inputs_load').is(':visible') && $('#bsa_pro_desc').val() === '' ||
$('.bsa_url_inputs_load').is(':visible') && $('#bsa_pro_url').val() === '' ||
$('.bsa_img_inputs_load').is(':visible') && $('#bsa_pro_img').val() === '' ||
$('.bsa_calendar_inputs_load').is(':visible') && $('#bsa_pro_calendar').val() === '' && $("#bsa_pro_space_id option:selected").attr("max") == 1 )
{
error = 'empty';
}
if ( $('input[name="ad_model"]:checked', '.bsaProOrderingForm').length && $('input[name="ad_limit_cpc"]:checked', '.bsaProOrderingForm').length ||
$('input[name="ad_model"]:checked', '.bsaProOrderingForm').length && $('input[name="ad_limit_cpm"]:checked', '.bsaProOrderingForm').length ||
$('input[name="ad_model"]:checked', '.bsaProOrderingForm').length && $('input[name="ad_limit_cpd"]:checked', '.bsaProOrderingForm').length )
{
// checked
} else {
error = 'empty';
}
if ( error !== null ) {
e.preventDefault();
$('html, body').animate({
scrollTop: bsaProOrderingForm.offset().top - 40
}, 100);
$('.bsaProAlertFailed').fadeIn();
} else {
$('.bsaProAlertFailed').hide();
}
});
})(jQuery);