Created
December 9, 2013 07:30
-
-
Save and80506/7868603 to your computer and use it in GitHub Desktop.
jQuery.support 实现
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Support testing using an element | |
* @param {Function} fn Passed the created div and expects a boolean result | |
*/ | |
function assert( fn ) { | |
var div = document.createElement("div"); | |
try { | |
return !!fn( div ); | |
} catch (e) { | |
return false; | |
} finally { | |
// Remove from its parent by default | |
if ( div.parentNode ) { | |
div.parentNode.removeChild( div ); | |
} | |
// release memory in IE | |
div = null; | |
} | |
} | |
// Check if getElementsByClassName can be trusted | |
support.getElementsByClassName = assert(function( div ) { | |
div.innerHTML = "<div class='a'></div><div class='a i'></div>"; | |
// Support: Safari<4 | |
// Catch class over-caching | |
div.firstChild.className = "i"; | |
// Support: Opera<10 | |
// Catch gEBCN failure to find non-leading classes | |
return div.getElementsByClassName("i").length === 2; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment