summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Kieffer <ckieffer@gmail.com>2009-08-09 22:51:21 -0600
committerChad Kieffer <ckieffer@gmail.com>2009-08-09 22:51:21 -0600
commita961211f569d51631a8ac12327cb72b4818c4853 (patch)
tree97b8673020a6549cda28181741e73716186e2291
parent13546d0be70764af812bb52c6022c4eeb0438ac0 (diff)
Move the get photo filter out to it's own function for re-use. Docblock cleanup.
-rw-r--r--lib/gallery.common.js38
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);