Skip to content

Commit 6e920f7

Browse files
author
Joel Steres
committed
Add position test cases to edge-cases
1 parent 4c56d2f commit 6e920f7

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

test/edge-cases.html

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,54 @@
2929
$('#powertip-css').attr('href', '../css/jquery.powertip' + theme + '.css');
3030
}
3131

32+
// css position switcher allows testing html and body CSS position values that
33+
// changes the origin from which the tooltip is positioned.
34+
function setCssPosition() {
35+
var attributeSets = {
36+
// default positioning is static
37+
static: { position: '', left: '', right: '', top: '', bottom: '' },
38+
absolute: { position: 'absolute', left: '50px', right: '100px', top: '25px', bottom: '75px' },
39+
relative: { position: 'relative', left: '50px', right: '100px', top: '25px', bottom: '75px' },
40+
fixed: { position: 'fixed', left: '50px', right: '100px', top: '25px', bottom: '75px' },
41+
};
42+
var posType = $('#position-switcher').val();
43+
var $html = $(document.documentElement);
44+
var $body = $(document.body);
45+
$html.css(attributeSets['static']);
46+
$body.css(attributeSets['static']);
47+
switch(posType) {
48+
case 'html-relative':
49+
$html.css(attributeSets['relative']);
50+
break;
51+
case 'html-fixed':
52+
$html.css(attributeSets['fixed']);
53+
break;
54+
case 'html-absolute':
55+
$html.css(attributeSets['absolute']);
56+
break;
57+
case 'body-relative':
58+
$body.css(attributeSets['relative']);
59+
break;
60+
case 'body-fixed':
61+
$body.css(attributeSets['fixed']);
62+
break;
63+
case 'body-absolute':
64+
$body.css(attributeSets['absolute']);
65+
break;
66+
default:
67+
// attributes clear above
68+
break;
69+
}
70+
// Trigger resize to force recalculation of position compensation
71+
window.dispatchEvent(new Event('resize'));
72+
}
73+
3274
// run theme switcher on page load
3375
setTheme();
3476

35-
// hook theme switcher to select change
77+
// hook theme and position switcher to select change
3678
$('#theme-switcher').on('change', setTheme);
79+
$('#position-switcher').on('change', setCssPosition);
3780

3881
// session debug info box
3982
var debugOutput = $('#session pre');
@@ -82,6 +125,16 @@ <h1>PowerTip Edge Case Tests</h1>
82125
<option value="red">Red</option>
83126
<option value="yellow">Yellow</option>
84127
</select>
128+
Tooltip Ancestor CSS Position:
129+
<select id="position-switcher">
130+
<option value="">Default</option>
131+
<option value="html-relative">HTML relative</option>
132+
<option value="html-fixed">HTML fixed</option>
133+
<option value="html-absolute">HTML absolute</option>
134+
<option value="body-relative">BODY relative</option>
135+
<option value="body-fixed">BODY fixed</option>
136+
<option value="body-absolute">BODY absolute</option>
137+
</select>
85138
</p>
86139
</header>
87140
<section id="open-on-load">

0 commit comments

Comments
 (0)