File: /var/www/html/israel-rentals/wp-content/themes/israel-rentals/js/custom.js
jQuery(document).ready(function ($) {
$('.datepicker').datepicker();
$(".testimonial-slider").slick({
centerMode: true,
centerPadding: "29%",
slidesToShow: 1,
arrows: true,
dots: true,
responsive: [
{
breakpoint: 1600,
settings: {
centerPadding: "22%",
slidesToShow: 1,
},
},
{
breakpoint: 1200,
settings: {
centerPadding: "10%",
slidesToShow: 1,
},
},
{
breakpoint: 768,
settings: {
centerPadding: "10%",
slidesToShow: 1,
arrows: false,
},
},
{
breakpoint: 580,
settings: {
centerPadding: "3%",
slidesToShow: 1,
arrows: false,
},
},
],
});
$('.image-slider').slick({
dots: true,
arrows: true,
fade: true,
prevArrow: '<button type="button" class="slick-prev"><img src="' + slickPrevArrowURL + '"></button>',
nextArrow: '<button type="button" class="slick-next"><img src="' + slickNextArrowURL + '"></button>',
});
// Fix for Slick refresh on tab click
$(".nav-tabs a").click(function () {
$('.slick-slider').slick('refresh');
});
// scroll down action
// function scrollToSec() {
// $('.js-anchor-link').click(function (e) {
// console.log(1);
// e.preventDefault();
// var target = $($(this).attr('href'));
// if (target.length) {
// var scrollTo = target.offset().top - 45;
// console.log(scrollTo);
// $('body, html').animate({ scrollTop: scrollTo + 'px' }, 800);
// }
// });
// }
// if ($(window).innerWidth() >= 991) {
// scrollToSec();
// }
// function scrollToSec() {
// $('.js-anchor-link').click(function (e) {
// e.preventDefault();
// // Get the href attribute and extract only the section ID part
// var targetId = $(this).attr('href').split('#')[1];
// // Find the target section by its ID
// var target = $('#' + targetId);
// // Check if the target exists
// if (target.length) {
// var scrollTo = target.offset().top - 45; // Adjust for any fixed headers
// $('body, html').animate({ scrollTop: scrollTo + 'px' }, 800);
// }
// });
// }
// Only activate the scroll function if the window width is >= 991
// if ($(window).innerWidth() >= 991) {
// scrollToSec();
// }
// scroll down action
// Smooth Scroll Function
function scrollToSec() {
// For anchor links within the same page
$('.js-anchor-link').click(function (e) {
e.preventDefault();
var target = $($(this).attr('href'));
if (target.length) {
var scrollTo = target.offset().top - 45; // Adjust for any fixed header
$('body, html').animate({ scrollTop: scrollTo + 'px' }, 800);
}
});
// For handling external links with a hash (e.g., #contact)
if (window.location.hash) {
var target = $(window.location.hash);
if (target.length) {
var scrollTo = target.offset().top - 45; // Adjust for any fixed header
$('body, html').animate({ scrollTop: scrollTo + 'px' }, 800);
}
}
}
// Initialize on DOM ready
$(document).ready(function () {
scrollToSec();
});
});
// block hover script
const propertyDescriptions = document.querySelectorAll('.property-description');
propertyDescriptions.forEach(propertyDescription => {
const overlay = propertyDescription.nextElementSibling;
if (overlay && overlay.classList.contains('overlay')) {
propertyDescription.addEventListener('mouseenter', () => {
overlay.classList.add('overlay-visible');
propertyDescription.classList.add('hide');
});
propertyDescription.addEventListener('mouseleave', () => {
if (!overlay.matches(':hover')) {
overlay.classList.remove('overlay-visible');
propertyDescription.classList.remove('hide');
}
});
overlay.addEventListener('mouseenter', () => {
overlay.classList.add('overlay-visible');
propertyDescription.classList.add('hide');
});
overlay.addEventListener('mouseleave', () => {
overlay.classList.remove('overlay-visible');
propertyDescription.classList.remove('hide');
});
}
});
jQuery(document).ready(function(){
const openModalEl = document.getElementById('addPropertyModal')
openModalEl.addEventListener('shown.bs.modal', event => {
console.log('modal open');
// jQuery(".up-files-slider").slick({
// slidesToShow: 5,
// slidesToScroll: 1,
// responsive: [
// {
// breakpoint: 600,
// settings: {
// slidesToShow: 2,
// slidesToScroll: 2
// }
// }
// ]
// });
})
})
jQuery(document).ready(function ($) {
// Initialize Parsley validation
$('#addPropertyForm').parsley();
$('#successAlert').hide();
$('#dangerAlert').hide();
// Submit form via AJAX
$('.saveProperty').on('click', function (e) {
e.preventDefault();
// Validate form using Parsley
if ($('#addPropertyForm').parsley().validate()) {
// Get the button and store its original text
var $button = $(this);
var originalText = $button.text();
// Set the button to "Loading..." and disable it
$button.text('Loading...').prop('disabled', true);
// Create FormData object for file upload
var formData = new FormData($('#addPropertyForm')[0]);
formData.append('action', 'add_property');
$.ajax({
url: ajax_obj.ajaxurl, // WordPress AJAX URL
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function (response) {
$button.text(originalText).prop('disabled', false);
if (response.success) {
$('#successAlert').show();
$('#dangerAlert').hide();
$('#successAlert').text('Property submitted successfully.');
setTimeout(function() {
$('#successAlert').fadeOut();
location.reload();
}, 3000);
$('#propertyModal').modal('hide'); // Corrected the modal close method
// Optional: You can reload the page or redirect if needed
// location.reload();
} else {
$('#dangerAlert').show();
$('#successAlert').hide();
// Check if response.data and response.data.message are defined
var errorMessage = response.data && response.data.message ? response.data.message : 'Unknown error occurred.';
$('#dangerAlert').text('Failed to submit property: ' + errorMessage);
}
},
error: function (xhr, status, error) {
$button.text(originalText).prop('disabled', false);
console.error('AJAX Error:', status, error); // Log any errors for debugging
console.log('Response:', xhr.responseText); // Log the full response
alert('An error occurred. Please try again.');
}
});
}
});
});
// jQuery(document).ready(function ($) {
// // Initialize Parsley validation
// $('#addPropertyForm').parsley();
// // Submit form via AJAX
// $('.saveProperty').on('click', function (e) {
// e.preventDefault();
// // Validate form using Parsley
// if ($('#addPropertyForm').parsley().validate()) {
// // Create FormData object for file upload
// var formData = new FormData($('#addPropertyForm')[0]);
// formData.append('action', 'add_property'); // Make sure to specify the action
// $.ajax({
// url: ajax_obj.ajaxurl, // Use the localized variable for the AJAX URL
// type: 'POST',
// data: formData,
// contentType: false,
// processData: false,
// success: function (response) {
// if (response.success) {
// alert('Property submitted successfully.');
// location.reload(); // Reload the page or redirect
// } else {
// alert('Failed to submit property: ' + response.data.message);
// }
// },
// error: function (xhr, status, error) {
// console.error('AJAX Error:', status, error); // Log error details
// console.log('Response:', xhr.responseText); // Log the full response
// alert('An error occurred. Please try again.'); // Notify user
// }
// });
// }
// });
// });
jQuery(document).ready(function($) {
$('.uploaded-files').hide();
// Handle image preview
$('#img_files').on('change', function(event) {
$('.uploaded-files').show();
var files = event.target.files;
var previewContainer = $('#uploaded-images-preview');
// Clear the preview container before showing new files
previewContainer.empty();
// Loop through each selected file
$.each(files, function(index, file) {
// Check if the file is an image (block PDF and other non-image files)
if (file.type.startsWith('image/')) {
var reader = new FileReader();
reader.onload = function(e) {
var fileUrl = e.target.result;
// Add the uploaded image preview to the container
previewContainer.append(`
<div class="up-file-itm">
<div class="slide-img-wrp">
<div class="del-ico">
<button type="button" class="btn-delete">
<img src="${myTheme.templateUrl}/img/icon-delete.svg" alt="Delete">
</button>
</div>
<img src="${fileUrl}" alt="Uploaded Image">
</div>
</div>
`);
}
reader.readAsDataURL(file);
}
});
// Reinitialize Slick slider after adding new files
var totalImages = files.length; // Count the total images
if (totalImages > 5) {
setTimeout(initializeSlickSlider, 100); // Delay to ensure DOM is updated
}
});
// Handle delete button click
$(document).on('click', '.btn-delete', function(e) {
e.preventDefault();
$(this).closest('.up-file-itm').remove();
// Reinitialize Slick slider after deleting files
// setTimeout(initializeSlickSlider, 100); // Delay to ensure DOM is updated
});
// Initialize Slick slider function
function initializeSlickSlider() {
var $slider = $(".up-files-slider");
console.log("Slider Found:", $slider); // Check if the slider element is found
if ($slider.length > 0) {
if ($slider.hasClass('slick-initialized')) {
console.log("Destroying existing Slick instance.");
$slider.slick('unslick'); // Destroy if already initialized
}
console.log("Initializing Slick.");
$slider.slick({
slidesToShow: 5,
slidesToScroll: 1,
responsive: [
{
breakpoint: 600,
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
}
]
});
} else {
console.warn('Slider element not found.');
}
}
// Initial Slick slider setup
// initializeSlickSlider();
});
//contact form submission
jQuery(document).ready(function ($) {
$('#custom-contact-form').parsley(); // Initialize Parsley validation
$('.saveContactUs').on('click', function (e) {
e.preventDefault();
if ($('#custom-contact-form').parsley().validate()) {
var buttonContact = $(this);
var originalTextContact = buttonContact.text();
buttonContact.text('Loading...').prop('disabled', true);
var formData = new FormData($('#custom-contact-form')[0]);
formData.append('action', 'submit_contact_form');
$.ajax({
url: ajax_obj.ajaxurl, // WordPress AJAX URL
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function (response) {
buttonContact.text(originalTextContact).prop('disabled', false);
$('#form-result').html('<div class="alert alert-success">' + response + '</div>');
$('#custom-contact-form')[0].reset(); // Reset the form
$('#custom-contact-form').parsley().reset(); // Reset Parsley validation
},
error: function () {
buttonContact.text(originalTextContact).prop('disabled', false);
$('#form-result').html('<div class="alert alert-danger">There was an error processing your request. Please try again.</div>');
}
});
}
});
});
jQuery(".accordion-button").on("click", function() {
// Find the clicked accordion item
const $accordionItem = jQuery(this).closest(".accordion-item");
// Remove 'hide' class from all accordion items except the clicked one
jQuery(".accordion-item").not($accordionItem).removeClass("hide");
// Toggle 'hide' class on the clicked accordion item
$accordionItem.toggleClass("hide");
// Ensure the button itself does not hide the clicked item when it's open
if ($accordionItem.hasClass("hide")) {
jQuery(this).removeClass("hide");
}
});
jQuery(document).ready(function($) {
var currentYear = new Date().getFullYear();
$('#year').text(currentYear);
});
jQuery(document).ready(function($) {
$('#searchHomeForm').on('submit', function(e) {
e.preventDefault(); // Prevent the default form submission
var searchQuery = $('#searchInput').val(); // Get the search input value
var searchFlag = $('#searchListPro').val();
const showMoreButton = document.querySelector('.view-more');
$.ajax({
url: ajax_obj.ajaxurl,
type: 'POST',
data: {
action: 'fetch_properties_home', // Custom action name
search: searchQuery,
searchFlag:searchFlag // Send the search query
},
success: function(response) {
// $('.searchProperty').html(response); // Update the properties listing with the new response
$('.tabSearchHome').html(response.data.html);
// Update the total property count
$('.match-result').html(response.data.total_properties + ' Properties is available');
showMoreButton.style.display = 'none';
const propertyDescriptions = document.querySelectorAll('.property-description');
propertyDescriptions.forEach(propertyDescription => {
const overlay = propertyDescription.nextElementSibling;
if (overlay && overlay.classList.contains('overlay')) {
propertyDescription.addEventListener('mouseenter', () => {
overlay.classList.add('overlay-visible');
propertyDescription.classList.add('hide');
});
propertyDescription.addEventListener('mouseleave', () => {
if (!overlay.matches(':hover')) {
overlay.classList.remove('overlay-visible');
propertyDescription.classList.remove('hide');
}
});
overlay.addEventListener('mouseenter', () => {
overlay.classList.add('overlay-visible');
propertyDescription.classList.add('hide');
});
overlay.addEventListener('mouseleave', () => {
overlay.classList.remove('overlay-visible');
propertyDescription.classList.remove('hide');
});
}
});
$('.image-slider').slick({
dots: true,
arrows: true,
fade: true,
prevArrow: '<button type="button" class="slick-prev"><img src="' + slickPrevArrowURL + '"></button>',
nextArrow: '<button type="button" class="slick-next"><img src="' + slickNextArrowURL + '"></button>',
});
$('a[data-bs-toggle="tab"]').on('shown.bs.tab', function(event) {
// Check if the clicked tab has the 'active' class and is the specific 'all-tab'
if ($(event.target).hasClass('active')) {
$('.image-slider').slick('unslick');
$('.image-slider').slick({
dots: true,
arrows: true,
fade: true,
prevArrow: '<button type="button" class="slick-prev"><img src="' + slickPrevArrowURL + '"></button>',
nextArrow: '<button type="button" class="slick-next"><img src="' + slickNextArrowURL + '"></button>',
});
}
});
},
error: function() {
alert('An error occurred while searching for properties.');
}
});
});
});