feat: 쇼핑몰 상품 배지 마스터 연동
This commit is contained in:
@@ -53,6 +53,42 @@
|
||||
<!-- 스크립트 -->
|
||||
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
|
||||
<script src="<c:url value='/js/sopmal/common.js'/>"></script>
|
||||
<script>
|
||||
(function () {
|
||||
var badgeMap = {};
|
||||
|
||||
function applyBadge(element) {
|
||||
var badge = badgeMap[element.dataset.badgeCd.toLowerCase()];
|
||||
if (!badge) { return; }
|
||||
element.textContent = badge.cdNm || element.textContent;
|
||||
if (badge.fontColor) { element.style.setProperty('color', badge.fontColor, 'important'); }
|
||||
if (badge.bgColor) { element.style.setProperty('background-color', badge.bgColor, 'important'); }
|
||||
if (badge.borderColor) { element.style.setProperty('border-color', badge.borderColor, 'important'); }
|
||||
}
|
||||
|
||||
function applyBadges(root) {
|
||||
if (root.nodeType === Node.ELEMENT_NODE && root.matches('.product-badge[data-badge-cd]')) {
|
||||
applyBadge(root);
|
||||
}
|
||||
if (root.querySelectorAll) {
|
||||
root.querySelectorAll('.product-badge[data-badge-cd]').forEach(applyBadge);
|
||||
}
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
fetch('/sopmal/goods/selectGoodsBadgeList')
|
||||
.then(function (response) { return response.ok ? response.json() : []; })
|
||||
.then(function (badgeList) {
|
||||
badgeList.forEach(function (badge) { badgeMap[badge.cd.toLowerCase()] = badge; });
|
||||
applyBadges(document);
|
||||
new MutationObserver(function (mutations) {
|
||||
mutations.forEach(function (mutation) { mutation.addedNodes.forEach(applyBadges); });
|
||||
}).observe(document.documentElement, { childList: true, subtree: true });
|
||||
});
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', initialize);
|
||||
}());
|
||||
</script>
|
||||
<script src="<c:url value='/pc/js/script.js'/>" defer></script>
|
||||
<script src="<c:url value='/js/sopmal/gcone.js'/>"></script>
|
||||
|
||||
@@ -488,4 +524,4 @@
|
||||
<!--로딩영역-->
|
||||
<div class="loadingImg" style="display:none; position: relative; z-index: 1010;">
|
||||
<div class="loding_popup_wrap"><img src="/mobile/images/loading.svg" alt="loading"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -32,6 +32,42 @@
|
||||
<!-- 스크립트 -->
|
||||
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
|
||||
<script src="/mobile/js/script.js" defer=""></script>
|
||||
<script>
|
||||
(function () {
|
||||
var badgeMap = {};
|
||||
|
||||
function applyBadge(element) {
|
||||
var badge = badgeMap[element.dataset.badgeCd.toLowerCase()];
|
||||
if (!badge) { return; }
|
||||
element.textContent = badge.cdNm || element.textContent;
|
||||
if (badge.fontColor) { element.style.setProperty('color', badge.fontColor, 'important'); }
|
||||
if (badge.bgColor) { element.style.setProperty('background-color', badge.bgColor, 'important'); }
|
||||
if (badge.borderColor) { element.style.setProperty('border-color', badge.borderColor, 'important'); }
|
||||
}
|
||||
|
||||
function applyBadges(root) {
|
||||
if (root.nodeType === Node.ELEMENT_NODE && root.matches('.product-badge[data-badge-cd]')) {
|
||||
applyBadge(root);
|
||||
}
|
||||
if (root.querySelectorAll) {
|
||||
root.querySelectorAll('.product-badge[data-badge-cd]').forEach(applyBadge);
|
||||
}
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
fetch('/sopmal/goods/selectGoodsBadgeList')
|
||||
.then(function (response) { return response.ok ? response.json() : []; })
|
||||
.then(function (badgeList) {
|
||||
badgeList.forEach(function (badge) { badgeMap[badge.cd.toLowerCase()] = badge; });
|
||||
applyBadges(document);
|
||||
new MutationObserver(function (mutations) {
|
||||
mutations.forEach(function (mutation) { mutation.addedNodes.forEach(applyBadges); });
|
||||
}).observe(document.documentElement, { childList: true, subtree: true });
|
||||
});
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', initialize);
|
||||
}());
|
||||
</script>
|
||||
<script src="<c:url value='/js/gcone.js'/>"></script>
|
||||
|
||||
<script src="/mobile/js/bottom-sheet.js" defer=""></script>
|
||||
@@ -1272,4 +1308,4 @@ $(document).on('click', '[name^="globalMbrMarktAgreeAt"]',function() {
|
||||
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user