Skip to content

Instantly share code, notes, and snippets.

@daksamedia
Created March 27, 2019 10:45
Show Gist options
  • Save daksamedia/1390cb18ba635224761b856fbd8e3aef to your computer and use it in GitHub Desktop.
Save daksamedia/1390cb18ba635224761b856fbd8e3aef to your computer and use it in GitHub Desktop.
bljkpjs_new
function getdata(index,itemArr,cat,type){
$.ajax({
url:url,
method:'POST',
data : "itemIds="+itemArr,
success:function(res){
var food1 = eval(res);
if(type=="NORMAL" || type==undefined){
for(var i=0;i < food1.length;i++){
//console.log(food1[i].id)
//$(".nama_orang").append("<li>"+ damn[i].title +"</li>")
$("."+cat).append('<div class="product-shortcode style-1 big col-md-15" data-tag="'+ cat +'" itemid="'+ food1[i].id +'" data-stock="'+ food1[i].qtyStatus +'"><a href="'+ food1[i].linkUrl +'">'+
'<div class="box">'+
'<div class="preview">'+
'<input type="hidden" class="kpItemId" value="'+ food1[i].id +'">'+
'<img class="lazyload img-responsive" src="https://s2.blanja.com/static/public/images/loading.gif" data-original="https:'+ food1[i].image +'?w=230" data-real="'+ food1[i].image +'">'+
'<span class="limitedtime" data-countdown="'+ food1[i].countdown +'"><span class="hours"></span>:<span class="minutes"></span>:<span class="seconds"></span></span>'+
'</div>'+
'<div class="title">'+
'<h2>'+ food1[i].title +'</h2>'+
'</div>'+
'<div class="product-price">'+
'<div class="coret">Rp '+ food1[i].price +'</div>'+
'<span class="product-price-sale">Rp '+ food1[i].salePrice +'</span>'+
'<span class="diskon product-price-discount">'+ food1[i].ribbon +'%</span>'+
'<div style="clear:both;"></div><div class="star-rating"><span class="stars" data-rating="'+ food1[i].score +'" style="width:'+ food1[i].score*20 +'%;"></span></div>'+
'<div class="sisaProduk">' + food1[i].quantity + ' produk tersisa</div><div style="clear:both;">'+
'</div>'+
'</div>'+
'</a></div>');
$(".all").append('<div class="product-shortcode style-1 big col-md-15" data-tag="'+ cat +'" itemid="'+ food1[i].id +'" data-stock="'+ food1[i].qtyStatus +'"><a href="'+ food1[i].linkUrl +'">'+
'<div class="box">'+
'<div class="preview">'+
'<input type="hidden" class="kpItemId" value="'+ food1[i].id +'">'+
'<img class="lazyload img-responsive" src="https://s2.blanja.com/static/public/images/loading.gif" data-original="https:'+ food1[i].image +'?w=230" data-real="'+ food1[i].image +'">'+
'<span class="limitedtime" data-countdown="'+ food1[i].countdown +'"><span class="hours"></span>:<span class="minutes"></span>:<span class="seconds"></span></span>'+
'</div>'+
'<div class="title">'+
'<h2>'+ food1[i].title +'</h2>'+
'</div>'+
'<div class="product-price">'+
'<div class="coret">Rp '+ food1[i].price +'</div>'+
'<span class="product-price-sale">Rp '+ food1[i].salePrice +'</span>'+
'<span class="diskon product-price-discount">'+ food1[i].ribbon +'%</span>'+
'<div style="clear:both;"></div><div class="star-rating"><span class="stars" data-rating="'+ food1[i].score +'" style="width:'+ food1[i].score*20 +'%;"></span></div>'+
'<div class="sisaProduk">' + food1[i].quantity + ' produk tersisa</div><div style="clear:both;">'+
'</div>'+
'</div>'+
'</a></div>');
}
}else{
for(var i=0;i < food1.length;i++){
$("."+cat).find(".swiper-wrapper").append('<div data-idx="'+ index +'" class="swiper-slide prod">'+
'<div class="col-md-12 no-padding" data-tag="'+ cat +'" itemid="'+food1[i].id+'"><a href="'+ food1[i].linkUrl +'" data-stock="'+ food1[i].qtyStatus +'">'+
'<div class="box-swipper">'+
'<div class="preview">'+
'<input type="hidden" class="kpItemId" value="'+ food1[i].id +'">'+
'<img class="swiper-lazy img-responsive" src="https://s2.blanja.com/static/public/images/loading.gif" data-src="https:'+ food1[i].image +'?w=230" data-original="https:'+ food1[i].image +'?w=230" data-real="'+ food1[i].image +'">'+
'<span class="limitedtime" data-countdown="'+ food1[i].countdown +'"><span class="hours"></span>:<span class="minutes"></span>:<span class="seconds"></span></span>'+
'</div>'+
'<div class="title">'+
'<h2>'+ food1[i].title +'</h2>'+
'</div>'+
'<div class="product-price">'+
'<div class="coret">Rp '+ food1[i].price +'</div>'+
'<span class="product-price-sale">Rp '+ food1[i].salePrice +'</span>'+
'<span class="diskon product-price-discount">'+ food1[i].ribbon +'%</span>'+
'<div style="clear:both;"></div><div class="star-rating"><span class="stars" data-rating="'+ food1[i].score +'" style="width:'+ food1[i].score*20 +'%;"></span></div>'+
'<div class="sisaProduk">' + food1[i].quantity + ' produk tersisa</div><div style="clear:both;">'+
'</div>'+
'</div>'+
'</a></div>'+
'</div>');
//$.getScript('',function(){
swiper_prods[i] = new Swiper('.'+cat,{
slidesPerView:5,
loop:false,
navigation: {
nextEl: '.next-btn'+ index +'',
prevEl: '.prev-btn'+ index +'',
},
preloadImages:false,
spaceBetween:10,
lazy: true
})
//})
}
}
},
error:function(err){
$(".nama_orang").html("error cuy")
},
complete:function(res){
$(".product-shortcode, .swiper-slide.prod").each(function(){
var data_countdown = $(this).find(".limitedtime").data("countdown");
var this_countdown = $(this).find(".limitedtime")
var this_stock = $(this).data("stock")
if($(this).find(".diskon").html()=="undefined%"){
$(this).find(".diskon").hide()
}
if($(this).find(".coret").html()=="Rp 0"){
$(this).find(".coret").css("opacity","0")
}
if(this_stock == 0){
$(this).remove()
}
if(!data_countdown){
$(this).find(".limitedtime").hide()
}else{
countdownFun(this_countdown,data_countdown)
}
var bintang = $(this).find('.stars').data('rating');
//console.log(bintang)
if(bintang < 0.1){
$(this).find('.stars').parent().css("display","none");
$(this).find('.sisaProduk').css("float","left");
}
var this_img = $(this).find(".img-responsive")
var src_img = this_img.attr("data-original");
var real_img = this_img.attr("data-real");
if (src_img.indexOf("tokopedia") !== -1) {
this_img.attr("data-original", ""+real_img);
this_img.attr("src", ""+real_img);
}
});
$('.img-responsive').lazyload({});
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment