key = key.replace(/^color_/, '');
require(['WoltLab/WCF/Ui/Redactor/Format'], (function(UiRedactorFormat) {
- this.selection.save();
+ this.buffer.set();
UiRedactorFormat.format(this.$editor[0], 'woltlab-color', 'woltlab-color-' + key);
-
- this.selection.restore();
}).bind(this));
},
removeColor: function() {
require(['WoltLab/WCF/Ui/Redactor/Format'], (function(UiRedactorFormat) {
- this.selection.save();
+ this.buffer.set();
UiRedactorFormat.removeFormat(this.$editor[0], 'woltlab-color');
-
- this.selection.restore();
}).bind(this));
}
};
setSize: function(key) {
require(['WoltLab/WCF/Ui/Redactor/Format'], (function(UiRedactorFormat) {
- this.selection.save();
+ this.buffer.set();
UiRedactorFormat.format(this.$editor[0], 'woltlab-size', 'woltlab-size-' + key.replace(/^size_/, ''));
-
- this.selection.restore();
}).bind(this));
},
removeSize: function() {
require(['WoltLab/WCF/Ui/Redactor/Format'], (function(UiRedactorFormat) {
- this.selection.save();
+ this.buffer.set();
UiRedactorFormat.removeFormat(this.$editor[0], 'woltlab-size');
-
- this.selection.restore();
}).bind(this));
}
};
* @param {Object=} attributes optional list of attributes for the format tag
*/
format: function(editorElement, tagName, className, attributes) {
- document.execCommand('strikethrough');
+ var selection = window.getSelection();
+ if (!selection.rangeCount) {
+ // no active selection
+ return;
+ }
+
+ var range = selection.getRangeAt(0);
+ var tmpElement = null;
+ if (range.collapsed) {
+ tmpElement = elCreate('strike');
+ tmpElement.textContent = '\u200B';
+ range.insertNode(tmpElement);
+
+ range = document.createRange();
+ range.selectNodeContents(tmpElement);
+
+ selection.removeAllRanges();
+ selection.addRange(range);
+ }
+
+ if (tmpElement === null) {
+ document.execCommand('strikethrough');
+ }
var elements = elBySelAll('strike', editorElement), formatElement, property, strike;
for (var i = 0, length = elements.length; i < length; i++) {