upgrade to textcomplete (jquery.textcomplete is discontinued), enable built-in cache and unify to start lookup after 3 characters

This commit is contained in:
Mario Vavti 2018-04-26 12:38:25 +02:00
parent 09666ae8e9
commit fe4defe752
9 changed files with 2467 additions and 1511 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -184,8 +184,9 @@ function string2bb(element) {
// Autocomplete contacts // Autocomplete contacts
contacts = { contacts = {
match: /(^|\s)(@\!*)([^ \n]+)$/, match: /(^|\s)(@\!*)([^ \n]{3,})$/,
index: 3, index: 3,
cache: true,
search: function(term, callback) { contact_search(term, callback, backend_url, 'c', extra_channels, spinelement=false); }, search: function(term, callback) { contact_search(term, callback, backend_url, 'c', extra_channels, spinelement=false); },
replace: editor_replace, replace: editor_replace,
template: contact_format template: contact_format
@ -193,8 +194,9 @@ function string2bb(element) {
// Autocomplete forums // Autocomplete forums
forums = { forums = {
match: /(^|\s)(\!\!*)([^ \n]+)$/, match: /(^|\s)(\!\!*)([^ \n]{3,})$/,
index: 3, index: 3,
cache: true,
search: function(term, callback) { contact_search(term, callback, backend_url, 'f', extra_channels, spinelement=false); }, search: function(term, callback) { contact_search(term, callback, backend_url, 'f', extra_channels, spinelement=false); },
replace: editor_replace, replace: editor_replace,
template: contact_format template: contact_format
@ -203,8 +205,9 @@ function string2bb(element) {
// Autocomplete hashtags // Autocomplete hashtags
tags = { tags = {
match: /(^|\s)(\#)([^ \n]{2,})$/, match: /(^|\s)(\#)([^ \n]{3,})$/,
index: 3, index: 3,
cache: true,
search: function(term, callback) { $.getJSON('/hashtags/' + '$f=&t=' + term).done(function(data) { callback($.map(data, function(entry) { return entry.text.toLowerCase().indexOf(term.toLowerCase()) === 0 ? entry : null; })); }); }, search: function(term, callback) { $.getJSON('/hashtags/' + '$f=&t=' + term).done(function(data) { callback($.map(data, function(entry) { return entry.text.toLowerCase().indexOf(term.toLowerCase()) === 0 ? entry : null; })); }); },
replace: function(item) { return "$1$2" + item.text + ' '; }, replace: function(item) { return "$1$2" + item.text + ' '; },
context: function(text) { return text.toLowerCase(); }, context: function(text) { return text.toLowerCase(); },
@ -215,13 +218,20 @@ function string2bb(element) {
smilies = { smilies = {
match: /(^|\s)(:[a-z_:]{2,})$/, match: /(^|\s)(:[a-z_:]{2,})$/,
index: 2, index: 2,
cache: true,
search: function(term, callback) { $.getJSON('/smilies/json').done(function(data) { callback($.map(data, function(entry) { return entry.text.indexOf(term) === 0 ? entry : null; })); }); }, search: function(term, callback) { $.getJSON('/smilies/json').done(function(data) { callback($.map(data, function(entry) { return entry.text.indexOf(term) === 0 ? entry : null; })); }); },
//template: function(item) { return item.icon + item.text; }, //template: function(item) { return item.icon + item.text; },
replace: function(item) { return "$1" + item.text + ' '; }, replace: function(item) { return "$1" + item.text + ' '; },
template: smiley_format template: smiley_format
}; };
this.attr('autocomplete','off'); this.attr('autocomplete','off');
this.textcomplete([contacts,forums,smilies,tags], {className:'acpopup', zIndex:1020});
var Textarea = Textcomplete.editors.Textarea;
var editor = new Textarea(this[0]);
var textcomplete = new Textcomplete(editor);
textcomplete.register([contacts,forums,smilies,tags], {className:'acpopup', zIndex:1020});
}; };
})( jQuery ); })( jQuery );
@ -234,6 +244,7 @@ function string2bb(element) {
contacts = { contacts = {
match: /(^@)([^\n]{3,})$/, match: /(^@)([^\n]{3,})$/,
index: 2, index: 2,
cache: true,
search: function(term, callback) { contact_search(term, callback, backend_url, 'x', [], spinelement='#nav-search-spinner'); }, search: function(term, callback) { contact_search(term, callback, backend_url, 'x', [], spinelement='#nav-search-spinner'); },
replace: basic_replace, replace: basic_replace,
template: contact_format, template: contact_format,
@ -243,6 +254,7 @@ function string2bb(element) {
forums = { forums = {
match: /(^\!)([^\n]{3,})$/, match: /(^\!)([^\n]{3,})$/,
index: 2, index: 2,
cache: true,
search: function(term, callback) { contact_search(term, callback, backend_url, 'f', [], spinelement='#nav-search-spinner'); }, search: function(term, callback) { contact_search(term, callback, backend_url, 'f', [], spinelement='#nav-search-spinner'); },
replace: basic_replace, replace: basic_replace,
template: contact_format template: contact_format
@ -252,6 +264,7 @@ function string2bb(element) {
tags = { tags = {
match: /(^\#)([^ \n]{3,})$/, match: /(^\#)([^ \n]{3,})$/,
index: 2, index: 2,
cache: true,
search: function(term, callback) { $.getJSON('/hashtags/' + '$f=&t=' + term).done(function(data) { callback($.map(data, function(entry) { return entry.text.toLowerCase().indexOf(term.toLowerCase()) === 0 ? entry : null; })); }); }, search: function(term, callback) { $.getJSON('/hashtags/' + '$f=&t=' + term).done(function(data) { callback($.map(data, function(entry) { return entry.text.toLowerCase().indexOf(term.toLowerCase()) === 0 ? entry : null; })); }); },
replace: function(item) { return "$1" + item.text + ' '; }, replace: function(item) { return "$1" + item.text + ' '; },
context: function(text) { return text.toLowerCase(); }, context: function(text) { return text.toLowerCase(); },
@ -259,8 +272,14 @@ function string2bb(element) {
}; };
this.attr('autocomplete', 'off'); this.attr('autocomplete', 'off');
var a = this.textcomplete([contacts,forums,tags], {className:'acpopup', maxCount:100, zIndex: 1020, appendTo:'nav'});
a.on('textComplete:select', function(e, value, strategy) { submit_form(this); }); var Textarea = Textcomplete.editors.Textarea;
var editor = new Textarea(this[0]);
var textcomplete = new Textcomplete(editor);
textcomplete.register([contacts,forums,tags], {className:'acpopup', maxCount:100, zIndex: 1020, appendTo:'nav'});
this.on('textComplete:select', function(e, value, strategy) { submit_form(this); });
}; };
})( jQuery ); })( jQuery );
@ -271,21 +290,27 @@ function string2bb(element) {
// Autocomplete contacts // Autocomplete contacts
contacts = { contacts = {
match: /(^)([^\n]+)$/, match: /(^)([^\n]{3,})$/,
index: 2, index: 2,
cache: true,
search: function(term, callback) { contact_search(term, callback, backend_url, typ,[], spinelement=false); }, search: function(term, callback) { contact_search(term, callback, backend_url, typ,[], spinelement=false); },
replace: basic_replace, replace: basic_replace,
template: contact_format, template: contact_format,
}; };
this.attr('autocomplete','off'); this.attr('autocomplete','off');
var a = this.textcomplete([contacts], {className:'acpopup', zIndex:1020});
var Textarea = Textcomplete.editors.Textarea;
var editor = new Textarea(this[0]);
var textcomplete = new Textcomplete(editor);
textcomplete.register([contacts], {className:'acpopup', zIndex:1020});
if(autosubmit) if(autosubmit)
a.on('textComplete:select', function(e,value,strategy) { submit_form(this); }); this.on('textComplete:select', function(e,value,strategy) { submit_form(this); });
if(typeof onselect !== 'undefined') if(typeof onselect !== 'undefined')
a.on('textComplete:select', function(e, value, strategy) { onselect(value); }); this.on('textComplete:select', function(e, value, strategy) { onselect(value); });
}; };
})( jQuery ); })( jQuery );
@ -297,21 +322,27 @@ function string2bb(element) {
// Autocomplete contacts // Autocomplete contacts
names = { names = {
match: /(^)([^\n]+)$/, match: /(^)([^\n]{3,})$/,
index: 2, index: 2,
cache: true,
search: function(term, callback) { contact_search(term, callback, backend_url, typ,[], spinelement=false); }, search: function(term, callback) { contact_search(term, callback, backend_url, typ,[], spinelement=false); },
replace: trim_replace, replace: trim_replace,
template: contact_format, template: contact_format,
}; };
this.attr('autocomplete','off'); this.attr('autocomplete','off');
var a = this.textcomplete([names], {className:'acpopup', zIndex:1020});
var Textarea = Textcomplete.editors.Textarea;
var editor = new Textarea(this[0]);
var textcomplete = new Textcomplete(editor);
textcomplete.register([names], {className:'acpopup', zIndex:1020});
if(autosubmit) if(autosubmit)
a.on('textComplete:select', function(e,value,strategy) { submit_form(this); }); this.on('textComplete:select', function(e,value,strategy) { submit_form(this); });
if(typeof onselect !== 'undefined') if(typeof onselect !== 'undefined')
a.on('textComplete:select', function(e, value, strategy) { onselect(value); }); this.on('textComplete:select', function(e, value, strategy) { onselect(value); });
}; };
})( jQuery ); })( jQuery );
@ -375,11 +406,16 @@ function string2bb(element) {
}; };
this.attr('autocomplete','off'); this.attr('autocomplete','off');
var a = this.textcomplete([bbco], {className:'acpopup', zIndex:1020});
a.on('textComplete:select', function(e, value, strategy) { value; }); var Textarea = Textcomplete.editors.Textarea;
var editor = new Textarea(this[0]);
var textcomplete = new Textcomplete(editor);
a.keypress(function(e){ textcomplete.register([bbco], {className:'acpopup', zIndex:1020});
this.on('textComplete:select', function(e, value, strategy) { value; });
this.keypress(function(e){
if (e.keyCode == 13) { if (e.keyCode == 13) {
var x = listNewLineAutocomplete(this.id); var x = listNewLineAutocomplete(this.id);
if(x) { if(x) {

View file

@ -15,9 +15,8 @@ head_add_js('jquery.js');
head_add_js('/library/justifiedGallery/jquery.justifiedGallery.min.js'); head_add_js('/library/justifiedGallery/jquery.justifiedGallery.min.js');
head_add_js('/library/sprintf.js/dist/sprintf.min.js'); head_add_js('/library/sprintf.js/dist/sprintf.min.js');
//head_add_js('jquery.textinputs.js'); head_add_js('/library/textcomplete/textcomplete.min.js');
head_add_js('autocomplete.js'); head_add_js('autocomplete.js');
head_add_js('/library/jquery-textcomplete/jquery.textcomplete.js');
head_add_js('/library/jquery.timeago.js'); head_add_js('/library/jquery.timeago.js');
head_add_js('/library/readmore.js/readmore.js'); head_add_js('/library/readmore.js/readmore.js');