Merge "Add block and unblock commands to WDIO"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.FilterTagMultiselectWidget.js
1 ( function () {
2 /**
3 * List displaying all filter groups
4 *
5 * @class
6 * @extends OO.ui.MenuTagMultiselectWidget
7 * @mixins OO.ui.mixin.PendingElement
8 *
9 * @constructor
10 * @param {mw.rcfilters.Controller} controller Controller
11 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
12 * @param {mw.rcfilters.dm.SavedQueriesModel} savedQueriesModel Saved queries model
13 * @param {Object} config Configuration object
14 * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups
15 * @cfg {jQuery} [$wrapper] A jQuery object for the wrapper of the general
16 * system. If not given, falls back to this widget's $element
17 * @cfg {boolean} [collapsed] Filter area is collapsed
18 */
19 mw.rcfilters.ui.FilterTagMultiselectWidget = function MwRcfiltersUiFilterTagMultiselectWidget( controller, model, savedQueriesModel, config ) {
20 var rcFiltersRow,
21 title = new OO.ui.LabelWidget( {
22 label: mw.msg( 'rcfilters-activefilters' ),
23 classes: [ 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-content-title' ]
24 } ),
25 $contentWrapper = $( '<div>' )
26 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper' );
27
28 config = config || {};
29
30 this.controller = controller;
31 this.model = model;
32 this.queriesModel = savedQueriesModel;
33 this.$overlay = config.$overlay || this.$element;
34 this.$wrapper = config.$wrapper || this.$element;
35 this.matchingQuery = null;
36 this.currentView = this.model.getCurrentView();
37 this.collapsed = false;
38
39 // Parent
40 mw.rcfilters.ui.FilterTagMultiselectWidget.parent.call( this, $.extend( true, {
41 label: mw.msg( 'rcfilters-filterlist-title' ),
42 placeholder: mw.msg( 'rcfilters-empty-filter' ),
43 inputPosition: 'outline',
44 allowArbitrary: false,
45 allowDisplayInvalidTags: false,
46 allowReordering: false,
47 $overlay: this.$overlay,
48 menu: {
49 // Our filtering is done through the model
50 filterFromInput: false,
51 hideWhenOutOfView: false,
52 hideOnChoose: false,
53 width: 650,
54 footers: [
55 {
56 name: 'viewSelect',
57 sticky: false,
58 // View select menu, appears on default view only
59 $element: $( '<div>' )
60 .append( new mw.rcfilters.ui.ViewSwitchWidget( this.controller, this.model ).$element ),
61 views: [ 'default' ]
62 },
63 {
64 name: 'feedback',
65 // Feedback footer, appears on all views
66 $element: $( '<div>' )
67 .append(
68 new OO.ui.ButtonWidget( {
69 framed: false,
70 icon: 'feedback',
71 flags: [ 'progressive' ],
72 label: mw.msg( 'rcfilters-filterlist-feedbacklink' ),
73 href: 'https://www.mediawiki.org/wiki/Help_talk:New_filters_for_edit_review'
74 } ).$element
75 )
76 }
77 ]
78 },
79 input: {
80 icon: 'menu',
81 placeholder: mw.msg( 'rcfilters-search-placeholder' )
82 }
83 }, config ) );
84
85 this.savedQueryTitle = new OO.ui.LabelWidget( {
86 label: '',
87 classes: [ 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-content-savedQueryTitle' ]
88 } );
89
90 this.resetButton = new OO.ui.ButtonWidget( {
91 framed: false,
92 classes: [ 'mw-rcfilters-ui-filterTagMultiselectWidget-resetButton' ]
93 } );
94
95 this.hideShowButton = new OO.ui.ButtonWidget( {
96 framed: false,
97 flags: [ 'progressive' ],
98 classes: [ 'mw-rcfilters-ui-filterTagMultiselectWidget-hideshowButton' ]
99 } );
100 this.toggleCollapsed( !!config.collapsed );
101
102 if ( !mw.user.isAnon() ) {
103 this.saveQueryButton = new mw.rcfilters.ui.SaveFiltersPopupButtonWidget(
104 this.controller,
105 this.queriesModel,
106 {
107 $overlay: this.$overlay
108 }
109 );
110
111 this.saveQueryButton.$element.on( 'mousedown', function ( e ) {
112 e.stopPropagation();
113 } );
114
115 this.saveQueryButton.connect( this, {
116 click: 'onSaveQueryButtonClick',
117 saveCurrent: 'setSavedQueryVisibility'
118 } );
119 this.queriesModel.connect( this, {
120 itemUpdate: 'onSavedQueriesItemUpdate',
121 initialize: 'onSavedQueriesInitialize',
122 default: 'reevaluateResetRestoreState'
123 } );
124 }
125
126 this.emptyFilterMessage = new OO.ui.LabelWidget( {
127 label: mw.msg( 'rcfilters-empty-filter' ),
128 classes: [ 'mw-rcfilters-ui-filterTagMultiselectWidget-emptyFilters' ]
129 } );
130 this.$content.append( this.emptyFilterMessage.$element );
131
132 // Events
133 this.resetButton.connect( this, { click: 'onResetButtonClick' } );
134 this.hideShowButton.connect( this, { click: 'onHideShowButtonClick' } );
135 // Stop propagation for mousedown, so that the widget doesn't
136 // trigger the focus on the input and scrolls up when we click the reset button
137 this.resetButton.$element.on( 'mousedown', function ( e ) {
138 e.stopPropagation();
139 } );
140 this.hideShowButton.$element.on( 'mousedown', function ( e ) {
141 e.stopPropagation();
142 } );
143 this.model.connect( this, {
144 initialize: 'onModelInitialize',
145 update: 'onModelUpdate',
146 searchChange: 'onModelSearchChange',
147 itemUpdate: 'onModelItemUpdate',
148 highlightChange: 'onModelHighlightChange'
149 } );
150 this.input.connect( this, { change: 'onInputChange' } );
151
152 // The filter list and button should appear side by side regardless of how
153 // wide the button is; the button also changes its width depending
154 // on language and its state, so the safest way to present both side
155 // by side is with a table layout
156 rcFiltersRow = $( '<div>' )
157 .addClass( 'mw-rcfilters-ui-row' )
158 .append(
159 this.$content
160 .addClass( 'mw-rcfilters-ui-cell' )
161 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-cell-filters' )
162 );
163
164 if ( !mw.user.isAnon() ) {
165 rcFiltersRow.append(
166 $( '<div>' )
167 .addClass( 'mw-rcfilters-ui-cell' )
168 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-cell-save' )
169 .append( this.saveQueryButton.$element )
170 );
171 }
172
173 // Add a selector at the right of the input
174 this.viewsSelectWidget = new OO.ui.ButtonSelectWidget( {
175 classes: [ 'mw-rcfilters-ui-filterTagMultiselectWidget-views-select-widget' ],
176 items: [
177 new OO.ui.ButtonOptionWidget( {
178 framed: false,
179 data: 'namespaces',
180 icon: 'article',
181 label: mw.msg( 'namespaces' ),
182 title: mw.msg( 'rcfilters-view-namespaces-tooltip' )
183 } ),
184 new OO.ui.ButtonOptionWidget( {
185 framed: false,
186 data: 'tags',
187 icon: 'tag',
188 label: mw.msg( 'tags-title' ),
189 title: mw.msg( 'rcfilters-view-tags-tooltip' )
190 } )
191 ]
192 } );
193
194 // Rearrange the UI so the select widget is at the right of the input
195 this.$element.append(
196 $( '<div>' )
197 .addClass( 'mw-rcfilters-ui-table' )
198 .append(
199 $( '<div>' )
200 .addClass( 'mw-rcfilters-ui-row' )
201 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-views' )
202 .append(
203 $( '<div>' )
204 .addClass( 'mw-rcfilters-ui-cell' )
205 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-views-input' )
206 .append( this.input.$element ),
207 $( '<div>' )
208 .addClass( 'mw-rcfilters-ui-cell' )
209 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-views-select' )
210 .append( this.viewsSelectWidget.$element )
211 )
212 )
213 );
214
215 // Event
216 this.viewsSelectWidget.connect( this, { choose: 'onViewsSelectWidgetChoose' } );
217
218 rcFiltersRow.append(
219 $( '<div>' )
220 .addClass( 'mw-rcfilters-ui-cell' )
221 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-cell-reset' )
222 .append( this.resetButton.$element )
223 );
224
225 // Build the content
226 $contentWrapper.append(
227 $( '<div>' )
228 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-top' )
229 .append(
230 $( '<div>' )
231 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-top-title' )
232 .append( title.$element ),
233 $( '<div>' )
234 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-top-queryName' )
235 .append( this.savedQueryTitle.$element ),
236 $( '<div>' )
237 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-top-hideshow' )
238 .append(
239 this.hideShowButton.$element
240 )
241 ),
242 $( '<div>' )
243 .addClass( 'mw-rcfilters-ui-table' )
244 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-filters' )
245 .append( rcFiltersRow )
246 );
247
248 // Initialize
249 this.$handle.append( $contentWrapper );
250 this.emptyFilterMessage.toggle( this.isEmpty() );
251 this.savedQueryTitle.toggle( false );
252
253 this.$element
254 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget' );
255
256 this.reevaluateResetRestoreState();
257 };
258
259 /* Initialization */
260
261 OO.inheritClass( mw.rcfilters.ui.FilterTagMultiselectWidget, OO.ui.MenuTagMultiselectWidget );
262
263 /* Methods */
264
265 /**
266 * Override parent method to avoid unnecessary resize events.
267 */
268 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.updateIfHeightChanged = function () { };
269
270 /**
271 * Respond to view select widget choose event
272 *
273 * @param {OO.ui.ButtonOptionWidget} buttonOptionWidget Chosen widget
274 */
275 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onViewsSelectWidgetChoose = function ( buttonOptionWidget ) {
276 this.controller.switchView( buttonOptionWidget.getData() );
277 this.viewsSelectWidget.selectItem( null );
278 this.focus();
279 };
280
281 /**
282 * Respond to model search change event
283 *
284 * @param {string} value Search value
285 */
286 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelSearchChange = function ( value ) {
287 this.input.setValue( value );
288 };
289
290 /**
291 * Respond to input change event
292 *
293 * @param {string} value Value of the input
294 */
295 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onInputChange = function ( value ) {
296 this.controller.setSearch( value );
297 };
298
299 /**
300 * Respond to query button click
301 */
302 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onSaveQueryButtonClick = function () {
303 this.getMenu().toggle( false );
304 };
305
306 /**
307 * Respond to save query model initialization
308 */
309 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onSavedQueriesInitialize = function () {
310 this.setSavedQueryVisibility();
311 };
312
313 /**
314 * Respond to save query item change. Mainly this is done to update the label in case
315 * a query item has been edited
316 *
317 * @param {mw.rcfilters.dm.SavedQueryItemModel} item Saved query item
318 */
319 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onSavedQueriesItemUpdate = function ( item ) {
320 if ( this.matchingQuery === item ) {
321 // This means we just edited the item that is currently matched
322 this.savedQueryTitle.setLabel( item.getLabel() );
323 }
324 };
325
326 /**
327 * Respond to menu toggle
328 *
329 * @param {boolean} isVisible Menu is visible
330 */
331 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onMenuToggle = function ( isVisible ) {
332 // Parent
333 mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onMenuToggle.call( this );
334
335 if ( isVisible ) {
336 this.focus();
337
338 mw.hook( 'RcFilters.popup.open' ).fire();
339
340 if ( !this.getMenu().findSelectedItem() ) {
341 // If there are no selected items, scroll menu to top
342 // This has to be in a setTimeout so the menu has time
343 // to be positioned and fixed
344 setTimeout(
345 function () {
346 this.getMenu().scrollToTop();
347 }.bind( this )
348 );
349 }
350 } else {
351 // Clear selection
352 this.selectTag( null );
353
354 // Clear the search
355 this.controller.setSearch( '' );
356
357 // Log filter grouping
358 this.controller.trackFilterGroupings( 'filtermenu' );
359
360 this.blur();
361 }
362
363 this.input.setIcon( isVisible ? 'search' : 'menu' );
364 };
365
366 /**
367 * @inheritdoc
368 */
369 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onInputFocus = function () {
370 // Parent
371 mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onInputFocus.call( this );
372
373 // Only scroll to top of the viewport if:
374 // - The widget is more than 20px from the top
375 // - The widget is not above the top of the viewport (do not scroll downwards)
376 // (This isn't represented because >20 is, anyways and always, bigger than 0)
377 this.scrollToTop( this.$element, 0, { min: 20, max: Infinity } );
378 };
379
380 /**
381 * @inheritdoc
382 */
383 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.doInputEscape = function () {
384 // Parent
385 mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.doInputEscape.call( this );
386
387 // Blur the input
388 this.input.$input.trigger( 'blur' );
389 };
390
391 /**
392 * @inheritdoc
393 */
394 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onMouseDown = function ( e ) {
395 if ( !this.collapsed && !this.isDisabled() && e.which === OO.ui.MouseButtons.LEFT ) {
396 this.menu.toggle();
397
398 return false;
399 }
400 };
401
402 /**
403 * @inheritdoc
404 */
405 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onChangeTags = function () {
406 // If initialized, call parent method.
407 if ( this.controller.isInitialized() ) {
408 mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onChangeTags.call( this );
409 }
410
411 this.emptyFilterMessage.toggle( this.isEmpty() );
412 };
413
414 /**
415 * Respond to model initialize event
416 */
417 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelInitialize = function () {
418 this.setSavedQueryVisibility();
419 };
420
421 /**
422 * Respond to model update event
423 */
424 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelUpdate = function () {
425 this.updateElementsForView();
426 };
427
428 /**
429 * Update the elements in the widget to the current view
430 */
431 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.updateElementsForView = function () {
432 var view = this.model.getCurrentView(),
433 inputValue = this.input.getValue().trim(),
434 inputView = this.model.getViewByTrigger( inputValue.substr( 0, 1 ) );
435
436 if ( inputView !== 'default' ) {
437 // We have a prefix already, remove it
438 inputValue = inputValue.substr( 1 );
439 }
440
441 if ( inputView !== view ) {
442 // Add the correct prefix
443 inputValue = this.model.getViewTrigger( view ) + inputValue;
444 }
445
446 // Update input
447 this.input.setValue( inputValue );
448
449 if ( this.currentView !== view ) {
450 this.scrollToTop( this.$element );
451 this.currentView = view;
452 }
453 };
454
455 /**
456 * Set the visibility of the saved query button
457 */
458 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.setSavedQueryVisibility = function () {
459 if ( mw.user.isAnon() ) {
460 return;
461 }
462
463 this.matchingQuery = this.controller.findQueryMatchingCurrentState();
464
465 this.savedQueryTitle.setLabel(
466 this.matchingQuery ? this.matchingQuery.getLabel() : ''
467 );
468 this.savedQueryTitle.toggle( !!this.matchingQuery );
469 this.saveQueryButton.setDisabled( !!this.matchingQuery );
470 this.saveQueryButton.setTitle( !this.matchingQuery ?
471 mw.msg( 'rcfilters-savedqueries-add-new-title' ) :
472 mw.msg( 'rcfilters-savedqueries-already-saved' ) );
473
474 if ( this.matchingQuery ) {
475 this.emphasize();
476 }
477 };
478
479 /**
480 * Respond to model itemUpdate event
481 * fixme: when a new state is applied to the model this function is called 60+ times in a row
482 *
483 * @param {mw.rcfilters.dm.FilterItem} item Filter item model
484 */
485 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelItemUpdate = function ( item ) {
486 if ( !item.getGroupModel().isHidden() ) {
487 if (
488 item.isSelected() ||
489 (
490 this.model.isHighlightEnabled() &&
491 item.getHighlightColor()
492 )
493 ) {
494 this.addTag( item.getName(), item.getLabel() );
495 } else {
496 // Only attempt to remove the tag if we can find an item for it (T198140, T198231)
497 if ( this.findItemFromData( item.getName() ) !== null ) {
498 this.removeTagByData( item.getName() );
499 }
500 }
501 }
502
503 this.setSavedQueryVisibility();
504
505 // Re-evaluate reset state
506 this.reevaluateResetRestoreState();
507 };
508
509 /**
510 * @inheritdoc
511 */
512 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.isAllowedData = function ( data ) {
513 return (
514 this.model.getItemByName( data ) &&
515 !this.isDuplicateData( data )
516 );
517 };
518
519 /**
520 * @inheritdoc
521 */
522 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onMenuChoose = function ( item ) {
523 this.controller.toggleFilterSelect( item.model.getName() );
524
525 // Select the tag if it exists, or reset selection otherwise
526 this.selectTag( this.findItemFromData( item.model.getName() ) );
527
528 this.focus();
529 };
530
531 /**
532 * Respond to highlightChange event
533 *
534 * @param {boolean} isHighlightEnabled Highlight is enabled
535 */
536 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelHighlightChange = function ( isHighlightEnabled ) {
537 var highlightedItems = this.model.getHighlightedItems();
538
539 if ( isHighlightEnabled ) {
540 // Add capsule widgets
541 highlightedItems.forEach( function ( filterItem ) {
542 this.addTag( filterItem.getName(), filterItem.getLabel() );
543 }.bind( this ) );
544 } else {
545 // Remove capsule widgets if they're not selected
546 highlightedItems.forEach( function ( filterItem ) {
547 if ( !filterItem.isSelected() ) {
548 // Only attempt to remove the tag if we can find an item for it (T198140, T198231)
549 if ( this.findItemFromData( filterItem.getName() ) !== null ) {
550 this.removeTagByData( filterItem.getName() );
551 }
552 }
553 }.bind( this ) );
554 }
555
556 this.setSavedQueryVisibility();
557 };
558
559 /**
560 * @inheritdoc
561 */
562 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onTagSelect = function ( tagItem ) {
563 var menuOption = this.menu.getItemFromModel( tagItem.getModel() );
564
565 this.menu.setUserSelecting( true );
566 // Parent method
567 mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onTagSelect.call( this, tagItem );
568
569 // Switch view
570 this.controller.resetSearchForView( tagItem.getView() );
571
572 this.selectTag( tagItem );
573 this.scrollToTop( menuOption.$element );
574
575 this.menu.setUserSelecting( false );
576 };
577
578 /**
579 * Select a tag by reference. This is what OO.ui.SelectWidget is doing.
580 * If no items are given, reset selection from all.
581 *
582 * @param {mw.rcfilters.ui.FilterTagItemWidget} [item] Tag to select,
583 * omit to deselect all
584 */
585 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.selectTag = function ( item ) {
586 var i, len, selected;
587
588 for ( i = 0, len = this.items.length; i < len; i++ ) {
589 selected = this.items[ i ] === item;
590 if ( this.items[ i ].isSelected() !== selected ) {
591 this.items[ i ].toggleSelected( selected );
592 }
593 }
594 };
595 /**
596 * @inheritdoc
597 */
598 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onTagRemove = function ( tagItem ) {
599 // Parent method
600 mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onTagRemove.call( this, tagItem );
601
602 this.controller.clearFilter( tagItem.getName() );
603
604 tagItem.destroy();
605 };
606
607 /**
608 * Respond to click event on the reset button
609 */
610 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onResetButtonClick = function () {
611 if ( this.model.areVisibleFiltersEmpty() ) {
612 // Reset to default filters
613 this.controller.resetToDefaults();
614 } else {
615 // Reset to have no filters
616 this.controller.emptyFilters();
617 }
618 };
619
620 /**
621 * Respond to hide/show button click
622 */
623 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onHideShowButtonClick = function () {
624 this.toggleCollapsed();
625 };
626
627 /**
628 * Toggle the collapsed state of the filters widget
629 *
630 * @param {boolean} isCollapsed Widget is collapsed
631 */
632 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.toggleCollapsed = function ( isCollapsed ) {
633 isCollapsed = isCollapsed === undefined ? !this.collapsed : !!isCollapsed;
634
635 this.collapsed = isCollapsed;
636
637 if ( isCollapsed ) {
638 // If we are collapsing, close the menu, in case it was open
639 // We should make sure the menu closes before the rest of the elements
640 // are hidden, otherwise there is an unknown error in jQuery as ooui
641 // sets and unsets properties on the input (which is hidden at that point)
642 this.menu.toggle( false );
643 }
644 this.input.setDisabled( isCollapsed );
645 this.hideShowButton.setLabel( mw.msg(
646 isCollapsed ? 'rcfilters-activefilters-show' : 'rcfilters-activefilters-hide'
647 ) );
648 this.hideShowButton.setTitle( mw.msg(
649 isCollapsed ? 'rcfilters-activefilters-show-tooltip' : 'rcfilters-activefilters-hide-tooltip'
650 ) );
651
652 // Toggle the wrapper class, so we have min height values correctly throughout
653 this.$wrapper.toggleClass( 'mw-rcfilters-collapsed', isCollapsed );
654
655 // Save the state
656 this.controller.updateCollapsedState( isCollapsed );
657 };
658
659 /**
660 * Reevaluate the restore state for the widget between setting to defaults and clearing all filters
661 */
662 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.reevaluateResetRestoreState = function () {
663 var defaultsAreEmpty = this.controller.areDefaultsEmpty(),
664 currFiltersAreEmpty = this.model.areVisibleFiltersEmpty(),
665 hideResetButton = currFiltersAreEmpty && defaultsAreEmpty;
666
667 this.resetButton.setIcon(
668 currFiltersAreEmpty ? 'history' : 'trash'
669 );
670
671 this.resetButton.setLabel(
672 currFiltersAreEmpty ? mw.msg( 'rcfilters-restore-default-filters' ) : ''
673 );
674 this.resetButton.setTitle(
675 currFiltersAreEmpty ? null : mw.msg( 'rcfilters-clear-all-filters' )
676 );
677
678 this.resetButton.toggle( !hideResetButton );
679 this.emptyFilterMessage.toggle( currFiltersAreEmpty );
680 };
681
682 /**
683 * @inheritdoc
684 */
685 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.createMenuWidget = function ( menuConfig ) {
686 return new mw.rcfilters.ui.MenuSelectWidget(
687 this.controller,
688 this.model,
689 menuConfig
690 );
691 };
692
693 /**
694 * @inheritdoc
695 */
696 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.createTagItemWidget = function ( data ) {
697 var filterItem = this.model.getItemByName( data );
698
699 if ( filterItem ) {
700 return new mw.rcfilters.ui.FilterTagItemWidget(
701 this.controller,
702 this.model,
703 this.model.getInvertModel(),
704 filterItem,
705 {
706 $overlay: this.$overlay
707 }
708 );
709 }
710 };
711
712 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.emphasize = function () {
713 if (
714 !this.$handle.hasClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-animate' )
715 ) {
716 this.$handle
717 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-emphasize' )
718 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-animate' );
719
720 setTimeout( function () {
721 this.$handle
722 .removeClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-emphasize' );
723
724 setTimeout( function () {
725 this.$handle
726 .removeClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-animate' );
727 }.bind( this ), 1000 );
728 }.bind( this ), 500 );
729
730 }
731 };
732 /**
733 * Scroll the element to top within its container
734 *
735 * @private
736 * @param {jQuery} $element Element to position
737 * @param {number} [marginFromTop=0] When scrolling the entire widget to the top, leave this
738 * much space (in pixels) above the widget.
739 * @param {Object} [threshold] Minimum distance from the top of the element to scroll at all
740 * @param {number} [threshold.min] Minimum distance above the element
741 * @param {number} [threshold.max] Minimum distance below the element
742 */
743 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.scrollToTop = function ( $element, marginFromTop, threshold ) {
744 var container = OO.ui.Element.static.getClosestScrollableContainer( $element[ 0 ], 'y' ),
745 pos = OO.ui.Element.static.getRelativePosition( $element, $( container ) ),
746 containerScrollTop = $( container ).scrollTop(),
747 effectiveScrollTop = $( container ).is( 'body, html' ) ? 0 : containerScrollTop,
748 newScrollTop = effectiveScrollTop + pos.top - ( marginFromTop || 0 );
749
750 // Scroll to item
751 if (
752 threshold === undefined ||
753 (
754 (
755 threshold.min === undefined ||
756 newScrollTop - containerScrollTop >= threshold.min
757 ) &&
758 (
759 threshold.max === undefined ||
760 newScrollTop - containerScrollTop <= threshold.max
761 )
762 )
763 ) {
764 // eslint-disable-next-line jquery/no-animate
765 $( container ).animate( {
766 scrollTop: newScrollTop
767 } );
768 }
769 };
770 }() );