}
this.selection.get();
- var $current = $(this.selection.getCurrent());
+ var current = this.selection.getCurrent();
var $parent = this.selection.getParent();
$parent = ($parent) ? $($parent) : $parent;
var $quote = ($parent) ? $parent.closest('blockquote.quoteBox', this.$editor.get()[0]) : { length: 0 };
// backspace key
case $.ui.keyCode.BACKSPACE:
if (this.wutil.isCaret()) {
+ var $preventAndSelectQuote = false;
+
if ($quote.length) {
// check if quote is empty
var $isEmpty = true;
- $quote.children('div').each(function() {
- if ($(this).text().replace(/\u200B/, '').length) {
- $isEmpty = false;
- return false;
+ for (var $i = 0; $i < $quote[0].children.length; $i++) {
+ var $child = $quote[0].children[$i];
+ if ($child.tagName === 'DIV') {
+ if ($child.textContent.replace(/\u200b/, '').length) {
+ $isEmpty = false;
+ break;
+ }
}
- });
+ }
if ($isEmpty) {
- // expand selection and prevent delete
- var $selection = window.getSelection();
- if ($selection.rangeCount) $selection.removeAllRanges();
-
- var $quoteRange = document.createRange();
- $quoteRange.selectNode($quote[0]);
- $selection.addRange($quoteRange);
-
- data.cancel = true;
+ $preventAndSelectQuote = true;
}
}
+ else if (current.previousElementSibling && current.previousElementSibling.tagName === 'BLOCKQUOTE') {
+ $quote = current.previousElementSibling;
+ $preventAndSelectQuote = true;
+ }
+
+ if ($preventAndSelectQuote) {
+ // expand selection and prevent delete
+ var $selection = window.getSelection();
+ if ($selection.rangeCount) $selection.removeAllRanges();
+
+ var $quoteRange = document.createRange();
+ $quoteRange.selectNode($quote[0] || $quote);
+ $selection.addRange($quoteRange);
+
+ data.cancel = true;
+ }
}
break;
// delete key
case $.ui.keyCode.DELETE:
- if (this.wutil.isCaret()) {
- if (this.wutil.isEndOfElement($current[0]) && $current.next('blockquote').length) {
+ if (this.wutil.isCaret() && this.wutil.isEndOfElement(current)) {
+ var $next = current.nextElementSibling;
+ if ($next && $next.tagName === 'BLOCKQUOTE') {
// expand selection and prevent delete
var $selection = window.getSelection();
if ($selection.rangeCount) $selection.removeAllRanges();
var $quoteRange = document.createRange();
- $quoteRange.selectNode($current.next()[0]);
+ $quoteRange.selectNode($next);
$selection.addRange($quoteRange);
data.cancel = true;
// arrow down
case $.ui.keyCode.DOWN:
+ var $current = $(current);
if ($current.next('blockquote').length) {
this.caret.setStart($current.next().children('div:first'));
return;
}
- var $container = $current.closest('div', $quote[0]);
+ var $container = $(current).closest('div', $quote[0]);
var $prev = $container.prev();
if ($prev[0].tagName === 'DIV') {
return;
}
else if ($prev[0].tagName === 'BLOCKQUOTE') {
- // TODO
- // set focus to quote text rather than the element itself
return;
- //this.selectionEnd($prev.find('> div > div:last'));
}
var $previousElement = $quote.prev();
this.wmonkeypatch.inline();
this.wmonkeypatch.insert();
this.wmonkeypatch.keydown();
+ this.wmonkeypatch.keyup();
this.wmonkeypatch.link();
this.wmonkeypatch.modal();
this.wmonkeypatch.paste();
}).bind(this);
},
+ /**
+ * Partially overwrites the 'keyup' module.
+ *
+ * - prevent divs inside a quote being replace with paragraphs
+ */
+ keyup: function() {
+ // keyup.replaceToParagraph
+ var $mpReplaceToParagraph = this.keyup.replaceToParagraph;
+ this.keyup.replaceToParagraph = (function(clone) {
+ if (this.keyup.current.tagName !== 'DIV' || this.keyup.current.parentElement.tagName !== 'BLOCKQUOTE') {
+ $mpReplaceToParagraph.call(this, clone);
+ }
+ }).bind(this);
+ },
+
/**
* Partially overwrites the 'link' module.
*