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