/*--Leigh Brown custom.js--*/
document.addEventListener("DOMContentLoaded", function () {
const companysite = account_info.website_owner_type==="company";
const officesite = account_info.website_owner_type==="entity";
const teamsite = account_info.website_owner_type==="entity"&& account_info.is_team_site===true;
const agentsite = account_info.website_owner_type === "user";
var agentPage = function() {
if ( $('#resources-bodycontent #agent-intro').length ) {
return true;
} else {
return false;
}
}();
if ( officesite ) {
officeNavLinks();
officeElfsightHome();
elfsightCustomPage();
activeCampaign();
customFooter();
}
else if( agentsite && account_info.agents[0].agentsubdomain === 'https://www.leighsells.com' ) {
leighsellsNavLinks();
leighsellsElfsightHome();
elfsightCustomPage();
activeCampaign();
loansenseWidget();
smoothScroll();
customFooter();
} else {
console.log('Not customized by kvTemplates.com');
}
customFavicon();
credits();
customHorizontalSearch();
customListingCarousel({
arrayAgent: account_info.mylistings,
arrayAgency: account_info.agencylistings,
filterAgents: ["Leigh Brown"],
filterZipCodes: [],
minPrice: 5000,
sortByPrice: true,
sectionName: "custom-listings p-t-3 p-b-2",
sectionContainerType: "container",
wrapperName: "listing-box-wrapper listing-box-background",
carouselWrapper: "listing-carousel-wrapper",
carouselName: "listing-carousel owl-carousel",
loop: false,
autoplay: false,
slidePauseTime: 5000,
sectionHeader: "Our Featured Listings",
appendTo: "",
insertAfter: "#agent-video",
});
//Custom Functions
function customFavicon() {
$('link[rel="icon"]').attr(
"href",
"https://kunversion-frontend-blog.s3.amazonaws.com/images/customarea-onecommunity.realestate-0-8dec9361e705662365b030f60a90c7c0ff71ab2b.png"
);
}
function officeNavLinks() {
//Remove unwanted links
$('.nav-primary li:contains("Sell")').remove();
$('.nav-primary .sub-menu li:contains("Blog")').remove();
$('.nav-primary li:contains("Resources")').remove();
//Add buyer/seller resource links to top level
$(`
`).prependTo('.footer-top-left');
}
function smoothScroll() {
$(document).on('click', 'a[href^="#"]', function (event) {
event.preventDefault();
$('html, body').animate({
scrollTop: $($.attr(this, 'href')).offset().top + -200
}, 500);
});
}//END SMOOTH SCROLL
function credits() {
if ( $('.kvcredits').length) {
var year = new Date().getFullYear();
$(`
`).appendTo(".footer-bottom");
}
} //END CREDITS
function customHorizontalSearch() {
if (agentPage) {
$('#custom-search #horizontal-search > .container > .row > form').unwrap();
$('#custom-search #horizontal-search form .row > .form-group:nth-child(1)').attr('class','form-group location-form-group col-xs-10 col-md-8 col-lg-10');
$('#custom-search #horizontal-search form .row > .form-group:nth-child(2)').attr('class','form-group col-xs-12');
$('#custom-search #horizontal-search form .row > .form-group:nth-child(n+3):nth-child(-n+6)').attr('class','form-group col-xs-6');
$('#custom-search #horizontal-search form .row > .form-group:nth-child(7)').attr('class','form-group col-xs-2 col-lg-1');
$('#custom-search #horizontal-search #location_search').attr('placeholder','Search by address, neighborhood, city or ZIP code');
$('#custom-search #horizontal-search input.tt-input').attr('placeholder','Search by address, neighborhood, city or ZIP code');
$('#custom-search #horizontal-search #qs-submit').html('
');
$('#custom-search #horizontal-search #more-options').remove();
$('#custom-search #horizontal-search form .row > .form-group:nth-child(7)').before(`
`);
$(`
`).appendTo('#custom-search #horizontal-search form');
$('#custom-search #horizontal-search form .row > .form-group:nth-child(n+2):nth-child(-n+6)').prependTo('#custom-search #horizontal-search #collapseFilters .card-body .row');
$('#custom-search #horizontal-search').removeClass('p-b-3').attr('style','opacity:1;');
}
}
function customListingCarousel(data) {
if (agentPage) {
Array.prototype.sortOn = function(key){
this.sort(function(a, b){
l1 = parseInt(a[key].replace(/[^0-9.]+/g, ""));
l2 = parseInt(b[key].replace(/[^0-9.]+/g, ""));
if(l1 > l2){
return -1;
}else if(l1 < l2){
return 1;
}
return 0;
});
}
if (data.arrayAgency.length || data.arrayAgent.length) {
var agencyListings = data.arrayAgency || [];
var agentListings = data.arrayAgent || [];
//Remove agent listing from broker listings to not duplicate
if( agentListings.length > 0 ) {
var listingAgentName = agentListings[0].agent;
agencyListings = agencyListings.filter((listing)=>{
return !listingAgentName.includes(listing.agent)
});
}
//Filter only agent XYZs listings
if (data.filterAgents.length !== 0) {
agentListings = agentListings.filter((listing)=>{
return data.filterAgents.includes(listing.agent)
});
}
if (data.filterZipCodes.length !== 0) {
agencyListings = agencyListings.filter((listing)=>{
return data.filterZipCodes.includes(listing.zip)
});
}
if (data.sortByPrice === true) {
if (agencyListings.length != 0) {
agencyListings.sortOn("price");
}
if (agentListings.length != 0) {
agentListings.sortOn("price");
}
}
if (data.minPrice !== '') {
agencyListings = agencyListings.filter(function (listing) {
return listing.price.replace(/[^0-9.]+/g, "") > data.minPrice;
});
}
const listings = $.merge($.merge([], agentListings), agencyListings);
const wrapper = $(
`
`
);
if ( data.appendTo !== '') {
$(wrapper).appendTo(data.appendTo);
} else if ( data.insertAfter !== '') {
if ( $(data.insertAfter).length ) {
$(wrapper).insertAfter(data.insertAfter);
} else if ( $('.listings.container').length ) {
$(wrapper).insertBefore('.listings.container').first();
} else {
$(wrapper).insertBefore( $('#footer').prev('div.p-t-3.p-b-3.background-white') );
}
}
const header = $(
`
${data.sectionHeader}
`).appendTo(wrapper);
const wrapperContainer = $(`
`).appendTo(wrapper);
const carouselWrapper = $(`
`).appendTo(wrapperContainer);
const carouselName = $(`
`).appendTo(carouselWrapper);
listings.slice(0, data.numOfItems).forEach(function(listing) {
const photo = listing["photo"];
const price = listing["price"];
const type = listing["listing_type_label"];
const beds = listing["beds"];
const baths = listing["baths"];
const size = listing["footage"];
const address = listing["address"];
const city = listing["city"];
const state = listing["state"];
const zip = listing["zip"];
const url = listing["url"];
const mlsLogo = listing["mlslogo"];
const noPhoto = url.indexOf("?v=") > -1;
var listingItem = $(
`
`
);
listingItem.appendTo(carouselName);
const listingItemImage = $(`
`).appendTo(listingItem);
const listingItemTitle = $(`
`).appendTo(listingItem);
const listingItemContentLink = $(`
`).appendTo(listingItem);
const listingItemContent = $(`
`).appendTo(listingItemContentLink);
if ( type !== undefined ) {
$(`
Type
${type}
`).appendTo(listingItemContent);
}
if ( size !== "0" ) {
$(`
Footage
${size} SqFt
`).appendTo(listingItemContent);
}
if ( beds !== "0" && baths !== "0") {
$(`
Rooms
${beds} Beds + ${baths} Baths
`).appendTo(listingItemContent);
}
if ( mlsLogo !== undefined ) {
$(`
`).appendTo(listingItemContent);
}
});
} //END IF
const customListingSlider = $(".custom-listings .owl-carousel");
customListingSlider.owlCarousel({
nav: true,
dots: false,
mouseDrag: true,
touchDrag: true,
loop: data.loop,
margin: 10,
autoplay: data.autoplay,
lazyLoad: true,
lazyLoadEager: 1,
navText: ['
', '
'],
autoplayTimeout: data.slidePauseTime,
animateOut: "fadeOut",
animateIn: "fadeIn",
responsive: {
0: {
items: 1,
},
576: {
items: 2,
},
992: {
items: 3,
},
1200: {
items: 4,
},
},
});
customListingSlider.on("changed.owl.carousel", function(e) {
customListingSlider.trigger("stop.owl.autoplay");
customListingSlider.trigger("play.owl.autoplay");
});
}
}//END CUSTOM LISTING CAROUSEL
});