diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 350da2e75c..463b6a73b8 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -492,7 +492,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst onOpenFocus: true }) -.directive('datepickerPopup', ['$compile', '$parse', '$document', '$rootScope', '$position', 'dateFilter', 'uibDateParser', 'datepickerPopupConfig', '$timeout', +.directive('datepickerPopup', ['$compile', '$parse', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'datepickerPopupConfig', '$timeout', function($compile, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout) { return { restrict: 'EA', diff --git a/src/position/position.js b/src/position/position.js index 70b3640c55..05020531e9 100644 --- a/src/position/position.js +++ b/src/position/position.js @@ -6,7 +6,7 @@ angular.module('ui.bootstrap.position', []) * relation to other, existing elements (this is the case for tooltips, popovers, * typeahead suggestions etc.). */ - .factory('$position', ['$document', '$window', function($document, $window) { + .factory('$uibPosition', ['$document', '$window', function($document, $window) { function getStyle(el, cssprop) { if (el.currentStyle) { //IE return el.currentStyle[cssprop]; @@ -148,3 +148,17 @@ angular.module('ui.bootstrap.position', []) } }; }]); + +/* Deprecated position below */ + +angular.module('ui.bootstrap.position') + +.value('$positionSuppressWarning', false) + +.service('$position', ['$log', '$positionSuppressWarning', '$uibPosition', function($log, $positionSuppressWarning, $uibPosition) { + if (!$positionSuppressWarning) { + $log.warn('$position is now deprecated. Use $uibPosition instead.'); + } + + angular.extend(this, $uibPosition); +}]); diff --git a/src/position/test/position.spec.js b/src/position/test/position.spec.js index d35b35363a..9b0f5a05ab 100644 --- a/src/position/test/position.spec.js +++ b/src/position/test/position.spec.js @@ -1,5 +1,4 @@ describe('position elements', function () { - var TargetElMock = function(width, height) { this.width = width; this.height = height; @@ -12,8 +11,8 @@ describe('position elements', function () { var $position; beforeEach(module('ui.bootstrap.position')); - beforeEach(inject(function(_$position_) { - $position = _$position_; + beforeEach(inject(function($uibPosition) { + $position = $uibPosition; })); beforeEach(function () { jasmine.addMatchers({ @@ -39,7 +38,6 @@ describe('position elements', function () { }); describe('append-to-body: false', function() { - beforeEach(function() { //mock position info normally queried from the DOM $position.position = function() { @@ -106,3 +104,61 @@ describe('position elements', function () { }); }); }); + +/* Deprecation tests below */ + +describe('position deprecation', function() { + var TargetElMock = function(width, height) { + this.width = width; + this.height = height; + + this.prop = function(propName) { + return propName === 'offsetWidth' ? width : height; + }; + }; + beforeEach(module('ui.bootstrap.position')); + + it('should suppress warning', function() { + module(function($provide) { + $provide.value('$positionSuppressWarning', true); + }); + + inject(function($log, $position) { + spyOn($log, 'warn'); + //mock position info normally queried from the DOM + $position.position = function() { + return { + width: 20, + height: 20, + top: 100, + left: 100 + }; + }; + + $position.positionElements({}, new TargetElMock(10, 10), 'other'); + + expect($log.warn.calls.count()).toBe(0); + }); + }); + + it('should give warning by default', inject(function($log) { + spyOn($log, 'warn'); + + inject(function($position) { + //mock position info normally queried from the DOM + $position.position = function() { + return { + width: 20, + height: 20, + top: 100, + left: 100 + }; + }; + + $position.positionElements({}, new TargetElMock(10, 10), 'other'); + + expect($log.warn.calls.count()).toBe(1); + expect($log.warn.calls.argsFor(0)).toEqual(['$position is now deprecated. Use $uibPosition instead.']); + }); + })); +}); diff --git a/src/tooltip/test/tooltip.spec.js b/src/tooltip/test/tooltip.spec.js index 6362fd885e..e99675aa6c 100644 --- a/src/tooltip/test/tooltip.spec.js +++ b/src/tooltip/test/tooltip.spec.js @@ -675,8 +675,8 @@ describe('tooltip positioning', function() { // load the template beforeEach(module('template/tooltip/tooltip-popup.html')); - beforeEach(inject(function($rootScope, $compile, _$position_) { - $position = _$position_; + beforeEach(inject(function($rootScope, $compile, $uibPosition) { + $position = $uibPosition; spyOn($position, 'positionElements').and.callThrough(); scope = $rootScope; diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index eb4f8d29cf..5c330382c9 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -66,7 +66,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s * Returns the actual instance of the $tooltip service. * TODO support multiple triggers */ - this.$get = ['$window', '$compile', '$timeout', '$document', '$position', '$interpolate', '$rootScope', '$parse', '$$stackedMap', function($window, $compile, $timeout, $document, $position, $interpolate, $rootScope, $parse, $$stackedMap) { + this.$get = ['$window', '$compile', '$timeout', '$document', '$uibPosition', '$interpolate', '$rootScope', '$parse', '$$stackedMap', function($window, $compile, $timeout, $document, $position, $interpolate, $rootScope, $parse, $$stackedMap) { var openedTooltips = $$stackedMap.createNew(); $document.on('keypress', function(e) { if (e.which === 27) { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index c7d6390d71..4aca91788a 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -28,7 +28,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position']) }; }]) - .directive('typeahead', ['$compile', '$parse', '$q', '$timeout', '$document', '$window', '$rootScope', '$position', 'typeaheadParser', + .directive('typeahead', ['$compile', '$parse', '$q', '$timeout', '$document', '$window', '$rootScope', '$uibPosition', 'typeaheadParser', function($compile, $parse, $q, $timeout, $document, $window, $rootScope, $position, typeaheadParser) { var HOT_KEYS = [9, 13, 27, 38, 40]; var eventDebounceTime = 200;