/* * 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() { 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('hidden'); }); } 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#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(); } });