Fix record [reply] links
[blerg.git] / www / jssrc / blerg / Post.js
1 enyo.kind({
2     name: "blerg.Post",
3     kind: "Control",
4     classes: "blerg-post",
5     handlers: {
6         onPostVisibility: "postVisibilityUpdate"
7     },
8     resizePostContentTimeout: null,
9     components: [
10         {tag: "h2", content: "What's on your mind?"},
11         {kind: "onyx.InputDecorator", components: [
12             {name: "postContent", classes: "content", kind: "onyx.TextArea", onkeydown: "resizePostContent"}
13         ]},
14         {classes: "buttons", components: [
15             {kind: "onyx.Button", content: "Close", onclick: "closePost", classes: "onyx-negative"},
16             {kind: "onyx.Button", content: "Post", onclick: "doPost", classes: "onyx-affirmative"}
17         ]}
18     ],
19     getData: function() {
20         return this.$.postContent.getValue();
21     },
22     setData: function(inVal) {
23         this.$.postContent.setValue(inVal);
24     },
25     closePost: function() {
26         this.bubble('onPostVisibility', {showing: false});
27     },
28     doPost: function() {
29         this.bubble('onPost', {data: this.getData()});
30     },
31     postVisibilityUpdate: function(inSender, inEvent) {
32         if (inEvent.showing) {
33             this.show();
34             this.$.postContent.focus();
35             if (inEvent.data && this.getData() == "") {
36                 this.setData(inEvent.data);
37                 this.$.postContent.node.setSelectionRange(inEvent.data.length, inEvent.data.length);
38             }
39         } else {
40             this.hide();
41         }
42     },
43     resizePostContent: function(inSender, inEvent) {
44         if (this.resizePostContentTimeout)
45             clearTimeout(this.resizePostContentTimeout);
46         this.resizePostContentTimeout = setTimeout(function() {
47             var n = this.$.postContent.hasNode();
48             if (!n)
49                 return;
50             var c = this.getData();
51             var lines = Math.floor(c.length / (100 * (n.clientWidth / 1000))) + 1;
52             var m = c.match(/\r?\n/g);
53             if (m)
54                 lines += m.length;
55             if (lines <= 3) {
56                 this.$.postContent.setStyle("");
57             } else {
58                 this.$.postContent.setStyle("height: " + (lines * 17) + "pt");
59             }
60             this.resizePostContentTimeout = null;
61         }.bind(this), 150);
62     }
63 });