(function() { function floorPlanOption() { var self = this; self.name = ko.observable(); self.isDefault = ko.observable(false); self.selected = ko.observable(false); self.elementID = ko.observable(); self.isSelected = ko.computed(function(){ if(self.selected()){ document.getElementById(self.elementID()).style.display = "block"; }else { document.getElementById(self.elementID()).style.display = "none"; } }); } function floorPlanOptionGroup() { var self = this; self.name = ko.observable(); self.options = ko.observableArray(); self.selectedOption = ko.observable(); self.defaultOption = ko.observable(); self.setSelectedOption = function(){ ko.utils.arrayForEach(self.options(), function(option) { option().selected(false); }); this.selected(true); } } function FloorPlan(data){ var self = this; var floorPlanMapping = { }; ko.mapping.fromJS(data, floorPlanMapping, self); self.floorPlanFile = ko.observable(); self.optionGroups = ko.observableArray(); self.rawSVG = ko.observable(); if(self.svgFloorplanFileUrl() != false && self.svgFloorplanFileUrl() != null){ // $.get(self.svgFloorplanFileUrl() ) // .done(function( returnFile ) { // self.rawSVG(returnFile.documentElement); // returnFile = new XMLSerializer().serializeToString(returnFile.documentElement); // self.floorPlanFile(returnFile); // $(returnFile).find('#Options').children().each(function( index ) { // // create new option group // var optionGroup = ko.observable(new floorPlanOptionGroup()); // var groupName = $(this).data("name"); // optionGroup().name(groupName); // $(this).children().each(function( index ) { // var dataName = $(this).data("name"); // var elemID = $(this).attr('id'); // if(dataName != 'OptionIcon' && dataName != undefined){ // // create new options // var option = ko.observable(new floorPlanOption()); // // find out if its the default option // option().elementID(elemID); // reg = /default/i; // if(reg.test(dataName)){ // option().isDefault(true); // option().selected(true); // optionGroup().selectedOption(option); // dataName = dataName.replace(/default/ig, ""); // } // // remove default from name and add it to option // option().name(dataName); // optionGroup().options().push(option); // } // }); // self.optionGroups().push(optionGroup()); // // $(this).find(".OptionIcon" ).append(''); // }); // }); } self.creatingPDF = ko.observable(false); self.downloadPDF = function(){ // self.creatingPDF(true); // // window.jsPDF = require('jspdf'); // svg = $("#floorPlanFile svg")[0]; // svg_to_pdf(svg, function (pdf) { // download_pdf(self.name(), pdf.output('dataurlstring')); // self.creatingPDF(false); // }); } self.nameClass = ko.computed(function(){ let n = self.name(); nameClass = n.replace(/\s/g, '_') return nameClass; }); self.numberWithCommas = function(x) { x=x.toString().replace('$', ""); x=x.toString().replace('sqft', ""); x=x.toString().replace('SQFT', ""); x=x.toString().replace('sq.ft.', ""); x=x.toString().replace('SQ.FT.', ""); x=x.toString().replace(",", ","); return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } self.sqftFormatted = ko.computed(function(){ formatSqft = self.sqft(); return self.numberWithCommas(formatSqft); }); } function Status(data){ var self = this; var statusMapping = { }; ko.mapping.fromJS(data, statusMapping, self); } function Lot(data, statuses){ var self = this; var lotMapping = { 'floorplan': { create: function(options) { if(options.data != null){ return ko.observable(new FloorPlan(options.data)); } else { return ko.observable(null) } } } }; ko.mapping.fromJS(data, lotMapping, self); self.hasFloorPlan = ko.computed(function(){ return (self.floorplan_id() != null?true:false); }) // Set status to inactive if null if(self.status_id() == null){ self.status_id(5) } self.statuses = statuses; self.numberWithCommas = function(x) { x=x.toString().replace('$', ""); x=x.toString().replace(",", ","); return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } self.priceFormatted = ko.computed(function(){ if(self.price() == 'tbd' || self.price() == 'TBD') { return 'TBD'; } else if(self.price() == '0' || self.price() == '$0'){ return 'TBD'; } else { formatPrice = self.price(); if(self.price() == 'TBD'){ return 'TBD' } else { return '$'+self.numberWithCommas(formatPrice); } } }); self.setStatus = ko.computed(function() { var search = self.status_id(); return ko.utils.arrayFirst(self.statuses(), function(status) { return status().id() == self.status_id(); }); }, self); self.status = ko.computed(function(){ return self.setStatus()().name(); }); self.statusClass = ko.computed(function(){ let s = self.status(); statusClass = s.replace(/\s/g, '_') return statusClass; }); // SET JS ON LOT theLot = document.getElementById('Lot_'+self.lotNumber()); if(theLot == null){ theLot = document.getElementById('Lot_'+self.lotNumber()+'_1_'); } if(theLot!= null){ theLot.setAttribute("data-lot-number", self.lotNumber()); theLot.setAttribute("data-toggle","modal"); theLot.setAttribute("data-target","#exampleModal"); theLot.setAttribute("data-has-floor-plan",self.hasFloorPlan()); theLot.classList.add(self.statusClass()); theLot.classList.add(self.customClasses()); // ADD FLOORPLAN CLASS if(self.hasFloorPlan()){ theLot.classList.add('hasFloorPlan'); } else { theLot.classList.add('noFloorPlan'); } } self.showFloorplan = ko.observable(false); self.showSlideshow = ko.observable(true); self.showContactForm= ko.observable(false); self.setShowSlideshow = function(){ self.showContactForm(false); self.showFloorplan(false); self.showSlideshow(true); } self.setShowFloorplan = function(){ self.showContactForm(false); self.showSlideshow(false); self.showFloorplan(true); } self.setShowContactForm = function(){ self.showSlideshow(false); self.showFloorplan(false); self.showContactForm(true); } // $('#lotPopup').on('hidden.bs.modal', function (e) { // self.showContactForm(false); // self.showFloorplan(false); // self.showSlideshow(true); // }) } /* Sitemap JS */ function SiteMap(data){ var self = this; var communityMapping = { 'statuses': { create: function(options) { return ko.observable(new Status(options.data)); } }, 'homes': { create: function(options) { return ko.observable(new Lot(options.data, self.statuses)); } } }; self.floorplanLots = ko.observableArray(); // SET FLOORPLAN LOTS TO ARRAY BEFORE MAPPING ko.mapping.fromJS(data, communityMapping, self); // self.setSelectedOption = function(){ // self.selectedOptionGroupName($(this).parent().data("name")); // self.showOptionsPopup(true); // } self.setSiteMapOptions = function(){ // $('#Options').children().each(function( index ) { // // create new option group // var optionGroup = ko.observable(new floorPlanOptionGroup()); // var groupName = $(this).data("name"); // optionGroup().name(groupName); // $(this).children().each(function( index ) { // var dataName = $(this).data("name"); // var elemID = $(this).attr('id'); // if(dataName != 'OptionIcon' && dataName != undefined){ // // create new options // var option = ko.observable(new floorPlanOption()); // // find out if its the default option // option().elementID(elemID); // reg = /default/i; // if(reg.test(dataName)){ // option().isDefault(true); // option().selected(true); // optionGroup().selectedOption(option); // dataName = dataName.replace(/default/ig, ""); // } // // remove default from name and add it to option // option().name(dataName); // optionGroup().options().push(option); // } // }); // self.optionGroups().push(optionGroup()); // // $(this).find(".OptionIcon" ).append(''); // }); } self.selectedLotID = ko.observable(); self.selectedLot = ko.observable(); self.slideshowImageIndex = ko.observable(0); // Next/previous controls self.jumpToSlide = function(slide){ toSlide = ((self.selectedLot().floorplan().images().length > slide) && (slide >=0)?slide:0); self.slideshowImageIndex(toSlide); } self.nextSlide = function(){ let newVal = self.slideshowImageIndex() + 1; self.slideshowImageIndex((newVal > (self.selectedLot().floorplan().images().length-1)?0:newVal)); } self.prevSlide = function(){ let newVal = self.slideshowImageIndex() - 1; self.slideshowImageIndex((newVal < 0 ?self.selectedLot().floorplan().images().length-1:newVal)); } // Thumbnail image controls self.currentSlide = function(n) { self.showSlides(self.slideshowImageIndex(n)); } self.selectedLotWatcher = ko.computed(function(){ ko.utils.arrayForEach(self.homes(), function(home) { if(home().lotNumber() == self.selectedLotID()) { self.slideshowImageIndex(0); self.selectedLot(home()); setCLass( "g[id*='OptionIcon']",'OptionIcon'); setCLass( "g[id*='Default']",'default'); self.setSiteMapOptions(); } }); }) // $('#lotPopup').on('hidden.bs.modal', function (e) { // self.selectedLotID('') // }) self.setSelectedLotFromHomeTile = function(lot){ self.selectedLotID(lot.lotNumber()); } self.showModal=ko.observable(false) self.hideModal = function(){ self.showModal(false); } self.setSelectedLot = function(){ lotNumber = this.getAttribute("data-lot-number"); self.selectedLotID(lotNumber); self.showModal(true); return true; } self.optionGroups = ko.observableArray(); self.showOptionsPopup = ko.observable(false); self.selectedOptionGroupName = ko.observable(); self.selectedOptionGroup = ko.observable(); self.selectedOptionGroupWatcher = ko.computed(function(){ filter = self.selectedOptionGroupName(); ko.utils.arrayForEach(self.optionGroups(), function(group) { if (group.name() == filter) { self.selectedOptionGroup(group); } }); }); self.popupPositionLeft = ko.observable(); self.popupPositionTop = ko.observable(); self.closePopupOptions = function(){ self.showOptionsPopup(false); } self.loadingHomes = ko.observable(true); self.visibleHomes = ko.computed(function(){ if (!self.homes) { self.loadingHomes(false); return '[]'; } else { var i=1; return ko.utils.arrayFilter(self.homes(), function(home) { // SETS FLOOR PLAN NAME FOR ANY LOT ADDED if(home().floorplan_id()!=null){ self.floorplanLots()['floorplan_'+home().floorplan().id()] = {"available":ko.observableArray([]), "coming_soon":ko.observableArray([])} } if(i==self.homes().length){ // TURNS OFF LOADING HOMES self.loadingHomes(false); } i++; if(home().status() == 'Sold'){ return false; } else if(home().status() == 'Inactive'){ return false; } else if(home().status() == 'Parking'){ return false; } else { if(home().floorplan_id()!=null){ return true; } else { return false; } } }); } }).extend({ deferred: true }); self.models = ko.computed(function(){ return ko.utils.arrayFilter(self.visibleHomes(), function(home) { return home().status() == 'Model'; }); }).extend({ deferred: true }); self.availableHomes = ko.computed(function(){ return ko.utils.arrayFilter(self.visibleHomes(), function(home) { if(home().status() == 'Available'){ self.floorplanLots()['floorplan_'+home().floorplan().id()].available.push(home().lotNumber()) return true; } else { return false } }); }).extend({ deferred: true }); self.comingSoonHomes = ko.computed(function(){ return ko.utils.arrayFilter(self.visibleHomes(), function(home) { if(home().status() == 'Coming Soon'){ self.floorplanLots()['floorplan_'+home().floorplan().id()].coming_soon.push(home().lotNumber()) return true; } else { return false } }); }).extend({ deferred: true }); self.comingSoonPlans = ko.dependentObservable(function() { var seen = []; return self.comingSoonHomes().filter(function(home) { return seen.indexOf(home().floorplan().name()) == -1 && seen.push(home().floorplan().name()); }); }); self.clickDefault = function(){ return true; } lotsWithPlans = document.getElementsByClassName("hasFloorPlan") for (let i = 0; i < lotsWithPlans.length; i++) { lotsWithPlans[i].addEventListener("click", self.setSelectedLot); } // $('.hasFloorPlan').on( "click", self.setSelectedLot ); // $(document).on( "click", '.OptionIcon', self.setSelectedOption ); sitemapDiv.style.display = "block"; } function setCLass(selecter, className){ let elements = document.querySelectorAll(selecter); len = elements !== null ? elements.length : 0, i = 0; for(i; i < len; i++) { elements[i].classList.add(className); } } function initSiteMap(siteMapJSON){ console.log('init sitemap'); setCLass("g[id*='Lot']", "lot"); setCLass("g[id*='lot']", "lot"); setCLass("g[id*='Sold']", "sold_text"); setCLass("g[id*='sold']", "sold_text"); setCLass("g[id*='Text']", "text"); setCLass("g[id*='text']", "text"); setCLass("path[id*='Text']", "text"); setCLass("path[id*='text']", "text"); setCLass("g[id*='Model']", "model_text"); setCLass("g[id*='model']", "model_text"); var isBound = function() { return !!ko.dataFor(sitemapDiv); }; if(!isBound()){ ko.bindingHandlers.fadeVisible = { init: function(element, valueAccessor) { // Initially set the element to be instantly visible/hidden depending on the value var value = valueAccessor(); $(element).toggle(ko.unwrap(value)); // Use "unwrapObservable" so we can handle values that may or may not be observable }, update: function(element, valueAccessor) { // Whenever the value subsequently changes, slowly fade the element in or out var value = valueAccessor(); ko.unwrap(value) ? $(element).fadeIn() : $(element).fadeOut(); } }; ko.bindingHandlers.slideVisible = { init: function(element, valueAccessor) { // Initially set the element to be instantly visible/hidden depending on the value var value = valueAccessor(); $(element).toggle(ko.unwrap(value)); // Use "unwrapObservable" so we can handle values that may or may not be observable }, update: function(element, valueAccessor) { // Whenever the value subsequently changes, slowly fade the element in or out var value = valueAccessor(); ko.unwrap(value) ? $(element).slideDown() : $(element).slideUp(); } }; ko.applyBindings(new SiteMap(siteMapJSON)); } } // end init sitemap var modal = ` `; //JS const sitemapDiv = document.getElementById('svgMap'); if(sitemapDiv == null){ console.log('no sitemap found'); } else { var knockoutLoad = document.createElement( "script" ); knockoutLoad.src ='https://www.tailoredcommunities.com/js/knockout.js'; const head = document.getElementsByTagName( "head" )[0]; head.appendChild( knockoutLoad ); var loadingContent = `

Loading

`; sitemapID = sitemapDiv.dataset.sitemap sitemapDiv.innerHTML=loadingContent; let url = 'https://www.tayloredcommunities.com/community/sitemap/data/'+sitemapID+'?v1.0.0' console.log(sitemapID); fetch(url) .then(response => response.json()) .then(data => { var sitemapData = data; fetch(data.siteMapFile) .then(response => response.text()) .then(sitemap => { // CSS var link = document.createElement( "link" ); link.href = 'https://www.tailoredcommunities.com/css/sitemap.css?v4' link.type = "text/css"; link.rel = "stylesheet"; link.media = "screen,print"; // MODAL var modalDiv = document.createElement('div'); // is a node modalDiv.innerHTML = modal; modalDiv.classList.add('smModal'); document.body.appendChild(modalDiv); head.appendChild( link ); sitemapDiv.innerHTML = sitemap; initSiteMap(sitemapData); }) }) } // END CHECK FOR SITEMAP DIV })() // END IIFE