added linking to formatting opts in editor

This commit is contained in:
Julian Lam
2013-05-16 10:37:17 -04:00
parent dcbc93cacf
commit 826edbd669
3 changed files with 15 additions and 2 deletions

View File

@@ -288,6 +288,7 @@ var socket,
var cursorEnd = postContentEl.value.length,
selectionStart = postContentEl.selectionStart,
selectionEnd = postContentEl.selectionEnd,
selectionLength = selectionEnd - selectionStart,
target;
if (e.target.nodeName === 'I') target = e.target;
else if (e.target.nodeName === 'SPAN') target = e.target.querySelector('i');
@@ -324,6 +325,19 @@ var socket,
postContentEl.selectionStart = cursorEnd+4;
postContentEl.selectionEnd = postContentEl.value.length;
break;
case 'icon-link':
if (selectionStart === selectionEnd) {
// Nothing selected
postContentEl.value = postContentEl.value + '[link text](link url)';
postContentEl.selectionStart = cursorEnd+12;
postContentEl.selectionEnd = postContentEl.value.length - 1;
} else {
// Text selected
postContentEl.value = postContentEl.value.slice(0, selectionStart) + '[' + postContentEl.value.slice(selectionStart, selectionEnd) + '](link url)' + postContentEl.value.slice(selectionEnd);
postContentEl.selectionStart = selectionStart + selectionLength + 3;
postContentEl.selectionEnd = selectionEnd + 11;
}
break;
}
}
}, false);