* @param {Object<string, *>} options list of configuration options
*/
init: function(options) {
+ this._activeDropdownElement = null;
this._activeElement = null;
this._dropdownMenu = null;
this._elements = new ObjectMap();
* @protected
*/
_click: function(element, event) {
- if (event !== null) event.preventDefault();
+ if (element === null) element = this._activeDropdownElement;
+ if (event) event.preventDefault();
if (this._activeElement === null) {
this._activeElement = element;
event.preventDefault();
event.stopPropagation();
- this._activeElement = element;
+ this._activeDropdownElement = element;
UiReusableDropdown.toggleDropdown(this._options.dropdownIdentifier, button);
}).bind(this));
}).bind(this)(button, element);
label.textContent = Language.get(item.label);
listItem.appendChild(label);
- if (item.action === 'editItem') {
- listItem.addEventListener('click', this._click.bind(this));
+ if (item.item === 'editItem') {
+ listItem.addEventListener('click', this._click.bind(this, null));
}
else {
listItem.addEventListener('click', callbackClick);
* @protected
*/
_dropdownToggle: function(containerId, action) {
- var elementData = this._elements.get(this._activeElement);
+ var elementData = this._elements.get(this._activeDropdownElement);
elementData.button.parentNode.classList[(action === 'open' ? 'add' : 'remove')]('dropdownOpen');
elementData.messageFooterButtons.classList[(action === 'open' ? 'add' : 'remove')]('forceVisible');
var visibility = this._dropdownOpen();
EventHandler.fire('com.woltlab.wcf.inlineEditor', 'dropdownOpen_' + this._options.dropdownIdentifier, {
- element: this._activeElement,
+ element: this._activeDropdownElement,
visibility: visibility
});
data: {
message: ''
},
- objectID: this._getObjectId(),
+ objectID: this._getObjectId(this._activeElement),
removeQuoteIDs: [] // @TODO
};
this._restoreMessage();
- this._updateHistory(this._getHash(this._getObjectId()));
+ this._updateHistory(this._getHash(this._getObjectId(this._activeElement)));
UiNotification.show();
parameters: {
containerID: this._options.containerId,
message: '',
- messageID: this._getObjectId()
+ messageID: this._getObjectId(this._activeElement)
}
};
var elementData = this._elements.get(this._activeElement);
var icon = elBySel('.fa-spinner', elementData.messageBodyEditor);
elRemove(icon);
- console.debug(icon);
- elShow(DomTraverse.childByClass(elementData.messageBodyEditor, 'editorContainer'));
+
+ var editorContainer = DomTraverse.childByClass(elementData.messageBodyEditor, 'editorContainer');
+ if (editorContainer !== null) elShow(editorContainer);
},
/**
* @protected
*/
_getEditorId: function() {
- return this._options.editorPrefix + this._getObjectId();
+ return this._options.editorPrefix + this._getObjectId(this._activeElement);
},
/**
* Returns the element's `data-object-id` value.
*
- * @param {Element=} element target element, `this._activeElement` if empty
+ * @param {Element} element target element
* @return {int}
* @protected
*/
_getObjectId: function(element) {
- return ~~elData(element || this._activeElement, 'object-id');
+ return ~~elData(element, 'object-id');
},
_ajaxFailure: function(data) {
+ var elementData = this._elements.get(this._activeElement);
+ var editor = elBySel('.redactor-editor', elementData.messageBodyEditor);
+
+ // handle errors occuring on editor load
+ if (editor === null) {
+ this._restoreMessage();
+
+ return true;
+ }
+
this._restoreEditor();
if (!data || data.returnValues === undefined || data.returnValues.errorType === undefined) {
return true;
}
- var elementData = this._elements.get(this._activeElement);
var innerError = elBySel('.innerError', elementData.messageBodyEditor);
if (innerError === null) {
innerError = elCreate('small');
innerError.className = 'innerError';
- var editor = elBySel('.redactor-editor', elementData.messageBodyEditor);
DomUtil.insertAfter(innerError, editor);
}