Show localized date over top of date input

Also move datepicker logic into edit_books.js and edit_books.js below the datepicker file declaration(s)
This commit is contained in:
Jonathan Rehm
2017-07-18 08:51:52 -07:00
parent 36c2b35588
commit 5715d27c97
2 changed files with 22 additions and 10 deletions

View File

@ -1,8 +1,23 @@
/**
* Created by SpeedProg on 05.04.2015.
*/
/* global Bloodhound */
/* global Bloodhound, language */
if (!Modernizr.inputtypes.date) {
$('#pubdate').datepicker({
format: 'yyyy-mm-dd',
language: language
}).on('change', function () {
// Show localized date over top of the standard YYYY-MM-DD date
let pubDate, results;
if ((results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value))) { // YYYY-MM-DD
pubDate = new Date(results[1], parseInt(results[2], 10)-1, results[3]) || new Date(this.value);
}
$('#fake_pubdate')
.val(pubDate.toLocaleDateString(language))
.removeClass('hidden');
}).trigger('change');
}
/*
Takes a prefix, query typeahead callback, Bloodhound typeahead adapter