PluginProbe
wpForo Forum / 1.0.2
wpForo Forum v1.0.2
3.1.6 3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 All 138 releases
wpforo / wpf-assets / js / ajax.js

ajax.js in wpForo Forum 1.0.2, at wpf-assets/js/ajax.js

625 lines 18.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // Like
2 jQuery(document).ready(function($){
3 $(document).on('click','.wpforo-like', function(){
4 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
5 var postid_value = $(this).attr('id');
6 var postid = postid_value.replace("wpf", "");
7 $.ajax({
8 type: 'POST',
9 url: wpf_ajax_obj.url,
10 data: {
11 postid: postid,
12 likestatus: 1,
13 action: 'wpforo_like_ajax'
14 }
15 }).done(function(response){
16 try{
17 response = $.parseJSON(response);
18 } catch (e) {
19 console.log(e);
20 }
21 if( response.stat == 1 ){
22 $("#" + postid_value).removeClass('wpforo-like').addClass('wpforo-unlike');
23 $("#like" + postid).removeClass('fa-thumbs-o-up').addClass('fa-thumbs-o-down');
24 $("#liketext" + postid).text(' ' + wpf_ajax_obj.phrases['unlike']);
25 $("#post-" + postid + " .bleft").html(response.likers);
26 }
27 $('#wpforo-load').invisible();
28 wpforo_notice_show(response.notice);
29 });
30 });
31
32 $(document).on('click','.wpforo-unlike', function(){
33 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
34 var postid_value = $(this).attr('id');
35 var postid = postid_value.replace("wpf", "");
36
37 $.ajax({
38 type: 'POST',
39 url: wpf_ajax_obj.url,
40 data: {
41 postid: postid,
42 likestatus: 0,
43 action: 'wpforo_like_ajax'
44 }
45 }).done(function(response){
46 try{
47 response = $.parseJSON(response);
48 } catch (e) {
49 console.log(e);
50 }
51 if( response.stat == 1 ){
52 $("#" + postid_value).removeClass('wpforo-unlike').addClass('wpforo-like');
53 $("#like" + postid).removeClass('fa-thumbs-o-down').addClass('fa-thumbs-o-up');
54 $("#liketext" + postid).text(' ' + wpf_ajax_obj.phrases['like']);
55 $("#post-" + postid + " .bleft").html(response.likers);
56 }
57 $('#wpforo-load').invisible();
58 wpforo_notice_show(response.notice);
59 });
60 });
61
62
63 // Vote
64 $(document).on('click','.voteup', function(){
65 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
66 var vote = 'up';
67 var itemtype = $(this).attr('itemtype');
68 var postid_value = $(this).attr('id');
69 var postid = postid_value.replace("wpfvote-up-", "");
70 $.ajax({
71 type: 'POST',
72 url: wpf_ajax_obj.url,
73 data: {
74 itemtype: itemtype,
75 postid: postid,
76 votestatus: vote,
77 action: 'wpforo_vote_ajax'
78 }
79 }).done(function(response){
80 try{
81 response = $.parseJSON(response);
82 } catch (e) {
83 console.log(e);
84 }
85 if( response.stat == 1 ){
86 count = document.getElementById( 'wpfvote-num-' + postid ).innerHTML;
87 $( '#wpfvote-num-' + postid ).replaceWith( ++count ).fadeIn();;
88 }
89 $('#wpforo-load').invisible();
90 wpforo_notice_show(response.notice);
91 });
92 });
93
94 $(document).on('click','.votedown', function(){
95 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
96 var vote = 'down';
97 var itemtype = $(this).attr('itemtype');
98 var postid_value = $(this).attr('id');
99 var postid = postid_value.replace("wpfvote-down-", "");
100 $.ajax({
101 type: 'POST',
102 url: wpf_ajax_obj.url,
103 data: {
104 itemtype: itemtype,
105 postid: postid,
106 votestatus: vote,
107 action: 'wpforo_vote_ajax'
108 }
109 }).done(function(response){
110 try{
111 response = $.parseJSON(response);
112 } catch (e) {
113 console.log(e);
114 }
115 if(response.stat == 1){
116 count = document.getElementById( 'wpfvote-num-' + postid ).innerHTML;
117 $( '#wpfvote-num-' + postid ).replaceWith( --count ).fadeIn();;
118 }
119 $('#wpforo-load').invisible();
120 wpforo_notice_show(response.notice);
121 });
122 });
123
124
125 // Answer
126 $(document).on('click','.wpf-toggle-answer', function(){
127 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
128 var postid_value = $(this).attr('id');
129 var postid = postid_value.replace("wpf-answer-", "");
130 $.ajax({
131 type: 'POST',
132 url: wpf_ajax_obj.url,
133 data: {
134 postid: postid,
135 answerstatus: 0,
136 action: 'wpforo_answer_ajax'
137 }
138 }).done(function(response){
139 try{
140 response = $.parseJSON(response);
141 } catch (e) {
142 console.log(e);
143 }
144 if( response.stat == 1 ){
145 $("#wpf-answer-" + postid).removeClass('wpf-toggle-answer').addClass('wpf-toggle-not-answer');
146 }
147 $('#wpforo-load').invisible();
148 wpforo_notice_show(response.notice);
149 });
150 });
151
152 $(document).on('click','.wpf-toggle-not-answer', function(){
153 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
154 var postid_value = $(this).attr('id');
155 var postid = postid_value.replace("wpf-answer-", "");
156 $.ajax({
157 type: 'POST',
158 url: wpf_ajax_obj.url,
159 data: {
160 postid: postid,
161 answerstatus: 1,
162 action: 'wpforo_answer_ajax'
163 }
164 }).done(function(response){
165 try{
166 response = $.parseJSON(response);
167 } catch (e) {
168 console.log(e);
169 }
170 if( response.stat == 1 ){
171 $("#wpf-answer-" + postid).removeClass('wpf-toggle-not-answer').addClass('wpf-toggle-answer');
172 }
173 $('#wpforo-load').invisible();
174 wpforo_notice_show(response.notice);
175 });
176 });
177
178
179
180 // Quote
181 $(".wpforo-quote").click(function(){
182 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
183 $("#wpf-reply-form-title").html('Reply with quote');
184 var postid_value = $(this).attr('id');
185 var postid = postid_value.replace("wpfquotepost", "");
186 $.ajax({
187 type: 'POST',
188 url: wpf_ajax_obj.url,
189 data: {
190 postid: postid,
191 action: 'wpforo_quote_ajax'
192 }
193 }).done(function(response){
194 tinyMCE.activeEditor.setContent(response);
195 $( "#formaction" ).attr('name', 'post[action]');
196 $( "#formbutton" ).attr('name', 'post[save]');
197 $( "#formtopicid" ).attr('name', 'post[topicid]');
198 $( "#title" ).attr('name', 'post[title]');
199 $( "#formbutton" ).val( wpf_ajax_obj.phrases.save );
200 $( "#title").val( wpf_ajax_obj.phrases['re'] + ": " + $("#title").attr('placeholder').replace( wpf_ajax_obj.phrases['re'] + ": ", "").replace( wpf_ajax_obj.phrases['answer to'] + ": ", "") );
201 $('html, body').animate({scrollTop: $("#wpf-form-wrapper").offset().top}, 1000);
202
203 tinymce.execCommand('mceFocus',false,'postbody');
204 tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
205 tinyMCE.activeEditor.selection.collapse(false);
206 $('#wpforo-load').invisible();
207 });
208 });
209
210
211
212 // Report
213 jQuery( ".wpforo-report" ).click(function(){
214 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
215 var postid_value = $(this).attr('id');
216 var postid = postid_value.replace("wpfreport", "");
217 $('#reportpostid').attr('value', postid);
218
219 var dialog;
220 var w = jQuery(window).width();
221 var h = jQuery(window).height();
222 var dialogWidth = 600;
223 var dialogHeight = 250;
224 H = ( dialogHeight < h ) ? dialogHeight : (h-40);
225 W = ( dialogWidth < w ) ? dialogWidth : (w-20);
226
227 dialog = $( "#reportdialog" ).dialog({
228 create: function(event, ui) {
229 $(event.target).parent().css('position', 'fixed');
230 },
231 close: function( event, ui ) {
232 $("#wpf_attach_dialog").html('<div style="margin-top: 20%; margin-left: auto; margin-right: auto; display: table;"><i class="fa fa-spinner fa-spin fa-5x"></i></div>');
233 },
234 autoOpen: false,
235 height: H,
236 width: W,
237 modal: true,
238 dialogClass:'wpforo-dialog wpforo-dialog-report'
239 });
240
241 dialog.dialog( "open" );
242 $('#wpforo-load').invisible();
243 });
244
245 jQuery( "#sendreport" ).click(function(){
246 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
247 var postid = $('#reportpostid').attr('value');
248 var messagecontent = $('#reportmessagecontent').attr('value');
249
250 $.ajax({
251 type: 'POST',
252 url: wpf_ajax_obj.url,
253 data:{
254 postid: postid,
255 reportmsg: messagecontent,
256 action: 'wpforo_report_ajax'
257 }
258 }).done(function(response){
259 try{
260 response = $.parseJSON(response);
261 } catch (e) {
262 console.log(e);
263 }
264 $( "#reportdialog" ).dialog('close');
265 $('#wpforo-load').invisible();
266 wpforo_notice_show(response);
267 });
268 });
269
270
271 // Sticky
272 $(document).on('click','.wpforo-sticky', function(){
273 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
274 var status_value = 'sticky';
275 var postid_value = $(this).attr('id');
276 var postid = postid_value.replace("wpfsticky", "");
277
278 $.ajax({
279 type: 'POST',
280 url: wpf_ajax_obj.url,
281 data:{
282 postid: postid,
283 status: status_value,
284 action: 'wpforo_sticky_ajax'
285 }
286 }).done(function(response){
287 if(response != 0){
288 $("#" + postid_value).removeClass('wpforo-sticky').addClass('wpforo-unsticky');
289 $("#stickytext" + postid).text(' ' + wpf_ajax_obj.phrases.unsticky);
290 }
291 $('#wpforo-load').invisible();
292 });
293 });
294
295 $(document).on('click','.wpforo-unsticky', function(){
296 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
297 var status_value = 'unsticky';
298 var postid_value = $(this).attr('id');
299 var postid = postid_value.replace("wpfsticky", "");
300
301 $.ajax({
302 type: 'POST',
303 url: wpf_ajax_obj.url,
304 data:{
305 postid: postid,
306 status: status_value,
307 action: 'wpforo_sticky_ajax'
308 }
309 }).done(function(response){
310 if(response != 0){
311 $("#" + postid_value).removeClass('wpforo-unsticky').addClass('wpforo-sticky');
312 $("#stickytext" + postid).text(' ' + wpf_ajax_obj.phrases.sticky);
313 }
314 $('#wpforo-load').invisible();
315 });
316 });
317
318 // Solved
319 $(document).on('click','.wpforo-solved', function(){
320 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
321 var status_value = 'solved';
322 var postid_value = $(this).attr('id');
323 var postid = postid_value.replace("wpfsolved", "");
324
325 $.ajax({
326 type: 'POST',
327 url: wpf_ajax_obj.url,
328 data:{
329 postid: postid,
330 status: status_value,
331 action: 'wpforo_solved_ajax'
332 }
333 }).done(function(response){
334 if(response != 0){
335 $("#" + postid_value).removeClass('wpforo-solved').addClass('wpforo-unsolved');
336 $("#solvedtext" + postid).text(' ' + wpf_ajax_obj.phrases.unsolved);
337 }
338 $('#wpforo-load').invisible();
339 });
340 });
341
342 $(document).on('click','.wpforo-unsolved', function(){
343 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
344 var status_value = 'unsolved';
345 var postid_value = $(this).attr('id');
346 var postid = postid_value.replace("wpfsolved", "");
347
348 $.ajax({
349 type: 'POST',
350 url: wpf_ajax_obj.url,
351 data:{
352 postid: postid,
353 status: status_value,
354 action: 'wpforo_solved_ajax'
355 }
356 }).done(function(response){
357 if(response != 0){
358 $("#" + postid_value).removeClass('wpforo-unsolved').addClass('wpforo-solved');
359 $("#solvedtext" + postid).text(' ' + wpf_ajax_obj.phrases.solved);
360 }
361 $('#wpforo-load').invisible();
362 });
363 });
364
365
366 // Close
367 $(document).on('click','.wpforo-close', function(){
368 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
369 var status_value = 'close';
370 var postid_value = $(this).attr('id');
371 var postid = postid_value.replace("wpfclose", "");
372 $.ajax({
373 type: 'POST',
374 url: wpf_ajax_obj.url,
375 data:{
376 postid: postid,
377 status: status_value,
378 action: 'wpforo_close_ajax'
379 }
380 }).done(function(response){
381 if(response != 0){
382 $("#" + postid_value).removeClass('wpforo-close').addClass('wpforo-open');
383 $("#closeicon" + postid).removeClass('fa-lock').addClass('fa-unlock');
384 $("#closetext" + postid).text(' ' + wpf_ajax_obj.phrases.open);
385 $("#wpf-form-wrapper").remove();
386 }
387 $('#wpforo-load').invisible();
388 });
389 });
390
391 $(document).on('click','.wpforo-open', function(){
392 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
393 var status_value = 'closed';
394 var postid_value = $(this).attr('id');
395 var postid = postid_value.replace("wpfclose", "");
396 $.ajax({
397 type: 'POST',
398 url: wpf_ajax_obj.url,
399 data:{
400 postid: postid,
401 status: status_value,
402 action: 'wpforo_close_ajax'
403 }
404 }).done(function(response){
405 if(response != 0){
406 $("#" + postid_value).removeClass('wpforo-open').addClass('wpforo-close');
407 $("#closeicon" + postid).removeClass('fa-unlock').addClass('fa-lock');
408 $("#closetext" + postid).text(' ' + wpf_ajax_obj.phrases.close);
409 window.location.assign(response);
410 }
411 $('#wpforo-load').invisible();
412
413 });
414 });
415
416
417 // Edit
418 $(document).on('click','.wpforo-edit', function(){
419 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
420 $("#wpf-reply-form-title").html('Edit post');
421 var postid_value = $(this).attr('id');
422 var is_topic = postid_value.indexOf("topic");
423
424 if(is_topic == -1){
425 var postid = postid_value.replace("wpfedit", "");
426 }else{
427 var postid = postid_value.replace("wpfedittopicpid", "");
428 }
429 $.ajax({
430 type: 'POST',
431 url: wpf_ajax_obj.url,
432 data: {
433 postid: postid,
434 action: 'wpforo_edit_ajax'
435 }
436 }).done(function(response){
437 if(response != 0){
438 try{
439 response = $.parseJSON(response);
440 }catch(e){
441 console.log(e);
442 }
443 tinyMCE.activeEditor.setContent( response.body );
444 $( "#formaction" ).val( 'edit' );
445 $( "#formpostid" ).val( postid );
446 $( "#formbutton" ).val( wpf_ajax_obj.phrases.update );
447 $( 'html, body' ).animate({scrollTop: $("#wpf-form-wrapper").offset().top}, 1000);
448 if(is_topic == -1){
449 // $( "#title" ).prop( "disabled", true );
450 $( "#title").val( response.post_title );
451
452 $( "#formaction" ).attr('name', 'post[action]');
453 $( "#formbutton" ).attr('name', 'post[save]');
454 $( "#formtopicid" ).attr('name', 'post[topicid]');
455 $( "#title" ).attr('name', 'post[title]');
456 }else{
457 // $( "#title" ).prop( "disabled", false );
458 $( "#title").val( response.topic_title );
459
460 $( "#formaction" ).attr('name', 'topic[action]');
461 $( "#formbutton" ).attr('name', 'topic[save]');
462 $( "#formtopicid" ).attr('name', 'topic[topicid]');
463 $( "#title" ).attr('name', 'topic[title]');
464 }
465
466 tinymce.execCommand('mceFocus',false,'postbody');
467 tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
468 tinyMCE.activeEditor.selection.collapse(false);
469 }
470
471 $('#wpforo-load').invisible();
472
473 });
474 });
475
476
477 // Delete
478 $(document).on('click','.wpforo-delete', function(){
479 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
480
481 var ok = confirm(wpforo_ucwords(wpf_ajax_obj.phrases["are you sure you want to delete?"]));
482
483 if (ok == true){
484 var postid_value = $(this).attr('id');
485 var is_topic = postid_value.indexOf("topic");
486
487 if(is_topic == -1){
488 var postid = postid_value.replace("wpfreplydelete", "");
489 var status_value = 'reply';
490 }else{
491 var postid = postid_value.replace("wpftopicdelete", "");
492 var status_value = 'topic';
493 }
494
495 var forumid = $("input[type='hidden']#parent").val();
496
497 $.ajax({
498 type: 'POST',
499 url: wpf_ajax_obj.url,
500 data:{
501 forumid: forumid,
502 postid: postid,
503 status: status_value,
504 action: 'wpforo_delete_ajax'
505 }
506 }).done(function(response){
507 try{
508 response = $.parseJSON(response);
509 } catch (e) {
510 console.log(e);
511 }
512 if( response.stat == 1 ){
513 if(is_topic == -1){
514 $('#post-'+response.postid).fadeOut().delay(200);
515 }else{
516 window.location.assign(response.location);
517 }
518 $('#wpforo-load').invisible();
519 }else{
520 $('#wpforo-load').invisible();
521 }
522
523 wpforo_notice_show(response.notice);
524 });
525 }else{
526 $('#wpforo-load').invisible();
527 }
528 });
529
530
531 // Subscribe
532 $(document).on('click','.wpf-subscribe-forum, .wpf-subscribe-topic', function(){
533 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
534 var type = '';
535 var status = 'subscribe';
536 var clases = $(this).attr('class');
537
538 if( clases.indexOf("wpf-subscribe-forum") > -1 ){
539 type = 'forum';
540 }
541 if( clases.indexOf("wpf-subscribe-topic") > -1 ){
542 type = 'topic';
543 }
544
545 var postid_value = $(this).attr('id');
546 var itemid = postid_value.replace("wpfsubscribe-", "");
547
548 $.ajax({
549 type: 'POST',
550 url: wpf_ajax_obj.url,
551 data: {
552 itemid: itemid,
553 type: type,
554 status: status,
555 action: 'wpforo_subscribe_ajax'
556 }
557 }).done(function(response){
558 try{
559 response = $.parseJSON(response);
560 } catch (e) {
561 console.log(e);
562 }
563 if( response.stat == 1 ){
564 $("#wpfsubscribe-" + itemid).removeClass('wpf-subscribe-' + type).addClass('wpf-unsubscribe-' + type);
565 $("#wpfsubscribe-" + itemid).text( ' ' + wpf_ajax_obj.phrases.unsubscribe );
566 $('#wpforo-load').invisible();
567 }else{
568 $('#wpforo-load').invisible();
569 }
570
571 wpforo_notice_show(response.notice);
572 });
573
574 });
575
576 $(document).on('click','.wpf-unsubscribe-forum, .wpf-unsubscribe-topic', function(){
577 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
578 var type = '';
579 var button_phrase = '';
580 var status = 'unsubscribe';
581 var clases = $(this).attr('class');
582 if( clases.indexOf("wpf-unsubscribe-forum") > -1 ){
583 type = 'forum';
584 button_phrase = wpforo_ucwords(wpf_ajax_obj.phrases["subscribe for new topics"]);
585 }
586 if( clases.indexOf("wpf-unsubscribe-topic") > -1 ){
587 type = 'topic';
588 button_phrase = wpforo_ucwords(wpf_ajax_obj.phrases["subscribe for new replies"]);
589 }
590 var postid_value = $(this).attr('id');
591 var itemid = postid_value.replace("wpfsubscribe-", "");
592
593 $.ajax({
594 type: 'POST',
595 url: wpf_ajax_obj.url,
596 data: {
597 itemid: itemid,
598 type: type,
599 status: status,
600 action: 'wpforo_subscribe_ajax'
601 }
602 }).done(function(response){
603 try{
604 response = $.parseJSON(response);
605 } catch (e) {
606 console.log(e);
607 }
608 if( response.stat == 1 ){
609 $("#wpfsubscribe-" + itemid).removeClass('wpf-unsubscribe-' + type).addClass('wpf-subscribe-' + type);
610 $("#wpfsubscribe-" + itemid).text( ' ' + button_phrase );
611 $('#wpforo-load').invisible();
612 }else{
613 $('#wpforo-load').invisible();
614 }
615
616 wpforo_notice_show(response.notice);
617 });
618 });
619 });
620
621 function wpforo_ucwords (str) {
622 return (str + '').replace(/^([a-z])|\s+([a-z])/, function ($1) {
623 return $1.toUpperCase();
624 });
625 }