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

Commit 6158091

Browse files
committed
feat(position): add uib- prefix
Closes #4507
1 parent 504e653 commit 6158091

File tree

6 files changed

+80
-10
lines changed

6 files changed

+80
-10
lines changed

src/datepicker/datepicker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
492492
onOpenFocus: true
493493
})
494494

495-
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$rootScope', '$position', 'dateFilter', 'uibDateParser', 'datepickerPopupConfig', '$timeout',
495+
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'datepickerPopupConfig', '$timeout',
496496
function($compile, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout) {
497497
return {
498498
restrict: 'EA',

src/position/position.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ angular.module('ui.bootstrap.position', [])
66
* relation to other, existing elements (this is the case for tooltips, popovers,
77
* typeahead suggestions etc.).
88
*/
9-
.factory('$position', ['$document', '$window', function($document, $window) {
9+
.factory('$uibPosition', ['$document', '$window', function($document, $window) {
1010
function getStyle(el, cssprop) {
1111
if (el.currentStyle) { //IE
1212
return el.currentStyle[cssprop];
@@ -148,3 +148,17 @@ angular.module('ui.bootstrap.position', [])
148148
}
149149
};
150150
}]);
151+
152+
/* Deprecated position below */
153+
154+
angular.module('ui.bootstrap.position')
155+
156+
.value('$positionSuppressWarning', false)
157+
158+
.service('$position', ['$log', '$positionSuppressWarning', '$uibPosition', function($log, $positionSuppressWarning, $uibPosition) {
159+
if (!$positionSuppressWarning) {
160+
$log.warn('$position is now deprecated. Use $uibPosition instead.');
161+
}
162+
163+
angular.extend(this, $uibPosition);
164+
}]);

src/position/test/position.spec.js

+60-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
describe('position elements', function () {
2-
32
var TargetElMock = function(width, height) {
43
this.width = width;
54
this.height = height;
@@ -12,8 +11,8 @@ describe('position elements', function () {
1211
var $position;
1312

1413
beforeEach(module('ui.bootstrap.position'));
15-
beforeEach(inject(function(_$position_) {
16-
$position = _$position_;
14+
beforeEach(inject(function($uibPosition) {
15+
$position = $uibPosition;
1716
}));
1817
beforeEach(function () {
1918
jasmine.addMatchers({
@@ -39,7 +38,6 @@ describe('position elements', function () {
3938
});
4039

4140
describe('append-to-body: false', function() {
42-
4341
beforeEach(function() {
4442
//mock position info normally queried from the DOM
4543
$position.position = function() {
@@ -106,3 +104,61 @@ describe('position elements', function () {
106104
});
107105
});
108106
});
107+
108+
/* Deprecation tests below */
109+
110+
describe('position deprecation', function() {
111+
var TargetElMock = function(width, height) {
112+
this.width = width;
113+
this.height = height;
114+
115+
this.prop = function(propName) {
116+
return propName === 'offsetWidth' ? width : height;
117+
};
118+
};
119+
beforeEach(module('ui.bootstrap.position'));
120+
121+
it('should suppress warning', function() {
122+
module(function($provide) {
123+
$provide.value('$positionSuppressWarning', true);
124+
});
125+
126+
inject(function($log, $position) {
127+
spyOn($log, 'warn');
128+
//mock position info normally queried from the DOM
129+
$position.position = function() {
130+
return {
131+
width: 20,
132+
height: 20,
133+
top: 100,
134+
left: 100
135+
};
136+
};
137+
138+
$position.positionElements({}, new TargetElMock(10, 10), 'other');
139+
140+
expect($log.warn.calls.count()).toBe(0);
141+
});
142+
});
143+
144+
it('should give warning by default', inject(function($log) {
145+
spyOn($log, 'warn');
146+
147+
inject(function($position) {
148+
//mock position info normally queried from the DOM
149+
$position.position = function() {
150+
return {
151+
width: 20,
152+
height: 20,
153+
top: 100,
154+
left: 100
155+
};
156+
};
157+
158+
$position.positionElements({}, new TargetElMock(10, 10), 'other');
159+
160+
expect($log.warn.calls.count()).toBe(1);
161+
expect($log.warn.calls.argsFor(0)).toEqual(['$position is now deprecated. Use $uibPosition instead.']);
162+
});
163+
}));
164+
});

src/tooltip/test/tooltip.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,8 @@ describe('tooltip positioning', function() {
675675
// load the template
676676
beforeEach(module('template/tooltip/tooltip-popup.html'));
677677

678-
beforeEach(inject(function($rootScope, $compile, _$position_) {
679-
$position = _$position_;
678+
beforeEach(inject(function($rootScope, $compile, $uibPosition) {
679+
$position = $uibPosition;
680680
spyOn($position, 'positionElements').and.callThrough();
681681

682682
scope = $rootScope;

src/tooltip/tooltip.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
6666
* Returns the actual instance of the $tooltip service.
6767
* TODO support multiple triggers
6868
*/
69-
this.$get = ['$window', '$compile', '$timeout', '$document', '$position', '$interpolate', '$rootScope', '$parse', '$$stackedMap', function($window, $compile, $timeout, $document, $position, $interpolate, $rootScope, $parse, $$stackedMap) {
69+
this.$get = ['$window', '$compile', '$timeout', '$document', '$uibPosition', '$interpolate', '$rootScope', '$parse', '$$stackedMap', function($window, $compile, $timeout, $document, $position, $interpolate, $rootScope, $parse, $$stackedMap) {
7070
var openedTooltips = $$stackedMap.createNew();
7171
$document.on('keypress', function(e) {
7272
if (e.which === 27) {

src/typeahead/typeahead.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
2828
};
2929
}])
3030

31-
.directive('typeahead', ['$compile', '$parse', '$q', '$timeout', '$document', '$window', '$rootScope', '$position', 'typeaheadParser',
31+
.directive('typeahead', ['$compile', '$parse', '$q', '$timeout', '$document', '$window', '$rootScope', '$uibPosition', 'typeaheadParser',
3232
function($compile, $parse, $q, $timeout, $document, $window, $rootScope, $position, typeaheadParser) {
3333
var HOT_KEYS = [9, 13, 27, 38, 40];
3434
var eventDebounceTime = 200;

0 commit comments

Comments
 (0)