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.

104 lines
3.2KB

  1. /*
  2. * toggle-images.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-images.js';
  14. *
  15. */
  16. $(document).ready(function(){
  17. var hide_images = localStorage['hideimages'] ? true : false;
  18. $('<style type="text/css"> img.hidden{ opacity: 0.1; background: grey; border: 1px solid #000; } </style>').appendTo($('head'));
  19. var hideImage = function() {
  20. if ($(this).parent().data('expanded') == 'true') {
  21. $(this).parent().click();
  22. }
  23. $(this)
  24. .attr('data-orig', this.src)
  25. .attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==')
  26. .addClass('hidden');
  27. };
  28. var restoreImage = function() {
  29. $(this)
  30. .attr('src', $(this).attr('data-orig'))
  31. .removeClass('hidden');
  32. };
  33. // Fix for hide-images.js
  34. var show_hide_hide_images_buttons = function() {
  35. if (hide_images) {
  36. $('a.hide-image-link').each(function() {
  37. if ($(this).next().hasClass('show-image-link')) {
  38. $(this).next().hide();
  39. }
  40. $(this).hide().after('<span class="toggle-images-placeholder">'+_('hidden')+'</span>');
  41. });
  42. } else {
  43. $('span.toggle-images-placeholder').remove();
  44. $('a.hide-image-link').each(function() {
  45. if ($(this).next().hasClass('show-image-link')) {
  46. $(this).next().show();
  47. } else {
  48. $(this).show();
  49. }
  50. });
  51. }
  52. };
  53. var selector, event;
  54. if (window.Options && Options.get_tab('general')) {
  55. selector = '#toggle-images>input';
  56. event = 'change';
  57. Options.extend_tab("general", "<label id='toggle-images'><input type='checkbox' />"+_('Hide images')+"</label>");
  58. }
  59. else {
  60. selector = '#toggle-images a';
  61. event = 'click';
  62. $('hr:first').before('<div id="toggle-images" style="text-align:right"><a class="unimportant" href="javascript:void(0)">-</a></div>');
  63. $('div#toggle-images a')
  64. .text(hide_images ? _('Show images') : _('Hide images'));
  65. }
  66. $(selector)
  67. .on(event, function() {
  68. hide_images = !hide_images;
  69. if (hide_images) {
  70. $('img.post-image, .theme-catalog .thread>a>img').each(hideImage);
  71. localStorage.hideimages = true;
  72. } else {
  73. $('img.post-image, .theme-catalog .thread>a>img').each(restoreImage);
  74. delete localStorage.hideimages;
  75. }
  76. show_hide_hide_images_buttons();
  77. $(this).text(hide_images ? _('Show images') : _('Hide images'))
  78. });
  79. if (hide_images) {
  80. $('img.post-image, .theme-catalog .thread>a>img').each(hideImage);
  81. show_hide_hide_images_buttons();
  82. if (window.Options && Options.get_tab('general')) {
  83. $('#toggle-images>input').prop('checked', true);
  84. }
  85. }
  86. $(document).on('new_post', function(e, post) {
  87. if (hide_images) {
  88. $(post).find('img.post-image').each(hideImage);
  89. }
  90. });
  91. });