aboutsummaryrefslogtreecommitdiffstats
path: root/view/js/autocomplete.js
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2016-04-07 00:46:45 +0200
committerMario Vavti <mario@mariovavti.com>2016-04-07 00:46:45 +0200
commite41082dcccdb46da7ef425f399cf4dd06dff9b6c (patch)
treef5e627a3a7c29c05ebd96710032152859db1698c /view/js/autocomplete.js
parent97ccbf1bfb95be412393bed207a26fd8d0cbf512 (diff)
downloadvolse-hubzilla-e41082dcccdb46da7ef425f399cf4dd06dff9b6c.tar.gz
volse-hubzilla-e41082dcccdb46da7ef425f399cf4dd06dff9b6c.tar.bz2
volse-hubzilla-e41082dcccdb46da7ef425f399cf4dd06dff9b6c.zip
automate bbcode list creation even further
Diffstat (limited to 'view/js/autocomplete.js')
-rw-r--r--view/js/autocomplete.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js
index 5f67476df..36551dc42 100644
--- a/view/js/autocomplete.js
+++ b/view/js/autocomplete.js
@@ -100,6 +100,56 @@ function submit_form(e) {
$(e).parents('form').submit();
}
+function getWord(text, caretPos) {
+ var index = text.indexOf(caretPos);
+ var postText = text.substring(caretPos, caretPos+8);
+ if ((postText.indexOf("[/list]") > 0) || postText.indexOf("[/ul]") > 0 || postText.indexOf("[/ol]") > 0) {
+ return postText;
+ }
+}
+
+function getCaretPosition(ctrl) {
+ var CaretPos = 0; // IE Support
+ if (document.selection) {
+ ctrl.focus();
+ var Sel = document.selection.createRange();
+ Sel.moveStart('character', -ctrl.value.length);
+ CaretPos = Sel.text.length;
+ }
+ // Firefox support
+ else if (ctrl.selectionStart || ctrl.selectionStart == '0')
+ CaretPos = ctrl.selectionStart;
+ return (CaretPos);
+}
+
+function setCaretPosition(ctrl, pos){
+ if(ctrl.setSelectionRange) {
+ ctrl.focus();
+ ctrl.setSelectionRange(pos,pos);
+ }
+ else if (ctrl.createTextRange) {
+ var range = ctrl.createTextRange();
+ range.collapse(true);
+ range.moveEnd('character', pos);
+ range.moveStart('character', pos);
+ range.select();
+ }
+}
+
+function listNewLineAutocomplete(id) {
+ var text = document.getElementById(id);
+ var caretPos = getCaretPosition(text)
+ var word = getWord(text.value, caretPos);
+ if (word != null) {
+ var textBefore = text.value.substring(0, caretPos);
+ var textAfter = text.value.substring(caretPos, text.length);
+ $('#' + id).val(textBefore + '\r\n[*] ' + textAfter);
+ setCaretPosition(text, caretPos + 5);
+ return true;
+ }
+}
+
+
/**
* jQuery plugin 'editor_autocomplete'
*/
@@ -242,6 +292,13 @@ function submit_form(e) {
var a = this.textcomplete([bbco], {className:'acpopup', zIndex:1020});
a.on('textComplete:select', function(e, value, strategy) { value; });
+ $(this).keypress(function(e){
+ if (e.keyCode == 13) {
+ x = listNewLineAutocomplete(this.id);
+ if(x)
+ e.preventDefault();
+ }
+ });
};
})( jQuery );