diff options
-rw-r--r-- | modules/slideshow/controllers/slideshow.php | 73 | ||||
-rw-r--r-- | modules/slideshow/css/buttons.png | bin | 0 -> 3579 bytes | |||
-rw-r--r-- | modules/slideshow/css/slideshow.css | 101 | ||||
-rw-r--r-- | modules/slideshow/helpers/slideshow_event.php | 51 | ||||
-rw-r--r-- | modules/slideshow/helpers/slideshow_installer.php | 8 | ||||
-rw-r--r-- | modules/slideshow/helpers/slideshow_theme.php | 5 | ||||
-rw-r--r-- | modules/slideshow/js/slideshow.js | 149 | ||||
-rw-r--r-- | modules/slideshow/module.info | 2 |
8 files changed, 349 insertions, 40 deletions
diff --git a/modules/slideshow/controllers/slideshow.php b/modules/slideshow/controllers/slideshow.php new file mode 100644 index 00000000..6649b00b --- /dev/null +++ b/modules/slideshow/controllers/slideshow.php @@ -0,0 +1,73 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Slideshow_Controller extends Controller { + function album($item_id) { + $item = ORM::factory("item", $item_id); + access::required("view", $item); + + print $this->_build_image_list($item->children()); + } + + function photo($item_id) { + $item = ORM::factory("item", $item_id); + access::required("view", $item); + + print $this->_build_image_list($item->parent()->children()); + } + + function tag($item_id) { + $item = ORM::factory("item", $item_id); + $root = $item->id == 1 ? $item : ORM::factory("item", 1); + access::required("view", $item); + + $v = new View("organize_dialog.html"); + $v->title = $item->title; + $parents = array(); + foreach ($item->parents() as $parent) { + $parents[$parent->id] = 1; + } + $parents[$item->id] = 1; + + $v->album_tree = self::_tree($root, $parents); + $v->micro_thumb_grid = self::_get_micro_thumb_grid($item, 0); + print $v; + } + + private function _build_image_list($children) { + $resizes = array(); + foreach ($children as $child) { + switch($child->type) { + case "album": + if (!empty($child->album_cover_item_id)) { + $cover = ORM::factory("item", $child->album_cover_item_id); + $resizes[] = array("url" => $cover->resize_url(), "width" => $cover->resize_width, + "height" => $cover->resize_height); + } + break; + case "photo": + $resizes[] = array("url" => $child->resize_url(), "width" => $child->resize_width, + "height" => $child->resize_height); + break; + } + } + + return json_encode($resizes); + } +} diff --git a/modules/slideshow/css/buttons.png b/modules/slideshow/css/buttons.png Binary files differnew file mode 100644 index 00000000..6fe50e1b --- /dev/null +++ b/modules/slideshow/css/buttons.png diff --git a/modules/slideshow/css/slideshow.css b/modules/slideshow/css/slideshow.css new file mode 100644 index 00000000..f635c244 --- /dev/null +++ b/modules/slideshow/css/slideshow.css @@ -0,0 +1,101 @@ +#gSlideshowOverlay { + border: none; + margin: 0; + padding: 0; + background-color: #000; + position: absolute; + top: 0px; + left: 0px; + width: 100%; + height: 100%; + opacity: 0.7; + filter: alpha(opacity=70); + -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; + -moz-background-inline-policy: -moz-initial; + z-index: 2001; +} + +#gSlideShowImages { + z-index: 2002; +} + +#gSlideShowImages img { + display: none; + float: left; + z-index: 2002; +} + +#gSlideshowButtonPanel { + bottom: .5em; + position: absolute; + width: 100%; + z-index: 2004; +} + +#gSlideshowButtonPanel div { + background-color: #000; + color: #fff; + filter: alpha(opacity=70); + height: 55px; + margin: 0 auto; + opacity: 0.7; + width: 232px; + z-index: 2004; +} + +#gSlideshowPrevious, +#gSlideshowPause, +#gSlideshowResume, +#gSlideshowResume, +#gSlideshowClose, +#gSlideshowNext { + background-image: url(buttons.png); + background-repeat: no-repeat; + display: block; + float: left; + height: 55px; + overflow: hidden; + text-indent: -99999px; + width: 58px; +} + +#gSlideshowPrevious { + background-position: 0 0; +} + +#gSlideshowPrevious:hover { + background-position: -58px 0; +} + +#gSlideshowPause { + background-position: -174px 0; +} + +#gSlideshowPause:hover { + background-position: -116px 0; +} + +#gSlideshowResume { + background-position: -290px 0; + display: none; +} + +#gSlideshowResume:hover { + background-position: -232px 0; +} + +#gSlideshowNext { + background-position: -406px 0; +} + +#gSlideshowNext:hover { + background-position: -348px 0; +} + +#gSlideshowClose { + background-position: -464px 0; +} + +#gSlideshowClose:hover { + background-position: -522px 0; +} diff --git a/modules/slideshow/helpers/slideshow_event.php b/modules/slideshow/helpers/slideshow_event.php index cf79f71a..7060fa1d 100644 --- a/modules/slideshow/helpers/slideshow_event.php +++ b/modules/slideshow/helpers/slideshow_event.php @@ -18,45 +18,30 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class slideshow_event_Core { - static function module_change($changes) { - if (!module::is_active("rss") || in_array("rss", $changes->deactivate)) { - site_status::warning( - t("The Slideshow module requires the RSS module. " . - "<a href=\"%url\">Activate the RSS module now</a>", - array("url" => url::site("admin/modules"))), - "slideshow_needs_rss"); - } else { - site_status::clear("slideshow_needs_rss"); - } - } - static function album_menu($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("slideshow") - ->label(t("View slideshow")) - ->url("javascript:PicLensLite.start(" . - "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") - ->css_id("gSlideshowLink")); + $item = $theme->item(); + $menu->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url(url::site("slideshow/album/{$item->id}")) + ->css_id("gSlideshowLink")); } static function photo_menu($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("slideshow") - ->label(t("View slideshow")) - ->url("javascript:PicLensLite.start(" . - "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") - ->css_id("gSlideshowLink")); + $item = $theme->item()->parent(); + $menu->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url(url::site("slideshow/photo/{$item->id}")) + ->css_id("gSlideshowLink")); } static function tag_menu($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("slideshow") - ->label(t("View slideshow")) - ->url("javascript:PicLensLite.start(" . - "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") - ->css_id("gSlideshowLink")); + $tag = $theme->tag(); + $menu->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url(url::site("slideshow/tag/{$tag->id}")) + ->css_id("gSlideshowLink")); } } diff --git a/modules/slideshow/helpers/slideshow_installer.php b/modules/slideshow/helpers/slideshow_installer.php index cd1c6e05..a71ea183 100644 --- a/modules/slideshow/helpers/slideshow_installer.php +++ b/modules/slideshow/helpers/slideshow_installer.php @@ -19,10 +19,12 @@ */ class slideshow_installer { static function install() { - module::set_version("slideshow", 1); + module::set_version("slideshow", 2); } - static function deactivate() { - site_status::clear("slideshow_needs_rss"); + static function upgrade($version) { + if ($version == 1) { + module::set_version("slideshow", 2); + } } } diff --git a/modules/slideshow/helpers/slideshow_theme.php b/modules/slideshow/helpers/slideshow_theme.php index 269a93ce..fdce22f3 100644 --- a/modules/slideshow/helpers/slideshow_theme.php +++ b/modules/slideshow/helpers/slideshow_theme.php @@ -19,8 +19,7 @@ */ class slideshow_theme_Core { static function head($theme) { - $proto = (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] === "off") ? "http" : "https"; - return "<script src=\"$proto://lite.piclens.com/current/piclens_optimized.js\" " . - "type=\"text/javascript\"></script>"; + $theme->script("slideshow.js"); + $theme->css("slideshow.css"); } } diff --git a/modules/slideshow/js/slideshow.js b/modules/slideshow/js/slideshow.js new file mode 100644 index 00000000..0f04a206 --- /dev/null +++ b/modules/slideshow/js/slideshow.js @@ -0,0 +1,149 @@ +(function($) { + $.gallery_slideshow = { + interval: 4000, + timer: null, + init: function(data) { + var self = this; + var size = $.gallery_get_viewport_size(); + $("body").append( + '<div id="gSlideshowOverlay" class="ui-dialog-overlay"></div>' + + '<div id="gSlideshowButtonPanel"><div class="ui-corner-all">' + + '<a id="gSlideshowPrevious" href="javascript: $.gallery_slideshow.previous()" />' + + '<a id="gSlideshowPause" href="javascript: $.gallery_slideshow.pause()" />' + + '<a id="gSlideshowResume" href="javascript: $.gallery_slideshow.resume()" />' + + '<a id="gSlideshowNext" href="javascript: $.gallery_slideshow.next()" />' + + '<a id="gSlideshowClose" href="javascript: $.gallery_slideshow.close()" />' + + '</div></div>' + + '<div id="gSlideShowImages"></div>'); + $().bind("mousemove", $.gallery_slideshow._mouse_over); + + // array of {url: xxx, width: nnn, height: nnn} + for (var i=0; i < data.length; i++) { + var position = $.gallery_slideshow._autofit_image(data[i].width, data[i].height); + $("#gSlideShowImages").append( + '<img id="img_' + i + '" src="' + data[i].url + '" width="' + position.width + 'px" ' + + 'height="' + position.height + 'px" style="position: absolute; top: ' + position.top + + 'px; left: ' + position.left + 'px;" />'); + if (i == 0) { + $("#gSlideShowImages #img_0").load(function() { + $.gallery_slideshow._show_image(null); + setTimeout(function() {$("#gSlideshowButtonPanel").hide();}, + $.gallery_slideshow.interval); + }); + } + } + }, + + close: function(event) { + $("#gSlideShowImages img.gSlideShowing").toggle(); + $.gallery_slideshow.pause(); + $("#gSlideshowOverlay").remove(); + $("#gSlideShowImages").remove(); + $("#gSlideshowButtonPanel").remove(); + $().unbind("mousemove", $.gallery_slideshow._mouse_over); + }, + + previous: function() { + $.gallery_slideshow.pause(); + var next_image = $("#gSlideShowImages img.gSlideShowing").prev(); + if (next_image.length == 0) { + next_image = $("#gSlideShowImages img:last"); + } + $.gallery_slideshow._show_image(next_image); + }, + + next: function() { + $.gallery_slideshow.pause(); + var next_image = $("#gSlideShowImages img.gSlideShowing").next(); + if (next_image.length == 0) { + next_image = $("#gSlideShowImages img:first"); + } + $.gallery_slideshow._show_image(next_image); + }, + + pause: function() { + if ($.gallery_slideshow.timer) { + $("#gSlideshowPause").toggle(); + $("#gSlideshowResume").toggle(); + clearTimeout($.gallery_slideshow.timer); + $.gallery_slideshow.timer = null; + } + }, + + resume: function() { + $("#gSlideshowPause").toggle(); + $("#gSlideshowResume").toggle(); + $.gallery_slideshow._show_image(null); + }, + + _mouse_over: function(event) { + var size = $.gallery_get_viewport_size(); + if (event.pageY < size.height() && size.height() - 100 <= event.pageY) { + $("#gSlideshowButtonPanel").show(); + } else { + $("#gSlideshowButtonPanel").hide(); + } + }, + + _autofit_image: function(imageWidth, imageHeight) { + var size = $.gallery_get_viewport_size(); + + var ratio = size.width() / imageWidth; + imageWidth *= ratio; + imageHeight *= ratio; + + /* after scaling the width, check that the height fits */ + if (imageHeight > size.height()) { + ratio = size.height() / imageHeight; + imageWidth *= ratio; + imageHeight *= ratio; + } + + // handle the case where the calculation is almost zero (2.14e-14) + return { + top: Number((size.height() - imageHeight) / 2), + left: Number((size.width() - imageWidth) / 2), + width: Number(imageWidth), + height: Number(imageHeight) + }; + }, + + // If next_image is not null, then this a call from prev or next + _show_image: function(next_image) { + var reset_timer = false; + if (next_image == null) { + next_image = $("#gSlideShowImages img.gSlideShowing").next(); + if (next_image.length == 0) { + next_image = $("#gSlideShowImages img:first"); + } + reset_timer = true; + } + next_image.addClass("gSlideShowNextImage"); + + var zIndex = parseInt(next_image.css("zIndex")); + next_image.css("zIndex", zIndex + 1); + next_image.fadeIn("slow", function() { + var current = $("#gSlideShowImages img.gSlideShowing"); + if (current.length) { + current.hide(); + current.removeClass("gSlideShowing"); + } + $(".gSlideShowNextImage").addClass("gSlideShowing").removeClass("gSlideShowNextImage") + .css("zIndex", zIndex); + if (reset_timer) { + $.gallery_slideshow.timer = + setTimeout(function() {$.gallery_slideshow._show_image(null);}, + $.gallery_slideshow.interval); + } + }); + } + }; +})(jQuery); + +$(document).ready(function() { + $("#gSlideshowLink").click(function(event) { + event.preventDefault(); + $.get($(event.currentTarget).attr("href"), {}, $.gallery_slideshow.init, "json"); + return false; + }); +}); diff --git a/modules/slideshow/module.info b/modules/slideshow/module.info index 6841199a..b56eac81 100644 --- a/modules/slideshow/module.info +++ b/modules/slideshow/module.info @@ -1,3 +1,3 @@ name = "Slideshow" description = "Allows users to view a slideshow of photos" -version = 1 +version = 2 |