X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FPost.js;h=527ffc920d67822e5677426e76ac9ca01ded521a;hb=13ce437d1c9120ac0813abbbf7602097e7ac14dc;hp=6e120a090dbbe8390fb2daf53baed31bfead92cc;hpb=21db04ef3e4f66d7b5c4c9be2be36703b18cbcaa;p=blerg.git diff --git a/www/jssrc/blerg/Post.js b/www/jssrc/blerg/Post.js index 6e120a0..527ffc9 100644 --- a/www/jssrc/blerg/Post.js +++ b/www/jssrc/blerg/Post.js @@ -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,38 @@ 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(); + if (inEvent.data && this.getData() == "") + this.setData(inEvent.data); + } 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); } });