PluginProbe
wpForo Forum / 1.1.2
wpForo Forum v1.1.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.1.2, at wpf-assets/js/ajax.js

684 lines 20.6 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("wpflike", "");
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 $("#likeicon" + 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("wpflike", "");
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 $("#likeicon" + 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 $( ".wpf-topic-sbs" ).show();
196 $( "#wpf-topic-sbs" ).prop("disabled", false);
197
198 $( "#formaction" ).attr('name', 'post[action]');
199 $( "#formbutton" ).attr('name', 'post[save]');
200 $( "#formtopicid" ).attr('name', 'post[topicid]');
201 $( "#title" ).attr('name', 'post[title]');
202 $( "#formbutton" ).val( wpf_ajax_obj.phrases.save );
203 $( "#title").val( wpf_ajax_obj.phrases['re'] + ": " + $("#title").attr('placeholder').replace( wpf_ajax_obj.phrases['re'] + ": ", "").replace( wpf_ajax_obj.phrases['answer to'] + ": ", "") );
204 $('html, body').animate({scrollTop: $("#wpf-form-wrapper").offset().top}, 1000);
205
206 tinymce.execCommand('mceFocus',false,'postbody');
207 tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
208 tinyMCE.activeEditor.selection.collapse(false);
209 $('#wpforo-load').invisible();
210 });
211 });
212
213
214
215 // Report
216 $( ".wpforo-report" ).click(function(){
217 $("#wpf-msg-box").hide();
218 $('#wpforo-load').visible();
219 var postid_value = $(this).attr('id');
220 var postid = postid_value.replace("wpfreport", "");
221 $('#reportpostid').attr('value', postid);
222
223 var dialog;
224 var w = jQuery(window).width();
225 var h = jQuery(window).height();
226 var dialogWidth = 600;
227 var dialogHeight = 250;
228 H = ( dialogHeight < h ) ? dialogHeight : (h-40);
229 W = ( dialogWidth < w ) ? dialogWidth : (w-20);
230
231 dialog = jQuery( "#reportdialog" ).dialog({
232 create: function(event, ui) {
233 jQuery(event.target).parent().css('position', 'fixed');
234 },
235 close: function( event, ui ) {
236 jQuery("#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>');
237 },
238 autoOpen: false,
239 height: H,
240 width: W,
241 modal: true,
242 dialogClass:'wpforo-dialog wpforo-dialog-report'
243 });
244
245 dialog.dialog( "open" );
246 $('#wpforo-load').invisible();
247 });
248
249 $( "#sendreport" ).click(function(){
250 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
251 var postid = $('#reportpostid').attr('value');
252 var messagecontent = $('#reportmessagecontent').attr('value');
253
254 $.ajax({
255 type: 'POST',
256 url: wpf_ajax_obj.url,
257 data:{
258 postid: postid,
259 reportmsg: messagecontent,
260 action: 'wpforo_report_ajax'
261 }
262 }).done(function(response){
263 try{
264 response = $.parseJSON(response);
265 } catch (e) {
266 console.log(e);
267 }
268 jQuery( "#reportdialog" ).dialog('close');
269 $('#wpforo-load').invisible();
270 wpforo_notice_show(response);
271 });
272 });
273
274
275 // Sticky
276 $(document).on('click','.wpforo-sticky', function(){
277 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
278 var status_value = 'sticky';
279 var postid_value = $(this).attr('id');
280 var postid = postid_value.replace("wpfsticky", "");
281
282 $.ajax({
283 type: 'POST',
284 url: wpf_ajax_obj.url,
285 data:{
286 postid: postid,
287 status: status_value,
288 action: 'wpforo_sticky_ajax'
289 }
290 }).done(function(response){
291 if(response != 0){
292 $("#" + postid_value).removeClass('wpforo-sticky').addClass('wpforo-unsticky');
293 $("#stickytext" + postid).text(' ' + wpf_ajax_obj.phrases.unsticky);
294 }
295 $('#wpforo-load').invisible();
296 });
297 });
298
299 $(document).on('click','.wpforo-unsticky', function(){
300 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
301 var status_value = 'unsticky';
302 var postid_value = $(this).attr('id');
303 var postid = postid_value.replace("wpfsticky", "");
304
305 $.ajax({
306 type: 'POST',
307 url: wpf_ajax_obj.url,
308 data:{
309 postid: postid,
310 status: status_value,
311 action: 'wpforo_sticky_ajax'
312 }
313 }).done(function(response){
314 if(response != 0){
315 $("#" + postid_value).removeClass('wpforo-unsticky').addClass('wpforo-sticky');
316 $("#stickytext" + postid).text(' ' + wpf_ajax_obj.phrases.sticky);
317 }
318 $('#wpforo-load').invisible();
319 });
320 });
321
322 // Private
323 $(document).on('click','.wpforo-private', function(){
324 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
325 var status_value = 'private';
326 var postid_value = $(this).attr('id');
327 var postid = postid_value.replace("wpfprivate", "");
328
329 $.ajax({
330 type: 'POST',
331 url: wpf_ajax_obj.url,
332 data:{
333 postid: postid,
334 status: status_value,
335 action: 'wpforo_private_ajax'
336 }
337 }).done(function(response){
338 if(response != 0){
339 $("#" + postid_value).removeClass('wpforo-private').addClass('wpforo-public');
340 $("#privateicon" + postid).removeClass('fa-eye-slash').addClass('fa-eye');
341 $("#privatetext" + postid).text(' ' + wpf_ajax_obj.phrases.public);
342 }
343 $('#wpforo-load').invisible();
344 });
345 });
346
347 $(document).on('click','.wpforo-public', function(){
348 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
349 var status_value = 'public';
350 var postid_value = $(this).attr('id');
351 var postid = postid_value.replace("wpfprivate", "");
352
353 $.ajax({
354 type: 'POST',
355 url: wpf_ajax_obj.url,
356 data:{
357 postid: postid,
358 status: status_value,
359 action: 'wpforo_private_ajax'
360 }
361 }).done(function(response){
362 if(response != 0){
363 $("#" + postid_value).removeClass('wpforo-public').addClass('wpforo-private');
364 $("#privateicon" + postid).removeClass('fa-eye').addClass('fa-eye-slash');
365 $("#privatetext" + postid).text(' ' + wpf_ajax_obj.phrases.private);
366 }
367 $('#wpforo-load').invisible();
368 });
369 });
370
371 // Solved
372 $(document).on('click','.wpforo-solved', function(){
373 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
374 var status_value = 'solved';
375 var postid_value = $(this).attr('id');
376 var postid = postid_value.replace("wpfsolved", "");
377
378 $.ajax({
379 type: 'POST',
380 url: wpf_ajax_obj.url,
381 data:{
382 postid: postid,
383 status: status_value,
384 action: 'wpforo_solved_ajax'
385 }
386 }).done(function(response){
387 if(response != 0){
388 $("#" + postid_value).removeClass('wpforo-solved').addClass('wpforo-unsolved');
389 $("#solvedtext" + postid).text(' ' + wpf_ajax_obj.phrases.unsolved);
390 }
391 $('#wpforo-load').invisible();
392 });
393 });
394
395 $(document).on('click','.wpforo-unsolved', function(){
396 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
397 var status_value = 'unsolved';
398 var postid_value = $(this).attr('id');
399 var postid = postid_value.replace("wpfsolved", "");
400
401 $.ajax({
402 type: 'POST',
403 url: wpf_ajax_obj.url,
404 data:{
405 postid: postid,
406 status: status_value,
407 action: 'wpforo_solved_ajax'
408 }
409 }).done(function(response){
410 if(response != 0){
411 $("#" + postid_value).removeClass('wpforo-unsolved').addClass('wpforo-solved');
412 $("#solvedtext" + postid).text(' ' + wpf_ajax_obj.phrases.solved);
413 }
414 $('#wpforo-load').invisible();
415 });
416 });
417
418
419 // Close
420 $(document).on('click','.wpforo-close', function(){
421 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
422 var status_value = 'close';
423 var postid_value = $(this).attr('id');
424 var postid = postid_value.replace("wpfclose", "");
425 $.ajax({
426 type: 'POST',
427 url: wpf_ajax_obj.url,
428 data:{
429 postid: postid,
430 status: status_value,
431 action: 'wpforo_close_ajax'
432 }
433 }).done(function(response){
434 if(response != 0){
435 $("#" + postid_value).removeClass('wpforo-close').addClass('wpforo-open');
436 $("#closeicon" + postid).removeClass('fa-lock').addClass('fa-unlock');
437 $("#closetext" + postid).text(' ' + wpf_ajax_obj.phrases.open);
438 $("#wpf-form-wrapper").remove();
439 $(".wpforo-reply").remove();
440 $(".wpforo-quote").remove();
441 $(".wpforo-edit").remove();
442 }
443 $('#wpforo-load').invisible();
444 });
445 });
446
447 $(document).on('click','.wpforo-open', function(){
448 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
449 var status_value = 'closed';
450 var postid_value = $(this).attr('id');
451 var postid = postid_value.replace("wpfclose", "");
452 $.ajax({
453 type: 'POST',
454 url: wpf_ajax_obj.url,
455 data:{
456 postid: postid,
457 status: status_value,
458 action: 'wpforo_close_ajax'
459 }
460 }).done(function(response){
461 if(response != 0){
462 /*$("#" + postid_value).removeClass('wpforo-open').addClass('wpforo-close');
463 $("#closeicon" + postid).removeClass('fa-unlock').addClass('fa-lock');
464 $("#closetext" + postid).text(' ' + wpf_ajax_obj.phrases.close);*/
465 window.location.assign(response);
466 }
467 $('#wpforo-load').invisible();
468
469 });
470 });
471
472
473 // Edit
474 $(document).on('click','.wpforo-edit', function(){
475 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
476 $("#wpf-reply-form-title").html('Edit post');
477 var postid_value = $(this).attr('id');
478 var is_topic = postid_value.indexOf("topic");
479
480 if(is_topic == -1){
481 var postid = postid_value.replace("wpfedit", "");
482 }else{
483 var postid = postid_value.replace("wpfedittopicpid", "");
484 }
485 $.ajax({
486 type: 'POST',
487 url: wpf_ajax_obj.url,
488 data: {
489 postid: postid,
490 action: 'wpforo_edit_ajax'
491 }
492 }).done(function(response){
493 if(response != 0){
494 try{
495 response = $.parseJSON(response);
496 }catch(e){
497 console.log(e);
498 }
499 tinyMCE.activeEditor.setContent( response.body );
500 $( ".wpf-topic-sbs" ).hide();
501 $( "#wpf-topic-sbs" ).prop("disabled", true);
502
503 $( "#formaction" ).val( 'edit' );
504 $( "#formpostid" ).val( postid );
505 $( "#formbutton" ).val( wpf_ajax_obj.phrases.update );
506 $( 'html, body' ).animate({scrollTop: $("#wpf-form-wrapper").offset().top}, 1000);
507 if(is_topic == -1){
508 // $( "#title" ).prop( "disabled", true );
509 $( "#title").val( response.post_title );
510
511 $( "#formaction" ).attr('name', 'post[action]');
512 $( "#formbutton" ).attr('name', 'post[save]');
513 $( "#formtopicid" ).attr('name', 'post[topicid]');
514 $( "#title" ).attr('name', 'post[title]');
515 }else{
516 // $( "#title" ).prop( "disabled", false );
517 $( "#title").val( response.topic_title );
518
519 $( "#formaction" ).attr('name', 'topic[action]');
520 $( "#formbutton" ).attr('name', 'topic[save]');
521 $( "#formtopicid" ).attr('name', 'topic[topicid]');
522 $( "#title" ).attr('name', 'topic[title]');
523 }
524
525 tinymce.execCommand('mceFocus',false,'postbody');
526 tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
527 tinyMCE.activeEditor.selection.collapse(false);
528 }
529
530 $('#wpforo-load').invisible();
531
532 });
533 });
534
535
536 // Delete
537 $(document).on('click','.wpforo-delete', function(){
538 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
539
540 var ok = confirm(wpforo_ucwords(wpf_ajax_obj.phrases["are you sure you want to delete?"]));
541
542 if (ok == true){
543 var postid_value = $(this).attr('id');
544 var is_topic = postid_value.indexOf("topic");
545
546 if(is_topic == -1){
547 var postid = postid_value.replace("wpfreplydelete", "");
548 var status_value = 'reply';
549 }else{
550 var postid = postid_value.replace("wpftopicdelete", "");
551 var status_value = 'topic';
552 }
553
554 var forumid = $("input[type='hidden']#parent").val();
555
556 $.ajax({
557 type: 'POST',
558 url: wpf_ajax_obj.url,
559 data:{
560 forumid: forumid,
561 postid: postid,
562 status: status_value,
563 action: 'wpforo_delete_ajax'
564 }
565 }).done(function(response){
566 try{
567 response = $.parseJSON(response);
568 } catch (e) {
569 console.log(e);
570 }
571 if( response.stat == 1 ){
572 if(is_topic == -1){
573 $('#post-'+response.postid).fadeOut().delay(200);
574 }else{
575 window.location.assign(response.location);
576 }
577 $('#wpforo-load').invisible();
578 }else{
579 $('#wpforo-load').invisible();
580 }
581
582 wpforo_notice_show(response.notice);
583 });
584 }else{
585 $('#wpforo-load').invisible();
586 }
587 });
588
589
590 // Subscribe
591 $(document).on('click','.wpf-subscribe-forum, .wpf-subscribe-topic', function(){
592 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
593 var type = '';
594 var status = 'subscribe';
595 var clases = $(this).attr('class');
596
597 if( clases.indexOf("wpf-subscribe-forum") > -1 ){
598 type = 'forum';
599 }
600 if( clases.indexOf("wpf-subscribe-topic") > -1 ){
601 type = 'topic';
602 }
603
604 var postid_value = $(this).attr('id');
605 var itemid = postid_value.replace("wpfsubscribe-", "");
606
607 $.ajax({
608 type: 'POST',
609 url: wpf_ajax_obj.url,
610 data: {
611 itemid: itemid,
612 type: type,
613 status: status,
614 action: 'wpforo_subscribe_ajax'
615 }
616 }).done(function(response){
617 try{
618 response = $.parseJSON(response);
619 } catch (e) {
620 console.log(e);
621 }
622 if( response.stat == 1 ){
623 $("#wpfsubscribe-" + itemid).removeClass('wpf-subscribe-' + type).addClass('wpf-unsubscribe-' + type);
624 $("#wpfsubscribe-" + itemid).text( ' ' + wpf_ajax_obj.phrases.unsubscribe );
625 $('#wpforo-load').invisible();
626 }else{
627 $('#wpforo-load').invisible();
628 }
629
630 wpforo_notice_show(response.notice);
631 });
632
633 });
634
635 $(document).on('click','.wpf-unsubscribe-forum, .wpf-unsubscribe-topic', function(){
636 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
637 var type = '';
638 var button_phrase = '';
639 var status = 'unsubscribe';
640 var clases = $(this).attr('class');
641 if( clases.indexOf("wpf-unsubscribe-forum") > -1 ){
642 type = 'forum';
643 button_phrase = wpforo_ucwords(wpf_ajax_obj.phrases["subscribe for new topics"]);
644 }
645 if( clases.indexOf("wpf-unsubscribe-topic") > -1 ){
646 type = 'topic';
647 button_phrase = wpforo_ucwords(wpf_ajax_obj.phrases["subscribe for new replies"]);
648 }
649 var postid_value = $(this).attr('id');
650 var itemid = postid_value.replace("wpfsubscribe-", "");
651
652 $.ajax({
653 type: 'POST',
654 url: wpf_ajax_obj.url,
655 data: {
656 itemid: itemid,
657 type: type,
658 status: status,
659 action: 'wpforo_subscribe_ajax'
660 }
661 }).done(function(response){
662 try{
663 response = $.parseJSON(response);
664 } catch (e) {
665 console.log(e);
666 }
667 if( response.stat == 1 ){
668 $("#wpfsubscribe-" + itemid).removeClass('wpf-unsubscribe-' + type).addClass('wpf-subscribe-' + type);
669 $("#wpfsubscribe-" + itemid).text( ' ' + button_phrase );
670 $('#wpforo-load').invisible();
671 }else{
672 $('#wpforo-load').invisible();
673 }
674
675 wpforo_notice_show(response.notice);
676 });
677 });
678 });
679
680 function wpforo_ucwords (str) {
681 return (str + '').replace(/^([a-z])|\s+([a-z])/, function ($1) {
682 return $1.toUpperCase();
683 });
684 }