From e1d871dcdb441c4dd33940ce80279ca9698f4f62 Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 14 Sep 2016 11:11:35 +0200 Subject: [PATCH 1/2] clear undefind from experiment name and refactor sidebar in reports [fixes SCI-448] --- app/assets/javascripts/reports/new.js | 35 ++++++++++++------- .../javascripts/sitewide/string_utils.js | 7 +++- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index b449e9f23..87372ea57 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1107,6 +1107,27 @@ 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 = { attributes: true, + childList: true, + characterData: true }; + + observer.observe(target, config); +} + /* Initialize the first-time demo tutorial if needed. */ function initializeTutorial() { if (showTutorial()) { @@ -1177,6 +1198,7 @@ function showTutorial() { */ initializeReportElements($(REPORT_CONTENT)); +initializeReportSidebartruncation(); initializeGlobalReportSort(); initializePrintPopup(); initializeSaveToPdf(); @@ -1185,16 +1207,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 + '...' ); + } } } From c4fabdb67aa22c470863a0f132326ec9796a0833 Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 14 Sep 2016 11:16:42 +0200 Subject: [PATCH 2/2] clean unneeded Observer configurations --- app/assets/javascripts/reports/new.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 87372ea57..dc639501c 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1121,9 +1121,7 @@ function initializeReportSidebartruncation() { }); } ); - var config = { attributes: true, - childList: true, - characterData: true }; + var config = { childList: true }; observer.observe(target, config); }