diff --git a/ext/zoom/main.php b/ext/zoom/main.php index f795cc6b..f8193e52 100644 --- a/ext/zoom/main.php +++ b/ext/zoom/main.php @@ -8,7 +8,7 @@ class Zoom extends Extension { if(is_a($event, 'DisplayingImageEvent')) { global $config; - $this->theme->display_zoomer($event->page, $config->get_bool("image_zoom", false)); + $this->theme->display_zoomer($event->page, $event->image, $config->get_bool("image_zoom", false)); } if(is_a($event, 'SetupBuildingEvent')) { diff --git a/ext/zoom/theme.php b/ext/zoom/theme.php index 0c95f5a7..c8384e73 100644 --- a/ext/zoom/theme.php +++ b/ext/zoom/theme.php @@ -1,11 +1,11 @@ add_block(new Block(null, $this->make_zoomer($zoom_by_default))); + public function display_zoomer($page, $image, $zoom_by_default) { + $page->add_block(new Block(null, $this->make_zoomer($image->width, $zoom_by_default))); } - private function make_zoomer($zoom_by_default) { + private function make_zoomer($image_width, $zoom_by_default) { global $config; $default = $zoom_by_default ? "scale(img);" : ""; return <<= img.parentNode.clientWidth * 0.9); function scale(img) { - // element.clientWidth is not part of the JS standard :( - if(img.style.width != "90%" && (img.clientWidth >= img.parentNode.clientWidth * 0.9)) { - origwidth = img.style.width; - img.style.width = "90%"; - msg_div.style.display = "block"; - } - else { - img.style.width = origwidth; - msg_div.style.display = "none"; + if(needs_scaling) { + if(img.style.width != "90%") { + img.style.width = "90%"; + msg_div.style.display = "block"; + } + else { + img.style.width = origwidth; + msg_div.style.display = "none"; + } } }