From 3dd520c089923a07220dc0c9b42199a6a57c4c7a Mon Sep 17 00:00:00 2001 From: Jonas Schulte Date: Tue, 18 Aug 2015 14:03:43 +0200 Subject: [PATCH] (#10) Added comment and refactored scrollWidgetIntoview function --- ax-messages-widget.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ax-messages-widget.js b/ax-messages-widget.js index bf13544..a65b96e 100644 --- a/ax-messages-widget.js +++ b/ax-messages-widget.js @@ -11,7 +11,7 @@ define( [ 'use strict'; var DID_ENCOUNTER_ERROR_RESOURCE = '_DID_ENCOUNTER_ERROR_RESOURCE'; - var EVENT_SCROLL_TO_MESSAGES = 'SCROLL_TO_MESSAGES'; + var EVENT_SCROLL_TO_MESSAGES = 'axMessagesWidget.scrollToMessages'; var levelMap = { BLANK: { weight: 0 }, @@ -297,11 +297,14 @@ define( [ //////////////////////////////////////////////////////////////////////////////////////////////////////// function scrollWidgetIntoView() { - if( $scope.features.autoScroll.enabled ) { - setTimeout( function() { - $scope.$broadcast( EVENT_SCROLL_TO_MESSAGES ); - }, 0 ); + if( !$scope.features.autoScroll.enabled ) { + return; } + // in case the are no messages yet, we set a timeout to ensure that the directive + // axMessagesAutoScroll has registered to the event and is not still blocked by the ngIf + setTimeout( function() { + $scope.$broadcast( EVENT_SCROLL_TO_MESSAGES ); + }, 0 ); } }