5 * @extends OO.ui.Widget
6 * @mixins OO.ui.mixin.PendingElement
9 * @param {mw.rcfilters.dm.FiltersViewModel} filtersViewModel View model
10 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListViewModel View model
11 * @param {jQuery} $changesListRoot Root element of the changes list to attach to
12 * @param {Object} config Configuration object
14 mw
.rcfilters
.ui
.ChangesListWrapperWidget
= function MwRcfiltersUiChangesListWrapperWidget(
20 config
= $.extend( {}, config
, {
21 $element
: $changesListRoot
25 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.parent
.call( this, config
);
27 OO
.ui
.mixin
.PendingElement
.call( this, config
);
29 this.filtersViewModel
= filtersViewModel
;
30 this.changesListViewModel
= changesListViewModel
;
33 this.filtersViewModel
.connect( this, {
34 itemUpdate
: 'onItemUpdate',
35 highlightChange
: 'onHighlightChange'
37 this.changesListViewModel
.connect( this, {
38 invalidate
: 'onModelInvalidate',
39 update
: 'onModelUpdate'
42 this.$element
.addClass( 'mw-rcfilters-ui-changesListWrapperWidget' );
44 // Set up highlight containers
45 this.setupHighlightContainers( this.$element
);
50 OO
.inheritClass( mw
.rcfilters
.ui
.ChangesListWrapperWidget
, OO
.ui
.Widget
);
51 OO
.mixinClass( mw
.rcfilters
.ui
.ChangesListWrapperWidget
, OO
.ui
.mixin
.PendingElement
);
54 * Respond to the highlight feature being toggled on and off
56 * @param {boolean} highlightEnabled
58 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onHighlightChange = function ( highlightEnabled
) {
59 if ( highlightEnabled
) {
60 this.applyHighlight();
62 this.clearHighlight();
67 * Respond to a filter item model update
69 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onItemUpdate = function () {
70 if ( this.filtersViewModel
.isHighlightEnabled() ) {
71 this.clearHighlight();
72 this.applyHighlight();
77 * Respond to changes list model invalidate
79 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onModelInvalidate = function () {
84 * Respond to changes list model update
86 * @param {jQuery|string} $changesListContent The content of the updated changes list
88 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onModelUpdate = function ( $changesListContent
) {
89 var isEmpty
= $changesListContent
=== 'NO_RESULTS';
91 this.$element
.toggleClass( 'mw-changeslist', !isEmpty
);
92 this.$element
.toggleClass( 'mw-changeslist-empty', isEmpty
);
94 this.$changesListContent
= null;
95 this.$element
.empty().append(
96 document
.createTextNode( mw
.message( 'recentchanges-noresult' ).text() )
99 this.$changesListContent
= $changesListContent
;
100 this.$element
.empty().append( this.$changesListContent
);
101 // Set up highlight containers
102 this.setupHighlightContainers( this.$element
);
105 this.applyHighlight();
107 // Make sure enhanced RC re-initializes correctly
108 mw
.hook( 'wikipage.content' ).fire( this.$element
);
114 * Set up the highlight containers with all color circle indicators.
116 * @param {jQuery|string} $content The content of the updated changes list
118 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.setupHighlightContainers = function ( $content
) {
119 var $highlights
= $( '<div>' )
120 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights' )
123 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-none' )
124 .prop( 'data-color', 'none' )
127 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
130 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-' + color
)
131 .prop( 'data-color', color
)
135 if ( Number( mw
.user
.options
.get( 'usenewrc' ) ) ) {
137 $content
.find( 'td.mw-enhanced-rc' )
141 .append( $highlights
.clone() )
145 $content
.find( 'ul.special li' )
146 .prepend( $highlights
.clone() );
151 * Apply color classes based on filters highlight configuration
153 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.applyHighlight = function () {
154 if ( !this.filtersViewModel
.isHighlightEnabled() ) {
158 this.filtersViewModel
.getHighlightedItems().forEach( function ( filterItem
) {
159 // Add highlight class to all highlighted list items
160 this.$element
.find( '.' + filterItem
.getCssClass() )
161 .addClass( 'mw-rcfilters-highlight-color-' + filterItem
.getHighlightColor() );
164 // Turn on highlights
165 this.$element
.addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );
169 * Remove all color classes
171 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.clearHighlight = function () {
172 // Remove highlight classes
173 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
174 this.$element
.find( '.mw-rcfilters-highlight-color-' + color
).removeClass( 'mw-rcfilters-highlight-color-' + color
);
177 // Turn off highlights
178 this.$element
.removeClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );