aboutsummaryrefslogtreecommitdiffstats
path: root/view/js
diff options
context:
space:
mode:
Diffstat (limited to 'view/js')
-rw-r--r--view/js/acl.js2
-rw-r--r--view/js/autocomplete.js132
-rw-r--r--view/js/jquery-compat.js71
-rw-r--r--view/js/main.js32
-rw-r--r--view/js/mod_admin.js3
-rw-r--r--view/js/mod_connections.js10
-rw-r--r--view/js/mod_connedit.js2
-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_new_channel.js2
-rw-r--r--view/js/mod_photos.js28
-rw-r--r--view/js/mod_poke.js13
-rw-r--r--view/js/mod_profiles.js3
-rw-r--r--view/js/mod_settings.js5
-rw-r--r--view/js/mod_sources.js18
16 files changed, 168 insertions, 184 deletions
diff --git a/view/js/acl.js b/view/js/acl.js
index f9428e1c5..77c65e21d 100644
--- a/view/js/acl.js
+++ b/view/js/acl.js
@@ -258,7 +258,7 @@ ACL.prototype.get = function(start,count, search){
}
ACL.prototype.populate = function(data){
- var height = Math.ceil(data.tot / that.nw) * 42;
+ var height = Math.ceil(data.items.length / that.nw) * 42;
that.list_content.height(height);
$(data.items).each(function(){
html = "<div class='acl-list-item {4} {7} {5}' title='{6}' id='{2}{3}'>"+that.item_tpl+"</div>";
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js
index 7c3145769..40a9cd4c8 100644
--- a/view/js/autocomplete.js
+++ b/view/js/autocomplete.js
@@ -3,13 +3,32 @@
*
* require jQuery, jquery.textcomplete
*/
-function mysearch(term, callback, backend_url) {
+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(typeof extra_channels !== 'undefined' && extra_channels)
+ postdata['extra_channels[]'] = extra_channels;
$.ajax({
type:'POST',
@@ -17,33 +36,70 @@ function mysearch(term, callback, backend_url) {
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}'><img src='{1}'>{2} ({3})</div>".format(item.taggable, item.photo, item.name, ((item.label) ? item.nick + ' ' + item.label : item.nick) )
+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
- return '$1$2'+item.nick.replace(' ','') + '+' + item.id;
+ 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.
+ // 16 chars is also the minimum length in the backend (otherwise it's interpreted as a local id).
+ if(id.length > 16)
+ id = item.id.substring(0,16);
+ 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) {
+ $.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); },
- replace: replace,
- template: format,
+ search: function(term, callback) { contact_search(term, callback, backend_url, 'c', extra_channels); },
+ replace: editor_replace,
+ template: contact_format,
}
smilies = {
@@ -53,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/jquery-compat.js b/view/js/jquery-compat.js
deleted file mode 100644
index 7bf912542..000000000
--- a/view/js/jquery-compat.js
+++ /dev/null
@@ -1,71 +0,0 @@
-
-// provide jquery.browser so we can get rid of the migration toolkit
-
-jQuery.uaMatch = function( ua ) {
- ua = ua.toLowerCase();
-
- var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
- /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
- /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
- /(msie) ([\w.]+)/.exec( ua ) ||
- ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
- [];
-
- return {
- browser: match[ 1 ] || "",
- version: match[ 2 ] || "0"
- };
-};
-
-
-// Don't clobber any existing jQuery.browser in case it's different
-if ( !jQuery.browser ) {
- matched = jQuery.uaMatch( navigator.userAgent );
- browser = {};
-
- if ( matched.browser ) {
- browser[ matched.browser ] = true;
- browser.version = matched.version;
- }
-
- // Chrome is Webkit, but Webkit is also Safari.
- if ( browser.chrome ) {
- browser.webkit = true;
- } else if ( browser.webkit ) {
- browser.safari = true;
- }
-
- jQuery.browser = browser;
-}
-
-jQuery.fn.toggle = function( fn, fn2 ) {
-
- // Don't mess with animation or css toggles
- if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) {
- return oldToggle.apply( this, arguments );
- }
-
- // Save reference to arguments for access in closure
- var args = arguments,
- guid = fn.guid || jQuery.guid++,
- i = 0,
- toggler = function( event ) {
- // Figure out which function to execute
- var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
- jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
-
- // Make sure that clicks stop
- event.preventDefault();
-
- // and execute the function
- return args[ lastToggle ].apply( this, arguments ) || false;
- };
-
- // link all the functions, so any of them can unbind this click handler
- toggler.guid = guid;
- while ( i < args.length ) {
- args[ i++ ].guid = guid;
- }
-
- return this.click( toggler );
-};
diff --git a/view/js/main.js b/view/js/main.js
index f979f6b6f..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();
@@ -269,9 +271,9 @@
}
// fancyboxes
- $("a.popupbox").fancybox({
- 'transitionIn' : 'elastic',
- 'transitionOut' : 'elastic'
+ // Is this actually used anywhere?
+ $("a.popupbox").colorbox({
+ 'transition' : 'elastic'
});
@@ -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").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").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").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").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").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,14 +601,19 @@ function updateConvItems(mode,data) {
$(".wall-item-body, .contact-info").each(function() {
if($(this).height() > divmore_height + 10) {
if(! $(this).hasClass('divmore')) {
- $(this).divgrow({ initialHeight: divmore_height, moreText: aStr['divgrowmore'], lessText: aStr['divgrowless'], showBrackets: false });
+ $(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');
}
- }
+ }
});
}
function liveUpdate() {
+ if(typeof profile_uid === 'undefined') profile_uid = false; /* Should probably be unified with channelId defined in head.tpl */
if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').spin(false); return; }
if(($('.comment-edit-text-full').length) || (in_progress)) {
if(livetime) {
@@ -844,10 +852,12 @@ function updateConvItems(mode,data) {
}
function filestorage(event,nick,id) {
+ $('#cloud-index-' + last_filestorage_id).removeClass('cloud-index-active');
$('#perms-panel-' + last_filestorage_id).hide().html('');
$('#file-edit-' + id).spin('tiny');
delete acl;
$.get('filestorage/' + nick + '/' + id + '/edit', function(data) {
+ $('#cloud-index-' + id).addClass('cloud-index-active');
$('#perms-panel-' + id).html(data).show();
$('#file-edit-' + id).spin(false);
last_filestorage_id = id;
diff --git a/view/js/mod_admin.js b/view/js/mod_admin.js
new file mode 100644
index 000000000..aad2ca902
--- /dev/null
+++ b/view/js/mod_admin.js
@@ -0,0 +1,3 @@
+$(document).ready(function() {
+ $('form').areYouSure(); // Warn user about unsaved settings
+});
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 fabf24e95..15b768929 100644
--- a/view/js/mod_connedit.js
+++ b/view/js/mod_connedit.js
@@ -1,7 +1,7 @@
function abook_perms_msg() {
$('.abook-permschange').show();
- $('.abook-permschange').html(aStr['permschange']);
+// $('.abook-permschange').html(aStr['permschange']);
$('.abook-permssave').show();
}
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_new_channel.js b/view/js/mod_new_channel.js
index 492267ff9..c4d5408f2 100644
--- a/view/js/mod_new_channel.js
+++ b/view/js/mod_new_channel.js
@@ -1,5 +1,5 @@
$(document).ready(function() {
-// $("#privacy-role-select").sSelect();
+// $("#id_permissions_role").sSelect();
$("#newchannel-name").blur(function() {
$("#name-spinner").spin('small');
var zreg_name = $("#newchannel-name").val();
diff --git a/view/js/mod_photos.js b/view/js/mod_photos.js
index 8b7706f16..4c724c5e1 100644
--- a/view/js/mod_photos.js
+++ b/view/js/mod_photos.js
@@ -2,29 +2,11 @@
var ispublic = aStr['everybody'];
$(document).ready(function() {
-
- $("a#photos-upload-perms-menu").colorbox({
- 'inline' : true,
- 'transition' : 'elastic'
- });
-
- $("a#settings-default-perms-menu").colorbox({
- 'inline' : true,
- 'transition' : 'elastic'
- });
-
- 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.replace(' ','_')); // TODO: Get rid of underscore
+ });
+ });
$('#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_profiles.js b/view/js/mod_profiles.js
new file mode 100644
index 000000000..aad2ca902
--- /dev/null
+++ b/view/js/mod_profiles.js
@@ -0,0 +1,3 @@
+$(document).ready(function() {
+ $('form').areYouSure(); // Warn user about unsaved settings
+});
diff --git a/view/js/mod_settings.js b/view/js/mod_settings.js
index 87c8c3a2b..0db0dd165 100644
--- a/view/js/mod_settings.js
+++ b/view/js/mod_settings.js
@@ -2,14 +2,15 @@
var ispublic = aStr['everybody'] ;
$(document).ready(function() {
+ $('form').areYouSure(); // Warn user about unsaved settings
$("a#settings-default-perms-menu").colorbox({
'inline' : true,
'transition' : 'elastic'
});
- $("#privacy-role-select").change(function() {
- var role = $("#privacy-role-select").val();
+ $("#id_permissions_role").change(function() {
+ var role = $("#id_permissions_role").val();
if(role == 'custom')
$('#advanced-perm').show();
else
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);
+ });
+ });
});