Subversion Repositories SmartDukaan

Rev

Rev 13731 | Rev 13820 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13579 anikendra 1
$(function(){
2
	$('.scroll').jscroll({
3
		loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
4
	    autoTriggerUntil: 3,
5
	    padding: 20,
6
	});
13695 anikendra 7
	$('.categorytab').on('click','.categorytabcontrol.active',function(){
8
		$(this).toggleClass('active');
9
		$('#preferences-'+$(this).data('id')).addClass('hidden');
10
		$(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
11
	});
13759 anikendra 12
	$('.categorytab').on('click','.categorytabcontrol:not(.active)',function(){
13
		$(this).parent().parent().find('.btn',0).click();
14
	});
13695 anikendra 15
	$('.categorytab').on('click','.editcategorypreferences',function(e){
16
		var that = $(this);
17
		$(that).removeClass('editcategorypreferences').addClass('savecategorypreferences').html('Done').addClass('btn-success');
18
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
19
		$('#preferences-'+$(that).data('id')).removeClass('hidden');
20
		$('.brandselector').each(function(){
21
			if($(this).data('catid')==$(that).data('id')){
22
				$(this).addClass('active');
23
			}
24
		});
25
	});
26
	$('.categorytab').on('click','.savecategorypreferences',function(e){
27
		var that = $(this);
28
		$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
29
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
30
		$.ajax({
31
			url: $('#categorypreference-'+$(that).data('id')).attr('action'),
32
			data: $('#categorypreference-'+$(that).data('id')).serialize(),
33
			// Tell jQuery we're expecting JSONP
34
			dataType: "json",
35
			// Tell YQL what we want and that we want JSON			
36
			method: 'post',
37
			// Work with the response
38
			success: function( response ) {
39
				if(response.success){
40
					$('#preferences-'+$(that).data('id')).addClass('hidden');
41
				}
42
			}
43
		});
44
		ga('send', 'event', 'preferences', 'update', me);
45
	});
13599 anikendra 46
	$('.row').on('click','.viewproduct',function(e){
13686 anikendra 47
		$('#loadingModal').modal();
13579 anikendra 48
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id');
49
		$.ajax({
50
			url: url,
51
			// The name of the callback parameter, as specified by the YQL service
52
			jsonp: "callback",
53
			// Tell jQuery we're expecting JSONP
54
			dataType: "jsonp",
55
			// Tell YQL what we want and that we want JSON
56
			data: {
57
				format: "json"
58
			},
59
			// Work with the response
60
			success: function( response ) {
61
				if(response.success && response.type=='redirect'){
62
					document.location = response.url;
63
				}
64
			}
65
		});
13686 anikendra 66
		ga('send', 'event', 'product', 'click', $(this).data('id'));
13583 anikendra 67
	});
13719 anikendra 68
	$('.jscroll-inner').on('click','.likedeal',function(e){	
13583 anikendra 69
		var that = $(this);
13682 anikendra 70
		if($(that).hasClass('active')){
13583 anikendra 71
			//User has already liked it,so remove like
72
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/like";	
73
		}else{
74
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/like";
75
		}
76
		$.ajax({
77
			url: url,
78
			// The name of the callback parameter, as specified by the YQL service
79
			jsonp: "callback",
80
			// Tell jQuery we're expecting JSONP
81
			dataType: "jsonp",
82
			// Tell YQL what we want and that we want JSON
83
			data: {
84
				format: "json"
85
			},
86
			// Work with the response
87
			success: function( response ) {
88
				if(response.success){
13672 anikendra 89
					$(that).toggleClass('active');
90
					$(that).parent().find('li.dislikedeal',0).removeClass('active');
13583 anikendra 91
				}
92
			}
93
		});
13686 anikendra 94
		ga('send', 'event', 'product', 'like', $(this).data('id'));
13583 anikendra 95
	});
13688 anikendra 96
	$('#myModal').on('click','#unlikebtn',function(e){
13682 anikendra 97
		e.preventDefault();
98
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
99
		console.log(url);
100
		$.ajax({
101
			url: url,
102
			// The name of the callback parameter, as specified by the YQL service
103
			jsonp: "callback",
104
			// Tell jQuery we're expecting JSONP
105
			dataType: "jsonp",
106
			// Tell YQL what we want and that we want JSON
107
			data: {
108
				format: "json"
109
			},
110
			// Work with the response
111
			success: function( response ) {
112
				// console.log(response);						
113
			}
114
		});
115
		$('#myModal').modal('hide');
13686 anikendra 116
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
13682 anikendra 117
	})
13719 anikendra 118
	$('.jscroll-inner').on('click','.dislikedeal',function(e){			
13583 anikendra 119
		var that = $(this);
13682 anikendra 120
		if($(that).hasClass('active')){
13583 anikendra 121
			//User has already liked it,so remove like
122
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
123
		}else{
13682 anikendra 124
			console.log('show modal');
125
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
126
			$('#myModal').modal();
13583 anikendra 127
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
128
		}
129
		$.ajax({
130
			url: url,
131
			// The name of the callback parameter, as specified by the YQL service
132
			jsonp: "callback",
133
			// Tell jQuery we're expecting JSONP
134
			dataType: "jsonp",
135
			// Tell YQL what we want and that we want JSON
136
			data: {
137
				format: "json"
138
			},
139
			// Work with the response
140
			success: function( response ) {
141
				if(response.success){
13672 anikendra 142
					$(that).toggleClass('active');
143
					$(that).parent().find('li.likedeal',0).removeClass('active');
13583 anikendra 144
				}
145
			}
146
		});
13686 anikendra 147
		ga('send', 'event', 'product', 'dislike', $(this).data('id'));
13583 anikendra 148
	});
13731 anikendra 149
	$('.deletefav').on('click',function(){
150
		var that = $(this);
151
		$('#loadingModal').modal();
152
		var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');			
153
		$.ajax({
154
			url: url,
155
			// The name of the callback parameter, as specified by the YQL service
156
			jsonp: "callback",
157
			// Tell jQuery we're expecting JSONP
158
			dataType: "jsonp",
159
			// Tell YQL what we want and that we want JSON
160
			data: {
161
				format: "json"
162
			},
163
			// Work with the response
164
			success: function( response ) {
165
				$('#loadingModal').modal('hide');
166
				if(response.success){			
167
					$('#fav-'+$(that).data('id')).hide('slow');
168
				}
169
			}
170
		});
171
		ga('send', 'event', 'favourites', 'remove', $(this).data('id'));
172
	});
173
	$('.clearfavs').on('click',function(){
174
		var that = $(this);
175
		$('#loadingModal').modal();
176
		var url = apihost+"/user_actions/deleteallfavs/"+me;			
177
		$.ajax({
178
			url: url,
179
			// The name of the callback parameter, as specified by the YQL service
180
			jsonp: "callback",
181
			// Tell jQuery we're expecting JSONP
182
			dataType: "jsonp",
183
			// Tell YQL what we want and that we want JSON
184
			data: {
185
				format: "json"
186
			},
187
			// Work with the response
188
			success: function( response ) {
189
				$('#loadingModal').modal('hide');
190
				if(response.success){			
191
					$('.deletefav').each(function(){
192
						$('#fav-'+$(this).data('id')).hide('slow');
193
					})					
194
				}
195
				$(that).hide();
196
			}
197
		});
198
		ga('send', 'event', 'favourites', 'removeall', me);
199
	});
13759 anikendra 200
	$('.revealbrands').on('click',function(){
201
		$(this).parent().find('.notfeatured').toggleClass('hidden');
202
		if($(this).html()=='Others'){
203
			$(this).html('Hide');
204
		}else{
205
			$(this).html('Others');
206
		}
207
	});
13731 anikendra 208
});