From 745ac1ec19805fce781157ea0a86a040d290a914 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 14 Oct 2011 16:29:34 +0200 Subject: [PATCH] Only listen to resize events with fitheight enabled. --- 4chan_x.user.js | 27 +++++++++++++++++---------- script.coffee | 21 +++++++++++++-------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 28820f6d7..e96860077 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2803,10 +2803,7 @@ imgExpand = { init: function() { g.callbacks.push(imgExpand.node); - imgExpand.dialog(); - $.bind(window, 'resize', imgExpand.resize); - imgExpand.style = $.addStyle(''); - return imgExpand.resize(); + return imgExpand.dialog(); }, node: function(root) { var a, thumb; @@ -2849,7 +2846,7 @@ } }, typeChange: function(e) { - var klass; + var form, klass; switch (this.value) { case 'full': klass = ''; @@ -2863,7 +2860,17 @@ case 'fit screen': klass = 'fitwidth fitheight'; } - return d.body.className = klass; + form = $('body > form'); + form.className = klass; + if (form.classList.contains('fitheight')) { + $.bind(window, 'resize', imgExpand.resize); + if (!imgExpand.style) { + imgExpand.style = $.addStyle(''); + return imgExpand.resize(); + } + } else if (imgExpand.style) { + return $.unbind(window, 'resize', imgExpand.resize); + } } }, toggle: function(a) { @@ -2937,8 +2944,8 @@ delform = $('form[name=delform]'); return $.prepend(delform, controls); }, - resize: function(e) { - return imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:" + d.body.clientHeight + "px;}"; + resize: function() { + return imgExpand.style.innerHTML = ".fitheight img + img {max-height:" + innerHeight + "px;}"; } }; firstRun = { @@ -3157,10 +3164,10 @@ float: left;\ pointer-events: none;\ }\ - img[md5], img[md5] + img {\ + img[md5], img + img {\ pointer-events: all;\ }\ - body.fitwidth img[md5] + img {\ + .fitwidth img + img {\ max-width: 100%;\ width: -moz-calc(100%); /* hack so only firefox sees this */\ }\ diff --git a/script.coffee b/script.coffee index ea8eb5f4a..de282e58b 100644 --- a/script.coffee +++ b/script.coffee @@ -2062,9 +2062,6 @@ imgExpand = init: -> g.callbacks.push imgExpand.node imgExpand.dialog() - $.bind window, 'resize', imgExpand.resize - imgExpand.style = $.addStyle '' - imgExpand.resize() node: (root) -> return unless thumb = $ 'img[md5]', root @@ -2094,7 +2091,15 @@ imgExpand = klass = 'fitheight' when 'fit screen' klass = 'fitwidth fitheight' - d.body.className = klass + form = $('body > form') + form.className = klass + if form.classList.contains 'fitheight' + $.bind window, 'resize', imgExpand.resize + unless imgExpand.style + imgExpand.style = $.addStyle '' + imgExpand.resize() + else if imgExpand.style + $.unbind window, 'resize', imgExpand.resize toggle: (a) -> thumb = a.firstChild @@ -2151,8 +2156,8 @@ imgExpand = delform = $ 'form[name=delform]' $.prepend delform, controls - resize: (e) -> - imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:#{d.body.clientHeight}px;}" + resize: -> + imgExpand.style.innerHTML = ".fitheight img + img {max-height:#{innerHeight}px;}" firstRun = init: -> @@ -2418,10 +2423,10 @@ Main = float: left; pointer-events: none; } - img[md5], img[md5] + img { + img[md5], img + img { pointer-events: all; } - body.fitwidth img[md5] + img { + .fitwidth img + img { max-width: 100%; width: -moz-calc(100%); /* hack so only firefox sees this */ }