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