Subversion Repositories SmartDukaan

Rev

Rev 13688 | Rev 13719 | 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
	});
12
	$('.categorytab').on('click','.editcategorypreferences',function(e){
13
		var that = $(this);
14
		$(that).removeClass('editcategorypreferences').addClass('savecategorypreferences').html('Done').addClass('btn-success');
15
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
16
		$('#preferences-'+$(that).data('id')).removeClass('hidden');
17
		$('.brandselector').each(function(){
18
			if($(this).data('catid')==$(that).data('id')){
19
				$(this).addClass('active');
20
			}
21
		});
22
	});
23
	$('.categorytab').on('click','.savecategorypreferences',function(e){
24
		var that = $(this);
25
		$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
26
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
27
		$.ajax({
28
			url: $('#categorypreference-'+$(that).data('id')).attr('action'),
29
			data: $('#categorypreference-'+$(that).data('id')).serialize(),
30
			// Tell jQuery we're expecting JSONP
31
			dataType: "json",
32
			// Tell YQL what we want and that we want JSON			
33
			method: 'post',
34
			// Work with the response
35
			success: function( response ) {
36
				if(response.success){
37
					$('#preferences-'+$(that).data('id')).addClass('hidden');
38
				}
39
			}
40
		});
41
		ga('send', 'event', 'preferences', 'update', me);
42
	});
13599 anikendra 43
	$('.row').on('click','.viewproduct',function(e){
13686 anikendra 44
		$('#loadingModal').modal();
13579 anikendra 45
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id');
46
		$.ajax({
47
			url: url,
48
			// The name of the callback parameter, as specified by the YQL service
49
			jsonp: "callback",
50
			// Tell jQuery we're expecting JSONP
51
			dataType: "jsonp",
52
			// Tell YQL what we want and that we want JSON
53
			data: {
54
				format: "json"
55
			},
56
			// Work with the response
57
			success: function( response ) {
13686 anikendra 58
				$('#loadingModal').modal('hide');
13579 anikendra 59
				if(response.success && response.type=='redirect'){
60
					document.location = response.url;
61
				}
62
			}
63
		});
13686 anikendra 64
		ga('send', 'event', 'product', 'click', $(this).data('id'));
13583 anikendra 65
	});
13686 anikendra 66
	$('.row').on('click','.likedeal',function(e){			
13583 anikendra 67
		var that = $(this);
13682 anikendra 68
		if($(that).hasClass('active')){
13583 anikendra 69
			//User has already liked it,so remove like
70
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/like";	
71
		}else{
72
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/like";
73
		}
74
		$.ajax({
75
			url: url,
76
			// The name of the callback parameter, as specified by the YQL service
77
			jsonp: "callback",
78
			// Tell jQuery we're expecting JSONP
79
			dataType: "jsonp",
80
			// Tell YQL what we want and that we want JSON
81
			data: {
82
				format: "json"
83
			},
84
			// Work with the response
85
			success: function( response ) {
86
				if(response.success){
13672 anikendra 87
					$(that).toggleClass('active');
88
					$(that).parent().find('li.dislikedeal',0).removeClass('active');
13583 anikendra 89
				}
90
			}
91
		});
13686 anikendra 92
		ga('send', 'event', 'product', 'like', $(this).data('id'));
13583 anikendra 93
	});
13688 anikendra 94
	$('#myModal').on('click','#unlikebtn',function(e){
13682 anikendra 95
		e.preventDefault();
96
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
97
		console.log(url);
98
		$.ajax({
99
			url: url,
100
			// The name of the callback parameter, as specified by the YQL service
101
			jsonp: "callback",
102
			// Tell jQuery we're expecting JSONP
103
			dataType: "jsonp",
104
			// Tell YQL what we want and that we want JSON
105
			data: {
106
				format: "json"
107
			},
108
			// Work with the response
109
			success: function( response ) {
110
				// console.log(response);						
111
			}
112
		});
113
		$('#myModal').modal('hide');
13686 anikendra 114
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
13682 anikendra 115
	})
116
	$('.row').on('click','.dislikedeal',function(e){			
13583 anikendra 117
		var that = $(this);
13682 anikendra 118
		if($(that).hasClass('active')){
13583 anikendra 119
			//User has already liked it,so remove like
120
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
121
		}else{
13682 anikendra 122
			console.log('show modal');
123
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
124
			$('#myModal').modal();
13583 anikendra 125
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
126
		}
127
		$.ajax({
128
			url: url,
129
			// The name of the callback parameter, as specified by the YQL service
130
			jsonp: "callback",
131
			// Tell jQuery we're expecting JSONP
132
			dataType: "jsonp",
133
			// Tell YQL what we want and that we want JSON
134
			data: {
135
				format: "json"
136
			},
137
			// Work with the response
138
			success: function( response ) {
139
				if(response.success){
13672 anikendra 140
					$(that).toggleClass('active');
141
					$(that).parent().find('li.likedeal',0).removeClass('active');
13583 anikendra 142
				}
143
			}
144
		});
13686 anikendra 145
		ga('send', 'event', 'product', 'dislike', $(this).data('id'));
13583 anikendra 146
	});
13599 anikendra 147
});