Skip to content

Instantly share code, notes, and snippets.

@prajwal-stha
Created January 15, 2018 05:00
Show Gist options
  • Select an option

  • Save prajwal-stha/2ca07c736cf1005dac2f375fc80711b6 to your computer and use it in GitHub Desktop.

Select an option

Save prajwal-stha/2ca07c736cf1005dac2f375fc80711b6 to your computer and use it in GitHub Desktop.
/*ECI:START: POST ATC Click: Recipe C */
var mobileCheck = function () {
var userAgent = false;
var mobileWidth = false;
if (navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
) {
userAgent = true;
}
else {
userAgent = false;
}
if(window.innerWidth <= 800 && window.innerHeight <= 600) {
mobileWidth = true;
} else {
mobileWidth = false;
}
return (userAgent || mobileWidth);
};
if(!mobileCheck()){
( function($){
var post_atc_click = {
// to load content from another page
eci_load_content: function(){
var obj = this;
var before = '<div class="eci-overlay-cart-popup" style = "display:none"><div class="eci-overlay"></div><div class="eci-recalculate-cart-wrap"><div class="eci-recalculate-cart-close"></div>';
var after = '</div></div>'
$('.eci-overlay-cart-popup').remove();
$.ajax({
type: 'GET',
url:'http://sandbox-corvettemods-com.3dcartstores.com/view_cart.asp',
success: function(data){
var mycart = $(data).find('.cart-area>a:first').html();
$('.cart-area>a:first').html(mycart);
var info = $(data).find('#recalculate').wrap('<p/>').parent().html();
$('.eci-overlay-cart-popup').remove();
var final = before + info + after;
console.log(final);
$('a[href = "checkout_one.asp"]').after(final);
obj.eci_implement_design();
},
});
},
// to implement design
eci_implement_design: function(){
$('#recalculate').addClass('eci-recalculate-cart');
$('.titles2 .item-info, .titles2 .item-qty, .titles2 .item-remove, .titles2 .item-price, .titles2 .item-total').remove();
$('.item-info').addClass('eci-product-item-cart-wrap');
$('.third-party-payment').remove();
$('.update-qty').remove();
$('.coupon_apply_row').remove();
$('.item-remove').remove();
$('.eci-product-item-cart-wrap').each(function(){
$(this).children('.product-name-options').append($(this).next('.item-qty'));
$(this).children('.product-name-options').after($(this).next('.item-total'));
})
$('.chk-buttons a .icon-left-open').remove();
$('.chk-buttons a').text('Keep Shopping');
$('.chk-buttons #vc_ChkButton').remove();
$('#divshoppingCartItems').before($('.titles2'));
$('.chk-buttons a').append("<a class='eci-btn-view-cart' href = 'http://sandbox-corvettemods-com.3dcartstores.com/view_cart.asp'>View Cart</a>");
$('#divshoppingCartItems').contents().filter(function(){
return this.nodeType == 3
}).remove()
$('#recalculate').contents().filter(function(){
return this.nodeType == 3
}).remove()
// to remove view/hidden option
$('a:contains("View/Hide options")').next('br').remove();
$('a:contains("View/Hide options")').prev('br').remove();
$('a:contains("View/Hide options")').remove();
//change text of subtotal
$('.shoppingCartTotal .item-price').text('Subtotal:');
$('.eci-overlay-cart-popup').show();
$('#divshoppingCartItems').after($('.shoppingCartTotal'))
$('.shoppingCartTotal .item-total:first').show();
$('.shoppingCartTotal .item-price:first').show();
if($('.shoppingCartTotal .item-price').length>1){
$('.chk-buttons').css('margin-top', '0');
}
if($('#divshoppingCartItems .row').length == 1){
$('#divshoppingCartItems').addClass('eci-removescroll')
}
if($('.chk-buttons > a').length > 1){
$('.chk-buttons > a:first').hide();
}
//to overcome mozilla repeated content
if($('.eci-your-item').length < 1){
$('.titles2').append('<div class="eci-your-item">YOUR ITEMS</div>');
$('#recalculate .txtBoxStyle').before('<span>QTY: </span>');
};
},
eci_trigger_event: function(){
var ob1 = this;
$('input#Add').click(function(){
if($('.option-required').length == 0 && $('.qtybox-addcart input.txtBoxStyle').val() >= 1){
//console.log('Check click');
setTimeout(function(){
ob1.eci_load_content();
},3000)
}
});
},
eci_change_structure: function(){
// $('#listing0').before('<iframe name="eciframe" id="eciframe" style="display: none;"></iframe>')
$('form#add').attr('target', 'eciframe');
$('.qtybox-addcart input.txtBoxStyle').after('<input type="submit" id="Add" class="btn" value="Add To Cart" onclick="check_and_add(document.add);">');
// $('button#Add').hide();
// $('.relatedBlock .action input.btn').hide();
},
eci_cart_status: function(){
$(document).click(function(){
$('.eci-overlay-cart-popup').remove();
});
$('.cart-area').on('click','.eci-recalculate-cart-close', function(event){
$('.eci-overlay-cart-popup').remove();
});
$('.cart-area').on('click','.eci-recalculate-cart-wrap', function(event){
event.stopPropagation();
});
},
eci_change_related_atc: function(){
$('.relatedBlock .action input.btn').each(function(i){
var atcurl = $(this).attr('onclick');
var atcid = atcurl.split('item_id=');
var reatcid = atcid[1].replace("'","");
$(this).after('<div class = "eci-related-atc" id = "'+ reatcid +'">Add To Cart</div>')
});
},
//trigger change
eci_relatc_click: function(){
var obj = this;
var before = '<div class="eci-overlay-cart-popup" style = "display:none"><div class="eci-overlay"></div><div class="eci-recalculate-cart-wrap"><div class="eci-recalculate-cart-close"></div>';
var after = '</div></div>'
$('.relatedBlock').on('click','.eci-related-atc', function(event){
event.stopPropagation();
var atcurl = $(this).attr('id')
var ajaxurl = "http://sandbox-corvettemods-com.3dcartstores.com/add_cart.asp?quick=1&item_id=" + atcurl;
$.ajax({
type: 'GET',
url: ajaxurl,
success: function(data,ts,xhr){
if(xhr.responseText == ''){
window.location = ajaxurl;
}else{
var mycart = $(data).find('.cart-area>a:first').html();
$('.cart-area>a:first').html(mycart);
var info = $(data).find('#recalculate').wrap('<p>').parent().html();
$('.eci-overlay-cart-popup').remove();
$('a[href = "checkout_one.asp"]').after(before + info + after);
}
},
complete: function(){
console.log(obj);
obj.eci_implement_design();
},
});
});
},
eci_init: function(){
var ob = this;
ob.eci_change_structure();
ob.eci_trigger_event();
ob.eci_cart_status();
ob.eci_relatc_click();
ob.eci_change_related_atc();
}
}.eci_init();
})(jQuery);
}
/*ECI:END: POST ATC Click: Recipe C */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment