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

Commit 9e5e1a2

Browse files
BobbieBarkerwesleycho
authored andcommitted
feat(typeahead): add uib- prefix
Closes #4542
1 parent 038157d commit 9e5e1a2

8 files changed

+745
-107
lines changed

src/typeahead/docs/demo.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<script type="text/ng-template" id="customTemplate.html">
3030
<a>
3131
<img ng-src="http://upload.wikimedia.org/wikipedia/commons/thumb/{{match.model.flag}}" width="16">
32-
<span ng-bind-html="match.label | typeaheadHighlight:query"></span>
32+
<span ng-bind-html="match.label | uibTypeaheadHighlight:query"></span>
3333
</a>
3434
</script>
3535

@@ -44,7 +44,7 @@
4444
<ul class="dropdown-menu" role="listbox">
4545
<li ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }"
4646
ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)" role="option" id="{{::match.id}}">
47-
<div typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
47+
<div uib-typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
4848
</li>
4949
</ul>
5050
</div>
@@ -54,21 +54,21 @@
5454

5555
<h4>Static arrays</h4>
5656
<pre>Model: {{selected | json}}</pre>
57-
<input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue | limitTo:8" class="form-control">
57+
<input type="text" ng-model="selected" uib-typeahead="state for state in states | filter:$viewValue | limitTo:8" class="form-control">
5858

5959
<h4>Asynchronous results</h4>
6060
<pre>Model: {{asyncSelected | json}}</pre>
61-
<input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" typeahead="address for address in getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control">
61+
<input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" uib-typeahead="address for address in getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control">
6262
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
6363
<div ng-show="noResults">
6464
<i class="glyphicon glyphicon-remove"></i> No Results Found
6565
</div>
6666

6767
<h4>Custom templates for results</h4>
6868
<pre>Model: {{customSelected | json}}</pre>
69-
<input type="text" ng-model="customSelected" placeholder="Custom template" typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-template-url="customTemplate.html" class="form-control">
69+
<input type="text" ng-model="customSelected" placeholder="Custom template" uib-typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-template-url="customTemplate.html" class="form-control">
7070

7171
<h4>Custom popup templates for typeahead's dropdown</h4>
7272
<pre>Model: {{customPopupSelected | json}}</pre>
73-
<input type="text" ng-model="customPopupSelected" placeholder="Custom popup template" typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-popup-template-url="customPopupTemplate.html" class="form-control">
73+
<input type="text" ng-model="customPopupSelected" placeholder="Custom popup template" uib-typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-popup-template-url="customPopupTemplate.html" class="form-control">
7474
</div>

src/typeahead/test/typeahead-highlight-ngsanitize.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ describe('Security concerns', function() {
33

44
beforeEach(module('ui.bootstrap.typeahead', 'ngSanitize'));
55

6-
beforeEach(inject(function (typeaheadHighlightFilter, _$sanitize_, $log) {
7-
highlightFilter = typeaheadHighlightFilter;
6+
beforeEach(inject(function (uibTypeaheadHighlightFilter, _$sanitize_, $log) {
7+
highlightFilter = uibTypeaheadHighlightFilter;
88
$sanitize = _$sanitize_;
99
logSpy = spyOn($log, 'warn');
1010
}));

src/typeahead/test/typeahead-highlight.spec.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ describe('typeaheadHighlight', function () {
1010
logSpy = spyOn($log, 'warn');
1111
}));
1212

13-
beforeEach(inject(function(typeaheadHighlightFilter) {
14-
highlightFilter = typeaheadHighlightFilter;
13+
beforeEach(inject(function(uibTypeaheadHighlightFilter) {
14+
highlightFilter = uibTypeaheadHighlightFilter;
1515
}));
1616

1717
it('should higlight a match', function() {
@@ -49,3 +49,32 @@ describe('typeaheadHighlight', function () {
4949
expect(logSpy).toHaveBeenCalled();
5050
});
5151
});
52+
53+
/* Deprecation tests below */
54+
55+
describe('typeahead highlightFilter deprecated', function(){
56+
var highlightFilter, $log, $sce, logSpy;
57+
58+
beforeEach(module('ui.bootstrap.typeahead'));
59+
60+
it('should supress the warning by default', function(){
61+
module(function($provide) {
62+
$provide.value('$typeaheadSuppressWarning', true);
63+
});
64+
65+
inject(function($compile, $log, $rootScope, typeaheadHighlightFilter, $sce){
66+
spyOn($log, 'warn');
67+
var highlightFilter = typeaheadHighlightFilter;
68+
$sce.getTrustedHtml(highlightFilter('before match after', 'match'));
69+
expect($log.warn.calls.count()).toBe(0);
70+
});
71+
});
72+
73+
it('should decrecate typeaheadHighlightFilter', inject(function($compile, $log, $rootScope, typeaheadHighlightFilter, $sce){
74+
spyOn($log, 'warn');
75+
var highlightFilter = typeaheadHighlightFilter;
76+
$sce.getTrustedHtml(highlightFilter('before match after', 'match'));
77+
expect($log.warn.calls.count()).toBe(1);
78+
expect($log.warn.calls.argsFor(0)).toEqual(['typeaheadHighlight is now deprecated. Use uibTypeaheadHighlight instead.']);
79+
}));
80+
});

src/typeahead/test/typeahead-popup.spec.js

+47-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('typeaheadPopup - result rendering', function() {
1414
scope.matches = ['foo', 'bar', 'baz'];
1515
scope.active = 1;
1616

17-
var el = $compile('<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>')(scope);
17+
var el = $compile('<div><uib-typeahead-popup matches="matches" active="active" select="select(activeIdx)"></uib-typeahead-popup></div>')(scope);
1818
$rootScope.$digest();
1919

2020
var liElems = el.find('li');
@@ -28,7 +28,7 @@ describe('typeaheadPopup - result rendering', function() {
2828
scope.matches = ['foo', 'bar', 'baz'];
2929
scope.active = 1;
3030

31-
var el = $compile('<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>')(scope);
31+
var el = $compile('<div><uib-typeahead-popup matches="matches" active="active" select="select(activeIdx)"></uib-typeahead-popup></div>')(scope);
3232
$rootScope.$digest();
3333

3434
var liElems = el.find('li');
@@ -47,11 +47,55 @@ describe('typeaheadPopup - result rendering', function() {
4747
$rootScope.select = angular.noop;
4848
spyOn($rootScope, 'select');
4949

50-
var el = $compile('<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>')(scope);
50+
var el = $compile('<div><uib-typeahead-popup matches="matches" active="active" select="select(activeIdx)"></uib-typeahead-popup></div>')(scope);
5151
$rootScope.$digest();
5252

5353
var liElems = el.find('li');
5454
liElems.eq(2).find('a').trigger('click');
5555
expect($rootScope.select).toHaveBeenCalledWith(2);
5656
});
5757
});
58+
59+
/* Deprecation tests below */
60+
61+
describe('typeaheadPopup deprecation', function() {
62+
beforeEach(module('ui.bootstrap.typeahead'));
63+
beforeEach(module('ngSanitize'));
64+
beforeEach(module('template/typeahead/typeahead-popup.html'));
65+
beforeEach(module('template/typeahead/typeahead-match.html'));
66+
67+
it('should suppress warning', function() {
68+
module(function($provide) {
69+
$provide.value('$typeaheadSuppressWarning', true);
70+
});
71+
72+
inject(function($compile, $log, $rootScope) {
73+
var scope = $rootScope.$new();
74+
scope.matches = ['foo', 'bar', 'baz'];
75+
scope.active = 1;
76+
$rootScope.select = angular.noop;
77+
spyOn($log, 'warn');
78+
79+
var element = '<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>';
80+
element = $compile(element)(scope);
81+
$rootScope.$digest();
82+
expect($log.warn.calls.count()).toBe(0);
83+
});
84+
});
85+
86+
it('should give warning by default', inject(function($compile, $log, $rootScope) {
87+
var scope = $rootScope.$new();
88+
scope.matches = ['foo', 'bar', 'baz'];
89+
scope.active = 1;
90+
$rootScope.select = angular.noop;
91+
spyOn($log, 'warn');
92+
93+
var element = '<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>';
94+
element = $compile(element)(scope);
95+
96+
$rootScope.$digest();
97+
98+
expect($log.warn.calls.count()).toBe(1);
99+
expect($log.warn.calls.argsFor(0)).toEqual(['typeahead-popup is now deprecated. Use uib-typeahead-popup instead.']);
100+
}));
101+
});

0 commit comments

Comments
 (0)