aboutsummaryrefslogtreecommitdiffstats
path: root/view/js
diff options
context:
space:
mode:
Diffstat (limited to 'view/js')
-rw-r--r--view/js/autocomplete.js123
-rw-r--r--view/js/main.js23
-rw-r--r--view/js/mod_connections.js10
-rw-r--r--view/js/mod_connedit.js28
-rw-r--r--view/js/mod_mail.js11
-rw-r--r--view/js/mod_message.js13
-rw-r--r--view/js/mod_network.js7
-rw-r--r--view/js/mod_photos.js18
-rw-r--r--view/js/mod_poke.js13
-rw-r--r--view/js/mod_sources.js18
10 files changed, 160 insertions, 104 deletions
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js
index e68356057..40a9cd4c8 100644
--- a/view/js/autocomplete.js
+++ b/view/js/autocomplete.js
@@ -3,15 +3,31 @@
*
* require jQuery, jquery.textcomplete
*/
-function mysearch(term, callback, backend_url, extra_channels) {
+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
+
+ 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[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 || x.nick.toLowerCase().indexOf(lterm) >= 0); });
+ matching.unshift({taggable:false, text: term, replace: term});
+ callback(matching);
+ return;
+ }
+ }
+
var postdata = {
start:0,
count:100,
search:term,
- type:'c',
+ type:type,
}
- if(extra_channels)
+ if(typeof extra_channels !== 'undefined' && extra_channels)
postdata['extra_channels[]'] = extra_channels;
$.ajax({
@@ -20,16 +36,36 @@ function mysearch(term, callback, backend_url, extra_channels) {
data: postdata,
dataType: 'json',
success:function(data){
- callback(data.items);
+ // 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[bt][lterm] = 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 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 )
+function contact_format(item) {
+ // 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 "<div class='{0}' title='{4}'><img src='{1}'>{2}{3}</div>".format(item.taggable, item.photo, item.name, desc, item.link)
+ }
+ else
+ return "<div>"+item.text+"</div>"
}
-function replace(item) {
+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.
@@ -39,20 +75,31 @@ function replace(item) {
return '$1$2'+item.nick.replace(' ','') + '+' + id;
}
+function basic_replace(item) {
+ if(typeof item.replace !== 'undefined')
+ return '$1'+item.replace;
+
+ return '$1'+item.name+' ';
+}
+
+function submit_form(e) {
+ $(e).parents('form').submit();
+}
+
/**
- * jQuery plugin 'contact_autocomplete'
+ * jQuery plugin 'editor_autocomplete'
*/
(function( $ ){
- $.fn.contact_autocomplete = function(backend_url, extra_channels) {
+ $.fn.editor_autocomplete = function(backend_url, extra_channels) {
if (typeof extra_channels === 'undefined') extra_channels = false;
// Autocomplete contacts
contacts = {
match: /(^|\s)(@\!*)([^ \n]+)$/,
index: 3,
- search: function(term, callback) { mysearch(term, callback, backend_url, extra_channels); },
- replace: replace,
- template: format,
+ search: function(term, callback) { contact_search(term, callback, backend_url, 'c', extra_channels); },
+ replace: editor_replace,
+ template: contact_format,
}
smilies = {
@@ -62,6 +109,56 @@ function replace(item) {
template: function(item) { return item['icon'] + item['text'] },
replace: function(item) { return "$1"+item['text'] + ' '; },
}
- this.textcomplete([contacts,smilies],{className:'acpopup'});
+ this.attr('autocomplete','off');
+ this.textcomplete([contacts,smilies],{className:'acpopup',zIndex:1050});
+ };
+})( jQuery );
+
+/**
+ * jQuery plugin 'search_autocomplete'
+ */
+(function( $ ){
+ $.fn.search_autocomplete = function(backend_url) {
+
+ // Autocomplete contacts
+ contacts = {
+ 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',maxCount:100,zIndex: 1050});
+
+ a.on('textComplete:select', function(e,value,strategy) { submit_form(this); });
+
+ };
+})( jQuery );
+
+(function( $ ){
+ $.fn.contact_autocomplete = function(backend_url, typ, autosubmit, onselect) {
+
+ if(typeof typ === 'undefined') typ = '';
+ if(typeof autosubmit === 'undefined') autosubmit = false;
+
+ // Autocomplete contacts
+ contacts = {
+ match: /(^)([^\n]+)$/,
+ index: 2,
+ search: function(term, callback) { contact_search(term, callback, backend_url, typ,[]); },
+ replace: basic_replace,
+ template: contact_format,
+ }
+
+ this.attr('autocomplete','off');
+ var a = this.textcomplete([contacts],{className:'acpopup',zIndex:1050});
+
+ if(autosubmit)
+ a.on('textComplete:select', function(e,value,strategy) { submit_form(this); });
+
+ if(typeof onselect !== 'undefined')
+ a.on('textComplete:select',function(e,value,strategy) { onselect(value); });
};
})( jQuery );
+
diff --git a/view/js/main.js b/view/js/main.js
index 85aea9875..0c56c8d41 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;
@@ -574,7 +577,7 @@ function updateConvItems(mode,data) {
}
/* autocomplete @nicknames */
- $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl?f=&n=1");
+ $(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl?f=&n=1");
var bimgs = $(".wall-item-body img").not(function() { return this.complete; });
var bimgcount = bimgs.length;
@@ -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');
}
}
@@ -1118,6 +1125,8 @@ $(document).ready(function() {
$(".autotime").timeago();
+ $("#toc").toc({content: "div.page-body", headings: "h1,h2,h3,h4"});
+
});
diff --git a/view/js/mod_connections.js b/view/js/mod_connections.js
index 8a8f2fee6..f29d96729 100644
--- a/view/js/mod_connections.js
+++ b/view/js/mod_connections.js
@@ -1,13 +1,5 @@
$(document).ready(function() {
- var a;
- a = $("#contacts-search").autocomplete({
- serviceUrl: baseurl + '/acl',
- minChars: 2,
- width: 250,
- id: 'contact-search-ac',
- });
- a.setOptions({ autoSubmit: true, params: { type: 'a' }});
-
+ $("#contacts-search").contact_autocomplete(baseurl + '/acl', 'a', true);
});
$("#contacts-search").keyup(function(event){
diff --git a/view/js/mod_connedit.js b/view/js/mod_connedit.js
index 15b768929..765cbcc30 100644
--- a/view/js/mod_connedit.js
+++ b/view/js/mod_connedit.js
@@ -1,16 +1,23 @@
function abook_perms_msg() {
- $('.abook-permschange').show();
+ $('.abook-permsmsg').show();
// $('.abook-permschange').html(aStr['permschange']);
$('.abook-permssave').show();
}
+function abook_perms_new() {
+ $('.abook-permsnew').show();
+ $('.abook-permssave').show();
+}
+
+
$(document).ready(function() {
if(typeof(after_following) !== 'undefined' && after_following) {
if(typeof(connectDefaultShare) !== 'undefined')
connectDefaultShare();
else
connectFullShare();
+ abook_perms_new();
}
$('#id_pending').click(function() {
@@ -18,11 +25,12 @@ $(document).ready(function() {
connectDefaultShare();
else
connectFullShare();
+ abook_perms_new();
});
- $('.abook-edit-me').click(function() {
- abook_perms_msg();
- });
+// $('.abook-edit-me').click(function() {
+// abook_perms_msg();
+// });
});
@@ -46,7 +54,7 @@ function connectFullShare() {
$('#me_id_perms_view_storage').attr('checked','checked');
$('#me_id_perms_republish').attr('checked','checked');
$('#me_id_perms_post_like').attr('checked','checked');
- abook_perms_msg();
+// abook_perms_msg();
}
function connectCautiousShare() {
@@ -64,7 +72,7 @@ function connectCautiousShare() {
$('#me_id_perms_post_comments').attr('checked','checked');
$('#me_id_perms_post_mail').attr('checked','checked');
$('#me_id_perms_post_like').attr('checked','checked');
- abook_perms_msg();
+// abook_perms_msg();
}
@@ -87,7 +95,7 @@ function connectForum() {
$('#me_id_perms_tag_deliver').attr('checked','checked');
$('#me_id_perms_republish').attr('checked','checked');
$('#me_id_perms_post_like').attr('checked','checked');
- abook_perms_msg();
+// abook_perms_msg();
}
@@ -96,7 +104,7 @@ function connectClear() {
if(! $(this).is(':disabled'))
$(this).removeAttr('checked');
});
- abook_perms_msg();
+// abook_perms_msg();
}
@@ -112,7 +120,7 @@ function connectSoapBox() {
$('#me_id_perms_view_contacts').attr('checked','checked');
$('#me_id_perms_view_storage').attr('checked','checked');
$('#me_id_perms_view_pages').attr('checked','checked');
- abook_perms_msg();
+// abook_perms_msg();
}
@@ -124,7 +132,7 @@ function connectFollowOnly() {
});
$('#me_id_perms_send_stream').attr('checked','checked');
- abook_perms_msg();
+// abook_perms_msg();
}
diff --git a/view/js/mod_mail.js b/view/js/mod_mail.js
index 82f60f46f..16e06e6f5 100644
--- a/view/js/mod_mail.js
+++ b/view/js/mod_mail.js
@@ -1,13 +1,6 @@
$(document).ready(function() {
- var a;
- a = $("#recip").autocomplete({
- serviceUrl: baseurl + '/acl',
- minChars: 2,
- width: 250,
- id: 'recip-ac',
- onSelect: function(value,data) {
- $("#recip-complete").val(data);
- },
+ $("#recip").contact_autocomplete(baseurl + '/acl', '', false, function(data) {
+ $("#recip-complete").val(data.xid);
});
});
diff --git a/view/js/mod_message.js b/view/js/mod_message.js
deleted file mode 100644
index 82f60f46f..000000000
--- a/view/js/mod_message.js
+++ /dev/null
@@ -1,13 +0,0 @@
-$(document).ready(function() {
- var a;
- a = $("#recip").autocomplete({
- serviceUrl: baseurl + '/acl',
- minChars: 2,
- width: 250,
- id: 'recip-ac',
- onSelect: function(value,data) {
- $("#recip-complete").val(data);
- },
- });
-
-});
diff --git a/view/js/mod_network.js b/view/js/mod_network.js
index 8f1e5132d..cbdb82c75 100644
--- a/view/js/mod_network.js
+++ b/view/js/mod_network.js
@@ -1,10 +1,5 @@
$(document).ready(function() {
- var a;
- a = $("#search-text").autocomplete({
- serviceUrl: baseurl + '/search_ac',
- minChars: 2,
- id: 'search-text-ac',
- });
+ $("#search-text").contact_autocomplete(baseurl + '/search_ac');
$('.jslider-scale ins').addClass('hidden-xs');
});
diff --git a/view/js/mod_photos.js b/view/js/mod_photos.js
index 0a64f8102..0526fd1e6 100644
--- a/view/js/mod_photos.js
+++ b/view/js/mod_photos.js
@@ -2,19 +2,11 @@
var ispublic = aStr['everybody'];
$(document).ready(function() {
-
- var a;
- a = $("#photo-edit-newtag").autocomplete({
- serviceUrl: baseurl + '/acl',
- minChars: 2,
- width: 250,
- id: 'newtag-ac',
- onSelect: function(value,data) {
- $("#photo-edit-newtag").val(data);
- },
- });
- a.setOptions({ params: { type: 'p' }});
-
+ $(document).ready(function() {
+ $("#photo-edit-newtag").contact_autocomplete(baseurl + '/acl', 'p', false, function(data) {
+ $("#photo-edit-newtag").val('@' + data.name);
+ });
+ });
$('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
var selstr;
diff --git a/view/js/mod_poke.js b/view/js/mod_poke.js
index 78972888f..58e50588f 100644
--- a/view/js/mod_poke.js
+++ b/view/js/mod_poke.js
@@ -1,14 +1,5 @@
$(document).ready(function() {
- var a;
- a = $("#poke-recip").autocomplete({
- serviceUrl: baseurl + '/acl',
- minChars: 2,
- width: 250,
- id: 'poke-recip-ac',
- onSelect: function(value,data) {
- $("#poke-recip-complete").val(data);
- }
+ $("#poke-recip").contact_autocomplete(baseurl + '/acl', 'a', false, function(data) {
+ $("#poke-recip-complete").val(data.id);
});
- a.setOptions({ params: { type: 'a' }});
-
});
diff --git a/view/js/mod_sources.js b/view/js/mod_sources.js
index 49880b38f..1bbf89765 100644
--- a/view/js/mod_sources.js
+++ b/view/js/mod_sources.js
@@ -1,15 +1,7 @@
$(document).ready(function() {
- var a;
- a = $("#id_name").autocomplete({
- serviceUrl: baseurl + '/acl',
- minChars: 2,
- width: 250,
- id: 'id-name-ac',
- onSelect: function(value,data) {
- $("#id_abook").val(data);
- }
- });
-
- a.setOptions({ params: { type: 'a' }});
-
+ $(document).ready(function() {
+ $("#id_name").contact_autocomplete(baseurl + '/acl', 'a', false, function(data) {
+ $("#id_abook").val(data.id);
+ });
+ });
});