diff options
Diffstat (limited to 'view/js')
-rw-r--r-- | view/js/autocomplete.js | 143 | ||||
-rw-r--r-- | view/js/main.js | 29 | ||||
-rw-r--r-- | view/js/mod_connections.js | 11 | ||||
-rw-r--r-- | view/js/mod_mail.js | 3 | ||||
-rw-r--r-- | view/js/mod_new_channel.js | 95 |
5 files changed, 188 insertions, 93 deletions
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index be632a07e..54eb03e13 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -7,21 +7,6 @@ function contact_search(term, callback, backend_url, type, extra_channels, spine if(spinelement) { $(spinelement).show(); } - // 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(var t in contact_search.cache[bt]) { - if(lterm.indexOf(t) >= 0) { // A more broad search has been performed already, so use those results - $(spinelement).hide(); - // Filter old results locally - var matching = contact_search.cache[bt][t].filter(function (x) { return (x.name.toLowerCase().indexOf(lterm) >= 0 || (typeof x.nick !== 'undefined' && x.nick.toLowerCase().indexOf(lterm) >= 0)); }); // Need to check that nick exists because groups don't have one - matching.unshift({taggable:false, text: term, replace: term}); - setTimeout(function() { callback(matching); } , 1); // Use "pseudo-thread" to avoid some problems - return; - } - } var postdata = { start:0, @@ -38,12 +23,7 @@ function contact_search(term, callback, backend_url, type, extra_channels, spine url: backend_url, 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 -1 < data.count) { - contact_search.cache[bt][lterm] = data.items; - } + success: function(data) { var items = data.items.slice(0); items.unshift({taggable:false, text: term, replace: term}); callback(items); @@ -60,7 +40,7 @@ function contact_format(item) { var desc = ((item.label) ? item.nick + ' ' + item.label : item.nick); if(typeof desc === 'undefined') desc = ''; if(desc) desc = ' ('+desc+')'; - return "<div class='{0} dropdown-item dropdown-notification clearfix' title='{4}'><img class='menu-img-2' src='{1}'><span class='contactname'>{2}</span><span class='dropdown-sub-text'>{3}</span></div>".format(item.taggable, item.photo, item.name, desc, typeof(item.link) !== 'undefined' ? item.link : desc.replace('(','').replace(')','')); + return "<div class='{0} dropdown-item dropdown-notification clearfix' title='{4}'><img class='menu-img-2' src='{1}'><span class='contactname'>{2}</span><span class='dropdown-sub-text'>{4}</span></div>".format(item.taggable, item.photo, item.name, desc, typeof(item.link) !== 'undefined' ? item.link : desc.replace('(','').replace(')','')); } else return "<div>" + item.text + "</div>"; @@ -84,13 +64,8 @@ function editor_replace(item) { } // $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. - // 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 + ' '; + return '$1$2{' + item.link + '} '; } function basic_replace(item) { @@ -107,11 +82,6 @@ function trim_replace(item) { return '$1'+item.name; } - -function submit_form(e) { - $(e).parents('form').submit(); -} - function getWord(text, caretPos) { var index = text.indexOf(caretPos); var postText = text.substring(caretPos, caretPos+13); @@ -185,12 +155,17 @@ function string2bb(element) { */ (function( $ ) { $.fn.editor_autocomplete = function(backend_url, extra_channels) { + + if(! this.length) + return; + if (typeof extra_channels === 'undefined') extra_channels = false; // Autocomplete contacts contacts = { - match: /(^|\s)(@\!*)([^ \n]+)$/, + match: /(^|\s)(@\!*)([^ \n]{2,})$/, index: 3, + cache: true, search: function(term, callback) { contact_search(term, callback, backend_url, 'c', extra_channels, spinelement=false); }, replace: editor_replace, template: contact_format @@ -198,8 +173,9 @@ function string2bb(element) { // Autocomplete forums forums = { - match: /(^|\s)(\!\!*)([^ \n]+)$/, + match: /(^|\s)(\!\!*)([^ \n]{2,})$/, index: 3, + cache: true, search: function(term, callback) { contact_search(term, callback, backend_url, 'f', extra_channels, spinelement=false); }, replace: editor_replace, template: contact_format @@ -210,6 +186,7 @@ function string2bb(element) { tags = { match: /(^|\s)(\#)([^ \n]{2,})$/, index: 3, + cache: true, search: function(term, callback) { $.getJSON('/hashtags/' + '$f=&t=' + term).done(function(data) { callback($.map(data, function(entry) { return entry.text.toLowerCase().indexOf(term.toLowerCase()) === 0 ? entry : null; })); }); }, replace: function(item) { return "$1$2" + item.text + ' '; }, context: function(text) { return text.toLowerCase(); }, @@ -220,13 +197,23 @@ function string2bb(element) { smilies = { match: /(^|\s)(:[a-z_:]{2,})$/, index: 2, + cache: true, search: function(term, callback) { $.getJSON('/smilies/json').done(function(data) { callback($.map(data, function(entry) { return entry.text.indexOf(term) === 0 ? entry : null; })); }); }, //template: function(item) { return item.icon + item.text; }, replace: function(item) { return "$1" + item.text + ' '; }, template: smiley_format }; this.attr('autocomplete','off'); - this.textcomplete([contacts,forums,smilies,tags], {className:'acpopup', zIndex:1020}); + + var Textarea = Textcomplete.editors.Textarea; + + $(this).each(function() { + var editor = new Textarea(this); + var textcomplete = new Textcomplete(editor); + textcomplete.register([contacts,forums,smilies,tags], {className:'acpopup', zIndex:1020}); + }); + + }; })( jQuery ); @@ -235,10 +222,15 @@ function string2bb(element) { */ (function( $ ) { $.fn.search_autocomplete = function(backend_url) { + + if(! this.length) + return; + // Autocomplete contacts contacts = { - match: /(^@)([^\n]{3,})$/, + match: /(^@)([^\n]{2,})$/, index: 2, + cache: true, search: function(term, callback) { contact_search(term, callback, backend_url, 'x', [], spinelement='#nav-search-spinner'); }, replace: basic_replace, template: contact_format, @@ -246,8 +238,9 @@ function string2bb(element) { // Autocomplete forums forums = { - match: /(^\!)([^\n]{3,})$/, + match: /(^\!)([^\n]{2,})$/, index: 2, + cache: true, search: function(term, callback) { contact_search(term, callback, backend_url, 'f', [], spinelement='#nav-search-spinner'); }, replace: basic_replace, template: contact_format @@ -255,8 +248,9 @@ function string2bb(element) { // Autocomplete hashtags tags = { - match: /(^\#)([^ \n]{3,})$/, + match: /(^\#)([^ \n]{2,})$/, index: 2, + cache: true, search: function(term, callback) { $.getJSON('/hashtags/' + '$f=&t=' + term).done(function(data) { callback($.map(data, function(entry) { return entry.text.toLowerCase().indexOf(term.toLowerCase()) === 0 ? entry : null; })); }); }, replace: function(item) { return "$1" + item.text + ' '; }, context: function(text) { return text.toLowerCase(); }, @@ -264,65 +258,105 @@ function string2bb(element) { }; this.attr('autocomplete', 'off'); - var a = this.textcomplete([contacts,forums,tags], {className:'acpopup', maxCount:100, zIndex: 1020, appendTo:'nav'}); - a.on('textComplete:select', function(e, value, strategy) { submit_form(this); }); + + var textcomplete; + var Textarea = Textcomplete.editors.Textarea; + + $(this).each(function() { + var editor = new Textarea(this); + textcomplete = new Textcomplete(editor); + textcomplete.register([contacts,forums,tags], {className:'acpopup', maxCount:100, zIndex: 1020, appendTo:'nav'}); + }); + + textcomplete.on('selected', function() { this.editor.el.form.submit(); }); + }; })( jQuery ); (function( $ ) { $.fn.contact_autocomplete = function(backend_url, typ, autosubmit, onselect) { + + if(! this.length) + return; + if(typeof typ === 'undefined') typ = ''; if(typeof autosubmit === 'undefined') autosubmit = false; // Autocomplete contacts contacts = { - match: /(^)([^\n]+)$/, + match: /(^)([^\n]{2,})$/, index: 2, + cache: true, search: function(term, callback) { contact_search(term, callback, backend_url, typ,[], spinelement=false); }, replace: basic_replace, template: contact_format, }; this.attr('autocomplete','off'); - var a = this.textcomplete([contacts], {className:'acpopup', zIndex:1020}); + + var textcomplete; + var Textarea = Textcomplete.editors.Textarea; + + $(this).each(function() { + var editor = new Textarea(this); + textcomplete = new Textcomplete(editor); + textcomplete.register([contacts], {className:'acpopup', zIndex:1020}); + }); if(autosubmit) - a.on('textComplete:select', function(e,value,strategy) { submit_form(this); }); + textcomplete.on('selected', function() { this.editor.el.form.submit(); }); if(typeof onselect !== 'undefined') - a.on('textComplete:select', function(e, value, strategy) { onselect(value); }); + textcomplete.on('select', function() { var item = this.dropdown.getActiveItem(); onselect(item.searchResult.data); }); }; })( jQuery ); (function( $ ) { $.fn.name_autocomplete = function(backend_url, typ, autosubmit, onselect) { + + if(! this.length) + return; + if(typeof typ === 'undefined') typ = ''; if(typeof autosubmit === 'undefined') autosubmit = false; // Autocomplete contacts names = { - match: /(^)([^\n]+)$/, + match: /(^)([^\n]{2,})$/, index: 2, + cache: true, search: function(term, callback) { contact_search(term, callback, backend_url, typ,[], spinelement=false); }, replace: trim_replace, template: contact_format, }; this.attr('autocomplete','off'); - var a = this.textcomplete([names], {className:'acpopup', zIndex:1020}); + + var textcomplete; + var Textarea = Textcomplete.editors.Textarea; + + $(this).each(function() { + var editor = new Textarea(this); + textcomplete = new Textcomplete(editor); + textcomplete.register([names], {className:'acpopup', zIndex:1020}); + }); if(autosubmit) - a.on('textComplete:select', function(e,value,strategy) { submit_form(this); }); + textcomplete.on('selected', function() { this.editor.el.form.submit(); }); if(typeof onselect !== 'undefined') - a.on('textComplete:select', function(e, value, strategy) { onselect(value); }); + textcomplete.on('select', function() { var item = this.dropdown.getActiveItem(); onselect(item.searchResult.data); }); + }; })( jQuery ); (function( $ ) { $.fn.bbco_autocomplete = function(type) { + if(! this.length) + return; + if(type=='bbcode') { var open_close_elements = ['bold', 'italic', 'underline', 'overline', 'strike', 'superscript', 'subscript', 'quote', 'code', 'open', 'spoiler', 'map', 'nobb', 'list', 'checklist', 'ul', 'ol', 'dl', 'li', 'table', 'tr', 'th', 'td', 'center', 'color', 'font', 'size', 'zrl', 'zmg', 'rpost', 'qr', 'observer', 'observer.language','embed', 'highlight', 'url', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; var open_elements = ['observer.baseurl', 'observer.address', 'observer.photo', 'observer.name', 'observer.webname', 'observer.url', '*', 'hr', ]; @@ -380,11 +414,16 @@ function string2bb(element) { }; this.attr('autocomplete','off'); - var a = this.textcomplete([bbco], {className:'acpopup', zIndex:1020}); - a.on('textComplete:select', function(e, value, strategy) { value; }); + var Textarea = Textcomplete.editors.Textarea; + + $(this).each(function() { + var editor = new Textarea(this); + var textcomplete = new Textcomplete(editor); + textcomplete.register([bbco], {className:'acpopup', zIndex:1020}); + }); - a.keypress(function(e){ + this.keypress(function(e){ if (e.keyCode == 13) { var x = listNewLineAutocomplete(this.id); if(x) { diff --git a/view/js/main.js b/view/js/main.js index acb9b462f..17f94dd16 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -62,6 +62,9 @@ $(document).ready(function() { numbers : aStr['t17'], }; + //mod_mail only + $(".mail-conv-detail .autotime").timeago(); + savedTitle = document.title; updateInit(); @@ -420,6 +423,14 @@ function notificationsUpdate(cached_data) { // Put the object into storage sessionStorage.setItem('notifications_cache', JSON.stringify(data)); + var fnotifs = []; + if(data.forums) { + $.each(data.forums_sub, function() { + fnotifs.push(this); + }); + handleNotificationsItems('forums', fnotifs); + } + if(data.invalid == 1) { window.location.href=window.location.href; } @@ -451,7 +462,7 @@ function notificationsUpdate(cached_data) { } function handleNotifications(data) { - if(data.network || data.home || data.intros || data.register || data.mail || data.all_events || data.notify || data.files || data.pubs) { + if(data.network || data.home || data.intros || data.register || data.mail || data.all_events || data.notify || data.files || data.pubs || data.forums) { $('.notifications-btn').css('opacity', 1); $('#no_notifications').hide(); } @@ -495,13 +506,13 @@ function handleNotifications(data) { } function handleNotificationsItems(notifyType, data) { - var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html()); + var notifications_tpl = ((notifyType == 'forums') ? unescape($("#nav-notifications-forums-template[rel=template]").html()) : unescape($("#nav-notifications-template[rel=template]").html())); var notify_menu = $("#nav-" + notifyType + "-menu"); notify_menu.html(''); $(data).each(function() { - html = notifications_tpl.format(this.notify_link,this.photo,this.name,this.message,this.when,this.hclass,this.b64mid,this.notify_id,this.thread_top); + html = notifications_tpl.format(this.notify_link,this.photo,this.name,this.message,this.when,this.hclass,this.b64mid,this.notify_id,this.thread_top,this.unseen,this.private_forum); notify_menu.append(html); }); @@ -812,6 +823,15 @@ function updateInit() { if (initialLoad && (sessionStorage.getItem('notifications_cache') !== null)) { var cached_data = JSON.parse(sessionStorage.getItem('notifications_cache')); notificationsUpdate(cached_data); + + var fnotifs = []; + if(cached_data.forums) { + $.each(cached_data.forums_sub, function() { + fnotifs.push(this); + }); + handleNotificationsItems('forums', fnotifs); + } + } if(! src) { @@ -1022,6 +1042,7 @@ function loadNotificationItems(notifyType) { } console.log('updating ' + notifyType + ' notifications...'); + $.get(pingExCmd, function(data) { if(data.invalid == 1) { window.location.href=window.location.href; @@ -1057,7 +1078,9 @@ function doprofilelike(ident, verb) { $.get('like/' + ident + '?verb=' + verb, function() { window.location.href=window.location.href; }); } + function dropItem(url, object) { + var confirm = confirmDelete(); if(confirm) { $('body').css('cursor', 'wait'); diff --git a/view/js/mod_connections.js b/view/js/mod_connections.js index 68add4eed..db18e078d 100644 --- a/view/js/mod_connections.js +++ b/view/js/mod_connections.js @@ -3,14 +3,3 @@ $(document).ready(function() { $(".autotime").timeago(); }); -$("#contacts-search").keyup(function(event){ - if(event.keyCode == 13){ - $("#contacts-search").click(); - } -}); -$(".autocomplete-w1 .selected").keyup(function(event){ - if(event.keyCode == 13){ - $("#contacts-search").click(); - } -}); - diff --git a/view/js/mod_mail.js b/view/js/mod_mail.js index 15a45519b..917e5414c 100644 --- a/view/js/mod_mail.js +++ b/view/js/mod_mail.js @@ -2,7 +2,6 @@ $(document).ready(function() { $("#recip").name_autocomplete(baseurl + '/acl', 'm', false, function(data) { $("#recip-complete").val(data.xid); }); - $(".autotime").timeago() $('#prvmail-text').bbco_autocomplete('bbcode'); - $("#prvmail-text").editor_autocomplete(baseurl+"/acl"); + $("#prvmail-text").editor_autocomplete(baseurl+"/acl"); }); diff --git a/view/js/mod_new_channel.js b/view/js/mod_new_channel.js index e78de2596..10a94796c 100644 --- a/view/js/mod_new_channel.js +++ b/view/js/mod_new_channel.js @@ -1,43 +1,88 @@ $(document).ready(function() { - - $("#newchannel-submit-button").attr('disabled','disabled'); + $("#id_name").focus(); $("#id_name").blur(function() { - $("#name-spinner").show(); - var zreg_name = $("#id_name").val(); - $.get("new_channel/autofill.json?f=&name=" + encodeURIComponent(zreg_name),function(data) { - $("#id_nickname").val(data); - if(data.error) { - $("#help_name").html(""); - zFormError("#help_name",data.error); - } - else { - $("#newchannel-submit-button").removeAttr('disabled'); - } - $("#name-spinner").hide(); - }); + if(validate_name()) { + var zreg_name = $("#id_name").val(); + $("#name_help_loading").show(); + $("#name_help_text").hide(); + $.get("new_channel/autofill.json?f=&name=" + encodeURIComponent(zreg_name),function(data) { + $("#id_nickname").val(data); + $("#id_nickname").addClass('is-validated'); + $("#name_help_loading").hide(); + $("#name_help_text").show(); + }); + } }); - $("#id_nickname").click(function() { - $("#newchannel-submit-button").attr('disabled','disabled'); + $("#id_nickname").on('input', function() { + $("#id_nickname").removeClass('is-validated'); }); - }); + $("#newchannel-form").on('submit', function(event) { + if(! validate_name()) { + $("#id_name").focus() + return false; + } + + if(! validate_channel()) { + $("#id_nickname").focus() + return false; + } + + if(! $("#id_nickname").hasClass('is-validated')) { + event.preventDefault(); + } + }); + }); function validate_channel() { - $("#nick-spinner").show(); + if($("#id_nickname").hasClass('is-validated')) + return true; + + $("#nick_help_loading").show(); + $("#nick_help_text").hide(); + var zreg_name = $("#id_name").val(); var zreg_nick = $("#id_nickname").val(); - $.get("new_channel/checkaddr.json?f=&nick=" + encodeURIComponent(zreg_nick),function(data) { + $.get("new_channel/checkaddr.json?f=&nick=" + encodeURIComponent(zreg_nick) + '&name=' + encodeURIComponent(zreg_name),function(data) { $("#id_nickname").val(data); - if(data.error) { - $("#help_nickname").html(""); - zFormError("#help_nickname",data.error); + if(data !== zreg_nick) { + $("#id_nickname").addClass('is-validated'); + $("#help_nickname").addClass('text-danger').removeClass('text-muted'); + $("#help_nickname").html(aStr['nick_invld1'] + data + aStr['nick_invld2']); + $("#id_nickname").focus(); } else { - $("#newchannel-submit-button").removeAttr('disabled'); + $("#id_nickname").addClass('is-validated'); + $("#help_nickname").addClass('text-success').removeClass('text-muted').removeClass('text-danger'); + $("#help_nickname").html(aStr['nick_valid']); } - $("#nick-spinner").hide(); + $("#nick_help_loading").hide(); + $("#nick_help_text").show(); + }); + return true; + + } + + function validate_name() { + if($("#id_name").hasClass('is-validated')) + return true; + + var verbs = [ aStr['lovely'], aStr['wonderful'], aStr['fantastic'], aStr['great'] ]; + var verb = verbs[Math.floor((Math.random() * 4) + 0)]; + if(! $("#id_name").val()) { + $("#id_name").focus(); + $("#help_name").addClass('text-danger').removeClass('text-muted'); + $("#help_name").html(aStr['name_empty']); + return false; + } + else { + $("#help_name").addClass('text-success').removeClass('text-muted').removeClass('text-danger'); + $("#help_name").html(aStr['name_ok1'] + verb + aStr['name_ok2']); + $("#id_name").addClass('is-validated'); + return true; + } } |