From 32878ebfdce943271824891639ab0384053bbadd Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 9 Sep 2010 21:04:18 -0700 Subject: Replace the hook function hack I introduced in cbba45fffc7368280e9529f55e108d0080175b6a with a namespaced jQuery custom event. This is way more portable. --- lib/gallery.common.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib/gallery.common.js') diff --git a/lib/gallery.common.js b/lib/gallery.common.js index 69452f39..9fccc602 100644 --- a/lib/gallery.common.js +++ b/lib/gallery.common.js @@ -119,11 +119,9 @@ }; // 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}); - if (typeof gallery_image_replaced_hook == 'function') { - gallery_image_replaced_hook(data, thumb); - } + $.gallery_replace_image = function(data, img_selector) { + $(img_selector).attr({src: data.src, width: data.width, height: data.height}); + $(img_selector).trigger("gallery.change"); }; // Initialize context menus -- cgit v1.2.3 From 6211ed69d7a07d88b18c4db2928663c2cb76b1ba Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 9 Sep 2010 21:25:23 -0700 Subject: Vertically realign thumbnails after rotation so that they stay centered. Partial fix for #1354. --- lib/gallery.common.js | 8 ++++++-- themes/wind/js/ui.init.js | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/gallery.common.js') diff --git a/lib/gallery.common.js b/lib/gallery.common.js index 9fccc602..548b2e7c 100644 --- a/lib/gallery.common.js +++ b/lib/gallery.common.js @@ -24,8 +24,12 @@ if (container == null) { container = 'div'; } - $(this).html("<" + container + " class=\"g-valign\">" + $(this).html() + ""); - var el = $(this).children(container + ".g-valign"); + var el = $(this).find(".g-valign"); + if (!el.length) { + $(this).html("<" + container + " class=\"g-valign\">" + $(this).html() + + ""); + el = $(this).children(container + ".g-valign"); + } var elh = $(el).height(); var ph = $(this).height(); var nh = (ph - elh) / 2; diff --git a/themes/wind/js/ui.init.js b/themes/wind/js/ui.init.js index a4fc0e2f..7637ad80 100644 --- a/themes/wind/js/ui.init.js +++ b/themes/wind/js/ui.init.js @@ -93,6 +93,11 @@ $(document).ready(function() { $("#g-place-holder").remove(); } ); + + // Realign any thumbnails that change so that when we rotate a thumb it stays centered. + $(".g-item").bind("gallery.change", function() { + $(this).gallery_valign(); + }); } // Photo/Item item view -- cgit v1.2.3 From b35886c0fc6f2d37ee1974a35b0cad50e6729757 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 11 Sep 2010 00:08:38 -0700 Subject: Refactor $.fn.gallery_context_menu() to store some variables instead of using CSS selector lookups for every operation. I assume (but have not verified) that this is more efficient. --- lib/gallery.common.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/gallery.common.js') diff --git a/lib/gallery.common.js b/lib/gallery.common.js index 548b2e7c..81e26e1b 100644 --- a/lib/gallery.common.js +++ b/lib/gallery.common.js @@ -131,20 +131,21 @@ // Initialize context menus $.fn.gallery_context_menu = function() { if ($(".g-context-menu li").length) { - var hover_target = ".g-context-menu"; + var hover_target = $(this).find(".g-context-menu"); + var list = $(hover_target).find("ul"); var in_progress = 0; - $(hover_target + " *").removeAttr('title'); - $(hover_target + " ul").hide(); - $(hover_target).hover( + hover_target.find("*").removeAttr('title'); + list.hide(); + hover_target.hover( function() { if (in_progress == 0) { - $(this).find("ul").slideDown("fast", function() { in_progress = 1; }); + list.slideDown("fast", function() { in_progress = 1; }); $(this).find(".g-dialog-link").gallery_dialog(); $(this).find(".g-ajax-link").gallery_ajax(); } }, function() { - $(this).find("ul").slideUp("slow", function() { in_progress = 0; }); + list.slideUp("slow", function() { in_progress = 0; }); } ); } -- cgit v1.2.3 From 81327641cd4d2d5bf5e1de8438ebf44d0c318314 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 11 Sep 2010 00:27:47 -0700 Subject: Fix two bugs with the context menu: 1) Prevent it from "bouncing" which happens when we queue up a lot of open and close events. Stop any running animations before starting new ones. This fixes #1340. 2) Prevent a bug that's not really visible to the user where we wind up re-initializing a context menu over and over which results in us binding tons of hover events. I don't think this causes any serious damage, but it's probably not good. --- lib/gallery.common.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/gallery.common.js') diff --git a/lib/gallery.common.js b/lib/gallery.common.js index 81e26e1b..2dbd7c7c 100644 --- a/lib/gallery.common.js +++ b/lib/gallery.common.js @@ -132,22 +132,23 @@ $.fn.gallery_context_menu = function() { if ($(".g-context-menu li").length) { var hover_target = $(this).find(".g-context-menu"); + if (hover_target.attr("context_menu_initialized")) { + return; + } var list = $(hover_target).find("ul"); - var in_progress = 0; hover_target.find("*").removeAttr('title'); list.hide(); hover_target.hover( function() { - if (in_progress == 0) { - list.slideDown("fast", function() { in_progress = 1; }); - $(this).find(".g-dialog-link").gallery_dialog(); - $(this).find(".g-ajax-link").gallery_ajax(); - } + list.stop(true, true).slideDown("fast"); + $(this).find(".g-dialog-link").gallery_dialog(); + $(this).find(".g-ajax-link").gallery_ajax(); }, function() { - list.slideUp("slow", function() { in_progress = 0; }); + list.stop(true, true).slideUp("slow"); } ); + hover_target.attr("context_menu_initialized", 1); } }; -- cgit v1.2.3