Merge remote-tracking branch 'refs/remotes/origin/2.1' into 3.0
authorAlexander Ebert <ebert@woltlab.com>
Mon, 12 Feb 2018 13:14:24 +0000 (14:14 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 12 Feb 2018 13:14:24 +0000 (14:14 +0100)
# Conflicts:
# wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
# wcfsetup/install/files/js/WCF.Message.js

1  2 
wcfsetup/install/files/js/WCF.Message.js

index 89f6bc988d63ea5e006d8358fbebc0ad81a22a8c,bfe5b30ccb1245e2e36d7c55e34cd1e7b501957c..060c4318e3dc88434c2be9d7e6a838b67c7d4c0b
@@@ -1358,165 -1756,167 +1358,184 @@@ WCF.Message.Quote.Handler = Class.exten
  });
  
  /**
 - * Handles submit buttons for forms with an embedded WYSIWYG editor.
 + * Manages stored quotes.
 + * 
 + * @param     integer         count
   */
 -WCF.Message.Submit = {
 +WCF.Message.Quote.Manager = Class.extend({
        /**
 -       * list of registered buttons
 -       * @var object
 +       * list of form buttons
 +       * @var {Object}
         */
 -      _buttons: { },
 +      _buttons: {},
        
        /**
 -       * Registers submit button for specified wysiwyg container id.
 -       * 
 -       * @param       string          wysiwygContainerID
 -       * @param       string          selector
 +       * number of stored quotes
 +       * @var {int}
         */
 -      registerButton: function(wysiwygContainerID, selector) {
 -              if (!WCF.Browser.isChrome()) {
 -                      return;
 -              }
 -              
 -              this._buttons[wysiwygContainerID] = $(selector);
 -      },
 +      _count: 0,
        
        /**
 -       * Triggers 'click' event for registered buttons.
 -       */
 -      execute: function(wysiwygContainerID) {
 -              if (!this._buttons[wysiwygContainerID]) {
 -                      return;
 -              }
 -              
 -              this._buttons[wysiwygContainerID].trigger('click');
 -      }
 -};
 -
 -/**
 - * Namespace for message quotes.
 - */
 -WCF.Message.Quote = { };
 -
 -/**
 - * Handles message quotes.
 - * 
 - * @param     string          className
 - * @param     string          objectType
 - * @param     string          containerSelector
 - * @param     string          messageBodySelector
 - */
 -WCF.Message.Quote.Handler = Class.extend({
 -      /**
 -       * active container id
 -       * @var string
 +       * dialog overlay
 +       * @var {jQuery}
         */
 -      _activeContainerID: '',
 +      _dialog: null,
        
        /**
 -       * action class name
 -       * @var string
 +       * editor element id
 +       * @var {string}
         */
 -      _className: '',
 +      _editorId: '',
        
        /**
 -       * list of message containers
 -       * @var object
 +       * alternative editor element id
 +       * @var {string}
         */
 -      _containers: { },
 +      _editorIdAlternative: '',
        
        /**
 -       * container selector
 -       * @var string
 +       * form element
 +       * @var {jQuery}
         */
 -      _containerSelector: '',
 +      _form: null,
        
        /**
 -       * 'copy quote' overlay
 -       * @var jQuery
 +       * list of quote handlers
 +       * @var {Object}
         */
 -      _copyQuote: null,
 +      _handlers: {},
        
        /**
 -       * marked message
 -       * @var string
 +       * true, if an up-to-date template exists
 +       * @var {boolean}
         */
 -      _message: '',
 +      _hasTemplate: false,
        
        /**
 -       * message body selector
 -       * @var string
 +       * true, if related quotes should be inserted
 +       * @var {boolean}
         */
 -      _messageBodySelector: '',
 +      _insertQuotes: true,
        
        /**
 -       * object id
 -       * @var integer
 +       * action proxy
 +       * @var {WCF.Action.Proxy}
         */
 -      _objectID: 0,
 +      _proxy: null,
        
        /**
 -       * object type name
 -       * @var string
 +       * list of quotes to remove upon submit
 +       * @var {Array}
         */
 -      _objectType: '',
 +      _removeOnSubmit: [ ],
        
        /**
 -       * action proxy
 -       * @var WCF.Action.Proxy
 +       * allow pasting
 +       * @var {boolean}
         */
 -      _proxy: null,
 +      _supportPaste: false,
        
 -       * quote manager
 -       * @var WCF.Message.Quote.Manager
+       /**
 -      _quoteManager: null,
++       * pasting was temporarily enabled due to an alternative editor being set
++       * @var boolean
+        */
++      _supportPasteOverride: false,
+       
        /**
 -       * Initializes the quote handler for given object type.
 +       * Initializes the quote manager.
         * 
 -       * @param       WCF.Message.Quote.Manager       quoteManager
 -       * @param       string                          className
 -       * @param       string                          objectType
 -       * @param       string                          containerSelector
 -       * @param       string                          messageBodySelector
 -       * @param       string                          messageContentSelector
 -       * @param       boolean                         supportDirectInsert
 +       * @param       {int}           count
 +       * @param       {string}        elementID
 +       * @param       {boolean}       supportPaste
 +       * @param       {Array}         removeOnSubmit
         */
 -      init: function(quoteManager, className, objectType, containerSelector, messageBodySelector, messageContentSelector, supportDirectInsert) {
 -              this._className = className;
 -              if (this._className == '') {
 -                      console.debug("[WCF.Message.QuoteManager] Empty class name given, aborting.");
 -                      return;
 -              }
 +      init: function(count, elementID, supportPaste, removeOnSubmit) {
 +              this._buttons = {
 +                      insert: null,
 +                      remove: null
 +              };
 +              this._count = parseInt(count) || 0;
 +              this._dialog = null;
 +              this._editorId = '';
 +              this._editorIdAlternative = '';
 +              this._form = null;
 +              this._handlers = { };
 +              this._hasTemplate = false;
 +              this._insertQuotes = true;
 +              this._removeOnSubmit = [];
 +              this._supportPaste = false;
++              this._supportPasteOverride = false;
                
 -              this._objectType = objectType;
 -              if (this._objectType == '') {
 -                      console.debug("[WCF.Message.QuoteManager] Empty object type name given, aborting.");
 -                      return;
 +              if (elementID) {
 +                      var element = $('#' + elementID);
 +                      if (element.length) {
 +                              this._editorId = elementID;
 +                              this._supportPaste = true;
 +                              
 +                              // get surrounding form-tag
 +                              this._form = element.parents('form:eq(0)');
 +                              if (this._form.length) {
 +                                      this._form.submit(this._submit.bind(this));
 +                                      this._removeOnSubmit = removeOnSubmit || [];
 +                              }
 +                              else {
 +                                      this._form = null;
 +                                      
 +                                      // allow override
 +                                      this._supportPaste = (supportPaste === true);
 +                              }
 +                      }
                }
                
 -              this._containerSelector = containerSelector;
 -              this._message = '';
 -              this._messageBodySelector = messageBodySelector;
 -              this._messageContentSelector = messageContentSelector;
 -              this._objectID = 0;
                this._proxy = new WCF.Action.Proxy({
 -                      success: $.proxy(this._success, this)
 +                      showLoadingOverlay: false,
 +                      success: $.proxy(this._success, this),
 +                      url: 'index.php?message-quote/&t=' + SECURITY_TOKEN
                });
                
 -              this._initContainers();
 +              this._toggleShowQuotes();
                
 -              supportDirectInsert = (supportDirectInsert && quoteManager.supportPaste()) ? true : false;
 -              this._initCopyQuote(supportDirectInsert);
 +              WCF.System.Event.addListener('com.woltlab.wcf.quote', 'reload', this.countQuotes.bind(this));
                
 -              $(document).mouseup($.proxy(this._mouseUp, this));
 +              // event forwarding
 +              WCF.System.Event.addListener('com.woltlab.wcf.message.quote', 'insert', (function(data) {
 +                      //noinspection JSUnresolvedVariable
 +                      WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'insertQuote_' + (this._editorIdAlternative ? this._editorIdAlternative : this._editorId), {
 +                              author: data.quote.username,
 +                              content: data.quote.text,
 +                              isText: !data.quote.isFullQuote,
 +                              link: data.quote.link
 +                      });
 +              }).bind(this));
 +      },
 +      
 +      /**
 +       * Sets an alternative editor element id on runtime.
 +       * 
 +       * @param       {(string|jQuery)}       elementId       element id or jQuery element
 +       */
 +      setAlternativeEditor: function(elementId) {
++              if (!this._editorIdAlternative && !this._supportPaste) {
++                      this._hasTemplate = false;
++                      this._supportPaste = true;
++                      this._supportPasteOverride = true;
++              }
+               
 -              // register with quote manager
 -              this._quoteManager = quoteManager;
 -              this._quoteManager.register(this._objectType, this);
 +              if (typeof elementId === 'object') elementId = elementId[0].id;
 +              this._editorIdAlternative = elementId;
 +      },
 +      
 +      /**
 +       * Clears alternative editor element id.
 +       */
 +      clearAlternativeEditor: function() {
++              if (this._supportPasteOverride) {
++                      this._hasTemplate = false;
++                      this._supportPaste = false;
++                      this._supportPasteOverride = false;
++              }
+               
 -              // register with DOMNodeInsertedHandler
 -              WCF.DOMNodeInsertedHandler.addCallback('WCF.Message.Quote.Handler' + objectType.hashCode(), $.proxy(this._initContainers, this));
 +              this._editorIdAlternative = '';
        },
        
        /**