X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FPost.js;h=112a4971b8946845ed1cb2013c95fcc767ace11f;hb=4720a1f90f7d42f3611f064cc5ba3d768a92b5c6;hp=3ab41971c1b2cdc1d3eaf05c4335c9753403c6b0;hpb=55431b133192e59138a51591d7ef4ef20b6ceb52;p=blerg.git diff --git a/www/jssrc/blerg/Post.js b/www/jssrc/blerg/Post.js index 3ab4197..112a497 100644 --- a/www/jssrc/blerg/Post.js +++ b/www/jssrc/blerg/Post.js @@ -1,57 +1,77 @@ 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: [ - {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(); - 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); - } + name: "blerg.Post", + kind: "Control", + classes: "blerg-post", + handlers: { + onPostVisibility: "postVisibilityUpdate", + onLogin: "loggedIn", + onLogout: "loggedOut" + }, + resizePostContentTimeout: null, + components: [ + {tag: "h2", content: "What's on your mind?"}, + {kind: "onyx.InputDecorator", components: [ + {name: "postContent", classes: "content", kind: "onyx.TextArea", onkeydown: "resizePostContent", attributes: {tabindex: 4}} + ]}, + {classes: "buttons", components: [ + {name: "loginReminder", tag: "span", classes: "blerg-error", style: "margin-right: 8px; vertical-align: 60%", content: "You must log in before posting."}, + {kind: "onyx.Button", content: "Close", onclick: "closePost", classes: "onyx-negative", attributes: {tabindex: 6}}, + {name: "postButton", kind: "onyx.Button", content: "Post", onclick: "doPost", classes: "onyx-affirmative", disabled: true, attributes: {tabindex: 5}} + ]} + ], + create: function() { + this.inherited(arguments); + }, + 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(); + this.$.postContent.focus(); + if (inEvent.data && this.getData() == "") { + this.setData(inEvent.data); + this.$.postContent.node.setSelectionRange(inEvent.data.length, inEvent.data.length); + } + } 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); + }, + loggedIn: function() { + this.$.postButton.setDisabled(false); + this.$.loginReminder.hide(); + }, + loggedOut: function() { + this.$.postButton.setDisabled(true); + this.$.loginReminder.show(); + } });