diff options
| author | 8chan <admin@8chan.co> | 2014-06-10 18:00:49 +0000 |
|---|---|---|
| committer | Fredrick Brennan <admin@8chan.co> | 2014-06-10 18:18:14 +0000 |
| commit | dfe8ddc34000685f5deaf504ffe78e8dd685681c (patch) | |
| tree | 26709ca0e3d2d1576edbdac8135de1ebeda54fa2 /js/no-animated-gif.js | |
| parent | e27c923b79e3d6d0817941bd3d7ca91576483397 (diff) | |
Disable-able animated GIFs in a non-shitty way (unlike wizardchan)
Diffstat (limited to 'js/no-animated-gif.js')
| -rw-r--r-- | js/no-animated-gif.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/js/no-animated-gif.js b/js/no-animated-gif.js new file mode 100644 index 00000000..cfdf757b --- /dev/null +++ b/js/no-animated-gif.js @@ -0,0 +1,51 @@ +/* + * no-animated-gif.js - Toggle GIF animated thumbnails when gifsicle is enabled + * + * Copyright (c) 2014 Fredrick Brennan <admin@8chan.co> + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/no-animated-gif.js'; + */ + +function unanimate_gif(e) { + var c = $('<canvas class="post-image"></canvas>'); + $(e).parent().prepend(c); + c.attr('width', $(e).width()); + c.attr('height',$(e).height()); + c[0].getContext('2d').drawImage(e, 0, 0, $(e).width(), $(e).height()); + $(e).hide(); +} + +function no_animated_gif() { + var anim_gifs = $('img.post-image[src$=".gif"]'); + localStorage.no_animated_gif = true; + $('#no-animated-gif>a').text(_('Animate GIFs')); + + $.each(anim_gifs, function(i, e) {unanimate_gif(e)} ); +} + +function animated_gif() { + $('canvas.post-image').remove(); + $('img.post-image').show(); + localStorage.no_animated_gif = false; + $('#no-animated-gif>a').text(_('Unanimate GIFs')); + +} + +if (active_page == 'thread' || active_page == 'index' || active_page == 'ukko') { + onready(function(){ + $('hr:first').before('<div id="no-animated-gif" style="text-align:right"><a class="unimportant" href="javascript:void(0)">'+_('Unanimate GIFs')+'</a></div>') + + $('#no-animated-gif').on('click', function() { + if (localStorage.no_animated_gif === 'true') { + animated_gif(); + } else { + no_animated_gif(); + } + }); + + if (localStorage.no_animated_gif === 'true') + $(document).ready(no_animated_gif); + }); +} |
