commit:65a1f7dc82554486ffa9cc03eac29a7a1642f046
author:Chip Black
committer:Chip Black
date:Sun Apr 22 14:10:51 2012 -0700
parents:9818631aecddd827374a0c01b3ec287e7b018bb1
Fix page loading scheme; fix User switching
diff --git a/www/jssrc/blerg/Main.js b/www/jssrc/blerg/Main.js
line changes: +10/-2
index 4c1fa27..757779d
--- a/www/jssrc/blerg/Main.js
+++ b/www/jssrc/blerg/Main.js
@@ -9,8 +9,16 @@ enyo.kind({
 			this.currentView = this.createComponent(objdef);
 			this.currentView.render();
 		} else {
-			for (var i in objdef)
-				this.currentView.setProperty(i, objdef[i])
+			// We don't want to invoke any change handlers until
+			// these are all set, so we do that ourselves
+			for (var i in objdef) {
+				if (i == 'kind') continue;
+				this.currentView[i] = objdef[i];
+			}
+			for (var i in objdef) {
+				if (i == 'kind') continue;
+				this.currentView[i + 'Changed'] && this.currentView[i + 'Changed']();
+			}
 		}
 	}
 });

diff --git a/www/jssrc/blerg/User.js b/www/jssrc/blerg/User.js
line changes: +17/-5
index ca0916a..b977fa0
--- a/www/jssrc/blerg/User.js
+++ b/www/jssrc/blerg/User.js
@@ -5,17 +5,17 @@ enyo.kind({
 	published: {
 		username: "",
 		permalink: false,
-		firstRecord: null,
+		record: null,
 	},
 	statics: {
 		locationDetect: function(l) {
-			var m = l.hash.match(/^#([A-Za-z0-9_-]+)(?:\/(p)?(\d+))?$/);
+			var m = l.hash.match(/^#([A-Za-z0-9_-]+)(?:\/(\d+))?$/);
 			if (m) {
 				return {
 					kind: "blerg.User",
 					username: m[1],
-					permalink: m[2] != 'p',
-					firstRecord: parseInt(m[3])
+					permalink: m[2] != undefined,
+					record: parseInt(m[2])
 				};
 			}
 		}
@@ -28,7 +28,12 @@ enyo.kind({
 		this.bubble('onSetTitle', {section: '@' + this.username});
 		this.$.records.destroyComponents();
 		this.lastRecord = null;
-		this.loadMore();
+		this.$.loadMoreButton.hide();
+		if (this.permalink) {
+			this.loadItems(this.record, this.record);
+		} else {
+			this.loadMore();
+		}
 	},
 	loadItems: function(from, to) {
 		this.inherited(arguments);
@@ -44,9 +49,16 @@ enyo.kind({
 			url: url
 		});
 		req.response(function(inSender, inResponse) {
+			if (this.permalink) {
+				this.$.loadMoreButton.hide();
+			} else {
+				this.$.loadMoreButton.show();
+			}
+
 			for (var i = 0; i < inResponse.length; i++) {
 				inResponse[i].author = this.username;
 			}
+
 			this.addItems(inResponse);
 		}.bind(this));
 		req.go();

diff --git a/www/jssrc/blerg/Util.js b/www/jssrc/blerg/Util.js
line changes: +11/-2
index 1bfab4c..b3f5369
--- a/www/jssrc/blerg/Util.js
+++ b/www/jssrc/blerg/Util.js
@@ -2,6 +2,15 @@ blerg = window.blerg || {};
 
 blerg.Util = {};
 
+// Dirty, terrible shim for rewritten links below
+blerg.Util.qlink = function() {
+	try {
+		location.href = event.target.href;
+	} catch(e) { }
+	enyo.$.blerg.bubble('onNavigate');
+	return false;
+}
+
 blerg.Util.blergFormat = function(text) {
 	var lines = text.split(/\r?\n/);
 	if (lines[lines.length - 1] == '')
@@ -67,8 +76,8 @@ blerg.Util.blergFormat = function(text) {
 		l = l.replace(/([^\w\\]|^)\*(\w[^*]*)\*(\W|$)/g, '$1<i>$2</i>$3');
 
 		// Turn refs and tags into links
-		l = l.replace(/(\s|^)#([A-Za-z0-9_-]+)/g, '$1<a href="#/tag/$2" class="ref" onclick="return qlink()">#$2</a>');
-		l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)(\/\d+)?/g, '$1<a href="#$2$3" class="ref" onclick="return qlink()">@$2</a>');
+		l = l.replace(/(\s|^)#([A-Za-z0-9_-]+)/g, '$1<a href="#/tag/$2" class="ref" onclick="return blerg.Util.qlink()">#$2</a>');
+		l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)(\/\d+)?/g, '$1<a href="#$2$3" class="ref" onclick="return blerg.Util.qlink()">@$2</a>');
 
 		// Create lists when lines begin with *
 		if (l[0] == '*') {