PageSourceSearch

https://spsamhwa.com/app/themes/sknk/src/js/common.js?ver=1791588684

js spsamhwa.com collected 2026-10-09 23:36:40 UTC 20,295 bytes, 676 lines download raw bytes

1var samhwa = {};
2
3//multipart submit
4samhwa.multipart = {
5    eventTarget: "",
6    defaultOption: {
7        hasProgress: false,
8        executeExceptionCallback: false,
9    },
10};
11
12samhwa.multipart.submit = function ($form, callback, option) {
13    var options = $.extend({}, samhwa.multipart.defaultOption, option || {});
14  // jquery ajaxform
15    $form.ajaxForm({
16        async: false,
17        dataType: "json",
18      // 전처리
19        beforeSubmit: function (data, form, option) {
20            return true;
21        },
22      // 성공시
23        success: function (response, status) {
24            if (typeof response === "string") {
25                response = response.replace(/[<][^>]*[>]/gi, "");
26                response = JSON.parse(response);
27            }
28          // callback
29            callback.call(this, response);
30        },
31      // 오류시
32        error: function (e) {
33            alert("서버 오류");
34          //callback.call(this, response);
35        },
36      // 통신완료 후처리
37        complete: function () {},
38    });
39    $form.submit();
40};
41
42function getTopBanner()
43{
44    $.pjax.defaults.scrollTo = false;
45    $.pjax({
46        url: "/getTopBanner",
47        container: "#topBanner",
48        fragment: "#topBanner",
49        async: false,
50        replace: false,
51        push: false,
52        pushRedirect: false,
53        replaceRedirect: false,
54    }).done(function () {});
55}
56
57function reloadHistory()
58{
59    $.ajax({
60        url: '/wp/wp-admin/admin-ajax.php',
61        data: {
62            'action': 'get_history'
63        },
64        async: false,
65        type: 'post',
66        success: function (response) {
67
68            let product = getCookie('product');
69            product = product.split('|');
70            if(product[product.length - 1] == '') {
71                product.pop();
72            }
73
74            $('.history_box > .h2 > i').html('(' + product.length + ')');
75
76            let color = getCookie('color');
77            color = color.split('|');
78            if(color[color.length - 1] == '') {
79                color.pop();
80            }
81
82            $('.seleted_colors > .h2 > i').html('(' + color.length + ')');
83
84            let colorHtml = '';
85            response.data.color.forEach(function (item) {
86                colorHtml += '<li class="color_module" data-colorcode="' + item.cl_color_hex + '" data-colorcodename="' + item.cl_color_cd + '">';
87                colorHtml += '<a href="#" class="color_chip">';
88                colorHtml += '<i class="color_palette" style="background:' + item.cl_color_hex + '"></i>';
89                colorHtml += '<span class="color_info">';
90                colorHtml += '<strong>' + item.post_title + '</strong>';
91                colorHtml += '<em><i>' + item.cl_color_cd + '(' + item.cl_page_no + ')</i></em>';
92                colorHtml += '</span>';
93                colorHtml += '</a>';
94                colorHtml += '<button type="button" class="color_copy"></button>';
95                colorHtml += '<button type="button" class="full_screen"></button>';
96                colorHtml += '</li>';
97            });
98            $('.color_list').html(colorHtml);
99
100            let productHtml = '';
101            response.data.product.forEach(function (item) {
102                productHtml += '<li><a href="' + item.guid + '">';
103                productHtml += '<i class="img_wrap">';
104                productHtml += '<img src="" data-prdt-img="' + item.mis_prod_cd[0].code + '"></i>';
105                // productHtml += '<div class="viewImg" style="background-image:url(&quot;' + item.guid + '&quot;)"></div></i>';
106                productHtml += '<em>';
107                const category = item.categories.join('</i><i>');
108                if(category) {
109                    productHtml += '<i>' + category + '</i>';
110                }
111                productHtml += '</em>';
112                productHtml += '<strong>' + item.post_title + '</strong><span>' + item.post_excerpt + '</span>';
113                productHtml += '</a></li>';
114
115            });
116
117            $('.history_box > ul').eq(0).html(productHtml);
118
119            $(".color_list li")
120                .bind("mouseenter", historyColorListEnterHandler)
121                .bind("mouseleave", historyColorListLeaveHandler);
122
123            $(".color_list li .full_screen")
124              .bind("click", historyColorListClickHandler);
125            $(".color_list li .color_copy")
126              .bind("click", historyColorCodeCopyClickHandler);
127            getProductImgList();
128        }
129    });
130
131    // $.pjax.defaults.scrollTo = false;
132    // $.pjax({
133    //     url: "/getHeader",
134    //     container: "#historyBox",
135    //     fragment: "#historyBox",
136    //     replace: false,
137    //     async: false,
138    //     push: false,
139    //     pushRedirect: false,
140    //     replaceRedirect: false,
141    // }).done(function () {
142    //     $(".color_list li")
143    //     .unbind("mouseenter")
144    //     .bind("mouseenter", historyColorListEnterHandler);
145    //     $(".color_list li")
146    //     .unbind("mouseleave")
147    //     .bind("mouseleave", historyColorListLeaveHandler);
148    //     $(".color_list li .full_screen")
149    //     .unbind("click")
150    //     .bind("click", historyColorListClickHandler);
151    //     $(".color_list li .color_copy")
152    //     .unbind("click")
153    //     .bind("click", historyColorCodeCopyClickHandler);
154    //     getProductImgList();
155    // });
156}
157
158function getProductImgList(type, callback)
159{
160    if (!type) {
161        type = "list";
162    }
163
164    var imgSel = "img[data-prdt-img]";
165    if ($(imgSel).length == 0) {
166        return;
167    }
168
169    var prodIdUniq = [];
170    $(imgSel).each(function () {
171        var prodId = $(this).data("prdt-img");
172        if (prodId && prodIdUniq.indexOf(prodId) < 0) {
173            prodIdUniq.push(prodId);
174        }
175    });
176
177    $.ajax({
178        url: '/wp/wp-admin/admin-ajax.php',
179        data: {
180            'action': 'get_product',
181            'type': 'jsonProductImgByProduct',
182            'prodId': prodIdUniq,
183        },
184        method: "POST",
185        success: function (json) {
186            $.each(json.data, function (k, v) {
187                if (type == "list" || (type == "detail" && v.sort == 1)) {
188                    $('img[data-prdt-img="' + v.id + '"]').attr("src", encodeURI(v.img_url.replace('http://', 'https://')));
189                    // 한번 로딩된 데이터는 재로딩 되지 않도록 처리
190                    $('img[data-prdt-img="' + v.id + '"]').attr("data-prdt-img", "");
191                }
192            });
193
194            if (typeof callback == "function") {
195                callback(json.data);
196            }
197        },
198    });
199}
200
201function getHistoryCount()
202{
203    color = getCookie('color');
204    color = color.split('|');
205    product = getCookie('product');
206    product = product.split('|');
207
208    colorLength = 0;
209    color.forEach(function (item, index) {
210        if(item != '') colorLength++;
211    });
212
213    productLength = 0;
214    product.forEach(function (item, index) {
215        if(item != '') productLength++;
216    });
217
218
219    $(".gnb_alarm i").html(colorLength + productLength);
220
221    // $.ajax({
222    //     url: "/getHistoryCount",
223    //     success: function (response) {
224    //         $(".gnb_alarm i").html(response);
225    //     },
226    // });
227}
228
229function searchAll()
230{
231    if ($("#searchTextAll").val().trim() == "") {
232        return;
233    }
234    location.href = (commonSknk.blog_id == 2 ? '/en' : '' ) + "/?s=" + encodeURI($("#searchTextAll").val());
235}
236
237function reloadSearchListHistory()
238{
239    $.pjax({
240        url: "/searchAll",
241        container: "#searchListBody",
242        fragment: "#searchListBody",
243        replace: false,
244        push: false,
245        pushRedirect: false,
246        replaceRedirect: false,
247        data: {},
248    }).done(function () {
249        $("#searchTextAll").keyup(function (event) {
250            if (event.keyCode == 13) {
251                searchAll();
252            }
253        });
254        $("#gnb_search .search_close").bind("click", searchPopupHideListener);
255        $("#gnb_search .search_area input").bind("focus", searchInputFocusListener);
256        $("#gnb_search .search_area").bind("mouseleave", searchInputBlurListener);
257        $("#gnb_search .search_area input").bind(
258            "keyup",
259            searchInputValueCheckListener
260        );
261    });
262}
263
264function deleteSearchText(event, searchText)
265{
266    $.ajax({
267        url: "/deleteSearchText",
268        data: {
269            searchText: searchText,
270        },
271        success: function (response) {
272          // 검색 페이지(all), 검색 레이어(header) 모두 처리
273            var idx = $(event).closest("li").index();
274
275            $("#searchList li:eq(" + idx + ")").remove();
276            $("#searchListAll li:eq(" + idx + ")").remove();
277
278            if ($("#searchList li").length === 0) {
279                $("#searchList, #searchListAll").each(function () {
280                    $(this).append(
281                        "<li>\n" +
282                        '<button type="button">최근 검색하신 내역이 없습니다.</button>\n' +
283                        "</li>"
284                    );
285                });
286            }
287        },
288        error: function () {
289            alert("삭제에 실패하였습니다.");
290        },
291    });
292}
293
294function deleteSearchTextAll()
295{
296    eraseCookie("search_query");
297    $("#searchListAll li").remove();
298    $("#searchListAll").append(
299        "<li>\n" +
300        '<button type="button">최근 검색하신 내역이 없습니다.</button>\n' +
301        "</li>");
302}
303
304function getPaintingGuideAll()
305{
306    $.ajax({
307        url: commonSknk.ajax_url,
308        data: {
309            'action': 'get_panting_guide'
310        },
311        async: false,
312        type: 'post',
313        success: function (response) {
314
315            $("#pGuideList li").remove();
316            const list = response.data.articleList;
317            const meta = response.data.meta;
318            for (let i = 0; i < list.length; i++) {
319                var source = "";
320                source += "<li>";
321                source += '	<a href="' + list[i].guid + '">';
322
323                if (meta[i].format == "video") {
324                    source += '  <i class="img_wrap movie_wrap">';
325                } else {
326                    source += '  <i class="img_wrap">';
327                }
328
329                source +=
330                "<div class='paintingViewImg' style='background-image: url(\"" + meta[i].thumbnail.guid + "\");'></div>";
331                source += "</i>";
332                source += "  <em>" + meta[i].term + "</em>";
333                source += "  <strong>" + list[i].post_title + "</strong>";
334                source += " </a>";
335                source += "</li>";
336
337                $("#pGuideList").append(source);
338            }
339        }
340    });
341
342  //TODO: 추천검색어와 인기검색어 추가 필요
343
344
345  // $.ajax({
346  //   url: "/search/api/paintingGuideAll",
347  //   type: "get",
348  //   data: {},
349  //   success: function (response) {
350  //     // 페인팅 가이드 영역
351  //
352  //
353  //     // 추천검색어 영역
354  //     $("#hSuggestList span").remove();
355  //     var suggestList = response.keywdSuggestList;
356  //     for (let i = 0; i < suggestList.length; i++) {
357  //       var source =
358  //         '<span><a href="/search/all?searchText=' +
359  //         encodeURI(suggestList[i].ksKeywd) +
360  //         '">#' +
361  //         suggestList[i].ksKeywd +
362  //         "</a></span>";
363  //       $("#hSuggestList").append(source);
364  //     }
365  //
366  //     // 인기검색어 영역
367  //     $("#hSearchLog li").remove();
368  //     var searchList = response.searchLog;
369  //     for (let i = 0; i < searchList.length; i++) {
370  //       var source = "";
371  //       source += "<li>";
372  //       source +=
373  //         '  <button type="button"><a href="/search/all?searchText=' +
374  //         encodeURI(searchList[i].searchText) +
375  //         '" >' +
376  //         searchList[i].searchText +
377  //         "</a></button>";
378  //       source += "</li>";
379  //       $("#hSearchLog").append(source);
380  //     }
381  //   },
382  //   error: function () {
383  //     //$('#pGuideList li').remove();
384  //   },
385  // });
386}
387
388$(document).ready(function () {
389  getHistoryCount();
390  //제품 검색 페이지일때에만, 처음 로딩할때 이미지를 가져ì˜
390¤ë„록 한다.
391
392  if($('img[data-prdt-img]').length > 0) {
393      // reloadHistory();
394      getProductImgList();
395  }
396
397$('.pc .swiper-container').swiper({
398    loop: true,
399    calculateHeight: true,
400    resizeReInit: true,
401    autoplay: 5000
402});
403  // getTopBanner();
404});
405
406function setProductCookie(code, url) {
407    product = getCookie("product");
408    setCookie("product", product + code + "|", 1);
409
410    if(url) {
411        location.href = url;
412    }
413}
414
415/* ********** pjax 관련  **********  */
416(function ($) {
417  // set press enter key event
418    $.fn.enter = function (callback) {
419        this.keypress(function (e) {
420            if (e.keyCode === 13) {
421                e.preventDefault();
422                callback();
423            }
424        });
425    };
426
427  // form to json
428    $.fn.serializeObject = function () {
429        try {
430            var o = {};
431            var a = this.serializeArray();
432            $.each(a, function () {
433                if (o[this.name]) {
434                    if (!o[this.name].push) {
435                        o[this.name] = [o[this.name]];
436                    }
437                    o[this.name].push(this.value || "");
438                } else {
439                    o[this.name] = this.value || "";
440                }
441            });
442            return o;
443        } catch (e) {
444          //console.log(e);
445        }
446    };
447})($);
448// 검색조건 입출력
449var SearchFunction = (function (sf) {
450    sf.config = {
451        loadKey: "?search=restore",
452        sessionKey: "searchInfo",
453        pathName: window.location.pathname,
454    };
455    sf.getSession = function () {
456        var data = sessionStorage.getItem(sf.config.sessionKey);
457        var jdata = null;
458        if (data) {
459            try {
460                jdata = JSON.parse(data);
461            } catch (e) {
462              //console.log(e);
463            }
464        }
465        return jdata;
466    };
467    sf.matchUrl = function (uri) {
468        var match = false;
469
470        $.each(uri, function (k, v) {
471            if (match == true) {
472                return;
473            }
474            var vTxt = v.replace(/\//gi, "\\/");
475            var regex = new RegExp(vTxt, "gi");
476
477            match = regex.test(sf.config.pathName);
478        });
479
480        return match;
481    };
482    sf.getQueryString = function () {
483        var jdata = sf.getSession();
484        var q = [];
485
486      // 동일 페이지가 아닐경우 skip
487        if (!jdata || (jdata && sf.matchUrl(jdata.uri) == false)) {
488            return "";
489        }
490
491        var dataType = Object.prototype.toString.call(jdata.info);
492        $.each(jdata.info, function (k, v) {
493            if (dataType == "[object Array]") {
494                q.push(encodeURI(v.name + "=" + v.value));
495            } else if (dataType == "[object Object]") {
496                q.push(encodeURI(k + "=" + v));
497            }
498        });
499        return "?" + q.join("&");
500    };
501    sf.getQueryString();
502  // search session
503    sf.get = function () {
504        var jdata = sf.getSession();
505
506      // querystring이 있을 경우 skip
507        if (window.location.search != sf.config.loadKey) {
508            return false;
509        }
510
511      // 동일 페이지가 아닐경우 skip
512        if (!jdata || (jdata && sf.matchUrl(jdata.uri) == false)) {
513            return false;
514        }
515
516        return jdata.info;
517    };
518    sf.set = function (data, postFix) {
519        var uriArray = [];
520        if (!postFix || typeof postFix == "string") {
521            uriArray.push(sf.config.pathName);
522        } else {
523            uriArray.push(sf.config.pathName);
524            $.each(postFix, function (k, v) {
525                if (!v) {
526                    uriArray.push(sf.config.pathName + v);
527                }
528            });
529        }
530        $.each(data, function (k, v) {
531            if (!v) {
532                delete data[k];
533            }
534        });
535
536        var info = {
537            uri: uriArray,
538            info: data,
539        };
540        sessionStorage.setItem(sf.config.sessionKey, JSON.stringify(info));
541    };
542    sf.init = function () {
543        var jdata = sf.getSession();
544        if (jdata && sf.matchUrl(jdata.uri) == false) {
545          // 페이지 이탈시 세션 초기화
546            sessionStorage.clear();
547        }
548    };
549    sf.init();
550
551    return sf;
552})(window.SearchFunction || {});
553
554function goSearchPage(url, searchText)
555{
556    location.href = url + "?s=" + encodeURI(searchText);
557}
558
559$(document).on("pjax:error", function (event, request) {
560    event.preventDefault();
561});
562
563var pop = {
564    element: null,
565    isActive: false,
566
567    init: function () {
568        $(document).on("click", ".layer-pop-wrap", function (e) {
569            if (pop.isActive) {
570                if ($(e.target).parents(".pop-data").length == 0) {
571                    pop.close();
572                }
573            }
574        });
575    },
576
577    open: function (_id, _item) {
578        this.element = $("#" + _id);
579
580        if (this.element.length > 0) {
581            pop.isActive = true;
582            $("html").addClass("fix");
583            if (
584            this.element.hasClass("bottom") &&
585            this.element.find(".pop-body").length > 0
586            ) {
587                this.element.find(".pop-body").scrollTop(0);
588            }
589            this.element.addClass("actived");
590        } else {
591            alert("컨텐츠가 없습니다.");
592        }
593    },
594
595    close: function (_item) {
596        var $element;
597        pop.isActive = false;
598        $("html").removeClass("fix");
599
600        if (_item) {
601            $element = $(_item).parents(".layer-pop-wrap");
602        } else {
603            $element = this.element;
604        }
605        $element.removeClass("actived");
606    },
607
608    change: function () {},
609};
610
611$(function () {
612    pop.init();
613});
614
615//*************************************************************
616//숫자 이외에는 다 뺀다.
617//@return : 숫자
618//*************************************************************
619String.prototype.onlyNum = function () {
620    var num = this.trim();
621    return this.trim().replace(/[^0-9]/g, "");
622};
623//*************************************************************
624//메일의 유효성을 체크
625//@return : true(맞는 형식) | false(잘못된 형식)
626//*************************************************************
627String.prototype.isEmail = function () {
628    var em = this.trim().match(
629        /^[_\-\.0-9a-zA-Z]{3,}@[-.0-9a-zA-z]{2,}\.[a-zA-Z]{2,4}$/
630    );
631    return em ? true : false;
632};
633//*************************************************************
634//핸드폰 체크 XXX-XXXX-XXXX 형태로 체크
635//@return : true(맞는 형식) | false(잘못된 형식)
636//*************************************************************
637String.prototype.isMobile = function () {
638    var num = this.trim().onlyNum();
639    num =
640    num.substring(0, 3) +
641    "-" +
642    num.substring(3, num.length - 4) +
643    "-" +
644    num.substring(num.length - 4, num.length);
645    num = num.trim().match(/^01([0|1|6|7|8|9]?)-?([0-9]{4})-?([0-9]{4})$/);
646    return num ? true : false;
647};
648
649// 23.04.27 추가 - searh-Brands.html 카테고리 체크 관련 스크립트
650$(document).ready(function () {
651  // Listen for changes to the checkboxes
652    $('input[name="searchProdBrand"]').change(function () {
653      // If "전체보기" checkbox is checked
654        if ($(this).val() === "" && $(this).prop("checked")) {
655          // Uncheck all other checkboxes
656            $('input[name="searchProdBrand"]').not(this).prop("checked", false);
657        }
658    });
659    if($("body[class*='newsletter']").length == 0) {
660        // $('.contents_box.editor_style *').removeAttr('style');
661        $('.contents_box.editor_style p').html(function(i, html) {
662          return html.replace(/&nbsp;/g, '');
663        })
664    }
665    // $('.contents_box.editor_style>p br').remove();
666
667});
668
669// 23.07.11 Add text-align star to p tag when Img has align class in editor styles.
670const alignCenterImages = document.querySelectorAll("img.aligncenter");
671
672alignCenterImages.forEach((img) => {
673    if (img.classList.contains("aligncenter")) {
674        img.parentNode.style.textAlign = "center";
675    }
676});

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.