}
else {
ref = element.nextSibling;
- if (ref === null) {
+ if (ref === null || ref === element.nextElementSibling && ref.nodeName === 'BR') {
var space = this.utils.createSpaceElement();
if (element.nextSibling === null) element.parentNode.appendChild(space);
else element.parentNode.insertBefore(space, element.nextSibling);
- this.caret.setEnd(space);
+ this.caret.setAfter(space);
}
else {
this.caret.setBefore(ref);
}
}
+ // check if caret is now inside <kbd>
+ range = (window.getSelection().rangeCount) ? window.getSelection().getRangeAt(0) : null;
+ if (range !== null) {
+ var container = range.startContainer;
+ if (container.nodeType === Node.TEXT_NODE) container = container.parentNode;
+
+ if (container.nodeName === 'KBD') {
+ if (container.nextElementSibling === editor.lastElementChild) {
+ if (editor.lastElementChild.nodeName === 'SPAN' && editor.lastElementChild.textContent === '') {
+ editor.removeChild(editor.lastElementChild);
+ }
+ }
+ else if (container.nextSibling === container.nextElementSibling) {
+ console.debug("this!");
+ if (container.nextElementSibling.nodeName === 'KBD' || container.nextElementSibling.nodeName === 'BR') {
+ setCaretBeforeOrAfter(container, false);
+ }
+ else {
+ console.debug(container.nextSibling);
+ console.debug(container.nextElementSibling);
+ }
+ }
+
+ if (container === editor.lastElementChild) {
+ setCaretBeforeOrAfter(container, false);
+ }
+ }
+ }
+
return false;
}
else if (event.target.nodeName === 'LI') {
}
}
else if (event.target.nodeName === 'BLOCKQUOTE') {
- range = (window.getSelection().rangeCount) ? window.getSelection().getRangeAt(0) : null;
if (range !== null && range.collapsed) {
// check if caret is now inside a quote
var blockquote = null;
* - handles custom button active states.
*/
observe: function() {
- var $toggleButtons = (function(parent, searchFor, buttonSelector, inverse, className, skipInSourceMode) {
+ var $toggleButtons = (function(element, searchFor, buttonSelector, inverse, className, skipInSourceMode) {
var $buttons = this.$toolbar.find(buttonSelector);
- if (parent && parent.closest(searchFor, this.$editor[0]).length != 0) {
+ if (element && element.closest(searchFor, this.$editor[0]).length != 0) {
$buttons[(inverse ? 'removeClass' : 'addClass')](className);
}
else {
this.observe.buttons = (function(e, btnName) {
$mpButtons.call(this, e, btnName);
- var parent = this.selection.getParent();
- parent = (parent === false) ? null : $(parent);
+ var element = this.selection.getCurrent();
+ if (element === false) {
+ console.debug("nope");
+ return;
+ }
+
+ if (element.nodeType === Node.TEXT_NODE) {
+ element = element.parentNode;
+ }
+ console.debug(element);
+ if (element === this.$editor[0]) {
+ return;
+ }
+
+ element = $(element);
- $toggleButtons(parent, 'ul, ol', 'a.re-indent, a.re-outdent', true, 'redactor-button-disabled');
- //$toggleButtons(parent, 'inline.inlineCode', 'a.re-__wcf_tt', false, 'redactor-act');
- $toggleButtons(parent, 'blockquote.quoteBox', 'a.re-__wcf_quote', false, 'redactor-button-disabled', true);
- $toggleButtons(parent, 'sub', 'a.re-subscript', false, 'redactor-act');
- $toggleButtons(parent, 'sup', 'a.re-superscript', false, 'redactor-act');
+ $toggleButtons(element, 'ul, ol', 'a.re-indent, a.re-outdent', true, 'redactor-button-disabled');
+ $toggleButtons(element, 'kbd', 'a.re-__wcf_tt', false, 'redactor-act');
+ $toggleButtons(element, 'blockquote.quoteBox', 'a.re-__wcf_quote', false, 'redactor-button-disabled', true);
+ $toggleButtons(element, 'sub', 'a.re-subscript', false, 'redactor-act');
+ $toggleButtons(element, 'sup', 'a.re-superscript', false, 'redactor-act');
}).bind(this);
// observe.load
}
if (item.closing) {
- var lastIndex = this._findOpenTag(openTags, item.name);
- if (lastIndex === -1) {
- // tag was never opened, treat as plain text
- stack[i] = item.source;
+ if (this._hasOpenTag(openTags, item.name)) {
+ reopenTags = this._closeUnclosedTags(stack, openTags, item.name);
+ for (var j = 0, innerLength = reopenTags.length; j < innerLength; j++) {
+ stack.splice(i, reopenTags[j]);
+ i++;
+ }
+
+ openTags.pop().pair = i;
}
else {
- tag = openTags.pop();
- tag.pair = i;
-
- if (sourceBBCode === item.name) {
- // join previous items in the stack
- if (lastIndex + 2 < i) {
- var joinWith = lastIndex + 1;
- for (var j = lastIndex + 2; j < i; j++) {
- stack[joinWith] += stack[j];
- stack[j] = '';
- }
- }
- }
- else {
- reopenTags = this._closeUnclosedTags(stack, openTags, item.name);
-
- for (var j = 0, innerLength = reopenTags.length; j < innerLength; j++) {
- stack.splice(i, reopenTags[j]);
- i++;
- }
- }
+ // tag was never opened, treat as plain text
+ stack[i] = item.source;
}
if (sourceBBCode === item.name) {
return reopenTags.reverse();
},
- _findOpenTag: function(openTags, name) {
+ _hasOpenTag: function(openTags, name) {
for (var i = openTags.length - 1; i >= 0; i--) {
if (openTags[i].name === name) {
- return i;
+ return true;
}
}
- return -1;
+ return false;
},
_parseAttributes: function(attrString) {