summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/gallery.ajax.js15
-rw-r--r--lib/gallery.common.js8
-rw-r--r--modules/gallery/helpers/gallery.php191
-rw-r--r--modules/gallery/libraries/Menu.php34
-rw-r--r--modules/gallery/libraries/Theme_View.php6
-rw-r--r--themes/admin_default/js/ui.init.js3
-rw-r--r--themes/admin_default/views/admin.html.php1
-rw-r--r--themes/default/js/ui.init.js9
-rw-r--r--themes/default/views/album.html.php2
-rw-r--r--themes/default/views/movie.html.php2
-rw-r--r--themes/default/views/page.html.php1
-rw-r--r--themes/default/views/photo.html.php2
12 files changed, 171 insertions, 103 deletions
diff --git a/lib/gallery.ajax.js b/lib/gallery.ajax.js
new file mode 100644
index 00000000..4f26745d
--- /dev/null
+++ b/lib/gallery.ajax.js
@@ -0,0 +1,15 @@
+(function($) {
+ $.widget("ui.gallery_ajax", {
+ _init: function() {
+ this.element.click(function(event) {
+ eval("var ajax_handler = " + $(event.currentTarget).attr("ajax_handler"));
+ $.get($(event.currentTarget).attr("href"), function(data) {
+ eval("var data = " + data);
+ ajax_handler(data);
+ });
+ event.preventDefault();
+ return false;
+ });
+ }
+ });
+})(jQuery);
diff --git a/lib/gallery.common.js b/lib/gallery.common.js
index eea0fada..317a73e7 100644
--- a/lib/gallery.common.js
+++ b/lib/gallery.common.js
@@ -80,7 +80,7 @@
return this.id.match(/gPhotoId-\d+/);
});
return photo;
- }
+ };
/**
* Get the sum of an element's height, margin-top, and margin-bottom
@@ -104,7 +104,11 @@
$(this).removeClass("ui-state-hover");
}
);
- }
+ };
+ // Ajax handler for replacing an image, used in Ajax thumbnail rotation
+ $.gallery_replace_image = function(data, thumb) {
+ $(thumb).attr({src: data.src, width: data.width, height: data.height});
+ };
})(jQuery);
diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php
index 279f2013..c81af842 100644
--- a/modules/gallery/helpers/gallery.php
+++ b/modules/gallery/helpers/gallery.php
@@ -197,108 +197,117 @@ class gallery_Core {
return $menu;
}
- static function context_menu($menu, $theme, $item) {
- $page_type = $theme->page_type();
- switch ($item->type) {
- case "movie":
- $edit_title = t("Edit this movie");
- $delete_title = t("Delete this movie");
- break;
-
- case "album":
- $edit_title = t("Edit this album");
- $delete_title = t("Delete this album");
- break;
-
- default:
- $edit_title = t("Edit this photo");
- $delete_title = t("Delete this photo");
- break;
- }
- $cover_title = t("Choose as the album cover");
- $move_title = t("Move to another album");
-
- $csrf = access::csrf_token();
-
+ static function context_menu($menu, $theme, $item, $thumb_css_selector) {
$menu->append($options_menu = Menu::factory("submenu")
->id("options_menu")
->label(t("Options"))
->css_class("ui-icon-carat-1-n"));
- $options_menu->append(Menu::factory("dialog")
- ->id("edit")
- ->label($edit_title)
- ->css_class("ui-icon-pencil")
- ->url(url::site("quick/form_edit/$item->id?page_type=$page_type")));
+ if (access::can("edit", $item)) {
+ $page_type = $theme->page_type();
+ switch ($item->type) {
+ case "movie":
+ $edit_title = t("Edit this movie");
+ $delete_title = t("Delete this movie");
+ break;
+ case "album":
+ $edit_title = t("Edit this album");
+ $delete_title = t("Delete this album");
+ break;
- if ($item->is_photo() && graphics::can("rotate")) {
- $options_menu
- ->append(Menu::factory("link")
- ->id("rotate_ccw")
- ->label(t("Rotate 90° counter clockwise"))
- ->css_class("ui-icon-rotate-ccw")
- ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&page_type=$page_type")))
- ->append(Menu::factory("link")
- ->id("rotate_cw")
- ->label(t("Rotate 90° clockwise"))
- ->css_class("ui-icon-rotate-cw")
- ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&page_type=$page_type")));
- }
+ default:
+ $edit_title = t("Edit this photo");
+ $delete_title = t("Delete this photo");
+ break;
+ }
+ $cover_title = t("Choose as the album cover");
+ $move_title = t("Move to another album");
- // Don't move photos from the photo page; we don't yet have a good way of redirecting after move
- if ($page_type == "album") {
- $options_menu
- ->append(Menu::factory("dialog")
- ->id("move")
- ->label($move_title)
- ->css_class("ui-icon-folder-open")
- ->url(url::site("move/browse/$item->id")));
- }
+ $csrf = access::csrf_token();
+
+ $options_menu->append(Menu::factory("dialog")
+ ->id("edit")
+ ->label($edit_title)
+ ->css_class("ui-icon-pencil")
+ ->url(url::site("quick/form_edit/$item->id?page_type=$page_type")));
- $parent = $item->parent();
- if (access::can("edit", $parent)) {
- // We can't make this item the highlight if it's an album with no album cover, or if it's
- // already the album cover.
- if (($item->type == "album" && empty($item->album_cover_item_id)) ||
- ($item->type == "album" && $parent->album_cover_item_id == $item->album_cover_item_id) ||
- $parent->album_cover_item_id == $item->id) {
- $disabledState = " ui-state-disabled";
- } else {
- $disabledState = " ";
+
+ if ($item->is_photo() && graphics::can("rotate")) {
+ $options_menu
+ ->append(
+ Menu::factory("ajax_link")
+ ->id("rotate_ccw")
+ ->label(t("Rotate 90° counter clockwise"))
+ ->css_class("ui-icon-rotate-ccw")
+ ->ajax_handler("function(data) { " .
+ "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
+ ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&page_type=$page_type")))
+ ->append(
+ Menu::factory("ajax_link")
+ ->id("rotate_cw")
+ ->label(t("Rotate 90° clockwise"))
+ ->css_class("ui-icon-rotate-cw")
+ ->ajax_handler("function(data) { " .
+ "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
+ ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&page_type=$page_type")));
+ }
+
+ // Don't move photos from the photo page; we don't yet have a good way of redirecting after
+ // move
+ if ($page_type == "album") {
+ $options_menu
+ ->append(Menu::factory("dialog")
+ ->id("move")
+ ->label($move_title)
+ ->css_class("ui-icon-folder-open")
+ ->url(url::site("move/browse/$item->id")));
}
- $options_menu
- ->append(Menu::factory("link")
- ->id("make_album_cover")
- ->label($cover_title)
- ->css_class("ui-icon-star")
- ->url(
- url::site("quick/make_album_cover/$item->id?csrf=$csrf&page_type=$page_type")))
- ->append(Menu::factory("dialog")
- ->id("delete")
- ->label($delete_title)
- ->css_class("ui-icon-trash")
- ->css_id("gQuickDelete")
- ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&page_type=$page_type")));
- }
- if ($item->is_album()) {
- $options_menu
- ->append(Menu::factory("dialog")
- ->id("add_item")
- ->label(t("Add a photo"))
- ->css_class("add_item")
- ->url(url::site("simple_uploader/app/$item->id")))
- ->append(Menu::factory("dialog")
- ->id("add_album")
- ->label(t("Add an album"))
- ->css_class("add_album")
- ->url(url::site("form/add/albums/$item->id?type=album")))
- ->append(Menu::factory("dialog")
- ->id("edit_permissions")
- ->label(t("Edit permissions"))
- ->css_class("permissions")
- ->url(url::site("permissions/browse/$item->id")));
+ $parent = $item->parent();
+ if (access::can("edit", $parent)) {
+ // We can't make this item the highlight if it's an album with no album cover, or if it's
+ // already the album cover.
+ if (($item->type == "album" && empty($item->album_cover_item_id)) ||
+ ($item->type == "album" && $parent->album_cover_item_id == $item->album_cover_item_id) ||
+ $parent->album_cover_item_id == $item->id) {
+ $disabledState = " ui-state-disabled";
+ } else {
+ $disabledState = " ";
+ }
+ $options_menu
+ ->append(Menu::factory("ajax_link")
+ ->id("make_album_cover")
+ ->label($cover_title)
+ ->css_class("ui-icon-star")
+ ->ajax_handler("function(data) { window.location.reload() }")
+ ->url(url::site("quick/make_album_cover/$item->id?csrf=$csrf")))
+ ->append(Menu::factory("dialog")
+ ->id("delete")
+ ->label($delete_title)
+ ->css_class("ui-icon-trash")
+ ->css_id("gQuickDelete")
+ ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&page_type=$page_type")));
+ }
+
+ if ($item->is_album()) {
+ $options_menu
+ ->append(Menu::factory("dialog")
+ ->id("add_item")
+ ->label(t("Add a photo"))
+ ->css_class("add_item")
+ ->url(url::site("simple_uploader/app/$item->id")))
+ ->append(Menu::factory("dialog")
+ ->id("add_album")
+ ->label(t("Add an album"))
+ ->css_class("add_album")
+ ->url(url::site("form/add/albums/$item->id?type=album")))
+ ->append(Menu::factory("dialog")
+ ->id("edit_permissions")
+ ->label(t("Edit permissions"))
+ ->css_class("permissions")
+ ->url(url::site("permissions/browse/$item->id")));
+ }
}
}
} \ No newline at end of file
diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php
index 263dc38d..07b2b2b8 100644
--- a/modules/gallery/libraries/Menu.php
+++ b/modules/gallery/libraries/Menu.php
@@ -97,6 +97,37 @@ class Menu_Element_Link extends Menu_Element {
}
/**
+ * Menu element that provides an AJAX link.
+ */
+class Menu_Element_Ajax_Link extends Menu_Element {
+ public $ajax_handler;
+
+ /**
+ * Set the AJAX handler
+ * @chainable
+ */
+ public function ajax_handler($ajax_handler) {
+ $this->ajax_handler = $ajax_handler;
+ return $this;
+ }
+
+ public function __toString() {
+ if (isset($this->css_id) && !empty($this->css_id)) {
+ $css_id = " id=\"$this->css_id\"";
+ } else {
+ $css_id = "";
+ }
+ if (isset($this->css_class) && !empty($this->css_class)) {
+ $css_class = " $this->css_class";
+ } else {
+ $css_class = "";
+ }
+ return "<li><a$css_id class=\"gAjaxLink $css_class\" href=\"$this->url\" " .
+ "title=\"$this->label\" ajax_handler=\"$this->ajax_handler\">$this->label</a></li>";
+ }
+}
+
+/**
* Menu element that provides a pop-up dialog
*/
class Menu_Element_Dialog extends Menu_Element {
@@ -132,6 +163,9 @@ class Menu_Core extends Menu_Element {
case "link":
return new Menu_Element_Link($type);
+ case "ajax_link":
+ return new Menu_Element_Ajax_Link($type);
+
case "dialog":
return new Menu_Element_Dialog($type);
diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php
index a5f5db03..541bce88 100644
--- a/modules/gallery/libraries/Theme_View.php
+++ b/modules/gallery/libraries/Theme_View.php
@@ -111,15 +111,15 @@ class Theme_View_Core extends Gallery_View {
return $menu->compact();
}
- public function context_menu($item) {
+ public function context_menu($item, $thumbnail_css_selector) {
$menu = Menu::factory("root")
->append(Menu::factory("submenu")
->id("context_menu")
->label(t("Options")))
->css_class("gContextMenu");
- gallery::context_menu($menu, $this, $item);
- module::event("context_menu", $menu, $this, $item);
+ gallery::context_menu($menu, $this, $item, $thumbnail_css_selector);
+ module::event("context_menu", $menu, $this, $item, $thumbnail_css_selector);
return $menu->compact();
}
diff --git a/themes/admin_default/js/ui.init.js b/themes/admin_default/js/ui.init.js
index e52f0c4c..daa6dd70 100644
--- a/themes/admin_default/js/ui.init.js
+++ b/themes/admin_default/js/ui.init.js
@@ -19,6 +19,9 @@ $(document).ready(function(){
// Initialize modal dialogs
$(".gDialogLink").gallery_dialog();
+ // Initialize ajax links
+ $(".gDialogLink").gallery_ajax();
+
// Initialize panels
$(".gPanelLink").gallery_panel();
diff --git a/themes/admin_default/views/admin.html.php b/themes/admin_default/views/admin.html.php
index d27f9260..3f4128cb 100644
--- a/themes/admin_default/views/admin.html.php
+++ b/themes/admin_default/views/admin.html.php
@@ -25,6 +25,7 @@
<script type="text/javascript">
var MSG_CANCEL = "<?= t('Cancel') ?>";
</script>
+ <?= $theme->script("gallery.ajax.js") ?>
<?= $theme->script("gallery.dialog.js") ?>
<?= $theme->script("superfish/js/superfish.js") ?>
<?= $theme->script("jquery.dropshadow.js") ?>
diff --git a/themes/default/js/ui.init.js b/themes/default/js/ui.init.js
index 3726d305..60482972 100644
--- a/themes/default/js/ui.init.js
+++ b/themes/default/js/ui.init.js
@@ -34,6 +34,7 @@ $(document).ready(function() {
// Initialize dialogs
$("#gLoginLink").addClass("gDialogLink");
$(".gDialogLink").gallery_dialog();
+ $(".gAjaxLink").gallery_ajax();
// Initialize view menu
if ($("#gViewMenu").length) {
@@ -100,8 +101,8 @@ $(document).ready(function() {
$(".gContextMenu").hover(
function() {
$(this).find("ul").slideDown("fast");
- var dialogLinks = $(this).find(".gDialogLink");
- $(dialogLinks).gallery_dialog();
+ $(this).find(".gDialogLink").gallery_dialog();
+ $(this).find(".gAjaxLink").gallery_ajax();
},
function() {
$(this).find("ul").slideUp("slow");
@@ -128,8 +129,8 @@ $(document).ready(function() {
$(".gContextMenu").hover(
function() {
$(this).find("ul").slideDown("fast");
- var dialogLinks = $(this).find(".gDialogLink");
- $(dialogLinks).gallery_dialog();
+ $(this).find(".gDialogLink").gallery_dialog();
+ $(this).find(".gAjaxLink").gallery_ajax();
},
function() {
$(this).find("ul").slideUp("slow");
diff --git a/themes/default/views/album.html.php b/themes/default/views/album.html.php
index ce57458e..e2890482 100644
--- a/themes/default/views/album.html.php
+++ b/themes/default/views/album.html.php
@@ -19,7 +19,7 @@
<?= $child->thumb_img(array("class" => "gThumbnail")) ?>
</a>
<?= $theme->thumb_bottom($child) ?>
- <?= $theme->context_menu($child) ?>
+ <?= $theme->context_menu($child, "#gItemId-{$child->id} .gThumbnail") ?>
<h2><span></span><a href="<?= $child->url() ?>"><?= p::clean($child->title) ?></a></h2>
<ul class="gMetadata">
<?= $theme->thumb_info($child) ?>
diff --git a/themes/default/views/movie.html.php b/themes/default/views/movie.html.php
index d255922b..c8ecd769 100644
--- a/themes/default/views/movie.html.php
+++ b/themes/default/views/movie.html.php
@@ -36,5 +36,5 @@
var ADD_A_COMMENT = "<?= t("Add a comment") ?>";
</script>
<?= $theme->photo_bottom() ?>
- <?= $theme->context_menu($item) ?>
+ <?= $theme->context_menu($item, "#gMovieId-{$item->id}") ?>
</div>
diff --git a/themes/default/views/page.html.php b/themes/default/views/page.html.php
index 66282bae..2cb71b9e 100644
--- a/themes/default/views/page.html.php
+++ b/themes/default/views/page.html.php
@@ -53,6 +53,7 @@
<script type="text/javascript">
var MSG_CANCEL = "<?= t('Cancel') ?>";
</script>
+ <?= $theme->script("gallery.ajax.js") ?>
<?= $theme->script("gallery.dialog.js") ?>
<?= $theme->script("gallery.form.js") ?>
<?= $theme->script("superfish/js/superfish.js") ?>
diff --git a/themes/default/views/photo.html.php b/themes/default/views/photo.html.php
index 453417dc..fa5def47 100644
--- a/themes/default/views/photo.html.php
+++ b/themes/default/views/photo.html.php
@@ -47,7 +47,7 @@
</a>
<? endif ?>
<?= $theme->resize_bottom($item) ?>
- <?= $theme->context_menu($item) ?>
+ <?= $theme->context_menu($item, "#gPhotoId-{$item->id}") ?>
</div>
<div id="gInfo">