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

feat(tooltip/popover): fix -class option for other tooltip/popup types #3569

Closed
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
4 changes: 2 additions & 2 deletions src/popover/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] )
return {
restrict: 'EA',
replace: true,
scope: { title: '@', contentExp: '&', placement: '@', animation: '&', isOpen: '&',
scope: { title: '@', contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&',
originScope: '&' },
templateUrl: 'template/popover/popover-template.html'
};
Expand All @@ -25,7 +25,7 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] )
return {
restrict: 'EA',
replace: true,
scope: { title: '@', content: '@', placement: '@', animation: '&', isOpen: '&' },
scope: { title: '@', content: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
templateUrl: 'template/popover/popover.html'
};
})
Expand Down
49 changes: 49 additions & 0 deletions src/popover/test/popover-template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,54 @@ describe('popover template', function() {
expect( elmBody.children().length ).toBe( 1 );
}));

describe('supports options', function () {

describe('placement', function () {

it('can specify an alternative, valid placement', inject(function ($compile) {
elmBody = angular.element(
'<div><span popover-template="templateUrl" popover-placement="left">Trigger</span></div>'
);
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
tooltipScope = elmScope.$$childTail;

elm.trigger( 'click' );
expect( tooltipScope.isOpen ).toBe( true );

expect( elmBody.children().length ).toBe( 2 );
var ttipElement = elmBody.find('div.popover');
expect(ttipElement).toHaveClass('left');
}));

});

describe('class', function () {

it('can specify a custom class', inject(function ($compile) {
elmBody = angular.element(
'<div><span popover-template="templateUrl" popover-class="custom">Trigger</span></div>'
);
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
tooltipScope = elmScope.$$childTail;

elm.trigger( 'click' );
expect( tooltipScope.isOpen ).toBe( true );

expect( elmBody.children().length ).toBe( 2 );
var ttipElement = elmBody.find('div.popover');
expect(ttipElement).toHaveClass('custom');
}));

});

});


});

48 changes: 48 additions & 0 deletions src/popover/test/popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,54 @@ describe('popover', function() {
expect(elmBody.children().eq(1)).not.toHaveClass('fade');
}));

describe('supports options', function () {

describe('placement', function () {

it('can specify an alternative, valid placement', inject(function ($compile) {
elmBody = angular.element(
'<div><span popover="popover text" popover-placement="left">Trigger here</span></div>'
);
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
tooltipScope = elmScope.$$childTail;

elm.trigger( 'click' );
expect( tooltipScope.isOpen ).toBe( true );

expect( elmBody.children().length ).toBe( 2 );
var ttipElement = elmBody.find('div.popover');
expect(ttipElement).toHaveClass('left');
}));

});

describe('class', function () {

it('can specify a custom class', inject(function ($compile) {
elmBody = angular.element(
'<div><span popover="popover text" popover-class="custom">Trigger here</span></div>'
);
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
tooltipScope = elmScope.$$childTail;

elm.trigger( 'click' );
expect( tooltipScope.isOpen ).toBe( true );

expect( elmBody.children().length ).toBe( 2 );
var ttipElement = elmBody.find('div.popover');
expect(ttipElement).toHaveClass('custom');
}));

});

});

});


64 changes: 44 additions & 20 deletions src/tooltip/test/tooltip2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ describe('tooltip directive', function () {

beforeEach(module('ui.bootstrap.tooltip'));
beforeEach(module('template/tooltip/tooltip-popup.html'));
beforeEach(module('template/tooltip/tooltip-template-popup.html'));
beforeEach(module('template/tooltip/tooltip-html-popup.html'));
beforeEach(module('template/tooltip/tooltip-html-unsafe-popup.html'));
beforeEach(inject(function (_$rootScope_, _$compile_, _$document_, _$timeout_) {
$rootScope = _$rootScope_;
$compile = _$compile_;
Expand Down Expand Up @@ -95,34 +98,55 @@ describe('tooltip directive', function () {

describe('option by option', function () {

describe('placement', function () {
var tooltipTypes = {
'tooltip': 'tooltip="tooltip text"',
'tooltip-html': 'tooltip-html="tooltipSafeHtml"',
'tooltip-html-unsafe': 'tooltip-html-unsafe="tooltip text"',
'tooltip-template': 'tooltip-template="\'tooltipTextUrl\'"'
};

it('can specify an alternative, valid placement', function () {
var fragment = compileTooltip('<span tooltip="tooltip text" tooltip-placement="left">Trigger here</span>');
fragment.find('span').trigger( 'mouseenter' );
beforeEach(inject(function ($sce, $templateCache) {
$rootScope.tooltipText = 'tooltip text';
$rootScope.tooltipSafeHtml = $sce.trustAsHtml('tooltip text');
$templateCache.put('tooltipTextUrl', [200, '<span>tooltip text</span>', {}]);
}));

var ttipElement = fragment.find('div.tooltip');
expect(fragment).toHaveOpenTooltips();
expect(ttipElement).toHaveClass('left');
angular.forEach(tooltipTypes, function (html, key) {

closeTooltip(fragment.find('span'));
expect(fragment).not.toHaveOpenTooltips();
});
describe(key, function () {

});
describe('placement', function () {

it('can specify an alternative, valid placement', function () {
var fragment = compileTooltip('<span ' + html + ' tooltip-placement="left">Trigger here</span>');
fragment.find('span').trigger( 'mouseenter' );

var ttipElement = fragment.find('div.tooltip');
expect(fragment).toHaveOpenTooltips();
expect(ttipElement).toHaveClass('left');

closeTooltip(fragment.find('span'));
expect(fragment).not.toHaveOpenTooltips();
});

});

describe('class', function () {

it('can specify a custom class', function () {
var fragment = compileTooltip('<span ' + html + ' tooltip-class="custom">Trigger here</span>');
fragment.find('span').trigger( 'mouseenter' );

describe('class', function () {
var ttipElement = fragment.find('div.tooltip');
expect(fragment).toHaveOpenTooltips();
expect(ttipElement).toHaveClass('custom');

it('can specify a custom class', function () {
var fragment = compileTooltip('<span tooltip="tooltip text" tooltip-class="custom">Trigger here</span>');
fragment.find('span').trigger( 'mouseenter' );
closeTooltip(fragment.find('span'));
expect(fragment).not.toHaveOpenTooltips();
});

var ttipElement = fragment.find('div.tooltip');
expect(fragment).toHaveOpenTooltips();
expect(ttipElement).toHaveClass('custom');
});

closeTooltip(fragment.find('span'));
expect(fragment).not.toHaveOpenTooltips();
});

});
Expand Down
2 changes: 1 addition & 1 deletion src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ function ($animate , $sce , $compile , $templateRequest) {
return {
restrict: 'EA',
replace: true,
scope: { title: '@', contentExp: '&', placement: '@', animation: '&', isOpen: '&',
scope: { contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&',
originScope: '&' },
templateUrl: 'template/tooltip/tooltip-template-popup.html'
};
Expand Down
5 changes: 4 additions & 1 deletion template/tooltip/tooltip-popup.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div class="tooltip {{placement}} {{popupClass}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip"
tooltip-animation-class="fade"
tooltip-classes
ng-class="{ in: isOpen() }">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner" ng-bind="content"></div>
</div>