Subversion Repositories SmartDukaan

Rev

Rev 13682 | Rev 13688 | 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
	});
13599 anikendra 7
	$('.row').on('click','.viewproduct',function(e){
13686 anikendra 8
		$('#loadingModal').modal();
13579 anikendra 9
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id');
10
		$.ajax({
11
			url: url,
12
			// The name of the callback parameter, as specified by the YQL service
13
			jsonp: "callback",
14
			// Tell jQuery we're expecting JSONP
15
			dataType: "jsonp",
16
			// Tell YQL what we want and that we want JSON
17
			data: {
18
				format: "json"
19
			},
20
			// Work with the response
21
			success: function( response ) {
13686 anikendra 22
				$('#loadingModal').modal('hide');
13579 anikendra 23
				if(response.success && response.type=='redirect'){
24
					document.location = response.url;
25
				}
26
			}
27
		});
13686 anikendra 28
		ga('send', 'event', 'product', 'click', $(this).data('id'));
13583 anikendra 29
	});
13686 anikendra 30
	$('.row').on('click','.likedeal',function(e){			
13583 anikendra 31
		var that = $(this);
13682 anikendra 32
		if($(that).hasClass('active')){
13583 anikendra 33
			//User has already liked it,so remove like
34
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/like";	
35
		}else{
36
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/like";
37
		}
38
		$.ajax({
39
			url: url,
40
			// The name of the callback parameter, as specified by the YQL service
41
			jsonp: "callback",
42
			// Tell jQuery we're expecting JSONP
43
			dataType: "jsonp",
44
			// Tell YQL what we want and that we want JSON
45
			data: {
46
				format: "json"
47
			},
48
			// Work with the response
49
			success: function( response ) {
50
				if(response.success){
13672 anikendra 51
					$(that).toggleClass('active');
52
					$(that).parent().find('li.dislikedeal',0).removeClass('active');
13583 anikendra 53
				}
54
			}
55
		});
13686 anikendra 56
		ga('send', 'event', 'product', 'like', $(this).data('id'));
13583 anikendra 57
	});
13682 anikendra 58
	$('.row').on('click','#unlikebtn',function(e){
59
		e.preventDefault();
60
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
61
		console.log(url);
62
		$.ajax({
63
			url: url,
64
			// The name of the callback parameter, as specified by the YQL service
65
			jsonp: "callback",
66
			// Tell jQuery we're expecting JSONP
67
			dataType: "jsonp",
68
			// Tell YQL what we want and that we want JSON
69
			data: {
70
				format: "json"
71
			},
72
			// Work with the response
73
			success: function( response ) {
74
				// console.log(response);						
75
			}
76
		});
77
		$('#myModal').modal('hide');
13686 anikendra 78
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
13682 anikendra 79
	})
80
	$('.row').on('click','.dislikedeal',function(e){			
13583 anikendra 81
		var that = $(this);
13682 anikendra 82
		if($(that).hasClass('active')){
13583 anikendra 83
			//User has already liked it,so remove like
84
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
85
		}else{
13682 anikendra 86
			console.log('show modal');
87
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
88
			$('#myModal').modal();
13583 anikendra 89
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
90
		}
91
		$.ajax({
92
			url: url,
93
			// The name of the callback parameter, as specified by the YQL service
94
			jsonp: "callback",
95
			// Tell jQuery we're expecting JSONP
96
			dataType: "jsonp",
97
			// Tell YQL what we want and that we want JSON
98
			data: {
99
				format: "json"
100
			},
101
			// Work with the response
102
			success: function( response ) {
103
				if(response.success){
13672 anikendra 104
					$(that).toggleClass('active');
105
					$(that).parent().find('li.likedeal',0).removeClass('active');
13583 anikendra 106
				}
107
			}
108
		});
13686 anikendra 109
		ga('send', 'event', 'product', 'dislike', $(this).data('id'));
13583 anikendra 110
	});
13599 anikendra 111
});