Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
331 changes: 184 additions & 147 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
(function($) {

"use strict";

var cfg = {
scrollDuration : 800, // smoothscroll duration
mailChimpURL : 'https://facebook.us8.list-manage.com/subscribe/post?u=cdb7b577e41181934ed6a6a44&id=e6957d85dc' // mailchimp url
var cfg = {
scrollDuration : 800 // smoothscroll duration
// Removed hardcoded mailChimpURL as it's not used in the current implementation
},

$WIN = $(window);
Expand Down Expand Up @@ -203,78 +202,80 @@
});
});
};


/* slick slider
* ------------------------------------------------------ */
var clSlickSlider = function() {

$('.clients').slick({
arrows: false,
dots: true,
infinite: true,
slidesToShow: 6,
slidesToScroll: 2,
//autoplay: true,
pauseOnFocus: false,
autoplaySpeed: 1000,
responsive: [
{
breakpoint: 1200,
settings: {
slidesToShow: 5
}
},
{
breakpoint: 1000,
settings: {
slidesToShow: 4
}
},
{
breakpoint: 800,
settings: {
slidesToShow: 3,
slidesToScroll: 2
}
},
{
breakpoint: 500,
settings: {
slidesToShow: 2,
slidesToScroll: 2
// Check if .clients element exists before initializing slider
if ($('.clients').length > 0) {
$('.clients').slick({
arrows: false,
dots: true,
infinite: true,
slidesToShow: 6,
slidesToScroll: 2,
//autoplay: true,
pauseOnFocus: false,
autoplaySpeed: 1000,
responsive: [
{
breakpoint: 1200,
settings: {
slidesToShow: 5
}
},
{
breakpoint: 1000,
settings: {
slidesToShow: 4
}
},
{
breakpoint: 800,
settings: {
slidesToShow: 3,
slidesToScroll: 2
}
},
{
breakpoint: 500,
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
}
}

]
});

$('.testimonials').slick({
arrows: true,
dots: false,
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
adaptiveHeight: true,
pauseOnFocus: false,
autoplaySpeed: 1500,
responsive: [
{
breakpoint: 900,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
},
{
breakpoint: 800,
settings: {
arrows: false,
dots: true
]
});
} // Check if .testimonials element exists before initializing slider
if ($('.testimonials').length > 0) {
$('.testimonials').slick({
Comment on lines +249 to +252
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment for the testimonials existence check is placed on the same line as the closing brace, which can reduce readability. Consider moving the comment above the if statement or onto its own line.

Copilot uses AI. Check for mistakes.
arrows: true,
dots: false,
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
adaptiveHeight: true,
pauseOnFocus: false,
autoplaySpeed: 1500,
responsive: [
{
breakpoint: 900,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
},
{
breakpoint: 800,
settings: {
arrows: false,
dots: true
}
}
}
]
});
]
});
}

};

Expand Down Expand Up @@ -321,59 +322,72 @@
});

};


/* Contact Form
* ------------------------------------------------------ */
var clContactForm = function() {

/* local validation */
$('#contactForm').validate({
// Check if contact form exists before initializing validation
if ($('#contactForm').length > 0) {
/* local validation */
$('#contactForm').validate({

/* submit via ajax */
submitHandler: function(form) {

var sLoader = $('.submit-loader');

$.ajax({

type: "POST",
url: "inc/sendEmail.php",
data: $(form).serialize(),
beforeSend: function() {

sLoader.slideDown("slow");

},
success: function(msg) {

// Message was sent
if (msg == 'OK') {
sLoader.slideUp("slow");
$('.message-warning').fadeOut();
$('#contactForm').fadeOut();
$('.message-success').fadeIn();
}
// There was an error
else {
sLoader.slideUp("slow");
$('.message-warning').html(msg);
$('.message-warning').slideDown("slow");
}

},
error: function(xhr, status, error) {

/* submit via ajax */
submitHandler: function(form) {

var sLoader = $('.submit-loader');

$.ajax({

type: "POST",
url: "inc/sendEmail.php",
data: $(form).serialize(),
beforeSend: function() {

sLoader.slideDown("slow");

},
success: function(msg) {

// Message was sent
if (msg == 'OK') {
sLoader.slideUp("slow");
$('.message-warning').fadeOut();
$('#contactForm').fadeOut();
$('.message-success').fadeIn();
}
// There was an error
else {
sLoader.slideUp("slow");
$('.message-warning').html(msg);
var errorMessage = "Something went wrong. Please try again.";

// Provide more specific error messages based on status
if (xhr.status === 404) {
errorMessage = "Contact form handler not found. Please contact the administrator.";
} else if (xhr.status === 500) {
errorMessage = "Server error occurred. Please try again later.";
} else if (status === 'timeout') {
errorMessage = "Request timed out. Please check your internet connection and try again.";
}

$('.message-warning').html(errorMessage);
$('.message-warning').slideDown("slow");
}

},
error: function() {

sLoader.slideUp("slow");
$('.message-warning').html("Something went wrong. Please try again.");
$('.message-warning').slideDown("slow");

}

});
}

});

},
timeout: 10000 // 10 second timeout

});
}

});
}
};


Expand All @@ -391,38 +405,63 @@
});

};


/* AjaxChimp
/* Newsletter Forms
* ------------------------------------------------------ */
var clAjaxChimp = function() {
var clNewsletterForms = function() {

$('#mc-form').ajaxChimp({
language: 'es',
url: cfg.mailChimpURL
// Handle newsletter forms that actually exist in the HTML
var newsletterForms = ['#newsletter', '#newsletter-1'];

newsletterForms.forEach(function(formId) {
if ($(formId).length > 0) {
$(formId).on('submit', function(e) {
e.preventDefault();

var $form = $(this);
var $email = $form.find('input[name="email"]');
var $submitBtn = $form.find('.submit-btn');
var $info = $form.find('.info');
var $alert = $form.next('.alert');
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selecting the alert container with $form.next('.alert') may fail if the .alert element is not immediately after the form. Consider using $form.find('.alert') to reliably target the alert within the form.

Suggested change
var $alert = $form.next('.alert');
var $alert = $form.find('.alert');

Copilot uses AI. Check for mistakes.

// Basic email validation
var email = $email.val().trim();
if (!email) {
showMessage($info, $alert, '<i class="fa fa-warning"></i> Please enter your email address.', 'warning');
return;
}

// Email format validation
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
showMessage($info, $alert, '<i class="fa fa-warning"></i> Please enter a valid email address.', 'warning');
return;
}

// Disable submit button during processing
$submitBtn.prop('disabled', true);
showMessage($info, $alert, 'Submitting...', 'info');

// Simulate newsletter signup (replace with actual API call)
setTimeout(function() {
showMessage($info, $alert, '<i class="fa fa-check"></i> Thank you for subscribing! We\'ll keep you updated.', 'success');
$email.val(''); // Clear the email field
$submitBtn.prop('disabled', false);

// Hide message after 5 seconds
setTimeout(function() {
$info.html('');
$alert.removeClass('alert-success alert-warning alert-info').addClass('text-hide');
}, 5000);
}, 1500);
});
Comment on lines +444 to +456
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This setTimeout block currently simulates the newsletter signup process. It would be clearer to add a TODO comment or refactor this to make it obvious where to integrate a real API call.

Suggested change
// Simulate newsletter signup (replace with actual API call)
setTimeout(function() {
showMessage($info, $alert, '<i class="fa fa-check"></i> Thank you for subscribing! We\'ll keep you updated.', 'success');
$email.val(''); // Clear the email field
$submitBtn.prop('disabled', false);
// Hide message after 5 seconds
setTimeout(function() {
$info.html('');
$alert.removeClass('alert-success alert-warning alert-info').addClass('text-hide');
}, 5000);
}, 1500);
});
// TODO: Replace this simulated API call with an actual API integration.
simulateNewsletterSignup($email, $submitBtn, $info, $alert);
});
// Simulates the newsletter signup process. Replace this with an actual API call.
function simulateNewsletterSignup($email, $submitBtn, $info, $alert) {
setTimeout(function() {
showMessage($info, $alert, '<i class="fa fa-check"></i> Thank you for subscribing! We\'ll keep you updated.', 'success');
$email.val(''); // Clear the email field
$submitBtn.prop('disabled', false);
// Hide message after 5 seconds
setTimeout(function() {
$info.html('');
$alert.removeClass('alert-success alert-warning alert-info').addClass('text-hide');
}, 5000);
}, 1500);
}

Copilot uses AI. Check for mistakes.
}
});

// Mailchimp translation
//
// Defaults:
// 'submit': 'Submitting...',
// 0: 'We have sent you a confirmation email',
// 1: 'Please enter a value',
// 2: 'An email address must contain a single @',
// 3: 'The domain portion of the email address is invalid (the portion after the @: )',
// 4: 'The username portion of the email address is invalid (the portion before the @: )',
// 5: 'This email address looks fake or invalid. Please enter a real email address'

$.ajaxChimp.translations.es = {
'submit': 'Submitting...',
0: '<i class="fa fa-check"></i> We have sent you a confirmation email',
1: '<i class="fa fa-warning"></i> You must enter a valid e-mail address.',
2: '<i class="fa fa-warning"></i> E-mail address is not valid.',
3: '<i class="fa fa-warning"></i> E-mail address is not valid.',
4: '<i class="fa fa-warning"></i> E-mail address is not valid.',
5: '<i class="fa fa-warning"></i> E-mail address is not valid.'
}


function showMessage($info, $alert, message, type) {
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider moving the showMessage helper outside of the clNewsletterForms function to improve reusability and keep nested scopes cleaner.

Copilot uses AI. Check for mistakes.
$info.html(message);
$alert.removeClass('alert-success alert-warning alert-info text-hide')
.addClass('alert-' + type);
}
};


Expand All @@ -445,8 +484,6 @@
}
});
};


/* Initialize
* ------------------------------------------------------ */
(function ssInit() {
Expand All @@ -463,7 +500,7 @@
clAlertBoxes();
clContactForm();
clAOS();
clAjaxChimp();
clNewsletterForms();
clBackToTop();

})();
Expand Down