diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-08-19 05:14:05 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-08-19 05:14:05 -0700 |
commit | bc42df35ee6cce419cbd9f514f245dcf8c70262b (patch) | |
tree | d1ad4c36130edf320368c5e08f79ebb950b6bcec /lib | |
parent | 2ac916783ad81f49185fa5c8514aefcb330a6128 (diff) | |
parent | 3b8323d5b4db4904aba9ea2f922140ab235dd681 (diff) |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gallery.ajax.js | 15 | ||||
-rw-r--r-- | lib/gallery.common.js | 78 |
2 files changed, 91 insertions, 2 deletions
diff --git a/lib/gallery.ajax.js b/lib/gallery.ajax.js new file mode 100644 index 00000000..31039ea4 --- /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 7e6acad9..e00eb62a 100644 --- a/lib/gallery.common.js +++ b/lib/gallery.common.js @@ -12,8 +12,8 @@ if (container == null) { container = 'div'; } - $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">"); - var el = $(this).children(container + ":first"); + $(this).html("<" + container + " class=\"gValign\">" + $(this).html() + "</" + container + ">"); + var el = $(this).children(container + ".gValign"); var elh = $(el).height(); var ph = $(this).height(); var nh = (ph - elh) / 2; @@ -52,4 +52,78 @@ $(this).toggleClass("gLoading" + size); }); }; + + /** + * Reduce the width of an image if it's wider than its parent container + * @param elementID The image container's ID + */ + $.fn.gallery_fit_photo = function() { + return this.each(function(i) { + var container_width = $(this).width(); + var photo = $(this).gallery_get_photo(); + var photo_width = photo.width(); + if (container_width < photo_width) { + var proportion = container_width / photo_width; + photo.width(container_width); + photo.height(proportion * photo.height()); + } + }); + }; + + /** + * Get a thumbnail or resize photo within a container + * @param elementID The image container's ID + * @return object + */ + $.fn.gallery_get_photo = function() { + var photo = $(this).find("img").filter(function() { + return this.id.match(/gPhotoId-\d+/); + }); + return photo; + }; + + /** + * Get the sum of an element's height, margin-top, and margin-bottom + * @param elementID the element's ID + * @return int + */ + $.fn.gallery_height = function() { + var ht = $(this).height(); + var mt = $(this).css("margin-top").replace("px",""); + var mb = $(this).css("margin-bottom").replace("px",""); + return ht + parseInt(mt) + parseInt(mb); + }; + + // Add hover state to buttons + $.fn.gallery_hover_init = function() { + $(".ui-state-default").hover( + function(){ + $(this).addClass("ui-state-hover"); + }, + function(){ + $(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}); + }; + + $.fn.gallery_context_menu = function() { + $(".gContextMenu ul").hide(); + $(".gContextMenu").hover( + function() { + $(this).find("ul").slideDown("fast"); + $(this).find(".gDialogLink").gallery_dialog(); + $(this).find(".gAjaxLink").gallery_ajax(); + }, + function() { + $(this).find("ul").slideUp("slow"); + } + ); + }; + })(jQuery); + |