dabory-banner-popup.js 8.3 KB

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