PageSourceSearch

https://www.minipactgames.com/js/site_coupon.js?1785372875

js minipactgames.com collected 2026-10-01 14:27:20 UTC 19,008 bytes, 538 lines download raw bytes

1var SITE_COUPON = function(){
2	var $couopn_list;
3	var $case_product_list;
4	var $case_category_list;
5	var page = 1;
6  var $mypage_modal_coupon_list;
7
8  var $detail_coupon_list;
9  var detail_downloadable_coupon_count = 0;
10
11  var designConfig;
12
13  /**
14   * 동적으로 디자인 설정 가져오기
15   */
16  var getDesignConfig = function() {
17    if (designConfig) {
18      return designConfig;
19    }
20
21    try {
22      $.ajax({
23        type: 'POST',
24        url: '/ajax/get_design_config.cm',
25        dataType: 'json',
26        async: false, // 동기 호출
27        cache: true,
28        success: function(res) {
29          if (res.success && res.data) {
30            designConfig = res.data;
31          }
32        }
33      });
34    } catch(e) {
35      console.error('Failed to fetch design config:', e);
36    }
37
38    return designConfig;
39  };
40
41	var init = function (){
42		$couopn_list = $("#couopn_list");
43		getMypageCouponList();
44	};
45  
46  var initDetail = function() {
47    
48  };
49  
50	function getMypageCouponList(){
51		$.ajax({
52			type: "POST",
53			url: ("/shop/mypage_coupon_list.cm"),
54			dataType: "json",
55			async: true,
56			cache: false,
57			success: function(res){
58				if(res.msg === "SUCCESS"){
59					$couopn_list.find("._coupon_list").html(res.html);
60					$couopn_list.find("._down_coupon_btn").off("click._down_coupon_btn").on("click._down_coupon_btn",function(){
61						var code = $(this).data("code");
62						if(code !== ""){
63							downCoupon(code);
64						}
65					});
66					setCouponTargetDialog();
67					setCouponUseDialog();
68          couponTitleResponsiveFontSize('#couopn_list');
69          setTimeout(couponSizeResponsive, 0);
70				}else{
71					alert(res.msg);
72				}
73			}
74		});
75	}
76
77  var openCouponDownloadModal = function(prod_code){
78    $(function(){
79      $.ajax({
80        type: 'POST',
81        data: {prod_code:prod_code },
82        url: ('/ajax/open_coupon_download_modal.cm'),
83        dataType: 'json',
84        async: false,
85        cache: false,
86        success: function (res) {
87          if(res.msg === 'SUCCESS'){
88            $.cocoaDialog.open({type : 'download_coupon', custom_popup : res.html, pc_width: 360 });
89            const afterToastNode = document.createElement('div');
90            const insetToastToModal = document.querySelector('.modal_download_coupon').appendChild(afterToastNode);
91            insetToastToModal.className = `modal-toast tw-bottom-[20px] tw-justify-center tw-items-center tw-py-[15px] tw-px-[30px] tw-bg-[rgba(0,0,0,0.6)] tw-rounded-[4px] tw-gap-[10px] tw-fixed tw-text-white tw-text-[14px]`;
92            $detail_coupon_list = $("#modal_coupon_list");
93            detail_downloadable_coupon_count = res.downloadable_count;
94          }else{
95            alert(res.msg);
96          }
97        }
98      });
99    });
100  };
101  
102  const toastAction = (toastMsg) => {
103    const toast = document.querySelector('.modal-toast');
104    toast.classList.add('show');
105    toast.textContent = toastMsg || '';
106
107    setTimeout(() => {
108      toast.classList.remove('show');
109    }, 2000);
110  };
111  
112  const isAllowedCouponIconSrc = (src) => {
113    try {
114      const url = new URL(src, window.location.origin);
115      return url.protocol === 'https:'
116        && /(^|\.)imweb\.[a-z.]+$/i.test(url.hostname)
117        && /\/images\/site\/download-icon2\.svg$/i.test(url.pathname);
118    } catch (e) {
119      return false;
120    }
121  };
122
123  const renderTotalCouponWrap = (wrap, htmlMsg, retryable) => {
124    if (!wrap) return;
125    const parsed = htmlMsg ? new DOMParser().parseFromString(String(htmlMsg), 'text/html') : null;
126    const text = parsed ? (parsed.body.textContent || '').trim() : '';
127    if (!text) return;
128    wrap.innerHTML = '';
129    const btn = document.createElement('button');
130    btn.className = 'total-coupon-download tw-w-full tw-py-[15px] tw-flex tw-items-center tw-justify-center btn-coupon tw-font-apple-sd-gothic tw-text-[15px]';
131    btn.textContent = text;
132    btn.disabled = !retryable;
133    if (retryable) {
134      btn.id = 'total_coupon_download';
135      btn.addEventListener('click', downloadEntireCoupon);
136      const imgs = parsed.querySelectorAll('img');
137      for (const serverImg of imgs) {
138        const src = serverImg.getAttribute('src') || '';
139        if (isAllowedCouponIconSrc(src)) {
140          const icon = document.createElement('img');
141          icon.src = src;
142          icon.alt = 'download_icon2';
143          icon.className = 'tw-ml-[10px]';
144          btn.appendChild(icon);
145          break;
146        }
147      }
148    }
149    wrap.appendChild(btn);
150  };
151
152  let downloadEntireCouponInFlight = false;
153
154  // 상세페이지 전체쿠폰 다운로드
155  const downloadEntireCoupon = () => {
156    if (downloadEntireCouponInFlight) return;
157    const downloadAbleCouponList = document.querySelector('#modal_coupon_list').querySelectorAll('[class*="_coupon_down_wrap_"]');
158    let downloadReadyCouponList = [];
159    downloadAbleCouponList.forEach((coupon) => {
160      const couponCode = coupon.dataset.code;
161      downloadReadyCouponList.push(couponCode);
162    });
163    const totalCouponWrap = document.querySelector('.total_coupon_wrap');
164    
165    if (downloadReadyCouponList.length > 0) {
166      downloadEntireCouponInFlight = true;
167      $.ajax({
168        type: "POST",
169        url: ('/shop/entire_coupon_download.cm'),
170        data: { code_list : downloadReadyCouponList },
171        dataType: "json",
172        async: true,
173        cache: false,
174        complete: function () {
175          downloadEntireCouponInFlight = false;
176        },
177        success: function (res) {
178          let is_partial_fail = false;
179          let totalCouponDownloadButton = '';
180          let totalCouponDownloadToastMsg = '';
181          const downloadedCouponCodes = [];
182
183          $detail_coupon_list = $("#modal_coupon_list");
184          res.map((res) => {
185            // $couopn_list = $("#modal_coupon_list");
186            $detail_coupon_list.find("._coupon_down_wrap_"+res.coupon_code).hide();
187
188            if (res.download === "SUCCESS") {
189              downloadedCouponCodes.push(res.coupon_code);
190              // $detail_coupon_list.find(".btn_down_failed_wrap_" + res.coupon_code).hide();
191              $detail_coupon_list.find(".btn_down_complete_wrap_"+res.coupon_code).css('display', 'flex');
192              // $detail_coupon_list.find('.coupon_wrap_'+res.coupon_code).addClass('download-done').find('.sale-price-title').addClass('download-done');
193
194                console.log(res.msg);
195
196              if (!is_partial_fail) {
197                totalCouponDownloadButton = res.msg;
198                totalCouponDownloadToastMsg = res.entireToastMsg;
199              }
200
201                detail_downloadable_coupon_count--;
202            } else {
203              $detail_coupon_list.find(".btn_down_complete_wrap_" + res.coupon_code).hide();
204              // $detail_coupon_list.find(".btn_down_failed_wrap_" + res.coupon_code).show();
205              // $detail_coupon_list.find(".coupon_wrap_" + res.coupon_code).addClass('download-failed').find('.sale-price-title').addClass('download-failed');
206              is_partial_fail = true;
207              totalCouponDownloadButton = res.msg;
208              totalCouponDownloadToastMsg = res.entireToastMsg;
209            }
210          });
211
212          if (downloadedCouponCodes.length > 0) {
213            window.dispatchEvent(new CustomEvent('imweb:coupon:downloaded', { detail: { codes: downloadedCouponCodes } }));
214          }
215          renderTotalCouponWrap(totalCouponWrap, totalCouponDownloadButton, is_partial_fail);
216          toastAction(totalCouponDownloadToastMsg);
217        }
218      });
219    }
220  };
221
222  // 상세페이지 개별쿠폰 다운로드
223  const detailPageDownCoupon = (code) => {
224    if (code != '') {
225      $.ajax({
226        type: 'POST',
227        data : {code:code},
228        url: ('/shop/detail_page_down_use_coupon.cm'),
229        dataType: 'json',
230        async: true,
231        cache: false,
232        success: function(res){
233          $detail_coupon_list = $("#modal_coupon_list");
234          $detail_coupon_list.find("._coupon_down_wrap_"+code).hide();
235          if (res.download === "SUCCESS"){
236            window.dispatchEvent(new CustomEvent('imweb:coupon:downloaded', { detail: { codes: [code] } }));
237            $detail_coupon_list.find(".btn_down_complete_wrap_"+code).css('display', 'flex');
238            $detail_coupon_list.find(".coupon-tag").css('display', 'none');
239
240            detail_downloadable_coupon_count--;
241            if (detail_downloadable_coupon_count == 0 && res.msg) {
242              const totalCouponWrap = document.querySelector('.total_coupon_wrap');
243              if (totalCouponWrap) renderTotalCouponWrap(totalCouponWrap, res.msg, false);
244            }
245          } else {
246            toastAction(res.toastMsg);
247          }
248        }
249      });
250    }
251  };
252  
253	//my page 쿠폰 다운받기
254	function downCoupon(code){
255		$.ajax({
256			type: 'POST',
257			data : {code:code},
258			url: ('/shop/mypage_down_use_coupon.cm'),
259			dataType: 'json',
260			async: true,
261			cache: false,
262			success: function(res){
263        if(res.msg === "SUCCESS"){
264          $couopn_list.find("._coupon_down_wrap_"+code).hide();
265          $couopn_list.find(".btn_down_complete_wrap_"+code).show();
266          // $couopn_list.find('.coupon_wrap_' +code).addClass('download-done').find('.sale-price-title').addClass('download-done');
267          // $couopn_list.find('.coupon_wrap_' +code).find('.use-info').removeClass('use-info').addClass('use-info-download-done');
268          // $couopn_list.find('.coupon_wrap_' +code).find('.sale-price-text').removeClass('sale-price-text').addClass('sale-price-text-done');
269
270          $mypage_modal_coupon_list = $(".modal_mypage_coupon_use_list");
271          if ($mypage_modal_coupon_list) {
272            $mypage_modal_coupon_list.find("._coupon_down_wrap_"+code).hide();
273            $mypage_modal_coupon_list.find(".btn_down_complete_wrap_"+code).show();
274            // $mypage_modal_coupon_list.find('.coupon_wrap_' +code).addClass('download-done').find('.sale-price-title').addClass('download-done');
275            // $mypage_modal_coupon_list.find('.coupon_wrap_' +code).find('.use-info').removeClass('.use-info').addClass('use-info-download-done');
276          }
277        }else{
278          alert(res.msg);
279        }
280      }
281		});
282	}
283	//쿠폰적용 다이얼로그 설정
284	function setCouponTargetDialog(){
285		$couopn_list.find("._coupon_target_btn").off("click.coupon_target_btn").on("click.coupon_target_btn",function(){
286			var coupon_code = $(this).data("code");
287			if(!isBlank(coupon_code)){
288				$.ajax({
289					type: 'POST',
290					data : {coupon_code:coupon_code},
291					url: ('/dialog/mypage_coupon_target.cm'),
292					dataType: 'html',
293					async: true,
294					cache: false,
295					success: function(res){
296						$.cocoaDialog.open({type : 'mypage_coupon_target', custom_popup : $(res)});
297					}
298				});
299			}
300		});
301	}
302  
303	function setCouponUseDialog(){
304		$couopn_list.find("._coupon_use_btn").off("click").on("click.coupon_use_btn", function () {
305      var coupon_code = $(this).data("code");
306      $.ajax({
307        type: 'POST',
308        url: ('/dialog/mypage_coupon_use_list.cm'),
309        data: {code: coupon_code},
310        dataType: 'json',
311        async: true,
312        cache: false,
313        success: function(res) {
314          if (res.msg === "SUCCESS") {
315            $.cocoaDialog.open(
316              //모달이 오픈되었을때
317              {type: 'mypage_coupon_use_list', custom_popup: $(res.html)},
318              function() {
319                $case_category_list = $("._case_category_wrap");
320                $case_product_list = $("._case_product_wrap");
321                getCouponApplyList(true, coupon_code);
322                $(".modal_mypage_coupon_use_list").find("._down_coupon_btn").off("click._down_coupon_btn").on("click._down_coupon_btn", function() {
323                  var code = $(this).data("code");
324                  if (code !== "") {
325                    downCoupon(code);
326                  }
327                });
328                couponTitleResponsiveFontSize('.modal_mypage_coupon_use_list');
329              });
330            // 사용제외 목록 on / off
331            /**
332             * 모달에 사용제외 목록이 붙어있는데, 얘는 사용제외가 있을 경우에만 생성이 되기때문에 모달 오픈후에 뿌려주도록 스크립트를 넣어줌 ! 
333             * 모양이 보기좋지는 않기때문에... 시간이 된다면 수정예정
334             * */
335            const excluded_list = document.querySelectorAll('.excluded_list_warp');
336            if (excluded_list.length !== 0) {
337              excluded_list.forEach(list => {
338                let ExcludedShowBtn = list.querySelector(
339                  '._btn_show_excluded_prod_list');
340                let ExcludedHideBtn = list.querySelector(
341                  '._btn_hide_excluded_prod_list');
342                ExcludedShowBtn.addEventListener('click', (e) => {
343                  ExcludedShowBtn.classList.add('hide');
344                  ExcludedHideBtn.classList.add('show');
345                  list.querySelector('._coupon_excluded_text_wrap').
346                    classList.
347                    add('show');
348                });
349                ExcludedHideBtn.addEventListener('click', (e) => {
350                  ExcludedHideBtn.classList.add('hide');
351                  ExcludedHideBtn.classList.remove('show');
352                  ExcludedShowBtn.classList.remove('hide');
353                  list.querySelector('._coupon_excluded_text_wrap').
354                    classList.remove('show');
355                });
356              });
357            }
358          } else {
359            alert(res.msg);
360          }
361        }
362      });
363    });
364	}
365  
366	function getCouponApplyList(list_clear,code){
367		if(list_clear === true) {
368			page = 1;
369			$case_category_list.empty();
370			$case_product_list.empty();
371			$(".modal_mypage_coupon_use_list").find(".more").hide();
372		}
373		$.ajax({
374			type: 'POST',
375			url: ('/dialog/get_coupon_apply_list.cm'),
376			data : {"code" : code, "page" : page},
377			dataType: 'json',
378			async: true,
379			cache: false,
380			success: function (res){
381				if(res.msg === "SUCCESS"){
382					if(res.is_category === "Y"){
383						$case_category_list.append(res.html);
384					}else{
385						$case_product_list.append(res.html);
386					}
387					page+=1;
388					if(res.is_more === "N") $(".modal_mypage_coupon_use_list").find(".more").hide();
389					else $(".modal_mypage_coupon_use_list").find(".more").show();
390				}else{
391					alert(res.msg);
392				}
393			}
394		});
395	}
396  
397  // 마이페이지내에서 쿠폰 폰트 사이즈를 조절해주는 함수
398  const couponTitleResponsiveFontSize = (currentElement) => {
399    // currentElement = 쿠폰 row들을 담고있는 부모요소의 클래스명 or 아이디명 넣어주면 됌
400      const CouponWrap = document.querySelector(currentElement);
401      const couponTitleList = CouponWrap.querySelectorAll('.sale-price-title');
402      couponTitleList.forEach(title => {
403        const couponTitleHeight = title.clientHeight;
404        //40은 쿠폰 타이틀 한줄기준 높이
405        couponTitleHeight > 40 ? title.style.fontSize = '20px' : title.style.fontSize = '28px';
406      });
407  };
408  
409  // 마이페이지내에서 한 row안에서 제일 긴 쿠폰사이즈로 변경시켜주는 함수
410  const couponSizeResponsive = () => {
411      const windowWidth = window.innerWidth;
412      if (windowWidth > 768) {
413        const myPageCoupon = document.querySelector('#couopn_list');
414        if (!myPageCoupon) return;
415          const couponRows = myPageCoupon.querySelectorAll('.row');
416          couponRows.forEach(row => {
417            let couponHeight = 0;
418            const couponWrapList = row.querySelectorAll('.coupon-wrap');
419            Array.from(couponWrapList).map(coupon => {
420              couponHeight = coupon.getBoundingClientRect().height > couponHeight ? coupon.getBoundingClientRect().height : couponHeight;
421            });
422            couponWrapList.forEach(coupon => {
423              coupon.style.height = `${couponHeight}px`;
424            });
425          });
426        
427      }else {
428          const couponWrapList = document.querySelectorAll('.coupon-wrap');
429          couponWrapList.forEach(coupon => {
430            coupon.style.height = 'auto';
431          });
432        }
433  };
434  window.addEventListener('resize', couponSizeResponsive);
435
436  /**
437   * 로그인 페이지로 이동 또는 로그인 팝업 열기
438   */
439  var handleLoginRedirect = function() {
440    var encodedCurrentUrl = encodeURIComponent(btoa(window.location.href));
441    var config = getDesignConfig();
442
443    if (typeof config !== 'undefined' && config.use_login_popup === 'Y') {
444      if (typeof window.SITE_MEMBER !== 'undefined' && typeof window.SITE_MEMBER.openLogin === 'function') {
445        SITE_MEMBER.openLogin(encodedCurrentUrl);
446      } else {
447        window.location.href = '/login?back_url=' + encodedCurrentUrl;
448      }
449    } else {
450      window.location.href = '/login?back_url=' + encodedCurrentUrl;
451    }
452  };
453
454  // 단일 쿠폰 다운로드 (링크 클릭용)
455  const downloadSingleCoupon = (couponUrl) => {
456    $.ajax({
457      type: 'POST',
458      url: '/shop/download_coupon_by_url.cm',
459      data: { coupon_url: couponUrl },
460      dataType: 'json',
461      async: true,
462      cache: false,
463      success: function(res) {
464        if (res.success) {
465          alert(res.message);
466        } else {
467          if (res.need_login) {
468            handleLoginRedirect();
469          } else {
470            alert(res.message);
471          }
472        }
473      },
474      error: function() {
475        alert(res.message);
476      }
477    });
478  };
479
480  // 쿠폰팩 다운로드 (링크 클릭용)
481  const downloadCouponPack = (couponPackUrls) => {
482    $.ajax({
483      type: 'POST',
484      url: '/shop/download_coupon_pack_by_url.cm',
485      data: { coupon_pack_urls: couponPackUrls },
486      dataType: 'json',
487      async: true,
488      cache: false,
489      success: function(res) {
490        if (res.success) {
491          alert(res.message);
492        } else {
493          if (res.need_login) {
494            handleLoginRedirect();
495          } else {
496            alert(res.message || '쿠폰 발급에 실패했습니다.');
497          }
498        }
499      },
500      error: function() {
501        alert(res.message);
502      }
503    });
504  };
505
506	return {
507		init:function(){
508			init();
509		},
510    initDetail:function(){
511      initDetail();
512    },
513    couponTitleResponsiveFontSize : (currentElement) => {
514      couponTitleResponsiveFontSize(currentElement);
515    },
516    getCouponApplyList: function(list_clear,code){
517			getCouponApplyList(list_clear,code);
518		},
519    detailPageDownCoupon: function(code){
520      detailPageDownCoupon(code);
521    },
522    downloadEntireCoupon: function(code, array) {
523      downloadEntireCoupon(code, array);
524    },
525    openCouponDownloadModal : function(prod_code){
526      openCouponDownloadModal(prod_code);
527    },
528    couponSizeResponsive : function() {
529      couponSizeResponsive();
530    },
531    downloadSingleCoupon: function(couponUrl) {
532      downloadSingleCoupon(couponUrl);
533    },
534    downloadCouponPack: function(couponPackUrls) {
535      downloadCouponPack(couponPackUrls);
536    }
537	};
538}();

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.