Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
aa479892
Commit
aa479892
authored
9 years ago
by
F A T
Browse files
Options
Download
Plain Diff
Merge pull request #16152 from jarthod/tooltip-placement-viewport-fix
Tooltip/popover: Fix auto placement to use viewport
parents
cc8567d7
5921724d
4 merge requests
!28721
Hot test
,
!16605
Test pull please ignore
,
!22103
test
,
!25326
Adjust examples
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/tests/unit/tooltip.js
+33
-12
js/tests/unit/tooltip.js
js/tooltip.js
+5
-6
js/tooltip.js
with
38 additions
and
18 deletions
+38
-18
js/tests/unit/tooltip.js
+
33
-
12
View file @
aa479892
...
...
@@ -376,23 +376,19 @@ $(function () {
assert
.
strictEqual
(
$
(
'
.tooltip
'
).
length
,
0
,
'
tooltip removed from dom
'
)
})
QUnit
.
test
(
'
should be placed dynamically with the dynamic placement option
'
,
function
(
assert
)
{
QUnit
.
test
(
'
should be placed dynamically
to viewport
with the dynamic placement option
'
,
function
(
assert
)
{
assert
.
expect
(
6
)
var
$style
=
$
(
'
<style>
a
[rel="tooltip"] {
display: inline-block; position: absolute; } </style>
'
)
var
$style
=
$
(
'
<style>
div
[rel="tooltip"] {
position: absolute; } #qunit-fixture { top: inherit; left: inherit } </style>
'
).
appendTo
(
'
head
'
)
var
$container
=
$
(
'
<div/>
'
)
.
css
({
position
:
'
absolute
'
,
overflow
:
'
hidden
'
,
width
:
600
,
height
:
400
,
top
:
0
,
left
:
0
position
:
'
relative
'
,
height
:
'
100%
'
})
.
appendTo
(
document
.
body
)
.
appendTo
(
'
#qunit-fixture
'
)
var
$topTooltip
=
$
(
'
<div style="left: 0; top: 0;" rel="tooltip" title="Top tooltip">Top Dynamic Tooltip</div>
'
)
.
appendTo
(
$container
)
.
bootstrapTooltip
({
placement
:
'
auto
'
})
.
bootstrapTooltip
({
placement
:
'
auto
'
,
viewport
:
'
#qunit-fixture
'
})
$topTooltip
.
bootstrapTooltip
(
'
show
'
)
assert
.
ok
(
$
(
'
.tooltip
'
).
is
(
'
.bottom
'
),
'
top positioned tooltip is dynamically positioned to bottom
'
)
...
...
@@ -402,7 +398,7 @@ $(function () {
var
$rightTooltip
=
$
(
'
<div style="right: 0;" rel="tooltip" title="Right tooltip">Right Dynamic Tooltip</div>
'
)
.
appendTo
(
$container
)
.
bootstrapTooltip
({
placement
:
'
right auto
'
})
.
bootstrapTooltip
({
placement
:
'
right auto
'
,
viewport
:
'
#qunit-fixture
'
})
$rightTooltip
.
bootstrapTooltip
(
'
show
'
)
assert
.
ok
(
$
(
'
.tooltip
'
).
is
(
'
.left
'
),
'
right positioned tooltip is dynamically positioned left
'
)
...
...
@@ -412,7 +408,7 @@ $(function () {
var
$leftTooltip
=
$
(
'
<div style="left: 0;" rel="tooltip" title="Left tooltip">Left Dynamic Tooltip</div>
'
)
.
appendTo
(
$container
)
.
bootstrapTooltip
({
placement
:
'
auto left
'
})
.
bootstrapTooltip
({
placement
:
'
auto left
'
,
viewport
:
'
#qunit-fixture
'
})
$leftTooltip
.
bootstrapTooltip
(
'
show
'
)
assert
.
ok
(
$
(
'
.tooltip
'
).
is
(
'
.right
'
),
'
left positioned tooltip is dynamically positioned right
'
)
...
...
@@ -450,6 +446,31 @@ $(function () {
$styles
.
remove
()
})
QUnit
.
test
(
'
should position tip on top if viewport has enough space and is not parent
'
,
function
(
assert
)
{
assert
.
expect
(
2
)
var
styles
=
'
<style>
'
+
'
#section { height: 300px; border: 1px solid red; margin-top: 100px; }
'
+
'
div[rel="tooltip"] { width: 150px; border: 1px solid blue; }
'
+
'
</style>
'
var
$styles
=
$
(
styles
).
appendTo
(
'
head
'
)
var
$container
=
$
(
'
<div id="section"/>
'
).
appendTo
(
'
#qunit-fixture
'
)
var
$target
=
$
(
'
<div rel="tooltip" title="tip"/>
'
)
.
appendTo
(
$container
)
.
bootstrapTooltip
({
placement
:
'
auto top
'
,
viewport
:
'
#qunit-fixture
'
})
$target
.
bootstrapTooltip
(
'
show
'
)
assert
.
ok
(
$
(
'
.tooltip
'
).
is
(
'
.top
'
),
'
top positioned tooltip is dynamically positioned to top
'
)
$target
.
bootstrapTooltip
(
'
hide
'
)
assert
.
strictEqual
(
$
(
'
.tooltip
'
).
length
,
0
,
'
tooltip removed from dom
'
)
$styles
.
remove
()
})
QUnit
.
test
(
'
should position tip on bottom if the tip
\'
s dimension exceeds the viewport area and placement is "auto top"
'
,
function
(
assert
)
{
assert
.
expect
(
2
)
var
styles
=
'
<style>
'
...
...
This diff is collapsed.
Click to expand it.
js/tooltip.js
+
5
-
6
View file @
aa479892
...
...
@@ -193,13 +193,12 @@
if
(
autoPlace
)
{
var
orgPlacement
=
placement
var
$container
=
this
.
options
.
container
?
$
(
this
.
options
.
container
)
:
this
.
$element
.
parent
()
var
containerDim
=
this
.
getPosition
(
$container
)
var
viewportDim
=
this
.
getPosition
(
this
.
$viewport
)
placement
=
placement
==
'
bottom
'
&&
pos
.
bottom
+
actualHeight
>
container
Dim
.
bottom
?
'
top
'
:
placement
==
'
top
'
&&
pos
.
top
-
actualHeight
<
container
Dim
.
top
?
'
bottom
'
:
placement
==
'
right
'
&&
pos
.
right
+
actualWidth
>
container
Dim
.
width
?
'
left
'
:
placement
==
'
left
'
&&
pos
.
left
-
actualWidth
<
container
Dim
.
left
?
'
right
'
:
placement
=
placement
==
'
bottom
'
&&
pos
.
bottom
+
actualHeight
>
viewport
Dim
.
bottom
?
'
top
'
:
placement
==
'
top
'
&&
pos
.
top
-
actualHeight
<
viewport
Dim
.
top
?
'
bottom
'
:
placement
==
'
right
'
&&
pos
.
right
+
actualWidth
>
viewport
Dim
.
width
?
'
left
'
:
placement
==
'
left
'
&&
pos
.
left
-
actualWidth
<
viewport
Dim
.
left
?
'
right
'
:
placement
$tip
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets