| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
const RcTopSectionWidget = function MwRcfiltersUiRcTopSectionWidget( |
| 13 |
savedLinksListWidget, $topLinks, config |
| 14 |
) { |
| 15 |
const topLinksCookieName = 'rcfilters-toplinks-collapsed-state', |
| 16 |
topLinksCookie = mw.cookie.get( topLinksCookieName ), |
| 17 |
topLinksCookieValue = topLinksCookie || 'collapsed', |
| 18 |
widget = this; |
| 19 |
|
| 20 |
config = config || {}; |
| 21 |
|
| 22 |
|
| 23 |
RcTopSectionWidget.super.call( this, config ); |
| 24 |
|
| 25 |
this.$topLinks = $topLinks; |
| 26 |
|
| 27 |
const toplinksTitle = new OO.ui.ButtonWidget( { |
| 28 |
framed: false, |
| 29 |
indicator: topLinksCookieValue === 'collapsed' ? 'down' : 'up', |
| 30 |
flags: [ 'progressive' ], |
| 31 |
label: mw.message( 'rcfilters-other-review-tools' ).parseDom() |
| 32 |
} ); |
| 33 |
|
| 34 |
this.$topLinks |
| 35 |
.makeCollapsible( { |
| 36 |
collapsed: topLinksCookieValue === 'collapsed', |
| 37 |
$customTogglers: toplinksTitle.$element |
| 38 |
} ) |
| 39 |
.on( 'beforeExpand.mw-collapsible', () => { |
| 40 |
mw.cookie.set( topLinksCookieName, 'expanded' ); |
| 41 |
toplinksTitle.setIndicator( 'up' ); |
| 42 |
widget.switchTopLinks( 'expanded' ); |
| 43 |
} ) |
| 44 |
.on( 'beforeCollapse.mw-collapsible', () => { |
| 45 |
mw.cookie.set( topLinksCookieName, 'collapsed' ); |
| 46 |
toplinksTitle.setIndicator( 'down' ); |
| 47 |
widget.switchTopLinks( 'collapsed' ); |
| 48 |
} ); |
| 49 |
|
| 50 |
this.$topLinks.find( '.mw-recentchanges-toplinks-title' ) |
| 51 |
.replaceWith( toplinksTitle.$element.removeAttr( 'tabIndex' ) ); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
this.$top = $( '<div>' ) |
| 56 |
.addClass( 'mw-rcfilters-ui-rcTopSectionWidget-topLinks-top' ); |
| 57 |
this.$tableTopLinks = $( '<div>' ) |
| 58 |
.addClass( 'mw-rcfilters-ui-cell' ) |
| 59 |
.addClass( 'mw-rcfilters-ui-rcTopSectionWidget-topLinks-table' ); |
| 60 |
|
| 61 |
|
| 62 |
this.$element |
| 63 |
.addClass( 'mw-rcfilters-ui-rcTopSectionWidget' ) |
| 64 |
.append( |
| 65 |
$( '<div>' ) |
| 66 |
.addClass( 'mw-rcfilters-ui-table' ) |
| 67 |
.append( |
| 68 |
$( '<div>' ) |
| 69 |
.addClass( 'mw-rcfilters-ui-row' ) |
| 70 |
.append( |
| 71 |
this.$tableTopLinks, |
| 72 |
$( '<div>' ) |
| 73 |
.addClass( 'mw-rcfilters-ui-table-placeholder' ) |
| 74 |
.addClass( 'mw-rcfilters-ui-cell' ), |
| 75 |
!mw.user.isAnon() ? |
| 76 |
$( '<div>' ) |
| 77 |
.addClass( 'mw-rcfilters-ui-cell' ) |
| 78 |
.addClass( 'mw-rcfilters-ui-rcTopSectionWidget-savedLinks' ) |
| 79 |
.append( savedLinksListWidget.$element ) : |
| 80 |
null |
| 81 |
) |
| 82 |
) |
| 83 |
); |
| 84 |
|
| 85 |
|
| 86 |
$( '.mw-rcfilters-head' ).before( this.$top ); |
| 87 |
|
| 88 |
|
| 89 |
widget.switchTopLinks( topLinksCookieValue ); |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
OO.inheritClass( RcTopSectionWidget, OO.ui.Widget ); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
RcTopSectionWidget.prototype.switchTopLinks = function ( state ) { |
| 103 |
state = state || 'expanded'; |
| 104 |
|
| 105 |
if ( state === 'expanded' ) { |
| 106 |
this.$top.append( this.$topLinks ); |
| 107 |
} else { |
| 108 |
this.$tableTopLinks.append( this.$topLinks ); |
| 109 |
} |
| 110 |
this.$topLinks.toggleClass( 'mw-recentchanges-toplinks-collapsed', state === 'collapsed' ); |
| 111 |
}; |
| 112 |
|
| 113 |
module.exports = RcTopSectionWidget; |