       if $scope.csWizardOptions.events[event]
         # Call the callback if it's set in the wizard options
         $scope.csWizardOptions.events[event](resource)
-    
+
     # If wizard has done it's job (no panels are open anymore) notify about finish as well
     if $scope.panelStack.length == 0
       $scope.$emit 'wizard-finished'

        $scope.$emit 'wizard-error', resource.data
        if $scope.csWizardOptions.events['wizard-error'] && $scope.panelStack.length == 1
          $scope.csWizardOptions.events['wizard-error'](resource)
        
    $scope.$on 'transitioned', (event, child, parent) ->
      if child && parent 
        if $scope.csWizardOptions.transitions
          if transitions = ($scope.csWizardOptions.transitions[parent.type] && $scope.csWizardOptions.transitions[parent.type][child.type])
            for transition in transitions
              transition(child, parent)
            
    keyPressed = (keyEvent) ->
      # Cancel form on escape
      if keyEvent.keyCode == 27

          panelDescriptor.directive = override.directive

      $scope.panelStack.push panelDescriptor

      # Hack to force induce mouse move event handling on creation
      # (otherwise the new div is created, you move mouse and there's a glitch)
      $scope.panelHover(panelIndex+1)

      if $scope.panelNumberCallback
        $scope.panelNumberCallback($scope.panelStack.length)

