src/vTabs/directives/vPages.js
function vPagesDirectiveController ($scope) {
  var ctrl = this;

  $scope.pages = [];

  ctrl.getPagesId = function getPagesId () {
    return $scope.id;
  };

  ctrl.getPageByIndex = function (index) {
    return $scope.pages[index];
  };

  ctrl.getPageIndex = function (page) {
    return $scope.pages.indexOf(page);
  };

  ctrl.getPageIndexById = function getPageIndexById (id) {
    var length = $scope.pages.length,
        index = null;

    for (var i = 0; i < length; i++) {
      var iteratedPage = $scope.pages[i];
      if (iteratedPage.id && iteratedPage.id === id) { index = i; }
    }

    return index;
  };

  ctrl.addPage = function (page) {
    $scope.pages.push(page);

    if ($scope.activeIndex === ctrl.getPageIndex(page)) {
      ctrl.activate(page);
    }
  };

  ctrl.next = function () {
    var newActiveIndex = $scope.activeIndex + 1;
    if (newActiveIndex > $scope.pages.length - 1) {
      newActiveIndex = 0;
    }

    $scope.activeIndex = newActiveIndex;
  };

  ctrl.previous = function () {
    var newActiveIndex = $scope.activeIndex - 1;
    if (newActiveIndex < 0) {
      newActiveIndex = $scope.pages.length - 1;
    }

    $scope.activeIndex = newActiveIndex;
  };

  ctrl.activate = function (pageToActivate) {
    if (!pageToActivate) { return; }

    if (!pageToActivate.isActive) {
      pageToActivate.isActive = true;

      angular.forEach($scope.pages, function (iteratedPage) {
        if (iteratedPage !== pageToActivate && iteratedPage.isActive) {
          iteratedPage.isActive = false;
        }
      });
    }
  };

  $scope.$watch('activeIndex', function (newValue, oldValue) {
    if (newValue === oldValue) { return; }

    var pageToActivate = ctrl.getPageByIndex(newValue);
    if (pageToActivate.isDisabled) {
      $scope.activeIndex = (angular.isDefined(oldValue)) ? oldValue : 0;
      return false;
    }

    ctrl.activate(pageToActivate);
  });

  // API
  $scope.internalControl = {
    next: function () {
      ctrl.next();
    },
    previous: function () {
      ctrl.previous();
    },
    activate: function (indexOrId) {
      if (angular.isString(indexOrId)) {
        $scope.activeIndex = ctrl.getPageIndexById(indexOrId);
      } else {
        $scope.activeIndex = indexOrId;
      }
    }
  };
}
function vPagesDirectiveController ($scope) {
  var ctrl = this;

  $scope.pages = [];

  ctrl.getPagesId = function getPagesId () {
    return $scope.id;
  };

  ctrl.getPageByIndex = function (index) {
    return $scope.pages[index];
  };

  ctrl.getPageIndex = function (page) {
    return $scope.pages.indexOf(page);
  };

  ctrl.getPageIndexById = function getPageIndexById (id) {
    var length = $scope.pages.length,
        index = null;

    for (var i = 0; i < length; i++) {
      var iteratedPage = $scope.pages[i];
      if (iteratedPage.id && iteratedPage.id === id) { index = i; }
    }

    return index;
  };

  ctrl.addPage = function (page) {
    $scope.pages.push(page);

    if ($scope.activeIndex === ctrl.getPageIndex(page)) {
      ctrl.activate(page);
    }
  };

  ctrl.next = function () {
    var newActiveIndex = $scope.activeIndex + 1;
    if (newActiveIndex > $scope.pages.length - 1) {
      newActiveIndex = 0;
    }

    $scope.activeIndex = newActiveIndex;
  };

  ctrl.previous = function () {
    var newActiveIndex = $scope.activeIndex - 1;
    if (newActiveIndex < 0) {
      newActiveIndex = $scope.pages.length - 1;
    }

    $scope.activeIndex = newActiveIndex;
  };

  ctrl.activate = function (pageToActivate) {
    if (!pageToActivate) { return; }

    if (!pageToActivate.isActive) {
      pageToActivate.isActive = true;

      angular.forEach($scope.pages, function (iteratedPage) {
        if (iteratedPage !== pageToActivate && iteratedPage.isActive) {
          iteratedPage.isActive = false;
        }
      });
    }
  };

  $scope.$watch('activeIndex', function (newValue, oldValue) {
    if (newValue === oldValue) { return; }

    var pageToActivate = ctrl.getPageByIndex(newValue);
    if (pageToActivate.isDisabled) {
      $scope.activeIndex = (angular.isDefined(oldValue)) ? oldValue : 0;
      return false;
    }

    ctrl.activate(pageToActivate);
  });

  // API
  $scope.internalControl = {
    next: function () {
      ctrl.next();
    },
    previous: function () {
      ctrl.previous();
    },
    activate: function (indexOrId) {
      if (angular.isString(indexOrId)) {
        $scope.activeIndex = ctrl.getPageIndexById(indexOrId);
      } else {
        $scope.activeIndex = indexOrId;
      }
    }
  };
}
function vPagesDirectiveController ( $scope ) { var ctrl = this ; $scope . pages = [ ] ; ctrl . getPagesId = function getPagesId ( ) { return $scope . id ; } ; ctrl . getPageByIndex = function ( index ) { return $scope . pages [ index ] ; } ; ctrl . getPageIndex = function ( page ) { return $scope . pages . indexOf ( page ) ; } ; ctrl . getPageIndexById = function getPageIndexById ( id ) { var length = $scope . pages . length , index = null ; for ( var i = 0 ; i < length ; i ++ ) { var iteratedPage = $scope . pages [ i ] ; if ( iteratedPage . id && iteratedPage . id === id ) { index = i ; } } return index ; } ; ctrl . addPage = function ( page ) { $scope . pages . push ( page ) ; if ( $scope . activeIndex === ctrl . getPageIndex ( page ) ) { ctrl . activate ( page ) ; } } ; ctrl . next = function ( ) { var newActiveIndex = $scope . activeIndex + 1 ; if ( newActiveIndex > $scope . pages . length - 1 ) { newActiveIndex = 0 ; } $scope . activeIndex = newActiveIndex ; } ; ctrl . previous = function ( ) { var newActiveIndex = $scope . activeIndex - 1 ; if ( newActiveIndex < 0 ) { newActiveIndex = $scope . pages . length - 1 ; } $scope . activeIndex = newActiveIndex ; } ; ctrl . activate = function ( pageToActivate ) { if ( ! pageToActivate ) { return ; } if ( ! pageToActivate . isActive ) { pageToActivate . isActive = true ; angular . forEach ( $scope . pages , function ( iteratedPage ) { if ( iteratedPage !== pageToActivate && iteratedPage . isActive ) { iteratedPage . isActive = false ; } } ) ; } } ; $scope . $watch ( 'activeIndex' , function ( newValue , oldValue ) { if ( newValue === oldValue ) { return ; } var pageToActivate = ctrl . getPageByIndex ( newValue ) ; if ( pageToActivate . isDisabled ) { $scope . activeIndex = ( angular . isDefined ( oldValue ) ) ? oldValue : 0 ; return false ; } ctrl . activate ( pageToActivate ) ; } ) ; // API $scope . internalControl = { next : function ( ) { ctrl . next ( ) ; } , previous : function ( ) { ctrl . previous ( ) ; } , activate : function ( indexOrId ) { if ( angular . isString ( indexOrId ) ) { $scope . activeIndex = ctrl . getPageIndexById ( indexOrId ) ; } else { $scope . activeIndex = indexOrId ; } } } ; }
vPages directive controller
vPages directive controller