From e8f1ff580c6290060d1de8f3e9eceae9028fd1fa Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 3 Jan 2009 05:36:16 +0000 Subject: Add a new quick-edit mode for editing photos when viewing albums. Implement image rotation this way. --- core/controllers/quick.php | 68 +++++++++++++++++++++++++++++ core/css/quickedit.css | 45 +++++++++++++++++++ core/helpers/core_block.php | 22 +++++++++- core/images/arrow_rotate_anticlockwise.png | Bin 0 -> 608 bytes core/images/arrow_rotate_clockwise.png | Bin 0 -> 602 bytes core/js/quickedit.js | 45 +++++++++++++++++++ core/views/quick_edit.html.php | 14 ++++++ 7 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 core/controllers/quick.php create mode 100644 core/css/quickedit.css create mode 100644 core/images/arrow_rotate_anticlockwise.png create mode 100644 core/images/arrow_rotate_clockwise.png create mode 100644 core/js/quickedit.js create mode 100644 core/views/quick_edit.html.php (limited to 'core') diff --git a/core/controllers/quick.php b/core/controllers/quick.php new file mode 100644 index 00000000..6a9ed0f8 --- /dev/null +++ b/core/controllers/quick.php @@ -0,0 +1,68 @@ +loaded) { + return ""; + } + + if ($item->type == "photo") { + $view = new View("quick_edit.html"); + $view->item = $item; + print $view; + } + } + + public function rotate($id, $dir) { + access::verify_csrf(); + $item = ORM::factory("item", $id); + if (!$item->loaded) { + return ""; + } + + $degrees = 0; + switch($dir) { + case "ccw": + $degrees = -90; + break; + + case "cw": + $degrees = 90; + break; + } + + if ($degrees) { + graphics::rotate($item->file_path(), $item->file_path(), array("degrees" => $degrees)); + + list($item->width, $item->height) = getimagesize($item->file_path()); + $item->resize_dirty= 1; + $item->thumb_dirty= 1; + $item->save(); + + graphics::generate($item); + } + + print json_encode( + array("src" => $item->thumb_url() . "?rnd=" . rand(), + "width" => $item->thumb_width, + "height" => $item->thumb_height)); + } +} diff --git a/core/css/quickedit.css b/core/css/quickedit.css new file mode 100644 index 00000000..1ab00de5 --- /dev/null +++ b/core/css/quickedit.css @@ -0,0 +1,45 @@ +div.gQuickEdit { + margin: 0px !important; + padding: 0px !important; + border: none !important; +} + +#gQuickEditPane { + background: white; + opacity: 0.8; + border-bottom: 1px dashed black; +} + +#gQuickEditPane div { + background: red; + float: right; + display: inline; + cursor: pointer; + margin: 8px; +} + +#gQuickEditPane div.rotate-clockwise { + background: url(../images/arrow_rotate_clockwise.png); + width: 16px; + height: 16px; + position: absolute; + top: 0px; + right: 0px; +} + +#gQuickEditPane div.rotate-clockwise span { + display: none; +} + +#gQuickEditPane div.rotate-counter-clockwise { + background: url(../images/arrow_rotate_anticlockwise.png); + width: 16px; + height: 16px; + position: absolute; + top: 0px; + left: 0px; +} + +#gQuickEditPane div.rotate-counter-clockwise span { + display: none; +} diff --git a/core/helpers/core_block.php b/core/helpers/core_block.php index c82ca53d..d161d9b4 100644 --- a/core/helpers/core_block.php +++ b/core/helpers/core_block.php @@ -20,10 +20,30 @@ class core_block_Core { public static function head($theme) { + $buf = ""; if (Session::instance()->get("debug")) { - return ""; } + if ($theme->page_type == "album" && access::can("edit", $theme->item())) { + $buf .= ""; + $buf .= html::script("core/js/quickedit.js"); + } + return $buf; + } + + public static function thumb_top($theme, $child) { + if (access::can("edit", $child)) { + $edit_link = url::site("quick/edit/$child->id"); + return "
"; + } + } + + public static function thumb_bottom($theme, $child) { + if (access::can("edit", $child)) { + return "
"; + } } public static function admin_head($theme) { diff --git a/core/images/arrow_rotate_anticlockwise.png b/core/images/arrow_rotate_anticlockwise.png new file mode 100644 index 00000000..46c75aa8 Binary files /dev/null and b/core/images/arrow_rotate_anticlockwise.png differ diff --git a/core/images/arrow_rotate_clockwise.png b/core/images/arrow_rotate_clockwise.png new file mode 100644 index 00000000..aa65210e Binary files /dev/null and b/core/images/arrow_rotate_clockwise.png differ diff --git a/core/js/quickedit.js b/core/js/quickedit.js new file mode 100644 index 00000000..5dad5e1f --- /dev/null +++ b/core/js/quickedit.js @@ -0,0 +1,45 @@ +$(document).ready(function() { + $("div.gQuickEdit").hover(show_quickedit, function() { }); +}); + +var show_quickedit = function() { + $("#gQuickEditPane").remove(); + $(this).append("
"); + var img = $(this).find("img"); + var pos = img.position(); + $("#gQuickEditPane").css({ + "position": "absolute", + "top": pos.top, + "left": pos.left, + "width": img.innerWidth() + 1, + "height": 32 + }); + $(this).hover(function() { }, hide_quickedit); + $.get( + $(this).attr("quickedit_link"), + {}, + function(data, textStatus) { + $("#gQuickEditPane").html(data); + $("#gQuickEditPane div").click(function() { + quickedit($(this).attr("quickedit_link"), img); + }); + } + ); +}; + +var quickedit = function(url, img) { + $.ajax({ + type: "GET", + url: url, + dataType: "json", + success: function(data) { + img.attr("width", data.width); + img.attr("height", data.height); + img.attr("src", data.src); + } + }); +}; + +var hide_quickedit = function() { + $("#gQuickEditPane").remove(); +}; diff --git a/core/views/quick_edit.html.php b/core/views/quick_edit.html.php new file mode 100644 index 00000000..30baf4f8 --- /dev/null +++ b/core/views/quick_edit.html.php @@ -0,0 +1,14 @@ +type == "photo"): ?> +
id/ccw?csrf=" . access::csrf_token()) ?>"> + + + +
+
id/cw?csrf=" . access::csrf_token()) ?>"> + + + +
+ -- cgit v1.2.3