Created
January 25, 2011 23:17
-
-
Save vinniefranco/795909 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Gallery = (function() { | |
var opts = {}, | |
cont = {}; | |
function displayMeta (data) { | |
if ( ! data.info) { opts.html(''); return; } | |
var meta = data.info, | |
str = "<img src='"+meta.image+"'><h3>"+meta.title+"</h3>"; | |
if (meta.parent_id) { | |
str = "<a href='#!/"+meta.parent_id+"'>< back</a>" + str; | |
} else if (meta.root) { | |
str = "<a href='#!/'>< back</a>" + str; | |
} | |
opts.html(str); | |
} | |
function buildGallery(gallery, list) { | |
/* | |
TODO This code smells. "htmhell()" | |
*/ | |
var li = $("<li/>", { | |
"id": "gallery_"+gallery.id, | |
"class": "gallery loading" | |
}).html("<h4>"+gallery.title+"</h4>"+"<p>"+gallery.meta+"</p><ul><li><a href='#!/"+gallery.id+"'>View</li><li><a class='add_photos' href='/photo_galleries/"+gallery.id+"/photos/new'>Add Photos</li></li></ul>") | |
.appendTo(list), | |
img = $("<img/>", { | |
"src": gallery.image || '/images/folder.png', | |
"alt": gallery.title | |
}).load(function() { | |
li.removeClass("loading"); | |
}).error(function(event) { | |
$(this).attr("src", '/images/folder.png'); | |
}).prependTo(li); | |
} | |
function buildPhoto(photo, list) { | |
var li = $("<li/>", { | |
"id": "photo_"+photo.id, | |
"class": "photo loading" | |
}).appendTo(list), | |
img = $("<img/>", { | |
"src": photo.image || '/images/folder.png', | |
"alt": photo.title | |
}).load(function(event) { | |
li.removeClass("loading"); | |
}).error(function(event) { | |
$(this).attr("src", '/images/folder.png'); | |
}).appendTo(li); | |
} | |
// Add this module to the stack. | |
Layout.addModule("gallery", function(data) { | |
opts = $("#meta"); | |
cont = $("#content").html(""); | |
var gallery_list = $("<ul class='photo_gallery list'/>").appendTo(cont); | |
displayMeta(data); | |
if (data.galleries) { | |
for(var datum in data.galleries) | |
buildGallery(data.galleries[datum], gallery_list); | |
} | |
if (data.photos) { | |
for(var datum in data.photos) | |
buildPhoto(data.photos[datum], gallery_list); | |
} | |
}); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment