2014-06-10 20:00:49 +02:00
|
|
|
/*
|
|
|
|
* no-animated-gif.js - Toggle GIF animated thumbnails when gifsicle is enabled
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Fredrick Brennan <admin@8chan.co>
|
2014-09-20 22:10:44 +02:00
|
|
|
* Copyright (c) 2014 Marcin Łabanowski <marcin@6irc.net>
|
2014-06-10 20:00:49 +02:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
2014-09-20 22:10:44 +02:00
|
|
|
* //$config['additional_javascript'][] = 'js/options.js';
|
|
|
|
* //$config['additional_javascript'][] = 'js/style-select.js';
|
|
|
|
* //$config['additional_javascript'][] = 'js/options/general.js';
|
2014-06-10 20:00:49 +02:00
|
|
|
* $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());
|
2014-06-10 20:50:14 +02:00
|
|
|
function draw_image() {
|
|
|
|
c[0].getContext('2d').drawImage(e, 0, 0, $(e).width(), $(e).height())
|
|
|
|
};
|
|
|
|
|
|
|
|
// Fix drawing image before loaded. Note that Chrome needs to check .complete because load() is NOT called if loaded from cache.
|
|
|
|
if (!e.complete) {
|
|
|
|
e.onload = draw_image;
|
|
|
|
} else {
|
|
|
|
draw_image();
|
|
|
|
}
|
|
|
|
|
2014-08-10 22:54:47 +02:00
|
|
|
$(e).addClass("unanimated").hide();
|
2014-06-10 20:00:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function no_animated_gif() {
|
|
|
|
var anim_gifs = $('img.post-image[src$=".gif"]');
|
|
|
|
localStorage.no_animated_gif = true;
|
|
|
|
$('#no-animated-gif>a').text(_('Animate GIFs'));
|
2014-09-20 22:10:44 +02:00
|
|
|
$('#no-animated-gif>input').prop('checked', true);
|
2014-06-10 20:00:49 +02:00
|
|
|
|
|
|
|
$.each(anim_gifs, function(i, e) {unanimate_gif(e)} );
|
|
|
|
}
|
|
|
|
|
|
|
|
function animated_gif() {
|
|
|
|
$('canvas.post-image').remove();
|
2014-08-10 22:54:47 +02:00
|
|
|
$('img.post-image').removeClass("unanimated").show();
|
2014-06-10 20:00:49 +02:00
|
|
|
localStorage.no_animated_gif = false;
|
|
|
|
$('#no-animated-gif>a').text(_('Unanimate GIFs'));
|
2014-09-20 22:10:44 +02:00
|
|
|
$('#no-animated-gif>input').prop('checked', false);
|
2014-06-10 20:00:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (active_page == 'thread' || active_page == 'index' || active_page == 'ukko') {
|
2014-09-20 22:10:44 +02:00
|
|
|
$(function(){
|
|
|
|
var selector, event;
|
|
|
|
if (window.Options && Options.get_tab('general')) {
|
|
|
|
selector = '#no-animated-gif>input';
|
|
|
|
event = 'change';
|
|
|
|
Options.extend_tab("general", "<label id='no-animated-gif'><input type='checkbox' /> "+_('Unanimate GIFs')+"</label>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
selector = '#no-animated-gif';
|
|
|
|
event = 'click';
|
|
|
|
$('hr:first').before('<div id="no-animated-gif" style="text-align:right"><a class="unimportant" href="javascript:void(0)">'+_('Unanimate GIFs')+'</a></div>')
|
|
|
|
}
|
2014-06-10 20:00:49 +02:00
|
|
|
|
2014-09-20 22:10:44 +02:00
|
|
|
$(selector).on(event, function() {
|
2014-06-10 20:00:49 +02:00
|
|
|
if (localStorage.no_animated_gif === 'true') {
|
|
|
|
animated_gif();
|
|
|
|
} else {
|
|
|
|
no_animated_gif();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (localStorage.no_animated_gif === 'true')
|
2014-09-20 22:10:44 +02:00
|
|
|
no_animated_gif();
|
2014-06-10 20:00:49 +02:00
|
|
|
});
|
|
|
|
}
|