' + safeMsg;
if (hasFile) {
var safeFileName = $('
').text(fileInput.files[0].name).html();
msgHtml += '
' + safeFileName + '
';
}
msgHtml += '
';
$('#chat-widget-messages').append(msgHtml);
$('#chat-widget-input').val('');
$('#chat-widget-file-input').val('');
$('#chat-file-preview-bar').addClass('d-none').removeClass('d-flex');
scrollChatToBottom();
});
});
// Live Header Search logic
$('#search').on('keyup focus', function(){ search(); });
function search(){
var searchKey = $('#search').val();
if(searchKey && searchKey.trim().length > 0){
$('body').addClass("typed-search-box-shown");
$('.typed-search-box').removeClass('d-none');
$('.search-preloader').removeClass('d-none');
$.post('https://www.mrporterstore.com/ajax-search', {
_token: AIZ.data.csrf,
search: searchKey,
seller_id: AIZ.data.seller_id
}, function(data){
if(data == '0'){
$('#search-content').html(null);
var safeSearchKey = $('
').text(searchKey).html();
$('.typed-search-box .search-nothing').removeClass('d-none').html("Sorry, nothing found for" + '
"'+safeSearchKey+'"');
$('.search-preloader').addClass('d-none');
}
else{
$('.typed-search-box .search-nothing').addClass('d-none').html(null);
$('#search-content').html(data);
$('.search-preloader').addClass('d-none');
}
});
}
else {
$('.typed-search-box').addClass('d-none');
$('body').removeClass("typed-search-box-shown");
}
}
$(".aiz-user-top-menu").on("mouseover", function () { $(".hover-user-top-menu").addClass('active'); })
.on("mouseout", function () { $(".hover-user-top-menu").removeClass('active'); });
$(document).on("click", function(event){
var $trigger = $("#category-menu-bar");
if($trigger.length && $trigger !== event.target && !$trigger.has(event.target).length){
$("#click-category-menu").slideUp("fast");
$("#category-menu-bar-icon").removeClass('show');
}
});
function updateNavCart(view,count){
$('.cart-count').html(count);
$('#cart_items').html(view);
}
function removeFromCart(key){
$.post('https://www.mrporterstore.com/cart/removeFromCart', {
_token : AIZ.data.csrf,
id : key
}, function(data){
updateNavCart(data.nav_cart_view, data.cart_count);
$('#cart-details').html(data.cart_view);
AIZ.plugins.notify('danger', "Item has been removed from cart");
var $sideCount = $('#cart_items_sidenav');
if ($sideCount.length) {
var currentVal = parseInt($sideCount.text().replace(/\D/g, ''), 10) || 0;
$sideCount.html(Math.max(0, currentVal - 1));
}
});
}
function showLoginModal() { $('#login_modal').modal('show'); }
function addToWishList(id){
AIZ.plugins.notify('warning', "Please login first");
}
function showAddToCartModal(id){
if(!$('#modal-size').hasClass('modal-lg')){ $('#modal-size').addClass('modal-lg'); }
$('#addToCart-modal-body').html(null);
$('#addToCart').modal('show');
$('.c-preloader').show();
$.post('https://www.mrporterstore.com/cart/show-cart-modal', {
_token: AIZ.data.csrf,
id: id,
seller_id: AIZ.data.seller_id
}, function(data){
$('.c-preloader').hide();
$('#addToCart-modal-body').html(data);
AIZ.plugins.slickCarousel();
AIZ.plugins.zoom();
AIZ.extra.plusMinus();
getVariantPrice();
});
}
// Sidebar Offcanvas Sidenav interactions (Slide drawer controller)
const rightOffcanvas = document.getElementById('rightOffcanvas');
const overlay = document.getElementById('rightOffcanvasOverlay');
function showAddToCartRightCanvas(id) {
const $social_chat = $('.sc-q8c6tt-3');
if ($social_chat.length) { $social_chat.addClass('d-none'); }
if (rightOffcanvas) { rightOffcanvas.classList.add('active'); }
if (overlay) { overlay.classList.add('active'); }
document.body.classList.add('body-no-scroll');
if (rightOffcanvas) {
rightOffcanvas.innerHTML = '
';
}
$.ajax({
url: 'https://www.mrporterstore.com/cart/show-variant-canvas',
type: 'POST',
data: {
_token: AIZ.data.csrf,
id: id,
seller_id: AIZ.data.seller_id
},
success: function (data) {
if (rightOffcanvas) { rightOffcanvas.innerHTML = data; }
AIZ.plugins.slickCarousel();
AIZ.plugins.zoom();
AIZ.extra.plusMinus();
getVariantPrice();
},
error: function () {
if (rightOffcanvas) {
rightOffcanvas.innerHTML = '
' + "Failed to load stock data" + '
';
}
}
});
}
function closeRightcanvas() {
if (rightOffcanvas) { rightOffcanvas.classList.remove('active'); }
if (overlay) { overlay.classList.remove('active'); }
document.body.classList.remove('body-no-scroll');
const $social_chat = $('.sc-q8c6tt-3');
if ($social_chat.length) { $social_chat.removeClass('d-none'); }
}
function closeOffcanvas() { closeRightcanvas(); }
if (overlay) { overlay.addEventListener('click', closeRightcanvas); }
document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeRightcanvas(); });
$(document).on('change click', '#option-choice-form input', function () { getVariantPrice(); });
function getVariantPrice(){
if($('#option-choice-form input[name=quantity]').val() > 0 && checkAddToCartValidity()){
$.ajax({
type:"POST",
url: 'https://www.mrporterstore.com/product/variant-price',
data: getCartFormData(),
success: function(data){
const responseImage = data.image || null;
if (responseImage) {
const thumbEl = document.querySelector('.thumb-slider');
const mainEl = document.querySelector('.main-slider');
const thumbSwiper = thumbEl && thumbEl.swiper ? thumbEl.swiper : null;
const mainSwiper = mainEl && mainEl.swiper ? mainEl.swiper : null;
let found = false;
$('.thumb-slider .swiper-slide').each(function (index) {
const slideImage = $(this).data('variation-image');
if (String(slideImage) === String(responseImage)) {
found = true;
if (thumbSwiper && typeof thumbSwiper.slideTo === 'function') thumbSwiper.slideTo(index);
if (mainSwiper && typeof mainSwiper.slideTo === 'function') mainSwiper.slideTo(index);
$(this).trigger('click');
return false;
}
});
if (!found) {
if (thumbSwiper && typeof thumbSwiper.slideTo === 'function') thumbSwiper.slideTo(0);
if (mainSwiper && typeof mainSwiper.slideTo === 'function') mainSwiper.slideTo(0);
}
}
$('#option-choice-form #chosen_price_div').removeClass('d-none');
$('#option-choice-form #chosen_price_div #chosen_price').html(data.price);
$('#variant_sku_section #variant_sku').html(data.sku);
$('#option-choice-form #selected_variant').html(data.variation);
$('#available-quantity').html(data.quantity);
$('.input-number').prop('max', data.max_limit);
if(parseInt(data.in_stock) == 0 && data.digital == 0){
$('.buy-now').addClass('d-none');
$('.add-to-cart').addClass('d-none');
$('.out-of-stock').removeClass('d-none');
} else {
$('.buy-now').removeClass('d-none');
$('.add-to-cart').removeClass('d-none');
$('.out-of-stock').addClass('d-none');
}
AIZ.extra.plusMinus();
}
});
$('#add_to_cart_count').text('(' + String($('#option-choice-form input[name=quantity]').val()).padStart(2, '0') + ')');
}
}
function checkAddToCartValidity(){
var names = {};
$('#option-choice-form input:radio').each(function() {
names[$(this).attr('name')] = true;
});
var count = 0;
$.each(names, function() { count++; });
if($('#option-choice-form input:radio:checked').length == count){ return true; }
return false;
}
function addToCart(){
if(checkAddToCartValidity()) {
animateAddToCartButton('#added_to_cart_btn', 'loading');
$('#addToCart').modal('show');
$('.c-preloader').show();
$.ajax({
type: "POST",
url: 'https://www.mrporterstore.com/cart/addtocart',
data: getCartFormData(),
success: function(data){
animateAddToCartButton('#added_to_cart_btn', 'success');
$('#addToCart-modal-body').html(null);
$('.c-preloader').hide();
$('#modal-size').removeClass('modal-lg');
$('#addToCart-modal-body').html(data.modal_view);
AIZ.extra.plusMinus();
AIZ.plugins.slickCarousel();
updateNavCart(data.nav_cart_view, data.cart_count);
if ("0" == 1){
pushGA4Event(data.ga4Data);
}
},
error: function(xhr, status, error) {
animateAddToCartButton('#added_to_cart_btn', 'reset');
$('.c-preloader').hide();
$('#addToCart').modal('hide');
AIZ.plugins.notify('danger', "Something went wrong. Please try again.");
}
});
if ("0" == 1){
fbq('track', 'AddToCart', {content_type: 'product'});
}
} else {
animateAddToCartButton('#added_to_cart_btn', 'reset');
AIZ.plugins.notify('warning', "Please choose all the options");
}
}
function buyNow(){
if(checkAddToCartValidity()) {
$('#addToCart-modal-body').html(null);
$('#addToCart').modal('show');
$('.c-preloader').show();
$.ajax({
type: "POST",
url: 'https://www.mrporterstore.com/cart/addtocart',
data: getCartFormData(),
success: function(data){
if(data.status == 1){
$('#addToCart-modal-body').html(data.modal_view);
updateNavCart(data.nav_cart_view, data.cart_count);
window.location.replace("https://www.mrporterstore.com/cart");
if ("0" == 1){ pushGA4Event(data.ga4Data); }
} else {
$('#addToCart-modal-body').html(null);
$('.c-preloader').hide();
$('#modal-size').removeClass('modal-lg');
$('#addToCart-modal-body').html(data.modal_view);
}
},
error: function(xhr, status, error) {
$('.c-preloader').hide();
$('#addToCart').modal('hide');
AIZ.plugins.notify('danger', "Something went wrong. Please try again.");
}
});
} else {
AIZ.plugins.notify('warning', "Please choose all the options");
}
}
function clickToSlide(btn,id){
$('#'+id+' .aiz-carousel').find('.'+btn).trigger('click');
}
function pushGA4Event(data){
if(window.dataLayer && data){
window.dataLayer.push(data);
}
}
function animateAddToCartButton(btnSelector, state) {
var $btn = $(btnSelector);
if (!$btn.length) return;
if (state === 'loading') {
$btn.data('original-text', $btn.html());
$btn.prop('disabled', true);
$btn.html('
' + "Adding...");
} else if (state === 'success') {
$btn.html('
' + "Added!");
setTimeout(function () {
$btn.html($btn.data('original-text'));
$btn.prop('disabled', false);
}, 2000);
} else if (state === 'reset') {
if ($btn.data('original-text')) {
$btn.html($btn.data('original-text'));
}
$btn.prop('disabled', false);
}
}