Created
April 6, 2012 09:35
-
-
Save RupW/2318497 to your computer and use it in GitHub Desktop.
Detect HTML5 checkbox indeterminate support storing result in jQuery.support namespace
This file contains hidden or 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
/** | |
* jQuery.support.checkboxIndeterminate | |
* https://github.com/RupW | |
* Tests for HTML 5 checkbox 'indeterminate' property | |
* http://www.w3.org/TR/html5/the-input-element.html#dom-input-indeterminate | |
* http://www.w3.org/TR/html5/number-state.html#checkbox-state | |
* | |
* Released under the same license as jQuery | |
* http://docs.jquery.com/License | |
* | |
* Usage: | |
* if ($.support.checkboxIndeterminate) { ... } | |
* | |
* 2011-12-12 Initial version; runs test at load time | |
* 2012-04-06 Added exception for Windows Safari | |
*/ | |
(function($) { | |
if (typeof($.support) === 'undefined') { $.support = {}; } | |
if (typeof($.support.checkboxIndeterminate) === 'undefined') { | |
var supportsIndeterminate = false; | |
try { | |
// Exception: Safari for Windows supports the indeterminate property but | |
// it's unusable - it renders indeterminate checkboxes identically to | |
// checked checkboxes. | |
// Reported December 2011 and verified still-broken in 5.1.5. | |
var n = window.navigator; | |
function navcontains(key, value) { return (typeof(n[key]) === 'string') && (n[key].indexOf(value) >= 0); } | |
var isSafariWin = n && navcontains('vendor', 'Apple') && navcontains('platform', 'Win') && navcontains('userAgent', 'Safari'); | |
if (!isSafariWin) { | |
// Test for the property on a newly-created input element | |
// Does not need to be typed checkbox or attached to the DOM | |
var newInput = document.createElement('input'); | |
supportsIndeterminate = ('indeterminate' in newInput); | |
} | |
} catch (e) { } | |
$.support.checkboxIndeterminate = supportsIndeterminate; | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi I need this to run in my project, how will I insert this on my code? Baiscally, I have the JSTree plugin and initiate it on $(function ({..}).. thanks for your help!