SpecialPages: Add ul { margin-top: 0; margin-bottom: 0 } for multicolumn
[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.setDisabled( !!this.matchingQuery );
421 this.saveQueryButton.setTitle( !this.matchingQuery ?
422 mw.msg( 'rcfilters-savedqueries-add-new-title' ) :
423 mw.msg( 'rcfilters-savedqueries-already-saved' ) );
424
425 if ( this.matchingQuery ) {
426 this.emphasize();
427 }
428 };
429
430 /**
431 * Respond to model itemUpdate event
432 * fixme: when a new state is applied to the model this function is called 60+ times in a row
433 *
434 * @param {mw.rcfilters.dm.FilterItem} item Filter item model
435 */
436 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelItemUpdate = function ( item ) {
437 if ( !item.getGroupModel().isHidden() ) {
438 if (
439 item.isSelected() ||
440 (
441 this.model.isHighlightEnabled() &&
442 item.getHighlightColor()
443 )
444 ) {
445 this.addTag( item.getName(), item.getLabel() );
446 } else {
447 this.removeTagByData( item.getName() );
448 }
449 }
450
451 this.setSavedQueryVisibility();
452
453 // Re-evaluate reset state
454 this.reevaluateResetRestoreState();
455 };
456
457 /**
458 * @inheritdoc
459 */
460 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.isAllowedData = function ( data ) {
461 return (
462 this.model.getItemByName( data ) &&
463 !this.isDuplicateData( data )
464 );
465 };
466
467 /**
468 * @inheritdoc
469 */
470 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onMenuChoose = function ( item ) {
471 this.controller.toggleFilterSelect( item.model.getName() );
472
473 // Select the tag if it exists, or reset selection otherwise
474 this.selectTag( this.getItemFromData( item.model.getName() ) );
475
476 this.focus();
477 };
478
479 /**
480 * Respond to highlightChange event
481 *
482 * @param {boolean} isHighlightEnabled Highlight is enabled
483 */
484 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelHighlightChange = function ( isHighlightEnabled ) {
485 var highlightedItems = this.model.getHighlightedItems();
486
487 if ( isHighlightEnabled ) {
488 // Add capsule widgets
489 highlightedItems.forEach( function ( filterItem ) {
490 this.addTag( filterItem.getName(), filterItem.getLabel() );
491 }.bind( this ) );
492 } else {
493 // Remove capsule widgets if they're not selected
494 highlightedItems.forEach( function ( filterItem ) {
495 if ( !filterItem.isSelected() ) {
496 this.removeTagByData( filterItem.getName() );
497 }
498 }.bind( this ) );
499 }
500
501 this.setSavedQueryVisibility();
502 };
503
504 /**
505 * @inheritdoc
506 */
507 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onTagSelect = function ( tagItem ) {
508 var widget = this,
509 menuOption = this.menu.getItemFromModel( tagItem.getModel() ),
510 oldInputValue = this.input.getValue().trim();
511
512 this.menu.setUserSelecting( true );
513
514 // Reset input
515 this.input.setValue( '' );
516
517 // Switch view
518 this.controller.switchView( tagItem.getView() );
519
520 // Parent method
521 mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onTagSelect.call( this, tagItem );
522
523 this.menu.selectItem( menuOption );
524 this.selectTag( tagItem );
525
526 // Scroll to the item
527 if ( this.model.removeViewTriggers( oldInputValue ) ) {
528 // We're binding a 'once' to the itemVisibilityChange event
529 // so this happens when the menu is ready after the items
530 // are visible again, in case this is done right after the
531 // user filtered the results
532 this.getMenu().once(
533 'itemVisibilityChange',
534 function () {
535 widget.scrollToTop( menuOption.$element );
536 widget.menu.setUserSelecting( false );
537 }
538 );
539 } else {
540 this.scrollToTop( menuOption.$element );
541 this.menu.setUserSelecting( false );
542 }
543
544 };
545
546 /**
547 * Select a tag by reference. This is what OO.ui.SelectWidget is doing.
548 * If no items are given, reset selection from all.
549 *
550 * @param {mw.rcfilters.ui.FilterTagItemWidget} [item] Tag to select,
551 * omit to deselect all
552 */
553 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.selectTag = function ( item ) {
554 var i, len, selected;
555
556 for ( i = 0, len = this.items.length; i < len; i++ ) {
557 selected = this.items[ i ] === item;
558 if ( this.items[ i ].isSelected() !== selected ) {
559 this.items[ i ].toggleSelected( selected );
560 }
561 }
562 };
563 /**
564 * @inheritdoc
565 */
566 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onTagRemove = function ( tagItem ) {
567 // Parent method
568 mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onTagRemove.call( this, tagItem );
569
570 this.controller.clearFilter( tagItem.getName() );
571
572 tagItem.destroy();
573 };
574
575 /**
576 * Respond to click event on the reset button
577 */
578 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onResetButtonClick = function () {
579 if ( this.model.areCurrentFiltersEmpty() ) {
580 // Reset to default filters
581 this.controller.resetToDefaults();
582 } else {
583 // Reset to have no filters
584 this.controller.emptyFilters();
585 }
586 };
587
588 /**
589 * Reevaluate the restore state for the widget between setting to defaults and clearing all filters
590 */
591 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.reevaluateResetRestoreState = function () {
592 var defaultsAreEmpty = this.controller.areDefaultsEmpty(),
593 currFiltersAreEmpty = this.model.areCurrentFiltersEmpty(),
594 hideResetButton = currFiltersAreEmpty && defaultsAreEmpty;
595
596 this.resetButton.setIcon(
597 currFiltersAreEmpty ? 'history' : 'trash'
598 );
599
600 this.resetButton.setLabel(
601 currFiltersAreEmpty ? mw.msg( 'rcfilters-restore-default-filters' ) : ''
602 );
603 this.resetButton.setTitle(
604 currFiltersAreEmpty ? null : mw.msg( 'rcfilters-clear-all-filters' )
605 );
606
607 this.resetButton.toggle( !hideResetButton );
608 this.emptyFilterMessage.toggle( currFiltersAreEmpty );
609 };
610
611 /**
612 * @inheritdoc
613 */
614 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.createMenuWidget = function ( menuConfig ) {
615 return new mw.rcfilters.ui.MenuSelectWidget(
616 this.controller,
617 this.model,
618 $.extend( {
619 filterFromInput: true
620 }, menuConfig )
621 );
622 };
623
624 /**
625 * @inheritdoc
626 */
627 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.createTagItemWidget = function ( data ) {
628 var filterItem = this.model.getItemByName( data );
629
630 if ( filterItem ) {
631 return new mw.rcfilters.ui.FilterTagItemWidget(
632 this.controller,
633 this.model,
634 this.model.getInvertModel(),
635 filterItem,
636 {
637 $overlay: this.$overlay
638 }
639 );
640 }
641 };
642
643 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.emphasize = function () {
644 if (
645 !this.$handle.hasClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-animate' )
646 ) {
647 this.$handle
648 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-emphasize' )
649 .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-animate' );
650
651 setTimeout( function () {
652 this.$handle
653 .removeClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-emphasize' );
654
655 setTimeout( function () {
656 this.$handle
657 .removeClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-animate' );
658 }.bind( this ), 1000 );
659 }.bind( this ), 500 );
660
661 }
662 };
663 /**
664 * Scroll the element to top within its container
665 *
666 * @private
667 * @param {jQuery} $element Element to position
668 * @param {number} [marginFromTop=0] When scrolling the entire widget to the top, leave this
669 * much space (in pixels) above the widget.
670 * @param {Object} [threshold] Minimum distance from the top of the element to scroll at all
671 * @param {number} [threshold.min] Minimum distance above the element
672 * @param {number} [threshold.max] Minimum distance below the element
673 */
674 mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.scrollToTop = function ( $element, marginFromTop, threshold ) {
675 var container = OO.ui.Element.static.getClosestScrollableContainer( $element[ 0 ], 'y' ),
676 pos = OO.ui.Element.static.getRelativePosition( $element, $( container ) ),
677 containerScrollTop = $( container ).scrollTop(),
678 effectiveScrollTop = $( container ).is( 'body, html' ) ? 0 : containerScrollTop,
679 newScrollTop = effectiveScrollTop + pos.top - ( marginFromTop || 0 );
680
681 // Scroll to item
682 if (
683 threshold === undefined ||
684 (
685 (
686 threshold.min === undefined ||
687 newScrollTop - containerScrollTop >= threshold.min
688 ) &&
689 (
690 threshold.max === undefined ||
691 newScrollTop - containerScrollTop <= threshold.max
692 )
693 )
694 ) {
695 $( container ).animate( {
696 scrollTop: newScrollTop
697 } );
698 }
699 };
700 }( mediaWiki ) );