app/js/controllers.index.js in storys-0.0.5 vs app/js/controllers.index.js in storys-0.0.6

- old
+ new

@@ -33,26 +33,21 @@ if(!sortDirection) sortDirection = "desc"; if(sortDirection == "desc") storys = storys.reverse(); storys = _.first(storys, 500); - function addStorys(storys) { + function getVisits(key) { + return parseInt(localStorage["visited." + key]); + } + + function addStories(storys) { if($("#stories > li").length) return; _.each(storys, function(story) { - var item = $("<li>"); - var link = $("<a>"); - link.attr("href", "#show/" + story.key + "!1"); - - link.append($("<span title='Story title'>").text(story.title)); - var emblems = $("<div class='emblems'>"); - emblems.append($("<span class='wc' title='Page count of story'>").text(Math.ceil(story.wordCount / 300))); - link.append(emblems); - - item.append(link); - - $("#stories").append(item); + story.visits = getVisits(story.key); + story.pages = Math.ceil(story.wordCount / 300); + $("#stories").append(controllers.index.storyTemplate({ story: story })); }); } this.init = function() { console.log("starting index"); @@ -87,11 +82,11 @@ $(".sort-direction button").removeClass("active"); $(".sort-direction button[data-sort-direction=" + sortDirection + "]").addClass("active"); $("#view-index").show().addClass("current-view"); - addStorys(storys); + addStories(storys); $.twoup.layout(); } this.render = function() { lastControllerLocation = location.hash; @@ -104,6 +99,10 @@ $(".sort button").unbind("click"); $(".sort-direction button").unbind("click"); $("#stories").empty(); $("#view-index").hide().removeClass("current-view"); } +} + +controllers.index.setup = function() { + controllers.index.storyTemplate = Handlebars.compile($("#stories-template").remove().html()); }