| 1 |
'use strict'; |
| 2 |
|
| 3 |
var merchant = merchant || {}; |
| 4 |
merchant.modules = merchant.modules || {}; |
| 5 |
(function ($) { |
| 6 |
merchant.modules.sizeChart = { |
| 7 |
init: function init($wrapper) { |
| 8 |
var $sizeChart = $wrapper ? $wrapper.find('.merchant-product-size-chart') : $('.merchant-product-size-chart'); |
| 9 |
if (!$sizeChart.length) { |
| 10 |
return; |
| 11 |
} |
| 12 |
var $body = $('body'); |
| 13 |
var $button = $sizeChart.find('.merchant-product-size-chart-button a'); |
| 14 |
var $modal = $sizeChart.find('.merchant-product-size-chart-modal'); |
| 15 |
$button.on('click', function (e) { |
| 16 |
e.preventDefault(); |
| 17 |
$body.addClass('merchant-product-size-chart-modal-open'); |
| 18 |
}); |
| 19 |
$modal.on('click', function (e) { |
| 20 |
e.preventDefault(); |
| 21 |
var $target = $(e.target); |
| 22 |
var $content = $sizeChart.find('.merchant-product-size-chart-modal-content'); |
| 23 |
if ($target.is($modal) || $target.closest('.merchant-product-size-chart-modal-close').length) { |
| 24 |
$content.scrollTop(0); |
| 25 |
$body.removeClass('merchant-product-size-chart-modal-open'); |
| 26 |
} |
| 27 |
}); |
| 28 |
var $tabs = $sizeChart.find('.merchant-product-size-chart-modal-tab'); |
| 29 |
var $tables = $sizeChart.find('.merchant-product-size-chart-modal-table'); |
| 30 |
if ($tabs.length && $tables.length) { |
| 31 |
$tabs.each(function () { |
| 32 |
var $tab = $(this); |
| 33 |
$tab.on('click', function () { |
| 34 |
$tab.addClass('active').siblings().removeClass('active'); |
| 35 |
$tables.eq($tab.index()).addClass('active').siblings().removeClass('active'); |
| 36 |
}); |
| 37 |
}); |
| 38 |
} |
| 39 |
} |
| 40 |
}; |
| 41 |
$(document).ready(function () { |
| 42 |
merchant.modules.sizeChart.init(); |
| 43 |
}); |
| 44 |
})(jQuery); |