| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
mw.echo.ui.DatedSubGroupListWidget = function MwEchoUiDatedSubGroupListWidget( controller, listModel, config ) { |
| 15 |
const now = moment(), |
| 16 |
$primaryDate = $( '<span>' ) |
| 17 |
.addClass( 'mw-echo-ui-datedSubGroupListWidget-title-primary' ), |
| 18 |
$secondaryDate = $( '<span>' ) |
| 19 |
.addClass( 'mw-echo-ui-datedSubGroupListWidget-title-secondary' ), |
| 20 |
$title = $( '<h2>' ) |
| 21 |
.addClass( 'mw-echo-ui-datedSubGroupListWidget-title' ) |
| 22 |
.append( $primaryDate, $secondaryDate ); |
| 23 |
|
| 24 |
|
| 25 |
mw.echo.ui.DatedSubGroupListWidget.super.call( this, controller, listModel, Object.assign( { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
sortingCallback: function ( a, b ) { |
| 30 |
|
| 31 |
if ( b.getTimestamp() < a.getTimestamp() ) { |
| 32 |
return -1; |
| 33 |
} else if ( b.getTimestamp() > a.getTimestamp() ) { |
| 34 |
return 1; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
return b.getId() - a.getId(); |
| 39 |
} |
| 40 |
}, config ) ); |
| 41 |
|
| 42 |
|
| 43 |
const stringTimestamp = moment.utc( this.model.getTimestamp() ).local().format( 'YYYY-MM-DD' ); |
| 44 |
const momentTimestamp = moment( stringTimestamp ); |
| 45 |
const diff = now.diff( momentTimestamp, 'weeks' ); |
| 46 |
const fullDate = momentTimestamp.format( 'LL' ); |
| 47 |
|
| 48 |
$primaryDate.text( fullDate ); |
| 49 |
if ( diff === 0 ) { |
| 50 |
$secondaryDate.text( fullDate ); |
| 51 |
momentTimestamp.locale( 'echo-shortRelativeTime' ); |
| 52 |
$primaryDate.text( momentTimestamp.calendar() ); |
| 53 |
} |
| 54 |
|
| 55 |
this.title.setLabel( $title ); |
| 56 |
|
| 57 |
this.$element |
| 58 |
.addClass( 'mw-echo-ui-datedSubGroupListWidget' ); |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
OO.inheritClass( mw.echo.ui.DatedSubGroupListWidget, mw.echo.ui.SubGroupListWidget ); |
| 64 |
}() ); |