From 96adf5238e6d95719def1e3954e1b5bc28bc9e71 Mon Sep 17 00:00:00 2001 From: Florian Orben Date: Sat, 7 Nov 2015 00:15:19 +0100 Subject: add button to preview your current post --- web/react/components/textbox.jsx | 42 ++++++++++++++++++++++++--- web/sass-files/sass/partials/_post.scss | 16 +++++++++- web/sass-files/sass/partials/_post_right.scss | 2 +- 3 files changed, 54 insertions(+), 6 deletions(-) (limited to 'web') diff --git a/web/react/components/textbox.jsx b/web/react/components/textbox.jsx index 707033d8f..82f830038 100644 --- a/web/react/components/textbox.jsx +++ b/web/react/components/textbox.jsx @@ -6,6 +6,7 @@ const SearchStore = require('../stores/search_store.jsx'); const CommandList = require('./command_list.jsx'); const ErrorStore = require('../stores/error_store.jsx'); +const TextFormatting = require('../utils/text_formatting.jsx'); const Utils = require('../utils/utils.jsx'); const Constants = require('../utils/constants.jsx'); const ActionTypes = Constants.ActionTypes; @@ -30,6 +31,7 @@ export default class Textbox extends React.Component { this.handleFocus = this.handleFocus.bind(this); this.handleBlur = this.handleBlur.bind(this); this.handlePaste = this.handlePaste.bind(this); + this.showPreview = this.showPreview.bind(this); this.state = { mentionText: '-1', @@ -118,7 +120,8 @@ export default class Textbox extends React.Component { } handleChange() { - this.props.onUserInput(ReactDOM.findDOMNode(this.refs.message).value); + const text = ReactDOM.findDOMNode(this.refs.message).value; + this.props.onUserInput(text); } handleKeyPress(e) { @@ -240,6 +243,7 @@ export default class Textbox extends React.Component { const lht = parseInt($(e).css('lineHeight'), 10); const lines = e.scrollHeight / lht; + const previewLinkHeightMod = 20; let mod = 15; if (lines < 2.5 || this.props.messageText === '') { @@ -248,12 +252,18 @@ export default class Textbox extends React.Component { if (e.scrollHeight - mod < 167) { $(e).css({height: 'auto', 'overflow-y': 'hidden'}).height(e.scrollHeight - mod); - $(w).css({height: 'auto'}).height(e.scrollHeight + 2); + $(w).css({height: 'auto'}).height(e.scrollHeight + 2 + previewLinkHeightMod); $(w).closest('.post-body__cell').removeClass('scroll'); + if (this.state.preview) { + $(ReactDOM.findDOMNode(this.refs.preview)).css({height: 'auto', 'overflow-y': 'auto'}).height(e.scrollHeight - mod); + } } else { - $(e).css({height: 'auto', 'overflow-y': 'scroll'}).height(167); - $(w).css({height: 'auto'}).height(167); + $(e).css({height: 'auto', 'overflow-y': 'scroll'}).height(167 - mod); + $(w).css({height: 'auto'}).height(167 + previewLinkHeightMod); $(w).closest('.post-body__cell').addClass('scroll'); + if (this.state.preview) { + $(ReactDOM.findDOMNode(this.refs.preview)).css({height: 'auto', 'overflow-y': 'scroll'}).height(167 - mod); + } } if (prevHeight !== $(e).height() && this.props.onHeightChange) { @@ -279,7 +289,16 @@ export default class Textbox extends React.Component { this.doProcessMentions = true; } + showPreview(e) { + e.preventDefault(); + e.target.blur(); + this.setState({preview: !this.state.preview}); + this.resize(); + } + render() { + const previewLinkVisible = this.props.messageText.length > 0; + return (
+
+
+ + {this.state.preview ? 'Edit message' : 'Preview'} +
); } diff --git a/web/sass-files/sass/partials/_post.scss b/web/sass-files/sass/partials/_post.scss index 36f6f445e..ffcba3b6a 100644 --- a/web/sass-files/sass/partials/_post.scss +++ b/web/sass-files/sass/partials/_post.scss @@ -46,7 +46,21 @@ body.ios { .textarea-wrapper { position:relative; - min-height:37px; + min-height:57px; + .textbox-preview-area { + position: absolute; + z-index: 2; + top: 0; + left: 0; + box-shadow: none; + } + .textbox-preview-link { + position: absolute; + z-index: 3; + bottom: 0; + right: 10px; + cursor: pointer; + } } .date-separator, .new-separator { diff --git a/web/sass-files/sass/partials/_post_right.scss b/web/sass-files/sass/partials/_post_right.scss index 91f9355de..c1d291073 100644 --- a/web/sass-files/sass/partials/_post_right.scss +++ b/web/sass-files/sass/partials/_post_right.scss @@ -23,7 +23,7 @@ .post-create__container { margin-top: 10px; .textarea-wrapper { - min-height: 100px; + min-height: 120px; } .custom-textarea { min-height: 100px; -- cgit v1.2.3-1-g7c22