Improved editor state in non-last-page reply
authorAlexander Ebert <ebert@woltlab.com>
Sun, 28 Aug 2016 11:26:59 +0000 (13:26 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 28 Aug 2016 11:26:59 +0000 (13:26 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js
wcfsetup/install/files/style/ui/message.scss
wcfsetup/install/files/style/ui/redactor.scss

index 7ac629d3fed69f655626bec1211f242db0435055..e34f361476a0a1fee8226dff0f9c8b8d0128bafb 100644 (file)
                                element.value = autosave.getInitialValue();
                        }
                        
+                       var placeholderCallback = null, replyContainer = element.closest('.messageQuickReplyContent');
+                       if (replyContainer) {
+                               var container = elById('messageQuickReply');
+                               if (container.classList.contains('messageQuickReplyCollapsed')) {
+                                       placeholderCallback = function (event) {
+                                               if (event instanceof Event) {
+                                                       event.preventDefault();
+                                               }
+                                               
+                                               if (container.classList.contains('messageQuickReplyCollapsed')) {
+                                                       container.classList.remove('messageQuickReplyCollapsed');
+                                                       $(element).redactor('focus.end');
+                                                       
+                                                       replyContainer.removeEventListener(WCF_CLICK_EVENT, placeholderCallback);
+                                               }
+                                               
+                                               return null;
+                                       };
+                                       
+                                       replyContainer.addEventListener(WCF_CLICK_EVENT, placeholderCallback);
+                               }
+                       }
+                       
                        var config = {
                                buttons: buttons,
                                formatting: ['p', 'h2', 'h3', 'h4'],
                                linkify: false,
                                linkSize: 0xBADC0DED, // some random value to disable truncating
                                minHeight: 200,
-                               placeholder: elData(element, 'placeholder') || '',
+                               //placeholder: elData(element, 'placeholder') || '',
                                plugins: [
                                        // Imperavi
                                        'alignment',
                                        buttons: buttonOptions,
                                        buttonMobile: buttonMobile,
                                        customButtons: customButtons,
-                                       highlighters: highlighters
+                                       highlighters: highlighters,
+                                       placeholderCallback: placeholderCallback
                                }
                        };
                        
                        
                        config.callbacks = config.callbacks || { };
                        config.callbacks.init = function() {
+                               var editor = element.previousElementSibling;
+                               if (replyContainer) {
+                                       elData(editor, 'reply-placeholder', elData(element, 'reply-placeholder'));
+                               }
+                               
                                // slight delay to allow Redactor to initialize itself
                                window.setTimeout(function() {
                                        $(element).redactor('code.set', content);
-                                       $(element).redactor('core.editor')[0].classList.add('redactorReady');
+                                       editor.classList.add('redactorReady');
                                }, 10);
                        };
                        
index 7fe482755c38a8768708d7fa65eb571f146209db..f868bb1884e2495732ed07d67c1425995250d347 100644 (file)
@@ -25,7 +25,7 @@ $.Redactor.prototype.WoltLabCaret = function() {
                        var selection = window.getSelection();
                        
                        var saveRange = function () {
-                               internalRange = selection.getRangeAt(0).cloneRange();
+                               internalRange = (selection.rangeCount) ? selection.getRangeAt(0).cloneRange() : null;
                        };
                        
                        var restoreRange = function () {
index 2a220a5051af237eab647d053aba4afbcb75a0f2..4d4003b4deea9e707fd620a6450a79637866b6fe 100644 (file)
@@ -3,8 +3,12 @@ $.Redactor.prototype.WoltLabInsert = function() {
        
        return {
                init: function () {
+                       var callback = this.opts.woltlab.placeholderCallback;
+                       
                        var mpHtml = this.insert.html;
                        this.insert.html = (function (html, data) {
+                               if (callback) callback = callback();
+                               
                                this.placeholder.hide();
                                this.core.editor().focus();
                                
@@ -19,6 +23,13 @@ $.Redactor.prototype.WoltLabInsert = function() {
                                        elRemove(block);
                                }
                        }).bind(this);
+                       
+                       var mpText = this.insert.text;
+                       this.insert.text = (function (text) {
+                               if (callback) callback = callback();
+                               
+                               mpText.call(this, text);
+                       }).bind(this);
                }
        };
 };
index 79a4c90a098c4446b8b128b6859d03ff0e716d1b..7d75d563fc9ff65ac9e9b80d692ac220c22377d2 100644 (file)
                }
        }
 }
-
-#messageQuickReply .messageSidebar {
-       opacity: .6;
-}
index 37dbcae768e391773b24f11da5854f99d01e1eb7..b9332587fb8cb84e2e631e1f596d1b306691294e 100644 (file)
        height: 238px;
        width: 100%;
 }
+
+.messageQuickReplyCollapsed {
+       .messageSidebar {
+               pointer-events: none;
+               
+               @include screen-sm-down {
+                       opacity: .6;
+               }
+               
+               @include screen-md-up {
+                       > .messageAuthor {
+                               > :not(.userAvatar),
+                               .badgeOnline {
+                                       display: none;
+                               }
+                       }
+                       
+                       > .userCredits {
+                               display: none;
+                       }
+               }
+       }
+       
+       .messageQuickReplyContent {
+               // simulate clickable area
+               cursor: pointer;
+               
+               .wysiwygTextarea {
+                       height: 138px;
+               }
+               
+               > .messageBody,
+               > .messageFooter {
+                       pointer-events: none;
+               }
+               
+               .redactor-editor {
+                       max-height: 100px !important;
+                       min-height: 100px !important;
+                       overflow: hidden;
+                       position: relative;
+                       
+                       &::before {
+                               color: rgb(169, 169, 169);
+                               content: attr(data-reply-placeholder);
+                               display: block;
+                               left: 20px;
+                               position: absolute;
+                               top: 50%;
+                               transform: translateY(-50%);
+                       }
+                       
+                       > * {
+                               visibility: hidden;
+                       }
+               }
+               
+               .redactor-toolbar > li,
+               .messageTabMenu li {
+                       opacity: .5;
+               }
+               
+               > .messageFooter {
+                       display: none;
+               }
+       }
+}