Created
March 5, 2014 09:40
-
-
Save Nemo64/9364173 to your computer and use it in GitHub Desktop.
jquery-ui datepicker if no support for type="date"
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
// 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