Subversion Repositories SmartDukaan

Rev

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

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