front.js 10 KB

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