custom.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. $(window).scroll(function() {
  2. if ($(window).scrollTop() >= 41) {
  3. $('body').addClass('header-fixed');
  4. } else {
  5. $('body').removeClass('header-fixed');
  6. }
  7. });
  8. //mobile touch
  9. $(document).ready(function($) {
  10. $(".carousel").carousel();
  11. });
  12. $(document).ready(function($) {
  13. // browser window scroll (in pixels) after which the "back to top" link is shown
  14. var offset = 300,
  15. //browser window scroll (in pixels) after which the "back to top" link opacity is reduced
  16. offset_opacity = 1200,
  17. //duration of the top scrolling animation (in ms)
  18. scroll_top_duration = 700,
  19. //grab the "back to top" link
  20. $back_to_top = $('.cd-top');
  21. //hide or show the "back to top" link
  22. $(window).scroll(function() {
  23. ($(this).scrollTop() > offset) ? $back_to_top.addClass('cd-is-visible'): $back_to_top.removeClass('cd-is-visible cd-fade-out');
  24. if ($(this).scrollTop() > offset_opacity) {
  25. $back_to_top.addClass('cd-fade-out');
  26. }
  27. });
  28. //smooth scroll to top
  29. $back_to_top.on('click', function(event) {
  30. event.preventDefault();
  31. $('body,html').animate({
  32. scrollTop: 0,
  33. }, scroll_top_duration);
  34. });
  35. // Multi image gallery
  36. openerp.jsonRpc('/kingfisher_pro/multi_image_effect_config', 'call', {})
  37. .done(function(res) {
  38. var dynamic_data = {}
  39. dynamic_data['gallery_images_preload_type'] = 'all'
  40. dynamic_data['slider_enable_text_panel'] = false
  41. dynamic_data['gallery_skin'] = "alexis"
  42. dynamic_data['gallery_height'] = 800
  43. if (res.theme_panel_position != false) {
  44. dynamic_data['theme_panel_position'] = res.theme_panel_position
  45. }
  46. if (res.interval_play != false) {
  47. dynamic_data['gallery_play_interval'] = res.interval_play
  48. }
  49. if (res.color_opt_thumbnail != false && res.color_opt_thumbnail != 'default') {
  50. dynamic_data['thumb_image_overlay_effect'] = true
  51. if (res.color_opt_thumbnail == 'b_n_w') {}
  52. if (res.color_opt_thumbnail == 'blur') {
  53. dynamic_data['thumb_image_overlay_type'] = "blur"
  54. }
  55. if (res.color_opt_thumbnail == 'sepia') {
  56. dynamic_data['thumb_image_overlay_type'] = "sepia"
  57. }
  58. }
  59. if (res.enable_disable_text == true) {
  60. dynamic_data['slider_enable_text_panel'] = true
  61. }
  62. if (res.change_thumbnail_size == true) {
  63. dynamic_data['thumb_height'] = res.thumb_height
  64. dynamic_data['thumb_width'] = res.thumb_width
  65. }
  66. if (res.no_extra_options == false) {
  67. dynamic_data['slider_enable_arrows'] = false
  68. dynamic_data['slider_enable_progress_indicator'] = false
  69. dynamic_data['slider_enable_play_button'] = false
  70. dynamic_data['slider_enable_fullscreen_button'] = false
  71. dynamic_data['slider_enable_zoom_panel'] = false
  72. dynamic_data['slider_enable_text_panel'] = false
  73. dynamic_data['strippanel_enable_handle'] = false
  74. dynamic_data['gridpanel_enable_handle'] = false
  75. dynamic_data['theme_panel_position'] = 'bottom'
  76. dynamic_data['thumb_image_overlay_effect'] = false
  77. }
  78. $('#gallery').unitegallery(
  79. dynamic_data
  80. );
  81. });
  82. $('div#recommended_products_slider').owlCarousel({
  83. margin: 10,
  84. responsiveClass: true,
  85. items: 4,
  86. loop: true,
  87. autoPlay: 7000,
  88. stopOnHover: true,
  89. navigation: true,
  90. responsive: {
  91. 0: {
  92. items: 1,
  93. nav: false
  94. },
  95. 500: {
  96. items: 2,
  97. nav: false
  98. },
  99. 700: {
  100. items: 3,
  101. margin: 10,
  102. nav: false
  103. },
  104. 1000: {
  105. items: 4,
  106. nav: false,
  107. loop: false
  108. },
  109. 1500: {
  110. items: 4,
  111. nav: false,
  112. loop: false
  113. }
  114. }
  115. });
  116. // Grid/List switching code
  117. $(".oe_website_sale .shift_list_view").click(function(e) {
  118. $(".oe_website_sale .shift_grid_view").removeClass('active')
  119. $(this).addClass('active')
  120. $('#products_grid').addClass("list-view-box");
  121. localStorage.setItem("product_view", "list");
  122. });
  123. $(".oe_website_sale .shift_grid_view").click(function(e) {
  124. $(".oe_website_sale .shift_list_view").removeClass('active')
  125. $(this).addClass('active')
  126. $('#products_grid').removeClass("list-view-box");
  127. localStorage.setItem("product_view", "grid");
  128. });
  129. if (localStorage.getItem("product_view") == 'list') {
  130. $(".oe_website_sale .shift_grid_view").removeClass('active')
  131. $(".oe_website_sale .shift_list_view").addClass('active')
  132. $('#products_grid').addClass("list-view-box");
  133. }
  134. if (localStorage.getItem("product_view") == 'grid') {
  135. $(".oe_website_sale .shift_list_view").removeClass('active')
  136. $(".oe_website_sale .shift_grid_view").addClass('active')
  137. $('#products_grid').removeClass("list-view-box");
  138. }
  139. // Grid/List switching code ends
  140. // Price slider code start
  141. var minval = $("input#m1").attr('value'),
  142. maxval = $('input#m2').attr('value'),
  143. minrange = $('input#ra1').attr('value'),
  144. maxrange = $('input#ra2').attr('value'),
  145. website_currency = $('input#king_pro_website_currency').attr('value');
  146. if (!minval) {
  147. minval = 0;
  148. }
  149. if (!maxval) {
  150. maxval = maxrange;
  151. }
  152. if (!minrange) {
  153. minrange = 0;
  154. }
  155. if (!maxrange) {
  156. maxrange = 2000;
  157. }
  158. $("div#priceslider").ionRangeSlider({
  159. keyboard: true,
  160. min: parseInt(minrange),
  161. max: parseInt(maxrange),
  162. type: 'double',
  163. from: minval,
  164. to: maxval,
  165. step: 1,
  166. prefix: website_currency,
  167. grid: true,
  168. onFinish: function(data) {
  169. $("input[name='min1']").attr('value', parseInt(data.from));
  170. $("input[name='max1']").attr('value', parseInt(data.to));
  171. $("div#priceslider").closest("form").submit();
  172. },
  173. });
  174. // Price slider code ends
  175. //attribute remove code
  176. $("a#clear").on('click', function() {
  177. var url = window.location.href.split("?");
  178. var lival;
  179. lival = $(this).closest("label").attr('id');
  180. openerp.jsonRpc("/kingfisher_pro/removeattribute", 'call', {
  181. 'attr_remove': lival
  182. }).then(function(data) {
  183. if (data = true) {
  184. window.location.href = url[0];
  185. }
  186. })
  187. });
  188. // Category Collapse
  189. $('#o_shop_collapse_category').on('click', '.fa-chevron-right', function() {
  190. $(this).parent().siblings().find('.fa-chevron-down:first').click();
  191. $(this).parents('li').find('ul:first').show('normal');
  192. $(this).toggleClass('fa-chevron-down fa-chevron-right');
  193. });
  194. $('#o_shop_collapse_category').on('click', '.fa-chevron-down', function() {
  195. $(this).parent().find('ul:first').hide('normal');
  196. $(this).toggleClass('fa-chevron-down fa-chevron-right');
  197. });
  198. // Dynamic cart update
  199. $('.oe_website_sale').each(function() {
  200. var oe_website_sale = this;
  201. $(oe_website_sale).find(".oe_cart input.js_quantity").on("change", function() {
  202. var $input = $(this);
  203. if ($input.data('update_change')) {
  204. return;
  205. }
  206. var value = parseInt($input.val(), 10);
  207. var $dom = $(this).closest('tr');
  208. // var default_price = parseFloat($dom.find('.text-danger > span.oe_currency_value').text());
  209. var $dom_optional = $dom.nextUntil(':not(.optional_product.info)');
  210. var line_id = parseInt($input.data('line-id'), 10);
  211. var product_id = parseInt($input.data('product-id'), 10);
  212. var product_ids = [product_id];
  213. $dom_optional.each(function() {
  214. product_ids.push($(this).find('span[data-product-id]').data('product-id'));
  215. });
  216. if (isNaN(value)) value = 0;
  217. $input.data('update_change', true);
  218. openerp.jsonRpc("/shop/get_unit_price", 'call', {
  219. 'product_ids': product_ids,
  220. 'add_qty': value,
  221. 'use_order_pricelist': true
  222. }).then(function(res) {
  223. //optional case
  224. openerp.jsonRpc("/shop/cart/update_json", 'call', {
  225. 'line_id': line_id,
  226. 'product_id': parseInt($input.data('product-id'), 10),
  227. 'set_qty': value
  228. }).then(function(data) {
  229. $input.data('update_change', false);
  230. if (value !== parseInt($input.val(), 10)) {
  231. $input.trigger('change');
  232. return;
  233. }
  234. if (!data.quantity) {
  235. location.reload(true);
  236. return;
  237. }
  238. var $q = $(".king_pro_cart_quantity");
  239. $q.parent().parent().removeClass("hidden", !data.quantity);
  240. $q.html(data.cart_quantity).hide().fadeIn(600);
  241. $input.val(data.quantity);
  242. $('.js_quantity[data-line-id=' + line_id + ']').val(data.quantity).html(data.quantity);
  243. $("table#cart_total").replaceWith(data['website_sale.total']);
  244. $("#king_hover_total").replaceWith(data['kingfisher_pro.hover_total']);
  245. });
  246. });
  247. });
  248. });
  249. // Switched to review section
  250. $('p.review').click(function() {
  251. $('body').animate({
  252. scrollTop: $(this).offset().top
  253. }, 1800);
  254. $('ul#description_reviews_tabs > li').removeClass('active')
  255. $('div#description_reviews_tabs_contents > div').removeClass('active')
  256. $('ul#description_reviews_tabs > li:nth-child(2)').addClass('active')
  257. $('div#description_reviews_tabs_contents > div:nth-child(2)').addClass('active')
  258. });
  259. // Toggle global search
  260. $('.st-toggle').on('click', function(e) {
  261. $('.search-toggle').toggleClass("search-toggle-open");
  262. });
  263. });
  264. // For Megamenu
  265. $(document).on('click', '.mega-dropdown-menu', function(e) {
  266. e.stopPropagation()
  267. });
  268. //Equal height
  269. $(window).load(function() {
  270. equal_height_all();
  271. });
  272. function equal_height_all() {
  273. function resetHeight() {
  274. var maxHeight = 0;
  275. jQuery(".cs-product .pwp-info .pwpi-title").height("auto").each(function() {
  276. maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
  277. }).height(maxHeight);
  278. }
  279. resetHeight();
  280. jQuery(window).resize(function() {
  281. resetHeight();
  282. });
  283. }
  284. $(document).ready(function() {
  285. $(".li-mega-menu > a .fa").click(function() {
  286. $(".li-mega-menu").toggleClass("open");
  287. });
  288. });
  289. (function(d, s, id) {
  290. var js, fjs = d.getElementsByTagName(s)[0];
  291. if (d.getElementById(id)) return;
  292. js = d.createElement(s); js.id = id;
  293. js.src = "//connect.facebook.net/es_ES/sdk.js#xfbml=1&version=v2.8&appId=1511113442515741";
  294. fjs.parentNode.insertBefore(js, fjs);
  295. }(document, 'script', 'facebook-jssdk'));