Created
September 21, 2018 14:00
-
-
Save nhtera/e7088d3d72ae404405b7cd8d8f4fdb6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function(){function a(){v=0==v?Object.keys(u)[1]:v;var a={};return $.each(document.location.search.substr(1).split("&"),function(t,i){var e=i.split("=");try{a[e[0].toString()]=e[1].toString()}catch(n){}}),isNaN(a.variant)?variant_id=$('[name="id"]').val():a.variant?variant_id=a.variant:variant_id=$("select option[value='"+v+"']").parent().val(),variant_id||v}function t(t){return t||(t=a()),variant_images=u.hasOwnProperty(t)?u[t]:u[v],variant_images?("at_start"==m?variant_images=u.g.concat(variant_images):"at_end"==m&&(variant_images=variant_images.concat(u.g)),variant_images):p}function i(a,t){return JSON.stringify(a)===JSON.stringify(t)}var e=!1,n=!1,r="Shoptimized",o=!1,d=!1,s={};if("/"!=window.location.pathname||"Startup"!=r&&"Flow"!=r){if(window.location.href.toLowerCase().indexOf("/products/")>=0)o=!0;else if(e)var l=setInterval(function(){window.$&&window.jQuery&&clearInterval(l)},10)}else o=!0,d=!0;if(o){if(d){if("Startup"==r)var c=$('[data-section-type="featured-product"] .product-title a').prop("href");else if("Flow"==r)c=$("#product-box .product-details--form-wrapper a").prop("href");c=c.replace(/\/$/,"")}else c=window.location.pathname.replace(/\/$/,"");if("undefined"==typeof via_product_handle||via_product_handle!=c){via_product_handle=c;var u={g:[]},p=[],v=0,m="at_end",_=new XMLHttpRequest;_.open("GET",c+".js",!0),_.send(),_.onreadystatechange=function(){var a=4,t=200;if(_.readyState===a&&_.status===t){var i=JSON.parse(_.responseText);for(var e in i.variants)if(!v&&i.variants[e].available)return v=i.variants[e].id,!1}};var f=new XMLHttpRequest;f.open("GET",c+".json",!0),f.send(),f.onreadystatechange=function(){var e=4,r=200;if(f.readyState===e&&f.status===r){var o=JSON.parse(f.responseText).product;p=o.images;var d=!0,l=[],c=[],v=[];o.variants.forEach(function(a){a.image_id&&(v[a.image_id]||(v[a.image_id]=[]),v[a.image_id].push(a.id))}),o.images.forEach(function(a,t){(assign_variant_ids=v[a.id],assign_variant_ids&&(a.variant_ids.push.apply(a.variant_ids,assign_variant_ids),a.variant_ids=a.variant_ids.filter(function(a,t,i){return i.indexOf(a)==t})),d&&0==a.variant_ids.length)?n&&0==t||u.g.push(a):(d=!1,(l=a.variant_ids.length?a.variant_ids:l).forEach(function(t){u[t]||(u[t]=[]),u[t].push(a)}),c.push(a))});var m=setInterval(function(){window.$&&window.jQuery&&(clearInterval(m),$(document).ready(function(){function e(a){if(variant_images=t(a),!i(s,variant_images)){s=variant_images,$(".bx-controls").remove(),$(".bx-wrapper").remove(),$(".product-single__thumbnails").remove();var e="",n="";$.each(variant_images,function(a,t){e+=$("#multi-variant-info li[data-image-id='"+t.id+"']").clone().find("a").attr("data-index-slide",a).closest("li").wrap("<div></div>").parent().html(),n+=$("#multi-variant-thumb li[data-image-id='"+t.id+"']").clone().find(".product-single__thumbnail").attr("data-slide-index",a).closest("li").wrap("<div></div>").parent().html()}),$(".product-single__photos").html('<ul class="bxslider" />'),$(".product-single__photos").after("<ul class='product-single__thumbnails bx-pager' />"),$(".product-single__photos .bxslider").html(e),$(".product-single__thumbnails").html(n),$(".product-single__photos .bxslider").bxSlider({pagerCustom:".product-single__thumbnails",infiniteLoop:!1,touchEnabled:!0,adaptiveHeight:!0}),$(".product-single__thumbnails").bxSlider({infiniteLoop:!1,slideWidth:80,slideMargin:10,minSlides:2,maxSlides:4,moveSlides:1}),$(window).width()>767?$(".product-single__photos .fancybox").fancybox():$(".fancybox").click(function(a){a.preventDefault()}),$(".product-single__thumbnail img").off("click").on("click",function(a){a.preventDefault();var t=$(this).data("ver"),i=o.id;if($("#productSelect--"+i+" option[data-image='"+t+"']").val()!==undefined&&$("#productSelect--"+i+" option[data-image='"+t+"']").attr("disabled")===undefined){var e=$("#productSelect--"+i+" option[data-image='"+t+"']").data("option1"),n=$("#productSelect--"+i+" option[data-image='"+t+"']").data("option2"),r=$("#productSelect--"+i+" option[data-image='"+t+"']").data("option3");""!==e&&$("#AddToCartForm--"+i).find("input[value='"+e+"']").attr("checked","true").change(),""!==n&&$("#AddToCartForm--"+i).find("input[value='"+n+"']").attr("checked","true").change(),""!==r&&$("#AddToCartForm--"+i).find("input[value='"+r+"']").attr("checked","true").change()}}),timber.magniflierImageZoom()}}$(".product-single__photos .bxslider li").each(function(a,t){$(t).attr("data-image-id",p[a].id),$(".product-single__thumbnails li").eq(a).attr("data-image-id",p[a].id)}),0==$("#multi-variant-info").length&&($("body").append("<div id='multi-variant-info' style='display:none'></div>"),$("body").append("<div id='multi-variant-thumb' style='display:none'></div>")),$("#multi-variant-info").html($(".product-single__photos .bxslider").html()),$("#multi-variant-thumb").html($(".product-single__thumbnails").html()),e();var n=0;$(document).on("change","select",function(){setTimeout(function(){variant_id=a(),n!=variant_id&&(e(variant_id),n=variant_id)},100)})}))},10)}}}}}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment