*/
init: function() {
// convert HTML to BBCode upon submit
- this.$textarea.parents('form').submit($.proxy(this.submit, this));
+ this.$textarea.parents('form').submit($.proxy(this.wutil.submit, this));
if (this.wutil.getOption('wautosave').active) {
this.wutil.autosaveEnable();
*/
getText: function() {
if (this.inWysiwygMode()) {
- this.wSync();
+ this.code.startSync();
+ this.$textarea.val(this.wbbcode.convertFromHtml(this.$textarea.val()));
}
return this.$textarea.val();
},
+ /**
+ * Returns true if editor is empty.
+ *
+ * @return boolean
+ */
+ isEmptyEditor: function() {
+ if (this.opts.visual) {
+ return this.utils.isEmpty(this.$editor.html());
+ }
+
+ return (!$.trim(this.$textarea.val()));
+ },
+
/**
* Converts HTML to BBCode upon submit.
*/
submit: function() {
- if (this.inWysiwygMode()) {
- this.wSync();
+ if (this.wutil.inWysiwygMode()) {
+ this.code.startSync();
+ this.$textarea.val(this.wbbcode.convertFromHtml(this.$textarea.val()));
}
this.autosavePurge();
* Resets the editor's contents.
*/
reset: function() {
- if (this.inWysiwygMode()) {
+ if (this.opts.visual) {
this.$editor.html('<p>' + this.opts.invisibleSpace + '</p>');
- this.sync();
- }
- else {
- this.$textarea.val('');
}
+ this.$textarea.val('');
+
WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'reset', { wysiwygContainerID: this.$textarea.wcfIdentify() });
},
return $string;
},
- /**
- * Synchronizes editor's source textarea.
- */
- wSync: function() {
- this.sync(undefined, true);
- this.$textarea.val(this.convertFromHtml(this.cleanHtml(this.$textarea.val())));
- },
-
/**
* Returns source textarea object.
*
* @param string value
*/
replaceText: function(value) {
+ var $document = $(document);
+ var $offsetTop = $document.scrollTop();
var $wasInWysiwygMode = false;
- var $offsetTop = $(document).scrollTop();
- if (this.inWysiwygMode()) {
- this.toggle();
+
+ if (this.wutil.inWysiwygMode()) {
+ this.code.toggle();
$wasInWysiwygMode = true;
}
this.$textarea.val(value);
if ($wasInWysiwygMode) {
- this.toggle();
+ this.code.toggle();
// restore scrolling since editor receives the focus
- $(document).scrollTop($offsetTop);
+ $document.scrollTop($offsetTop);
}
+
+ // trigger resize event to rebuild message tab menu
+ $document.trigger('resize');
},
setCaretBefore: function(element) {
this._wysiwygSelector = wysiwygSelector;
WCF.System.Dependency.Manager.register('Redactor_' + this._wysiwygSelector, $.proxy(function() {
- this._redactor = $('#' + this._wysiwygSelector).redactor('getObject');
+ this._redactor = $('#' + this._wysiwygSelector).redactor('core.getObject');
$('.messageTabMenu[data-wysiwyg-container-id=' + this._wysiwygSelector + ']').on('click', '.jsSmiley', $.proxy(this._smileyClick, this));
}, this));
var $smileyPath = $target.data('smileyPath');
// register smiley
- this._redactor.insertSmiley($smileyCode, $smileyPath, true);
+ this._redactor.wbbcode.insertSmiley($smileyCode, $smileyPath, true);
}
});
var $empty = true;
if ($.browser.redactor) {
if (this._messageField.data('redactor')) {
- $empty = (!$.trim(this._messageField.redactor('getText')));
- this._editorCallback($empty);
+ this._editorCallback(this._messageField.redactor('wutil.isEmptyEditor'));
}
}
else {
}
if ($.browser.redactor) {
- this._messageField.redactor('focus');
+ this._messageField.redactor('focus.setEnd');
}
else {
this._messageField.focus();
this._revertQuickReply(true);
if ($.browser.redactor) {
- this._messageField.redactor('reset');
+ this._messageField.redactor('wutil.reset');
}
else {
this._messageField.val('');
*/
init: function(wysiwygSelector) {
this._textarea = $('#' + wysiwygSelector);
- this._redactor = this._textarea.redactor('getObject');
+ this._redactor = this._textarea.redactor('core.getObject');
- this._redactor.setOption('keyupCallback', $.proxy(this._keyup, this));
-
- this._dropdown = this._textarea.redactor('getEditor');
+ this._dropdown = this._textarea.redactor('core.getEditor');
this._dropdownMenu = $('<ul class="dropdownMenu userSuggestionList" />').appendTo(this._textarea.parent());
WCF.Dropdown.initDropdownFragment(this._dropdown, this._dropdownMenu);
});
WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'keydown_' + wysiwygSelector, $.proxy(this._keydown, this));
+ WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'keyup_' + wysiwygSelector, $.proxy(this._keyup, this));
},
/**
*/
_click: function(event) {
// restore caret position
- this._redactor.replaceRangesWith(this._caretPosition);
+ this._redactor.wutil.replaceRangesWith(this._caretPosition);
this._setUsername($(event.currentTarget).data('username'));
},
$newRange.setStart($orgRange.startContainer, $orgRange.startOffset - (this._mentionStart.length + 1));
$newRange.setEnd($orgRange.startContainer, $orgRange.startOffset);
- this._redactor.replaceRangesWith($newRange);
+ this._redactor.wutil.replaceRangesWith($newRange);
// get the offsets of the bounding box of current text selection
var $range = getSelection().getRangeAt(0);
}
// restore caret position
- this._redactor.replaceRangesWith($orgRange);
+ this._redactor.wutil.replaceRangesWith($orgRange);
this._caretPosition = $orgRange;
return $offsets;
var $orgRange = getSelection().getRangeAt(0).cloneRange();
// allow redactor to undo this
- this._redactor.bufferSet();
+ this._redactor.buffer.set();
var $newRange = document.createRange();
$newRange.setStart($orgRange.startContainer, $orgRange.startOffset - (this._mentionStart.length + 1));
$newRange.setEnd($orgRange.startContainer, $orgRange.startOffset);
- this._redactor.replaceRangesWith($newRange);
+ this._redactor.wutil.replaceRangesWith($newRange);
var $range = getSelection().getRangeAt(0);
$range.deleteContents();
$newRange.setStart($text, username.length + 1);
$newRange.setEnd($text, username.length + 1);
- this._redactor.replaceRangesWith($newRange);
+ this._redactor.wutil.replaceRangesWith($newRange);
this._hideList();
},
*/
_getTextLineInFrontOfCaret: function() {
// if text is marked, user suggestions are disabled
- if (this._redactor.getSelectionHtml().length) {
+ if (this._redactor.selection.getHtml().length) {
return '';
}
- var $range = this._redactor.getSelection().getRangeAt(0);
+ var $range = getSelection().getRangeAt(0);
var $text = $range.startContainer.textContent.substr(0, $range.startOffset);
// remove unicode zero width space and non-breaking space
* @param object data
*/
_keydown: function(data) {
- if (this._redactor.inPlainMode()) {
+ if (this._redactor.wutil.inPlainMode()) {
return;
}
switch (data.event.which) {
case $.ui.keyCode.ENTER:
data.cancel = true;
- data.event.preventDefault();
this._dropdownMenu.children('li').eq(this._itemIndex).trigger('click');
-
- return;
break;
case $.ui.keyCode.UP:
data.cancel = true;
- data.event.preventDefault();
this._selectItem(this._itemIndex - 1);
-
- return;
break;
case $.ui.keyCode.DOWN:
data.cancel = true;
- data.event.preventDefault();
this._selectItem(this._itemIndex + 1);
-
- return;
break;
}
}
-
- return true;
},
/**
* Handles the keyup event to check if the user starts mentioning someone.
*
- * @param object event
+ * @param object data
*/
- _keyup: function(event) {
- if (this._redactor.inPlainMode()) {
+ _keyup: function(data) {
+ if (this._redactor.wutil.inPlainMode()) {
return true;
}
// ignore enter key up event
- if (event.which === $.ui.keyCode.ENTER) {
+ if (data.event.which === $.ui.keyCode.ENTER) {
return;
}
// ignore event if suggestion list and user pressed enter, arrow up or arrow down
- if (this._dropdownMenu.is(':visible') && event.which in { 13:1, 38:1, 40:1 }) {
+ if (this._dropdownMenu.is(':visible') && data.event.which in { 13:1, 38:1, 40:1 }) {
return;
}