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: [
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);
}
});