/**
* Handles message quotes.
- *
- * @param string className
- * @param string objectType
- * @param string containerSelector
- * @param string messageBodySelector
*/
WCF.Message.Quote.Handler = Class.extend({
/**
/**
* Initializes the quote handler for given object type.
*
- * @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 {WCF.Message.Quote.Manager} quoteManager
+ * @param {string} className
+ * @param {string} objectType
+ * @param {string} containerSelector
+ * @param {string} messageBodySelector
+ * @param {string} messageContentSelector
+ * @param {boolean} supportDirectInsert
*/
init: function(quoteManager, className, objectType, containerSelector, messageBodySelector, messageContentSelector, supportDirectInsert) {
this._className = className;
return true;
}
- if (self._messageBodySelector !== null) {
+ if (self._messageBodySelector) {
$container = $container.find(self._messageBodySelector).data('containerID', $containerID);
}
/**
* Handles mouse down event.
*
- * @param object event
+ * @param {Event} event
*/
_mouseDown: function(event) {
// hide copy quote
- this._copyQuote.hide();
+ this._copyQuote.removeClass('active');
// store container ID
var $container = $(event.currentTarget);
return;
}
else {
- // check if mousedown occured inside a <blockquote>
+ // check if mousedown occurred inside a <blockquote>
var $element = event.target;
while ($element !== $container[0]) {
if ($element.tagName === 'BLOCKQUOTE') {
}
this._activeContainerID = $container.wcfIdentify();
-
- // remove alt-tag from all images, fixes quoting in Firefox
- if ($.browser.mozilla) {
- // TODO: is this still required?
- $container.find('img').each(function() {
- var $image = $(this);
- $image.data('__alt', $image.attr('alt')).removeAttr('alt');
- });
- }
},
/**
* Returns the text of a node and its children.
*
- * @param object node
- * @return string
+ * @param {Node} node
+ * @return {string}
*/
_getNodeText: function(node) {
// work-around for IE, see http://stackoverflow.com/a/5983176
var $nodeFilter = function(node) {
switch (node.tagName) {
case 'BLOCKQUOTE':
- case 'H3':
+ case 'IMG':
case 'SCRIPT':
return NodeFilter.FILTER_REJECT;
break;
case 'LI':
case 'UL':
$text += "\n";
- break;
+ break;
case 'TD':
if (!$.browser.msie) {
$text += "\n";
}
- break;
+ break;
+
+ case 'P':
+ $text += "\n\n";
+ break;
}
}
else {
/**
* Handles the mouse up event.
*
- * @param object event
+ * @param {Event} event
*/
_mouseUp: function(event) {
// ignore event
if (this._activeContainerID == '') {
- this._copyQuote.hide();
+ this._copyQuote.removeClass('active');
return;
}
var $selection = this._getSelectedText();
var $text = $.trim($selection);
if ($text == '') {
- this._copyQuote.hide();
+ this._copyQuote.removeClass('active');
return;
}
var $messageBody = (this._messageBodySelector) ? $container.find(this._messageContentSelector)[0] : $container[0];
- // check if mouseup occured within a <blockquote>
+ // check if mouseup occurred within a <blockquote>
var $element = event.target;
while ($element !== $container[0]) {
if ($element === null || $element.tagName === 'BLOCKQUOTE') {
- this._copyQuote.hide();
+ this._copyQuote.removeClass('active');
return;
}
// check if selection starts and ends within the $messageBody element
var $range = window.getSelection().getRangeAt(0);
if (!this._elementInsideContainer($range.startContainer, $messageBody) || !this._elementInsideContainer($range.endContainer, $messageBody)) {
- this._copyQuote.hide();
+ this._copyQuote.removeClass('active');
return;
}
if (this._normalize($messageText).indexOf(this._normalize($text)) === -1) {
return;
}
- this._copyQuote.show();
+ this._copyQuote.addClass('active');
var $coordinates = this._getBoundingRectangle($container, window.getSelection());
var $dimensions = this._copyQuote.getDimensions('outer');
top: $coordinates.top - $dimensions.height - 7 + 'px',
left: $left + 'px'
});
- this._copyQuote.hide();
+ this._copyQuote.removeClass('active');
// reset containerID
this._activeContainerID = '';
// show element after a delay, to prevent display if text was unmarked again (clicking into marked text)
var self = this;
- new WCF.PeriodicalExecuter(function(pe) {
- pe.stop();
-
+ window.setTimeout(function() {
var $text = $.trim(self._getSelectedText());
if ($text != '') {
- self._copyQuote.show();
+ self._copyQuote.addClass('active');
self._message = $text;
self._objectID = $container.data('objectID');
-
- // revert alt tags, fixes quoting in Firefox
- if ($.browser.mozilla) {
- // TODO: is this still required?
- $container.find('img').each(function() {
- var $image = $(this);
- $image.attr('alt', $image.data('__alt'));
- });
- }
}
}, 10);
},
/**
* Returns true if given element is a child element of given container element.
*
- * @param Node element
- * @param Element container
- * @return boolean
+ * @param {Node} element
+ * @param {Element} container
+ * @return {boolean}
*/
_elementInsideContainer: function(element, container) {
if (element.nodeType === Node.TEXT_NODE) element = element.parentNode;
/**
* Normalizes a text for comparison.
*
- * @param string text
- * @return string
+ * @param {string} text
+ * @return {string}
*/
_normalize: function(text) {
return text.replace(/\r?\n|\r/g, "\n").replace(/\s/g, ' ').replace(/\s{2,}/g, ' ');
/**
* Returns the left or right offset of the current text selection.
*
- * @param object range
- * @param boolean before
- * @return object
+ * @param {Range} range
+ * @param {boolean} before
+ * @return {Object}
*/
_getOffset: function(range, before) {
range.collapse(before);
/**
* Returns the offsets of the selection's bounding rectangle.
*
- * @return object
+ * @return {Object}
*/
_getBoundingRectangle: function(container, selection) {
var $coordinates = null;
- if (document.createRange && typeof document.createRange().getBoundingClientRect != "undefined") { // Opera, Firefox, Safari, Chrome
- if (selection.rangeCount > 0) {
- // the coordinates returned by getBoundingClientRect() is relative to the window, not the document!
- var $rect = selection.getRangeAt(0).getBoundingClientRect();
-
- $coordinates = {
- left: $rect.left,
- right: $rect.right,
- top: $rect.top + $(document).scrollTop()
- };
- }
- }
- else if (document.selection && document.selection.type != "Control") { // IE
- var $range = document.selection.createRange();
+ if (selection.rangeCount > 0) {
+ // the coordinates returned by getBoundingClientRect() are relative to the viewport, not the document!
+ var $rect = selection.getRangeAt(0).getBoundingClientRect();
$coordinates = {
- left: $range.boundingLeft,
- right: $range.boundingRight,
- top: $range.boundingTop
+ left: $rect.left,
+ right: $rect.right,
+ top: $rect.top + $(document).scrollTop()
};
}
*
* @see http://stackoverflow.com/a/13950376
*
- * @param object containerEl
- * @return object
+ * @param {Element} containerEl
+ * @return {Object}
*/
_saveSelection: function(containerEl) {
- if (window.getSelection && document.createRange) {
- var range = window.getSelection().getRangeAt(0);
- var preSelectionRange = range.cloneRange();
- preSelectionRange.selectNodeContents(containerEl);
- preSelectionRange.setEnd(range.startContainer, range.startOffset);
- var start = preSelectionRange.toString().length;
-
- return {
- start: start,
- end: start + range.toString().length
- };
- }
- else {
- var selectedTextRange = document.selection.createRange();
- var preSelectionTextRange = document.body.createTextRange();
- preSelectionTextRange.moveToElementText(containerEl);
- preSelectionTextRange.setEndPoint("EndToStart", selectedTextRange);
- var start = preSelectionTextRange.text.length;
-
- return {
- start: start,
- end: start + selectedTextRange.text.length
- };
- }
+ var range = window.getSelection().getRangeAt(0);
+ var preSelectionRange = range.cloneRange();
+ preSelectionRange.selectNodeContents(containerEl);
+ preSelectionRange.setEnd(range.startContainer, range.startOffset);
+ var start = preSelectionRange.toString().length;
+
+ return {
+ start: start,
+ end: start + range.toString().length
+ };
},
/**
*
* @see http://stackoverflow.com/a/13950376
*
- * @param object containerEl
- * @param object savedSel
+ * @param {Element} containerEl
+ * @param {Object} savedSel
*/
_restoreSelection: function(containerEl, savedSel) {
- if (window.getSelection && document.createRange) {
- var charIndex = 0, range = document.createRange();
- range.setStart(containerEl, 0);
- range.collapse(true);
- var nodeStack = [containerEl], node, foundStart = false, stop = false;
-
- while (!stop && (node = nodeStack.pop())) {
- if (node.nodeType == Node.TEXT_NODE) {
- var nextCharIndex = charIndex + node.length;
- if (!foundStart && savedSel.start >= charIndex && savedSel.start <= nextCharIndex) {
- range.setStart(node, savedSel.start - charIndex);
- foundStart = true;
- }
- if (foundStart && savedSel.end >= charIndex && savedSel.end <= nextCharIndex) {
- range.setEnd(node, savedSel.end - charIndex);
- stop = true;
- }
- charIndex = nextCharIndex;
- } else {
- var i = node.childNodes.length;
- while (i--) {
- nodeStack.push(node.childNodes[i]);
- };
- };
+ var charIndex = 0, range = document.createRange();
+ range.setStart(containerEl, 0);
+ range.collapse(true);
+ var nodeStack = [containerEl], node, foundStart = false, stop = false;
+
+ while (!stop && (node = nodeStack.pop())) {
+ if (node.nodeType == Node.TEXT_NODE) {
+ var nextCharIndex = charIndex + node.length;
+ if (!foundStart && savedSel.start >= charIndex && savedSel.start <= nextCharIndex) {
+ range.setStart(node, savedSel.start - charIndex);
+ foundStart = true;
+ }
+ if (foundStart && savedSel.end >= charIndex && savedSel.end <= nextCharIndex) {
+ range.setEnd(node, savedSel.end - charIndex);
+ stop = true;
+ }
+ charIndex = nextCharIndex;
+ } else {
+ var i = node.childNodes.length;
+ while (i--) {
+ nodeStack.push(node.childNodes[i]);
+ }
}
-
- var sel = window.getSelection();
- sel.removeAllRanges();
- sel.addRange(range);
- }
- else {
- var textRange = document.body.createTextRange();
- textRange.moveToElementText(containerEl);
- textRange.collapse(true);
- textRange.moveEnd("character", savedSel.end);
- textRange.moveStart("character", savedSel.start);
- textRange.select();
}
+
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
},
/**
* Initializes the 'copy quote' element.
*
- * @param boolean supportDirectInsert
+ * @param {boolean} supportDirectInsert
*/
_initCopyQuote: function(supportDirectInsert) {
this._copyQuote = $('#quoteManagerCopy');
if (!this._copyQuote.length) {
- this._copyQuote = $('<div id="quoteManagerCopy" class="balloonTooltip"><span class="jsQuoteManagerStore">' + WCF.Language.get('wcf.message.quote.quoteSelected') + '</span><span class="pointer"><span></span></span></div>').hide().appendTo(document.body);
+ this._copyQuote = $('<div id="quoteManagerCopy" class="balloonTooltip interactive"><span class="jsQuoteManagerStore">' + WCF.Language.get('wcf.message.quote.quoteSelected') + '</span></div>').appendTo(document.body);
var $storeQuote = this._copyQuote.children('span.jsQuoteManagerStore').click($.proxy(this._saveQuote, this));
if (supportDirectInsert) {
$('<span class="jsQuoteManagerQuoteAndInsert">' + WCF.Language.get('wcf.message.quote.quoteAndReply') + '</span>').click($.proxy(this._saveAndInsertQuote, this)).insertAfter($storeQuote);
/**
* Saves a full quote.
*
- * @param object event
+ * @param {Event} event
*/
_saveFullQuote: function(event) {
var $listItem = $(event.currentTarget);
/**
* Saves a quote.
*
- * @param boolean renderQuote
+ * @param {boolean} renderQuote
*/
_saveQuote: function(renderQuote) {
- renderQuote = (renderQuote === true) ? true : false;
-
this._proxy.setOption('data', {
actionName: 'saveQuote',
className: this._className,
objectIDs: [ this._objectID ],
parameters: {
message: this._message,
- renderQuote: renderQuote
+ renderQuote: (renderQuote === true)
}
});
this._proxy.sendRequest();
/**
* Handles successful AJAX requests.
*
- * @param object data
- * @param string textStatus
- * @param jQuery jqXHR
+ * @param {Object} data
*/
- _success: function(data, textStatus, jqXHR) {
+ _success: function(data) {
if (data.returnValues.count !== undefined) {
if (data.returnValues.fullQuoteMessageIDs !== undefined) {
data.returnValues.fullQuoteObjectIDs = data.returnValues.fullQuoteMessageIDs;
case 'saveFullQuote':
if (data.returnValues.renderedQuote) {
WCF.System.Event.fireEvent('com.woltlab.wcf.message.quote', 'insert', {
- forceInsert: (data.actionName === 'saveQuote' ? true : false),
+ forceInsert: (data.actionName === 'saveQuote'),
quote: data.returnValues.renderedQuote
});
}
WCF.Message.Quote.Manager = Class.extend({
/**
* list of form buttons
- * @var object
+ * @var {Object}
*/
- _buttons: { },
+ _buttons: {},
/**
* number of stored quotes
- * @var integer
+ * @var {int}
*/
_count: 0,
/**
* dialog overlay
- * @var jQuery
+ * @var {jQuery}
*/
_dialog: null,
/**
- * Redactor element
- * @var jQuery
+ * editor element id
+ * @var {string}
*/
- _editorElement: null,
+ _editorId: '',
/**
- * alternative Redactor element
- * @var jQuery
+ * alternative editor element id
+ * @var {string}
*/
- _editorElementAlternative: null,
+ _editorIdAlternative: '',
/**
* form element
- * @var jQuery
+ * @var {jQuery}
*/
_form: null,
/**
* list of quote handlers
- * @var object
+ * @var {Object}
*/
- _handlers: { },
+ _handlers: {},
/**
* true, if an up-to-date template exists
- * @var boolean
+ * @var {boolean}
*/
_hasTemplate: false,
/**
* true, if related quotes should be inserted
- * @var boolean
+ * @var {boolean}
*/
_insertQuotes: true,
/**
* action proxy
- * @var WCF.Action.Proxy
+ * @var {WCF.Action.Proxy}
*/
_proxy: null,
/**
* list of quotes to remove upon submit
- * @var array<string>
+ * @var {Array}
*/
_removeOnSubmit: [ ],
- /**
- * show quotes element
- * @var jQuery
- */
- _showQuotes: null,
-
/**
* allow pasting
- * @var boolean
+ * @var {boolean}
*/
_supportPaste: false,
/**
* Initializes the quote manager.
*
- * @param integer count
- * @param string elementID
- * @param boolean supportPaste
- * @param array<string> removeOnSubmit
+ * @param {int} count
+ * @param {string} elementID
+ * @param {boolean} supportPaste
+ * @param {Array} removeOnSubmit
*/
init: function(count, elementID, supportPaste, removeOnSubmit) {
this._buttons = {
};
this._count = parseInt(count) || 0;
this._dialog = null;
- this._editorElement = null;
- this._editorElementAlternative = null;
+ this._editorId = '';
+ this._editorIdAlternative = '';
this._form = null;
this._handlers = { };
this._hasTemplate = false;
this._insertQuotes = true;
- this._removeOnSubmit = [ ];
- this._showQuotes = null;
+ this._removeOnSubmit = [];
this._supportPaste = false;
if (elementID) {
- this._editorElement = $('#' + elementID);
- if (this._editorElement.length) {
+ var element = $('#' + elementID);
+ if (element.length) {
+ this._editorId = elementID;
this._supportPaste = true;
// get surrounding form-tag
- this._form = this._editorElement.parents('form:eq(0)');
+ this._form = element.parents('form:eq(0)');
if (this._form.length) {
- this._form.submit($.proxy(this._submit, this));
- this._removeOnSubmit = removeOnSubmit || [ ];
+ this._form.submit(this._submit.bind(this));
+ this._removeOnSubmit = removeOnSubmit || [];
}
else {
this._form = null;
// allow override
- this._supportPaste = (supportPaste === true) ? true : false;
+ this._supportPaste = (supportPaste === true);
}
}
}
},
/**
- * Sets an alternative editor element on runtime.
+ * Sets an alternative editor element id on runtime.
*
- * @param jQuery element
+ * @param {(string|jQuery)} elementId element id or jQuery element
*/
- setAlternativeEditor: function(element) {
- this._editorElementAlternative = element;
+ setAlternativeEditor: function(elementId) {
+ if (typeof elementId === 'object') elementId = elementId[0].id;
+ this._editorIdAlternative = elementId;
},
/**
- * Clears alternative editor element.
+ * Clears alternative editor element id.
*/
clearAlternativeEditor: function() {
- this._editorElementAlternative = null;
+ this._editorIdAlternative = '';
},
/**
* Registers a quote handler.
*
- * @param string objectType
- * @param WCF.Message.Quote.Handler handler
+ * @param {string} objectType
+ * @param {WCF.Message.Quote.Handler} handler
*/
register: function(objectType, handler) {
this._handlers[objectType] = handler;
/**
* Updates number of stored quotes.
*
- * @param integer count
- * @param object fullQuoteObjectIDs
+ * @param {int} count
+ * @param {Object} fullQuoteObjectIDs
*/
updateCount: function(count, fullQuoteObjectIDs) {
this._count = parseInt(count) || 0;
// update full quote ids of handlers
for (var $objectType in this._handlers) {
- var $objectIDs = fullQuoteObjectIDs[$objectType] || [ ];
- this._handlers[$objectType].updateFullQuoteObjectIDs($objectIDs);
+ if (this._handlers.hasOwnProperty($objectType)) {
+ var $objectIDs = fullQuoteObjectIDs[$objectType] || [];
+ this._handlers[$objectType].updateFullQuoteObjectIDs($objectIDs);
+ }
}
},
/**
* Inserts all associated quotes upon first time using quick reply.
*
- * @param string className
- * @param integer parentObjectID
- * @param object callback
+ * @param {string} className
+ * @param {int} parentObjectID
+ * @param {Object} callback
*/
insertQuotes: function(className, parentObjectID, callback) {
if (!this._insertQuotes) {
* Toggles the display of the 'Show quotes' button
*/
_toggleShowQuotes: function() {
- if (!this._count) {
- if (this._showQuotes !== null) {
- this._showQuotes.hide();
- }
- }
- else {
- if (this._showQuotes === null) {
- this._showQuotes = $('#showQuotes');
- if (!this._showQuotes.length) {
- this._showQuotes = $('<div id="showQuotes" class="balloonTooltip" />').click($.proxy(this._click, this)).appendTo(document.body);
+ require(['WoltLab/WCF/Ui/Page/Action'], (function(UiPageAction) {
+ var buttonName = 'showQuotes';
+
+ if (this._count) {
+ var button = UiPageAction.get(buttonName);
+ if (button === undefined) {
+ button = elCreate('a');
+ button.addEventListener(WCF_CLICK_EVENT, this._click.bind(this));
+
+ UiPageAction.add(buttonName, button);
}
+
+ button.textContent = WCF.Language.get('wcf.message.quote.showQuotes').replace(/#count#/, this._count);
+
+ UiPageAction.show(buttonName);
+ }
+ else {
+ UiPageAction.hide(buttonName);
}
- var $text = WCF.Language.get('wcf.message.quote.showQuotes').replace(/#count#/, this._count);
- this._showQuotes.text($text).show();
- }
-
- this._hasTemplate = false;
+ this._hasTemplate = false;
+ }).bind(this));
},
/**
/**
* Renders the dialog.
*
- * @param string template
+ * @param {string} template
*/
renderDialog: function(template) {
// create dialog if not exists
/**
* Checks for change event on delete-checkboxes.
*
- * @param object event
+ * @param {Object} event
*/
_change: function(event) {
var $input = $(event.currentTarget);
this._removeOnSubmit.push($quoteID);
}
else {
- for (var $index in this._removeOnSubmit) {
- if (this._removeOnSubmit[$index] == $quoteID) {
- delete this._removeOnSubmit[$index];
- break;
- }
+ var index = this._removeOnSubmit.indexOf($quoteID);
+ if (index !== -1) {
+ this._removeOnSubmit.splice(index, 1);
}
}
},
* Inserts the selected quotes.
*/
_insertSelected: function() {
- if (this._editorElementAlternative === null) {
- var $api = $('.jsQuickReply:eq(0)').data('__api');
- if ($api && !$api.getContainer().is(':visible')) {
- this._insertQuotes = false;
- $api.click(null);
- }
- }
-
if (!this._dialog.find('input.jsCheckbox:checked').length) {
this._dialog.find('input.jsCheckbox').prop('checked', 'checked');
}
// insert all quotes
this._dialog.find('input.jsCheckbox:checked').each($.proxy(function(index, input) {
- this._insertQuote(null, input);
+ this._insertQuote(null, input, undefined);
}, this));
// close dialog
/**
* Inserts a quote.
*
- * @param object event
- * @param object inputElement
- * @param object data
+ * @param {Event} event
+ * @param {Object} inputElement
+ * @param {Object} data
*/
_insertQuote: function(event, inputElement, data) {
+ var listItem = $(event ? event.currentTarget : inputElement).parents('li:eq(0)');
+ var text = listItem.children('.jsFullQuote')[0].textContent.trim();
+
+ var message = listItem.parents('.message:eq(0)');
+ var author = message.data('username');
+ var link = message.data('link');
+ var isText = listItem.find('.jsQuote').length === 0;
+ /*
var $listItem = null, $quote, $username, $link;
if (data === undefined) {
$listItem = (event === null) ? $(inputElement).parents('li') : $(event.currentTarget).parents('li');
$username = data.quote.username;
$link = data.quote.link;
}
+ */
+
+ console.debug('insertQuote_' + (this._editorIdAlternative ? this._editorIdAlternative : this._editorId));
+
+ WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'insertQuote_' + (this._editorIdAlternative ? this._editorIdAlternative : this._editorId), {
+ author: author,
+ content: text,
+ isText: isText,
+ link: link
+ });
+
+ // remove quote upon submit or upon request
+ this._removeOnSubmit.push(listItem.data('quote-id'));
+
+ // close dialog
+ if (event !== null) {
+ this._dialog.wcfDialog('close');
+ }
+ return;
// insert into editor
if ($.browser.redactor) {
- if (this._editorElementAlternative === null) {
+ if (this._editorIdAlternative === null) {
var insert = true;
if (event !== null || data !== null) {
var $api = $('.jsQuickReply:eq(0)').data('__api');
}
}
- if (insert && this._editorElement.length) this._editorElement.redactor('wbbcode.insertQuoteBBCode', $username, $link, $quote, $quote);
+ if (insert && this._editorId.length) this._editorId.redactor('wbbcode.insertQuoteBBCode', $username, $link, $quote, $quote);
}
else {
- this._editorElementAlternative.redactor('wbbcode.insertQuoteBBCode', $username, $link, $quote, $quote);
+ this._editorIdAlternative.redactor('wbbcode.insertQuoteBBCode', $username, $link, $quote, $quote);
}
}
else {
$quote = "[quote='" + $username + "','" + $link + "']" + $quote + "[/quote]";
// plain textarea
- var $textarea = (this._editorElementAlternative === null) ? this._editorElement : this._editorElementAlternative;
+ var $textarea = (this._editorIdAlternative === null) ? this._editorId : this._editorIdAlternative;
var $value = $textarea.val();
$quote += "\n\n";
if ($value.length == 0) {
}
}
- // remove quote upon submit or upon request
- if ($listItem !== null) this._removeOnSubmit.push($listItem.attr('data-quote-id'));
- // close dialog
- if (event !== null) {
- this._dialog.wcfDialog('close');
- }
},
/**
if ($quoteIDs.length) {
// get object types
- var $objectTypes = [ ];
+ var $objectTypes = [];
for (var $objectType in this._handlers) {
- $objectTypes.push($objectType);
+ if (this._handlers.hasOwnProperty($objectType)) {
+ $objectTypes.push($objectType);
+ }
}
this._proxy.setOption('data', {
_submit: function() {
if (this._supportPaste && this._removeOnSubmit.length > 0) {
var $formSubmit = this._form.find('.formSubmit');
- for (var $i in this._removeOnSubmit) {
- $('<input type="hidden" name="__removeQuoteIDs[]" value="' + this._removeOnSubmit[$i] + '" />').appendTo($formSubmit);
+ for (var i = 0, length = this._removeOnSubmit.length; i < length; i++) {
+ $('<input type="hidden" name="__removeQuoteIDs[]" value="' + this._removeOnSubmit[i] + '" />').appendTo($formSubmit);
}
}
},
/**
* Returns a list of quote ids marked for removal.
*
- * @return array<integer>
+ * @return {Array}
*/
getQuotesMarkedForRemoval: function() {
return this._removeOnSubmit;
countQuotes: function() {
var $objectTypes = [ ];
for (var $objectType in this._handlers) {
- $objectTypes.push($objectType);
+ if (this._handlers.hasOwnProperty($objectType)) {
+ $objectTypes.push($objectType);
+ }
}
this._proxy.setOption('data', {
/**
* Handles successful AJAX requests.
*
- * @param object data
- * @param string textStatus
- * @param jQuery jqXHR
+ * @param {Object} data
*/
- _success: function(data, textStatus, jqXHR) {
+ _success: function(data) {
if (data === null) {
return;
}
*/
define(
[
- 'Ajax', 'Core', 'Dictionary', 'Environment',
- 'EventHandler', 'Language', 'ObjectMap', 'Dom/Traverse',
- 'Dom/Util', 'Ui/Notification', 'Ui/ReusableDropdown'
+ 'Ajax', 'Core', 'Dictionary', 'Environment',
+ 'EventHandler', 'Language', 'ObjectMap', 'Dom/Traverse',
+ 'Dom/Util', 'Ui/Notification', 'Ui/ReusableDropdown', 'WoltLab/WCF/Ui/Scroll'
],
function(
- Ajax, Core, Dictionary, Environment,
- EventHandler, Language, ObjectMap, DomTraverse,
- DomUtil, UiNotification, UiReusableDropdown
+ Ajax, Core, Dictionary, Environment,
+ EventHandler, Language, ObjectMap, DomTraverse,
+ DomUtil, UiNotification, UiReusableDropdown, UiScroll
)
{
"use strict";
/**
* Initializes the message inline editor.
*
- * @param {Object<string, *>} options list of configuration options
+ * @param {Object} options list of configuration options
*/
init: function(options) {
this._activeDropdownElement = null;
dropdownIdentifier: '',
editorPrefix: 'messageEditor',
- messageSelector: '.jsMessage'
+ messageSelector: '.jsMessage',
+
+ quoteManager: null
}, options);
this.rebuild();
_clickDropdownItem: function(event) {
event.preventDefault();
+ //noinspection JSCheckFunctionSignatures
this._dropdownSelect(elData(event.currentTarget, 'item'));
},
var messageBody = elementData.messageBodyEditor;
var editor = elCreate('div');
editor.className = 'editorContainer';
+ //noinspection JSUnresolvedVariable
DomUtil.setInnerHtml(editor, data.returnValues.template);
messageBody.appendChild(editor);
var editorElement = elById(id);
if (Environment.editor() === 'redactor') {
window.setTimeout((function() {
- // TODO: quote manager
- if (this._quoteManager) {
- this._quoteManager.setAlternativeEditor($element);
+ if (this._options.quoteManager) {
+ this._options.quoteManager.setAlternativeEditor(id);
}
- // TODO
- new WCF.Effect.Scroll().scrollTo(this._activeElement, true);
+ UiScroll.element(this._activeElement);
}).bind(this), 250);
}
else {
this._activeElement = null;
- // @TODO
- if (this._quoteManager) {
- this._quoteManager.clearAlternativeEditor();
+ if (this._options.quoteManager) {
+ this._options.quoteManager.clearAlternativeEditor();
}
},
message: ''
},
objectID: this._getObjectId(this._activeElement),
- removeQuoteIDs: [] // @TODO
+ removeQuoteIDs: (this._options.quoteManager) ? this._options.quoteManager.getQuotesMarkedForRemoval() : []
};
var id = this._getEditorId();
var attachmentLists = elBySelAll('.attachmentThumbnailList, .attachmentFileList', elementData.messageBody);
// set new content
+ //noinspection JSUnresolvedVariable
DomUtil.setInnerHtml(elementData.messageBody, data.returnValues.message);
// handle attachment list
+ //noinspection JSUnresolvedVariable
if (typeof data.returnValues.attachmentList === 'string') {
for (var i = 0, length = attachmentLists.length; i < length; i++) {
elRemove(attachmentLists[i]);
}
var element = elCreate('div');
+ //noinspection JSUnresolvedVariable
DomUtil.setInnerHtml(element, data.returnValues.attachmentList);
while (element.childNodes.length) {
}
// handle poll
+ //noinspection JSUnresolvedVariable
if (typeof data.returnValues.poll === 'string') {
// find current poll
var poll = elBySel('.pollContainer', elementData.messageBody);
var pollContainer = elCreate('div');
pollContainer.className = 'jsInlineEditorHideContent';
+ //noinspection JSUnresolvedVariable
DomUtil.setInnerHtml(pollContainer, data.returnValues.poll);
DomUtil.prepend(pollContainer, elementData.messageBody);
UiNotification.show();
- // @TODO
- return;
-
- if (this._quoteManager) {
- this._quoteManager.clearAlternativeEditor();
- this._quoteManager.countQuotes();
+ if (this._options.quoteManager) {
+ this._options.quoteManager.clearAlternativeEditor();
+ this._options.quoteManager.countQuotes();
}
},
var elementData = this._elements.get(this._activeElement);
var editor = elBySel('.redactor-editor', elementData.messageBodyEditor);
- // handle errors occuring on editor load
+ // handle errors occurring on editor load
if (editor === null) {
this._restoreMessage();
this._restoreEditor();
+ //noinspection JSUnresolvedVariable
if (!data || data.returnValues === undefined || data.returnValues.errorType === undefined) {
return true;
}
DomUtil.insertAfter(innerError, editor);
}
-
+ //noinspection JSUnresolvedVariable
innerError.textContent = data.returnValues.errorType;
return false;