getClientRect.js
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
describe('getClientRect', function() {
var getClientRect = $.fullCalendar.getClientRect;
defineTests(
'when margin',
{ margin: '5px 10px' },
{ width: 100, height: 100 },
{ width: 100, height: 100 }
);
defineTests(
'when border',
{ border: '5px solid red' },
{ width: 100, height: 100 },
{ width: 100, height: 100 }
);
defineTests(
'when padding',
{ padding: '5px 10px' },
{ width: 100, height: 100 },
{ width: 120, height: 110 }
);
defineTests(
'when border and padding',
{ border: '5px solid red', padding: '5px 10px' },
{ width: 100, height: 100 },
{ width: 120, height: 110 }
);
function defineTests(description, cssProps, innerDims, dims) {
describe(description, function() {
describe('when no scrolling', function() {
describe('when LTR', function() {
defineTest(false, 'ltr', cssProps, innerDims, dims);
});
describe('when RTL', function() {
defineTest(false, 'rtl', cssProps, innerDims, dims);
});
});
describe('when scrolling', function() {
describe('when LTR', function() {
defineTest(true, 'ltr', cssProps, innerDims, dims);
});
describe('when RTL', function() {
defineTest(true, 'rtl', cssProps, innerDims, dims);
});
});
});
}
function defineTest(isScrolling, dir, cssProps, innerDims, dims) {
it('computes correct dimensions', function() {
var el = $(
'<div style="position:absolute" />'
)
.css('overflow', isScrolling ? 'scroll' : 'hidden')
.css('direction', dir)
.css(cssProps)
.append(
$('<div style="position:relative" />').css(innerDims)
)
.appendTo('body');
var rect = getClientRect(el);
var offset = el.offset();
var borderLeftWidth = parseFloat(el.css('border-left-width')) || 0;
var borderTopWidth = parseFloat(el.css('border-top-width')) || 0;
var scrollbarWidths;
if (isScrolling) {
scrollbarWidths = getStockScrollbarWidths(dir);
}
else {
scrollbarWidths = { left: 0, right: 0, top: 0, bottom: 0 };
}
expect(rect.left).toBe(offset.left + borderLeftWidth + scrollbarWidths.left);
expect(rect.top).toBe(offset.top + borderTopWidth + scrollbarWidths.top);
expect(rect.right - rect.left).toBe(dims.width);
expect(rect.bottom - rect.top).toBe(dims.height);
el.remove();
});
}
});