}
},
- /**
- * Removes the unicode zero width space (0x200B).
- *
- * @param string string
- * @return string
- */
- _removeCrap: function(string) {
- var $string = '';
-
- for (var $i = 0, $length = string.length; $i < $length; $i++) {
- var $byte = string.charCodeAt($i).toString(16);
- if ($byte != '200b') {
- $string += string[$i];
- }
- }
-
- return $string;
- },
-
_convertParagraphs: function() {
this.$editor.find('p').replaceWith(function() {
var $html = $(this).html();
var data = this.$source.val();
// remove 0x200B (unicode zero width space)
- data = this._removeCrap(data);
+ data = this.removeZeroWidthSpace(data);
//if (!$pasted) {
// Convert & to its HTML entity.
marginLeft: -1 * Math.round($dimensions.width / 2) + 'px',
marginTop: -1 * Math.round($dimensions.height / 2) + 'px'
});
- }
+ },
+
+ /**
+ * Overwrites $.Redactor.inlineEachNodes(), the original method compares "selectionHtml"
+ * and "parentHtml" to check if the callback should be invoked. In some cases the "parentHtml"
+ * may contain a trailing unicode zero-width space and the comparision will fail, even though
+ * the "entire" node is selected.
+ *
+ * @see $.Redactor.inlineEachNodes()
+ */
+ inlineEachNodes: function(callback)
+ {
+ var range = this.getRange(),
+ node = this.getElement(),
+ nodes = this.getNodes(),
+ collapsed;
+
+ if (range.collapsed || range.startContainer === range.endContainer && node)
+ {
+ nodes = $(node);
+ collapsed = true;
+ }
+
+ $.each(nodes, $.proxy(function(i, node)
+ {
+ if (!collapsed && node.tagName !== 'INLINE')
+ {
+ var selectionHtml = this.getSelectionText();
+ var parentHtml = $(node).parent().text();
+ // if parentHtml contains a trailing 0x200B, the comparison will most likely fail
+ var selected = this.removeZeroWidthSpace(selectionHtml) == this.removeZeroWidthSpace(parentHtml);
+
+ if (selected && node.parentNode.tagName === 'INLINE' && !$(node.parentNode).hasClass('redactor_editor'))
+ {
+ node = node.parentNode;
+ }
+ else return;
+ }
+ callback.call(this, node);
+
+ }, this ) );
+ },
}
\ No newline at end of file
$target.parent().remove();
return $button;
- }
+ },
+
+ /**
+ * Removes the unicode zero-width space (0x200B).
+ *
+ * @param string string
+ * @return string
+ */
+ removeZeroWidthSpace: function(string) {
+ var $string = '';
+
+ for (var $i = 0, $length = string.length; $i < $length; $i++) {
+ var $byte = string.charCodeAt($i).toString(16);
+ if ($byte != '200b') {
+ $string += string[$i];
+ }
+ }
+
+ return $string;
+ },
};