Skip to content

Instantly share code, notes, and snippets.

@Nemo64
Created March 5, 2014 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nemo64/9364173 to your computer and use it in GitHub Desktop.
Save Nemo64/9364173 to your computer and use it in GitHub Desktop.
jquery-ui datepicker if no support for type="date"
// check for support of a datepicker
// assume that the browser must be able to parse the date if it is of type date
$.support.datepicker = (function () {
var el = document.createElement('input'), notADateValue = 'not-a-date';
el.setAttribute('type', 'date');
el.setAttribute('value', notADateValue);
return !(el.value === notADateValue);
})();
// if not supported jquery-ui to the rescue
if (! $.support.datepicker) {
$(document).on("ready update.datepicker", function (e) {
var $target = $(e.target);
var $datepicker = $target.find("input[type=date]");
$datepicker.each(function () {
var $this = $(this);
var data = $this.data();
for (var key in data) {
data[$.camelCase(key)] = data[key];
}
$this.datepicker(data);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment