Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap
Commits
142a9e4a
Commit
142a9e4a
authored
Dec 03, 2014
by
nakupanda
Committed by
Heinrich Fenkart
Feb 26, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modal: Apply any preexisting body padding again after closing
parent
033dbfd0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
7 deletions
+86
-7
js/modal.js
js/modal.js
+9
-7
js/tests/unit/modal.js
js/tests/unit/modal.js
+77
-0
No files found.
js/modal.js
View file @
142a9e4a
...
...
@@ -19,6 +19,7 @@
this
.
$element
=
$
(
element
)
this
.
$backdrop
=
null
this
.
isShown
=
null
this
.
originalBodyPad
=
null
this
.
scrollbarWidth
=
0
if
(
this
.
options
.
remote
)
{
...
...
@@ -259,11 +260,12 @@
Modal
.
prototype
.
setScrollbar
=
function
()
{
var
bodyPad
=
parseInt
((
this
.
$body
.
css
(
'
padding-right
'
)
||
0
),
10
)
this
.
originalBodyPad
=
document
.
body
.
style
.
paddingRight
||
''
if
(
this
.
bodyIsOverflowing
)
this
.
$body
.
css
(
'
padding-right
'
,
bodyPad
+
this
.
scrollbarWidth
)
}
Modal
.
prototype
.
resetScrollbar
=
function
()
{
this
.
$body
.
css
(
'
padding-right
'
,
''
)
this
.
$body
.
css
(
'
padding-right
'
,
this
.
originalBodyPad
)
}
Modal
.
prototype
.
measureScrollbar
=
function
()
{
// thx walsh
...
...
js/tests/unit/modal.js
View file @
142a9e4a
...
...
@@ -301,4 +301,81 @@ $(function () {
$toggleBtn
.
click
()
})
QUnit
.
test
(
'
should restore inline body padding after closing
'
,
function
(
assert
)
{
var
done
=
assert
.
async
()
var
originalBodyPad
=
0
var
$body
=
$
(
document
.
body
)
$body
.
css
(
'
padding-right
'
,
originalBodyPad
)
$
(
'
<div id="modal-test"/>
'
)
.
on
(
'
hidden.bs.modal
'
,
function
()
{
var
currentBodyPad
=
parseInt
(
$body
.
css
(
'
padding-right
'
),
10
)
assert
.
notStrictEqual
(
$body
.
attr
(
'
style
'
),
''
,
'
body has non-empty style attribute
'
)
assert
.
strictEqual
(
currentBodyPad
,
originalBodyPad
,
'
original body padding was not changed
'
)
$body
.
removeAttr
(
'
style
'
)
done
()
})
.
on
(
'
shown.bs.modal
'
,
function
()
{
$
(
this
).
bootstrapModal
(
'
hide
'
)
})
.
bootstrapModal
(
'
show
'
)
})
QUnit
.
test
(
'
should ignore values set via CSS when trying to restore body padding after closing
'
,
function
(
assert
)
{
var
done
=
assert
.
async
()
var
$body
=
$
(
document
.
body
)
var
$style
=
$
(
'
<style>body { padding-right: 42px; }</style>
'
).
appendTo
(
'
head
'
)
$
(
'
<div id="modal-test"/>
'
)
.
on
(
'
hidden.bs.modal
'
,
function
()
{
assert
.
ok
(
!
$body
.
attr
(
'
style
'
),
'
body does not have inline padding set
'
)
$style
.
remove
()
done
()
})
.
on
(
'
shown.bs.modal
'
,
function
()
{
$
(
this
).
bootstrapModal
(
'
hide
'
)
})
.
bootstrapModal
(
'
show
'
)
})
QUnit
.
test
(
'
should ignore other inline styles when trying to restore body padding after closing
'
,
function
(
assert
)
{
var
done
=
assert
.
async
()
var
$body
=
$
(
document
.
body
)
var
$style
=
$
(
'
<style>body { padding-right: 42px; }</style>
'
).
appendTo
(
'
head
'
)
$body
.
css
(
'
color
'
,
'
red
'
)
$
(
'
<div id="modal-test"/>
'
)
.
on
(
'
hidden.bs.modal
'
,
function
()
{
assert
.
strictEqual
(
$body
[
0
].
style
.
paddingRight
,
''
,
'
body does not have inline padding set
'
)
assert
.
strictEqual
(
$body
[
0
].
style
.
color
,
'
red
'
,
'
body still has other inline styles set
'
)
$body
.
removeAttr
(
'
style
'
)
$style
.
remove
()
done
()
})
.
on
(
'
shown.bs.modal
'
,
function
()
{
$
(
this
).
bootstrapModal
(
'
hide
'
)
})
.
bootstrapModal
(
'
show
'
)
})
QUnit
.
test
(
'
should properly restore non-pixel inline body padding after closing
'
,
function
(
assert
)
{
var
done
=
assert
.
async
()
var
$body
=
$
(
document
.
body
)
$body
.
css
(
'
padding-right
'
,
'
5%
'
)
$
(
'
<div id="modal-test"/>
'
)
.
on
(
'
hidden.bs.modal
'
,
function
()
{
assert
.
strictEqual
(
$body
[
0
].
style
.
paddingRight
,
'
5%
'
,
'
body does not have inline padding set
'
)
$body
.
removeAttr
(
'
style
'
)
done
()
})
.
on
(
'
shown.bs.modal
'
,
function
()
{
$
(
this
).
bootstrapModal
(
'
hide
'
)
})
.
bootstrapModal
(
'
show
'
)
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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