front.js 9.8 KB

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