Back

Template Source: bdgenerix/snippets/_spec_scripts.html

<script type="text/javascript"> var sidebar_container_pos = 130; function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(name)==0) return c.substring(name.length,c.length); } return ""; } function setCookie(cname,cvalue,exdays,path) { var d = new Date(); d.setTime(d.getTime()+(exdays*24*60*60*1000)); var expires = "expires="+d.toGMTString(); document.cookie = cname + "=" + cvalue + (path==null? "" : ("; path=" + path)) + "; " + expires; } form_add_to_cart = document.getElementById("product-form"); if(form_add_to_cart != null ){ form_add_to_cart.onsubmit = function(event){ cur_time = new Date().getTime(); cookie_key_cart = "last_add_to_cart"; last_time = getCookie(cookie_key_cart); if(last_time != ""){ seconds_elapsed = (parseInt(cur_time) - parseInt(last_time))/1000; if(seconds_elapsed <= 3){ alert("You are clicking too fast! Please slow down!"); return false; } else{ setCookie(cookie_key_cart, cur_time, 1); } } else{ setCookie(cookie_key_cart, cur_time, 1); } }; } /* Switch between 3 prducts and 4 products per row */ cookie_key_cols = "selected_cols"; function product_list_layout_changer_init(){ // Init cols layout according to cookies var selected_cols = getCookie(cookie_key_cols); if(selected_cols == ""){ selected_cols = "cols-3"; } $("#layout-cols-3").removeClass("active"); $("#layout-cols-4").removeClass("active"); $("#product-list-container").removeClass("cols-3"); $("#product-list-container").removeClass("cols-4"); $("#layout-" + selected_cols).addClass("active"); $("#product-list-container").addClass(selected_cols); $("#layout-cols-3").click(function(){ $("#layout-cols-4").removeClass("active"); $(this).addClass("active"); $("#product-list-container").removeClass("cols-4"); $("#product-list-container").addClass("cols-3"); $('body,html').scroll(); // triger lazyload image to show // put your selection into cookies setCookie(cookie_key_cols, "cols-3", 1, "/"); }); $("#layout-cols-4").click(function(){ $("#layout-cols-3").removeClass("active"); $(this).addClass("active"); $("#product-list-container").removeClass("cols-3"); $("#product-list-container").addClass("cols-4"); $('body,html').scroll(); // triger lazyload image to show // put your selection into cookies setCookie(cookie_key_cols, "cols-4", 1, "/"); }); } // Scroll images on sidebar right, recently viewed product cur_step_view_history = 0; function scroll_history_product_image(step, $container){ scroll_items = $(".view-history-container .scroll .item"); view_history_items_height = parseInt(scroll_items.css("height") ); view_history_items_length= parseInt(scroll_items.length ); scroll_length = view_history_items_height * view_history_items_length; scroll_height = parseInt($(".view-history-container .scroll").css("height") ); max_step_view_history = scroll_length / scroll_height; if(cur_step_view_history + step >= 0 && cur_step_view_history + step < max_step_view_history){ cur_step_view_history += step; $moving_scroll = $(".moving-scroll", $container); scroll_margin = parseInt(scroll_items.css("margin-top") ); var margin_top = -1 * cur_step_view_history * scroll_height + (scroll_margin*cur_step_view_history); $moving_scroll.stop().animate({"margin-top": margin_top + "px"},1000); } } $(document).ready(function(){ product_list_layout_changer_init(); // Recently viewed products $(".btn-view-history").click(function(){ right = parseInt($(".sidebar-right .container").css("right")); $(".sidebar-right .container").stop().animate({"right": -(100+right) + "px"}, 500); }); // Recently viewed products scroll $(".view-history-container .scroll-down").click(function(){ scroll_history_product_image(1, $(".view-history-container .scroll")); }); $(".view-history-container .scroll-up").click(function(){ scroll_history_product_image(-1, $(".view-history-container .scroll")); }); }); </script>