diff options
author | Chad Kieffer <ckieffer@gmail.com> | 2009-08-09 11:31:31 -0600 |
---|---|---|
committer | Chad Kieffer <ckieffer@gmail.com> | 2009-08-09 11:31:31 -0600 |
commit | 2f4c4a3f706d98be7dd41f8fa7c9124314c515c8 (patch) | |
tree | fdd50b4eb0db7ad586c51b989bdbcadddd013a83 | |
parent | ea17a51148884d0297baf3fc8b94916d9c60a5d3 (diff) |
Rename resizeImage gallery_fit_image to follow convention. Move the function to gallery.common.js.
-rw-r--r-- | lib/gallery.common.js | 21 | ||||
-rw-r--r-- | themes/default/js/ui.init.js | 24 |
2 files changed, 24 insertions, 21 deletions
diff --git a/lib/gallery.common.js b/lib/gallery.common.js index 7e6acad9..08656a83 100644 --- a/lib/gallery.common.js +++ b/lib/gallery.common.js @@ -12,7 +12,7 @@ if (container == null) { container = 'div'; } - $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">"); + $(this).html("<" + container + " class=\"gValign\">" + $(this).html() + "</" + container + ">"); var el = $(this).children(container + ":first"); var elh = $(el).height(); var ph = $(this).height(); @@ -52,4 +52,23 @@ $(this).toggleClass("gLoading" + size); }); }; + + /** + * Reduce the width of an image if it's wider than its parent container + * @param elementID The image's container + */ + $.fn.gallery_fit_image = function() { + var photo = $(this).find("img").filter(function() { + return this.id.match(/gPhotoId-\d+/); + }); + var cont_width = $(this).width(); + var photo_width = photo.width(); + if (cont_width < photo_width) { + var proportion = cont_width / photo_width; + photo.width(cont_width); + photo.height(proportion * photo.height()); + } + }; + })(jQuery); + diff --git a/themes/default/js/ui.init.js b/themes/default/js/ui.init.js index a8c558c5..29680a48 100644 --- a/themes/default/js/ui.init.js +++ b/themes/default/js/ui.init.js @@ -58,16 +58,15 @@ $(document).ready(function() { $(".gContextMenu a").addClass("gButtonLink ui-icon-left"); $(".gContextMenu a").prepend("<span class=\"ui-icon\"></span>"); $(".gContextMenu a span").each(function() { - var iconClass = $(this).parent().attr("class").match(/ui-icon-.[^\s]*/).toString(); + var iconClass = $(this).parent().attr("class").match(/ui-icon-.[^\s]+/).toString(); $(this).addClass(iconClass); }); } - // Photo/Item item view only + // Photo/Item item view if ($("#gItem").length) { - // Ensure that sized image versions - // fit inside their container - sizedImage(); + // Ensure the resized image fits within its container + $("#gItem").gallery_fit_image(); // Collapse comments form, insert button to expand if ($("#gAddCommentForm").length) { @@ -140,18 +139,3 @@ $(document).ready(function() { ); }); - -/** - * Reduce width of sized photo if it's wider than its parent container - */ -function sizedImage() { - var containerWidth = $("#gItem").width(); - var oPhoto = $("#gItem img").filter(function() { - return this.id.match(/gPhotoId-/); - }); - if (containerWidth < oPhoto.width()) { - var proportion = containerWidth / oPhoto.width(); - oPhoto.width(containerWidth); - oPhoto.height(proportion * oPhoto.height()); - } -} |