diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gallery.common.js | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/gallery.common.js b/lib/gallery.common.js index b1160e31..3a4d3c0a 100644 --- a/lib/gallery.common.js +++ b/lib/gallery.common.js @@ -55,20 +55,42 @@ /** * Reduce the width of an image if it's wider than its parent container - * @param elementID The image's container + * @param elementID The image container's ID */ $.fn.gallery_fit_image = function() { - var photo = $(this).find("img").filter(function() { - return this.id.match(/gPhotoId-\d+/); - }); - var cont_width = $(this).width(); + var container_width = $(this).width(); + var photo = $(this).gallery_get_photo(); var photo_width = photo.width(); - if (cont_width < photo_width) { - var proportion = cont_width / photo_width; - photo.width(cont_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); + }; + })(jQuery); |