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

Commit

Permalink
feat(position): add uib- prefix
Browse files Browse the repository at this point in the history
Closes #4507
  • Loading branch information
wesleycho committed Oct 2, 2015
1 parent 504e653 commit 6158091
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 15 additions & 1 deletion src/position/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}]);
64 changes: 60 additions & 4 deletions src/position/test/position.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
describe('position elements', function () {

var TargetElMock = function(width, height) {
this.width = width;
this.height = height;
Expand All @@ -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({
Expand All @@ -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() {
Expand Down Expand Up @@ -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.']);
});
}));
});
4 changes: 2 additions & 2 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6158091

Please sign in to comment.