From dfe8ddc34000685f5deaf504ffe78e8dd685681c Mon Sep 17 00:00:00 2001 From: 8chan Date: Tue, 10 Jun 2014 18:00:49 +0000 Subject: [PATCH 1/3] Disable-able animated GIFs in a non-shitty way (unlike wizardchan) --- js/inline-expanding.js | 12 ++++++++++++ js/no-animated-gif.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ stylesheets/style.css | 10 ++-------- 3 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 js/no-animated-gif.js diff --git a/js/inline-expanding.js b/js/inline-expanding.js index 04d9298f..5bbfa0a0 100644 --- a/js/inline-expanding.js +++ b/js/inline-expanding.js @@ -27,9 +27,17 @@ onready(function(){ if (!this.dataset.src) { this.parentNode.removeAttribute('style'); this.dataset.expanded = 'true'; + + if (this.childNodes[0].tagName === 'CANVAS') { + this.removeChild(this.childNodes[0]); + this.childNodes[0].style.display = 'block'; + } + this.dataset.src= this.childNodes[0].src; this.dataset.width = this.childNodes[0].style.width; this.dataset.height = this.childNodes[0].style.height; + + this.childNodes[0].src = this.href; this.childNodes[0].style.width = 'auto'; this.childNodes[0].style.height = 'auto'; @@ -48,6 +56,10 @@ onready(function(){ delete this.dataset.src; delete this.childNodes[0].style.opacity; delete this.childNodes[0].style.filter; + + if (localStorage.no_animated_gif === 'true' && typeof unanimate_gif === 'function') { + unanimate_gif(this.childNodes[0]); + } } return false; } 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 + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/no-animated-gif.js'; + */ + +function unanimate_gif(e) { + var c = $(''); + $(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('') + + $('#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); + }); +} diff --git a/stylesheets/style.css b/stylesheets/style.css index 58e3f4ba..664bf717 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -145,13 +145,13 @@ img.banner, img.board_image { border: 1px solid #a9a9a9; margin: 12px auto 0 auto; } -img.post-image { +.post-image { display: block; float: left; margin: 10px 20px; border: none; } -div.post img.post-image { +div.post .post-image { padding: 5px; margin: 5px 20px 0 0; } @@ -623,12 +623,6 @@ form.ban-appeal textarea { } /* Containerchan */ - video.post-image { - display: block; - float: left; - margin: 10px 20px; - border: none; - } div.post video.post-image { padding: 0px; margin: 10px 25px 5px 5px; From 5a02cd61db118d08fe76f880cf57606b083fcea7 Mon Sep 17 00:00:00 2001 From: 8chan Date: Tue, 10 Jun 2014 18:50:14 +0000 Subject: [PATCH 2/3] Fix issue when loading images in Chrome --- js/no-animated-gif.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/js/no-animated-gif.js b/js/no-animated-gif.js index cfdf757b..36d48954 100644 --- a/js/no-animated-gif.js +++ b/js/no-animated-gif.js @@ -13,7 +13,17 @@ function unanimate_gif(e) { $(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()); + 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(); + } + $(e).hide(); } From 4f070d16e562d1b90f5b7fd171b7fd243dde36bd Mon Sep 17 00:00:00 2001 From: Fredrick Brennan Date: Tue, 10 Jun 2014 23:09:39 +0000 Subject: [PATCH 3/3] Congrats, you broke the mod page on non-secured servers @jdh8 --- inc/mod/pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index d340dc44..3cb94619 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -150,7 +150,7 @@ function mod_dashboard() { $latest = false; } - setcookie('update', serialize($latest), time() + $config['check_updates_time'], $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, $_SERVER['HTTPS'], true); + setcookie('update', serialize($latest), time() + $config['check_updates_time'], $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']), true); } if ($latest)