(function($) { $.fn.coupon = async function(options) { const opts = $.extend({}, $.fn.coupon.defaults, options) this.append(html.call(this, '', opts, '')) loadModule.call(this) }; function html(couponList, opts, langJson) { return `` } function getLangText(langJson, key) { if (! langJson) { return key } return langJson[key] } function actCouponApi($btn) { const self = this $($btn).prop('disabled', true) $.fn.widget.spinnerLoading($(this).find('.send-btn'), true) $.fn.dataLinker.daboryApp('item-url-scrap', { "ItemUrl": $(this).find('.current-url-txt').val(), "InitDcrate": $(this).find('.init-dcrate-select').val(), "BuyerEmail": $(this).find('.buyer-email-txt').val(), "Sort": $(this).find('.sort-select').val(), "SortDesc": $(this).find('.sort-desc-txt').val(), }, function (response) { $.fn.widget.spinnerLoading($(self).find('.send-btn'), false) $($btn).prop('disabled', false) hidePopup.call(self) window.location.href = '/item-gallery/05' if (response.apiStatus) { if (response.apiStatus === 604) { return iziToast.error({ title: 'Error', message: '쿠폰지원예정-웹사이트(보류중)' }); } return iziToast.error({ title: 'Error', message: 'API Error' }); } return iziToast.success({ title: 'Success', message: 'Success' }); }) } function isRequiredInput() { if (! $(this).find('.current-url-txt').val()) { iziToast.error({ title: 'Error', message: '상품상세페이지 인터넷 주소를 입력하세요' }); return false; } if (! $(this).find('.buyer-email-txt').val()) { iziToast.error({ title: 'Error', message: '쿠폰을 받을 이메일주소를 입력하세요' }); return false; } if (! $(this).find('.policy-txt').prop('checked')) { return iziToast.error({ title: 'Error', message: '쿠폰 신청 이용 약관 에 동의하셔야 합니다' }) } return true; } function hidePopup() { $(this).find('.dabory-coupon-popup').hide() $(this).closest('#dabory-widget-list').trigger('hide.widget', 'coupon') } function loadModule() { const self = this $(document).ready(function () { $(self).find('.dabory-coupon-popup').draggable() $(self).find('.sort-select').on('change', function() { $(self).find('.sort-desc-txt').val('') $(self).find('.sort-desc-txt').prop('disabled', $(this).val() !== '3') }); $(self).find('.send-btn').on('click', function() { const v = grecaptcha.getResponse(); if (v.length === 0) { return iziToast.error({ title: 'Error', message: "자동입력방지 기능 - '로봇이 아닙니다.'를 체크해주세요" }); } if (isRequiredInput.call(self)) { actCouponApi.call(self, this) } }); $(self).find('.current-url-txt').on('click', function() { $(this).val('') validateInputs.call(self) }); $(document).on('show.widget', '.dabory-coupon-popup', function (event, widgetName) { const currentURL = window.location.protocol + "//" + window.location.host + window.location.pathname $(self).find('.current-url-txt').val(currentURL) }); $(self).find('.current-url-txt').on('input', function () { validateInputs.call(self) }); $(self).find('.buyer-email-txt').on('input', function () { validateInputs.call(self) }); $(self).find('.policy-txt').on('change', function () { validateInputs.call(self) }); }); } function validateInputs() { // Get the input values const value1 = $(this).find('.current-url-txt').val() const value2 = $(this).find('.buyer-email-txt').val() // Perform your validation checks if (value1.length >= 1 && value2.length >= 1 && $(this).find('.policy-txt').prop('checked')) { // Enable the submit button $(this).find('.send-btn').prop('disabled', false) } else { // Disable the submit button $(this).find('.send-btn').prop('disabled', true) } } $.fn.coupon.defaults = { top: 0, left: 0, width: 500, langType: 'ko', basePath: '/dabory/widget/coupon', }; }(jQuery));