Fix page loading scheme; fix User switching
authorChip Black <bytex64@bytex64.net>
Sun, 22 Apr 2012 21:10:51 +0000 (14:10 -0700)
committerChip Black <bytex64@bytex64.net>
Sun, 22 Apr 2012 21:10:51 +0000 (14:10 -0700)
www/jssrc/blerg/Main.js
www/jssrc/blerg/User.js
www/jssrc/blerg/Util.js

index 4c1fa27..757779d 100644 (file)
@@ -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']();
+                       }
                }
        }
 });
index ca0916a..b977fa0 100644 (file)
@@ -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();
index 1bfab4c..b3f5369 100644 (file)
@@ -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] == '*') {