X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.widgets%2Fmw.widgets.CalendarWidget.js;h=d519c0df54c73d8cbdf23c17033bc62d2fa7203b;hb=f8659ae6ea90d7bc8ce28bfc1caa56153878836f;hp=9016e895b94c575634a63c54ea7b5238dc729def;hpb=d00393687300d2e2111040c48e6b5e811ea9296d;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.widgets/mw.widgets.CalendarWidget.js b/resources/src/mediawiki.widgets/mw.widgets.CalendarWidget.js index 9016e895b9..d519c0df54 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.CalendarWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.CalendarWidget.js @@ -10,6 +10,8 @@ /** * Creates an mw.widgets.CalendarWidget object. * + * You will most likely want to use mw.widgets.DateInputWidget instead of CalendarWidget directly. + * * @class * @extends OO.ui.Widget * @mixins OO.ui.mixin.TabIndexedElement @@ -17,8 +19,9 @@ * @constructor * @param {Object} [config] Configuration options * @cfg {string} [precision='day'] Date precision to use, 'day' or 'month' - * @cfg {string|null} [date=null] Day or month date (depending on `precision`), in the - * format 'YYYY-MM-DD' or 'YYYY-MM'. When null, defaults to current date. + * @cfg {string|null} [date=null] Day or month date (depending on `precision`), in the format + * 'YYYY-MM-DD' or 'YYYY-MM'. When null, the calendar will show today's date, but not select + * it. */ mw.widgets.CalendarWidget = function MWWCalendarWidget( config ) { // Config initialization @@ -156,6 +159,7 @@ if ( this.displayLayer === this.previousDisplayLayer && + this.date === this.previousDate && this.previousMoment && this.previousMoment.isSame( this.moment, this.precision === 'month' ? 'month' : 'day' ) ) { @@ -169,7 +173,7 @@ } this.$oldBody = this.$body.addClass( 'mw-widget-calendarWidget-old-body' ); // Clone without children - this.$body = $( this.$body[0].cloneNode( false ) ) + this.$body = $( this.$body[ 0 ].cloneNode( false ) ) .removeClass( 'mw-widget-calendarWidget-old-body' ) .toggleClass( 'mw-widget-calendarWidget-body-month', this.displayLayer === 'month' ) .toggleClass( 'mw-widget-calendarWidget-body-year', this.displayLayer === 'year' ) @@ -299,12 +303,14 @@ this.previousMoment = moment( this.moment ); this.previousDisplayLayer = this.displayLayer; + this.previousDate = this.date; this.$body.on( 'click', this.onBodyClick.bind( this ) ); }; /** * Handle click events on the "up" button, switching to less precise view. + * * @private */ mw.widgets.CalendarWidget.prototype.onUpButtonClick = function () { @@ -322,6 +328,7 @@ /** * Handle click events on the "previous" button, switching to previous pane. + * * @private */ mw.widgets.CalendarWidget.prototype.onPrevButtonClick = function () { @@ -341,6 +348,7 @@ /** * Handle click events on the "next" button, switching to next pane. + * * @private */ mw.widgets.CalendarWidget.prototype.onNextButtonClick = function () { @@ -362,6 +370,7 @@ * Handle click events anywhere in the body of the widget, which contains the matrix of days, * months or years to choose. Maybe change the pane or switch to more precise view, depending on * what gets clicked. + * * @private */ mw.widgets.CalendarWidget.prototype.onBodyClick = function ( e ) { @@ -396,13 +405,19 @@ * Set the date. * * @param {string|null} [date=null] Day or month date, in the format 'YYYY-MM-DD' or 'YYYY-MM'. - * When null, defaults to current date. When invalid, the date is not changed. + * When null, the calendar will show today's date, but not select it. When invalid, the date + * is not changed. */ mw.widgets.CalendarWidget.prototype.setDate = function ( date ) { var mom = date !== null ? moment( date, this.getDateFormat() ) : moment(); if ( mom.isValid() ) { this.moment = mom; - this.setDateFromMoment(); + if ( date !== null ) { + this.setDateFromMoment(); + } else if ( this.date !== null ) { + this.date = null; + this.emit( 'change', this.date ); + } this.displayLayer = this.getDisplayLayers()[ 0 ]; this.updateUI(); } @@ -436,7 +451,7 @@ * Get current date, in the format 'YYYY-MM-DD' or 'YYYY-MM', depending on precision. Digits will * not be localised. * - * @returns {string} Date string + * @returns {string|null} Date string */ mw.widgets.CalendarWidget.prototype.getDate = function () { return this.date;