/**
- * Friendica people autocomplete
+ * @brief Friendica people autocomplete
*
* require jQuery, jquery.textcomplete
+ *
+ * for further documentation look at:
+ * http://yuku-t.com/jquery-textcomplete/
+ *
+ * https://github.com/yuku-t/jquery-textcomplete/blob/master/doc/how_to_use.md
*/
-function contact_search(term, callback, backend_url, type) {
+
+
+function contact_search(term, callback, backend_url, type, mode) {
// Check if there is a conversation id to include the unkonwn contacts of the conversation
var conv_id = document.activeElement.id.match(/\d+$/);
-
// Check if there is a cached result that contains the same information we would get with a full server-side search
var bt = backend_url+type;
if(!(bt in contact_search.cache)) contact_search.cache[bt] = {};
if(lterm.indexOf(t) >= 0) { // A more broad search has been performed already, so use those results
// Filter old results locally
var matching = contact_search.cache[bt][t].filter(function (x) { return (x.name.toLowerCase().indexOf(lterm) >= 0 || (typeof x.nick !== 'undefined' && x.nick.toLowerCase().indexOf(lterm) >= 0)); }); // Need to check that nick exists because groups don't have one
- matching.unshift({taggable:false, text: term, replace: term});
+ matching.unshift({forum:false, text: term, replace: term});
setTimeout(function() { callback(matching); } , 1); // Use "pseudo-thread" to avoid some problems
return;
}
if(conv_id !== null)
postdata['conversation'] = conv_id[0];
+ if(mode !== null)
+ postdata['mode'] = mode;
+
$.ajax({
type:'POST',
// Show contact information if not explicitly told to show something else
if(typeof item.text === 'undefined') {
var desc = ((item.label) ? item.nick + ' ' + item.label : item.nick);
+ var forum = ((item.forum) ? 'forum' : '');
if(typeof desc === 'undefined') desc = '';
if(desc) desc = ' ('+desc+')';
- return "<div class='{0}' title='{4}'><img class='acpopup-img' src='{1}'><span class='acpopup-contactname'>{2}</span><span class='acpopup-sub-text'>{3}</span><div class='clear'></div></div>".format(item.taggable, item.photo, item.name, desc, item.link);
+ return "<div class='{0}' title='{4}'><img class='acpopup-img' src='{1}'><span class='acpopup-contactname'>{2}</span><span class='acpopup-sub-text'>{3}</span><div class='clear'></div></div>".format(forum, item.photo, item.name, desc, item.link);
}
else
return "<div>" + item.text + "</div>";
(function( $ ) {
$.fn.editor_autocomplete = function(backend_url) {
+ // list of supported bbtags
+ var bbelements = ['b', 'u', 'i', 'img', 'url', 'quote', 'code', 'spoiler', 'audio', 'video', 'youtube', 'map', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 's', 'o', 'list', 'center', 'nosmile', 'vimeo' ];
+
// Autocomplete contacts
contacts = {
match: /(^|\s)(@\!*)([^ \n]+)$/,
template: contact_format,
};
+ // Autocomplete smilies e.g. ":like"
smilies = {
match: /(^|\s)(:[a-z]{2,})$/,
index: 2,
- 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; },
+ 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; },
replace: function(item) { return "$1" + item.text + ' '; },
};
+
+ // Autocomplete BBTags
+ bbtags = {
+ match: /\[(\w*)$/,
+ index: 1,
+ search: function (term, callback) { callback($.map(bbelements, function (element) { return element.indexOf(term) === 0 ? element : null; })); },
+ replace: function (element) { return ['[' + element + ']', '[/' + element + ']']; },
+ };
this.attr('autocomplete','off');
- this.textcomplete([contacts,smilies], {className:'acpopup', zIndex:1020});
+ this.textcomplete([contacts,smilies, bbtags], {className:'acpopup', zIndex:1020});
};
})( jQuery );
contacts = {
match: /(^@)([^\n]{2,})$/,
index: 2,
- search: function(term, callback) { contact_search(term, callback, backend_url, 'x'); },
+ search: function(term, callback) { contact_search(term, callback, backend_url, 'x', 'contact'); },
+ replace: basic_replace,
+ template: contact_format,
+ };
+
+ // Autocomplete forum accounts
+ community = {
+ match: /(^!)([^\n]{2,})$/,
+ index: 2,
+ search: function(term, callback) { contact_search(term, callback, backend_url, 'x', 'community'); },
replace: basic_replace,
template: contact_format,
};
this.attr('autocomplete', 'off');
- var a = this.textcomplete([contacts], {className:'acpopup', maxCount:100, zIndex: 1020, appendTo:'nav'});
+ var a = this.textcomplete([contacts, community], {className:'acpopup', maxCount:100, zIndex: 1020, appendTo:'#nav-search-box'});
a.on('textComplete:select', function(e, value, strategy) { submit_form(this); });
};
})( jQuery );