Make nav search use textcomplete
This commit is contained in:
parent
4e3aadc38a
commit
34ecbcceea
@ -15,15 +15,7 @@ function nav(&$a) {
|
|||||||
$a->page['htmlhead'] .= <<< EOT
|
$a->page['htmlhead'] .= <<< EOT
|
||||||
|
|
||||||
<script>$(document).ready(function() {
|
<script>$(document).ready(function() {
|
||||||
var a;
|
$("#nav-search-text").search_autocomplete('$base/acl');
|
||||||
a = $("#nav-search-text").autocomplete({
|
|
||||||
serviceUrl: '$base/acl',
|
|
||||||
minChars: 2,
|
|
||||||
width: 250,
|
|
||||||
id: 'nav-search-text-ac',
|
|
||||||
});
|
|
||||||
a.setOptions({ autoSubmit: true, params: { type: 'x' }});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
28
mod/acl.php
28
mod/acl.php
@ -182,25 +182,25 @@ function acl_init(&$a){
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
elseif($type == 'x') {
|
elseif($type == 'x') {
|
||||||
|
|
||||||
$r = navbar_complete($a);
|
$r = navbar_complete($a);
|
||||||
$x = array();
|
$contacts = array();
|
||||||
$x['query'] = $search;
|
|
||||||
$x['photos'] = array();
|
|
||||||
$x['links'] = array();
|
|
||||||
$x['suggestions'] = array();
|
|
||||||
$x['data'] = array();
|
|
||||||
if($r) {
|
if($r) {
|
||||||
foreach($r as $g) {
|
foreach($r as $g) {
|
||||||
$x['photos'][] = $g['photo'];
|
$contacts[] = array(
|
||||||
$x['links'][] = $g['url'];
|
"photo" => $g['photo'],
|
||||||
$x['suggestions'][] = '@' . $g['name'];
|
"name" => $g['name'],
|
||||||
$x['data'][] = $g['name'];
|
"nick" => $g['address'],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo json_encode($x);
|
|
||||||
killme();
|
|
||||||
|
|
||||||
|
$o = array(
|
||||||
|
'start' => $start,
|
||||||
|
'count' => $count,
|
||||||
|
'items' => $contacts,
|
||||||
|
);
|
||||||
|
echo json_encode($o);
|
||||||
|
killme();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$r = array();
|
$r = array();
|
||||||
@ -284,7 +284,7 @@ function navbar_complete(&$a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dirmode = intval(get_config('system','directory_mode'));
|
$dirmode = intval(get_config('system','directory_mode'));
|
||||||
$search = ((x($_REQUEST,'query')) ? htmlentities($_REQUEST['query'],ENT_COMPAT,'UTF-8',false) : '');
|
$search = ((x($_REQUEST,'search')) ? htmlentities($_REQUEST['search'],ENT_COMPAT,'UTF-8',false) : '');
|
||||||
if(! $search || mb_strlen($search) < 2)
|
if(! $search || mb_strlen($search) < 2)
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
|
@ -3,15 +3,15 @@
|
|||||||
*
|
*
|
||||||
* require jQuery, jquery.textcomplete
|
* require jQuery, jquery.textcomplete
|
||||||
*/
|
*/
|
||||||
function contact_search(term, callback, backend_url, extra_channels) {
|
function contact_search(term, callback, backend_url, type, extra_channels) {
|
||||||
var postdata = {
|
var postdata = {
|
||||||
start:0,
|
start:0,
|
||||||
count:100,
|
count:100,
|
||||||
search:term,
|
search:term,
|
||||||
type:'c',
|
type:type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if(extra_channels)
|
if(typeof extra_channels !== 'undefined' && extra_channels)
|
||||||
postdata['extra_channels[]'] = extra_channels;
|
postdata['extra_channels[]'] = extra_channels;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@ -39,6 +39,10 @@ function editor_replace(item) {
|
|||||||
return '$1$2'+item.nick.replace(' ','') + '+' + id;
|
return '$1$2'+item.nick.replace(' ','') + '+' + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function basic_replace(item) {
|
||||||
|
return '$1$2'+item.nick;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* jQuery plugin 'editor_autocomplete'
|
* jQuery plugin 'editor_autocomplete'
|
||||||
*/
|
*/
|
||||||
@ -50,7 +54,7 @@ function editor_replace(item) {
|
|||||||
contacts = {
|
contacts = {
|
||||||
match: /(^|\s)(@\!*)([^ \n]+)$/,
|
match: /(^|\s)(@\!*)([^ \n]+)$/,
|
||||||
index: 3,
|
index: 3,
|
||||||
search: function(term, callback) { contact_search(term, callback, backend_url, extra_channels); },
|
search: function(term, callback) { contact_search(term, callback, backend_url, 'c', extra_channels); },
|
||||||
replace: editor_replace,
|
replace: editor_replace,
|
||||||
template: contact_format,
|
template: contact_format,
|
||||||
}
|
}
|
||||||
@ -65,3 +69,21 @@ function editor_replace(item) {
|
|||||||
this.textcomplete([contacts,smilies],{className:'acpopup'});
|
this.textcomplete([contacts,smilies],{className:'acpopup'});
|
||||||
};
|
};
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jQuery plugin 'search_autocomplete'
|
||||||
|
*/
|
||||||
|
(function( $ ){
|
||||||
|
$.fn.search_autocomplete = function(backend_url) {
|
||||||
|
|
||||||
|
// Autocomplete contacts
|
||||||
|
contacts = {
|
||||||
|
match: /(^)(@)([^\n]+)$/,
|
||||||
|
index: 3,
|
||||||
|
search: function(term, callback) { contact_search(term, callback, backend_url, 'x',[]); },
|
||||||
|
replace: basic_replace,
|
||||||
|
template: contact_format,
|
||||||
|
}
|
||||||
|
this.textcomplete([contacts],{className:'acpopup'});
|
||||||
|
};
|
||||||
|
})( jQuery );
|
||||||
|
Reference in New Issue
Block a user