/**
 * focusOn - Focuses an input on scope event
 *
 * @note depends on jQuery
 *
 * @example
 *   <input focus-on="someEventName">
 *   or
 *   <input focus-on="focus-row-{{$index}}">
 *   or
 *   <p focus-on="anotherEvent"></p>
 *   ...
 *   $scope.$broadcast('someEventName');
 *   $scope.$broadcast('focus-row-2');
 *   $scope.$broadcast('anotherEvent');
 *
 */
 angular.module('ts.utils').directive('focusOn', function($window){
  return {
    link: function($scope, $element, $attrs) {
      var listener = angular.noop;
      $attrs.$observe('focusOn', function(newVal){
        // Stop listening to old event name
        listener();
        // Listen to new event name
        listener = $scope.$on(newVal, function(speed = 1000){
          // Center element on screen
          var offset = $element.offset().top - ( $window.innerHeight / 2 ) - ( $element.height() / 2 );
          $('body').animate({ scrollTop: offset }, {
            speed: speed,
            complete: function() {
              // Focus element (if input)
              $element[0].focus();
            }
          });
        });
      });
    }
  };
});

@@ -785,102 +785,524 @@
     
-var offset = $element.offset().top - ( $window.innerHeight / 2 ) - ( $element.height() / 2 );%0A
+if($element.parents('.reveal-modal').length) %7B%0A            var targetWindow = $element.parents('.reveal-modal .content');%0A            targetWindow.animate(%7B scrollTop: $element.offset().top - targetWindow.offset().top + targetWindow.scrollTop() %7D, %7B%0A              speed: speed,%0A              complete: function complete() %7B%0A                // Focus element (if input)%0A                $element%5B0%5D.focus();%0A              %7D%0A            %7D);%0A          %7D%0A          else %7B%0A            var offset = $element.offset().top;%0A  
     
@@ -1346,24 +1346,26 @@
 offset %7D, %7B%0A
+  
             
@@ -1382,32 +1382,34 @@
 ed,%0A            
+  
 complete: functi
@@ -1410,21 +1410,32 @@
 function
+ complete
 () %7B%0A
+  
         
@@ -1474,32 +1474,34 @@
 )%0A              
+  
 $element%5B0%5D.focu
@@ -1509,34 +1509,38 @@
 ();%0A            
+ 
+ 
 %7D%0A
+  
           %7D);%0A  
@@ -1529,32 +1529,44 @@
             %7D);%0A
+          %7D%0A
         %7D);%0A    

make focus directive work in modals