From baa6793516242890222d3b4c94cac3f31649bd3b Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 26 Jul 2013 19:39:11 -0400 Subject: [PATCH] toggle-images.js (this was written last year, but I never pushed it to git) --- js/toggle-images.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 js/toggle-images.js diff --git a/js/toggle-images.js b/js/toggle-images.js new file mode 100644 index 00000000..006b3622 --- /dev/null +++ b/js/toggle-images.js @@ -0,0 +1,50 @@ +/* + * toggle-images.js + * + * Released under the MIT license + * Copyright (c) 2012 Michael Save + * + * 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; + + $('').appendTo($('head')); + + var hideImage = function() { + $(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'); + }; + + $('hr:first').before(''); + $('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; + } + + $(this).text((hide_images ? 'Show' : 'Hide') + ' images') + }); + + if (hide_images) { + $('div > a > img').each(hideImage); + } +});