| 14386 |
anikendra |
1 |
var livePriceCalls = [];
|
| 14432 |
anikendra |
2 |
var outOfStockCount = 0;
|
| 14773 |
anikendra |
3 |
function getcashbackstring(type,value) {
|
|
|
4 |
if(value==0){
|
|
|
5 |
return '';
|
|
|
6 |
}
|
|
|
7 |
if(type==2){
|
| 14789 |
anikendra |
8 |
return ' +'+value+' Cashback';
|
| 14773 |
anikendra |
9 |
}else if(type==1){
|
| 14789 |
anikendra |
10 |
return ' +'+value+'% Cashback';
|
| 14773 |
anikendra |
11 |
}else{
|
|
|
12 |
return '';
|
|
|
13 |
}
|
| 15926 |
anikendra |
14 |
};
|
|
|
15 |
function showShopcluesPopup(url){
|
|
|
16 |
$('#shopcluesUrl').prop('href',url);
|
|
|
17 |
$('#shopcluesModal').modal('show');
|
|
|
18 |
return;
|
|
|
19 |
};
|
| 13984 |
anikendra |
20 |
$(function(){
|
|
|
21 |
if($('.scroll > .card').length>0) {
|
| 14969 |
anikendra |
22 |
setTimeout(function(){ document.location.reload(); }, 1000*15*60);
|
| 13820 |
anikendra |
23 |
$('.scroll').jscroll({
|
|
|
24 |
loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
|
|
|
25 |
autoTriggerUntil: 3,
|
|
|
26 |
padding: 20,
|
|
|
27 |
});
|
|
|
28 |
}
|
| 13901 |
anikendra |
29 |
if($('.storeminprice').length>0) {
|
|
|
30 |
var globalminprice = 9999999;
|
| 14773 |
anikendra |
31 |
var globalminsku;
|
|
|
32 |
var globalmincashback = '';
|
| 16124 |
anikendra |
33 |
var globalminoffer = '';
|
| 14345 |
anikendra |
34 |
var calls = [];
|
| 13901 |
anikendra |
35 |
$('.storeminprice').each(function(){
|
| 14345 |
anikendra |
36 |
var temp = {'sort':$(this).data('searchorder'),'val':$(this)};
|
|
|
37 |
calls.push(temp);
|
|
|
38 |
});
|
|
|
39 |
calls = sortByKey(calls,'sort');
|
|
|
40 |
for(var i in calls){
|
|
|
41 |
fetchLivePrice(calls[i]['val'])
|
| 14969 |
anikendra |
42 |
}
|
| 14345 |
anikendra |
43 |
};
|
|
|
44 |
function sortByKey(array, key) {
|
|
|
45 |
return array.sort(function(a, b) {
|
|
|
46 |
var x = a[key]; var y = b[key];
|
|
|
47 |
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
|
|
48 |
});
|
| 15926 |
anikendra |
49 |
};
|
| 15923 |
anikendra |
50 |
function getCouponText(coupon){
|
|
|
51 |
return "<span class='red'>"+coupon+"</span>";
|
| 15926 |
anikendra |
52 |
};
|
| 14432 |
anikendra |
53 |
function fetchLivePrice(obj){
|
| 15607 |
anikendra |
54 |
ga('send', 'event', 'liveprice', 'fetch',$('#bestpriceproductname').html());
|
| 15550 |
anikendra |
55 |
var properties = {};
|
|
|
56 |
properties.bundle_id = String($(obj).data('bundle_id'));
|
| 15607 |
anikendra |
57 |
properties.product_name = String($('#bestpriceproductname').html());
|
| 15585 |
anikendra |
58 |
pma.send('products','livesprice','fetch',me,properties);
|
| 14432 |
anikendra |
59 |
var that = obj;
|
|
|
60 |
var inStock = false;
|
| 14386 |
anikendra |
61 |
var req = $.ajax({
|
| 14345 |
anikendra |
62 |
url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
|
|
|
63 |
// Tell jQuery we're expecting JSONP
|
|
|
64 |
dataType: "json",
|
|
|
65 |
// Tell YQL what we want and that we want JSON
|
|
|
66 |
method: 'get',
|
| 14430 |
anikendra |
67 |
// timeout: 30000,
|
| 14345 |
anikendra |
68 |
// Work with the response
|
|
|
69 |
success: function( response ) {
|
|
|
70 |
if(response.success){
|
|
|
71 |
var i = 0;
|
| 16219 |
anikendra |
72 |
var minpriceindex = 0;
|
| 14797 |
anikendra |
73 |
if(response.products[i].in_stock == 1) {
|
| 16219 |
anikendra |
74 |
inStock = true;
|
| 14797 |
anikendra |
75 |
var minprice = Math.round(response.products[i]['available_price']);
|
|
|
76 |
var minpriceurl = response.products[i]['marketPlaceUrl'];
|
|
|
77 |
}
|
| 14345 |
anikendra |
78 |
if(response.products.length>0){
|
|
|
79 |
//More than one products in store
|
|
|
80 |
var variants = [];
|
| 16124 |
anikendra |
81 |
var j = 0;
|
|
|
82 |
for(var i in response.products){
|
| 14685 |
anikendra |
83 |
if(response.products[i].in_stock == 1){
|
| 15923 |
anikendra |
84 |
inStock = true;
|
| 14685 |
anikendra |
85 |
if(response.products[i].available_price && response.products[i].available_price < globalminprice) {
|
|
|
86 |
globalminprice = Math.round(response.products[i].available_price);
|
|
|
87 |
globalminsku = response.products[i]._id;
|
|
|
88 |
var globalminsource = response.products[i].source_id;
|
| 14773 |
anikendra |
89 |
var globalminurl = response.products[i].marketPlaceUrl;
|
| 16124 |
anikendra |
90 |
var globalminoffer = response.products[i].offer;
|
| 14773 |
anikendra |
91 |
var globalmincashback = getcashbackstring(response.products[i].cash_back_type,response.products[i].cash_back);
|
| 14685 |
anikendra |
92 |
}
|
| 16219 |
anikendra |
93 |
if(typeof minprice == 'undefined' || response.products[i].available_price < minprice) {
|
| 14685 |
anikendra |
94 |
minprice = Math.round(response.products[i].available_price);
|
| 16219 |
anikendra |
95 |
minpriceindex = j;
|
| 16124 |
anikendra |
96 |
}
|
| 16234 |
anikendra |
97 |
if(response.products[i].tagline && response.products[i].tagline.length>0 && $('#productoneliner').html().length==0) {
|
| 16124 |
anikendra |
98 |
$('#productoneliner').html(response.products[i].tagline).removeClass('hidden').show();
|
|
|
99 |
}
|
|
|
100 |
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,'coupon': response.products[i].coupon,'codAvailable' : response.products[i].codAvailable,'offer' : response.products[i].offer});
|
|
|
101 |
}
|
| 16219 |
anikendra |
102 |
j++;
|
| 13901 |
anikendra |
103 |
}
|
| 16219 |
anikendra |
104 |
if(variants.length>1){
|
| 16124 |
anikendra |
105 |
variants.splice(minpriceindex,1);
|
| 14713 |
anikendra |
106 |
var variantslink = $('<span class="variants"> '+(variants.length+1)+' Options</span>');
|
|
|
107 |
$(that).parent().parent().find('.pull-left',0).append(variantslink);
|
| 14799 |
anikendra |
108 |
$(variantslink).data('variants',variants).data('minprice',minprice);
|
| 13948 |
anikendra |
109 |
}
|
| 14345 |
anikendra |
110 |
}
|
|
|
111 |
if(inStock){
|
| 14797 |
anikendra |
112 |
$(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');
|
| 14689 |
anikendra |
113 |
$('#name-'+$(that).data('id')).html(response.products[minpriceindex]['source_product_name']);
|
| 16039 |
anikendra |
114 |
if(response.products[minpriceindex]['coupon'] && response.products[minpriceindex]['coupon'].length>0){
|
| 15923 |
anikendra |
115 |
$('#couponcode-'+$(that).data('id')).show().find('span.red',0).html(getCouponText(response.products[minpriceindex]['coupon']));
|
| 16013 |
anikendra |
116 |
}
|
|
|
117 |
if(!response.products[minpriceindex]['codAvailable']){
|
| 16124 |
anikendra |
118 |
$('#codstatus-'+$(that).data('id')).show().removeClass('codstatus');
|
| 15923 |
anikendra |
119 |
}
|
| 16124 |
anikendra |
120 |
if(response.products[minpriceindex]['offer'].length>0){
|
|
|
121 |
$('#itemoffer-'+$(that).data('id')).show().html(response.products[minpriceindex]['offer']);
|
|
|
122 |
}
|
| 14685 |
anikendra |
123 |
$('#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');
|
| 14345 |
anikendra |
124 |
if(globalminprice != 9999999) {
|
| 16124 |
anikendra |
125 |
$('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback).siblings('.productoffer').html(globalminoffer);
|
| 14685 |
anikendra |
126 |
$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
|
| 14345 |
anikendra |
127 |
$('#bestpricecontainer').removeClass('hidden');
|
| 14432 |
anikendra |
128 |
}
|
| 14386 |
anikendra |
129 |
} else{
|
| 15607 |
anikendra |
130 |
ga('send', 'event', 'liveprice', 'outofstock', $('#bestpriceproductname').html());
|
| 15550 |
anikendra |
131 |
var properties = {};
|
|
|
132 |
properties.sku = String(response.products[0]._id);
|
| 15607 |
anikendra |
133 |
properties.source = String(response.products[0].source_id);
|
|
|
134 |
properties.product_name = String($('#bestpriceproductname').html());
|
| 15767 |
anikendra |
135 |
pma.send('products','liveprice','outofstock',me,properties);
|
| 14432 |
anikendra |
136 |
outOfStockCount++;
|
| 14345 |
anikendra |
137 |
$(that).parent().parent().remove();
|
| 13901 |
anikendra |
138 |
}
|
| 14345 |
anikendra |
139 |
if(!response.products[0].available_price){
|
| 14434 |
anikendra |
140 |
// outOfStockCount++;
|
|
|
141 |
// $(that).parent().parent().remove();
|
|
|
142 |
var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
|
|
|
143 |
$(that).html(btn);
|
| 15585 |
anikendra |
144 |
// ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
|
|
|
145 |
// console.log('failed for '+ response);
|
|
|
146 |
// properties = {};
|
|
|
147 |
// properties.sku = String(response.products[0]._id);
|
|
|
148 |
// pma.send('products','liveprice','failed',me,properties);
|
| 14969 |
anikendra |
149 |
}
|
| 14386 |
anikendra |
150 |
} else{
|
| 14434 |
anikendra |
151 |
// outOfStockCount++;
|
|
|
152 |
// $(that).parent().parent().remove();
|
|
|
153 |
var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
|
|
|
154 |
$(that).html(btn);
|
| 14969 |
anikendra |
155 |
ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
|
| 15550 |
anikendra |
156 |
properties = {};
|
|
|
157 |
properties.sku = String(response.products[0]._id);
|
|
|
158 |
pma.send('products','liveprice','failure',me,properties);
|
| 13901 |
anikendra |
159 |
}
|
| 14432 |
anikendra |
160 |
checkForOutStocks(outOfStockCount);
|
| 14345 |
anikendra |
161 |
},
|
| 15310 |
anikendra |
162 |
error: function(request, status, err) {
|
|
|
163 |
var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
|
|
|
164 |
$(that).html(btn);
|
|
|
165 |
try{
|
|
|
166 |
if(response){
|
|
|
167 |
ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
|
| 15550 |
anikendra |
168 |
var properties = {};
|
|
|
169 |
properties.sku = String(response.products[0]._id);
|
|
|
170 |
pma.send('products','livescore','error',me,properties);
|
| 15310 |
anikendra |
171 |
}
|
|
|
172 |
} catch(e){}
|
| 14345 |
anikendra |
173 |
}
|
| 13901 |
anikendra |
174 |
});
|
| 14386 |
anikendra |
175 |
livePriceCalls.push(req);
|
| 14357 |
anikendra |
176 |
};
|
| 14432 |
anikendra |
177 |
function checkForOutStocks(count){
|
|
|
178 |
if(count>=livePriceCalls.length){
|
|
|
179 |
$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');
|
| 14969 |
anikendra |
180 |
}
|
| 14432 |
anikendra |
181 |
};
|
| 14687 |
anikendra |
182 |
$(document).on('click','.showless',function(){
|
|
|
183 |
$(this).addClass('hidden').siblings('.varnts').hide();
|
|
|
184 |
$(this).parent().find('.variants',0).removeClass('hidden').addClass('justshow');
|
|
|
185 |
});
|
| 13901 |
anikendra |
186 |
$(document).on('click','.variants',function(){
|
|
|
187 |
$('.storeproductinfo').empty();
|
| 16219 |
anikendra |
188 |
var variants = $(this).data('variants');
|
| 14799 |
anikendra |
189 |
var minprice = $(this).data('minprice');
|
| 14026 |
anikendra |
190 |
$('#variantscount').html(variants.length);
|
| 13901 |
anikendra |
191 |
for(var i in variants){
|
| 14849 |
anikendra |
192 |
if(minprice == variants[i].available_price) {
|
| 16013 |
anikendra |
193 |
var html = '<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>';
|
| 14849 |
anikendra |
194 |
} else {
|
| 16013 |
anikendra |
195 |
var html = '<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>';
|
| 16124 |
anikendra |
196 |
}
|
|
|
197 |
if(variants[i].offer.length>0){
|
|
|
198 |
html += '<p class="text-small">'+variants[i].offer+'</p>';
|
| 16013 |
anikendra |
199 |
}
|
| 16039 |
anikendra |
200 |
if(variants[i].coupon && variants[i].coupon.length>0){
|
| 16013 |
anikendra |
201 |
html += '<p class="text-small">Use Coupon <span class="red">'+variants[i].coupon+'</span></p>';
|
|
|
202 |
}
|
|
|
203 |
if(!variants[i].codAvailable){
|
| 16124 |
anikendra |
204 |
html += '<p class="text-small">COD not available</p>';
|
|
|
205 |
}
|
| 16013 |
anikendra |
206 |
html += '</div></div>';
|
|
|
207 |
var row = $(html);
|
| 14687 |
anikendra |
208 |
$(this).parent().parent().append(row);
|
| 13901 |
anikendra |
209 |
}
|
| 14713 |
anikendra |
210 |
var showless = $('<div class="showless col-xs-9 text-right">Less <i class="glyphicon glyphicon-chevron-up"></i></span>');
|
| 14687 |
anikendra |
211 |
$(this).parent().parent().append(showless);
|
|
|
212 |
$(this).addClass('hidden');
|
| 13901 |
anikendra |
213 |
});
|
| 13695 |
anikendra |
214 |
$('.categorytab').on('click','.categorytabcontrol.active',function(){
|
|
|
215 |
$(this).toggleClass('active');
|
|
|
216 |
$('#preferences-'+$(this).data('id')).addClass('hidden');
|
|
|
217 |
$(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
|
|
|
218 |
});
|
| 13759 |
anikendra |
219 |
$('.categorytab').on('click','.categorytabcontrol:not(.active)',function(){
|
|
|
220 |
$(this).parent().parent().find('.btn',0).click();
|
|
|
221 |
});
|
| 13695 |
anikendra |
222 |
$('.categorytab').on('click','.editcategorypreferences',function(e){
|
|
|
223 |
var that = $(this);
|
|
|
224 |
$(that).removeClass('editcategorypreferences').addClass('savecategorypreferences').html('Done').addClass('btn-success');
|
|
|
225 |
$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
|
|
|
226 |
$('#preferences-'+$(that).data('id')).removeClass('hidden');
|
|
|
227 |
$('.brandselector').each(function(){
|
|
|
228 |
if($(this).data('catid')==$(that).data('id')){
|
|
|
229 |
$(this).addClass('active');
|
|
|
230 |
}
|
| 16066 |
anikendra |
231 |
});
|
| 13695 |
anikendra |
232 |
});
|
|
|
233 |
$('.categorytab').on('click','.savecategorypreferences',function(e){
|
|
|
234 |
var that = $(this);
|
|
|
235 |
$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
|
|
|
236 |
$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
|
|
|
237 |
$.ajax({
|
|
|
238 |
url: $('#categorypreference-'+$(that).data('id')).attr('action'),
|
|
|
239 |
data: $('#categorypreference-'+$(that).data('id')).serialize(),
|
|
|
240 |
// Tell jQuery we're expecting JSONP
|
|
|
241 |
dataType: "json",
|
|
|
242 |
// Tell YQL what we want and that we want JSON
|
|
|
243 |
method: 'post',
|
|
|
244 |
// Work with the response
|
|
|
245 |
success: function( response ) {
|
|
|
246 |
if(response.success){
|
|
|
247 |
$('#preferences-'+$(that).data('id')).addClass('hidden');
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
});
|
| 16066 |
anikendra |
251 |
active = getCookie('shopcluesActive',1);
|
| 16068 |
anikendra |
252 |
if(active && active == 'true'){
|
| 16066 |
anikendra |
253 |
$('.firsttimemsg').removeClass('hidden').show();
|
|
|
254 |
}
|
| 13695 |
anikendra |
255 |
ga('send', 'event', 'preferences', 'update', me);
|
| 15550 |
anikendra |
256 |
properties = pma.formDataToObject($('#categorypreference-'+$(this).data('id')).serializeArray());
|
|
|
257 |
pma.send('preferences', 'update', 'set', me, properties);
|
| 13695 |
anikendra |
258 |
});
|
| 15767 |
anikendra |
259 |
$(document).on('click','.viewproduct',function(e){
|
| 14386 |
anikendra |
260 |
if(typeof livePriceCalls != undefined) {
|
|
|
261 |
for(var i in livePriceCalls){
|
|
|
262 |
livePriceCalls[i].abort();
|
|
|
263 |
}
|
|
|
264 |
}
|
| 13686 |
anikendra |
265 |
$('#loadingModal').modal();
|
| 14952 |
anikendra |
266 |
if($(this).data('source')==2){
|
|
|
267 |
//in case of flipkart, close popup after 5 seconds
|
| 15311 |
anikendra |
268 |
setTimeout(function(){ $('#loadingModal').modal('hide');$('#customMessageModal').modal('hide'); }, 1000*10);
|
| 14952 |
anikendra |
269 |
}
|
| 15159 |
anikendra |
270 |
var store = $(this).data('source');
|
| 14345 |
anikendra |
271 |
var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
|
| 13579 |
anikendra |
272 |
$.ajax({
|
|
|
273 |
url: url,
|
|
|
274 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
275 |
jsonp: "callback",
|
|
|
276 |
// Tell jQuery we're expecting JSONP
|
|
|
277 |
dataType: "jsonp",
|
|
|
278 |
// Tell YQL what we want and that we want JSON
|
|
|
279 |
data: {
|
|
|
280 |
format: "json"
|
|
|
281 |
},
|
|
|
282 |
// Work with the response
|
|
|
283 |
success: function( response ) {
|
|
|
284 |
if(response.success && response.type=='redirect'){
|
| 15920 |
anikendra |
285 |
if(store == 5) {
|
|
|
286 |
//check if shopclues is active or not
|
|
|
287 |
active = getCookie('shopcluesActive',1);
|
| 15925 |
anikendra |
288 |
if(active && active == 'true'){
|
| 15920 |
anikendra |
289 |
document.location = response.url;
|
|
|
290 |
pma.send('apk','shopclues','active',me,null);
|
|
|
291 |
}else{
|
|
|
292 |
pma.send('apk','shopclues','inactive',me,null);
|
|
|
293 |
$('#loadingModal').modal('hide');
|
|
|
294 |
showShopcluesPopup(response.url);
|
|
|
295 |
// return;
|
|
|
296 |
}
|
|
|
297 |
} else if(store == 1 ) {
|
| 15901 |
anikendra |
298 |
url = 'http://mobilehotindia.com/r.html?'+Base64.encode(response.url);
|
|
|
299 |
document.location = url;
|
| 15310 |
anikendra |
300 |
} else if (store == 3 || store == 2) {
|
|
|
301 |
if (store == 2){
|
|
|
302 |
response.url = 'http://mobilehotindia.com/r.html?'+Base64.encode(response.url);
|
|
|
303 |
}
|
| 15188 |
anikendra |
304 |
if(response.showmessage == 1) {
|
|
|
305 |
$('#loadingModal').modal('hide');
|
|
|
306 |
$('#customMessage').html(response.message);
|
| 15310 |
anikendra |
307 |
$('#customMessageModal').modal('show');
|
| 15311 |
anikendra |
308 |
setTimeout(function(){ document.location = response.url;}, 1000*3);
|
| 15310 |
anikendra |
309 |
} else{
|
| 15206 |
anikendra |
310 |
document.location = response.url;
|
| 15188 |
anikendra |
311 |
}
|
| 15203 |
anikendra |
312 |
} else {
|
| 15128 |
anikendra |
313 |
document.location = response.url;
|
|
|
314 |
}
|
| 13579 |
anikendra |
315 |
}
|
| 15310 |
anikendra |
316 |
},
|
|
|
317 |
error: function() {
|
|
|
318 |
document.location = url;
|
| 13579 |
anikendra |
319 |
}
|
|
|
320 |
});
|
| 14432 |
anikendra |
321 |
ga('send', 'event', 'product', 'click', $(this).data('url'));
|
| 15550 |
anikendra |
322 |
var properties = {};
|
|
|
323 |
properties.sku = String($(this).data('id'));
|
|
|
324 |
properties.source = String($(this).data('source'));
|
|
|
325 |
properties.url = encodeURIComponent($(this).data('url'));
|
|
|
326 |
properties.price = String($(this).data('price'));
|
|
|
327 |
pma.send('products','url','click',me,properties);
|
| 13583 |
anikendra |
328 |
});
|
| 13719 |
anikendra |
329 |
$('.jscroll-inner').on('click','.likedeal',function(e){
|
| 13583 |
anikendra |
330 |
var that = $(this);
|
| 13682 |
anikendra |
331 |
if($(that).hasClass('active')){
|
| 13583 |
anikendra |
332 |
//User has already liked it,so remove like
|
|
|
333 |
var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/like";
|
|
|
334 |
}else{
|
|
|
335 |
var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/like";
|
|
|
336 |
}
|
|
|
337 |
$.ajax({
|
|
|
338 |
url: url,
|
|
|
339 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
340 |
jsonp: "callback",
|
|
|
341 |
// Tell jQuery we're expecting JSONP
|
|
|
342 |
dataType: "jsonp",
|
|
|
343 |
// Tell YQL what we want and that we want JSON
|
|
|
344 |
data: {
|
|
|
345 |
format: "json"
|
|
|
346 |
},
|
|
|
347 |
// Work with the response
|
|
|
348 |
success: function( response ) {
|
|
|
349 |
if(response.success){
|
| 13672 |
anikendra |
350 |
$(that).toggleClass('active');
|
|
|
351 |
$(that).parent().find('li.dislikedeal',0).removeClass('active');
|
| 13583 |
anikendra |
352 |
}
|
|
|
353 |
}
|
|
|
354 |
});
|
| 13686 |
anikendra |
355 |
ga('send', 'event', 'product', 'like', $(this).data('id'));
|
| 15550 |
anikendra |
356 |
var properties = {};
|
|
|
357 |
properties.sku = String($(this).data('id'));
|
|
|
358 |
pma.send('products','favourites','like',me,properties);
|
| 13583 |
anikendra |
359 |
});
|
| 13688 |
anikendra |
360 |
$('#myModal').on('click','#unlikebtn',function(e){
|
| 13682 |
anikendra |
361 |
e.preventDefault();
|
|
|
362 |
var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
|
|
|
363 |
$.ajax({
|
|
|
364 |
url: url,
|
|
|
365 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
366 |
jsonp: "callback",
|
|
|
367 |
// Tell jQuery we're expecting JSONP
|
|
|
368 |
dataType: "jsonp",
|
|
|
369 |
// Tell YQL what we want and that we want JSON
|
|
|
370 |
data: {
|
|
|
371 |
format: "json"
|
|
|
372 |
},
|
|
|
373 |
// Work with the response
|
|
|
374 |
success: function( response ) {
|
|
|
375 |
}
|
|
|
376 |
});
|
|
|
377 |
$('#myModal').modal('hide');
|
| 13686 |
anikendra |
378 |
ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
|
| 15550 |
anikendra |
379 |
pma.send('brands','hide',$('#myModal').find('#productToHide',0).val(),me);
|
| 13682 |
anikendra |
380 |
})
|
| 13719 |
anikendra |
381 |
$('.jscroll-inner').on('click','.dislikedeal',function(e){
|
| 13583 |
anikendra |
382 |
var that = $(this);
|
| 13682 |
anikendra |
383 |
if($(that).hasClass('active')){
|
| 13583 |
anikendra |
384 |
//User has already liked it,so remove like
|
|
|
385 |
var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";
|
|
|
386 |
}else{
|
| 13682 |
anikendra |
387 |
$('#myModal').find('#productToHide',0).val($(this).data('id'));
|
| 13583 |
anikendra |
388 |
var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
|
|
|
389 |
}
|
|
|
390 |
$.ajax({
|
|
|
391 |
url: url,
|
|
|
392 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
393 |
jsonp: "callback",
|
|
|
394 |
// Tell jQuery we're expecting JSONP
|
|
|
395 |
dataType: "jsonp",
|
|
|
396 |
// Tell YQL what we want and that we want JSON
|
|
|
397 |
data: {
|
|
|
398 |
format: "json"
|
|
|
399 |
},
|
|
|
400 |
// Work with the response
|
|
|
401 |
success: function( response ) {
|
|
|
402 |
if(response.success){
|
| 13672 |
anikendra |
403 |
$(that).toggleClass('active');
|
|
|
404 |
$(that).parent().find('li.likedeal',0).removeClass('active');
|
| 13583 |
anikendra |
405 |
}
|
|
|
406 |
}
|
|
|
407 |
});
|
| 13686 |
anikendra |
408 |
ga('send', 'event', 'product', 'dislike', $(this).data('id'));
|
| 15550 |
anikendra |
409 |
var properties = {};
|
|
|
410 |
properties.sku = String($(this).data('id'));
|
|
|
411 |
pma.send('products','favourites','dislike',me,properties);
|
| 13583 |
anikendra |
412 |
});
|
| 13731 |
anikendra |
413 |
$('.deletefav').on('click',function(){
|
|
|
414 |
var that = $(this);
|
|
|
415 |
$('#loadingModal').modal();
|
|
|
416 |
var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');
|
|
|
417 |
$.ajax({
|
|
|
418 |
url: url,
|
|
|
419 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
420 |
jsonp: "callback",
|
|
|
421 |
// Tell jQuery we're expecting JSONP
|
|
|
422 |
dataType: "jsonp",
|
|
|
423 |
// Tell YQL what we want and that we want JSON
|
|
|
424 |
data: {
|
|
|
425 |
format: "json"
|
|
|
426 |
},
|
|
|
427 |
// Work with the response
|
|
|
428 |
success: function( response ) {
|
|
|
429 |
$('#loadingModal').modal('hide');
|
|
|
430 |
if(response.success){
|
|
|
431 |
$('#fav-'+$(that).data('id')).hide('slow');
|
|
|
432 |
}
|
|
|
433 |
}
|
|
|
434 |
});
|
|
|
435 |
ga('send', 'event', 'favourites', 'remove', $(this).data('id'));
|
| 15550 |
anikendra |
436 |
var properties = {};
|
|
|
437 |
properties.sku = String($(this).data('id'));
|
|
|
438 |
pma.send('products','favourites','remove',me,properties);
|
| 13731 |
anikendra |
439 |
});
|
|
|
440 |
$('.clearfavs').on('click',function(){
|
|
|
441 |
var that = $(this);
|
|
|
442 |
$('#loadingModal').modal();
|
| 14300 |
anikendra |
443 |
var url = apihost+"/user_actions/deleteallfavs/"+me+'/'+$(this).data('type');
|
| 13731 |
anikendra |
444 |
$.ajax({
|
|
|
445 |
url: url,
|
|
|
446 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
447 |
jsonp: "callback",
|
|
|
448 |
// Tell jQuery we're expecting JSONP
|
|
|
449 |
dataType: "jsonp",
|
|
|
450 |
// Tell YQL what we want and that we want JSON
|
|
|
451 |
data: {
|
|
|
452 |
format: "json"
|
|
|
453 |
},
|
|
|
454 |
// Work with the response
|
|
|
455 |
success: function( response ) {
|
|
|
456 |
$('#loadingModal').modal('hide');
|
|
|
457 |
if(response.success){
|
|
|
458 |
$('.deletefav').each(function(){
|
|
|
459 |
$('#fav-'+$(this).data('id')).hide('slow');
|
|
|
460 |
})
|
|
|
461 |
}
|
|
|
462 |
$(that).hide();
|
|
|
463 |
}
|
|
|
464 |
});
|
|
|
465 |
ga('send', 'event', 'favourites', 'removeall', me);
|
| 15550 |
anikendra |
466 |
pma.send('products','favourites','removeall',me);
|
| 13731 |
anikendra |
467 |
});
|
| 13759 |
anikendra |
468 |
$('.revealbrands').on('click',function(){
|
|
|
469 |
$(this).parent().find('.notfeatured').toggleClass('hidden');
|
|
|
470 |
if($(this).html()=='Others'){
|
|
|
471 |
$(this).html('Hide');
|
|
|
472 |
}else{
|
|
|
473 |
$(this).html('Others');
|
|
|
474 |
}
|
|
|
475 |
});
|
| 14068 |
anikendra |
476 |
$(document).on('click','.creditedcashbacks',function(){
|
|
|
477 |
if($(this).find('.glyphicon-plus',0).length>0){
|
|
|
478 |
$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
|
|
|
479 |
}else{
|
|
|
480 |
$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
|
|
|
481 |
}
|
|
|
482 |
$(this).next().toggleClass('hidden');
|
|
|
483 |
});
|
|
|
484 |
$(document).on('click','.panel-heading',function(){
|
|
|
485 |
if($(this).find('.glyphicon-plus',0).length>0){
|
|
|
486 |
$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
|
|
|
487 |
}else{
|
|
|
488 |
$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
|
|
|
489 |
}
|
|
|
490 |
});
|
| 14135 |
anikendra |
491 |
$(document).on('click','.prefcatselect',function(){
|
|
|
492 |
$('.prefcatselect').removeClass('active')
|
|
|
493 |
$(this).addClass('active');
|
|
|
494 |
$('.categorypreferences').addClass('hidden');
|
|
|
495 |
$('#cat-'+$(this).data('id')).toggleClass('hidden');
|
| 14150 |
anikendra |
496 |
});
|
|
|
497 |
$(document).on('click','.refresh',function(){
|
|
|
498 |
document.location.reload();
|
|
|
499 |
});
|
| 14215 |
anikendra |
500 |
$(document).on('click','.hasmoretext',function(){
|
|
|
501 |
$('#fulltext').html($(this).data('fulltext'));
|
|
|
502 |
$('#fullTextModal').modal();
|
|
|
503 |
});
|
| 14300 |
anikendra |
504 |
$(document).on('click','.favswitch',function(){
|
|
|
505 |
$('.favswitch').removeClass('active')
|
|
|
506 |
$(this).addClass('active');
|
|
|
507 |
$('.clearfavs').addClass('hidden');
|
|
|
508 |
$('.card').addClass('hidden');
|
|
|
509 |
$('.'+$(this).data('type')).removeClass('hidden');
|
|
|
510 |
});
|
| 14386 |
anikendra |
511 |
$(document).on('click','.brandpreferences .brands',function(){
|
|
|
512 |
$(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();
|
|
|
513 |
});
|
|
|
514 |
$(document).on('click','.tryagainforliveprice',function(){
|
|
|
515 |
fetchLivePrice($(this).parent());
|
|
|
516 |
$(this).parent().html('Getting Live Prices');
|
|
|
517 |
});
|
| 14579 |
anikendra |
518 |
$(document).on('click','.alert > a',function(){
|
|
|
519 |
ga('send', 'event', 'notifications', 'click', $(this).html());
|
| 15550 |
anikendra |
520 |
pma.send('notifications','click',$(this).html(),me);
|
| 14579 |
anikendra |
521 |
});
|
|
|
522 |
$(document).on('click','.banner',function(){
|
|
|
523 |
ga('send', 'event', 'banners', 'click', $(this).data('name'));
|
| 15550 |
anikendra |
524 |
pma.send('banners','click',$(this).data('name'),me);
|
| 14579 |
anikendra |
525 |
});
|
| 13992 |
anikendra |
526 |
});
|
| 15310 |
anikendra |
527 |
function setCookie(cname, cvalue, days, forceCookie) {
|
|
|
528 |
if(typeof(Storage) !== "undefined" && !forceCookie) {
|
|
|
529 |
localStorage.setItem(cname, cvalue);
|
|
|
530 |
} else{
|
|
|
531 |
var d = new Date();
|
|
|
532 |
d.setTime(d.getTime() + (days*24*60*60*1000));
|
|
|
533 |
var expires = "expires="+d.toUTCString();
|
|
|
534 |
document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
|
|
|
535 |
}
|
| 14849 |
anikendra |
536 |
}
|
|
|
537 |
|
| 15310 |
anikendra |
538 |
function getCookie(cname,forceCookie) {
|
|
|
539 |
if(typeof(Storage) !== "undefined" && !forceCookie) {
|
|
|
540 |
return localStorage.getItem(cname);
|
|
|
541 |
} else {
|
|
|
542 |
var name = cname + "=";
|
|
|
543 |
var ca = document.cookie.split(';');
|
|
|
544 |
for(var i=0; i<ca.length; i++) {
|
|
|
545 |
var c = ca[i];
|
|
|
546 |
while (c.charAt(0)==' ') c = c.substring(1);
|
|
|
547 |
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
|
|
|
548 |
}
|
|
|
549 |
return "";
|
|
|
550 |
}
|
| 14849 |
anikendra |
551 |
}
|
| 15310 |
anikendra |
552 |
|
| 14849 |
anikendra |
553 |
function showpopup(id,count,interval){
|
| 14851 |
anikendra |
554 |
var cname = 'notif-count-'+me+'-'+id;
|
| 15797 |
anikendra |
555 |
var cookieval = getCookie(cname,1);
|
| 14851 |
anikendra |
556 |
var cname = 'notif-lastshown-'+me+'-'+id;
|
| 15797 |
anikendra |
557 |
var lastshown = getCookie(cname,1);
|
| 15310 |
anikendra |
558 |
if(!cookieval || cookieval == 'NaN' || cookieval==''){
|
| 15077 |
anikendra |
559 |
incrementPopupCount(id,0,'notif-count-');
|
|
|
560 |
setLastShown(id,'notif-lastshown-');
|
| 14849 |
anikendra |
561 |
return true;
|
|
|
562 |
} else{
|
|
|
563 |
var d = new Date();
|
|
|
564 |
var t = d.getTime();
|
|
|
565 |
if(t-lastshown>interval*60*1000){
|
|
|
566 |
if(cookieval>=count){
|
|
|
567 |
return false;
|
|
|
568 |
}else{
|
| 15077 |
anikendra |
569 |
setLastShown(id,'notif-lastshown-');
|
|
|
570 |
incrementPopupCount(id,cookieval,'notif-count-');
|
| 14849 |
anikendra |
571 |
return true;
|
|
|
572 |
}
|
|
|
573 |
}
|
|
|
574 |
}
|
|
|
575 |
}
|
| 15077 |
anikendra |
576 |
function setLastShown(id,cookiename){
|
|
|
577 |
var cname = cookiename+me+'-'+id;
|
| 14849 |
anikendra |
578 |
var d = new Date();
|
| 15721 |
anikendra |
579 |
setCookie(cname, d.getTime(), 365, 1);
|
| 14849 |
anikendra |
580 |
}
|
| 15077 |
anikendra |
581 |
function incrementPopupCount(id,currentCount,cookiename) {
|
|
|
582 |
var cname = cookiename+me+'-'+id;
|
| 15721 |
anikendra |
583 |
setCookie(cname, parseInt(currentCount)+1, 365, 1);
|
| 14858 |
anikendra |
584 |
}
|
|
|
585 |
var hidden, visibilityChange;
|
|
|
586 |
function handleVisibilityChange() {
|
|
|
587 |
if (document[hidden]) {
|
| 15058 |
anikendra |
588 |
// pagetitle = document.title;
|
| 14858 |
anikendra |
589 |
} else {
|
| 15058 |
anikendra |
590 |
// document.title = pagetitle;
|
| 14858 |
anikendra |
591 |
}
|
|
|
592 |
}
|
|
|
593 |
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
|
|
|
594 |
hidden = "hidden";
|
|
|
595 |
visibilityChange = "visibilitychange";
|
|
|
596 |
} else if (typeof document.mozHidden !== "undefined") {
|
|
|
597 |
hidden = "mozHidden";
|
|
|
598 |
visibilityChange = "mozvisibilitychange";
|
|
|
599 |
} else if (typeof document.msHidden !== "undefined") {
|
|
|
600 |
hidden = "msHidden";
|
|
|
601 |
visibilityChange = "msvisibilitychange";
|
|
|
602 |
} else if (typeof document.webkitHidden !== "undefined") {
|
|
|
603 |
hidden = "webkitHidden";
|
|
|
604 |
visibilityChange = "webkitvisibilitychange";
|
|
|
605 |
}
|
|
|
606 |
if (typeof document.addEventListener === "undefined" ||
|
|
|
607 |
typeof document[hidden] === "undefined") {
|
| 15077 |
anikendra |
608 |
console.log("This feature requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");
|
| 14858 |
anikendra |
609 |
} else {
|
|
|
610 |
// Handle page visibility change
|
|
|
611 |
document.addEventListener(visibilityChange, handleVisibilityChange, false);
|
|
|
612 |
}
|
| 14936 |
anikendra |
613 |
$('.notificationok').on('click',function(e){
|
| 14932 |
anikendra |
614 |
e.preventDefault();
|
| 14931 |
anikendra |
615 |
$('.notificationmodal').modal('hide');
|
| 15159 |
anikendra |
616 |
// setTimeout(function(){ $('.notificationmodal').modal('hide'); }, 1000);
|
| 16133 |
anikendra |
617 |
ga('send', 'event', 'popupnotification-'+$(this).parent().data('id'), 'ok', me);
|
|
|
618 |
var properties = {};
|
|
|
619 |
properties.id = String($(this).parent().data('id'));
|
|
|
620 |
pma.send('popupnotification','click','ok',me,properties);
|
| 14932 |
anikendra |
621 |
document.location = $(this).parent().prop('href');
|
| 15015 |
anikendra |
622 |
});
|
|
|
623 |
$(document).on('click','.clearfilter',function(){
|
|
|
624 |
$('.filterbrand').each(function(){
|
|
|
625 |
$(this).prop('checked',false);
|
|
|
626 |
});
|
| 15550 |
anikendra |
627 |
ga('send', 'event', 'filter', 'brand', 'reset');
|
|
|
628 |
pma.send('filters','brands','reset',me);
|
| 15015 |
anikendra |
629 |
});
|
|
|
630 |
$(document).on('click','.applyfilter',function(){
|
| 15584 |
anikendra |
631 |
$(this).prop('disabled',true);
|
|
|
632 |
$('#loadingModal').modal();
|
| 15015 |
anikendra |
633 |
var brands = [];
|
| 15026 |
anikendra |
634 |
var brandnames = [];
|
| 15015 |
anikendra |
635 |
$('.filterbrand').each(function(){
|
|
|
636 |
if($(this).prop('checked')){
|
|
|
637 |
brands.push($(this).val());
|
| 15026 |
anikendra |
638 |
brandnames.push($(this).parent().siblings('.brandname').html());
|
| 15015 |
anikendra |
639 |
}
|
|
|
640 |
});
|
|
|
641 |
if(brands.length==0){
|
| 15721 |
anikendra |
642 |
$('#loadingModal').modal('hide');
|
| 15015 |
anikendra |
643 |
$('#message').html('Please choose a few brands first').removeClass('hidden');
|
|
|
644 |
setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
|
| 15722 |
anikendra |
645 |
$(this).prop('disabled',false);
|
| 15015 |
anikendra |
646 |
return false;
|
|
|
647 |
}else{
|
| 16240 |
anikendra |
648 |
setCookie('brandschosen', brands, 0.25, true);
|
| 15015 |
anikendra |
649 |
var url = $('#brandselecter').prop('action');
|
| 15026 |
anikendra |
650 |
ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
|
| 15550 |
anikendra |
651 |
properties = {};
|
|
|
652 |
for(var i in brandnames){
|
|
|
653 |
properties['brand_'+i] = brandnames[i];
|
|
|
654 |
}
|
|
|
655 |
pma.send('filters','brands','addfilter',me,properties);
|
| 15085 |
anikendra |
656 |
var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
|
|
|
657 |
$.post( "/user_filters/add", postdata, function( data ) {
|
| 15584 |
anikendra |
658 |
$('#loadingModal').modal('hide');
|
| 15722 |
anikendra |
659 |
$(this).prop('disabled',false);
|
| 15584 |
anikendra |
660 |
document.location = url+'&brands='+brands.join('^');
|
| 15085 |
anikendra |
661 |
});
|
| 15015 |
anikendra |
662 |
}
|
|
|
663 |
});
|
|
|
664 |
$(document).on('click','#showallbrands',function(){
|
|
|
665 |
$('.hidden').removeClass('hidden');
|
|
|
666 |
$(this).hide();
|
| 15019 |
anikendra |
667 |
});
|
|
|
668 |
$(document).on('input','#brandfilter',function(){
|
|
|
669 |
$('.brand').addClass('hidden');
|
|
|
670 |
$('#showallbrands').hide();
|
|
|
671 |
var that = $(this);
|
|
|
672 |
$('li.brand').filter(function() {
|
|
|
673 |
return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
|
|
|
674 |
}).removeClass('hidden','slow');
|
| 15042 |
anikendra |
675 |
});
|
| 15077 |
anikendra |
676 |
$(document).on('click','.filterbrand',function(){
|
|
|
677 |
var clicked = $(this).parent().parent();
|
| 15042 |
anikendra |
678 |
// all the LIs above the clicked one
|
|
|
679 |
var previousAll = clicked.prevAll();
|
|
|
680 |
|
|
|
681 |
// only proceed if it's not already on top (no previous siblings)
|
|
|
682 |
if(previousAll.length > 0) {
|
|
|
683 |
// top LI
|
|
|
684 |
var top = $(previousAll[previousAll.length - 1]);
|
|
|
685 |
|
|
|
686 |
// immediately previous LI
|
|
|
687 |
var previous = $(previousAll[0]);
|
|
|
688 |
|
|
|
689 |
// how far up do we need to move the clicked LI?
|
|
|
690 |
var moveUp = clicked.attr('offsetTop') - top.attr('offsetTop');
|
|
|
691 |
|
|
|
692 |
// how far down do we need to move the previous siblings?
|
|
|
693 |
var moveDown = (clicked.offset().top + clicked.outerHeight()) - (previous.offset().top + previous.outerHeight());
|
|
|
694 |
|
|
|
695 |
// let's move stuff
|
|
|
696 |
clicked.css('position', 'relative');
|
|
|
697 |
previousAll.css('position', 'relative');
|
|
|
698 |
clicked.animate({'top': -moveUp});
|
|
|
699 |
previousAll.animate({'top': moveDown}, {complete: function() {
|
|
|
700 |
// rearrange the DOM and restore positioning when we're done moving
|
|
|
701 |
clicked.parent().prepend(clicked);
|
|
|
702 |
clicked.css({'position': 'static', 'top': 0});
|
|
|
703 |
previousAll.css({'position': 'static', 'top': 0});
|
|
|
704 |
}});
|
|
|
705 |
}
|
|
|
706 |
})
|
|
|
707 |
$(document).on('click','.clearfilters',function(){
|
| 15310 |
anikendra |
708 |
setCookie('brandschosen', '', -1, true);
|
| 15058 |
anikendra |
709 |
ga('send', 'event', 'filter', 'brand', 'clearfilters');
|
| 15550 |
anikendra |
710 |
pma.send('filters','brands','clearfilters',me);
|
| 15085 |
anikendra |
711 |
var postdata = {'user_id':me,'type':'clear'};
|
| 16240 |
anikendra |
712 |
$('#loadingModal').modal('show');
|
|
|
713 |
$.post("/user_filters/add", postdata, function( data ) {
|
|
|
714 |
document.location.reload();
|
| 15085 |
anikendra |
715 |
});
|
| 15042 |
anikendra |
716 |
});
|
|
|
717 |
function selectChosenBrands(){
|
| 15310 |
anikendra |
718 |
var brandschosen = getCookie('brandschosen',true);
|
| 15042 |
anikendra |
719 |
if(brandschosen && brandschosen.length>0){
|
|
|
720 |
var brands = brandschosen.split(',');
|
|
|
721 |
for(var i in brands){
|
|
|
722 |
$('.brand').filter(function() {
|
|
|
723 |
return $(this).data("brandid") == brands[i];
|
| 15077 |
anikendra |
724 |
}).removeClass('hidden').find('.filterbrand',0).trigger( "click" );
|
| 15042 |
anikendra |
725 |
}
|
|
|
726 |
}
|
| 15065 |
anikendra |
727 |
}
|
| 15585 |
anikendra |
728 |
function showPosition(position) {
|
| 15586 |
anikendra |
729 |
setCookie('latitude',position.coords.latitude,1,true);
|
|
|
730 |
setCookie('longitude',position.coords.longitude,1,true);
|
| 15585 |
anikendra |
731 |
}
|
| 15065 |
anikendra |
732 |
$(function () {
|
| 15077 |
anikendra |
733 |
var poid = 'popovertrigger';
|
| 15310 |
anikendra |
734 |
var cname = 'popover-count-'+me+'-'+poid;
|
| 15721 |
anikendra |
735 |
var cookieval = getCookie(cname,1);
|
| 15310 |
anikendra |
736 |
$('#dropdownMenu1').on('click',function(){
|
|
|
737 |
var cname = 'popover-count-'+me+'-'+poid;
|
| 15721 |
anikendra |
738 |
var cookieval = getCookie(cname,1);
|
| 15310 |
anikendra |
739 |
$('#popovertrigger').popover('hide');
|
|
|
740 |
if(!cookieval || cookieval == 'NaN' || cookieval == ''){
|
|
|
741 |
incrementPopupCount(poid,0,'popover-count-');
|
| 15526 |
anikendra |
742 |
} else if(cookieval > 0) {
|
| 15310 |
anikendra |
743 |
incrementPopupCount(poid, cookieval, 'popover-count-');
|
|
|
744 |
}
|
|
|
745 |
setLastShown(poid,'popover-lastshown-');
|
|
|
746 |
})
|
|
|
747 |
|
| 15077 |
anikendra |
748 |
var cname = 'popover-lastshown-'+me+'-'+poid;
|
| 15721 |
anikendra |
749 |
var lastshown = getCookie(cname,1);
|
| 15310 |
anikendra |
750 |
if(cookieval=='' || cookieval == 'NaN' || !cookieval){
|
| 15077 |
anikendra |
751 |
showpopover(poid);
|
| 15521 |
anikendra |
752 |
}
|
|
|
753 |
//Donot show popover anymore as long as we don't find a suitable solution
|
| 15721 |
anikendra |
754 |
else{
|
| 15077 |
anikendra |
755 |
var d = new Date();
|
|
|
756 |
var t = d.getTime();
|
| 15085 |
anikendra |
757 |
if(t-lastshown>18*3600*1000){
|
| 15310 |
anikendra |
758 |
if(cookieval>=2){
|
| 15077 |
anikendra |
759 |
return false;
|
|
|
760 |
}else{
|
| 15310 |
anikendra |
761 |
showpopover(poid);
|
| 15077 |
anikendra |
762 |
}
|
|
|
763 |
}
|
| 15721 |
anikendra |
764 |
}
|
| 15583 |
anikendra |
765 |
ga('send', 'event', 'popover', me, cookieval);
|
| 15585 |
anikendra |
766 |
if (navigator.geolocation) {
|
|
|
767 |
navigator.geolocation.getCurrentPosition(showPosition);
|
|
|
768 |
}
|
| 15077 |
anikendra |
769 |
});
|
|
|
770 |
function showpopover(id){
|
|
|
771 |
$('[data-toggle="popover"]#'+id).popover({'html':true});
|
|
|
772 |
$('[data-toggle="popover"]#'+id).trigger('click');
|
| 15085 |
anikendra |
773 |
}
|
|
|
774 |
$(document).on('click','.nodeals',function(){
|
|
|
775 |
document.location = $(this).data('href');
|
| 16018 |
anikendra |
776 |
});
|
|
|
777 |
$(document).on('click','.selectbrand',function(e){
|
|
|
778 |
e.preventDefault();
|
|
|
779 |
var brands = $(this).data('id');
|
|
|
780 |
var brandname = $(this).html();
|
|
|
781 |
console.log(brandname);
|
|
|
782 |
setCookie('brandschosen', brands, 1, true);
|
|
|
783 |
var url = $(this).data('href');
|
|
|
784 |
ga('send', 'event', 'selectbrand', 'brand', brandname);
|
|
|
785 |
properties = {};
|
|
|
786 |
properties['brand'] = brandname;
|
|
|
787 |
pma.send('filters','brands','selectbrand',me,properties);
|
|
|
788 |
var postdata = {'user_id':me,'type':'brand','filters':brandname};
|
|
|
789 |
$.post( "/user_filters/add", postdata, function( data ) {
|
|
|
790 |
$('#loadingModal').modal('hide');
|
|
|
791 |
$(this).addClass('activebrand');
|
|
|
792 |
document.location = url+'&brands='+brands;
|
|
|
793 |
});
|
|
|
794 |
});
|
| 15128 |
anikendra |
795 |
var Base64 = {
|
|
|
796 |
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
|
797 |
encode: function(input) {
|
|
|
798 |
var output = "";
|
|
|
799 |
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
|
800 |
var i = 0;
|
|
|
801 |
input = Base64._utf8_encode(input);
|
|
|
802 |
while (i < input.length) {
|
|
|
803 |
chr1 = input.charCodeAt(i++);
|
|
|
804 |
chr2 = input.charCodeAt(i++);
|
|
|
805 |
chr3 = input.charCodeAt(i++);
|
|
|
806 |
|
|
|
807 |
enc1 = chr1 >> 2;
|
|
|
808 |
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
|
|
809 |
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
|
|
810 |
enc4 = chr3 & 63;
|
|
|
811 |
if (isNaN(chr2)) {
|
|
|
812 |
enc3 = enc4 = 64;
|
|
|
813 |
} else if (isNaN(chr3)) {
|
|
|
814 |
enc4 = 64;
|
|
|
815 |
}
|
|
|
816 |
output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
|
|
|
817 |
}
|
|
|
818 |
return output;
|
|
|
819 |
},
|
|
|
820 |
|
|
|
821 |
|
|
|
822 |
decode: function(input) {
|
|
|
823 |
var output = "";
|
|
|
824 |
var chr1, chr2, chr3;
|
|
|
825 |
var enc1, enc2, enc3, enc4;
|
|
|
826 |
var i = 0;
|
|
|
827 |
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
|
|
828 |
while (i < input.length) {
|
|
|
829 |
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
|
|
830 |
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
|
|
831 |
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
|
|
832 |
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
|
|
833 |
chr1 = (enc1 << 2) | (enc2 >> 4);
|
|
|
834 |
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
|
|
835 |
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
|
836 |
output = output + String.fromCharCode(chr1);
|
|
|
837 |
if (enc3 != 64) {
|
|
|
838 |
output = output + String.fromCharCode(chr2);
|
|
|
839 |
}
|
|
|
840 |
if (enc4 != 64) {
|
|
|
841 |
output = output + String.fromCharCode(chr3);
|
|
|
842 |
}
|
|
|
843 |
}
|
|
|
844 |
output = Base64._utf8_decode(output);
|
|
|
845 |
return output;
|
|
|
846 |
},
|
|
|
847 |
|
|
|
848 |
_utf8_encode: function(string) {
|
|
|
849 |
string = string.replace(/\r\n/g, "\n");
|
|
|
850 |
var utftext = "";
|
|
|
851 |
for (var n = 0; n < string.length; n++) {
|
|
|
852 |
var c = string.charCodeAt(n);
|
|
|
853 |
if (c < 128) {
|
|
|
854 |
utftext += String.fromCharCode(c);
|
|
|
855 |
}
|
|
|
856 |
else if ((c > 127) && (c < 2048)) {
|
|
|
857 |
utftext += String.fromCharCode((c >> 6) | 192);
|
|
|
858 |
utftext += String.fromCharCode((c & 63) | 128);
|
|
|
859 |
}
|
|
|
860 |
else {
|
|
|
861 |
utftext += String.fromCharCode((c >> 12) | 224);
|
|
|
862 |
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
|
863 |
utftext += String.fromCharCode((c & 63) | 128);
|
|
|
864 |
}
|
|
|
865 |
}
|
|
|
866 |
return utftext;
|
|
|
867 |
},
|
|
|
868 |
|
|
|
869 |
_utf8_decode: function(utftext) {
|
|
|
870 |
var string = "";
|
|
|
871 |
var i = 0;
|
|
|
872 |
var c = c1 = c2 = 0;
|
|
|
873 |
while (i < utftext.length) {
|
|
|
874 |
c = utftext.charCodeAt(i);
|
|
|
875 |
if (c < 128) {
|
|
|
876 |
string += String.fromCharCode(c);
|
|
|
877 |
i++;
|
|
|
878 |
}
|
|
|
879 |
else if ((c > 191) && (c < 224)) {
|
|
|
880 |
c2 = utftext.charCodeAt(i + 1);
|
|
|
881 |
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
|
882 |
i += 2;
|
|
|
883 |
}
|
|
|
884 |
else {
|
|
|
885 |
c2 = utftext.charCodeAt(i + 1);
|
|
|
886 |
c3 = utftext.charCodeAt(i + 2);
|
|
|
887 |
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
|
888 |
i += 3;
|
|
|
889 |
}
|
|
|
890 |
}
|
|
|
891 |
return string;
|
|
|
892 |
}
|
| 15550 |
anikendra |
893 |
}
|
|
|
894 |
|
|
|
895 |
|
|
|
896 |
var pma = new function() {
|
| 15584 |
anikendra |
897 |
this.apiurl = "http://45.33.50.227:8081/";
|
| 15550 |
anikendra |
898 |
this.endpoints = {'identify':'identify','profile':'profile','track':'track'};
|
|
|
899 |
|
|
|
900 |
this.send = function (category,action,label,user_id,properties) {
|
| 15585 |
anikendra |
901 |
if(!properties){
|
|
|
902 |
properties = {};
|
|
|
903 |
}
|
|
|
904 |
properties.location = window.location.href;
|
|
|
905 |
// properties.appCodeName = navigator.appCodeName;
|
|
|
906 |
// properties.appName = navigator.appName;
|
|
|
907 |
// properties.appVersion = navigator.appVersion;
|
|
|
908 |
properties.cookieEnabled = String(navigator.cookieEnabled);
|
|
|
909 |
properties.platform = navigator.platform;
|
|
|
910 |
properties.userAgent = navigator.userAgent;
|
|
|
911 |
properties.ip = ip;
|
|
|
912 |
if (navigator.geolocation) {
|
| 15586 |
anikendra |
913 |
if(getCookie('latitude',true)){
|
|
|
914 |
properties.latitude = getCookie('latitude');
|
|
|
915 |
}
|
|
|
916 |
if(getCookie('longitude',true)){
|
|
|
917 |
properties.longitude = getCookie('longitude');
|
|
|
918 |
}
|
| 15585 |
anikendra |
919 |
}
|
|
|
920 |
properties.screenHeight = String(screen.height);
|
|
|
921 |
properties.screenWidth = String(screen.width);
|
|
|
922 |
// console.log(properties);
|
| 15550 |
anikendra |
923 |
$.ajax({
|
|
|
924 |
url: this.apiurl + this.endpoints.track,
|
|
|
925 |
data: {'category':category,'action':action,'label':label,'user_id':user_id,'properties':cassandraMAP.stringify(properties)},
|
|
|
926 |
// Tell jQuery we're expecting JSONP
|
|
|
927 |
dataType: "json",
|
|
|
928 |
// Tell YQL what we want and that we want JSON
|
|
|
929 |
method: 'post',
|
|
|
930 |
// Work with the response
|
|
|
931 |
success: function( response ) {
|
|
|
932 |
//Well, well, well :)
|
|
|
933 |
}
|
|
|
934 |
});
|
|
|
935 |
};
|
|
|
936 |
|
|
|
937 |
this.formDataToObject = function(formdata){
|
|
|
938 |
var properties = {};
|
|
|
939 |
var keys = [];
|
|
|
940 |
var formdata = JSON.parse(JSON.stringify(formdata));
|
|
|
941 |
for (var i in formdata) {
|
|
|
942 |
var key = formdata[i].name;
|
|
|
943 |
if(index = keys.indexOf(key)==-1){
|
|
|
944 |
properties[key] = formdata[i].value;
|
|
|
945 |
}else{
|
|
|
946 |
properties[key+'_'+i] = formdata[i].value;
|
|
|
947 |
}
|
|
|
948 |
keys.push(key);
|
|
|
949 |
};
|
|
|
950 |
return properties;
|
|
|
951 |
}
|
| 15128 |
anikendra |
952 |
}
|