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.

91 lines
3.0KB

  1. /*
  2. * toggle-locked-threads.js
  3. *
  4. * Released under the MIT license
  5. * Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
  6. * Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
  7. *
  8. * Usage:
  9. * $config['additional_javascript'][] = 'js/jquery.min.js';
  10. * //$config['additional_javascript'][] = 'js/options.js';
  11. * //$config['additional_javascript'][] = 'js/style-select.js';
  12. * //$config['additional_javascript'][] = 'js/options/general.js';
  13. * $config['additional_javascript'][] = 'js/toggle-locked-threads.js';
  14. *
  15. */
  16. if (active_page == 'ukko' || active_page == 'index' || (window.Options && Options.get_tab('general')))
  17. $(document).ready(function(){
  18. var hide_locked_threads = localStorage['hidelockedthreads'] ? true : false;
  19. $('<style type="text/css"> img.hidden{ opacity: 0.1; background: grey; border: 1px solid #000; } </style>').appendTo($('head'));
  20. var hideLockedThread = function($thread) {
  21. if (active_page == 'ukko' || active_page == 'index')
  22. $thread
  23. .hide()
  24. .addClass('hidden');
  25. };
  26. var restoreLockedThread = function($thread) {
  27. $thread
  28. .show()
  29. .removeClass('hidden');
  30. };
  31. var getThreadFromIcon = function($icon) {
  32. return $icon.parent().parent().parent()
  33. };
  34. var selector, event;
  35. if (window.Options && Options.get_tab('general')) {
  36. selector = '#toggle-locked-threads>input';
  37. event = 'change';
  38. Options.extend_tab("general", "<label id='toggle-locked-threads'><input type='checkbox' /> "+_('Hide locked threads')+"</label>");
  39. }
  40. else {
  41. selector = '#toggle-locked-threads a';
  42. event = 'click';
  43. $('hr:first').before('<div id="toggle-locked-threads" style="text-align:right"><a class="unimportant" href="javascript:void(0)">-</a></div>');
  44. }
  45. $('div#toggle-locked-threads a')
  46. .text(hide_locked_threads ? _('Show locked threads') : _('Hide locked threads'));
  47. $(selector)
  48. .on(event, function() {
  49. hide_locked_threads = !hide_locked_threads;
  50. if (hide_locked_threads) {
  51. $('img.icon[title="Locked"], i.fa-lock.fa').each(function() {
  52. hideLockedThread(getThreadFromIcon($(this)));
  53. });
  54. localStorage.hidelockedthreads = true;
  55. } else {
  56. $('img.icon[title="Locked"], i.fa-lock.fa').each(function() {
  57. restoreLockedThread(getThreadFromIcon($(this)));
  58. });
  59. delete localStorage.hidelockedthreads;
  60. }
  61. $(this).text(hide_locked_threads ? _('Show locked threads') : _('Hide locked threads'))
  62. });
  63. if (hide_locked_threads) {
  64. $('img.icon[title="Locked"], i.fa-lock.fa').each(function() {
  65. hideLockedThread(getThreadFromIcon($(this)));
  66. });
  67. if (window.Options && Options.get_tab('general')) {
  68. $('#toggle-locked-threads>input').prop('checked', true);
  69. }
  70. }
  71. $(document).on('new_post', function(e, post) {
  72. if (hide_locked_threads) {
  73. $(post).find('img.icon[title="Locked"], i.fa-lock.fa').each(function() {
  74. hideLockedThread(getThreadFromIcon($(this)));
  75. });
  76. }
  77. });
  78. });