Rev 14928 | Rev 14932 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
var livePriceCalls = [];var outOfStockCount = 0;function getcashbackstring(type,value) {// console.log(type+' '+value);if(value==0){return '';}if(type==2){return ' +'+value+' Cashback';}else if(type==1){return ' +'+value+'% Cashback';}else{return '';}}$(function(){if($('.scroll > .card').length>0) {setTimeout(function(){ document.location.reload(); }, 1000*10*60);$('.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;var globalmincashback = '';var calls = [];$('.storeminprice').each(function(){var temp = {'sort':$(this).data('searchorder'),'val':$(this)};calls.push(temp);});calls = sortByKey(calls,'sort');for(var i in calls){fetchLivePrice(calls[i]['val'])}};function sortByKey(array, key) {return array.sort(function(a, b) {var x = a[key]; var y = b[key];return ((x < y) ? -1 : ((x > y) ? 1 : 0));});};function fetchLivePrice(obj){var that = obj;var inStock = false;var req = $.ajax({url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),// Tell jQuery we're expecting JSONPdataType: "json",// Tell YQL what we want and that we want JSONmethod: 'get',// timeout: 30000,// Work with the responsesuccess: function( response ) {// console.log(response);if(response.success){var i = 0;var minpriceindex = 0;if(response.products[i].in_stock == 1) {inStock = true;}if(response.products[i].in_stock == 1) {var minprice = Math.round(response.products[i]['available_price']);var minpriceurl = response.products[i]['marketPlaceUrl'];console.log(minprice);}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 = Math.round(response.products[i].available_price);globalminsku = response.products[i]._id;var globalminsource = response.products[i].source_id;var globalminurl = response.products[i].marketPlaceUrl;var globalmincashback = getcashbackstring(response.products[i].cash_back_type,response.products[i].cash_back);}if(typeof minprice == 'undefined' || response.products[i].available_price <= minprice) {minprice = Math.round(response.products[i].available_price);minpriceindex = i;}variants.push({'name' : response.products[i].source_product_name, 'source_id' : response.products[i].source_id, 'available_price' : Math.round(response.products[i].available_price), 'url' : response.products[i].marketPlaceUrl,'source_product_name' : response.products[i].source_product_name,'id' : response.products[i]._id,'cash_back_type' : response.products[i].cash_back_type,'cash_back' : response.products[i].cash_back});}}if(variants.length>1){variants.splice(minpriceindex,1);var variantslink = $('<span class="variants"> '+(variants.length+1)+' Options</span>');$(that).parent().parent().find('.pull-left',0).append(variantslink);$(variantslink).data('variants',variants).data('minprice',minprice);}}if(inStock){$(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');$('#name-'+$(that).data('id')).html(response.products[minpriceindex]['source_product_name']);// console.log(response.products[minpriceindex]);$('#sku-'+$(that).data('id')).data('id',response.products[minpriceindex]['_id']).data('source',response.products[minpriceindex]['source_id']).data('price',response.products[minpriceindex]['available_price']).data('url',response.products[minpriceindex]['marketPlaceUrl']).removeClass('hidden');// console.log(globalminprice+' '+globalminsku);if(globalminprice != 9999999) {$('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback);$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');$('#bestpricecontainer').removeClass('hidden');}} else{outOfStockCount++;$(that).parent().parent().remove();}if(!response.products[0].available_price){// outOfStockCount++;// $(that).parent().parent().remove();var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");$(that).html(btn);}} else{// outOfStockCount++;// $(that).parent().parent().remove();var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");$(that).html(btn);}checkForOutStocks(outOfStockCount);},error: function(request, status, err) {//console.log(status+' '+err+' '+request);// if (status == "timeout") {var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");$(that).html(btn);// } else {// $(that).parent().parent().remove();// }}});livePriceCalls.push(req);};function checkForOutStocks(count){if(count>=livePriceCalls.length){$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');}};$(document).on('click','.showless',function(){$(this).addClass('hidden').siblings('.varnts').hide();$(this).parent().find('.variants',0).removeClass('hidden').addClass('justshow');});$(document).on('click','.variants',function(){$('.storeproductinfo').empty();var variants = $(this).data('variants');var minprice = $(this).data('minprice');// console.log(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);// var row = $('<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-4 varnts"><span class="cashbackrupee"></span> <span>'+variants[i].available_price+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span></div><div class="col-xs-2 viewproduct varnts text-right" data-source="'+variants[i].source_id+'" data-price="'+variants[i].available_price+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><button type="button" class="btn-xs btn btn-success">BUY</button></div>');if(minprice == variants[i].available_price) {var row = $('<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-6 varnts viewproduct" data-source="'+variants[i].source_id+'" data-price="'+variants[i].available_price+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span class="storeminprice">'+variants[i].available_price+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span></div></div>');} else {var row = $('<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-6 varnts viewproduct" data-source="'+variants[i].source_id+'" data-price="'+variants[i].available_price+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span>'+variants[i].available_price+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span></div></div>');}$(this).parent().parent().append(row);}var showless = $('<div class="showless col-xs-9 text-right">Less <i class="glyphicon glyphicon-chevron-up"></i></span>');$(this).parent().parent().append(showless);$(this).addClass('hidden');});$('.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){if(typeof livePriceCalls != undefined) {for(var i in livePriceCalls){// console.log('killing ajax call '+i);livePriceCalls[i].abort();}}$('#loadingModal').modal();// console.log($(this).data('id'));var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');$.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('url'));});$('.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');});$(document).on('click','.brandpreferences .brands',function(){$(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();});$(document).on('click','.tryagainforliveprice',function(){fetchLivePrice($(this).parent());$(this).parent().html('Getting Live Prices');});$(document).on('click','.alert > a',function(){ga('send', 'event', 'notifications', 'click', $(this).html());});$(document).on('click','.banner',function(){ga('send', 'event', 'banners', 'click', $(this).data('name'));});});function setCookie(cname, cvalue, days) {var d = new Date();d.setTime(d.getTime() + (days*24*60*60*1000));var expires = "expires="+d.toUTCString();document.cookie = cname + "=" + cvalue + "; " + expires;}function getCookie(cname) {var name = cname + "=";var ca = document.cookie.split(';');for(var i=0; i<ca.length; i++) {var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1);if (c.indexOf(name) == 0) return c.substring(name.length, c.length);}return "";}function showpopup(id,count,interval){var cname = 'notif-count-'+me+'-'+id;var cookieval = getCookie(cname);var cname = 'notif-lastshown-'+me+'-'+id;var lastshown = getCookie(cname);if(cookieval==''){incrementPopupCount(id,0);setLastShown(id);return true;} else{var d = new Date();var t = d.getTime();console.log(t-lastshown);console.log(interval*60*1000);if(t-lastshown>interval*60*1000){if(cookieval>=count){return false;}else{setLastShown(id);incrementPopupCount(id,cookieval);return true;}}}}function setLastShown(id){var cname = 'notif-lastshown-'+me+'-'+id;var d = new Date();setCookie(cname, d.getTime(), 365);}function incrementPopupCount(id,currentCount) {var cname = 'notif-count-'+me+'-'+id;setCookie(cname, parseInt(currentCount)+1, 365);}var hidden, visibilityChange;function handleVisibilityChange() {if (document[hidden]) {console.log('mujhe dekho');document.title = "Mujhe Dekho Please";var tout = setTimeout(function(){ document.location.reload(); }, 1000*60);} else {console.log('active');clearTimeout(tout);}}if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later supporthidden = "hidden";visibilityChange = "visibilitychange";} else if (typeof document.mozHidden !== "undefined") {hidden = "mozHidden";visibilityChange = "mozvisibilitychange";} else if (typeof document.msHidden !== "undefined") {hidden = "msHidden";visibilityChange = "msvisibilitychange";} else if (typeof document.webkitHidden !== "undefined") {hidden = "webkitHidden";visibilityChange = "webkitvisibilitychange";}if (typeof document.addEventListener === "undefined" ||typeof document[hidden] === "undefined") {alert("This feature requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");} else {// Handle page visibility changedocument.addEventListener(visibilityChange, handleVisibilityChange, false);}$('#notificationok').on('click',function(){$('.notificationmodal').modal('hide');})