mirror of
https://github.com/jquery/jquery.git
synced 2026-01-24 23:58:12 -05:00
141 lines
4.9 KiB
JavaScript
141 lines
4.9 KiB
JavaScript
jQuery.support = (function() {
|
|
|
|
var support, all, a, select, opt, input, fragment,
|
|
div = document.createElement("div");
|
|
|
|
// Setup
|
|
div.setAttribute( "className", "t" );
|
|
div.innerHTML = " <link/><table></table><a>a</a><input type='checkbox'/>";
|
|
|
|
// Support tests won't run in some limited or non-browser environments
|
|
all = div.getElementsByTagName("*");
|
|
a = div.getElementsByTagName("a")[ 0 ];
|
|
if ( !all || !a || !all.length ) {
|
|
return {};
|
|
}
|
|
|
|
// First batch of tests
|
|
select = document.createElement("select");
|
|
opt = select.appendChild( document.createElement("option") );
|
|
input = div.getElementsByTagName("input")[ 0 ];
|
|
|
|
a.style.cssText = "float:left;opacity:.5";
|
|
support = {
|
|
// Verify style float existence
|
|
// (IE uses styleFloat instead of cssFloat)
|
|
cssFloat: !!a.style.cssFloat,
|
|
|
|
// Check the default checkbox/radio value ("" on WebKit; "on" elsewhere)
|
|
checkOn: !!input.value,
|
|
|
|
// Must access the parent to make an option select properly
|
|
// Support: IE9, IE10
|
|
optSelected: opt.selected,
|
|
|
|
// jQuery.support.boxModel DEPRECATED in 1.8 since we don't support Quirks Mode
|
|
boxModel: document.compatMode === "CSS1Compat",
|
|
|
|
// Will be defined later
|
|
noCloneEvent: true,
|
|
reliableMarginRight: true,
|
|
boxSizingReliable: true,
|
|
pixelPosition: false
|
|
};
|
|
|
|
// Make sure checked status is properly cloned
|
|
input.checked = true;
|
|
support.noCloneChecked = input.cloneNode( true ).checked;
|
|
|
|
// Make sure that the options inside disabled selects aren't marked as disabled
|
|
// (WebKit marks them as disabled)
|
|
select.disabled = true;
|
|
support.optDisabled = !opt.disabled;
|
|
|
|
// Check if an input maintains its value after becoming a radio
|
|
input = document.createElement("input");
|
|
input.value = "t";
|
|
input.setAttribute( "type", "radio" );
|
|
support.radioValue = input.value === "t";
|
|
|
|
// #11217 - WebKit loses check when the name is after the checked attribute
|
|
input.setAttribute( "checked", "t" );
|
|
input.setAttribute( "name", "t" );
|
|
|
|
fragment = document.createDocumentFragment();
|
|
fragment.appendChild( input );
|
|
|
|
// Check if a disconnected checkbox will retain its checked
|
|
// value of true after appended to the DOM (IE6/7)
|
|
support.appendChecked = input.checked;
|
|
|
|
// WebKit doesn't clone checked state correctly in fragments
|
|
support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
|
|
|
|
// Support: IE<9
|
|
// Opera does not clone events (and typeof div.attachEvent === undefined).
|
|
// IE9-10 clones events bound via attachEvent, but they don't trigger with .click()
|
|
if ( div.attachEvent ) {
|
|
div.attachEvent( "onclick", function() {
|
|
support.noCloneEvent = false;
|
|
});
|
|
|
|
div.cloneNode( true ).click();
|
|
}
|
|
|
|
// Support: Firefox 17+
|
|
// Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP), test/csp.php
|
|
div.setAttribute( "onfocusin", "t" );
|
|
support.focusinBubbles = "onfocusin" in window || div.attributes.onfocusin.expando === false;
|
|
|
|
// Run tests that need a body at doc ready
|
|
jQuery(function() {
|
|
var container, marginDiv, tds,
|
|
divReset = "padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",
|
|
body = document.getElementsByTagName("body")[0];
|
|
|
|
if ( !body ) {
|
|
// Return for frameset docs that don't have a body
|
|
return;
|
|
}
|
|
|
|
container = document.createElement("div");
|
|
container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px";
|
|
|
|
// Check box-sizing and margin behavior
|
|
body.appendChild( container ).appendChild( div );
|
|
div.innerHTML = "";
|
|
div.style.cssText = "box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;";
|
|
support.boxSizing = ( div.offsetWidth === 4 );
|
|
support.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== 1 );
|
|
|
|
// Use window.getComputedStyle because jsdom on node.js will break without it.
|
|
if ( window.getComputedStyle ) {
|
|
support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
|
|
support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px";
|
|
|
|
// Check if div with explicit width and no margin-right incorrectly
|
|
// gets computed margin-right based on width of container. (#3333)
|
|
// Fails in WebKit before Feb 2011 nightlies
|
|
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
|
|
marginDiv = div.appendChild( document.createElement("div") );
|
|
marginDiv.style.cssText = div.style.cssText = divReset;
|
|
marginDiv.style.marginRight = marginDiv.style.width = "0";
|
|
div.style.width = "1px";
|
|
|
|
support.reliableMarginRight =
|
|
!parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight );
|
|
}
|
|
|
|
body.removeChild( container );
|
|
|
|
// Null elements to avoid leaks in IE
|
|
container = div = tds = marginDiv = null;
|
|
});
|
|
|
|
// Null elements to avoid leaks in IE
|
|
all = select = fragment = opt = a = input = null;
|
|
|
|
return support;
|
|
})();
|
|
|