|
|
| Line 1: |
Line 1: |
| /* Any JavaScript here will be loaded for all users on every page load. */ | | /* Any JavaScript here will be loaded for all users on every page load. */ |
|
| |
| $(function() {
| |
| var ascStartDate = new Date (1999, 7, 6);
| |
| var anStartDate = new Date (1880, 1, 8);
| |
| var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
| |
| var anMonths = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VII', 'IX', 'X', 'XI', 'XII', 'XIII', 'XIV', 'XV'];
| |
|
| |
| function monthDiff(d1, d2) {
| |
| return (d2.getFullYear() - d1.getFullYear()) * 12 + d2.getMonth() - d1.getMonth();
| |
| }
| |
|
| |
| function midnight(date) {
| |
| date.setHours(0);
| |
| date.setMinutes(0);
| |
| date.setSeconds(0);
| |
| date.setMilliseconds(0);
| |
| return date;
| |
| }
| |
|
| |
| function dateToAsc(date)
| |
| {
| |
| return (Math.floor((date - ascStartDate) / 86400000));
| |
| }
| |
|
| |
| function ascToDate(ascYear)
| |
| {
| |
| var date = new Date(ascStartDate.getTime() + (ascYear + 1) * 86400000);
| |
| midnight(date);
| |
| return date;
| |
| }
| |
| function dateToAn(date)
| |
| {
| |
| return {year: monthDiff(anStartDate, date) + 1,
| |
| month: Math.floor((date.getDate() - 1) / 2),
| |
| period: (date.getDate() - 1) % 2
| |
| };
| |
| }
| |
|
| |
| function anYearTitle(anYear) {
| |
| var dateOfAnYearStart = midnight(new Date(anStartDate.getFullYear() + anYear / 12, anYear % 12, 1));
| |
| var dateOfAnYearEnd = midnight(new Date(anStartDate.getFullYear() + anYear / 12, anYear % 12 + 1, -1));
| |
| return months[dateOfAnYearStart.getMonth()] + ' ' + dateOfAnYearStart.getFullYear() + ', or ' + dateToAsc(dateOfAnYearStart) + ' - ' + dateToAsc(dateOfAnYearEnd) + ' ASC';
| |
| }
| |
|
| |
| function ascYearTitle(ascYear) {
| |
| var date = ascToDate(ascYear);
| |
| var anDate = dateToAn(date);
| |
|
| |
| return date.toLocaleDateString() + ', or ' + anMonths[anDate.month] + '.' + anDate.year + ' ' + (anDate.period == 0 ? '(1..12)' : '(13..24)');
| |
| }
| |
|
| |
| $('.micraswiki-an-year').each(function() {
| |
| var $this = $(this);
| |
| var year = parseInt($this.data('an-year') == undefined ? $this.html() : $this.data('an-year'));
| |
| if (year != undefined) {
| |
| $this.wrap($('<abbr title="' + anYearTitle(year) + '" />'));
| |
| }
| |
| });
| |
|
| |
| $('.micraswiki-asc-year').each(function() {
| |
| var $this = $(this);
| |
| var year = parseInt($this.data('asc-year') == undefined ? $this.html() : $this.data('asc-year'));
| |
| if (year != undefined) {
| |
| $this.wrap($('<abbr title="' + ascYearTitle(year) + '" />'));
| |
| }
| |
| });
| |
| });
| |