| 1 |
"use strict"; |
| 2 |
|
| 3 |
; |
| 4 |
(function ($, window, document, undefined) { |
| 5 |
var autoClearEnabledOnLoad = $('.merchant-field-enable_auto_clear input').is(':checked'); |
| 6 |
|
| 7 |
// Clear Cookie |
| 8 |
$(document).on('save.merchant', function (e, module) { |
| 9 |
if (module === 'clear-cart') { |
| 10 |
var autoClearEnabledOnSave = $('.merchant-field-enable_auto_clear input').is(':checked'); |
| 11 |
if (autoClearEnabledOnLoad && !autoClearEnabledOnSave) { |
| 12 |
document.cookie = 'merchant_clear_cart=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/'; |
| 13 |
} |
| 14 |
} |
| 15 |
}); |
| 16 |
|
| 17 |
// Page load |
| 18 |
$(document).on('ready', function () { |
| 19 |
initPreview(); |
| 20 |
}); |
| 21 |
|
| 22 |
// Change settings |
| 23 |
$(document).on('change', function () { |
| 24 |
initPreview(); |
| 25 |
}); |
| 26 |
|
| 27 |
// Change button style |
| 28 |
$(document).on('change', '.merchant-field-style input', function () { |
| 29 |
var val = $(this).val(); |
| 30 |
var color = "#ffffff"; |
| 31 |
if (val === 'outline' || val === 'text') { |
| 32 |
color = "#212121"; |
| 33 |
} |
| 34 |
$('.merchant-field-text_color input, .merchant-field-text_color_hover input').val(color).attr('value', color).trigger('change').trigger('input'); |
| 35 |
}); |
| 36 |
function initPreview() { |
| 37 |
var $buttonPreview = $('.merchant-clear-cart-button'); |
| 38 |
var isCartPageEnabled = $('.merchant-field-enable_cart_page input').is(':checked'); |
| 39 |
var $cartPagePositionField = $('.merchant-field-cart_page_position select'); |
| 40 |
var cartPagePosition = $cartPagePositionField.val(); |
| 41 |
|
| 42 |
// If Cart Page is Disabled |
| 43 |
$buttonPreview.toggleClass('hide', !isCartPageEnabled); |
| 44 |
if (isCartPageEnabled) { |
| 45 |
$buttonPreview.each(function () { |
| 46 |
if ($(this).hasClass(cartPagePosition)) { |
| 47 |
$(this).removeClass('hide'); |
| 48 |
} else { |
| 49 |
$(this).addClass('hide'); |
| 50 |
} |
| 51 |
}); |
| 52 |
} |
| 53 |
|
| 54 |
// Style - Solid/Outline/Text |
| 55 |
var $buttonStyleField = $('.merchant-field-style input'); |
| 56 |
$buttonStyleField.each(function () { |
| 57 |
var value = $(this).val(); |
| 58 |
$buttonPreview.removeClass("merchant-clear-cart-button--".concat(value)); |
| 59 |
if ($(this).is(':checked')) { |
| 60 |
$buttonPreview.addClass("merchant-clear-cart-button--".concat(value)); |
| 61 |
} |
| 62 |
}); |
| 63 |
var $shopTableBottom = $('.shop_table-bottom'); |
| 64 |
$cartPagePositionField.find('option').each(function () { |
| 65 |
var value = $(this).val(); |
| 66 |
|
| 67 |
// Remove the class corresponding to the value of each option |
| 68 |
$shopTableBottom.removeClass(value); |
| 69 |
|
| 70 |
// If the current option is selected, add the class |
| 71 |
if ($(this).is(':selected')) { |
| 72 |
$shopTableBottom.addClass(value); |
| 73 |
} |
| 74 |
}); |
| 75 |
} |
| 76 |
})(jQuery, window, document); |