PageSourceSearch

https://www.donus.org/js/site_shop/site_shop_analytics_sdk.js?1769082613

js donus.org collected 2026-10-03 19:16:31 UTC 5,964 bytes, 165 lines download raw bytes

1/**
2 * 상품 상세 분석용 높이 측정 SDK
3 * window.IMWEB_SHOP_DETAIL_PAGE 전역에 높이 정보를 기록한다.
4 */
5window.IMWEB_SHOP_ANALYTICS_SDK = (function () {
6    var $body = null;
7    var $prod_detail_content_pc = null;
8    var $prod_detail_content_mobile = null;
9    var get_is_mobile_width = null;
10    var analyticsEventName = 'imweb:shop:detail-analytics';
11
12    var setProdDetailTargets = function (body, pcTarget, mobileTarget, isMobileGetter) {
13        $body = body || null;
14        $prod_detail_content_pc = pcTarget || null;
15        $prod_detail_content_mobile = mobileTarget || null;
16        get_is_mobile_width = typeof isMobileGetter === 'function' ? isMobileGetter : null;
17    };
18
19    var ensureDetailNamespace = function () {
20        if (!window.IMWEB_SHOP_DETAIL_PAGE) return false;
21        if (!window.IMWEB_SHOP_DETAIL_PAGE.detail) {
22            window.IMWEB_SHOP_DETAIL_PAGE.detail = {};
23        }
24        return true;
25    };
26
27    var selectHeight = function (pcHeight, mobileHeight, isMobileWidth) {
28        if (isMobileWidth && mobileHeight > 0) return mobileHeight;
29        if (!isMobileWidth && pcHeight > 0) return pcHeight;
30        if (mobileHeight > 0) return mobileHeight;
31        if (pcHeight > 0) return pcHeight;
32        return 0;
33    };
34
35    /**
36     * 접힌 상태에서도 실제 펼쳐졌을 때의 높이를 계산한다.
37     * @param {jQuery} $target
38     * @returns {number}
39     */
40    var measureExpandedHeight = function ($target) {
41        if (!$target || $target.length === 0) return 0;
42
43        var el = $target.get(0);
44        var height = Math.max(el.scrollHeight || 0, el.offsetHeight || 0);
45        if (height > 0) return height;
46
47        var $clone = $target.clone();
48        $clone.removeAttr('id');
49        $clone.css({
50            position: 'absolute',
51            visibility: 'hidden',
52            height: 'auto',
53            maxHeight: 'none',
54            overflow: 'visible',
55            left: '-99999px',
56            top: 0
57        });
58        var width = $target.outerWidth() || $target.parent().outerWidth() || window.innerWidth;
59        $clone.css('width', width + 'px');
60        if ($body && typeof $body.append === 'function') {
61            $body.append($clone);
62        } else if (document && document.body) {
63            document.body.appendChild($clone.get(0));
64        }
65        var cloneEl = $clone.get(0);
66        var cloneHeight = Math.max(cloneEl.scrollHeight || 0, cloneEl.getBoundingClientRect().height || 0);
67        $clone.remove();
68
69        return Math.ceil(cloneHeight);
70    };
71
72    /**
73     * 접힌 상태에서의 현재 높이를 계산한다.
74     * @param {jQuery} $target
75     * @returns {number}
76     */
77    var measureCollapsedHeight = function ($target) {
78        if (!$target || $target.length === 0) return 0;
79
80        var el = $target.get(0);
81        var rectHeight = 0;
82        if (el.getBoundingClientRect) {
83            rectHeight = el.getBoundingClientRect().height || 0;
84        }
85        var height = Math.max(rectHeight, el.offsetHeight || 0);
86
87        return Math.ceil(height || 0);
88    };
89
90    /**
91     * 상품 상세 body의 펼쳐진 높이를 전역 네임스페이스에 저장한다.
92     * @returns {void}
93     */
94    var updateProdDetailBodyExpandedHeight = function () {
95        if (!ensureDetailNamespace()) return;
96
97        var pcExpandedHeight = measureExpandedHeight($prod_detail_content_pc);
98        var mobileExpandedHeight = measureExpandedHeight($prod_detail_content_mobile);
99        var pcCollapsedHeight = measureCollapsedHeight($prod_detail_content_pc);
100        var mobileCollapsedHeight = measureCollapsedHeight($prod_detail_content_mobile);
101        var bodyHeightExpanded = 0;
102        var bodyHeightCollapsed = 0;
103        var is_mobile_width = false;
104
105        if (get_is_mobile_width) {
106            is_mobile_width = !!get_is_mobile_width();
107        }
108
109        bodyHeightExpanded = selectHeight(pcExpandedHeight, mobileExpandedHeight, is_mobile_width);
110        bodyHeightCollapsed = selectHeight(pcCollapsedHeight, mobileCollapsedHeight, is_mobile_width);
111
112        if (bodyHeightExpanded > 0) {
113            window.IMWEB_SHOP_DETAIL_PAGE.detail.bodyHeight = bodyHeightExpanded;
114            window.IMWEB_SHOP_DETAIL_PAGE.detail.bodyHeightExpanded = bodyHeightExpanded;
115        }
116
117        if (bodyHeightCollapsed > 0) {
118            window.IMWEB_SHOP_DETAIL_PAGE.detail.bodyHeightCollapsed = bodyHeightCollapsed;
119        }
120    };
121
122    /**
123     * 레이아웃 안정 이후 높이를 재계산한다.
124     * @returns {void}
125     */
126    var scheduleProdDetailBodyExpandedHeightUpdate = function () {
127        requestAnimationFrame(function () {
128            setTimeout(updateProdDetailBodyExpandedHeight, 0);
129        });
130    };
131
132    var listenAnalyticsEvents = function () {
133        if (!document || typeof document.addEventListener !== 'function') return;
134
135        document.addEventListener(analyticsEventName, function (event) {
136            try {
137                if (!event || !event.detail) return;
138
139                var detail = event.detail || {};
140                var payload = detail.payload || {};
141
142                switch (detail.type) {
143                    case 'setTargets':
144                        setProdDetailTargets(payload.body, payload.pcTarget, payload.mobileTarget, payload.isMobileGetter);
145                        break;
146                    case 'scheduleBodyHeightUpdate':
147                        scheduleProdDetailBodyExpandedHeightUpdate();
148                        break;
149                    default:
150                        break;
151                }
152            } catch (e) {
153                return;
154            }
155        });
156    };
157
158    listenAnalyticsEvents();
159
160    return {
161        setProdDetailTargets: setProdDetailTargets,
162        updateProdDetailBodyExpandedHeight: updateProdDetailBodyExpandedHeight,
163        scheduleProdDetailBodyExpandedHeightUpdate: scheduleProdDetailBodyExpandedHeightUpdate
164    };
165})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.