code: function getNearestSafeIndex (newIndex) {
      if (newIndex === -1) return -1;
      var maxOffset = Math.max(ctrl.tabs.length - newIndex, newIndex),
          i, tab;
      for (i = 0; i <= maxOffset; i++) {
        tab = ctrl.tabs[ newIndex + i ];
        if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
        tab = ctrl.tabs[ newIndex - i ];
        if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
      }
      return newIndex;
    }
docs: Finds the nearest tab index that is available. This is primarily used for when the active
  tab is removed.
  @param newIndex
  @returns {*}