summaryrefslogtreecommitdiff
path: root/js/tbc_comment_ajax.js
blob: 0e92692e8cda9ed056ae5e5731267c04aca5555a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
 
$(document).ready(function(e){

    var basePath = Drupal.settings.basePath;
    var modPath = basePath + "comments/";
    var modPath1 = basePath + "comments/books/";
    var modPath2 = basePath + "comments/books/all";
    var modPath3 = basePath + "comments/forms/";
    var modPath4 = basePath + "comments/rand/";
//function changeLikeDislike(type,id){

$(".likebt").click(function(){
    console.log("Like");

var type = $(this).attr('data-name');
var id = $(this).attr('data-bid');
      console.log("###");
      var dataString = 'id='+ id + '&type=' + type;
      $("#product_flash_"+id).show();
      $("#product_flash_"+id).fadeIn(400).html('<img src="' +basePath+'sites/all/modules/tbc_comments/image/loading.gif" />');      
      console.log(dataString);
      $.ajax({
      type: "POST",
      url: modPath + "ajax/",
      data: dataString,
      cache: false,
      success: function(result){
       console.log("Like");
       console.log(result);
       $('#product_like_'+ id).html(result);  
              
      }
      });
});

$(".dislikebt").click(function(){
var type = $(this).attr('data-name');
var id = $(this).attr('data-bid');
      console.log("###");
      var dataString = 'id='+ id + '&type=' + type;
      $("#product_flash_"+id).show();
      $("#product_flash_"+id).fadeIn(400).html('<img src="' +basePath+'sites/all/modules/tbc_comments/image/loading.gif" />');            
      console.log(dataString);
      $.ajax({
      type: "POST",
      url: modPath + "ajax/",
      data: dataString,
      cache: false,
      success: function(result){
       console.log("disLike");
        console.log(result);       
       $('#product_dislike_'+ id).html(result);              
      }
      });
      
      
});
			
	
$(".popup_comment_box").hide();
$(".comment_click").click(function() {


var cid = $(this).attr('data-bookid');
$('#popup_box_'+ cid).fadeIn("slow");
            $("#container").css({ // this is just for style
                "opacity": "0.3"  
            });
            
var datastring = 'id=' + cid;
console.log(datastring);
           $.ajax({
             type: "POST",
             url: modPath3 + "ajax/",
             data: datastring,             
             cache: false,
             success: function(data){
             console.log("TTTTT");
             console.log(data);
           
       $('#wrap_box_'+ cid).html(data);
              
          }    
            
            
      });

 });
 
  $(this).on('click', '.close_box',function() { 
              $(".popup_comment_box").fadeOut("slow");
                  $("#container").css({ // this is just for style        
                  "opacity": "1"  
                  }); 
                  
 }); 

 
 /*$(this).on('keyup','#rand_num',function(e) {  
      var num_input = $(this).val();
      var input_num = $(this).attr('data-num');
 
       if( num_input != input_num){
       
      $('.submit_form').val('Submit Comment').attr('disabled', 'disabled');
       e.preventDefault();
      
      }else{
     
    $('.submit_form').val('Submit Comment').removeAttr('disabled');
     e.preventDefault(); 
     
     
      }
              
 });*/
 
 $(this).on('click', '.submit_form', function() {
 
 var num_input = $('#rand_num').val();
 if (num_input.length > 0){

  var input_num = $('#rand_num').attr('data-num');
   if( num_input == input_num){
 
     
    var form = $('form');	
	var submit = $('.submit_form');  
	form.on('submit', function(e) {
	
		// prevent default action
		//e.preventDefault();
		$('#rand_num').val('');
		rand_refresh();		
		e.stopImmediatePropagation();
		
		// send ajax request
		$.ajax({
			url: modPath1 + "ajax/",
			type: 'POST',
			//cache: false,
			data: form.serialize(), //form serizlize data
			beforeSend: function(){
			console.log('###');
				// change submit button value text and disabled it
				console.log(form.serialize());
				submit.val('Submitting...').attr('disabled', 'disabled');
			},
			success: function(data){
			console.log(item);
				
				var item = $(data).hide().fadeIn(800);
				console.log('sssss');
				console.log(item);
				$('#comment-block').prepend(item);
				

				// reset form and button
				form.trigger('reset');				
						
				submit.val('Submit Comment').removeAttr('disabled');
				
			},
			error: function(e){
				alert(e);
			}
		});
			
		return false;
		

	});
	
	 
	}else{
	alert("Incorrect value, please insert again");
	
	$(".num_input").css({ // this is just for style
         "border":  "1px solid red"  
                  }); 
                  return false;	
	}
	
}
else{
         alert("Please insert value");
         $(".num_input").css({ // this is just for style
           "border":  "1px solid red"  
                  }); 
         return false;
}

});

function rand_refresh()
{
 $.ajax({
      type: "POST",
      url: modPath4 + "ajax/",
      //data: dataString,
      cache: false,
      success: function(result){
      console.log(result);       
       $('#rand_fun').html(result);
              
      }
      
      });

}

});