aboutsummaryrefslogtreecommitdiffstats
path: root/web/js
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2011-05-17 00:32:48 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2011-05-17 00:32:48 -0400
commit8131adcd41cdabc7e968d29eb100b1a53604cd25 (patch)
tree1a82ee886f2b5a77b0fa1cbccb145540738284d4 /web/js
parentSeperate photofloat internals to javascript class. (diff)
downloadPhotoFloat-8131adcd41cdabc7e968d29eb100b1a53604cd25.tar.xz
PhotoFloat-8131adcd41cdabc7e968d29eb100b1a53604cd25.zip
Add nice comments to explain things and restructure order.
Diffstat (limited to 'web/js')
-rw-r--r--web/js/011-display.js80
1 files changed, 57 insertions, 23 deletions
diff --git a/web/js/011-display.js b/web/js/011-display.js
index a8f6a02..aa1a7a1 100644
--- a/web/js/011-display.js
+++ b/web/js/011-display.js
@@ -1,4 +1,55 @@
$(document).ready(function() {
+
+ /*
+ * The display is not yet object oriented. It's procedural code
+ * broken off into functions. It makes use of libphotofloat's
+ * PhotoFloat class for the network and management logic.
+ *
+ * All of this could potentially be object oriented, but presently
+ * it should be pretty readable and sufficient. The only thing to
+ * perhaps change in the future would be to consolidate calls to
+ * jQuery selectors. And perhaps it'd be nice to move variable
+ * declarations to the top, to stress that JavaScript scope is
+ * for an entire function and always hoisted.
+ *
+ * None of the globals here polutes the global scope, as everything
+ * is enclosed in an anonymous function.
+ *
+ */
+
+
+ /* Globals */
+
+ var currentAlbum = null;
+ var currentPhoto = null;
+ var currentPhotoIndex = -1;
+ var previousAlbum = null;
+ var previousPhoto = null;
+ var originalTitle = document.title;
+ var photoFloat = new PhotoFloat();
+
+
+ /* Entry point for most events */
+
+ function hashParsed(album, photo, photoIndex) {
+ undie();
+ $("#loading").hide();
+ if (album == currentAlbum && photo == currentPhoto)
+ return;
+ previousAlbum = currentAlbum;
+ previousPhoto = currentPhoto;
+ currentAlbum = album;
+ currentPhoto = photo;
+ currentPhotoIndex = photoIndex;
+ setTitle();
+ showAlbum(previousAlbum != currentAlbum);
+ if (photo != null)
+ showPhoto();
+ }
+
+
+ /* Displays */
+
function setTitle() {
var title = "";
var documentTitle = "";
@@ -171,7 +222,10 @@ $(document).ready(function() {
thumb.addClass("current-thumb");
}
}
-
+
+
+ /* Error displays */
+
function die() {
$("#error-overlay").fadeTo(500, 0.8);
$("#error-text").fadeIn(2500);
@@ -182,29 +236,9 @@ $(document).ready(function() {
$("body, html").css("overflow", "auto");
}
- function hashParsed(album, photo, photoIndex) {
- undie();
- $("#loading").hide();
- if (album == currentAlbum && photo == currentPhoto)
- return;
- previousAlbum = currentAlbum;
- previousPhoto = currentPhoto;
- currentAlbum = album;
- currentPhoto = photo;
- currentPhotoIndex = photoIndex;
- setTitle();
- showAlbum(previousAlbum != currentAlbum);
- if (photo != null)
- showPhoto();
- }
- var currentAlbum = null;
- var currentPhoto = null;
- var currentPhotoIndex = -1;
- var previousAlbum = null;
- var previousPhoto = null;
- var originalTitle = document.title;
- var photoFloat = new PhotoFloat();
+ /* Event listeners */
+
$(window).hashchange(function() {
$("#loading").show();
$("link[rel=image_src]").remove();