merged image zoom
This commit is contained in:
parent
0d73aa7692
commit
115d992ff0
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Name: Image Zoom
|
||||
* Author: Shish <webmaster@shishnet.org>
|
||||
* License: GPLv2
|
||||
* Description: Scales down too-large images using browser based scaling
|
||||
*/
|
||||
|
||||
class Zoom extends SimpleExtension {
|
||||
public function onDisplayingImage($event) {
|
||||
global $config, $page;
|
||||
$this->theme->display_zoomer($page, $event->image, $config->get_bool("image_zoom", false));
|
||||
}
|
||||
|
||||
public function onSetupBuilding($event) {
|
||||
$sb = new SetupBlock("Image Zoom");
|
||||
$sb->add_bool_option("image_zoom", "Zoom by default: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
class ZoomTest extends ShimmieWebTestCase {
|
||||
function testZoom() {
|
||||
$this->log_in_as_admin();
|
||||
$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
|
||||
$this->get("post/view/$image_id"); # just check that the page isn't borked
|
||||
$this->delete_image($image_id);
|
||||
$this->log_out();
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ZoomTheme extends Themelet {
|
||||
public function display_zoomer(Page $page, Image $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
|
||||
<!-- cancel border -->
|
||||
<script type="text/javascript">
|
||||
img = document.getElementById("main_image");
|
||||
|
||||
if(img) {
|
||||
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;
|
||||
|
||||
$default
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
EOD;
|
||||
}
|
||||
}
|
||||
?>
|
@ -152,8 +152,14 @@ abstract class DataHandlerExtension implements Extension {
|
||||
global $page;
|
||||
$this->theme->display_image($page, $event->image);
|
||||
}
|
||||
|
||||
if(($event instanceof SetupBuildingEvent)) {
|
||||
$sb = $this->setup();
|
||||
if($sb) $event->panel->add_block($sb);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setup() {}
|
||||
abstract protected function supported_ext($ext);
|
||||
abstract protected function check_contents($tmpname);
|
||||
abstract protected function create_image_from_data($filename, $metadata);
|
||||
|
@ -6,6 +6,12 @@
|
||||
*/
|
||||
|
||||
class PixelFileHandler extends DataHandlerExtension {
|
||||
public function setup() {
|
||||
$sb = new SetupBlock("Image Zoom");
|
||||
$sb->add_bool_option("image_zoom", "Zoom by default: ");
|
||||
return $sb;
|
||||
}
|
||||
|
||||
protected function supported_ext($ext) {
|
||||
$exts = array("jpg", "jpeg", "gif", "png");
|
||||
return in_array(strtolower($ext), $exts);
|
||||
|
@ -23,7 +23,40 @@ class PixelFileHandlerTheme extends Themelet {
|
||||
}
|
||||
}
|
||||
}
|
||||
$page->add_block(new Block("Image", $html, "main", 0));
|
||||
|
||||
$zoom_default = $config->get_bool("image_zoom", false) ? "scale(img);" : "";
|
||||
$zoom = "<script type=\"text/javascript\">
|
||||
img = document.getElementById(\"main_image\");
|
||||
|
||||
if(img) {
|
||||
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;
|
||||
|
||||
$zoom_default
|
||||
}
|
||||
|
||||
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\";
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>";
|
||||
|
||||
$page->add_block(new Block("Image", $html.$zoom, "main", 0));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user