2 * Top section (between page title and filters) on Special:Recentchanges.
4 * @class mw.rcfilters.ui.RcTopSectionWidget
6 * @extends OO.ui.Widget
8 * @param {mw.rcfilters.ui.SavedLinksListWidget} savedLinksListWidget
9 * @param {jQuery} $topLinks Content of the community-defined links
10 * @param {Object} [config] Configuration object
12 const RcTopSectionWidget = function MwRcfiltersUiRcTopSectionWidget(
13 savedLinksListWidget, $topLinks, config
15 const topLinksCookieName = 'rcfilters-toplinks-collapsed-state',
16 topLinksCookie = mw.cookie.get( topLinksCookieName ),
17 topLinksCookieValue = topLinksCookie || 'collapsed';
19 config = config || {};
22 RcTopSectionWidget.super.call( this, config );
24 this.$topLinks = $topLinks;
26 const toplinksTitle = new OO.ui.ButtonWidget( {
28 indicator: topLinksCookieValue === 'collapsed' ? 'down' : 'up',
29 flags: [ 'progressive' ],
30 label: mw.message( 'rcfilters-other-review-tools' ).parseDom()
35 collapsed: topLinksCookieValue === 'collapsed',
36 $customTogglers: toplinksTitle.$element
38 .on( 'beforeExpand.mw-collapsible', () => {
39 mw.cookie.set( topLinksCookieName, 'expanded' );
40 toplinksTitle.setIndicator( 'up' );
41 this.switchTopLinks( 'expanded' );
43 .on( 'beforeCollapse.mw-collapsible', () => {
44 mw.cookie.set( topLinksCookieName, 'collapsed' );
45 toplinksTitle.setIndicator( 'down' );
46 this.switchTopLinks( 'collapsed' );
49 this.$topLinks.find( '.mw-recentchanges-toplinks-title' )
50 .replaceWith( toplinksTitle.$element.removeAttr( 'tabIndex' ) );
52 // Create two positions for the toplinks to toggle between
53 // in the table (first cell) or up above it
54 this.$top = $( '<div>' )
55 .addClass( 'mw-rcfilters-ui-rcTopSectionWidget-topLinks-top' );
56 this.$tableTopLinks = $( '<div>' )
57 .addClass( 'mw-rcfilters-ui-cell' )
58 .addClass( 'mw-rcfilters-ui-rcTopSectionWidget-topLinks-table' );
62 .addClass( 'mw-rcfilters-ui-rcTopSectionWidget' )
65 .addClass( 'mw-rcfilters-ui-table' )
68 .addClass( 'mw-rcfilters-ui-row' )
72 .addClass( 'mw-rcfilters-ui-table-placeholder' )
73 .addClass( 'mw-rcfilters-ui-cell' ),
76 .addClass( 'mw-rcfilters-ui-cell' )
77 .addClass( 'mw-rcfilters-ui-rcTopSectionWidget-savedLinks' )
78 .append( savedLinksListWidget.$element ) :
84 // Hack: For jumpiness reasons, this should be a sibling of -head
85 $( '.mw-rcfilters-head' ).before( this.$top );
87 // Initialize top links position
88 this.switchTopLinks( topLinksCookieValue );
93 OO.inheritClass( RcTopSectionWidget, OO.ui.Widget );
96 * Switch the top links widget from inside the table (when collapsed)
97 * to the 'top' (when open)
99 * @param {string} [state] The state of the top links widget: 'expanded' or 'collapsed'
101 RcTopSectionWidget.prototype.switchTopLinks = function ( state ) {
102 state = state || 'expanded';
104 if ( state === 'expanded' ) {
105 this.$top.append( this.$topLinks );
107 this.$tableTopLinks.append( this.$topLinks );
109 this.$topLinks.toggleClass( 'mw-recentchanges-toplinks-collapsed', state === 'collapsed' );
112 module.exports = RcTopSectionWidget;