Get rid of CoffeeScript-style weirdness and make it plain and simple.
This commit is contained in:
parent
fc2f923de1
commit
264738009b
@ -1,80 +1,10 @@
|
||||
(function() {
|
||||
var PhotoFloat = (function() {
|
||||
PhotoFloat.cachePath = function(path) {
|
||||
if (path === "")
|
||||
return "root";
|
||||
if (path[0] === "/")
|
||||
path = path.substring(1);
|
||||
path = path
|
||||
.replace(/ /g, "_")
|
||||
.replace(/\//g, "-")
|
||||
.replace(/\(/g, "")
|
||||
.replace(/\)/g, "")
|
||||
.replace(/#/g, "")
|
||||
.replace(/&/g, "")
|
||||
.replace(/,/g, "")
|
||||
.replace(/\[/g, "")
|
||||
.replace(/\]/g, "")
|
||||
.replace(/"/g, "")
|
||||
.replace(/'/g, "")
|
||||
.replace(/_-_/g, "-")
|
||||
.toLowerCase();
|
||||
while (path.indexOf("--") !== -1)
|
||||
path = path.replace(/--/g, "-");
|
||||
while (path.indexOf("__") !== -1)
|
||||
path = path.replace(/__/g, "_");
|
||||
return path;
|
||||
};
|
||||
PhotoFloat.photoHash = function(album, photo) {
|
||||
return PhotoFloat.albumHash(album) + "/" + PhotoFloat.cachePath(photo.name);
|
||||
};
|
||||
PhotoFloat.albumHash = function(album) {
|
||||
if (typeof album.photos !== "undefined" && album.photos !== null)
|
||||
return PhotoFloat.cachePath(album.path);
|
||||
return PhotoFloat.cachePath(album.parent.path + "/" + album.path);
|
||||
};
|
||||
PhotoFloat.photoPath = function(album, photo, size, square) {
|
||||
var suffix;
|
||||
if (square)
|
||||
suffix = size.toString() + "s";
|
||||
else
|
||||
suffix = size.toString();
|
||||
return "cache/" + PhotoFloat.cachePath(PhotoFloat.photoHash(album, photo) + "_" + suffix + ".jpg");
|
||||
};
|
||||
PhotoFloat.originalPhotoPath = function(album, photo) {
|
||||
return "albums/" + album.path + "/" + photo.name;
|
||||
};
|
||||
PhotoFloat.trimExtension = function(name) {
|
||||
var index = name.lastIndexOf(".");
|
||||
if (index !== -1)
|
||||
return name.substring(0, index);
|
||||
return name;
|
||||
};
|
||||
PhotoFloat.cleanHash = function(hash) {
|
||||
while (hash.length) {
|
||||
if (hash[0] === "#")
|
||||
hash = hash.substring(1);
|
||||
else if (hash[0] === "!")
|
||||
hash = hash.substring(1);
|
||||
else if (hash[0] === "/")
|
||||
hash = hash.substring(1);
|
||||
else if (hash[hash.length - 1] === "/")
|
||||
hash = hash.substring(0, hash.length - 1);
|
||||
else
|
||||
break;
|
||||
}
|
||||
return hash;
|
||||
};
|
||||
/* constructor */
|
||||
function PhotoFloat() {
|
||||
this.albumCache = [];
|
||||
}
|
||||
PhotoFloat.prototype.cachePath = PhotoFloat.cachePath;
|
||||
PhotoFloat.prototype.photoHash = PhotoFloat.photoHash;
|
||||
PhotoFloat.prototype.albumHash = PhotoFloat.albumHash;
|
||||
PhotoFloat.prototype.photoPath = PhotoFloat.photoPath;
|
||||
PhotoFloat.prototype.originalPhotoPath = PhotoFloat.originalPhotoPath;
|
||||
PhotoFloat.prototype.trimExtension = PhotoFloat.trimExtension;
|
||||
PhotoFloat.prototype.cleanHash = PhotoFloat.cleanHash;
|
||||
|
||||
/* public member functions */
|
||||
PhotoFloat.prototype.album = function(subalbum, callback, error) {
|
||||
var cacheKey, ajaxOptions, self;
|
||||
if (typeof subalbum.photos !== "undefined" && subalbum.photos !== null) {
|
||||
@ -155,7 +85,83 @@
|
||||
callback(theAlbum, photo, i);
|
||||
}, error);
|
||||
};
|
||||
return PhotoFloat;
|
||||
})();
|
||||
|
||||
/* static functions */
|
||||
PhotoFloat.cachePath = function(path) {
|
||||
if (path === "")
|
||||
return "root";
|
||||
if (path[0] === "/")
|
||||
path = path.substring(1);
|
||||
path = path
|
||||
.replace(/ /g, "_")
|
||||
.replace(/\//g, "-")
|
||||
.replace(/\(/g, "")
|
||||
.replace(/\)/g, "")
|
||||
.replace(/#/g, "")
|
||||
.replace(/&/g, "")
|
||||
.replace(/,/g, "")
|
||||
.replace(/\[/g, "")
|
||||
.replace(/\]/g, "")
|
||||
.replace(/"/g, "")
|
||||
.replace(/'/g, "")
|
||||
.replace(/_-_/g, "-")
|
||||
.toLowerCase();
|
||||
while (path.indexOf("--") !== -1)
|
||||
path = path.replace(/--/g, "-");
|
||||
while (path.indexOf("__") !== -1)
|
||||
path = path.replace(/__/g, "_");
|
||||
return path;
|
||||
};
|
||||
PhotoFloat.photoHash = function(album, photo) {
|
||||
return PhotoFloat.albumHash(album) + "/" + PhotoFloat.cachePath(photo.name);
|
||||
};
|
||||
PhotoFloat.albumHash = function(album) {
|
||||
if (typeof album.photos !== "undefined" && album.photos !== null)
|
||||
return PhotoFloat.cachePath(album.path);
|
||||
return PhotoFloat.cachePath(album.parent.path + "/" + album.path);
|
||||
};
|
||||
PhotoFloat.photoPath = function(album, photo, size, square) {
|
||||
var suffix;
|
||||
if (square)
|
||||
suffix = size.toString() + "s";
|
||||
else
|
||||
suffix = size.toString();
|
||||
return "cache/" + PhotoFloat.cachePath(PhotoFloat.photoHash(album, photo) + "_" + suffix + ".jpg");
|
||||
};
|
||||
PhotoFloat.originalPhotoPath = function(album, photo) {
|
||||
return "albums/" + album.path + "/" + photo.name;
|
||||
};
|
||||
PhotoFloat.trimExtension = function(name) {
|
||||
var index = name.lastIndexOf(".");
|
||||
if (index !== -1)
|
||||
return name.substring(0, index);
|
||||
return name;
|
||||
};
|
||||
PhotoFloat.cleanHash = function(hash) {
|
||||
while (hash.length) {
|
||||
if (hash[0] === "#")
|
||||
hash = hash.substring(1);
|
||||
else if (hash[0] === "!")
|
||||
hash = hash.substring(1);
|
||||
else if (hash[0] === "/")
|
||||
hash = hash.substring(1);
|
||||
else if (hash[hash.length - 1] === "/")
|
||||
hash = hash.substring(0, hash.length - 1);
|
||||
else
|
||||
break;
|
||||
}
|
||||
return hash;
|
||||
};
|
||||
|
||||
/* make static methods callable as member functions */
|
||||
PhotoFloat.prototype.cachePath = PhotoFloat.cachePath;
|
||||
PhotoFloat.prototype.photoHash = PhotoFloat.photoHash;
|
||||
PhotoFloat.prototype.albumHash = PhotoFloat.albumHash;
|
||||
PhotoFloat.prototype.photoPath = PhotoFloat.photoPath;
|
||||
PhotoFloat.prototype.originalPhotoPath = PhotoFloat.originalPhotoPath;
|
||||
PhotoFloat.prototype.trimExtension = PhotoFloat.trimExtension;
|
||||
PhotoFloat.prototype.cleanHash = PhotoFloat.cleanHash;
|
||||
|
||||
/* expose class globally */
|
||||
window.PhotoFloat = PhotoFloat;
|
||||
}).call(this);
|
||||
}());
|
||||
|
Loading…
Reference in New Issue
Block a user