r2541 - photoviewer: small refactoring
Author: joern.zaefferer
Date: Wed May 13 01:35:53 2009
New Revision: 2541
Modified:
branches/photoviewer/ui/ui.photoviewer.js
Log:
photoviewer: small refactoring
Modified: branches/photoviewer/ui/ui.photoviewer.js
==============================================================================
--- branches/photoviewer/ui/ui.photoviewer.js (original)
+++ branches/photoviewer/ui/ui.photoviewer.js Wed May 13 01:35:53 2009
@@ -16,7 +16,7 @@
$.widget('ui.photoviewer', {
_init: function() {
var self = this;
- this.anchors =
this.element.find("a[href]:has(img[src])").click(function(event) {
+ this._anchors().click(function(event) {
self._display(this);
return false;
});
@@ -56,6 +56,11 @@
}
},
+ _anchors: function() {
+ // consider caching selection
+ return this.element.find("a[href]:has(img[src])");
+ },
+
_display: function(anchor, direction) {
if (!anchor)
return;
@@ -95,15 +100,18 @@
},
next: function() {
- if (!this.currentAnchor)
- return;
- this._display(this.anchors.filter(":gt(" +
this.anchors.index(this.currentAnchor) + "):first")[0], "down");
+ this._rotate(":gt(", "):first", "up");
},
prev: function() {
+ this._rotate(":lt(", "):last", "down");
+ },
+
+ _rotate: function(selectorA, selectorB, direction) {
if (!this.currentAnchor)
return;
- this._display(this.anchors.filter(":lt(" +
this.anchors.index(this.currentAnchor) + "):last")[0], "up");
+ var anchors = this._anchors();
+ this._display(anchors.filter(selectorA +
anchors.index(this.currentAnchor) + selectorB)[0], direction);
},
_viewer: function() {