From 63c76eae0c87a07e5ee0fc7b88a3e6c56bba6969 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 26 Apr 2018 15:40:59 +0200 Subject: a better way to deal with js errors in autocomplete plugins if the object is not available --- view/js/autocomplete.js | 19 +++++++++++++++++++ view/js/mod_network.js | 3 +-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 7bbcd6451..5fbdab27b 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -180,6 +180,10 @@ 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 @@ -240,6 +244,10 @@ function string2bb(element) { */ (function( $ ) { $.fn.search_autocomplete = function(backend_url) { + + if(! this.length) + return; + // Autocomplete contacts contacts = { match: /(^@)([^\n]{3,})$/, @@ -285,6 +293,10 @@ function string2bb(element) { (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; @@ -317,6 +329,10 @@ function string2bb(element) { (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; @@ -349,6 +365,9 @@ function string2bb(element) { (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', ]; diff --git a/view/js/mod_network.js b/view/js/mod_network.js index 22a5e9ba6..2899bbacd 100644 --- a/view/js/mod_network.js +++ b/view/js/mod_network.js @@ -1,5 +1,4 @@ $(document).ready(function() { - if($("#search-text").length) - $("#search-text").contact_autocomplete(baseurl + '/search_ac','',true); + $("#search-text").contact_autocomplete(baseurl + '/search_ac','',true); }); -- cgit v1.2.3