diff options
| author | czaks <marcin@6irc.net> | 2013-07-27 01:04:36 -0400 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2013-07-27 01:04:36 -0400 |
| commit | 64a66db6131dc2d86d9499836d64e8e35f46bf33 (patch) | |
| tree | 9e88e639b99d80d38eb72a8aa0818f3b2d4bd035 /js/toggle-images.js | |
| parent | e3cb427feefbbb4fd6a5e76ce77ef80a240941f1 (diff) | |
| parent | 1c33285c81efe174f09e99b15be81f527c0f8ae0 (diff) | |
Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
Conflicts:
js/hide-threads.js
js/inline-expanding.js
stylesheets/style.css
Diffstat (limited to 'js/toggle-images.js')
| -rw-r--r-- | js/toggle-images.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/js/toggle-images.js b/js/toggle-images.js new file mode 100644 index 00000000..74f2fab4 --- /dev/null +++ b/js/toggle-images.js @@ -0,0 +1,77 @@ +/* + * toggle-images.js + * + * Released under the MIT license + * Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org> + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/toggle-images.js'; + * + */ + +$(document).ready(function(){ + var hide_images = localStorage['hideimages'] ? true : false; + + $('<style type="text/css"> img.hidden{ opacity: 0.1; background: grey; border: 1px solid #000; } </style>').appendTo($('head')); + + var hideImage = function() { + if ($(this).parent()[0].dataset.expanded == 'true') { + $(this).parent().click(); + } + $(this) + .attr('data-orig', this.src) + .attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==') + .addClass('hidden'); + }; + + var restoreImage = function() { + $(this) + .attr('src', $(this).attr('data-orig')) + .removeClass('hidden'); + }; + + // Fix for hide-images.js + var show_hide_hide_images_buttons = function() { + if (hide_images) { + $('a.hide-image-link').each(function() { + if ($(this).next().hasClass('show-image-link')) { + $(this).next().hide(); + } + $(this).hide().after('<span class="toggle-images-placeholder">hidden</span>'); + }); + } else { + $('span.toggle-images-placeholder').remove(); + $('a.hide-image-link').each(function() { + if ($(this).next().hasClass('show-image-link')) { + $(this).next().show(); + } else { + $(this).show(); + } + }); + } + }; + + $('hr:first').before('<div id="toggle-images" style="text-align:right"><a class="unimportant" href="javascript:void(0)">-</a></div>'); + $('div#toggle-images a') + .text((hide_images ? 'Show' : 'Hide') + ' images') + .click(function() { + hide_images = !hide_images; + if (hide_images) { + $('div > a > img').each(hideImage); + localStorage.hideimages = true; + } else { + $('div > a > img').each(restoreImage); + delete localStorage.hideimages; + } + + show_hide_hide_images_buttons(); + + $(this).text((hide_images ? 'Show' : 'Hide') + ' images') + }); + + if (hide_images) { + $('div > a > img').each(hideImage); + show_hide_hide_images_buttons(); + } +}); |
