/**
* Class OnOffice
*
* @author CKo/ÖS
* @link onOffice
*
*/
var OnOffice = {};
OnOffice.Base = {
init: function () {
this.multilanguage(); // language switch - shows current language
this.navigation(); // add bootstrap classes to main navigation
this.banner(); // initialize slick slider
this.hideTopObject(); // hiding top-object-section on startpage if empty
this.removeDataRows(); // remove empty unnecessary data-rows in listings
this.teamSlider(); // making a teamslider if more than 3 members
this.keepFormFields(); // keep form fields on refresh
this.externalLink(); // enables external links in smart site
this.topLink(); // scroll event on click for top-link
this.restrictSubmit(); // restrict formsubmit to first click
},
// add contentkey as class for body-tag
bodyClass: function (contentkey) {
var body_class = contentkey.split(".");
document.querySelector("body").classList.add("body-" + body_class[0]);
},
// language switch - shows current language
multilanguage: function () {
$(".languages ul li.selected a").appendTo(".languages .active-language");
$(".languages ul li.selected").hide().remove();
},
// language switch - shows available languages (onclick)
multilanguageTrigger: function () {
$(".languages .active-language a").removeAttr("href");
if ($(".languages .active-language").hasClass("triggered")) {
$(".languages .active-language").removeClass("triggered");
$(".languages ul").fadeOut(200);
}
else {
$(".languages .active-language").addClass("triggered");
$(".languages ul").fadeIn(200);
}
// remove class "triggered" when pressing escape key (close language picker)
$(document).keydown(function (e) {
if (e.keyCode == 27) {
if ($(".languages .active-language").hasClass("triggered")) {
$(".languages .active-language").removeClass("triggered");
$(".languages ul").fadeOut();
}
}
});
//remove class "triggered" when clicking outside of box (close language picker)
$(document).on("click", function (e) {
if (!$(".languages .active-language").is(e.target) && $(".languages .active-language").has(e.target).length === 0) {
if ($(".languages .active-language").hasClass("triggered")) {
$(".languages .active-language").removeClass("triggered");
$(".languages ul").fadeOut();
}
}
});
//remove class "triggered" when scrolling (close language picker)
$(document).on("scroll", function () {
if ($(".languages .active-language").hasClass("triggered")) {
$(".languages .active-language").removeClass("triggered");
$(".languages ul").fadeOut(200);
}
});
},
// add bootstrap classes to main navigation
navigation: function () {
var navigation = document.querySelector("#navigation");
var li = navigation.getElementsByTagName("li");
var numberOfLi = li.length;
document.querySelector(".navbar .navbar-collapse > ul").classList.add("navbar-nav", "ml-auto");
for (var i = 0; i < numberOfLi; i++) {
li[i].classList.add("nav-item");
li[i].getElementsByTagName("a")[0].classList.add("nav-link");
if (li[i].getElementsByTagName("ul")[0] != undefined) {
li[i].classList.add("subnav");
li[i].getElementsByTagName("ul")[0].classList.add("dropdown", "dropdown-menu");
}
}
},
// initialize slick slider
banner: function () {
$(".banner ul").slick({
arrows: false,
autoplay: true,
infinite: true,
speed: 1000,
fade: true,
cssEase: "linear",
});
},
// hiding top-object-section on startpage if empty
hideTopObject: function () {
if ($("#startseiteobjecttop0 .row .obj-list-object").length == 0) {
$(".container-top-objects").remove();
}
},
// remove empty unnecessary data-rows in listings
removeDataRows: function () {
var objects = document.getElementsByClassName("wohnen");
for (var i = 0; i < objects.length; i++) {
var el = objects[i].getElementsByClassName("col");
var empty = true;
for (var k = 0; k < el.length; k++) {
if (el[k].innerHTML != "") {
empty = false;
}
}
if (empty == false) {
var parent = objects[i].parentNode;
var grundstueck = parent.getElementsByClassName("grundstueck");
parent.removeChild(grundstueck[0]);
}
}
},
// making a teamslider if more than 3 members
teamSlider: function () {
if ($(".team-members .member").length > 3) {
$(".team-members").slick({
prevArrow: '',
nextArrow: '',
infinite: true,
slidesToShow: 3,
slidesToScroll: 1,
responsive: [
{
breakpoint: 992,
settings: {
slidesToShow: 2,
},
},
{
breakpoint: 767,
settings: {
slidesToShow: 1,
},
},
],
});
// giving same height to all members in slider
var maxHeight = 0;
$(".slick-list .member").each(function () {
var currentHeight = $(this).height();
if (currentHeight > maxHeight) {
maxHeight = currentHeight;
}
});
$(".slick-list .member").height(maxHeight);
}
},
// keep form fields on refresh
keepFormFields: function () {
var url = document.URL.split("?");
if (url[1] != undefined) {
url = url[1].split("&");
for (x = 0; x <= url.length - 1; x++) {
var this_parameter = url[x].split("=");
if (this_parameter != "") {
var this_name = this_parameter[0].replace(/\%5B/g, "[").replace(/\%5D/g, "]");
var this_value = "";
if (this_parameter[1] != undefined) {
this_value = decodeURI(
this_parameter[1]
.replace(/\+/g, " ")
.replace(/\+\%2F\+/g, " / ")
.replace(/\%2C/g, ",")
);
}
$('select[name="' + this_name + '"]').each(function () {
$(this).find("option").each(function () {
if ($(this).val() == this_value) {
$(this).attr("selected", "selected");
if ($(this).val() == "grundstueck") {
$(this).change();
}
}
});
});
$('input[name="' + this_name + '"]').each(function () {
if ($(this).attr("type") == "text" || $(this).attr("type") == "hidden") {
if (this_value != "") {
$(this).val(this_value);
}
}
else if ($(this).attr("type") == "checkbox") {
if (this_value != "") {
$(this).attr("checked", "checked");
}
}
else if ($(this).attr("type") == "radio" && $(this).val() == this_value) {
$(this).attr("checked", "checked");
}
else if ($(this).attr("type") == "number" || $(this).attr("type") == "hidden") {
if (this_value != "") {
$(this).val(this_value);
}
}
});
}
}
}
},
// enables external links in smart site
externalLink: function () {
$("a[href]").each(function () {
var thisHref = $(this).attr("href");
if (thisHref.indexOf("?link") >= 0) {
var externalLink = thisHref.split("?link=");
$(this).attr("href", externalLink[1]);
if (externalLink[1].indexOf("http") >= 0) {
$(this).attr("target", "_blank");
}
}
});
},
// scroll event on click for top-link
topLink: function () {
var topLinkTrigger = document.querySelector(".top-link-bar i");
var rootElement = document.documentElement;
topLinkTrigger.addEventListener("click", function () {
rootElement.scrollTo({
top: 0,
behavior: "smooth",
});
});
},
// restrict formsubmit to first click
restrictSubmit: function() {
$('form').on('submit', function(){
$(this).find(':input[type=submit]').prop('disabled', true);
});
},
};
OnOffice.Optional = {
init: function () {
this.hideFooterSocial(); // hide social media area in footer if empty
this.hideJumpbox(); // hide jumpbox if only one page
this.setInitialTheme(); // set initial session storage value vor ligh/dark mode
this.newsletterBox(); // newsletter box (appears once per cookie)
// this.cookie(); // hide cookie box when cookie is set
this.dsgvoAddRequired(); // Add attr required to DSGVO-checkbox in forms
this.formFeedback(); // hide/show form feedbacks after submit
this.iService(); // I-service
this.iServiceEmptyVal(); // remove empty row I-Service
this.hideEmptySections(); // hide sections on home page if empty
this.setNiceSelect(); // set all select fields to be niceSelect
},
// return true when element is about to enter viewport
isIntoView: function (element) {
var documentViewTop = $(window).scrollTop();
var documentViewBottom = documentViewTop + $(window).height();
var elementTop = $(element).offset().top;
var elementBottom = elementTop + $(element).height();
return elementBottom <= documentViewBottom && elementTop >= documentViewTop;
},
// build and load map when element entering viewport
loadMapInViewport: function () {
$(window).on("scroll load", function () {
if (OnOffice.Optional.isIntoView("#map-outer")) {
var geocoder;
var map;
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 14,
center: latlng,
};
map = new google.maps.Map(document.getElementById("map-outer"), mapOptions);
var address = document.getElementById("map-address").value;
geocoder.geocode({ address: address }, function (results, status) {
if (status == "OK") {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
});
}
else {
console.log("Geocode was not successful for the following reason: " + status);
}
});
$(this).off("scroll");
}
});
},
// hide social media area in footer if empty
hideFooterSocial: function () {
const socialMediaArea = $(".footer-social");
const socialMediaList = $(".footer-social li");
if (!socialMediaList.length) {
socialMediaArea.hide();
}
},
// hide jumpbox if only one page
hideJumpbox: function () {
var pageCount = $(
".frame-bottom .jumpbox span a, .objektjumpbox span a, .jumpbox-frame span a, .objtracking_jumpbox span a, .nws_jumpbox span a").length;
if (pageCount == 1) {
$(".frame-bottom .jumpbox, .objektjumpbox, .jumpbox-frame, .objtracking_jumpbox, .nws_jumpbox").hide();
}
},
// set initial session storage value vor ligh/dark mode
setInitialTheme: function () {
if (sessionStorage.getItem("status") == "dark") {
sessionStorage.setItem("status", "dark");
$("body").addClass("dark-mode");
$("html").attr("data-theme", "dark");
$("#customSwitches").prop("checked", true);
// $(".dark-mode-switch").fadeIn(300);
}
else {
sessionStorage.setItem("status", "light");
$("html").attr("data-theme", "light");
// $(".dark-mode-switch").fadeIn(300);
}
},
// toggle dark/light mode
darkModeTrigger: function () {
if (sessionStorage.getItem("status") == "light") {
$("body").addClass("dark-mode");
$("html").attr("data-theme", "dark");
sessionStorage.setItem("status", "dark");
}
else if (sessionStorage.getItem("status") == "dark") {
$("body").removeClass("dark-mode");
$("html").attr("data-theme", "light");
sessionStorage.setItem("status", "light");
}
},
// newsletter box (appears once per cookie)
newsletterBox: function () {
$('.nlf-close').on('click', function () {
document.cookie = 'nlf-slidebox-cookie=1;path=/';
$('.nlf-stage').slideUp();
$('.nlf-slidebox').fadeOut();
});
$('.nlf-form').on('submit', function () {
document.cookie = 'nlf-slidebox-cookie=1;path=/';
$('.nlf-stage').slideUp();
$('.nlf-slidebox').fadeOut();
});
$(document).scroll(function () {
var y = $(this).scrollTop();
if (document.cookie.indexOf('nlf-slidebox-cookie=1') != -1) {
$('.nlf-stage').hide();
}
else {
if (y > 640) {
$('.nlf-slidebox').fadeIn();
$('.nlf-stage').slideDown();
}
}
});
if (window.location.href.indexOf('nlfsend') > -1) {
setTimeout(function () {
$('.nlf-slidebox').fadeIn();
$('.nlf-thxbox').slideDown();
}, 500);
}
$('.nlf-thxclose').on('click', function () {
$('.nlf-thxbox').slideUp();
$('.nlf-slidebox').fadeOut();
});
},
cookie: function () {
if (document.cookie.indexOf('hidecookie=1') != -1) {
$('#cookie').hide();
}
else {
$('#cookie').show();
$('#cookieCloser').show();
}
},
// Add attr required to DSGVO-checkbox in forms
dsgvoAddRequired: function () {
$(document).find('input#DSGVOStatus').prop('required', true);
},
// hide/show form feedbacks after submit
formFeedback: function () {
if ($('.formfeedbacks .successalert p').length || $('.formfeedbacks .erroralert p').length) {
if ($('.formfeedbacks .erroralert p').length) {
$('.formfeedbacks .erroralert').css('border', '5px solid #dc3545');
}
else {
$('.formfeedbacks .erroralert').hide();
}
$('.formfeedbacks').show();
}
},
// I-service
iService: function () {
$('.iservice-listobject').each(function () {
$(this).find('tr').each(function () {
var contentTd = $.trim($(this).find('td:eq(2)').html());
if (contentTd == '') {
$(this).hide().remove();
}
});
});
},
// remove empty row I-Service
iServiceEmptyVal: function () {
$('.iservice-listobject').each(function () {
var contentEmpty = $(this).find('.emptyval');
if (contentEmpty.length) {
$(contentEmpty).parent().parent().hide();
}
});
},
hideEmptySections: function() {
if ($('.welcome-text > .container > .row > .col').text().trim() == '') {
$('.welcome-text').hide();
}
if (!$('.cards > .container > .row').find('.card').length) {
$('.cards').hide();
}
if (!$('.team > .container > .team-members').find('.member').length) {
$('.team').hide();
}
if ($('.about > .container > .row > .col').text().trim() == '') {
$('.about').hide();
}
if ($('.references > .container-fluid').find('.noobject').length) {
$('.references').hide();
}
if ($('.news > .container > .row > .col > div').text().trim() == '') {
$('.news').hide();
}
if (!$('.partner .partners').find('.partner-logo').length) {
$('.partner').hide();
}
},
setNiceSelect: function() {
var optionWithoutSearch = {searchable: false};
var optionWithSearch = {searchable: true};
var allSelects = document.getElementsByTagName("select");
for (let i = 0; i < allSelects.length; i++) {
if (allSelects[i].classList.contains('select')) {
allSelects[i].firstChild.nextElementSibling.setAttribute('selected', true);
}
}
for (let i = 0; i < allSelects.length; i++) {
if (allSelects[i].classList.contains('searchable')) {
NiceSelect.bind(allSelects[i], optionWithSearch);
}
else {
NiceSelect.bind(allSelects[i], optionWithoutSearch);
}
}
$('.nice-select .nice-select-search').attr('placeholder', 'Suchen...');
}
};
OnOffice.List = {
init: function () {
this.hidePrice(); // show/hide price if empty
this.estateStatusFlag(); // set estate status flag
this.hideDetailsInList(); // hide details in list view if empty
this.lazyLoading(); // lazy loading for obj-list objects
},
// show/hide price if empty
hidePrice: function() {
$('.obj-list-object').each(function() {
const kaufpreis = $(this).find('.obj-kaufpreis');
const mietpreis = $(this).find('.obj-mietpreis');
if (kaufpreis.text().trim() !== '' && mietpreis.text().trim() !== '') {
kaufpreis.show();
mietpreis.hide();
}
});
},
// set estate status flag
estateStatusFlag: function () {
var objects = document.getElementsByClassName("obj-list-picture");
for (var i = 0; i < objects.length; i++) {
var el = objects[i].getElementsByTagName("span")[0];
var status = el.className;
if (status == "status-top") {
el.innerHTML = 'Top-Angebot';
}
else if (status == "status-new") {
el.innerHTML = 'Neu';
}
else if (status == "status-rented") {
el.innerHTML = 'Vermietet';
}
else if (status == "status-sold") {
el.innerHTML = 'Verkauft';
}
else if (status == "status-reduced") {
el.innerHTML = 'Reduziert';
}
else if (status == "status-reserved") {
el.innerHTML = 'Reserviert';
}
else if (status == "status-reference") {
el.innerHTML = 'Referenz';
}
else if (status == "status-courtage_free") {
el.innerHTML = 'Courtage-frei';
}
else if (status == "status-object_of_the_day") {
el.innerHTML = 'Objekt des Tages';
}
else if (status == "status-exclusive") {
el.innerHTML = 'Exklusiv';
}
}
},
// hide details in list view if empty
hideDetailsInList: function () {
$('.obj-list-object span[title|="Fläche"]').each(function () {
if (!$(this).find('.object-area-wrapper').length) {
$(this).remove();
}
});
$('.obj-list-data .col:empty').each(function () {
$(this).remove();
});
},
lazyLoading: function () {
$('.obj-list-picture').each(function () {
$(this).find('img').addClass('lazy');
});
$('.lazy').lazy({
effect: 'fadeIn', // animation type
effectTime: 200, // animation duration
threshold: 500, // load image 500px before entering in view
enableThrottle: true,
throttle: 250, // check every 250ms
});
},
tabfilter: function () {
$(".sortierbutton").on("click", function () {
$(".sortierbutton").removeClass("active");
var clickedButton = $(this).attr("id");
$(".requestfield").val(clickedButton);
switch (clickedButton) {
case "sort-haus":
$("#sort-art").val("haus");
break;
case "sort-wohnung":
$("#sort-art").val("wohnung");
break;
case "sort-gewerbe":
$("#sort-nutzung").val("gewerbe");
break;
case "sort-grundstueck":
$("#sort-art").val("grundstueck");
break;
default:
console.error("Tabfilter error");
}
$(".frame-sort form .submit").trigger("click");
});
var chosenSort = $(".chosen").val();
switch (chosenSort) {
case "sort-haus":
$("#sort-haus").addClass("active");
break;
case "sort-wohnung":
$("#sort-wohnung").addClass("active");
break;
case "sort-gewerbe":
$("#sort-gewerbe").addClass("active");
break;
case "sort-grundstueck":
$("#sort-grundstueck").addClass("active");
break;
default:
$("#sort-all").addClass("active");
}
}
};
OnOffice.DetailView = {
init: function () {
this.equalizeHeightsOfGalleryAndTable(); // setting the detail-table on same height as the gallery
this.checkOgulo(); // hide container-ogulo if src of iframe is empty
this.detailSlider(); // making an estateslider if more than one other interesting estate
this.removeEmptyFreetextFields(); // check for empty freetext fields and remove them
this.checkYoutube(); // shows container-youtube if not empty
this.checkVimeo(); // shows container-vimeo if not empty
this.checkReference(); // check if object is reference
},
// setting the detail-table on same height as the gallery
equalizeHeightsOfGalleryAndTable: function () {
if (document.querySelector('.fotorama') !== null) {
if (window.innerWidth > 992) {
let galleryHeight = document.querySelector(".fotorama").offsetHeight;
let tableBox = document.querySelector(".obj-table .inner-data-box");
let table = tableBox.querySelector("table");
let tableHeight = table.offsetHeight;
let tableHeadlineHeight = tableBox.querySelector(".headline").offsetHeight;
let button = document.querySelector(".obj-button-down");
table.style.height = galleryHeight - tableHeadlineHeight - 105 + "px";
button.addEventListener("click", function () {
if (table.classList.contains("opened")) {
table.classList.remove("opened");
tableBox.querySelector("i").classList.remove("fa-rotate-180");
table.style.height = galleryHeight - tableHeadlineHeight - 105 + "px";
}
else {
table.classList.add("opened");
tableBox.querySelector("i").classList.add("fa-rotate-180");
table.style.height = tableHeight + "px";
}
});
$(window).on('resize', function() {
let galleryHeight = document.querySelector(".fotorama").offsetHeight;
let tableBox = document.querySelector(".obj-table .inner-data-box");
let table = tableBox.querySelector("table");
let tableHeight = table.offsetHeight;
let tableHeadlineHeight = tableBox.querySelector(".headline").offsetHeight;
let button = document.querySelector(".obj-button-down");
table.style.height = galleryHeight - tableHeadlineHeight - 105 + "px";
button.addEventListener("click", function () {
if (table.classList.contains("opened")) {
table.classList.remove("opened");
tableBox.querySelector("i").classList.remove("fa-rotate-180");
table.style.height = galleryHeight - tableHeadlineHeight - 105 + "px";
}
else {
table.classList.add("opened");
tableBox.querySelector("i").classList.add("fa-rotate-180");
table.style.height = tableHeight + "px";
}
});
});
}
}
},
// hide container-ogulo if src of iframe is empty
checkOgulo: function () {
if ($(".container-ogulo iframe").attr("src") != "") {
$(".container-ogulo").show();
}
else {
$(".container-ogulo").hide();
}
},
// making an estateslider if more than one other interesting estate
detailSlider: function () {
if ($(".detailobjekt").length > 1) {
$(".detailliste").slick({
autoplay: true,
prevArrow: '',
nextArrow: '',
infinite: true,
responsive: [
{
breakpoint: 992,
settings: {
slidesToShow: 2,
slidesToScroll: 1,
},
},
{
breakpoint: 767,
settings: {
slidesToShow: 1,
},
},
],
});
}
else if ($(".detailobjekt").length == 0) {
$(".moreobjects").remove();
}
},
// check for empty freetext fields and remove them
removeEmptyFreetextFields: function () {
$(".freetext").each(function () {
if ($(this).find("span").text() == "") {
$(this).remove();
}
});
if ($.trim($('.energy-data table').html()) == '' && $.trim($('.energy-image').html()) == '') {
$(".obj-energy").remove();
}
},
// shows container-youtube if not empty
checkYoutube: function () {
if ($(".container-youtube .youtube iframe").attr("src") != "") {
$(".container-youtube").show();
}
},
// shows container-vimeo if not empty
checkVimeo: function () {
if ($(".container-vimeo .vimeo iframe").attr("src") != "") {
$(".container-vimeo").show();
}
},
// check if object is reference
checkReference: function () {
var referencecheck = $(".referencecheck").val();
if (referencecheck == "1") {
$(".hide-if-reference").remove();
}
},
// open street map in detail view
openStreetMap: function () {
if ($('.showmap').val() == '0') {
$('#osm-detail').hide();
}
else {
$('#osm-detail').show();
}
var estate = {
'lat': $('.latitude').val(),
'lng': $('.longitude').val()
};
var coordinates = [estate.lat, estate.lng];
var marker = L.marker(coordinates);
var container = L.DomUtil.get('osm-detail');
if (container != null) {
container._leaflet_id = null;
}
var osmDetailMap = L.map('osm-detail', {
scrollWheelZoom: false,
dragging: false
}).setView(coordinates, 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data © OpenStreetMap contributors',
maxZoom: 18
}).addTo(osmDetailMap);
if ($('.showmarker').val() == '1') {
marker.addTo(osmDetailMap);
}
},
};
OnOffice.Objekttracking = {
init: function () {
this.headlineOnSameHeight(); // set headlines on same height
this.toggleDetails(); // toggle details by clicking + (or -)
},
// set headlines on same height
headlineOnSameHeight: function () {
if (window.innerWidth > 767) {
var highestHeadline = 0;
$(".objekttracking .listenobjekt").each(function () {
var thisHeight = $(this).find("h2").height();
if (thisHeight > highestHeadline) {
highestHeadline = thisHeight;
}
});
$(".objekttracking .listenobjekt h2").height(highestHeadline);
}
},
// toggle details by clicking + (or -)
toggleDetails: function () {
$(".showmore").on("click", function () {
$(this).parent().parent().next().find("div#tracking-bemerkung").slideToggle("slow");
if ($(".tracking-details .showmore").html() == "+") {
$(this).html("-");
}
else if ($(".tracking-details .showmore").html() == "-") {
$(this).html("+");
}
});
}
};