dabory-quick.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. (function($) {
  2. $.fn.quick = async function(options) {
  3. const opts = $.extend({}, $.fn.quick.defaults, options)
  4. $.fn.quick.zIndex = 5000
  5. callApi.call(this)
  6. };
  7. function callApi() {
  8. const self = this
  9. $.fn.dataLinker.api23Js('setup-get', {
  10. "SetupCode": "quick-launcher"
  11. }, function (response) {
  12. if (response) {
  13. self.append(html.call(self, response))
  14. loadModule.call(self)
  15. loadWidget.call(self)
  16. }
  17. })
  18. }
  19. function loadWidget() {
  20. this.append(
  21. `<div id="dabory-widget-list">
  22. <div id="dabory-banner"></div>
  23. <div id="dabory-contact-us"></div>
  24. <div id="dabory-coupon"></div>
  25. <div id="dabory-review"></div>
  26. </div>`
  27. )
  28. $(this).find('#dabory-banner').bannerPopup()
  29. $(this).find('#dabory-contact-us').contactUs({
  30. top: 170,
  31. left: 170,
  32. })
  33. $(this).find('#dabory-coupon').coupon({
  34. top: 40,
  35. left: 375,
  36. })
  37. $(this).find('#dabory-review').review({
  38. top: 100,
  39. left: 100,
  40. })
  41. loadScript()
  42. }
  43. function loadScript() {
  44. $('head').append(`<script src="https://www.google.com/recaptcha/api.js" async defer></script>`)
  45. }
  46. function showWidget(widgetName, active) {
  47. const $widget = $(this).find(`.${widgetName}`)
  48. if (active) {
  49. $($widget).css('z-index', $.fn.quick.zIndex++)
  50. $($widget).trigger('show.widget')
  51. }
  52. $($widget).toggle()
  53. }
  54. function attachedType(buttons) {
  55. return `<div class="dabory-quick-A quick-launcher">
  56. <ul>
  57. <li>
  58. <button type="button" class="return-to-bottom">
  59. <span class="ico ico-bottom"></span>
  60. </button>
  61. </li>
  62. ${appendButtons.call(this, buttons)}
  63. <li>
  64. <button type="button" class="return-to-top">
  65. <span class="ico ico-top"></span>
  66. </button>
  67. </li>
  68. </ul>
  69. </div>`
  70. }
  71. function floatingType(buttons) {
  72. return `<div class="dabory-quick-B quick-launcher">
  73. <ul>
  74. <li>
  75. <button type="button" class="return-to-bottom">
  76. <span class="ico ico-bottom"></span>
  77. </button>
  78. </li>
  79. ${appendButtons.call(this, buttons)}
  80. <li>
  81. <button type="button" class="return-to-top">
  82. <span class="ico ico-top"></span>
  83. </button>
  84. </li>
  85. </ul>
  86. </div>`
  87. }
  88. function appendButtons(buttons) {
  89. return buttons.reduce((html, button) => {
  90. return html + `<li>
  91. <button type="button" class="show-widget-btn" data-widget="${button['Class']}">
  92. <img src="${button['ImageUrl']}" alt="${button['Name']}">
  93. <p class="txt">${button['Name']}</p>
  94. </button>
  95. </li>`
  96. }, '')
  97. }
  98. function html(quickLauncher) {
  99. switch (quickLauncher['Type']) {
  100. case 'right-floating':
  101. return floatingType(quickLauncher['Buttons'])
  102. case 'right-attached':
  103. return attachedType(quickLauncher['Buttons'])
  104. }
  105. }
  106. function loadModule() {
  107. const self = this
  108. $(document).ready(function () {
  109. $(document).on('hide.widget', '#dabory-widget-list', function (event, widgetName) {
  110. $(self).find('.quick-launcher')
  111. .find(`[data-widget="${widgetName}"]`)
  112. .closest('li').toggleClass('active')
  113. });
  114. $(self).find('.show-widget-btn').on('click', function() {
  115. $(this).closest('li').toggleClass('active')
  116. showWidget.call(self, $(this).data('widget'), $(this).closest('li').hasClass('active'))
  117. });
  118. $(self).find('.return-to-top').on('click', function() {
  119. $('body,html').animate({
  120. scrollTop: 0
  121. }, 500);
  122. });
  123. $(self).find('.return-to-bottom').on('click', function() {
  124. $('body,html').animate({
  125. scrollTop: $('body,html')[0].scrollHeight
  126. }, 500);
  127. });
  128. $(document).on('click', '.tab-close', function () {
  129. const widget = $(this).data('widget')
  130. $(this).closest(`.${widget}`).hide()
  131. $(this).closest('#dabory-widget-list').trigger('hide.widget', widget)
  132. });
  133. // $('.show-widget-btn[data-widget="coupon"]').trigger('click')
  134. });
  135. }
  136. $.fn.quick.defaults = {
  137. langType: 'ko',
  138. basePath: '/dabory/widget/quick',
  139. };
  140. }(jQuery));