X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=sidebyside;f=www%2Fjssrc%2Fblerg%2FWelcome.js;h=1d7d9dbf816a1b31d66cff60cb67ecb344c7952f;hb=7fe1682ce5c257aee20c7b7bd20aa016eb6d8f75;hp=2ac7bde62c6f7766a6a3bfaa5b66281f1c314fca;hpb=55431b133192e59138a51591d7ef4ef20b6ceb52;p=blerg.git diff --git a/www/jssrc/blerg/Welcome.js b/www/jssrc/blerg/Welcome.js index 2ac7bde..1d7d9db 100644 --- a/www/jssrc/blerg/Welcome.js +++ b/www/jssrc/blerg/Welcome.js @@ -19,15 +19,22 @@ enyo.kind({ {name: "moreLink", kind: "blerg.Link", onNavigate: "loadMore", content: "Tell me more..."}, {style: "clear: both"}, {name: "contentBox", allowHtml: true}, - {tag: "h2", content: "Latest posts"}, - {name: "latestPosts"}, - {tag: "h2", content: "Latest tags"}, - {name: "latestTags"} + {classes: "latest", components: [ + {tag: "h2", content: "Latest posts"}, + {name: "latestPosts", classes: "latest-posts", onmouseover: "pauseTicker", onmouseout: "startTicker"}, + {tag: "h2", content: "Latest tags"}, + {name: "latestTags", classes: "latest-tags"} + ]} ], rendered: function() { this.inherited(arguments); this.bubble("onSetTitle", {section: "Welcome!"}); + this.loadLatest(); + }, + destroy: function() { + this.stopTicker(); + this.inherited(arguments); }, loadMore: function() { var req = new enyo.Ajax({ @@ -42,5 +49,63 @@ enyo.kind({ }, startSignup: function() { this.bubble('onStartSignup'); + }, + loadLatest: function() { + var req = new enyo.Ajax({ + url: baseURL + '/latest.json' + }); + req.response(function(inSender, inResponse) { + this.$.latestTags.destroyComponents(); + for (var i = 0; i < inResponse.tags.length; i++) { + var v = inResponse.tags[i]; + this.$.latestTags.createComponent({ + kind: "blerg.Link", + href: baseURL + "/#/tag/" + v, + content: "#" + v, + classes: "ref" + }); + this.$.latestTags.createComponent({noDom: true, content: " "}); + } + this.$.latestTags.render(); + + this.$.latestPosts.destroyComponents(); + for (var i = 0; i < inResponse.records.length; i++) { + var v = inResponse.records[i]; + this.$.latestPosts.createComponent({kind: "blerg.BriefRecord"}, v); + } + this.$.latestPosts.render(); + this.startTickerCycle(); + }.bind(this)); + req.go(); + }, + startTickerCycle: function() { + this.tickerTimeout = setTimeout(function() { + this.$.latestPosts.node.scrollTop = 0; + this.startTicker(); + }.bind(this), 2500); + }, + startTicker: function() { + if (this.tickerInterval) + return; + this.tickerInterval = setInterval(this.ticker.bind(this), 100); + }, + pauseTicker: function() { + clearInterval(this.tickerInterval); + this.tickerInterval = null; + }, + stopTicker: function() { + clearTimeout(this.tickerTimeout); + this.tickerTimeout = null; + clearInterval(this.tickerInterval); + this.tickerInterval = null; + }, + ticker: function() { + var n = this.$.latestPosts.node; + if (n.scrollTop < n.scrollHeight - n.clientHeight) { + n.scrollTop += 2; + } else { + this.stopTicker(); + this.startTickerCycle(); + } } });