landers.angular
Version:
landers.angular
40 lines (39 loc) • 1.65 kB
JavaScript
;angular.module('Landers.angular')
.directive('landersTab', ['$timeout', 'Helpers', function($timeout, Helpers) {
return {
restrict : 'A',
scope: {
'tabModel': '=?',
'tabCloseEvent': '@',
'tabOpenEvent': '@'
},
link : function($scope, $element, $attrs){
$timeout(function(){
var tab = new Landers.tab($element, {
active: $scope.tabModel,
onClose: function(tab_key){
if ($scope.tabCloseEvent) {
$scope.$emit($scope.tabCloseEvent, tab_key);
}
},
onOpen: function(tab_key){
$timeout(function(){
if ($scope.tabOpenEvent) {
$scope.$emit($scope.tabOpenEvent, tab_key);
}
$scope.tabModel = tab_key;
}, 10);
}
});
if ($attrs['tabModel']) {
$scope.$watch('tabModel', function(new_value){
if (!new_value) return;
var $li = tab.caption.find('ul li[tab-key=' + new_value + ']');
var index = $li.index();
if (index >= 0) tab.active(index);
});
}
}, 100);
}
};
}]);