PageSourceSearch

https://guponoodle.co.kr/js/shop.js

js guponoodle.co.kr collected 2026-10-06 13:17:11 UTC 13,997 bytes, 453 lines download raw bytes

1var option_add = false;
2var supply_add = false;
3var isAndroid = (navigator.userAgent.toLowerCase().indexOf("android") > -1);
4
5$(function() {
6    // 선택옵션
7    /* 가상커서 ctrl keyup 이베트 대응 */
8    /*
9    $(document).on("keyup", "select.it_option", function(e) {
10        var sel_count = $("select.it_option").size();
11        var idx = $("select.it_option").index($(this));
12        var code = e.keyCode;
13        var val = $(this).val();
14
15        option_add = false;
16        if(code == 17 && sel_count == idx + 1) {
17            if(val == "")
18                return;
19
20            sel_option_process(true);
21        }
22    });
23    */
24
25    /* 키보드 접근 후 옵션 선택 Enter keydown 이벤트 대응 */
26    $(document).on("keydown", "select.it_option", function(e) {
27        var sel_count = $("select.it_option").size();
28        var idx = $("select.it_option").index($(this));
29        var code = e.keyCode;
30        var val = $(this).val();
31
32        option_add = false;
33        if(code == 13 && sel_count == idx + 1) {
34            if(val == "")
35                return;
36
37            sel_option_process(true);
38        }
39    });
40
41    if(isAndroid) {
42        $(document).on("touchend", "select.it_option", function() {
43            option_add = true;
44        });
45    } else {
46        $(document).on("mouseup", "select.it_option", function() {
47            option_add = true;
48        });
49    }
50
51    $(document).on("change", "select.it_option", function() {
52        var sel_count = $("select.it_option").size();
53        var idx = $("select.it_option").index($(this));
54        var val = $(this).val();
55        var it_id = $("input[name='it_id[]']").val();
56
57        // 선택값이 없을 경우 하위 옵션은 disabled
58        if(val == "") {
59            $("select.it_option:gt("+idx+")").val("").attr("disabled", true);
60            return;
61        }
62
63        // 하위선택옵션로드
64        if(sel_count > 1 && (idx + 1) < sel_count) {
65            var opt_id = "";
66
67            // 상위 옵션의 값을 읽어 옵션id 만듬
68            if(idx > 0) {
69                $("select.it_option:lt("+idx+")").each(function() {
70                    if(!opt_id)
71                        opt_id = $(this).val();
72                    else
73                        opt_id += chr(30)+$(this).val();
74                });
75
76                opt_id += chr(30)+val;
77            } else if(idx == 0) {
78                opt_id = val;
79            }
80
81            $.post(
82                "./itemoption.php",
83                { it_id: it_id, opt_id: opt_id, idx: idx, sel_count: sel_count },
84                function(data) {
85                    $("select.it_option").eq(idx+1).empty().html(data).attr("disabled", false);
86
87                    // select의 옵션이 변경됐을 경우 하위 옵션 disabled
88                    if(idx+1 < sel_count) {
89                        var idx2 = idx + 1;
90                        $("select.it_option:gt("+idx2+")").val("").attr("disabled", true);
91                    }
92                }
93            );
94        } else if((idx + 1) == sel_count) { // 선택옵션처리
95            if(option_add && val == "")
96                return;
97
98            var info = val.split(",");
99            // 재고체크
100            if(parseInt(info[2]) < 1) {
101                alert("선택하신 선택옵션상품은 재고가 부족하여 구매할 수 없습니다.");
102                return false;
103            }
104
105            if(option_add)
106                sel_option_process(true);
107        }
108    });
109
110    // 추가옵션
111    /* 가상커서 ctrl keyup 이베트 대응 */
112    /*
113    $(document).on("keyup", "select.it_supply", function(e) {
114        var $el = $(this);
115        var code = e.keyCode;
116        var val = $(this).val();
117
118        supply_add = false;
119        if(code == 17) {
120            if(val == "")
121                return;
122
123            sel_supply_process($el, true);
124        }
125    });
126    */
127
128    /* 키보드 접근 후 옵션 선택 Enter keydown 이벤트 대응 */
129    $(document).on("keydown", "select.it_supply", function(e) {
130        var $el = $(this);
131        var code = e.keyCode;
132        var val = $(this).val();
133
134        supply_add = false;
135        if(code == 13) {
136            if(val == "")
137                return;
138
139            sel_supply_process($el, true);
140        }
141    });
142
143    if(isAndroid) {
144        $(document).on("touchend", "select.it_supply", function() {
145            supply_add = true;
146        });
147    } else {
148        $(document).on("mouseup", "select.it_supply", function() {
149            supply_add = true;
150        });
151    }
152
153    $(document).on("change", "select.it_supply", function() {
154        var $el = $(this);
155        var val = $(this).val();
156
157        if(val == "")
158            return;
159
160        if(supply_add)
161            sel_supply_process($el, true);
162    });
163
164    // 수량변경 및 삭제
165    $(document).on("click", "#sit_sel_option li button", function() {
166        var mode = $(this).text();
167        var this_qty, max_qty = 9999, min_qty = 1;
168        var $el_qty = $(this).closest("li").find("input[name^=ct_qty]");
169        var stock = parseInt($(this).closest("li").find("input.io_stock").val());
170
171        switch(mode) {
172            case "증가":
173                this_qty = parseInt($el_qty.val().replace(/[^0-9]/, "")) + 1;
174                if(this_qty > stock) {
175                    alert("재고수량 보다 많은 수량을 구매할 수 없습니다.");
176                    this_qty = stock;
177                }
178
179                if(this_qty > max_qty) {
180                    this_qty = max_qty;
181                    alert("최대 구매수량은 "+number_format(String(max_qty))+" 입니다.");
182                }
183
184                $el_qty.val(this_qty);
185                price_calculate();
186                break;
187
188            case "감소":
189                this_qty = parseInt($el_qty.val().replace(/[^0-9]/, "")) - 1;
190                if(this_qty < min_qty) {
191                    this_qty = min_qty;
192                    alert("최소 구매수량은 "+number_format(String(min_qty))+" 입니다.");
193                }
194                $el_qty.val(this_qty);
195                price_calculate();
196                break;
197
198            case "삭제":
199                if(confirm("선택하신 옵션항목을 삭제하시겠습니까?")) {
200                    var $el = $(this).closest("li");
201                    var del_exec = true;
202
203                    if($("#sit_sel_option .sit_spl_list").size() > 0) {
204                        // 선택옵션이 하나이상인지
205                        if($el.hasClass("sit_opt_list")) {
206                            if($(".sit_opt_list").size() <= 1)
207                                del_exec = false;
208                        }
209                    }
210
211                    if(del_exec) {
212                        $el.closest("li").remove();
213                        price_calculate();
214                    } else {
215                        alert("선택옵션은 하나이상이어야 합니다.");
216                        return false;
217                    }
218                }
219                break;
220
221            default:
222                alert("올바른 방법으로 이용해 주십시오.");
223                break;
224        }
225    });
226
227    // 수량직접입력
228    $(document).on("keyup", "input[name^=ct_qty]", function() {
229        var val= $(this).val();
230
231        if(val != "") {
232            if(val.replace(/[0-9]/g, "").length > 0) {
233                alert("수량은 숫자만 입력해 주십시오.");
234                $(this).val(1);
235            } else {
236                var d_val = parseInt(val);
237                if(d_val < 1 || d_val > 9999) {
238                    alert("수량은 1에서 9999 사이의 값으로 입력해 주십시오.");
239                    $(this).val(1);
240                } else {
241                    var stock = parseInt($(this).closest("li").find("input.io_stock").val());
242                    if(d_val > stock) {
243                        alert("재고수량 보다 많은 수량을 구매할 수 없습니다.");
244                        $(this).val(stock);
245                    }
246                }
247            }
248
249            price_calculate();
250        }
251    });
252});
253
254// 선택옵션 추가처리
255function sel_option_process(add_exec)
256{
257    var it_price = parseInt($("input#it_price").val());
258    var id = "";
259    var value, info, sel_opt, item, price, stock, run_error = false;
260    var option = sep = "";
261    info = $("select.it_option:last").val().split(",");
262
263    $("select.it_option").each(function(index) {
264        value = $(this).val();
265        item = $(this).closest("tr").find("th label").text();
266
267        if(!value) {
268            run_error = true;
269            return false;
270        }
271
272        // 옵션선택정보
273        sel_opt = value.split(",")[0];
274
275        if(id == "") {
276            id = sel_opt;
277        } else {
278            id += chr(30)+sel_opt;
279            sep = " / ";
280        }
281
282        option += sep + item + ":" + sel_opt;
283    });
284
285    if(run_error) {
286        alert(item+"을(를) 선택해 주십시오.");
287        return false;
288    }
289
290    price = info[1];
291    stock = info[2];
292
293    // 금액 음수 체크
294    if(it_price + parseInt(price) < 0) {
295        alert("구매금액이 음수인 상품은 구매할 수 없습니다.");
296        return false;
297    }
298
299    if(add_exec) {
300        if(same_option_check(option))
301            return;
302
303        add_sel_option(0, id, option, price, stock);
304    }
305}
306
307// 추가옵션 추가처리
308function sel_supply_process($el, add_exec)
309{
310    var val = $el.val();
311    var item = $el.closest("tr").find("th label").text();
312
313    if(!val) {
314        alert(item+"을(를) 선택해 주십시오.");
315        return;
316    }
317
318    var info = val.split(",");
319
320    // 재고체크
321    if(parseInt(info[2]) < 1) {
322        alert(info[0]+"은(는) 재고가 부족하여 구매할 수 없습니다.");
323        return false;
324    }
325
326    var id = item+chr(30)+info[0];
327    var option = item+":"+info[0];
328    var price = info[1];
329    var stock = info[2];
330
331    // 금액 음수 체크
332    if(parseInt(price) < 0) {
333        alert("구매금액이 음수인 상품은 구매할 수 없습니다.");
334        return false;
335    }
336
337    if(add_exec) {
338        if(same_option_check(option))
339            return;
340
341        add_sel_option(1, id, option, price, stock);
342    }
343}
344
345// 선택된 옵션 출력
346function add_sel_option(type, id, option, price, stock)
347{
348    var item_code = $("input[name='it_id[]']").val();
349    var opt = "";
350    var li_class = "sit_opt_list";
351    if(type)
352        li_class = "sit_spl_list";
353
354    var opt_prc;
355    if(parseInt(price) >= 0)
356        opt_prc = "(+"+number_format(String(price))+"원)";
357    else
358        opt_prc = "("+number_format(String(price))+"원)";
359
360    opt += "<li class=\""+li_class+"\">";
361    opt += "<input type=\"hidden\" name=\"io_type["+item_code+"][]\" value=\""+type+"\">";
362    opt += "<input type=\"hidden\" name=\"io_id["+item_code+"][]\" value=\""+id+"\">";
363    opt += "<input type=\"hidden\" name=\"io_value["+item_code+"][]\" value=\""+option+"\">";
364    opt += "<input type=\"hidden\" class=\"io_price\" value=\""+price+"\">";
365    opt += "<input type=\"hidden\" class=\"io_stock\" value=\""+stock+"\">";
366    opt += "<span class=\"sit_opt_subj\">"+option+"</span>";
367    opt += "<span class=\"sit_opt_prc\">"+opt_prc+"</span>";
368    opt += "<div><input type=\"text\" name=\"ct_qty["+item_code+"][]\" value=\"1\" class=\"frm_input\" size=\"5\">";
369    opt += "<button type=\"button\" class=\"sit_qty_plus btn_frmline\">증가</button>";
370    opt += "<button type=\"button\" class=\"sit_qty_minus btn_frmline\">감소</button>";
371    opt += "<button type=\"button\" class=\"sit_opt_del btn_frmline\">삭제</button></div>";
372    opt += "</li>";
373
374    if($("#sit_sel_option > ul").size() < 1) {
375        $("#sit_sel_option").html("<ul id=\"sit_opt_added\"></ul>");
376        $("#sit_sel_option > ul").html(opt);
377    } else{
378        if(type) {
379            if($("#sit_sel_option .sit_spl_list").size() > 0) {
380                $("#sit_sel_option .sit_spl_list:last").after(opt);
381            } else {
382                if($("#sit_sel_option .sit_opt_list").size() > 0) {
383                    $("#sit_sel_option .sit_opt_list:last").after(opt);
384                } else {
385                    $("#sit_sel_option > ul").html(opt);
386                }
387            }
388        } else {
389            if($("#sit_sel_option .sit_opt_list").size() > 0) {
390                $("#sit_sel_option .sit_opt_list:last").after(opt);
391            } else {
392                if($("#sit_sel_option .sit_spl_list").size() > 0) {
393                    $("#sit_sel_option .sit_spl_list:first").before(opt);
394                } else {
395                    $("#sit_sel_option > ul").html(opt);
396                }
397            }
398        }
399    }
400
401    price_calculate();
402}
403
404// 동일선택옵션있는지
405function same_option_check(val)
406{
407    var result = false;
408    $("input[name^=io_value]").each(function() {
409        if(val == $(this).val()) {
410            result = true;
411            return false;
412        }
413    });
414
415    if(result)
416        alert(val+" 은(는) 이미 추가하신 옵션상품입니다.");
417
418    return result;
419}
420
421// 가격계산
422function price_calculate()
423{
424    var it_price = parseInt($("input#it_price").val());
425
426    if(isNaN(it_price))
427        return;
428
429    var $el_prc = $("input.io_price");
430    var $el_qty = $("input[name^=ct_qty]");
431    var $el_type = $("input[name^=io_type]");
432    var price, type, qty, total = 0;
433
434    $el_prc.each(function(index) {
435        price = parseInt($(this).val());
436        qty = parseInt($el_qty.eq(index).val());
437        type = $el_type.eq(index).val();
438
439        if(type == "0") { // 선택옵션
440            total += (it_price + price) * qty;
441        } else { // 추가옵션
442            total += price * qty;
443        }
444    });
445
446    $("#sit_tot_price").empty().html("<span>총 금액 :</span> "+number_format(String(total))+"원");
447}
448
449// php chr() 대응
450function chr(code)
451{
452    return String.fromCharCode(code);
453}

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.