var GalleryView = View.extend({ el: "#gallery", events: { }, initialize: function(){ this.__super__.initialize.call(this) this.template = this.$(".template").html() }, load: function(files){ if (! files.length) { this.$el.hide() } this.add(files) }, add: function(files) { files.forEach(function(file){ if (! is_image(file.filename)) { return } this.appendFile(file) }.bind(this)) }, parse: function(file){ var age = get_age(file.date) var link = make_link(file) var thumb = make_thumb(file) var t = this.template.replace(/{{username}}/g, file.username) .replace(/{{thumb}}/g, thumb) .replace(/{{link}}/g, link) .replace(/{{age}}/g, age) var $t = $(t) if (app.debug) { $t.find('.date').append(', #' + file.id) } return $t }, prependFile: function(file){ var $el = this.parse(file) this.$el.prepend($el) }, appendFile: function(file){ var $el = this.parse(file) this.$el.append($el) }, })