First stab at enyo rewrite
[blerg.git] / www / jssrc / blerg / Blerg.js
1 enyo.kind({
2         name: "blerg.Blerg",
3         kind: "Control",
4         lastHash: null,
5         handlers: {
6                 onStartSignup: "showSignupDialog",
7                 onTryLogin: "tryLogin",
8                 onSetTitle: "setTitle"
9         },
10         components: [
11                 {classes: "blerg-header", components: [
12                         {kind: "blerg.Title"},
13                         {kind: "blerg.Controls"},
14                         {style: "clear: both"},
15                         {name: "post", kind: "blerg.Post", showing: false},
16                         {name: "help", kind: "blerg.Help"}
17                 ]},
18                 {name: "main", kind: "blerg.Main"},
19                 {name: "signupDialog", kind: "blerg.SignupDialog"},
20                 {name: "passwdDialog", kind: "blerg.PasswdDialog"}
21         ],
22         urlmap: [
23                 ['search', /^\?post\/([^/]+)\/(.+)/, "blerg.ExternalURLPost"],
24                 ['hash',   /^#\/(ref|tag)\/([A-Za-z0-9_-]+)(?:\/p(\d+))?$/, "blerg.Tag"],
25                 ['hash',   /^#\/feed(?:\/p(\d+))?$/, "blerg.Feed"],
26                 ['hash',   /^#([A-Za-z0-9_-]+)(?:\/(p)?(\d+))?$/, "blerg.User"]
27         ],
28         pathHandlers: [ blerg.Welcome ],
29         rendered: function() {
30                 this.inherited(arguments);
31
32                 this.lastHash = location.hash;
33                 this.urlSwitch();
34
35                 //setInterval(this.hashCheck.bind(this), 250);
36
37                 document.body.addEventListener('keyup', function(event) {
38                         if (event.shiftKey && event.keyCode == 32) {
39                                 this.$.post.show();
40                                 event.stopPropagation();
41                         }
42                 }, false);
43         },
44         hashCheck: function() {
45                 if (location.hash != this.lastHash) {
46                         this.lastHash = location.hash;
47                         this.urlSwitch();
48                 }
49         },
50         urlSwitch: function() {
51                 var m;
52                 var objdef = null;
53
54                 for (var i = 0; i < this.pathHandlers.length; i++) {
55                         var handler = this.pathHandlers[i];
56                         objdef = handler.locationDetect(window.location);
57                         if (objdef)
58                                 break;
59                 }
60                 if (!objdef)
61                         objdef = {classes: "blerg-error", content: "No handler found"}
62
63                 this.$.main.updateView(objdef);
64         },
65         showSignupDialog: function() {
66                 this.$.signupDialog.show();
67         },
68         setTitle: function(inSender, inEvent) {
69                 if (inEvent.section != undefined)
70                         this.$.title.setSection(inEvent.section);
71
72                 if (inEvent.subscribed != undefined)
73                         this.$.title.setSubscribed(inEvent.subscribed);
74
75                 if (inEvent.showControls)
76                         this.$.title.showControls()
77                 else
78                         this.$.title.hideControls();
79         },
80         tryLogin: function(inSender, inEvent) {
81         }
82 });