| 13984 |
anikendra |
1 |
$(function(){
|
|
|
2 |
if($('.scroll > .card').length>0) {
|
|
|
3 |
setTimeout(function(){ document.location.reload(); }, 1000*60*35);
|
| 13820 |
anikendra |
4 |
$('.scroll').jscroll({
|
|
|
5 |
loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
|
|
|
6 |
autoTriggerUntil: 3,
|
|
|
7 |
padding: 20,
|
|
|
8 |
});
|
|
|
9 |
}
|
| 13901 |
anikendra |
10 |
if($('.storeminprice').length>0) {
|
|
|
11 |
var globalminprice = 9999999;
|
|
|
12 |
var globalminsku;
|
| 14215 |
anikendra |
13 |
var inStock = false;
|
| 13901 |
anikendra |
14 |
$('.storeminprice').each(function(){
|
|
|
15 |
var that = $(this);
|
|
|
16 |
$.ajax({
|
|
|
17 |
url: '/store_products/getliveprice/'+$(this).data('bundle_id')+'/'+$(this).data('id'),
|
|
|
18 |
// Tell jQuery we're expecting JSONP
|
|
|
19 |
dataType: "json",
|
|
|
20 |
// Tell YQL what we want and that we want JSON
|
|
|
21 |
method: 'get',
|
|
|
22 |
// Work with the response
|
|
|
23 |
success: function( response ) {
|
|
|
24 |
if(response.success){
|
|
|
25 |
var i = 0;
|
| 14215 |
anikendra |
26 |
var minpriceindex = 0;
|
|
|
27 |
if(response.products[i].in_stock == 1){inStock = true;}
|
| 13901 |
anikendra |
28 |
var minprice = response.products[0]['available_price'];
|
|
|
29 |
var minpriceurl = response.products[0]['marketPlaceUrl'];
|
|
|
30 |
if(response.products.length>0){
|
|
|
31 |
//More than one products in store
|
|
|
32 |
var variants = [];
|
|
|
33 |
// var i = 0;
|
| 14215 |
anikendra |
34 |
for(var i in response.products){
|
|
|
35 |
if(response.products[i].in_stock == 1){inStock = true;}
|
|
|
36 |
console.log(response.products[i]);
|
| 13901 |
anikendra |
37 |
if(response.products[i].available_price && response.products[i].available_price < globalminprice) {
|
|
|
38 |
globalminprice = response.products[i].available_price;
|
|
|
39 |
globalminsku = response.products[i]._id;
|
|
|
40 |
}
|
|
|
41 |
if(response.products[i].available_price <= minprice) {
|
|
|
42 |
minprice = response.products[i].available_price;
|
|
|
43 |
minpriceindex = i;
|
|
|
44 |
}
|
| 14026 |
anikendra |
45 |
console.log(response);
|
| 13901 |
anikendra |
46 |
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});
|
|
|
47 |
}
|
|
|
48 |
if(i>0){
|
|
|
49 |
var variantslink = $('<span class="variants">+ '+i+' Options</span>');
|
|
|
50 |
$(that).parent().append(variantslink);
|
|
|
51 |
$(variantslink).data('variants',variants)
|
|
|
52 |
}
|
|
|
53 |
}
|
| 14215 |
anikendra |
54 |
if(inStock){
|
|
|
55 |
$(that).html(minprice);
|
|
|
56 |
$('#sku-'+$(that).data('id')).data('id',response.products[minpriceindex]['_id']).removeClass('hidden');
|
|
|
57 |
console.log(globalminprice+' '+globalminsku);
|
|
|
58 |
if(globalminprice != 9999999) {
|
|
|
59 |
$('#bestprice').html(globalminprice);
|
|
|
60 |
$('#beststorelink').data('id',globalminsku).removeClass('hidden');
|
|
|
61 |
$('#bestpricecontainer').removeClass('hidden');
|
|
|
62 |
}
|
|
|
63 |
}else{
|
|
|
64 |
$(that).parent().parent().remove();
|
| 13948 |
anikendra |
65 |
}
|
| 13901 |
anikendra |
66 |
if(!response.products[0].available_price){
|
|
|
67 |
$(that).parent().parent().remove();
|
|
|
68 |
}
|
|
|
69 |
}else{
|
|
|
70 |
$(that).parent().parent().remove();
|
|
|
71 |
}
|
|
|
72 |
},
|
|
|
73 |
error : function() {
|
|
|
74 |
$(that).parent().parent().remove();
|
|
|
75 |
}
|
|
|
76 |
});
|
|
|
77 |
});
|
|
|
78 |
}
|
|
|
79 |
$(document).on('click','.variants',function(){
|
|
|
80 |
$('.storeproductinfo').empty();
|
| 14026 |
anikendra |
81 |
var variants = $(this).data('variants');
|
|
|
82 |
$('#variantscount').html(variants.length);
|
| 13901 |
anikendra |
83 |
for(var i in variants){
|
|
|
84 |
console.log(variants[i]);
|
| 14026 |
anikendra |
85 |
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>');
|
| 13901 |
anikendra |
86 |
$('#storeproducts').parent().append(row);
|
|
|
87 |
}
|
| 14026 |
anikendra |
88 |
// console.log($(this).parent());
|
|
|
89 |
$('#storename').html($(this).parent().data('storename'));
|
| 13901 |
anikendra |
90 |
$('#variantModal').modal();
|
|
|
91 |
});
|
| 13695 |
anikendra |
92 |
$('.categorytab').on('click','.categorytabcontrol.active',function(){
|
|
|
93 |
$(this).toggleClass('active');
|
|
|
94 |
$('#preferences-'+$(this).data('id')).addClass('hidden');
|
|
|
95 |
$(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
|
|
|
96 |
});
|
| 13759 |
anikendra |
97 |
$('.categorytab').on('click','.categorytabcontrol:not(.active)',function(){
|
|
|
98 |
$(this).parent().parent().find('.btn',0).click();
|
|
|
99 |
});
|
| 13695 |
anikendra |
100 |
$('.categorytab').on('click','.editcategorypreferences',function(e){
|
|
|
101 |
var that = $(this);
|
|
|
102 |
$(that).removeClass('editcategorypreferences').addClass('savecategorypreferences').html('Done').addClass('btn-success');
|
|
|
103 |
$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
|
|
|
104 |
$('#preferences-'+$(that).data('id')).removeClass('hidden');
|
|
|
105 |
$('.brandselector').each(function(){
|
|
|
106 |
if($(this).data('catid')==$(that).data('id')){
|
|
|
107 |
$(this).addClass('active');
|
|
|
108 |
}
|
|
|
109 |
});
|
|
|
110 |
});
|
|
|
111 |
$('.categorytab').on('click','.savecategorypreferences',function(e){
|
|
|
112 |
var that = $(this);
|
|
|
113 |
$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
|
|
|
114 |
$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
|
|
|
115 |
$.ajax({
|
|
|
116 |
url: $('#categorypreference-'+$(that).data('id')).attr('action'),
|
|
|
117 |
data: $('#categorypreference-'+$(that).data('id')).serialize(),
|
|
|
118 |
// Tell jQuery we're expecting JSONP
|
|
|
119 |
dataType: "json",
|
|
|
120 |
// Tell YQL what we want and that we want JSON
|
|
|
121 |
method: 'post',
|
|
|
122 |
// Work with the response
|
|
|
123 |
success: function( response ) {
|
|
|
124 |
if(response.success){
|
|
|
125 |
$('#preferences-'+$(that).data('id')).addClass('hidden');
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
});
|
|
|
129 |
ga('send', 'event', 'preferences', 'update', me);
|
|
|
130 |
});
|
| 13901 |
anikendra |
131 |
// $('.row').on('click','.viewproduct',function(e){
|
|
|
132 |
$(document).on('click','.viewproduct',function(e){
|
| 13686 |
anikendra |
133 |
$('#loadingModal').modal();
|
| 13901 |
anikendra |
134 |
console.log($(this).data('id'));
|
| 13579 |
anikendra |
135 |
var url = apihost+"clicks/add/"+me+"/"+$(this).data('id');
|
|
|
136 |
$.ajax({
|
|
|
137 |
url: url,
|
|
|
138 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
139 |
jsonp: "callback",
|
|
|
140 |
// Tell jQuery we're expecting JSONP
|
|
|
141 |
dataType: "jsonp",
|
|
|
142 |
// Tell YQL what we want and that we want JSON
|
|
|
143 |
data: {
|
|
|
144 |
format: "json"
|
|
|
145 |
},
|
|
|
146 |
// Work with the response
|
|
|
147 |
success: function( response ) {
|
|
|
148 |
if(response.success && response.type=='redirect'){
|
|
|
149 |
document.location = response.url;
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
});
|
| 13686 |
anikendra |
153 |
ga('send', 'event', 'product', 'click', $(this).data('id'));
|
| 13583 |
anikendra |
154 |
});
|
| 13719 |
anikendra |
155 |
$('.jscroll-inner').on('click','.likedeal',function(e){
|
| 13583 |
anikendra |
156 |
var that = $(this);
|
| 13682 |
anikendra |
157 |
if($(that).hasClass('active')){
|
| 13583 |
anikendra |
158 |
//User has already liked it,so remove like
|
|
|
159 |
var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/like";
|
|
|
160 |
}else{
|
|
|
161 |
var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/like";
|
|
|
162 |
}
|
|
|
163 |
$.ajax({
|
|
|
164 |
url: url,
|
|
|
165 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
166 |
jsonp: "callback",
|
|
|
167 |
// Tell jQuery we're expecting JSONP
|
|
|
168 |
dataType: "jsonp",
|
|
|
169 |
// Tell YQL what we want and that we want JSON
|
|
|
170 |
data: {
|
|
|
171 |
format: "json"
|
|
|
172 |
},
|
|
|
173 |
// Work with the response
|
|
|
174 |
success: function( response ) {
|
|
|
175 |
if(response.success){
|
| 13672 |
anikendra |
176 |
$(that).toggleClass('active');
|
|
|
177 |
$(that).parent().find('li.dislikedeal',0).removeClass('active');
|
| 13583 |
anikendra |
178 |
}
|
|
|
179 |
}
|
|
|
180 |
});
|
| 13686 |
anikendra |
181 |
ga('send', 'event', 'product', 'like', $(this).data('id'));
|
| 13583 |
anikendra |
182 |
});
|
| 13688 |
anikendra |
183 |
$('#myModal').on('click','#unlikebtn',function(e){
|
| 13682 |
anikendra |
184 |
e.preventDefault();
|
|
|
185 |
var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
|
|
|
186 |
console.log(url);
|
|
|
187 |
$.ajax({
|
|
|
188 |
url: url,
|
|
|
189 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
190 |
jsonp: "callback",
|
|
|
191 |
// Tell jQuery we're expecting JSONP
|
|
|
192 |
dataType: "jsonp",
|
|
|
193 |
// Tell YQL what we want and that we want JSON
|
|
|
194 |
data: {
|
|
|
195 |
format: "json"
|
|
|
196 |
},
|
|
|
197 |
// Work with the response
|
|
|
198 |
success: function( response ) {
|
|
|
199 |
// console.log(response);
|
|
|
200 |
}
|
|
|
201 |
});
|
|
|
202 |
$('#myModal').modal('hide');
|
| 13686 |
anikendra |
203 |
ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
|
| 13682 |
anikendra |
204 |
})
|
| 13719 |
anikendra |
205 |
$('.jscroll-inner').on('click','.dislikedeal',function(e){
|
| 13583 |
anikendra |
206 |
var that = $(this);
|
| 13682 |
anikendra |
207 |
if($(that).hasClass('active')){
|
| 13583 |
anikendra |
208 |
//User has already liked it,so remove like
|
|
|
209 |
var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";
|
|
|
210 |
}else{
|
| 13682 |
anikendra |
211 |
console.log('show modal');
|
|
|
212 |
$('#myModal').find('#productToHide',0).val($(this).data('id'));
|
| 14139 |
anikendra |
213 |
//$('#myModal').modal();
|
| 13583 |
anikendra |
214 |
var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
|
|
|
215 |
}
|
|
|
216 |
$.ajax({
|
|
|
217 |
url: url,
|
|
|
218 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
219 |
jsonp: "callback",
|
|
|
220 |
// Tell jQuery we're expecting JSONP
|
|
|
221 |
dataType: "jsonp",
|
|
|
222 |
// Tell YQL what we want and that we want JSON
|
|
|
223 |
data: {
|
|
|
224 |
format: "json"
|
|
|
225 |
},
|
|
|
226 |
// Work with the response
|
|
|
227 |
success: function( response ) {
|
|
|
228 |
if(response.success){
|
| 13672 |
anikendra |
229 |
$(that).toggleClass('active');
|
|
|
230 |
$(that).parent().find('li.likedeal',0).removeClass('active');
|
| 13583 |
anikendra |
231 |
}
|
|
|
232 |
}
|
|
|
233 |
});
|
| 13686 |
anikendra |
234 |
ga('send', 'event', 'product', 'dislike', $(this).data('id'));
|
| 13583 |
anikendra |
235 |
});
|
| 13731 |
anikendra |
236 |
$('.deletefav').on('click',function(){
|
|
|
237 |
var that = $(this);
|
|
|
238 |
$('#loadingModal').modal();
|
|
|
239 |
var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');
|
|
|
240 |
$.ajax({
|
|
|
241 |
url: url,
|
|
|
242 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
243 |
jsonp: "callback",
|
|
|
244 |
// Tell jQuery we're expecting JSONP
|
|
|
245 |
dataType: "jsonp",
|
|
|
246 |
// Tell YQL what we want and that we want JSON
|
|
|
247 |
data: {
|
|
|
248 |
format: "json"
|
|
|
249 |
},
|
|
|
250 |
// Work with the response
|
|
|
251 |
success: function( response ) {
|
|
|
252 |
$('#loadingModal').modal('hide');
|
|
|
253 |
if(response.success){
|
|
|
254 |
$('#fav-'+$(that).data('id')).hide('slow');
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
});
|
|
|
258 |
ga('send', 'event', 'favourites', 'remove', $(this).data('id'));
|
|
|
259 |
});
|
|
|
260 |
$('.clearfavs').on('click',function(){
|
|
|
261 |
var that = $(this);
|
|
|
262 |
$('#loadingModal').modal();
|
| 14300 |
anikendra |
263 |
var url = apihost+"/user_actions/deleteallfavs/"+me+'/'+$(this).data('type');
|
| 13731 |
anikendra |
264 |
$.ajax({
|
|
|
265 |
url: url,
|
|
|
266 |
// The name of the callback parameter, as specified by the YQL service
|
|
|
267 |
jsonp: "callback",
|
|
|
268 |
// Tell jQuery we're expecting JSONP
|
|
|
269 |
dataType: "jsonp",
|
|
|
270 |
// Tell YQL what we want and that we want JSON
|
|
|
271 |
data: {
|
|
|
272 |
format: "json"
|
|
|
273 |
},
|
|
|
274 |
// Work with the response
|
|
|
275 |
success: function( response ) {
|
|
|
276 |
$('#loadingModal').modal('hide');
|
|
|
277 |
if(response.success){
|
|
|
278 |
$('.deletefav').each(function(){
|
|
|
279 |
$('#fav-'+$(this).data('id')).hide('slow');
|
|
|
280 |
})
|
|
|
281 |
}
|
|
|
282 |
$(that).hide();
|
|
|
283 |
}
|
|
|
284 |
});
|
|
|
285 |
ga('send', 'event', 'favourites', 'removeall', me);
|
|
|
286 |
});
|
| 13759 |
anikendra |
287 |
$('.revealbrands').on('click',function(){
|
|
|
288 |
$(this).parent().find('.notfeatured').toggleClass('hidden');
|
|
|
289 |
if($(this).html()=='Others'){
|
|
|
290 |
$(this).html('Hide');
|
|
|
291 |
}else{
|
|
|
292 |
$(this).html('Others');
|
|
|
293 |
}
|
|
|
294 |
});
|
| 14068 |
anikendra |
295 |
$(document).on('click','.creditedcashbacks',function(){
|
|
|
296 |
if($(this).find('.glyphicon-plus',0).length>0){
|
|
|
297 |
$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
|
|
|
298 |
}else{
|
|
|
299 |
$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
|
|
|
300 |
}
|
|
|
301 |
$(this).next().toggleClass('hidden');
|
|
|
302 |
});
|
|
|
303 |
$(document).on('click','.panel-heading',function(){
|
|
|
304 |
if($(this).find('.glyphicon-plus',0).length>0){
|
|
|
305 |
$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
|
|
|
306 |
}else{
|
|
|
307 |
$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
|
|
|
308 |
}
|
|
|
309 |
});
|
| 14135 |
anikendra |
310 |
$(document).on('click','.prefcatselect',function(){
|
|
|
311 |
$('.prefcatselect').removeClass('active')
|
|
|
312 |
$(this).addClass('active');
|
|
|
313 |
$('.categorypreferences').addClass('hidden');
|
|
|
314 |
$('#cat-'+$(this).data('id')).toggleClass('hidden');
|
| 14150 |
anikendra |
315 |
});
|
|
|
316 |
$(document).on('click','.refresh',function(){
|
|
|
317 |
document.location.reload();
|
|
|
318 |
});
|
| 14215 |
anikendra |
319 |
$(document).on('click','.hasmoretext',function(){
|
|
|
320 |
$('#fulltext').html($(this).data('fulltext'));
|
|
|
321 |
$('#fullTextModal').modal();
|
|
|
322 |
});
|
| 14300 |
anikendra |
323 |
$(document).on('click','.favswitch',function(){
|
|
|
324 |
$('.favswitch').removeClass('active')
|
|
|
325 |
$(this).addClass('active');
|
|
|
326 |
$('.clearfavs').addClass('hidden');
|
|
|
327 |
$('.card').addClass('hidden');
|
|
|
328 |
$('.'+$(this).data('type')).removeClass('hidden');
|
|
|
329 |
});
|
| 13992 |
anikendra |
330 |
});
|