diff --git a/data/web/js/site/mailbox.js b/data/web/js/site/mailbox.js index d7fca848d..3ddeea944 100644 --- a/data/web/js/site/mailbox.js +++ b/data/web/js/site/mailbox.js @@ -1458,30 +1458,37 @@ jQuery(function($){ } function draw_bcc_table() { $.get("/api/v1/get/bcc-destination-options", function(data){ + var optgroup = ""; // Domains - var optgroup = ""; - $.each(data.domains, function(index, domain){ - optgroup += ""; - }); - optgroup += ""; - $('#bcc-local-dest').append(optgroup); - // Alias domains - var optgroup = ""; - $.each(data.alias_domains, function(index, alias_domain){ - optgroup += ""; - }); - optgroup += "" - $('#bcc-local-dest').append(optgroup); - // Mailboxes and aliases - $.each(data.mailboxes, function(mailbox, aliases){ - var optgroup = ""; - $.each(aliases, function(index, alias){ - optgroup += ""; + if (data.domains && data.domains.length > 0) { + optgroup = ""; + $.each(data.domains, function(index, domain){ + optgroup += ""; }); optgroup += ""; $('#bcc-local-dest').append(optgroup); - }); - // Finish + } + // Alias domains + if (data.alias_domains && data.alias_domains.length > 0) { + optgroup = ""; + $.each(data.alias_domains, function(index, alias_domain){ + optgroup += ""; + }); + optgroup += "" + $('#bcc-local-dest').append(optgroup); + } + // Mailboxes and aliases + if (data.mailboxes && Object.keys(data.mailboxes).length > 0) { + $.each(data.mailboxes, function(mailbox, aliases){ + optgroup = ""; + $.each(aliases, function(index, alias){ + optgroup += ""; + }); + optgroup += ""; + $('#bcc-local-dest').append(optgroup); + }); + } + // Recreate picker $('#bcc-local-dest').selectpicker('refresh'); }); @@ -2326,16 +2333,19 @@ jQuery(function($){ // detect element visibility changes function onVisible(element, callback) { $(document).ready(function() { - element_object = document.querySelector(element); + let element_object = document.querySelector(element); if (element_object === null) return; - new IntersectionObserver((entries, observer) => { + let observer = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if(entry.intersectionRatio > 0) { callback(element_object); + observer.unobserve(element_object); } }); - }).observe(element_object); + }) + + observer.observe(element_object); }); }