Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
夏彬
jquery
Commits
a2534300
Commit
a2534300
authored
Sep 17, 2013
by
Oleg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #12723 and simplification and optmization of defaultDisplay helper
parent
642e9a45
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
19 deletions
+34
-19
defaultDisplay.js
src/css/defaultDisplay.js
+20
-9
css.js
test/unit/css.js
+14
-10
No files found.
src/css/defaultDisplay.js
View file @
a2534300
...
...
@@ -4,17 +4,28 @@ define([
],
function
(
jQuery
)
{
var
iframe
,
elemdisplay
=
{
BODY
:
"block"
};
elemdisplay
=
{};
/**
* Retrieve the actual display of a element
* @param {String} name nodeName of the element
* @param {Object} doc Document object
*/
// Called only from within defaultDisplay
function
actualDisplay
(
name
,
doc
)
{
var
elem
=
jQuery
(
doc
.
createElement
(
name
)
).
appendTo
(
doc
.
body
),
display
=
jQuery
.
css
(
elem
[
0
],
"display"
);
elem
.
remove
();
// getDefaultComputedStyle might be reliably used only on attached element
display
=
window
.
getDefaultComputedStyle
?
// Use of this method is a temporary fix (more like optmization) until something better comes along,
// since it was removed from specification and supported only in FF
window
.
getDefaultComputedStyle
(
elem
[
0
]
).
display
:
jQuery
.
css
(
elem
[
0
],
"display"
);
// We don't have any data stored on the element,
// so use "detach" method as fast way to get rid of the element
elem
.
detach
();
return
display
;
}
...
...
@@ -31,15 +42,15 @@ function defaultDisplay( nodeName ) {
// If the simple way fails, read from inside an iframe
if
(
display
===
"none"
||
!
display
)
{
// Use the already-created iframe if possible
iframe
=
(
iframe
||
jQuery
(
"<iframe frameborder='0' width='0' height='0'/>"
)
.
css
(
"cssText"
,
"display:block !important"
)
).
appendTo
(
doc
.
documentElement
);
iframe
=
(
iframe
||
jQuery
(
"<iframe frameborder='0' width='0' height='0'/>"
)).
appendTo
(
doc
.
documentElement
);
// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
doc
=
(
iframe
[
0
].
contentWindow
||
iframe
[
0
].
contentDocument
).
document
;
doc
.
write
(
"<!doctype html><html><body>"
);
doc
=
iframe
[
0
].
contentDocument
;
// Support: IE
doc
.
write
();
doc
.
close
();
display
=
actualDisplay
(
nodeName
,
doc
);
...
...
test/unit/css.js
View file @
a2534300
...
...
@@ -543,21 +543,25 @@ test( "show() resolves correct default display for detached nodes", function(){
span
.
remove
();
});
test
(
"show() resolves correct default display #10227"
,
function
()
{
expect
(
2
);
test
(
"show() resolves correct default display #10227"
,
4
,
function
()
{
var
html
=
jQuery
(
document
.
documentElement
),
body
=
jQuery
(
"body"
);
var
body
=
jQuery
(
"body"
);
body
.
append
(
"<p id='ddisplay'>a<style>body{display:none}</style></p>"
);
body
.
append
(
"<p class='ddisplay'>a<style>body{display:none}</style></p>"
);
equal
(
body
.
css
(
"display"
),
"none"
,
"Initial display: none"
);
equal
(
body
.
css
(
"display"
),
"none"
,
"Initial display
for body element
: none"
);
body
.
show
();
equal
(
body
.
css
(
"display"
),
"block"
,
"Correct display: block"
);
equal
(
body
.
css
(
"display"
),
"block"
,
"Correct display for body element: block"
);
body
.
append
(
"<p class='ddisplay'>a<style>html{display:none}</style></p>"
);
equal
(
html
.
css
(
"display"
),
"none"
,
"Initial display for html element: none"
);
html
.
show
();
equal
(
html
.
css
(
"display"
),
"block"
,
"Correct display for html element: block"
);
jQuery
(
"#ddisplay"
).
remove
();
QUnit
.
expectJqData
(
body
[
0
],
"olddisplay"
);
jQuery
(
".ddisplay"
).
remove
();
});
test
(
"show() resolves correct default display when iframe display:none #12904"
,
function
()
{
...
...
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