commit:13ce437d1c9120ac0813abbbf7602097e7ac14dc
author:Chip Black
committer:Chip Black
date:Mon Apr 16 15:02:48 2012 -0700
parents:55431b133192e59138a51591d7ef4ef20b6ceb52
Fix latest posts and tags on the welcome screen

Created new Record kinds
diff --git a/www/css/blerg.css b/www/css/blerg.css
line changes: +5/-5
index 2230014..24bb13e
--- a/www/css/blerg.css
+++ b/www/css/blerg.css
@@ -180,25 +180,25 @@ h1, h2, h3 {
 	text-align: right;
 }
 
-#latest h2 {
+.latest h2 {
 	font-size: 16pt;
 }
 
-#latest-tags {
+.latest-tags {
 	text-align: center;
 	line-height: 2em;
 }
 
-#latest-tags a {
+.latest-tags a {
 	margin: 0 0.75em;
 }
 
-#latest-posts {
+.latest-posts {
 	height: 184pt;
 	overflow: hidden;
 }
 
-#latest-posts .record {
+.latest-posts .record {
 	font-size: 12pt;
 	margin: 8pt 0;
 }

diff --git a/www/jssrc/blerg/Link.js b/www/jssrc/blerg/Link.js
line changes: +6/-1
index bb2d8d3..b2468bf
--- a/www/jssrc/blerg/Link.js
+++ b/www/jssrc/blerg/Link.js
@@ -2,12 +2,17 @@ enyo.kind({
 	name: "blerg.Link",
 	kind: "Control",
 	tag: "a",
-	href: "#",
+	published: {
+		href: "#",
+	},
 	handlers: {
 		onclick: "muteLink",
 	},
 	create: function() {
 		this.inherited(arguments);
+		this.hrefChanged();
+	},
+	hrefChanged: function() {
 		this.setAttribute('href', this.href);
 	},
 	muteLink: function(inSender, inEvent) {

diff --git a/www/jssrc/blerg/Post.js b/www/jssrc/blerg/Post.js
line changes: +5/-2
index 3ab4197..527ffc9
--- a/www/jssrc/blerg/Post.js
+++ b/www/jssrc/blerg/Post.js
@@ -29,10 +29,13 @@ enyo.kind({
 		this.bubble('onPost', {data: this.getData()});
 	},
 	postVisibilityUpdate: function(inSender, inEvent) {
-		if (inEvent.showing)
+		if (inEvent.showing) {
 			this.show();
-		else
+			if (inEvent.data && this.getData() == "")
+				this.setData(inEvent.data);
+		} else {
 			this.hide();
+		}
 	},
 	resizePostContent: function(inSender, inEvent) {
 		if (this.resizePostContentTimeout)

diff --git a/www/jssrc/blerg/Record.js b/www/jssrc/blerg/Record.js
line changes: +74/-0
index 0000000..2751042
--- /dev/null
+++ b/www/jssrc/blerg/Record.js
@@ -0,0 +1,74 @@
+enyo.kind({
+	name: "blerg.Record",
+	kind: "Control",
+	classes: "record",
+	published: {
+		data: "",
+		timestamp: 0,
+		author: "",
+		record: null
+	},
+	components: [
+		{name: "data", noDom: true},
+		{classes: "info", components: [
+			{noDom: true, content: "Posted "},
+			{name: "date", noDom: true},
+			{noDom: true, content: ". "},
+			{name: "permalink", kind: "blerg.Link", content: "[permalink]"},
+			{noDom: true, content: " "},
+			{name: "reply", kind: "blerg.Link", content: "[reply]", onclick: "postPopup"}
+		]}
+	],
+	create: function() {
+		this.inherited(arguments);
+		this.dataChanged();
+		this.timestampChanged();
+		this.updateLinks();
+	},
+	dataChanged: function() {
+		this.$.data.setContent(postMangle(this.data));
+	},
+	timestampChanged: function() {
+		this.$.date.setContent(new Date(this.timestamp * 1000).toString());
+	},
+	authorChanged: function() {
+		this.updateLinks();
+	},
+	recordChanged: function() {
+		this.updateLinks();
+	},
+	updateLinks: function() {
+		this.$.permalink.setHref(baseURL + enyo.macroize("/#{$author}/{$record}", this));
+	},
+	postPopup: function() {
+		this.bubble('onPostVisibility', {
+			showing: true,
+			data: enyo.macroize("@{$author}/{$record}", this)
+		});
+		return true;
+	}
+});
+
+enyo.kind({
+	name: "blerg.TagRecord",
+	kind: "blerg.Record"
+});
+
+enyo.kind({
+	name: "blerg.BriefRecord",
+	kind: "blerg.Record",
+	components: [
+		{name: "authorlink", kind: "blerg.Link", classes: "author ref"},
+		{noDom: true, content: " "},
+		{name: "data", noDom: true}
+	],
+	dataChanged: function() {
+		var d = this.data.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
+		this.$.data.setContent(d);
+	},
+	timestampChanged: function() { },
+	updateLinks: function() {
+		this.$.authorlink.setHref(baseURL + '/#' + this.author);
+		this.$.authorlink.setContent('@' + this.author);
+	},
+});

diff --git a/www/jssrc/blerg/Welcome.js b/www/jssrc/blerg/Welcome.js
line changes: +69/-4
index 2ac7bde..1d7d9db
--- 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();
+		}
 	}
 });

diff --git a/www/jssrc/blerg/package.js b/www/jssrc/blerg/package.js
line changes: +1/-0
index 764a0d0..c3c3013
--- a/www/jssrc/blerg/package.js
+++ b/www/jssrc/blerg/package.js
@@ -1,6 +1,7 @@
 enyo.depends(
 	'API.js',
 	'Link.js',
+	'Record.js',
 	'Title.js',
 	'Controls.js',
 	'Post.js',