Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

add a select attribute on tabs pane to trigger a callback #141

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ angular.module('ui.bootstrap.tabs', [])
restrict: 'EA',
transclude: true,
scope:{
heading:'@'
heading:'@',
select:'&'
},
link: function(scope, element, attrs, tabsCtrl) {
var getSelected, setSelected;
Expand All @@ -57,6 +58,9 @@ angular.module('ui.bootstrap.tabs', [])
}
scope.$watch('selected', function(selected) {
if(selected) {
if (scope.select) {
scope.select(this);
}
tabsCtrl.select(scope);
}
if(setSelected) {
Expand Down
20 changes: 19 additions & 1 deletion src/tabs/test/tabsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('tabs', function() {
'<pane heading="First Tab">' +
'first content is {{first}}' +
'</pane>' +
'<pane heading="Second Tab">' +
'<pane heading="Second Tab" select="selectCb()">' +
'second content is {{second}}' +
'</pane>' +
'</tabs>' +
Expand Down Expand Up @@ -85,6 +85,24 @@ describe('tabs', function() {
expect(contents.eq(1)).toHaveClass('active');
expect(contents.eq(1).css('display')).not.toBe('none');
});


it('should trigger the select attribute if any', function() {

var titles = elm.find('ul.nav-tabs li');

var called = false;
scope.selectCb = function(tab) {
called = true;
};
titles.eq(0).find('a').click();
expect(called).toBe(false);

titles.eq(1).find('a').click();
expect(called).toBe(true);

});

});


Expand Down
4 changes: 2 additions & 2 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ angular.module( 'ui.bootstrap.tooltip', [] )
return {
width: element.prop( 'offsetWidth' ),
height: element.prop( 'offsetHeight' ),
top: boundingClientRect.top + $window.pageYOffset,
left: boundingClientRect.left + $window.pageXOffset
top: boundingClientRect.top + ($window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop || 0),
left: boundingClientRect.left + ($window.pageXOffset || document.body.scrollLeft|| document.documentElement.scrollLeft || 0)
};
}

Expand Down