Rev 14300 | Rev 14345 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
$(function(){if($('.scroll > .card').length>0) {setTimeout(function(){ document.location.reload(); }, 1000*60*35);$('.scroll').jscroll({loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',autoTriggerUntil: 3,padding: 20,});}if($('.storeminprice').length>0) {var globalminprice = 9999999;var globalminsku;$('.storeminprice').each(function(){var inStock = false;var that = $(this);$.ajax({url: '/store_products/getliveprice/'+$(this).data('bundle_id')+'/'+$(this).data('id'),// Tell jQuery we're expecting JSONPdataType: "json",// Tell YQL what we want and that we want JSONmethod: 'get',// Work with the responsesuccess: function( response ) {if(response.success){var i = 0;var minpriceindex = 0;if(response.products[i].in_stock == 1){inStock = true;}var minprice = response.products[0]['available_price'];var minpriceurl = response.products[0]['marketPlaceUrl'];if(response.products.length>0){//More than one products in storevar variants = [];// var i = 0;for(var i in response.products){if(response.products[i].in_stock == 1){inStock = true;}console.log(response.products[i]);if(response.products[i].available_price && response.products[i].available_price < globalminprice) {globalminprice = response.products[i].available_price;globalminsku = response.products[i]._id;}if(response.products[i].available_price <= minprice) {minprice = response.products[i].available_price;minpriceindex = i;}console.log(response);variants.push({'available_price' : response.products[i].available_price, 'url' : response.products[i].marketPlaceUrl,'source_product_name' : response.products[i].source_product_name,'id' : response.products[i]._id});}if(i>0){var variantslink = $('<span class="variants">+ '+i+' Options</span>');$(that).parent().append(variantslink);$(variantslink).data('variants',variants)}}if(inStock){$(that).html(minprice);$('#sku-'+$(that).data('id')).data('id',response.products[minpriceindex]['_id']).removeClass('hidden');console.log(globalminprice+' '+globalminsku);if(globalminprice != 9999999) {$('#bestprice').html(globalminprice);$('#beststorelink').data('id',globalminsku).removeClass('hidden');$('#bestpricecontainer').removeClass('hidden');}}else{$(that).parent().parent().remove();}if(!response.products[0].available_price){$(that).parent().parent().remove();}}else{$(that).parent().parent().remove();}},error : function() {$(that).parent().parent().remove();}});});}$(document).on('click','.variants',function(){$('.storeproductinfo').empty();var variants = $(this).data('variants');$('#variantscount').html(variants.length);for(var i in variants){console.log(variants[i]);var row = $('<div class="row storeproductinfo"><div class="col-xs-7">'+variants[i].source_product_name+'</div><div class="col-xs-3">'+variants[i].available_price+'</div><div class="col-xs-2"><button class="btn btn-primary btn-xs viewproduct" type="button" data-id="'+variants[i].id+'">Buy</button></div></div>');$('#storeproducts').parent().append(row);}// console.log($(this).parent());$('#storename').html($(this).parent().data('storename'));$('#variantModal').modal();});$('.categorytab').on('click','.categorytabcontrol.active',function(){$(this).toggleClass('active');$('#preferences-'+$(this).data('id')).addClass('hidden');$(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');});$('.categorytab').on('click','.categorytabcontrol:not(.active)',function(){$(this).parent().parent().find('.btn',0).click();});$('.categorytab').on('click','.editcategorypreferences',function(e){var that = $(this);$(that).removeClass('editcategorypreferences').addClass('savecategorypreferences').html('Done').addClass('btn-success');$('#togglepreferences-'+$(that).data('id')).toggleClass('active');$('#preferences-'+$(that).data('id')).removeClass('hidden');$('.brandselector').each(function(){if($(this).data('catid')==$(that).data('id')){$(this).addClass('active');}});});$('.categorytab').on('click','.savecategorypreferences',function(e){var that = $(this);$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');$('#togglepreferences-'+$(that).data('id')).toggleClass('active');$.ajax({url: $('#categorypreference-'+$(that).data('id')).attr('action'),data: $('#categorypreference-'+$(that).data('id')).serialize(),// Tell jQuery we're expecting JSONPdataType: "json",// Tell YQL what we want and that we want JSONmethod: 'post',// Work with the responsesuccess: function( response ) {if(response.success){$('#preferences-'+$(that).data('id')).addClass('hidden');}}});ga('send', 'event', 'preferences', 'update', me);});// $('.row').on('click','.viewproduct',function(e){$(document).on('click','.viewproduct',function(e){$('#loadingModal').modal();console.log($(this).data('id'));var url = apihost+"clicks/add/"+me+"/"+$(this).data('id');$.ajax({url: url,// The name of the callback parameter, as specified by the YQL servicejsonp: "callback",// Tell jQuery we're expecting JSONPdataType: "jsonp",// Tell YQL what we want and that we want JSONdata: {format: "json"},// Work with the responsesuccess: function( response ) {if(response.success && response.type=='redirect'){document.location = response.url;}}});ga('send', 'event', 'product', 'click', $(this).data('id'));});$('.jscroll-inner').on('click','.likedeal',function(e){var that = $(this);if($(that).hasClass('active')){//User has already liked it,so remove likevar url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/like";}else{var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/like";}$.ajax({url: url,// The name of the callback parameter, as specified by the YQL servicejsonp: "callback",// Tell jQuery we're expecting JSONPdataType: "jsonp",// Tell YQL what we want and that we want JSONdata: {format: "json"},// Work with the responsesuccess: function( response ) {if(response.success){$(that).toggleClass('active');$(that).parent().find('li.dislikedeal',0).removeClass('active');}}});ga('send', 'event', 'product', 'like', $(this).data('id'));});$('#myModal').on('click','#unlikebtn',function(e){e.preventDefault();var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()console.log(url);$.ajax({url: url,// The name of the callback parameter, as specified by the YQL servicejsonp: "callback",// Tell jQuery we're expecting JSONPdataType: "jsonp",// Tell YQL what we want and that we want JSONdata: {format: "json"},// Work with the responsesuccess: function( response ) {// console.log(response);}});$('#myModal').modal('hide');ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());})$('.jscroll-inner').on('click','.dislikedeal',function(e){var that = $(this);if($(that).hasClass('active')){//User has already liked it,so remove likevar url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";}else{console.log('show modal');$('#myModal').find('#productToHide',0).val($(this).data('id'));//$('#myModal').modal();var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";}$.ajax({url: url,// The name of the callback parameter, as specified by the YQL servicejsonp: "callback",// Tell jQuery we're expecting JSONPdataType: "jsonp",// Tell YQL what we want and that we want JSONdata: {format: "json"},// Work with the responsesuccess: function( response ) {if(response.success){$(that).toggleClass('active');$(that).parent().find('li.likedeal',0).removeClass('active');}}});ga('send', 'event', 'product', 'dislike', $(this).data('id'));});$('.deletefav').on('click',function(){var that = $(this);$('#loadingModal').modal();var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');$.ajax({url: url,// The name of the callback parameter, as specified by the YQL servicejsonp: "callback",// Tell jQuery we're expecting JSONPdataType: "jsonp",// Tell YQL what we want and that we want JSONdata: {format: "json"},// Work with the responsesuccess: function( response ) {$('#loadingModal').modal('hide');if(response.success){$('#fav-'+$(that).data('id')).hide('slow');}}});ga('send', 'event', 'favourites', 'remove', $(this).data('id'));});$('.clearfavs').on('click',function(){var that = $(this);$('#loadingModal').modal();var url = apihost+"/user_actions/deleteallfavs/"+me+'/'+$(this).data('type');$.ajax({url: url,// The name of the callback parameter, as specified by the YQL servicejsonp: "callback",// Tell jQuery we're expecting JSONPdataType: "jsonp",// Tell YQL what we want and that we want JSONdata: {format: "json"},// Work with the responsesuccess: function( response ) {$('#loadingModal').modal('hide');if(response.success){$('.deletefav').each(function(){$('#fav-'+$(this).data('id')).hide('slow');})}$(that).hide();}});ga('send', 'event', 'favourites', 'removeall', me);});$('.revealbrands').on('click',function(){$(this).parent().find('.notfeatured').toggleClass('hidden');if($(this).html()=='Others'){$(this).html('Hide');}else{$(this).html('Others');}});$(document).on('click','.creditedcashbacks',function(){if($(this).find('.glyphicon-plus',0).length>0){$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');}else{$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');}$(this).next().toggleClass('hidden');});$(document).on('click','.panel-heading',function(){if($(this).find('.glyphicon-plus',0).length>0){$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');}else{$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');}});$(document).on('click','.prefcatselect',function(){$('.prefcatselect').removeClass('active')$(this).addClass('active');$('.categorypreferences').addClass('hidden');$('#cat-'+$(this).data('id')).toggleClass('hidden');});$(document).on('click','.refresh',function(){document.location.reload();});$(document).on('click','.hasmoretext',function(){$('#fulltext').html($(this).data('fulltext'));$('#fullTextModal').modal();});$(document).on('click','.favswitch',function(){$('.favswitch').removeClass('active')$(this).addClass('active');$('.clearfavs').addClass('hidden');$('.card').addClass('hidden');$('.'+$(this).data('type')).removeClass('hidden');});});