hashtag autocomplete

This commit is contained in:
zotlabs 2018-03-07 16:59:55 -08:00
parent a454aad124
commit 48b1042347
2 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace Zotlabs\Module;
class Hashtags extends \Zotlabs\Web\Controller {
function init() {
$result = [];
logger(print_r($_REQUEST,true));
$t = escape_tags($_REQUEST['t']);
if(! $t)
json_return_and_die($result);
$r = q("select distinct(term) from term where term like '%s' and ttype = %d order by term",
dbesc($t . '%'),
intval(TERM_HASHTAG)
);
if($r) {
foreach($r as $rv) {
$result[] = [ 'text' => strtolower($rv['term']) ];
}
}
logger(print_r($result,true));
json_return_and_die($result);
}
}

View File

@ -74,6 +74,10 @@ function bbco_format(item) {
return "<div class='dropdown-item'>" + item + "</div>";
}
function tag_format(item) {
return "<div class='dropdown-item'>" + '#' + item.text + "</div>";
}
function editor_replace(item) {
if(typeof item.replace !== 'undefined') {
return '$1$2' + item.replace;
@ -202,6 +206,16 @@ function string2bb(element) {
};
// Autocomplete hashtags
tags = {
match: /(^|\s)(\#)([^ \n]{2,})$/,
index: 3,
search: function(term, callback) { $.getJSON('/hashtags/' + '$f=&t=' + term).done(function(data) { callback($.map(data, function(entry) { return entry.text.indexOf(term) === 0 ? entry : null; })); }); },
replace: function(item) { return "$1$2" + item.text + ' '; },
template: tag_format
};
smilies = {
match: /(^|\s)(:[a-z_:]{2,})$/,
index: 2,
@ -211,7 +225,7 @@ function string2bb(element) {
template: smiley_format
};
this.attr('autocomplete','off');
this.textcomplete([contacts,forums,smilies], {className:'acpopup', zIndex:1020});
this.textcomplete([contacts,forums,smilies,tags], {className:'acpopup', zIndex:1020});
};
})( jQuery );