       tool: '=tool'
     link: (scope, element, attrs) ->
 
-      ctrl = "#{$window.location}/#{scope.tool.controllerURI}"
-      tmpl = "#{$window.location}/#{scope.tool.templateURI}"
+      scope.$watch 'tool.controllerURI', ->
+        if scope.tool
 
-      require [ctrl, "text!#{ tmpl }"], (controller, template) ->
+          ctrl = $window.location.origin + scope.tool.controllerURI
+          tmpl = $window.location.origin + scope.tool.templateURI
 
-        $injector.invoke controller, this, {'$scope': scope}
+          require [ctrl, "text!#{ tmpl }"], (controller, template) ->
 
-        element.html(template)
-        $compile(element.contents())(scope)
+            $injector.invoke controller, this, {'$scope': scope}
 
-        scope.$apply()
+            element.html(template)
+            $compile(element.contents())(scope)
+
+            scope.$apply()
 
 


  doesntIntersectWith = (p1, q1) -> ({p, q}) -> not lines.intersects p1, q1, p, q

  Directives.directive 'currentStep', Array '$window', ($window) ->
    restrict: 'C'
    scope:
      tool: '=tool'


    link: (scope, element, attrs) ->

      scope.$watch 'tool.expandable', (expandable) ->
        if expandable
          doResize = ->
            margin = 38 # HARDCODED! TODO! CALCULATE!
            offsets = getOffsets(document, 'starting-point')
            maxx = L.max offsets.map (o) -> o.left + o.width
            maxy = L.max offsets.map (o) -> o.top + o.height
            topBars = getTopBars offsets
            ystep = element[0].offsetHeight
            p1 =
              x: element[0].offsetLeft
              y: element[0].offsetTop + 1 # Don't get intersects with own top bar.
            q1 =
              x: p1.x + element[0].offsetWidth
              y: p1.y + element[0].offsetHeight

            factor = 1

            while factor < 3 and (q1.y + ystep) <= maxy
              q1.y += ystep + margin
              if L.every topBars, doesntIntersectWith p1, q1
                factor += 1

            if factor > 1 and panelBody = element[0].querySelector('.panel-body')
              totalHeight = ystep * factor - margin
              panelBody.style.height = "#{ totalHeight - (p1.y - panelBody.offsetTop) }px"
              element.addClass 'expanded'

          $window.addEventListener 'resize', ->
            element[0].querySelector('.panel-body')?.style.height = null
            element.removeClass 'expanded'
            setTimeout doResize, 10

          setTimeout doResize, 10

  Directives.directive 'nativeTool', ($window, $compile, $injector) ->
    restrict: 'E'
