Skip to content

Instantly share code, notes, and snippets.

@RupW
Created April 6, 2012 09:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RupW/2318497 to your computer and use it in GitHub Desktop.
Save RupW/2318497 to your computer and use it in GitHub Desktop.
Detect HTML5 checkbox indeterminate support storing result in jQuery.support namespace
/**
* 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);
@ciaowii
Copy link

ciaowii commented Mar 10, 2016

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment