MediaWiki:RefToolbar.js: Difference between revisions
Content deleted Content added
lookup script moved to labs |
support formatting incomplete dates |
||
Line 516:
if (type === 'doi' && (data.fulldate || $('.'+cl+'month').size() == 0)) {
var DT = new Date(data.date);
var useday = /\d{4}-\d{2}-\d{2}/.test(data.date);
$('.'+cl+'date').val(CiteTB.formatDate(DT));▼
var usemonth = /\d{4}-\d{2}/.test(data.date);
▲ $('.'+cl+'date').val(CiteTB.formatDate(DT, useday, usemonth));
} else if (type === 'doi' && !data.fulldate) {
if (data.month) { // lookup.php sets month to false if it isn't provided
Line 550 ⟶ 552:
};
CiteTB.formatDate = function(DT, useday, usemonth) {
if (typeof useday == "undefined") {
useday = true;
}
if (typeof usemonth == "undefined") {
usemonth = true;
}
var datestr = CiteTB.getOption('date format');
var zmonth = '';
Line 568 ⟶ 576:
}
date = date.toString();
if (useday) {
datestr = datestr.replace('<date>', date); datestr = datestr.replace('<
} else {
datestr = datestr.replace('<zdate>', zdate);▼
datestr = datestr.replace('<
datestr = datestr.replace('<
}
if (usemonth) {
datestr = datestr.replace('<month>', month);
datestr = datestr.replace('<zmonth>', zmonth);
datestr = datestr.replace('<monthname>', CiteTB.getOption('months')[DT.getUTCMonth()]);
} else {
datestr = datestr.replace('<zmonth>', '');
datestr = datestr.replace('<monthname>', '');
}
datestr = datestr.replace('<year>', DT.getUTCFullYear().toString());
return datestr.replace(/^[ \/\-\,\.]*(.*?)[ \/\-\,\.]*$/g, "$1"); // Cleanup any dangling spaces or connectors that might result from omitting date/month
};
|