From 97ccbf1bfb95be412393bed207a26fd8d0cbf512 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 6 Apr 2016 22:18:59 +0200 Subject: adjust the regex to also work with asteriks and use the simpler syntax for lists --- view/js/autocomplete.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'view') diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 3e7e08b35..5f67476df 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -216,7 +216,7 @@ function submit_form(e) { } bbco = { - match: /\[(\w*)$/, + match: /\[(\w*\**)$/, search: function (term, callback) { callback($.map(elements, function (element) { return element.indexOf(term) === 0 ? element : null; @@ -225,11 +225,12 @@ function submit_form(e) { index: 1, replace: function (element) { if(open_elements.indexOf(element) < 0) { - if(element === 'ol' || element === 'ul') { - return ['\[' + element + '\]' + '\n\[li\]', '\[/li\]\n' + '\[/' + element + '\]']; - } else { - return ['\[' + element + '\]', '\[/' + element + '\]']; - } + if(element === 'list' || element === 'ol' || element === 'ul') { + return ['\[' + element + '\]' + '\n\[*\] ', '\n\[/' + element + '\]']; + } + else { + return ['\[' + element + '\]', '\[/' + element + '\]']; + } } else { return '\[' + element + '\] '; -- cgit v1.2.3 From e41082dcccdb46da7ef425f399cf4dd06dff9b6c Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 7 Apr 2016 00:46:45 +0200 Subject: automate bbcode list creation even further --- view/js/autocomplete.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'view') 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 ); -- cgit v1.2.3