This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/contrib/zoom/theme.php
shish ff199a7c63 Now that the extension manager is working, the non-essential extensions can be made optional
git-svn-id: file:///home/shish/svn/shimmie2/trunk@803 7f39781d-f577-437e-ae19-be835c7a54ca
2008-04-11 05:28:36 +00:00

43 lines
1 KiB
PHP

<?php
class ZoomTheme extends Themelet {
public function display_zoomer($page, $image, $zoom_by_default) {
$page->add_block(new Block(null, $this->make_zoomer($image->width, $zoom_by_default)));
}
protected function make_zoomer($image_width, $zoom_by_default) {
global $config;
$default = $zoom_by_default ? "scale(img);" : "";
return <<<EOD
<script type="text/javascript">
img = document.getElementById("main_image");
img.onclick = function() {scale(img);};
msg_div = document.createElement("div");
msg_div.id = "msg_div";
msg_div.appendChild(document.createTextNode("Note: Image has been scaled to fit the screen; click to enlarge"));
msg_div.style.display="none";
img.parentNode.insertBefore(msg_div, img);
orig_width = $image_width;
function scale(img) {
if(orig_width >= img.parentNode.clientWidth * 0.9) {
if(img.style.width != "90%") {
img.style.width = "90%";
msg_div.style.display = "block";
}
else {
img.style.width = orig_width + 'px';
msg_div.style.display = "none";
}
}
}
$default
</script>
EOD;
}
}
?>