X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FPost.js;h=1f7ea7da4bb10e448031721dbfa9a2d2f2b83934;hb=80ad774f55998cc11e08694245dfd6cb1b49a86f;hp=6e120a090dbbe8390fb2daf53baed31bfead92cc;hpb=21db04ef3e4f66d7b5c4c9be2be36703b18cbcaa;p=blerg.git diff --git a/www/jssrc/blerg/Post.js b/www/jssrc/blerg/Post.js index 6e120a0..1f7ea7d 100644 --- a/www/jssrc/blerg/Post.js +++ b/www/jssrc/blerg/Post.js @@ -1,27 +1,60 @@ enyo.kind({ - name: "blerg.Post", - kind: "Control", - classes: "blerg-post", - components: [ - {tag: "h2", content: "What's on your mind?"}, - {kind: "onyx.InputDecorator", components: [ - {name: "postContent", classes: "content", kind: "onyx.TextArea", onkeydown: "resizePostContent"} - ]}, - {classes: "buttons", components: [ - {kind: "onyx.Button", content: "Close", onclick: "closePost", classes: "onyx-negative"}, - {kind: "onyx.Button", content: "Post", onclick: "doPost", classes: "onyx-affirmative"} - ]} - ], - getData: function() { - return this.$.postContent.getValue(); - }, - setData: function(inVal) { - this.$.postContent.setValue(inVal); - }, - closePost: function() { - this.hide(); - }, - doPost: function() { - this.bubble('onPost', {data: this.getData()}); - } + 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: [ + {name: "postContent", classes: "content", kind: "onyx.TextArea", onkeydown: "resizePostContent"} + ]}, + {classes: "buttons", components: [ + {kind: "onyx.Button", content: "Close", onclick: "closePost", classes: "onyx-negative"}, + {kind: "onyx.Button", content: "Post", onclick: "doPost", classes: "onyx-affirmative"} + ]} + ], + getData: function() { + return this.$.postContent.getValue(); + }, + setData: function(inVal) { + this.$.postContent.setValue(inVal); + }, + closePost: function() { + 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); + } });