dabory-banner-popup.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. (function($) {
  2. $.fn.bannerPopup = async function(options) {
  3. const opts = $.extend({}, $.fn.bannerPopup.defaults, options)
  4. const langJson = await loadLangJson.call(this, opts['basePath'], opts['langType'])
  5. callBannerApi.call(this, opts, langJson)
  6. };
  7. function appendSlide(bannerList, opts) {
  8. return bannerList.reduce((html, banner) => {
  9. return html + `<li class="dabory-slide swiper-slide" style="width: ${opts['width']}px;">
  10. <a href="${banner['C5']}" target="${banner['C4'] === '0' ? '_self' : '_blank'}">
  11. <img src="${$.fn.dataLinker.serverUrl ?? window.env['MEDIA_URL']}${banner['C11']}" style="width: ${opts['width']}px;">
  12. </a>
  13. </li>`
  14. }, '')
  15. }
  16. function callBannerApi(opts, langJson) {
  17. const self = this
  18. $.fn.dataLinker.localApi('list-type1-book', {
  19. "Book": [
  20. {
  21. "QueryVars": {
  22. "QueryName": "post/banner-input",
  23. "SimpleFilter": "(mx.post_type_id = 8 and mx.status = '0') and (DATE_FORMAT(now(), '%Y-%m-%d') BETWEEN mx.pc6 AND mx.pc7)",
  24. "IsntPagination": true,
  25. },
  26. "ListType1Vars" : {
  27. 'OrderBy': 'mx.pc3 asc'
  28. },
  29. "PageVars": {
  30. "Limit": 100000
  31. }
  32. },
  33. {
  34. "QueryVars": {
  35. "QueryName": "pro/setup",
  36. "SimpleFilter": "setup_code='popup-slider'",
  37. "IsntPagination": true,
  38. },
  39. "PageVars": {
  40. "Limit": 100000
  41. }
  42. }
  43. ]
  44. }, function (response) {
  45. const bannerList = response['Book'][0]['Page']
  46. if (bannerList) {
  47. bannerList['Setup'] = JSON.parse(response['Book'][1]['Page'][0]['C1'])
  48. opts['left'] = bannerList[0]['C7']
  49. opts['top'] = bannerList[0]['C8']
  50. self.append(html.call(self, bannerList, opts, langJson))
  51. loadModule.call(self, bannerList.map(banner => banner['C1']), bannerList['Setup'])
  52. }
  53. })
  54. }
  55. async function loadLangJson(basePath, langType) {
  56. let langJson = null
  57. if (langType === 'ko') { return langJson }
  58. const filePath = `${basePath}/lang/${langType}.json`
  59. await $.getJSON(filePath, function (data) {
  60. langJson = data
  61. });
  62. return langJson
  63. }
  64. // function loadScript(basePath) {
  65. // if (typeof Swiper === 'undefined') {
  66. // $('head').append(`<script src="${basePath}/swiper/swiper-bundle.js"></script>`)
  67. // }
  68. // if (jQuery().draggable === undefined) {
  69. // $('head').append(`<script src="${basePath}/jquery-ui.js"></script>`)
  70. // }
  71. // if ($.cookie === undefined) {
  72. // $('head').append(`<script src="${basePath}/jquery.cookie.js"></script>`)
  73. // }
  74. // }
  75. function loadSwiper(popupTitleList, setup) {
  76. const swiper = new Swiper($(this).find('.dabory-container')[0], {
  77. allowTouchMove: false,
  78. pagination: {
  79. el: $(this).find('.dabory-pagination')[0],
  80. clickable: true,
  81. renderBullet: function (index, className) {
  82. const titleList = popupTitleList[index].split(' ')
  83. let caption = ''
  84. titleList.forEach((title, index) => {
  85. if (index === 0) {
  86. caption += title
  87. } else if (index === 1) {
  88. caption += (`<br>${title}`)
  89. } else {
  90. caption += ' ' + title
  91. }
  92. });
  93. return `<div class="dabory-pagination-item ${className}">
  94. <div class="dabory-pagination-item-link"
  95. style="height: ${setup['FooterHeight']}px !important;">
  96. <span class="dabory-pagination-item-text">${caption}</span>
  97. </div>
  98. </div>`
  99. }
  100. },
  101. autoplay: {
  102. delay: 5000,
  103. disableOnInteraction: false,
  104. },
  105. });
  106. $(this).find('.dabory-slide').on('mouseover', function() {
  107. swiper.autoplay.stop();
  108. });
  109. $(this).find('.dabory-slide').on('mouseout', function() {
  110. swiper.autoplay.start();
  111. });
  112. }
  113. function todayCloseBanner(today = false) {
  114. if (today) {
  115. $.cookie($(this).getSelector(), 'ok', { expires: 1, path: '/' });
  116. }
  117. $(this).find('.dabory-bannermanager').hide()
  118. $(this).closest('#dabory-widget-list').trigger('hide.widget', 'banner')
  119. }
  120. function loadModule(titleList, setup) {
  121. const self = this
  122. $(document).ready(function () {
  123. $(self).find('.dabory-multipopup').draggable()
  124. if ($.cookie($(self).getSelector()) === 'ok') {
  125. $(self).find('.dabory-bannermanager').css('display', 'none')
  126. }
  127. else {
  128. $(self).find('.dabory-bannermanager').css('display', 'block')
  129. }
  130. $(self).find('.dabory-multipopup-btn-item_close').on('click', function() {
  131. todayCloseBanner.call(self)
  132. });
  133. $(self).find('.dabory-multipopup-btn-item_todayclose').on('click', function() {
  134. todayCloseBanner.call(self, true)
  135. });
  136. loadSwiper.call(self, titleList, setup)
  137. });
  138. }
  139. function html(bannerList, opts, langJson) {
  140. return `<div class="dabory-multipopup dabory-bannermanager dabory-bannermanager-pc-multi-popup banner"
  141. style="top: ${bannerList['Setup']['PosY']}px; left: ${bannerList['Setup']['PosX']}px; width: ${bannerList['Setup']['Width']}px; display: ${opts['hide'] ? 'none' : 'block'}; z-index: 9999;">
  142. <div class="dabory-multipopup-box">
  143. <div class="dabory-slider">
  144. <div
  145. class="dabory-container swiper-container swiper-container-slide swiper-container-initialized swiper-container-horizontal swiper-container-autoheight">
  146. <ul class="swiper-wrapper">
  147. ${appendSlide.call(this, bannerList, opts)}
  148. </ul>
  149. <span class="swiper-notification" aria-live="assertive" aria-atomic="true"></span>
  150. </div>
  151. <div
  152. class="dabory-pagination swiper-pagination swiper-pagination-clickable swiper-pagination-bullets swiper-pagination-text">
  153. </div>
  154. </div>
  155. </div>
  156. <div class="dabory-multipopup-btn-items">
  157. <div class="dabory-multipopup-btn-item dabory-multipopup-btn-item_todayclose"
  158. style="background-color: ${bannerList['Setup']['FooterBackColor']} !important; color: ${bannerList['Setup']['FooterFontColor']} !important;">
  159. ${getLangText(langJson, '오늘하루 열지 않음')}
  160. </div>
  161. <div class="dabory-multipopup-btn-item dabory-multipopup-btn-item_close"
  162. style="background-color: ${bannerList['Setup']['FooterBackColor']} !important; color: ${bannerList['Setup']['FooterFontColor']} !important;">
  163. ${getLangText(langJson, '닫기')}
  164. </div>
  165. </div>
  166. </div>`
  167. }
  168. function getLangText(langJson, key) {
  169. if (! langJson) { return key }
  170. return langJson[key]
  171. }
  172. $.fn.bannerPopup.defaults = {
  173. top: 0,
  174. left: 0,
  175. width: 650,
  176. langType: 'ko',
  177. basePath: '/dabory/widget/banner-popup',
  178. hide: true,
  179. };
  180. }(jQuery));