(function($){
"use strict";
$(document).ready(function(){
$(".listeo_core-dashboard-action-delete").click(function (e){
e.preventDefault();
if(window.confirm(listeo_core.areyousure)){
location.href=this.href;
}});
$("body").on("click", ".listeo_core-bookmark-it", function (e){
e.preventDefault();
if($(this).is(".clicked,.liked")){
return;
}
$(this).addClass("clicked");
var post_id=$(this).data("post_id"),
handler=$(this),
nonce=$(this).data("nonce"),
addedtolist=$(this).data("saved-title");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_core_bookmark_this",
post_id: post_id,
nonce: nonce,
},
success: function (response){
console.log(response);
if(response.type=="success"){
handler
.removeClass("listeo_core-bookmark-it")
.addClass("liked")
.addClass("listeo_core-unbookmark-it")
.removeClass("clicked");
if(handler.hasClass("fa-regular")){
handler.removeClass("fa-regular");
handler.addClass("fa-solid");
}
var confirmed=handler.data("confirm");
handler
.children(".like-icon")
.addClass("liked")
.removeClass("clicked")
.parent()
.html('<span class="like-icon liked"></span> ' + confirmed);
}else{
handler.removeClass("clicked");
handler.children(".like-icon").removeClass("liked");
}},
});
});
$(".listeo_core-unbookmark-it").on("click", function (e){
e.preventDefault();
var handler=$(this);
var post_id=$(this).data("post_id");
var nonce=$(this).data("nonce");
handler.closest("li").addClass("opacity-05");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_core_unbookmark_this",
post_id: post_id,
nonce: nonce,
},
success: function (response){
console.log(handler);
console.log(response);
if(response.type=="success"){
handler.closest("li").fadeOut();
if(handler.hasClass("fa-solid")){
handler.removeClass("fa-solid");
handler.addClass("fa-regular");
}
handler.removeClass("clicked");
handler.removeClass("liked");
handler.children(".like-icon").removeClass("liked");
}else{
handler.closest("li").removeClass("opacity-05");
}},
});
});
$(".add-listing-section.type-selection a").on("click", function (e){
e.preventDefault();
var type=$(this).data("type");
$("#listing_type").val(type);
$("#submit-listing-form").submit();
});
$(".add-listing-section.type-selection a").on("click", function (e){
e.preventDefault();
var type=$(this).data("type");
$("#listing_type").val(type);
$("#submit-listing-form").submit();
});
var elements=document.querySelectorAll("input,select,textarea");
for (var i=elements.length; i--;){
elements[i].addEventListener("invalid", function (){
this.scrollIntoView(false);
});
}
$("#_normal_price").on("input", function (e){
e.preventDefault();
var price=$(this).val();
$(".listeo-calendar-day:not(.weekend) .calendar-price span").html(price);
submit_calendar_update_price();
});
$("#_weekend_price,#_weekday_price").on("input", function (e){
e.preventDefault();
var price=$(this).val();
$(".listeo-calendar-day.weekend .calendar-price span").html(price);
submit_calendar_update_price();
});
$(".add-listing-section.availability_calendar").on("click",
".prev",
function (event){
var month=$(this).data("prev-month");
var year=$(this).data("prev-year");
getCalendar(month, year);
}
);
$(".add-listing-section.availability_calendar").on("click",
".next",
function (event){
var month=$(this).data("next-month");
var year=$(this).data("next-year");
getCalendar(month, year);
}
);
$(".add-listing-section.availability_calendar").on("blur",
"#currentYear",
function (event){
var month=$("#currentMonth").text();
var year=$("#currentYear").text();
getCalendar(month, year);
}
);
function getCalendar(month, year){
$.ajax({
type: "post",
dataType: "json",
url: listeo_core.ajax_url,
data: { action: "listeo_core_calendar", month: month, year: year },
success: function (data){
$("#listeo-calendar-outer").html(data.response);
var _normal_price=$("#_normal_price").val();
$(".listeo-calendar-day:not(.weekend) .calendar-price span").html(_normal_price
);
var _weekend_price=$("#_weekday_price").val();
$(".listeo-calendar-day.weekend .calendar-price span").html(_weekend_price
);
submit_calendar_update_price();
submit_calendar_update_unav_days();
},
});
}
function submit_calendar_update_unav_days(){
var days=$(".listeo-calendar-avail").val();
if(days){
var array=days.split("|");
$.each(array, function (key, day){
if(day){
$("td.listeo-calendar-day[data-date='" + day + "']").addClass("not_active"
);
}});
}}
function submit_calendar_update_price(){
var prices=$(".listeo-calendar-price").val();
if(prices){
var obj=JSON.parse(prices);
$.each(obj, function (day, price){
if(day){
$(
"td.listeo-calendar-day[data-date='" +
day +
"'] .calendar-price span"
).text(price);
}});
}}
var _normal_price=$("#_normal_price").val();
$(".listeo-calendar-day:not(.weekend) .calendar-price span").html(_normal_price
);
var _weekend_price=$("#_weekday_price").val();
$(".listeo-calendar-day.weekend .calendar-price span").html(_weekend_price);
submit_calendar_update_price();
submit_calendar_update_unav_days();
$(document).on("submit", "form", function (){
var $form=$(this);
if(!$form.find(".availability-slots").length) return;
var slot_container=0;
var slots=[];
$form.find(".slots-container").each(function (){
var inside_slots=[];
var slot_number=0;
$(this)
.find(".single-slot-time")
.each(function (){
var $row=$(this).closest(".single-slot");
if($row.hasClass("cloned")) return;
var timeText=$(this).text()
.replace(/[–—]/g, "-")
.replace(/\s+u201[34]\s+/g, " - ");
inside_slots[slot_number] =
timeText + "|" + $row.find('input[name="slot-qty"]').val();
slot_number++;
});
slots[slot_container]=inside_slots;
slot_container++;
});
$form.find("#_slots, input[type='hidden'][name='_slots']")
.val(JSON.stringify(slots));
});
$("#listeo-activities-list a.close-list-item").on("click", function (e){
var $this=$(this),
id=$(this).data("id"),
nonce=$(this).data("nonce");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "remove_activity",
id: id,
nonce: nonce,
},
success: function (data){
if(data.success==true){
$this
.parent()
.addClass("wait")
.fadeOut("normal", function (){
$this.remove();
});
}else{
}},
});
e.preventDefault();
});
$("#listeo-clear-activities").on("click", function (e){
var $this=$(this),
nonce=$(this).data("nonce");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "remove_all_activities",
nonce: nonce,
},
success: function (data){
if(data.success==true){
$("ul#listeo-activities-list li:not(.cleared)").remove();
$("li.cleared").show();
$this.parent().parent().find(".pagination-container").remove();
}else{
}},
});
e.preventDefault();
});
$("select#sort-reviews-by").on("change", function (e){
var button=$(this);
button.parents(".dashboard-list-box").addClass("loading");
var page=button.find("#reviews_list_visitors").data("page");
var post_id=$(this).val();
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "reload_reviews",
id: post_id,
page: page,
},
success: function (data){
button.parents(".dashboard-list-box").removeClass("loading");
if(data.success==true){
$("#reviews_list_visitors").html(data.comments);
$("#visitor-reviews-pagination").html(data.pagination);
$(".popup-with-zoom-anim").magnificPopup({
type: "inline",
fixedContentPos: false,
fixedBgPos: true,
overflowY: "auto",
closeBtnInside: true,
preloader: false,
midClick: true,
removalDelay: 300,
mainClass: "my-mfp-zoom-in",
});
}else{
console.log("error");
}},
});
e.preventDefault();
});
$("#visitor-reviews-pagination").on("click", "a", function (e){
var page=$(this).parent().data("paged");
var post_id=$("#sort-reviews-by").val();
$(".reviews-visitior-box").addClass("loading");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "reload_reviews",
id: post_id,
page: page,
},
success: function (data){
$(".reviews-visitior-box").removeClass("loading");
if(data.success==true){
$("#reviews_list_visitors").html(data.comments);
$("#visitor-reviews-pagination").html(data.pagination);
$(".popup-with-zoom-anim").magnificPopup({
type: "inline",
fixedContentPos: false,
fixedBgPos: true,
overflowY: "auto",
closeBtnInside: true,
preloader: false,
midClick: true,
removalDelay: 300,
mainClass: "my-mfp-zoom-in",
});
}else{
console.log("error");
}},
});
e.preventDefault();
});
$(".reviews-visitior-box").on("click", ".reply-to-review-link", function (e){
$("#comment_reply").val();
var post_id=$(this).data("postid");
var review_id=$(this).data("replyid");
$("#send-comment-reply input#reply-post-id").val(post_id);
$("#send-comment-reply input#reply-review-id").val(review_id);
});
$(".reviews-visitior-box").on("click", ".edit-reply", function (e){
$("#send-comment-edit-reply textarea#comment_reply").val("");
var comment_id=$(this).data("comment-id");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "get_comment_review_details",
comment: comment_id,
},
success: function (data){
var comment_content=data.comment_content;
$("#send-comment-edit-reply textarea#comment_reply").val(comment_content
);
},
});
$("#send-comment-edit-reply input#reply_id").val(comment_id);
});
$("#send-comment-edit-reply").on("submit", function (e){
$("#send-comment-edit-reply button").addClass("loading");
var content=$(this).find("textarea#comment_reply").val();
var reply_id=$(this).find("input#reply_id").val();
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "edit_reply_to_review",
reply_id: $(this).find("input#reply_id").val(),
content: content,
},
success: function (data){
if(data.success==true){
$("#send-comment-edit-reply button").removeClass("loading");
$('.edit-reply[data-comment-id="' + reply_id + '"]').data("comment-content",
content
);
$(".mfp-close").trigger("click");
}else{
$("#send-comment-edit-reply button").removeClass("loading");
}},
});
e.preventDefault();
});
$("#send-comment-reply").on("submit", function (e){
$("#send-comment-reply button").addClass("loading");
var review_id=$(this).find("input#reply-review-id").val();
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "reply_to_review",
post_id: $(this).find("input#reply-post-id").val(),
review_id: review_id,
content: $(this).find("textarea#comment_reply").val(),
},
success: function (data){
console.log(data);
if(data.success==true){
$("#send-comment-reply button").removeClass("loading");
$(".mfp-close").trigger("click");
$("#review-" + review_id + " .reply-to-review-link")
.html('<i class="sl sl-icon-check"></i> ' + listeo_core.replied)
.off("click");
}else{
$("#send-comment-reply button").removeClass("loading");
}},
});
e.preventDefault();
});
var critera=listeo_core.review_criteria.split(",");
$(".your-reviews-box").on("click", ".edit-review", function (e){
$("#send-comment-edit-review input[type=radio]").prop("checked", false);
$("#send-comment-edit-review textarea#comment_reply").val("");
$(".message-reply").addClass("loading");
var comment_id=$(this).data("comment-id");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "get_comment_review_details",
comment: comment_id,
},
success: function (data){
$("#send-comment-edit-review input#reply_id").val(comment_id);
$("#send-comment-edit-review input#rating-" + data.comment_rating).prop("checked",
true
);
$(".sub-ratings-container").html(data.ratings);
$("#send-comment-edit-review textarea#comment_reply").val(data.comment_content
);
$(".message-reply").removeClass("loading");
},
});
});
$(".listeo_core-dashboard-delete-review").click(function (e){
e.preventDefault();
if(window.confirm(listeo_core.areyousure)){
location.href=this.href;
}});
function get_url_extension(url){
return url.split(/\#|\?/)[0].split(".").pop().trim();
}
$("body").on("submit", ".ical-import-form", function (e){
e.preventDefault();
$(this).find("button").addClass("loading");
$("input.import_ical_url").removeClass("bounce");
var form=$(this);
var listing_id=$(this).data("listing-id");
var name=$(this).find("input.import_ical_name").val();
var url=$(this).find("input.import_ical_url").val();
var force_update=$(this)
.find("input.import_ical_force_update")
.prop("checked");
var filetype=get_url_extension(url);
var valid_filetypes=["ical", "ics", "ifb", "icalendar", "calendar"];
var urlLower=url.toLowerCase();
if(urlLower.indexOf("calendar")!==-1 ||
urlLower.indexOf("accommodation_id")!==-1 ||
urlLower.indexOf("ical")!==-1 ||
urlLower.indexOf("airtable.com")!==-1 ||
$.inArray(filetype, valid_filetypes) > -1
){
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "add_new_listing_ical",
name: name,
url: url,
listing_id: listing_id,
force_update: force_update,
},
success: function (data){
if(data.type=="success"){
form.find("button").removeClass("loading");
form.find("input.import_ical_name").val("");
form.find("input.import_ical_url").val("");
form
.parents(".ical-import-dialog")
.find(".saved-icals")
.html(data.output);
$(".ical-import-dialog .notification")
.removeClass("error notice")
.addClass("success")
.show()
.html(data.notification);
}
if(data.type=="error"){
form.find("button").removeClass("loading");
$(".ical-import-dialog .notification")
.removeClass("success notice")
.addClass("error")
.show()
.html(data.notification);
}},
});
}else{
$(this).find("button").removeClass("loading");
$("input.import_ical_url").addClass("bounce");
window.setTimeout(function (){
$("input.import_ical_url").removeClass("bounce");
}, 1000);
}});
$("body").on("click", "a.ical-remove", function (e){
e.preventDefault();
var $this=$(this),
index=$(this).data("remove"),
nonce=$(this).data("nonce");
var listing_id=$(this).data("listing-id");
$this.parents(".saved-icals").addClass("loading");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "add_remove_listing_ical",
index: index,
listing_id: listing_id,
},
success: function (data){
if(data.type=="success"){
$this
.parents(".saved-icals")
.removeClass("loading")
.html(data.output);
}
$(".ical-import-dialog .notification").show().html(data.notification);
},
});
});
$("body").on("click", "a.ical-force-toggle", function (e){
e.preventDefault();
var $this=$(this),
index=$(this).data("index"),
listing_id=$(this).data("listing-id");
$this.parents(".saved-icals").addClass("loading");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "toggle_listing_ical_force_update",
index: index,
listing_id: listing_id,
},
success: function (data){
var $wrap=$this.parents(".saved-icals").removeClass("loading");
if(data.type=="success"){
$wrap.html(data.output);
}
$(".ical-import-dialog .notification").show().html(data.notification);
},
});
});
$("body").on("click", "a.update-all-icals", function (e){
e.preventDefault();
var $this=$(this),
listing_id=$(this).data("listing-id");
$this.addClass("loading");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "refresh_listing_import_ical",
listing_id: listing_id,
},
success: function (data){
$this.removeClass("loading");
if(data.type=="success"){
$(".ical-import-dialog .notification")
.removeClass("error notice")
.addClass("success")
.show()
.html(data.notification);
}else if(data.type=="error"){
$(".ical-import-dialog .notification")
.removeClass("success notice")
.addClass("error")
.show()
.html(data.notification);
}},
});
});
$("#send-comment-edit-review").on("submit", function (e){
$("#send-comment-edit-review button").addClass("loading");
var button=$(this);
var content=$(this).find("textarea#comment_reply").val();
var reply_id=$(this).find("input#reply_id").val();
var reply_rating=$(this).find('input[type="radio"]:checked').val();
var data={
action: "edit_review",
reply_id: $(this).find("input#reply_id").val(),
content: content,
};
$.each(critera, function (index, value){
data["rating_" + value]=button
.find('input[type="radio"][name="' + value + '"]:checked')
.val();
});
console.log(data);
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: data,
success: function (data){
if(data.success==true){
$("#send-comment-edit-review button").removeClass("loading");
$(".mfp-close").trigger("click");
}else{
$("#send-comment-edit-review button").removeClass("loading");
}},
});
e.preventDefault();
});
$("a.listeo_core-rate-review").on("click", function (e){
e.preventDefault();
var $this=$(this),
comment=$(this).data("comment"),
nonce=$(this).data("nonce");
if($this.data("processing")){
return false;
}
$this.data("processing", true);
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_core_rate_review",
comment: comment,
},
success: function (data){
$this.html(data.output);
},
complete: function (){
$this.data("processing", false);
},
});
e.preventDefault();
});
$("#send-message-from-widget").on("submit", function (e){
$("#send-message-from-widget button")
.addClass("loading")
.prop("disabled", true);
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_send_message",
recipient: $(this).find("textarea#contact-message").data("recipient"),
referral: $(this).find("textarea#contact-message").data("referral"),
message: $(this).find("textarea#contact-message").val(),
},
success: function (data){
if(data.type=="success"){
$("#send-message-from-widget button").removeClass("loading");
$("#send-message-from-widget .notification")
.show()
.html(data.message);
window.setTimeout(closepopup, 3000);
$(this).find("textarea#contact-message").val("");
}else{
$("#send-message-from-widget .notification")
.removeClass("success")
.addClass("error")
.show()
.html(data.message);
$("#send-message-from-widget button")
.removeClass("loading")
.prop("disabled", false);
}},
});
e.preventDefault();
});
function closepopup(){
var magnificPopup=$.magnificPopup.instance;
if(magnificPopup){
magnificPopup.close();
$("#send-message-from-widget button")
.removeClass("loading")
.prop("disabled", false);
}}
$(document).on("change", "#message-attachment", function (e){
var file=this.files[0];
if(file){
var fileName=file.name;
var fileSize=file.size;
var maxSize=10 * 1024 * 1024;
if(fileSize > maxSize){
alert("File size exceeds 10MB limit");
this.value="";
return;
}
$(".attachment-preview").show();
$(".attachment-preview-name").text(fileName);
$(".attachment-label").hide();
var formData=new FormData();
formData.append("attachment", file);
formData.append("conversation_id", $("#conversation_id").val());
formData.append("nonce", $("#messages_nonce").val());
formData.append("action", "listeo_upload_message_attachment");
$(".attachment-upload-progress").show();
$(".attachment-preview").hide();
$.ajax({
url: listeo.ajaxurl,
type: "POST",
data: formData,
processData: false,
contentType: false,
xhr: function (){
var xhr=new window.XMLHttpRequest();
xhr.upload.addEventListener("progress",
function (evt){
if(evt.lengthComputable){
var percentComplete=(evt.loaded / evt.total) * 100;
$(".progress-fill").css("width", percentComplete + "%");
}},
false
);
return xhr;
},
success: function (response){
if(response.success){
$("#attachment_id").val(response.data.attachment_id);
$(".attachment-upload-progress").hide();
$(".attachment-preview").show();
}else{
alert(response.data);
$(".attachment-upload-progress").hide();
$(".attachment-label").show();
$("#message-attachment").val("");
}},
error: function (){
alert("Upload failed. Please try again.");
$(".attachment-upload-progress").hide();
$(".attachment-label").show();
$("#message-attachment").val("");
},
});
}});
$(document).on("click", ".remove-attachment", function (e){
e.preventDefault();
$("#message-attachment").val("");
$("#attachment_id").val("");
$(".attachment-preview").hide();
$(".attachment-label").show();
});
$("#send-message-from-chat").on("submit", function (e){
var message=$(this).find("textarea#contact-message").val();
var attachment_id=$(this).find("input#attachment_id").val();
if(message||attachment_id){
$(this).find("textarea#contact-message").removeClass("error");
$(".loading").show();
$(this).find("button").prop("disabled", true);
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_send_message_chat",
recipient: $(this).find("input#recipient").val(),
conversation_id: $(this).find("input#conversation_id").val(),
message: message,
attachment_id: attachment_id,
},
success: function (data){
if(data.type=="success"){
$(this).addClass("success");
refreshMessages();
$("#send-message-from-chat textarea").val("");
$("#send-message-from-chat button").prop("disabled", false);
$("#attachment_id").val("");
$("#message-attachment").val("");
$(".attachment-preview").hide();
$(".attachment-label").show();
}else{
$(this).addClass("error");
}},
});
}else{
$(this).find("textarea#contact-message").addClass("error");
}
e.preventDefault();
});
$(document).on("click", ".booking-message", function (e){
var recipient=$(this).data("recipient");
var referral=$(this).data("booking_id");
$("#send-message-from-widget textarea").val("");
$("#send-message-from-widget .notification").hide();
$("#send-message-from-widget textarea")
.data("referral", referral)
.data("recipient", recipient);
$(".send-message-to-owner").trigger("click");
});
function refreshMessages(){
if($(".message-bubbles").length){
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_get_conversation",
conversation_id: $(
"#send-message-from-chat input#conversation_id"
).val(),
},
success: function (data){
if(data.type=="success"){
$(".message-bubbles").html(data.message);
}
$(".loading").hide();
},
complete: function (){
setTimeout(refreshMessages, 4000);
},
});
}}
setTimeout(refreshMessages, 4000);
if($("#coupon_bg-uploader").length > 0){
Dropzone.autoDiscover=false;
var couponDropzone=new Dropzone("#coupon_bg-uploader", {
url: listeo_core.upload,
maxFiles: 1,
maxFilesize: listeo_core.maxFilesize,
dictDefaultMessage: listeo_core.dictDefaultMessage,
dictFallbackMessage: listeo_core.dictFallbackMessage,
dictFallbackText: listeo_core.dictFallbackText,
dictFileTooBig: listeo_core.dictFileTooBig,
dictInvalidFileType: listeo_core.dictInvalidFileType,
dictResponseError: listeo_core.dictResponseError,
dictCancelUpload: listeo_core.dictCancelUpload,
dictCancelUploadConfirmation: listeo_core.dictCancelUploadConfirmation,
dictRemoveFile: listeo_core.dictRemoveFile,
dictMaxFilesExceeded: listeo_core.dictMaxFilesExceeded,
acceptedFiles: "image/*",
accept: function (file, done){
done();
},
init: function (){
this.on("addedfile", function (){
if(this.files[1]!=null){
this.removeFile(this.files[0]);
}});
this.on("sending", function(file, xhr, formData){
formData.append("nonce", listeo_core.upload_nonce);
});
},
success: function (file, response){
file.previewElement.classList.add("dz-success");
response=response.replace(/(\r\n|\n|\r)/gm, "");
file["attachment_id"]=response;
$("#coupon_bg-uploader-id").val(file["attachment_id"]);
},
error: function (file, response){
file.previewElement.classList.add("dz-error");
},
addRemoveLinks: true,
removedfile: function (file){
var attachment_id=file["attachment_id"];
if(attachment_id==undefined){
attachment_id=$("#coupon_bg-uploader-id").val();
}
$("#coupon_bg-uploader-id").val("");
$.ajax({
type: "POST",
url: listeo_core.delete,
data: {
media_id: attachment_id,
nonce: listeo_core.upload_nonce
},
success: function (result){
console.log(result);
},
error: function (){
console.log("delete error");
},
});
var _ref;
return (_ref=file.previewElement)!=null
? _ref.parentNode.removeChild(file.previewElement)
: void 0;
},
});
couponDropzone.on("maxfilesexceeded", function (file){
this.removeFile(file);
});
if($(".edit-coupon-photo").attr("data-photo")){
var mockFile={
name: $(".edit-coupon-photo").attr("data-name"),
size: $(".edit-coupon-photo").attr("data-size"),
};
couponDropzone.emit("addedfile", mockFile);
couponDropzone.emit("thumbnail",
mockFile,
$(".edit-coupon-photo").attr("data-photo")
);
couponDropzone.emit("complete", mockFile);
couponDropzone.files.push(mockFile);
couponDropzone.options.maxFiles=1;
}}
if($("#avatar-uploader").length > 0){
/* Upload using dropzone */
Dropzone.autoDiscover=false;
var avatarDropzone=new Dropzone("#avatar-uploader", {
url: listeo_core.upload,
maxFiles: 1,
maxFilesize: listeo_core.maxFilesize,
dictDefaultMessage: listeo_core.dictDefaultMessage,
dictFallbackMessage: listeo_core.dictFallbackMessage,
dictFallbackText: listeo_core.dictFallbackText,
dictFileTooBig: listeo_core.dictFileTooBig,
dictInvalidFileType: listeo_core.dictInvalidFileType,
dictResponseError: listeo_core.dictResponseError,
dictCancelUpload: listeo_core.dictCancelUpload,
dictCancelUploadConfirmation: listeo_core.dictCancelUploadConfirmation,
dictRemoveFile: listeo_core.dictRemoveFile,
dictMaxFilesExceeded: listeo_core.dictMaxFilesExceeded,
acceptedFiles: "image/jpeg,image/png,image/gif,image/jpg",
accept: function (file, done){
done();
},
init: function (){
this.on("addedfile", function (){
if(this.files[1]!=null){
this.removeFile(this.files[0]);
}});
this.on("sending", function(file, xhr, formData){
formData.append("nonce", listeo_core.upload_nonce);
});
},
success: function (file, response){
file.previewElement.classList.add("dz-success");
file["attachment_id"]=response;
$("#avatar-uploader-id").val(file["attachment_id"]);
},
error: function (file, response){
file.previewElement.classList.add("dz-error");
$(file.previewElement).find(".dz-error-message").text(response);
},
addRemoveLinks: true,
removedfile: function (file){
var attachment_id=file["attachment_id"];
if(attachment_id==undefined){
attachment_id=$("#avatar-uploader-id").val();
}
$("#avatar-uploader-id").val("");
$.ajax({
type: "POST",
url: listeo_core.delete,
data: {
media_id: attachment_id,
nonce: listeo_core.upload_nonce
},
success: function (result){
console.log(result);
},
error: function (){
console.log("delete error");
},
});
var _ref;
return (_ref=file.previewElement)!=null
? _ref.parentNode.removeChild(file.previewElement)
: void 0;
},
});
avatarDropzone.on("maxfilesexceeded", function (file){
this.removeFile(file);
});
if($(".edit-profile-photo").attr("data-photo")){
var mockFile={
name: $(".edit-profile-photo").attr("data-name"),
size: $(".edit-profile-photo").attr("data-size"),
};
avatarDropzone.emit("addedfile", mockFile);
avatarDropzone.emit("thumbnail",
mockFile,
$(".edit-profile-photo").attr("data-photo")
);
avatarDropzone.emit("complete", mockFile);
avatarDropzone.files.push(mockFile);
avatarDropzone.options.maxFiles=1;
}}
if($("#media-uploader").length > 0){
var mediaUploaderElement=document.querySelector("#media-uploader");
var galleryDropzone;
if(mediaUploaderElement.dropzone){
galleryDropzone=mediaUploaderElement.dropzone;
galleryDropzone.on("sending", function(file, xhr, formData){
formData.append("nonce", listeo_core.upload_nonce);
});
galleryDropzone.options.removedfile=function(file){
var attachment_id=file["attachment_id"];
if(attachment_id){
$.ajax({
type: "POST",
url: listeo_core.delete,
data: {
media_id: attachment_id,
nonce: listeo_core.upload_nonce
},
success: function (result){
console.log("File deleted:", result);
},
error: function (xhr, status, error){
console.log("delete error:", xhr.responseText);
},
});
$('input[value="' + attachment_id + '"]').remove();
}
if(file.previewElement&&file.previewElement.parentNode){
file.previewElement.parentNode.removeChild(file.previewElement);
}
galleryDropzone._updateMaxFilesReachedClass();
};
$("#media-uploader").off("click", "[data-dz-remove]").on("click", "[data-dz-remove]", function(e){
e.preventDefault();
e.stopImmediatePropagation();
var fileElement=$(this).closest(".dz-preview, .dz-file-preview");
var file=null;
for (var i=0; i < galleryDropzone.files.length; i++){
if(galleryDropzone.files[i].previewElement===fileElement[0]){
file=galleryDropzone.files[i];
break;
}}
if(file){
galleryDropzone.removeFile(file);
}
return false;
});
}else{
Dropzone.autoDiscover=false;
galleryDropzone=new Dropzone("#media-uploader", {
url: listeo_core.upload,
maxFiles: listeo_core.maxFiles||10,
maxFilesize: listeo_core.maxFilesize,
dictDefaultMessage: listeo_core.dictDefaultMessage,
dictFallbackMessage: listeo_core.dictFallbackMessage,
dictFallbackText: listeo_core.dictFallbackText,
dictFileTooBig: listeo_core.dictFileTooBig,
dictInvalidFileType: listeo_core.dictInvalidFileType,
dictResponseError: listeo_core.dictResponseError,
dictCancelUpload: listeo_core.dictCancelUpload,
dictCancelUploadConfirmation: listeo_core.dictCancelUploadConfirmation,
dictRemoveFile: listeo_core.dictRemoveFile,
dictMaxFilesExceeded: listeo_core.dictMaxFilesExceeded,
acceptedFiles: "image/*",
addRemoveLinks: true,
init: function (){
this.on("sending", function(file, xhr, formData){
formData.append("nonce", listeo_core.upload_nonce);
});
},
success: function (file, response){
file.previewElement.classList.add("dz-success");
response=response.replace(/(\r\n|\n|\r)/gm, "");
file["attachment_id"]=response;
var mediaUploaderIds=$("#media-uploader-ids");
if(mediaUploaderIds.length){
var elementKey=mediaUploaderIds.attr("data-elementkey");
mediaUploaderIds.append('<input type="hidden" name="_gallery[' + response + ']" value="' + response + '">');
}},
error: function (file, response){
file.previewElement.classList.add("dz-error");
},
removedfile: function (file){
var attachment_id=file["attachment_id"];
if(attachment_id){
$.ajax({
type: "POST",
url: listeo_core.delete,
data: {
media_id: attachment_id,
nonce: listeo_core.upload_nonce
},
success: function (result){
console.log("File deleted:", result);
},
error: function (){
console.log("delete error");
},
});
$('input[value="' + attachment_id + '"]').remove();
}
var _ref;
return (_ref=file.previewElement)!=null
? _ref.parentNode.removeChild(file.previewElement)
: void 0;
},
});
if(typeof images!=='undefined'&&images){
var existingImages=JSON.parse(images);
existingImages.forEach(function(image){
var mockFile={
name: image.name,
size: image.size,
attachment_id: image.attachment_id
};
galleryDropzone.emit("addedfile", mockFile);
galleryDropzone.emit("thumbnail", mockFile, image.thumb);
galleryDropzone.emit("complete", mockFile);
galleryDropzone.files.push(mockFile);
});
}}
}
$(document).on("change", ".dynamic select[id*='_category'], .dynamic [id*='_category-panel'] input", function (e){
var cat_ids=[];
$("#tax-listing_feature-panel .checkboxes").addClass("loading");
$("#tax-listing_feature-panel .panel-buttons").hide();
var panel=false;
$(".drilldown-generated").each(function (){
if($(this).val()){
cat_ids.push($(this).val());
}});
$(".dynamic select[id*='_category']").each(function(){
var selectValue=$(this).val();
if(selectValue&&selectValue!==''&&selectValue!=='all'){
if($(this).prop("multiple")){
var selectedValues=$(this).val();
if(Array.isArray(selectedValues)){
selectedValues.forEach(function(val){
if(val&&val!==''&&val!=='all'){
cat_ids.push(val);
}});
}}else{
cat_ids.push(selectValue);
}}
});
$(".dynamic [id*='_category-panel'] input[type=checkbox]:checked").each(function(){
var checkboxValue=$(this).val();
if(checkboxValue&&checkboxValue!==''&&checkboxValue!=='all'){
cat_ids.push(checkboxValue);
}});
if($("[id*='_category-panel']").length > 0){
panel=true;
}
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_get_features_from_category",
cat_ids: cat_ids,
panel: panel,
},
success: function (data){
$("#tax-listing_feature-panel .checkboxes").removeClass("loading");
$("#tax-listing_feature-panel .checkboxes .row")
.html(data["output"])
.removeClass("loading");
$("#tax-listing_feature").html(data["output"]).removeClass("loading");
if(data["success"]){
$("#tax-listing_feature-panel .panel-buttons").show();
}},
});
});
$(".dynamic #tax-listing_category").trigger("change");
$(
".dynamic-taxonomies #tax-listing_category,.dynamic-taxonomies #tax-listing_category-panel input"
).on("change", function (e){
var cat_ids=[];
$(".dynamic-taxonomies #listeo-search-form_tax-service_category").hide();
$(".dynamic-taxonomies #listeo-search-form_tax-rental_category").hide();
$(".dynamic-taxonomies #listeo-search-form_tax-event_category").hide();
$(
".dynamic-taxonomies #listeo-search-form_tax-classifieds_category"
).hide();
$(
".dynamic-taxonomies #listeo-search-form_tax-service_category select, .dynamic-taxonomies #tax-service_category-panel select"
).val("");
$(
".dynamic-taxonomies #listeo-search-form_tax-rental_category select, .dynamic-taxonomies #tax-rental_category-panel select"
).val("");
$(
".dynamic-taxonomies #listeo-search-form_tax-event_category select, .dynamic-taxonomies #tax-event_category-panel select"
).val("");
$(
".dynamic-taxonomies #listeo-search-form_tax-classifieds_category select, .dynamic-taxonomies #tax-classifieds_category-panel select"
).val("");
$(".dynamic-taxonomies #tax-service_category-panel").hide();
$(".dynamic-taxonomies #tax-rental_category-panel").hide();
$(".dynamic-taxonomies #tax-event_category-panel").hide();
$(".dynamic-taxonomies #tax-classifieds_category-panel").hide();
$(".dynamic-taxonomies #tax-service_category-panel input:checkbox").prop("checked",
false
);
$(".dynamic-taxonomies #tax-rental_category-panel input:checkbox").prop("checked",
false
);
$(".dynamic-taxonomies #tax-event_category-panel input:checkbox").prop("checked",
false
);
$(
".dynamic-taxonomies #tax-classifieds_category-panel input:checkbox"
).prop("checked", false);
$(
".dynamic-taxonomies #tax-event_category-panel input:checkbox"
).removeAttr("checked");
var panel=false;
if($("#tax-listing_category-panel").length > 0){
panel=true;
$("#tax-listing_category-panel input[type=checkbox]:checked").each(function (){
cat_ids.push($(this).val());
}
);
}else{
if($("#tax-listing_feature-panel").length > 0){
panel=true;
}
if($(this).prop("multiple")){
$("#tax-listing_category :selected").each(function (i, sel){
cat_ids.push($(sel).val());
});
}else{
cat_ids.push($(this).val());
}}
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_get_listing_types_from_categories",
cat_ids: cat_ids,
panel: panel,
},
success: function (data){
if(data["success"]){
var types=data["output"];
types.forEach(function(type){
var categoryTaxonomy=type + '_category';
$(".dynamic-taxonomies #listeo-search-form_tax-" + categoryTaxonomy).show();
$(".dynamic-taxonomies #tax-" + categoryTaxonomy + "-panel").css("display", "inline-block");
if(type==='region'){
$(".dynamic-taxonomies #listeo-search-form_tax-region").show();
$(".dynamic-taxonomies #tax-region-panel").css("display", "inline-block");
}});
}},
});
});
$(document).on("drilldown-updated",
".submit-page .drilldown-menu",
function (e){
if(!$(this).closest(".add-listing-section").hasClass("dynamic-features")){
return;
}
var listing_id=$("input[name='listing_id']").val();
var cat_ids=[];
$(".drilldown-generated").each(function (){
if($(this).val()){
cat_ids.push($(this).val());
}});
$(".submit-page select[name*='tax-'], .submit-page select[name*='_category']").each(function(){
var selectValue=$(this).val();
if(selectValue&&selectValue!==''&&selectValue!=='all'){
cat_ids.push(selectValue);
}});
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_get_features_ids_from_category",
cat_ids: cat_ids,
listing_id: listing_id,
selected: listeoSelectedFeaturesArray(),
panel: false,
},
success: function (data){
$(
".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature"
).removeClass("loading");
$(
".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature"
)
.html(data["output"])
.removeClass("loading");
},
});
}
);
$(document).on("drilldown-updated",
"#listeo_core-search-form .drilldown-menu",
function (e){
var cat_ids=[];
$(".drilldown-generated").each(function (){
if($(this).val()){
cat_ids.push($(this).val());
}});
$("#listeo_core-search-form select[id*='_category']").each(function(){
var selectValue=$(this).val();
if(selectValue&&selectValue!==''&&selectValue!=='all'){
if($(this).prop("multiple")){
var selectedValues=$(this).val();
if(Array.isArray(selectedValues)){
selectedValues.forEach(function(val){
if(val&&val!==''&&val!=='all'){
cat_ids.push(val);
}});
}}else{
cat_ids.push(selectValue);
}}
});
$("#listeo_core-search-form [id*='_category-panel'] input[type=checkbox]:checked").each(function(){
var checkboxValue=$(this).val();
if(checkboxValue&&checkboxValue!==''&&checkboxValue!=='all'){
cat_ids.push(checkboxValue);
}});
$("#tax-listing_feature-panel .checkboxes").addClass("loading");
$("#tax-listing_feature-panel .panel-buttons").hide();
var panel=false;
if($("[id*='_category-panel']").length > 0){
panel=true;
}
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_get_features_from_category",
cat_ids: cat_ids,
panel: panel,
},
success: function (data){
$("#tax-listing_feature-panel .checkboxes").removeClass("loading");
$("#tax-listing_feature-panel .checkboxes .row")
.html(data["output"])
.removeClass("loading");
$("#tax-listing_feature").html(data["output"]).removeClass("loading");
if(data["success"]){
$("#tax-listing_feature-panel .panel-buttons").show();
}},
});
}
);
$(
".add-listing-section.dynamic-features #listing_category,.add-listing-section.dynamic-features #tax-listing_category"
).on("change", function (e){
var listing_id=$("input[name='listing_id']").val();
if($(this).prop("multiple")){
var cat_ids;
cat_ids=$(this).val();
}else{
var cat_ids=[];
cat_ids.push($(this).val());
}
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_get_features_ids_from_category",
cat_ids: cat_ids,
listing_id: listing_id,
selected: listeoSelectedFeaturesArray(),
panel: false,
},
success: function (data){
$(
".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature"
).removeClass("loading");
$(
".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature"
)
.html(data["output"])
.removeClass("loading");
},
});
});
$(document).on('change', '.submit-page select[name*="_category"], .submit-page select[name*="tax-"]', function(e){
if(!$(this).closest(".add-listing-section").hasClass("dynamic-features")){
return;
}
var listing_id=$("input[name='listing_id']").val();
var cat_ids=[];
$(".drilldown-generated").each(function (){
if($(this).val()){
cat_ids.push($(this).val());
}});
$(".submit-page select[name*='tax-'], .submit-page select[name*='_category']").each(function(){
var selectValue=$(this).val();
if(selectValue&&selectValue!==''&&selectValue!=='all'){
cat_ids.push(selectValue);
}});
if(cat_ids.length > 0){
$(".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature").addClass("loading");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "listeo_get_features_ids_from_category",
cat_ids: cat_ids,
listing_id: listing_id,
selected: listeoSelectedFeaturesArray(),
panel: false,
},
success: function (data){
$(".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature").removeClass("loading");
$(".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature")
.html(data["output"])
.removeClass("loading");
},
});
}});
var selectedFeaturesSet=new Set();
function listeoSeedSelectedFeatures(){
$(".listeo_core-term-checklist-listing_feature[data-saved-features],.listeo_core-term-checklist-tax-listing_feature[data-saved-features]")
.each(function (){
String($(this).attr("data-saved-features")).split(",").forEach(function (id){
id=$.trim(id);
if(id){
selectedFeaturesSet.add(id);
}});
});
$(".submit-page input[name='tax_input[listing_feature][]']:checked").each(function (){
selectedFeaturesSet.add(String($(this).val()));
});
}
function listeoSelectedFeaturesArray(){
return Array.from(selectedFeaturesSet);
}
$(document).on("change", ".submit-page input[name='tax_input[listing_feature][]']", function (){
var val=String($(this).val());
if($(this).is(":checked")){
selectedFeaturesSet.add(val);
}else{
selectedFeaturesSet.delete(val);
}});
$(document).on("submit", "#submit-listing-form", function (){
var $form=$(this);
$form.find("input.listeo-preserved-feature").remove();
selectedFeaturesSet.forEach(function (id){
if(!$form.find("input[name='tax_input[listing_feature][]'][value='" + id + "']").length){
$("<input>", {
type: "hidden",
name: "tax_input[listing_feature][]",
value: id,
"class": "listeo-preserved-feature",
}).appendTo($form);
}});
});
if($(".add-listing-section").length){
listeoSeedSelectedFeatures();
$("select#listing_category").trigger("change");
$("select#tax-listing_category").trigger("change");
}
if($("body").hasClass("tax-listing_category") ||
$("body").hasClass("post-type-archive-listing")
){
$("select#tax-listing_category").trigger("change");
$("#tax-listing_category-panel input:checked").trigger("change");
}
$("#tax-listing_category-panel input:checked").trigger("change");
$(".panel-dropdown-content .notification").each(function (index){
$(this).parent().parent().find(".panel-buttons").hide();
});
$(".add-listing-section").on("change", ".uploadButton-input", function (e){
_populateFileField($(this));
});
$(".dashboard-list-box-static").on("change",
".uploadButton-input",
function (e){
_populateFileField($(this));
}
);
$(".zoom-anim-dialog").on("change", ".uploadButton-input", function (e){
_populateFileField($(this));
});
$(document).on("change", ".uploadButton-input", function (e){
_populateFileField($(this));
});
function _populateFileField($button){
console.log($button);
var selectedFile=[];
for (var i=0; i < $button.get(0).files.length; ++i){
selectedFile.push($button.get(0).files[i].name + "<br>");
}
console.log(selectedFile);
$($button).siblings(".uploadButton-file-name").html(selectedFile);
}
/*----------------------------------------------------*/
function updateCopySlotsDisplay(daySlots){
var dayIndex=daySlots.index(".day-slots");
if(daySlots.find(".slots-container .single-slot").length > 0){
$(".copy-slots-item[data-value='" + dayIndex + "']").css("display",
"block"
);
}else{
$(".copy-slots-item[data-value='" + dayIndex + "']").css("display",
"none"
);
}
updateIcalDropdownVisibility();
}
function updateIcalDropdownVisibility(){
$(".day-slots").each(function (index){
var $currentDay=$(this);
var otherDaysWithSlots=false;
$(".day-slots").each(function (otherIndex){
if(index!==otherIndex &&
$(this).find(".slots-container .single-slot").length > 0
){
otherDaysWithSlots=true;
return false;
}});
if(otherDaysWithSlots){
$currentDay.find(".ical-dropdown-btn").show();
}else{
$currentDay.find(".ical-dropdown-btn").hide();
}});
}
function timeStringToMinutes(timeStr, ampm=null){
const [hours, minutes]=timeStr.split(":");
let totalHours=parseInt(hours, 10);
if(ampm){
if(totalHours===12&&ampm.toLowerCase()==="am"){
totalHours=0;
}
else if(ampm.toLowerCase()==="pm"&&totalHours!==12){
totalHours +=12;
}}
return totalHours * 60 + parseInt(minutes, 10);
}
function minutesToTimeString(minutes, use12HourFormat=false){
let totalHours=Math.floor(minutes / 60);
let hours=totalHours % 24;
let mins=minutes % 60;
let ampm="";
if(hours < 0){
hours +=24;
}
if(mins < 0){
mins +=60;
hours -=1;
if(hours < 0){
hours +=24;
}}
if(use12HourFormat){
ampm=hours >=12 ? "pm":"am";
if(hours > 12){
hours=hours - 12;
}else if(hours===0){
hours=12;
}
return {
time: `${hours.toString().padStart(2, "0")}:${mins
.toString()
.padStart(2, "0")}`,
ampm: ampm,
};}
return `${hours.toString().padStart(2, "0")}:${mins
.toString()
.padStart(2, "0")}`;
}
$(document).ready(function (){
var is12HourFormat =
typeof listeo_core!=="undefined" &&
listeo_core.clockformat!==undefined
? !listeo_core.clockformat
: $(".availability-slots").data("clock-type")==="12hr";
function syncSlotsHiddenInput(daySlots){
var $editor=daySlots.closest(".availability-slots");
if(!$editor.length) return;
var slots=[];
var slot_container=0;
$editor.find(".day-slots .slots-container").each(function (){
var inside_slots=[];
var slot_number=0;
$(this)
.find(".single-slot-time")
.each(function (){
var $row=$(this).closest(".single-slot");
if($row.hasClass("cloned")) return;
var timeText=$(this).text()
.replace(/[–—]/g, "-")
.replace(/\s+u201[34]\s+/g, " - ");
inside_slots[slot_number] =
timeText + "|" + $row.find('input[name="slot-qty"]').val();
slot_number++;
});
slots[slot_container]=inside_slots;
slot_container++;
});
$editor
.find("#_slots, input[type='hidden'][name='_slots']")
.val(JSON.stringify(slots));
}
$(document).on("change input",
".availability-slots .single-slot input[name='slot-qty']",
function (){
var $daySlots=$(this).closest(".day-slots");
if($daySlots.length){
syncSlotsHiddenInput($daySlots);
}}
);
$(document).on("click",
".availability-slots .add-slot-btn, .availability-slots .remove-slot",
function (){
var $daySlots=$(this).closest(".day-slots");
if(!$daySlots.length) return;
setTimeout(function (){ syncSlotsHiddenInput($daySlots); }, 50);
setTimeout(function (){ syncSlotsHiddenInput($daySlots); }, 500);
}
);
$("form").has(".availability-slots").on("submit", function (){
var $form=$(this);
$form.find(".availability-slots .day-slots").each(function (){
syncSlotsHiddenInput($(this));
});
});
$(".day-slots").each(function (){
var daySlots=$(this);
updateCopySlotsDisplay(daySlots);
if(is12HourFormat){
var $endAmPm=daySlots.find(".add-slot-inputs select.time-slot-end");
$endAmPm.on("change.lbpManual", function (){
$(this).data("user-touched", true);
});
daySlots
.find(".add-slot-inputs select.time-slot-start")
.on("change", function (){
if($endAmPm.data("user-touched")){
return;
}
$endAmPm.val($(this).val());
});
}
daySlots.find(".copy-slots-item").on("click", function (e){
e.preventDefault();
var targetDaySlots=$(this).closest(".day-slots");
var sourceDayIndex=$(this).data("value");
var sourceDaySlots=$(".day-slots").eq(sourceDayIndex);
var slotsToCopy=sourceDaySlots
.find(".slots-container .single-slot")
.clone();
targetDaySlots
.find(".slots-container .single-slot")
.animate({ height: 0, opacity: 0 }, "fast", function (){
$(this).remove();
});
setTimeout(function (){
targetDaySlots.find(".slots-container").append(slotsToCopy);
slotsToCopy.find(".plusminus").each(function (){
$(this).numberPicker();
});
slotsToCopy
.hide()
.animate({ height: "show", opacity: "show" }, "fast");
syncSlotsHiddenInput(targetDaySlots);
}, 200);
targetDaySlots
.find(".no-slots")
.addClass("no-slots-fadeout")
.removeClass("no-slots-fadein");
updateCopySlotsDisplay(sourceDaySlots);
updateCopySlotsDisplay(targetDaySlots);
});
daySlots.find(".add-slot-btn").on("click", function (e){
e.preventDefault();
var slotTime_Start=daySlots
.find(".add-slot-inputs input.time-slot-start")
.val();
var slotTime_End=daySlots
.find(".add-slot-inputs input.time-slot-end")
.val();
var slotTimePM_AM_Start="";
var slotTimePM_AM_End="";
if(is12HourFormat){
slotTimePM_AM_Start=daySlots
.find(".add-slot-inputs select.time-slot-start")
.val();
slotTimePM_AM_End=daySlots
.find(".add-slot-inputs select.time-slot-end")
.val();
}
if(slotTime_Start.length > 0&&slotTime_End.length > 0){
var newTimeSlot=daySlots
.find(".single-slot.cloned")
.clone(true)
.addClass("slot-animation")
.removeClass("cloned");
setTimeout(function (){
newTimeSlot.removeClass("slot-animation");
}, 300);
newTimeSlot.find(".plusminus input").val("1");
newTimeSlot.find(".plusminus").numberPicker();
if(is12HourFormat){
newTimeSlot
.find(".single-slot-time")
.html(slotTime_Start +
" " +
'<i class="am-pm">' +
slotTimePM_AM_Start +
"</i>" +
" - " +
slotTime_End +
" " +
'<i class="am-pm">' +
slotTimePM_AM_End +
"</i>"
);
}else{
newTimeSlot
.find(".single-slot-time")
.html("" + slotTime_Start + " - " + slotTime_End);
}
newTimeSlot.appendTo(daySlots.find(".slots-container"));
$(".slots-container").sortable("refresh");
syncSlotsHiddenInput(daySlots);
updateCopySlotsDisplay(daySlots);
var slotTime_StartInMinutes, slotTime_EndInMinutes;
if(is12HourFormat){
slotTime_StartInMinutes=timeStringToMinutes(
slotTime_Start,
slotTimePM_AM_Start
);
slotTime_EndInMinutes=timeStringToMinutes(
slotTime_End,
slotTimePM_AM_End
);
}else{
slotTime_StartInMinutes=timeStringToMinutes(slotTime_Start);
slotTime_EndInMinutes=timeStringToMinutes(slotTime_End);
}
if(slotTime_EndInMinutes < slotTime_StartInMinutes){
slotTime_EndInMinutes +=24 * 60;
}
const hourDifferenceInMinutes =
slotTime_EndInMinutes - slotTime_StartInMinutes;
if(hourDifferenceInMinutes > 0){
if(is12HourFormat){
daySlots
.find(".add-slot-inputs input.time-slot-start")
.val(slotTime_End);
daySlots
.find(".add-slot-inputs select.time-slot-start")
.val(slotTimePM_AM_End);
const newEndTimeInMinutes =
slotTime_EndInMinutes + hourDifferenceInMinutes;
const newEndTimeObj=minutesToTimeString(
newEndTimeInMinutes,
true
);
daySlots
.find(".add-slot-inputs input.time-slot-end")
.val(newEndTimeObj.time);
daySlots
.find(".add-slot-inputs select.time-slot-end")
.val(newEndTimeObj.ampm);
}else{
daySlots
.find(".add-slot-inputs input.time-slot-start")
.val(slotTime_End);
const newEndTimeInMinutes =
slotTime_EndInMinutes + hourDifferenceInMinutes;
const newEndTime=minutesToTimeString(newEndTimeInMinutes);
daySlots
.find(".add-slot-inputs input.time-slot-end")
.val(newEndTime);
}}else{
console.log("End time is not larger than start time, not updating time inputs."
);
}}else{
daySlots.find(".add-slot").addClass("add-slot-shake-error");
setTimeout(function (){
daySlots.find(".add-slot").removeClass("add-slot-shake-error");
}, 600);
}});
function hideSlotInfo(){
var slotCount=daySlots.find(".slots-container").children().length;
if(slotCount < 1){
daySlots
.find(".no-slots")
.addClass("no-slots-fadein")
.removeClass("no-slots-fadeout");
}}
hideSlotInfo();
daySlots.on("click touchstart", ".remove-slot", function (e){
e.preventDefault();
$(this)
.closest(".single-slot")
.animate({ height: 0, opacity: 0 }, "fast", function (){
$(this).remove();
syncSlotsHiddenInput(daySlots);
});
setTimeout(function (){
hideSlotInfo();
}, 400);
updateCopySlotsDisplay(daySlots);
});
daySlots.find(".add-slot-btn").on("click", function (e){
e.preventDefault();
var slotCount=daySlots.find(".slots-container").children().length;
if(slotCount >=1){
daySlots
.find(".no-slots")
.removeClass("no-slots-fadein")
.addClass("no-slots-fadeout");
}});
});
});
$(".slots-container").sortable();
if($(".availability-slots").attr("data-clock-type")=="24hr"){
$(".availability-slots").addClass("twenty-four-clock");
$(".availability-slots").find('input[type="time"]').attr({ max: "24:00" });
}
function shouldSectionBeVisible(section){
const isMultiStepForm=document.querySelector(".submit-page")?.classList.contains("multi-step-form");
if(!isMultiStepForm){
const isBookingDependent=section.classList.contains('availability_calendar') ||
section.classList.contains('slots') ||
section.classList.contains('basic_prices');
const isBookingEnabled=document.querySelector('#_booking_status')?.checked;
if(isBookingDependent){
return isBookingEnabled;
}
return true;
}
return null;
}
$(".add-listing-section").each(function (){
var switcherSection=$(this);
var switcherInput=$(this).find(".switch input");
if(switcherInput.is(":checked")){
$(switcherSection).addClass("switcher-on");
}
switcherInput.change(function (){
if(this.checked===true){
$(switcherSection).addClass("switcher-on");
if(switcherInput.attr("id")=="_booking_status"){
const isMultiStepForm=document.querySelector(".submit-page")?.classList.contains("multi-step-form");
if(!isMultiStepForm){
$(
".add-listing-section.slots,.add-listing-section.basic_prices,.add-listing-section.availability_calendar"
).show();
}
else if(typeof window.listeoUpdateFormUI==='function'){
window.listeoUpdateFormUI();
}}
}else{
$(switcherSection).removeClass("switcher-on");
if(switcherInput.attr("id")=="_booking_status"){
const isMultiStepForm=document.querySelector(".submit-page")?.classList.contains("multi-step-form");
if(!isMultiStepForm){
$(
".add-listing-section.slots,.add-listing-section.basic_prices,.add-listing-section.availability_calendar"
).hide();
}
else if(typeof window.listeoUpdateFormUI==='function'){
window.listeoUpdateFormUI();
}}
}});
});
const isMultiStepForm=document.querySelector(".submit-page")?.classList.contains("multi-step-form");
if(!isMultiStepForm){
if($("#_booking_status").is(":checked")){
$(
".add-listing-section.slots,.add-listing-section.basic_prices,.add-listing-section.availability_calendar"
).show();
}else{
$(
".add-listing-section.slots,.add-listing-section.basic_prices,.add-listing-section.availability_calendar"
).hide();
}}
$(".booking-sticky-footer a.button").on("click", function (e){
var $anchor=$(this);
$("html, body").animate({ scrollTop: $($anchor.attr("href")).offset().top - 100 },
1000
);
});
$("body").on("click", ".opening-day-remove", function (e){
e.preventDefault();
var div_class=$(this).data("remove");
$(this).parent().parent().remove();
$("div." + div_class).remove();
});
$("body").on("click", ".opening-day-add-hours", function (e){
e.preventDefault();
var dayname=$(this).data("dayname");
var count=$(this).parents(".opening-day").find(".row").length;
var id=$(this).data("id");
var namePrefix=$(this).attr("data-name-prefix");
if(typeof namePrefix!=="string"||namePrefix===""){
namePrefix="_";
}
var newElem=$(
"" +
'<div class="row"><div class="col-md-2 opening-day-tools"><a class="opening-day-remove button" data-remove="' +
dayname +
"-opening-hours-row" +
count +
'" href="#">' +
listeo_core.remove +
"</a>" +
'</div><div class="col-md-5 ' +
dayname +
"-opening-hours-row" +
count +
'">' +
'<input type="text" class="listeo-flatpickr" name="' +
namePrefix +
id +
'_opening_hour[]" placeholder="' +
listeo_core.opening_time +
'" value=""></div>' +
'<div class="col-md-5 ' +
dayname +
"-opening-hours-row" +
count +
'" >' +
'<input type="text" class="listeo-flatpickr" name="' +
namePrefix +
id +
'_closing_hour[]" placeholder="' +
listeo_core.closing_time +
'" value="">' +
"</div></div>"
);
newElem.appendTo($(this).parents(".opening-day"));
var time24=false;
if(listeo_core.clockformat){
time24=true;
}
var fpOpts={
enableTime: true,
noCalendar: true,
dateFormat: "H:i",
time_24hr: time24,
disableMobile: true,
};
if(!time24){
fpOpts.altInput=true;
fpOpts.altFormat="h:i K";
}
$(this)
.parents(".opening-day")
.find(".row:last .listeo-flatpickr")
.flatpickr(fpOpts);
});
$(document).ready(function(){
setTimeout(function(){
var $defaultRadio=$("input[type=radio][name=user_role]:checked");
if($defaultRadio.length > 0){
$defaultRadio.trigger('change');
}}, 100);
});
$("input[type=radio][name=user_role]").change(function (){
$("#listeo-core-registration-fields").find(".select2-hidden-accessible").each(function(){
try {
$(this).select2("destroy");
} catch(e){}});
$("#listeo-core-registration-fields").html("");
if(this.value=="owner" ||
this.value=="vendor" ||
this.value=="seller"
){
$("#listeo-core-registration-fields").html($(
".listeo-custom-fields-wrapper #listeo-core-registration-owner-fields"
).html()
);
}else{
$("#listeo-core-registration-fields").html($(
".listeo-custom-fields-wrapper #listeo-core-registration-guest-fields"
).html()
);
}
$("#listeo-core-registration-fields").find("select").each(function(){
$(this).removeClass("select2-single select2-multiple select2-hidden-accessible");
$(this).removeAttr("data-select2-id");
$(this).removeAttr("aria-hidden");
$(this).removeAttr("tabindex");
});
$("#listeo-core-registration-fields").find(".select2-container").remove();
});
function pricingCoverSwitcher(){
var readURL=function (input){
if(input.files&&input.files[0]){
var reader=new FileReader();
var input_obj=$(input);
reader.onload=function (e){
$(input).parent().find(".cover-pic").attr("src", e.target.result);
$(input).parent().find(".menu-cover-id").val("");
};
reader.readAsDataURL(input.files[0]);
}};
$("#pricing-list-container").on("change", ".file-upload", function (e){
readURL(this);
});
$("#pricing-list-container").on("click", ".upload-button", function (e){
$(this).next(".file-upload").click();
});
$("#pricing-list-container").on("change", ".pricing-quantity-enable", function (){
var $maxInput=$(this).closest(".pricing-quantity-pair").find(".bookable_quantity_max");
$maxInput.prop("disabled", !this.checked);
if(!this.checked){
$maxInput.val("");
}});
}
pricingCoverSwitcher();
$(".remove-cover").on("click", function (e){
e.preventDefault();
$(this).next(".menu-cover-id").val("");
$(this)
.parent()
.find(".cover-pic")
.attr("src", listeo.theme_url + "/images/pricing-cover-placeholder.png");
});
function listeoIsHourlyPricing(){
var $toggle=$('input[name="_count_by_hour"]');
return $toggle.length > 0&&$toggle.is(":checked");
}
function listeoSyncChargeTypeLabels(){
var hourly=listeoIsHourlyPricing();
$(".pricing-bookable-options select option").each(function (){
var label=hourly
? $(this).data("label-hours")
: $(this).data("label-days");
if(label){
$(this).text(label);
}});
$(".pricing-bookable-options select.select2-hidden-accessible").trigger("change.select2"
);
}
$(document).on("change",
'input[name="_count_by_hour"]',
listeoSyncChargeTypeLabels
);
listeoSyncChargeTypeLabels();
function newMenuItem(){
var extra_services=listeo_core.extra_services_options_type;
var select_extra_service_types="";
if(typeof extra_services==="string"){
extra_services=extra_services.split(",");
}
var charge_type_block="";
var quantity_block="";
if(extra_services.length < 4){
charge_type_block =
'<div class="fm-input pricing-bookable-options">' +
'<label class="fm-input-label">' +
(listeo_core.pricing_label_charge_type||"Charge Type") +
"</label>" +
'<select class="select2-single" name="_menu[0][menu_elements][0][bookable_options]">';
if(!extra_services.includes("onetime")){
charge_type_block +=
'<option value="onetime">' + listeo_core.onetimefee + "</option>";
}
if(!extra_services.includes("byguest")){
charge_type_block +=
'<option value="byguest">' + listeo_core.multiguest + "</option>";
}
var hourly_pricing=listeoIsHourlyPricing();
var multihours=listeo_core.multihours||"Multiply by hours";
var multiguesthours =
listeo_core.multiguesthours||"Multiply by guests & hours";
if(!extra_services.includes("bydays")){
charge_type_block +=
'<option value="bydays" data-label-days="' +
listeo_core.multidays +
'" data-label-hours="' +
multihours +
'">' +
(hourly_pricing ? multihours:listeo_core.multidays) +
"</option>";
}
if(!extra_services.includes("byguestanddays")){
charge_type_block +=
'<option value="byguestanddays" data-label-days="' +
listeo_core.multiguestdays +
'" data-label-hours="' +
multiguesthours +
'">' +
(hourly_pricing ? multiguesthours:listeo_core.multiguestdays) +
"</option>";
}
charge_type_block +="</select></div>";
quantity_block =
'<div class="pricing-row-pair pricing-quantity-pair">' +
'<div class="fm-input pricing-quantity">' +
'<div class="checkboxes in-row pricing-quantity-row">' +
'<input type="checkbox" class="input-checkbox pricing-quantity-enable" name="_menu[0][menu_elements][0][bookable_quantity]" id="_menu_0_0_qty" value="on" />' +
'<label for="_menu_0_0_qty">' +(listeo_core.quantitybuttons||"Allow quantity") + "</label>" +
"</div>" +
'<p class="pricing-field-desc">' +(listeo_core.allow_quantity_desc||"Customer can pick more") + "</p>" +
"</div>" +
'<div class="fm-input pricing-quantity-max-wrap">' +
'<label class="fm-input-label">' +(listeo_core.bookable_quantity_max||"Max quantity") + "</label>" +
'<input type="number" class="bookable_quantity_max" step="1" min="1" disabled name="_menu[0][menu_elements][0][bookable_quantity_max]" placeholder="' +
(listeo_core.optional||"Optional") +
'" />' +
"</div>" +
"</div>";
}
var newElem=$(
'<tr class="pricing-list-item pattern" data-iterator="0">' +
"<td>" +
'<div class="fm-move"><i class="sl sl-icon-cursor-move"></i></div>' +
'<div class="pricing-row-grid">' +
'<div class="pricing-row-image">' +
'<div class="fm-input pricing-cover">' +
'<div class="pricing-cover-wrapper" data-tippy-placement="bottom" title="Change Cover">' +
'<img class="cover-pic" src="' + listeo.theme_url + '/images/pricing-cover-placeholder.png" alt="">' +
'<div class="upload-button"></div>' +
'<input class="file-upload" type="file" accept="image/*" name="_menu[0][menu_elements][0][cover]">' +
"</div>" +
"</div>" +
"</div>" +
'<div class="pricing-row-info pricing-row-section">' +
'<h4 class="pricing-row-section-title">' +
'<span class="pricing-row-section-num">1</span>' +
(listeo_core.section_basic_info||"Basic service info") +
"</h4>" +
'<div class="fm-input pricing-name">' +
'<label class="fm-input-label">' + listeo_core.menu_title + "</label>" +
'<input type="text" placeholder="' + listeo_core.menu_title + '" name="_menu[0][menu_elements][0][name]" />' +
"</div>" +
'<div class="fm-input pricing-ingredients">' +
'<label class="fm-input-label">' + listeo_core.menu_desc + "</label>" +
'<textarea name="_menu[0][menu_elements][0][description]" placeholder="' + listeo_core.menu_desc + '" rows="3"></textarea>' +
"</div>" +
'<div class="pricing-row-pair">' +
'<div class="fm-input pricing-price">' +
'<label class="fm-input-label">' +
(listeo_core.pricing_label_price||"Price") +
"</label>" +
'<input type="number" step="0.01" placeholder="' + listeo_core.menu_price + '" name="_menu[0][menu_elements][0][price]" data-unit="' + listeo_core.currency_symbol + '" />' +
"</div>" +
charge_type_block +
"</div>" +
"</div>" +
'<div class="pricing-row-right pricing-row-section">' +
'<h4 class="pricing-row-section-title">' +
'<span class="pricing-row-section-num">2</span>' +
(listeo_core.section_booking_settings||"Booking & availability settings") +
"</h4>" +
'<div class="fm-input pricing-bookable">' +
'<div class="switcher-tip" data-tip-content="' + listeo_core.pricingTooltip + '">' +
'<input type="checkbox" class="input-checkbox switch_1" id="_menu_0_0_bookable" value="on" name="_menu[0][menu_elements][0][bookable]" />' +
'<label for="_menu_0_0_bookable" class="pricing-bookable-label">' +(listeo_core.bookable_label||"Bookable service") + "</label>" +
"</div>" +
"</div>" +
quantity_block +
"</div>" +
'<div class="pricing-row-close">' +
'<div class="fm-close"><a class="delete" href="#"><i class="fa fa-remove"></i></a></div>' +
"</div>" +
"</div>" +
"</td>" +
"</tr>"
);
newElem.find("input").val("");
newElem.find("textarea").val("");
var prev_category_number=$(".pricing-submenu").last().data("number");
var prev_data_iterator=$("tr.pricing-list-item:not(.pricing-submenu)")
.last()
.data("iterator");
if(prev_category_number==undefined){
prev_category_number=0;
}
var next_data_iterator=prev_data_iterator + 1;
var last_table_el=$("tr.pricing-list-item").last();
newElem.find("input").each(function (){
this.name=this.name.replace(/\[\d+\]/,
"[" + prev_category_number + "]"
);
this.id=this.id.replace(/\[\d+\]/, "[" + prev_category_number + "]");
if(last_table_el.hasClass("pricing-submenu")){
next_data_iterator=0;
this.name=replaceLast(
this.name,
"[0]",
"[" + next_data_iterator + "]"
);
this.id=replaceLast(this.id, "[0]", "[" + next_data_iterator + "]");
}else{
this.name=replaceLast(
this.name,
"[0]",
"[" + next_data_iterator + "]"
);
this.id=replaceLast(this.id, "[0]", "[" + next_data_iterator + "]");
}});
newElem.find("select").each(function (){
this.name=this.name.replace(/\[\d+\]/,
"[" + prev_category_number + "]"
);
this.id=this.id.replace(/\[\d+\]/, "[" + prev_category_number + "]");
if(last_table_el.hasClass("pricing-submenu")){
next_data_iterator=0;
this.name=replaceLast(
this.name,
"[0]",
"[" + next_data_iterator + "]"
);
this.id=replaceLast(this.id, "[0]", "[" + next_data_iterator + "]");
}else{
this.name=replaceLast(
this.name,
"[0]",
"[" + next_data_iterator + "]"
);
this.id=replaceLast(this.id, "[0]", "[" + next_data_iterator + "]");
}});
newElem.find("textarea").each(function (){
this.name=this.name.replace(/\[\d+\]/,
"[" + prev_category_number + "]"
);
if(last_table_el.hasClass("pricing-submenu")){
next_data_iterator=0;
}
this.name=replaceLast(
this.name,
"[0]",
"[" + next_data_iterator + "]"
);
});
newElem.find("label").each(function (){
this.htmlFor=this.htmlFor.replace(/\[\d+\]/,
"[" + prev_category_number + "]"
);
if(last_table_el.hasClass("pricing-submenu")){
next_data_iterator=0;
this.htmlFor=replaceLast(
this.htmlFor,
"[0]",
"[" + next_data_iterator + "]"
);
}else{
this.htmlFor=replaceLast(
this.htmlFor,
"[0]",
"[" + next_data_iterator + "]"
);
}});
var underscoreSrc=/^_menu_\d+_\d+_/;
var underscoreDst="_menu_" + prev_category_number + "_" + next_data_iterator + "_";
newElem.find('[id^="_menu_"]').each(function (){
this.id=this.id.replace(underscoreSrc, underscoreDst);
});
newElem.find('label[for^="_menu_"]').each(function (){
this.htmlFor=this.htmlFor.replace(underscoreSrc, underscoreDst);
});
newElem
.appendTo("table#pricing-list-container")
.data("iterator", next_data_iterator)
.find("select")
.trigger("chosen:updated");
newElem.find(".select2-single").each(function (){
var $sel=$(this);
if(!$sel.hasClass("select2-hidden-accessible")){
$sel.select2({
dropdownPosition: "below",
minimumResultsForSearch: 20,
width: "100%",
});
}});
newElem.find(".pricing-price > input[data-unit]").each(function (){
var $input=$(this);
if($input.prev("i.data-unit").length===0){
$input.before('<i class="data-unit">' + $input.attr("data-unit") + "</i>");
}});
$("#pricing-list-container").data("iterator", next_data_iterator);
$(document).trigger("listeo:pricing-row-added", [
newElem,
prev_category_number,
next_data_iterator,
]);
}
var test="_menu[0][menu_elements][0][bookable_quantity]";
function replaceLast(string, search, replace){
var n=string.lastIndexOf(search);
return string.slice(0, n) + string.slice(n).replace(search, replace);
}
if($("table#pricing-list-container").is("*")){
$(".add-pricing-list-item").on("click", function (e){
e.preventDefault();
newMenuItem();
});
$(document).on("click", "#pricing-list-container .delete", function (e){
e.preventDefault();
$(this).closest("tr.pricing-list-item").remove();
});
$(".add-pricing-submenu").on("click", function (e){
e.preventDefault();
var i=$(".pricing-submenu").length;
var newElem=$(
"" +
'<tr class="pricing-list-item pricing-submenu" data-number="' +
i +
'">' +
"<td>" +
'<div class="fm-move"><i class="sl sl-icon-cursor-move"></i></div>' +
'<div class="fm-input"><input name="_menu[' +
i +
'][menu_title]" type="text" placeholder="' +
listeo_core.category_title +
'" /></div>' +
'<div class="fm-close"><a class="delete" href="#"><i class="fa fa-remove"></i></a></div>' +
"</td>" +
"</tr>"
);
newElem.appendTo("table#pricing-list-container");
updateNames($("table#pricing-list-container tbody"));
});
$("table#pricing-list-container tbody").sortable({
forcePlaceholderSize: true,
forceHelperSize: false,
placeholder: "sortableHelper",
zIndex: 999990,
opacity: 0.6,
tolerance: "pointer",
start: function (e, ui){
ui.placeholder.height(ui.helper.outerHeight());
},
stop: function (event, ui){
updateNames($(this));
},
});
$(window).on("load resize", function (){
var winWidth=$(window).width();
if(winWidth < 992){
$("table#pricing-list-container tbody").sortable("disable");
}else if(winWidth > 992){
$("table#pricing-list-container tbody").sortable("enable");
}});
}
function updateNames($list){
var cat_i=0;
var subcat_i=0;
$list.find("tr").each(function (){
var prev_data_iterator=$(this).data("iterator");
if($(this).hasClass("pricing-submenu")){
var cat_input=$(this).find("input");
cat_input.each(function (){
this.name=this.name.replace(/(\[\d\])/, "[" + cat_i + "]");
});
var cat_select=$(this).find("select");
cat_select.each(function (){
this.name=this.name.replace(/(\[\d\])/, "[" + cat_i + "]");
});
$(this).data("number", cat_i);
}else{
var prev_category_number=$(this)
.prevAll(".pricing-submenu")
.first()
.data("number");
if(typeof prev_category_number==="undefined"){
prev_category_number=0;
}
var subcat_input=$(this).find("input");
subcat_input.each(function (){
this.name=this.name.replace(/\[\d+\]/,
"[" + prev_category_number + "]"
);
this.name=replaceLast(
this.name,
"[" + prev_data_iterator + "]",
"[" + subcat_i + "]"
);
});
var subcat_select=$(this).find("select");
subcat_select.each(function (){
this.name=this.name.replace(/\[\d+\]/,
"[" + prev_category_number + "]"
);
this.name=replaceLast(
this.name,
"[" + prev_data_iterator + "]",
"[" + subcat_i + "]"
);
});
$(this).data("iterator", subcat_i);
subcat_i++;
}
if($(this).hasClass("pricing-submenu")){
cat_i++;
subcat_i=0;
}});
}
var fieldUnit=$(".pricing-price").children("input").attr("data-unit");
$(".pricing-price")
.children("input")
.before('<i class="data-unit">' + fieldUnit + "</i>");
if($("body").hasClass("page-template-template-home-search-splash") ||
$("body").hasClass("page-template-template-home-search") ||
$("body").hasClass("page-template-template-split-map")
){
var open_cal="right";
}else{
var open_cal="left";
}
$(document).on("click", ".add-repeatable-list-item", function (e){
e.preventDefault();
newRepeatableItem($(this));
});
$(document).on("click", "#repeatable-list-container .delete", function (e){
e.preventDefault();
$(this).parent().parent().remove();
});
$(document).on("click",
".listeo-mandatory-fees-list .listeo-fee-remove",
function (e){
e.preventDefault();
var $list=$(this).closest(".listeo-mandatory-fees-list");
var $row=$(this).closest(".listeo-fee-row");
if($list.find(".listeo-fee-row").length > 1){
$row.remove();
reindexMandatoryFees($list);
}else{
$row.find("input[type='text'], input[type='number'], textarea").val("");
$row.find("select").each(function (){
this.selectedIndex=0;
});
$row.find('input[type="hidden"][name$="[id]"]').val(newFeeId());
}}
);
$(document).on("click", ".listeo-mandatory-fees-list .listeo-fee-add", function (e){
e.preventDefault();
var $list=$(this).closest(".listeo-mandatory-fees-list");
var $template=$list.find(".listeo-fee-row").last();
if(!$template.length) return;
var $newRow=$template.clone();
$newRow.find("input[type='text'], input[type='number'], textarea").val("");
$newRow.find("select").each(function (){
this.selectedIndex=0;
});
$newRow.find('input[type="hidden"][name$="[id]"]').val(newFeeId());
$newRow.insertBefore($(this));
reindexMandatoryFees($list);
syncFeeRowPriceUnit($newRow);
});
function newFeeId(){
return "fee_" + Date.now().toString(36) + Math.floor(Math.random() * 1e4).toString(36);
}
function syncFeeRowPriceUnit($row){
var type=$row.find("select.listeo-fee-input-type").val();
var $wrap=$row.find(".listeo-fee-input-price");
if(!$wrap.length) return;
var isPercent=type==="percent";
var symbol=isPercent
? $wrap.data("percentSymbol")||"%"
: $wrap.data("flatSymbol")||"";
var placeholder=isPercent
? $wrap.data("percentPlaceholder")||"Rate"
: $wrap.data("flatPlaceholder")||"Price";
$wrap.find(".listeo-fee-currency").text(symbol);
$wrap.find("input").attr("placeholder", placeholder);
}
$(document).on("change", ".listeo-mandatory-fees-list select.listeo-fee-input-type", function (){
syncFeeRowPriceUnit($(this).closest(".listeo-fee-row"));
});
function reindexMandatoryFees($list){
var fieldName=$list.data("field-name");
if(!fieldName) return;
var prefix=String(fieldName).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
var re=new RegExp("^" + prefix + "\\[\\d+\\]");
$list.find(".listeo-fee-row").each(function (index){
$(this).attr("data-iterator", index);
$(this).find("input, select, textarea").each(function (){
var name=$(this).attr("name");
if(!name) return;
$(this).attr("name", name.replace(re, fieldName + "[" + index + "]"));
});
});
}
function newRepeatableItem(el){
var newElem=el.parent().find(".repeatable-list-item").last().clone(true);
var appendTo=el.parent().find("table");
newElem.find("input").val("");
newElem.find("select").val("");
newElem.find("textarea").val("");
var prev_data_iterator=el
.parent()
.find(".repeatable-list-item")
.last()
.data("iterator");
var next_data_iterator=prev_data_iterator + 1;
newElem.find("input").each(function (){
this.name=this.name.replace(/\[\d+\]/, "[" + next_data_iterator + "]");
this.id=this.id.replace(/\[\d+\]/, "[" + next_data_iterator + "]");
});
newElem.find("select").each(function (){
this.name=this.name.replace(/\[\d+\]/, "[" + next_data_iterator + "]");
this.id=this.id.replace(/\[\d+\]/, "[" + next_data_iterator + "]");
});
newElem.find("textarea").each(function (){
this.name=this.name.replace(/\[\d+\]/, "[" + next_data_iterator + "]");
this.id=this.id.replace(/\[\d+\]/, "[" + next_data_iterator + "]");
});
newElem
.appendTo(appendTo)
.removeClass("pattern")
.data("iterator", next_data_iterator);
}
$(".repeatable-list-item .fm-input").each(function (){
var repeatableFieldUnit=$(this).children("input").data("unit");
if(repeatableFieldUnit)
$(this)
.children("input")
.before('<i class="data-unit">' + repeatableFieldUnit + "</i>");
});
$(".date_range").daterangepicker({
opens: open_cal,
autoUpdateInput: false,
minDate: moment().subtract(0, "days"),
locale: {
format: wordpress_date_format.date,
firstDay: parseInt(wordpress_date_format.day),
applyLabel: listeo_core.applyLabel,
cancelLabel: listeo_core.clearLabel,
fromLabel: listeo_core.fromLabel,
toLabel: listeo_core.toLabel,
customRangeLabel: listeo_core.customRangeLabel,
daysOfWeek: [
listeo_core.day_short_su,
listeo_core.day_short_mo,
listeo_core.day_short_tu,
listeo_core.day_short_we,
listeo_core.day_short_th,
listeo_core.day_short_fr,
listeo_core.day_short_sa,
],
monthNames: [
listeo_core.january,
listeo_core.february,
listeo_core.march,
listeo_core.april,
listeo_core.may,
listeo_core.june,
listeo_core.july,
listeo_core.august,
listeo_core.september,
listeo_core.october,
listeo_core.november,
listeo_core.december,
],
},
});
$(".date_range").on("apply.daterangepicker", function (ev, picker){
$("input[name=_listing_type]").prop("disabled", false);
$(this)
.val(picker.startDate.format(wordpress_date_format.date) +
" - " +
picker.endDate.format(wordpress_date_format.date)
)
.trigger("change");
Cookies.set("listeo_rental_startdate",
picker.startDate.format(wordpress_date_format.date)
);
Cookies.set("listeo_rental_enddate",
picker.endDate.format(wordpress_date_format.date)
);
});
$(".date_range").on("cancel.daterangepicker", function (ev, picker){
$("input[name=_listing_type]").prop("disabled", true);
$(this).val("").trigger("change");
});
$(".date_range").on("show.daterangepicker", function (ev, picker){
$(".daterangepicker").addClass("calendar-visible calendar-animated bordered-alt-style"
);
$(".daterangepicker").removeClass("calendar-hidden");
$("input[name=_listing_type]").prop("disabled", false);
});
$(".date_range").on("hide.daterangepicker", function (ev, picker){
$(".daterangepicker").removeClass("calendar-visible");
$(".daterangepicker").addClass("calendar-hidden");
});
$("input.slot-time-input")
.keydown(function (e){
if(e.ctrlKey||e.metaKey){
return true;
}
if(e.which >=37&&e.which <=40){
return true;
}
if(e.which!==8&&e.which!==0&&e.key.match(/[^:0-9]/)){
return false;
}})
.keyup(function (e){
var $this=$(this);
if(e.ctrlKey ||
e.metaKey ||
e.which===8 ||
e.which===0 ||
(e.which >=37&&e.which <=40)
){
return true;
}
var ss=parseInt(this.selectionStart);
var v=$this.val();
var t=v.replace(/[^0-9]/g, "");
if($(".availability-slots").attr("data-clock-type")=="24hr"){
var h=Math.max(0, Math.min(24, parseInt(t.substr(0, 2))));
}else{
var h=Math.max(0, Math.min(12, parseInt(t.substr(0, 2))));
}
var m=Math.max(0, Math.min(59, parseInt(t.substr(2))));
if(t.length < 3){
m="";
}
var r;
if(v.length===2){
r=String("0" + h).substr(String(h).length - 1) + ":";
ss++;
}else if(v.length >=3&&v.length < 5){
r=String("0" + h).substr(String(h).length - 1) + ":" + m;
ss++;
}else if(v.length===5){
r =
String("0" + h).substr(String(h).length - 1) +
":" +
String("0" + m).substr(String(m).length - 1);
}
if(r&&r!==$this.val()){
$this.val(r);
this.selectionStart=this.selectionEnd=ss;
}})
.blur(function (e){
var $this=$(this);
var v=$this.val();
var t=v.replace(/[^0-9]/g, "");
var h=Math.max(0, Math.min(23, parseInt(t.substr(0, 2))));
var m=Math.max(0, Math.min(59, parseInt(t.substr(2))))||0;
var r="";
if(!isNaN(h)){
r =
String("0" + h).substr(String(h).length - 1) +
":" +
String("0" + m).substr(String(m).length - 1);
}
$this.val(r);
});
$(document.body).on("click", ".remove-uploaded-file", function (){
$(this).closest(".job-manager-uploaded-file").remove();
$(this).closest(".listeo-uploaded-file").remove();
return false;
});
$("input.listeo-export-ical-input").blur(function (){
if($(this).attr("data-selected-all")){
$(this).removeAttr("data-selected-all");
}});
$("input.listeo-export-ical-input").click(function (){
if(!$(this).attr("data-selected-all")){
try {
$(this).selectionStart=0;
$(this).selectionEnd=$(this).value.length + 1;
$(this).attr("data-selected-all", true);
} catch (err){
$(this).select();
$(this).attr("data-selected-all", true);
}}
});
function updateDashboardChart(params){
console.log($("#chart-date-range").data("daterangepicker"));
var startDataSql=moment(
$("#chart-date-range").data("daterangepicker").startDate,
["MM/DD/YYYY"]
).format("YYYY-MM-DD");
var endDataSql=moment(
$("#chart-date-range").data("daterangepicker").endDate,
["MM/DD/YYYY"]
).format("YYYY-MM-DD");
var listing_id=$("#listing_id").val();
var stat_type=$("#stat_type").val();
var ajax_data={
action: "listeo_chart_refresh",
date_start: startDataSql,
date_end: endDataSql,
listing: listing_id,
stat_type: stat_type,
};
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: ajax_data,
success: function (data){
let labels=new Array();
Object.keys(data.labels).forEach((key)=> {
labels.push(data.labels[key]);
});
chart.data.labels=labels;
let postdata=new Array();
Object.keys(data.data).forEach((key)=> {
postdata.push(data.data[key]);
});
console.log(postdata);
chart.data.datasets=postdata;
chart.update();
},
});
}
if($("#chart-date-range").length){
var start=moment().subtract(6, "days");
var end=moment();
function cb(start, end){
$("#chart-date-range span").html(start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY")
);
}
var ranges=new Object();
ranges[listeo_core.today]=[moment().subtract(1, "days"), moment()];
ranges[listeo_core.yesterday]=[
moment().subtract(1, "days"),
moment().subtract(1, "days"),
];
ranges[listeo_core.last_7_days]=[moment().subtract(6, "days"), moment()];
ranges[listeo_core.last_30_days]=[
moment().subtract(29, "days"),
moment(),
];
ranges[listeo_core.this_month]=[
moment().startOf("month"),
moment().endOf("month"),
];
ranges[listeo_core.last_month]=[
moment().subtract(1, "month").startOf("month"),
moment().subtract(1, "month").endOf("month"),
];
cb(start, end);
$("#chart-date-range")
.show()
.daterangepicker({
opens: "left",
autoUpdateInput: false,
alwaysShowCalendars: true,
startDate: start,
endDate: end,
ranges: ranges,
locale: {
format: wordpress_date_format.date,
firstDay: parseInt(wordpress_date_format.day),
applyLabel: listeo_core.applyLabel,
cancelLabel: listeo_core.cancelLabel,
fromLabel: listeo_core.fromLabel,
toLabel: listeo_core.toLabel,
customRangeLabel: listeo_core.customRangeLabel,
daysOfWeek: [
listeo_core.day_short_su,
listeo_core.day_short_mo,
listeo_core.day_short_tu,
listeo_core.day_short_we,
listeo_core.day_short_th,
listeo_core.day_short_fr,
listeo_core.day_short_sa,
],
monthNames: [
listeo_core.january,
listeo_core.february,
listeo_core.march,
listeo_core.april,
listeo_core.may,
listeo_core.june,
listeo_core.july,
listeo_core.august,
listeo_core.september,
listeo_core.october,
listeo_core.november,
listeo_core.december,
],
},
},
cb
);
cb(start, end);
$("#chart-date-range").on("show.daterangepicker", function (ev, picker){
$(".daterangepicker").addClass("calendar-visible calendar-animated bordered-style"
);
$(".daterangepicker").removeClass("calendar-hidden");
});
$("#chart-date-range").on("hide.daterangepicker", function (ev, picker){
$(".daterangepicker").removeClass("calendar-visible");
$(".daterangepicker").addClass("calendar-hidden");
});
}
$("#chart-date-range").on("apply.daterangepicker", function (e){
updateDashboardChart();
});
$(".dashboard-chart-full #listing_id").on("change", function (e){
updateDashboardChart();
});
$(".dashboard-chart-full #stat_type").on("change", function (e){
updateDashboardChart();
});
$(".listeo-create-stripe-express-link-account").on("click", function (e){
e.preventDefault();
var $this=$(this);
$(this).addClass("loading");
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "create_express_stripe_account",
nonce: listeo_core.stripe_express_nonce,
},
success: function (data){
if(data.success){
get_listeo_stripe_account_link();
}else{
$this.removeClass("loading");
$this.after($("<p>").text(data.data));
}},
});
});
function get_listeo_stripe_account_link(){
$.ajax({
type: "POST",
dataType: "json",
url: listeo.ajaxurl,
data: {
action: "get_express_stripe_account_link",
nonce: listeo_core.stripe_express_nonce,
},
success: function (data){
if(data.success){
$(".listeo-create-stripe-express-link-account").hide();
$(".real-conntect-w-stripe-btn").attr("href", data.data).show();
}else{
$(".listeo-create-stripe-express-link-account").removeClass("loading"
);
$(".listeo-create-stripe-express-link-account").after($("<p>").text(data.data)
);
}},
});
}
$("#claim-listing-form").on("submit", function (e){
$("#claim-dialog button").addClass("loading").prop("disabled", true);
var form=$("#claim-listing-form")[0];
var formData=new FormData(form);
var required_fields=true;
$("#claim-listing-form .required").each(function (){
if(!$(this).val()){
required_fields=false;
$(this).addClass("error");
}});
if(!required_fields){
$("#claim-dialog button").removeClass("loading").prop("disabled", false);
$("#claim-dialog .notification")
.removeClass("success")
.addClass("error")
.show()
.html(listeo_core.required_fields);
e.preventDefault();
return false;
}
$.ajax({
type: "POST",
dataType: "json",
url: listeo_core.ajax_url,
data: formData,
processData: false,
contentType: false,
success: function (data){
if(data.success){
if(data.payment_url&&data.payment_url!==""){
$("html, body").animate({ scrollTop: 0 }, "slow");
$("#claim-dialog button")
.removeClass("loading")
.prop("disabled", false);
$("#claim-dialog form").hide();
$(".claim-listing-pay-button")
.attr("href", data.payment_url)
.show();
$(".claim-confirmation-box").show();
}else{
$("#claim-listing-form .required").each(function (){
$(this).removeClass("error");
});
$("#claim-dialog button").removeClass("loading");
$("#claim-dialog .notification")
.removeClass("error")
.addClass("success")
.show()
.html(data.message);
window.setTimeout(closepopup, 3000);
$(".claim-listing-button span").text(data.button_text);
$(".claim-listing-button").removeClass("popup-with-zoom-anim");
if(data.reload&&listeo_core.autologin){
setTimeout(function (){
window.location.reload();
}, 2000);
}}
}else{
$("#claim-dialog .notification")
.removeClass("success")
.addClass("error")
.show()
.html(data.message);
$("#claim-dialog button")
.removeClass("loading")
.prop("disabled", false);
}},
});
e.preventDefault();
});
$(".add-sub-rating").each(function (){
const ratingName=$(this).find('input[type="radio"]').first().attr("name");
$(this).append(`<input type="text"
class="rating-validator"
style="position: absolute; opacity: 0; pointer-events: none;"
name="validate_${ratingName}"
required
data-rating-group="${ratingName}">`);
});
$('.leave-rating input[type="radio"]').on("change", function (){
const ratingGroup=$(this).attr("name");
const validator=$(`input[data-rating-group="${ratingGroup}"]`);
validator.val($(this).val());
$(this).closest(".add-sub-rating").removeClass("rating-validation-error");
$(this).closest(".add-sub-rating").find(".rating-error-message").hide();
});
$("#commentform").on("submit", function (e){
let isValid=true;
let firstError=null;
$(".add-sub-rating").each(function (){
const ratingGroup=$(this);
const hasRating =
ratingGroup.find('input[type="radio"]:checked').length > 0;
if(!hasRating){
isValid=false;
ratingGroup.addClass("rating-validation-error");
ratingGroup.find(".rating-error-message").show();
if(!firstError){
firstError=ratingGroup;
}}
});
if(!isValid){
e.preventDefault();
if(firstError){
$("html, body").animate({
scrollTop: firstError.offset().top - 100,
},
500
);
}}
});
});
})(this.jQuery);
/**/;
(function ($){
"use strict";
$(document).ready(function (){
var defaultCategories=[
{
label: "Default",
children: [{ label: "Item 1" }, { label: "Item 2" }],
},
];
function hasRealChildren(item){
if(!item.children||item.children.length===0){
return false;
}
if(item.children.length===1){
var child=item.children[0];
if(child.value===item.value&&child.id===item.id){
return false;
}
if(child.label==="All in " + item.label){
return false;
}}
return true;
}
$(".drilldown-menu").each(function (){
var $menu=$(this);
var selectedItems=[];
var menuStack=[];
var initialized=false;
var singleSelect=$menu.data("single-select")===true;
var categories=$menu.data("categories");
if(typeof categories==="string"){
try {
categories=JSON.parse(categories);
} catch (e){
categories=defaultCategories;
}}else if(!categories){
categories=defaultCategories;
}
var $menuToggle=$menu.find(".menu-toggle");
var $menuPanel=$menu.find(".menu-panel");
var $menuLevelsContainer=$menu.find(".menu-levels");
var $menuLabel=$menu.find(".menu-label");
var $menuLabelText=$menu.data("label");
var $resetButton=$menu.find(".reset-button");
function itemMatchesSearch(item, searchTerm){
if($.trim(searchTerm)==="") return true;
var lowerSearch=searchTerm.toLowerCase();
if(item.label.toLowerCase().indexOf(lowerSearch)!==-1){
return true;
}
if(item.children&&item.children.length > 0){
for (var i=0; i < item.children.length; i++){
if(itemMatchesSearch(item.children[i], searchTerm)){
return true;
}}
}
return false;
}
function initMenu(){
menuStack=[];
menuStack.push({ data: categories, parent: null });
$menuLevelsContainer.empty();
var $levelElement=createMenuLevel(categories, 0);
$menuLevelsContainer.append($levelElement);
updateMenuLevelPosition();
updateMenuHeight();
initializePreselectedValues();
}
function createMenuLevel(data, levelIndex){
var $levelDiv=$("<div/>")
.addClass("menu-level")
.attr("data-level", levelIndex);
if(levelIndex > 0){
var $backButton=$("<button/>")
.addClass("back-button")
.text(listeo_core.back)
.on("click", function (e){
e.stopPropagation();
drillUp();
});
$levelDiv.append($backButton);
}
var $searchInput=$("<input/>", {
type: "text",
placeholder: listeo_core.search,
class: "menu-search",
}).on("input", function (){
filterMenuLevel($levelDiv, $searchInput.val());
});
$levelDiv.append($searchInput);
var $itemsContainer=$("<div/>").addClass("menu-items");
$levelDiv.append($itemsContainer);
$.each(data, function (i, item){
var $itemDiv=$("<div/>")
.addClass("menu-item")
.attr("data-label", item.label);
if(item.value){
$itemDiv.attr("data-value", item.value);
}
if(item.id){
$itemDiv.attr("data-id", item.id);
}
$itemDiv.data("item", item);
var $labelSpan=$("<span/>")
.addClass("item-label")
.text(item.label);
$itemDiv.append($labelSpan);
if(hasRealChildren(item)){
var $arrowSpan=$("<span/>").addClass("arrow");
$itemDiv.append($arrowSpan);
$itemDiv.on("click", function (e){
e.stopPropagation();
drillDown(item);
});
}else{
$itemDiv.on("click", function (e){
e.stopPropagation();
$(".category-item").removeClass("active");
var menuId=$menu.attr("id");
if(menuId&&menuId.startsWith("listeo-drilldown-tax-")){
var taxonomyName=menuId.replace("listeo-drilldown-tax-", "");
var sliderInputName="tax-" + taxonomyName;
$("#listeo_core-search-form")
.find('input[name="' + sliderInputName + '"]:not([name*="["])')
.remove();
}
toggleSelection(item, $itemDiv);
});
if(isSelected(item)){
$itemDiv.addClass("selected");
}}
$itemsContainer.append($itemDiv);
});
return $levelDiv;
}
function filterMenuLevel($levelDiv, searchTerm){
var $itemsContainer=$levelDiv.find(".menu-items");
var $items=$itemsContainer.find(".menu-item");
var anyVisible=false;
$levelDiv.find(".no-results").remove();
$items.each(function (){
var $item=$(this);
var itemObj=$item.data("item");
var label=itemObj.label;
var lowerSearch=$.trim(searchTerm).toLowerCase();
var directMatch =
lowerSearch!=="" &&
label.toLowerCase().indexOf(lowerSearch) > -1;
var matches=itemMatchesSearch(itemObj, searchTerm);
if(matches){
$item.css("display", "flex");
anyVisible=true;
var $labelSpan=$item.find(".item-label");
$item.removeClass("child-match");
$labelSpan.text(label);
if($.trim(searchTerm)!==""){
if(directMatch){
var regex=new RegExp(
"(" + escapeRegExp(searchTerm) + ")",
"gi"
);
$labelSpan.html(label.replace(regex, "<mark>$1</mark>"));
}else{
$item.addClass("child-match");
}}
}else{
$item.css("display", "none");
}});
if(!anyVisible){
var $noResults=$("<div/>")
.addClass("no-results")
.text("No results");
$itemsContainer.append($noResults);
}
updateMenuHeight();
}
function escapeRegExp(string){
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function drillDown(category){
if(!category.children||category.children.length===0) return;
var $currentLevel=$menuLevelsContainer.children().last();
var parentSearchTerm=$currentLevel.find(".menu-search").val();
menuStack.push({ data: category.children, parent: category });
var levelIndex=menuStack.length - 1;
var $newLevel=createMenuLevel(category.children, levelIndex);
$newLevel.find(".menu-search").val(parentSearchTerm);
filterMenuLevel($newLevel, parentSearchTerm);
$menuLevelsContainer.append($newLevel);
updateMenuLevelPosition();
setTimeout(updateMenuHeight, 0);
}
function drillUp(){
if(menuStack.length <=1) return;
menuStack.pop();
$menuLevelsContainer.children().last().remove();
updateMenuLevelPosition();
updateMenuHeight();
}
function findItemByValue(categories, value){
for (var i=0; i < categories.length; i++){
var item=categories[i];
if($("#submit-listing-form").length){
if(item.id==value){
return item;
}}else{
if(item.id==value){
return item;
}
var directMatch=item.value===value;
var prefixedMatch=item.value===("listing_category:" + value);
var labelMatch = !item.value&&item.label===value;
if(directMatch||prefixedMatch||labelMatch){
return item;
}}
if(item.children&&item.children.length > 0){
var found=findItemByValue(item.children, value);
if(found) return found;
}}
return null;
}
if(!window.ListeoDrilldown) window.ListeoDrilldown={};
window.ListeoDrilldown[$menu.attr("id")]={
initMenu: initMenu,
selectById: function (categoryId){
initMenu();
setTimeout(function (){
const item=findItemByValue(categories, categoryId);
if(item){
const $fake=$("<div>")
.addClass("menu-item")
.attr("data-id", categoryId);
toggleSelection(item, $fake);
}else{
resetSelections();
}}, 20);
},
selectListingType: function (slug){
initMenu();
setTimeout(function (){
var typeValue="all_" + slug;
var parent =
findItemByValue(categories, typeValue) ||
findItemByValue(categories, slug);
if(parent){
var target=parent;
if(parent.children&&parent.children.length){
var allChild=parent.children.find(function (c){
return c.value==="type" + slug;
});
if(allChild){
target=allChild;
}}
var $fake=jQuery("<div>").addClass("menu-item");
toggleSelection(target, $fake);
}else{
resetSelections();
}}, 20);
},
};
function updateVisualSelection(){
$menu.find(".menu-item.selected").removeClass("selected");
selectedItems.forEach(function(item){
$menu
.find('.menu-item[data-value="' + (item.value||item.label) + '"]')
.addClass("selected");
if(item.id){
$menu
.find('.menu-item[data-id="' + item.id + '"]')
.addClass("selected");
}});
}
function initializePreselectedValues(){
selectedItems=[];
var inputName=$menu.data("name");
console.log("Initializing preselected values for input name:", inputName);
var $existingInputs=$menu.find("input.drilldown-values");
console.log("Found existing inputs:", $existingInputs.length);
$existingInputs.each(function (){
var value=$(this).val();
if(value&&value.trim()!==''){
console.log("Found existing input value:", value);
var item=findItemByValue(categories, value.trim());
if(item){
selectedItems.push(item);
}}
});
if(selectedItems.length > 0){
updateMainButton();
updateHiddenInput();
updateVisualSelection();
}}
function updateHiddenInput(){
var inputName=$menu.data("name");
$menu.find("input.drilldown-values").remove();
$menu.find("input.drilldown-generated").remove();
selectedItems.forEach(function (item){
if($("#submit-listing-form").length){
var value=item.id;
}else{
var value=item.value||item.label;
}
var menuId=$menu.attr("id");
if(menuId&&menuId.startsWith("listeo-drilldown-tax-")&&!menuId.includes("listing-types")){
if(typeof value==='string'&&value.includes(':')){
var parts=value.split(':');
if(parts.length===2){
value=parts[1];
}}
}
$("<input>", {
type: "hidden",
name: inputName + "[]",
value: value,
"data-label": item.label,
class: "drilldown-values drilldown-generated",
}).appendTo($menu);
});
var target=$("div#listeo-listings-container");
target.triggerHandler("update_results", [1, false]);
$menu.trigger("drilldown-updated");
}
function updateMenuLevelPosition(){
var levelIndex=menuStack.length - 1;
$menuLevelsContainer.css("transform",
"translateX(-" + levelIndex * 100 + "%)"
);
}
function updateMenuHeight(){
var $levels=$menuLevelsContainer.children();
if($levels.length===0) return;
var $activeLevel=$levels.last();
$menuPanel.height($activeLevel[0].scrollHeight);
}
function toggleSelection(item, $itemDiv){
var index=selectedItems.findIndex(function (selected){
if($("#submit-listing-form").length){
if(item.id&&selected.id){
return selected.id===item.id;
}}else{
if(item.value&&selected.value){
return selected.value===item.value;
}}
return selected.label===item.label;
});
if(index > -1){
selectedItems.splice(index, 1);
$itemDiv.removeClass("selected");
$menu
.find('.menu-item[data-value="' + (item.value||item.label) + '"]'
)
.removeClass("selected");
if(item.id){
$menu
.find('.menu-item[data-id="' + item.id + '"]')
.removeClass("selected");
}}else{
if(singleSelect){
$menu.find(".menu-item.selected").removeClass("selected");
selectedItems=[];
}
if(!isSelected(item)){
selectedItems.push(item);
}
$itemDiv.addClass("selected");
$menu
.find('.menu-item[data-value="' + (item.value||item.label) + '"]'
)
.addClass("selected");
if(item.id){
$menu
.find('.menu-item[data-id="' + item.id + '"]')
.addClass("selected");
}}
updateMainButton();
updateHiddenInput();
}
function isSelected(item){
return selectedItems.some(function (selected){
if($("#submit-listing-form").length){
if(item.id&&selected.id){
return selected.id===item.id;
}}else{
if(item.value&&selected.value){
return selected.value===item.value;
}}
return selected.label===item.label;
});
}
function updateMainButton(){
var searchTerm =
$menuLevelsContainer.children().last().find(".menu-search").val() ||
"";
if(selectedItems.length===0){
$menuLabel.html($menuLabelText);
$resetButton.hide();
$menuToggle.removeClass("dd-chosen");
}else if(selectedItems.length===1){
var label=selectedItems[0].label;
if($.trim(searchTerm)!==""){
var regex=new RegExp(
"(" + escapeRegExp(searchTerm) + ")",
"gi"
);
label=label.replace(regex, "<mark>$1</mark>");
}
$menuLabel.html(label);
$resetButton.show();
$menuToggle.addClass("dd-chosen");
}else{
var label=selectedItems[0].label;
if($.trim(searchTerm)!==""){
var regex=new RegExp(
"(" + escapeRegExp(searchTerm) + ")",
"gi"
);
label=label.replace(regex, "<mark>$1</mark>");
}
$menuLabel.html(label + " +" + (selectedItems.length - 1));
$resetButton.show();
$menuToggle.addClass("dd-chosen");
}}
function resetSelections(){
selectedItems=[];
$menu.find(".menu-item.selected").removeClass("selected");
$menuLevelsContainer
.find(".menu-item.selected")
.removeClass("selected");
console.log("$menuLabel:", $menuLabel);
console.log("$menuLabelText:", $menuLabelText);
console.log("Current label HTML:", $menuLabel.html());
if($menuLabelText){
$menuLabel.html($menuLabelText);
}else{
var originalText =
$menu.data("label") ||
$menu.attr("data-label") ||
"Select an option";
console.log("Using fallback text:", originalText);
$menuLabel.html(originalText);
}
$resetButton.hide();
$menuToggle.removeClass("dd-chosen");
updateHiddenInput();
}
function openMenu(){
$(".drilldown-menu")
.not($menu)
.each(function (){
$(this).find(".menu-panel").removeClass("open");
$(this).find(".menu-toggle").removeClass("dd-active");
});
if($.fn.selectpicker){
$(".bootstrap-select.show").each(function (){
$(this).removeClass("show");
$(this).find(".dropdown-menu").removeClass("show");
});
$(".bootstrap-select.open").each(function (){
$(this).removeClass("open");
$(this).find(".dropdown-menu").removeClass("open");
});
}
$menuPanel.addClass("open");
$menuToggle.addClass("dd-active");
if(!initialized){
initMenu();
initialized=true;
}else{
restoreSelectedState();
}}
function restoreSelectedState(){
selectedItems.forEach(function (selectedItem){
var selector="";
if(selectedItem.id){
selector='[data-id="' + selectedItem.id + '"]';
}else if(selectedItem.value){
selector='[data-value="' + selectedItem.value + '"]';
}else{
selector='[data-label="' + selectedItem.label + '"]';
}
$menu.find(".menu-item" + selector).addClass("selected");
});
updateMainButton();
}
function closeMenu(){
$menuPanel.removeClass("open");
$menuToggle.removeClass("dd-active");
}
$menuToggle.on("click", function (e){
e.stopPropagation();
if($menuPanel.hasClass("open")){
closeMenu();
}else{
openMenu();
}});
$resetButton.on("click", function (e){
e.stopPropagation();
resetSelections();
$(".category-item").removeClass("active");
});
$(document).on("click", function (e){
if(!$menu.is(e.target)&&$menu.has(e.target).length===0){
closeMenu();
}});
if($menu.find("input.drilldown-values[value!='']").length > 0){
initMenu();
initialized=true;
}});
window.selectDrilldownCategoryById=function (categoryId){
$(".drilldown-menu").each(function (){
var $menu=$(this);
var $matchingItem=$menu.find('.menu-item[data-id="${categoryId}"]');
console.log("Matching item:", $matchingItem);
if($matchingItem.length){
$matchingItem.trigger("click");
console.log("Item clicked:", $matchingItem.text());
}});
};});
})(this.jQuery);