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

635 lines 19.0 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 $( ".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 // Solved
323 $(document).on('click','.wpforo-solved', function(){
324 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
325 var status_value = 'solved';
326 var postid_value = $(this).attr('id');
327 var postid = postid_value.replace("wpfsolved", "");
328
329 $.ajax({
330 type: 'POST',
331 url: wpf_ajax_obj.url,
332 data:{
333 postid: postid,
334 status: status_value,
335 action: 'wpforo_solved_ajax'
336 }
337 }).done(function(response){
338 if(response != 0){
339 $("#" + postid_value).removeClass('wpforo-solved').addClass('wpforo-unsolved');
340 $("#solvedtext" + postid).text(' ' + wpf_ajax_obj.phrases.unsolved);
341 }
342 $('#wpforo-load').invisible();
343 });
344 });
345
346 $(document).on('click','.wpforo-unsolved', function(){
347 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
348 var status_value = 'unsolved';
349 var postid_value = $(this).attr('id');
350 var postid = postid_value.replace("wpfsolved", "");
351
352 $.ajax({
353 type: 'POST',
354 url: wpf_ajax_obj.url,
355 data:{
356 postid: postid,
357 status: status_value,
358 action: 'wpforo_solved_ajax'
359 }
360 }).done(function(response){
361 if(response != 0){
362 $("#" + postid_value).removeClass('wpforo-unsolved').addClass('wpforo-solved');
363 $("#solvedtext" + postid).text(' ' + wpf_ajax_obj.phrases.solved);
364 }
365 $('#wpforo-load').invisible();
366 });
367 });
368
369
370 // Close
371 $(document).on('click','.wpforo-close', function(){
372 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
373 var status_value = 'close';
374 var postid_value = $(this).attr('id');
375 var postid = postid_value.replace("wpfclose", "");
376 $.ajax({
377 type: 'POST',
378 url: wpf_ajax_obj.url,
379 data:{
380 postid: postid,
381 status: status_value,
382 action: 'wpforo_close_ajax'
383 }
384 }).done(function(response){
385 if(response != 0){
386 $("#" + postid_value).removeClass('wpforo-close').addClass('wpforo-open');
387 $("#closeicon" + postid).removeClass('fa-lock').addClass('fa-unlock');
388 $("#closetext" + postid).text(' ' + wpf_ajax_obj.phrases.open);
389 $("#wpf-form-wrapper").remove();
390 $(".wpforo-reply").remove();
391 $(".wpforo-quote").remove();
392 $(".wpforo-edit").remove();
393 }
394 $('#wpforo-load').invisible();
395 });
396 });
397
398 $(document).on('click','.wpforo-open', function(){
399 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
400 var status_value = 'closed';
401 var postid_value = $(this).attr('id');
402 var postid = postid_value.replace("wpfclose", "");
403 $.ajax({
404 type: 'POST',
405 url: wpf_ajax_obj.url,
406 data:{
407 postid: postid,
408 status: status_value,
409 action: 'wpforo_close_ajax'
410 }
411 }).done(function(response){
412 if(response != 0){
413 /*$("#" + postid_value).removeClass('wpforo-open').addClass('wpforo-close');
414 $("#closeicon" + postid).removeClass('fa-unlock').addClass('fa-lock');
415 $("#closetext" + postid).text(' ' + wpf_ajax_obj.phrases.close);*/
416 window.location.assign(response);
417 }
418 $('#wpforo-load').invisible();
419
420 });
421 });
422
423
424 // Edit
425 $(document).on('click','.wpforo-edit', function(){
426 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
427 $("#wpf-reply-form-title").html('Edit post');
428 var postid_value = $(this).attr('id');
429 var is_topic = postid_value.indexOf("topic");
430
431 if(is_topic == -1){
432 var postid = postid_value.replace("wpfedit", "");
433 }else{
434 var postid = postid_value.replace("wpfedittopicpid", "");
435 }
436 $.ajax({
437 type: 'POST',
438 url: wpf_ajax_obj.url,
439 data: {
440 postid: postid,
441 action: 'wpforo_edit_ajax'
442 }
443 }).done(function(response){
444 if(response != 0){
445 try{
446 response = $.parseJSON(response);
447 }catch(e){
448 console.log(e);
449 }
450 tinyMCE.activeEditor.setContent( response.body );
451 $( ".wpf-topic-sbs" ).hide();
452 $( "#wpf-topic-sbs" ).prop("disabled", true);
453
454 $( "#formaction" ).val( 'edit' );
455 $( "#formpostid" ).val( postid );
456 $( "#formbutton" ).val( wpf_ajax_obj.phrases.update );
457 $( 'html, body' ).animate({scrollTop: $("#wpf-form-wrapper").offset().top}, 1000);
458 if(is_topic == -1){
459 // $( "#title" ).prop( "disabled", true );
460 $( "#title").val( response.post_title );
461
462 $( "#formaction" ).attr('name', 'post[action]');
463 $( "#formbutton" ).attr('name', 'post[save]');
464 $( "#formtopicid" ).attr('name', 'post[topicid]');
465 $( "#title" ).attr('name', 'post[title]');
466 }else{
467 // $( "#title" ).prop( "disabled", false );
468 $( "#title").val( response.topic_title );
469
470 $( "#formaction" ).attr('name', 'topic[action]');
471 $( "#formbutton" ).attr('name', 'topic[save]');
472 $( "#formtopicid" ).attr('name', 'topic[topicid]');
473 $( "#title" ).attr('name', 'topic[title]');
474 }
475
476 tinymce.execCommand('mceFocus',false,'postbody');
477 tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
478 tinyMCE.activeEditor.selection.collapse(false);
479 }
480
481 $('#wpforo-load').invisible();
482
483 });
484 });
485
486
487 // Delete
488 $(document).on('click','.wpforo-delete', function(){
489 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
490
491 var ok = confirm(wpforo_ucwords(wpf_ajax_obj.phrases["are you sure you want to delete?"]));
492
493 if (ok == true){
494 var postid_value = $(this).attr('id');
495 var is_topic = postid_value.indexOf("topic");
496
497 if(is_topic == -1){
498 var postid = postid_value.replace("wpfreplydelete", "");
499 var status_value = 'reply';
500 }else{
501 var postid = postid_value.replace("wpftopicdelete", "");
502 var status_value = 'topic';
503 }
504
505 var forumid = $("input[type='hidden']#parent").val();
506
507 $.ajax({
508 type: 'POST',
509 url: wpf_ajax_obj.url,
510 data:{
511 forumid: forumid,
512 postid: postid,
513 status: status_value,
514 action: 'wpforo_delete_ajax'
515 }
516 }).done(function(response){
517 try{
518 response = $.parseJSON(response);
519 } catch (e) {
520 console.log(e);
521 }
522 if( response.stat == 1 ){
523 if(is_topic == -1){
524 $('#post-'+response.postid).fadeOut().delay(200);
525 }else{
526 window.location.assign(response.location);
527 }
528 $('#wpforo-load').invisible();
529 }else{
530 $('#wpforo-load').invisible();
531 }
532
533 wpforo_notice_show(response.notice);
534 });
535 }else{
536 $('#wpforo-load').invisible();
537 }
538 });
539
540
541 // Subscribe
542 $(document).on('click','.wpf-subscribe-forum, .wpf-subscribe-topic', function(){
543 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
544 var type = '';
545 var status = 'subscribe';
546 var clases = $(this).attr('class');
547
548 if( clases.indexOf("wpf-subscribe-forum") > -1 ){
549 type = 'forum';
550 }
551 if( clases.indexOf("wpf-subscribe-topic") > -1 ){
552 type = 'topic';
553 }
554
555 var postid_value = $(this).attr('id');
556 var itemid = postid_value.replace("wpfsubscribe-", "");
557
558 $.ajax({
559 type: 'POST',
560 url: wpf_ajax_obj.url,
561 data: {
562 itemid: itemid,
563 type: type,
564 status: status,
565 action: 'wpforo_subscribe_ajax'
566 }
567 }).done(function(response){
568 try{
569 response = $.parseJSON(response);
570 } catch (e) {
571 console.log(e);
572 }
573 if( response.stat == 1 ){
574 $("#wpfsubscribe-" + itemid).removeClass('wpf-subscribe-' + type).addClass('wpf-unsubscribe-' + type);
575 $("#wpfsubscribe-" + itemid).text( ' ' + wpf_ajax_obj.phrases.unsubscribe );
576 $('#wpforo-load').invisible();
577 }else{
578 $('#wpforo-load').invisible();
579 }
580
581 wpforo_notice_show(response.notice);
582 });
583
584 });
585
586 $(document).on('click','.wpf-unsubscribe-forum, .wpf-unsubscribe-topic', function(){
587 $("#wpf-msg-box").hide(); $('#wpforo-load').visible();
588 var type = '';
589 var button_phrase = '';
590 var status = 'unsubscribe';
591 var clases = $(this).attr('class');
592 if( clases.indexOf("wpf-unsubscribe-forum") > -1 ){
593 type = 'forum';
594 button_phrase = wpforo_ucwords(wpf_ajax_obj.phrases["subscribe for new topics"]);
595 }
596 if( clases.indexOf("wpf-unsubscribe-topic") > -1 ){
597 type = 'topic';
598 button_phrase = wpforo_ucwords(wpf_ajax_obj.phrases["subscribe for new replies"]);
599 }
600 var postid_value = $(this).attr('id');
601 var itemid = postid_value.replace("wpfsubscribe-", "");
602
603 $.ajax({
604 type: 'POST',
605 url: wpf_ajax_obj.url,
606 data: {
607 itemid: itemid,
608 type: type,
609 status: status,
610 action: 'wpforo_subscribe_ajax'
611 }
612 }).done(function(response){
613 try{
614 response = $.parseJSON(response);
615 } catch (e) {
616 console.log(e);
617 }
618 if( response.stat == 1 ){
619 $("#wpfsubscribe-" + itemid).removeClass('wpf-unsubscribe-' + type).addClass('wpf-subscribe-' + type);
620 $("#wpfsubscribe-" + itemid).text( ' ' + button_phrase );
621 $('#wpforo-load').invisible();
622 }else{
623 $('#wpforo-load').invisible();
624 }
625
626 wpforo_notice_show(response.notice);
627 });
628 });
629 });
630
631 function wpforo_ucwords (str) {
632 return (str + '').replace(/^([a-z])|\s+([a-z])/, function ($1) {
633 return $1.toUpperCase();
634 });
635 }