This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,211 @@
define(['jquery', 'mage/translate'], function ($, $t) {
'use strict';
return function (config, element) {
var $root = $(element),
items = config.items || [],
archives = config.archives || [],
brands = config.brands || [],
modelsByBrand = config.modelsByBrand || {},
pageSize = 20,
currentPage = 1,
$brand = $root.find('[data-role="spec-brand"]'),
$model = $root.find('[data-role="spec-model"]'),
$count = $root.find('[data-role="spec-count"]'),
$empty = $root.find('[data-role="spec-empty"]'),
$list = $root.find('[data-role="spec-list"]'),
$pagination = $root.find('[data-role="spec-pagination"]');
function renderBrands() {
$.each(brands, function (_, brandItem) {
$('<option/>', {
value: brandItem.id,
text: brandItem.name
}).appendTo($brand);
});
}
function renderModels() {
var brandId = $brand.val(),
models = brandId ? (modelsByBrand[brandId] || []).slice() : [];
if (!brandId) {
$.each(modelsByBrand, function (_, brandModels) {
$.each(brandModels, function (_, modelName) {
if ($.inArray(modelName, models) === -1) {
models.push(modelName);
}
});
});
models.sort();
}
$model.empty().append($('<option/>', {
value: '',
text: $t('All Models')
}));
$.each(models, function (_, modelName) {
$('<option/>', {
value: modelName,
text: modelName
}).appendTo($model);
});
}
function filterItems() {
var brandId = $brand.val(),
modelName = $model.val(),
results;
if (!brandId && !modelName) {
return archives.slice();
}
results = $.grep(items, function (item) {
return (!brandId || String(item.brand_id) === String(brandId)) &&
(!modelName || item.model_name === modelName);
});
if (brandId) {
results = $.grep(archives, function (archive) {
return String(archive.brand_id) === String(brandId);
}).concat(results);
}
return results;
}
function createPageButton(label, page, options) {
var settings = options || {},
$button = $('<button/>', {
'class': 'esun-download-specifications__page' + (settings.active ? ' is-active' : ''),
type: 'button',
text: label,
disabled: settings.disabled || false,
'aria-label': settings.ariaLabel || null,
'aria-current': settings.active ? 'page' : null
});
if (!settings.disabled && !settings.active) {
$button.on('click', function () {
currentPage = page;
renderList();
$root.get(0).scrollIntoView({behavior: 'smooth', block: 'start'});
});
}
return $button;
}
function renderPagination(totalPages) {
var pages = [],
previousPage = 0;
$pagination.empty();
if (totalPages <= 1) {
return;
}
$pagination.append(createPageButton($t('Previous'), currentPage - 1, {
disabled: currentPage === 1,
ariaLabel: $t('Previous page')
}));
for (var page = 1; page <= totalPages; page++) {
if (page === 1 || page === totalPages || Math.abs(page - currentPage) <= 2) {
pages.push(page);
}
}
$.each(pages, function (_, page) {
if (previousPage && page - previousPage > 1) {
$('<span/>', {
'class': 'esun-download-specifications__ellipsis',
text: '…',
'aria-hidden': 'true'
}).appendTo($pagination);
}
$pagination.append(createPageButton(String(page), page, {
active: page === currentPage,
ariaLabel: $t('Page %1').replace('%1', page)
}));
previousPage = page;
});
$pagination.append(createPageButton($t('Next'), currentPage + 1, {
disabled: currentPage === totalPages,
ariaLabel: $t('Next page')
}));
}
function renderItem(item) {
var $item = $('<a/>', {
'class': 'esun-download-specifications__item',
href: item.file_url,
download: item.file_name
}),
$logo = $('<span/>', {'class': 'esun-download-specifications__logo'}),
$body = $('<span/>', {'class': 'esun-download-specifications__body'}),
$meta = $('<span/>', {'class': 'esun-download-specifications__meta'}),
$info = $('<span/>', {'class': 'esun-download-specifications__info'}),
$action = $('<span/>', {'class': 'esun-download-specifications__action'});
if (item.brand_logo_url) {
$('<img/>', {src: item.brand_logo_url, alt: ''}).appendTo($logo);
}
$('<span/>', {'class': 'esun-download-specifications__brand', text: item.brand_name}).appendTo($meta);
if (item.model_name) {
$('<span/>', {'class': 'esun-download-specifications__model', text: item.model_name}).appendTo($meta);
}
$('<strong/>', {text: item.file_name}).appendTo($body);
$('<span/>', {text: item.file_size_label}).appendTo($info);
if (item.file_date) {
$('<span/>', {text: item.file_date}).appendTo($info);
}
$('<span/>', {
'class': 'esun-download-specifications__download-text',
text: $t('Download')
}).appendTo($action);
$('<span/>', {'class': 'esun-download-specifications__download-icon'}).appendTo($action);
$body.prepend($meta).append($info);
$item.append($logo, $body, $action).appendTo($list);
}
function renderList() {
var results = filterItems(),
totalPages = Math.ceil(results.length / pageSize),
start;
if (totalPages > 0 && currentPage > totalPages) {
currentPage = totalPages;
}
$count.text(results.length);
$list.empty();
$empty.toggle(results.length === 0);
$list.toggle(results.length > 0);
start = (currentPage - 1) * pageSize;
$.each(results.slice(start, start + pageSize), function (_, item) {
renderItem(item);
});
renderPagination(totalPages);
}
renderBrands();
renderModels();
renderList();
$brand.on('change', function () {
currentPage = 1;
renderModels();
renderList();
});
$model.on('change', function () {
currentPage = 1;
renderList();
});
};
});
@@ -0,0 +1,236 @@
define(['jquery', 'mage/translate'], function ($, $t) {
'use strict';
return function (config, element) {
var $root = $(element),
rawConfig = $root.find('[data-role="parameter-config"]').text(),
data = rawConfig ? JSON.parse(rawConfig) : {},
products = data.products || [],
applicationOptions = data.applicationOptions || [],
messages = data.messages || {},
maximum = 6,
selected = [],
mode = 'key',
keyParameters = [
'Density(g/cm3) (unit to be confirmed)',
'Heat Distortion Temperature(°C)',
'Tensile Strength (XY) (MPa)',
'Elongation at Break (XY) (%)',
'Flexural Strength (XY) (MPa)',
'Flexural Modulus (XY) (MPa)',
'IZOD Impact Strength (XY) (kJ/m²)',
'Extruder Temperature(°C)',
'Bed Temperature(°C)',
'Fan Speed(%)',
'Printing Speed(mm/s) (high-speed printing parameter)',
'Printing Recommendation',
'Drying'
],
$seriesList = $root.find('[data-role="series-list"]'),
$selectedMaterials = $root.find('[data-role="selected-materials"]'),
$notice = $root.find('[data-role="material-notice"]'),
$selectionCount = $root.find('[data-role="selection-count"]'),
$comparisonCount = $root.find('[data-role="comparison-count"]'),
$resultCount = $root.find('[data-role="result-count"]'),
$placeholder = $root.find('[data-role="comparison-placeholder"]'),
$tableWrap = $root.find('[data-role="comparison-table-wrap"]'),
$head = $root.find('[data-role="comparison-head"]'),
$body = $root.find('[data-role="comparison-body"]');
function selectedBase() {
return $root.find('[data-role="base-filter"]:checked').val() || '';
}
function productsForBase() {
var base = selectedBase();
return $.grep(products, function (product) { return product.base === base; });
}
function primaryApplication(product) {
return product.applications && product.applications.length ? product.applications[0] : 'other';
}
function applicationLabel(value) {
var option = applicationOptions.find(function (item) { return item.value === value; });
return option ? option.label : $t('Other Series');
}
function isSelected(id) {
return $.inArray(id, selected) !== -1;
}
function findProduct(id) {
return products.find(function (product) { return product.id === id; });
}
function renderSeries() {
var baseProducts = productsForBase(), groups = {};
$.each(baseProducts, function (_, product) {
var application = primaryApplication(product);
groups[application] = groups[application] || [];
groups[application].push(product);
});
$seriesList.empty();
$.each(applicationOptions, function (_, option) {
var groupProducts = groups[option.value] || [];
if (!groupProducts.length) {
return;
}
renderSeriesRow(option.label, groupProducts);
delete groups[option.value];
});
$.each(groups, function (application, groupProducts) {
renderSeriesRow(applicationLabel(application), groupProducts);
});
$resultCount.text(baseProducts.length);
updateSelection();
}
function renderSeriesRow(label, groupProducts) {
var $row = $('<div/>', {'class': 'esun-parameter-comparison__series-row'}),
$label = $('<div/>', {'class': 'esun-parameter-comparison__series-name'}),
$products = $('<div/>', {'class': 'esun-parameter-comparison__series-products'});
$label.append($('<strong/>', {text: label}), $('<span/>', {text: groupProducts.length}));
$.each(groupProducts, function (_, product) {
$('<button/>', {
type: 'button',
'class': 'esun-parameter-comparison__product' + (isSelected(product.id) ? ' is-selected' : ''),
text: product.name,
title: product.name,
disabled: !isSelected(product.id) && selected.length >= maximum,
'data-role': 'material-option',
'data-id': product.id
}).appendTo($products);
});
$row.append($label, $products).appendTo($seriesList);
}
function updateSelection() {
$selectionCount.text(selected.length);
$comparisonCount.text(selected.length);
$selectedMaterials.empty();
$.each(selected, function (_, id) {
var product = findProduct(id), $pill;
if (!product) {
return;
}
$pill = $('<span/>', {'class': 'esun-parameter-comparison__selected-pill'});
$pill.append(
$('<span/>', {text: product.name}),
$('<button/>', {
type: 'button',
text: '×',
'aria-label': $t('Remove %1').replace('%1', product.name),
'data-role': 'remove-material',
'data-id': id
})
).appendTo($selectedMaterials);
});
renderComparison();
}
function removeMaterial(id) {
selected = $.grep(selected, function (selectedId) { return selectedId !== id; });
$notice.text('');
renderSeries();
}
function parameterIsVisible(name, values) {
if (mode === 'key' && $.inArray(name, keyParameters) === -1) {
return false;
}
if (mode === 'differences') {
return values.filter(function (value, index, array) {
return array.indexOf(value) === index;
}).length > 1;
}
return true;
}
function renderComparison() {
var selectedProducts = $.map(selected, findProduct),
groups = data.parameterGroups || {};
$head.empty();
$body.empty();
if (selectedProducts.length < 1) {
$placeholder.show();
$tableWrap.hide();
return;
}
$tableWrap.toggleClass('is-single', selectedProducts.length === 1);
var $headerRow = $('<tr/>').append($('<th/>', {text: $t('Parameter')}));
$.each(selectedProducts, function (_, product) {
var $name = $('<span/>', {text: product.name}),
$remove = $('<button/>', {
type: 'button', text: '×',
'aria-label': $t('Remove %1').replace('%1', product.name),
'data-role': 'remove-material', 'data-id': product.id
});
$headerRow.append($('<th/>').append($name, $remove));
});
$head.append($headerRow);
$.each(groups, function (groupName, parameters) {
var rows = [];
$.each(parameters, function (_, parameterName) {
var values = $.map(selectedProducts, function (product) {
var value = product.groups[groupName] && product.groups[groupName][parameterName];
return value === undefined || value === null || value === ''
? (messages.missingValue || '—') : String(value);
});
if (!parameterIsVisible(parameterName, values)) {
return;
}
var $row = $('<tr/>').append($('<th/>', {scope: 'row', text: parameterName}));
$.each(values, function (_, value) { $row.append($('<td/>').text(value)); });
rows.push($row);
});
if (rows.length) {
$body.append($('<tr/>', {'class': 'esun-parameter-comparison__group-row'})
.append($('<th/>', {colspan: selectedProducts.length + 1, text: groupName})));
$.each(rows, function (_, row) { $body.append(row); });
}
});
$placeholder.hide();
$tableWrap.show();
}
$root.on('change', '[data-role="base-filter"]', function () {
selected = [];
$notice.text('');
renderSeries();
});
$root.on('click', '[data-role="material-option"]', function () {
var id = $(this).data('id');
if (isSelected(id)) {
removeMaterial(id);
return;
}
if (selected.length >= maximum) {
$notice.text($t('You can compare up to 6 materials.'));
return;
}
selected.push(id);
$notice.text('');
renderSeries();
});
$root.on('click', '[data-role="remove-material"]', function () {
removeMaterial($(this).data('id'));
});
$root.on('click', '[data-role="comparison-mode"]', function () {
mode = $(this).data('mode');
$root.find('[data-role="comparison-mode"]').removeClass('is-active');
$(this).addClass('is-active');
renderComparison();
});
renderSeries();
};
});
@@ -0,0 +1,296 @@
define([
'jquery'
], function ($) {
'use strict';
return function (config, element) {
var $root = $(element),
$activeTrigger = $(),
$activeTooltip = $(),
$drawers = $root.find('[data-wiki-drawer]'),
$drawerBackdrop = $root.find('.esun-wiki-drawer-backdrop'),
$activeDrawer = $(),
$activeDrawerTrigger = $(),
drawerMedia = window.matchMedia('(max-width: 860px)'),
hideTimer = null;
function syncSearchClear($input) {
var hasValue = $.trim($input.val()).length > 0;
$input.closest('form').find('.esun-wiki-search-clear').toggleClass('is-visible', hasValue);
}
function cancelTooltipHide() {
if (hideTimer) {
window.clearTimeout(hideTimer);
hideTimer = null;
}
}
function positionTooltip($trigger, $tooltip) {
var triggerRect = $trigger[0].getBoundingClientRect(),
viewportWidth = window.innerWidth || document.documentElement.clientWidth,
viewportHeight = window.innerHeight || document.documentElement.clientHeight,
gutter = 14,
gap = 18,
tooltipWidth,
tooltipHeight,
left,
top,
arrowLeft,
showBelow;
$tooltip
.addClass('is-active')
.css({left: 0, top: 0, visibility: 'hidden'});
tooltipWidth = $tooltip.outerWidth();
tooltipHeight = $tooltip.outerHeight();
left = triggerRect.left + (triggerRect.width / 2) - (tooltipWidth / 2);
left = Math.max(gutter, Math.min(left, viewportWidth - tooltipWidth - gutter));
top = triggerRect.top - tooltipHeight - gap;
showBelow = top < gutter;
if (showBelow) {
top = triggerRect.bottom + gap;
}
top = Math.max(gutter, Math.min(top, viewportHeight - tooltipHeight - gutter));
arrowLeft = triggerRect.left + (triggerRect.width / 2) - left;
arrowLeft = Math.max(26, Math.min(arrowLeft, tooltipWidth - 26));
$tooltip
.toggleClass('is-below', showBelow)
.css({
left: Math.round(left),
top: Math.round(top),
visibility: 'visible',
'--esun-wiki-tip-arrow-left': Math.round(arrowLeft) + 'px'
});
}
function closeTooltip(restoreFocus) {
cancelTooltipHide();
if ($activeTooltip.length) {
$activeTooltip
.removeClass('is-active is-below')
.attr('aria-hidden', 'true')
.removeAttr('style');
}
if ($activeTrigger.length) {
$activeTrigger.attr('aria-expanded', 'false');
if (restoreFocus) {
$activeTrigger.trigger('focus');
}
}
$activeTrigger = $();
$activeTooltip = $();
}
function showTooltip($trigger) {
var tooltipId = $trigger.attr('data-wiki-tip'),
$tooltip = $root.find('[data-wiki-tooltip-id="' + tooltipId + '"]');
if (!$tooltip.length) {
return;
}
cancelTooltipHide();
if ($activeTooltip.length && $activeTooltip[0] !== $tooltip[0]) {
closeTooltip(false);
}
$activeTrigger = $trigger;
$activeTooltip = $tooltip;
$trigger.attr('aria-expanded', 'true');
$tooltip.attr('aria-hidden', 'false');
positionTooltip($trigger, $tooltip);
}
function scheduleTooltipHide() {
cancelTooltipHide();
hideTimer = window.setTimeout(function () {
closeTooltip(false);
}, 140);
}
function closeDrawer(restoreFocus) {
var $trigger = $activeDrawerTrigger;
$drawers.removeClass('is-open');
$root.find('[data-wiki-drawer-open]').attr('aria-expanded', 'false');
$drawerBackdrop.removeClass('is-visible').attr('aria-hidden', 'true');
$('html, body').removeClass('esun-wiki-drawer-lock');
if (restoreFocus && $trigger.length) {
$trigger.trigger('focus');
}
if (drawerMedia.matches) {
$drawers.attr('aria-hidden', 'true');
} else {
$drawers.removeAttr('aria-hidden');
}
$activeDrawer = $();
$activeDrawerTrigger = $();
}
function openDrawer(name, $trigger) {
var $drawer;
if (!drawerMedia.matches) {
return;
}
$drawer = $drawers.filter('[data-wiki-drawer="' + name + '"]');
if (!$drawer.length) {
return;
}
closeTooltip(false);
closeDrawer(false);
$activeDrawer = $drawer;
$activeDrawerTrigger = $trigger;
$drawer.addClass('is-open').attr('aria-hidden', 'false');
$trigger.attr('aria-expanded', 'true');
$drawerBackdrop.addClass('is-visible').attr('aria-hidden', 'false');
$('html, body').addClass('esun-wiki-drawer-lock');
window.setTimeout(function () {
if ($drawer.hasClass('is-open')) {
$drawer.find('.esun-wiki-drawer-close').first().trigger('focus');
}
}, 220);
}
function syncDrawerMode() {
closeDrawer(false);
}
function trapDrawerFocus(event) {
var $focusable,
first,
last;
if (event.key !== 'Tab' || !$activeDrawer.length) {
return;
}
$focusable = $activeDrawer
.find('a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])')
.filter(':visible');
if (!$focusable.length) {
event.preventDefault();
return;
}
first = $focusable[0];
last = $focusable[$focusable.length - 1];
if (event.shiftKey && document.activeElement === first) {
event.preventDefault();
$(last).trigger('focus');
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault();
$(first).trigger('focus');
}
}
$root.find('.esun-wiki-search input[type="search"]').each(function () {
syncSearchClear($(this));
});
$root.on('click', '.esun-wiki-tree-toggle', function () {
var $button = $(this),
$item = $button.closest('.esun-wiki-tree-item'),
isOpen = !$item.hasClass('is-open');
$item.toggleClass('is-open', isOpen);
$button.attr('aria-expanded', isOpen ? 'true' : 'false');
});
$root.on('input change', '.esun-wiki-search input[type="search"]', function () {
syncSearchClear($(this));
});
$root.on('click', '.esun-wiki-search-clear', function () {
var $form = $(this).closest('form'),
$input = $form.find('input[type="search"]');
$input.val('').trigger('focus');
syncSearchClear($input);
if (window.location.search.indexOf('q=') !== -1) {
window.location.href = $form.attr('action');
}
});
$root.on('click', '[data-wiki-drawer-open]', function () {
openDrawer($(this).attr('data-wiki-drawer-open'), $(this));
});
$root.on('click', '[data-wiki-drawer-close]', function () {
closeDrawer(true);
});
$root.on('click', '.esun-wiki-toc a, .esun-wiki-sidebar a.esun-wiki-tree-link', function () {
if (drawerMedia.matches) {
closeDrawer(false);
}
});
$root.on('mouseenter focusin', '.esun-wiki-tip-trigger', function () {
showTooltip($(this));
});
$root.on('mouseleave focusout', '.esun-wiki-tip-trigger', scheduleTooltipHide);
$root.on('click', '.esun-wiki-tip-trigger', function (event) {
event.preventDefault();
showTooltip($(this));
});
$root.on('mouseenter focusin', '.esun-wiki-tooltip', cancelTooltipHide);
$root.on('mouseleave focusout', '.esun-wiki-tooltip', scheduleTooltipHide);
$(window).on('resize.esunWikiTooltip', function () {
if ($activeTrigger.length && $activeTooltip.length) {
positionTooltip($activeTrigger, $activeTooltip);
}
});
$(window).on('scroll.esunWikiTooltip', function () {
if ($activeTrigger.length && $activeTooltip.length) {
positionTooltip($activeTrigger, $activeTooltip);
}
});
$(document).on('mousedown.esunWikiTooltip touchstart.esunWikiTooltip', function (event) {
if (!$(event.target).closest('.esun-wiki-tip-trigger, .esun-wiki-tooltip').length) {
closeTooltip(false);
}
});
$(document).on('keydown.esunWikiTooltip', function (event) {
if (event.key === 'Escape' && $activeDrawer.length) {
closeDrawer(true);
} else if (event.key === 'Escape' && $activeTooltip.length) {
closeTooltip(true);
}
trapDrawerFocus(event);
});
if (drawerMedia.addEventListener) {
drawerMedia.addEventListener('change', syncDrawerMode);
} else {
drawerMedia.addListener(syncDrawerMode);
}
syncDrawerMode();
};
});