mirror of
https://github.com/jquery/jquery.git
synced 2026-04-20 03:01:22 -04:00
85
src/css.js
85
src/css.js
@@ -1,12 +1,21 @@
|
||||
var curCSS, iframe,
|
||||
define([
|
||||
"./core",
|
||||
"./var/pnum",
|
||||
"./css/var/cssExpand",
|
||||
"./css/var/isHidden",
|
||||
"./css/defaultDisplay",
|
||||
"./data/var/data_priv",
|
||||
"./core/swap",
|
||||
"./selector" // contains
|
||||
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, data_priv ) {
|
||||
var curCSS,
|
||||
// swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
|
||||
// see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
|
||||
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
|
||||
rmargin = /^margin/,
|
||||
rnumsplit = new RegExp( "^(" + core_pnum + ")(.*)$", "i" ),
|
||||
rnumnonpx = new RegExp( "^(" + core_pnum + ")(?!px)[a-z%]+$", "i" ),
|
||||
rrelNum = new RegExp( "^([+-])=(" + core_pnum + ")", "i" ),
|
||||
elemdisplay = { BODY: "block" },
|
||||
rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
|
||||
rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" ),
|
||||
rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
|
||||
|
||||
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
|
||||
cssNormalTransform = {
|
||||
@@ -14,7 +23,6 @@ var curCSS, iframe,
|
||||
fontWeight: 400
|
||||
},
|
||||
|
||||
cssExpand = [ "Top", "Right", "Bottom", "Left" ],
|
||||
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
|
||||
|
||||
// return a css property mapped to a potentially vendor prefixed property
|
||||
@@ -40,13 +48,6 @@ function vendorPropName( style, name ) {
|
||||
return origName;
|
||||
}
|
||||
|
||||
function isHidden( elem, el ) {
|
||||
// isHidden might be called from jQuery#filter function;
|
||||
// in that case, element will be second argument
|
||||
elem = el || elem;
|
||||
return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
|
||||
}
|
||||
|
||||
// NOTE: we've included the "window" in window.getComputedStyle
|
||||
// because jsdom on node.js will break without it.
|
||||
function getStyles( elem ) {
|
||||
@@ -78,7 +79,7 @@ function showHide( elements, show ) {
|
||||
// in a stylesheet to whatever the default browser style is
|
||||
// for such an element
|
||||
if ( elem.style.display === "" && isHidden( elem ) ) {
|
||||
values[ index ] = data_priv.access( elem, "olddisplay", css_defaultDisplay(elem.nodeName) );
|
||||
values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -414,46 +415,6 @@ function getWidthOrHeight( elem, name, extra ) {
|
||||
) + "px";
|
||||
}
|
||||
|
||||
// Try to determine the default display value of an element
|
||||
function css_defaultDisplay( nodeName ) {
|
||||
var doc = document,
|
||||
display = elemdisplay[ nodeName ];
|
||||
|
||||
if ( !display ) {
|
||||
display = actualDisplay( nodeName, doc );
|
||||
|
||||
// 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 );
|
||||
|
||||
// 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.close();
|
||||
|
||||
display = actualDisplay( nodeName, doc );
|
||||
iframe.detach();
|
||||
}
|
||||
|
||||
// Store the correct default display
|
||||
elemdisplay[ nodeName ] = display;
|
||||
}
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
// Called ONLY from within css_defaultDisplay
|
||||
function actualDisplay( name, doc ) {
|
||||
var elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
|
||||
display = jQuery.css( elem[0], "display" );
|
||||
elem.remove();
|
||||
return display;
|
||||
}
|
||||
|
||||
jQuery.each([ "height", "width" ], function( i, name ) {
|
||||
jQuery.cssHooks[ name ] = {
|
||||
get: function( elem, computed, extra ) {
|
||||
@@ -504,6 +465,7 @@ jQuery(function() {
|
||||
// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
|
||||
// getComputedStyle returns percent when specified for top/left/bottom/right
|
||||
// rather than make the css module depend on the offset module, we just check for it here
|
||||
// TODO: Optional dependency on offset
|
||||
if ( !jQuery.support.pixelPosition && jQuery.fn.position ) {
|
||||
jQuery.each( [ "top", "left" ], function( i, prop ) {
|
||||
jQuery.cssHooks[ prop ] = {
|
||||
@@ -519,21 +481,8 @@ jQuery(function() {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if ( jQuery.expr && jQuery.expr.filters ) {
|
||||
jQuery.expr.filters.hidden = function( elem ) {
|
||||
// Support: Opera <= 12.12
|
||||
// Opera reports offsetWidths and offsetHeights less than zero on some elements
|
||||
return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
|
||||
};
|
||||
|
||||
jQuery.expr.filters.visible = function( elem ) {
|
||||
return !jQuery.expr.filters.hidden( elem );
|
||||
};
|
||||
}
|
||||
|
||||
// These hooks are used by animate to expand properties
|
||||
jQuery.each({
|
||||
margin: "",
|
||||
@@ -561,3 +510,5 @@ jQuery.each({
|
||||
jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user