//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // jQuery //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var mapStyles = [ {"featureType":"road","elementType":"labels","stylers":[{"visibility":"simplified"},{"lightness":20}]},{"featureType":"administrative.land_parcel","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"landscape.man_made","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"transit","elementType":"all","stylers":[{"saturation":-100},{"visibility":"on"},{"lightness":10}]},{"featureType":"road.local","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"road.local","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"road.highway","elementType":"labels","stylers":[{"visibility":"simplified"}]},{"featureType":"poi","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"road.arterial","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":50}]},{"featureType":"water","elementType":"all","stylers":[{"hue":"#a1cdfc"},{"saturation":30},{"lightness":49}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"hue":"#f49935"}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"hue":"#fad959"}]}, {featureType:'road.highway',elementType:'all',stylers:[{hue:'#dddbd7'},{saturation:-92},{lightness:60},{visibility:'on'}]}, {featureType:'landscape.natural',elementType:'all',stylers:[{hue:'#c8c6c3'},{saturation:-71},{lightness:-18},{visibility:'on'}]}, {featureType:'poi',elementType:'all',stylers:[{hue:'#d9d5cd'},{saturation:-70},{lightness:20},{visibility:'on'}]} ]; var $ = jQuery.noConflict(); $(document).ready(function($) { "use strict"; if( $('body').hasClass('navigation-fixed') ){ $('.off-canvas-navigation').css( 'top', - $('.header').height() ); $('#page-canvas').css( 'margin-top',$('.header').height() ); } rating(); setInputsWidth(); adaptBackgroundHeight(); $('.quick-view, .results .item').on('click', function(){ var videourl = $(this).data('iframe'); console.log(videourl); var videotitle = $(this).data('title'); var linkurl = $(this).data('url'); quickView(videourl,videotitle,linkurl); return false; }); // Scrollbar on "Results" section if( $('.items-list').length > 0 ){ $(".items-list").mCustomScrollbar({ mouseWheel:{ scrollAmount: 350 } }); } // Bootstrap tooltip $(function () { $('[data-toggle="tooltip"]').tooltip() }); $('.off-canvas-navigation header').css( 'line-height', $('.header').height() + 'px' ); // Date & Time picker if( $('.input-group.date').length > 0 ){ $('.input-group.date').datepicker({ }); } if( $('.input-daterange').length > 0 ){ $('.input-daterange').datepicker({ todayHighlight: true }); } // Bootstrap Select --------------------------------------------------------------------------------------------------- var select = $('select'); if (select.length > 0 ){ select.selectpicker(); } var bootstrapSelect = $('.bootstrap-select'); var dropDownMenu = $('.dropdown-menu'); bootstrapSelect.on('shown.bs.dropdown', function () { dropDownMenu.removeClass('animation-fade-out'); dropDownMenu.addClass('animation-fade-in'); }); bootstrapSelect.on('hide.bs.dropdown', function () { dropDownMenu.removeClass('animation-fade-in'); dropDownMenu.addClass('animation-fade-out'); }); bootstrapSelect.on('hidden.bs.dropdown', function () { var _this = $(this); $(_this).addClass('open'); setTimeout(function() { $(_this).removeClass('open'); }, 100); }); // Expand content on click -------------------------------------------------------------------------------------------- $('.expand-content').live('click', function(e){ e.preventDefault(); var children = $(this).attr('data-expand'); var parentHeight = $(this).closest('.expandable-content').height(); var contentSize = $( children + ' .content' ).height(); $( children ).toggleClass('collapsed'); $( this ).toggleClass('active'); $( children ).css( 'height' , contentSize ); if( !$( children).hasClass('collapsed') ){ setTimeout(function() { $( children ).css('overflow', 'visible'); }, 400); } else { $( children ).css('overflow', 'hidden'); } $('.has-child').live('click', function(e){ var parent = $(this).closest('.expandable-content'); var childHeight = $( $(this).attr('data-expand') + ' .content').height(); if( $(this).hasClass('active') ){ $(parent).height( parent.height() + childHeight ) } else { $(parent).height(parentHeight); } }); }); // Set width for inputs in horizontal search bar ----------------------------------------------------------------------- // var searchParams = new URLSearchParams(window.location.search); // if (searchParams.get("avideo_params")) { // $( "#redefine-search-form" ).load( "/assets/external/_search-bar2.php?avideo_params="+searchParams.get("avideo_params"), function() { // setInputsWidth(); // //autoComplete(); // }); // } else { // var pathname = window.location.pathname; // if (pathname.indexOf("::avideo_params=")) { // var avideo_params = pathname.split("avideo_params::"); // $( "#redefine-search-form" ).load( "/assets/external/_search-bar2.php?avideo_params="+avideo_params[1], function() { // setInputsWidth(); // //autoComplete(); // }); // } else { // $( "#redefine-search-form" ).load( "/assets/external/_search-bar.html", function() { // setInputsWidth(); // //autoComplete(); // }); // } // } // if( $('#location').length ){ // autoComplete(); // } // Keyboard Shortcuts -------------------------------------------------------------------------------------------------- $(document).bind('keypress', 'F', function(){ $('.redefine-search .expand-content').trigger('click'); if( !$('.search-bar').hasClass('collapsed') ){ setTimeout(function() { $('.search-bar input').first().focus(); }, 200); } return false; }); $(document).bind('keypress', 'M', function(){ $('.header .toggle-navigation').trigger('click'); return false; }); $(document).bind('keypress', '+', function(){ $('.header .submit-item').trigger('click'); return false; }); $(document).keydown(function(e) { switch(e.which) { case 37: // left $('.item-slider').trigger('prev.owl.carousel'); break; case 39: // right $('.item-slider').trigger('next.owl.carousel'); break; case 27: // ESC $('.modal-background').trigger('click'); break; } }); // Smooth Navigation Scrolling ---------------------------------------------------------------------------------------- $('.navigation .nav a[href^="#"], a[href^="#"].roll').on('click',function (e) { e.preventDefault(); var target = this.hash, $target = $(target); if ($(window).width() > 768) { $('html, body').stop().animate({ 'scrollTop': $target.offset().top - $('.navigation').height() }, 2000) } else { $('html, body').stop().animate({ 'scrollTop': $target.offset().top }, 2000) } return false; }); // iCheck ------------------------------------------------------------------------------------------------------------- if ($('.checkbox').length > 0) { $('input').iCheck(); } if ($('.radio').length > 0) { $('input').iCheck(); } $('body').addClass('page-fade-in'); $('a').on('click', function (e) { var attr = $(this).attr('href'); //alert( $(this).attr('href') ); if ( attr.indexOf('#') != 0 ) { e.preventDefault(); var goTo = this.getAttribute("href"); $('body').removeClass('page-fade-in'); $('body').addClass('page-fade-out'); setTimeout(function(){ window.location = goTo; },200); } else if ( $(this).attr('href') == '#' ) { e.preventDefault(); } }); // Dropzone ----------------------------------------------------------------------------------------------------------- if( $('.dropzone').length > 0 ) { Dropzone.autoDiscover = false; $("#file-submit").dropzone({ url: "upload", addRemoveLinks: true }); $("#profile-picture").dropzone({ url: "upload", addRemoveLinks: true }); } // Timepicker --------------------------------------------------------------------------------------------------------- if( $('.oh-timepicker').length > 0 ) { $('.oh-timepicker').timepicker(); } $('.item .quick-view').on('click',function (e) { e.preventDefault(); }); // Items scripts ------------------------------------------------------------------------------------------------------ $('.item.admin-view .hide-item').on('click',function (e) { $(this).closest('.item').toggleClass('is-hidden'); }); // No UI Slider ------------------------------------------------------------------------------------------------------- if( $('.ui-slider').length > 0 ){ $('.ui-slider').each(function(){ var step; if( $(this).attr('data-step') ) { step = parseInt( $(this).attr('data-step') ); } else { step = 10; } var sliderElement = $(this).attr('id'); var element = $( '#' + sliderElement); var valueMin = parseInt( $(this).attr('data-value-min') ); var valueMax = parseInt( $(this).attr('data-value-max') ); $(this).noUiSlider({ start: [ valueMin, valueMax ], connect: true, range: { 'min': valueMin, 'max': valueMax }, step: step }); if( $(this).attr('data-value-type') == 'price' ) { if( $(this).attr('data-currency-placement') == 'before' ) { $(this).Link('lower').to( $(this).children('.values').children('.value-min'), null, wNumb({ prefix: $(this).attr('data-currency'), decimals: 0, thousand: '.' })); $(this).Link('upper').to( $(this).children('.values').children('.value-max'), null, wNumb({ prefix: $(this).attr('data-currency'), decimals: 0, thousand: '.' })); } else if( $(this).attr('data-currency-placement') == 'after' ){ $(this).Link('lower').to( $(this).children('.values').children('.value-min'), null, wNumb({ postfix: $(this).attr('data-currency'), decimals: 0, thousand: ' ' })); $(this).Link('upper').to( $(this).children('.values').children('.value-max'), null, wNumb({ postfix: $(this).attr('data-currency'), decimals: 0, thousand: ' ' })); } } else { $(this).Link('lower').to( $(this).children('.values').children('.value-min'), null, wNumb({ decimals: 0 })); $(this).Link('upper').to( $(this).children('.values').children('.value-max'), null, wNumb({ decimals: 0 })); } }); } }); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // On Load //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $(window).load(function(){ var $equalHeight = $('.equal-height'); for( var i=0; i<$equalHeight.length; i++ ){ equalHeight( $equalHeight ); } }); $(window).resize(function(){ adaptBackgroundHeight(); var $equalHeight = $('.equal-height'); for( var i=0; i<$equalHeight.length; i++ ){ equalHeight( $equalHeight ); } }); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Functions //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function setInputsWidth(){ var $inputRow = $('.search-bar.horizontal .input-row'); for( var i=0; i<$inputRow.length; i++ ){ if( $inputRow.find( $('button[type="submit"]') ).length ){ $inputRow.find('.form-group:last').css('width','initial'); } } var searchBar = $('.search-bar.horizontal .form-group'); for( var a=0; a 0 ){ $('.search-bar.horizontal .form-group:last-child button').css('margin-top', 25) } } } // Autocomplete address ------------------------------------------------------------------------------------------------ function autoComplete(){ if( !$("script[src="proxy.php?url=https%3A%2F%2Fsearchmercials.com%2Fassets%2Fjs%2Fleaflet.js"]").length ){ var input = document.getElementById('location') ; var autocomplete = new google.maps.places.Autocomplete(input, { types: ["geocode"] }); google.maps.event.addListener(autocomplete, 'place_changed', function() { var place = autocomplete.getPlace(); if (!place.geometry) { return; } var address = ''; if (place.address_components) { address = [ (place.address_components[0] && place.address_components[0].short_name || ''), (place.address_components[1] && place.address_components[1].short_name || ''), (place.address_components[2] && place.address_components[2].short_name || '') ].join(' '); } }); } } // Rating -------------------------------------------------------------------------------------------------------------- function rating(element){ var ratingElement = ''+ ''+ ''+ ''+ ''+ ''+ '' ; if( !element ) { element = ''; } $.each( $(element + ' .rating'), function(i) { $(this).append(ratingElement); if( $(this).hasClass('active') ){ $(this).append(''); } var rating = $(this).attr('data-rating'); for( var e = 0; e < rating; e++ ){ var rate = e+1; $(this).children('.stars').children( '.s' + rate ).addClass('active'); } }); var ratingActive = $('.rating.active i'); ratingActive.on('hover',function(){ for( var i=0; i<$(this).attr('data-score'); i++ ){ var a = i+1; $(this).parent().children('.s'+a).addClass('hover'); } }, function(){ for( var i=0; i<$(this).attr('data-score'); i++ ){ var a = i+1; $(this).parent().children('.s'+a).removeClass('hover'); } }); ratingActive.on('click', function(){ $(this).parent().parent().children('input').val( $(this).attr('data-score') ); $(this).parent().children('.fa').removeClass('active'); for( var i=0; i<$(this).attr('data-score'); i++ ){ var a = i+1; $(this).parent().children('.s'+a).addClass('active'); } return false; }); } // Owl Carousel in Modal Window ---------------------------------------------------------------------------------------- function drawOwlCarousel(_rtl){ $.getScript( "/assets/js/owl.carousel.min.js", function( data, textStatus, jqxhr ) { $(".image .gallery").owlCarousel({ rtl: _rtl, items: 1, nav: true, navText: ["",""], responsiveBaseElement: ".image" }); }); } function lazyLoad(selector){ selector.load(function() { $(this).parent().removeClass('loading'); }); } // Equal heights ------------------------------------------------------------------------------------------------------ function equalHeight(container){ var currentTallest = 0, currentRowStart = 0, rowDivs = new Array(), $el, topPosition = 0; $(container).find('.item, .price-box').each(function() { $el = $(this); $($el).height('auto'); topPostion = $el.position().top; if (currentRowStart != topPostion) { for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { rowDivs[currentDiv].height(currentTallest); } rowDivs.length = 0; // empty the array currentRowStart = topPostion; currentTallest = $el.height(); rowDivs.push($el); } else { rowDivs.push($el); currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest); } for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { rowDivs[currentDiv].height(currentTallest); } }); } // Initialize Owl carousel --------------------------------------------------------------------------------------------- function initializeOwl(_rtl){ $.getScript( "/assets/js/owl.carousel.min.js", function( data, textStatus, jqxhr ) { if ($('.owl-carousel').length > 0) { if ($('.carousel-full-width').length > 0) { setCarouselWidth(); } $(".carousel.wide").owlCarousel({ rtl: _rtl, items: 1, responsiveBaseWidth: ".slide", nav: true, navText: ["",""] }); $(".item-slider").owlCarousel({ rtl: _rtl, items: 1, autoHeight: true, responsiveBaseWidth: ".slide", nav: false, callbacks: true, URLhashListener: true, navText: ["",""] }); $(".list-slider").owlCarousel({ rtl: _rtl, items: 1, responsiveBaseWidth: ".slide", nav: true, navText: ["",""] }); $(".testimonials").owlCarousel({ rtl: _rtl, items: 1, responsiveBaseWidth: "blockquote", nav: true, navText: ["",""] }); $('.item-gallery .thumbnails a').on('click', function(){ $('.item-gallery .thumbnails a').each(function(){ $(this).removeClass('active'); }); $(this).addClass('active'); }); $('.item-slider').on('translated.owl.carousel', function(event) { var thumbnailNumber = $('.item-slider .owl-item.active img').attr('data-hash'); $( '.item-gallery .thumbnails #thumbnail-' + thumbnailNumber ).trigger('click'); }); return false; } }); } // Specific data for each item ----------------------------------------------------------------------------------------- function drawItemSpecific(category, json, a){ var itemSpecific = ''; if( category ){ if( category == 'real_estate' ){ if( json.data[a].item_specific ){ if( json.data[a].item_specific.bedrooms ){ itemSpecific += '' + json.data[a].item_specific.bedrooms + ''; } if( json.data[a].item_specific.bathrooms ){ itemSpecific += '' + json.data[a].item_specific.bathrooms + ''; } if( json.data[a].item_specific.area ){ itemSpecific += '' + json.data[a].item_specific.area + '2'; } if( json.data[a].item_specific.garages ){ itemSpecific += '' + json.data[a].item_specific.garages + ''; } return itemSpecific; } } else if ( category == 'bar_restaurant' ){ if( json.data[a].item_specific ){ if( json.data[a].item_specific.menu ){ itemSpecific += 'Menu from: ' + json.data[a].item_specific.menu + ''; } return itemSpecific; } return itemSpecific; } } else { return ''; } return ''; } // Quick View ---------------------------------------------------------------------------------------------------------- function quickView(video,title,url){ $.ajax({ type: 'POST', url: '/assets/external/_modal.php', data: {'videourl':video,'title':title,'url':url}, success: function (data) { // Create HTML element with loaded data $('body').append(data); } }); } // Adapt background height to block element ---------------------------------------------------------------------------- function adaptBackgroundHeight(){ $('.background').each(function(){ if( $(this).children('img').height() < $(this).height() ){ //$(this).children('img').css('right', ( $(this).children('img').width()/2 - $(window).width())/2 ); $(this).children('img').css('width', 'auto'); $(this).children('img').css('height', '100%'); } }); } // Protocol and User location check ------------------------------------------- var $hostname = window.location.hostname; var $pathname = window.location.pathname; function getlocalstorageitem( $var ){ return localStorage.getItem( $var ); } function createCookie(name,value,days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + value + expires + "; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } /* /* Function : setlatlong /* Version : 3.0 - 11/12/2015 /* Subject : Set the latitude and longitude variable from the local storage /* Author : Bennex Louis Edquiba /* Variables : {$var} - [ 'lat' | 'long' | 'geodate' ] */ var lat = readCookie('lat'); var long = readCookie('long'); var datestored = readCookie('geodate'); var geolocationcontrol = readCookie('geolocation'); var latlong = lat+':'+long || $('#area').val(); console.log(datestored); if(datestored!=''){ var daterecorded = new Date(datestored); var todaysDate = new Date(); var dateFormat = new Date(todaysDate.getYear(),todaysDate.getMonth(),todaysDate.getDate()); var dateInterval = $.trim(((dateFormat-daterecorded).toString())); //console.log( "DateIntervalCheck : "+ dateInterval.toString() ); } if (location.protocol !== 'https:') { $.ajax({ url:"/class/common/user.location.check.php", data: {'hostname':$hostname}, type:"POST", dataType:"json", success: function(response){ //console.log(response); $(document).find('#location').each(function(index, el) { $(this).val(response.city); }); //Set the Date Today var dateGet = new Date(); var today = new Date( dateGet.getYear(),dateGet.getMonth(),dateGet.getDate() ); //Set localStorage Items createCookie('lat',response.latitude,1); createCookie('long',response.longitude,1); createCookie('geodate',today,1); createCookie('geolocation',0,1); } }); } else { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition, showError, {enableHighAccuracy:true, timeout:60000, maximumAge:0}); } else { alert("Geolocation is not supported by this browser."); } } function showPosition(position) { //Set the Date Today var dateGet = new Date(); var today = new Date( dateGet.getYear(),dateGet.getMonth(),dateGet.getDate() ); //Set localStorage Items eraseCookie('lat',"",-1); eraseCookie('long',"",-1); createCookie('lat',position.coords.latitude,1); createCookie('long',position.coords.longitude,1); eraseCookie('geodate',"",-1); createCookie('geodate',today,7); createCookie('geolocation',1,1); $.get('https://maps.googleapis.com/maps/api/geocode/json?latlng='+position.coords.latitude+','+position.coords.longitude+'&key=AIzaSyAiaBUw_BmGBw0BNg6oKNOVc6nS4wpAtOA',function(result){ console.log(result); $(document).find('#location').each(function(index, el) { $(this).val(result.results[0].address_components[1].long_name + ' ' +result.results[0].address_components[2].long_name); }); }) console.log(position); } function showError(error) { switch(error.code) { case error.PERMISSION_DENIED: $.ajax({ url:"/class/common/user.location.check.php", data: {'hostname':$hostname}, type:"POST", dataType:"json", success: function(response){ //console.log(response); $(document).find('#location').each(function(index, el) { $(this).val(response.city); }); //Set the Date Today var dateGet = new Date(); var today = new Date( dateGet.getYear(),dateGet.getMonth(),dateGet.getDate() ); //Set localStorage Items createCookie('lat',response.latitude,1); createCookie('long',response.longitude,1); createCookie('geodate',today,1); createCookie('geolocation',0,1); } }); //if( !isMobile.any() ) alert("User denied the request for Geolocation.") //else alert("User denied the request for Geolocation.") break; case error.POSITION_UNAVAILABLE: if( !isMobile.any() ) alert("Location information is unavailable.") break; case error.TIMEOUT: if( !isMobile.any() ) alert("The request to get user location timed out.") //else alert("The request to get user location timed out.") break; case error.UNKNOWN_ERROR: if( !isMobile.any() ) alert("An unknown error occurred.") //else alert("An unknown error occurred.") break; } }