diff options
Diffstat (limited to 'view/js')
-rw-r--r-- | view/js/autocomplete.js | 21 | ||||
-rw-r--r-- | view/js/main.js | 19 |
2 files changed, 32 insertions, 8 deletions
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index afdf9c230..8572cf708 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -4,6 +4,17 @@ * require jQuery, jquery.textcomplete */ 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 + for(t in contact_search.cache) { + if(term.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); }); + callback(matching); + return; + } + } + var postdata = { start:0, count:100, @@ -20,10 +31,16 @@ function contact_search(term, callback, backend_url, type, extra_channels) { data: postdata, dataType: 'json', 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; + } callback(data.items); }, }).fail(function () {callback([]); }); // Callback must be invoked even if something went wrong. } +contact_search.cache = {}; function contact_format(item) { return "<div class='{0}' title='{4}'><img src='{1}'>{2} ({3})</div>".format(item.taggable, item.photo, item.name, ((item.label) ? item.nick + ' ' + item.label : item.nick), item.link ) @@ -83,14 +100,14 @@ function submit_form(e) { // Autocomplete contacts contacts = { - match: /(^@)([^\n]+)$/, + match: /(^@)([^\n]{2,})$/, index: 2, search: function(term, callback) { contact_search(term, callback, backend_url, 'x',[]); }, replace: basic_replace, template: contact_format, } this.attr('autocomplete','off'); - var a = this.textcomplete([contacts],{className:'acpopup'}); + var a = this.textcomplete([contacts],{className:'acpopup',maxCount:100}); a.on('textComplete:select', function(e,value,strategy) { submit_form(this); }); diff --git a/view/js/main.js b/view/js/main.js index 5e3fb2bff..9d5136c34 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -135,11 +135,13 @@ function showHideComments(id) { if( $('#collapsed-comments-' + id).is(':visible')) { + $('#collapsed-comments-' + id + ' .autotime').timeago('dispose'); $('#collapsed-comments-' + id).slideUp(); $('#hide-comments-' + id).html(aStr['showmore']); $('#hide-comments-total-' + id).show(); } else { + $('#collapsed-comments-' + id + ' .autotime').timeago(); $('#collapsed-comments-' + id).slideDown(); $('#hide-comments-' + id).html(aStr['showfewer']); $('#hide-comments-total-' + id).hide(); @@ -452,6 +454,7 @@ function updateConvItems(mode,data) { $('.thread-wrapper.toplevel_item',data).each(function() { var ident = $(this).attr('id'); + // This should probably use the context argument instead var commentWrap = $('#'+ident+' .collapsed-comments').attr('id'); var itmId = 0; var isVisible = false; @@ -468,7 +471,7 @@ function updateConvItems(mode,data) { $('#' + prev).after($(this)); if(isVisible) showHideComments(itmId); - $(".autotime",this).timeago(); + $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); } else { $('img',this).each(function() { @@ -479,7 +482,7 @@ function updateConvItems(mode,data) { $('#' + ident).replaceWith($(this)); if(isVisible) showHideComments(itmId); - $(".autotime",this).timeago(); + $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); } prev = ident; }); @@ -510,7 +513,7 @@ function updateConvItems(mode,data) { $('#threads-end').before($(this)); if(isVisible) showHideComments(itmId); - $(".autotime",this).timeago(); + $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); } else { $('img',this).each(function() { @@ -521,7 +524,7 @@ function updateConvItems(mode,data) { $('#' + ident).replaceWith($(this)); if(isVisible) showHideComments(itmId); - $(".autotime",this).timeago(); + $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); } }); @@ -555,7 +558,7 @@ function updateConvItems(mode,data) { $('#' + prev).after($(this)); if(isVisible) showHideComments(itmId); - $(".autotime",this).timeago(); + $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); } prev = ident; @@ -598,7 +601,11 @@ function updateConvItems(mode,data) { $(".wall-item-body, .contact-info").each(function() { if($(this).height() > divmore_height + 10) { if(! $(this).hasClass('divmore')) { - $(this).readmore({collapsedHeight: divmore_height, moreLink: '<a href="#">'+aStr['divgrowmore']+'</a>', lessLink: '<a href="#">'+aStr['divgrowless']+'</a>'}); + $(this).readmore({ + collapsedHeight: divmore_height, + moreLink: '<a href="#" class="divgrow-showmore">'+aStr['divgrowmore']+'</a>', + lessLink: '<a href="#" class="divgrow-showmore">'+aStr['divgrowless']+'</a>' + }); $(this).addClass('divmore'); } } |