[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/jscripts/ -> thread.js (source)

   1  var Thread = {
   2      init: function()
   3      {
   4          $(function(){
   5              Thread.quickEdit();
   6              Thread.initQuickReply();
   7              Thread.initMultiQuote();
   8  
   9              if(thread_deleted == "1")
  10              {
  11                  $("#quick_reply_form, .new_reply_button, .thread_tools, .inline_rating").hide();
  12                  $("#moderator_options_selector option.option_mirage").attr("disabled","disabled");
  13              }
  14  
  15              visible_replies = parseInt(visible_replies, 10);
  16              Thread.splitToolHandler();
  17              
  18              if($("#moderator_options_selector").length !== 0) {
  19                  $("#moderator_options_selector").on('change', function() {
  20                      $("#moderator_options").trigger('submit');
  21                  });
  22  
  23                  $("#moderator_options").on('submit', function(){
  24                      if($("#moderator_options_selector").val() == "") {
  25                          $.jGrowl(lang.select_tool, {theme:'jgrowl_error'});
  26                          return false;
  27                      }
  28                  });
  29              }
  30              
  31              // Set spinner image
  32              $('#quickreply_spinner img').attr('src', spinner_image);
  33          });
  34      },
  35  
  36      initMultiQuote: function()
  37      {
  38          var quoted = Cookie.get('multiquote');
  39          if(quoted)
  40          {
  41              var post_ids = quoted.split("|");
  42  
  43              $.each(post_ids, function(key, value) {
  44                  var mquote_a = $("#multiquote_"+value).closest('a');
  45                  if(mquote_a.length)
  46                  {
  47                      mquote_a.removeClass('postbit_multiquote').addClass('postbit_multiquote_on');
  48                  }
  49              });
  50  
  51              var mquote_quick = $('#quickreply_multiquote');
  52              if(mquote_quick.length)
  53              {
  54                  mquote_quick.show();
  55              }
  56          }
  57          return true;
  58      },
  59  
  60      multiQuote: function(pid)
  61      {
  62          var new_post_ids = new Array();
  63          var quoted = Cookie.get("multiquote");
  64          var is_new = true;
  65          var deleted = false;
  66          if($("#pid" + pid).next("div.post").hasClass('deleted_post'))
  67          {
  68              $.jGrowl(lang.post_deleted_error, {theme:'jgrowl_error'});
  69              deleted = true;
  70          }
  71  
  72          if(quoted && !deleted)
  73          {
  74              var post_ids = quoted.split("|");
  75  
  76              $.each(post_ids, function(key, post_id) {
  77                  if(post_id != pid && post_id != '')
  78                  {
  79                      new_post_ids[new_post_ids.length] = post_id;
  80                  }
  81                  else if(post_id == pid)
  82                  {
  83                      is_new = false;
  84                  }
  85              });
  86          }
  87  
  88          var mquote_a = $("#multiquote_"+pid).closest('a')
  89          if(is_new == true && !deleted)
  90          {
  91              new_post_ids[new_post_ids.length] = pid;
  92              mquote_a.removeClass('postbit_multiquote').addClass('postbit_multiquote_on');
  93          }
  94          else
  95          {
  96              mquote_a.removeClass('postbit_multiquote_on').addClass('postbit_multiquote');
  97          }
  98  
  99          var mquote_quick = $('#quickreply_multiquote');
 100          if(mquote_quick.length)
 101          {
 102              if(new_post_ids.length)
 103              {
 104                  mquote_quick.show();
 105              }
 106              else
 107              {
 108                  mquote_quick.hide();
 109              }
 110          }
 111          Cookie.set("multiquote", new_post_ids.join("|"));
 112      },
 113  
 114      loadMultiQuoted: function()
 115      {
 116          if(use_xmlhttprequest == 1)
 117          {
 118              // Spinner!
 119              var mquote_spinner = $('#quickreply_spinner');
 120              mquote_spinner.show();
 121  
 122              $.ajax(
 123              {
 124                  url: 'xmlhttp.php?action=get_multiquoted&load_all=1',
 125                  type: 'get',
 126                  complete: function (request, status)
 127                  {
 128                      Thread.multiQuotedLoaded(request, status);
 129  
 130                      // Get rid of spinner
 131                      mquote_spinner.hide();
 132                  }
 133              });
 134  
 135              return false;
 136          }
 137          else
 138          {
 139              return true;
 140          }
 141      },
 142  
 143      multiQuotedLoaded: function(request)
 144      {
 145          var json = JSON.parse(request.responseText);
 146          if(typeof json == 'object')
 147          {
 148              if(json.hasOwnProperty("errors"))
 149              {
 150                  $.each(json.errors, function(i, message)
 151                  {
 152                      $.jGrowl(lang.post_fetch_error + ' ' + message, {theme:'jgrowl_error'});
 153                  });
 154                  return false;
 155              }
 156          }
 157  
 158          if(typeof MyBBEditor !== 'undefined' && MyBBEditor !== null)
 159          {
 160              MyBBEditor.insert(json.message);
 161          }
 162          else
 163          {
 164              var id = $('#message');
 165              if(id.value)
 166              {
 167                  id.value += "\n";
 168              }
 169              id.val(id.val() + json.message);
 170          }
 171  
 172          Thread.clearMultiQuoted();
 173          $('#quickreply_multiquote').hide();
 174          $('#quoted_ids').val('all');
 175  
 176          $('#message').trigger('focus');
 177      },
 178  
 179      clearMultiQuoted: function()
 180      {
 181          $('#quickreply_multiquote').hide();
 182          var quoted = Cookie.get("multiquote");
 183          if(quoted)
 184          {
 185              var post_ids = quoted.split("|");
 186  
 187              $.each(post_ids, function(key, post_id) {
 188                  var mquote_a = $("#multiquote_"+post_id).closest('a');
 189                  if(mquote_a.length)
 190                  {
 191                      mquote_a.removeClass('postbit_multiquote_on').addClass('postbit_multiquote');
 192                  }
 193              });
 194          }
 195          Cookie.unset('multiquote');
 196      },
 197  
 198      quickEdit: function(el)
 199      {
 200          if(typeof el === 'undefined' || !el.length) el = '.post_body';
 201  
 202          $(el).each(function()
 203          {
 204              // Take pid out of the id attribute
 205              id = $(this).attr('id');
 206              pid = id.replace( /[^\d.]/g, '');
 207  
 208              $('#pid_' + pid).editable("xmlhttp.php?action=edit_post&do=update_post&pid=" + pid + '&my_post_key=' + my_post_key,
 209              {
 210                  indicator: spinner,
 211                  loadurl: "xmlhttp.php?action=edit_post&do=get_post&pid=" + pid,
 212                  type: "textarea",
 213                  rows: 12,
 214                  submit: lang.save_changes,
 215                  cancel: lang.cancel_edit,
 216                  placeholder: "",
 217                  event: "edit" + pid, // Triggered by the event "edit_[pid]",
 218                  onblur: "ignore",
 219                  dataType: "json",
 220                  submitdata: function (values, settings)
 221                  {
 222                      id = $(this).attr('id');
 223                      pid = id.replace( /[^\d.]/g, '');
 224                      $("#quickedit_" + pid + "_editreason_original").val($("#quickedit_" + pid + "_editreason").val());
 225                      return {
 226                          editreason: $("#quickedit_" + pid + "_editreason").val()
 227                      }
 228                  },
 229                  callback: function(values, settings)
 230                  {
 231                      id = $(this).attr('id');
 232                      pid = id.replace( /[^\d.]/g, '');
 233  
 234                      var json = JSON.parse(values);
 235                      if(typeof json == 'object')
 236                      {
 237                          if(json.hasOwnProperty("errors"))
 238                          {
 239                              $(".jGrowl").jGrowl("close");
 240  
 241                              $.each(json.errors, function(i, message)
 242                              {
 243                                  $.jGrowl(lang.quick_edit_update_error + ' ' + message, {theme:'jgrowl_error'});
 244                              });
 245                              $(this).html($('#pid_' + pid + '_temp').html());
 246                          }
 247                          else if(json.hasOwnProperty("moderation_post"))
 248                          {
 249                              $(".jGrowl").jGrowl("close");
 250  
 251                              $(this).html(json.message);
 252  
 253                              // No more posts on this page? (testing for "1" as the last post would be removed here)
 254                              if($('.post').length == 1)
 255                              {
 256                                  alert(json.moderation_post);
 257                                  window.location = json.url;
 258                              }
 259                              else
 260                              {
 261                                  $.jGrowl(json.moderation_post, {theme:'jgrowl_success'});
 262                                  $('#post_' + pid).slideToggle();
 263                              }
 264                          }
 265                          else if(json.hasOwnProperty("moderation_thread"))
 266                          {
 267                              $(".jGrowl").jGrowl("close");
 268  
 269                              $(this).html(json.message);
 270  
 271                              alert(json.moderation_thread);
 272  
 273                              // Redirect user to forum
 274                              window.location = json.url;
 275                          }
 276                          else
 277                          {
 278                              // Change html content
 279                              $(this).html(json.message);
 280                              $('#edited_by_' + pid).html(json.editedmsg);
 281                          }
 282                      }
 283                      else
 284                      {
 285                          // Change html content
 286                          $(this).html(json.message);
 287                          $('#edited_by_' + pid).html(json.editedmsg);
 288                      }
 289                      $('#pid_' + pid + '_temp').remove();
 290                  }
 291              });
 292          });
 293  
 294          $('.quick_edit_button').each(function()
 295          {
 296              $(this).on("click", function(e)
 297              {
 298                  e.preventDefault();
 299  
 300                  // Take pid out of the id attribute
 301                  id = $(this).attr('id');
 302                  pid = id.replace( /[^\d.]/g, '');
 303                  if($("#pid" + pid).next("div.post").hasClass('deleted_post'))
 304                  {
 305                      $.jGrowl(lang.post_deleted_error, {theme:'jgrowl_error'});
 306                      return false;
 307                  }
 308  
 309                  // Create a copy of the post
 310                  if($('#pid_' + pid + '_temp').length == 0)
 311                  {
 312                      $('#pid_' + pid).clone().attr('id','pid_' + pid + '_temp').appendTo("body").hide();
 313                  }
 314  
 315                  // Trigger the edit event
 316                  $('#pid_' + pid).trigger("edit" + pid);
 317  
 318                  // Edit Reason
 319                  $('#pid_' + pid + ' textarea').attr('id', 'quickedit_' + pid);
 320                  if(allowEditReason == 1 && $('#quickedit_' + pid + '_editreason').length == 0)
 321                  {
 322                      edit_el = $('#editreason_' + pid + '_original').clone().attr('id','editreason_' + pid);
 323                      edit_el.children('#quickedit_' + pid + '_editreason_original').attr('id','quickedit_' + pid + '_editreason');
 324                      edit_el.insertAfter('#quickedit_' + pid).show();
 325                  }
 326              });
 327          });
 328  
 329          return false;
 330      },
 331  
 332      initQuickReply: function()
 333      {
 334          if($('#quick_reply_form').length && use_xmlhttprequest == 1)
 335          {
 336              // Bind closing event to our popup menu
 337              $('#quick_reply_submit').on('click', function(e) {
 338                  return Thread.quickReply(e);
 339              });
 340          }
 341      },
 342  
 343      quickReply: function(e)
 344      {
 345          e.stopPropagation();
 346  
 347          if(this.quick_replying)
 348          {
 349              return false;
 350          }
 351  
 352          this.quick_replying = 1;
 353          var post_body = $('#quick_reply_form').serialize();
 354  
 355          // Spinner!
 356          var qreply_spinner = $('#quickreply_spinner');
 357          qreply_spinner.show();
 358  
 359          $.ajax(
 360          {
 361              url: 'newreply.php?ajax=1',
 362              type: 'post',
 363              data: post_body,
 364              dataType: 'html',
 365              complete: function (request, status)
 366              {
 367                    Thread.quickReplyDone(request, status);
 368  
 369                  // Get rid of spinner
 370                  qreply_spinner.hide();
 371                }
 372          });
 373  
 374          return false;
 375      },
 376  
 377      quickReplyDone: function(request, status)
 378      {
 379          this.quick_replying = 0;
 380  
 381          var json = JSON.parse(request.responseText);
 382          if(typeof json == 'object')
 383          {
 384              if(json.hasOwnProperty("errors"))
 385              {
 386                  $(".jGrowl").jGrowl("close");
 387  
 388                  $.each(json.errors, function(i, message)
 389                  {
 390                      $.jGrowl(lang.quick_reply_post_error + ' ' + message, {theme:'jgrowl_error'});
 391                  });
 392                  $('#quickreply_spinner').hide();
 393              }
 394          }
 395  
 396          if($('#captcha_trow').length)
 397          {
 398              cap = json.data.match(/^<captcha>([0-9a-zA-Z]+)(\|([0-9a-zA-Z]+)|)<\/captcha>/);
 399              if(cap)
 400              {
 401                  json.data = json.data.replace(/^<captcha>(.*)<\/captcha>/, '');
 402  
 403                  if($("#captcha_img").length)
 404                  {
 405                      if(cap[1])
 406                      {
 407                          imghash = cap[1];
 408                          $('#imagehash').val(imghash);
 409                          if(cap[3])
 410                          {
 411                              $('#imagestring').attr('type', 'hidden').val(cap[3]);
 412                              // hide the captcha
 413                              $('#captcha_trow').hide();
 414                          }
 415                          else
 416                          {
 417                              $('#captcha_img').attr('src', "captcha.php?action=regimage&imagehash="+imghash);
 418                              $('#imagestring').attr('type', 'text').val('');
 419                              $('#captcha_trow').show();
 420                          }
 421                      }
 422                  }
 423              }
 424          }
 425  
 426          if(json.hasOwnProperty("errors"))
 427              return false;
 428  
 429          if(json.data.match(/id="post_([0-9]+)"/))
 430          {
 431              var pid = json.data.match(/id="post_([0-9]+)"/)[1];
 432              var post = document.createElement("div");
 433  
 434              $('#posts').append(json.data);
 435  
 436              ++visible_replies;
 437              Thread.splitToolHandler();
 438              
 439              if (typeof inlineModeration != "undefined") // Guests don't have this object defined
 440                  $("#inlinemod_" + pid).on('change', inlineModeration.checkItem);
 441  
 442              Thread.quickEdit("#pid_" + pid);
 443  
 444              // Eval javascript
 445              $(json.data).filter("script").each(function(e) {
 446                  eval($(this).text());
 447              });
 448  
 449              $('#quick_reply_form')[0].reset();
 450  
 451              var lastpid = $('#lastpid');
 452              if(lastpid.length)
 453              {
 454                  lastpid.val(pid);
 455              }
 456          }
 457          else
 458          {
 459              // Eval javascript
 460              $(json.data).filter("script").each(function(e) {
 461                  eval($(this).text());
 462              });
 463          }
 464  
 465          $(".jGrowl").jGrowl("close");
 466      },
 467  
 468      showIgnoredPost: function(pid)
 469      {
 470          $('#ignored_post_'+pid).slideToggle("slow");
 471          $('#post_'+pid).slideToggle("slow");
 472      },
 473  
 474      showDeletedPost: function(pid)
 475      {
 476          $('#deleted_post_'+pid).slideToggle("slow");
 477          $('#post_'+pid).slideToggle("slow");
 478      },
 479  
 480      deletePost: function(pid)
 481      {
 482          MyBB.prompt(quickdelete_confirm, {
 483              buttons:[
 484                      {title: yes_confirm, value: true},
 485                      {title: no_confirm, value: false}
 486              ],
 487              submit: function(e,v,m,f){
 488                  if(v == true)
 489                  {
 490                      $.ajax(
 491                      {
 492                          url: 'editpost.php?ajax=1&action=deletepost&delete=1&my_post_key='+my_post_key+'&pid='+pid,
 493                          type: 'post',
 494                          complete: function (request, status)
 495                          {
 496                              var json = JSON.parse(request.responseText);
 497                              if(json.hasOwnProperty("errors"))
 498                              {
 499                                  $.each(json.errors, function(i, message)
 500                                  {
 501                                      $.jGrowl(lang.quick_delete_error + ' ' + message, {theme:'jgrowl_error'});
 502                                  });
 503                              }
 504                              else if(json.hasOwnProperty("data"))
 505                              {
 506                                  // Soft deleted
 507                                  if(json.data == 1)
 508                                  {
 509                                      // Change CSS class of div 'post_[pid]'
 510                                      $("#post_"+pid).addClass("unapproved_post deleted_post");
 511                                      if(json.first == 1)
 512                                      {
 513                                          $("#quick_reply_form, .thread_tools, .new_reply_button, .inline_rating").hide();
 514                                          $("#moderator_options_selector option.option_mirage").attr("disabled","disabled");
 515                                          $("#moderator_options_selector option[value='softdeletethread']").val("restorethread").text(lang.restore_thread);
 516                                          thread_deleted = "1";
 517                                      }
 518                                      $.jGrowl(lang.quick_delete_success, {theme:'jgrowl_success'});
 519                                  }
 520                                  else if(json.data == 2)
 521                                  {
 522                                      // Actually deleted
 523                                      $('#post_'+pid).slideToggle("slow");
 524  
 525                                      --visible_replies;
 526                                      Thread.splitToolHandler();
 527                                      $.jGrowl(lang.quick_delete_success, {theme:'jgrowl_success'});
 528                                  }
 529                                  else if(json.data == 3)
 530                                  {
 531                                      // deleted thread --> redirect
 532  
 533                                      if(!json.hasOwnProperty("url"))
 534                                      {
 535                                          $.jGrowl(lang.unknown_error, {theme:'jgrowl_error'});
 536                                      }
 537  
 538                                      // set timeout for redirect
 539                                      window.setTimeout(function()
 540                                      {
 541                                           window.location = json.url;
 542                                      }, 3000);
 543  
 544                                      // print success message
 545                                      $.jGrowl(lang.quick_delete_thread_success, {theme:'jgrowl_success'});
 546                                  }
 547                              }
 548                              else
 549                              {
 550                                  $.jGrowl(lang.unknown_error, {theme:'jgrowl_error'});
 551                              }
 552                          }
 553                      });
 554                  }
 555              }
 556          });
 557  
 558          return false;
 559      },
 560  
 561  
 562      restorePost: function(pid)
 563      {
 564          MyBB.prompt(quickrestore_confirm, {
 565              buttons:[
 566                      {title: yes_confirm, value: true},
 567                      {title: no_confirm, value: false}
 568              ],
 569              submit: function(e,v,m,f){
 570                  if(v == true)
 571                  {
 572                      $.ajax(
 573                      {
 574                          url: 'editpost.php?ajax=1&action=restorepost&restore=1&my_post_key='+my_post_key+'&pid='+pid,
 575                          type: 'post',
 576                          complete: function (request, status)
 577                          {
 578                              var json = JSON.parse(request.responseText);
 579                              if(json.hasOwnProperty("errors"))
 580                              {
 581                                  $.each(json.errors, function(i, message)
 582                                  {
 583                                      $.jGrowl(lang.quick_restore_error + ' ' + message, {theme:'jgrowl_error'});
 584                                  });
 585                              }
 586                              else if(json.hasOwnProperty("data"))
 587                              {
 588                                  // Change CSS class of div 'post_[pid]'
 589                                  $("#post_"+pid).removeClass("unapproved_post deleted_post");
 590                                  if(json.first == 1)
 591                                  {
 592                                      $("#quick_reply_form, .thread_tools, .new_reply_button, .inline_rating").show();
 593                                      $("#moderator_options_selector option.option_mirage").prop("disabled", false);
 594                                      $("#moderator_options_selector option[value='restorethread']").val("softdeletethread").text(lang.softdelete_thread);
 595                                      thread_deleted = "";
 596                                  }
 597  
 598                                  $.jGrowl(lang.quick_restore_success, {theme:'jgrowl_success'});
 599                              }
 600                              else
 601                              {
 602                                  $.jGrowl(lang.unknown_error, {theme:'jgrowl_error'});
 603                              }
 604                          }
 605                      });
 606                  }
 607              }
 608          });
 609  
 610          return false;
 611      },
 612  
 613      viewNotes: function(tid)
 614      {
 615          MyBB.popupWindow("/moderation.php?action=viewthreadnotes&tid="+tid+"&modal=1");
 616      },
 617  
 618      splitToolHandler: function()
 619      {
 620          if($(thread_deleted !== "1" && "#moderator_options_selector").length !== 0){
 621              var splitTool = $("#moderator_options_selector").find("option[value=split]");
 622              if(visible_replies > 0) {
 623                  splitTool.prop("disabled", false);
 624              } else {
 625                  splitTool.attr("disabled","disabled");
 626              }
 627          }
 628      }
 629  };
 630  
 631  Thread.init();


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref