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

Commit f8bc038

Browse files
wesleychoFoxandxss
authored andcommitted
feat(tooltip): add uib- prefix
Closes #4515
1 parent 9aea856 commit f8bc038

18 files changed

+692
-145
lines changed

src/popover/docs/demo.html

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ <h4>Dynamic</h4>
1212
<label>Popup Template:</label>
1313
<input type="text" ng-model="dynamicPopover.templateUrl" class="form-control">
1414
</div>
15-
<button popover="{{dynamicPopover.content}}" popover-title="{{dynamicPopover.title}}" type="button" class="btn btn-default">Dynamic Popover</button>
15+
<button uib-popover="{{dynamicPopover.content}}" popover-title="{{dynamicPopover.title}}" type="button" class="btn btn-default">Dynamic Popover</button>
1616

17-
<button popover-template="dynamicPopover.templateUrl" popover-title="{{dynamicPopover.title}}" type="button" class="btn btn-default">Popover With Template</button>
17+
<button uib-popover-template="dynamicPopover.templateUrl" popover-title="{{dynamicPopover.title}}" type="button" class="btn btn-default">Popover With Template</button>
1818

1919
<script type="text/ng-template" id="myPopoverTemplate.html">
2020
<div>{{dynamicPopover.content}}</div>
@@ -25,20 +25,20 @@ <h4>Dynamic</h4>
2525
</script>
2626
<hr />
2727
<h4>Positional</h4>
28-
<button popover-placement="top" popover="On the Top!" type="button" class="btn btn-default">Top</button>
29-
<button popover-placement="left" popover="On the Left!" type="button" class="btn btn-default">Left</button>
30-
<button popover-placement="right" popover="On the Right!" type="button" class="btn btn-default">Right</button>
31-
<button popover-placement="bottom" popover="On the Bottom!" type="button" class="btn btn-default">Bottom</button>
28+
<button popover-placement="top" uib-popover="On the Top!" type="button" class="btn btn-default">Top</button>
29+
<button popover-placement="left" uib-popover="On the Left!" type="button" class="btn btn-default">Left</button>
30+
<button popover-placement="right" uib-popover="On the Right!" type="button" class="btn btn-default">Right</button>
31+
<button popover-placement="bottom" uib-popover="On the Bottom!" type="button" class="btn btn-default">Bottom</button>
3232

3333
<hr />
3434
<h4>Triggers</h4>
3535
<p>
36-
<button popover="I appeared on mouse enter!" popover-trigger="mouseenter" type="button" class="btn btn-default">Mouseenter</button>
36+
<button uib-popover="I appeared on mouse enter!" popover-trigger="mouseenter" type="button" class="btn btn-default">Mouseenter</button>
3737
</p>
38-
<input type="text" value="Click me!" popover="I appeared on focus! Click away and I'll vanish..." popover-trigger="focus" class="form-control">
38+
<input type="text" value="Click me!" uib-popover="I appeared on focus! Click away and I'll vanish..." popover-trigger="focus" class="form-control">
3939

4040
<hr />
4141
<h4>Other</h4>
42-
<button Popover-animation="true" popover="I fade in and out!" type="button" class="btn btn-default">fading</button>
43-
<button popover="I have a title!" popover-title="The title." type="button" class="btn btn-default">title</button>
42+
<button popover-animation="true" uib-popover="I fade in and out!" type="button" class="btn btn-default">fading</button>
43+
<button uib-popover="I have a title!" popover-title="The title." type="button" class="btn btn-default">title</button>
4444
</div>

src/popover/docs/readme.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ directive supports multiple placements, optional transition animation, and more.
44
Like the Bootstrap jQuery plugin, the popover **requires** the tooltip
55
module.
66

7-
There are two versions of the popover: `popover` and `popover-template`:
7+
There are two versions of the popover: `uib-popover` and `uib-popover-template`:
88

9-
- `popover` takes text only and will escape any HTML provided for the popover
9+
- `uib-popover` takes text only and will escape any HTML provided for the popover
1010
body.
11-
- `popover-html` takes an expression that evaluates to an html string. *The user is responsible for ensuring the
11+
- `uib-popover-html` takes an expression that evaluates to an html string. *The user is responsible for ensuring the
1212
content is safe to put into the DOM!*
13-
- `popover-template` takes text that specifies the location of a template to
13+
- `uib-popover-template` takes text that specifies the location of a template to
1414
use for the popover body. Note that this needs to be wrapped in a tag.
1515

1616
The popover directives provides several optional attributes to control how it
@@ -40,7 +40,7 @@ $tooltipProvider. See the [tooltip](#tooltip) section for more information.
4040
For Safari 7+ support, if you want to use **focus** `popover-trigger`, you need to use an anchor tag with a tab index. For example:
4141

4242
```
43-
<a tabindex="0" popover="Test" popover-trigger="focus" class="btn btn-default">
43+
<a tabindex="0" uib-popover="Test" popover-trigger="focus" class="btn btn-default">
4444
Click Me
4545
</a>
4646
```

src/popover/popover.js

+72-12
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,108 @@
33
* function, placement as a function, inside, support for more triggers than
44
* just mouse enter/leave, and selector delegatation.
55
*/
6-
angular.module( 'ui.bootstrap.popover', ['ui.bootstrap.tooltip'])
6+
angular.module('ui.bootstrap.popover', ['ui.bootstrap.tooltip'])
77

8-
.directive('popoverTemplatePopup', function() {
8+
.directive('uibPopoverTemplatePopup', function() {
99
return {
10-
restrict: 'EA',
1110
replace: true,
1211
scope: { title: '@', contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&',
1312
originScope: '&' },
1413
templateUrl: 'template/popover/popover-template.html'
1514
};
1615
})
1716

18-
.directive('popoverTemplate', ['$tooltip', function($tooltip) {
19-
return $tooltip('popoverTemplate', 'popover', 'click', {
17+
.directive('uibPopoverTemplate', ['$uibTooltip', function($uibTooltip) {
18+
return $uibTooltip('uibPopoverTemplate', 'popover', 'click', {
2019
useContentExp: true
2120
});
2221
}])
2322

24-
.directive('popoverHtmlPopup', function() {
23+
.directive('uibPopoverHtmlPopup', function() {
2524
return {
26-
restrict: 'EA',
2725
replace: true,
2826
scope: { contentExp: '&', title: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
2927
templateUrl: 'template/popover/popover-html.html'
3028
};
3129
})
3230

33-
.directive('popoverHtml', ['$tooltip', function($tooltip) {
34-
return $tooltip( 'popoverHtml', 'popover', 'click', {
31+
.directive('uibPopoverHtml', ['$uibTooltip', function($uibTooltip) {
32+
return $uibTooltip('uibPopoverHtml', 'popover', 'click', {
3533
useContentExp: true
3634
});
3735
}])
3836

39-
.directive('popoverPopup', function() {
37+
.directive('uibPopoverPopup', function() {
4038
return {
41-
restrict: 'EA',
4239
replace: true,
4340
scope: { title: '@', content: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
4441
templateUrl: 'template/popover/popover.html'
4542
};
4643
})
4744

45+
.directive('uibPopover', ['$uibTooltip', function($uibTooltip) {
46+
return $uibTooltip('uibPopover', 'popover', 'click');
47+
}]);
48+
49+
/* Deprecated popover below */
50+
51+
angular.module('ui.bootstrap.popover')
52+
53+
.value('$popoverSuppressWarning', false)
54+
55+
.directive('popoverTemplatePopup', ['$log', '$popoverSuppressWarning', function($log, $popoverSuppressWarning) {
56+
return {
57+
replace: true,
58+
scope: { title: '@', contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&',
59+
originScope: '&' },
60+
templateUrl: 'template/popover/popover-template.html',
61+
link: function() {
62+
if (!$popoverSuppressWarning) {
63+
$log.warn('popover-template-popup is now deprecated. Use uib-popover-template-popup instead.');
64+
}
65+
}
66+
};
67+
}])
68+
69+
.directive('popoverTemplate', ['$tooltip', function($tooltip) {
70+
return $tooltip('popoverTemplate', 'popover', 'click', {
71+
useContentExp: true
72+
});
73+
}])
74+
75+
.directive('popoverHtmlPopup', ['$log', '$popoverSuppressWarning', function($log, $popoverSuppressWarning) {
76+
return {
77+
replace: true,
78+
scope: { contentExp: '&', title: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
79+
templateUrl: 'template/popover/popover-html.html',
80+
link: function() {
81+
if (!$popoverSuppressWarning) {
82+
$log.warn('popover-html-popup is now deprecated. Use uib-popover-html-popup instead.');
83+
}
84+
}
85+
};
86+
}])
87+
88+
.directive('popoverHtml', ['$tooltip', function($tooltip) {
89+
return $tooltip('popoverHtml', 'popover', 'click', {
90+
useContentExp: true
91+
});
92+
}])
93+
94+
.directive('popoverPopup', ['$log', '$popoverSuppressWarning', function($log, $popoverSuppressWarning) {
95+
return {
96+
replace: true,
97+
scope: { title: '@', content: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
98+
templateUrl: 'template/popover/popover.html',
99+
link: function() {
100+
if (!$popoverSuppressWarning) {
101+
$log.warn('popover-popup is now deprecated. Use uib-popover-popup instead.');
102+
}
103+
}
104+
};
105+
}])
106+
48107
.directive('popover', ['$tooltip', function($tooltip) {
49-
return $tooltip( 'popover', 'popover', 'click' );
108+
109+
return $tooltip('popover', 'popover', 'click');
50110
}]);

src/popover/test/popover-html.spec.js

+66-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('popover', function() {
1313

1414
beforeEach(inject(function($rootScope, $compile, $sce) {
1515
elmBody = angular.element(
16-
'<div><span popover-html="template">Selector Text</span></div>'
16+
'<div><span uib-popover-html="template">Selector Text</span></div>'
1717
);
1818

1919
scope = $rootScope;
@@ -100,7 +100,7 @@ describe('popover', function() {
100100
};
101101

102102
elmBody = angular.element(
103-
'<div><input popover-html="template" ng-click="click()" popover-trigger="mouseenter"/></div>'
103+
'<div><input uib-popover-html="template" ng-click="click()" popover-trigger="mouseenter"/></div>'
104104
);
105105
$compile(elmBody)(scope);
106106
scope.$digest();
@@ -127,7 +127,7 @@ describe('popover', function() {
127127

128128
it('should popup without animate class when animation disabled', inject(function($compile) {
129129
elmBody = angular.element(
130-
'<div><span popover-html="template" popover-animation="false">Selector Text</span></div>'
130+
'<div><span uib-popover-html="template" popover-animation="false">Selector Text</span></div>'
131131
);
132132

133133
$compile(elmBody)(scope);
@@ -146,7 +146,7 @@ describe('popover', function() {
146146
describe('placement', function() {
147147
it('can specify an alternative, valid placement', inject(function($compile) {
148148
elmBody = angular.element(
149-
'<div><span popover-html="template" popover-placement="left">Trigger here</span></div>'
149+
'<div><span uib-popover-html="template" popover-placement="left">Trigger here</span></div>'
150150
);
151151
$compile(elmBody)(scope);
152152
scope.$digest();
@@ -168,7 +168,7 @@ describe('popover', function() {
168168
describe('class', function() {
169169
it('can specify a custom class', inject(function($compile) {
170170
elmBody = angular.element(
171-
'<div><span popover-html="template" popover-class="custom">Trigger here</span></div>'
171+
'<div><span uib-popover-html="template" popover-class="custom">Trigger here</span></div>'
172172
);
173173
$compile(elmBody)(scope);
174174
scope.$digest();
@@ -187,3 +187,64 @@ describe('popover', function() {
187187
});
188188
});
189189
});
190+
191+
/* Deprecation tests below */
192+
193+
describe('popover deprecation', function() {
194+
beforeEach(module('ui.bootstrap.popover'));
195+
beforeEach(module('template/popover/popover-html.html'));
196+
197+
var elm, elmBody, elmScope, tooltipScope;
198+
199+
function trigger(element, evt) {
200+
evt = new Event(evt);
201+
202+
element[0].dispatchEvent(evt);
203+
element.scope().$$childTail.$digest();
204+
}
205+
206+
it('should suppress warning', function() {
207+
module(function($provide) {
208+
$provide.value('$popoverSuppressWarning', true);
209+
$provide.value('$tooltipSuppressWarning', true);
210+
});
211+
212+
inject(function($compile, $log, $rootScope, $sce) {
213+
spyOn($log, 'warn');
214+
215+
$rootScope.html = 'I say: <strong class="hello">Hello!</strong>';
216+
$rootScope.safeHtml = $sce.trustAsHtml($rootScope.html);
217+
elmBody = angular.element('<div><span popover-html="safeHtml">Selector Text</span></div>');
218+
$compile(elmBody)($rootScope);
219+
$rootScope.$digest();
220+
elm = elmBody.find('span');
221+
elmScope = elm.scope();
222+
tooltipScope = elmScope.$$childTail;
223+
224+
trigger(elm, 'mouseenter');
225+
tooltipScope.$digest();
226+
227+
expect($log.warn.calls.count()).toBe(0);
228+
});
229+
});
230+
231+
it('should give warning by default', inject(function($compile, $log, $rootScope, $sce) {
232+
spyOn($log, 'warn');
233+
234+
$rootScope.html = 'I say: <strong class="hello">Hello!</strong>';
235+
$rootScope.safeHtml = $sce.trustAsHtml($rootScope.html);
236+
elmBody = angular.element('<div><span popover-html="safeHtml">Selector Text</span></div>');
237+
$compile(elmBody)($rootScope);
238+
$rootScope.$digest();
239+
elm = elmBody.find('span');
240+
elmScope = elm.scope();
241+
tooltipScope = elmScope.$$childTail;
242+
243+
elm.trigger('click');
244+
tooltipScope.$digest();
245+
246+
expect($log.warn.calls.count()).toBe(2);
247+
expect($log.warn.calls.argsFor(0)).toEqual(['$tooltip is now deprecated. Use $uibTooltip instead.']);
248+
expect($log.warn.calls.argsFor(1)).toEqual(['popover-html-popup is now deprecated. Use uib-popover-html-popup instead.']);
249+
}));
250+
});

src/popover/test/popover-template.spec.js

+56-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('popover template', function() {
1818

1919
beforeEach(inject(function($rootScope, $compile) {
2020
elmBody = angular.element(
21-
'<div><span popover-template="templateUrl">Selector Text</span></div>'
21+
'<div><span uib-popover-template="templateUrl">Selector Text</span></div>'
2222
);
2323

2424
scope = $rootScope;
@@ -84,7 +84,7 @@ describe('popover template', function() {
8484
describe('placement', function() {
8585
it('can specify an alternative, valid placement', inject(function($compile) {
8686
elmBody = angular.element(
87-
'<div><span popover-template="templateUrl" popover-placement="left">Trigger</span></div>'
87+
'<div><span uib-popover-template="templateUrl" popover-placement="left">Trigger</span></div>'
8888
);
8989
$compile(elmBody)(scope);
9090
scope.$digest();
@@ -106,7 +106,7 @@ describe('popover template', function() {
106106
describe('class', function() {
107107
it('can specify a custom class', inject(function($compile) {
108108
elmBody = angular.element(
109-
'<div><span popover-template="templateUrl" popover-class="custom">Trigger</span></div>'
109+
'<div><span uib-popover-template="templateUrl" popover-class="custom">Trigger</span></div>'
110110
);
111111
$compile(elmBody)(scope);
112112
scope.$digest();
@@ -125,3 +125,56 @@ describe('popover template', function() {
125125
});
126126
});
127127
});
128+
129+
/* Deprecation tests below */
130+
131+
describe('popover template deprecation', function() {
132+
beforeEach(module('ui.bootstrap.popover'));
133+
beforeEach(module('template/popover/popover.html'));
134+
beforeEach(module('template/popover/popover-template.html'));
135+
136+
var elm, elmBody, elmScope, tooltipScope;
137+
138+
it('should suppress warning', function() {
139+
module(function($provide) {
140+
$provide.value('$popoverSuppressWarning', true);
141+
$provide.value('$tooltipSuppressWarning', true);
142+
});
143+
144+
inject(function($compile, $log, $rootScope, $templateCache) {
145+
spyOn($log, 'warn');
146+
$templateCache.put('myUrl', [200, '<span>{{ myTemplateText }}</span>', {}]);
147+
$rootScope.templateUrl = 'myUrl';
148+
149+
elmBody = angular.element('<div><span popover-template="templateUrl">Selector Text</span></div>');
150+
$compile(elmBody)($rootScope);
151+
$rootScope.$digest();
152+
elm = elmBody.find('span');
153+
elmScope = elm.scope();
154+
tooltipScope = elmScope.$$childTail;
155+
156+
elm.trigger('click');
157+
tooltipScope.$digest();
158+
expect($log.warn.calls.count()).toBe(0);
159+
});
160+
});
161+
162+
it('should give warning by default', inject(function($compile, $log, $rootScope, $templateCache) {
163+
spyOn($log, 'warn');
164+
$templateCache.put('myUrl', [200, '<span>{{ myTemplateText }}</span>', {}]);
165+
$rootScope.templateUrl = 'myUrl';
166+
167+
elmBody = angular.element('<div><span popover-template="templateUrl">Selector Text</span></div>');
168+
$compile(elmBody)($rootScope);
169+
elm = elmBody.find('span');
170+
elmScope = elm.scope();
171+
tooltipScope = elmScope.$$childTail;
172+
173+
elm.trigger('click');
174+
tooltipScope.$digest();
175+
176+
expect($log.warn.calls.count()).toBe(2);
177+
expect($log.warn.calls.argsFor(0)).toEqual(['$tooltip is now deprecated. Use $uibTooltip instead.']);
178+
expect($log.warn.calls.argsFor(1)).toEqual(['popover-template-popup is now deprecated. Use uib-popover-template-popup instead.']);
179+
}));
180+
});

0 commit comments

Comments
 (0)