front.js 10 KB

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