X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FPost.js;h=b4ab559b6b00a3f44d7c0b40d5be5b55c2e8c801;hb=4210d2d20df6635e19c20f5b303d498f4657968b;hp=de01c86a96fca7e0ac3892d4a75048c340099937;hpb=3e5f69d01b9488475413d4ecce8161ab7a889ca2;p=blerg.git diff --git a/www/jssrc/blerg/Post.js b/www/jssrc/blerg/Post.js index de01c86..b4ab559 100644 --- a/www/jssrc/blerg/Post.js +++ b/www/jssrc/blerg/Post.js @@ -1,27 +1,42 @@ enyo.kind({ name: "blerg.Post", - kind: "Control", + kind: "FittableRows", classes: "blerg-post", handlers: { onPostVisibility: "postVisibilityUpdate", onLogin: "loggedIn", - onLogout: "loggedOut" + onLogout: "loggedOut", + onkeydown: "keyHandler" }, - resizePostContentTimeout: null, components: [ - {name: "helpContent", allowHtml: true, showing: false}, - {style: "position: relative;", components: [ - {tag: "h2", content: "What's on your mind?", style: "width: 75%;",}, - {name: "showHelpLink", kind: "blerg.Link", onNavigate: "showHelp", content: "Help!", style: "position: absolute; right: 1pt; bottom: 1pt; font-weight: bold; font-size: large;"}, - {name: "hideHelpLink", kind: "blerg.Link", onNavigate: "hideHelp", content: "Hide Help", style: "position: absolute; right: 1pt; bottom: 1pt; font-weight: bold; font-size: large;", showing: false} + {tag: "h2", content: "What's on your mind?"}, + {kind: "onyx.InputDecorator", alwaysLooksFocused: true, classes: "content-decorator", fit: true, components: [ + {name: "postContent", kind: "onyx.TextArea", classes: "content", onkeyup: "updatePreview", attributes: {tabindex: 4}} ]}, - {kind: "onyx.InputDecorator", components: [ - {name: "postContent", classes: "content", kind: "onyx.TextArea", onkeydown: "resizePostContent", attributes: {tabindex: 4}} + {name: "toolbar", classes: "toolbar", components: [ + {classes: "buttons", fit: true, components: [ + {name: "loginReminder", tag: "span", classes: "blerg-error", style: "margin-right: 8px", 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}} + ]}, + {classes: "switcher", components: [ + {kind: "onyx.RadioGroup", onActivate: "switchBottomPanel", components: [ + {name: "replyButton", content: "Replying to", showing: false}, + {name: "previewButton", content: "Preview"}, + {content: "Help"} + ]} + ]} ]}, - {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}} + {name: "bottomPanel", kind: "Panels", classes: "bottom-panel", draggable: false, fit: true, components: [ + {kind: "Scroller", components: [ + {name: "replyView", classes: "record", allowHtml: true}, + ]}, + {kind: "Scroller", components: [ + {name: "preview", classes: "record", allowHtml: true}, + ]}, + {kind: "Scroller", components: [ + {name: "helpContent", allowHtml: true}, + ]} ]}, {name: "api", kind: "blerg.API", onPostSuccessful: "postSuccessful", @@ -46,7 +61,8 @@ enyo.kind({ this.setData(''); this.closePost(); if (location.hash != '#' + blerg.API.username) { - qlink(blerg.API.username); + location.hash = '#' + blerg.API.username + this.bubble('onNavigate'); } else { this.bubble('onReload'); } @@ -58,33 +74,37 @@ enyo.kind({ 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); + this.updatePreview(); } + + if (inEvent.replyto) { + this.$.replyButton.show(); + this.$.replyButton.setActive(true); + this.$.replyView.setContent(inEvent.replyto); + } else { + this.$.replyButton.hide(); + this.$.previewButton.setActive(true); + } + + // Need to reflow manually because this is hidden by default + this.$.toolbar.reflow(); + this.reflow(); } else { - this.hide(); + this.$.postContent.node.blur(); + setTimeout(function() { + this.hide(); + this.removeClass('exit'); + }.bind(this), 500); } + this.addRemoveClass('enter', inEvent.showing); + this.addRemoveClass('exit', !inEvent.showing); }, - 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); + updatePreview: function(inSender, inEvent) { + this.$.preview.setContent(blerg.Util.blergFormat(this.getData())); }, loggedIn: function() { this.$.postButton.setDisabled(false); @@ -94,10 +114,7 @@ enyo.kind({ this.$.postButton.setDisabled(true); this.$.loginReminder.show(); }, - showHelp: function() { - this.$.helpContent.show(); - this.$.showHelpLink.hide(); - this.$.hideHelpLink.show(); + loadHelp: function() { if (this.$.helpContent.getContent() == '') { var req = new enyo.Ajax({ url: baseURL + '/doc/post_help.html', @@ -109,9 +126,17 @@ enyo.kind({ req.go(); } }, - hideHelp: function() { - this.$.helpContent.hide(); - this.$.showHelpLink.show(); - this.$.hideHelpLink.hide(); + switchBottomPanel: function(inSender, inEvent) { + var active = inSender.getActive(); + var index = inSender.children.indexOf(active); + this.$.bottomPanel.setIndex(index); + if (index == 2) { + this.loadHelp(); + } + }, + keyHandler: function(inSender, inEvent) { + if (inEvent.which == 27) { + this.closePost(); + } } });