diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index b449e9f23..dc639501c 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1107,6 +1107,25 @@ function constructElementContentsJson(el) { return jsonEl; } +/** + * Binds listeners to sidebar + * that truncate long strings + */ +function initializeReportSidebartruncation() { + var target = document.getElementById("report-sidebar-tree"); + var observer = new MutationObserver( + function() { + $.each($("a.report-nav-link"), + function(){ + truncateLongString($(this), 30); + }); + } + ); + var config = { childList: true }; + + observer.observe(target, config); +} + /* Initialize the first-time demo tutorial if needed. */ function initializeTutorial() { if (showTutorial()) { @@ -1177,6 +1196,7 @@ function showTutorial() { */ initializeReportElements($(REPORT_CONTENT)); +initializeReportSidebartruncation(); initializeGlobalReportSort(); initializePrintPopup(); initializeSaveToPdf(); @@ -1185,16 +1205,3 @@ initializeAddContentsModal(); initializeSidebarNavigation(); initializeUnsavedWorkDialog(); initializeTutorial(); - -$(document).change(function(){ - setTimeout(function(){ - $(".report-nav-link").each( function(){ - truncateLongString( $(this), 30); - }); - }, 1000); -}); -$(document).ready(function(){ - $(".report-nav-link").each( function(){ - truncateLongString( $(this), 30); - }); -}); diff --git a/app/assets/javascripts/sitewide/string_utils.js b/app/assets/javascripts/sitewide/string_utils.js index 5b63fb1fb..b1489bdc2 100644 --- a/app/assets/javascripts/sitewide/string_utils.js +++ b/app/assets/javascripts/sitewide/string_utils.js @@ -17,7 +17,12 @@ function truncateLongString( el, chars ) { break; } } - el.html(html.outerHTML + newText + '...' ); + + if ( html ) { + el.html(html.outerHTML + newText + '...' ); + } else { + el.html(newText + '...' ); + } } }