From 833d51527b7cf852f519ea29c6bf20bc25a3d717 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Thu, 8 Jan 2015 16:05:00 +0100 Subject: [PATCH 1/3] Honor requested count in navbar search --- mod/acl.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mod/acl.php b/mod/acl.php index f575db55b..d406942c3 100644 --- a/mod/acl.php +++ b/mod/acl.php @@ -293,9 +293,10 @@ function navbar_complete(&$a) { $url = $directory['url'] . '/dirsearch'; } + $count = (x($_REQUEST,'count')?$_REQUEST['count']:100); if($url) { $query = $url . '?f=' ; - $query .= '&name=' . urlencode($search) . '&limit=50' . (($address) ? '&address=' . urlencode($search) : ''); + $query .= '&name=' . urlencode($search) . "&limit=$count" . (($address) ? '&address=' . urlencode($search) : ''); $x = z_fetch_url($query); if($x['success']) { From 4beb78201467f4256424d688b2a55705e333f96a Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Thu, 8 Jan 2015 16:06:37 +0100 Subject: [PATCH 2/3] Fix issue with case sensitive filtering in autocomplete, put autocomplete dropdown on top of navbar, show entry to leave the text unchanged --- view/js/autocomplete.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 8572cf708..63aa7a8f1 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -6,10 +6,12 @@ function contact_search(term, callback, backend_url, type, extra_channels) { // Check if there is a cached result that contains the same information we would get with a full server-side search // Assume type hasn't changed + var lterm = term.toLowerCase(); // Ignore case for(t in contact_search.cache) { - if(term.indexOf(t) >= 0) { // A more broad search has been performed already, so use those results + 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[t].filter(function (x) { return (x.name.indexOf(term) >= 0 || x.nick.indexOf(term) >= 0); }); + var matching = contact_search.cache[t].filter(function (x) { return (x.name.toLowerCase().indexOf(lterm) >= 0 || x.nick.toLowerCase().indexOf(lterm) >= 0); }); + matching.unshift({taggable:false, text: term, replace: term}); callback(matching); return; } @@ -33,20 +35,30 @@ function contact_search(term, callback, backend_url, type, extra_channels) { success:function(data){ // Cache results if we got them all (more information would not improve results) // data.count represents the maximum number of items - if(data.items.length < data.count) { - contact_search.cache[term] = data.items; + if(data.items.length -1 < data.count) { + contact_search.cache[lterm] = data.items; } - callback(data.items); + var items = data.items.slice(0); + items.unshift({taggable:false, text: term, replace: term}); + callback(items); }, }).fail(function () {callback([]); }); // Callback must be invoked even if something went wrong. } contact_search.cache = {}; + function contact_format(item) { - return "
{2} ({3})
".format(item.taggable, item.photo, item.name, ((item.label) ? item.nick + ' ' + item.label : item.nick), item.link ) + if(typeof item.text === 'undefined') + return "
{2} ({3})
".format(item.taggable, item.photo, item.name, ((item.label) ? item.nick + ' ' + item.label : item.nick), item.link) + else + return "
"+item.text+"
" } function editor_replace(item) { + if(typeof item.replace !== 'undefined') { + return '$1$2'+item.replace; + } + // $2 ensures that prefix (@,@!) is preserved var id = item.id; // 16 chars of hash should be enough. Full hash could be used if it can be done in a visually appealing way. @@ -57,6 +69,9 @@ function editor_replace(item) { } function basic_replace(item) { + if(typeof item.replace !== 'undefined') + return '$1'+item.replace; + return '$1'+item.name+' '; } @@ -88,7 +103,7 @@ function submit_form(e) { replace: function(item) { return "$1"+item['text'] + ' '; }, } this.attr('autocomplete','off'); - this.textcomplete([contacts,smilies],{className:'acpopup'}); + this.textcomplete([contacts,smilies],{className:'acpopup',zIndex:1050}); }; })( jQuery ); @@ -107,7 +122,7 @@ function submit_form(e) { template: contact_format, } this.attr('autocomplete','off'); - var a = this.textcomplete([contacts],{className:'acpopup',maxCount:100}); + var a = this.textcomplete([contacts],{className:'acpopup',maxCount:100,zIndex: 1050}); a.on('textComplete:select', function(e,value,strategy) { submit_form(this); }); @@ -130,7 +145,7 @@ function submit_form(e) { } this.attr('autocomplete','off'); - var a = this.textcomplete([contacts],{className:'acpopup'}); + var a = this.textcomplete([contacts],{className:'acpopup',zIndex:1050}); if(autosubmit) a.on('textComplete:select', function(e,value,strategy) { submit_form(this); }); From 32c6eab01c820c0ab44aa1b8860bf3173061e4e2 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Thu, 8 Jan 2015 17:16:08 +0100 Subject: [PATCH 3/3] Fix saved searches on network page, fix caching mith multiple autocompleters --- mod/search_ac.php | 48 ++++++++++++++++++++++------------------- view/js/autocomplete.js | 19 ++++++++++------ view/js/mod_network.js | 2 +- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/mod/search_ac.php b/mod/search_ac.php index 36da21376..b4f5c9600 100644 --- a/mod/search_ac.php +++ b/mod/search_ac.php @@ -1,8 +1,9 @@ $g['xchan_photo_s'], + "name" => '@'.$g['xchan_name'], + "id" => $g['abook_id'], + "link" => $g['xchan_url'], + "label" => '', + "nick" => '', + ); } } @@ -53,15 +48,24 @@ function search_ac_init(&$a){ if(count($r)) { foreach($r as $g) { - $x['photos'][] = $a->get_baseurl() . '/images/hashtag.png'; - $x['links'][] = $g['url']; - $x['suggestions'][] = '#' . $g['term']; - $x['data'][] = intval($g['tid']); + $results[] = array( + "photo" => $a->get_baseurl() . '/images/hashtag.png', + "name" => '#'.$g['term'], + "id" => $g['tid'], + "link" => $g['url'], + "label" => '', + "nick" => '', + ); } } header("content-type: application/json"); - echo json_encode($x); + $o = array( + 'start' => $start, + 'count' => $count, + 'items' => $results, + ); + echo json_encode($o); logger('search_ac: ' . print_r($x,true)); diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 63aa7a8f1..40a9cd4c8 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -5,12 +5,15 @@ */ function contact_search(term, callback, backend_url, type, extra_channels) { // Check if there is a cached result that contains the same information we would get with a full server-side search - // Assume type hasn't changed + + var bt = backend_url+type; + if(!(bt in contact_search.cache)) contact_search.cache[bt] = {}; + var lterm = term.toLowerCase(); // Ignore case - for(t in contact_search.cache) { + for(t in 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[t].filter(function (x) { return (x.name.toLowerCase().indexOf(lterm) >= 0 || x.nick.toLowerCase().indexOf(lterm) >= 0); }); + var matching = contact_search.cache[bt][t].filter(function (x) { return (x.name.toLowerCase().indexOf(lterm) >= 0 || x.nick.toLowerCase().indexOf(lterm) >= 0); }); matching.unshift({taggable:false, text: term, replace: term}); callback(matching); return; @@ -36,7 +39,7 @@ function contact_search(term, callback, backend_url, type, extra_channels) { // Cache results if we got them all (more information would not improve results) // data.count represents the maximum number of items if(data.items.length -1 < data.count) { - contact_search.cache[lterm] = data.items; + contact_search.cache[bt][lterm] = data.items; } var items = data.items.slice(0); items.unshift({taggable:false, text: term, replace: term}); @@ -48,8 +51,12 @@ contact_search.cache = {}; function contact_format(item) { - if(typeof item.text === 'undefined') - return "
{2} ({3})
".format(item.taggable, item.photo, item.name, ((item.label) ? item.nick + ' ' + item.label : item.nick), item.link) + // 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) + if(desc) desc = ' ('+desc+')'; + return "
{2}{3}
".format(item.taggable, item.photo, item.name, desc, item.link) + } else return "
"+item.text+"
" } diff --git a/view/js/mod_network.js b/view/js/mod_network.js index 1b7ccdc0a..cbdb82c75 100644 --- a/view/js/mod_network.js +++ b/view/js/mod_network.js @@ -1,5 +1,5 @@ $(document).ready(function() { - $("#search-text").contact_autocomplete(baseurl + '/acl'); + $("#search-text").contact_autocomplete(baseurl + '/search_ac'); $('.jslider-scale ins').addClass('hidden-xs'); });