The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.4KB

  1. /*
  2. * quick-posts-controls.js
  3. * https://github.com/savetheinternet/Tinyboard/blob/master/js/quick-posts-controls.js
  4. *
  5. * Released under the MIT license
  6. * Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
  7. * Copyright (c) 2013 undido <firekid109@hotmail.com>
  8. * Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
  9. *
  10. * Usage:
  11. * $config['additional_javascript'][] = 'js/jquery.min.js';
  12. * $config['additional_javascript'][] = 'js/quick-post-controls.js';
  13. *
  14. */
  15. $(document).ready(function(){
  16. var open_form = function() {
  17. var thread = $(this).parent().parent().hasClass('op');
  18. var id = $(this).attr('name').match(/^delete_(\d+)$/)[1];
  19. var submitButton;
  20. if(this.checked) {
  21. var post_form = $('<form class="post-actions" method="post" style="margin:10px 0 0 0">' +
  22. '<div style="text-align:right">' +
  23. (!thread ? '<hr>' : '') +
  24. '<input type="hidden" name="delete_' + id + '">' +
  25. '<label for="password_' + id + '">'+_("Password")+'</label>: ' +
  26. '<input id="password_' + id + '" type="password" name="password" size="11" maxlength="18">' +
  27. '<input title="'+_('Delete file only')+'" type="checkbox" name="file" id="delete_file_' + id + '">' +
  28. '<label for="delete_file_' + id + '">'+_('File')+'</label>' +
  29. ' <input type="submit" name="delete" value="'+_('Delete')+'">' +
  30. '<br>' +
  31. '<label for="reason_' + id + '">'+_('Reason')+'</label>: ' +
  32. '<input id="reason_' + id + '" type="text" name="reason" size="20" maxlength="100">' +
  33. ' <input type="submit" name="report" value="'+_('Report')+'">' +
  34. '</div>' +
  35. '</form>');
  36. if($('form[name="post"]:first').size()){
  37. var board=$(this).parent().parent().parent().attr("data-board");
  38. post_form
  39. .attr('action', $('form[name="post"]:first').attr('action'))
  40. .append('<input type="hidden" value="'+board+'" name="board" />');
  41. }else{
  42. var board=$(this).parent().parent().parent().attr("data-board");
  43. if(board){
  44. post_form.attr('action', '/post.php'); //doesn't respect $config["root"] but...
  45. post_form.append('<input type="hidden" value="'+board+'" name="board" />');
  46. }else{
  47. return;//better not to show a form if it isn't going to work
  48. }
  49. }
  50. post_form.find('input:not([type="checkbox"]):not([type="submit"]):not([type="hidden"])').keypress(function(e) {
  51. if(e.which == 13) {
  52. e.preventDefault();
  53. if($(this).attr('name') == 'password') {
  54. post_form.find('input[name=delete]').click();
  55. } else if($(this).attr('name') == 'reason') {
  56. post_form.find('input[name=report]').click();
  57. }
  58. return false;
  59. }
  60. return true;
  61. });
  62. post_form.find('input[type="password"]').val(localStorage.password);
  63. if(thread) {
  64. post_form.prependTo($(this).parent().parent().find('div.body'));
  65. } else {
  66. post_form.appendTo($(this).parent().parent());
  67. //post_form.insertBefore($(this));
  68. }
  69. $(window).trigger('quick-post-controls', post_form);
  70. } else {
  71. var elm = $(this).parent().parent().find('form');
  72. if(elm.attr('class') == 'post-actions')
  73. elm.remove();
  74. }
  75. };
  76. var init_qpc = function() {
  77. $(this).change(open_form);
  78. if(this.checked)
  79. $(this).trigger('change');
  80. };
  81. $('div.post input[type=checkbox].delete').each(init_qpc);
  82. $(document).on('new_post', function(e, post) {
  83. $(post).find('input[type=checkbox].delete').each(init_qpc);
  84. });
  85. });