init
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* SewJoy Theme - Page Builder / Customizer Interaction
|
||||
*/
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
$(function () {
|
||||
var $builder = $('.builder');
|
||||
if (!$builder.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle option button clicks.
|
||||
$builder.on('click', '.builder-option', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var $button = $(this);
|
||||
var component = $button.data('component');
|
||||
var option = $button.data('option');
|
||||
|
||||
if (!component || !option) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Deselect siblings within the same component group.
|
||||
$builder
|
||||
.find('.builder-component[data-component="' + component + '"] .builder-option')
|
||||
.removeClass('selected');
|
||||
|
||||
// Mark the clicked button as selected.
|
||||
$button.addClass('selected');
|
||||
|
||||
// Update the corresponding summary entry.
|
||||
var $summaryValue = $('#summary-' + component + ' .builder__summary-value');
|
||||
if ($summaryValue.length) {
|
||||
$summaryValue.text(option);
|
||||
}
|
||||
});
|
||||
|
||||
// Optional: Add-to-cart button placeholder behavior.
|
||||
$builder.on('click', '.builder__add-to-cart', function () {
|
||||
var selections = {};
|
||||
$builder.find('.builder-option.selected').each(function () {
|
||||
var $btn = $(this);
|
||||
selections[$btn.data('component')] = $btn.data('option');
|
||||
});
|
||||
|
||||
if (Object.keys(selections).length === 0) {
|
||||
console.warn('SEWJOY THEME: 请先选择组件选项');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('SEWJOY THEME: 加入购物车', selections);
|
||||
});
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user