front.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /* global $this: true */
  2. /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "animationsSlider" }] */
  3. if ($.cookie('themeCSSpath')) {
  4. $('link#theme-stylesheet').attr('href', $.cookie('themeCSSpath'))
  5. }
  6. if ($.cookie('themeLayout')) {
  7. $('body').addClass($.cookie('themeLayout'))
  8. }
  9. // test
  10. $(function () {
  11. sliderHomepage()
  12. sliders()
  13. fullScreenContainer()
  14. productDetailGallery(4000)
  15. menuSliding()
  16. productDetailSizes()
  17. utils()
  18. animations()
  19. counters()
  20. demo()
  21. contactFormAjax()
  22. getVtuber()
  23. })
  24. // Ajax contact
  25. function contactFormAjax () {
  26. var form = $('.contact-form-ajax')
  27. if (typeof form === 'undefined') return false
  28. form.submit(function () {
  29. $this = $(this)
  30. $.post($(this).attr('action'),
  31. $this.serialize(),
  32. function () {
  33. $this[0].reset() // clear form
  34. $('#contact-message')
  35. .html('<div class="alert alert-success" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>Thank you for getting in touch. We will get back to you soon!</div>')
  36. .fadeIn()
  37. }
  38. , 'json')
  39. return false
  40. })
  41. }
  42. /* for demo purpose only - can be deleted */
  43. function demo () {
  44. if ($.cookie('themeCSSpath')) {
  45. $('link#theme-stylesheet').attr('href', $.cookie('themeCSSpath'))
  46. }
  47. $('#colour').change(function () {
  48. if ($(this).val() !== '') {
  49. var themeCSSpath = 'css/style.' + $(this).val() + '.css'
  50. $('link#theme-stylesheet').attr('href', themeCSSpath)
  51. $.cookie('themeCSSpath', themeCSSpath, {expires: 365, path: '/'})
  52. }
  53. return false
  54. })
  55. $('#layout').change(function () {
  56. if ($(this).val() !== '') {
  57. var themeLayout = $(this).val()
  58. $('body').removeClass('wide')
  59. $('body').removeClass('boxed')
  60. $('body').addClass(themeLayout)
  61. $.cookie('themeLayout', themeLayout, {expires: 365, path: '/'})
  62. }
  63. return false
  64. })
  65. }
  66. /* slider homepage */
  67. function sliderHomepage () {
  68. if ($('#slider').length) {
  69. // var owl = $('#slider')
  70. $('#slider').owlCarousel({
  71. autoPlay: 3000,
  72. items: 4,
  73. itemsDesktopSmall: [900, 3],
  74. itemsTablet: [600, 3],
  75. itemsMobile: [500, 2]
  76. })
  77. }
  78. }
  79. /* sliders */
  80. function sliders () {
  81. if ($('.owl-carousel').length) {
  82. console.log("pass");
  83. $('.customers').owlCarousel({
  84. items: 6,
  85. itemsDesktopSmall: [990, 4],
  86. itemsTablet: [768, 2],
  87. itemsMobile: [480, 1]
  88. })
  89. $('.testimonials').owlCarousel({
  90. items: 4,
  91. itemsDesktopSmall: [990, 3],
  92. itemsTablet: [768, 2],
  93. itemsMobile: [480, 1]
  94. })
  95. $('.project').owlCarousel({
  96. navigation: true, // Show next and prev buttons
  97. navigationText: ['<i class="fas fa-angle-left"></i>', '<i class="fas fa-angle-right"></i>'],
  98. dots: false,
  99. slideSpeed: 300,
  100. paginationSpeed: 400,
  101. autoPlay: true,
  102. stopOnHover: true,
  103. singleItem: true,
  104. afterInit: '',
  105. lazyLoad: true
  106. })
  107. $(".eu-vtuber").owlCarousel({
  108. navigation: true, // Show next and prev buttons
  109. navigationText: ['<i class="fas fa-angle-left"></i>', '<i class="fas fa-angle-right"></i>'],
  110. dots: false,
  111. slideSpeed: 300,
  112. paginationSpeed: 400,
  113. autoPlay: true,
  114. stopOnHover: true,
  115. singleItem: true,
  116. afterInit: '',
  117. lazyLoad: true
  118. })
  119. $('.homepage').owlCarousel({
  120. navigation: false, // Show next and prev buttons
  121. margin: 10,
  122. navigationText: ['<i class="fas fa-angle-left"></i>', '<i class="fas fa-angle-right"></i>'],
  123. slideSpeed: 2000,
  124. paginationSpeed: 1000,
  125. autoPlay: true,
  126. stopOnHover: true,
  127. singleItem: true,
  128. lazyLoad: false,
  129. addClassActive: true,
  130. afterInit: function () {
  131. // animationsSlider()
  132. },
  133. afterMove: function () {
  134. // animationsSlider()
  135. }
  136. })
  137. }
  138. }
  139. /* menu sliding */
  140. function menuSliding () {
  141. $('.dropdown').on('show.bs.dropdown', function () {
  142. if ($(window).width() > 750) {
  143. $(this).find('.dropdown-menu').first().stop(true, true).slideDown()
  144. } else {
  145. $(this).find('.dropdown-menu').first().stop(true, true).show()
  146. }
  147. })
  148. $('.dropdown').on('hide.bs.dropdown', function () {
  149. if ($(window).width() > 750) {
  150. $(this).find('.dropdown-menu').first().stop(true, true).slideUp()
  151. } else {
  152. $(this).find('.dropdown-menu').first().stop(true, true).hide()
  153. }
  154. })
  155. }
  156. /* animations */
  157. function animations () {
  158. var delayTime = 0
  159. $('[data-animate]').css({opacity: '0'})
  160. $('[data-animate]').waypoint(function () {
  161. delayTime += 150
  162. $(this).delay(delayTime).queue(function (next) {
  163. $(this).toggleClass('animated')
  164. $(this).toggleClass($(this).data('animate'))
  165. delayTime = 0
  166. next()
  167. // $(this).removeClass('animated')
  168. // $(this).toggleClass($(this).data('animate'))
  169. })
  170. }, {
  171. offset: '90%',
  172. triggerOnce: true
  173. })
  174. $('[data-animate-hover]').hover(function () {
  175. $(this).css({opacity: 1})
  176. $(this).addClass('animated')
  177. $(this).removeClass($(this).data('animate'))
  178. $(this).addClass($(this).data('animate-hover'))
  179. }, function () {
  180. $(this).removeClass('animated')
  181. $(this).removeClass($(this).data('animate-hover'))
  182. })
  183. }
  184. function animationsSlider () {
  185. var delayTimeSlider = 400
  186. $('.owl-item:not(.active) [data-animate-always]').each(function () {
  187. $(this).removeClass('animated')
  188. $(this).removeClass($(this).data('animate-always'))
  189. $(this).stop(true, true, true).css({opacity: 0})
  190. })
  191. $('.owl-item.active [data-animate-always]').each(function () {
  192. delayTimeSlider += 500
  193. $(this).delay(delayTimeSlider).queue(function () {
  194. $(this).addClass('animated')
  195. $(this).addClass($(this).data('animate-always'))
  196. console.log($(this).data('animate-always'))
  197. })
  198. })
  199. }
  200. /* counters */
  201. function counters () {
  202. $('.counter').counterUp({
  203. delay: 10,
  204. time: 1000
  205. })
  206. }
  207. /* picture zoom */
  208. function pictureZoom () {
  209. $('.product .image, .post .image, .photostream div').each(function () {
  210. var imgHeight = $(this).find('img').height()
  211. if (imgHeight) {
  212. $(this).height(imgHeight)
  213. }
  214. })
  215. }
  216. /* full screen intro */
  217. function fullScreenContainer () {
  218. var screenWidth = $(window).width() + 'px'
  219. var screenHeight = '500px'
  220. if ($(window).height() > 500) {
  221. screenHeight = $(window).height() + 'px'
  222. }
  223. $('#intro, #intro .item').css({
  224. width: screenWidth,
  225. height: screenHeight
  226. })
  227. }
  228. function utils () {
  229. /* tooltips */
  230. $('[data-toggle="tooltip"]').tooltip()
  231. /* click on the box activates the radio */
  232. $('#checkout').on('click', '.box.shipping-method, .box.payment-method', function () {
  233. var radio = $(this).find(':radio')
  234. radio.prop('checked', true)
  235. })
  236. /* click on the box activates the link in it */
  237. $('.box.clickable').on('click', function () {
  238. window.location = $(this).find('a').attr('href')
  239. })
  240. /* external links in new window */
  241. $('.external').on('click', function (e) {
  242. e.preventDefault()
  243. window.open($(this).attr('href'))
  244. })
  245. /* animated scrolling */
  246. $('.scroll-to, .scroll-to-top').click(function (event) {
  247. var fullUrl = this.href
  248. var parts = fullUrl.split('#')
  249. if (parts.length > 1) {
  250. scrollTo(fullUrl)
  251. event.preventDefault()
  252. }
  253. })
  254. function scrollTo (fullUrl) {
  255. var parts = fullUrl.split('#')
  256. var trgt = parts[1]
  257. var targetOffset = $('#' + trgt).offset()
  258. var targetTop = targetOffset.top - 100
  259. if (targetTop < 0) {
  260. targetTop = 0
  261. }
  262. $('html, body').animate({
  263. scrollTop: targetTop
  264. }, 1000)
  265. }
  266. }
  267. /* product detail gallery */
  268. function productDetailGallery (confDetailSwitch) {
  269. $('.thumb:first').addClass('active')
  270. var timer = setInterval(autoSwitch, confDetailSwitch)
  271. $('.thumb').click(function (e) {
  272. switchImage($(this))
  273. clearInterval(timer)
  274. timer = setInterval(autoSwitch, confDetailSwitch)
  275. e.preventDefault()
  276. })
  277. $('#mainImage').hover(function () {
  278. clearInterval(timer)
  279. }, function () {
  280. timer = setInterval(autoSwitch, confDetailSwitch)
  281. })
  282. function autoSwitch () {
  283. var nextThumb = $('.thumb.active').closest('div').next('div').find('.thumb')
  284. if (nextThumb.length === 0) {
  285. nextThumb = $('.thumb:first')
  286. }
  287. switchImage(nextThumb)
  288. }
  289. function switchImage (thumb) {
  290. $('.thumb').removeClass('active')
  291. var bigUrl = thumb.attr('href')
  292. thumb.addClass('active')
  293. $('#mainImage img').attr('src', bigUrl)
  294. }
  295. }
  296. /* product detail sizes */
  297. function productDetailSizes () {
  298. $('.sizes a').click(function (e) {
  299. e.preventDefault()
  300. $('.sizes a').removeClass('active')
  301. $('.size-input').prop('checked', false)
  302. $(this).addClass('active')
  303. $(this).next('input').prop('checked', true)
  304. })
  305. }
  306. $.fn.alignElementsSameHeight = function () {
  307. $('.same-height-row').each(function () {
  308. var maxHeight = 0
  309. var children = $(this).find('.same-height')
  310. children.height('auto')
  311. if ($(window).width() > 768) {
  312. children.each(function () {
  313. if ($(this).innerHeight() > maxHeight) {
  314. maxHeight = $(this).innerHeight()
  315. }
  316. })
  317. children.innerHeight(maxHeight)
  318. }
  319. maxHeight = 0
  320. children = $(this).find('.same-height-always')
  321. children.height('auto')
  322. children.each(function () {
  323. if ($(this).height() > maxHeight) {
  324. maxHeight = $(this).innerHeight()
  325. }
  326. })
  327. children.innerHeight(maxHeight)
  328. })
  329. }
  330. var windowWidth
  331. $(function () {
  332. windowWidth = $(window).width()
  333. $(this).alignElementsSameHeight()
  334. pictureZoom()
  335. })
  336. $(window).resize(function () {
  337. var newWindowWidth = $(window).width()
  338. if (windowWidth !== newWindowWidth) {
  339. setTimeout(function () {
  340. $(this).alignElementsSameHeight()
  341. fullScreenContainer()
  342. pictureZoom()
  343. }, 205)
  344. windowWidth = newWindowWidth
  345. }
  346. });