diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6 index 9dbd7f25d..ddc86134c 100644 --- a/app/assets/javascripts/discourse/components/composer-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6 @@ -5,7 +5,7 @@ import { linkSeenCategoryHashtags, fetchUnseenCategoryHashtags } from 'discourse export default Ember.Component.extend({ classNames: ['wmd-controls'], - classNameBindings: [':wmd-controls', 'showPreview', 'showPreview::hide-preview'], + classNameBindings: ['showToolbar:toolbar-visible', ':wmd-controls', 'showPreview', 'showPreview::hide-preview'], uploadProgress: 0, showPreview: true, @@ -343,12 +343,34 @@ export default Ember.Component.extend({ }, showOptions() { + // long term we want some smart positioning algorithm in popup-menu + // the problem is that positioning in a fixed panel is a nightmare + // cause offsetParent can end up returning a fixed element and then + // using offset() is not going to work, so you end up needing special logic + // especially since we allow for negative .top, provided there is room on screen const myPos = this.$().position(); const buttonPos = this.$('.options').position(); + const popupHeight = $('#reply-control .popup-menu').height(); + const popupWidth = $('#reply-control .popup-menu').width(); + + var top = myPos.top + buttonPos.top - 15; + var left = myPos.left + buttonPos.left - (popupWidth/2); + + const composerPos = $('#reply-control').position(); + + if (composerPos.top + top - popupHeight < 0) { + top = top + popupHeight + this.$('.options').height() + 50; + } + + var replyWidth = $('#reply-control').width(); + if (left + popupWidth > replyWidth) { + left = replyWidth - popupWidth - 40; + } + this.sendAction('showOptions', { position: "absolute", - left: myPos.left + buttonPos.left, - top: myPos.top + buttonPos.top }); + left: left, + top: top }); }, showUploadModal(toolbarEvent) { diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index 5ebd6ed92..e81f14c21 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -31,7 +31,7 @@ function Toolbar() { this.groups = [ {group: 'fontStyles', buttons: []}, {group: 'insertions', buttons: []}, - {group: 'extras', buttons: [], lastGroup: true} + {group: 'extras', buttons: []} ]; this.addButton({ @@ -105,6 +105,20 @@ function Toolbar() { title: 'composer.hr_title', perform: e => e.addText("\n\n----------\n") }); + + if (Discourse.Mobile.mobileView) { + this.groups.push({group: 'mobileExtras', buttons: []}); + + this.addButton({ + id: 'preview', + group: 'mobileExtras', + icon: 'television', + title: 'composer.hr_preview', + perform: e => e.preview() + }); + } + + this.groups[this.groups.length-1].lastGroup = true; }; Toolbar.prototype.addButton = function(button) { @@ -166,6 +180,7 @@ export function onToolbarCreate(func) { export default Ember.Component.extend({ classNames: ['d-editor'], ready: false, + forcePreview: false, insertLinkHidden: true, link: '', lastSel: null, @@ -446,6 +461,10 @@ export default Ember.Component.extend({ Ember.run.scheduleOnce("afterRender", () => this.$("textarea.d-editor-input").focus()); }, + _togglePreview() { + this.toggleProperty('forcePreview'); + }, + actions: { toolbarButton(button) { const selected = this._getSelected(); @@ -453,7 +472,8 @@ export default Ember.Component.extend({ selected, applySurround: (head, tail, exampleKey) => this._applySurround(selected, head, tail, exampleKey), applyList: (head, exampleKey) => this._applyList(selected, head, exampleKey), - addText: text => this._addText(selected, text) + addText: text => this._addText(selected, text), + preview: () => this._togglePreview() }; if (button.sendAction) { @@ -463,6 +483,10 @@ export default Ember.Component.extend({ } }, + hidePreview() { + this.set('forcePreview', false); + }, + showLinkModal() { this._lastSel = this._getSelected(); this.set('insertLinkHidden', false); diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index 1c7384c25..88e6c532b 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -54,12 +54,10 @@ export default Ember.Controller.extend({ similarTopicsMessage: null, lastSimilaritySearch: null, optionsVisible: false, - lastValidatedAt: null, - isUploading: false, - topic: null, + showToolbar: false, _initializeSimilar: function() { this.set('similarTopics', []); @@ -90,6 +88,10 @@ export default Ember.Controller.extend({ this.toggleProperty('model.whisper'); }, + toggleToolbar() { + this.toggleProperty('showToolbar'); + }, + showOptions(loc) { this.appEvents.trigger('popup-menu:open', loc); this.set('optionsVisible', true); diff --git a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 index c14aa64b6..93e584f23 100644 --- a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 +++ b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 @@ -89,11 +89,15 @@ function positioningWorkaround($fixedElement) { } const checkForInputs = _.debounce(function(){ - $fixedElement.find('button,a:not(.mobile-file-upload)').each(function(idx, elem){ + $fixedElement.find('button:not(.hide-preview),a:not(.mobile-file-upload):not(.toggle-toolbar)').each(function(idx, elem){ if ($(elem).parents('.autocomplete').length > 0) { return; } + if ($(elem).parents('.d-editor-button-bar').length > 0) { + return; + } + attachTouchStart(this, function(evt){ done = true; $(document.activeElement).blur(); diff --git a/app/assets/javascripts/discourse/templates/components/d-editor.hbs b/app/assets/javascripts/discourse/templates/components/d-editor.hbs index 64ea89098..e9226920d 100644 --- a/app/assets/javascripts/discourse/templates/components/d-editor.hbs +++ b/app/assets/javascripts/discourse/templates/components/d-editor.hbs @@ -25,9 +25,12 @@ {{popup-input-tip validation=validation}} -