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