Skip to content

Commit 804fe62

Browse files
committed
2 parents 0569e11 + a8624e0 commit 804fe62

File tree

5 files changed

+168
-4
lines changed

5 files changed

+168
-4
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ module.exports = function(grunt) {
444444
.replace(/\\/g, '\\\\')
445445
.replace(/'/g, "\\'")
446446
.replace(/\r?\n/g, '\\n');
447-
js = "!angular.$$csp() && angular.element(document).find('head').prepend('<style type=\"text/css\">" + css + "</style>');";
447+
js = "angular.module('ui.bootstrap.carousel').run(function() {!angular.$$csp() && angular.element(document).find('head').prepend('<style type=\"text/css\">" + css + "</style>'); })";
448448
state.js.push(js);
449449

450450
return state;

src/pagination/pagination.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ angular.module('ui.bootstrap.pagination', [])
2828
$scope.$watch('totalPages', function(value) {
2929
setNumPages($scope.$parent, value); // Readonly variable
3030

31-
if ( $scope.page > value ) {
31+
if ($scope.page > value) {
3232
$scope.selectPage(value);
3333
} else {
3434
ngModelCtrl.$render();

src/pagination/test/pagination.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ describe('pagination directive', function() {
244244
});
245245
});
246246

247-
describe('executes `ng-change` expression', function() {
247+
describe('executes `ng-change` expression', function() {
248248
beforeEach(function() {
249249
$rootScope.selectPageHandler = jasmine.createSpy('selectPageHandler');
250250
element = $compile('<uib-pagination total-items="total" ng-model="currentPage" ng-change="selectPageHandler()"></uib-pagination>')($rootScope);

src/position/position.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ angular.module('ui.bootstrap.position', [])
141141
top: hostElPos.top - targetElHeight,
142142
left: shiftWidth[pos1]()
143143
};
144-
break;
145144
}
146145

147146
return targetElPos;

src/position/test/position.spec.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,104 @@ describe('position elements', function () {
3737
});
3838
});
3939

40+
describe('offset', function() {
41+
var $document;
42+
43+
beforeEach(inject(function(_$document_) {
44+
$document = _$document_;
45+
}));
46+
47+
it('returns getBoundingClientRect by default', function() {
48+
var el = angular.element('<div>Foo</div>');
49+
50+
/* getBoundingClientRect values will be based on the testing Chrome window
51+
so that makes this tests very brittle if we don't mock */
52+
spyOn(el[0], 'getBoundingClientRect').and.returnValue({
53+
width: 100,
54+
height: 100,
55+
top: 2,
56+
left: 2
57+
});
58+
$document.find('body').append(el);
59+
60+
var offset = $position.offset(el);
61+
62+
expect(offset).toEqual({
63+
width: 100,
64+
height: 100,
65+
top: 2,
66+
left: 2
67+
});
68+
69+
el.remove();
70+
});
71+
});
72+
73+
describe('position', function() {
74+
var $document, el;
75+
76+
beforeEach(inject(function(_$document_) {
77+
$document = _$document_;
78+
}));
79+
80+
afterEach(function() {
81+
el.remove();
82+
});
83+
84+
it('gets position with document as the relative parent', function() {
85+
el = angular.element('<div>Foo</div>');
86+
87+
spyOn(el[0], 'getBoundingClientRect').and.returnValue({
88+
width: 100,
89+
height: 100,
90+
top: 2,
91+
left: 2
92+
});
93+
94+
$document.find('body').append(el);
95+
96+
var position = $position.position(el);
97+
98+
expect(position).toEqual({
99+
width: 100,
100+
height: 100,
101+
top: 2,
102+
left: 2
103+
});
104+
});
105+
106+
it('gets position with another DOM as the relative parent', function() {
107+
el = angular.element('<div id="outer" style="position:relative;"><div id="inner">Foo</div></div>');
108+
109+
$document.find('body').append(el);
110+
111+
var outerEl = angular.element(document.getElementById('outer'));
112+
var innerEl = angular.element(document.getElementById('inner'));
113+
114+
spyOn(outerEl[0], 'getBoundingClientRect').and.returnValue({
115+
width: 100,
116+
height: 100,
117+
top: 2,
118+
left: 2
119+
});
120+
spyOn(innerEl[0], 'getBoundingClientRect').and.returnValue({
121+
width: 20,
122+
height: 20,
123+
top: 5,
124+
left: 5
125+
});
126+
127+
var position = $position.position(innerEl);
128+
129+
expect(position).toEqual({
130+
width: 20,
131+
height: 20,
132+
top: 3,
133+
left: 3
134+
});
135+
});
136+
});
137+
40138
describe('append-to-body: false', function() {
41139
beforeEach(function() {
42140
//mock position info normally queried from the DOM
@@ -103,4 +201,71 @@ describe('position elements', function () {
103201
expect($position.positionElements({}, new TargetElMock(10, 10), 'right-bottom')).toBePositionedAt(120, 120);
104202
});
105203
});
204+
205+
describe('append-to-body: true', function() {
206+
beforeEach(function() {
207+
//mock offset info normally queried from the DOM
208+
$position.offset = function() {
209+
return {
210+
width: 20,
211+
height: 20,
212+
top: 100,
213+
left: 100
214+
};
215+
};
216+
});
217+
218+
it('should position element on top-center by default', function() {
219+
expect($position.positionElements({}, new TargetElMock(10, 10), 'other', true)).toBePositionedAt(90, 105);
220+
expect($position.positionElements({}, new TargetElMock(10, 10), 'top', true)).toBePositionedAt(90, 105);
221+
expect($position.positionElements({}, new TargetElMock(10, 10), 'top-center', true)).toBePositionedAt(90, 105);
222+
});
223+
224+
it('should position on top-left', function() {
225+
expect($position.positionElements({}, new TargetElMock(10, 10), 'top-left', true)).toBePositionedAt(90, 100);
226+
});
227+
228+
it('should position on top-right', function() {
229+
expect($position.positionElements({}, new TargetElMock(10, 10), 'top-right', true)).toBePositionedAt(90, 120);
230+
});
231+
232+
it('should position elements on bottom-center when "bottom" specified', function() {
233+
expect($position.positionElements({}, new TargetElMock(10, 10), 'bottom', true)).toBePositionedAt(120, 105);
234+
expect($position.positionElements({}, new TargetElMock(10, 10), 'bottom-center', true)).toBePositionedAt(120, 105);
235+
});
236+
237+
it('should position elements on bottom-left', function() {
238+
expect($position.positionElements({}, new TargetElMock(10, 10), 'bottom-left', true)).toBePositionedAt(120, 100);
239+
});
240+
241+
it('should position elements on bottom-right', function() {
242+
expect($position.positionElements({}, new TargetElMock(10, 10), 'bottom-right', true)).toBePositionedAt(120, 120);
243+
});
244+
245+
it('should position elements on left-center when "left" specified', function() {
246+
expect($position.positionElements({}, new TargetElMock(10, 10), 'left', true)).toBePositionedAt(105, 90);
247+
expect($position.positionElements({}, new TargetElMock(10, 10), 'left-center', true)).toBePositionedAt(105, 90);
248+
});
249+
250+
it('should position elements on left-top when "left-top" specified', function() {
251+
expect($position.positionElements({}, new TargetElMock(10, 10), 'left-top', true)).toBePositionedAt(100, 90);
252+
});
253+
254+
it('should position elements on left-bottom when "left-bottom" specified', function() {
255+
expect($position.positionElements({}, new TargetElMock(10, 10), 'left-bottom', true)).toBePositionedAt(120, 90);
256+
});
257+
258+
it('should position elements on right-center when "right" specified', function() {
259+
expect($position.positionElements({}, new TargetElMock(10, 10), 'right', true)).toBePositionedAt(105, 120);
260+
expect($position.positionElements({}, new TargetElMock(10, 10), 'right-center', true)).toBePositionedAt(105, 120);
261+
});
262+
263+
it('should position elements on right-top when "right-top" specified', function() {
264+
expect($position.positionElements({}, new TargetElMock(10, 10), 'right-top', true)).toBePositionedAt(100, 120);
265+
});
266+
267+
it('should position elements on right-top when "right-top" specified', function() {
268+
expect($position.positionElements({}, new TargetElMock(10, 10), 'right-bottom', true)).toBePositionedAt(120, 120);
269+
});
270+
});
106271
});

0 commit comments

Comments
 (0)