Redesign user tasks
[blerg.git] / www / jssrc / blerg / Post.js
index 6e120a0..3ab4197 100644 (file)
@@ -2,6 +2,10 @@ enyo.kind({
        name: "blerg.Post",
        kind: "Control",
        classes: "blerg-post",
+       handlers: {
+               onPostVisibility: "postVisibilityUpdate"
+       },
+       resizePostContentTimeout: null,
        components: [
                {tag: "h2", content: "What's on your mind?"},
                {kind: "onyx.InputDecorator", components: [
@@ -19,9 +23,35 @@ enyo.kind({
                this.$.postContent.setValue(inVal);
        },
        closePost: function() {
-               this.hide();
+               this.bubble('onPostVisibility', {showing: false});
        },
        doPost: function() {
                this.bubble('onPost', {data: this.getData()});
+       },
+       postVisibilityUpdate: function(inSender, inEvent) {
+               if (inEvent.showing)
+                       this.show();
+               else
+                       this.hide();
+       },
+       resizePostContent: function(inSender, inEvent) {
+               if (this.resizePostContentTimeout)
+                       clearTimeout(this.resizePostContentTimeout);
+               this.resizePostContentTimeout = setTimeout(function() {
+                       var n = this.$.postContent.hasNode();
+                       if (!n)
+                               return;
+                       var c = this.getData();
+                       var lines = Math.floor(c.length / (100 * (n.clientWidth / 1000))) + 1;
+                       var m = c.match(/\r?\n/g);
+                       if (m)
+                               lines += m.length;
+                       if (lines <= 3) {
+                               this.$.postContent.setStyle("");
+                       } else {
+                               this.$.postContent.setStyle("height: " + (lines * 17) + "pt");
+                       }
+                       this.resizePostContentTimeout = null;
+               }.bind(this), 150);
        }
 });