r2571 - photoviewer: removed resize option, always try to resize, don't when ratio is 1 (window b...

r2571 - photoviewer: removed resize option, always try to resize, don't when ratio is 1 (window b...


Author: joern.zaefferer
Date: Thu May 14 07:52:05 2009
New Revision: 2571
Modified:
branches/photoviewer/ui/ui.photoviewer.js
Log:
photoviewer: removed resize option, always try to resize, don't when ratio
is 1 (window big enough); add tooltip to overlay, too
Modified: branches/photoviewer/ui/ui.photoviewer.js
==============================================================================
--- branches/photoviewer/ui/ui.photoviewer.js    (original)
+++ branches/photoviewer/ui/ui.photoviewer.js    Thu May 14 07:52:05 2009
@@ -16,6 +16,7 @@
    $.widget('ui.photoviewer', {
        _init: function() {
            var self = this;
+            // consider event delegation to make this more dynamic
            this._anchors().click(function(event) {
                event.preventDefault();
                if (self.overlayElement || self.viewerElement)
@@ -49,9 +50,7 @@
            $(window).resize(function() {
                if (!self.currentAnchor)
                    return;
-                if (self.options.resize) {
-                    self._resize(self._viewer());
-                }
+                self._resize(self._viewer());
                self._position(self._viewer());
            });
            if ($.fn.mousewheel) {
@@ -100,7 +99,7 @@
        
        _anchors: function() {
            // if deemed necessary, cache selection here
-            return this.element.find("a[href]:has(img[src])");
+            return this.element.find(this.options.selector);
        },
        
        _display: function(anchor, direction) {
@@ -120,10 +119,9 @@
            }
            
            this._viewer("new").attr("title", anchor.title +
this.options.titleSuffix).attr("src", anchor.href).one("load", function() {
-                if (self.options.resize) {
-                    self._resize($(this));
-                }
+                self._resize($(this));
                self._position($(this));
+                self._overlay().attr("title", anchor.title + self.options.titleSuffix)
                if (visible) {
                    self.options.rotateIn.call(this, direction == "up" ? "down" : "up");
                } else {
@@ -164,10 +162,12 @@
                borderWidth = outerWidth - img.width(),
                borderHeight = outerHeight - img.height(),
                ratio = Math.min(Math.min($(window).width() - 36, outerWidth) /
outerWidth, Math.min($(window).height() - 60, outerHeight) / outerHeight);
-            img.css({
-                width: Math.round(ratio * outerWidth - borderWidth),
-                height: Math.round(ratio * outerHeight, - borderHeight)
-            });
+            if (ratio < 1) {
+                img.css({
+                    width: Math.round(ratio * outerWidth - borderWidth),
+                    height: Math.round(ratio * outerHeight, - borderHeight)
+                });
+            }
        },
        
        _rotate: function(selectorA, selectorB, direction) {
@@ -206,8 +206,8 @@
        defaults: {
            loop: true,
            overlay: true,
-            resize: false,
-            titleSuffix: " - Click anywhere to close, use keyboard arrows or
mousewheel to rotate images",
+            selector: "a[href]:has(img[src])",
+            titleSuffix: " - Click anywhere to close (or press Escape), use
keyboard arrows or mousewheel to rotate images",
            rotateIn: function(direction) {
                $(this).effect("drop", {
                    direction: direction,