blur() isn't that great with Firefox because getSelection() already contains the new range and focusout is not supported.
init: function() {
var $identifier = this.$textarea.wcfIdentify();
- this.opts.initCallback = $.proxy(function() {
+ this.opts.initCallback = (function() {
// use stored editor contents
var $content = $.trim(this.wutil.getOption('woltlab.originalValue'));
if ($content.length) {
delete this.opts.woltlab.originalValue;
$(document).trigger('resize');
- }, this);
+ this.wmonkeypatch.saveSelection();
+ }).bind(this);
this.opts.pasteBeforeCallback = $.proxy(this.wbbcode._pasteBeforeCallback, this);
this.opts.pasteCallback = $.proxy(this.wbbcode._pasteCallback, this);
this.button.get('html').children('i').removeClass('fa-square').addClass('fa-square-o');
$tooltip.text(WCF.Language.get('wcf.bbcode.button.toggleBBCode'));
+
+ this.wmonkeypatch.saveSelection();
}
}).bind(this);
// insert a new line if user clicked into the editor and the last children is a quote (same behavior as arrow down)
this.wutil.setOption('clickCallback', (function(event) {
+ this.wmonkeypatch.saveSelection();
+
if (event.target === this.$editor[0]) {
if (this.$editor[0].lastElementChild && this.$editor[0].lastElementChild.tagName === 'BLOCKQUOTE') {
this.wutil.setCaretAfter($(this.$editor[0].lastElementChild));
this.wmonkeypatch.fixWebKit();
},
+ /**
+ * Saves current caret position.
+ */
+ saveSelection: function() {
+ this.wmonkeypatch._range = getSelection().getRangeAt(0);
+ },
+
/**
* Setups event listeners and callbacks.
*/
});
// keyup
- this.wutil.setOption('keyupCallback', function(event) {
+ this.wutil.setOption('keyupCallback', (function(event) {
+ this.wmonkeypatch.saveSelection();
+
var $data = {
cancel: false,
event: event
WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'keyup_' + $identifier, $data);
return ($data.cancel ? false : true);
- });
+ }).bind(this));
// buttons response
if (this.opts.activeButtons) {
this.$editor.on('keyup.redactor', $.proxy(this.keyup.init, this));
}
- this.$editor.on('blur.wredactor', (function() {
+ // blur is unreliable in Firefox, especially since 'focusout' is not available
+ /*this.$editor.on('blur.wredactor', (function() {
var $selection = window.getSelection();
if ($selection.rangeCount) {
this.wmonkeypatch._range = $selection.getRangeAt(0);
}
- }).bind(this));
+ }).bind(this));*/
},
/**
reset: function() {
if (this.opts.visual) {
this.$editor.html('<p>' + this.opts.invisibleSpace + '</p>');
+ this.wmonkeypatch.saveSelection();
}
this.$textarea.val('');