// Websites jQuery functions It's important to understand what is needed and what isn't depending on what features you've added to your website, delete functions if not required.
$(document).ready(function() {
// Safety net plugin reminders
"undefined"==typeof $.fn.validate&&($.fn.validate=function(){this.length&&console.warn('You forgot the validate plugin. You need to add to your page!'),this.length&&alert('You forgot the validate plugin. You need to add to your page!')}),"undefined"==typeof $.fn.placeholder&&($.fn.placeholder=function(){this.length&&console.warn('You forgot the placeholder plugin. You need to add to your page!'),this.length&&alert('You forgot the placeholder plugin. You need to add to your page!')}),"undefined"==typeof $.fn.swipe&&($.fn.swipe=function(){this.length&&console.warn('You forgot the touch swipe plugin. You need to add to your page!'),this.length&&alert('You forgot the touch swipe plugin. You need to add to your page!')});
if (typeof ShowMap == "function") ShowMap({fillColour: '#068743',strokeColour: '#068743'}); // Google map initialisation and custom code to change the polygon colour for draw searches.
// Placeholder shim for older browsers not capable of showing placeholder=""
if ($('input[type=text], input[type=tel], input[type=email], textarea').length) {
$('input[type=text], input[type=tel], input[type=email], textarea').placeholder();
}
// Form validation
if ($('#viewingForm').length) {
$('#viewingForm').validate();
}
if ($('#contactForm').length) {
$('#contactForm').validate();
}
if ($('#valuationForm').length) {
$('#valuationForm').validate();
}
// NB: high to low
var old_stamp_duty_bands = [
{ min: 2000000, rate: 0.07 },
{ min: 1000000, rate: 0.05 },
{ min: 500000, rate: 0.04 },
{ min: 250000, rate: 0.03 },
{ min: 125000, rate: 0.01 }
],
new_stamp_duty_bands = [
{ min: 1500000, rate: 0.12 },
{ min: 925000, rate: 0.10 },
{ min: 250000, rate: 0.05 },
{ min: 125000, rate: 0.02 }
];
/*
$("form.stamp-duty-calc").submit(function (ev) {
ev.preventDefault();
var price = Number($(this).find("input.stamp-duty-price").val().replace(/[^\d.]/g, "")),
banded_price = price, // to mutate during "new duty" calculation
old_duty = 0, new_duty = 0, new_duty_plus_three = 0,
$search = $("form.stamp-duty-search");
if (price == 0) {
alert("Please enter a value");
return;
}
$.each(old_stamp_duty_bands, function () {
if (price > this.min) {
old_duty = price * this.rate;
return false; // "break"
}
});
$.each(new_stamp_duty_bands, function () {
if (banded_price > this.min) {
new_duty += (banded_price - this.min) * this.rate;
banded_price = this.min;
}
});
if ($('#duty_stamp_checkbox').is(":checked"))
{
new_duty_plus_three = new_duty + (price * 0.03);
}
$(".old-stamp-duty").text("\xA3" + number_format(old_duty));
$(".new-stamp-duty").text("\xA3" + number_format(new_duty));
$(".new-duty-plus-three").text("\xA3" + number_format(new_duty_plus_three));
$(".stamp-duty-price-display").text("\xA3" + number_format(price));
$search.show();
$search.find("input.stamp-duty-min-price").val(Math.floor(price * 0.80));
$search.find("input.stamp-duty-max-price").val(Math.ceil( price * 1.10));
$('input[id="showstc"]').click(function(){
if($(this).is(":checked")){
$("#showstc").val("off");
}
if($(this).is(":not(:checked)")){
$("#showstc").val("on");
}
});
});
*/
// This function looks for the home page carousel div on the page and then sets autoplay and pause on hover
if ($('#full-width-carousel').length) {
$('.carousel').carousel({
interval: 7000,
pause: 'hover'
});
}else { // If no home page carousel div exists on page then stop all autoplay on carousels
if ($('.carousel').length) {
$('.carousel').carousel({
interval: false
});
}
}
//Enable swiping for Bootstrap carousels
if ($('.carousel-inner').length) {
$('.carousel-inner').swipe( {
//Generic swipe handler for all directions
swipeRight:function(event, direction, distance, duration, fingerCount) {
$(this).parent().carousel('prev');
},
swipeLeft: function() {
$(this).parent().carousel('next');
},
//Default is 75px, set to 0 for demo so any distance triggers swipe
threshold:0
});
}
// If play and pause buttons are enabled on the image slide show
if ($('#play-and-pause').length) {
$('#button-pause').click(function(event) { // Pause button function
event.preventDefault();// Removes default click behavior and stops page jumping
$('#property-slideshow').carousel('pause');
$('#button-pause').html(' Paused');
$('#button-play').html(' Play');
});
$('#button-play').click(function(event) {// Play button function, set options in here
event.preventDefault();// Removes default click behavior and stops page jumping
$('#property-slideshow').data('bs.carousel').options.interval=3000;
$('#property-slideshow').carousel('cycle');
$('#button-play').html(' Playing');
$('#button-pause').html(' Pause');
});
$('.close-btn').click(function(event) { // When clicking close buttons, pause slideshow
event.preventDefault();// Removes default click behavior and stops page jumping
$('#property-slideshow').carousel('pause');
$('#button-pause').html(' Paused');
$('#button-play').html(' Play');
});
}
});