front.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. }
  121. }
  122. /* menu sliding */
  123. function menuSliding () {
  124. $('.dropdown').on('show.bs.dropdown', function () {
  125. if ($(window).width() > 750) {
  126. $(this).find('.dropdown-menu').first().stop(true, true).slideDown()
  127. } else {
  128. $(this).find('.dropdown-menu').first().stop(true, true).show()
  129. }
  130. })
  131. $('.dropdown').on('hide.bs.dropdown', function () {
  132. if ($(window).width() > 750) {
  133. $(this).find('.dropdown-menu').first().stop(true, true).slideUp()
  134. } else {
  135. $(this).find('.dropdown-menu').first().stop(true, true).hide()
  136. }
  137. })
  138. }
  139. /* animations */
  140. function animations () {
  141. var delayTime = 0
  142. $('[data-animate]').css({opacity: '0'})
  143. $('[data-animate]').waypoint(function () {
  144. delayTime += 150
  145. $(this).delay(delayTime).queue(function (next) {
  146. $(this).toggleClass('animated')
  147. $(this).toggleClass($(this).data('animate'))
  148. delayTime = 0
  149. next()
  150. // $(this).removeClass('animated')
  151. // $(this).toggleClass($(this).data('animate'))
  152. })
  153. }, {
  154. offset: '90%',
  155. triggerOnce: true
  156. })
  157. $('[data-animate-hover]').hover(function () {
  158. $(this).css({opacity: 1})
  159. $(this).addClass('animated')
  160. $(this).removeClass($(this).data('animate'))
  161. $(this).addClass($(this).data('animate-hover'))
  162. }, function () {
  163. $(this).removeClass('animated')
  164. $(this).removeClass($(this).data('animate-hover'))
  165. })
  166. }
  167. function animationsSlider () {
  168. var delayTimeSlider = 400
  169. $('.owl-item:not(.active) [data-animate-always]').each(function () {
  170. $(this).removeClass('animated')
  171. $(this).removeClass($(this).data('animate-always'))
  172. $(this).stop(true, true, true).css({opacity: 0})
  173. })
  174. $('.owl-item.active [data-animate-always]').each(function () {
  175. delayTimeSlider += 500
  176. $(this).delay(delayTimeSlider).queue(function () {
  177. $(this).addClass('animated')
  178. $(this).addClass($(this).data('animate-always'))
  179. console.log($(this).data('animate-always'))
  180. })
  181. })
  182. }
  183. /* counters */
  184. function counters () {
  185. $('.counter').counterUp({
  186. delay: 10,
  187. time: 1000
  188. })
  189. }
  190. /* picture zoom */
  191. function pictureZoom () {
  192. $('.product .image, .post .image, .photostream div').each(function () {
  193. var imgHeight = $(this).find('img').height()
  194. if (imgHeight) {
  195. $(this).height(imgHeight)
  196. }
  197. })
  198. }
  199. /* full screen intro */
  200. function fullScreenContainer () {
  201. var screenWidth = $(window).width() + 'px'
  202. var screenHeight = '500px'
  203. if ($(window).height() > 500) {
  204. screenHeight = $(window).height() + 'px'
  205. }
  206. $('#intro, #intro .item').css({
  207. width: screenWidth,
  208. height: screenHeight
  209. })
  210. }
  211. function utils () {
  212. /* tooltips */
  213. $('[data-toggle="tooltip"]').tooltip()
  214. /* click on the box activates the radio */
  215. $('#checkout').on('click', '.box.shipping-method, .box.payment-method', function () {
  216. var radio = $(this).find(':radio')
  217. radio.prop('checked', true)
  218. })
  219. /* click on the box activates the link in it */
  220. $('.box.clickable').on('click', function () {
  221. window.location = $(this).find('a').attr('href')
  222. })
  223. /* external links in new window */
  224. $('.external').on('click', function (e) {
  225. e.preventDefault()
  226. window.open($(this).attr('href'))
  227. })
  228. /* animated scrolling */
  229. $('.scroll-to, .scroll-to-top').click(function (event) {
  230. var fullUrl = this.href
  231. var parts = fullUrl.split('#')
  232. if (parts.length > 1) {
  233. scrollTo(fullUrl)
  234. event.preventDefault()
  235. }
  236. })
  237. function scrollTo (fullUrl) {
  238. var parts = fullUrl.split('#')
  239. var trgt = parts[1]
  240. var targetOffset = $('#' + trgt).offset()
  241. var targetTop = targetOffset.top - 100
  242. if (targetTop < 0) {
  243. targetTop = 0
  244. }
  245. $('html, body').animate({
  246. scrollTop: targetTop
  247. }, 1000)
  248. }
  249. }
  250. /* product detail gallery */
  251. function productDetailGallery (confDetailSwitch) {
  252. $('.thumb:first').addClass('active')
  253. var timer = setInterval(autoSwitch, confDetailSwitch)
  254. $('.thumb').click(function (e) {
  255. switchImage($(this))
  256. clearInterval(timer)
  257. timer = setInterval(autoSwitch, confDetailSwitch)
  258. e.preventDefault()
  259. })
  260. $('#mainImage').hover(function () {
  261. clearInterval(timer)
  262. }, function () {
  263. timer = setInterval(autoSwitch, confDetailSwitch)
  264. })
  265. function autoSwitch () {
  266. var nextThumb = $('.thumb.active').closest('div').next('div').find('.thumb')
  267. if (nextThumb.length === 0) {
  268. nextThumb = $('.thumb:first')
  269. }
  270. switchImage(nextThumb)
  271. }
  272. function switchImage (thumb) {
  273. $('.thumb').removeClass('active')
  274. var bigUrl = thumb.attr('href')
  275. thumb.addClass('active')
  276. $('#mainImage img').attr('src', bigUrl)
  277. }
  278. }
  279. /* product detail sizes */
  280. function productDetailSizes () {
  281. $('.sizes a').click(function (e) {
  282. e.preventDefault()
  283. $('.sizes a').removeClass('active')
  284. $('.size-input').prop('checked', false)
  285. $(this).addClass('active')
  286. $(this).next('input').prop('checked', true)
  287. })
  288. }
  289. $.fn.alignElementsSameHeight = function () {
  290. $('.same-height-row').each(function () {
  291. var maxHeight = 0
  292. var children = $(this).find('.same-height')
  293. children.height('auto')
  294. if ($(window).width() > 768) {
  295. children.each(function () {
  296. if ($(this).innerHeight() > maxHeight) {
  297. maxHeight = $(this).innerHeight()
  298. }
  299. })
  300. children.innerHeight(maxHeight)
  301. }
  302. maxHeight = 0
  303. children = $(this).find('.same-height-always')
  304. children.height('auto')
  305. children.each(function () {
  306. if ($(this).height() > maxHeight) {
  307. maxHeight = $(this).innerHeight()
  308. }
  309. })
  310. children.innerHeight(maxHeight)
  311. })
  312. }
  313. var windowWidth
  314. $(function () {
  315. windowWidth = $(window).width()
  316. $(this).alignElementsSameHeight()
  317. pictureZoom()
  318. })
  319. $(window).resize(function () {
  320. var newWindowWidth = $(window).width()
  321. if (windowWidth !== newWindowWidth) {
  322. setTimeout(function () {
  323. $(this).alignElementsSameHeight()
  324. fullScreenContainer()
  325. pictureZoom()
  326. }, 205)
  327. windowWidth = newWindowWidth
  328. }
  329. })