3 * https://www.mediawiki.org/wiki/OOjs_UI
5 * Copyright 2011–2015 OOjs UI Team and other contributors.
6 * Released under the MIT license
7 * http://oojs.mit-license.org
9 * Date: 2015-08-11T22:34:00Z
16 * Namespace for all classes, static methods and static properties.
53 * Generate a unique ID for element
55 * @return {String} [id]
57 OO
.ui
.generateElementId = function () {
59 return 'oojsui-' + OO
.ui
.elementId
;
63 * Check if an element is focusable.
64 * Inspired from :focusable in jQueryUI v1.11.4 - 2015-04-14
66 * @param {jQuery} element Element to test
67 * @return {Boolean} [description]
69 OO
.ui
.isFocusableElement = function ( $element
) {
70 var node
= $element
[0],
71 nodeName
= node
.nodeName
.toLowerCase(),
72 // Check if the element have tabindex set
73 isInElementGroup
= /^(input|select|textarea|button|object)$/.test( nodeName
),
74 // Check if the element is a link with href or if it has tabindex
76 ( nodeName
=== 'a' && node
.href
) ||
77 !isNaN( $element
.attr( 'tabindex' ) )
79 // Check if the element is visible
81 // This is quicker than calling $element.is( ':visible' )
82 $.expr
.filters
.visible( node
) &&
83 // Check that all parents are visible
84 !$element
.parents().addBack().filter( function () {
85 return $.css( this, 'visibility' ) === 'hidden';
88 isTabOk
= isNaN( $element
.attr( 'tabindex' ) ) || +$element
.attr( 'tabindex' ) >= 0;
91 ( isInElementGroup
? !node
.disabled
: isOtherElement
) &&
97 * Get the user's language and any fallback languages.
99 * These language codes are used to localize user interface elements in the user's language.
101 * In environments that provide a localization system, this function should be overridden to
102 * return the user's language(s). The default implementation returns English (en) only.
104 * @return {string[]} Language codes, in descending order of priority
106 OO
.ui
.getUserLanguages = function () {
111 * Get a value in an object keyed by language code.
113 * @param {Object.<string,Mixed>} obj Object keyed by language code
114 * @param {string|null} [lang] Language code, if omitted or null defaults to any user language
115 * @param {string} [fallback] Fallback code, used if no matching language can be found
116 * @return {Mixed} Local value
118 OO
.ui
.getLocalValue = function ( obj
, lang
, fallback
) {
121 // Requested language
125 // Known user language
126 langs
= OO
.ui
.getUserLanguages();
127 for ( i
= 0, len
= langs
.length
; i
< len
; i
++ ) {
134 if ( obj
[ fallback
] ) {
135 return obj
[ fallback
];
137 // First existing language
138 for ( lang
in obj
) {
146 * Check if a node is contained within another node
148 * Similar to jQuery#contains except a list of containers can be supplied
149 * and a boolean argument allows you to include the container in the match list
151 * @param {HTMLElement|HTMLElement[]} containers Container node(s) to search in
152 * @param {HTMLElement} contained Node to find
153 * @param {boolean} [matchContainers] Include the container(s) in the list of nodes to match, otherwise only match descendants
154 * @return {boolean} The node is in the list of target nodes
156 OO
.ui
.contains = function ( containers
, contained
, matchContainers
) {
158 if ( !Array
.isArray( containers
) ) {
159 containers
= [ containers
];
161 for ( i
= containers
.length
- 1; i
>= 0; i
-- ) {
162 if ( ( matchContainers
&& contained
=== containers
[ i
] ) || $.contains( containers
[ i
], contained
) ) {
170 * Return a function, that, as long as it continues to be invoked, will not
171 * be triggered. The function will be called after it stops being called for
172 * N milliseconds. If `immediate` is passed, trigger the function on the
173 * leading edge, instead of the trailing.
175 * Ported from: http://underscorejs.org/underscore.js
177 * @param {Function} func
178 * @param {number} wait
179 * @param {boolean} immediate
182 OO
.ui
.debounce = function ( func
, wait
, immediate
) {
187 later = function () {
190 func
.apply( context
, args
);
193 if ( immediate
&& !timeout
) {
194 func
.apply( context
, args
);
196 clearTimeout( timeout
);
197 timeout
= setTimeout( later
, wait
);
202 * Reconstitute a JavaScript object corresponding to a widget created by
203 * the PHP implementation.
205 * This is an alias for `OO.ui.Element.static.infuse()`.
207 * @param {string|HTMLElement|jQuery} idOrNode
208 * A DOM id (if a string) or node for the widget to infuse.
209 * @return {OO.ui.Element}
210 * The `OO.ui.Element` corresponding to this (infusable) document node.
212 OO
.ui
.infuse = function ( idOrNode
) {
213 return OO
.ui
.Element
.static.infuse( idOrNode
);
218 * Message store for the default implementation of OO.ui.msg
220 * Environments that provide a localization system should not use this, but should override
221 * OO.ui.msg altogether.
226 // Tool tip for a button that moves items in a list down one place
227 'ooui-outline-control-move-down': 'Move item down',
228 // Tool tip for a button that moves items in a list up one place
229 'ooui-outline-control-move-up': 'Move item up',
230 // Tool tip for a button that removes items from a list
231 'ooui-outline-control-remove': 'Remove item',
232 // Label for the toolbar group that contains a list of all other available tools
233 'ooui-toolbar-more': 'More',
234 // Label for the fake tool that expands the full list of tools in a toolbar group
235 'ooui-toolgroup-expand': 'More',
236 // Label for the fake tool that collapses the full list of tools in a toolbar group
237 'ooui-toolgroup-collapse': 'Fewer',
238 // Default label for the accept button of a confirmation dialog
239 'ooui-dialog-message-accept': 'OK',
240 // Default label for the reject button of a confirmation dialog
241 'ooui-dialog-message-reject': 'Cancel',
242 // Title for process dialog error description
243 'ooui-dialog-process-error': 'Something went wrong',
244 // Label for process dialog dismiss error button, visible when describing errors
245 'ooui-dialog-process-dismiss': 'Dismiss',
246 // Label for process dialog retry action button, visible when describing only recoverable errors
247 'ooui-dialog-process-retry': 'Try again',
248 // Label for process dialog retry action button, visible when describing only warnings
249 'ooui-dialog-process-continue': 'Continue',
250 // Default placeholder for file selection widgets
251 'ooui-selectfile-not-supported': 'File selection is not supported',
252 // Default placeholder for file selection widgets
253 'ooui-selectfile-placeholder': 'No file is selected',
254 // Semicolon separator
255 'ooui-semicolon-separator': '; '
259 * Get a localized message.
261 * In environments that provide a localization system, this function should be overridden to
262 * return the message translated in the user's language. The default implementation always returns
265 * After the message key, message parameters may optionally be passed. In the default implementation,
266 * any occurrences of $1 are replaced with the first parameter, $2 with the second parameter, etc.
267 * Alternative implementations of OO.ui.msg may use any substitution system they like, as long as
268 * they support unnamed, ordered message parameters.
271 * @param {string} key Message key
272 * @param {Mixed...} [params] Message parameters
273 * @return {string} Translated message with parameters substituted
275 OO
.ui
.msg = function ( key
) {
276 var message
= messages
[ key
],
277 params
= Array
.prototype.slice
.call( arguments
, 1 );
278 if ( typeof message
=== 'string' ) {
279 // Perform $1 substitution
280 message
= message
.replace( /\$(\d+)/g, function ( unused
, n
) {
281 var i
= parseInt( n
, 10 );
282 return params
[ i
- 1 ] !== undefined ? params
[ i
- 1 ] : '$' + n
;
285 // Return placeholder if message not found
286 message
= '[' + key
+ ']';
292 * Package a message and arguments for deferred resolution.
294 * Use this when you are statically specifying a message and the message may not yet be present.
296 * @param {string} key Message key
297 * @param {Mixed...} [params] Message parameters
298 * @return {Function} Function that returns the resolved message when executed
300 OO
.ui
.deferMsg = function () {
301 var args
= arguments
;
303 return OO
.ui
.msg
.apply( OO
.ui
, args
);
310 * If the message is a function it will be executed, otherwise it will pass through directly.
312 * @param {Function|string} msg Deferred message, or message text
313 * @return {string} Resolved message
315 OO
.ui
.resolveMsg = function ( msg
) {
316 if ( $.isFunction( msg
) ) {
323 * @param {string} url
326 OO
.ui
.isSafeUrl = function ( url
) {
328 // Keep in sync with php/Tag.php
330 'bitcoin:', 'ftp:', 'ftps:', 'geo:', 'git:', 'gopher:', 'http:', 'https:', 'irc:', 'ircs:',
331 'magnet:', 'mailto:', 'mms:', 'news:', 'nntp:', 'redis:', 'sftp:', 'sip:', 'sips:', 'sms:', 'ssh:',
332 'svn:', 'tel:', 'telnet:', 'urn:', 'worldwind:', 'xmpp:'
335 if ( url
.indexOf( ':' ) === -1 ) {
340 protocol
= url
.split( ':', 1 )[0] + ':';
341 if ( !protocol
.match( /^([A-za-z0-9\+\.\-])+:/ ) ) {
342 // Not a valid protocol, safe
346 // Safe if in the whitelist
347 return $.inArray( protocol
, whitelist
) !== -1;
357 * Namespace for OOjs UI mixins.
359 * Mixins are named according to the type of object they are intended to
360 * be mixed in to. For example, OO.ui.mixin.GroupElement is intended to be
361 * mixed in to an instance of OO.ui.Element, and OO.ui.mixin.GroupWidget
362 * is intended to be mixed in to an instance of OO.ui.Widget.
370 * PendingElement is a mixin that is used to create elements that notify users that something is happening
371 * and that they should wait before proceeding. The pending state is visually represented with a pending
372 * texture that appears in the head of a pending {@link OO.ui.ProcessDialog process dialog} or in the input
373 * field of a {@link OO.ui.TextInputWidget text input widget}.
375 * Currently, {@link OO.ui.ActionWidget Action widgets}, which mix in this class, can also be marked as pending, but only when
376 * used in {@link OO.ui.MessageDialog message dialogs}. The behavior is not currently supported for action widgets used
377 * in process dialogs.
380 * function MessageDialog( config ) {
381 * MessageDialog.parent.call( this, config );
383 * OO.inheritClass( MessageDialog, OO.ui.MessageDialog );
385 * MessageDialog.static.actions = [
386 * { action: 'save', label: 'Done', flags: 'primary' },
387 * { label: 'Cancel', flags: 'safe' }
390 * MessageDialog.prototype.initialize = function () {
391 * MessageDialog.parent.prototype.initialize.apply( this, arguments );
392 * this.content = new OO.ui.PanelLayout( { $: this.$, padded: true } );
393 * this.content.$element.append( '<p>Click the \'Done\' action widget to see its pending state. Note that action widgets can be marked pending in message dialogs but not process dialogs.</p>' );
394 * this.$body.append( this.content.$element );
396 * MessageDialog.prototype.getBodyHeight = function () {
399 * MessageDialog.prototype.getActionProcess = function ( action ) {
401 * if ( action === 'save' ) {
402 * dialog.getActions().get({actions: 'save'})[0].pushPending();
403 * return new OO.ui.Process()
405 * .next( function () {
406 * dialog.getActions().get({actions: 'save'})[0].popPending();
409 * return MessageDialog.parent.prototype.getActionProcess.call( this, action );
412 * var windowManager = new OO.ui.WindowManager();
413 * $( 'body' ).append( windowManager.$element );
415 * var dialog = new MessageDialog();
416 * windowManager.addWindows( [ dialog ] );
417 * windowManager.openWindow( dialog );
423 * @param {Object} [config] Configuration options
424 * @cfg {jQuery} [$pending] Element to mark as pending, defaults to this.$element
426 OO
.ui
.mixin
.PendingElement
= function OoUiMixinPendingElement( config
) {
427 // Configuration initialization
428 config
= config
|| {};
432 this.$pending
= null;
435 this.setPendingElement( config
.$pending
|| this.$element
);
440 OO
.initClass( OO
.ui
.mixin
.PendingElement
);
445 * Set the pending element (and clean up any existing one).
447 * @param {jQuery} $pending The element to set to pending.
449 OO
.ui
.mixin
.PendingElement
.prototype.setPendingElement = function ( $pending
) {
450 if ( this.$pending
) {
451 this.$pending
.removeClass( 'oo-ui-pendingElement-pending' );
454 this.$pending
= $pending
;
455 if ( this.pending
> 0 ) {
456 this.$pending
.addClass( 'oo-ui-pendingElement-pending' );
461 * Check if an element is pending.
463 * @return {boolean} Element is pending
465 OO
.ui
.mixin
.PendingElement
.prototype.isPending = function () {
466 return !!this.pending
;
470 * Increase the pending counter. The pending state will remain active until the counter is zero
471 * (i.e., the number of calls to #pushPending and #popPending is the same).
475 OO
.ui
.mixin
.PendingElement
.prototype.pushPending = function () {
476 if ( this.pending
=== 0 ) {
477 this.$pending
.addClass( 'oo-ui-pendingElement-pending' );
478 this.updateThemeClasses();
486 * Decrease the pending counter. The pending state will remain active until the counter is zero
487 * (i.e., the number of calls to #pushPending and #popPending is the same).
491 OO
.ui
.mixin
.PendingElement
.prototype.popPending = function () {
492 if ( this.pending
=== 1 ) {
493 this.$pending
.removeClass( 'oo-ui-pendingElement-pending' );
494 this.updateThemeClasses();
496 this.pending
= Math
.max( 0, this.pending
- 1 );
502 * ActionSets manage the behavior of the {@link OO.ui.ActionWidget action widgets} that comprise them.
503 * Actions can be made available for specific contexts (modes) and circumstances
504 * (abilities). Action sets are primarily used with {@link OO.ui.Dialog Dialogs}.
506 * ActionSets contain two types of actions:
508 * - Special: Special actions are the first visible actions with special flags, such as 'safe' and 'primary', the default special flags. Additional special flags can be configured in subclasses with the static #specialFlags property.
509 * - Other: Other actions include all non-special visible actions.
511 * Please see the [OOjs UI documentation on MediaWiki][1] for more information.
514 * // Example: An action set used in a process dialog
515 * function MyProcessDialog( config ) {
516 * MyProcessDialog.parent.call( this, config );
518 * OO.inheritClass( MyProcessDialog, OO.ui.ProcessDialog );
519 * MyProcessDialog.static.title = 'An action set in a process dialog';
520 * // An action set that uses modes ('edit' and 'help' mode, in this example).
521 * MyProcessDialog.static.actions = [
522 * { action: 'continue', modes: 'edit', label: 'Continue', flags: [ 'primary', 'constructive' ] },
523 * { action: 'help', modes: 'edit', label: 'Help' },
524 * { modes: 'edit', label: 'Cancel', flags: 'safe' },
525 * { action: 'back', modes: 'help', label: 'Back', flags: 'safe' }
528 * MyProcessDialog.prototype.initialize = function () {
529 * MyProcessDialog.parent.prototype.initialize.apply( this, arguments );
530 * this.panel1 = new OO.ui.PanelLayout( { padded: true, expanded: false } );
531 * this.panel1.$element.append( '<p>This dialog uses an action set (continue, help, cancel, back) configured with modes. This is edit mode. Click \'help\' to see help mode.</p>' );
532 * this.panel2 = new OO.ui.PanelLayout( { padded: true, expanded: false } );
533 * this.panel2.$element.append( '<p>This is help mode. Only the \'back\' action widget is configured to be visible here. Click \'back\' to return to \'edit\' mode.</p>' );
534 * this.stackLayout = new OO.ui.StackLayout( {
535 * items: [ this.panel1, this.panel2 ]
537 * this.$body.append( this.stackLayout.$element );
539 * MyProcessDialog.prototype.getSetupProcess = function ( data ) {
540 * return MyProcessDialog.parent.prototype.getSetupProcess.call( this, data )
541 * .next( function () {
542 * this.actions.setMode( 'edit' );
545 * MyProcessDialog.prototype.getActionProcess = function ( action ) {
546 * if ( action === 'help' ) {
547 * this.actions.setMode( 'help' );
548 * this.stackLayout.setItem( this.panel2 );
549 * } else if ( action === 'back' ) {
550 * this.actions.setMode( 'edit' );
551 * this.stackLayout.setItem( this.panel1 );
552 * } else if ( action === 'continue' ) {
554 * return new OO.ui.Process( function () {
558 * return MyProcessDialog.parent.prototype.getActionProcess.call( this, action );
560 * MyProcessDialog.prototype.getBodyHeight = function () {
561 * return this.panel1.$element.outerHeight( true );
563 * var windowManager = new OO.ui.WindowManager();
564 * $( 'body' ).append( windowManager.$element );
565 * var dialog = new MyProcessDialog( {
568 * windowManager.addWindows( [ dialog ] );
569 * windowManager.openWindow( dialog );
571 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs#Action_sets
575 * @mixins OO.EventEmitter
578 * @param {Object} [config] Configuration options
580 OO
.ui
.ActionSet
= function OoUiActionSet( config
) {
581 // Configuration initialization
582 config
= config
|| {};
584 // Mixin constructors
585 OO
.EventEmitter
.call( this );
590 actions
: 'getAction',
594 this.categorized
= {};
597 this.organized
= false;
598 this.changing
= false;
599 this.changed
= false;
604 OO
.mixinClass( OO
.ui
.ActionSet
, OO
.EventEmitter
);
606 /* Static Properties */
609 * Symbolic name of the flags used to identify special actions. Special actions are displayed in the
610 * header of a {@link OO.ui.ProcessDialog process dialog}.
611 * See the [OOjs UI documentation on MediaWiki][2] for more information and examples.
613 * [2]:https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs
620 OO
.ui
.ActionSet
.static.specialFlags
= [ 'safe', 'primary' ];
627 * A 'click' event is emitted when an action is clicked.
629 * @param {OO.ui.ActionWidget} action Action that was clicked
635 * A 'resize' event is emitted when an action widget is resized.
637 * @param {OO.ui.ActionWidget} action Action that was resized
643 * An 'add' event is emitted when actions are {@link #method-add added} to the action set.
645 * @param {OO.ui.ActionWidget[]} added Actions added
651 * A 'remove' event is emitted when actions are {@link #method-remove removed}
652 * or {@link #clear cleared}.
654 * @param {OO.ui.ActionWidget[]} added Actions removed
660 * A 'change' event is emitted when actions are {@link #method-add added}, {@link #clear cleared},
661 * or {@link #method-remove removed} from the action set or when the {@link #setMode mode} is changed.
668 * Handle action change events.
673 OO
.ui
.ActionSet
.prototype.onActionChange = function () {
674 this.organized
= false;
675 if ( this.changing
) {
678 this.emit( 'change' );
683 * Check if an action is one of the special actions.
685 * @param {OO.ui.ActionWidget} action Action to check
686 * @return {boolean} Action is special
688 OO
.ui
.ActionSet
.prototype.isSpecial = function ( action
) {
691 for ( flag
in this.special
) {
692 if ( action
=== this.special
[ flag
] ) {
701 * Get action widgets based on the specified filter: ‘actions’, ‘flags’, ‘modes’, ‘visible’,
704 * @param {Object} [filters] Filters to use, omit to get all actions
705 * @param {string|string[]} [filters.actions] Actions that action widgets must have
706 * @param {string|string[]} [filters.flags] Flags that action widgets must have (e.g., 'safe')
707 * @param {string|string[]} [filters.modes] Modes that action widgets must have
708 * @param {boolean} [filters.visible] Action widgets must be visible
709 * @param {boolean} [filters.disabled] Action widgets must be disabled
710 * @return {OO.ui.ActionWidget[]} Action widgets matching all criteria
712 OO
.ui
.ActionSet
.prototype.get = function ( filters
) {
713 var i
, len
, list
, category
, actions
, index
, match
, matches
;
718 // Collect category candidates
720 for ( category
in this.categorized
) {
721 list
= filters
[ category
];
723 if ( !Array
.isArray( list
) ) {
726 for ( i
= 0, len
= list
.length
; i
< len
; i
++ ) {
727 actions
= this.categorized
[ category
][ list
[ i
] ];
728 if ( Array
.isArray( actions
) ) {
729 matches
.push
.apply( matches
, actions
);
734 // Remove by boolean filters
735 for ( i
= 0, len
= matches
.length
; i
< len
; i
++ ) {
736 match
= matches
[ i
];
738 ( filters
.visible
!== undefined && match
.isVisible() !== filters
.visible
) ||
739 ( filters
.disabled
!== undefined && match
.isDisabled() !== filters
.disabled
)
741 matches
.splice( i
, 1 );
747 for ( i
= 0, len
= matches
.length
; i
< len
; i
++ ) {
748 match
= matches
[ i
];
749 index
= matches
.lastIndexOf( match
);
750 while ( index
!== i
) {
751 matches
.splice( index
, 1 );
753 index
= matches
.lastIndexOf( match
);
758 return this.list
.slice();
762 * Get 'special' actions.
764 * Special actions are the first visible action widgets with special flags, such as 'safe' and 'primary'.
765 * Special flags can be configured in subclasses by changing the static #specialFlags property.
767 * @return {OO.ui.ActionWidget[]|null} 'Special' action widgets.
769 OO
.ui
.ActionSet
.prototype.getSpecial = function () {
771 return $.extend( {}, this.special
);
775 * Get 'other' actions.
777 * Other actions include all non-special visible action widgets.
779 * @return {OO.ui.ActionWidget[]} 'Other' action widgets
781 OO
.ui
.ActionSet
.prototype.getOthers = function () {
783 return this.others
.slice();
787 * Set the mode (e.g., ‘edit’ or ‘view’). Only {@link OO.ui.ActionWidget#modes actions} configured
788 * to be available in the specified mode will be made visible. All other actions will be hidden.
790 * @param {string} mode The mode. Only actions configured to be available in the specified
791 * mode will be made visible.
796 OO
.ui
.ActionSet
.prototype.setMode = function ( mode
) {
799 this.changing
= true;
800 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
801 action
= this.list
[ i
];
802 action
.toggle( action
.hasMode( mode
) );
805 this.organized
= false;
806 this.changing
= false;
807 this.emit( 'change' );
813 * Set the abilities of the specified actions.
815 * Action widgets that are configured with the specified actions will be enabled
816 * or disabled based on the boolean values specified in the `actions`
819 * @param {Object.<string,boolean>} actions A list keyed by action name with boolean
820 * values that indicate whether or not the action should be enabled.
823 OO
.ui
.ActionSet
.prototype.setAbilities = function ( actions
) {
824 var i
, len
, action
, item
;
826 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
827 item
= this.list
[ i
];
828 action
= item
.getAction();
829 if ( actions
[ action
] !== undefined ) {
830 item
.setDisabled( !actions
[ action
] );
838 * Executes a function once per action.
840 * When making changes to multiple actions, use this method instead of iterating over the actions
841 * manually to defer emitting a #change event until after all actions have been changed.
843 * @param {Object|null} actions Filters to use to determine which actions to iterate over; see #get
844 * @param {Function} callback Callback to run for each action; callback is invoked with three
845 * arguments: the action, the action's index, the list of actions being iterated over
848 OO
.ui
.ActionSet
.prototype.forEach = function ( filter
, callback
) {
849 this.changed
= false;
850 this.changing
= true;
851 this.get( filter
).forEach( callback
);
852 this.changing
= false;
853 if ( this.changed
) {
854 this.emit( 'change' );
861 * Add action widgets to the action set.
863 * @param {OO.ui.ActionWidget[]} actions Action widgets to add
868 OO
.ui
.ActionSet
.prototype.add = function ( actions
) {
871 this.changing
= true;
872 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
873 action
= actions
[ i
];
874 action
.connect( this, {
875 click
: [ 'emit', 'click', action
],
876 resize
: [ 'emit', 'resize', action
],
877 toggle
: [ 'onActionChange' ]
879 this.list
.push( action
);
881 this.organized
= false;
882 this.emit( 'add', actions
);
883 this.changing
= false;
884 this.emit( 'change' );
890 * Remove action widgets from the set.
892 * To remove all actions, you may wish to use the #clear method instead.
894 * @param {OO.ui.ActionWidget[]} actions Action widgets to remove
899 OO
.ui
.ActionSet
.prototype.remove = function ( actions
) {
900 var i
, len
, index
, action
;
902 this.changing
= true;
903 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
904 action
= actions
[ i
];
905 index
= this.list
.indexOf( action
);
906 if ( index
!== -1 ) {
907 action
.disconnect( this );
908 this.list
.splice( index
, 1 );
911 this.organized
= false;
912 this.emit( 'remove', actions
);
913 this.changing
= false;
914 this.emit( 'change' );
920 * Remove all action widets from the set.
922 * To remove only specified actions, use the {@link #method-remove remove} method instead.
928 OO
.ui
.ActionSet
.prototype.clear = function () {
930 removed
= this.list
.slice();
932 this.changing
= true;
933 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
934 action
= this.list
[ i
];
935 action
.disconnect( this );
940 this.organized
= false;
941 this.emit( 'remove', removed
);
942 this.changing
= false;
943 this.emit( 'change' );
951 * This is called whenever organized information is requested. It will only reorganize the actions
952 * if something has changed since the last time it ran.
957 OO
.ui
.ActionSet
.prototype.organize = function () {
958 var i
, iLen
, j
, jLen
, flag
, action
, category
, list
, item
, special
,
959 specialFlags
= this.constructor.static.specialFlags
;
961 if ( !this.organized
) {
962 this.categorized
= {};
965 for ( i
= 0, iLen
= this.list
.length
; i
< iLen
; i
++ ) {
966 action
= this.list
[ i
];
967 if ( action
.isVisible() ) {
968 // Populate categories
969 for ( category
in this.categories
) {
970 if ( !this.categorized
[ category
] ) {
971 this.categorized
[ category
] = {};
973 list
= action
[ this.categories
[ category
] ]();
974 if ( !Array
.isArray( list
) ) {
977 for ( j
= 0, jLen
= list
.length
; j
< jLen
; j
++ ) {
979 if ( !this.categorized
[ category
][ item
] ) {
980 this.categorized
[ category
][ item
] = [];
982 this.categorized
[ category
][ item
].push( action
);
985 // Populate special/others
987 for ( j
= 0, jLen
= specialFlags
.length
; j
< jLen
; j
++ ) {
988 flag
= specialFlags
[ j
];
989 if ( !this.special
[ flag
] && action
.hasFlag( flag
) ) {
990 this.special
[ flag
] = action
;
996 this.others
.push( action
);
1000 this.organized
= true;
1007 * Each Element represents a rendering in the DOM—a button or an icon, for example, or anything
1008 * that is visible to a user. Unlike {@link OO.ui.Widget widgets}, plain elements usually do not have events
1009 * connected to them and can't be interacted with.
1015 * @param {Object} [config] Configuration options
1016 * @cfg {string[]} [classes] The names of the CSS classes to apply to the element. CSS styles are added
1017 * to the top level (e.g., the outermost div) of the element. See the [OOjs UI documentation on MediaWiki][2]
1019 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Buttons_and_Switches#cssExample
1020 * @cfg {string} [id] The HTML id attribute used in the rendered tag.
1021 * @cfg {string} [text] Text to insert
1022 * @cfg {Array} [content] An array of content elements to append (after #text).
1023 * Strings will be html-escaped; use an OO.ui.HtmlSnippet to append raw HTML.
1024 * Instances of OO.ui.Element will have their $element appended.
1025 * @cfg {jQuery} [$content] Content elements to append (after #text)
1026 * @cfg {Mixed} [data] Custom data of any type or combination of types (e.g., string, number, array, object).
1027 * Data can also be specified with the #setData method.
1029 OO
.ui
.Element
= function OoUiElement( config
) {
1030 // Configuration initialization
1031 config
= config
|| {};
1035 this.visible
= true;
1036 this.data
= config
.data
;
1037 this.$element
= config
.$element
||
1038 $( document
.createElement( this.getTagName() ) );
1039 this.elementGroup
= null;
1040 this.debouncedUpdateThemeClassesHandler
= this.debouncedUpdateThemeClasses
.bind( this );
1041 this.updateThemeClassesPending
= false;
1044 if ( Array
.isArray( config
.classes
) ) {
1045 this.$element
.addClass( config
.classes
.join( ' ' ) );
1048 this.$element
.attr( 'id', config
.id
);
1050 if ( config
.text
) {
1051 this.$element
.text( config
.text
);
1053 if ( config
.content
) {
1054 // The `content` property treats plain strings as text; use an
1055 // HtmlSnippet to append HTML content. `OO.ui.Element`s get their
1056 // appropriate $element appended.
1057 this.$element
.append( config
.content
.map( function ( v
) {
1058 if ( typeof v
=== 'string' ) {
1059 // Escape string so it is properly represented in HTML.
1060 return document
.createTextNode( v
);
1061 } else if ( v
instanceof OO
.ui
.HtmlSnippet
) {
1063 return v
.toString();
1064 } else if ( v
instanceof OO
.ui
.Element
) {
1070 if ( config
.$content
) {
1071 // The `$content` property treats plain strings as HTML.
1072 this.$element
.append( config
.$content
);
1078 OO
.initClass( OO
.ui
.Element
);
1080 /* Static Properties */
1083 * The name of the HTML tag used by the element.
1085 * The static value may be ignored if the #getTagName method is overridden.
1089 * @property {string}
1091 OO
.ui
.Element
.static.tagName
= 'div';
1093 /* Static Methods */
1096 * Reconstitute a JavaScript object corresponding to a widget created
1097 * by the PHP implementation.
1099 * @param {string|HTMLElement|jQuery} idOrNode
1100 * A DOM id (if a string) or node for the widget to infuse.
1101 * @return {OO.ui.Element}
1102 * The `OO.ui.Element` corresponding to this (infusable) document node.
1103 * For `Tag` objects emitted on the HTML side (used occasionally for content)
1104 * the value returned is a newly-created Element wrapping around the existing
1107 OO
.ui
.Element
.static.infuse = function ( idOrNode
) {
1108 var obj
= OO
.ui
.Element
.static.unsafeInfuse( idOrNode
, false );
1109 // Verify that the type matches up.
1110 // FIXME: uncomment after T89721 is fixed (see T90929)
1112 if ( !( obj instanceof this['class'] ) ) {
1113 throw new Error( 'Infusion type mismatch!' );
1120 * Implementation helper for `infuse`; skips the type check and has an
1121 * extra property so that only the top-level invocation touches the DOM.
1123 * @param {string|HTMLElement|jQuery} idOrNode
1124 * @param {jQuery.Promise|boolean} domPromise A promise that will be resolved
1125 * when the top-level widget of this infusion is inserted into DOM,
1126 * replacing the original node; or false for top-level invocation.
1127 * @return {OO.ui.Element}
1129 OO
.ui
.Element
.static.unsafeInfuse = function ( idOrNode
, domPromise
) {
1130 // look for a cached result of a previous infusion.
1131 var id
, $elem
, data
, cls
, parts
, parent
, obj
, top
, state
;
1132 if ( typeof idOrNode
=== 'string' ) {
1134 $elem
= $( document
.getElementById( id
) );
1136 $elem
= $( idOrNode
);
1137 id
= $elem
.attr( 'id' );
1139 if ( !$elem
.length
) {
1140 throw new Error( 'Widget not found: ' + id
);
1142 data
= $elem
.data( 'ooui-infused' ) || $elem
[0].oouiInfused
;
1145 if ( data
=== true ) {
1146 throw new Error( 'Circular dependency! ' + id
);
1150 data
= $elem
.attr( 'data-ooui' );
1152 throw new Error( 'No infusion data found: ' + id
);
1155 data
= $.parseJSON( data
);
1159 if ( !( data
&& data
._
) ) {
1160 throw new Error( 'No valid infusion data found: ' + id
);
1162 if ( data
._
=== 'Tag' ) {
1163 // Special case: this is a raw Tag; wrap existing node, don't rebuild.
1164 return new OO
.ui
.Element( { $element
: $elem
} );
1166 parts
= data
._
.split( '.' );
1167 cls
= OO
.getProp
.apply( OO
, [ window
].concat( parts
) );
1168 if ( cls
=== undefined ) {
1169 // The PHP output might be old and not including the "OO.ui" prefix
1170 // TODO: Remove this back-compat after next major release
1171 cls
= OO
.getProp
.apply( OO
, [ OO
.ui
].concat( parts
) );
1172 if ( cls
=== undefined ) {
1173 throw new Error( 'Unknown widget type: id: ' + id
+ ', class: ' + data
._
);
1177 // Verify that we're creating an OO.ui.Element instance
1178 parent
= cls
.parent
;
1180 while ( parent
!== undefined ) {
1181 if ( parent
=== OO
.ui
.Element
) {
1186 parent
= parent
.parent
;
1189 if ( parent
!== OO
.ui
.Element
) {
1190 throw new Error( 'Unknown widget type: id: ' + id
+ ', class: ' + data
._
);
1193 if ( domPromise
=== false ) {
1195 domPromise
= top
.promise();
1197 $elem
.data( 'ooui-infused', true ); // prevent loops
1198 data
.id
= id
; // implicit
1199 data
= OO
.copy( data
, null, function deserialize( value
) {
1200 if ( OO
.isPlainObject( value
) ) {
1202 return OO
.ui
.Element
.static.unsafeInfuse( value
.tag
, domPromise
);
1205 return new OO
.ui
.HtmlSnippet( value
.html
);
1209 // jscs:disable requireCapitalizedConstructors
1210 obj
= new cls( data
); // rebuild widget
1211 // pick up dynamic state, like focus, value of form inputs, scroll position, etc.
1212 state
= obj
.gatherPreInfuseState( $elem
);
1213 // now replace old DOM with this new DOM.
1215 $elem
.replaceWith( obj
.$element
);
1216 // This element is now gone from the DOM, but if anyone is holding a reference to it,
1217 // let's allow them to OO.ui.infuse() it and do what they expect (T105828).
1218 // Do not use jQuery.data(), as using it on detached nodes leaks memory in 1.x line by design.
1219 $elem
[0].oouiInfused
= obj
;
1222 obj
.$element
.data( 'ooui-infused', obj
);
1223 // set the 'data-ooui' attribute so we can identify infused widgets
1224 obj
.$element
.attr( 'data-ooui', '' );
1225 // restore dynamic state after the new element is inserted into DOM
1226 domPromise
.done( obj
.restorePreInfuseState
.bind( obj
, state
) );
1231 * Get a jQuery function within a specific document.
1234 * @param {jQuery|HTMLElement|HTMLDocument|Window} context Context to bind the function to
1235 * @param {jQuery} [$iframe] HTML iframe element that contains the document, omit if document is
1237 * @return {Function} Bound jQuery function
1239 OO
.ui
.Element
.static.getJQuery = function ( context
, $iframe
) {
1240 function wrapper( selector
) {
1241 return $( selector
, wrapper
.context
);
1244 wrapper
.context
= this.getDocument( context
);
1247 wrapper
.$iframe
= $iframe
;
1254 * Get the document of an element.
1257 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Object to get the document for
1258 * @return {HTMLDocument|null} Document object
1260 OO
.ui
.Element
.static.getDocument = function ( obj
) {
1261 // jQuery - selections created "offscreen" won't have a context, so .context isn't reliable
1262 return ( obj
[ 0 ] && obj
[ 0 ].ownerDocument
) ||
1263 // Empty jQuery selections might have a context
1266 obj
.ownerDocument
||
1270 ( obj
.nodeType
=== 9 && obj
) ||
1275 * Get the window of an element or document.
1278 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Context to get the window for
1279 * @return {Window} Window object
1281 OO
.ui
.Element
.static.getWindow = function ( obj
) {
1282 var doc
= this.getDocument( obj
);
1283 return doc
.parentWindow
|| doc
.defaultView
;
1287 * Get the direction of an element or document.
1290 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Context to get the direction for
1291 * @return {string} Text direction, either 'ltr' or 'rtl'
1293 OO
.ui
.Element
.static.getDir = function ( obj
) {
1296 if ( obj
instanceof jQuery
) {
1299 isDoc
= obj
.nodeType
=== 9;
1300 isWin
= obj
.document
!== undefined;
1301 if ( isDoc
|| isWin
) {
1307 return $( obj
).css( 'direction' );
1311 * Get the offset between two frames.
1313 * TODO: Make this function not use recursion.
1316 * @param {Window} from Window of the child frame
1317 * @param {Window} [to=window] Window of the parent frame
1318 * @param {Object} [offset] Offset to start with, used internally
1319 * @return {Object} Offset object, containing left and top properties
1321 OO
.ui
.Element
.static.getFrameOffset = function ( from, to
, offset
) {
1322 var i
, len
, frames
, frame
, rect
;
1328 offset
= { top
: 0, left
: 0 };
1330 if ( from.parent
=== from ) {
1334 // Get iframe element
1335 frames
= from.parent
.document
.getElementsByTagName( 'iframe' );
1336 for ( i
= 0, len
= frames
.length
; i
< len
; i
++ ) {
1337 if ( frames
[ i
].contentWindow
=== from ) {
1338 frame
= frames
[ i
];
1343 // Recursively accumulate offset values
1345 rect
= frame
.getBoundingClientRect();
1346 offset
.left
+= rect
.left
;
1347 offset
.top
+= rect
.top
;
1348 if ( from !== to
) {
1349 this.getFrameOffset( from.parent
, offset
);
1356 * Get the offset between two elements.
1358 * The two elements may be in a different frame, but in that case the frame $element is in must
1359 * be contained in the frame $anchor is in.
1362 * @param {jQuery} $element Element whose position to get
1363 * @param {jQuery} $anchor Element to get $element's position relative to
1364 * @return {Object} Translated position coordinates, containing top and left properties
1366 OO
.ui
.Element
.static.getRelativePosition = function ( $element
, $anchor
) {
1367 var iframe
, iframePos
,
1368 pos
= $element
.offset(),
1369 anchorPos
= $anchor
.offset(),
1370 elementDocument
= this.getDocument( $element
),
1371 anchorDocument
= this.getDocument( $anchor
);
1373 // If $element isn't in the same document as $anchor, traverse up
1374 while ( elementDocument
!== anchorDocument
) {
1375 iframe
= elementDocument
.defaultView
.frameElement
;
1377 throw new Error( '$element frame is not contained in $anchor frame' );
1379 iframePos
= $( iframe
).offset();
1380 pos
.left
+= iframePos
.left
;
1381 pos
.top
+= iframePos
.top
;
1382 elementDocument
= iframe
.ownerDocument
;
1384 pos
.left
-= anchorPos
.left
;
1385 pos
.top
-= anchorPos
.top
;
1390 * Get element border sizes.
1393 * @param {HTMLElement} el Element to measure
1394 * @return {Object} Dimensions object with `top`, `left`, `bottom` and `right` properties
1396 OO
.ui
.Element
.static.getBorders = function ( el
) {
1397 var doc
= el
.ownerDocument
,
1398 win
= doc
.parentWindow
|| doc
.defaultView
,
1399 style
= win
&& win
.getComputedStyle
?
1400 win
.getComputedStyle( el
, null ) :
1403 top
= parseFloat( style
? style
.borderTopWidth
: $el
.css( 'borderTopWidth' ) ) || 0,
1404 left
= parseFloat( style
? style
.borderLeftWidth
: $el
.css( 'borderLeftWidth' ) ) || 0,
1405 bottom
= parseFloat( style
? style
.borderBottomWidth
: $el
.css( 'borderBottomWidth' ) ) || 0,
1406 right
= parseFloat( style
? style
.borderRightWidth
: $el
.css( 'borderRightWidth' ) ) || 0;
1417 * Get dimensions of an element or window.
1420 * @param {HTMLElement|Window} el Element to measure
1421 * @return {Object} Dimensions object with `borders`, `scroll`, `scrollbar` and `rect` properties
1423 OO
.ui
.Element
.static.getDimensions = function ( el
) {
1425 doc
= el
.ownerDocument
|| el
.document
,
1426 win
= doc
.parentWindow
|| doc
.defaultView
;
1428 if ( win
=== el
|| el
=== doc
.documentElement
) {
1431 borders
: { top
: 0, left
: 0, bottom
: 0, right
: 0 },
1433 top
: $win
.scrollTop(),
1434 left
: $win
.scrollLeft()
1436 scrollbar
: { right
: 0, bottom
: 0 },
1440 bottom
: $win
.innerHeight(),
1441 right
: $win
.innerWidth()
1447 borders
: this.getBorders( el
),
1449 top
: $el
.scrollTop(),
1450 left
: $el
.scrollLeft()
1453 right
: $el
.innerWidth() - el
.clientWidth
,
1454 bottom
: $el
.innerHeight() - el
.clientHeight
1456 rect
: el
.getBoundingClientRect()
1462 * Get scrollable object parent
1464 * documentElement can't be used to get or set the scrollTop
1465 * property on Blink. Changing and testing its value lets us
1466 * use 'body' or 'documentElement' based on what is working.
1468 * https://code.google.com/p/chromium/issues/detail?id=303131
1471 * @param {HTMLElement} el Element to find scrollable parent for
1472 * @return {HTMLElement} Scrollable parent
1474 OO
.ui
.Element
.static.getRootScrollableElement = function ( el
) {
1475 var scrollTop
, body
;
1477 if ( OO
.ui
.scrollableElement
=== undefined ) {
1478 body
= el
.ownerDocument
.body
;
1479 scrollTop
= body
.scrollTop
;
1482 if ( body
.scrollTop
=== 1 ) {
1483 body
.scrollTop
= scrollTop
;
1484 OO
.ui
.scrollableElement
= 'body';
1486 OO
.ui
.scrollableElement
= 'documentElement';
1490 return el
.ownerDocument
[ OO
.ui
.scrollableElement
];
1494 * Get closest scrollable container.
1496 * Traverses up until either a scrollable element or the root is reached, in which case the window
1500 * @param {HTMLElement} el Element to find scrollable container for
1501 * @param {string} [dimension] Dimension of scrolling to look for; `x`, `y` or omit for either
1502 * @return {HTMLElement} Closest scrollable container
1504 OO
.ui
.Element
.static.getClosestScrollableContainer = function ( el
, dimension
) {
1506 // props = [ 'overflow' ] doesn't work due to https://bugzilla.mozilla.org/show_bug.cgi?id=889091
1507 props
= [ 'overflow-x', 'overflow-y' ],
1508 $parent
= $( el
).parent();
1510 if ( dimension
=== 'x' || dimension
=== 'y' ) {
1511 props
= [ 'overflow-' + dimension
];
1514 while ( $parent
.length
) {
1515 if ( $parent
[ 0 ] === this.getRootScrollableElement( el
) ) {
1516 return $parent
[ 0 ];
1520 val
= $parent
.css( props
[ i
] );
1521 if ( val
=== 'auto' || val
=== 'scroll' ) {
1522 return $parent
[ 0 ];
1525 $parent
= $parent
.parent();
1527 return this.getDocument( el
).body
;
1531 * Scroll element into view.
1534 * @param {HTMLElement} el Element to scroll into view
1535 * @param {Object} [config] Configuration options
1536 * @param {string} [config.duration] jQuery animation duration value
1537 * @param {string} [config.direction] Scroll in only one direction, e.g. 'x' or 'y', omit
1538 * to scroll in both directions
1539 * @param {Function} [config.complete] Function to call when scrolling completes
1541 OO
.ui
.Element
.static.scrollIntoView = function ( el
, config
) {
1542 // Configuration initialization
1543 config
= config
|| {};
1546 callback
= typeof config
.complete
=== 'function' && config
.complete
,
1547 sc
= this.getClosestScrollableContainer( el
, config
.direction
),
1549 eld
= this.getDimensions( el
),
1550 scd
= this.getDimensions( sc
),
1551 $win
= $( this.getWindow( el
) );
1553 // Compute the distances between the edges of el and the edges of the scroll viewport
1554 if ( $sc
.is( 'html, body' ) ) {
1555 // If the scrollable container is the root, this is easy
1558 bottom
: $win
.innerHeight() - eld
.rect
.bottom
,
1559 left
: eld
.rect
.left
,
1560 right
: $win
.innerWidth() - eld
.rect
.right
1563 // Otherwise, we have to subtract el's coordinates from sc's coordinates
1565 top
: eld
.rect
.top
- ( scd
.rect
.top
+ scd
.borders
.top
),
1566 bottom
: scd
.rect
.bottom
- scd
.borders
.bottom
- scd
.scrollbar
.bottom
- eld
.rect
.bottom
,
1567 left
: eld
.rect
.left
- ( scd
.rect
.left
+ scd
.borders
.left
),
1568 right
: scd
.rect
.right
- scd
.borders
.right
- scd
.scrollbar
.right
- eld
.rect
.right
1572 if ( !config
.direction
|| config
.direction
=== 'y' ) {
1573 if ( rel
.top
< 0 ) {
1574 anim
.scrollTop
= scd
.scroll
.top
+ rel
.top
;
1575 } else if ( rel
.top
> 0 && rel
.bottom
< 0 ) {
1576 anim
.scrollTop
= scd
.scroll
.top
+ Math
.min( rel
.top
, -rel
.bottom
);
1579 if ( !config
.direction
|| config
.direction
=== 'x' ) {
1580 if ( rel
.left
< 0 ) {
1581 anim
.scrollLeft
= scd
.scroll
.left
+ rel
.left
;
1582 } else if ( rel
.left
> 0 && rel
.right
< 0 ) {
1583 anim
.scrollLeft
= scd
.scroll
.left
+ Math
.min( rel
.left
, -rel
.right
);
1586 if ( !$.isEmptyObject( anim
) ) {
1587 $sc
.stop( true ).animate( anim
, config
.duration
|| 'fast' );
1589 $sc
.queue( function ( next
) {
1602 * Force the browser to reconsider whether it really needs to render scrollbars inside the element
1603 * and reserve space for them, because it probably doesn't.
1605 * Workaround primarily for <https://code.google.com/p/chromium/issues/detail?id=387290>, but also
1606 * similar bugs in other browsers. "Just" forcing a reflow is not sufficient in all cases, we need
1607 * to first actually detach (or hide, but detaching is simpler) all children, *then* force a reflow,
1608 * and then reattach (or show) them back.
1611 * @param {HTMLElement} el Element to reconsider the scrollbars on
1613 OO
.ui
.Element
.static.reconsiderScrollbars = function ( el
) {
1614 var i
, len
, scrollLeft
, scrollTop
, nodes
= [];
1615 // Save scroll position
1616 scrollLeft
= el
.scrollLeft
;
1617 scrollTop
= el
.scrollTop
;
1618 // Detach all children
1619 while ( el
.firstChild
) {
1620 nodes
.push( el
.firstChild
);
1621 el
.removeChild( el
.firstChild
);
1624 void el
.offsetHeight
;
1625 // Reattach all children
1626 for ( i
= 0, len
= nodes
.length
; i
< len
; i
++ ) {
1627 el
.appendChild( nodes
[ i
] );
1629 // Restore scroll position (no-op if scrollbars disappeared)
1630 el
.scrollLeft
= scrollLeft
;
1631 el
.scrollTop
= scrollTop
;
1637 * Toggle visibility of an element.
1639 * @param {boolean} [show] Make element visible, omit to toggle visibility
1643 OO
.ui
.Element
.prototype.toggle = function ( show
) {
1644 show
= show
=== undefined ? !this.visible
: !!show
;
1646 if ( show
!== this.isVisible() ) {
1647 this.visible
= show
;
1648 this.$element
.toggleClass( 'oo-ui-element-hidden', !this.visible
);
1649 this.emit( 'toggle', show
);
1656 * Check if element is visible.
1658 * @return {boolean} element is visible
1660 OO
.ui
.Element
.prototype.isVisible = function () {
1661 return this.visible
;
1667 * @return {Mixed} Element data
1669 OO
.ui
.Element
.prototype.getData = function () {
1676 * @param {Mixed} Element data
1679 OO
.ui
.Element
.prototype.setData = function ( data
) {
1685 * Check if element supports one or more methods.
1687 * @param {string|string[]} methods Method or list of methods to check
1688 * @return {boolean} All methods are supported
1690 OO
.ui
.Element
.prototype.supports = function ( methods
) {
1694 methods
= Array
.isArray( methods
) ? methods
: [ methods
];
1695 for ( i
= 0, len
= methods
.length
; i
< len
; i
++ ) {
1696 if ( $.isFunction( this[ methods
[ i
] ] ) ) {
1701 return methods
.length
=== support
;
1705 * Update the theme-provided classes.
1707 * @localdoc This is called in element mixins and widget classes any time state changes.
1708 * Updating is debounced, minimizing overhead of changing multiple attributes and
1709 * guaranteeing that theme updates do not occur within an element's constructor
1711 OO
.ui
.Element
.prototype.updateThemeClasses = function () {
1712 if ( !this.updateThemeClassesPending
) {
1713 this.updateThemeClassesPending
= true;
1714 setTimeout( this.debouncedUpdateThemeClassesHandler
);
1721 OO
.ui
.Element
.prototype.debouncedUpdateThemeClasses = function () {
1722 OO
.ui
.theme
.updateElementClasses( this );
1723 this.updateThemeClassesPending
= false;
1727 * Get the HTML tag name.
1729 * Override this method to base the result on instance information.
1731 * @return {string} HTML tag name
1733 OO
.ui
.Element
.prototype.getTagName = function () {
1734 return this.constructor.static.tagName
;
1738 * Check if the element is attached to the DOM
1739 * @return {boolean} The element is attached to the DOM
1741 OO
.ui
.Element
.prototype.isElementAttached = function () {
1742 return $.contains( this.getElementDocument(), this.$element
[ 0 ] );
1746 * Get the DOM document.
1748 * @return {HTMLDocument} Document object
1750 OO
.ui
.Element
.prototype.getElementDocument = function () {
1751 // Don't cache this in other ways either because subclasses could can change this.$element
1752 return OO
.ui
.Element
.static.getDocument( this.$element
);
1756 * Get the DOM window.
1758 * @return {Window} Window object
1760 OO
.ui
.Element
.prototype.getElementWindow = function () {
1761 return OO
.ui
.Element
.static.getWindow( this.$element
);
1765 * Get closest scrollable container.
1767 OO
.ui
.Element
.prototype.getClosestScrollableElementContainer = function () {
1768 return OO
.ui
.Element
.static.getClosestScrollableContainer( this.$element
[ 0 ] );
1772 * Get group element is in.
1774 * @return {OO.ui.mixin.GroupElement|null} Group element, null if none
1776 OO
.ui
.Element
.prototype.getElementGroup = function () {
1777 return this.elementGroup
;
1781 * Set group element is in.
1783 * @param {OO.ui.mixin.GroupElement|null} group Group element, null if none
1786 OO
.ui
.Element
.prototype.setElementGroup = function ( group
) {
1787 this.elementGroup
= group
;
1792 * Scroll element into view.
1794 * @param {Object} [config] Configuration options
1796 OO
.ui
.Element
.prototype.scrollElementIntoView = function ( config
) {
1797 return OO
.ui
.Element
.static.scrollIntoView( this.$element
[ 0 ], config
);
1801 * Gather the dynamic state (focus, value of form inputs, scroll position, etc.) of a HTML DOM node
1802 * (and its children) that represent an Element of the same type and configuration as the current
1803 * one, generated by the PHP implementation.
1805 * This method is called just before `node` is detached from the DOM. The return value of this
1806 * function will be passed to #restorePreInfuseState after this widget's #$element is inserted into
1807 * DOM to replace `node`.
1810 * @param {HTMLElement} node
1813 OO
.ui
.Element
.prototype.gatherPreInfuseState = function () {
1818 * Restore the pre-infusion dynamic state for this widget.
1820 * This method is called after #$element has been inserted into DOM. The parameter is the return
1821 * value of #gatherPreInfuseState.
1824 * @param {Object} state
1826 OO
.ui
.Element
.prototype.restorePreInfuseState = function () {
1830 * Layouts are containers for elements and are used to arrange other widgets of arbitrary type in a way
1831 * that is centrally controlled and can be updated dynamically. Layouts can be, and usually are, combined.
1832 * See {@link OO.ui.FieldsetLayout FieldsetLayout}, {@link OO.ui.FieldLayout FieldLayout}, {@link OO.ui.FormLayout FormLayout},
1833 * {@link OO.ui.PanelLayout PanelLayout}, {@link OO.ui.StackLayout StackLayout}, {@link OO.ui.PageLayout PageLayout},
1834 * {@link OO.ui.HorizontalLayout HorizontalLayout}, and {@link OO.ui.BookletLayout BookletLayout} for more information and examples.
1838 * @extends OO.ui.Element
1839 * @mixins OO.EventEmitter
1842 * @param {Object} [config] Configuration options
1844 OO
.ui
.Layout
= function OoUiLayout( config
) {
1845 // Configuration initialization
1846 config
= config
|| {};
1848 // Parent constructor
1849 OO
.ui
.Layout
.parent
.call( this, config
);
1851 // Mixin constructors
1852 OO
.EventEmitter
.call( this );
1855 this.$element
.addClass( 'oo-ui-layout' );
1860 OO
.inheritClass( OO
.ui
.Layout
, OO
.ui
.Element
);
1861 OO
.mixinClass( OO
.ui
.Layout
, OO
.EventEmitter
);
1864 * Widgets are compositions of one or more OOjs UI elements that users can both view
1865 * and interact with. All widgets can be configured and modified via a standard API,
1866 * and their state can change dynamically according to a model.
1870 * @extends OO.ui.Element
1871 * @mixins OO.EventEmitter
1874 * @param {Object} [config] Configuration options
1875 * @cfg {boolean} [disabled=false] Disable the widget. Disabled widgets cannot be used and their
1876 * appearance reflects this state.
1878 OO
.ui
.Widget
= function OoUiWidget( config
) {
1879 // Initialize config
1880 config
= $.extend( { disabled
: false }, config
);
1882 // Parent constructor
1883 OO
.ui
.Widget
.parent
.call( this, config
);
1885 // Mixin constructors
1886 OO
.EventEmitter
.call( this );
1889 this.disabled
= null;
1890 this.wasDisabled
= null;
1893 this.$element
.addClass( 'oo-ui-widget' );
1894 this.setDisabled( !!config
.disabled
);
1899 OO
.inheritClass( OO
.ui
.Widget
, OO
.ui
.Element
);
1900 OO
.mixinClass( OO
.ui
.Widget
, OO
.EventEmitter
);
1902 /* Static Properties */
1905 * Whether this widget will behave reasonably when wrapped in a HTML `<label>`. If this is true,
1906 * wrappers such as OO.ui.FieldLayout may use a `<label>` instead of implementing own label click
1911 * @property {boolean}
1913 OO
.ui
.Widget
.static.supportsSimpleLabel
= false;
1920 * A 'disable' event is emitted when a widget is disabled.
1922 * @param {boolean} disabled Widget is disabled
1928 * A 'toggle' event is emitted when the visibility of the widget changes.
1930 * @param {boolean} visible Widget is visible
1936 * Check if the widget is disabled.
1938 * @return {boolean} Widget is disabled
1940 OO
.ui
.Widget
.prototype.isDisabled = function () {
1941 return this.disabled
;
1945 * Set the 'disabled' state of the widget.
1947 * When a widget is disabled, it cannot be used and its appearance is updated to reflect this state.
1949 * @param {boolean} disabled Disable widget
1952 OO
.ui
.Widget
.prototype.setDisabled = function ( disabled
) {
1955 this.disabled
= !!disabled
;
1956 isDisabled
= this.isDisabled();
1957 if ( isDisabled
!== this.wasDisabled
) {
1958 this.$element
.toggleClass( 'oo-ui-widget-disabled', isDisabled
);
1959 this.$element
.toggleClass( 'oo-ui-widget-enabled', !isDisabled
);
1960 this.$element
.attr( 'aria-disabled', isDisabled
.toString() );
1961 this.emit( 'disable', isDisabled
);
1962 this.updateThemeClasses();
1964 this.wasDisabled
= isDisabled
;
1970 * Update the disabled state, in case of changes in parent widget.
1974 OO
.ui
.Widget
.prototype.updateDisabled = function () {
1975 this.setDisabled( this.disabled
);
1980 * A window is a container for elements that are in a child frame. They are used with
1981 * a window manager (OO.ui.WindowManager), which is used to open and close the window and control
1982 * its presentation. The size of a window is specified using a symbolic name (e.g., ‘small’, ‘medium’,
1983 * ‘large’), which is interpreted by the window manager. If the requested size is not recognized,
1984 * the window manager will choose a sensible fallback.
1986 * The lifecycle of a window has three primary stages (opening, opened, and closing) in which
1987 * different processes are executed:
1989 * **opening**: The opening stage begins when the window manager's {@link OO.ui.WindowManager#openWindow
1990 * openWindow} or the window's {@link #open open} methods are used, and the window manager begins to open
1993 * - {@link #getSetupProcess} method is called and its result executed
1994 * - {@link #getReadyProcess} method is called and its result executed
1996 * **opened**: The window is now open
1998 * **closing**: The closing stage begins when the window manager's
1999 * {@link OO.ui.WindowManager#closeWindow closeWindow}
2000 * or the window's {@link #close} methods are used, and the window manager begins to close the window.
2002 * - {@link #getHoldProcess} method is called and its result executed
2003 * - {@link #getTeardownProcess} method is called and its result executed. The window is now closed
2005 * Each of the window's processes (setup, ready, hold, and teardown) can be extended in subclasses
2006 * by overriding the window's #getSetupProcess, #getReadyProcess, #getHoldProcess and #getTeardownProcess
2007 * methods. Note that each {@link OO.ui.Process process} is executed in series, so asynchronous
2008 * processing can complete. Always assume window processes are executed asynchronously.
2010 * For more information, please see the [OOjs UI documentation on MediaWiki] [1].
2012 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows
2016 * @extends OO.ui.Element
2017 * @mixins OO.EventEmitter
2020 * @param {Object} [config] Configuration options
2021 * @cfg {string} [size] Symbolic name of the dialog size: `small`, `medium`, `large`, `larger` or
2022 * `full`. If omitted, the value of the {@link #static-size static size} property will be used.
2024 OO
.ui
.Window
= function OoUiWindow( config
) {
2025 // Configuration initialization
2026 config
= config
|| {};
2028 // Parent constructor
2029 OO
.ui
.Window
.parent
.call( this, config
);
2031 // Mixin constructors
2032 OO
.EventEmitter
.call( this );
2035 this.manager
= null;
2036 this.size
= config
.size
|| this.constructor.static.size
;
2037 this.$frame
= $( '<div>' );
2038 this.$overlay
= $( '<div>' );
2039 this.$content
= $( '<div>' );
2042 this.$overlay
.addClass( 'oo-ui-window-overlay' );
2044 .addClass( 'oo-ui-window-content' )
2045 .attr( 'tabindex', 0 );
2047 .addClass( 'oo-ui-window-frame' )
2048 .append( this.$content
);
2051 .addClass( 'oo-ui-window' )
2052 .append( this.$frame
, this.$overlay
);
2054 // Initially hidden - using #toggle may cause errors if subclasses override toggle with methods
2055 // that reference properties not initialized at that time of parent class construction
2056 // TODO: Find a better way to handle post-constructor setup
2057 this.visible
= false;
2058 this.$element
.addClass( 'oo-ui-element-hidden' );
2063 OO
.inheritClass( OO
.ui
.Window
, OO
.ui
.Element
);
2064 OO
.mixinClass( OO
.ui
.Window
, OO
.EventEmitter
);
2066 /* Static Properties */
2069 * Symbolic name of the window size: `small`, `medium`, `large`, `larger` or `full`.
2071 * The static size is used if no #size is configured during construction.
2075 * @property {string}
2077 OO
.ui
.Window
.static.size
= 'medium';
2082 * Handle mouse down events.
2085 * @param {jQuery.Event} e Mouse down event
2087 OO
.ui
.Window
.prototype.onMouseDown = function ( e
) {
2088 // Prevent clicking on the click-block from stealing focus
2089 if ( e
.target
=== this.$element
[ 0 ] ) {
2095 * Check if the window has been initialized.
2097 * Initialization occurs when a window is added to a manager.
2099 * @return {boolean} Window has been initialized
2101 OO
.ui
.Window
.prototype.isInitialized = function () {
2102 return !!this.manager
;
2106 * Check if the window is visible.
2108 * @return {boolean} Window is visible
2110 OO
.ui
.Window
.prototype.isVisible = function () {
2111 return this.visible
;
2115 * Check if the window is opening.
2117 * This method is a wrapper around the window manager's {@link OO.ui.WindowManager#isOpening isOpening}
2120 * @return {boolean} Window is opening
2122 OO
.ui
.Window
.prototype.isOpening = function () {
2123 return this.manager
.isOpening( this );
2127 * Check if the window is closing.
2129 * This method is a wrapper around the window manager's {@link OO.ui.WindowManager#isClosing isClosing} method.
2131 * @return {boolean} Window is closing
2133 OO
.ui
.Window
.prototype.isClosing = function () {
2134 return this.manager
.isClosing( this );
2138 * Check if the window is opened.
2140 * This method is a wrapper around the window manager's {@link OO.ui.WindowManager#isOpened isOpened} method.
2142 * @return {boolean} Window is opened
2144 OO
.ui
.Window
.prototype.isOpened = function () {
2145 return this.manager
.isOpened( this );
2149 * Get the window manager.
2151 * All windows must be attached to a window manager, which is used to open
2152 * and close the window and control its presentation.
2154 * @return {OO.ui.WindowManager} Manager of window
2156 OO
.ui
.Window
.prototype.getManager = function () {
2157 return this.manager
;
2161 * Get the symbolic name of the window size (e.g., `small` or `medium`).
2163 * @return {string} Symbolic name of the size: `small`, `medium`, `large`, `larger`, `full`
2165 OO
.ui
.Window
.prototype.getSize = function () {
2166 var viewport
= OO
.ui
.Element
.static.getDimensions( this.getElementWindow() ),
2167 sizes
= this.manager
.constructor.static.sizes
,
2170 if ( !sizes
[ size
] ) {
2171 size
= this.manager
.constructor.static.defaultSize
;
2173 if ( size
!== 'full' && viewport
.rect
.right
- viewport
.rect
.left
< sizes
[ size
].width
) {
2181 * Get the size properties associated with the current window size
2183 * @return {Object} Size properties
2185 OO
.ui
.Window
.prototype.getSizeProperties = function () {
2186 return this.manager
.constructor.static.sizes
[ this.getSize() ];
2190 * Disable transitions on window's frame for the duration of the callback function, then enable them
2194 * @param {Function} callback Function to call while transitions are disabled
2196 OO
.ui
.Window
.prototype.withoutSizeTransitions = function ( callback
) {
2197 // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements.
2198 // Disable transitions first, otherwise we'll get values from when the window was animating.
2200 styleObj
= this.$frame
[ 0 ].style
;
2201 oldTransition
= styleObj
.transition
|| styleObj
.OTransition
|| styleObj
.MsTransition
||
2202 styleObj
.MozTransition
|| styleObj
.WebkitTransition
;
2203 styleObj
.transition
= styleObj
.OTransition
= styleObj
.MsTransition
=
2204 styleObj
.MozTransition
= styleObj
.WebkitTransition
= 'none';
2206 // Force reflow to make sure the style changes done inside callback really are not transitioned
2207 this.$frame
.height();
2208 styleObj
.transition
= styleObj
.OTransition
= styleObj
.MsTransition
=
2209 styleObj
.MozTransition
= styleObj
.WebkitTransition
= oldTransition
;
2213 * Get the height of the full window contents (i.e., the window head, body and foot together).
2215 * What consistitutes the head, body, and foot varies depending on the window type.
2216 * A {@link OO.ui.MessageDialog message dialog} displays a title and message in its body,
2217 * and any actions in the foot. A {@link OO.ui.ProcessDialog process dialog} displays a title
2218 * and special actions in the head, and dialog content in the body.
2220 * To get just the height of the dialog body, use the #getBodyHeight method.
2222 * @return {number} The height of the window contents (the dialog head, body and foot) in pixels
2224 OO
.ui
.Window
.prototype.getContentHeight = function () {
2227 bodyStyleObj
= this.$body
[ 0 ].style
,
2228 frameStyleObj
= this.$frame
[ 0 ].style
;
2230 // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements.
2231 // Disable transitions first, otherwise we'll get values from when the window was animating.
2232 this.withoutSizeTransitions( function () {
2233 var oldHeight
= frameStyleObj
.height
,
2234 oldPosition
= bodyStyleObj
.position
;
2235 frameStyleObj
.height
= '1px';
2236 // Force body to resize to new width
2237 bodyStyleObj
.position
= 'relative';
2238 bodyHeight
= win
.getBodyHeight();
2239 frameStyleObj
.height
= oldHeight
;
2240 bodyStyleObj
.position
= oldPosition
;
2244 // Add buffer for border
2245 ( this.$frame
.outerHeight() - this.$frame
.innerHeight() ) +
2246 // Use combined heights of children
2247 ( this.$head
.outerHeight( true ) + bodyHeight
+ this.$foot
.outerHeight( true ) )
2252 * Get the height of the window body.
2254 * To get the height of the full window contents (the window body, head, and foot together),
2255 * use #getContentHeight.
2257 * When this function is called, the window will temporarily have been resized
2258 * to height=1px, so .scrollHeight measurements can be taken accurately.
2260 * @return {number} Height of the window body in pixels
2262 OO
.ui
.Window
.prototype.getBodyHeight = function () {
2263 return this.$body
[ 0 ].scrollHeight
;
2267 * Get the directionality of the frame (right-to-left or left-to-right).
2269 * @return {string} Directionality: `'ltr'` or `'rtl'`
2271 OO
.ui
.Window
.prototype.getDir = function () {
2272 return OO
.ui
.Element
.static.getDir( this.$content
) || 'ltr';
2276 * Get the 'setup' process.
2278 * The setup process is used to set up a window for use in a particular context,
2279 * based on the `data` argument. This method is called during the opening phase of the window’s
2282 * Override this method to add additional steps to the ‘setup’ process the parent method provides
2283 * using the {@link OO.ui.Process#first first} and {@link OO.ui.Process#next next} methods
2286 * To add window content that persists between openings, you may wish to use the #initialize method
2290 * @param {Object} [data] Window opening data
2291 * @return {OO.ui.Process} Setup process
2293 OO
.ui
.Window
.prototype.getSetupProcess = function () {
2294 return new OO
.ui
.Process();
2298 * Get the ‘ready’ process.
2300 * The ready process is used to ready a window for use in a particular
2301 * context, based on the `data` argument. This method is called during the opening phase of
2302 * the window’s lifecycle, after the window has been {@link #getSetupProcess setup}.
2304 * Override this method to add additional steps to the ‘ready’ process the parent method
2305 * provides using the {@link OO.ui.Process#first first} and {@link OO.ui.Process#next next}
2306 * methods of OO.ui.Process.
2309 * @param {Object} [data] Window opening data
2310 * @return {OO.ui.Process} Ready process
2312 OO
.ui
.Window
.prototype.getReadyProcess = function () {
2313 return new OO
.ui
.Process();
2317 * Get the 'hold' process.
2319 * The hold proccess is used to keep a window from being used in a particular context,
2320 * based on the `data` argument. This method is called during the closing phase of the window’s
2323 * Override this method to add additional steps to the 'hold' process the parent method provides
2324 * using the {@link OO.ui.Process#first first} and {@link OO.ui.Process#next next} methods
2328 * @param {Object} [data] Window closing data
2329 * @return {OO.ui.Process} Hold process
2331 OO
.ui
.Window
.prototype.getHoldProcess = function () {
2332 return new OO
.ui
.Process();
2336 * Get the ‘teardown’ process.
2338 * The teardown process is used to teardown a window after use. During teardown,
2339 * user interactions within the window are conveyed and the window is closed, based on the `data`
2340 * argument. This method is called during the closing phase of the window’s lifecycle.
2342 * Override this method to add additional steps to the ‘teardown’ process the parent method provides
2343 * using the {@link OO.ui.Process#first first} and {@link OO.ui.Process#next next} methods
2347 * @param {Object} [data] Window closing data
2348 * @return {OO.ui.Process} Teardown process
2350 OO
.ui
.Window
.prototype.getTeardownProcess = function () {
2351 return new OO
.ui
.Process();
2355 * Set the window manager.
2357 * This will cause the window to initialize. Calling it more than once will cause an error.
2359 * @param {OO.ui.WindowManager} manager Manager for this window
2360 * @throws {Error} An error is thrown if the method is called more than once
2363 OO
.ui
.Window
.prototype.setManager = function ( manager
) {
2364 if ( this.manager
) {
2365 throw new Error( 'Cannot set window manager, window already has a manager' );
2368 this.manager
= manager
;
2375 * Set the window size by symbolic name (e.g., 'small' or 'medium')
2377 * @param {string} size Symbolic name of size: `small`, `medium`, `large`, `larger` or
2381 OO
.ui
.Window
.prototype.setSize = function ( size
) {
2388 * Update the window size.
2390 * @throws {Error} An error is thrown if the window is not attached to a window manager
2393 OO
.ui
.Window
.prototype.updateSize = function () {
2394 if ( !this.manager
) {
2395 throw new Error( 'Cannot update window size, must be attached to a manager' );
2398 this.manager
.updateWindowSize( this );
2404 * Set window dimensions. This method is called by the {@link OO.ui.WindowManager window manager}
2405 * when the window is opening. In general, setDimensions should not be called directly.
2407 * To set the size of the window, use the #setSize method.
2409 * @param {Object} dim CSS dimension properties
2410 * @param {string|number} [dim.width] Width
2411 * @param {string|number} [dim.minWidth] Minimum width
2412 * @param {string|number} [dim.maxWidth] Maximum width
2413 * @param {string|number} [dim.width] Height, omit to set based on height of contents
2414 * @param {string|number} [dim.minWidth] Minimum height
2415 * @param {string|number} [dim.maxWidth] Maximum height
2418 OO
.ui
.Window
.prototype.setDimensions = function ( dim
) {
2421 styleObj
= this.$frame
[ 0 ].style
;
2423 // Calculate the height we need to set using the correct width
2424 if ( dim
.height
=== undefined ) {
2425 this.withoutSizeTransitions( function () {
2426 var oldWidth
= styleObj
.width
;
2427 win
.$frame
.css( 'width', dim
.width
|| '' );
2428 height
= win
.getContentHeight();
2429 styleObj
.width
= oldWidth
;
2432 height
= dim
.height
;
2436 width
: dim
.width
|| '',
2437 minWidth
: dim
.minWidth
|| '',
2438 maxWidth
: dim
.maxWidth
|| '',
2439 height
: height
|| '',
2440 minHeight
: dim
.minHeight
|| '',
2441 maxHeight
: dim
.maxHeight
|| ''
2448 * Initialize window contents.
2450 * Before the window is opened for the first time, #initialize is called so that content that
2451 * persists between openings can be added to the window.
2453 * To set up a window with new content each time the window opens, use #getSetupProcess.
2455 * @throws {Error} An error is thrown if the window is not attached to a window manager
2458 OO
.ui
.Window
.prototype.initialize = function () {
2459 if ( !this.manager
) {
2460 throw new Error( 'Cannot initialize window, must be attached to a manager' );
2464 this.$head
= $( '<div>' );
2465 this.$body
= $( '<div>' );
2466 this.$foot
= $( '<div>' );
2467 this.$document
= $( this.getElementDocument() );
2470 this.$element
.on( 'mousedown', this.onMouseDown
.bind( this ) );
2473 this.$head
.addClass( 'oo-ui-window-head' );
2474 this.$body
.addClass( 'oo-ui-window-body' );
2475 this.$foot
.addClass( 'oo-ui-window-foot' );
2476 this.$content
.append( this.$head
, this.$body
, this.$foot
);
2484 * This method is a wrapper around a call to the window manager’s {@link OO.ui.WindowManager#openWindow openWindow}
2485 * method, which returns a promise resolved when the window is done opening.
2487 * To customize the window each time it opens, use #getSetupProcess or #getReadyProcess.
2489 * @param {Object} [data] Window opening data
2490 * @return {jQuery.Promise} Promise resolved with a value when the window is opened, or rejected
2491 * if the window fails to open. When the promise is resolved successfully, the first argument of the
2492 * value is a new promise, which is resolved when the window begins closing.
2493 * @throws {Error} An error is thrown if the window is not attached to a window manager
2495 OO
.ui
.Window
.prototype.open = function ( data
) {
2496 if ( !this.manager
) {
2497 throw new Error( 'Cannot open window, must be attached to a manager' );
2500 return this.manager
.openWindow( this, data
);
2506 * This method is a wrapper around a call to the window
2507 * manager’s {@link OO.ui.WindowManager#closeWindow closeWindow} method,
2508 * which returns a closing promise resolved when the window is done closing.
2510 * The window's #getHoldProcess and #getTeardownProcess methods are called during the closing
2511 * phase of the window’s lifecycle and can be used to specify closing behavior each time
2512 * the window closes.
2514 * @param {Object} [data] Window closing data
2515 * @return {jQuery.Promise} Promise resolved when window is closed
2516 * @throws {Error} An error is thrown if the window is not attached to a window manager
2518 OO
.ui
.Window
.prototype.close = function ( data
) {
2519 if ( !this.manager
) {
2520 throw new Error( 'Cannot close window, must be attached to a manager' );
2523 return this.manager
.closeWindow( this, data
);
2529 * This is called by OO.ui.WindowManager during window opening, and should not be called directly
2532 * @param {Object} [data] Window opening data
2533 * @return {jQuery.Promise} Promise resolved when window is setup
2535 OO
.ui
.Window
.prototype.setup = function ( data
) {
2537 deferred
= $.Deferred();
2539 this.toggle( true );
2541 this.getSetupProcess( data
).execute().done( function () {
2542 // Force redraw by asking the browser to measure the elements' widths
2543 win
.$element
.addClass( 'oo-ui-window-active oo-ui-window-setup' ).width();
2544 win
.$content
.addClass( 'oo-ui-window-content-setup' ).width();
2548 return deferred
.promise();
2554 * This is called by OO.ui.WindowManager during window opening, and should not be called directly
2557 * @param {Object} [data] Window opening data
2558 * @return {jQuery.Promise} Promise resolved when window is ready
2560 OO
.ui
.Window
.prototype.ready = function ( data
) {
2562 deferred
= $.Deferred();
2564 this.$content
.focus();
2565 this.getReadyProcess( data
).execute().done( function () {
2566 // Force redraw by asking the browser to measure the elements' widths
2567 win
.$element
.addClass( 'oo-ui-window-ready' ).width();
2568 win
.$content
.addClass( 'oo-ui-window-content-ready' ).width();
2572 return deferred
.promise();
2578 * This is called by OO.ui.WindowManager during window closing, and should not be called directly
2581 * @param {Object} [data] Window closing data
2582 * @return {jQuery.Promise} Promise resolved when window is held
2584 OO
.ui
.Window
.prototype.hold = function ( data
) {
2586 deferred
= $.Deferred();
2588 this.getHoldProcess( data
).execute().done( function () {
2589 // Get the focused element within the window's content
2590 var $focus
= win
.$content
.find( OO
.ui
.Element
.static.getDocument( win
.$content
).activeElement
);
2592 // Blur the focused element
2593 if ( $focus
.length
) {
2597 // Force redraw by asking the browser to measure the elements' widths
2598 win
.$element
.removeClass( 'oo-ui-window-ready' ).width();
2599 win
.$content
.removeClass( 'oo-ui-window-content-ready' ).width();
2603 return deferred
.promise();
2609 * This is called by OO.ui.WindowManager during window closing, and should not be called directly
2612 * @param {Object} [data] Window closing data
2613 * @return {jQuery.Promise} Promise resolved when window is torn down
2615 OO
.ui
.Window
.prototype.teardown = function ( data
) {
2618 return this.getTeardownProcess( data
).execute()
2619 .done( function () {
2620 // Force redraw by asking the browser to measure the elements' widths
2621 win
.$element
.removeClass( 'oo-ui-window-active oo-ui-window-setup' ).width();
2622 win
.$content
.removeClass( 'oo-ui-window-content-setup' ).width();
2623 win
.toggle( false );
2628 * The Dialog class serves as the base class for the other types of dialogs.
2629 * Unless extended to include controls, the rendered dialog box is a simple window
2630 * that users can close by hitting the ‘Esc’ key. Dialog windows are used with OO.ui.WindowManager,
2631 * which opens, closes, and controls the presentation of the window. See the
2632 * [OOjs UI documentation on MediaWiki] [1] for more information.
2635 * // A simple dialog window.
2636 * function MyDialog( config ) {
2637 * MyDialog.parent.call( this, config );
2639 * OO.inheritClass( MyDialog, OO.ui.Dialog );
2640 * MyDialog.prototype.initialize = function () {
2641 * MyDialog.parent.prototype.initialize.call( this );
2642 * this.content = new OO.ui.PanelLayout( { padded: true, expanded: false } );
2643 * this.content.$element.append( '<p>A simple dialog window. Press \'Esc\' to close.</p>' );
2644 * this.$body.append( this.content.$element );
2646 * MyDialog.prototype.getBodyHeight = function () {
2647 * return this.content.$element.outerHeight( true );
2649 * var myDialog = new MyDialog( {
2652 * // Create and append a window manager, which opens and closes the window.
2653 * var windowManager = new OO.ui.WindowManager();
2654 * $( 'body' ).append( windowManager.$element );
2655 * windowManager.addWindows( [ myDialog ] );
2656 * // Open the window!
2657 * windowManager.openWindow( myDialog );
2659 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Dialogs
2663 * @extends OO.ui.Window
2664 * @mixins OO.ui.mixin.PendingElement
2667 * @param {Object} [config] Configuration options
2669 OO
.ui
.Dialog
= function OoUiDialog( config
) {
2670 // Parent constructor
2671 OO
.ui
.Dialog
.parent
.call( this, config
);
2673 // Mixin constructors
2674 OO
.ui
.mixin
.PendingElement
.call( this );
2677 this.actions
= new OO
.ui
.ActionSet();
2678 this.attachedActions
= [];
2679 this.currentAction
= null;
2680 this.onDocumentKeyDownHandler
= this.onDocumentKeyDown
.bind( this );
2683 this.actions
.connect( this, {
2684 click
: 'onActionClick',
2685 resize
: 'onActionResize',
2686 change
: 'onActionsChange'
2691 .addClass( 'oo-ui-dialog' )
2692 .attr( 'role', 'dialog' );
2697 OO
.inheritClass( OO
.ui
.Dialog
, OO
.ui
.Window
);
2698 OO
.mixinClass( OO
.ui
.Dialog
, OO
.ui
.mixin
.PendingElement
);
2700 /* Static Properties */
2703 * Symbolic name of dialog.
2705 * The dialog class must have a symbolic name in order to be registered with OO.Factory.
2706 * Please see the [OOjs UI documentation on MediaWiki] [3] for more information.
2708 * [3]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Window_managers
2713 * @property {string}
2715 OO
.ui
.Dialog
.static.name
= '';
2720 * The title can be specified as a plaintext string, a {@link OO.ui.mixin.LabelElement Label} node, or a function
2721 * that will produce a Label node or string. The title can also be specified with data passed to the
2722 * constructor (see #getSetupProcess). In this case, the static value will be overriden.
2727 * @property {jQuery|string|Function}
2729 OO
.ui
.Dialog
.static.title
= '';
2732 * An array of configured {@link OO.ui.ActionWidget action widgets}.
2734 * Actions can also be specified with data passed to the constructor (see #getSetupProcess). In this case, the static
2735 * value will be overriden.
2737 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs#Action_sets
2741 * @property {Object[]}
2743 OO
.ui
.Dialog
.static.actions
= [];
2746 * Close the dialog when the 'Esc' key is pressed.
2751 * @property {boolean}
2753 OO
.ui
.Dialog
.static.escapable
= true;
2758 * Handle frame document key down events.
2761 * @param {jQuery.Event} e Key down event
2763 OO
.ui
.Dialog
.prototype.onDocumentKeyDown = function ( e
) {
2764 if ( e
.which
=== OO
.ui
.Keys
.ESCAPE
) {
2767 e
.stopPropagation();
2772 * Handle action resized events.
2775 * @param {OO.ui.ActionWidget} action Action that was resized
2777 OO
.ui
.Dialog
.prototype.onActionResize = function () {
2778 // Override in subclass
2782 * Handle action click events.
2785 * @param {OO.ui.ActionWidget} action Action that was clicked
2787 OO
.ui
.Dialog
.prototype.onActionClick = function ( action
) {
2788 if ( !this.isPending() ) {
2789 this.executeAction( action
.getAction() );
2794 * Handle actions change event.
2798 OO
.ui
.Dialog
.prototype.onActionsChange = function () {
2799 this.detachActions();
2800 if ( !this.isClosing() ) {
2801 this.attachActions();
2806 * Get the set of actions used by the dialog.
2808 * @return {OO.ui.ActionSet}
2810 OO
.ui
.Dialog
.prototype.getActions = function () {
2811 return this.actions
;
2815 * Get a process for taking action.
2817 * When you override this method, you can create a new OO.ui.Process and return it, or add additional
2818 * accept steps to the process the parent method provides using the {@link OO.ui.Process#first 'first'}
2819 * and {@link OO.ui.Process#next 'next'} methods of OO.ui.Process.
2822 * @param {string} [action] Symbolic name of action
2823 * @return {OO.ui.Process} Action process
2825 OO
.ui
.Dialog
.prototype.getActionProcess = function ( action
) {
2826 return new OO
.ui
.Process()
2827 .next( function () {
2829 // An empty action always closes the dialog without data, which should always be
2830 // safe and make no changes
2839 * @param {Object} [data] Dialog opening data
2840 * @param {jQuery|string|Function|null} [data.title] Dialog title, omit to use
2841 * the {@link #static-title static title}
2842 * @param {Object[]} [data.actions] List of configuration options for each
2843 * {@link OO.ui.ActionWidget action widget}, omit to use {@link #static-actions static actions}.
2845 OO
.ui
.Dialog
.prototype.getSetupProcess = function ( data
) {
2849 return OO
.ui
.Dialog
.parent
.prototype.getSetupProcess
.call( this, data
)
2850 .next( function () {
2851 var config
= this.constructor.static,
2852 actions
= data
.actions
!== undefined ? data
.actions
: config
.actions
;
2854 this.title
.setLabel(
2855 data
.title
!== undefined ? data
.title
: this.constructor.static.title
2857 this.actions
.add( this.getActionWidgets( actions
) );
2859 if ( this.constructor.static.escapable
) {
2860 this.$document
.on( 'keydown', this.onDocumentKeyDownHandler
);
2868 OO
.ui
.Dialog
.prototype.getTeardownProcess = function ( data
) {
2870 return OO
.ui
.Dialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
2871 .first( function () {
2872 if ( this.constructor.static.escapable
) {
2873 this.$document
.off( 'keydown', this.onDocumentKeyDownHandler
);
2876 this.actions
.clear();
2877 this.currentAction
= null;
2884 OO
.ui
.Dialog
.prototype.initialize = function () {
2886 OO
.ui
.Dialog
.parent
.prototype.initialize
.call( this );
2888 var titleId
= OO
.ui
.generateElementId();
2891 this.title
= new OO
.ui
.LabelWidget( {
2896 this.$content
.addClass( 'oo-ui-dialog-content' );
2897 this.$element
.attr( 'aria-labelledby', titleId
);
2898 this.setPendingElement( this.$head
);
2902 * Get action widgets from a list of configs
2904 * @param {Object[]} actions Action widget configs
2905 * @return {OO.ui.ActionWidget[]} Action widgets
2907 OO
.ui
.Dialog
.prototype.getActionWidgets = function ( actions
) {
2908 var i
, len
, widgets
= [];
2909 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
2911 new OO
.ui
.ActionWidget( actions
[ i
] )
2918 * Attach action actions.
2922 OO
.ui
.Dialog
.prototype.attachActions = function () {
2923 // Remember the list of potentially attached actions
2924 this.attachedActions
= this.actions
.get();
2928 * Detach action actions.
2933 OO
.ui
.Dialog
.prototype.detachActions = function () {
2936 // Detach all actions that may have been previously attached
2937 for ( i
= 0, len
= this.attachedActions
.length
; i
< len
; i
++ ) {
2938 this.attachedActions
[ i
].$element
.detach();
2940 this.attachedActions
= [];
2944 * Execute an action.
2946 * @param {string} action Symbolic name of action to execute
2947 * @return {jQuery.Promise} Promise resolved when action completes, rejected if it fails
2949 OO
.ui
.Dialog
.prototype.executeAction = function ( action
) {
2951 this.currentAction
= action
;
2952 return this.getActionProcess( action
).execute()
2953 .always( this.popPending
.bind( this ) );
2957 * Window managers are used to open and close {@link OO.ui.Window windows} and control their presentation.
2958 * Managed windows are mutually exclusive. If a new window is opened while a current window is opening
2959 * or is opened, the current window will be closed and any ongoing {@link OO.ui.Process process} will be cancelled. Windows
2960 * themselves are persistent and—rather than being torn down when closed—can be repopulated with the
2961 * pertinent data and reused.
2963 * Over the lifecycle of a window, the window manager makes available three promises: `opening`,
2964 * `opened`, and `closing`, which represent the primary stages of the cycle:
2966 * **Opening**: the opening stage begins when the window manager’s #openWindow or a window’s
2967 * {@link OO.ui.Window#open open} method is used, and the window manager begins to open the window.
2969 * - an `opening` event is emitted with an `opening` promise
2970 * - the #getSetupDelay method is called and the returned value is used to time a pause in execution before
2971 * the window’s {@link OO.ui.Window#getSetupProcess getSetupProcess} method is called on the
2972 * window and its result executed
2973 * - a `setup` progress notification is emitted from the `opening` promise
2974 * - the #getReadyDelay method is called the returned value is used to time a pause in execution before
2975 * the window’s {@link OO.ui.Window#getReadyProcess getReadyProcess} method is called on the
2976 * window and its result executed
2977 * - a `ready` progress notification is emitted from the `opening` promise
2978 * - the `opening` promise is resolved with an `opened` promise
2980 * **Opened**: the window is now open.
2982 * **Closing**: the closing stage begins when the window manager's #closeWindow or the
2983 * window's {@link OO.ui.Window#close close} methods is used, and the window manager begins
2984 * to close the window.
2986 * - the `opened` promise is resolved with `closing` promise and a `closing` event is emitted
2987 * - the #getHoldDelay method is called and the returned value is used to time a pause in execution before
2988 * the window's {@link OO.ui.Window#getHoldProcess getHoldProces} method is called on the
2989 * window and its result executed
2990 * - a `hold` progress notification is emitted from the `closing` promise
2991 * - the #getTeardownDelay() method is called and the returned value is used to time a pause in execution before
2992 * the window's {@link OO.ui.Window#getTeardownProcess getTeardownProcess} method is called on the
2993 * window and its result executed
2994 * - a `teardown` progress notification is emitted from the `closing` promise
2995 * - the `closing` promise is resolved. The window is now closed
2997 * See the [OOjs UI documentation on MediaWiki][1] for more information.
2999 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Window_managers
3002 * @extends OO.ui.Element
3003 * @mixins OO.EventEmitter
3006 * @param {Object} [config] Configuration options
3007 * @cfg {OO.Factory} [factory] Window factory to use for automatic instantiation
3008 * Note that window classes that are instantiated with a factory must have
3009 * a {@link OO.ui.Dialog#static-name static name} property that specifies a symbolic name.
3010 * @cfg {boolean} [modal=true] Prevent interaction outside the dialog
3012 OO
.ui
.WindowManager
= function OoUiWindowManager( config
) {
3013 // Configuration initialization
3014 config
= config
|| {};
3016 // Parent constructor
3017 OO
.ui
.WindowManager
.parent
.call( this, config
);
3019 // Mixin constructors
3020 OO
.EventEmitter
.call( this );
3023 this.factory
= config
.factory
;
3024 this.modal
= config
.modal
=== undefined || !!config
.modal
;
3026 this.opening
= null;
3028 this.closing
= null;
3029 this.preparingToOpen
= null;
3030 this.preparingToClose
= null;
3031 this.currentWindow
= null;
3032 this.globalEvents
= false;
3033 this.$ariaHidden
= null;
3034 this.onWindowResizeTimeout
= null;
3035 this.onWindowResizeHandler
= this.onWindowResize
.bind( this );
3036 this.afterWindowResizeHandler
= this.afterWindowResize
.bind( this );
3040 .addClass( 'oo-ui-windowManager' )
3041 .toggleClass( 'oo-ui-windowManager-modal', this.modal
);
3046 OO
.inheritClass( OO
.ui
.WindowManager
, OO
.ui
.Element
);
3047 OO
.mixinClass( OO
.ui
.WindowManager
, OO
.EventEmitter
);
3052 * An 'opening' event is emitted when the window begins to be opened.
3055 * @param {OO.ui.Window} win Window that's being opened
3056 * @param {jQuery.Promise} opening An `opening` promise resolved with a value when the window is opened successfully.
3057 * When the `opening` promise is resolved, the first argument of the value is an 'opened' promise, the second argument
3058 * is the opening data. The `opening` promise emits `setup` and `ready` notifications when those processes are complete.
3059 * @param {Object} data Window opening data
3063 * A 'closing' event is emitted when the window begins to be closed.
3066 * @param {OO.ui.Window} win Window that's being closed
3067 * @param {jQuery.Promise} closing A `closing` promise is resolved with a value when the window
3068 * is closed successfully. The promise emits `hold` and `teardown` notifications when those
3069 * processes are complete. When the `closing` promise is resolved, the first argument of its value
3070 * is the closing data.
3071 * @param {Object} data Window closing data
3075 * A 'resize' event is emitted when a window is resized.
3078 * @param {OO.ui.Window} win Window that was resized
3081 /* Static Properties */
3084 * Map of the symbolic name of each window size and its CSS properties.
3088 * @property {Object}
3090 OO
.ui
.WindowManager
.static.sizes
= {
3104 // These can be non-numeric because they are never used in calculations
3111 * Symbolic name of the default window size.
3113 * The default size is used if the window's requested size is not recognized.
3117 * @property {string}
3119 OO
.ui
.WindowManager
.static.defaultSize
= 'medium';
3124 * Handle window resize events.
3127 * @param {jQuery.Event} e Window resize event
3129 OO
.ui
.WindowManager
.prototype.onWindowResize = function () {
3130 clearTimeout( this.onWindowResizeTimeout
);
3131 this.onWindowResizeTimeout
= setTimeout( this.afterWindowResizeHandler
, 200 );
3135 * Handle window resize events.
3138 * @param {jQuery.Event} e Window resize event
3140 OO
.ui
.WindowManager
.prototype.afterWindowResize = function () {
3141 if ( this.currentWindow
) {
3142 this.updateWindowSize( this.currentWindow
);
3147 * Check if window is opening.
3149 * @return {boolean} Window is opening
3151 OO
.ui
.WindowManager
.prototype.isOpening = function ( win
) {
3152 return win
=== this.currentWindow
&& !!this.opening
&& this.opening
.state() === 'pending';
3156 * Check if window is closing.
3158 * @return {boolean} Window is closing
3160 OO
.ui
.WindowManager
.prototype.isClosing = function ( win
) {
3161 return win
=== this.currentWindow
&& !!this.closing
&& this.closing
.state() === 'pending';
3165 * Check if window is opened.
3167 * @return {boolean} Window is opened
3169 OO
.ui
.WindowManager
.prototype.isOpened = function ( win
) {
3170 return win
=== this.currentWindow
&& !!this.opened
&& this.opened
.state() === 'pending';
3174 * Check if a window is being managed.
3176 * @param {OO.ui.Window} win Window to check
3177 * @return {boolean} Window is being managed
3179 OO
.ui
.WindowManager
.prototype.hasWindow = function ( win
) {
3182 for ( name
in this.windows
) {
3183 if ( this.windows
[ name
] === win
) {
3192 * Get the number of milliseconds to wait after opening begins before executing the ‘setup’ process.
3194 * @param {OO.ui.Window} win Window being opened
3195 * @param {Object} [data] Window opening data
3196 * @return {number} Milliseconds to wait
3198 OO
.ui
.WindowManager
.prototype.getSetupDelay = function () {
3203 * Get the number of milliseconds to wait after setup has finished before executing the ‘ready’ process.
3205 * @param {OO.ui.Window} win Window being opened
3206 * @param {Object} [data] Window opening data
3207 * @return {number} Milliseconds to wait
3209 OO
.ui
.WindowManager
.prototype.getReadyDelay = function () {
3214 * Get the number of milliseconds to wait after closing has begun before executing the 'hold' process.
3216 * @param {OO.ui.Window} win Window being closed
3217 * @param {Object} [data] Window closing data
3218 * @return {number} Milliseconds to wait
3220 OO
.ui
.WindowManager
.prototype.getHoldDelay = function () {
3225 * Get the number of milliseconds to wait after the ‘hold’ process has finished before
3226 * executing the ‘teardown’ process.
3228 * @param {OO.ui.Window} win Window being closed
3229 * @param {Object} [data] Window closing data
3230 * @return {number} Milliseconds to wait
3232 OO
.ui
.WindowManager
.prototype.getTeardownDelay = function () {
3233 return this.modal
? 250 : 0;
3237 * Get a window by its symbolic name.
3239 * If the window is not yet instantiated and its symbolic name is recognized by a factory, it will be
3240 * instantiated and added to the window manager automatically. Please see the [OOjs UI documentation on MediaWiki][3]
3241 * for more information about using factories.
3242 * [3]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Window_managers
3244 * @param {string} name Symbolic name of the window
3245 * @return {jQuery.Promise} Promise resolved with matching window, or rejected with an OO.ui.Error
3246 * @throws {Error} An error is thrown if the symbolic name is not recognized by the factory.
3247 * @throws {Error} An error is thrown if the named window is not recognized as a managed window.
3249 OO
.ui
.WindowManager
.prototype.getWindow = function ( name
) {
3250 var deferred
= $.Deferred(),
3251 win
= this.windows
[ name
];
3253 if ( !( win
instanceof OO
.ui
.Window
) ) {
3254 if ( this.factory
) {
3255 if ( !this.factory
.lookup( name
) ) {
3256 deferred
.reject( new OO
.ui
.Error(
3257 'Cannot auto-instantiate window: symbolic name is unrecognized by the factory'
3260 win
= this.factory
.create( name
);
3261 this.addWindows( [ win
] );
3262 deferred
.resolve( win
);
3265 deferred
.reject( new OO
.ui
.Error(
3266 'Cannot get unmanaged window: symbolic name unrecognized as a managed window'
3270 deferred
.resolve( win
);
3273 return deferred
.promise();
3277 * Get current window.
3279 * @return {OO.ui.Window|null} Currently opening/opened/closing window
3281 OO
.ui
.WindowManager
.prototype.getCurrentWindow = function () {
3282 return this.currentWindow
;
3288 * @param {OO.ui.Window|string} win Window object or symbolic name of window to open
3289 * @param {Object} [data] Window opening data
3290 * @return {jQuery.Promise} An `opening` promise resolved when the window is done opening.
3291 * See {@link #event-opening 'opening' event} for more information about `opening` promises.
3294 OO
.ui
.WindowManager
.prototype.openWindow = function ( win
, data
) {
3296 opening
= $.Deferred();
3298 // Argument handling
3299 if ( typeof win
=== 'string' ) {
3300 return this.getWindow( win
).then( function ( win
) {
3301 return manager
.openWindow( win
, data
);
3306 if ( !this.hasWindow( win
) ) {
3307 opening
.reject( new OO
.ui
.Error(
3308 'Cannot open window: window is not attached to manager'
3310 } else if ( this.preparingToOpen
|| this.opening
|| this.opened
) {
3311 opening
.reject( new OO
.ui
.Error(
3312 'Cannot open window: another window is opening or open'
3317 if ( opening
.state() !== 'rejected' ) {
3318 // If a window is currently closing, wait for it to complete
3319 this.preparingToOpen
= $.when( this.closing
);
3320 // Ensure handlers get called after preparingToOpen is set
3321 this.preparingToOpen
.done( function () {
3322 if ( manager
.modal
) {
3323 manager
.toggleGlobalEvents( true );
3324 manager
.toggleAriaIsolation( true );
3326 manager
.currentWindow
= win
;
3327 manager
.opening
= opening
;
3328 manager
.preparingToOpen
= null;
3329 manager
.emit( 'opening', win
, opening
, data
);
3330 setTimeout( function () {
3331 win
.setup( data
).then( function () {
3332 manager
.updateWindowSize( win
);
3333 manager
.opening
.notify( { state
: 'setup' } );
3334 setTimeout( function () {
3335 win
.ready( data
).then( function () {
3336 manager
.opening
.notify( { state
: 'ready' } );
3337 manager
.opening
= null;
3338 manager
.opened
= $.Deferred();
3339 opening
.resolve( manager
.opened
.promise(), data
);
3341 }, manager
.getReadyDelay() );
3343 }, manager
.getSetupDelay() );
3347 return opening
.promise();
3353 * @param {OO.ui.Window|string} win Window object or symbolic name of window to close
3354 * @param {Object} [data] Window closing data
3355 * @return {jQuery.Promise} A `closing` promise resolved when the window is done closing.
3356 * See {@link #event-closing 'closing' event} for more information about closing promises.
3357 * @throws {Error} An error is thrown if the window is not managed by the window manager.
3360 OO
.ui
.WindowManager
.prototype.closeWindow = function ( win
, data
) {
3362 closing
= $.Deferred(),
3365 // Argument handling
3366 if ( typeof win
=== 'string' ) {
3367 win
= this.windows
[ win
];
3368 } else if ( !this.hasWindow( win
) ) {
3374 closing
.reject( new OO
.ui
.Error(
3375 'Cannot close window: window is not attached to manager'
3377 } else if ( win
!== this.currentWindow
) {
3378 closing
.reject( new OO
.ui
.Error(
3379 'Cannot close window: window already closed with different data'
3381 } else if ( this.preparingToClose
|| this.closing
) {
3382 closing
.reject( new OO
.ui
.Error(
3383 'Cannot close window: window already closing with different data'
3388 if ( closing
.state() !== 'rejected' ) {
3389 // If the window is currently opening, close it when it's done
3390 this.preparingToClose
= $.when( this.opening
);
3391 // Ensure handlers get called after preparingToClose is set
3392 this.preparingToClose
.done( function () {
3393 manager
.closing
= closing
;
3394 manager
.preparingToClose
= null;
3395 manager
.emit( 'closing', win
, closing
, data
);
3396 opened
= manager
.opened
;
3397 manager
.opened
= null;
3398 opened
.resolve( closing
.promise(), data
);
3399 setTimeout( function () {
3400 win
.hold( data
).then( function () {
3401 closing
.notify( { state
: 'hold' } );
3402 setTimeout( function () {
3403 win
.teardown( data
).then( function () {
3404 closing
.notify( { state
: 'teardown' } );
3405 if ( manager
.modal
) {
3406 manager
.toggleGlobalEvents( false );
3407 manager
.toggleAriaIsolation( false );
3409 manager
.closing
= null;
3410 manager
.currentWindow
= null;
3411 closing
.resolve( data
);
3413 }, manager
.getTeardownDelay() );
3415 }, manager
.getHoldDelay() );
3419 return closing
.promise();
3423 * Add windows to the window manager.
3425 * Windows can be added by reference, symbolic name, or explicitly defined symbolic names.
3426 * See the [OOjs ui documentation on MediaWiki] [2] for examples.
3427 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Window_managers
3429 * @param {Object.<string,OO.ui.Window>|OO.ui.Window[]} windows An array of window objects specified
3430 * by reference, symbolic name, or explicitly defined symbolic names.
3431 * @throws {Error} An error is thrown if a window is added by symbolic name, but has neither an
3432 * explicit nor a statically configured symbolic name.
3434 OO
.ui
.WindowManager
.prototype.addWindows = function ( windows
) {
3435 var i
, len
, win
, name
, list
;
3437 if ( Array
.isArray( windows
) ) {
3438 // Convert to map of windows by looking up symbolic names from static configuration
3440 for ( i
= 0, len
= windows
.length
; i
< len
; i
++ ) {
3441 name
= windows
[ i
].constructor.static.name
;
3442 if ( typeof name
!== 'string' ) {
3443 throw new Error( 'Cannot add window' );
3445 list
[ name
] = windows
[ i
];
3447 } else if ( OO
.isPlainObject( windows
) ) {
3452 for ( name
in list
) {
3454 this.windows
[ name
] = win
.toggle( false );
3455 this.$element
.append( win
.$element
);
3456 win
.setManager( this );
3461 * Remove the specified windows from the windows manager.
3463 * Windows will be closed before they are removed. If you wish to remove all windows, you may wish to use
3464 * the #clearWindows method instead. If you no longer need the window manager and want to ensure that it no
3465 * longer listens to events, use the #destroy method.
3467 * @param {string[]} names Symbolic names of windows to remove
3468 * @return {jQuery.Promise} Promise resolved when window is closed and removed
3469 * @throws {Error} An error is thrown if the named windows are not managed by the window manager.
3471 OO
.ui
.WindowManager
.prototype.removeWindows = function ( names
) {
3472 var i
, len
, win
, name
, cleanupWindow
,
3475 cleanup = function ( name
, win
) {
3476 delete manager
.windows
[ name
];
3477 win
.$element
.detach();
3480 for ( i
= 0, len
= names
.length
; i
< len
; i
++ ) {
3482 win
= this.windows
[ name
];
3484 throw new Error( 'Cannot remove window' );
3486 cleanupWindow
= cleanup
.bind( null, name
, win
);
3487 promises
.push( this.closeWindow( name
).then( cleanupWindow
, cleanupWindow
) );
3490 return $.when
.apply( $, promises
);
3494 * Remove all windows from the window manager.
3496 * Windows will be closed before they are removed. Note that the window manager, though not in use, will still
3497 * listen to events. If the window manager will not be used again, you may wish to use the #destroy method instead.
3498 * To remove just a subset of windows, use the #removeWindows method.
3500 * @return {jQuery.Promise} Promise resolved when all windows are closed and removed
3502 OO
.ui
.WindowManager
.prototype.clearWindows = function () {
3503 return this.removeWindows( Object
.keys( this.windows
) );
3507 * Set dialog size. In general, this method should not be called directly.
3509 * Fullscreen mode will be used if the dialog is too wide to fit in the screen.
3513 OO
.ui
.WindowManager
.prototype.updateWindowSize = function ( win
) {
3514 // Bypass for non-current, and thus invisible, windows
3515 if ( win
!== this.currentWindow
) {
3519 var isFullscreen
= win
.getSize() === 'full';
3521 this.$element
.toggleClass( 'oo-ui-windowManager-fullscreen', isFullscreen
);
3522 this.$element
.toggleClass( 'oo-ui-windowManager-floating', !isFullscreen
);
3523 win
.setDimensions( win
.getSizeProperties() );
3525 this.emit( 'resize', win
);
3531 * Bind or unbind global events for scrolling.
3534 * @param {boolean} [on] Bind global events
3537 OO
.ui
.WindowManager
.prototype.toggleGlobalEvents = function ( on
) {
3538 on
= on
=== undefined ? !!this.globalEvents
: !!on
;
3540 var scrollWidth
, bodyMargin
,
3541 $body
= $( this.getElementDocument().body
),
3542 // We could have multiple window managers open so only modify
3543 // the body css at the bottom of the stack
3544 stackDepth
= $body
.data( 'windowManagerGlobalEvents' ) || 0 ;
3547 if ( !this.globalEvents
) {
3548 $( this.getElementWindow() ).on( {
3549 // Start listening for top-level window dimension changes
3550 'orientationchange resize': this.onWindowResizeHandler
3552 if ( stackDepth
=== 0 ) {
3553 scrollWidth
= window
.innerWidth
- document
.documentElement
.clientWidth
;
3554 bodyMargin
= parseFloat( $body
.css( 'margin-right' ) ) || 0;
3557 'margin-right': bodyMargin
+ scrollWidth
3561 this.globalEvents
= true;
3563 } else if ( this.globalEvents
) {
3564 $( this.getElementWindow() ).off( {
3565 // Stop listening for top-level window dimension changes
3566 'orientationchange resize': this.onWindowResizeHandler
3569 if ( stackDepth
=== 0 ) {
3575 this.globalEvents
= false;
3577 $body
.data( 'windowManagerGlobalEvents', stackDepth
);
3583 * Toggle screen reader visibility of content other than the window manager.
3586 * @param {boolean} [isolate] Make only the window manager visible to screen readers
3589 OO
.ui
.WindowManager
.prototype.toggleAriaIsolation = function ( isolate
) {
3590 isolate
= isolate
=== undefined ? !this.$ariaHidden
: !!isolate
;
3593 if ( !this.$ariaHidden
) {
3594 // Hide everything other than the window manager from screen readers
3595 this.$ariaHidden
= $( 'body' )
3597 .not( this.$element
.parentsUntil( 'body' ).last() )
3598 .attr( 'aria-hidden', '' );
3600 } else if ( this.$ariaHidden
) {
3601 // Restore screen reader visibility
3602 this.$ariaHidden
.removeAttr( 'aria-hidden' );
3603 this.$ariaHidden
= null;
3610 * Destroy the window manager.
3612 * Destroying the window manager ensures that it will no longer listen to events. If you would like to
3613 * continue using the window manager, but wish to remove all windows from it, use the #clearWindows method
3616 OO
.ui
.WindowManager
.prototype.destroy = function () {
3617 this.toggleGlobalEvents( false );
3618 this.toggleAriaIsolation( false );
3619 this.clearWindows();
3620 this.$element
.remove();
3624 * Errors contain a required message (either a string or jQuery selection) that is used to describe what went wrong
3625 * in a {@link OO.ui.Process process}. The error's #recoverable and #warning configurations are used to customize the
3626 * appearance and functionality of the error interface.
3628 * The basic error interface contains a formatted error message as well as two buttons: 'Dismiss' and 'Try again' (i.e., the error
3629 * is 'recoverable' by default). If the error is not recoverable, the 'Try again' button will not be rendered and the widget
3630 * that initiated the failed process will be disabled.
3632 * If the error is a warning, the error interface will include a 'Dismiss' and a 'Continue' button, which will try the
3635 * For an example of error interfaces, please see the [OOjs UI documentation on MediaWiki][1].
3637 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs#Processes_and_errors
3642 * @param {string|jQuery} message Description of error
3643 * @param {Object} [config] Configuration options
3644 * @cfg {boolean} [recoverable=true] Error is recoverable.
3645 * By default, errors are recoverable, and users can try the process again.
3646 * @cfg {boolean} [warning=false] Error is a warning.
3647 * If the error is a warning, the error interface will include a
3648 * 'Dismiss' and a 'Continue' button. It is the responsibility of the developer to ensure that the warning
3649 * is not triggered a second time if the user chooses to continue.
3651 OO
.ui
.Error
= function OoUiError( message
, config
) {
3652 // Allow passing positional parameters inside the config object
3653 if ( OO
.isPlainObject( message
) && config
=== undefined ) {
3655 message
= config
.message
;
3658 // Configuration initialization
3659 config
= config
|| {};
3662 this.message
= message
instanceof jQuery
? message
: String( message
);
3663 this.recoverable
= config
.recoverable
=== undefined || !!config
.recoverable
;
3664 this.warning
= !!config
.warning
;
3669 OO
.initClass( OO
.ui
.Error
);
3674 * Check if the error is recoverable.
3676 * If the error is recoverable, users are able to try the process again.
3678 * @return {boolean} Error is recoverable
3680 OO
.ui
.Error
.prototype.isRecoverable = function () {
3681 return this.recoverable
;
3685 * Check if the error is a warning.
3687 * If the error is a warning, the error interface will include a 'Dismiss' and a 'Continue' button.
3689 * @return {boolean} Error is warning
3691 OO
.ui
.Error
.prototype.isWarning = function () {
3692 return this.warning
;
3696 * Get error message as DOM nodes.
3698 * @return {jQuery} Error message in DOM nodes
3700 OO
.ui
.Error
.prototype.getMessage = function () {
3701 return this.message
instanceof jQuery
?
3702 this.message
.clone() :
3703 $( '<div>' ).text( this.message
).contents();
3707 * Get the error message text.
3709 * @return {string} Error message
3711 OO
.ui
.Error
.prototype.getMessageText = function () {
3712 return this.message
instanceof jQuery
? this.message
.text() : this.message
;
3716 * Wraps an HTML snippet for use with configuration values which default
3717 * to strings. This bypasses the default html-escaping done to string
3723 * @param {string} [content] HTML content
3725 OO
.ui
.HtmlSnippet
= function OoUiHtmlSnippet( content
) {
3727 this.content
= content
;
3732 OO
.initClass( OO
.ui
.HtmlSnippet
);
3739 * @return {string} Unchanged HTML snippet.
3741 OO
.ui
.HtmlSnippet
.prototype.toString = function () {
3742 return this.content
;
3746 * A Process is a list of steps that are called in sequence. The step can be a number, a jQuery promise,
3749 * - **number**: the process will wait for the specified number of milliseconds before proceeding.
3750 * - **promise**: the process will continue to the next step when the promise is successfully resolved
3751 * or stop if the promise is rejected.
3752 * - **function**: the process will execute the function. The process will stop if the function returns
3753 * either a boolean `false` or a promise that is rejected; if the function returns a number, the process
3754 * will wait for that number of milliseconds before proceeding.
3756 * If the process fails, an {@link OO.ui.Error error} is generated. Depending on how the error is
3757 * configured, users can dismiss the error and try the process again, or not. If a process is stopped,
3758 * its remaining steps will not be performed.
3763 * @param {number|jQuery.Promise|Function} step Number of miliseconds to wait before proceeding, promise
3764 * that must be resolved before proceeding, or a function to execute. See #createStep for more information. see #createStep for more information
3765 * @param {Object} [context=null] Execution context of the function. The context is ignored if the step is
3766 * a number or promise.
3767 * @return {Object} Step object, with `callback` and `context` properties
3769 OO
.ui
.Process = function ( step
, context
) {
3774 if ( step
!== undefined ) {
3775 this.next( step
, context
);
3781 OO
.initClass( OO
.ui
.Process
);
3786 * Start the process.
3788 * @return {jQuery.Promise} Promise that is resolved when all steps have successfully completed.
3789 * If any of the steps return a promise that is rejected or a boolean false, this promise is rejected
3790 * and any remaining steps are not performed.
3792 OO
.ui
.Process
.prototype.execute = function () {
3793 var i
, len
, promise
;
3796 * Continue execution.
3799 * @param {Array} step A function and the context it should be called in
3800 * @return {Function} Function that continues the process
3802 function proceed( step
) {
3803 return function () {
3804 // Execute step in the correct context
3806 result
= step
.callback
.call( step
.context
);
3808 if ( result
=== false ) {
3809 // Use rejected promise for boolean false results
3810 return $.Deferred().reject( [] ).promise();
3812 if ( typeof result
=== 'number' ) {
3814 throw new Error( 'Cannot go back in time: flux capacitor is out of service' );
3816 // Use a delayed promise for numbers, expecting them to be in milliseconds
3817 deferred
= $.Deferred();
3818 setTimeout( deferred
.resolve
, result
);
3819 return deferred
.promise();
3821 if ( result
instanceof OO
.ui
.Error
) {
3822 // Use rejected promise for error
3823 return $.Deferred().reject( [ result
] ).promise();
3825 if ( Array
.isArray( result
) && result
.length
&& result
[ 0 ] instanceof OO
.ui
.Error
) {
3826 // Use rejected promise for list of errors
3827 return $.Deferred().reject( result
).promise();
3829 // Duck-type the object to see if it can produce a promise
3830 if ( result
&& $.isFunction( result
.promise
) ) {
3831 // Use a promise generated from the result
3832 return result
.promise();
3834 // Use resolved promise for other results
3835 return $.Deferred().resolve().promise();
3839 if ( this.steps
.length
) {
3840 // Generate a chain reaction of promises
3841 promise
= proceed( this.steps
[ 0 ] )();
3842 for ( i
= 1, len
= this.steps
.length
; i
< len
; i
++ ) {
3843 promise
= promise
.then( proceed( this.steps
[ i
] ) );
3846 promise
= $.Deferred().resolve().promise();
3853 * Create a process step.
3856 * @param {number|jQuery.Promise|Function} step
3858 * - Number of milliseconds to wait before proceeding
3859 * - Promise that must be resolved before proceeding
3860 * - Function to execute
3861 * - If the function returns a boolean false the process will stop
3862 * - If the function returns a promise, the process will continue to the next
3863 * step when the promise is resolved or stop if the promise is rejected
3864 * - If the function returns a number, the process will wait for that number of
3865 * milliseconds before proceeding
3866 * @param {Object} [context=null] Execution context of the function. The context is
3867 * ignored if the step is a number or promise.
3868 * @return {Object} Step object, with `callback` and `context` properties
3870 OO
.ui
.Process
.prototype.createStep = function ( step
, context
) {
3871 if ( typeof step
=== 'number' || $.isFunction( step
.promise
) ) {
3873 callback: function () {
3879 if ( $.isFunction( step
) ) {
3885 throw new Error( 'Cannot create process step: number, promise or function expected' );
3889 * Add step to the beginning of the process.
3891 * @inheritdoc #createStep
3892 * @return {OO.ui.Process} this
3895 OO
.ui
.Process
.prototype.first = function ( step
, context
) {
3896 this.steps
.unshift( this.createStep( step
, context
) );
3901 * Add step to the end of the process.
3903 * @inheritdoc #createStep
3904 * @return {OO.ui.Process} this
3907 OO
.ui
.Process
.prototype.next = function ( step
, context
) {
3908 this.steps
.push( this.createStep( step
, context
) );
3913 * A ToolFactory creates tools on demand. All tools ({@link OO.ui.Tool Tools}, {@link OO.ui.PopupTool PopupTools},
3914 * and {@link OO.ui.ToolGroupTool ToolGroupTools}) must be registered with a tool factory. Tools are
3915 * registered by their symbolic name. See {@link OO.ui.Toolbar toolbars} for an example.
3917 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki][1].
3919 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
3922 * @extends OO.Factory
3925 OO
.ui
.ToolFactory
= function OoUiToolFactory() {
3926 // Parent constructor
3927 OO
.ui
.ToolFactory
.parent
.call( this );
3932 OO
.inheritClass( OO
.ui
.ToolFactory
, OO
.Factory
);
3937 * Get tools from the factory
3939 * @param {Array} include Included tools
3940 * @param {Array} exclude Excluded tools
3941 * @param {Array} promote Promoted tools
3942 * @param {Array} demote Demoted tools
3943 * @return {string[]} List of tools
3945 OO
.ui
.ToolFactory
.prototype.getTools = function ( include
, exclude
, promote
, demote
) {
3946 var i
, len
, included
, promoted
, demoted
,
3950 // Collect included and not excluded tools
3951 included
= OO
.simpleArrayDifference( this.extract( include
), this.extract( exclude
) );
3954 promoted
= this.extract( promote
, used
);
3955 demoted
= this.extract( demote
, used
);
3958 for ( i
= 0, len
= included
.length
; i
< len
; i
++ ) {
3959 if ( !used
[ included
[ i
] ] ) {
3960 auto
.push( included
[ i
] );
3964 return promoted
.concat( auto
).concat( demoted
);
3968 * Get a flat list of names from a list of names or groups.
3970 * Tools can be specified in the following ways:
3972 * - A specific tool: `{ name: 'tool-name' }` or `'tool-name'`
3973 * - All tools in a group: `{ group: 'group-name' }`
3974 * - All tools: `'*'`
3977 * @param {Array|string} collection List of tools
3978 * @param {Object} [used] Object with names that should be skipped as properties; extracted
3979 * names will be added as properties
3980 * @return {string[]} List of extracted names
3982 OO
.ui
.ToolFactory
.prototype.extract = function ( collection
, used
) {
3983 var i
, len
, item
, name
, tool
,
3986 if ( collection
=== '*' ) {
3987 for ( name
in this.registry
) {
3988 tool
= this.registry
[ name
];
3990 // Only add tools by group name when auto-add is enabled
3991 tool
.static.autoAddToCatchall
&&
3992 // Exclude already used tools
3993 ( !used
|| !used
[ name
] )
3997 used
[ name
] = true;
4001 } else if ( Array
.isArray( collection
) ) {
4002 for ( i
= 0, len
= collection
.length
; i
< len
; i
++ ) {
4003 item
= collection
[ i
];
4004 // Allow plain strings as shorthand for named tools
4005 if ( typeof item
=== 'string' ) {
4006 item
= { name
: item
};
4008 if ( OO
.isPlainObject( item
) ) {
4010 for ( name
in this.registry
) {
4011 tool
= this.registry
[ name
];
4013 // Include tools with matching group
4014 tool
.static.group
=== item
.group
&&
4015 // Only add tools by group name when auto-add is enabled
4016 tool
.static.autoAddToGroup
&&
4017 // Exclude already used tools
4018 ( !used
|| !used
[ name
] )
4022 used
[ name
] = true;
4026 // Include tools with matching name and exclude already used tools
4027 } else if ( item
.name
&& ( !used
|| !used
[ item
.name
] ) ) {
4028 names
.push( item
.name
);
4030 used
[ item
.name
] = true;
4040 * ToolGroupFactories create {@link OO.ui.ToolGroup toolgroups} on demand. The toolgroup classes must
4041 * specify a symbolic name and be registered with the factory. The following classes are registered by
4044 * - {@link OO.ui.BarToolGroup BarToolGroups} (‘bar’)
4045 * - {@link OO.ui.MenuToolGroup MenuToolGroups} (‘menu’)
4046 * - {@link OO.ui.ListToolGroup ListToolGroups} (‘list’)
4048 * See {@link OO.ui.Toolbar toolbars} for an example.
4050 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki][1].
4052 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
4054 * @extends OO.Factory
4057 OO
.ui
.ToolGroupFactory
= function OoUiToolGroupFactory() {
4058 // Parent constructor
4059 OO
.Factory
.call( this );
4062 defaultClasses
= this.constructor.static.getDefaultClasses();
4064 // Register default toolgroups
4065 for ( i
= 0, l
= defaultClasses
.length
; i
< l
; i
++ ) {
4066 this.register( defaultClasses
[ i
] );
4072 OO
.inheritClass( OO
.ui
.ToolGroupFactory
, OO
.Factory
);
4074 /* Static Methods */
4077 * Get a default set of classes to be registered on construction.
4079 * @return {Function[]} Default classes
4081 OO
.ui
.ToolGroupFactory
.static.getDefaultClasses = function () {
4084 OO
.ui
.ListToolGroup
,
4096 * @param {Object} [config] Configuration options
4098 OO
.ui
.Theme
= function OoUiTheme( config
) {
4099 // Configuration initialization
4100 config
= config
|| {};
4105 OO
.initClass( OO
.ui
.Theme
);
4110 * Get a list of classes to be applied to a widget.
4112 * The 'on' and 'off' lists combined MUST contain keys for all classes the theme adds or removes,
4113 * otherwise state transitions will not work properly.
4115 * @param {OO.ui.Element} element Element for which to get classes
4116 * @return {Object.<string,string[]>} Categorized class names with `on` and `off` lists
4118 OO
.ui
.Theme
.prototype.getElementClasses = function ( /* element */ ) {
4119 return { on
: [], off
: [] };
4123 * Update CSS classes provided by the theme.
4125 * For elements with theme logic hooks, this should be called any time there's a state change.
4127 * @param {OO.ui.Element} element Element for which to update classes
4128 * @return {Object.<string,string[]>} Categorized class names with `on` and `off` lists
4130 OO
.ui
.Theme
.prototype.updateElementClasses = function ( element
) {
4131 var classes
= this.getElementClasses( element
);
4134 .removeClass( classes
.off
.join( ' ' ) )
4135 .addClass( classes
.on
.join( ' ' ) );
4139 * The TabIndexedElement class is an attribute mixin used to add additional functionality to an
4140 * element created by another class. The mixin provides a ‘tabIndex’ property, which specifies the
4141 * order in which users will navigate through the focusable elements via the "tab" key.
4144 * // TabIndexedElement is mixed into the ButtonWidget class
4145 * // to provide a tabIndex property.
4146 * var button1 = new OO.ui.ButtonWidget( {
4150 * var button2 = new OO.ui.ButtonWidget( {
4154 * var button3 = new OO.ui.ButtonWidget( {
4158 * var button4 = new OO.ui.ButtonWidget( {
4162 * $( 'body' ).append( button1.$element, button2.$element, button3.$element, button4.$element );
4168 * @param {Object} [config] Configuration options
4169 * @cfg {jQuery} [$tabIndexed] The element that should use the tabindex functionality. By default,
4170 * the functionality is applied to the element created by the class ($element). If a different element is specified, the tabindex
4171 * functionality will be applied to it instead.
4172 * @cfg {number|null} [tabIndex=0] Number that specifies the element’s position in the tab-navigation
4173 * order (e.g., 1 for the first focusable element). Use 0 to use the default navigation order; use -1
4174 * to remove the element from the tab-navigation flow.
4176 OO
.ui
.mixin
.TabIndexedElement
= function OoUiMixinTabIndexedElement( config
) {
4177 // Configuration initialization
4178 config
= $.extend( { tabIndex
: 0 }, config
);
4181 this.$tabIndexed
= null;
4182 this.tabIndex
= null;
4185 this.connect( this, { disable
: 'onTabIndexedElementDisable' } );
4188 this.setTabIndex( config
.tabIndex
);
4189 this.setTabIndexedElement( config
.$tabIndexed
|| this.$element
);
4194 OO
.initClass( OO
.ui
.mixin
.TabIndexedElement
);
4199 * Set the element that should use the tabindex functionality.
4201 * This method is used to retarget a tabindex mixin so that its functionality applies
4202 * to the specified element. If an element is currently using the functionality, the mixin’s
4203 * effect on that element is removed before the new element is set up.
4205 * @param {jQuery} $tabIndexed Element that should use the tabindex functionality
4208 OO
.ui
.mixin
.TabIndexedElement
.prototype.setTabIndexedElement = function ( $tabIndexed
) {
4209 var tabIndex
= this.tabIndex
;
4210 // Remove attributes from old $tabIndexed
4211 this.setTabIndex( null );
4212 // Force update of new $tabIndexed
4213 this.$tabIndexed
= $tabIndexed
;
4214 this.tabIndex
= tabIndex
;
4215 return this.updateTabIndex();
4219 * Set the value of the tabindex.
4221 * @param {number|null} tabIndex Tabindex value, or `null` for no tabindex
4224 OO
.ui
.mixin
.TabIndexedElement
.prototype.setTabIndex = function ( tabIndex
) {
4225 tabIndex
= typeof tabIndex
=== 'number' ? tabIndex
: null;
4227 if ( this.tabIndex
!== tabIndex
) {
4228 this.tabIndex
= tabIndex
;
4229 this.updateTabIndex();
4236 * Update the `tabindex` attribute, in case of changes to tab index or
4242 OO
.ui
.mixin
.TabIndexedElement
.prototype.updateTabIndex = function () {
4243 if ( this.$tabIndexed
) {
4244 if ( this.tabIndex
!== null ) {
4245 // Do not index over disabled elements
4246 this.$tabIndexed
.attr( {
4247 tabindex
: this.isDisabled() ? -1 : this.tabIndex
,
4248 // ChromeVox and NVDA do not seem to inherit this from parent elements
4249 'aria-disabled': this.isDisabled().toString()
4252 this.$tabIndexed
.removeAttr( 'tabindex aria-disabled' );
4259 * Handle disable events.
4262 * @param {boolean} disabled Element is disabled
4264 OO
.ui
.mixin
.TabIndexedElement
.prototype.onTabIndexedElementDisable = function () {
4265 this.updateTabIndex();
4269 * Get the value of the tabindex.
4271 * @return {number|null} Tabindex value
4273 OO
.ui
.mixin
.TabIndexedElement
.prototype.getTabIndex = function () {
4274 return this.tabIndex
;
4278 * ButtonElement is often mixed into other classes to generate a button, which is a clickable
4279 * interface element that can be configured with access keys for accessibility.
4280 * See the [OOjs UI documentation on MediaWiki] [1] for examples.
4282 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Buttons_and_Switches#Buttons
4287 * @param {Object} [config] Configuration options
4288 * @cfg {jQuery} [$button] The button element created by the class.
4289 * If this configuration is omitted, the button element will use a generated `<a>`.
4290 * @cfg {boolean} [framed=true] Render the button with a frame
4291 * @cfg {string} [accessKey] Button's access key
4293 OO
.ui
.mixin
.ButtonElement
= function OoUiMixinButtonElement( config
) {
4294 // Configuration initialization
4295 config
= config
|| {};
4298 this.$button
= null;
4300 this.accessKey
= null;
4301 this.active
= false;
4302 this.onMouseUpHandler
= this.onMouseUp
.bind( this );
4303 this.onMouseDownHandler
= this.onMouseDown
.bind( this );
4304 this.onKeyDownHandler
= this.onKeyDown
.bind( this );
4305 this.onKeyUpHandler
= this.onKeyUp
.bind( this );
4306 this.onClickHandler
= this.onClick
.bind( this );
4307 this.onKeyPressHandler
= this.onKeyPress
.bind( this );
4310 this.$element
.addClass( 'oo-ui-buttonElement' );
4311 this.toggleFramed( config
.framed
=== undefined || config
.framed
);
4312 this.setAccessKey( config
.accessKey
);
4313 this.setButtonElement( config
.$button
|| $( '<a>' ) );
4318 OO
.initClass( OO
.ui
.mixin
.ButtonElement
);
4320 /* Static Properties */
4323 * Cancel mouse down events.
4325 * This property is usually set to `true` to prevent the focus from changing when the button is clicked.
4326 * Classes such as {@link OO.ui.mixin.DraggableElement DraggableElement} and {@link OO.ui.ButtonOptionWidget ButtonOptionWidget}
4327 * use a value of `false` so that dragging behavior is possible and mousedown events can be handled by a
4332 * @property {boolean}
4334 OO
.ui
.mixin
.ButtonElement
.static.cancelButtonMouseDownEvents
= true;
4339 * A 'click' event is emitted when the button element is clicked.
4347 * Set the button element.
4349 * This method is used to retarget a button mixin so that its functionality applies to
4350 * the specified button element instead of the one created by the class. If a button element
4351 * is already set, the method will remove the mixin’s effect on that element.
4353 * @param {jQuery} $button Element to use as button
4355 OO
.ui
.mixin
.ButtonElement
.prototype.setButtonElement = function ( $button
) {
4356 if ( this.$button
) {
4358 .removeClass( 'oo-ui-buttonElement-button' )
4359 .removeAttr( 'role accesskey' )
4361 mousedown
: this.onMouseDownHandler
,
4362 keydown
: this.onKeyDownHandler
,
4363 click
: this.onClickHandler
,
4364 keypress
: this.onKeyPressHandler
4368 this.$button
= $button
4369 .addClass( 'oo-ui-buttonElement-button' )
4370 .attr( { role
: 'button', accesskey
: this.accessKey
} )
4372 mousedown
: this.onMouseDownHandler
,
4373 keydown
: this.onKeyDownHandler
,
4374 click
: this.onClickHandler
,
4375 keypress
: this.onKeyPressHandler
4380 * Handles mouse down events.
4383 * @param {jQuery.Event} e Mouse down event
4385 OO
.ui
.mixin
.ButtonElement
.prototype.onMouseDown = function ( e
) {
4386 if ( this.isDisabled() || e
.which
!== 1 ) {
4389 this.$element
.addClass( 'oo-ui-buttonElement-pressed' );
4390 // Run the mouseup handler no matter where the mouse is when the button is let go, so we can
4391 // reliably remove the pressed class
4392 this.getElementDocument().addEventListener( 'mouseup', this.onMouseUpHandler
, true );
4393 // Prevent change of focus unless specifically configured otherwise
4394 if ( this.constructor.static.cancelButtonMouseDownEvents
) {
4400 * Handles mouse up events.
4403 * @param {jQuery.Event} e Mouse up event
4405 OO
.ui
.mixin
.ButtonElement
.prototype.onMouseUp = function ( e
) {
4406 if ( this.isDisabled() || e
.which
!== 1 ) {
4409 this.$element
.removeClass( 'oo-ui-buttonElement-pressed' );
4410 // Stop listening for mouseup, since we only needed this once
4411 this.getElementDocument().removeEventListener( 'mouseup', this.onMouseUpHandler
, true );
4415 * Handles mouse click events.
4418 * @param {jQuery.Event} e Mouse click event
4421 OO
.ui
.mixin
.ButtonElement
.prototype.onClick = function ( e
) {
4422 if ( !this.isDisabled() && e
.which
=== 1 ) {
4423 if ( this.emit( 'click' ) ) {
4430 * Handles key down events.
4433 * @param {jQuery.Event} e Key down event
4435 OO
.ui
.mixin
.ButtonElement
.prototype.onKeyDown = function ( e
) {
4436 if ( this.isDisabled() || ( e
.which
!== OO
.ui
.Keys
.SPACE
&& e
.which
!== OO
.ui
.Keys
.ENTER
) ) {
4439 this.$element
.addClass( 'oo-ui-buttonElement-pressed' );
4440 // Run the keyup handler no matter where the key is when the button is let go, so we can
4441 // reliably remove the pressed class
4442 this.getElementDocument().addEventListener( 'keyup', this.onKeyUpHandler
, true );
4446 * Handles key up events.
4449 * @param {jQuery.Event} e Key up event
4451 OO
.ui
.mixin
.ButtonElement
.prototype.onKeyUp = function ( e
) {
4452 if ( this.isDisabled() || ( e
.which
!== OO
.ui
.Keys
.SPACE
&& e
.which
!== OO
.ui
.Keys
.ENTER
) ) {
4455 this.$element
.removeClass( 'oo-ui-buttonElement-pressed' );
4456 // Stop listening for keyup, since we only needed this once
4457 this.getElementDocument().removeEventListener( 'keyup', this.onKeyUpHandler
, true );
4461 * Handles key press events.
4464 * @param {jQuery.Event} e Key press event
4467 OO
.ui
.mixin
.ButtonElement
.prototype.onKeyPress = function ( e
) {
4468 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
4469 if ( this.emit( 'click' ) ) {
4476 * Check if button has a frame.
4478 * @return {boolean} Button is framed
4480 OO
.ui
.mixin
.ButtonElement
.prototype.isFramed = function () {
4485 * Render the button with or without a frame. Omit the `framed` parameter to toggle the button frame on and off.
4487 * @param {boolean} [framed] Make button framed, omit to toggle
4490 OO
.ui
.mixin
.ButtonElement
.prototype.toggleFramed = function ( framed
) {
4491 framed
= framed
=== undefined ? !this.framed
: !!framed
;
4492 if ( framed
!== this.framed
) {
4493 this.framed
= framed
;
4495 .toggleClass( 'oo-ui-buttonElement-frameless', !framed
)
4496 .toggleClass( 'oo-ui-buttonElement-framed', framed
);
4497 this.updateThemeClasses();
4504 * Set the button's access key.
4506 * @param {string} accessKey Button's access key, use empty string to remove
4509 OO
.ui
.mixin
.ButtonElement
.prototype.setAccessKey = function ( accessKey
) {
4510 accessKey
= typeof accessKey
=== 'string' && accessKey
.length
? accessKey
: null;
4512 if ( this.accessKey
!== accessKey
) {
4513 if ( this.$button
) {
4514 if ( accessKey
!== null ) {
4515 this.$button
.attr( 'accesskey', accessKey
);
4517 this.$button
.removeAttr( 'accesskey' );
4520 this.accessKey
= accessKey
;
4527 * Set the button to its 'active' state.
4529 * The active state occurs when a {@link OO.ui.ButtonOptionWidget ButtonOptionWidget} or
4530 * a {@link OO.ui.ToggleButtonWidget ToggleButtonWidget} is pressed. This method does nothing
4531 * for other button types.
4533 * @param {boolean} [value] Make button active
4536 OO
.ui
.mixin
.ButtonElement
.prototype.setActive = function ( value
) {
4537 this.$element
.toggleClass( 'oo-ui-buttonElement-active', !!value
);
4542 * Any OOjs UI widget that contains other widgets (such as {@link OO.ui.ButtonWidget buttons} or
4543 * {@link OO.ui.OptionWidget options}) mixes in GroupElement. Adding, removing, and clearing
4544 * items from the group is done through the interface the class provides.
4545 * For more information, please see the [OOjs UI documentation on MediaWiki] [1].
4547 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Elements/Groups
4553 * @param {Object} [config] Configuration options
4554 * @cfg {jQuery} [$group] The container element created by the class. If this configuration
4555 * is omitted, the group element will use a generated `<div>`.
4557 OO
.ui
.mixin
.GroupElement
= function OoUiMixinGroupElement( config
) {
4558 // Configuration initialization
4559 config
= config
|| {};
4564 this.aggregateItemEvents
= {};
4567 this.setGroupElement( config
.$group
|| $( '<div>' ) );
4573 * Set the group element.
4575 * If an element is already set, items will be moved to the new element.
4577 * @param {jQuery} $group Element to use as group
4579 OO
.ui
.mixin
.GroupElement
.prototype.setGroupElement = function ( $group
) {
4582 this.$group
= $group
;
4583 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4584 this.$group
.append( this.items
[ i
].$element
);
4589 * Check if a group contains no items.
4591 * @return {boolean} Group is empty
4593 OO
.ui
.mixin
.GroupElement
.prototype.isEmpty = function () {
4594 return !this.items
.length
;
4598 * Get all items in the group.
4600 * The method returns an array of item references (e.g., [button1, button2, button3]) and is useful
4601 * when synchronizing groups of items, or whenever the references are required (e.g., when removing items
4604 * @return {OO.ui.Element[]} An array of items.
4606 OO
.ui
.mixin
.GroupElement
.prototype.getItems = function () {
4607 return this.items
.slice( 0 );
4611 * Get an item by its data.
4613 * Only the first item with matching data will be returned. To return all matching items,
4614 * use the #getItemsFromData method.
4616 * @param {Object} data Item data to search for
4617 * @return {OO.ui.Element|null} Item with equivalent data, `null` if none exists
4619 OO
.ui
.mixin
.GroupElement
.prototype.getItemFromData = function ( data
) {
4621 hash
= OO
.getHash( data
);
4623 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4624 item
= this.items
[ i
];
4625 if ( hash
=== OO
.getHash( item
.getData() ) ) {
4634 * Get items by their data.
4636 * All items with matching data will be returned. To return only the first match, use the #getItemFromData method instead.
4638 * @param {Object} data Item data to search for
4639 * @return {OO.ui.Element[]} Items with equivalent data
4641 OO
.ui
.mixin
.GroupElement
.prototype.getItemsFromData = function ( data
) {
4643 hash
= OO
.getHash( data
),
4646 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4647 item
= this.items
[ i
];
4648 if ( hash
=== OO
.getHash( item
.getData() ) ) {
4657 * Aggregate the events emitted by the group.
4659 * When events are aggregated, the group will listen to all contained items for the event,
4660 * and then emit the event under a new name. The new event will contain an additional leading
4661 * parameter containing the item that emitted the original event. Other arguments emitted from
4662 * the original event are passed through.
4664 * @param {Object.<string,string|null>} events An object keyed by the name of the event that should be
4665 * aggregated (e.g., ‘click’) and the value of the new name to use (e.g., ‘groupClick’).
4666 * A `null` value will remove aggregated events.
4668 * @throws {Error} An error is thrown if aggregation already exists.
4670 OO
.ui
.mixin
.GroupElement
.prototype.aggregate = function ( events
) {
4671 var i
, len
, item
, add
, remove
, itemEvent
, groupEvent
;
4673 for ( itemEvent
in events
) {
4674 groupEvent
= events
[ itemEvent
];
4676 // Remove existing aggregated event
4677 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
4678 // Don't allow duplicate aggregations
4680 throw new Error( 'Duplicate item event aggregation for ' + itemEvent
);
4682 // Remove event aggregation from existing items
4683 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4684 item
= this.items
[ i
];
4685 if ( item
.connect
&& item
.disconnect
) {
4687 remove
[ itemEvent
] = [ 'emit', this.aggregateItemEvents
[itemEvent
], item
];
4688 item
.disconnect( this, remove
);
4691 // Prevent future items from aggregating event
4692 delete this.aggregateItemEvents
[ itemEvent
];
4695 // Add new aggregate event
4697 // Make future items aggregate event
4698 this.aggregateItemEvents
[ itemEvent
] = groupEvent
;
4699 // Add event aggregation to existing items
4700 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4701 item
= this.items
[ i
];
4702 if ( item
.connect
&& item
.disconnect
) {
4704 add
[ itemEvent
] = [ 'emit', groupEvent
, item
];
4705 item
.connect( this, add
);
4713 * Add items to the group.
4715 * Items will be added to the end of the group array unless the optional `index` parameter specifies
4716 * a different insertion point. Adding an existing item will move it to the end of the array or the point specified by the `index`.
4718 * @param {OO.ui.Element[]} items An array of items to add to the group
4719 * @param {number} [index] Index of the insertion point
4722 OO
.ui
.mixin
.GroupElement
.prototype.addItems = function ( items
, index
) {
4723 var i
, len
, item
, event
, events
, currentIndex
,
4726 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
4729 // Check if item exists then remove it first, effectively "moving" it
4730 currentIndex
= $.inArray( item
, this.items
);
4731 if ( currentIndex
>= 0 ) {
4732 this.removeItems( [ item
] );
4733 // Adjust index to compensate for removal
4734 if ( currentIndex
< index
) {
4739 if ( item
.connect
&& item
.disconnect
&& !$.isEmptyObject( this.aggregateItemEvents
) ) {
4741 for ( event
in this.aggregateItemEvents
) {
4742 events
[ event
] = [ 'emit', this.aggregateItemEvents
[ event
], item
];
4744 item
.connect( this, events
);
4746 item
.setElementGroup( this );
4747 itemElements
.push( item
.$element
.get( 0 ) );
4750 if ( index
=== undefined || index
< 0 || index
>= this.items
.length
) {
4751 this.$group
.append( itemElements
);
4752 this.items
.push
.apply( this.items
, items
);
4753 } else if ( index
=== 0 ) {
4754 this.$group
.prepend( itemElements
);
4755 this.items
.unshift
.apply( this.items
, items
);
4757 this.items
[ index
].$element
.before( itemElements
);
4758 this.items
.splice
.apply( this.items
, [ index
, 0 ].concat( items
) );
4765 * Remove the specified items from a group.
4767 * Removed items are detached (not removed) from the DOM so that they may be reused.
4768 * To remove all items from a group, you may wish to use the #clearItems method instead.
4770 * @param {OO.ui.Element[]} items An array of items to remove
4773 OO
.ui
.mixin
.GroupElement
.prototype.removeItems = function ( items
) {
4774 var i
, len
, item
, index
, remove
, itemEvent
;
4776 // Remove specific items
4777 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
4779 index
= $.inArray( item
, this.items
);
4780 if ( index
!== -1 ) {
4782 item
.connect
&& item
.disconnect
&&
4783 !$.isEmptyObject( this.aggregateItemEvents
)
4786 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
4787 remove
[ itemEvent
] = [ 'emit', this.aggregateItemEvents
[ itemEvent
], item
];
4789 item
.disconnect( this, remove
);
4791 item
.setElementGroup( null );
4792 this.items
.splice( index
, 1 );
4793 item
.$element
.detach();
4801 * Clear all items from the group.
4803 * Cleared items are detached from the DOM, not removed, so that they may be reused.
4804 * To remove only a subset of items from a group, use the #removeItems method.
4808 OO
.ui
.mixin
.GroupElement
.prototype.clearItems = function () {
4809 var i
, len
, item
, remove
, itemEvent
;
4812 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4813 item
= this.items
[ i
];
4815 item
.connect
&& item
.disconnect
&&
4816 !$.isEmptyObject( this.aggregateItemEvents
)
4819 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
4820 remove
[ itemEvent
] = [ 'emit', this.aggregateItemEvents
[ itemEvent
], item
];
4822 item
.disconnect( this, remove
);
4824 item
.setElementGroup( null );
4825 item
.$element
.detach();
4833 * DraggableElement is a mixin class used to create elements that can be clicked
4834 * and dragged by a mouse to a new position within a group. This class must be used
4835 * in conjunction with OO.ui.mixin.DraggableGroupElement, which provides a container for
4836 * the draggable elements.
4843 OO
.ui
.mixin
.DraggableElement
= function OoUiMixinDraggableElement() {
4847 // Initialize and events
4849 .attr( 'draggable', true )
4850 .addClass( 'oo-ui-draggableElement' )
4852 dragstart
: this.onDragStart
.bind( this ),
4853 dragover
: this.onDragOver
.bind( this ),
4854 dragend
: this.onDragEnd
.bind( this ),
4855 drop
: this.onDrop
.bind( this )
4859 OO
.initClass( OO
.ui
.mixin
.DraggableElement
);
4866 * A dragstart event is emitted when the user clicks and begins dragging an item.
4867 * @param {OO.ui.mixin.DraggableElement} item The item the user has clicked and is dragging with the mouse.
4872 * A dragend event is emitted when the user drags an item and releases the mouse,
4873 * thus terminating the drag operation.
4878 * A drop event is emitted when the user drags an item and then releases the mouse button
4879 * over a valid target.
4882 /* Static Properties */
4885 * @inheritdoc OO.ui.mixin.ButtonElement
4887 OO
.ui
.mixin
.DraggableElement
.static.cancelButtonMouseDownEvents
= false;
4892 * Respond to dragstart event.
4895 * @param {jQuery.Event} event jQuery event
4898 OO
.ui
.mixin
.DraggableElement
.prototype.onDragStart = function ( e
) {
4899 var dataTransfer
= e
.originalEvent
.dataTransfer
;
4900 // Define drop effect
4901 dataTransfer
.dropEffect
= 'none';
4902 dataTransfer
.effectAllowed
= 'move';
4903 // We must set up a dataTransfer data property or Firefox seems to
4904 // ignore the fact the element is draggable.
4906 dataTransfer
.setData( 'application-x/OOjs-UI-draggable', this.getIndex() );
4908 // The above is only for firefox. No need to set a catch clause
4909 // if it fails, move on.
4911 // Add dragging class
4912 this.$element
.addClass( 'oo-ui-draggableElement-dragging' );
4914 this.emit( 'dragstart', this );
4919 * Respond to dragend event.
4924 OO
.ui
.mixin
.DraggableElement
.prototype.onDragEnd = function () {
4925 this.$element
.removeClass( 'oo-ui-draggableElement-dragging' );
4926 this.emit( 'dragend' );
4930 * Handle drop event.
4933 * @param {jQuery.Event} event jQuery event
4936 OO
.ui
.mixin
.DraggableElement
.prototype.onDrop = function ( e
) {
4938 this.emit( 'drop', e
);
4942 * In order for drag/drop to work, the dragover event must
4943 * return false and stop propogation.
4947 OO
.ui
.mixin
.DraggableElement
.prototype.onDragOver = function ( e
) {
4953 * Store it in the DOM so we can access from the widget drag event
4956 * @param {number} Item index
4958 OO
.ui
.mixin
.DraggableElement
.prototype.setIndex = function ( index
) {
4959 if ( this.index
!== index
) {
4961 this.$element
.data( 'index', index
);
4969 * @return {number} Item index
4971 OO
.ui
.mixin
.DraggableElement
.prototype.getIndex = function () {
4976 * DraggableGroupElement is a mixin class used to create a group element to
4977 * contain draggable elements, which are items that can be clicked and dragged by a mouse.
4978 * The class is used with OO.ui.mixin.DraggableElement.
4982 * @mixins OO.ui.mixin.GroupElement
4985 * @param {Object} [config] Configuration options
4986 * @cfg {string} [orientation] Item orientation: 'horizontal' or 'vertical'. The orientation
4987 * should match the layout of the items. Items displayed in a single row
4988 * or in several rows should use horizontal orientation. The vertical orientation should only be
4989 * used when the items are displayed in a single column. Defaults to 'vertical'
4991 OO
.ui
.mixin
.DraggableGroupElement
= function OoUiMixinDraggableGroupElement( config
) {
4992 // Configuration initialization
4993 config
= config
|| {};
4995 // Parent constructor
4996 OO
.ui
.mixin
.GroupElement
.call( this, config
);
4999 this.orientation
= config
.orientation
|| 'vertical';
5000 this.dragItem
= null;
5001 this.itemDragOver
= null;
5003 this.sideInsertion
= '';
5007 dragstart
: 'itemDragStart',
5008 dragend
: 'itemDragEnd',
5011 this.connect( this, {
5012 itemDragStart
: 'onItemDragStart',
5013 itemDrop
: 'onItemDrop',
5014 itemDragEnd
: 'onItemDragEnd'
5017 dragover
: $.proxy( this.onDragOver
, this ),
5018 dragleave
: $.proxy( this.onDragLeave
, this )
5022 if ( Array
.isArray( config
.items
) ) {
5023 this.addItems( config
.items
);
5025 this.$placeholder
= $( '<div>' )
5026 .addClass( 'oo-ui-draggableGroupElement-placeholder' );
5028 .addClass( 'oo-ui-draggableGroupElement' )
5029 .append( this.$status
)
5030 .toggleClass( 'oo-ui-draggableGroupElement-horizontal', this.orientation
=== 'horizontal' )
5031 .prepend( this.$placeholder
);
5035 OO
.mixinClass( OO
.ui
.mixin
.DraggableGroupElement
, OO
.ui
.mixin
.GroupElement
);
5040 * A 'reorder' event is emitted when the order of items in the group changes.
5043 * @param {OO.ui.mixin.DraggableElement} item Reordered item
5044 * @param {number} [newIndex] New index for the item
5050 * Respond to item drag start event
5053 * @param {OO.ui.mixin.DraggableElement} item Dragged item
5055 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onItemDragStart = function ( item
) {
5058 // Map the index of each object
5059 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
5060 this.items
[ i
].setIndex( i
);
5063 if ( this.orientation
=== 'horizontal' ) {
5064 // Set the height of the indicator
5065 this.$placeholder
.css( {
5066 height
: item
.$element
.outerHeight(),
5070 // Set the width of the indicator
5071 this.$placeholder
.css( {
5073 width
: item
.$element
.outerWidth()
5076 this.setDragItem( item
);
5080 * Respond to item drag end event
5084 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onItemDragEnd = function () {
5085 this.unsetDragItem();
5090 * Handle drop event and switch the order of the items accordingly
5093 * @param {OO.ui.mixin.DraggableElement} item Dropped item
5096 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onItemDrop = function ( item
) {
5097 var toIndex
= item
.getIndex();
5098 // Check if the dropped item is from the current group
5099 // TODO: Figure out a way to configure a list of legally droppable
5100 // elements even if they are not yet in the list
5101 if ( this.getDragItem() ) {
5102 // If the insertion point is 'after', the insertion index
5103 // is shifted to the right (or to the left in RTL, hence 'after')
5104 if ( this.sideInsertion
=== 'after' ) {
5107 // Emit change event
5108 this.emit( 'reorder', this.getDragItem(), toIndex
);
5110 this.unsetDragItem();
5111 // Return false to prevent propogation
5116 * Handle dragleave event.
5120 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onDragLeave = function () {
5121 // This means the item was dragged outside the widget
5124 .addClass( 'oo-ui-element-hidden' );
5128 * Respond to dragover event
5131 * @param {jQuery.Event} event Event details
5133 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onDragOver = function ( e
) {
5134 var dragOverObj
, $optionWidget
, itemOffset
, itemMidpoint
, itemBoundingRect
,
5135 itemSize
, cssOutput
, dragPosition
, itemIndex
, itemPosition
,
5136 clientX
= e
.originalEvent
.clientX
,
5137 clientY
= e
.originalEvent
.clientY
;
5139 // Get the OptionWidget item we are dragging over
5140 dragOverObj
= this.getElementDocument().elementFromPoint( clientX
, clientY
);
5141 $optionWidget
= $( dragOverObj
).closest( '.oo-ui-draggableElement' );
5142 if ( $optionWidget
[ 0 ] ) {
5143 itemOffset
= $optionWidget
.offset();
5144 itemBoundingRect
= $optionWidget
[ 0 ].getBoundingClientRect();
5145 itemPosition
= $optionWidget
.position();
5146 itemIndex
= $optionWidget
.data( 'index' );
5151 this.isDragging() &&
5152 itemIndex
!== this.getDragItem().getIndex()
5154 if ( this.orientation
=== 'horizontal' ) {
5155 // Calculate where the mouse is relative to the item width
5156 itemSize
= itemBoundingRect
.width
;
5157 itemMidpoint
= itemBoundingRect
.left
+ itemSize
/ 2;
5158 dragPosition
= clientX
;
5159 // Which side of the item we hover over will dictate
5160 // where the placeholder will appear, on the left or
5163 left
: dragPosition
< itemMidpoint
? itemPosition
.left
: itemPosition
.left
+ itemSize
,
5164 top
: itemPosition
.top
5167 // Calculate where the mouse is relative to the item height
5168 itemSize
= itemBoundingRect
.height
;
5169 itemMidpoint
= itemBoundingRect
.top
+ itemSize
/ 2;
5170 dragPosition
= clientY
;
5171 // Which side of the item we hover over will dictate
5172 // where the placeholder will appear, on the top or
5175 top
: dragPosition
< itemMidpoint
? itemPosition
.top
: itemPosition
.top
+ itemSize
,
5176 left
: itemPosition
.left
5179 // Store whether we are before or after an item to rearrange
5180 // For horizontal layout, we need to account for RTL, as this is flipped
5181 if ( this.orientation
=== 'horizontal' && this.$element
.css( 'direction' ) === 'rtl' ) {
5182 this.sideInsertion
= dragPosition
< itemMidpoint
? 'after' : 'before';
5184 this.sideInsertion
= dragPosition
< itemMidpoint
? 'before' : 'after';
5186 // Add drop indicator between objects
5189 .removeClass( 'oo-ui-element-hidden' );
5191 // This means the item was dragged outside the widget
5194 .addClass( 'oo-ui-element-hidden' );
5201 * Set a dragged item
5203 * @param {OO.ui.mixin.DraggableElement} item Dragged item
5205 OO
.ui
.mixin
.DraggableGroupElement
.prototype.setDragItem = function ( item
) {
5206 this.dragItem
= item
;
5210 * Unset the current dragged item
5212 OO
.ui
.mixin
.DraggableGroupElement
.prototype.unsetDragItem = function () {
5213 this.dragItem
= null;
5214 this.itemDragOver
= null;
5215 this.$placeholder
.addClass( 'oo-ui-element-hidden' );
5216 this.sideInsertion
= '';
5220 * Get the item that is currently being dragged.
5222 * @return {OO.ui.mixin.DraggableElement|null} The currently dragged item, or `null` if no item is being dragged
5224 OO
.ui
.mixin
.DraggableGroupElement
.prototype.getDragItem = function () {
5225 return this.dragItem
;
5229 * Check if an item in the group is currently being dragged.
5231 * @return {Boolean} Item is being dragged
5233 OO
.ui
.mixin
.DraggableGroupElement
.prototype.isDragging = function () {
5234 return this.getDragItem() !== null;
5238 * IconElement is often mixed into other classes to generate an icon.
5239 * Icons are graphics, about the size of normal text. They are used to aid the user
5240 * in locating a control or to convey information in a space-efficient way. See the
5241 * [OOjs UI documentation on MediaWiki] [1] for a list of icons
5242 * included in the library.
5244 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Icons
5250 * @param {Object} [config] Configuration options
5251 * @cfg {jQuery} [$icon] The icon element created by the class. If this configuration is omitted,
5252 * the icon element will use a generated `<span>`. To use a different HTML tag, or to specify that
5253 * the icon element be set to an existing icon instead of the one generated by this class, set a
5254 * value using a jQuery selection. For example:
5256 * // Use a <div> tag instead of a <span>
5258 * // Use an existing icon element instead of the one generated by the class
5259 * $icon: this.$element
5260 * // Use an icon element from a child widget
5261 * $icon: this.childwidget.$element
5262 * @cfg {Object|string} [icon=''] The symbolic name of the icon (e.g., ‘remove’ or ‘menu’), or a map of
5263 * symbolic names. A map is used for i18n purposes and contains a `default` icon
5264 * name and additional names keyed by language code. The `default` name is used when no icon is keyed
5265 * by the user's language.
5267 * Example of an i18n map:
5269 * { default: 'bold-a', en: 'bold-b', de: 'bold-f' }
5270 * See the [OOjs UI documentation on MediaWiki] [2] for a list of icons included in the library.
5271 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Icons
5272 * @cfg {string|Function} [iconTitle] A text string used as the icon title, or a function that returns title
5273 * text. The icon title is displayed when users move the mouse over the icon.
5275 OO
.ui
.mixin
.IconElement
= function OoUiMixinIconElement( config
) {
5276 // Configuration initialization
5277 config
= config
|| {};
5282 this.iconTitle
= null;
5285 this.setIcon( config
.icon
|| this.constructor.static.icon
);
5286 this.setIconTitle( config
.iconTitle
|| this.constructor.static.iconTitle
);
5287 this.setIconElement( config
.$icon
|| $( '<span>' ) );
5292 OO
.initClass( OO
.ui
.mixin
.IconElement
);
5294 /* Static Properties */
5297 * The symbolic name of the icon (e.g., ‘remove’ or ‘menu’), or a map of symbolic names. A map is used
5298 * for i18n purposes and contains a `default` icon name and additional names keyed by
5299 * language code. The `default` name is used when no icon is keyed by the user's language.
5301 * Example of an i18n map:
5303 * { default: 'bold-a', en: 'bold-b', de: 'bold-f' }
5305 * Note: the static property will be overridden if the #icon configuration is used.
5309 * @property {Object|string}
5311 OO
.ui
.mixin
.IconElement
.static.icon
= null;
5314 * The icon title, displayed when users move the mouse over the icon. The value can be text, a
5315 * function that returns title text, or `null` for no title.
5317 * The static property will be overridden if the #iconTitle configuration is used.
5321 * @property {string|Function|null}
5323 OO
.ui
.mixin
.IconElement
.static.iconTitle
= null;
5328 * Set the icon element. This method is used to retarget an icon mixin so that its functionality
5329 * applies to the specified icon element instead of the one created by the class. If an icon
5330 * element is already set, the mixin’s effect on that element is removed. Generated CSS classes
5331 * and mixin methods will no longer affect the element.
5333 * @param {jQuery} $icon Element to use as icon
5335 OO
.ui
.mixin
.IconElement
.prototype.setIconElement = function ( $icon
) {
5338 .removeClass( 'oo-ui-iconElement-icon oo-ui-icon-' + this.icon
)
5339 .removeAttr( 'title' );
5343 .addClass( 'oo-ui-iconElement-icon' )
5344 .toggleClass( 'oo-ui-icon-' + this.icon
, !!this.icon
);
5345 if ( this.iconTitle
!== null ) {
5346 this.$icon
.attr( 'title', this.iconTitle
);
5351 * Set icon by symbolic name (e.g., ‘remove’ or ‘menu’). Use `null` to remove an icon.
5352 * The icon parameter can also be set to a map of icon names. See the #icon config setting
5355 * @param {Object|string|null} icon A symbolic icon name, a {@link #icon map of icon names} keyed
5356 * by language code, or `null` to remove the icon.
5359 OO
.ui
.mixin
.IconElement
.prototype.setIcon = function ( icon
) {
5360 icon
= OO
.isPlainObject( icon
) ? OO
.ui
.getLocalValue( icon
, null, 'default' ) : icon
;
5361 icon
= typeof icon
=== 'string' && icon
.trim().length
? icon
.trim() : null;
5363 if ( this.icon
!== icon
) {
5365 if ( this.icon
!== null ) {
5366 this.$icon
.removeClass( 'oo-ui-icon-' + this.icon
);
5368 if ( icon
!== null ) {
5369 this.$icon
.addClass( 'oo-ui-icon-' + icon
);
5375 this.$element
.toggleClass( 'oo-ui-iconElement', !!this.icon
);
5376 this.updateThemeClasses();
5382 * Set the icon title. Use `null` to remove the title.
5384 * @param {string|Function|null} iconTitle A text string used as the icon title,
5385 * a function that returns title text, or `null` for no title.
5388 OO
.ui
.mixin
.IconElement
.prototype.setIconTitle = function ( iconTitle
) {
5389 iconTitle
= typeof iconTitle
=== 'function' ||
5390 ( typeof iconTitle
=== 'string' && iconTitle
.length
) ?
5391 OO
.ui
.resolveMsg( iconTitle
) : null;
5393 if ( this.iconTitle
!== iconTitle
) {
5394 this.iconTitle
= iconTitle
;
5396 if ( this.iconTitle
!== null ) {
5397 this.$icon
.attr( 'title', iconTitle
);
5399 this.$icon
.removeAttr( 'title' );
5408 * Get the symbolic name of the icon.
5410 * @return {string} Icon name
5412 OO
.ui
.mixin
.IconElement
.prototype.getIcon = function () {
5417 * Get the icon title. The title text is displayed when a user moves the mouse over the icon.
5419 * @return {string} Icon title text
5421 OO
.ui
.mixin
.IconElement
.prototype.getIconTitle = function () {
5422 return this.iconTitle
;
5426 * IndicatorElement is often mixed into other classes to generate an indicator.
5427 * Indicators are small graphics that are generally used in two ways:
5429 * - To draw attention to the status of an item. For example, an indicator might be
5430 * used to show that an item in a list has errors that need to be resolved.
5431 * - To clarify the function of a control that acts in an exceptional way (a button
5432 * that opens a menu instead of performing an action directly, for example).
5434 * For a list of indicators included in the library, please see the
5435 * [OOjs UI documentation on MediaWiki] [1].
5437 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Indicators
5443 * @param {Object} [config] Configuration options
5444 * @cfg {jQuery} [$indicator] The indicator element created by the class. If this
5445 * configuration is omitted, the indicator element will use a generated `<span>`.
5446 * @cfg {string} [indicator] Symbolic name of the indicator (e.g., ‘alert’ or ‘down’).
5447 * See the [OOjs UI documentation on MediaWiki][2] for a list of indicators included
5449 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Indicators
5450 * @cfg {string|Function} [indicatorTitle] A text string used as the indicator title,
5451 * or a function that returns title text. The indicator title is displayed when users move
5452 * the mouse over the indicator.
5454 OO
.ui
.mixin
.IndicatorElement
= function OoUiMixinIndicatorElement( config
) {
5455 // Configuration initialization
5456 config
= config
|| {};
5459 this.$indicator
= null;
5460 this.indicator
= null;
5461 this.indicatorTitle
= null;
5464 this.setIndicator( config
.indicator
|| this.constructor.static.indicator
);
5465 this.setIndicatorTitle( config
.indicatorTitle
|| this.constructor.static.indicatorTitle
);
5466 this.setIndicatorElement( config
.$indicator
|| $( '<span>' ) );
5471 OO
.initClass( OO
.ui
.mixin
.IndicatorElement
);
5473 /* Static Properties */
5476 * Symbolic name of the indicator (e.g., ‘alert’ or ‘down’).
5477 * The static property will be overridden if the #indicator configuration is used.
5481 * @property {string|null}
5483 OO
.ui
.mixin
.IndicatorElement
.static.indicator
= null;
5486 * A text string used as the indicator title, a function that returns title text, or `null`
5487 * for no title. The static property will be overridden if the #indicatorTitle configuration is used.
5491 * @property {string|Function|null}
5493 OO
.ui
.mixin
.IndicatorElement
.static.indicatorTitle
= null;
5498 * Set the indicator element.
5500 * If an element is already set, it will be cleaned up before setting up the new element.
5502 * @param {jQuery} $indicator Element to use as indicator
5504 OO
.ui
.mixin
.IndicatorElement
.prototype.setIndicatorElement = function ( $indicator
) {
5505 if ( this.$indicator
) {
5507 .removeClass( 'oo-ui-indicatorElement-indicator oo-ui-indicator-' + this.indicator
)
5508 .removeAttr( 'title' );
5511 this.$indicator
= $indicator
5512 .addClass( 'oo-ui-indicatorElement-indicator' )
5513 .toggleClass( 'oo-ui-indicator-' + this.indicator
, !!this.indicator
);
5514 if ( this.indicatorTitle
!== null ) {
5515 this.$indicator
.attr( 'title', this.indicatorTitle
);
5520 * Set the indicator by its symbolic name: ‘alert’, ‘down’, ‘next’, ‘previous’, ‘required’, ‘up’. Use `null` to remove the indicator.
5522 * @param {string|null} indicator Symbolic name of indicator, or `null` for no indicator
5525 OO
.ui
.mixin
.IndicatorElement
.prototype.setIndicator = function ( indicator
) {
5526 indicator
= typeof indicator
=== 'string' && indicator
.length
? indicator
.trim() : null;
5528 if ( this.indicator
!== indicator
) {
5529 if ( this.$indicator
) {
5530 if ( this.indicator
!== null ) {
5531 this.$indicator
.removeClass( 'oo-ui-indicator-' + this.indicator
);
5533 if ( indicator
!== null ) {
5534 this.$indicator
.addClass( 'oo-ui-indicator-' + indicator
);
5537 this.indicator
= indicator
;
5540 this.$element
.toggleClass( 'oo-ui-indicatorElement', !!this.indicator
);
5541 this.updateThemeClasses();
5547 * Set the indicator title.
5549 * The title is displayed when a user moves the mouse over the indicator.
5551 * @param {string|Function|null} indicator Indicator title text, a function that returns text, or
5552 * `null` for no indicator title
5555 OO
.ui
.mixin
.IndicatorElement
.prototype.setIndicatorTitle = function ( indicatorTitle
) {
5556 indicatorTitle
= typeof indicatorTitle
=== 'function' ||
5557 ( typeof indicatorTitle
=== 'string' && indicatorTitle
.length
) ?
5558 OO
.ui
.resolveMsg( indicatorTitle
) : null;
5560 if ( this.indicatorTitle
!== indicatorTitle
) {
5561 this.indicatorTitle
= indicatorTitle
;
5562 if ( this.$indicator
) {
5563 if ( this.indicatorTitle
!== null ) {
5564 this.$indicator
.attr( 'title', indicatorTitle
);
5566 this.$indicator
.removeAttr( 'title' );
5575 * Get the symbolic name of the indicator (e.g., ‘alert’ or ‘down’).
5577 * @return {string} Symbolic name of indicator
5579 OO
.ui
.mixin
.IndicatorElement
.prototype.getIndicator = function () {
5580 return this.indicator
;
5584 * Get the indicator title.
5586 * The title is displayed when a user moves the mouse over the indicator.
5588 * @return {string} Indicator title text
5590 OO
.ui
.mixin
.IndicatorElement
.prototype.getIndicatorTitle = function () {
5591 return this.indicatorTitle
;
5595 * LabelElement is often mixed into other classes to generate a label, which
5596 * helps identify the function of an interface element.
5597 * See the [OOjs UI documentation on MediaWiki] [1] for more information.
5599 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Labels
5605 * @param {Object} [config] Configuration options
5606 * @cfg {jQuery} [$label] The label element created by the class. If this
5607 * configuration is omitted, the label element will use a generated `<span>`.
5608 * @cfg {jQuery|string|Function|OO.ui.HtmlSnippet} [label] The label text. The label can be specified
5609 * as a plaintext string, a jQuery selection of elements, or a function that will produce a string
5610 * in the future. See the [OOjs UI documentation on MediaWiki] [2] for examples.
5611 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Labels
5612 * @cfg {boolean} [autoFitLabel=true] Fit the label to the width of the parent element.
5613 * The label will be truncated to fit if necessary.
5615 OO
.ui
.mixin
.LabelElement
= function OoUiMixinLabelElement( config
) {
5616 // Configuration initialization
5617 config
= config
|| {};
5622 this.autoFitLabel
= config
.autoFitLabel
=== undefined || !!config
.autoFitLabel
;
5625 this.setLabel( config
.label
|| this.constructor.static.label
);
5626 this.setLabelElement( config
.$label
|| $( '<span>' ) );
5631 OO
.initClass( OO
.ui
.mixin
.LabelElement
);
5636 * @event labelChange
5637 * @param {string} value
5640 /* Static Properties */
5643 * The label text. The label can be specified as a plaintext string, a function that will
5644 * produce a string in the future, or `null` for no label. The static value will
5645 * be overridden if a label is specified with the #label config option.
5649 * @property {string|Function|null}
5651 OO
.ui
.mixin
.LabelElement
.static.label
= null;
5656 * Set the label element.
5658 * If an element is already set, it will be cleaned up before setting up the new element.
5660 * @param {jQuery} $label Element to use as label
5662 OO
.ui
.mixin
.LabelElement
.prototype.setLabelElement = function ( $label
) {
5663 if ( this.$label
) {
5664 this.$label
.removeClass( 'oo-ui-labelElement-label' ).empty();
5667 this.$label
= $label
.addClass( 'oo-ui-labelElement-label' );
5668 this.setLabelContent( this.label
);
5674 * An empty string will result in the label being hidden. A string containing only whitespace will
5675 * be converted to a single ` `.
5677 * @param {jQuery|string|OO.ui.HtmlSnippet|Function|null} label Label nodes; text; a function that returns nodes or
5678 * text; or null for no label
5681 OO
.ui
.mixin
.LabelElement
.prototype.setLabel = function ( label
) {
5682 label
= typeof label
=== 'function' ? OO
.ui
.resolveMsg( label
) : label
;
5683 label
= ( ( typeof label
=== 'string' && label
.length
) || label
instanceof jQuery
|| label
instanceof OO
.ui
.HtmlSnippet
) ? label
: null;
5685 this.$element
.toggleClass( 'oo-ui-labelElement', !!label
);
5687 if ( this.label
!== label
) {
5688 if ( this.$label
) {
5689 this.setLabelContent( label
);
5692 this.emit( 'labelChange' );
5701 * @return {jQuery|string|Function|null} Label nodes; text; a function that returns nodes or
5702 * text; or null for no label
5704 OO
.ui
.mixin
.LabelElement
.prototype.getLabel = function () {
5713 OO
.ui
.mixin
.LabelElement
.prototype.fitLabel = function () {
5714 if ( this.$label
&& this.$label
.autoEllipsis
&& this.autoFitLabel
) {
5715 this.$label
.autoEllipsis( { hasSpan
: false, tooltip
: true } );
5722 * Set the content of the label.
5724 * Do not call this method until after the label element has been set by #setLabelElement.
5727 * @param {jQuery|string|Function|null} label Label nodes; text; a function that returns nodes or
5728 * text; or null for no label
5730 OO
.ui
.mixin
.LabelElement
.prototype.setLabelContent = function ( label
) {
5731 if ( typeof label
=== 'string' ) {
5732 if ( label
.match( /^\s*$/ ) ) {
5733 // Convert whitespace only string to a single non-breaking space
5734 this.$label
.html( ' ' );
5736 this.$label
.text( label
);
5738 } else if ( label
instanceof OO
.ui
.HtmlSnippet
) {
5739 this.$label
.html( label
.toString() );
5740 } else if ( label
instanceof jQuery
) {
5741 this.$label
.empty().append( label
);
5743 this.$label
.empty();
5748 * LookupElement is a mixin that creates a {@link OO.ui.TextInputMenuSelectWidget menu} of suggested values for
5749 * a {@link OO.ui.TextInputWidget text input widget}. Suggested values are based on the characters the user types
5750 * into the text input field and, in general, the menu is only displayed when the user types. If a suggested value is chosen
5751 * from the lookup menu, that value becomes the value of the input field.
5753 * Note that a new menu of suggested items is displayed when a value is chosen from the lookup menu. If this is
5754 * not the desired behavior, disable lookup menus with the #setLookupsDisabled method, then set the value, then
5755 * re-enable lookups.
5757 * See the [OOjs UI demos][1] for an example.
5759 * [1]: https://tools.wmflabs.org/oojs-ui/oojs-ui/demos/index.html#widgets-apex-vector-ltr
5765 * @param {Object} [config] Configuration options
5766 * @cfg {jQuery} [$overlay] Overlay for the lookup menu; defaults to relative positioning
5767 * @cfg {jQuery} [$container=this.$element] The container element. The lookup menu is rendered beneath the specified element.
5768 * @cfg {boolean} [allowSuggestionsWhenEmpty=false] Request and display a lookup menu when the text input is empty.
5769 * By default, the lookup menu is not generated and displayed until the user begins to type.
5771 OO
.ui
.mixin
.LookupElement
= function OoUiMixinLookupElement( config
) {
5772 // Configuration initialization
5773 config
= config
|| {};
5776 this.$overlay
= config
.$overlay
|| this.$element
;
5777 this.lookupMenu
= new OO
.ui
.TextInputMenuSelectWidget( this, {
5780 $container
: config
.$container
5783 this.allowSuggestionsWhenEmpty
= config
.allowSuggestionsWhenEmpty
|| false;
5785 this.lookupCache
= {};
5786 this.lookupQuery
= null;
5787 this.lookupRequest
= null;
5788 this.lookupsDisabled
= false;
5789 this.lookupInputFocused
= false;
5793 focus
: this.onLookupInputFocus
.bind( this ),
5794 blur
: this.onLookupInputBlur
.bind( this ),
5795 mousedown
: this.onLookupInputMouseDown
.bind( this )
5797 this.connect( this, { change
: 'onLookupInputChange' } );
5798 this.lookupMenu
.connect( this, {
5799 toggle
: 'onLookupMenuToggle',
5800 choose
: 'onLookupMenuItemChoose'
5804 this.$element
.addClass( 'oo-ui-lookupElement' );
5805 this.lookupMenu
.$element
.addClass( 'oo-ui-lookupElement-menu' );
5806 this.$overlay
.append( this.lookupMenu
.$element
);
5812 * Handle input focus event.
5815 * @param {jQuery.Event} e Input focus event
5817 OO
.ui
.mixin
.LookupElement
.prototype.onLookupInputFocus = function () {
5818 this.lookupInputFocused
= true;
5819 this.populateLookupMenu();
5823 * Handle input blur event.
5826 * @param {jQuery.Event} e Input blur event
5828 OO
.ui
.mixin
.LookupElement
.prototype.onLookupInputBlur = function () {
5829 this.closeLookupMenu();
5830 this.lookupInputFocused
= false;
5834 * Handle input mouse down event.
5837 * @param {jQuery.Event} e Input mouse down event
5839 OO
.ui
.mixin
.LookupElement
.prototype.onLookupInputMouseDown = function () {
5840 // Only open the menu if the input was already focused.
5841 // This way we allow the user to open the menu again after closing it with Esc
5842 // by clicking in the input. Opening (and populating) the menu when initially
5843 // clicking into the input is handled by the focus handler.
5844 if ( this.lookupInputFocused
&& !this.lookupMenu
.isVisible() ) {
5845 this.populateLookupMenu();
5850 * Handle input change event.
5853 * @param {string} value New input value
5855 OO
.ui
.mixin
.LookupElement
.prototype.onLookupInputChange = function () {
5856 if ( this.lookupInputFocused
) {
5857 this.populateLookupMenu();
5862 * Handle the lookup menu being shown/hidden.
5865 * @param {boolean} visible Whether the lookup menu is now visible.
5867 OO
.ui
.mixin
.LookupElement
.prototype.onLookupMenuToggle = function ( visible
) {
5869 // When the menu is hidden, abort any active request and clear the menu.
5870 // This has to be done here in addition to closeLookupMenu(), because
5871 // MenuSelectWidget will close itself when the user presses Esc.
5872 this.abortLookupRequest();
5873 this.lookupMenu
.clearItems();
5878 * Handle menu item 'choose' event, updating the text input value to the value of the clicked item.
5881 * @param {OO.ui.MenuOptionWidget} item Selected item
5883 OO
.ui
.mixin
.LookupElement
.prototype.onLookupMenuItemChoose = function ( item
) {
5884 this.setValue( item
.getData() );
5891 * @return {OO.ui.TextInputMenuSelectWidget}
5893 OO
.ui
.mixin
.LookupElement
.prototype.getLookupMenu = function () {
5894 return this.lookupMenu
;
5898 * Disable or re-enable lookups.
5900 * When lookups are disabled, calls to #populateLookupMenu will be ignored.
5902 * @param {boolean} disabled Disable lookups
5904 OO
.ui
.mixin
.LookupElement
.prototype.setLookupsDisabled = function ( disabled
) {
5905 this.lookupsDisabled
= !!disabled
;
5909 * Open the menu. If there are no entries in the menu, this does nothing.
5914 OO
.ui
.mixin
.LookupElement
.prototype.openLookupMenu = function () {
5915 if ( !this.lookupMenu
.isEmpty() ) {
5916 this.lookupMenu
.toggle( true );
5922 * Close the menu, empty it, and abort any pending request.
5927 OO
.ui
.mixin
.LookupElement
.prototype.closeLookupMenu = function () {
5928 this.lookupMenu
.toggle( false );
5929 this.abortLookupRequest();
5930 this.lookupMenu
.clearItems();
5935 * Request menu items based on the input's current value, and when they arrive,
5936 * populate the menu with these items and show the menu.
5938 * If lookups have been disabled with #setLookupsDisabled, this function does nothing.
5943 OO
.ui
.mixin
.LookupElement
.prototype.populateLookupMenu = function () {
5945 value
= this.getValue();
5947 if ( this.lookupsDisabled
) {
5951 // If the input is empty, clear the menu, unless suggestions when empty are allowed.
5952 if ( !this.allowSuggestionsWhenEmpty
&& value
=== '' ) {
5953 this.closeLookupMenu();
5954 // Skip population if there is already a request pending for the current value
5955 } else if ( value
!== this.lookupQuery
) {
5956 this.getLookupMenuItems()
5957 .done( function ( items
) {
5958 widget
.lookupMenu
.clearItems();
5959 if ( items
.length
) {
5963 widget
.initializeLookupMenuSelection();
5965 widget
.lookupMenu
.toggle( false );
5968 .fail( function () {
5969 widget
.lookupMenu
.clearItems();
5977 * Highlight the first selectable item in the menu.
5982 OO
.ui
.mixin
.LookupElement
.prototype.initializeLookupMenuSelection = function () {
5983 if ( !this.lookupMenu
.getSelectedItem() ) {
5984 this.lookupMenu
.highlightItem( this.lookupMenu
.getFirstSelectableItem() );
5989 * Get lookup menu items for the current query.
5992 * @return {jQuery.Promise} Promise object which will be passed menu items as the first argument of
5993 * the done event. If the request was aborted to make way for a subsequent request, this promise
5994 * will not be rejected: it will remain pending forever.
5996 OO
.ui
.mixin
.LookupElement
.prototype.getLookupMenuItems = function () {
5998 value
= this.getValue(),
5999 deferred
= $.Deferred(),
6002 this.abortLookupRequest();
6003 if ( Object
.prototype.hasOwnProperty
.call( this.lookupCache
, value
) ) {
6004 deferred
.resolve( this.getLookupMenuOptionsFromData( this.lookupCache
[ value
] ) );
6007 this.lookupQuery
= value
;
6008 ourRequest
= this.lookupRequest
= this.getLookupRequest();
6010 .always( function () {
6011 // We need to pop pending even if this is an old request, otherwise
6012 // the widget will remain pending forever.
6013 // TODO: this assumes that an aborted request will fail or succeed soon after
6014 // being aborted, or at least eventually. It would be nice if we could popPending()
6015 // at abort time, but only if we knew that we hadn't already called popPending()
6016 // for that request.
6017 widget
.popPending();
6019 .done( function ( response
) {
6020 // If this is an old request (and aborting it somehow caused it to still succeed),
6021 // ignore its success completely
6022 if ( ourRequest
=== widget
.lookupRequest
) {
6023 widget
.lookupQuery
= null;
6024 widget
.lookupRequest
= null;
6025 widget
.lookupCache
[ value
] = widget
.getLookupCacheDataFromResponse( response
);
6026 deferred
.resolve( widget
.getLookupMenuOptionsFromData( widget
.lookupCache
[ value
] ) );
6029 .fail( function () {
6030 // If this is an old request (or a request failing because it's being aborted),
6031 // ignore its failure completely
6032 if ( ourRequest
=== widget
.lookupRequest
) {
6033 widget
.lookupQuery
= null;
6034 widget
.lookupRequest
= null;
6039 return deferred
.promise();
6043 * Abort the currently pending lookup request, if any.
6047 OO
.ui
.mixin
.LookupElement
.prototype.abortLookupRequest = function () {
6048 var oldRequest
= this.lookupRequest
;
6050 // First unset this.lookupRequest to the fail handler will notice
6051 // that the request is no longer current
6052 this.lookupRequest
= null;
6053 this.lookupQuery
= null;
6059 * Get a new request object of the current lookup query value.
6063 * @return {jQuery.Promise} jQuery AJAX object, or promise object with an .abort() method
6065 OO
.ui
.mixin
.LookupElement
.prototype.getLookupRequest = function () {
6066 // Stub, implemented in subclass
6071 * Pre-process data returned by the request from #getLookupRequest.
6073 * The return value of this function will be cached, and any further queries for the given value
6074 * will use the cache rather than doing API requests.
6078 * @param {Mixed} response Response from server
6079 * @return {Mixed} Cached result data
6081 OO
.ui
.mixin
.LookupElement
.prototype.getLookupCacheDataFromResponse = function () {
6082 // Stub, implemented in subclass
6087 * Get a list of menu option widgets from the (possibly cached) data returned by
6088 * #getLookupCacheDataFromResponse.
6092 * @param {Mixed} data Cached result data, usually an array
6093 * @return {OO.ui.MenuOptionWidget[]} Menu items
6095 OO
.ui
.mixin
.LookupElement
.prototype.getLookupMenuOptionsFromData = function () {
6096 // Stub, implemented in subclass
6101 * Set the read-only state of the widget.
6103 * This will also disable/enable the lookups functionality.
6105 * @param {boolean} readOnly Make input read-only
6108 OO
.ui
.mixin
.LookupElement
.prototype.setReadOnly = function ( readOnly
) {
6110 // Note: Calling #setReadOnly this way assumes this is mixed into an OO.ui.TextInputWidget
6111 OO
.ui
.TextInputWidget
.prototype.setReadOnly
.call( this, readOnly
);
6113 this.setLookupsDisabled( readOnly
);
6114 // During construction, #setReadOnly is called before the OO.ui.mixin.LookupElement constructor
6115 if ( readOnly
&& this.lookupMenu
) {
6116 this.closeLookupMenu();
6123 * PopupElement is mixed into other classes to generate a {@link OO.ui.PopupWidget popup widget}.
6124 * A popup is a container for content. It is overlaid and positioned absolutely. By default, each
6125 * popup has an anchor, which is an arrow-like protrusion that points toward the popup’s origin.
6126 * See {@link OO.ui.PopupWidget PopupWidget} for an example.
6132 * @param {Object} [config] Configuration options
6133 * @cfg {Object} [popup] Configuration to pass to popup
6134 * @cfg {boolean} [popup.autoClose=true] Popup auto-closes when it loses focus
6136 OO
.ui
.mixin
.PopupElement
= function OoUiMixinPopupElement( config
) {
6137 // Configuration initialization
6138 config
= config
|| {};
6141 this.popup
= new OO
.ui
.PopupWidget( $.extend(
6142 { autoClose
: true },
6144 { $autoCloseIgnore
: this.$element
}
6153 * @return {OO.ui.PopupWidget} Popup widget
6155 OO
.ui
.mixin
.PopupElement
.prototype.getPopup = function () {
6160 * The FlaggedElement class is an attribute mixin, meaning that it is used to add
6161 * additional functionality to an element created by another class. The class provides
6162 * a ‘flags’ property assigned the name (or an array of names) of styling flags,
6163 * which are used to customize the look and feel of a widget to better describe its
6164 * importance and functionality.
6166 * The library currently contains the following styling flags for general use:
6168 * - **progressive**: Progressive styling is applied to convey that the widget will move the user forward in a process.
6169 * - **destructive**: Destructive styling is applied to convey that the widget will remove something.
6170 * - **constructive**: Constructive styling is applied to convey that the widget will create something.
6172 * The flags affect the appearance of the buttons:
6175 * // FlaggedElement is mixed into ButtonWidget to provide styling flags
6176 * var button1 = new OO.ui.ButtonWidget( {
6177 * label: 'Constructive',
6178 * flags: 'constructive'
6180 * var button2 = new OO.ui.ButtonWidget( {
6181 * label: 'Destructive',
6182 * flags: 'destructive'
6184 * var button3 = new OO.ui.ButtonWidget( {
6185 * label: 'Progressive',
6186 * flags: 'progressive'
6188 * $( 'body' ).append( button1.$element, button2.$element, button3.$element );
6190 * {@link OO.ui.ActionWidget ActionWidgets}, which are a special kind of button that execute an action, use these flags: **primary** and **safe**.
6191 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information.
6193 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Elements/Flagged
6199 * @param {Object} [config] Configuration options
6200 * @cfg {string|string[]} [flags] The name or names of the flags (e.g., 'constructive' or 'primary') to apply.
6201 * Please see the [OOjs UI documentation on MediaWiki] [2] for more information about available flags.
6202 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Elements/Flagged
6203 * @cfg {jQuery} [$flagged] The flagged element. By default,
6204 * the flagged functionality is applied to the element created by the class ($element).
6205 * If a different element is specified, the flagged functionality will be applied to it instead.
6207 OO
.ui
.mixin
.FlaggedElement
= function OoUiMixinFlaggedElement( config
) {
6208 // Configuration initialization
6209 config
= config
|| {};
6213 this.$flagged
= null;
6216 this.setFlags( config
.flags
);
6217 this.setFlaggedElement( config
.$flagged
|| this.$element
);
6224 * A flag event is emitted when the #clearFlags or #setFlags methods are used. The `changes`
6225 * parameter contains the name of each modified flag and indicates whether it was
6228 * @param {Object.<string,boolean>} changes Object keyed by flag name. A Boolean `true` indicates
6229 * that the flag was added, `false` that the flag was removed.
6235 * Set the flagged element.
6237 * This method is used to retarget a flagged mixin so that its functionality applies to the specified element.
6238 * If an element is already set, the method will remove the mixin’s effect on that element.
6240 * @param {jQuery} $flagged Element that should be flagged
6242 OO
.ui
.mixin
.FlaggedElement
.prototype.setFlaggedElement = function ( $flagged
) {
6243 var classNames
= Object
.keys( this.flags
).map( function ( flag
) {
6244 return 'oo-ui-flaggedElement-' + flag
;
6247 if ( this.$flagged
) {
6248 this.$flagged
.removeClass( classNames
);
6251 this.$flagged
= $flagged
.addClass( classNames
);
6255 * Check if the specified flag is set.
6257 * @param {string} flag Name of flag
6258 * @return {boolean} The flag is set
6260 OO
.ui
.mixin
.FlaggedElement
.prototype.hasFlag = function ( flag
) {
6261 // This may be called before the constructor, thus before this.flags is set
6262 return this.flags
&& ( flag
in this.flags
);
6266 * Get the names of all flags set.
6268 * @return {string[]} Flag names
6270 OO
.ui
.mixin
.FlaggedElement
.prototype.getFlags = function () {
6271 // This may be called before the constructor, thus before this.flags is set
6272 return Object
.keys( this.flags
|| {} );
6281 OO
.ui
.mixin
.FlaggedElement
.prototype.clearFlags = function () {
6282 var flag
, className
,
6285 classPrefix
= 'oo-ui-flaggedElement-';
6287 for ( flag
in this.flags
) {
6288 className
= classPrefix
+ flag
;
6289 changes
[ flag
] = false;
6290 delete this.flags
[ flag
];
6291 remove
.push( className
);
6294 if ( this.$flagged
) {
6295 this.$flagged
.removeClass( remove
.join( ' ' ) );
6298 this.updateThemeClasses();
6299 this.emit( 'flag', changes
);
6305 * Add one or more flags.
6307 * @param {string|string[]|Object.<string, boolean>} flags A flag name, an array of flag names,
6308 * or an object keyed by flag name with a boolean value that indicates whether the flag should
6309 * be added (`true`) or removed (`false`).
6313 OO
.ui
.mixin
.FlaggedElement
.prototype.setFlags = function ( flags
) {
6314 var i
, len
, flag
, className
,
6318 classPrefix
= 'oo-ui-flaggedElement-';
6320 if ( typeof flags
=== 'string' ) {
6321 className
= classPrefix
+ flags
;
6323 if ( !this.flags
[ flags
] ) {
6324 this.flags
[ flags
] = true;
6325 add
.push( className
);
6327 } else if ( Array
.isArray( flags
) ) {
6328 for ( i
= 0, len
= flags
.length
; i
< len
; i
++ ) {
6330 className
= classPrefix
+ flag
;
6332 if ( !this.flags
[ flag
] ) {
6333 changes
[ flag
] = true;
6334 this.flags
[ flag
] = true;
6335 add
.push( className
);
6338 } else if ( OO
.isPlainObject( flags
) ) {
6339 for ( flag
in flags
) {
6340 className
= classPrefix
+ flag
;
6341 if ( flags
[ flag
] ) {
6343 if ( !this.flags
[ flag
] ) {
6344 changes
[ flag
] = true;
6345 this.flags
[ flag
] = true;
6346 add
.push( className
);
6350 if ( this.flags
[ flag
] ) {
6351 changes
[ flag
] = false;
6352 delete this.flags
[ flag
];
6353 remove
.push( className
);
6359 if ( this.$flagged
) {
6361 .addClass( add
.join( ' ' ) )
6362 .removeClass( remove
.join( ' ' ) );
6365 this.updateThemeClasses();
6366 this.emit( 'flag', changes
);
6372 * TitledElement is mixed into other classes to provide a `title` attribute.
6373 * Titles are rendered by the browser and are made visible when the user moves
6374 * the mouse over the element. Titles are not visible on touch devices.
6377 * // TitledElement provides a 'title' attribute to the
6378 * // ButtonWidget class
6379 * var button = new OO.ui.ButtonWidget( {
6380 * label: 'Button with Title',
6381 * title: 'I am a button'
6383 * $( 'body' ).append( button.$element );
6389 * @param {Object} [config] Configuration options
6390 * @cfg {jQuery} [$titled] The element to which the `title` attribute is applied.
6391 * If this config is omitted, the title functionality is applied to $element, the
6392 * element created by the class.
6393 * @cfg {string|Function} [title] The title text or a function that returns text. If
6394 * this config is omitted, the value of the {@link #static-title static title} property is used.
6396 OO
.ui
.mixin
.TitledElement
= function OoUiMixinTitledElement( config
) {
6397 // Configuration initialization
6398 config
= config
|| {};
6401 this.$titled
= null;
6405 this.setTitle( config
.title
|| this.constructor.static.title
);
6406 this.setTitledElement( config
.$titled
|| this.$element
);
6411 OO
.initClass( OO
.ui
.mixin
.TitledElement
);
6413 /* Static Properties */
6416 * The title text, a function that returns text, or `null` for no title. The value of the static property
6417 * is overridden if the #title config option is used.
6421 * @property {string|Function|null}
6423 OO
.ui
.mixin
.TitledElement
.static.title
= null;
6428 * Set the titled element.
6430 * This method is used to retarget a titledElement mixin so that its functionality applies to the specified element.
6431 * If an element is already set, the mixin’s effect on that element is removed before the new element is set up.
6433 * @param {jQuery} $titled Element that should use the 'titled' functionality
6435 OO
.ui
.mixin
.TitledElement
.prototype.setTitledElement = function ( $titled
) {
6436 if ( this.$titled
) {
6437 this.$titled
.removeAttr( 'title' );
6440 this.$titled
= $titled
;
6442 this.$titled
.attr( 'title', this.title
);
6449 * @param {string|Function|null} title Title text, a function that returns text, or `null` for no title
6452 OO
.ui
.mixin
.TitledElement
.prototype.setTitle = function ( title
) {
6453 title
= typeof title
=== 'string' ? OO
.ui
.resolveMsg( title
) : null;
6455 if ( this.title
!== title
) {
6456 if ( this.$titled
) {
6457 if ( title
!== null ) {
6458 this.$titled
.attr( 'title', title
);
6460 this.$titled
.removeAttr( 'title' );
6472 * @return {string} Title string
6474 OO
.ui
.mixin
.TitledElement
.prototype.getTitle = function () {
6479 * Element that can be automatically clipped to visible boundaries.
6481 * Whenever the element's natural height changes, you have to call
6482 * {@link OO.ui.mixin.ClippableElement#clip} to make sure it's still
6483 * clipping correctly.
6489 * @param {Object} [config] Configuration options
6490 * @cfg {jQuery} [$clippable] Nodes to clip, assigned to #$clippable, omit to use #$element
6492 OO
.ui
.mixin
.ClippableElement
= function OoUiMixinClippableElement( config
) {
6493 // Configuration initialization
6494 config
= config
|| {};
6497 this.$clippable
= null;
6498 this.clipping
= false;
6499 this.clippedHorizontally
= false;
6500 this.clippedVertically
= false;
6501 this.$clippableContainer
= null;
6502 this.$clippableScroller
= null;
6503 this.$clippableWindow
= null;
6504 this.idealWidth
= null;
6505 this.idealHeight
= null;
6506 this.onClippableContainerScrollHandler
= this.clip
.bind( this );
6507 this.onClippableWindowResizeHandler
= this.clip
.bind( this );
6510 this.setClippableElement( config
.$clippable
|| this.$element
);
6516 * Set clippable element.
6518 * If an element is already set, it will be cleaned up before setting up the new element.
6520 * @param {jQuery} $clippable Element to make clippable
6522 OO
.ui
.mixin
.ClippableElement
.prototype.setClippableElement = function ( $clippable
) {
6523 if ( this.$clippable
) {
6524 this.$clippable
.removeClass( 'oo-ui-clippableElement-clippable' );
6525 this.$clippable
.css( { width
: '', height
: '', overflowX
: '', overflowY
: '' } );
6526 OO
.ui
.Element
.static.reconsiderScrollbars( this.$clippable
[ 0 ] );
6529 this.$clippable
= $clippable
.addClass( 'oo-ui-clippableElement-clippable' );
6536 * Do not turn clipping on until after the element is attached to the DOM and visible.
6538 * @param {boolean} [clipping] Enable clipping, omit to toggle
6541 OO
.ui
.mixin
.ClippableElement
.prototype.toggleClipping = function ( clipping
) {
6542 clipping
= clipping
=== undefined ? !this.clipping
: !!clipping
;
6544 if ( this.clipping
!== clipping
) {
6545 this.clipping
= clipping
;
6547 this.$clippableContainer
= $( this.getClosestScrollableElementContainer() );
6548 // If the clippable container is the root, we have to listen to scroll events and check
6549 // jQuery.scrollTop on the window because of browser inconsistencies
6550 this.$clippableScroller
= this.$clippableContainer
.is( 'html, body' ) ?
6551 $( OO
.ui
.Element
.static.getWindow( this.$clippableContainer
) ) :
6552 this.$clippableContainer
;
6553 this.$clippableScroller
.on( 'scroll', this.onClippableContainerScrollHandler
);
6554 this.$clippableWindow
= $( this.getElementWindow() )
6555 .on( 'resize', this.onClippableWindowResizeHandler
);
6556 // Initial clip after visible
6559 this.$clippable
.css( { width
: '', height
: '', overflowX
: '', overflowY
: '' } );
6560 OO
.ui
.Element
.static.reconsiderScrollbars( this.$clippable
[ 0 ] );
6562 this.$clippableContainer
= null;
6563 this.$clippableScroller
.off( 'scroll', this.onClippableContainerScrollHandler
);
6564 this.$clippableScroller
= null;
6565 this.$clippableWindow
.off( 'resize', this.onClippableWindowResizeHandler
);
6566 this.$clippableWindow
= null;
6574 * Check if the element will be clipped to fit the visible area of the nearest scrollable container.
6576 * @return {boolean} Element will be clipped to the visible area
6578 OO
.ui
.mixin
.ClippableElement
.prototype.isClipping = function () {
6579 return this.clipping
;
6583 * Check if the bottom or right of the element is being clipped by the nearest scrollable container.
6585 * @return {boolean} Part of the element is being clipped
6587 OO
.ui
.mixin
.ClippableElement
.prototype.isClipped = function () {
6588 return this.clippedHorizontally
|| this.clippedVertically
;
6592 * Check if the right of the element is being clipped by the nearest scrollable container.
6594 * @return {boolean} Part of the element is being clipped
6596 OO
.ui
.mixin
.ClippableElement
.prototype.isClippedHorizontally = function () {
6597 return this.clippedHorizontally
;
6601 * Check if the bottom of the element is being clipped by the nearest scrollable container.
6603 * @return {boolean} Part of the element is being clipped
6605 OO
.ui
.mixin
.ClippableElement
.prototype.isClippedVertically = function () {
6606 return this.clippedVertically
;
6610 * Set the ideal size. These are the dimensions the element will have when it's not being clipped.
6612 * @param {number|string} [width] Width as a number of pixels or CSS string with unit suffix
6613 * @param {number|string} [height] Height as a number of pixels or CSS string with unit suffix
6615 OO
.ui
.mixin
.ClippableElement
.prototype.setIdealSize = function ( width
, height
) {
6616 this.idealWidth
= width
;
6617 this.idealHeight
= height
;
6619 if ( !this.clipping
) {
6620 // Update dimensions
6621 this.$clippable
.css( { width
: width
, height
: height
} );
6623 // While clipping, idealWidth and idealHeight are not considered
6627 * Clip element to visible boundaries and allow scrolling when needed. Call this method when
6628 * the element's natural height changes.
6630 * Element will be clipped the bottom or right of the element is within 10px of the edge of, or
6631 * overlapped by, the visible area of the nearest scrollable container.
6635 OO
.ui
.mixin
.ClippableElement
.prototype.clip = function () {
6636 if ( !this.clipping
) {
6637 // this.$clippableContainer and this.$clippableWindow are null, so the below will fail
6641 var buffer
= 7, // Chosen by fair dice roll
6642 cOffset
= this.$clippable
.offset(),
6643 $container
= this.$clippableContainer
.is( 'html, body' ) ?
6644 this.$clippableWindow
: this.$clippableContainer
,
6645 ccOffset
= $container
.offset() || { top
: 0, left
: 0 },
6646 ccHeight
= $container
.innerHeight() - buffer
,
6647 ccWidth
= $container
.innerWidth() - buffer
,
6648 cWidth
= this.$clippable
.outerWidth() + buffer
,
6649 scrollerIsWindow
= this.$clippableScroller
[0] === this.$clippableWindow
[0],
6650 scrollTop
= scrollerIsWindow
? this.$clippableScroller
.scrollTop() : 0,
6651 scrollLeft
= scrollerIsWindow
? this.$clippableScroller
.scrollLeft() : 0,
6652 desiredWidth
= cOffset
.left
< 0 ?
6653 cWidth
+ cOffset
.left
:
6654 ( ccOffset
.left
+ scrollLeft
+ ccWidth
) - cOffset
.left
,
6655 desiredHeight
= ( ccOffset
.top
+ scrollTop
+ ccHeight
) - cOffset
.top
,
6656 naturalWidth
= this.$clippable
.prop( 'scrollWidth' ),
6657 naturalHeight
= this.$clippable
.prop( 'scrollHeight' ),
6658 clipWidth
= desiredWidth
< naturalWidth
,
6659 clipHeight
= desiredHeight
< naturalHeight
;
6662 this.$clippable
.css( { overflowX
: 'scroll', width
: desiredWidth
} );
6664 this.$clippable
.css( { width
: this.idealWidth
|| '', overflowX
: '' } );
6667 this.$clippable
.css( { overflowY
: 'scroll', height
: desiredHeight
} );
6669 this.$clippable
.css( { height
: this.idealHeight
|| '', overflowY
: '' } );
6672 // If we stopped clipping in at least one of the dimensions
6673 if ( ( this.clippedHorizontally
&& !clipWidth
) || ( this.clippedVertically
&& !clipHeight
) ) {
6674 OO
.ui
.Element
.static.reconsiderScrollbars( this.$clippable
[ 0 ] );
6677 this.clippedHorizontally
= clipWidth
;
6678 this.clippedVertically
= clipHeight
;
6684 * Tools, together with {@link OO.ui.ToolGroup toolgroups}, constitute {@link OO.ui.Toolbar toolbars}.
6685 * Each tool is configured with a static name, title, and icon and is customized with the command to carry
6686 * out when the tool is selected. Tools must also be registered with a {@link OO.ui.ToolFactory tool factory},
6687 * which creates the tools on demand.
6689 * Tools are added to toolgroups ({@link OO.ui.ListToolGroup ListToolGroup},
6690 * {@link OO.ui.BarToolGroup BarToolGroup}, or {@link OO.ui.MenuToolGroup MenuToolGroup}), which determine how
6691 * the tool is displayed in the toolbar. See {@link OO.ui.Toolbar toolbars} for an example.
6693 * For more information, please see the [OOjs UI documentation on MediaWiki][1].
6694 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
6698 * @extends OO.ui.Widget
6699 * @mixins OO.ui.mixin.IconElement
6700 * @mixins OO.ui.mixin.FlaggedElement
6701 * @mixins OO.ui.mixin.TabIndexedElement
6704 * @param {OO.ui.ToolGroup} toolGroup
6705 * @param {Object} [config] Configuration options
6706 * @cfg {string|Function} [title] Title text or a function that returns text. If this config is omitted, the value of
6707 * the {@link #static-title static title} property is used.
6709 * The title is used in different ways depending on the type of toolgroup that contains the tool. The
6710 * title is used as a tooltip if the tool is part of a {@link OO.ui.BarToolGroup bar} toolgroup, or as the label text if the tool is
6711 * part of a {@link OO.ui.ListToolGroup list} or {@link OO.ui.MenuToolGroup menu} toolgroup.
6713 * For bar toolgroups, a description of the accelerator key is appended to the title if an accelerator key
6714 * is associated with an action by the same name as the tool and accelerator functionality has been added to the application.
6715 * To add accelerator key functionality, you must subclass OO.ui.Toolbar and override the {@link OO.ui.Toolbar#getToolAccelerator getToolAccelerator} method.
6717 OO
.ui
.Tool
= function OoUiTool( toolGroup
, config
) {
6718 // Allow passing positional parameters inside the config object
6719 if ( OO
.isPlainObject( toolGroup
) && config
=== undefined ) {
6721 toolGroup
= config
.toolGroup
;
6724 // Configuration initialization
6725 config
= config
|| {};
6727 // Parent constructor
6728 OO
.ui
.Tool
.parent
.call( this, config
);
6731 this.toolGroup
= toolGroup
;
6732 this.toolbar
= this.toolGroup
.getToolbar();
6733 this.active
= false;
6734 this.$title
= $( '<span>' );
6735 this.$accel
= $( '<span>' );
6736 this.$link
= $( '<a>' );
6739 // Mixin constructors
6740 OO
.ui
.mixin
.IconElement
.call( this, config
);
6741 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
6742 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$link
} ) );
6745 this.toolbar
.connect( this, { updateState
: 'onUpdateState' } );
6748 this.$title
.addClass( 'oo-ui-tool-title' );
6750 .addClass( 'oo-ui-tool-accel' )
6752 // This may need to be changed if the key names are ever localized,
6753 // but for now they are essentially written in English
6758 .addClass( 'oo-ui-tool-link' )
6759 .append( this.$icon
, this.$title
, this.$accel
)
6760 .attr( 'role', 'button' );
6762 .data( 'oo-ui-tool', this )
6764 'oo-ui-tool ' + 'oo-ui-tool-name-' +
6765 this.constructor.static.name
.replace( /^([^\/]+)\/([^\/]+).*$/, '$1-$2' )
6767 .toggleClass( 'oo-ui-tool-with-label', this.constructor.static.displayBothIconAndLabel
)
6768 .append( this.$link
);
6769 this.setTitle( config
.title
|| this.constructor.static.title
);
6774 OO
.inheritClass( OO
.ui
.Tool
, OO
.ui
.Widget
);
6775 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.mixin
.IconElement
);
6776 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.mixin
.FlaggedElement
);
6777 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.mixin
.TabIndexedElement
);
6779 /* Static Properties */
6785 OO
.ui
.Tool
.static.tagName
= 'span';
6788 * Symbolic name of tool.
6790 * The symbolic name is used internally to register the tool with a {@link OO.ui.ToolFactory ToolFactory}. It can
6791 * also be used when adding tools to toolgroups.
6796 * @property {string}
6798 OO
.ui
.Tool
.static.name
= '';
6801 * Symbolic name of the group.
6803 * The group name is used to associate tools with each other so that they can be selected later by
6804 * a {@link OO.ui.ToolGroup toolgroup}.
6809 * @property {string}
6811 OO
.ui
.Tool
.static.group
= '';
6814 * Tool title text or a function that returns title text. The value of the static property is overridden if the #title config option is used.
6819 * @property {string|Function}
6821 OO
.ui
.Tool
.static.title
= '';
6824 * Display both icon and label when the tool is used in a {@link OO.ui.BarToolGroup bar} toolgroup.
6825 * Normally only the icon is displayed, or only the label if no icon is given.
6829 * @property {boolean}
6831 OO
.ui
.Tool
.static.displayBothIconAndLabel
= false;
6834 * Add tool to catch-all groups automatically.
6836 * A catch-all group, which contains all tools that do not currently belong to a toolgroup,
6837 * can be included in a toolgroup using the wildcard selector, an asterisk (*).
6841 * @property {boolean}
6843 OO
.ui
.Tool
.static.autoAddToCatchall
= true;
6846 * Add tool to named groups automatically.
6848 * By default, tools that are configured with a static ‘group’ property are added
6849 * to that group and will be selected when the symbolic name of the group is specified (e.g., when
6850 * toolgroups include tools by group name).
6853 * @property {boolean}
6856 OO
.ui
.Tool
.static.autoAddToGroup
= true;
6859 * Check if this tool is compatible with given data.
6861 * This is a stub that can be overriden to provide support for filtering tools based on an
6862 * arbitrary piece of information (e.g., where the cursor is in a document). The implementation
6863 * must also call this method so that the compatibility check can be performed.
6867 * @param {Mixed} data Data to check
6868 * @return {boolean} Tool can be used with data
6870 OO
.ui
.Tool
.static.isCompatibleWith = function () {
6877 * Handle the toolbar state being updated.
6879 * This is an abstract method that must be overridden in a concrete subclass.
6884 OO
.ui
.Tool
.prototype.onUpdateState = function () {
6886 'OO.ui.Tool.onUpdateState not implemented in this subclass:' + this.constructor
6891 * Handle the tool being selected.
6893 * This is an abstract method that must be overridden in a concrete subclass.
6898 OO
.ui
.Tool
.prototype.onSelect = function () {
6900 'OO.ui.Tool.onSelect not implemented in this subclass:' + this.constructor
6905 * Check if the tool is active.
6907 * Tools become active when their #onSelect or #onUpdateState handlers change them to appear pressed
6908 * with the #setActive method. Additional CSS is applied to the tool to reflect the active state.
6910 * @return {boolean} Tool is active
6912 OO
.ui
.Tool
.prototype.isActive = function () {
6917 * Make the tool appear active or inactive.
6919 * This method should be called within #onSelect or #onUpdateState event handlers to make the tool
6920 * appear pressed or not.
6922 * @param {boolean} state Make tool appear active
6924 OO
.ui
.Tool
.prototype.setActive = function ( state
) {
6925 this.active
= !!state
;
6926 if ( this.active
) {
6927 this.$element
.addClass( 'oo-ui-tool-active' );
6929 this.$element
.removeClass( 'oo-ui-tool-active' );
6934 * Set the tool #title.
6936 * @param {string|Function} title Title text or a function that returns text
6939 OO
.ui
.Tool
.prototype.setTitle = function ( title
) {
6940 this.title
= OO
.ui
.resolveMsg( title
);
6946 * Get the tool #title.
6948 * @return {string} Title text
6950 OO
.ui
.Tool
.prototype.getTitle = function () {
6955 * Get the tool's symbolic name.
6957 * @return {string} Symbolic name of tool
6959 OO
.ui
.Tool
.prototype.getName = function () {
6960 return this.constructor.static.name
;
6966 OO
.ui
.Tool
.prototype.updateTitle = function () {
6967 var titleTooltips
= this.toolGroup
.constructor.static.titleTooltips
,
6968 accelTooltips
= this.toolGroup
.constructor.static.accelTooltips
,
6969 accel
= this.toolbar
.getToolAccelerator( this.constructor.static.name
),
6972 this.$title
.text( this.title
);
6973 this.$accel
.text( accel
);
6975 if ( titleTooltips
&& typeof this.title
=== 'string' && this.title
.length
) {
6976 tooltipParts
.push( this.title
);
6978 if ( accelTooltips
&& typeof accel
=== 'string' && accel
.length
) {
6979 tooltipParts
.push( accel
);
6981 if ( tooltipParts
.length
) {
6982 this.$link
.attr( 'title', tooltipParts
.join( ' ' ) );
6984 this.$link
.removeAttr( 'title' );
6991 * Destroying the tool removes all event handlers and the tool’s DOM elements.
6992 * Call this method whenever you are done using a tool.
6994 OO
.ui
.Tool
.prototype.destroy = function () {
6995 this.toolbar
.disconnect( this );
6996 this.$element
.remove();
7000 * Toolbars are complex interface components that permit users to easily access a variety
7001 * of {@link OO.ui.Tool tools} (e.g., formatting commands) and actions, which are additional commands that are
7002 * part of the toolbar, but not configured as tools.
7004 * Individual tools are customized and then registered with a {@link OO.ui.ToolFactory tool factory}, which creates
7005 * the tools on demand. Each tool has a symbolic name (used when registering the tool), a title (e.g., ‘Insert
7006 * picture’), and an icon.
7008 * Individual tools are organized in {@link OO.ui.ToolGroup toolgroups}, which can be {@link OO.ui.MenuToolGroup menus}
7009 * of tools, {@link OO.ui.ListToolGroup lists} of tools, or a single {@link OO.ui.BarToolGroup bar} of tools.
7010 * The arrangement and order of the toolgroups is customized when the toolbar is set up. Tools can be presented in
7011 * any order, but each can only appear once in the toolbar.
7013 * The following is an example of a basic toolbar.
7016 * // Example of a toolbar
7017 * // Create the toolbar
7018 * var toolFactory = new OO.ui.ToolFactory();
7019 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
7020 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
7022 * // We will be placing status text in this element when tools are used
7023 * var $area = $( '<p>' ).text( 'Toolbar example' );
7025 * // Define the tools that we're going to place in our toolbar
7027 * // Create a class inheriting from OO.ui.Tool
7028 * function PictureTool() {
7029 * PictureTool.parent.apply( this, arguments );
7031 * OO.inheritClass( PictureTool, OO.ui.Tool );
7032 * // Each tool must have a 'name' (used as an internal identifier, see later) and at least one
7033 * // of 'icon' and 'title' (displayed icon and text).
7034 * PictureTool.static.name = 'picture';
7035 * PictureTool.static.icon = 'picture';
7036 * PictureTool.static.title = 'Insert picture';
7037 * // Defines the action that will happen when this tool is selected (clicked).
7038 * PictureTool.prototype.onSelect = function () {
7039 * $area.text( 'Picture tool clicked!' );
7040 * // Never display this tool as "active" (selected).
7041 * this.setActive( false );
7043 * // Make this tool available in our toolFactory and thus our toolbar
7044 * toolFactory.register( PictureTool );
7046 * // Register two more tools, nothing interesting here
7047 * function SettingsTool() {
7048 * SettingsTool.parent.apply( this, arguments );
7050 * OO.inheritClass( SettingsTool, OO.ui.Tool );
7051 * SettingsTool.static.name = 'settings';
7052 * SettingsTool.static.icon = 'settings';
7053 * SettingsTool.static.title = 'Change settings';
7054 * SettingsTool.prototype.onSelect = function () {
7055 * $area.text( 'Settings tool clicked!' );
7056 * this.setActive( false );
7058 * toolFactory.register( SettingsTool );
7060 * // Register two more tools, nothing interesting here
7061 * function StuffTool() {
7062 * StuffTool.parent.apply( this, arguments );
7064 * OO.inheritClass( StuffTool, OO.ui.Tool );
7065 * StuffTool.static.name = 'stuff';
7066 * StuffTool.static.icon = 'ellipsis';
7067 * StuffTool.static.title = 'More stuff';
7068 * StuffTool.prototype.onSelect = function () {
7069 * $area.text( 'More stuff tool clicked!' );
7070 * this.setActive( false );
7072 * toolFactory.register( StuffTool );
7074 * // This is a PopupTool. Rather than having a custom 'onSelect' action, it will display a
7075 * // little popup window (a PopupWidget).
7076 * function HelpTool( toolGroup, config ) {
7077 * OO.ui.PopupTool.call( this, toolGroup, $.extend( { popup: {
7082 * this.popup.$body.append( '<p>I am helpful!</p>' );
7084 * OO.inheritClass( HelpTool, OO.ui.PopupTool );
7085 * HelpTool.static.name = 'help';
7086 * HelpTool.static.icon = 'help';
7087 * HelpTool.static.title = 'Help';
7088 * toolFactory.register( HelpTool );
7090 * // Finally define which tools and in what order appear in the toolbar. Each tool may only be
7091 * // used once (but not all defined tools must be used).
7094 * // 'bar' tool groups display tools' icons only, side-by-side.
7096 * include: [ 'picture', 'help' ]
7099 * // 'list' tool groups display both the titles and icons, in a dropdown list.
7101 * indicator: 'down',
7103 * include: [ 'settings', 'stuff' ]
7105 * // Note how the tools themselves are toolgroup-agnostic - the same tool can be displayed
7106 * // either in a 'list' or a 'bar'. There is a 'menu' tool group too, not showcased here,
7107 * // since it's more complicated to use. (See the next example snippet on this page.)
7110 * // Create some UI around the toolbar and place it in the document
7111 * var frame = new OO.ui.PanelLayout( {
7115 * var contentFrame = new OO.ui.PanelLayout( {
7119 * frame.$element.append(
7121 * contentFrame.$element.append( $area )
7123 * $( 'body' ).append( frame.$element );
7125 * // Here is where the toolbar is actually built. This must be done after inserting it into the
7127 * toolbar.initialize();
7129 * The following example extends the previous one to illustrate 'menu' toolgroups and the usage of
7130 * 'updateState' event.
7133 * // Create the toolbar
7134 * var toolFactory = new OO.ui.ToolFactory();
7135 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
7136 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
7138 * // We will be placing status text in this element when tools are used
7139 * var $area = $( '<p>' ).text( 'Toolbar example' );
7141 * // Define the tools that we're going to place in our toolbar
7143 * // Create a class inheriting from OO.ui.Tool
7144 * function PictureTool() {
7145 * PictureTool.parent.apply( this, arguments );
7147 * OO.inheritClass( PictureTool, OO.ui.Tool );
7148 * // Each tool must have a 'name' (used as an internal identifier, see later) and at least one
7149 * // of 'icon' and 'title' (displayed icon and text).
7150 * PictureTool.static.name = 'picture';
7151 * PictureTool.static.icon = 'picture';
7152 * PictureTool.static.title = 'Insert picture';
7153 * // Defines the action that will happen when this tool is selected (clicked).
7154 * PictureTool.prototype.onSelect = function () {
7155 * $area.text( 'Picture tool clicked!' );
7156 * // Never display this tool as "active" (selected).
7157 * this.setActive( false );
7159 * // The toolbar can be synchronized with the state of some external stuff, like a text
7160 * // editor's editing area, highlighting the tools (e.g. a 'bold' tool would be shown as active
7161 * // when the text cursor was inside bolded text). Here we simply disable this feature.
7162 * PictureTool.prototype.onUpdateState = function () {
7164 * // Make this tool available in our toolFactory and thus our toolbar
7165 * toolFactory.register( PictureTool );
7167 * // Register two more tools, nothing interesting here
7168 * function SettingsTool() {
7169 * SettingsTool.parent.apply( this, arguments );
7170 * this.reallyActive = false;
7172 * OO.inheritClass( SettingsTool, OO.ui.Tool );
7173 * SettingsTool.static.name = 'settings';
7174 * SettingsTool.static.icon = 'settings';
7175 * SettingsTool.static.title = 'Change settings';
7176 * SettingsTool.prototype.onSelect = function () {
7177 * $area.text( 'Settings tool clicked!' );
7178 * // Toggle the active state on each click
7179 * this.reallyActive = !this.reallyActive;
7180 * this.setActive( this.reallyActive );
7181 * // To update the menu label
7182 * this.toolbar.emit( 'updateState' );
7184 * SettingsTool.prototype.onUpdateState = function () {
7186 * toolFactory.register( SettingsTool );
7188 * // Register two more tools, nothing interesting here
7189 * function StuffTool() {
7190 * StuffTool.parent.apply( this, arguments );
7191 * this.reallyActive = false;
7193 * OO.inheritClass( StuffTool, OO.ui.Tool );
7194 * StuffTool.static.name = 'stuff';
7195 * StuffTool.static.icon = 'ellipsis';
7196 * StuffTool.static.title = 'More stuff';
7197 * StuffTool.prototype.onSelect = function () {
7198 * $area.text( 'More stuff tool clicked!' );
7199 * // Toggle the active state on each click
7200 * this.reallyActive = !this.reallyActive;
7201 * this.setActive( this.reallyActive );
7202 * // To update the menu label
7203 * this.toolbar.emit( 'updateState' );
7205 * StuffTool.prototype.onUpdateState = function () {
7207 * toolFactory.register( StuffTool );
7209 * // This is a PopupTool. Rather than having a custom 'onSelect' action, it will display a
7210 * // little popup window (a PopupWidget). 'onUpdateState' is also already implemented.
7211 * function HelpTool( toolGroup, config ) {
7212 * OO.ui.PopupTool.call( this, toolGroup, $.extend( { popup: {
7217 * this.popup.$body.append( '<p>I am helpful!</p>' );
7219 * OO.inheritClass( HelpTool, OO.ui.PopupTool );
7220 * HelpTool.static.name = 'help';
7221 * HelpTool.static.icon = 'help';
7222 * HelpTool.static.title = 'Help';
7223 * toolFactory.register( HelpTool );
7225 * // Finally define which tools and in what order appear in the toolbar. Each tool may only be
7226 * // used once (but not all defined tools must be used).
7229 * // 'bar' tool groups display tools' icons only, side-by-side.
7231 * include: [ 'picture', 'help' ]
7234 * // 'menu' tool groups display both the titles and icons, in a dropdown menu.
7235 * // Menu label indicates which items are selected.
7237 * indicator: 'down',
7238 * include: [ 'settings', 'stuff' ]
7242 * // Create some UI around the toolbar and place it in the document
7243 * var frame = new OO.ui.PanelLayout( {
7247 * var contentFrame = new OO.ui.PanelLayout( {
7251 * frame.$element.append(
7253 * contentFrame.$element.append( $area )
7255 * $( 'body' ).append( frame.$element );
7257 * // Here is where the toolbar is actually built. This must be done after inserting it into the
7259 * toolbar.initialize();
7260 * toolbar.emit( 'updateState' );
7263 * @extends OO.ui.Element
7264 * @mixins OO.EventEmitter
7265 * @mixins OO.ui.mixin.GroupElement
7268 * @param {OO.ui.ToolFactory} toolFactory Factory for creating tools
7269 * @param {OO.ui.ToolGroupFactory} toolGroupFactory Factory for creating toolgroups
7270 * @param {Object} [config] Configuration options
7271 * @cfg {boolean} [actions] Add an actions section to the toolbar. Actions are commands that are included
7272 * in the toolbar, but are not configured as tools. By default, actions are displayed on the right side of
7274 * @cfg {boolean} [shadow] Add a shadow below the toolbar.
7276 OO
.ui
.Toolbar
= function OoUiToolbar( toolFactory
, toolGroupFactory
, config
) {
7277 // Allow passing positional parameters inside the config object
7278 if ( OO
.isPlainObject( toolFactory
) && config
=== undefined ) {
7279 config
= toolFactory
;
7280 toolFactory
= config
.toolFactory
;
7281 toolGroupFactory
= config
.toolGroupFactory
;
7284 // Configuration initialization
7285 config
= config
|| {};
7287 // Parent constructor
7288 OO
.ui
.Toolbar
.parent
.call( this, config
);
7290 // Mixin constructors
7291 OO
.EventEmitter
.call( this );
7292 OO
.ui
.mixin
.GroupElement
.call( this, config
);
7295 this.toolFactory
= toolFactory
;
7296 this.toolGroupFactory
= toolGroupFactory
;
7299 this.$bar
= $( '<div>' );
7300 this.$actions
= $( '<div>' );
7301 this.initialized
= false;
7302 this.onWindowResizeHandler
= this.onWindowResize
.bind( this );
7306 .add( this.$bar
).add( this.$group
).add( this.$actions
)
7307 .on( 'mousedown keydown', this.onPointerDown
.bind( this ) );
7310 this.$group
.addClass( 'oo-ui-toolbar-tools' );
7311 if ( config
.actions
) {
7312 this.$bar
.append( this.$actions
.addClass( 'oo-ui-toolbar-actions' ) );
7315 .addClass( 'oo-ui-toolbar-bar' )
7316 .append( this.$group
, '<div style="clear:both"></div>' );
7317 if ( config
.shadow
) {
7318 this.$bar
.append( '<div class="oo-ui-toolbar-shadow"></div>' );
7320 this.$element
.addClass( 'oo-ui-toolbar' ).append( this.$bar
);
7325 OO
.inheritClass( OO
.ui
.Toolbar
, OO
.ui
.Element
);
7326 OO
.mixinClass( OO
.ui
.Toolbar
, OO
.EventEmitter
);
7327 OO
.mixinClass( OO
.ui
.Toolbar
, OO
.ui
.mixin
.GroupElement
);
7332 * Get the tool factory.
7334 * @return {OO.ui.ToolFactory} Tool factory
7336 OO
.ui
.Toolbar
.prototype.getToolFactory = function () {
7337 return this.toolFactory
;
7341 * Get the toolgroup factory.
7343 * @return {OO.Factory} Toolgroup factory
7345 OO
.ui
.Toolbar
.prototype.getToolGroupFactory = function () {
7346 return this.toolGroupFactory
;
7350 * Handles mouse down events.
7353 * @param {jQuery.Event} e Mouse down event
7355 OO
.ui
.Toolbar
.prototype.onPointerDown = function ( e
) {
7356 var $closestWidgetToEvent
= $( e
.target
).closest( '.oo-ui-widget' ),
7357 $closestWidgetToToolbar
= this.$element
.closest( '.oo-ui-widget' );
7358 if ( !$closestWidgetToEvent
.length
|| $closestWidgetToEvent
[ 0 ] === $closestWidgetToToolbar
[ 0 ] ) {
7364 * Handle window resize event.
7367 * @param {jQuery.Event} e Window resize event
7369 OO
.ui
.Toolbar
.prototype.onWindowResize = function () {
7370 this.$element
.toggleClass(
7371 'oo-ui-toolbar-narrow',
7372 this.$bar
.width() <= this.narrowThreshold
7377 * Sets up handles and preloads required information for the toolbar to work.
7378 * This must be called after it is attached to a visible document and before doing anything else.
7380 OO
.ui
.Toolbar
.prototype.initialize = function () {
7381 this.initialized
= true;
7382 this.narrowThreshold
= this.$group
.width() + this.$actions
.width();
7383 $( this.getElementWindow() ).on( 'resize', this.onWindowResizeHandler
);
7384 this.onWindowResize();
7388 * Set up the toolbar.
7390 * The toolbar is set up with a list of toolgroup configurations that specify the type of
7391 * toolgroup ({@link OO.ui.BarToolGroup bar}, {@link OO.ui.MenuToolGroup menu}, or {@link OO.ui.ListToolGroup list})
7392 * to add and which tools to include, exclude, promote, or demote within that toolgroup. Please
7393 * see {@link OO.ui.ToolGroup toolgroups} for more information about including tools in toolgroups.
7395 * @param {Object.<string,Array>} groups List of toolgroup configurations
7396 * @param {Array|string} [groups.include] Tools to include in the toolgroup
7397 * @param {Array|string} [groups.exclude] Tools to exclude from the toolgroup
7398 * @param {Array|string} [groups.promote] Tools to promote to the beginning of the toolgroup
7399 * @param {Array|string} [groups.demote] Tools to demote to the end of the toolgroup
7401 OO
.ui
.Toolbar
.prototype.setup = function ( groups
) {
7402 var i
, len
, type
, group
,
7404 defaultType
= 'bar';
7406 // Cleanup previous groups
7409 // Build out new groups
7410 for ( i
= 0, len
= groups
.length
; i
< len
; i
++ ) {
7411 group
= groups
[ i
];
7412 if ( group
.include
=== '*' ) {
7413 // Apply defaults to catch-all groups
7414 if ( group
.type
=== undefined ) {
7415 group
.type
= 'list';
7417 if ( group
.label
=== undefined ) {
7418 group
.label
= OO
.ui
.msg( 'ooui-toolbar-more' );
7421 // Check type has been registered
7422 type
= this.getToolGroupFactory().lookup( group
.type
) ? group
.type
: defaultType
;
7424 this.getToolGroupFactory().create( type
, this, group
)
7427 this.addItems( items
);
7431 * Remove all tools and toolgroups from the toolbar.
7433 OO
.ui
.Toolbar
.prototype.reset = function () {
7438 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
7439 this.items
[ i
].destroy();
7445 * Destroy the toolbar.
7447 * Destroying the toolbar removes all event handlers and DOM elements that constitute the toolbar. Call
7448 * this method whenever you are done using a toolbar.
7450 OO
.ui
.Toolbar
.prototype.destroy = function () {
7451 $( this.getElementWindow() ).off( 'resize', this.onWindowResizeHandler
);
7453 this.$element
.remove();
7457 * Check if the tool is available.
7459 * Available tools are ones that have not yet been added to the toolbar.
7461 * @param {string} name Symbolic name of tool
7462 * @return {boolean} Tool is available
7464 OO
.ui
.Toolbar
.prototype.isToolAvailable = function ( name
) {
7465 return !this.tools
[ name
];
7469 * Prevent tool from being used again.
7471 * @param {OO.ui.Tool} tool Tool to reserve
7473 OO
.ui
.Toolbar
.prototype.reserveTool = function ( tool
) {
7474 this.tools
[ tool
.getName() ] = tool
;
7478 * Allow tool to be used again.
7480 * @param {OO.ui.Tool} tool Tool to release
7482 OO
.ui
.Toolbar
.prototype.releaseTool = function ( tool
) {
7483 delete this.tools
[ tool
.getName() ];
7487 * Get accelerator label for tool.
7489 * The OOjs UI library does not contain an accelerator system, but this is the hook for one. To
7490 * use an accelerator system, subclass the toolbar and override this method, which is meant to return a label
7491 * that describes the accelerator keys for the tool passed (by symbolic name) to the method.
7493 * @param {string} name Symbolic name of tool
7494 * @return {string|undefined} Tool accelerator label if available
7496 OO
.ui
.Toolbar
.prototype.getToolAccelerator = function () {
7501 * ToolGroups are collections of {@link OO.ui.Tool tools} that are used in a {@link OO.ui.Toolbar toolbar}.
7502 * The type of toolgroup ({@link OO.ui.ListToolGroup list}, {@link OO.ui.BarToolGroup bar}, or {@link OO.ui.MenuToolGroup menu})
7503 * to which a tool belongs determines how the tool is arranged and displayed in the toolbar. Toolgroups
7504 * themselves are created on demand with a {@link OO.ui.ToolGroupFactory toolgroup factory}.
7506 * Toolgroups can contain individual tools, groups of tools, or all available tools:
7508 * To include an individual tool (or array of individual tools), specify tools by symbolic name:
7510 * include: [ 'tool-name' ] or [ { name: 'tool-name' }]
7512 * To include a group of tools, specify the group name. (The tool's static ‘group’ config is used to assign the tool to a group.)
7514 * include: [ { group: 'group-name' } ]
7516 * To include all tools that are not yet assigned to a toolgroup, use the catch-all selector, an asterisk (*):
7520 * See {@link OO.ui.Toolbar toolbars} for a full example. For more information about toolbars in general,
7521 * please see the [OOjs UI documentation on MediaWiki][1].
7523 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
7527 * @extends OO.ui.Widget
7528 * @mixins OO.ui.mixin.GroupElement
7531 * @param {OO.ui.Toolbar} toolbar
7532 * @param {Object} [config] Configuration options
7533 * @cfg {Array|string} [include=[]] List of tools to include in the toolgroup.
7534 * @cfg {Array|string} [exclude=[]] List of tools to exclude from the toolgroup.
7535 * @cfg {Array|string} [promote=[]] List of tools to promote to the beginning of the toolgroup.
7536 * @cfg {Array|string} [demote=[]] List of tools to demote to the end of the toolgroup.
7537 * This setting is particularly useful when tools have been added to the toolgroup
7538 * en masse (e.g., via the catch-all selector).
7540 OO
.ui
.ToolGroup
= function OoUiToolGroup( toolbar
, config
) {
7541 // Allow passing positional parameters inside the config object
7542 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
7544 toolbar
= config
.toolbar
;
7547 // Configuration initialization
7548 config
= config
|| {};
7550 // Parent constructor
7551 OO
.ui
.ToolGroup
.parent
.call( this, config
);
7553 // Mixin constructors
7554 OO
.ui
.mixin
.GroupElement
.call( this, config
);
7557 this.toolbar
= toolbar
;
7559 this.pressed
= null;
7560 this.autoDisabled
= false;
7561 this.include
= config
.include
|| [];
7562 this.exclude
= config
.exclude
|| [];
7563 this.promote
= config
.promote
|| [];
7564 this.demote
= config
.demote
|| [];
7565 this.onCapturedMouseKeyUpHandler
= this.onCapturedMouseKeyUp
.bind( this );
7569 mousedown
: this.onMouseKeyDown
.bind( this ),
7570 mouseup
: this.onMouseKeyUp
.bind( this ),
7571 keydown
: this.onMouseKeyDown
.bind( this ),
7572 keyup
: this.onMouseKeyUp
.bind( this ),
7573 focus
: this.onMouseOverFocus
.bind( this ),
7574 blur
: this.onMouseOutBlur
.bind( this ),
7575 mouseover
: this.onMouseOverFocus
.bind( this ),
7576 mouseout
: this.onMouseOutBlur
.bind( this )
7578 this.toolbar
.getToolFactory().connect( this, { register
: 'onToolFactoryRegister' } );
7579 this.aggregate( { disable
: 'itemDisable' } );
7580 this.connect( this, { itemDisable
: 'updateDisabled' } );
7583 this.$group
.addClass( 'oo-ui-toolGroup-tools' );
7585 .addClass( 'oo-ui-toolGroup' )
7586 .append( this.$group
);
7592 OO
.inheritClass( OO
.ui
.ToolGroup
, OO
.ui
.Widget
);
7593 OO
.mixinClass( OO
.ui
.ToolGroup
, OO
.ui
.mixin
.GroupElement
);
7601 /* Static Properties */
7604 * Show labels in tooltips.
7608 * @property {boolean}
7610 OO
.ui
.ToolGroup
.static.titleTooltips
= false;
7613 * Show acceleration labels in tooltips.
7615 * Note: The OOjs UI library does not include an accelerator system, but does contain
7616 * a hook for one. To use an accelerator system, subclass the {@link OO.ui.Toolbar toolbar} and
7617 * override the {@link OO.ui.Toolbar#getToolAccelerator getToolAccelerator} method, which is
7618 * meant to return a label that describes the accelerator keys for a given tool (e.g., 'Ctrl + M').
7622 * @property {boolean}
7624 OO
.ui
.ToolGroup
.static.accelTooltips
= false;
7627 * Automatically disable the toolgroup when all tools are disabled
7631 * @property {boolean}
7633 OO
.ui
.ToolGroup
.static.autoDisable
= true;
7640 OO
.ui
.ToolGroup
.prototype.isDisabled = function () {
7641 return this.autoDisabled
|| OO
.ui
.ToolGroup
.parent
.prototype.isDisabled
.apply( this, arguments
);
7647 OO
.ui
.ToolGroup
.prototype.updateDisabled = function () {
7648 var i
, item
, allDisabled
= true;
7650 if ( this.constructor.static.autoDisable
) {
7651 for ( i
= this.items
.length
- 1; i
>= 0; i
-- ) {
7652 item
= this.items
[ i
];
7653 if ( !item
.isDisabled() ) {
7654 allDisabled
= false;
7658 this.autoDisabled
= allDisabled
;
7660 OO
.ui
.ToolGroup
.parent
.prototype.updateDisabled
.apply( this, arguments
);
7664 * Handle mouse down and key down events.
7667 * @param {jQuery.Event} e Mouse down or key down event
7669 OO
.ui
.ToolGroup
.prototype.onMouseKeyDown = function ( e
) {
7671 !this.isDisabled() &&
7672 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
7674 this.pressed
= this.getTargetTool( e
);
7675 if ( this.pressed
) {
7676 this.pressed
.setActive( true );
7677 this.getElementDocument().addEventListener( 'mouseup', this.onCapturedMouseKeyUpHandler
, true );
7678 this.getElementDocument().addEventListener( 'keyup', this.onCapturedMouseKeyUpHandler
, true );
7685 * Handle captured mouse up and key up events.
7688 * @param {Event} e Mouse up or key up event
7690 OO
.ui
.ToolGroup
.prototype.onCapturedMouseKeyUp = function ( e
) {
7691 this.getElementDocument().removeEventListener( 'mouseup', this.onCapturedMouseKeyUpHandler
, true );
7692 this.getElementDocument().removeEventListener( 'keyup', this.onCapturedMouseKeyUpHandler
, true );
7693 // onMouseKeyUp may be called a second time, depending on where the mouse is when the button is
7694 // released, but since `this.pressed` will no longer be true, the second call will be ignored.
7695 this.onMouseKeyUp( e
);
7699 * Handle mouse up and key up events.
7702 * @param {jQuery.Event} e Mouse up or key up event
7704 OO
.ui
.ToolGroup
.prototype.onMouseKeyUp = function ( e
) {
7705 var tool
= this.getTargetTool( e
);
7708 !this.isDisabled() && this.pressed
&& this.pressed
=== tool
&&
7709 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
7711 this.pressed
.onSelect();
7712 this.pressed
= null;
7716 this.pressed
= null;
7720 * Handle mouse over and focus events.
7723 * @param {jQuery.Event} e Mouse over or focus event
7725 OO
.ui
.ToolGroup
.prototype.onMouseOverFocus = function ( e
) {
7726 var tool
= this.getTargetTool( e
);
7728 if ( this.pressed
&& this.pressed
=== tool
) {
7729 this.pressed
.setActive( true );
7734 * Handle mouse out and blur events.
7737 * @param {jQuery.Event} e Mouse out or blur event
7739 OO
.ui
.ToolGroup
.prototype.onMouseOutBlur = function ( e
) {
7740 var tool
= this.getTargetTool( e
);
7742 if ( this.pressed
&& this.pressed
=== tool
) {
7743 this.pressed
.setActive( false );
7748 * Get the closest tool to a jQuery.Event.
7750 * Only tool links are considered, which prevents other elements in the tool such as popups from
7751 * triggering tool group interactions.
7754 * @param {jQuery.Event} e
7755 * @return {OO.ui.Tool|null} Tool, `null` if none was found
7757 OO
.ui
.ToolGroup
.prototype.getTargetTool = function ( e
) {
7759 $item
= $( e
.target
).closest( '.oo-ui-tool-link' );
7761 if ( $item
.length
) {
7762 tool
= $item
.parent().data( 'oo-ui-tool' );
7765 return tool
&& !tool
.isDisabled() ? tool
: null;
7769 * Handle tool registry register events.
7771 * If a tool is registered after the group is created, we must repopulate the list to account for:
7773 * - a tool being added that may be included
7774 * - a tool already included being overridden
7777 * @param {string} name Symbolic name of tool
7779 OO
.ui
.ToolGroup
.prototype.onToolFactoryRegister = function () {
7784 * Get the toolbar that contains the toolgroup.
7786 * @return {OO.ui.Toolbar} Toolbar that contains the toolgroup
7788 OO
.ui
.ToolGroup
.prototype.getToolbar = function () {
7789 return this.toolbar
;
7793 * Add and remove tools based on configuration.
7795 OO
.ui
.ToolGroup
.prototype.populate = function () {
7796 var i
, len
, name
, tool
,
7797 toolFactory
= this.toolbar
.getToolFactory(),
7801 list
= this.toolbar
.getToolFactory().getTools(
7802 this.include
, this.exclude
, this.promote
, this.demote
7805 // Build a list of needed tools
7806 for ( i
= 0, len
= list
.length
; i
< len
; i
++ ) {
7810 toolFactory
.lookup( name
) &&
7811 // Tool is available or is already in this group
7812 ( this.toolbar
.isToolAvailable( name
) || this.tools
[ name
] )
7814 // Hack to prevent infinite recursion via ToolGroupTool. We need to reserve the tool before
7815 // creating it, but we can't call reserveTool() yet because we haven't created the tool.
7816 this.toolbar
.tools
[ name
] = true;
7817 tool
= this.tools
[ name
];
7819 // Auto-initialize tools on first use
7820 this.tools
[ name
] = tool
= toolFactory
.create( name
, this );
7823 this.toolbar
.reserveTool( tool
);
7825 names
[ name
] = true;
7828 // Remove tools that are no longer needed
7829 for ( name
in this.tools
) {
7830 if ( !names
[ name
] ) {
7831 this.tools
[ name
].destroy();
7832 this.toolbar
.releaseTool( this.tools
[ name
] );
7833 remove
.push( this.tools
[ name
] );
7834 delete this.tools
[ name
];
7837 if ( remove
.length
) {
7838 this.removeItems( remove
);
7840 // Update emptiness state
7842 this.$element
.removeClass( 'oo-ui-toolGroup-empty' );
7844 this.$element
.addClass( 'oo-ui-toolGroup-empty' );
7846 // Re-add tools (moving existing ones to new locations)
7847 this.addItems( add
);
7848 // Disabled state may depend on items
7849 this.updateDisabled();
7853 * Destroy toolgroup.
7855 OO
.ui
.ToolGroup
.prototype.destroy = function () {
7859 this.toolbar
.getToolFactory().disconnect( this );
7860 for ( name
in this.tools
) {
7861 this.toolbar
.releaseTool( this.tools
[ name
] );
7862 this.tools
[ name
].disconnect( this ).destroy();
7863 delete this.tools
[ name
];
7865 this.$element
.remove();
7869 * MessageDialogs display a confirmation or alert message. By default, the rendered dialog box
7870 * consists of a header that contains the dialog title, a body with the message, and a footer that
7871 * contains any {@link OO.ui.ActionWidget action widgets}. The MessageDialog class is the only type
7872 * of {@link OO.ui.Dialog dialog} that is usually instantiated directly.
7874 * There are two basic types of message dialogs, confirmation and alert:
7876 * - **confirmation**: the dialog title describes what a progressive action will do and the message provides
7877 * more details about the consequences.
7878 * - **alert**: the dialog title describes which event occurred and the message provides more information
7879 * about why the event occurred.
7881 * The MessageDialog class specifies two actions: ‘accept’, the primary
7882 * action (e.g., ‘ok’) and ‘reject,’ the safe action (e.g., ‘cancel’). Both will close the window,
7883 * passing along the selected action.
7885 * For more information and examples, please see the [OOjs UI documentation on MediaWiki][1].
7888 * // Example: Creating and opening a message dialog window.
7889 * var messageDialog = new OO.ui.MessageDialog();
7891 * // Create and append a window manager.
7892 * var windowManager = new OO.ui.WindowManager();
7893 * $( 'body' ).append( windowManager.$element );
7894 * windowManager.addWindows( [ messageDialog ] );
7895 * // Open the window.
7896 * windowManager.openWindow( messageDialog, {
7897 * title: 'Basic message dialog',
7898 * message: 'This is the message'
7901 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Message_Dialogs
7904 * @extends OO.ui.Dialog
7907 * @param {Object} [config] Configuration options
7909 OO
.ui
.MessageDialog
= function OoUiMessageDialog( config
) {
7910 // Parent constructor
7911 OO
.ui
.MessageDialog
.parent
.call( this, config
);
7914 this.verticalActionLayout
= null;
7917 this.$element
.addClass( 'oo-ui-messageDialog' );
7922 OO
.inheritClass( OO
.ui
.MessageDialog
, OO
.ui
.Dialog
);
7924 /* Static Properties */
7926 OO
.ui
.MessageDialog
.static.name
= 'message';
7928 OO
.ui
.MessageDialog
.static.size
= 'small';
7930 OO
.ui
.MessageDialog
.static.verbose
= false;
7935 * The title of a confirmation dialog describes what a progressive action will do. The
7936 * title of an alert dialog describes which event occurred.
7940 * @property {jQuery|string|Function|null}
7942 OO
.ui
.MessageDialog
.static.title
= null;
7945 * The message displayed in the dialog body.
7947 * A confirmation message describes the consequences of a progressive action. An alert
7948 * message describes why an event occurred.
7952 * @property {jQuery|string|Function|null}
7954 OO
.ui
.MessageDialog
.static.message
= null;
7956 OO
.ui
.MessageDialog
.static.actions
= [
7957 { action
: 'accept', label
: OO
.ui
.deferMsg( 'ooui-dialog-message-accept' ), flags
: 'primary' },
7958 { action
: 'reject', label
: OO
.ui
.deferMsg( 'ooui-dialog-message-reject' ), flags
: 'safe' }
7966 OO
.ui
.MessageDialog
.prototype.setManager = function ( manager
) {
7967 OO
.ui
.MessageDialog
.parent
.prototype.setManager
.call( this, manager
);
7970 this.manager
.connect( this, {
7980 OO
.ui
.MessageDialog
.prototype.onActionResize = function ( action
) {
7982 return OO
.ui
.MessageDialog
.parent
.prototype.onActionResize
.call( this, action
);
7986 * Handle window resized events.
7990 OO
.ui
.MessageDialog
.prototype.onResize = function () {
7992 dialog
.fitActions();
7993 // Wait for CSS transition to finish and do it again :(
7994 setTimeout( function () {
7995 dialog
.fitActions();
8000 * Toggle action layout between vertical and horizontal.
8004 * @param {boolean} [value] Layout actions vertically, omit to toggle
8007 OO
.ui
.MessageDialog
.prototype.toggleVerticalActionLayout = function ( value
) {
8008 value
= value
=== undefined ? !this.verticalActionLayout
: !!value
;
8010 if ( value
!== this.verticalActionLayout
) {
8011 this.verticalActionLayout
= value
;
8013 .toggleClass( 'oo-ui-messageDialog-actions-vertical', value
)
8014 .toggleClass( 'oo-ui-messageDialog-actions-horizontal', !value
);
8023 OO
.ui
.MessageDialog
.prototype.getActionProcess = function ( action
) {
8025 return new OO
.ui
.Process( function () {
8026 this.close( { action
: action
} );
8029 return OO
.ui
.MessageDialog
.parent
.prototype.getActionProcess
.call( this, action
);
8035 * @param {Object} [data] Dialog opening data
8036 * @param {jQuery|string|Function|null} [data.title] Description of the action being confirmed
8037 * @param {jQuery|string|Function|null} [data.message] Description of the action's consequence
8038 * @param {boolean} [data.verbose] Message is verbose and should be styled as a long message
8039 * @param {Object[]} [data.actions] List of OO.ui.ActionOptionWidget configuration options for each
8042 OO
.ui
.MessageDialog
.prototype.getSetupProcess = function ( data
) {
8046 return OO
.ui
.MessageDialog
.parent
.prototype.getSetupProcess
.call( this, data
)
8047 .next( function () {
8048 this.title
.setLabel(
8049 data
.title
!== undefined ? data
.title
: this.constructor.static.title
8051 this.message
.setLabel(
8052 data
.message
!== undefined ? data
.message
: this.constructor.static.message
8054 this.message
.$element
.toggleClass(
8055 'oo-ui-messageDialog-message-verbose',
8056 data
.verbose
!== undefined ? data
.verbose
: this.constructor.static.verbose
8064 OO
.ui
.MessageDialog
.prototype.getBodyHeight = function () {
8065 var bodyHeight
, oldOverflow
,
8066 $scrollable
= this.container
.$element
;
8068 oldOverflow
= $scrollable
[ 0 ].style
.overflow
;
8069 $scrollable
[ 0 ].style
.overflow
= 'hidden';
8071 OO
.ui
.Element
.static.reconsiderScrollbars( $scrollable
[ 0 ] );
8073 bodyHeight
= this.text
.$element
.outerHeight( true );
8074 $scrollable
[ 0 ].style
.overflow
= oldOverflow
;
8082 OO
.ui
.MessageDialog
.prototype.setDimensions = function ( dim
) {
8083 var $scrollable
= this.container
.$element
;
8084 OO
.ui
.MessageDialog
.parent
.prototype.setDimensions
.call( this, dim
);
8086 // Twiddle the overflow property, otherwise an unnecessary scrollbar will be produced.
8087 // Need to do it after transition completes (250ms), add 50ms just in case.
8088 setTimeout( function () {
8089 var oldOverflow
= $scrollable
[ 0 ].style
.overflow
;
8090 $scrollable
[ 0 ].style
.overflow
= 'hidden';
8092 OO
.ui
.Element
.static.reconsiderScrollbars( $scrollable
[ 0 ] );
8094 $scrollable
[ 0 ].style
.overflow
= oldOverflow
;
8103 OO
.ui
.MessageDialog
.prototype.initialize = function () {
8105 OO
.ui
.MessageDialog
.parent
.prototype.initialize
.call( this );
8108 this.$actions
= $( '<div>' );
8109 this.container
= new OO
.ui
.PanelLayout( {
8110 scrollable
: true, classes
: [ 'oo-ui-messageDialog-container' ]
8112 this.text
= new OO
.ui
.PanelLayout( {
8113 padded
: true, expanded
: false, classes
: [ 'oo-ui-messageDialog-text' ]
8115 this.message
= new OO
.ui
.LabelWidget( {
8116 classes
: [ 'oo-ui-messageDialog-message' ]
8120 this.title
.$element
.addClass( 'oo-ui-messageDialog-title' );
8121 this.$content
.addClass( 'oo-ui-messageDialog-content' );
8122 this.container
.$element
.append( this.text
.$element
);
8123 this.text
.$element
.append( this.title
.$element
, this.message
.$element
);
8124 this.$body
.append( this.container
.$element
);
8125 this.$actions
.addClass( 'oo-ui-messageDialog-actions' );
8126 this.$foot
.append( this.$actions
);
8132 OO
.ui
.MessageDialog
.prototype.attachActions = function () {
8133 var i
, len
, other
, special
, others
;
8136 OO
.ui
.MessageDialog
.parent
.prototype.attachActions
.call( this );
8138 special
= this.actions
.getSpecial();
8139 others
= this.actions
.getOthers();
8140 if ( special
.safe
) {
8141 this.$actions
.append( special
.safe
.$element
);
8142 special
.safe
.toggleFramed( false );
8144 if ( others
.length
) {
8145 for ( i
= 0, len
= others
.length
; i
< len
; i
++ ) {
8146 other
= others
[ i
];
8147 this.$actions
.append( other
.$element
);
8148 other
.toggleFramed( false );
8151 if ( special
.primary
) {
8152 this.$actions
.append( special
.primary
.$element
);
8153 special
.primary
.toggleFramed( false );
8156 if ( !this.isOpening() ) {
8157 // If the dialog is currently opening, this will be called automatically soon.
8158 // This also calls #fitActions.
8164 * Fit action actions into columns or rows.
8166 * Columns will be used if all labels can fit without overflow, otherwise rows will be used.
8170 OO
.ui
.MessageDialog
.prototype.fitActions = function () {
8172 previous
= this.verticalActionLayout
,
8173 actions
= this.actions
.get();
8176 this.toggleVerticalActionLayout( false );
8177 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
8178 action
= actions
[ i
];
8179 if ( action
.$element
.innerWidth() < action
.$label
.outerWidth( true ) ) {
8180 this.toggleVerticalActionLayout( true );
8185 // Move the body out of the way of the foot
8186 this.$body
.css( 'bottom', this.$foot
.outerHeight( true ) );
8188 if ( this.verticalActionLayout
!== previous
) {
8189 // We changed the layout, window height might need to be updated.
8195 * ProcessDialog windows encapsulate a {@link OO.ui.Process process} and all of the code necessary
8196 * to complete it. If the process terminates with an error, a customizable {@link OO.ui.Error error
8197 * interface} alerts users to the trouble, permitting the user to dismiss the error and try again when
8198 * relevant. The ProcessDialog class is always extended and customized with the actions and content
8199 * required for each process.
8201 * The process dialog box consists of a header that visually represents the ‘working’ state of long
8202 * processes with an animation. The header contains the dialog title as well as
8203 * two {@link OO.ui.ActionWidget action widgets}: a ‘safe’ action on the left (e.g., ‘Cancel’) and
8204 * a ‘primary’ action on the right (e.g., ‘Done’).
8206 * Like other windows, the process dialog is managed by a {@link OO.ui.WindowManager window manager}.
8207 * Please see the [OOjs UI documentation on MediaWiki][1] for more information and examples.
8210 * // Example: Creating and opening a process dialog window.
8211 * function MyProcessDialog( config ) {
8212 * MyProcessDialog.parent.call( this, config );
8214 * OO.inheritClass( MyProcessDialog, OO.ui.ProcessDialog );
8216 * MyProcessDialog.static.title = 'Process dialog';
8217 * MyProcessDialog.static.actions = [
8218 * { action: 'save', label: 'Done', flags: 'primary' },
8219 * { label: 'Cancel', flags: 'safe' }
8222 * MyProcessDialog.prototype.initialize = function () {
8223 * MyProcessDialog.parent.prototype.initialize.apply( this, arguments );
8224 * this.content = new OO.ui.PanelLayout( { padded: true, expanded: false } );
8225 * this.content.$element.append( '<p>This is a process dialog window. The header contains the title and two buttons: \'Cancel\' (a safe action) on the left and \'Done\' (a primary action) on the right.</p>' );
8226 * this.$body.append( this.content.$element );
8228 * MyProcessDialog.prototype.getActionProcess = function ( action ) {
8229 * var dialog = this;
8231 * return new OO.ui.Process( function () {
8232 * dialog.close( { action: action } );
8235 * return MyProcessDialog.parent.prototype.getActionProcess.call( this, action );
8238 * var windowManager = new OO.ui.WindowManager();
8239 * $( 'body' ).append( windowManager.$element );
8241 * var dialog = new MyProcessDialog();
8242 * windowManager.addWindows( [ dialog ] );
8243 * windowManager.openWindow( dialog );
8245 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs
8249 * @extends OO.ui.Dialog
8252 * @param {Object} [config] Configuration options
8254 OO
.ui
.ProcessDialog
= function OoUiProcessDialog( config
) {
8255 // Parent constructor
8256 OO
.ui
.ProcessDialog
.parent
.call( this, config
);
8259 this.fitOnOpen
= false;
8262 this.$element
.addClass( 'oo-ui-processDialog' );
8267 OO
.inheritClass( OO
.ui
.ProcessDialog
, OO
.ui
.Dialog
);
8272 * Handle dismiss button click events.
8278 OO
.ui
.ProcessDialog
.prototype.onDismissErrorButtonClick = function () {
8283 * Handle retry button click events.
8285 * Hides errors and then tries again.
8289 OO
.ui
.ProcessDialog
.prototype.onRetryButtonClick = function () {
8291 this.executeAction( this.currentAction
);
8297 OO
.ui
.ProcessDialog
.prototype.onActionResize = function ( action
) {
8298 if ( this.actions
.isSpecial( action
) ) {
8301 return OO
.ui
.ProcessDialog
.parent
.prototype.onActionResize
.call( this, action
);
8307 OO
.ui
.ProcessDialog
.prototype.initialize = function () {
8309 OO
.ui
.ProcessDialog
.parent
.prototype.initialize
.call( this );
8312 this.$navigation
= $( '<div>' );
8313 this.$location
= $( '<div>' );
8314 this.$safeActions
= $( '<div>' );
8315 this.$primaryActions
= $( '<div>' );
8316 this.$otherActions
= $( '<div>' );
8317 this.dismissButton
= new OO
.ui
.ButtonWidget( {
8318 label
: OO
.ui
.msg( 'ooui-dialog-process-dismiss' )
8320 this.retryButton
= new OO
.ui
.ButtonWidget();
8321 this.$errors
= $( '<div>' );
8322 this.$errorsTitle
= $( '<div>' );
8325 this.dismissButton
.connect( this, { click
: 'onDismissErrorButtonClick' } );
8326 this.retryButton
.connect( this, { click
: 'onRetryButtonClick' } );
8329 this.title
.$element
.addClass( 'oo-ui-processDialog-title' );
8331 .append( this.title
.$element
)
8332 .addClass( 'oo-ui-processDialog-location' );
8333 this.$safeActions
.addClass( 'oo-ui-processDialog-actions-safe' );
8334 this.$primaryActions
.addClass( 'oo-ui-processDialog-actions-primary' );
8335 this.$otherActions
.addClass( 'oo-ui-processDialog-actions-other' );
8337 .addClass( 'oo-ui-processDialog-errors-title' )
8338 .text( OO
.ui
.msg( 'ooui-dialog-process-error' ) );
8340 .addClass( 'oo-ui-processDialog-errors oo-ui-element-hidden' )
8341 .append( this.$errorsTitle
, this.dismissButton
.$element
, this.retryButton
.$element
);
8343 .addClass( 'oo-ui-processDialog-content' )
8344 .append( this.$errors
);
8346 .addClass( 'oo-ui-processDialog-navigation' )
8347 .append( this.$safeActions
, this.$location
, this.$primaryActions
);
8348 this.$head
.append( this.$navigation
);
8349 this.$foot
.append( this.$otherActions
);
8355 OO
.ui
.ProcessDialog
.prototype.getActionWidgets = function ( actions
) {
8356 var i
, len
, widgets
= [];
8357 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
8359 new OO
.ui
.ActionWidget( $.extend( { framed
: true }, actions
[ i
] ) )
8368 OO
.ui
.ProcessDialog
.prototype.attachActions = function () {
8369 var i
, len
, other
, special
, others
;
8372 OO
.ui
.ProcessDialog
.parent
.prototype.attachActions
.call( this );
8374 special
= this.actions
.getSpecial();
8375 others
= this.actions
.getOthers();
8376 if ( special
.primary
) {
8377 this.$primaryActions
.append( special
.primary
.$element
);
8379 for ( i
= 0, len
= others
.length
; i
< len
; i
++ ) {
8380 other
= others
[ i
];
8381 this.$otherActions
.append( other
.$element
);
8383 if ( special
.safe
) {
8384 this.$safeActions
.append( special
.safe
.$element
);
8388 this.$body
.css( 'bottom', this.$foot
.outerHeight( true ) );
8394 OO
.ui
.ProcessDialog
.prototype.executeAction = function ( action
) {
8396 return OO
.ui
.ProcessDialog
.parent
.prototype.executeAction
.call( this, action
)
8397 .fail( function ( errors
) {
8398 process
.showErrors( errors
|| [] );
8405 OO
.ui
.ProcessDialog
.prototype.setDimensions = function () {
8407 OO
.ui
.ProcessDialog
.parent
.prototype.setDimensions
.apply( this, arguments
);
8413 * Fit label between actions.
8418 OO
.ui
.ProcessDialog
.prototype.fitLabel = function () {
8419 var safeWidth
, primaryWidth
, biggerWidth
, labelWidth
, navigationWidth
, leftWidth
, rightWidth
,
8420 size
= this.getSizeProperties();
8422 if ( typeof size
.width
!== 'number' ) {
8423 if ( this.isOpened() ) {
8424 navigationWidth
= this.$head
.width() - 20;
8425 } else if ( this.isOpening() ) {
8426 if ( !this.fitOnOpen
) {
8427 // Size is relative and the dialog isn't open yet, so wait.
8428 this.manager
.opening
.done( this.fitLabel
.bind( this ) );
8429 this.fitOnOpen
= true;
8436 navigationWidth
= size
.width
- 20;
8439 safeWidth
= this.$safeActions
.is( ':visible' ) ? this.$safeActions
.width() : 0;
8440 primaryWidth
= this.$primaryActions
.is( ':visible' ) ? this.$primaryActions
.width() : 0;
8441 biggerWidth
= Math
.max( safeWidth
, primaryWidth
);
8443 labelWidth
= this.title
.$element
.width();
8445 if ( 2 * biggerWidth
+ labelWidth
< navigationWidth
) {
8446 // We have enough space to center the label
8447 leftWidth
= rightWidth
= biggerWidth
;
8449 // Let's hope we at least have enough space not to overlap, because we can't wrap the label…
8450 if ( this.getDir() === 'ltr' ) {
8451 leftWidth
= safeWidth
;
8452 rightWidth
= primaryWidth
;
8454 leftWidth
= primaryWidth
;
8455 rightWidth
= safeWidth
;
8459 this.$location
.css( { paddingLeft
: leftWidth
, paddingRight
: rightWidth
} );
8465 * Handle errors that occurred during accept or reject processes.
8468 * @param {OO.ui.Error[]|OO.ui.Error} errors Errors to be handled
8470 OO
.ui
.ProcessDialog
.prototype.showErrors = function ( errors
) {
8471 var i
, len
, $item
, actions
,
8477 if ( errors
instanceof OO
.ui
.Error
) {
8478 errors
= [ errors
];
8481 for ( i
= 0, len
= errors
.length
; i
< len
; i
++ ) {
8482 if ( !errors
[ i
].isRecoverable() ) {
8483 recoverable
= false;
8485 if ( errors
[ i
].isWarning() ) {
8488 $item
= $( '<div>' )
8489 .addClass( 'oo-ui-processDialog-error' )
8490 .append( errors
[ i
].getMessage() );
8491 items
.push( $item
[ 0 ] );
8493 this.$errorItems
= $( items
);
8494 if ( recoverable
) {
8495 abilities
[this.currentAction
] = true;
8496 // Copy the flags from the first matching action
8497 actions
= this.actions
.get( { actions
: this.currentAction
} );
8498 if ( actions
.length
) {
8499 this.retryButton
.clearFlags().setFlags( actions
[0].getFlags() );
8502 abilities
[this.currentAction
] = false;
8503 this.actions
.setAbilities( abilities
);
8506 this.retryButton
.setLabel( OO
.ui
.msg( 'ooui-dialog-process-continue' ) );
8508 this.retryButton
.setLabel( OO
.ui
.msg( 'ooui-dialog-process-retry' ) );
8510 this.retryButton
.toggle( recoverable
);
8511 this.$errorsTitle
.after( this.$errorItems
);
8512 this.$errors
.removeClass( 'oo-ui-element-hidden' ).scrollTop( 0 );
8520 OO
.ui
.ProcessDialog
.prototype.hideErrors = function () {
8521 this.$errors
.addClass( 'oo-ui-element-hidden' );
8522 if ( this.$errorItems
) {
8523 this.$errorItems
.remove();
8524 this.$errorItems
= null;
8531 OO
.ui
.ProcessDialog
.prototype.getTeardownProcess = function ( data
) {
8533 return OO
.ui
.ProcessDialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
8534 .first( function () {
8535 // Make sure to hide errors
8537 this.fitOnOpen
= false;
8542 * FieldLayouts are used with OO.ui.FieldsetLayout. Each FieldLayout requires a field-widget,
8543 * which is a widget that is specified by reference before any optional configuration settings.
8545 * Field layouts can be configured with help text and/or labels. Labels are aligned in one of four ways:
8547 * - **left**: The label is placed before the field-widget and aligned with the left margin.
8548 * A left-alignment is used for forms with many fields.
8549 * - **right**: The label is placed before the field-widget and aligned to the right margin.
8550 * A right-alignment is used for long but familiar forms which users tab through,
8551 * verifying the current field with a quick glance at the label.
8552 * - **top**: The label is placed above the field-widget. A top-alignment is used for brief forms
8553 * that users fill out from top to bottom.
8554 * - **inline**: The label is placed after the field-widget and aligned to the left.
8555 * An inline-alignment is best used with checkboxes or radio buttons.
8557 * Help text is accessed via a help icon that appears in the upper right corner of the rendered field layout.
8558 * Please see the [OOjs UI documentation on MediaWiki] [1] for examples and more information.
8560 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Layouts/Fields_and_Fieldsets
8562 * @extends OO.ui.Layout
8563 * @mixins OO.ui.mixin.LabelElement
8564 * @mixins OO.ui.mixin.TitledElement
8567 * @param {OO.ui.Widget} fieldWidget Field widget
8568 * @param {Object} [config] Configuration options
8569 * @cfg {string} [align='left'] Alignment of the label: 'left', 'right', 'top' or 'inline'
8570 * @cfg {Array} [errors] Error messages about the widget, which will be displayed below the widget.
8571 * The array may contain strings or OO.ui.HtmlSnippet instances.
8572 * @cfg {Array} [notices] Notices about the widget, which will be displayed below the widget.
8573 * The array may contain strings or OO.ui.HtmlSnippet instances.
8574 * @cfg {string|OO.ui.HtmlSnippet} [help] Help text. When help text is specified, a "help" icon will appear
8575 * in the upper-right corner of the rendered field; clicking it will display the text in a popup.
8576 * For important messages, you are advised to use `notices`, as they are always shown.
8578 OO
.ui
.FieldLayout
= function OoUiFieldLayout( fieldWidget
, config
) {
8579 // Allow passing positional parameters inside the config object
8580 if ( OO
.isPlainObject( fieldWidget
) && config
=== undefined ) {
8581 config
= fieldWidget
;
8582 fieldWidget
= config
.fieldWidget
;
8585 var hasInputWidget
= fieldWidget
.constructor.static.supportsSimpleLabel
,
8588 // Configuration initialization
8589 config
= $.extend( { align
: 'left' }, config
);
8591 // Parent constructor
8592 OO
.ui
.FieldLayout
.parent
.call( this, config
);
8594 // Mixin constructors
8595 OO
.ui
.mixin
.LabelElement
.call( this, config
);
8596 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$label
} ) );
8599 this.fieldWidget
= fieldWidget
;
8600 this.errors
= config
.errors
|| [];
8601 this.notices
= config
.notices
|| [];
8602 this.$field
= $( '<div>' );
8603 this.$messages
= $( '<ul>' );
8604 this.$body
= $( '<' + ( hasInputWidget
? 'label' : 'div' ) + '>' );
8606 if ( config
.help
) {
8607 this.popupButtonWidget
= new OO
.ui
.PopupButtonWidget( {
8608 classes
: [ 'oo-ui-fieldLayout-help' ],
8614 if ( config
.help
instanceof OO
.ui
.HtmlSnippet
) {
8615 div
.html( config
.help
.toString() );
8617 div
.text( config
.help
);
8619 this.popupButtonWidget
.getPopup().$body
.append(
8620 div
.addClass( 'oo-ui-fieldLayout-help-content' )
8622 this.$help
= this.popupButtonWidget
.$element
;
8624 this.$help
= $( [] );
8628 if ( hasInputWidget
) {
8629 this.$label
.on( 'click', this.onLabelClick
.bind( this ) );
8631 this.fieldWidget
.connect( this, { disable
: 'onFieldDisable' } );
8635 .addClass( 'oo-ui-fieldLayout' )
8636 .append( this.$help
, this.$body
);
8637 if ( this.errors
.length
|| this.notices
.length
) {
8638 this.$element
.append( this.$messages
);
8640 this.$body
.addClass( 'oo-ui-fieldLayout-body' );
8641 this.$messages
.addClass( 'oo-ui-fieldLayout-messages' );
8643 .addClass( 'oo-ui-fieldLayout-field' )
8644 .toggleClass( 'oo-ui-fieldLayout-disable', this.fieldWidget
.isDisabled() )
8645 .append( this.fieldWidget
.$element
);
8647 for ( i
= 0; i
< this.notices
.length
; i
++ ) {
8648 this.$messages
.append( this.makeMessage( 'notice', this.notices
[i
] ) );
8650 for ( i
= 0; i
< this.errors
.length
; i
++ ) {
8651 this.$messages
.append( this.makeMessage( 'error', this.errors
[i
] ) );
8654 this.setAlignment( config
.align
);
8659 OO
.inheritClass( OO
.ui
.FieldLayout
, OO
.ui
.Layout
);
8660 OO
.mixinClass( OO
.ui
.FieldLayout
, OO
.ui
.mixin
.LabelElement
);
8661 OO
.mixinClass( OO
.ui
.FieldLayout
, OO
.ui
.mixin
.TitledElement
);
8666 * Handle field disable events.
8669 * @param {boolean} value Field is disabled
8671 OO
.ui
.FieldLayout
.prototype.onFieldDisable = function ( value
) {
8672 this.$element
.toggleClass( 'oo-ui-fieldLayout-disabled', value
);
8676 * Handle label mouse click events.
8679 * @param {jQuery.Event} e Mouse click event
8681 OO
.ui
.FieldLayout
.prototype.onLabelClick = function () {
8682 this.fieldWidget
.simulateLabelClick();
8687 * Get the widget contained by the field.
8689 * @return {OO.ui.Widget} Field widget
8691 OO
.ui
.FieldLayout
.prototype.getField = function () {
8692 return this.fieldWidget
;
8696 * @param {string} kind 'error' or 'notice'
8697 * @param {string|OO.ui.HtmlSnippet} text
8700 OO
.ui
.FieldLayout
.prototype.makeMessage = function ( kind
, text
) {
8701 var $listItem
, $icon
, message
;
8702 $listItem
= $( '<li>' );
8703 if ( kind
=== 'error' ) {
8704 $icon
= new OO
.ui
.IconWidget( { icon
: 'alert', flags
: [ 'warning' ] } ).$element
;
8705 } else if ( kind
=== 'notice' ) {
8706 $icon
= new OO
.ui
.IconWidget( { icon
: 'info' } ).$element
;
8710 message
= new OO
.ui
.LabelWidget( { label
: text
} );
8712 .append( $icon
, message
.$element
)
8713 .addClass( 'oo-ui-fieldLayout-messages-' + kind
);
8718 * Set the field alignment mode.
8721 * @param {string} value Alignment mode, either 'left', 'right', 'top' or 'inline'
8724 OO
.ui
.FieldLayout
.prototype.setAlignment = function ( value
) {
8725 if ( value
!== this.align
) {
8726 // Default to 'left'
8727 if ( [ 'left', 'right', 'top', 'inline' ].indexOf( value
) === -1 ) {
8731 if ( value
=== 'inline' ) {
8732 this.$body
.append( this.$field
, this.$label
);
8734 this.$body
.append( this.$label
, this.$field
);
8736 // Set classes. The following classes can be used here:
8737 // * oo-ui-fieldLayout-align-left
8738 // * oo-ui-fieldLayout-align-right
8739 // * oo-ui-fieldLayout-align-top
8740 // * oo-ui-fieldLayout-align-inline
8742 this.$element
.removeClass( 'oo-ui-fieldLayout-align-' + this.align
);
8744 this.$element
.addClass( 'oo-ui-fieldLayout-align-' + value
);
8752 * ActionFieldLayouts are used with OO.ui.FieldsetLayout. The layout consists of a field-widget, a button,
8753 * and an optional label and/or help text. The field-widget (e.g., a {@link OO.ui.TextInputWidget TextInputWidget}),
8754 * is required and is specified before any optional configuration settings.
8756 * Labels can be aligned in one of four ways:
8758 * - **left**: The label is placed before the field-widget and aligned with the left margin.
8759 * A left-alignment is used for forms with many fields.
8760 * - **right**: The label is placed before the field-widget and aligned to the right margin.
8761 * A right-alignment is used for long but familiar forms which users tab through,
8762 * verifying the current field with a quick glance at the label.
8763 * - **top**: The label is placed above the field-widget. A top-alignment is used for brief forms
8764 * that users fill out from top to bottom.
8765 * - **inline**: The label is placed after the field-widget and aligned to the left.
8766 * An inline-alignment is best used with checkboxes or radio buttons.
8768 * Help text is accessed via a help icon that appears in the upper right corner of the rendered field layout when help
8769 * text is specified.
8772 * // Example of an ActionFieldLayout
8773 * var actionFieldLayout = new OO.ui.ActionFieldLayout(
8774 * new OO.ui.TextInputWidget( {
8775 * placeholder: 'Field widget'
8777 * new OO.ui.ButtonWidget( {
8781 * label: 'An ActionFieldLayout. This label is aligned top',
8783 * help: 'This is help text'
8787 * $( 'body' ).append( actionFieldLayout.$element );
8791 * @extends OO.ui.FieldLayout
8794 * @param {OO.ui.Widget} fieldWidget Field widget
8795 * @param {OO.ui.ButtonWidget} buttonWidget Button widget
8797 OO
.ui
.ActionFieldLayout
= function OoUiActionFieldLayout( fieldWidget
, buttonWidget
, config
) {
8798 // Allow passing positional parameters inside the config object
8799 if ( OO
.isPlainObject( fieldWidget
) && config
=== undefined ) {
8800 config
= fieldWidget
;
8801 fieldWidget
= config
.fieldWidget
;
8802 buttonWidget
= config
.buttonWidget
;
8805 // Parent constructor
8806 OO
.ui
.ActionFieldLayout
.parent
.call( this, fieldWidget
, config
);
8809 this.buttonWidget
= buttonWidget
;
8810 this.$button
= $( '<div>' );
8811 this.$input
= $( '<div>' );
8815 .addClass( 'oo-ui-actionFieldLayout' );
8817 .addClass( 'oo-ui-actionFieldLayout-button' )
8818 .append( this.buttonWidget
.$element
);
8820 .addClass( 'oo-ui-actionFieldLayout-input' )
8821 .append( this.fieldWidget
.$element
);
8823 .append( this.$input
, this.$button
);
8828 OO
.inheritClass( OO
.ui
.ActionFieldLayout
, OO
.ui
.FieldLayout
);
8831 * FieldsetLayouts are composed of one or more {@link OO.ui.FieldLayout FieldLayouts},
8832 * which each contain an individual widget and, optionally, a label. Each Fieldset can be
8833 * configured with a label as well. For more information and examples,
8834 * please see the [OOjs UI documentation on MediaWiki][1].
8837 * // Example of a fieldset layout
8838 * var input1 = new OO.ui.TextInputWidget( {
8839 * placeholder: 'A text input field'
8842 * var input2 = new OO.ui.TextInputWidget( {
8843 * placeholder: 'A text input field'
8846 * var fieldset = new OO.ui.FieldsetLayout( {
8847 * label: 'Example of a fieldset layout'
8850 * fieldset.addItems( [
8851 * new OO.ui.FieldLayout( input1, {
8852 * label: 'Field One'
8854 * new OO.ui.FieldLayout( input2, {
8855 * label: 'Field Two'
8858 * $( 'body' ).append( fieldset.$element );
8860 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Layouts/Fields_and_Fieldsets
8863 * @extends OO.ui.Layout
8864 * @mixins OO.ui.mixin.IconElement
8865 * @mixins OO.ui.mixin.LabelElement
8866 * @mixins OO.ui.mixin.GroupElement
8869 * @param {Object} [config] Configuration options
8870 * @cfg {OO.ui.FieldLayout[]} [items] An array of fields to add to the fieldset. See OO.ui.FieldLayout for more information about fields.
8872 OO
.ui
.FieldsetLayout
= function OoUiFieldsetLayout( config
) {
8873 // Configuration initialization
8874 config
= config
|| {};
8876 // Parent constructor
8877 OO
.ui
.FieldsetLayout
.parent
.call( this, config
);
8879 // Mixin constructors
8880 OO
.ui
.mixin
.IconElement
.call( this, config
);
8881 OO
.ui
.mixin
.LabelElement
.call( this, config
);
8882 OO
.ui
.mixin
.GroupElement
.call( this, config
);
8884 if ( config
.help
) {
8885 this.popupButtonWidget
= new OO
.ui
.PopupButtonWidget( {
8886 classes
: [ 'oo-ui-fieldsetLayout-help' ],
8891 this.popupButtonWidget
.getPopup().$body
.append(
8893 .text( config
.help
)
8894 .addClass( 'oo-ui-fieldsetLayout-help-content' )
8896 this.$help
= this.popupButtonWidget
.$element
;
8898 this.$help
= $( [] );
8903 .addClass( 'oo-ui-fieldsetLayout' )
8904 .prepend( this.$help
, this.$icon
, this.$label
, this.$group
);
8905 if ( Array
.isArray( config
.items
) ) {
8906 this.addItems( config
.items
);
8912 OO
.inheritClass( OO
.ui
.FieldsetLayout
, OO
.ui
.Layout
);
8913 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.mixin
.IconElement
);
8914 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.mixin
.LabelElement
);
8915 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.mixin
.GroupElement
);
8918 * FormLayouts are used to wrap {@link OO.ui.FieldsetLayout FieldsetLayouts} when you intend to use browser-based
8919 * form submission for the fields instead of handling them in JavaScript. Form layouts can be configured with an
8920 * HTML form action, an encoding type, and a method using the #action, #enctype, and #method configs, respectively.
8921 * See the [OOjs UI documentation on MediaWiki] [1] for more information and examples.
8923 * Only widgets from the {@link OO.ui.InputWidget InputWidget} family support form submission. It
8924 * includes standard form elements like {@link OO.ui.CheckboxInputWidget checkboxes}, {@link
8925 * OO.ui.RadioInputWidget radio buttons} and {@link OO.ui.TextInputWidget text fields}, as well as
8926 * some fancier controls. Some controls have both regular and InputWidget variants, for example
8927 * OO.ui.DropdownWidget and OO.ui.DropdownInputWidget – only the latter support form submission and
8928 * often have simplified APIs to match the capabilities of HTML forms.
8929 * See the [OOjs UI Inputs documentation on MediaWiki] [2] for more information about InputWidgets.
8931 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Layouts/Forms
8932 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
8935 * // Example of a form layout that wraps a fieldset layout
8936 * var input1 = new OO.ui.TextInputWidget( {
8937 * placeholder: 'Username'
8939 * var input2 = new OO.ui.TextInputWidget( {
8940 * placeholder: 'Password',
8943 * var submit = new OO.ui.ButtonInputWidget( {
8947 * var fieldset = new OO.ui.FieldsetLayout( {
8948 * label: 'A form layout'
8950 * fieldset.addItems( [
8951 * new OO.ui.FieldLayout( input1, {
8952 * label: 'Username',
8955 * new OO.ui.FieldLayout( input2, {
8956 * label: 'Password',
8959 * new OO.ui.FieldLayout( submit )
8961 * var form = new OO.ui.FormLayout( {
8962 * items: [ fieldset ],
8963 * action: '/api/formhandler',
8966 * $( 'body' ).append( form.$element );
8969 * @extends OO.ui.Layout
8970 * @mixins OO.ui.mixin.GroupElement
8973 * @param {Object} [config] Configuration options
8974 * @cfg {string} [method] HTML form `method` attribute
8975 * @cfg {string} [action] HTML form `action` attribute
8976 * @cfg {string} [enctype] HTML form `enctype` attribute
8977 * @cfg {OO.ui.FieldsetLayout[]} [items] Fieldset layouts to add to the form layout.
8979 OO
.ui
.FormLayout
= function OoUiFormLayout( config
) {
8980 // Configuration initialization
8981 config
= config
|| {};
8983 // Parent constructor
8984 OO
.ui
.FormLayout
.parent
.call( this, config
);
8986 // Mixin constructors
8987 OO
.ui
.mixin
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
8990 this.$element
.on( 'submit', this.onFormSubmit
.bind( this ) );
8992 // Make sure the action is safe
8993 if ( config
.action
!== undefined && !OO
.ui
.isSafeUrl( config
.action
) ) {
8994 throw new Error( 'Potentially unsafe action provided: ' + config
.action
);
8999 .addClass( 'oo-ui-formLayout' )
9001 method
: config
.method
,
9002 action
: config
.action
,
9003 enctype
: config
.enctype
9005 if ( Array
.isArray( config
.items
) ) {
9006 this.addItems( config
.items
);
9012 OO
.inheritClass( OO
.ui
.FormLayout
, OO
.ui
.Layout
);
9013 OO
.mixinClass( OO
.ui
.FormLayout
, OO
.ui
.mixin
.GroupElement
);
9018 * A 'submit' event is emitted when the form is submitted.
9023 /* Static Properties */
9025 OO
.ui
.FormLayout
.static.tagName
= 'form';
9030 * Handle form submit events.
9033 * @param {jQuery.Event} e Submit event
9036 OO
.ui
.FormLayout
.prototype.onFormSubmit = function () {
9037 if ( this.emit( 'submit' ) ) {
9043 * MenuLayouts combine a menu and a content {@link OO.ui.PanelLayout panel}. The menu is positioned relative to the content (after, before, top, or bottom)
9044 * and its size is customized with the #menuSize config. The content area will fill all remaining space.
9047 * var menuLayout = new OO.ui.MenuLayout( {
9050 * menuPanel = new OO.ui.PanelLayout( { padded: true, expanded: true, scrollable: true } ),
9051 * contentPanel = new OO.ui.PanelLayout( { padded: true, expanded: true, scrollable: true } ),
9052 * select = new OO.ui.SelectWidget( {
9054 * new OO.ui.OptionWidget( {
9058 * new OO.ui.OptionWidget( {
9062 * new OO.ui.OptionWidget( {
9066 * new OO.ui.OptionWidget( {
9071 * } ).on( 'select', function ( item ) {
9072 * menuLayout.setMenuPosition( item.getData() );
9075 * menuLayout.$menu.append(
9076 * menuPanel.$element.append( '<b>Menu panel</b>', select.$element )
9078 * menuLayout.$content.append(
9079 * contentPanel.$element.append( '<b>Content panel</b>', '<p>Note that the menu is positioned relative to the content panel: top, bottom, after, before.</p>')
9081 * $( 'body' ).append( menuLayout.$element );
9083 * If menu size needs to be overridden, it can be accomplished using CSS similar to the snippet
9084 * below. MenuLayout's CSS will override the appropriate values with 'auto' or '0' to display the
9085 * menu correctly. If `menuPosition` is known beforehand, CSS rules corresponding to other positions
9088 * .oo-ui-menuLayout-menu {
9092 * .oo-ui-menuLayout-content {
9100 * @extends OO.ui.Layout
9103 * @param {Object} [config] Configuration options
9104 * @cfg {boolean} [showMenu=true] Show menu
9105 * @cfg {string} [menuPosition='before'] Position of menu: `top`, `after`, `bottom` or `before`
9107 OO
.ui
.MenuLayout
= function OoUiMenuLayout( config
) {
9108 // Configuration initialization
9109 config
= $.extend( {
9111 menuPosition
: 'before'
9114 // Parent constructor
9115 OO
.ui
.MenuLayout
.parent
.call( this, config
);
9120 * @property {jQuery}
9122 this.$menu
= $( '<div>' );
9126 * @property {jQuery}
9128 this.$content
= $( '<div>' );
9132 .addClass( 'oo-ui-menuLayout-menu' );
9133 this.$content
.addClass( 'oo-ui-menuLayout-content' );
9135 .addClass( 'oo-ui-menuLayout' )
9136 .append( this.$content
, this.$menu
);
9137 this.setMenuPosition( config
.menuPosition
);
9138 this.toggleMenu( config
.showMenu
);
9143 OO
.inheritClass( OO
.ui
.MenuLayout
, OO
.ui
.Layout
);
9150 * @param {boolean} showMenu Show menu, omit to toggle
9153 OO
.ui
.MenuLayout
.prototype.toggleMenu = function ( showMenu
) {
9154 showMenu
= showMenu
=== undefined ? !this.showMenu
: !!showMenu
;
9156 if ( this.showMenu
!== showMenu
) {
9157 this.showMenu
= showMenu
;
9159 .toggleClass( 'oo-ui-menuLayout-showMenu', this.showMenu
)
9160 .toggleClass( 'oo-ui-menuLayout-hideMenu', !this.showMenu
);
9167 * Check if menu is visible
9169 * @return {boolean} Menu is visible
9171 OO
.ui
.MenuLayout
.prototype.isMenuVisible = function () {
9172 return this.showMenu
;
9176 * Set menu position.
9178 * @param {string} position Position of menu, either `top`, `after`, `bottom` or `before`
9179 * @throws {Error} If position value is not supported
9182 OO
.ui
.MenuLayout
.prototype.setMenuPosition = function ( position
) {
9183 this.$element
.removeClass( 'oo-ui-menuLayout-' + this.menuPosition
);
9184 this.menuPosition
= position
;
9185 this.$element
.addClass( 'oo-ui-menuLayout-' + position
);
9191 * Get menu position.
9193 * @return {string} Menu position
9195 OO
.ui
.MenuLayout
.prototype.getMenuPosition = function () {
9196 return this.menuPosition
;
9200 * BookletLayouts contain {@link OO.ui.PageLayout page layouts} as well as
9201 * an {@link OO.ui.OutlineSelectWidget outline} that allows users to easily navigate
9202 * through the pages and select which one to display. By default, only one page is
9203 * displayed at a time and the outline is hidden. When a user navigates to a new page,
9204 * the booklet layout automatically focuses on the first focusable element, unless the
9205 * default setting is changed. Optionally, booklets can be configured to show
9206 * {@link OO.ui.OutlineControlsWidget controls} for adding, moving, and removing items.
9209 * // Example of a BookletLayout that contains two PageLayouts.
9211 * function PageOneLayout( name, config ) {
9212 * PageOneLayout.parent.call( this, name, config );
9213 * this.$element.append( '<p>First page</p><p>(This booklet has an outline, displayed on the left)</p>' );
9215 * OO.inheritClass( PageOneLayout, OO.ui.PageLayout );
9216 * PageOneLayout.prototype.setupOutlineItem = function () {
9217 * this.outlineItem.setLabel( 'Page One' );
9220 * function PageTwoLayout( name, config ) {
9221 * PageTwoLayout.parent.call( this, name, config );
9222 * this.$element.append( '<p>Second page</p>' );
9224 * OO.inheritClass( PageTwoLayout, OO.ui.PageLayout );
9225 * PageTwoLayout.prototype.setupOutlineItem = function () {
9226 * this.outlineItem.setLabel( 'Page Two' );
9229 * var page1 = new PageOneLayout( 'one' ),
9230 * page2 = new PageTwoLayout( 'two' );
9232 * var booklet = new OO.ui.BookletLayout( {
9236 * booklet.addPages ( [ page1, page2 ] );
9237 * $( 'body' ).append( booklet.$element );
9240 * @extends OO.ui.MenuLayout
9243 * @param {Object} [config] Configuration options
9244 * @cfg {boolean} [continuous=false] Show all pages, one after another
9245 * @cfg {boolean} [autoFocus=true] Focus on the first focusable element when a new page is displayed.
9246 * @cfg {boolean} [outlined=false] Show the outline. The outline is used to navigate through the pages of the booklet.
9247 * @cfg {boolean} [editable=false] Show controls for adding, removing and reordering pages
9249 OO
.ui
.BookletLayout
= function OoUiBookletLayout( config
) {
9250 // Configuration initialization
9251 config
= config
|| {};
9253 // Parent constructor
9254 OO
.ui
.BookletLayout
.parent
.call( this, config
);
9257 this.currentPageName
= null;
9259 this.ignoreFocus
= false;
9260 this.stackLayout
= new OO
.ui
.StackLayout( { continuous
: !!config
.continuous
} );
9261 this.$content
.append( this.stackLayout
.$element
);
9262 this.autoFocus
= config
.autoFocus
=== undefined || !!config
.autoFocus
;
9263 this.outlineVisible
= false;
9264 this.outlined
= !!config
.outlined
;
9265 if ( this.outlined
) {
9266 this.editable
= !!config
.editable
;
9267 this.outlineControlsWidget
= null;
9268 this.outlineSelectWidget
= new OO
.ui
.OutlineSelectWidget();
9269 this.outlinePanel
= new OO
.ui
.PanelLayout( { scrollable
: true } );
9270 this.$menu
.append( this.outlinePanel
.$element
);
9271 this.outlineVisible
= true;
9272 if ( this.editable
) {
9273 this.outlineControlsWidget
= new OO
.ui
.OutlineControlsWidget(
9274 this.outlineSelectWidget
9278 this.toggleMenu( this.outlined
);
9281 this.stackLayout
.connect( this, { set: 'onStackLayoutSet' } );
9282 if ( this.outlined
) {
9283 this.outlineSelectWidget
.connect( this, { select
: 'onOutlineSelectWidgetSelect' } );
9285 if ( this.autoFocus
) {
9286 // Event 'focus' does not bubble, but 'focusin' does
9287 this.stackLayout
.$element
.on( 'focusin', this.onStackLayoutFocus
.bind( this ) );
9291 this.$element
.addClass( 'oo-ui-bookletLayout' );
9292 this.stackLayout
.$element
.addClass( 'oo-ui-bookletLayout-stackLayout' );
9293 if ( this.outlined
) {
9294 this.outlinePanel
.$element
9295 .addClass( 'oo-ui-bookletLayout-outlinePanel' )
9296 .append( this.outlineSelectWidget
.$element
);
9297 if ( this.editable
) {
9298 this.outlinePanel
.$element
9299 .addClass( 'oo-ui-bookletLayout-outlinePanel-editable' )
9300 .append( this.outlineControlsWidget
.$element
);
9307 OO
.inheritClass( OO
.ui
.BookletLayout
, OO
.ui
.MenuLayout
);
9312 * A 'set' event is emitted when a page is {@link #setPage set} to be displayed by the booklet layout.
9314 * @param {OO.ui.PageLayout} page Current page
9318 * An 'add' event is emitted when pages are {@link #addPages added} to the booklet layout.
9321 * @param {OO.ui.PageLayout[]} page Added pages
9322 * @param {number} index Index pages were added at
9326 * A 'remove' event is emitted when pages are {@link #clearPages cleared} or
9327 * {@link #removePages removed} from the booklet.
9330 * @param {OO.ui.PageLayout[]} pages Removed pages
9336 * Handle stack layout focus.
9339 * @param {jQuery.Event} e Focusin event
9341 OO
.ui
.BookletLayout
.prototype.onStackLayoutFocus = function ( e
) {
9344 // Find the page that an element was focused within
9345 $target
= $( e
.target
).closest( '.oo-ui-pageLayout' );
9346 for ( name
in this.pages
) {
9347 // Check for page match, exclude current page to find only page changes
9348 if ( this.pages
[ name
].$element
[ 0 ] === $target
[ 0 ] && name
!== this.currentPageName
) {
9349 this.setPage( name
);
9356 * Handle stack layout set events.
9359 * @param {OO.ui.PanelLayout|null} page The page panel that is now the current panel
9361 OO
.ui
.BookletLayout
.prototype.onStackLayoutSet = function ( page
) {
9364 page
.scrollElementIntoView( { complete: function () {
9365 if ( layout
.autoFocus
) {
9373 * Focus the first input in the current page.
9375 * If no page is selected, the first selectable page will be selected.
9376 * If the focus is already in an element on the current page, nothing will happen.
9377 * @param {number} [itemIndex] A specific item to focus on
9379 OO
.ui
.BookletLayout
.prototype.focus = function ( itemIndex
) {
9381 items
= this.stackLayout
.getItems();
9383 if ( itemIndex
!== undefined && items
[ itemIndex
] ) {
9384 page
= items
[ itemIndex
];
9386 page
= this.stackLayout
.getCurrentItem();
9389 if ( !page
&& this.outlined
) {
9390 this.selectFirstSelectablePage();
9391 page
= this.stackLayout
.getCurrentItem();
9396 // Only change the focus if is not already in the current page
9397 if ( !page
.$element
.find( ':focus' ).length
) {
9398 $input
= page
.$element
.find( ':input:first' );
9399 if ( $input
.length
) {
9400 $input
[ 0 ].focus();
9406 * Find the first focusable input in the booklet layout and focus
9409 OO
.ui
.BookletLayout
.prototype.focusFirstFocusable = function () {
9412 items
= this.stackLayout
.getItems(),
9413 checkAndFocus = function () {
9414 if ( OO
.ui
.isFocusableElement( $( this ) ) ) {
9421 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
9425 // Find all potentially focusable elements in the item
9426 // and check if they are focusable
9428 .find( 'input, select, textarea, button, object' )
9429 /* jshint loopfunc:true */
9430 .each( checkAndFocus
);
9435 * Handle outline widget select events.
9438 * @param {OO.ui.OptionWidget|null} item Selected item
9440 OO
.ui
.BookletLayout
.prototype.onOutlineSelectWidgetSelect = function ( item
) {
9442 this.setPage( item
.getData() );
9447 * Check if booklet has an outline.
9449 * @return {boolean} Booklet has an outline
9451 OO
.ui
.BookletLayout
.prototype.isOutlined = function () {
9452 return this.outlined
;
9456 * Check if booklet has editing controls.
9458 * @return {boolean} Booklet is editable
9460 OO
.ui
.BookletLayout
.prototype.isEditable = function () {
9461 return this.editable
;
9465 * Check if booklet has a visible outline.
9467 * @return {boolean} Outline is visible
9469 OO
.ui
.BookletLayout
.prototype.isOutlineVisible = function () {
9470 return this.outlined
&& this.outlineVisible
;
9474 * Hide or show the outline.
9476 * @param {boolean} [show] Show outline, omit to invert current state
9479 OO
.ui
.BookletLayout
.prototype.toggleOutline = function ( show
) {
9480 if ( this.outlined
) {
9481 show
= show
=== undefined ? !this.outlineVisible
: !!show
;
9482 this.outlineVisible
= show
;
9483 this.toggleMenu( show
);
9490 * Get the page closest to the specified page.
9492 * @param {OO.ui.PageLayout} page Page to use as a reference point
9493 * @return {OO.ui.PageLayout|null} Page closest to the specified page
9495 OO
.ui
.BookletLayout
.prototype.getClosestPage = function ( page
) {
9496 var next
, prev
, level
,
9497 pages
= this.stackLayout
.getItems(),
9498 index
= $.inArray( page
, pages
);
9500 if ( index
!== -1 ) {
9501 next
= pages
[ index
+ 1 ];
9502 prev
= pages
[ index
- 1 ];
9503 // Prefer adjacent pages at the same level
9504 if ( this.outlined
) {
9505 level
= this.outlineSelectWidget
.getItemFromData( page
.getName() ).getLevel();
9508 level
=== this.outlineSelectWidget
.getItemFromData( prev
.getName() ).getLevel()
9514 level
=== this.outlineSelectWidget
.getItemFromData( next
.getName() ).getLevel()
9520 return prev
|| next
|| null;
9524 * Get the outline widget.
9526 * If the booklet is not outlined, the method will return `null`.
9528 * @return {OO.ui.OutlineSelectWidget|null} Outline widget, or null if the booklet is not outlined
9530 OO
.ui
.BookletLayout
.prototype.getOutline = function () {
9531 return this.outlineSelectWidget
;
9535 * Get the outline controls widget.
9537 * If the outline is not editable, the method will return `null`.
9539 * @return {OO.ui.OutlineControlsWidget|null} The outline controls widget.
9541 OO
.ui
.BookletLayout
.prototype.getOutlineControls = function () {
9542 return this.outlineControlsWidget
;
9546 * Get a page by its symbolic name.
9548 * @param {string} name Symbolic name of page
9549 * @return {OO.ui.PageLayout|undefined} Page, if found
9551 OO
.ui
.BookletLayout
.prototype.getPage = function ( name
) {
9552 return this.pages
[ name
];
9556 * Get the current page.
9558 * @return {OO.ui.PageLayout|undefined} Current page, if found
9560 OO
.ui
.BookletLayout
.prototype.getCurrentPage = function () {
9561 var name
= this.getCurrentPageName();
9562 return name
? this.getPage( name
) : undefined;
9566 * Get the symbolic name of the current page.
9568 * @return {string|null} Symbolic name of the current page
9570 OO
.ui
.BookletLayout
.prototype.getCurrentPageName = function () {
9571 return this.currentPageName
;
9575 * Add pages to the booklet layout
9577 * When pages are added with the same names as existing pages, the existing pages will be
9578 * automatically removed before the new pages are added.
9580 * @param {OO.ui.PageLayout[]} pages Pages to add
9581 * @param {number} index Index of the insertion point
9585 OO
.ui
.BookletLayout
.prototype.addPages = function ( pages
, index
) {
9586 var i
, len
, name
, page
, item
, currentIndex
,
9587 stackLayoutPages
= this.stackLayout
.getItems(),
9591 // Remove pages with same names
9592 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
9594 name
= page
.getName();
9596 if ( Object
.prototype.hasOwnProperty
.call( this.pages
, name
) ) {
9597 // Correct the insertion index
9598 currentIndex
= $.inArray( this.pages
[ name
], stackLayoutPages
);
9599 if ( currentIndex
!== -1 && currentIndex
+ 1 < index
) {
9602 remove
.push( this.pages
[ name
] );
9605 if ( remove
.length
) {
9606 this.removePages( remove
);
9610 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
9612 name
= page
.getName();
9613 this.pages
[ page
.getName() ] = page
;
9614 if ( this.outlined
) {
9615 item
= new OO
.ui
.OutlineOptionWidget( { data
: name
} );
9616 page
.setOutlineItem( item
);
9621 if ( this.outlined
&& items
.length
) {
9622 this.outlineSelectWidget
.addItems( items
, index
);
9623 this.selectFirstSelectablePage();
9625 this.stackLayout
.addItems( pages
, index
);
9626 this.emit( 'add', pages
, index
);
9632 * Remove the specified pages from the booklet layout.
9634 * To remove all pages from the booklet, you may wish to use the #clearPages method instead.
9636 * @param {OO.ui.PageLayout[]} pages An array of pages to remove
9640 OO
.ui
.BookletLayout
.prototype.removePages = function ( pages
) {
9641 var i
, len
, name
, page
,
9644 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
9646 name
= page
.getName();
9647 delete this.pages
[ name
];
9648 if ( this.outlined
) {
9649 items
.push( this.outlineSelectWidget
.getItemFromData( name
) );
9650 page
.setOutlineItem( null );
9653 if ( this.outlined
&& items
.length
) {
9654 this.outlineSelectWidget
.removeItems( items
);
9655 this.selectFirstSelectablePage();
9657 this.stackLayout
.removeItems( pages
);
9658 this.emit( 'remove', pages
);
9664 * Clear all pages from the booklet layout.
9666 * To remove only a subset of pages from the booklet, use the #removePages method.
9671 OO
.ui
.BookletLayout
.prototype.clearPages = function () {
9673 pages
= this.stackLayout
.getItems();
9676 this.currentPageName
= null;
9677 if ( this.outlined
) {
9678 this.outlineSelectWidget
.clearItems();
9679 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
9680 pages
[ i
].setOutlineItem( null );
9683 this.stackLayout
.clearItems();
9685 this.emit( 'remove', pages
);
9691 * Set the current page by symbolic name.
9694 * @param {string} name Symbolic name of page
9696 OO
.ui
.BookletLayout
.prototype.setPage = function ( name
) {
9699 page
= this.pages
[ name
];
9701 if ( name
!== this.currentPageName
) {
9702 if ( this.outlined
) {
9703 selectedItem
= this.outlineSelectWidget
.getSelectedItem();
9704 if ( selectedItem
&& selectedItem
.getData() !== name
) {
9705 this.outlineSelectWidget
.selectItemByData( name
);
9709 if ( this.currentPageName
&& this.pages
[ this.currentPageName
] ) {
9710 this.pages
[ this.currentPageName
].setActive( false );
9711 // Blur anything focused if the next page doesn't have anything focusable - this
9712 // is not needed if the next page has something focusable because once it is focused
9713 // this blur happens automatically
9714 if ( this.autoFocus
&& !page
.$element
.find( ':input' ).length
) {
9715 $focused
= this.pages
[ this.currentPageName
].$element
.find( ':focus' );
9716 if ( $focused
.length
) {
9717 $focused
[ 0 ].blur();
9721 this.currentPageName
= name
;
9722 this.stackLayout
.setItem( page
);
9723 page
.setActive( true );
9724 this.emit( 'set', page
);
9730 * Select the first selectable page.
9734 OO
.ui
.BookletLayout
.prototype.selectFirstSelectablePage = function () {
9735 if ( !this.outlineSelectWidget
.getSelectedItem() ) {
9736 this.outlineSelectWidget
.selectItem( this.outlineSelectWidget
.getFirstSelectableItem() );
9743 * IndexLayouts contain {@link OO.ui.CardLayout card layouts} as well as
9744 * {@link OO.ui.TabSelectWidget tabs} that allow users to easily navigate through the cards and
9745 * select which one to display. By default, only one card is displayed at a time. When a user
9746 * navigates to a new card, the index layout automatically focuses on the first focusable element,
9747 * unless the default setting is changed.
9749 * TODO: This class is similar to BookletLayout, we may want to refactor to reduce duplication
9752 * // Example of a IndexLayout that contains two CardLayouts.
9754 * function CardOneLayout( name, config ) {
9755 * CardOneLayout.parent.call( this, name, config );
9756 * this.$element.append( '<p>First card</p>' );
9758 * OO.inheritClass( CardOneLayout, OO.ui.CardLayout );
9759 * CardOneLayout.prototype.setupTabItem = function () {
9760 * this.tabItem.setLabel( 'Card One' );
9763 * function CardTwoLayout( name, config ) {
9764 * CardTwoLayout.parent.call( this, name, config );
9765 * this.$element.append( '<p>Second card</p>' );
9767 * OO.inheritClass( CardTwoLayout, OO.ui.CardLayout );
9768 * CardTwoLayout.prototype.setupTabItem = function () {
9769 * this.tabItem.setLabel( 'Card Two' );
9772 * var card1 = new CardOneLayout( 'one' ),
9773 * card2 = new CardTwoLayout( 'two' );
9775 * var index = new OO.ui.IndexLayout();
9777 * index.addCards ( [ card1, card2 ] );
9778 * $( 'body' ).append( index.$element );
9781 * @extends OO.ui.MenuLayout
9784 * @param {Object} [config] Configuration options
9785 * @cfg {boolean} [continuous=false] Show all cards, one after another
9786 * @cfg {boolean} [autoFocus=true] Focus on the first focusable element when a new card is displayed.
9788 OO
.ui
.IndexLayout
= function OoUiIndexLayout( config
) {
9789 // Configuration initialization
9790 config
= $.extend( {}, config
, { menuPosition
: 'top' } );
9792 // Parent constructor
9793 OO
.ui
.IndexLayout
.parent
.call( this, config
);
9796 this.currentCardName
= null;
9798 this.ignoreFocus
= false;
9799 this.stackLayout
= new OO
.ui
.StackLayout( { continuous
: !!config
.continuous
} );
9800 this.$content
.append( this.stackLayout
.$element
);
9801 this.autoFocus
= config
.autoFocus
=== undefined || !!config
.autoFocus
;
9803 this.tabSelectWidget
= new OO
.ui
.TabSelectWidget();
9804 this.tabPanel
= new OO
.ui
.PanelLayout();
9805 this.$menu
.append( this.tabPanel
.$element
);
9807 this.toggleMenu( true );
9810 this.stackLayout
.connect( this, { set: 'onStackLayoutSet' } );
9811 this.tabSelectWidget
.connect( this, { select
: 'onTabSelectWidgetSelect' } );
9812 if ( this.autoFocus
) {
9813 // Event 'focus' does not bubble, but 'focusin' does
9814 this.stackLayout
.$element
.on( 'focusin', this.onStackLayoutFocus
.bind( this ) );
9818 this.$element
.addClass( 'oo-ui-indexLayout' );
9819 this.stackLayout
.$element
.addClass( 'oo-ui-indexLayout-stackLayout' );
9820 this.tabPanel
.$element
9821 .addClass( 'oo-ui-indexLayout-tabPanel' )
9822 .append( this.tabSelectWidget
.$element
);
9827 OO
.inheritClass( OO
.ui
.IndexLayout
, OO
.ui
.MenuLayout
);
9832 * A 'set' event is emitted when a card is {@link #setCard set} to be displayed by the index layout.
9834 * @param {OO.ui.CardLayout} card Current card
9838 * An 'add' event is emitted when cards are {@link #addCards added} to the index layout.
9841 * @param {OO.ui.CardLayout[]} card Added cards
9842 * @param {number} index Index cards were added at
9846 * A 'remove' event is emitted when cards are {@link #clearCards cleared} or
9847 * {@link #removeCards removed} from the index.
9850 * @param {OO.ui.CardLayout[]} cards Removed cards
9856 * Handle stack layout focus.
9859 * @param {jQuery.Event} e Focusin event
9861 OO
.ui
.IndexLayout
.prototype.onStackLayoutFocus = function ( e
) {
9864 // Find the card that an element was focused within
9865 $target
= $( e
.target
).closest( '.oo-ui-cardLayout' );
9866 for ( name
in this.cards
) {
9867 // Check for card match, exclude current card to find only card changes
9868 if ( this.cards
[ name
].$element
[ 0 ] === $target
[ 0 ] && name
!== this.currentCardName
) {
9869 this.setCard( name
);
9876 * Handle stack layout set events.
9879 * @param {OO.ui.PanelLayout|null} card The card panel that is now the current panel
9881 OO
.ui
.IndexLayout
.prototype.onStackLayoutSet = function ( card
) {
9884 card
.scrollElementIntoView( { complete: function () {
9885 if ( layout
.autoFocus
) {
9893 * Focus the first input in the current card.
9895 * If no card is selected, the first selectable card will be selected.
9896 * If the focus is already in an element on the current card, nothing will happen.
9897 * @param {number} [itemIndex] A specific item to focus on
9899 OO
.ui
.IndexLayout
.prototype.focus = function ( itemIndex
) {
9901 items
= this.stackLayout
.getItems();
9903 if ( itemIndex
!== undefined && items
[ itemIndex
] ) {
9904 card
= items
[ itemIndex
];
9906 card
= this.stackLayout
.getCurrentItem();
9910 this.selectFirstSelectableCard();
9911 card
= this.stackLayout
.getCurrentItem();
9916 // Only change the focus if is not already in the current card
9917 if ( !card
.$element
.find( ':focus' ).length
) {
9918 $input
= card
.$element
.find( ':input:first' );
9919 if ( $input
.length
) {
9920 $input
[ 0 ].focus();
9926 * Find the first focusable input in the index layout and focus
9929 OO
.ui
.IndexLayout
.prototype.focusFirstFocusable = function () {
9932 items
= this.stackLayout
.getItems(),
9933 checkAndFocus = function () {
9934 if ( OO
.ui
.isFocusableElement( $( this ) ) ) {
9941 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
9945 // Find all potentially focusable elements in the item
9946 // and check if they are focusable
9948 .find( 'input, select, textarea, button, object' )
9949 .each( checkAndFocus
);
9954 * Handle tab widget select events.
9957 * @param {OO.ui.OptionWidget|null} item Selected item
9959 OO
.ui
.IndexLayout
.prototype.onTabSelectWidgetSelect = function ( item
) {
9961 this.setCard( item
.getData() );
9966 * Get the card closest to the specified card.
9968 * @param {OO.ui.CardLayout} card Card to use as a reference point
9969 * @return {OO.ui.CardLayout|null} Card closest to the specified card
9971 OO
.ui
.IndexLayout
.prototype.getClosestCard = function ( card
) {
9972 var next
, prev
, level
,
9973 cards
= this.stackLayout
.getItems(),
9974 index
= $.inArray( card
, cards
);
9976 if ( index
!== -1 ) {
9977 next
= cards
[ index
+ 1 ];
9978 prev
= cards
[ index
- 1 ];
9979 // Prefer adjacent cards at the same level
9980 level
= this.tabSelectWidget
.getItemFromData( card
.getName() ).getLevel();
9983 level
=== this.tabSelectWidget
.getItemFromData( prev
.getName() ).getLevel()
9989 level
=== this.tabSelectWidget
.getItemFromData( next
.getName() ).getLevel()
9994 return prev
|| next
|| null;
9998 * Get the tabs widget.
10000 * @return {OO.ui.TabSelectWidget} Tabs widget
10002 OO
.ui
.IndexLayout
.prototype.getTabs = function () {
10003 return this.tabSelectWidget
;
10007 * Get a card by its symbolic name.
10009 * @param {string} name Symbolic name of card
10010 * @return {OO.ui.CardLayout|undefined} Card, if found
10012 OO
.ui
.IndexLayout
.prototype.getCard = function ( name
) {
10013 return this.cards
[ name
];
10017 * Get the current card.
10019 * @return {OO.ui.CardLayout|undefined} Current card, if found
10021 OO
.ui
.IndexLayout
.prototype.getCurrentCard = function () {
10022 var name
= this.getCurrentCardName();
10023 return name
? this.getCard( name
) : undefined;
10027 * Get the symbolic name of the current card.
10029 * @return {string|null} Symbolic name of the current card
10031 OO
.ui
.IndexLayout
.prototype.getCurrentCardName = function () {
10032 return this.currentCardName
;
10036 * Add cards to the index layout
10038 * When cards are added with the same names as existing cards, the existing cards will be
10039 * automatically removed before the new cards are added.
10041 * @param {OO.ui.CardLayout[]} cards Cards to add
10042 * @param {number} index Index of the insertion point
10046 OO
.ui
.IndexLayout
.prototype.addCards = function ( cards
, index
) {
10047 var i
, len
, name
, card
, item
, currentIndex
,
10048 stackLayoutCards
= this.stackLayout
.getItems(),
10052 // Remove cards with same names
10053 for ( i
= 0, len
= cards
.length
; i
< len
; i
++ ) {
10055 name
= card
.getName();
10057 if ( Object
.prototype.hasOwnProperty
.call( this.cards
, name
) ) {
10058 // Correct the insertion index
10059 currentIndex
= $.inArray( this.cards
[ name
], stackLayoutCards
);
10060 if ( currentIndex
!== -1 && currentIndex
+ 1 < index
) {
10063 remove
.push( this.cards
[ name
] );
10066 if ( remove
.length
) {
10067 this.removeCards( remove
);
10071 for ( i
= 0, len
= cards
.length
; i
< len
; i
++ ) {
10073 name
= card
.getName();
10074 this.cards
[ card
.getName() ] = card
;
10075 item
= new OO
.ui
.TabOptionWidget( { data
: name
} );
10076 card
.setTabItem( item
);
10077 items
.push( item
);
10080 if ( items
.length
) {
10081 this.tabSelectWidget
.addItems( items
, index
);
10082 this.selectFirstSelectableCard();
10084 this.stackLayout
.addItems( cards
, index
);
10085 this.emit( 'add', cards
, index
);
10091 * Remove the specified cards from the index layout.
10093 * To remove all cards from the index, you may wish to use the #clearCards method instead.
10095 * @param {OO.ui.CardLayout[]} cards An array of cards to remove
10099 OO
.ui
.IndexLayout
.prototype.removeCards = function ( cards
) {
10100 var i
, len
, name
, card
,
10103 for ( i
= 0, len
= cards
.length
; i
< len
; i
++ ) {
10105 name
= card
.getName();
10106 delete this.cards
[ name
];
10107 items
.push( this.tabSelectWidget
.getItemFromData( name
) );
10108 card
.setTabItem( null );
10110 if ( items
.length
) {
10111 this.tabSelectWidget
.removeItems( items
);
10112 this.selectFirstSelectableCard();
10114 this.stackLayout
.removeItems( cards
);
10115 this.emit( 'remove', cards
);
10121 * Clear all cards from the index layout.
10123 * To remove only a subset of cards from the index, use the #removeCards method.
10128 OO
.ui
.IndexLayout
.prototype.clearCards = function () {
10130 cards
= this.stackLayout
.getItems();
10133 this.currentCardName
= null;
10134 this.tabSelectWidget
.clearItems();
10135 for ( i
= 0, len
= cards
.length
; i
< len
; i
++ ) {
10136 cards
[ i
].setTabItem( null );
10138 this.stackLayout
.clearItems();
10140 this.emit( 'remove', cards
);
10146 * Set the current card by symbolic name.
10149 * @param {string} name Symbolic name of card
10151 OO
.ui
.IndexLayout
.prototype.setCard = function ( name
) {
10154 card
= this.cards
[ name
];
10156 if ( name
!== this.currentCardName
) {
10157 selectedItem
= this.tabSelectWidget
.getSelectedItem();
10158 if ( selectedItem
&& selectedItem
.getData() !== name
) {
10159 this.tabSelectWidget
.selectItemByData( name
);
10162 if ( this.currentCardName
&& this.cards
[ this.currentCardName
] ) {
10163 this.cards
[ this.currentCardName
].setActive( false );
10164 // Blur anything focused if the next card doesn't have anything focusable - this
10165 // is not needed if the next card has something focusable because once it is focused
10166 // this blur happens automatically
10167 if ( this.autoFocus
&& !card
.$element
.find( ':input' ).length
) {
10168 $focused
= this.cards
[ this.currentCardName
].$element
.find( ':focus' );
10169 if ( $focused
.length
) {
10170 $focused
[ 0 ].blur();
10174 this.currentCardName
= name
;
10175 this.stackLayout
.setItem( card
);
10176 card
.setActive( true );
10177 this.emit( 'set', card
);
10183 * Select the first selectable card.
10187 OO
.ui
.IndexLayout
.prototype.selectFirstSelectableCard = function () {
10188 if ( !this.tabSelectWidget
.getSelectedItem() ) {
10189 this.tabSelectWidget
.selectItem( this.tabSelectWidget
.getFirstSelectableItem() );
10196 * PanelLayouts expand to cover the entire area of their parent. They can be configured with scrolling, padding,
10197 * and a frame, and are often used together with {@link OO.ui.StackLayout StackLayouts}.
10200 * // Example of a panel layout
10201 * var panel = new OO.ui.PanelLayout( {
10205 * $content: $( '<p>A panel layout with padding and a frame.</p>' )
10207 * $( 'body' ).append( panel.$element );
10210 * @extends OO.ui.Layout
10213 * @param {Object} [config] Configuration options
10214 * @cfg {boolean} [scrollable=false] Allow vertical scrolling
10215 * @cfg {boolean} [padded=false] Add padding between the content and the edges of the panel.
10216 * @cfg {boolean} [expanded=true] Expand the panel to fill the entire parent element.
10217 * @cfg {boolean} [framed=false] Render the panel with a frame to visually separate it from outside content.
10219 OO
.ui
.PanelLayout
= function OoUiPanelLayout( config
) {
10220 // Configuration initialization
10221 config
= $.extend( {
10228 // Parent constructor
10229 OO
.ui
.PanelLayout
.parent
.call( this, config
);
10232 this.$element
.addClass( 'oo-ui-panelLayout' );
10233 if ( config
.scrollable
) {
10234 this.$element
.addClass( 'oo-ui-panelLayout-scrollable' );
10236 if ( config
.padded
) {
10237 this.$element
.addClass( 'oo-ui-panelLayout-padded' );
10239 if ( config
.expanded
) {
10240 this.$element
.addClass( 'oo-ui-panelLayout-expanded' );
10242 if ( config
.framed
) {
10243 this.$element
.addClass( 'oo-ui-panelLayout-framed' );
10249 OO
.inheritClass( OO
.ui
.PanelLayout
, OO
.ui
.Layout
);
10252 * CardLayouts are used within {@link OO.ui.IndexLayout index layouts} to create cards that users can select and display
10253 * from the index's optional {@link OO.ui.TabSelectWidget tab} navigation. Cards are usually not instantiated directly,
10254 * rather extended to include the required content and functionality.
10256 * Each card must have a unique symbolic name, which is passed to the constructor. In addition, the card's tab
10257 * item is customized (with a label) using the #setupTabItem method. See
10258 * {@link OO.ui.IndexLayout IndexLayout} for an example.
10261 * @extends OO.ui.PanelLayout
10264 * @param {string} name Unique symbolic name of card
10265 * @param {Object} [config] Configuration options
10267 OO
.ui
.CardLayout
= function OoUiCardLayout( name
, config
) {
10268 // Allow passing positional parameters inside the config object
10269 if ( OO
.isPlainObject( name
) && config
=== undefined ) {
10271 name
= config
.name
;
10274 // Configuration initialization
10275 config
= $.extend( { scrollable
: true }, config
);
10277 // Parent constructor
10278 OO
.ui
.CardLayout
.parent
.call( this, config
);
10282 this.tabItem
= null;
10283 this.active
= false;
10286 this.$element
.addClass( 'oo-ui-cardLayout' );
10291 OO
.inheritClass( OO
.ui
.CardLayout
, OO
.ui
.PanelLayout
);
10296 * An 'active' event is emitted when the card becomes active. Cards become active when they are
10297 * shown in a index layout that is configured to display only one card at a time.
10300 * @param {boolean} active Card is active
10306 * Get the symbolic name of the card.
10308 * @return {string} Symbolic name of card
10310 OO
.ui
.CardLayout
.prototype.getName = function () {
10315 * Check if card is active.
10317 * Cards become active when they are shown in a {@link OO.ui.IndexLayout index layout} that is configured to display
10318 * only one card at a time. Additional CSS is applied to the card's tab item to reflect the active state.
10320 * @return {boolean} Card is active
10322 OO
.ui
.CardLayout
.prototype.isActive = function () {
10323 return this.active
;
10329 * The tab item allows users to access the card from the index's tab
10330 * navigation. The tab item itself can be customized (with a label, level, etc.) using the #setupTabItem method.
10332 * @return {OO.ui.TabOptionWidget|null} Tab option widget
10334 OO
.ui
.CardLayout
.prototype.getTabItem = function () {
10335 return this.tabItem
;
10339 * Set or unset the tab item.
10341 * Specify a {@link OO.ui.TabOptionWidget tab option} to set it,
10342 * or `null` to clear the tab item. To customize the tab item itself (e.g., to set a label or tab
10343 * level), use #setupTabItem instead of this method.
10345 * @param {OO.ui.TabOptionWidget|null} tabItem Tab option widget, null to clear
10348 OO
.ui
.CardLayout
.prototype.setTabItem = function ( tabItem
) {
10349 this.tabItem
= tabItem
|| null;
10351 this.setupTabItem();
10357 * Set up the tab item.
10359 * Use this method to customize the tab item (e.g., to add a label or tab level). To set or unset
10360 * the tab item itself (with a {@link OO.ui.TabOptionWidget tab option} or `null`), use
10361 * the #setTabItem method instead.
10363 * @param {OO.ui.TabOptionWidget} tabItem Tab option widget to set up
10366 OO
.ui
.CardLayout
.prototype.setupTabItem = function () {
10371 * Set the card to its 'active' state.
10373 * Cards become active when they are shown in a index layout that is configured to display only one card at a time. Additional
10374 * CSS is applied to the tab item to reflect the card's active state. Outside of the index
10375 * context, setting the active state on a card does nothing.
10377 * @param {boolean} value Card is active
10380 OO
.ui
.CardLayout
.prototype.setActive = function ( active
) {
10383 if ( active
!== this.active
) {
10384 this.active
= active
;
10385 this.$element
.toggleClass( 'oo-ui-cardLayout-active', this.active
);
10386 this.emit( 'active', this.active
);
10391 * PageLayouts are used within {@link OO.ui.BookletLayout booklet layouts} to create pages that users can select and display
10392 * from the booklet's optional {@link OO.ui.OutlineSelectWidget outline} navigation. Pages are usually not instantiated directly,
10393 * rather extended to include the required content and functionality.
10395 * Each page must have a unique symbolic name, which is passed to the constructor. In addition, the page's outline
10396 * item is customized (with a label, outline level, etc.) using the #setupOutlineItem method. See
10397 * {@link OO.ui.BookletLayout BookletLayout} for an example.
10400 * @extends OO.ui.PanelLayout
10403 * @param {string} name Unique symbolic name of page
10404 * @param {Object} [config] Configuration options
10406 OO
.ui
.PageLayout
= function OoUiPageLayout( name
, config
) {
10407 // Allow passing positional parameters inside the config object
10408 if ( OO
.isPlainObject( name
) && config
=== undefined ) {
10410 name
= config
.name
;
10413 // Configuration initialization
10414 config
= $.extend( { scrollable
: true }, config
);
10416 // Parent constructor
10417 OO
.ui
.PageLayout
.parent
.call( this, config
);
10421 this.outlineItem
= null;
10422 this.active
= false;
10425 this.$element
.addClass( 'oo-ui-pageLayout' );
10430 OO
.inheritClass( OO
.ui
.PageLayout
, OO
.ui
.PanelLayout
);
10435 * An 'active' event is emitted when the page becomes active. Pages become active when they are
10436 * shown in a booklet layout that is configured to display only one page at a time.
10439 * @param {boolean} active Page is active
10445 * Get the symbolic name of the page.
10447 * @return {string} Symbolic name of page
10449 OO
.ui
.PageLayout
.prototype.getName = function () {
10454 * Check if page is active.
10456 * Pages become active when they are shown in a {@link OO.ui.BookletLayout booklet layout} that is configured to display
10457 * only one page at a time. Additional CSS is applied to the page's outline item to reflect the active state.
10459 * @return {boolean} Page is active
10461 OO
.ui
.PageLayout
.prototype.isActive = function () {
10462 return this.active
;
10466 * Get outline item.
10468 * The outline item allows users to access the page from the booklet's outline
10469 * navigation. The outline item itself can be customized (with a label, level, etc.) using the #setupOutlineItem method.
10471 * @return {OO.ui.OutlineOptionWidget|null} Outline option widget
10473 OO
.ui
.PageLayout
.prototype.getOutlineItem = function () {
10474 return this.outlineItem
;
10478 * Set or unset the outline item.
10480 * Specify an {@link OO.ui.OutlineOptionWidget outline option} to set it,
10481 * or `null` to clear the outline item. To customize the outline item itself (e.g., to set a label or outline
10482 * level), use #setupOutlineItem instead of this method.
10484 * @param {OO.ui.OutlineOptionWidget|null} outlineItem Outline option widget, null to clear
10487 OO
.ui
.PageLayout
.prototype.setOutlineItem = function ( outlineItem
) {
10488 this.outlineItem
= outlineItem
|| null;
10489 if ( outlineItem
) {
10490 this.setupOutlineItem();
10496 * Set up the outline item.
10498 * Use this method to customize the outline item (e.g., to add a label or outline level). To set or unset
10499 * the outline item itself (with an {@link OO.ui.OutlineOptionWidget outline option} or `null`), use
10500 * the #setOutlineItem method instead.
10502 * @param {OO.ui.OutlineOptionWidget} outlineItem Outline option widget to set up
10505 OO
.ui
.PageLayout
.prototype.setupOutlineItem = function () {
10510 * Set the page to its 'active' state.
10512 * Pages become active when they are shown in a booklet layout that is configured to display only one page at a time. Additional
10513 * CSS is applied to the outline item to reflect the page's active state. Outside of the booklet
10514 * context, setting the active state on a page does nothing.
10516 * @param {boolean} value Page is active
10519 OO
.ui
.PageLayout
.prototype.setActive = function ( active
) {
10522 if ( active
!== this.active
) {
10523 this.active
= active
;
10524 this.$element
.toggleClass( 'oo-ui-pageLayout-active', active
);
10525 this.emit( 'active', this.active
);
10530 * StackLayouts contain a series of {@link OO.ui.PanelLayout panel layouts}. By default, only one panel is displayed
10531 * at a time, though the stack layout can also be configured to show all contained panels, one after another,
10532 * by setting the #continuous option to 'true'.
10535 * // A stack layout with two panels, configured to be displayed continously
10536 * var myStack = new OO.ui.StackLayout( {
10538 * new OO.ui.PanelLayout( {
10539 * $content: $( '<p>Panel One</p>' ),
10543 * new OO.ui.PanelLayout( {
10544 * $content: $( '<p>Panel Two</p>' ),
10551 * $( 'body' ).append( myStack.$element );
10554 * @extends OO.ui.PanelLayout
10555 * @mixins OO.ui.mixin.GroupElement
10558 * @param {Object} [config] Configuration options
10559 * @cfg {boolean} [continuous=false] Show all panels, one after another. By default, only one panel is displayed at a time.
10560 * @cfg {OO.ui.Layout[]} [items] Panel layouts to add to the stack layout.
10562 OO
.ui
.StackLayout
= function OoUiStackLayout( config
) {
10563 // Configuration initialization
10564 config
= $.extend( { scrollable
: true }, config
);
10566 // Parent constructor
10567 OO
.ui
.StackLayout
.parent
.call( this, config
);
10569 // Mixin constructors
10570 OO
.ui
.mixin
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
10573 this.currentItem
= null;
10574 this.continuous
= !!config
.continuous
;
10577 this.$element
.addClass( 'oo-ui-stackLayout' );
10578 if ( this.continuous
) {
10579 this.$element
.addClass( 'oo-ui-stackLayout-continuous' );
10581 if ( Array
.isArray( config
.items
) ) {
10582 this.addItems( config
.items
);
10588 OO
.inheritClass( OO
.ui
.StackLayout
, OO
.ui
.PanelLayout
);
10589 OO
.mixinClass( OO
.ui
.StackLayout
, OO
.ui
.mixin
.GroupElement
);
10594 * A 'set' event is emitted when panels are {@link #addItems added}, {@link #removeItems removed},
10595 * {@link #clearItems cleared} or {@link #setItem displayed}.
10598 * @param {OO.ui.Layout|null} item Current panel or `null` if no panel is shown
10604 * Get the current panel.
10606 * @return {OO.ui.Layout|null}
10608 OO
.ui
.StackLayout
.prototype.getCurrentItem = function () {
10609 return this.currentItem
;
10613 * Unset the current item.
10616 * @param {OO.ui.StackLayout} layout
10619 OO
.ui
.StackLayout
.prototype.unsetCurrentItem = function () {
10620 var prevItem
= this.currentItem
;
10621 if ( prevItem
=== null ) {
10625 this.currentItem
= null;
10626 this.emit( 'set', null );
10630 * Add panel layouts to the stack layout.
10632 * Panels will be added to the end of the stack layout array unless the optional index parameter specifies a different
10633 * insertion point. Adding a panel that is already in the stack will move it to the end of the array or the point specified
10636 * @param {OO.ui.Layout[]} items Panels to add
10637 * @param {number} [index] Index of the insertion point
10640 OO
.ui
.StackLayout
.prototype.addItems = function ( items
, index
) {
10641 // Update the visibility
10642 this.updateHiddenState( items
, this.currentItem
);
10645 OO
.ui
.mixin
.GroupElement
.prototype.addItems
.call( this, items
, index
);
10647 if ( !this.currentItem
&& items
.length
) {
10648 this.setItem( items
[ 0 ] );
10655 * Remove the specified panels from the stack layout.
10657 * Removed panels are detached from the DOM, not removed, so that they may be reused. To remove all panels,
10658 * you may wish to use the #clearItems method instead.
10660 * @param {OO.ui.Layout[]} items Panels to remove
10664 OO
.ui
.StackLayout
.prototype.removeItems = function ( items
) {
10666 OO
.ui
.mixin
.GroupElement
.prototype.removeItems
.call( this, items
);
10668 if ( $.inArray( this.currentItem
, items
) !== -1 ) {
10669 if ( this.items
.length
) {
10670 this.setItem( this.items
[ 0 ] );
10672 this.unsetCurrentItem();
10680 * Clear all panels from the stack layout.
10682 * Cleared panels are detached from the DOM, not removed, so that they may be reused. To remove only
10683 * a subset of panels, use the #removeItems method.
10688 OO
.ui
.StackLayout
.prototype.clearItems = function () {
10689 this.unsetCurrentItem();
10690 OO
.ui
.mixin
.GroupElement
.prototype.clearItems
.call( this );
10696 * Show the specified panel.
10698 * If another panel is currently displayed, it will be hidden.
10700 * @param {OO.ui.Layout} item Panel to show
10704 OO
.ui
.StackLayout
.prototype.setItem = function ( item
) {
10705 if ( item
!== this.currentItem
) {
10706 this.updateHiddenState( this.items
, item
);
10708 if ( $.inArray( item
, this.items
) !== -1 ) {
10709 this.currentItem
= item
;
10710 this.emit( 'set', item
);
10712 this.unsetCurrentItem();
10720 * Update the visibility of all items in case of non-continuous view.
10722 * Ensure all items are hidden except for the selected one.
10723 * This method does nothing when the stack is continuous.
10726 * @param {OO.ui.Layout[]} items Item list iterate over
10727 * @param {OO.ui.Layout} [selectedItem] Selected item to show
10729 OO
.ui
.StackLayout
.prototype.updateHiddenState = function ( items
, selectedItem
) {
10732 if ( !this.continuous
) {
10733 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
10734 if ( !selectedItem
|| selectedItem
!== items
[ i
] ) {
10735 items
[ i
].$element
.addClass( 'oo-ui-element-hidden' );
10738 if ( selectedItem
) {
10739 selectedItem
.$element
.removeClass( 'oo-ui-element-hidden' );
10745 * HorizontalLayout arranges its contents in a single line (using `display: inline-block` for its
10746 * items), with small margins between them. Convenient when you need to put a number of block-level
10747 * widgets on a single line next to each other.
10749 * Note that inline elements, such as OO.ui.ButtonWidgets, do not need this wrapper.
10752 * // HorizontalLayout with a text input and a label
10753 * var layout = new OO.ui.HorizontalLayout( {
10755 * new OO.ui.LabelWidget( { label: 'Label' } ),
10756 * new OO.ui.TextInputWidget( { value: 'Text' } )
10759 * $( 'body' ).append( layout.$element );
10762 * @extends OO.ui.Layout
10763 * @mixins OO.ui.mixin.GroupElement
10766 * @param {Object} [config] Configuration options
10767 * @cfg {OO.ui.Widget[]|OO.ui.Layout[]} [items] Widgets or other layouts to add to the layout.
10769 OO
.ui
.HorizontalLayout
= function OoUiHorizontalLayout( config
) {
10770 // Configuration initialization
10771 config
= config
|| {};
10773 // Parent constructor
10774 OO
.ui
.HorizontalLayout
.parent
.call( this, config
);
10776 // Mixin constructors
10777 OO
.ui
.mixin
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
10780 this.$element
.addClass( 'oo-ui-horizontalLayout' );
10781 if ( Array
.isArray( config
.items
) ) {
10782 this.addItems( config
.items
);
10788 OO
.inheritClass( OO
.ui
.HorizontalLayout
, OO
.ui
.Layout
);
10789 OO
.mixinClass( OO
.ui
.HorizontalLayout
, OO
.ui
.mixin
.GroupElement
);
10792 * BarToolGroups are one of three types of {@link OO.ui.ToolGroup toolgroups} that are used to
10793 * create {@link OO.ui.Toolbar toolbars} (the other types of groups are {@link OO.ui.MenuToolGroup MenuToolGroup}
10794 * and {@link OO.ui.ListToolGroup ListToolGroup}). The {@link OO.ui.Tool tools} in a BarToolGroup are
10795 * displayed by icon in a single row. The title of the tool is displayed when users move the mouse over
10798 * BarToolGroups are created by a {@link OO.ui.ToolGroupFactory tool group factory} when the toolbar is
10802 * // Example of a BarToolGroup with two tools
10803 * var toolFactory = new OO.ui.ToolFactory();
10804 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
10805 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
10807 * // We will be placing status text in this element when tools are used
10808 * var $area = $( '<p>' ).text( 'Example of a BarToolGroup with two tools.' );
10810 * // Define the tools that we're going to place in our toolbar
10812 * // Create a class inheriting from OO.ui.Tool
10813 * function PictureTool() {
10814 * PictureTool.parent.apply( this, arguments );
10816 * OO.inheritClass( PictureTool, OO.ui.Tool );
10817 * // Each tool must have a 'name' (used as an internal identifier, see later) and at least one
10818 * // of 'icon' and 'title' (displayed icon and text).
10819 * PictureTool.static.name = 'picture';
10820 * PictureTool.static.icon = 'picture';
10821 * PictureTool.static.title = 'Insert picture';
10822 * // Defines the action that will happen when this tool is selected (clicked).
10823 * PictureTool.prototype.onSelect = function () {
10824 * $area.text( 'Picture tool clicked!' );
10825 * // Never display this tool as "active" (selected).
10826 * this.setActive( false );
10828 * // Make this tool available in our toolFactory and thus our toolbar
10829 * toolFactory.register( PictureTool );
10831 * // This is a PopupTool. Rather than having a custom 'onSelect' action, it will display a
10832 * // little popup window (a PopupWidget).
10833 * function HelpTool( toolGroup, config ) {
10834 * OO.ui.PopupTool.call( this, toolGroup, $.extend( { popup: {
10839 * this.popup.$body.append( '<p>I am helpful!</p>' );
10841 * OO.inheritClass( HelpTool, OO.ui.PopupTool );
10842 * HelpTool.static.name = 'help';
10843 * HelpTool.static.icon = 'help';
10844 * HelpTool.static.title = 'Help';
10845 * toolFactory.register( HelpTool );
10847 * // Finally define which tools and in what order appear in the toolbar. Each tool may only be
10848 * // used once (but not all defined tools must be used).
10851 * // 'bar' tool groups display tools by icon only
10853 * include: [ 'picture', 'help' ]
10857 * // Create some UI around the toolbar and place it in the document
10858 * var frame = new OO.ui.PanelLayout( {
10862 * var contentFrame = new OO.ui.PanelLayout( {
10866 * frame.$element.append(
10867 * toolbar.$element,
10868 * contentFrame.$element.append( $area )
10870 * $( 'body' ).append( frame.$element );
10872 * // Here is where the toolbar is actually built. This must be done after inserting it into the
10874 * toolbar.initialize();
10876 * For more information about how to add tools to a bar tool group, please see {@link OO.ui.ToolGroup toolgroup}.
10877 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki][1].
10879 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
10882 * @extends OO.ui.ToolGroup
10885 * @param {OO.ui.Toolbar} toolbar
10886 * @param {Object} [config] Configuration options
10888 OO
.ui
.BarToolGroup
= function OoUiBarToolGroup( toolbar
, config
) {
10889 // Allow passing positional parameters inside the config object
10890 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
10892 toolbar
= config
.toolbar
;
10895 // Parent constructor
10896 OO
.ui
.BarToolGroup
.parent
.call( this, toolbar
, config
);
10899 this.$element
.addClass( 'oo-ui-barToolGroup' );
10904 OO
.inheritClass( OO
.ui
.BarToolGroup
, OO
.ui
.ToolGroup
);
10906 /* Static Properties */
10908 OO
.ui
.BarToolGroup
.static.titleTooltips
= true;
10910 OO
.ui
.BarToolGroup
.static.accelTooltips
= true;
10912 OO
.ui
.BarToolGroup
.static.name
= 'bar';
10915 * PopupToolGroup is an abstract base class used by both {@link OO.ui.MenuToolGroup MenuToolGroup}
10916 * and {@link OO.ui.ListToolGroup ListToolGroup} to provide a popup--an overlaid menu or list of tools with an
10917 * optional icon and label. This class can be used for other base classes that also use this functionality.
10921 * @extends OO.ui.ToolGroup
10922 * @mixins OO.ui.mixin.IconElement
10923 * @mixins OO.ui.mixin.IndicatorElement
10924 * @mixins OO.ui.mixin.LabelElement
10925 * @mixins OO.ui.mixin.TitledElement
10926 * @mixins OO.ui.mixin.ClippableElement
10927 * @mixins OO.ui.mixin.TabIndexedElement
10930 * @param {OO.ui.Toolbar} toolbar
10931 * @param {Object} [config] Configuration options
10932 * @cfg {string} [header] Text to display at the top of the popup
10934 OO
.ui
.PopupToolGroup
= function OoUiPopupToolGroup( toolbar
, config
) {
10935 // Allow passing positional parameters inside the config object
10936 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
10938 toolbar
= config
.toolbar
;
10941 // Configuration initialization
10942 config
= config
|| {};
10944 // Parent constructor
10945 OO
.ui
.PopupToolGroup
.parent
.call( this, toolbar
, config
);
10948 this.active
= false;
10949 this.dragging
= false;
10950 this.onBlurHandler
= this.onBlur
.bind( this );
10951 this.$handle
= $( '<span>' );
10953 // Mixin constructors
10954 OO
.ui
.mixin
.IconElement
.call( this, config
);
10955 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
10956 OO
.ui
.mixin
.LabelElement
.call( this, config
);
10957 OO
.ui
.mixin
.TitledElement
.call( this, config
);
10958 OO
.ui
.mixin
.ClippableElement
.call( this, $.extend( {}, config
, { $clippable
: this.$group
} ) );
10959 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$handle
} ) );
10963 keydown
: this.onHandleMouseKeyDown
.bind( this ),
10964 keyup
: this.onHandleMouseKeyUp
.bind( this ),
10965 mousedown
: this.onHandleMouseKeyDown
.bind( this ),
10966 mouseup
: this.onHandleMouseKeyUp
.bind( this )
10971 .addClass( 'oo-ui-popupToolGroup-handle' )
10972 .append( this.$icon
, this.$label
, this.$indicator
);
10973 // If the pop-up should have a header, add it to the top of the toolGroup.
10974 // Note: If this feature is useful for other widgets, we could abstract it into an
10975 // OO.ui.HeaderedElement mixin constructor.
10976 if ( config
.header
!== undefined ) {
10978 .prepend( $( '<span>' )
10979 .addClass( 'oo-ui-popupToolGroup-header' )
10980 .text( config
.header
)
10984 .addClass( 'oo-ui-popupToolGroup' )
10985 .prepend( this.$handle
);
10990 OO
.inheritClass( OO
.ui
.PopupToolGroup
, OO
.ui
.ToolGroup
);
10991 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.IconElement
);
10992 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.IndicatorElement
);
10993 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.LabelElement
);
10994 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.TitledElement
);
10995 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.ClippableElement
);
10996 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.TabIndexedElement
);
11003 OO
.ui
.PopupToolGroup
.prototype.setDisabled = function () {
11005 OO
.ui
.PopupToolGroup
.parent
.prototype.setDisabled
.apply( this, arguments
);
11007 if ( this.isDisabled() && this.isElementAttached() ) {
11008 this.setActive( false );
11013 * Handle focus being lost.
11015 * The event is actually generated from a mouseup/keyup, so it is not a normal blur event object.
11018 * @param {jQuery.Event} e Mouse up or key up event
11020 OO
.ui
.PopupToolGroup
.prototype.onBlur = function ( e
) {
11021 // Only deactivate when clicking outside the dropdown element
11022 if ( $( e
.target
).closest( '.oo-ui-popupToolGroup' )[ 0 ] !== this.$element
[ 0 ] ) {
11023 this.setActive( false );
11030 OO
.ui
.PopupToolGroup
.prototype.onMouseKeyUp = function ( e
) {
11031 // Only close toolgroup when a tool was actually selected
11033 !this.isDisabled() && this.pressed
&& this.pressed
=== this.getTargetTool( e
) &&
11034 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
11036 this.setActive( false );
11038 return OO
.ui
.PopupToolGroup
.parent
.prototype.onMouseKeyUp
.call( this, e
);
11042 * Handle mouse up and key up events.
11045 * @param {jQuery.Event} e Mouse up or key up event
11047 OO
.ui
.PopupToolGroup
.prototype.onHandleMouseKeyUp = function ( e
) {
11049 !this.isDisabled() &&
11050 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
11057 * Handle mouse down and key down events.
11060 * @param {jQuery.Event} e Mouse down or key down event
11062 OO
.ui
.PopupToolGroup
.prototype.onHandleMouseKeyDown = function ( e
) {
11064 !this.isDisabled() &&
11065 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
11067 this.setActive( !this.active
);
11073 * Switch into 'active' mode.
11075 * When active, the popup is visible. A mouseup event anywhere in the document will trigger
11078 OO
.ui
.PopupToolGroup
.prototype.setActive = function ( value
) {
11079 var containerWidth
, containerLeft
;
11081 if ( this.active
!== value
) {
11082 this.active
= value
;
11084 this.getElementDocument().addEventListener( 'mouseup', this.onBlurHandler
, true );
11085 this.getElementDocument().addEventListener( 'keyup', this.onBlurHandler
, true );
11087 this.$clippable
.css( 'left', '' );
11088 // Try anchoring the popup to the left first
11089 this.$element
.addClass( 'oo-ui-popupToolGroup-active oo-ui-popupToolGroup-left' );
11090 this.toggleClipping( true );
11091 if ( this.isClippedHorizontally() ) {
11092 // Anchoring to the left caused the popup to clip, so anchor it to the right instead
11093 this.toggleClipping( false );
11095 .removeClass( 'oo-ui-popupToolGroup-left' )
11096 .addClass( 'oo-ui-popupToolGroup-right' );
11097 this.toggleClipping( true );
11099 if ( this.isClippedHorizontally() ) {
11100 // Anchoring to the right also caused the popup to clip, so just make it fill the container
11101 containerWidth
= this.$clippableContainer
.width();
11102 containerLeft
= this.$clippableContainer
.offset().left
;
11104 this.toggleClipping( false );
11105 this.$element
.removeClass( 'oo-ui-popupToolGroup-right' );
11107 this.$clippable
.css( {
11108 left
: -( this.$element
.offset().left
- containerLeft
),
11109 width
: containerWidth
11113 this.getElementDocument().removeEventListener( 'mouseup', this.onBlurHandler
, true );
11114 this.getElementDocument().removeEventListener( 'keyup', this.onBlurHandler
, true );
11115 this.$element
.removeClass(
11116 'oo-ui-popupToolGroup-active oo-ui-popupToolGroup-left oo-ui-popupToolGroup-right'
11118 this.toggleClipping( false );
11124 * ListToolGroups are one of three types of {@link OO.ui.ToolGroup toolgroups} that are used to
11125 * create {@link OO.ui.Toolbar toolbars} (the other types of groups are {@link OO.ui.MenuToolGroup MenuToolGroup}
11126 * and {@link OO.ui.BarToolGroup BarToolGroup}). The {@link OO.ui.Tool tools} in a ListToolGroup are displayed
11127 * by label in a dropdown menu. The title of the tool is used as the label text. The menu itself can be configured
11128 * with a label, icon, indicator, header, and title.
11130 * ListToolGroups can be configured to be expanded and collapsed. Collapsed lists will have a ‘More’ option that
11131 * users can select to see the full list of tools. If a collapsed toolgroup is expanded, a ‘Fewer’ option permits
11132 * users to collapse the list again.
11134 * ListToolGroups are created by a {@link OO.ui.ToolGroupFactory toolgroup factory} when the toolbar is set up. The factory
11135 * requires the ListToolGroup's symbolic name, 'list', which is specified along with the other configurations. For more
11136 * information about how to add tools to a ListToolGroup, please see {@link OO.ui.ToolGroup toolgroup}.
11139 * // Example of a ListToolGroup
11140 * var toolFactory = new OO.ui.ToolFactory();
11141 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
11142 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
11144 * // Configure and register two tools
11145 * function SettingsTool() {
11146 * SettingsTool.parent.apply( this, arguments );
11148 * OO.inheritClass( SettingsTool, OO.ui.Tool );
11149 * SettingsTool.static.name = 'settings';
11150 * SettingsTool.static.icon = 'settings';
11151 * SettingsTool.static.title = 'Change settings';
11152 * SettingsTool.prototype.onSelect = function () {
11153 * this.setActive( false );
11155 * toolFactory.register( SettingsTool );
11156 * // Register two more tools, nothing interesting here
11157 * function StuffTool() {
11158 * StuffTool.parent.apply( this, arguments );
11160 * OO.inheritClass( StuffTool, OO.ui.Tool );
11161 * StuffTool.static.name = 'stuff';
11162 * StuffTool.static.icon = 'ellipsis';
11163 * StuffTool.static.title = 'Change the world';
11164 * StuffTool.prototype.onSelect = function () {
11165 * this.setActive( false );
11167 * toolFactory.register( StuffTool );
11170 * // Configurations for list toolgroup.
11172 * label: 'ListToolGroup',
11173 * indicator: 'down',
11175 * title: 'This is the title, displayed when user moves the mouse over the list toolgroup',
11176 * header: 'This is the header',
11177 * include: [ 'settings', 'stuff' ],
11178 * allowCollapse: ['stuff']
11182 * // Create some UI around the toolbar and place it in the document
11183 * var frame = new OO.ui.PanelLayout( {
11187 * frame.$element.append(
11190 * $( 'body' ).append( frame.$element );
11191 * // Build the toolbar. This must be done after the toolbar has been appended to the document.
11192 * toolbar.initialize();
11194 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki][1].
11196 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
11199 * @extends OO.ui.PopupToolGroup
11202 * @param {OO.ui.Toolbar} toolbar
11203 * @param {Object} [config] Configuration options
11204 * @cfg {Array} [allowCollapse] Allow the specified tools to be collapsed. By default, collapsible tools
11205 * will only be displayed if users click the ‘More’ option displayed at the bottom of the list. If
11206 * the list is expanded, a ‘Fewer’ option permits users to collapse the list again. Any tools that
11207 * are included in the toolgroup, but are not designated as collapsible, will always be displayed.
11208 * To open a collapsible list in its expanded state, set #expanded to 'true'.
11209 * @cfg {Array} [forceExpand] Expand the specified tools. All other tools will be designated as collapsible.
11210 * Unless #expanded is set to true, the collapsible tools will be collapsed when the list is first opened.
11211 * @cfg {boolean} [expanded=false] Expand collapsible tools. This config is only relevant if tools have
11212 * been designated as collapsible. When expanded is set to true, all tools in the group will be displayed
11213 * when the list is first opened. Users can collapse the list with a ‘Fewer’ option at the bottom.
11215 OO
.ui
.ListToolGroup
= function OoUiListToolGroup( toolbar
, config
) {
11216 // Allow passing positional parameters inside the config object
11217 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
11219 toolbar
= config
.toolbar
;
11222 // Configuration initialization
11223 config
= config
|| {};
11225 // Properties (must be set before parent constructor, which calls #populate)
11226 this.allowCollapse
= config
.allowCollapse
;
11227 this.forceExpand
= config
.forceExpand
;
11228 this.expanded
= config
.expanded
!== undefined ? config
.expanded
: false;
11229 this.collapsibleTools
= [];
11231 // Parent constructor
11232 OO
.ui
.ListToolGroup
.parent
.call( this, toolbar
, config
);
11235 this.$element
.addClass( 'oo-ui-listToolGroup' );
11240 OO
.inheritClass( OO
.ui
.ListToolGroup
, OO
.ui
.PopupToolGroup
);
11242 /* Static Properties */
11244 OO
.ui
.ListToolGroup
.static.name
= 'list';
11251 OO
.ui
.ListToolGroup
.prototype.populate = function () {
11252 var i
, len
, allowCollapse
= [];
11254 OO
.ui
.ListToolGroup
.parent
.prototype.populate
.call( this );
11256 // Update the list of collapsible tools
11257 if ( this.allowCollapse
!== undefined ) {
11258 allowCollapse
= this.allowCollapse
;
11259 } else if ( this.forceExpand
!== undefined ) {
11260 allowCollapse
= OO
.simpleArrayDifference( Object
.keys( this.tools
), this.forceExpand
);
11263 this.collapsibleTools
= [];
11264 for ( i
= 0, len
= allowCollapse
.length
; i
< len
; i
++ ) {
11265 if ( this.tools
[ allowCollapse
[ i
] ] !== undefined ) {
11266 this.collapsibleTools
.push( this.tools
[ allowCollapse
[ i
] ] );
11270 // Keep at the end, even when tools are added
11271 this.$group
.append( this.getExpandCollapseTool().$element
);
11273 this.getExpandCollapseTool().toggle( this.collapsibleTools
.length
!== 0 );
11274 this.updateCollapsibleState();
11277 OO
.ui
.ListToolGroup
.prototype.getExpandCollapseTool = function () {
11278 if ( this.expandCollapseTool
=== undefined ) {
11279 var ExpandCollapseTool = function () {
11280 ExpandCollapseTool
.parent
.apply( this, arguments
);
11283 OO
.inheritClass( ExpandCollapseTool
, OO
.ui
.Tool
);
11285 ExpandCollapseTool
.prototype.onSelect = function () {
11286 this.toolGroup
.expanded
= !this.toolGroup
.expanded
;
11287 this.toolGroup
.updateCollapsibleState();
11288 this.setActive( false );
11290 ExpandCollapseTool
.prototype.onUpdateState = function () {
11291 // Do nothing. Tool interface requires an implementation of this function.
11294 ExpandCollapseTool
.static.name
= 'more-fewer';
11296 this.expandCollapseTool
= new ExpandCollapseTool( this );
11298 return this.expandCollapseTool
;
11304 OO
.ui
.ListToolGroup
.prototype.onMouseKeyUp = function ( e
) {
11305 // Do not close the popup when the user wants to show more/fewer tools
11307 $( e
.target
).closest( '.oo-ui-tool-name-more-fewer' ).length
&&
11308 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
11310 // HACK: Prevent the popup list from being hidden. Skip the PopupToolGroup implementation (which
11311 // hides the popup list when a tool is selected) and call ToolGroup's implementation directly.
11312 return OO
.ui
.ListToolGroup
.parent
.parent
.prototype.onMouseKeyUp
.call( this, e
);
11314 return OO
.ui
.ListToolGroup
.parent
.prototype.onMouseKeyUp
.call( this, e
);
11318 OO
.ui
.ListToolGroup
.prototype.updateCollapsibleState = function () {
11321 this.getExpandCollapseTool()
11322 .setIcon( this.expanded
? 'collapse' : 'expand' )
11323 .setTitle( OO
.ui
.msg( this.expanded
? 'ooui-toolgroup-collapse' : 'ooui-toolgroup-expand' ) );
11325 for ( i
= 0, len
= this.collapsibleTools
.length
; i
< len
; i
++ ) {
11326 this.collapsibleTools
[ i
].toggle( this.expanded
);
11331 * MenuToolGroups are one of three types of {@link OO.ui.ToolGroup toolgroups} that are used to
11332 * create {@link OO.ui.Toolbar toolbars} (the other types of groups are {@link OO.ui.BarToolGroup BarToolGroup}
11333 * and {@link OO.ui.ListToolGroup ListToolGroup}). MenuToolGroups contain selectable {@link OO.ui.Tool tools},
11334 * which are displayed by label in a dropdown menu. The tool's title is used as the label text, and the
11335 * menu label is updated to reflect which tool or tools are currently selected. If no tools are selected,
11336 * the menu label is empty. The menu can be configured with an indicator, icon, title, and/or header.
11338 * MenuToolGroups are created by a {@link OO.ui.ToolGroupFactory tool group factory} when the toolbar
11339 * is set up. Note that all tools must define an {@link OO.ui.Tool#onUpdateState onUpdateState} method if
11340 * a MenuToolGroup is used.
11343 * // Example of a MenuToolGroup
11344 * var toolFactory = new OO.ui.ToolFactory();
11345 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
11346 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
11348 * // We will be placing status text in this element when tools are used
11349 * var $area = $( '<p>' ).text( 'An example of a MenuToolGroup. Select a tool from the dropdown menu.' );
11351 * // Define the tools that we're going to place in our toolbar
11353 * function SettingsTool() {
11354 * SettingsTool.parent.apply( this, arguments );
11355 * this.reallyActive = false;
11357 * OO.inheritClass( SettingsTool, OO.ui.Tool );
11358 * SettingsTool.static.name = 'settings';
11359 * SettingsTool.static.icon = 'settings';
11360 * SettingsTool.static.title = 'Change settings';
11361 * SettingsTool.prototype.onSelect = function () {
11362 * $area.text( 'Settings tool clicked!' );
11363 * // Toggle the active state on each click
11364 * this.reallyActive = !this.reallyActive;
11365 * this.setActive( this.reallyActive );
11366 * // To update the menu label
11367 * this.toolbar.emit( 'updateState' );
11369 * SettingsTool.prototype.onUpdateState = function () {
11371 * toolFactory.register( SettingsTool );
11373 * function StuffTool() {
11374 * StuffTool.parent.apply( this, arguments );
11375 * this.reallyActive = false;
11377 * OO.inheritClass( StuffTool, OO.ui.Tool );
11378 * StuffTool.static.name = 'stuff';
11379 * StuffTool.static.icon = 'ellipsis';
11380 * StuffTool.static.title = 'More stuff';
11381 * StuffTool.prototype.onSelect = function () {
11382 * $area.text( 'More stuff tool clicked!' );
11383 * // Toggle the active state on each click
11384 * this.reallyActive = !this.reallyActive;
11385 * this.setActive( this.reallyActive );
11386 * // To update the menu label
11387 * this.toolbar.emit( 'updateState' );
11389 * StuffTool.prototype.onUpdateState = function () {
11391 * toolFactory.register( StuffTool );
11393 * // Finally define which tools and in what order appear in the toolbar. Each tool may only be
11394 * // used once (but not all defined tools must be used).
11398 * header: 'This is the (optional) header',
11399 * title: 'This is the (optional) title',
11400 * indicator: 'down',
11401 * include: [ 'settings', 'stuff' ]
11405 * // Create some UI around the toolbar and place it in the document
11406 * var frame = new OO.ui.PanelLayout( {
11410 * var contentFrame = new OO.ui.PanelLayout( {
11414 * frame.$element.append(
11415 * toolbar.$element,
11416 * contentFrame.$element.append( $area )
11418 * $( 'body' ).append( frame.$element );
11420 * // Here is where the toolbar is actually built. This must be done after inserting it into the
11422 * toolbar.initialize();
11423 * toolbar.emit( 'updateState' );
11425 * For more information about how to add tools to a MenuToolGroup, please see {@link OO.ui.ToolGroup toolgroup}.
11426 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki] [1].
11428 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
11431 * @extends OO.ui.PopupToolGroup
11434 * @param {OO.ui.Toolbar} toolbar
11435 * @param {Object} [config] Configuration options
11437 OO
.ui
.MenuToolGroup
= function OoUiMenuToolGroup( toolbar
, config
) {
11438 // Allow passing positional parameters inside the config object
11439 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
11441 toolbar
= config
.toolbar
;
11444 // Configuration initialization
11445 config
= config
|| {};
11447 // Parent constructor
11448 OO
.ui
.MenuToolGroup
.parent
.call( this, toolbar
, config
);
11451 this.toolbar
.connect( this, { updateState
: 'onUpdateState' } );
11454 this.$element
.addClass( 'oo-ui-menuToolGroup' );
11459 OO
.inheritClass( OO
.ui
.MenuToolGroup
, OO
.ui
.PopupToolGroup
);
11461 /* Static Properties */
11463 OO
.ui
.MenuToolGroup
.static.name
= 'menu';
11468 * Handle the toolbar state being updated.
11470 * When the state changes, the title of each active item in the menu will be joined together and
11471 * used as a label for the group. The label will be empty if none of the items are active.
11475 OO
.ui
.MenuToolGroup
.prototype.onUpdateState = function () {
11479 for ( name
in this.tools
) {
11480 if ( this.tools
[ name
].isActive() ) {
11481 labelTexts
.push( this.tools
[ name
].getTitle() );
11485 this.setLabel( labelTexts
.join( ', ' ) || ' ' );
11489 * Popup tools open a popup window when they are selected from the {@link OO.ui.Toolbar toolbar}. Each popup tool is configured
11490 * with a static name, title, and icon, as well with as any popup configurations. Unlike other tools, popup tools do not require that developers specify
11491 * an #onSelect or #onUpdateState method, as these methods have been implemented already.
11493 * // Example of a popup tool. When selected, a popup tool displays
11494 * // a popup window.
11495 * function HelpTool( toolGroup, config ) {
11496 * OO.ui.PopupTool.call( this, toolGroup, $.extend( { popup: {
11501 * this.popup.$body.append( '<p>I am helpful!</p>' );
11503 * OO.inheritClass( HelpTool, OO.ui.PopupTool );
11504 * HelpTool.static.name = 'help';
11505 * HelpTool.static.icon = 'help';
11506 * HelpTool.static.title = 'Help';
11507 * toolFactory.register( HelpTool );
11509 * For an example of a toolbar that contains a popup tool, see {@link OO.ui.Toolbar toolbars}. For more information about
11510 * toolbars in genreral, please see the [OOjs UI documentation on MediaWiki][1].
11512 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
11516 * @extends OO.ui.Tool
11517 * @mixins OO.ui.mixin.PopupElement
11520 * @param {OO.ui.ToolGroup} toolGroup
11521 * @param {Object} [config] Configuration options
11523 OO
.ui
.PopupTool
= function OoUiPopupTool( toolGroup
, config
) {
11524 // Allow passing positional parameters inside the config object
11525 if ( OO
.isPlainObject( toolGroup
) && config
=== undefined ) {
11526 config
= toolGroup
;
11527 toolGroup
= config
.toolGroup
;
11530 // Parent constructor
11531 OO
.ui
.PopupTool
.parent
.call( this, toolGroup
, config
);
11533 // Mixin constructors
11534 OO
.ui
.mixin
.PopupElement
.call( this, config
);
11538 .addClass( 'oo-ui-popupTool' )
11539 .append( this.popup
.$element
);
11544 OO
.inheritClass( OO
.ui
.PopupTool
, OO
.ui
.Tool
);
11545 OO
.mixinClass( OO
.ui
.PopupTool
, OO
.ui
.mixin
.PopupElement
);
11550 * Handle the tool being selected.
11554 OO
.ui
.PopupTool
.prototype.onSelect = function () {
11555 if ( !this.isDisabled() ) {
11556 this.popup
.toggle();
11558 this.setActive( false );
11563 * Handle the toolbar state being updated.
11567 OO
.ui
.PopupTool
.prototype.onUpdateState = function () {
11568 this.setActive( false );
11572 * A ToolGroupTool is a special sort of tool that can contain other {@link OO.ui.Tool tools}
11573 * and {@link OO.ui.ToolGroup toolgroups}. The ToolGroupTool was specifically designed to be used
11574 * inside a {@link OO.ui.BarToolGroup bar} toolgroup to provide access to additional tools from
11575 * the bar item. Included tools will be displayed in a dropdown {@link OO.ui.ListToolGroup list}
11576 * when the ToolGroupTool is selected.
11578 * // Example: ToolGroupTool with two nested tools, 'setting1' and 'setting2', defined elsewhere.
11580 * function SettingsTool() {
11581 * SettingsTool.parent.apply( this, arguments );
11583 * OO.inheritClass( SettingsTool, OO.ui.ToolGroupTool );
11584 * SettingsTool.static.name = 'settings';
11585 * SettingsTool.static.title = 'Change settings';
11586 * SettingsTool.static.groupConfig = {
11587 * icon: 'settings',
11588 * label: 'ToolGroupTool',
11589 * include: [ 'setting1', 'setting2' ]
11591 * toolFactory.register( SettingsTool );
11593 * For more information, please see the [OOjs UI documentation on MediaWiki][1].
11595 * Please note that this implementation is subject to change per [T74159] [2].
11597 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars#ToolGroupTool
11598 * [2]: https://phabricator.wikimedia.org/T74159
11602 * @extends OO.ui.Tool
11605 * @param {OO.ui.ToolGroup} toolGroup
11606 * @param {Object} [config] Configuration options
11608 OO
.ui
.ToolGroupTool
= function OoUiToolGroupTool( toolGroup
, config
) {
11609 // Allow passing positional parameters inside the config object
11610 if ( OO
.isPlainObject( toolGroup
) && config
=== undefined ) {
11611 config
= toolGroup
;
11612 toolGroup
= config
.toolGroup
;
11615 // Parent constructor
11616 OO
.ui
.ToolGroupTool
.parent
.call( this, toolGroup
, config
);
11619 this.innerToolGroup
= this.createGroup( this.constructor.static.groupConfig
);
11622 this.innerToolGroup
.connect( this, { disable
: 'onToolGroupDisable' } );
11625 this.$link
.remove();
11627 .addClass( 'oo-ui-toolGroupTool' )
11628 .append( this.innerToolGroup
.$element
);
11633 OO
.inheritClass( OO
.ui
.ToolGroupTool
, OO
.ui
.Tool
);
11635 /* Static Properties */
11638 * Toolgroup configuration.
11640 * The toolgroup configuration consists of the tools to include, as well as an icon and label
11641 * to use for the bar item. Tools can be included by symbolic name, group, or with the
11642 * wildcard selector. Please see {@link OO.ui.ToolGroup toolgroup} for more information.
11644 * @property {Object.<string,Array>}
11646 OO
.ui
.ToolGroupTool
.static.groupConfig
= {};
11651 * Handle the tool being selected.
11655 OO
.ui
.ToolGroupTool
.prototype.onSelect = function () {
11656 this.innerToolGroup
.setActive( !this.innerToolGroup
.active
);
11661 * Synchronize disabledness state of the tool with the inner toolgroup.
11664 * @param {boolean} disabled Element is disabled
11666 OO
.ui
.ToolGroupTool
.prototype.onToolGroupDisable = function ( disabled
) {
11667 this.setDisabled( disabled
);
11671 * Handle the toolbar state being updated.
11675 OO
.ui
.ToolGroupTool
.prototype.onUpdateState = function () {
11676 this.setActive( false );
11680 * Build a {@link OO.ui.ToolGroup toolgroup} from the specified configuration.
11682 * @param {Object.<string,Array>} group Toolgroup configuration. Please see {@link OO.ui.ToolGroup toolgroup} for
11683 * more information.
11684 * @return {OO.ui.ListToolGroup}
11686 OO
.ui
.ToolGroupTool
.prototype.createGroup = function ( group
) {
11687 if ( group
.include
=== '*' ) {
11688 // Apply defaults to catch-all groups
11689 if ( group
.label
=== undefined ) {
11690 group
.label
= OO
.ui
.msg( 'ooui-toolbar-more' );
11694 return this.toolbar
.getToolGroupFactory().create( 'list', this.toolbar
, group
);
11698 * Mixin for OO.ui.Widget subclasses to provide OO.ui.mixin.GroupElement.
11700 * Use together with OO.ui.mixin.ItemWidget to make disabled state inheritable.
11705 * @extends OO.ui.mixin.GroupElement
11708 * @param {Object} [config] Configuration options
11710 OO
.ui
.mixin
.GroupWidget
= function OoUiMixinGroupWidget( config
) {
11711 // Parent constructor
11712 OO
.ui
.mixin
.GroupWidget
.parent
.call( this, config
);
11717 OO
.inheritClass( OO
.ui
.mixin
.GroupWidget
, OO
.ui
.mixin
.GroupElement
);
11722 * Set the disabled state of the widget.
11724 * This will also update the disabled state of child widgets.
11726 * @param {boolean} disabled Disable widget
11729 OO
.ui
.mixin
.GroupWidget
.prototype.setDisabled = function ( disabled
) {
11733 // Note: Calling #setDisabled this way assumes this is mixed into an OO.ui.Widget
11734 OO
.ui
.Widget
.prototype.setDisabled
.call( this, disabled
);
11736 // During construction, #setDisabled is called before the OO.ui.mixin.GroupElement constructor
11737 if ( this.items
) {
11738 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
11739 this.items
[ i
].updateDisabled();
11747 * Mixin for widgets used as items in widgets that mix in OO.ui.mixin.GroupWidget.
11749 * Item widgets have a reference to a OO.ui.mixin.GroupWidget while they are attached to the group. This
11750 * allows bidirectional communication.
11752 * Use together with OO.ui.mixin.GroupWidget to make disabled state inheritable.
11760 OO
.ui
.mixin
.ItemWidget
= function OoUiMixinItemWidget() {
11767 * Check if widget is disabled.
11769 * Checks parent if present, making disabled state inheritable.
11771 * @return {boolean} Widget is disabled
11773 OO
.ui
.mixin
.ItemWidget
.prototype.isDisabled = function () {
11774 return this.disabled
||
11775 ( this.elementGroup
instanceof OO
.ui
.Widget
&& this.elementGroup
.isDisabled() );
11779 * Set group element is in.
11781 * @param {OO.ui.mixin.GroupElement|null} group Group element, null if none
11784 OO
.ui
.mixin
.ItemWidget
.prototype.setElementGroup = function ( group
) {
11786 // Note: Calling #setElementGroup this way assumes this is mixed into an OO.ui.Element
11787 OO
.ui
.Element
.prototype.setElementGroup
.call( this, group
);
11789 // Initialize item disabled states
11790 this.updateDisabled();
11796 * OutlineControlsWidget is a set of controls for an {@link OO.ui.OutlineSelectWidget outline select widget}.
11797 * Controls include moving items up and down, removing items, and adding different kinds of items.
11799 * **Currently, this class is only used by {@link OO.ui.BookletLayout booklet layouts}.**
11802 * @extends OO.ui.Widget
11803 * @mixins OO.ui.mixin.GroupElement
11804 * @mixins OO.ui.mixin.IconElement
11807 * @param {OO.ui.OutlineSelectWidget} outline Outline to control
11808 * @param {Object} [config] Configuration options
11809 * @cfg {Object} [abilities] List of abilties
11810 * @cfg {boolean} [abilities.move=true] Allow moving movable items
11811 * @cfg {boolean} [abilities.remove=true] Allow removing removable items
11813 OO
.ui
.OutlineControlsWidget
= function OoUiOutlineControlsWidget( outline
, config
) {
11814 // Allow passing positional parameters inside the config object
11815 if ( OO
.isPlainObject( outline
) && config
=== undefined ) {
11817 outline
= config
.outline
;
11820 // Configuration initialization
11821 config
= $.extend( { icon
: 'add' }, config
);
11823 // Parent constructor
11824 OO
.ui
.OutlineControlsWidget
.parent
.call( this, config
);
11826 // Mixin constructors
11827 OO
.ui
.mixin
.GroupElement
.call( this, config
);
11828 OO
.ui
.mixin
.IconElement
.call( this, config
);
11831 this.outline
= outline
;
11832 this.$movers
= $( '<div>' );
11833 this.upButton
= new OO
.ui
.ButtonWidget( {
11836 title
: OO
.ui
.msg( 'ooui-outline-control-move-up' )
11838 this.downButton
= new OO
.ui
.ButtonWidget( {
11841 title
: OO
.ui
.msg( 'ooui-outline-control-move-down' )
11843 this.removeButton
= new OO
.ui
.ButtonWidget( {
11846 title
: OO
.ui
.msg( 'ooui-outline-control-remove' )
11848 this.abilities
= { move: true, remove
: true };
11851 outline
.connect( this, {
11852 select
: 'onOutlineChange',
11853 add
: 'onOutlineChange',
11854 remove
: 'onOutlineChange'
11856 this.upButton
.connect( this, { click
: [ 'emit', 'move', -1 ] } );
11857 this.downButton
.connect( this, { click
: [ 'emit', 'move', 1 ] } );
11858 this.removeButton
.connect( this, { click
: [ 'emit', 'remove' ] } );
11861 this.$element
.addClass( 'oo-ui-outlineControlsWidget' );
11862 this.$group
.addClass( 'oo-ui-outlineControlsWidget-items' );
11864 .addClass( 'oo-ui-outlineControlsWidget-movers' )
11865 .append( this.removeButton
.$element
, this.upButton
.$element
, this.downButton
.$element
);
11866 this.$element
.append( this.$icon
, this.$group
, this.$movers
);
11867 this.setAbilities( config
.abilities
|| {} );
11872 OO
.inheritClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.Widget
);
11873 OO
.mixinClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.mixin
.GroupElement
);
11874 OO
.mixinClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.mixin
.IconElement
);
11880 * @param {number} places Number of places to move
11892 * @param {Object} abilities List of abilties
11893 * @param {boolean} [abilities.move] Allow moving movable items
11894 * @param {boolean} [abilities.remove] Allow removing removable items
11896 OO
.ui
.OutlineControlsWidget
.prototype.setAbilities = function ( abilities
) {
11899 for ( ability
in this.abilities
) {
11900 if ( abilities
[ability
] !== undefined ) {
11901 this.abilities
[ability
] = !!abilities
[ability
];
11905 this.onOutlineChange();
11911 * Handle outline change events.
11913 OO
.ui
.OutlineControlsWidget
.prototype.onOutlineChange = function () {
11914 var i
, len
, firstMovable
, lastMovable
,
11915 items
= this.outline
.getItems(),
11916 selectedItem
= this.outline
.getSelectedItem(),
11917 movable
= this.abilities
.move && selectedItem
&& selectedItem
.isMovable(),
11918 removable
= this.abilities
.remove
&& selectedItem
&& selectedItem
.isRemovable();
11922 len
= items
.length
;
11923 while ( ++i
< len
) {
11924 if ( items
[ i
].isMovable() ) {
11925 firstMovable
= items
[ i
];
11931 if ( items
[ i
].isMovable() ) {
11932 lastMovable
= items
[ i
];
11937 this.upButton
.setDisabled( !movable
|| selectedItem
=== firstMovable
);
11938 this.downButton
.setDisabled( !movable
|| selectedItem
=== lastMovable
);
11939 this.removeButton
.setDisabled( !removable
);
11943 * ToggleWidget implements basic behavior of widgets with an on/off state.
11944 * Please see OO.ui.ToggleButtonWidget and OO.ui.ToggleSwitchWidget for examples.
11948 * @extends OO.ui.Widget
11951 * @param {Object} [config] Configuration options
11952 * @cfg {boolean} [value=false] The toggle’s initial on/off state.
11953 * By default, the toggle is in the 'off' state.
11955 OO
.ui
.ToggleWidget
= function OoUiToggleWidget( config
) {
11956 // Configuration initialization
11957 config
= config
|| {};
11959 // Parent constructor
11960 OO
.ui
.ToggleWidget
.parent
.call( this, config
);
11966 this.$element
.addClass( 'oo-ui-toggleWidget' );
11967 this.setValue( !!config
.value
);
11972 OO
.inheritClass( OO
.ui
.ToggleWidget
, OO
.ui
.Widget
);
11979 * A change event is emitted when the on/off state of the toggle changes.
11981 * @param {boolean} value Value representing the new state of the toggle
11987 * Get the value representing the toggle’s state.
11989 * @return {boolean} The on/off state of the toggle
11991 OO
.ui
.ToggleWidget
.prototype.getValue = function () {
11996 * Set the state of the toggle: `true` for 'on', `false' for 'off'.
11998 * @param {boolean} value The state of the toggle
12002 OO
.ui
.ToggleWidget
.prototype.setValue = function ( value
) {
12004 if ( this.value
!== value
) {
12005 this.value
= value
;
12006 this.emit( 'change', value
);
12007 this.$element
.toggleClass( 'oo-ui-toggleWidget-on', value
);
12008 this.$element
.toggleClass( 'oo-ui-toggleWidget-off', !value
);
12009 this.$element
.attr( 'aria-checked', value
.toString() );
12015 * A ButtonGroupWidget groups related buttons and is used together with OO.ui.ButtonWidget and
12016 * its subclasses. Each button in a group is addressed by a unique reference. Buttons can be added,
12017 * removed, and cleared from the group.
12020 * // Example: A ButtonGroupWidget with two buttons
12021 * var button1 = new OO.ui.PopupButtonWidget( {
12022 * label: 'Select a category',
12025 * $content: $( '<p>List of categories...</p>' ),
12030 * var button2 = new OO.ui.ButtonWidget( {
12031 * label: 'Add item'
12033 * var buttonGroup = new OO.ui.ButtonGroupWidget( {
12034 * items: [button1, button2]
12036 * $( 'body' ).append( buttonGroup.$element );
12039 * @extends OO.ui.Widget
12040 * @mixins OO.ui.mixin.GroupElement
12043 * @param {Object} [config] Configuration options
12044 * @cfg {OO.ui.ButtonWidget[]} [items] Buttons to add
12046 OO
.ui
.ButtonGroupWidget
= function OoUiButtonGroupWidget( config
) {
12047 // Configuration initialization
12048 config
= config
|| {};
12050 // Parent constructor
12051 OO
.ui
.ButtonGroupWidget
.parent
.call( this, config
);
12053 // Mixin constructors
12054 OO
.ui
.mixin
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
12057 this.$element
.addClass( 'oo-ui-buttonGroupWidget' );
12058 if ( Array
.isArray( config
.items
) ) {
12059 this.addItems( config
.items
);
12065 OO
.inheritClass( OO
.ui
.ButtonGroupWidget
, OO
.ui
.Widget
);
12066 OO
.mixinClass( OO
.ui
.ButtonGroupWidget
, OO
.ui
.mixin
.GroupElement
);
12069 * ButtonWidget is a generic widget for buttons. A wide variety of looks,
12070 * feels, and functionality can be customized via the class’s configuration options
12071 * and methods. Please see the [OOjs UI documentation on MediaWiki] [1] for more information
12074 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Buttons_and_Switches
12077 * // A button widget
12078 * var button = new OO.ui.ButtonWidget( {
12079 * label: 'Button with Icon',
12081 * iconTitle: 'Remove'
12083 * $( 'body' ).append( button.$element );
12085 * NOTE: HTML form buttons should use the OO.ui.ButtonInputWidget class.
12088 * @extends OO.ui.Widget
12089 * @mixins OO.ui.mixin.ButtonElement
12090 * @mixins OO.ui.mixin.IconElement
12091 * @mixins OO.ui.mixin.IndicatorElement
12092 * @mixins OO.ui.mixin.LabelElement
12093 * @mixins OO.ui.mixin.TitledElement
12094 * @mixins OO.ui.mixin.FlaggedElement
12095 * @mixins OO.ui.mixin.TabIndexedElement
12098 * @param {Object} [config] Configuration options
12099 * @cfg {string} [href] Hyperlink to visit when the button is clicked.
12100 * @cfg {string} [target] The frame or window in which to open the hyperlink.
12101 * @cfg {boolean} [noFollow] Search engine traversal hint (default: true)
12103 OO
.ui
.ButtonWidget
= function OoUiButtonWidget( config
) {
12104 // Configuration initialization
12105 config
= config
|| {};
12107 // Parent constructor
12108 OO
.ui
.ButtonWidget
.parent
.call( this, config
);
12110 // Mixin constructors
12111 OO
.ui
.mixin
.ButtonElement
.call( this, config
);
12112 OO
.ui
.mixin
.IconElement
.call( this, config
);
12113 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
12114 OO
.ui
.mixin
.LabelElement
.call( this, config
);
12115 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$button
} ) );
12116 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
12117 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$button
} ) );
12121 this.target
= null;
12122 this.noFollow
= false;
12125 this.connect( this, { disable
: 'onDisable' } );
12128 this.$button
.append( this.$icon
, this.$label
, this.$indicator
);
12130 .addClass( 'oo-ui-buttonWidget' )
12131 .append( this.$button
);
12132 this.setHref( config
.href
);
12133 this.setTarget( config
.target
);
12134 this.setNoFollow( config
.noFollow
);
12139 OO
.inheritClass( OO
.ui
.ButtonWidget
, OO
.ui
.Widget
);
12140 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.ButtonElement
);
12141 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.IconElement
);
12142 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.IndicatorElement
);
12143 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.LabelElement
);
12144 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.TitledElement
);
12145 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.FlaggedElement
);
12146 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.TabIndexedElement
);
12153 OO
.ui
.ButtonWidget
.prototype.onMouseDown = function ( e
) {
12154 if ( !this.isDisabled() ) {
12155 // Remove the tab-index while the button is down to prevent the button from stealing focus
12156 this.$button
.removeAttr( 'tabindex' );
12159 return OO
.ui
.mixin
.ButtonElement
.prototype.onMouseDown
.call( this, e
);
12165 OO
.ui
.ButtonWidget
.prototype.onMouseUp = function ( e
) {
12166 if ( !this.isDisabled() ) {
12167 // Restore the tab-index after the button is up to restore the button's accessibility
12168 this.$button
.attr( 'tabindex', this.tabIndex
);
12171 return OO
.ui
.mixin
.ButtonElement
.prototype.onMouseUp
.call( this, e
);
12175 * Get hyperlink location.
12177 * @return {string} Hyperlink location
12179 OO
.ui
.ButtonWidget
.prototype.getHref = function () {
12184 * Get hyperlink target.
12186 * @return {string} Hyperlink target
12188 OO
.ui
.ButtonWidget
.prototype.getTarget = function () {
12189 return this.target
;
12193 * Get search engine traversal hint.
12195 * @return {boolean} Whether search engines should avoid traversing this hyperlink
12197 OO
.ui
.ButtonWidget
.prototype.getNoFollow = function () {
12198 return this.noFollow
;
12202 * Set hyperlink location.
12204 * @param {string|null} href Hyperlink location, null to remove
12206 OO
.ui
.ButtonWidget
.prototype.setHref = function ( href
) {
12207 href
= typeof href
=== 'string' ? href
: null;
12208 if ( href
!== null ) {
12209 if ( !OO
.ui
.isSafeUrl( href
) ) {
12210 throw new Error( 'Potentially unsafe href provided: ' + href
);
12215 if ( href
!== this.href
) {
12224 * Update the `href` attribute, in case of changes to href or
12230 OO
.ui
.ButtonWidget
.prototype.updateHref = function () {
12231 if ( this.href
!== null && !this.isDisabled() ) {
12232 this.$button
.attr( 'href', this.href
);
12234 this.$button
.removeAttr( 'href' );
12241 * Handle disable events.
12244 * @param {boolean} disabled Element is disabled
12246 OO
.ui
.ButtonWidget
.prototype.onDisable = function () {
12251 * Set hyperlink target.
12253 * @param {string|null} target Hyperlink target, null to remove
12255 OO
.ui
.ButtonWidget
.prototype.setTarget = function ( target
) {
12256 target
= typeof target
=== 'string' ? target
: null;
12258 if ( target
!== this.target
) {
12259 this.target
= target
;
12260 if ( target
!== null ) {
12261 this.$button
.attr( 'target', target
);
12263 this.$button
.removeAttr( 'target' );
12271 * Set search engine traversal hint.
12273 * @param {boolean} noFollow True if search engines should avoid traversing this hyperlink
12275 OO
.ui
.ButtonWidget
.prototype.setNoFollow = function ( noFollow
) {
12276 noFollow
= typeof noFollow
=== 'boolean' ? noFollow
: true;
12278 if ( noFollow
!== this.noFollow
) {
12279 this.noFollow
= noFollow
;
12281 this.$button
.attr( 'rel', 'nofollow' );
12283 this.$button
.removeAttr( 'rel' );
12291 * An ActionWidget is a {@link OO.ui.ButtonWidget button widget} that executes an action.
12292 * Action widgets are used with OO.ui.ActionSet, which manages the behavior and availability
12295 * Both actions and action sets are primarily used with {@link OO.ui.Dialog Dialogs}.
12296 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information
12299 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs#Action_sets
12302 * @extends OO.ui.ButtonWidget
12303 * @mixins OO.ui.mixin.PendingElement
12306 * @param {Object} [config] Configuration options
12307 * @cfg {string} [action] Symbolic name of the action (e.g., ‘continue’ or ‘cancel’).
12308 * @cfg {string[]} [modes] Symbolic names of the modes (e.g., ‘edit’ or ‘read’) in which the action
12309 * should be made available. See the action set's {@link OO.ui.ActionSet#setMode setMode} method
12310 * for more information about setting modes.
12311 * @cfg {boolean} [framed=false] Render the action button with a frame
12313 OO
.ui
.ActionWidget
= function OoUiActionWidget( config
) {
12314 // Configuration initialization
12315 config
= $.extend( { framed
: false }, config
);
12317 // Parent constructor
12318 OO
.ui
.ActionWidget
.parent
.call( this, config
);
12320 // Mixin constructors
12321 OO
.ui
.mixin
.PendingElement
.call( this, config
);
12324 this.action
= config
.action
|| '';
12325 this.modes
= config
.modes
|| [];
12330 this.$element
.addClass( 'oo-ui-actionWidget' );
12335 OO
.inheritClass( OO
.ui
.ActionWidget
, OO
.ui
.ButtonWidget
);
12336 OO
.mixinClass( OO
.ui
.ActionWidget
, OO
.ui
.mixin
.PendingElement
);
12341 * A resize event is emitted when the size of the widget changes.
12349 * Check if the action is configured to be available in the specified `mode`.
12351 * @param {string} mode Name of mode
12352 * @return {boolean} The action is configured with the mode
12354 OO
.ui
.ActionWidget
.prototype.hasMode = function ( mode
) {
12355 return this.modes
.indexOf( mode
) !== -1;
12359 * Get the symbolic name of the action (e.g., ‘continue’ or ‘cancel’).
12363 OO
.ui
.ActionWidget
.prototype.getAction = function () {
12364 return this.action
;
12368 * Get the symbolic name of the mode or modes for which the action is configured to be available.
12370 * The current mode is set with the action set's {@link OO.ui.ActionSet#setMode setMode} method.
12371 * Only actions that are configured to be avaiable in the current mode will be visible. All other actions
12374 * @return {string[]}
12376 OO
.ui
.ActionWidget
.prototype.getModes = function () {
12377 return this.modes
.slice();
12381 * Emit a resize event if the size has changed.
12386 OO
.ui
.ActionWidget
.prototype.propagateResize = function () {
12389 if ( this.isElementAttached() ) {
12390 width
= this.$element
.width();
12391 height
= this.$element
.height();
12393 if ( width
!== this.width
|| height
!== this.height
) {
12394 this.width
= width
;
12395 this.height
= height
;
12396 this.emit( 'resize' );
12406 OO
.ui
.ActionWidget
.prototype.setIcon = function () {
12408 OO
.ui
.mixin
.IconElement
.prototype.setIcon
.apply( this, arguments
);
12409 this.propagateResize();
12417 OO
.ui
.ActionWidget
.prototype.setLabel = function () {
12419 OO
.ui
.mixin
.LabelElement
.prototype.setLabel
.apply( this, arguments
);
12420 this.propagateResize();
12428 OO
.ui
.ActionWidget
.prototype.setFlags = function () {
12430 OO
.ui
.mixin
.FlaggedElement
.prototype.setFlags
.apply( this, arguments
);
12431 this.propagateResize();
12439 OO
.ui
.ActionWidget
.prototype.clearFlags = function () {
12441 OO
.ui
.mixin
.FlaggedElement
.prototype.clearFlags
.apply( this, arguments
);
12442 this.propagateResize();
12448 * Toggle the visibility of the action button.
12450 * @param {boolean} [show] Show button, omit to toggle visibility
12453 OO
.ui
.ActionWidget
.prototype.toggle = function () {
12455 OO
.ui
.ActionWidget
.parent
.prototype.toggle
.apply( this, arguments
);
12456 this.propagateResize();
12462 * PopupButtonWidgets toggle the visibility of a contained {@link OO.ui.PopupWidget PopupWidget},
12463 * which is used to display additional information or options.
12466 * // Example of a popup button.
12467 * var popupButton = new OO.ui.PopupButtonWidget( {
12468 * label: 'Popup button with options',
12471 * $content: $( '<p>Additional options here.</p>' ),
12473 * align: 'force-left'
12476 * // Append the button to the DOM.
12477 * $( 'body' ).append( popupButton.$element );
12480 * @extends OO.ui.ButtonWidget
12481 * @mixins OO.ui.mixin.PopupElement
12484 * @param {Object} [config] Configuration options
12486 OO
.ui
.PopupButtonWidget
= function OoUiPopupButtonWidget( config
) {
12487 // Parent constructor
12488 OO
.ui
.PopupButtonWidget
.parent
.call( this, config
);
12490 // Mixin constructors
12491 OO
.ui
.mixin
.PopupElement
.call( this, config
);
12494 this.connect( this, { click
: 'onAction' } );
12498 .addClass( 'oo-ui-popupButtonWidget' )
12499 .attr( 'aria-haspopup', 'true' )
12500 .append( this.popup
.$element
);
12505 OO
.inheritClass( OO
.ui
.PopupButtonWidget
, OO
.ui
.ButtonWidget
);
12506 OO
.mixinClass( OO
.ui
.PopupButtonWidget
, OO
.ui
.mixin
.PopupElement
);
12511 * Handle the button action being triggered.
12515 OO
.ui
.PopupButtonWidget
.prototype.onAction = function () {
12516 this.popup
.toggle();
12520 * ToggleButtons are buttons that have a state (‘on’ or ‘off’) that is represented by a
12521 * Boolean value. Like other {@link OO.ui.ButtonWidget buttons}, toggle buttons can be
12522 * configured with {@link OO.ui.mixin.IconElement icons}, {@link OO.ui.mixin.IndicatorElement indicators},
12523 * {@link OO.ui.mixin.TitledElement titles}, {@link OO.ui.mixin.FlaggedElement styling flags},
12524 * and {@link OO.ui.mixin.LabelElement labels}. Please see
12525 * the [OOjs UI documentation][1] on MediaWiki for more information.
12528 * // Toggle buttons in the 'off' and 'on' state.
12529 * var toggleButton1 = new OO.ui.ToggleButtonWidget( {
12530 * label: 'Toggle Button off'
12532 * var toggleButton2 = new OO.ui.ToggleButtonWidget( {
12533 * label: 'Toggle Button on',
12536 * // Append the buttons to the DOM.
12537 * $( 'body' ).append( toggleButton1.$element, toggleButton2.$element );
12539 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Buttons_and_Switches#Toggle_buttons
12542 * @extends OO.ui.ToggleWidget
12543 * @mixins OO.ui.mixin.ButtonElement
12544 * @mixins OO.ui.mixin.IconElement
12545 * @mixins OO.ui.mixin.IndicatorElement
12546 * @mixins OO.ui.mixin.LabelElement
12547 * @mixins OO.ui.mixin.TitledElement
12548 * @mixins OO.ui.mixin.FlaggedElement
12549 * @mixins OO.ui.mixin.TabIndexedElement
12552 * @param {Object} [config] Configuration options
12553 * @cfg {boolean} [value=false] The toggle button’s initial on/off
12554 * state. By default, the button is in the 'off' state.
12556 OO
.ui
.ToggleButtonWidget
= function OoUiToggleButtonWidget( config
) {
12557 // Configuration initialization
12558 config
= config
|| {};
12560 // Parent constructor
12561 OO
.ui
.ToggleButtonWidget
.parent
.call( this, config
);
12563 // Mixin constructors
12564 OO
.ui
.mixin
.ButtonElement
.call( this, config
);
12565 OO
.ui
.mixin
.IconElement
.call( this, config
);
12566 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
12567 OO
.ui
.mixin
.LabelElement
.call( this, config
);
12568 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$button
} ) );
12569 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
12570 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$button
} ) );
12573 this.connect( this, { click
: 'onAction' } );
12576 this.$button
.append( this.$icon
, this.$label
, this.$indicator
);
12578 .addClass( 'oo-ui-toggleButtonWidget' )
12579 .append( this.$button
);
12584 OO
.inheritClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.ToggleWidget
);
12585 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.ButtonElement
);
12586 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.IconElement
);
12587 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.IndicatorElement
);
12588 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.LabelElement
);
12589 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.TitledElement
);
12590 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.FlaggedElement
);
12591 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.TabIndexedElement
);
12596 * Handle the button action being triggered.
12600 OO
.ui
.ToggleButtonWidget
.prototype.onAction = function () {
12601 this.setValue( !this.value
);
12607 OO
.ui
.ToggleButtonWidget
.prototype.setValue = function ( value
) {
12609 if ( value
!== this.value
) {
12610 // Might be called from parent constructor before ButtonElement constructor
12611 if ( this.$button
) {
12612 this.$button
.attr( 'aria-pressed', value
.toString() );
12614 this.setActive( value
);
12618 OO
.ui
.ToggleButtonWidget
.parent
.prototype.setValue
.call( this, value
);
12626 OO
.ui
.ToggleButtonWidget
.prototype.setButtonElement = function ( $button
) {
12627 if ( this.$button
) {
12628 this.$button
.removeAttr( 'aria-pressed' );
12630 OO
.ui
.mixin
.ButtonElement
.prototype.setButtonElement
.call( this, $button
);
12631 this.$button
.attr( 'aria-pressed', this.value
.toString() );
12635 * CapsuleMultiSelectWidgets are something like a {@link OO.ui.ComboBoxWidget combo box widget}
12636 * that allows for selecting multiple values.
12638 * For more information about menus and options, please see the [OOjs UI documentation on MediaWiki][1].
12641 * // Example: A CapsuleMultiSelectWidget.
12642 * var capsule = new OO.ui.CapsuleMultiSelectWidget( {
12643 * label: 'CapsuleMultiSelectWidget',
12644 * selected: [ 'Option 1', 'Option 3' ],
12647 * new OO.ui.MenuOptionWidget( {
12648 * data: 'Option 1',
12649 * label: 'Option One'
12651 * new OO.ui.MenuOptionWidget( {
12652 * data: 'Option 2',
12653 * label: 'Option Two'
12655 * new OO.ui.MenuOptionWidget( {
12656 * data: 'Option 3',
12657 * label: 'Option Three'
12659 * new OO.ui.MenuOptionWidget( {
12660 * data: 'Option 4',
12661 * label: 'Option Four'
12663 * new OO.ui.MenuOptionWidget( {
12664 * data: 'Option 5',
12665 * label: 'Option Five'
12670 * $( 'body' ).append( capsule.$element );
12672 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Menu_selects_and_options
12675 * @extends OO.ui.Widget
12676 * @mixins OO.ui.mixin.TabIndexedElement
12677 * @mixins OO.ui.mixin.GroupElement
12680 * @param {Object} [config] Configuration options
12681 * @cfg {boolean} [allowArbitrary=false] Allow data items to be added even if not present in the menu.
12682 * @cfg {Object} [menu] Configuration options to pass to the {@link OO.ui.MenuSelectWidget menu select widget}.
12683 * @cfg {Object} [popup] Configuration options to pass to the {@link OO.ui.PopupWidget popup widget}.
12684 * If specified, this popup will be shown instead of the menu (but the menu
12685 * will still be used for item labels and allowArbitrary=false). The widgets
12686 * in the popup should use this.addItemsFromData() or this.addItems() as necessary.
12687 * @cfg {jQuery} [$overlay] Render the menu or popup into a separate layer.
12688 * This configuration is useful in cases where the expanded menu is larger than
12689 * its containing `<div>`. The specified overlay layer is usually on top of
12690 * the containing `<div>` and has a larger area. By default, the menu uses
12691 * relative positioning.
12693 OO
.ui
.CapsuleMultiSelectWidget
= function OoUiCapsuleMultiSelectWidget( config
) {
12696 // Configuration initialization
12697 config
= config
|| {};
12699 // Parent constructor
12700 OO
.ui
.CapsuleMultiSelectWidget
.parent
.call( this, config
);
12702 // Properties (must be set before mixin constructor calls)
12703 this.$input
= config
.popup
? null : $( '<input>' );
12704 this.$handle
= $( '<div>' );
12706 // Mixin constructors
12707 OO
.ui
.mixin
.GroupElement
.call( this, config
);
12708 if ( config
.popup
) {
12709 config
.popup
= $.extend( {}, config
.popup
, {
12713 OO
.ui
.mixin
.PopupElement
.call( this, config
);
12714 $tabFocus
= $( '<span>' );
12715 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: $tabFocus
} ) );
12719 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$input
} ) );
12721 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
12722 OO
.ui
.mixin
.IconElement
.call( this, config
);
12725 this.allowArbitrary
= !!config
.allowArbitrary
;
12726 this.$overlay
= config
.$overlay
|| this.$element
;
12727 this.menu
= new OO
.ui
.MenuSelectWidget( $.extend(
12730 $input
: this.$input
,
12731 filterFromInput
: true,
12732 disabled
: this.isDisabled()
12738 if ( this.popup
) {
12740 focus
: this.onFocusForPopup
.bind( this )
12742 this.popup
.connect( this, {
12743 toggle: function ( visible
) {
12744 $tabFocus
.toggle( !visible
);
12749 focus
: this.onInputFocus
.bind( this ),
12750 blur
: this.onInputBlur
.bind( this ),
12751 'propertychange change click mouseup keydown keyup input cut paste select': this.onInputChange
.bind( this ),
12752 keydown
: this.onKeyDown
.bind( this ),
12753 keypress
: this.onKeyPress
.bind( this )
12756 this.menu
.connect( this, {
12757 choose
: 'onMenuChoose',
12758 add
: 'onMenuItemsChange',
12759 remove
: 'onMenuItemsChange'
12762 click
: this.onClick
.bind( this )
12766 if ( this.$input
) {
12767 this.$input
.prop( 'disabled', this.isDisabled() );
12768 this.$input
.attr( {
12770 'aria-autocomplete': 'list'
12772 this.$input
.width( '1em' );
12774 if ( config
.data
) {
12775 this.setItemsFromData( config
.data
);
12777 this.$group
.addClass( 'oo-ui-capsuleMultiSelectWidget-group' );
12778 this.$handle
.addClass( 'oo-ui-capsuleMultiSelectWidget-handle' )
12779 .append( this.$indicator
, this.$icon
, this.$group
);
12780 this.$element
.addClass( 'oo-ui-capsuleMultiSelectWidget' )
12781 .append( this.$handle
);
12782 if ( this.popup
) {
12783 this.$handle
.append( $tabFocus
);
12784 this.$overlay
.append( this.popup
.$element
);
12786 this.$handle
.append( this.$input
);
12787 this.$overlay
.append( this.menu
.$element
);
12789 this.onMenuItemsChange();
12794 OO
.inheritClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.Widget
);
12795 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.GroupElement
);
12796 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.PopupElement
);
12797 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
12798 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.IndicatorElement
);
12799 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.IconElement
);
12806 * A change event is emitted when the set of selected items changes.
12808 * @param {Mixed[]} datas Data of the now-selected items
12814 * Get the data of the items in the capsule
12815 * @return {Mixed[]}
12817 OO
.ui
.CapsuleMultiSelectWidget
.prototype.getItemsData = function () {
12818 return $.map( this.getItems(), function ( e
) { return e
.data
; } );
12822 * Set the items in the capsule by providing data
12824 * @param {Mixed[]} datas
12825 * @return {OO.ui.CapsuleMultiSelectWidget}
12827 OO
.ui
.CapsuleMultiSelectWidget
.prototype.setItemsFromData = function ( datas
) {
12830 items
= this.getItems();
12832 $.each( datas
, function ( i
, data
) {
12834 item
= menu
.getItemFromData( data
);
12837 label
= item
.label
;
12838 } else if ( widget
.allowArbitrary
) {
12839 label
= String( data
);
12845 for ( j
= 0; j
< items
.length
; j
++ ) {
12846 if ( items
[j
].data
=== data
&& items
[j
].label
=== label
) {
12848 items
.splice( j
, 1 );
12853 item
= new OO
.ui
.CapsuleItemWidget( { data
: data
, label
: label
} );
12855 widget
.addItems( [ item
], i
);
12858 if ( items
.length
) {
12859 widget
.removeItems( items
);
12866 * Add items to the capsule by providing their data
12868 * @param {Mixed[]} datas
12869 * @return {OO.ui.CapsuleMultiSelectWidget}
12871 OO
.ui
.CapsuleMultiSelectWidget
.prototype.addItemsFromData = function ( datas
) {
12876 $.each( datas
, function ( i
, data
) {
12879 if ( !widget
.getItemFromData( data
) ) {
12880 item
= menu
.getItemFromData( data
);
12882 items
.push( new OO
.ui
.CapsuleItemWidget( { data
: data
, label
: item
.label
} ) );
12883 } else if ( widget
.allowArbitrary
) {
12884 items
.push( new OO
.ui
.CapsuleItemWidget( { data
: data
, label
: String( data
) } ) );
12889 if ( items
.length
) {
12890 this.addItems( items
);
12897 * Remove items by data
12899 * @param {Mixed[]} datas
12900 * @return {OO.ui.CapsuleMultiSelectWidget}
12902 OO
.ui
.CapsuleMultiSelectWidget
.prototype.removeItemsFromData = function ( datas
) {
12906 $.each( datas
, function ( i
, data
) {
12907 var item
= widget
.getItemFromData( data
);
12909 items
.push( item
);
12913 if ( items
.length
) {
12914 this.removeItems( items
);
12923 OO
.ui
.CapsuleMultiSelectWidget
.prototype.addItems = function ( items
) {
12925 oldItems
= this.items
.slice();
12927 OO
.ui
.mixin
.GroupElement
.prototype.addItems
.call( this, items
);
12929 if ( this.items
.length
!== oldItems
.length
) {
12933 for ( i
= 0, l
= oldItems
.length
; same
&& i
< l
; i
++ ) {
12934 same
= same
&& this.items
[i
] === oldItems
[i
];
12938 this.emit( 'change', this.getItemsData() );
12947 OO
.ui
.CapsuleMultiSelectWidget
.prototype.removeItems = function ( items
) {
12949 oldItems
= this.items
.slice();
12951 OO
.ui
.mixin
.GroupElement
.prototype.removeItems
.call( this, items
);
12953 if ( this.items
.length
!== oldItems
.length
) {
12957 for ( i
= 0, l
= oldItems
.length
; same
&& i
< l
; i
++ ) {
12958 same
= same
&& this.items
[i
] === oldItems
[i
];
12962 this.emit( 'change', this.getItemsData() );
12971 OO
.ui
.CapsuleMultiSelectWidget
.prototype.clearItems = function () {
12972 if ( this.items
.length
) {
12973 OO
.ui
.mixin
.GroupElement
.prototype.clearItems
.call( this );
12974 this.emit( 'change', this.getItemsData() );
12980 * Get the capsule widget's menu.
12981 * @return {OO.ui.MenuSelectWidget} Menu widget
12983 OO
.ui
.CapsuleMultiSelectWidget
.prototype.getMenu = function () {
12988 * Handle focus events
12991 * @param {jQuery.Event} event
12993 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onInputFocus = function () {
12994 if ( !this.isDisabled() ) {
12995 this.menu
.toggle( true );
13000 * Handle blur events
13003 * @param {jQuery.Event} event
13005 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onInputBlur = function () {
13010 * Handle focus events
13013 * @param {jQuery.Event} event
13015 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onFocusForPopup = function () {
13016 if ( !this.isDisabled() ) {
13017 this.popup
.setSize( this.$handle
.width() );
13018 this.popup
.toggle( true );
13019 this.popup
.$element
.find( '*' )
13020 .filter( function () { return OO
.ui
.isFocusableElement( $( this ), true ); } )
13027 * Handle mouse click events.
13030 * @param {jQuery.Event} e Mouse click event
13032 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onClick = function ( e
) {
13033 if ( e
.which
=== 1 ) {
13040 * Handle key press events.
13043 * @param {jQuery.Event} e Key press event
13045 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onKeyPress = function ( e
) {
13048 if ( !this.isDisabled() ) {
13049 if ( e
.which
=== OO
.ui
.Keys
.ESCAPE
) {
13054 if ( !this.popup
) {
13055 this.menu
.toggle( true );
13056 if ( e
.which
=== OO
.ui
.Keys
.ENTER
) {
13057 item
= this.menu
.getItemFromLabel( this.$input
.val(), true );
13059 this.addItemsFromData( [ item
.data
] );
13061 } else if ( this.allowArbitrary
&& this.$input
.val().trim() !== '' ) {
13062 this.addItemsFromData( [ this.$input
.val() ] );
13068 // Make sure the input gets resized.
13069 setTimeout( this.onInputChange
.bind( this ), 0 );
13075 * Handle key down events.
13078 * @param {jQuery.Event} e Key down event
13080 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onKeyDown = function ( e
) {
13081 if ( !this.isDisabled() ) {
13082 // 'keypress' event is not triggered for Backspace
13083 if ( e
.keyCode
=== OO
.ui
.Keys
.BACKSPACE
&& this.$input
.val() === '' ) {
13084 if ( this.items
.length
) {
13085 this.removeItems( this.items
.slice( -1 ) );
13093 * Handle input change events.
13096 * @param {jQuery.Event} e Event of some sort
13098 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onInputChange = function () {
13099 if ( !this.isDisabled() ) {
13100 this.$input
.width( this.$input
.val().length
+ 'em' );
13105 * Handle menu choose events.
13108 * @param {OO.ui.OptionWidget} item Chosen item
13110 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onMenuChoose = function ( item
) {
13111 if ( item
&& item
.isVisible() ) {
13112 this.addItemsFromData( [ item
.getData() ] );
13118 * Handle menu item change events.
13122 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onMenuItemsChange = function () {
13123 this.setItemsFromData( this.getItemsData() );
13124 this.$element
.toggleClass( 'oo-ui-capsuleMultiSelectWidget-empty', this.menu
.isEmpty() );
13128 * Clear the input field
13131 OO
.ui
.CapsuleMultiSelectWidget
.prototype.clearInput = function () {
13132 if ( this.$input
) {
13133 this.$input
.val( '' );
13134 this.$input
.width( '1em' );
13136 if ( this.popup
) {
13137 this.popup
.toggle( false );
13139 this.menu
.toggle( false );
13140 this.menu
.selectItem();
13141 this.menu
.highlightItem();
13147 OO
.ui
.CapsuleMultiSelectWidget
.prototype.setDisabled = function ( disabled
) {
13151 OO
.ui
.CapsuleMultiSelectWidget
.parent
.prototype.setDisabled
.call( this, disabled
);
13153 if ( this.$input
) {
13154 this.$input
.prop( 'disabled', this.isDisabled() );
13157 this.menu
.setDisabled( this.isDisabled() );
13159 if ( this.popup
) {
13160 this.popup
.setDisabled( this.isDisabled() );
13163 if ( this.items
) {
13164 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
13165 this.items
[i
].updateDisabled();
13175 * @return {OO.ui.CapsuleMultiSelectWidget}
13177 OO
.ui
.CapsuleMultiSelectWidget
.prototype.focus = function () {
13178 if ( !this.isDisabled() ) {
13179 if ( this.popup
) {
13180 this.popup
.setSize( this.$handle
.width() );
13181 this.popup
.toggle( true );
13182 this.popup
.$element
.find( '*' )
13183 .filter( function () { return OO
.ui
.isFocusableElement( $( this ), true ); } )
13187 this.menu
.toggle( true );
13188 this.$input
.focus();
13195 * CapsuleItemWidgets are used within a {@link OO.ui.CapsuleMultiSelectWidget
13196 * CapsuleMultiSelectWidget} to display the selected items.
13199 * @extends OO.ui.Widget
13200 * @mixins OO.ui.mixin.ItemWidget
13201 * @mixins OO.ui.mixin.IndicatorElement
13202 * @mixins OO.ui.mixin.LabelElement
13203 * @mixins OO.ui.mixin.FlaggedElement
13204 * @mixins OO.ui.mixin.TabIndexedElement
13207 * @param {Object} [config] Configuration options
13209 OO
.ui
.CapsuleItemWidget
= function OoUiCapsuleItemWidget( config
) {
13210 // Configuration initialization
13211 config
= config
|| {};
13213 // Parent constructor
13214 OO
.ui
.CapsuleItemWidget
.parent
.call( this, config
);
13216 // Properties (must be set before mixin constructor calls)
13217 this.$indicator
= $( '<span>' );
13219 // Mixin constructors
13220 OO
.ui
.mixin
.ItemWidget
.call( this );
13221 OO
.ui
.mixin
.IndicatorElement
.call( this, $.extend( {}, config
, { $indicator
: this.$indicator
, indicator
: 'clear' } ) );
13222 OO
.ui
.mixin
.LabelElement
.call( this, config
);
13223 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
13224 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$indicator
} ) );
13227 this.$indicator
.on( {
13228 keydown
: this.onCloseKeyDown
.bind( this ),
13229 click
: this.onCloseClick
.bind( this )
13231 this.$element
.on( 'click', false );
13235 .addClass( 'oo-ui-capsuleItemWidget' )
13236 .append( this.$indicator
, this.$label
);
13241 OO
.inheritClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.Widget
);
13242 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.ItemWidget
);
13243 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.IndicatorElement
);
13244 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.LabelElement
);
13245 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.FlaggedElement
);
13246 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.TabIndexedElement
);
13251 * Handle close icon clicks
13252 * @param {jQuery.Event} event
13254 OO
.ui
.CapsuleItemWidget
.prototype.onCloseClick = function () {
13255 var element
= this.getElementGroup();
13257 if ( !this.isDisabled() && element
&& $.isFunction( element
.removeItems
) ) {
13258 element
.removeItems( [ this ] );
13264 * Handle close keyboard events
13265 * @param {jQuery.Event} event Key down event
13267 OO
.ui
.CapsuleItemWidget
.prototype.onCloseKeyDown = function ( e
) {
13268 if ( !this.isDisabled() && $.isFunction( this.getElementGroup().removeItems
) ) {
13269 switch ( e
.which
) {
13270 case OO
.ui
.Keys
.ENTER
:
13271 case OO
.ui
.Keys
.BACKSPACE
:
13272 case OO
.ui
.Keys
.SPACE
:
13273 this.getElementGroup().removeItems( [ this ] );
13280 * DropdownWidgets are not menus themselves, rather they contain a menu of options created with
13281 * OO.ui.MenuOptionWidget. The DropdownWidget takes care of opening and displaying the menu so that
13282 * users can interact with it.
13284 * If you want to use this within a HTML form, such as a OO.ui.FormLayout, use
13285 * OO.ui.DropdownInputWidget instead.
13288 * // Example: A DropdownWidget with a menu that contains three options
13289 * var dropDown = new OO.ui.DropdownWidget( {
13290 * label: 'Dropdown menu: Select a menu option',
13293 * new OO.ui.MenuOptionWidget( {
13297 * new OO.ui.MenuOptionWidget( {
13301 * new OO.ui.MenuOptionWidget( {
13309 * $( 'body' ).append( dropDown.$element );
13311 * For more information, please see the [OOjs UI documentation on MediaWiki] [1].
13313 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Menu_selects_and_options
13316 * @extends OO.ui.Widget
13317 * @mixins OO.ui.mixin.IconElement
13318 * @mixins OO.ui.mixin.IndicatorElement
13319 * @mixins OO.ui.mixin.LabelElement
13320 * @mixins OO.ui.mixin.TitledElement
13321 * @mixins OO.ui.mixin.TabIndexedElement
13324 * @param {Object} [config] Configuration options
13325 * @cfg {Object} [menu] Configuration options to pass to menu widget
13327 OO
.ui
.DropdownWidget
= function OoUiDropdownWidget( config
) {
13328 // Configuration initialization
13329 config
= $.extend( { indicator
: 'down' }, config
);
13331 // Parent constructor
13332 OO
.ui
.DropdownWidget
.parent
.call( this, config
);
13334 // Properties (must be set before TabIndexedElement constructor call)
13335 this.$handle
= this.$( '<span>' );
13337 // Mixin constructors
13338 OO
.ui
.mixin
.IconElement
.call( this, config
);
13339 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
13340 OO
.ui
.mixin
.LabelElement
.call( this, config
);
13341 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$label
} ) );
13342 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$handle
} ) );
13345 this.menu
= new OO
.ui
.MenuSelectWidget( $.extend( { widget
: this }, config
.menu
) );
13349 click
: this.onClick
.bind( this ),
13350 keypress
: this.onKeyPress
.bind( this )
13352 this.menu
.connect( this, { select
: 'onMenuSelect' } );
13356 .addClass( 'oo-ui-dropdownWidget-handle' )
13357 .append( this.$icon
, this.$label
, this.$indicator
);
13359 .addClass( 'oo-ui-dropdownWidget' )
13360 .append( this.$handle
, this.menu
.$element
);
13365 OO
.inheritClass( OO
.ui
.DropdownWidget
, OO
.ui
.Widget
);
13366 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.IconElement
);
13367 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.IndicatorElement
);
13368 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.LabelElement
);
13369 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.TitledElement
);
13370 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.TabIndexedElement
);
13377 * @return {OO.ui.MenuSelectWidget} Menu of widget
13379 OO
.ui
.DropdownWidget
.prototype.getMenu = function () {
13384 * Handles menu select events.
13387 * @param {OO.ui.MenuOptionWidget} item Selected menu item
13389 OO
.ui
.DropdownWidget
.prototype.onMenuSelect = function ( item
) {
13393 this.setLabel( null );
13397 selectedLabel
= item
.getLabel();
13399 // If the label is a DOM element, clone it, because setLabel will append() it
13400 if ( selectedLabel
instanceof jQuery
) {
13401 selectedLabel
= selectedLabel
.clone();
13404 this.setLabel( selectedLabel
);
13408 * Handle mouse click events.
13411 * @param {jQuery.Event} e Mouse click event
13413 OO
.ui
.DropdownWidget
.prototype.onClick = function ( e
) {
13414 if ( !this.isDisabled() && e
.which
=== 1 ) {
13415 this.menu
.toggle();
13421 * Handle key press events.
13424 * @param {jQuery.Event} e Key press event
13426 OO
.ui
.DropdownWidget
.prototype.onKeyPress = function ( e
) {
13427 if ( !this.isDisabled() &&
13428 ( ( e
.which
=== OO
.ui
.Keys
.SPACE
&& !this.menu
.isVisible() ) || e
.which
=== OO
.ui
.Keys
.ENTER
)
13430 this.menu
.toggle();
13436 * SelectFileWidgets allow for selecting files, using the HTML5 File API. These
13437 * widgets can be configured with {@link OO.ui.mixin.IconElement icons} and {@link
13438 * OO.ui.mixin.IndicatorElement indicators}.
13439 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information and examples.
13442 * // Example of a file select widget
13443 * var selectFile = new OO.ui.SelectFileWidget();
13444 * $( 'body' ).append( selectFile.$element );
13446 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets
13449 * @extends OO.ui.Widget
13450 * @mixins OO.ui.mixin.IconElement
13451 * @mixins OO.ui.mixin.IndicatorElement
13452 * @mixins OO.ui.mixin.PendingElement
13453 * @mixins OO.ui.mixin.LabelElement
13454 * @mixins OO.ui.mixin.TabIndexedElement
13457 * @param {Object} [config] Configuration options
13458 * @cfg {string[]|null} [accept=null] MIME types to accept. null accepts all types.
13459 * @cfg {string} [placeholder] Text to display when no file is selected.
13460 * @cfg {string} [notsupported] Text to display when file support is missing in the browser.
13461 * @cfg {boolean} [droppable=true] Whether to accept files by drag and drop.
13463 OO
.ui
.SelectFileWidget
= function OoUiSelectFileWidget( config
) {
13466 // Configuration initialization
13467 config
= $.extend( {
13469 placeholder
: OO
.ui
.msg( 'ooui-selectfile-placeholder' ),
13470 notsupported
: OO
.ui
.msg( 'ooui-selectfile-not-supported' ),
13474 // Parent constructor
13475 OO
.ui
.SelectFileWidget
.parent
.call( this, config
);
13477 // Properties (must be set before TabIndexedElement constructor call)
13478 this.$handle
= $( '<span>' );
13480 // Mixin constructors
13481 OO
.ui
.mixin
.IconElement
.call( this, config
);
13482 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
13483 OO
.ui
.mixin
.PendingElement
.call( this, $.extend( {}, config
, { $pending
: this.$handle
} ) );
13484 OO
.ui
.mixin
.LabelElement
.call( this, $.extend( {}, config
, { autoFitLabel
: true } ) );
13485 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$handle
} ) );
13488 this.isSupported
= this.constructor.static.isSupported();
13489 this.currentFile
= null;
13490 if ( Array
.isArray( config
.accept
) ) {
13491 this.accept
= config
.accept
;
13493 this.accept
= null;
13495 this.placeholder
= config
.placeholder
;
13496 this.notsupported
= config
.notsupported
;
13497 this.onFileSelectedHandler
= this.onFileSelected
.bind( this );
13499 this.clearButton
= new OO
.ui
.ButtonWidget( {
13500 classes
: [ 'oo-ui-selectFileWidget-clearButton' ],
13503 disabled
: this.disabled
13508 keypress
: this.onKeyPress
.bind( this )
13510 this.clearButton
.connect( this, {
13511 click
: 'onClearClick'
13513 if ( config
.droppable
) {
13514 dragHandler
= this.onDragEnterOrOver
.bind( this );
13516 dragenter
: dragHandler
,
13517 dragover
: dragHandler
,
13518 dragleave
: this.onDragLeave
.bind( this ),
13519 drop
: this.onDrop
.bind( this )
13526 this.$label
.addClass( 'oo-ui-selectFileWidget-label' );
13528 .addClass( 'oo-ui-selectFileWidget-handle' )
13529 .append( this.$icon
, this.$label
, this.clearButton
.$element
, this.$indicator
);
13531 .addClass( 'oo-ui-selectFileWidget' )
13532 .append( this.$handle
);
13533 if ( config
.droppable
) {
13534 this.$element
.addClass( 'oo-ui-selectFileWidget-droppable' );
13540 OO
.inheritClass( OO
.ui
.SelectFileWidget
, OO
.ui
.Widget
);
13541 OO
.mixinClass( OO
.ui
.SelectFileWidget
, OO
.ui
.mixin
.IconElement
);
13542 OO
.mixinClass( OO
.ui
.SelectFileWidget
, OO
.ui
.mixin
.IndicatorElement
);
13543 OO
.mixinClass( OO
.ui
.SelectFileWidget
, OO
.ui
.mixin
.PendingElement
);
13544 OO
.mixinClass( OO
.ui
.SelectFileWidget
, OO
.ui
.mixin
.LabelElement
);
13545 OO
.mixinClass( OO
.ui
.SelectFileWidget
, OO
.ui
.mixin
.TabIndexedElement
);
13547 /* Static Properties */
13550 * Check if this widget is supported
13553 * @return {boolean}
13555 OO
.ui
.SelectFileWidget
.static.isSupported = function () {
13557 if ( OO
.ui
.SelectFileWidget
.static.isSupportedCache
=== null ) {
13558 $input
= $( '<input type="file">' );
13559 OO
.ui
.SelectFileWidget
.static.isSupportedCache
= $input
[0].files
!== undefined;
13561 return OO
.ui
.SelectFileWidget
.static.isSupportedCache
;
13564 OO
.ui
.SelectFileWidget
.static.isSupportedCache
= null;
13571 * A change event is emitted when the on/off state of the toggle changes.
13573 * @param {File|null} value New value
13579 * Get the current value of the field
13581 * @return {File|null}
13583 OO
.ui
.SelectFileWidget
.prototype.getValue = function () {
13584 return this.currentFile
;
13588 * Set the current value of the field
13590 * @param {File|null} file File to select
13592 OO
.ui
.SelectFileWidget
.prototype.setValue = function ( file
) {
13593 if ( this.currentFile
!== file
) {
13594 this.currentFile
= file
;
13596 this.emit( 'change', this.currentFile
);
13601 * Update the user interface when a file is selected or unselected
13605 OO
.ui
.SelectFileWidget
.prototype.updateUI = function () {
13606 if ( !this.isSupported
) {
13607 this.$element
.addClass( 'oo-ui-selectFileWidget-notsupported' );
13608 this.$element
.removeClass( 'oo-ui-selectFileWidget-empty' );
13609 this.setLabel( this.notsupported
);
13610 } else if ( this.currentFile
) {
13611 this.$element
.removeClass( 'oo-ui-selectFileWidget-empty' );
13612 this.setLabel( this.currentFile
.name
+
13613 ( this.currentFile
.type
!== '' ? OO
.ui
.msg( 'ooui-semicolon-separator' ) + this.currentFile
.type
: '' )
13616 this.$element
.addClass( 'oo-ui-selectFileWidget-empty' );
13617 this.setLabel( this.placeholder
);
13620 if ( this.$input
) {
13621 this.$input
.attr( 'title', this.getLabel() );
13626 * Add the input to the handle
13630 OO
.ui
.SelectFileWidget
.prototype.addInput = function () {
13631 if ( this.$input
) {
13632 this.$input
.remove();
13635 if ( !this.isSupported
) {
13636 this.$input
= null;
13640 this.$input
= $( '<input type="file">' );
13641 this.$input
.on( 'change', this.onFileSelectedHandler
);
13642 this.$input
.attr( {
13644 title
: this.getLabel()
13646 if ( this.accept
) {
13647 this.$input
.attr( 'accept', this.accept
.join( ', ' ) );
13649 this.$handle
.append( this.$input
);
13653 * Determine if we should accept this file
13656 * @param {File} file
13657 * @return {boolean}
13659 OO
.ui
.SelectFileWidget
.prototype.isFileAcceptable = function ( file
) {
13660 var i
, mime
, mimeTest
;
13662 if ( !this.accept
|| file
.type
=== '' ) {
13667 for ( i
= 0; i
< this.accept
.length
; i
++ ) {
13668 mimeTest
= this.accept
[i
];
13669 if ( mimeTest
=== mime
) {
13671 } else if ( mimeTest
.substr( -2 ) === '/*' ) {
13672 mimeTest
= mimeTest
.substr( 0, mimeTest
.length
- 1 );
13673 if ( mime
.substr( 0, mimeTest
.length
) === mimeTest
) {
13683 * Handle file selection from the input
13686 * @param {jQuery.Event} e
13688 OO
.ui
.SelectFileWidget
.prototype.onFileSelected = function ( e
) {
13691 if ( e
.target
.files
&& e
.target
.files
[0] ) {
13692 file
= e
.target
.files
[0];
13693 if ( !this.isFileAcceptable( file
) ) {
13698 this.setValue( file
);
13703 * Handle clear button click events.
13707 OO
.ui
.SelectFileWidget
.prototype.onClearClick = function () {
13708 this.setValue( null );
13713 * Handle key press events.
13716 * @param {jQuery.Event} e Key press event
13718 OO
.ui
.SelectFileWidget
.prototype.onKeyPress = function ( e
) {
13719 if ( this.isSupported
&& !this.isDisabled() && this.$input
&&
13720 ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
13722 this.$input
.click();
13728 * Handle drag enter and over events
13731 * @param {jQuery.Event} e Drag event
13733 OO
.ui
.SelectFileWidget
.prototype.onDragEnterOrOver = function ( e
) {
13735 dt
= e
.originalEvent
.dataTransfer
;
13737 e
.preventDefault();
13738 e
.stopPropagation();
13740 if ( this.isDisabled() || !this.isSupported
) {
13741 this.$element
.removeClass( 'oo-ui-selectFileWidget-canDrop' );
13742 dt
.dropEffect
= 'none';
13746 if ( dt
&& dt
.files
&& dt
.files
[0] ) {
13747 file
= dt
.files
[0];
13748 if ( !this.isFileAcceptable( file
) ) {
13751 } else if ( dt
&& dt
.types
&& $.inArray( 'Files', dt
.types
) ) {
13752 // We know we have files so set 'file' to something truthy, we just
13753 // can't know any details about them.
13754 // * https://bugzilla.mozilla.org/show_bug.cgi?id=640534
13755 file
= 'Files exist, but details are unknown';
13758 this.$element
.addClass( 'oo-ui-selectFileWidget-canDrop' );
13760 this.$element
.removeClass( 'oo-ui-selectFileWidget-canDrop' );
13761 dt
.dropEffect
= 'none';
13768 * Handle drag leave events
13771 * @param {jQuery.Event} e Drag event
13773 OO
.ui
.SelectFileWidget
.prototype.onDragLeave = function () {
13774 this.$element
.removeClass( 'oo-ui-selectFileWidget-canDrop' );
13778 * Handle drop events
13781 * @param {jQuery.Event} e Drop event
13783 OO
.ui
.SelectFileWidget
.prototype.onDrop = function ( e
) {
13785 dt
= e
.originalEvent
.dataTransfer
;
13787 e
.preventDefault();
13788 e
.stopPropagation();
13789 this.$element
.removeClass( 'oo-ui-selectFileWidget-canDrop' );
13791 if ( this.isDisabled() || !this.isSupported
) {
13795 if ( dt
&& dt
.files
&& dt
.files
[0] ) {
13796 file
= dt
.files
[0];
13797 if ( !this.isFileAcceptable( file
) ) {
13802 this.setValue( file
);
13811 OO
.ui
.SelectFileWidget
.prototype.setDisabled = function ( state
) {
13812 OO
.ui
.SelectFileWidget
.parent
.prototype.setDisabled
.call( this, state
);
13813 if ( this.clearButton
) {
13814 this.clearButton
.setDisabled( state
);
13820 * IconWidget is a generic widget for {@link OO.ui.mixin.IconElement icons}. In general, IconWidgets should be used with OO.ui.LabelWidget,
13821 * which creates a label that identifies the icon’s function. See the [OOjs UI documentation on MediaWiki] [1]
13822 * for a list of icons included in the library.
13825 * // An icon widget with a label
13826 * var myIcon = new OO.ui.IconWidget( {
13828 * iconTitle: 'Help'
13830 * // Create a label.
13831 * var iconLabel = new OO.ui.LabelWidget( {
13834 * $( 'body' ).append( myIcon.$element, iconLabel.$element );
13836 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Icons
13839 * @extends OO.ui.Widget
13840 * @mixins OO.ui.mixin.IconElement
13841 * @mixins OO.ui.mixin.TitledElement
13842 * @mixins OO.ui.mixin.FlaggedElement
13845 * @param {Object} [config] Configuration options
13847 OO
.ui
.IconWidget
= function OoUiIconWidget( config
) {
13848 // Configuration initialization
13849 config
= config
|| {};
13851 // Parent constructor
13852 OO
.ui
.IconWidget
.parent
.call( this, config
);
13854 // Mixin constructors
13855 OO
.ui
.mixin
.IconElement
.call( this, $.extend( {}, config
, { $icon
: this.$element
} ) );
13856 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$element
} ) );
13857 OO
.ui
.mixin
.FlaggedElement
.call( this, $.extend( {}, config
, { $flagged
: this.$element
} ) );
13860 this.$element
.addClass( 'oo-ui-iconWidget' );
13865 OO
.inheritClass( OO
.ui
.IconWidget
, OO
.ui
.Widget
);
13866 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.mixin
.IconElement
);
13867 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.mixin
.TitledElement
);
13868 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.mixin
.FlaggedElement
);
13870 /* Static Properties */
13872 OO
.ui
.IconWidget
.static.tagName
= 'span';
13875 * IndicatorWidgets create indicators, which are small graphics that are generally used to draw
13876 * attention to the status of an item or to clarify the function of a control. For a list of
13877 * indicators included in the library, please see the [OOjs UI documentation on MediaWiki][1].
13880 * // Example of an indicator widget
13881 * var indicator1 = new OO.ui.IndicatorWidget( {
13882 * indicator: 'alert'
13885 * // Create a fieldset layout to add a label
13886 * var fieldset = new OO.ui.FieldsetLayout();
13887 * fieldset.addItems( [
13888 * new OO.ui.FieldLayout( indicator1, { label: 'An alert indicator:' } )
13890 * $( 'body' ).append( fieldset.$element );
13892 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Indicators
13895 * @extends OO.ui.Widget
13896 * @mixins OO.ui.mixin.IndicatorElement
13897 * @mixins OO.ui.mixin.TitledElement
13900 * @param {Object} [config] Configuration options
13902 OO
.ui
.IndicatorWidget
= function OoUiIndicatorWidget( config
) {
13903 // Configuration initialization
13904 config
= config
|| {};
13906 // Parent constructor
13907 OO
.ui
.IndicatorWidget
.parent
.call( this, config
);
13909 // Mixin constructors
13910 OO
.ui
.mixin
.IndicatorElement
.call( this, $.extend( {}, config
, { $indicator
: this.$element
} ) );
13911 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$element
} ) );
13914 this.$element
.addClass( 'oo-ui-indicatorWidget' );
13919 OO
.inheritClass( OO
.ui
.IndicatorWidget
, OO
.ui
.Widget
);
13920 OO
.mixinClass( OO
.ui
.IndicatorWidget
, OO
.ui
.mixin
.IndicatorElement
);
13921 OO
.mixinClass( OO
.ui
.IndicatorWidget
, OO
.ui
.mixin
.TitledElement
);
13923 /* Static Properties */
13925 OO
.ui
.IndicatorWidget
.static.tagName
= 'span';
13928 * InputWidget is the base class for all input widgets, which
13929 * include {@link OO.ui.TextInputWidget text inputs}, {@link OO.ui.CheckboxInputWidget checkbox inputs},
13930 * {@link OO.ui.RadioInputWidget radio inputs}, and {@link OO.ui.ButtonInputWidget button inputs}.
13931 * See the [OOjs UI documentation on MediaWiki] [1] for more information and examples.
13933 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
13937 * @extends OO.ui.Widget
13938 * @mixins OO.ui.mixin.FlaggedElement
13939 * @mixins OO.ui.mixin.TabIndexedElement
13942 * @param {Object} [config] Configuration options
13943 * @cfg {string} [name=''] The value of the input’s HTML `name` attribute.
13944 * @cfg {string} [value=''] The value of the input.
13945 * @cfg {Function} [inputFilter] The name of an input filter function. Input filters modify the value of an input
13946 * before it is accepted.
13948 OO
.ui
.InputWidget
= function OoUiInputWidget( config
) {
13949 // Configuration initialization
13950 config
= config
|| {};
13952 // Parent constructor
13953 OO
.ui
.InputWidget
.parent
.call( this, config
);
13956 this.$input
= this.getInputElement( config
);
13958 this.inputFilter
= config
.inputFilter
;
13960 // Mixin constructors
13961 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
13962 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$input
} ) );
13965 this.$input
.on( 'keydown mouseup cut paste change input select', this.onEdit
.bind( this ) );
13969 .addClass( 'oo-ui-inputWidget-input' )
13970 .attr( 'name', config
.name
)
13971 .prop( 'disabled', this.isDisabled() );
13973 .addClass( 'oo-ui-inputWidget' )
13974 .append( this.$input
);
13975 this.setValue( config
.value
);
13980 OO
.inheritClass( OO
.ui
.InputWidget
, OO
.ui
.Widget
);
13981 OO
.mixinClass( OO
.ui
.InputWidget
, OO
.ui
.mixin
.FlaggedElement
);
13982 OO
.mixinClass( OO
.ui
.InputWidget
, OO
.ui
.mixin
.TabIndexedElement
);
13984 /* Static Properties */
13986 OO
.ui
.InputWidget
.static.supportsSimpleLabel
= true;
13993 * A change event is emitted when the value of the input changes.
13995 * @param {string} value
14001 * Get input element.
14003 * Subclasses of OO.ui.InputWidget use the `config` parameter to produce different elements in
14004 * different circumstances. The element must have a `value` property (like form elements).
14007 * @param {Object} config Configuration options
14008 * @return {jQuery} Input element
14010 OO
.ui
.InputWidget
.prototype.getInputElement = function () {
14011 return $( '<input>' );
14015 * Handle potentially value-changing events.
14018 * @param {jQuery.Event} e Key down, mouse up, cut, paste, change, input, or select event
14020 OO
.ui
.InputWidget
.prototype.onEdit = function () {
14022 if ( !this.isDisabled() ) {
14023 // Allow the stack to clear so the value will be updated
14024 setTimeout( function () {
14025 widget
.setValue( widget
.$input
.val() );
14031 * Get the value of the input.
14033 * @return {string} Input value
14035 OO
.ui
.InputWidget
.prototype.getValue = function () {
14036 // Resynchronize our internal data with DOM data. Other scripts executing on the page can modify
14037 // it, and we won't know unless they're kind enough to trigger a 'change' event.
14038 var value
= this.$input
.val();
14039 if ( this.value
!== value
) {
14040 this.setValue( value
);
14046 * Set the direction of the input, either RTL (right-to-left) or LTR (left-to-right).
14048 * @param {boolean} isRTL
14049 * Direction is right-to-left
14051 OO
.ui
.InputWidget
.prototype.setRTL = function ( isRTL
) {
14052 this.$input
.prop( 'dir', isRTL
? 'rtl' : 'ltr' );
14056 * Set the value of the input.
14058 * @param {string} value New value
14062 OO
.ui
.InputWidget
.prototype.setValue = function ( value
) {
14063 value
= this.cleanUpValue( value
);
14064 // Update the DOM if it has changed. Note that with cleanUpValue, it
14065 // is possible for the DOM value to change without this.value changing.
14066 if ( this.$input
.val() !== value
) {
14067 this.$input
.val( value
);
14069 if ( this.value
!== value
) {
14070 this.value
= value
;
14071 this.emit( 'change', this.value
);
14077 * Clean up incoming value.
14079 * Ensures value is a string, and converts undefined and null to empty string.
14082 * @param {string} value Original value
14083 * @return {string} Cleaned up value
14085 OO
.ui
.InputWidget
.prototype.cleanUpValue = function ( value
) {
14086 if ( value
=== undefined || value
=== null ) {
14088 } else if ( this.inputFilter
) {
14089 return this.inputFilter( String( value
) );
14091 return String( value
);
14096 * Simulate the behavior of clicking on a label bound to this input. This method is only called by
14097 * {@link OO.ui.LabelWidget LabelWidget} and {@link OO.ui.FieldLayout FieldLayout}. It should not be
14100 OO
.ui
.InputWidget
.prototype.simulateLabelClick = function () {
14101 if ( !this.isDisabled() ) {
14102 if ( this.$input
.is( ':checkbox, :radio' ) ) {
14103 this.$input
.click();
14105 if ( this.$input
.is( ':input' ) ) {
14106 this.$input
[ 0 ].focus();
14114 OO
.ui
.InputWidget
.prototype.setDisabled = function ( state
) {
14115 OO
.ui
.InputWidget
.parent
.prototype.setDisabled
.call( this, state
);
14116 if ( this.$input
) {
14117 this.$input
.prop( 'disabled', this.isDisabled() );
14127 OO
.ui
.InputWidget
.prototype.focus = function () {
14128 this.$input
[ 0 ].focus();
14137 OO
.ui
.InputWidget
.prototype.blur = function () {
14138 this.$input
[ 0 ].blur();
14145 OO
.ui
.InputWidget
.prototype.gatherPreInfuseState = function ( node
) {
14147 state
= OO
.ui
.InputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
),
14148 $input
= state
.$input
|| $( node
).find( '.oo-ui-inputWidget-input' );
14149 state
.value
= $input
.val();
14150 // Might be better in TabIndexedElement, but it's awkward to do there because mixins are awkward
14151 state
.focus
= $input
.is( ':focus' );
14158 OO
.ui
.InputWidget
.prototype.restorePreInfuseState = function ( state
) {
14159 OO
.ui
.InputWidget
.parent
.prototype.restorePreInfuseState
.call( this, state
);
14160 if ( state
.value
!== undefined && state
.value
!== this.getValue() ) {
14161 this.setValue( state
.value
);
14163 if ( state
.focus
) {
14169 * ButtonInputWidget is used to submit HTML forms and is intended to be used within
14170 * a OO.ui.FormLayout. If you do not need the button to work with HTML forms, you probably
14171 * want to use OO.ui.ButtonWidget instead. Button input widgets can be rendered as either an
14172 * HTML `<button/>` (the default) or an HTML `<input/>` tags. See the
14173 * [OOjs UI documentation on MediaWiki] [1] for more information.
14176 * // A ButtonInputWidget rendered as an HTML button, the default.
14177 * var button = new OO.ui.ButtonInputWidget( {
14178 * label: 'Input button',
14182 * $( 'body' ).append( button.$element );
14184 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs#Button_inputs
14187 * @extends OO.ui.InputWidget
14188 * @mixins OO.ui.mixin.ButtonElement
14189 * @mixins OO.ui.mixin.IconElement
14190 * @mixins OO.ui.mixin.IndicatorElement
14191 * @mixins OO.ui.mixin.LabelElement
14192 * @mixins OO.ui.mixin.TitledElement
14195 * @param {Object} [config] Configuration options
14196 * @cfg {string} [type='button'] The value of the HTML `'type'` attribute: 'button', 'submit' or 'reset'.
14197 * @cfg {boolean} [useInputTag=false] Use an `<input/>` tag instead of a `<button/>` tag, the default.
14198 * Widgets configured to be an `<input/>` do not support {@link #icon icons} and {@link #indicator indicators},
14199 * non-plaintext {@link #label labels}, or {@link #value values}. In general, useInputTag should only
14200 * be set to `true` when there’s need to support IE6 in a form with multiple buttons.
14202 OO
.ui
.ButtonInputWidget
= function OoUiButtonInputWidget( config
) {
14203 // Configuration initialization
14204 config
= $.extend( { type
: 'button', useInputTag
: false }, config
);
14206 // Properties (must be set before parent constructor, which calls #setValue)
14207 this.useInputTag
= config
.useInputTag
;
14209 // Parent constructor
14210 OO
.ui
.ButtonInputWidget
.parent
.call( this, config
);
14212 // Mixin constructors
14213 OO
.ui
.mixin
.ButtonElement
.call( this, $.extend( {}, config
, { $button
: this.$input
} ) );
14214 OO
.ui
.mixin
.IconElement
.call( this, config
);
14215 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
14216 OO
.ui
.mixin
.LabelElement
.call( this, config
);
14217 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$input
} ) );
14220 if ( !config
.useInputTag
) {
14221 this.$input
.append( this.$icon
, this.$label
, this.$indicator
);
14223 this.$element
.addClass( 'oo-ui-buttonInputWidget' );
14228 OO
.inheritClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.InputWidget
);
14229 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.ButtonElement
);
14230 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.IconElement
);
14231 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.IndicatorElement
);
14232 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.LabelElement
);
14233 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.TitledElement
);
14235 /* Static Properties */
14238 * Disable generating `<label>` elements for buttons. One would very rarely need additional label
14239 * for a button, and it's already a big clickable target, and it causes unexpected rendering.
14241 OO
.ui
.ButtonInputWidget
.static.supportsSimpleLabel
= false;
14249 OO
.ui
.ButtonInputWidget
.prototype.getInputElement = function ( config
) {
14250 var type
= [ 'button', 'submit', 'reset' ].indexOf( config
.type
) !== -1 ?
14253 return $( '<' + ( config
.useInputTag
? 'input' : 'button' ) + ' type="' + type
+ '">' );
14259 * If #useInputTag is `true`, the label is set as the `value` of the `<input/>` tag.
14261 * @param {jQuery|string|Function|null} label Label nodes, text, a function that returns nodes or
14262 * text, or `null` for no label
14265 OO
.ui
.ButtonInputWidget
.prototype.setLabel = function ( label
) {
14266 OO
.ui
.mixin
.LabelElement
.prototype.setLabel
.call( this, label
);
14268 if ( this.useInputTag
) {
14269 if ( typeof label
=== 'function' ) {
14270 label
= OO
.ui
.resolveMsg( label
);
14272 if ( label
instanceof jQuery
) {
14273 label
= label
.text();
14278 this.$input
.val( label
);
14285 * Set the value of the input.
14287 * This method is disabled for button inputs configured as {@link #useInputTag <input/> tags}, as
14288 * they do not support {@link #value values}.
14290 * @param {string} value New value
14293 OO
.ui
.ButtonInputWidget
.prototype.setValue = function ( value
) {
14294 if ( !this.useInputTag
) {
14295 OO
.ui
.ButtonInputWidget
.parent
.prototype.setValue
.call( this, value
);
14301 * CheckboxInputWidgets, like HTML checkboxes, can be selected and/or configured with a value.
14302 * Note that these {@link OO.ui.InputWidget input widgets} are best laid out
14303 * in {@link OO.ui.FieldLayout field layouts} that use the {@link OO.ui.FieldLayout#align inline}
14304 * alignment. For more information, please see the [OOjs UI documentation on MediaWiki][1].
14306 * This widget can be used inside a HTML form, such as a OO.ui.FormLayout.
14309 * // An example of selected, unselected, and disabled checkbox inputs
14310 * var checkbox1=new OO.ui.CheckboxInputWidget( {
14314 * var checkbox2=new OO.ui.CheckboxInputWidget( {
14317 * var checkbox3=new OO.ui.CheckboxInputWidget( {
14321 * // Create a fieldset layout with fields for each checkbox.
14322 * var fieldset = new OO.ui.FieldsetLayout( {
14323 * label: 'Checkboxes'
14325 * fieldset.addItems( [
14326 * new OO.ui.FieldLayout( checkbox1, { label: 'Selected checkbox', align: 'inline' } ),
14327 * new OO.ui.FieldLayout( checkbox2, { label: 'Unselected checkbox', align: 'inline' } ),
14328 * new OO.ui.FieldLayout( checkbox3, { label: 'Disabled checkbox', align: 'inline' } ),
14330 * $( 'body' ).append( fieldset.$element );
14332 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
14335 * @extends OO.ui.InputWidget
14338 * @param {Object} [config] Configuration options
14339 * @cfg {boolean} [selected=false] Select the checkbox initially. By default, the checkbox is not selected.
14341 OO
.ui
.CheckboxInputWidget
= function OoUiCheckboxInputWidget( config
) {
14342 // Configuration initialization
14343 config
= config
|| {};
14345 // Parent constructor
14346 OO
.ui
.CheckboxInputWidget
.parent
.call( this, config
);
14350 .addClass( 'oo-ui-checkboxInputWidget' )
14351 // Required for pretty styling in MediaWiki theme
14352 .append( $( '<span>' ) );
14353 this.setSelected( config
.selected
!== undefined ? config
.selected
: false );
14358 OO
.inheritClass( OO
.ui
.CheckboxInputWidget
, OO
.ui
.InputWidget
);
14366 OO
.ui
.CheckboxInputWidget
.prototype.getInputElement = function () {
14367 return $( '<input type="checkbox" />' );
14373 OO
.ui
.CheckboxInputWidget
.prototype.onEdit = function () {
14375 if ( !this.isDisabled() ) {
14376 // Allow the stack to clear so the value will be updated
14377 setTimeout( function () {
14378 widget
.setSelected( widget
.$input
.prop( 'checked' ) );
14384 * Set selection state of this checkbox.
14386 * @param {boolean} state `true` for selected
14389 OO
.ui
.CheckboxInputWidget
.prototype.setSelected = function ( state
) {
14391 if ( this.selected
!== state
) {
14392 this.selected
= state
;
14393 this.$input
.prop( 'checked', this.selected
);
14394 this.emit( 'change', this.selected
);
14400 * Check if this checkbox is selected.
14402 * @return {boolean} Checkbox is selected
14404 OO
.ui
.CheckboxInputWidget
.prototype.isSelected = function () {
14405 // Resynchronize our internal data with DOM data. Other scripts executing on the page can modify
14406 // it, and we won't know unless they're kind enough to trigger a 'change' event.
14407 var selected
= this.$input
.prop( 'checked' );
14408 if ( this.selected
!== selected
) {
14409 this.setSelected( selected
);
14411 return this.selected
;
14417 OO
.ui
.CheckboxInputWidget
.prototype.gatherPreInfuseState = function ( node
) {
14419 state
= OO
.ui
.CheckboxInputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
),
14420 $input
= $( node
).find( '.oo-ui-inputWidget-input' );
14421 state
.$input
= $input
; // shortcut for performance, used in InputWidget
14422 state
.checked
= $input
.prop( 'checked' );
14429 OO
.ui
.CheckboxInputWidget
.prototype.restorePreInfuseState = function ( state
) {
14430 OO
.ui
.CheckboxInputWidget
.parent
.prototype.restorePreInfuseState
.call( this, state
);
14431 if ( state
.checked
!== undefined && state
.checked
!== this.isSelected() ) {
14432 this.setSelected( state
.checked
);
14437 * DropdownInputWidget is a {@link OO.ui.DropdownWidget DropdownWidget} intended to be used
14438 * within a HTML form, such as a OO.ui.FormLayout. The selected value is synchronized with the value
14439 * of a hidden HTML `input` tag. Please see the [OOjs UI documentation on MediaWiki][1] for
14440 * more information about input widgets.
14442 * A DropdownInputWidget always has a value (one of the options is always selected), unless there
14443 * are no options. If no `value` configuration option is provided, the first option is selected.
14444 * If you need a state representing no value (no option being selected), use a DropdownWidget.
14446 * This and OO.ui.RadioSelectInputWidget support the same configuration options.
14449 * // Example: A DropdownInputWidget with three options
14450 * var dropdownInput = new OO.ui.DropdownInputWidget( {
14452 * { data: 'a', label: 'First' },
14453 * { data: 'b', label: 'Second'},
14454 * { data: 'c', label: 'Third' }
14457 * $( 'body' ).append( dropdownInput.$element );
14459 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
14462 * @extends OO.ui.InputWidget
14463 * @mixins OO.ui.mixin.TitledElement
14466 * @param {Object} [config] Configuration options
14467 * @cfg {Object[]} [options=[]] Array of menu options in the format `{ data: …, label: … }`
14469 OO
.ui
.DropdownInputWidget
= function OoUiDropdownInputWidget( config
) {
14470 // Configuration initialization
14471 config
= config
|| {};
14473 // Properties (must be done before parent constructor which calls #setDisabled)
14474 this.dropdownWidget
= new OO
.ui
.DropdownWidget();
14476 // Parent constructor
14477 OO
.ui
.DropdownInputWidget
.parent
.call( this, config
);
14479 // Mixin constructors
14480 OO
.ui
.mixin
.TitledElement
.call( this, config
);
14483 this.dropdownWidget
.getMenu().connect( this, { select
: 'onMenuSelect' } );
14486 this.setOptions( config
.options
|| [] );
14488 .addClass( 'oo-ui-dropdownInputWidget' )
14489 .append( this.dropdownWidget
.$element
);
14494 OO
.inheritClass( OO
.ui
.DropdownInputWidget
, OO
.ui
.InputWidget
);
14495 OO
.mixinClass( OO
.ui
.DropdownInputWidget
, OO
.ui
.mixin
.TitledElement
);
14503 OO
.ui
.DropdownInputWidget
.prototype.getInputElement = function () {
14504 return $( '<input type="hidden">' );
14508 * Handles menu select events.
14511 * @param {OO.ui.MenuOptionWidget} item Selected menu item
14513 OO
.ui
.DropdownInputWidget
.prototype.onMenuSelect = function ( item
) {
14514 this.setValue( item
.getData() );
14520 OO
.ui
.DropdownInputWidget
.prototype.setValue = function ( value
) {
14521 value
= this.cleanUpValue( value
);
14522 this.dropdownWidget
.getMenu().selectItemByData( value
);
14523 OO
.ui
.DropdownInputWidget
.parent
.prototype.setValue
.call( this, value
);
14530 OO
.ui
.DropdownInputWidget
.prototype.setDisabled = function ( state
) {
14531 this.dropdownWidget
.setDisabled( state
);
14532 OO
.ui
.DropdownInputWidget
.parent
.prototype.setDisabled
.call( this, state
);
14537 * Set the options available for this input.
14539 * @param {Object[]} options Array of menu options in the format `{ data: …, label: … }`
14542 OO
.ui
.DropdownInputWidget
.prototype.setOptions = function ( options
) {
14544 value
= this.getValue(),
14547 // Rebuild the dropdown menu
14548 this.dropdownWidget
.getMenu()
14550 .addItems( options
.map( function ( opt
) {
14551 var optValue
= widget
.cleanUpValue( opt
.data
);
14552 return new OO
.ui
.MenuOptionWidget( {
14554 label
: opt
.label
!== undefined ? opt
.label
: optValue
14558 // Restore the previous value, or reset to something sensible
14559 if ( this.dropdownWidget
.getMenu().getItemFromData( value
) ) {
14560 // Previous value is still available, ensure consistency with the dropdown
14561 this.setValue( value
);
14563 // No longer valid, reset
14564 if ( options
.length
) {
14565 this.setValue( options
[ 0 ].data
);
14575 OO
.ui
.DropdownInputWidget
.prototype.focus = function () {
14576 this.dropdownWidget
.getMenu().toggle( true );
14583 OO
.ui
.DropdownInputWidget
.prototype.blur = function () {
14584 this.dropdownWidget
.getMenu().toggle( false );
14589 * RadioInputWidget creates a single radio button. Because radio buttons are usually used as a set,
14590 * in most cases you will want to use a {@link OO.ui.RadioSelectWidget radio select}
14591 * with {@link OO.ui.RadioOptionWidget radio options} instead of this class. For more information,
14592 * please see the [OOjs UI documentation on MediaWiki][1].
14594 * This widget can be used inside a HTML form, such as a OO.ui.FormLayout.
14597 * // An example of selected, unselected, and disabled radio inputs
14598 * var radio1 = new OO.ui.RadioInputWidget( {
14602 * var radio2 = new OO.ui.RadioInputWidget( {
14605 * var radio3 = new OO.ui.RadioInputWidget( {
14609 * // Create a fieldset layout with fields for each radio button.
14610 * var fieldset = new OO.ui.FieldsetLayout( {
14611 * label: 'Radio inputs'
14613 * fieldset.addItems( [
14614 * new OO.ui.FieldLayout( radio1, { label: 'Selected', align: 'inline' } ),
14615 * new OO.ui.FieldLayout( radio2, { label: 'Unselected', align: 'inline' } ),
14616 * new OO.ui.FieldLayout( radio3, { label: 'Disabled', align: 'inline' } ),
14618 * $( 'body' ).append( fieldset.$element );
14620 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
14623 * @extends OO.ui.InputWidget
14626 * @param {Object} [config] Configuration options
14627 * @cfg {boolean} [selected=false] Select the radio button initially. By default, the radio button is not selected.
14629 OO
.ui
.RadioInputWidget
= function OoUiRadioInputWidget( config
) {
14630 // Configuration initialization
14631 config
= config
|| {};
14633 // Parent constructor
14634 OO
.ui
.RadioInputWidget
.parent
.call( this, config
);
14638 .addClass( 'oo-ui-radioInputWidget' )
14639 // Required for pretty styling in MediaWiki theme
14640 .append( $( '<span>' ) );
14641 this.setSelected( config
.selected
!== undefined ? config
.selected
: false );
14646 OO
.inheritClass( OO
.ui
.RadioInputWidget
, OO
.ui
.InputWidget
);
14654 OO
.ui
.RadioInputWidget
.prototype.getInputElement = function () {
14655 return $( '<input type="radio" />' );
14661 OO
.ui
.RadioInputWidget
.prototype.onEdit = function () {
14662 // RadioInputWidget doesn't track its state.
14666 * Set selection state of this radio button.
14668 * @param {boolean} state `true` for selected
14671 OO
.ui
.RadioInputWidget
.prototype.setSelected = function ( state
) {
14672 // RadioInputWidget doesn't track its state.
14673 this.$input
.prop( 'checked', state
);
14678 * Check if this radio button is selected.
14680 * @return {boolean} Radio is selected
14682 OO
.ui
.RadioInputWidget
.prototype.isSelected = function () {
14683 return this.$input
.prop( 'checked' );
14689 OO
.ui
.RadioInputWidget
.prototype.gatherPreInfuseState = function ( node
) {
14691 state
= OO
.ui
.RadioInputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
),
14692 $input
= $( node
).find( '.oo-ui-inputWidget-input' );
14693 state
.$input
= $input
; // shortcut for performance, used in InputWidget
14694 state
.checked
= $input
.prop( 'checked' );
14701 OO
.ui
.RadioInputWidget
.prototype.restorePreInfuseState = function ( state
) {
14702 OO
.ui
.RadioInputWidget
.parent
.prototype.restorePreInfuseState
.call( this, state
);
14703 if ( state
.checked
!== undefined && state
.checked
!== this.isSelected() ) {
14704 this.setSelected( state
.checked
);
14709 * RadioSelectInputWidget is a {@link OO.ui.RadioSelectWidget RadioSelectWidget} intended to be used
14710 * within a HTML form, such as a OO.ui.FormLayout. The selected value is synchronized with the value
14711 * of a hidden HTML `input` tag. Please see the [OOjs UI documentation on MediaWiki][1] for
14712 * more information about input widgets.
14714 * This and OO.ui.DropdownInputWidget support the same configuration options.
14717 * // Example: A RadioSelectInputWidget with three options
14718 * var radioSelectInput = new OO.ui.RadioSelectInputWidget( {
14720 * { data: 'a', label: 'First' },
14721 * { data: 'b', label: 'Second'},
14722 * { data: 'c', label: 'Third' }
14725 * $( 'body' ).append( radioSelectInput.$element );
14727 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
14730 * @extends OO.ui.InputWidget
14733 * @param {Object} [config] Configuration options
14734 * @cfg {Object[]} [options=[]] Array of menu options in the format `{ data: …, label: … }`
14736 OO
.ui
.RadioSelectInputWidget
= function OoUiRadioSelectInputWidget( config
) {
14737 // Configuration initialization
14738 config
= config
|| {};
14740 // Properties (must be done before parent constructor which calls #setDisabled)
14741 this.radioSelectWidget
= new OO
.ui
.RadioSelectWidget();
14743 // Parent constructor
14744 OO
.ui
.RadioSelectInputWidget
.parent
.call( this, config
);
14747 this.radioSelectWidget
.connect( this, { select
: 'onMenuSelect' } );
14750 this.setOptions( config
.options
|| [] );
14752 .addClass( 'oo-ui-radioSelectInputWidget' )
14753 .append( this.radioSelectWidget
.$element
);
14758 OO
.inheritClass( OO
.ui
.RadioSelectInputWidget
, OO
.ui
.InputWidget
);
14760 /* Static Properties */
14762 OO
.ui
.RadioSelectInputWidget
.static.supportsSimpleLabel
= false;
14770 OO
.ui
.RadioSelectInputWidget
.prototype.getInputElement = function () {
14771 return $( '<input type="hidden">' );
14775 * Handles menu select events.
14778 * @param {OO.ui.RadioOptionWidget} item Selected menu item
14780 OO
.ui
.RadioSelectInputWidget
.prototype.onMenuSelect = function ( item
) {
14781 this.setValue( item
.getData() );
14787 OO
.ui
.RadioSelectInputWidget
.prototype.setValue = function ( value
) {
14788 value
= this.cleanUpValue( value
);
14789 this.radioSelectWidget
.selectItemByData( value
);
14790 OO
.ui
.RadioSelectInputWidget
.parent
.prototype.setValue
.call( this, value
);
14797 OO
.ui
.RadioSelectInputWidget
.prototype.setDisabled = function ( state
) {
14798 this.radioSelectWidget
.setDisabled( state
);
14799 OO
.ui
.RadioSelectInputWidget
.parent
.prototype.setDisabled
.call( this, state
);
14804 * Set the options available for this input.
14806 * @param {Object[]} options Array of menu options in the format `{ data: …, label: … }`
14809 OO
.ui
.RadioSelectInputWidget
.prototype.setOptions = function ( options
) {
14811 value
= this.getValue(),
14814 // Rebuild the radioSelect menu
14815 this.radioSelectWidget
14817 .addItems( options
.map( function ( opt
) {
14818 var optValue
= widget
.cleanUpValue( opt
.data
);
14819 return new OO
.ui
.RadioOptionWidget( {
14821 label
: opt
.label
!== undefined ? opt
.label
: optValue
14825 // Restore the previous value, or reset to something sensible
14826 if ( this.radioSelectWidget
.getItemFromData( value
) ) {
14827 // Previous value is still available, ensure consistency with the radioSelect
14828 this.setValue( value
);
14830 // No longer valid, reset
14831 if ( options
.length
) {
14832 this.setValue( options
[ 0 ].data
);
14842 OO
.ui
.RadioSelectInputWidget
.prototype.gatherPreInfuseState = function ( node
) {
14843 var state
= OO
.ui
.RadioSelectInputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
);
14844 state
.value
= $( node
).find( '.oo-ui-radioInputWidget .oo-ui-inputWidget-input:checked' ).val();
14849 * TextInputWidgets, like HTML text inputs, can be configured with options that customize the
14850 * size of the field as well as its presentation. In addition, these widgets can be configured
14851 * with {@link OO.ui.mixin.IconElement icons}, {@link OO.ui.mixin.IndicatorElement indicators}, an optional
14852 * validation-pattern (used to determine if an input value is valid or not) and an input filter,
14853 * which modifies incoming values rather than validating them.
14854 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information and examples.
14856 * This widget can be used inside a HTML form, such as a OO.ui.FormLayout.
14859 * // Example of a text input widget
14860 * var textInput = new OO.ui.TextInputWidget( {
14861 * value: 'Text input'
14863 * $( 'body' ).append( textInput.$element );
14865 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
14868 * @extends OO.ui.InputWidget
14869 * @mixins OO.ui.mixin.IconElement
14870 * @mixins OO.ui.mixin.IndicatorElement
14871 * @mixins OO.ui.mixin.PendingElement
14872 * @mixins OO.ui.mixin.LabelElement
14875 * @param {Object} [config] Configuration options
14876 * @cfg {string} [type='text'] The value of the HTML `type` attribute: 'text', 'password', 'search',
14877 * 'email' or 'url'. Ignored if `multiline` is true.
14879 * Some values of `type` result in additional behaviors:
14881 * - `search`: implies `icon: 'search'` and `indicator: 'clear'`; when clicked, the indicator
14882 * empties the text field
14883 * @cfg {string} [placeholder] Placeholder text
14884 * @cfg {boolean} [autofocus=false] Use an HTML `autofocus` attribute to
14885 * instruct the browser to focus this widget.
14886 * @cfg {boolean} [readOnly=false] Prevent changes to the value of the text input.
14887 * @cfg {number} [maxLength] Maximum number of characters allowed in the input.
14888 * @cfg {boolean} [multiline=false] Allow multiple lines of text
14889 * @cfg {number} [rows] If multiline, number of visible lines in textarea. If used with `autosize`,
14890 * specifies minimum number of rows to display.
14891 * @cfg {boolean} [autosize=false] Automatically resize the text input to fit its content.
14892 * Use the #maxRows config to specify a maximum number of displayed rows.
14893 * @cfg {boolean} [maxRows] Maximum number of rows to display when #autosize is set to true.
14894 * Defaults to the maximum of `10` and `2 * rows`, or `10` if `rows` isn't provided.
14895 * @cfg {string} [labelPosition='after'] The position of the inline label relative to that of
14896 * the value or placeholder text: `'before'` or `'after'`
14897 * @cfg {boolean} [required=false] Mark the field as required. Implies `indicator: 'required'`.
14898 * @cfg {boolean} [autocomplete=true] Should the browser support autocomplete for this field
14899 * @cfg {RegExp|Function|string} [validate] Validation pattern: when string, a symbolic name of a
14900 * pattern defined by the class: 'non-empty' (the value cannot be an empty string) or 'integer'
14901 * (the value must contain only numbers); when RegExp, a regular expression that must match the
14902 * value for it to be considered valid; when Function, a function receiving the value as parameter
14903 * that must return true, or promise that resolves, for it to be considered valid.
14905 OO
.ui
.TextInputWidget
= function OoUiTextInputWidget( config
) {
14906 // Configuration initialization
14907 config
= $.extend( {
14909 labelPosition
: 'after'
14911 if ( config
.type
=== 'search' ) {
14912 if ( config
.icon
=== undefined ) {
14913 config
.icon
= 'search';
14915 // indicator: 'clear' is set dynamically later, depending on value
14917 if ( config
.required
) {
14918 if ( config
.indicator
=== undefined ) {
14919 config
.indicator
= 'required';
14923 // Parent constructor
14924 OO
.ui
.TextInputWidget
.parent
.call( this, config
);
14926 // Mixin constructors
14927 OO
.ui
.mixin
.IconElement
.call( this, config
);
14928 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
14929 OO
.ui
.mixin
.PendingElement
.call( this, $.extend( {}, config
, { $pending
: this.$input
} ) );
14930 OO
.ui
.mixin
.LabelElement
.call( this, config
);
14933 this.type
= this.getSaneType( config
);
14934 this.readOnly
= false;
14935 this.multiline
= !!config
.multiline
;
14936 this.autosize
= !!config
.autosize
;
14937 this.minRows
= config
.rows
!== undefined ? config
.rows
: '';
14938 this.maxRows
= config
.maxRows
|| Math
.max( 2 * ( this.minRows
|| 0 ), 10 );
14939 this.validate
= null;
14941 // Clone for resizing
14942 if ( this.autosize
) {
14943 this.$clone
= this.$input
14945 .insertAfter( this.$input
)
14946 .attr( 'aria-hidden', 'true' )
14947 .addClass( 'oo-ui-element-hidden' );
14950 this.setValidation( config
.validate
);
14951 this.setLabelPosition( config
.labelPosition
);
14955 keypress
: this.onKeyPress
.bind( this ),
14956 blur
: this.onBlur
.bind( this )
14959 focus
: this.onElementAttach
.bind( this )
14961 this.$icon
.on( 'mousedown', this.onIconMouseDown
.bind( this ) );
14962 this.$indicator
.on( 'mousedown', this.onIndicatorMouseDown
.bind( this ) );
14963 this.on( 'labelChange', this.updatePosition
.bind( this ) );
14964 this.connect( this, {
14965 change
: 'onChange',
14966 disable
: 'onDisable'
14971 .addClass( 'oo-ui-textInputWidget oo-ui-textInputWidget-type-' + this.type
)
14972 .append( this.$icon
, this.$indicator
);
14973 this.setReadOnly( !!config
.readOnly
);
14974 this.updateSearchIndicator();
14975 if ( config
.placeholder
) {
14976 this.$input
.attr( 'placeholder', config
.placeholder
);
14978 if ( config
.maxLength
!== undefined ) {
14979 this.$input
.attr( 'maxlength', config
.maxLength
);
14981 if ( config
.autofocus
) {
14982 this.$input
.attr( 'autofocus', 'autofocus' );
14984 if ( config
.required
) {
14985 this.$input
.attr( 'required', 'required' );
14986 this.$input
.attr( 'aria-required', 'true' );
14988 if ( config
.autocomplete
=== false ) {
14989 this.$input
.attr( 'autocomplete', 'off' );
14991 if ( this.multiline
&& config
.rows
) {
14992 this.$input
.attr( 'rows', config
.rows
);
14994 if ( this.label
|| config
.autosize
) {
14995 this.installParentChangeDetector();
15001 OO
.inheritClass( OO
.ui
.TextInputWidget
, OO
.ui
.InputWidget
);
15002 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.mixin
.IconElement
);
15003 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.mixin
.IndicatorElement
);
15004 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.mixin
.PendingElement
);
15005 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.mixin
.LabelElement
);
15007 /* Static Properties */
15009 OO
.ui
.TextInputWidget
.static.validationPatterns
= {
15017 * An `enter` event is emitted when the user presses 'enter' inside the text box.
15019 * Not emitted if the input is multiline.
15027 * Handle icon mouse down events.
15030 * @param {jQuery.Event} e Mouse down event
15033 OO
.ui
.TextInputWidget
.prototype.onIconMouseDown = function ( e
) {
15034 if ( e
.which
=== 1 ) {
15035 this.$input
[ 0 ].focus();
15041 * Handle indicator mouse down events.
15044 * @param {jQuery.Event} e Mouse down event
15047 OO
.ui
.TextInputWidget
.prototype.onIndicatorMouseDown = function ( e
) {
15048 if ( e
.which
=== 1 ) {
15049 if ( this.type
=== 'search' ) {
15050 // Clear the text field
15051 this.setValue( '' );
15053 this.$input
[ 0 ].focus();
15059 * Handle key press events.
15062 * @param {jQuery.Event} e Key press event
15063 * @fires enter If enter key is pressed and input is not multiline
15065 OO
.ui
.TextInputWidget
.prototype.onKeyPress = function ( e
) {
15066 if ( e
.which
=== OO
.ui
.Keys
.ENTER
&& !this.multiline
) {
15067 this.emit( 'enter', e
);
15072 * Handle blur events.
15075 * @param {jQuery.Event} e Blur event
15077 OO
.ui
.TextInputWidget
.prototype.onBlur = function () {
15078 this.setValidityFlag();
15082 * Handle element attach events.
15085 * @param {jQuery.Event} e Element attach event
15087 OO
.ui
.TextInputWidget
.prototype.onElementAttach = function () {
15088 // Any previously calculated size is now probably invalid if we reattached elsewhere
15089 this.valCache
= null;
15091 this.positionLabel();
15095 * Handle change events.
15097 * @param {string} value
15100 OO
.ui
.TextInputWidget
.prototype.onChange = function () {
15101 this.updateSearchIndicator();
15102 this.setValidityFlag();
15107 * Handle disable events.
15109 * @param {boolean} disabled Element is disabled
15112 OO
.ui
.TextInputWidget
.prototype.onDisable = function () {
15113 this.updateSearchIndicator();
15117 * Check if the input is {@link #readOnly read-only}.
15119 * @return {boolean}
15121 OO
.ui
.TextInputWidget
.prototype.isReadOnly = function () {
15122 return this.readOnly
;
15126 * Set the {@link #readOnly read-only} state of the input.
15128 * @param {boolean} state Make input read-only
15131 OO
.ui
.TextInputWidget
.prototype.setReadOnly = function ( state
) {
15132 this.readOnly
= !!state
;
15133 this.$input
.prop( 'readOnly', this.readOnly
);
15134 this.updateSearchIndicator();
15139 * Support function for making #onElementAttach work across browsers.
15141 * This whole function could be replaced with one line of code using the DOMNodeInsertedIntoDocument
15142 * event, but it's not supported by Firefox and allegedly deprecated, so we only use it as fallback.
15144 * Due to MutationObserver performance woes, #onElementAttach is only somewhat reliably called the
15145 * first time that the element gets attached to the documented.
15147 OO
.ui
.TextInputWidget
.prototype.installParentChangeDetector = function () {
15148 var mutationObserver
, onRemove
, topmostNode
, fakeParentNode
,
15149 MutationObserver
= window
.MutationObserver
|| window
.WebKitMutationObserver
|| window
.MozMutationObserver
,
15152 if ( MutationObserver
) {
15153 // The new way. If only it wasn't so ugly.
15155 if ( this.$element
.closest( 'html' ).length
) {
15156 // Widget is attached already, do nothing. This breaks the functionality of this function when
15157 // the widget is detached and reattached. Alas, doing this correctly with MutationObserver
15158 // would require observation of the whole document, which would hurt performance of other,
15159 // more important code.
15163 // Find topmost node in the tree
15164 topmostNode
= this.$element
[0];
15165 while ( topmostNode
.parentNode
) {
15166 topmostNode
= topmostNode
.parentNode
;
15169 // We have no way to detect the $element being attached somewhere without observing the entire
15170 // DOM with subtree modifications, which would hurt performance. So we cheat: we hook to the
15171 // parent node of $element, and instead detect when $element is removed from it (and thus
15172 // probably attached somewhere else). If there is no parent, we create a "fake" one. If it
15173 // doesn't get attached, we end up back here and create the parent.
15175 mutationObserver
= new MutationObserver( function ( mutations
) {
15176 var i
, j
, removedNodes
;
15177 for ( i
= 0; i
< mutations
.length
; i
++ ) {
15178 removedNodes
= mutations
[ i
].removedNodes
;
15179 for ( j
= 0; j
< removedNodes
.length
; j
++ ) {
15180 if ( removedNodes
[ j
] === topmostNode
) {
15181 setTimeout( onRemove
, 0 );
15188 onRemove = function () {
15189 // If the node was attached somewhere else, report it
15190 if ( widget
.$element
.closest( 'html' ).length
) {
15191 widget
.onElementAttach();
15193 mutationObserver
.disconnect();
15194 widget
.installParentChangeDetector();
15197 // Create a fake parent and observe it
15198 fakeParentNode
= $( '<div>' ).append( topmostNode
)[0];
15199 mutationObserver
.observe( fakeParentNode
, { childList
: true } );
15201 // Using the DOMNodeInsertedIntoDocument event is much nicer and less magical, and works for
15202 // detachment and reattachment, but it's not supported by Firefox and allegedly deprecated.
15203 this.$element
.on( 'DOMNodeInsertedIntoDocument', this.onElementAttach
.bind( this ) );
15208 * Automatically adjust the size of the text input.
15210 * This only affects #multiline inputs that are {@link #autosize autosized}.
15214 OO
.ui
.TextInputWidget
.prototype.adjustSize = function () {
15215 var scrollHeight
, innerHeight
, outerHeight
, maxInnerHeight
, measurementError
, idealHeight
;
15217 if ( this.multiline
&& this.autosize
&& this.$input
.val() !== this.valCache
) {
15219 .val( this.$input
.val() )
15220 .attr( 'rows', this.minRows
)
15221 // Set inline height property to 0 to measure scroll height
15222 .css( 'height', 0 );
15224 this.$clone
.removeClass( 'oo-ui-element-hidden' );
15226 this.valCache
= this.$input
.val();
15228 scrollHeight
= this.$clone
[ 0 ].scrollHeight
;
15230 // Remove inline height property to measure natural heights
15231 this.$clone
.css( 'height', '' );
15232 innerHeight
= this.$clone
.innerHeight();
15233 outerHeight
= this.$clone
.outerHeight();
15235 // Measure max rows height
15237 .attr( 'rows', this.maxRows
)
15238 .css( 'height', 'auto' )
15240 maxInnerHeight
= this.$clone
.innerHeight();
15242 // Difference between reported innerHeight and scrollHeight with no scrollbars present
15243 // Equals 1 on Blink-based browsers and 0 everywhere else
15244 measurementError
= maxInnerHeight
- this.$clone
[ 0 ].scrollHeight
;
15245 idealHeight
= Math
.min( maxInnerHeight
, scrollHeight
+ measurementError
);
15247 this.$clone
.addClass( 'oo-ui-element-hidden' );
15249 // Only apply inline height when expansion beyond natural height is needed
15250 if ( idealHeight
> innerHeight
) {
15251 // Use the difference between the inner and outer height as a buffer
15252 this.$input
.css( 'height', idealHeight
+ ( outerHeight
- innerHeight
) );
15254 this.$input
.css( 'height', '' );
15264 OO
.ui
.TextInputWidget
.prototype.getInputElement = function ( config
) {
15265 return config
.multiline
?
15266 $( '<textarea>' ) :
15267 $( '<input type="' + this.getSaneType( config
) + '" />' );
15271 * Get sanitized value for 'type' for given config.
15273 * @param {Object} config Configuration options
15274 * @return {string|null}
15277 OO
.ui
.TextInputWidget
.prototype.getSaneType = function ( config
) {
15278 var type
= [ 'text', 'password', 'search', 'email', 'url' ].indexOf( config
.type
) !== -1 ?
15281 return config
.multiline
? 'multiline' : type
;
15285 * Check if the input supports multiple lines.
15287 * @return {boolean}
15289 OO
.ui
.TextInputWidget
.prototype.isMultiline = function () {
15290 return !!this.multiline
;
15294 * Check if the input automatically adjusts its size.
15296 * @return {boolean}
15298 OO
.ui
.TextInputWidget
.prototype.isAutosizing = function () {
15299 return !!this.autosize
;
15303 * Select the entire text of the input.
15307 OO
.ui
.TextInputWidget
.prototype.select = function () {
15308 this.$input
.select();
15313 * Set the validation pattern.
15315 * The validation pattern is either a regular expression, a function, or the symbolic name of a
15316 * pattern defined by the class: 'non-empty' (the value cannot be an empty string) or 'integer' (the
15317 * value must contain only numbers).
15319 * @param {RegExp|Function|string|null} validate Regular expression, function, or the symbolic name
15320 * of a pattern (either ‘integer’ or ‘non-empty’) defined by the class.
15322 OO
.ui
.TextInputWidget
.prototype.setValidation = function ( validate
) {
15323 if ( validate
instanceof RegExp
|| validate
instanceof Function
) {
15324 this.validate
= validate
;
15326 this.validate
= this.constructor.static.validationPatterns
[ validate
] || /.*/;
15331 * Sets the 'invalid' flag appropriately.
15333 * @param {boolean} [isValid] Optionally override validation result
15335 OO
.ui
.TextInputWidget
.prototype.setValidityFlag = function ( isValid
) {
15337 setFlag = function ( valid
) {
15339 widget
.$input
.attr( 'aria-invalid', 'true' );
15341 widget
.$input
.removeAttr( 'aria-invalid' );
15343 widget
.setFlags( { invalid
: !valid
} );
15346 if ( isValid
!== undefined ) {
15347 setFlag( isValid
);
15349 this.getValidity().then( function () {
15358 * Check if a value is valid.
15360 * This method returns a promise that resolves with a boolean `true` if the current value is
15361 * considered valid according to the supplied {@link #validate validation pattern}.
15364 * @return {jQuery.Promise} A promise that resolves to a boolean `true` if the value is valid.
15366 OO
.ui
.TextInputWidget
.prototype.isValid = function () {
15367 if ( this.validate
instanceof Function
) {
15368 var result
= this.validate( this.getValue() );
15369 if ( $.isFunction( result
.promise
) ) {
15370 return result
.promise();
15372 return $.Deferred().resolve( !!result
).promise();
15375 return $.Deferred().resolve( !!this.getValue().match( this.validate
) ).promise();
15380 * Get the validity of current value.
15382 * This method returns a promise that resolves if the value is valid and rejects if
15383 * it isn't. Uses the {@link #validate validation pattern} to check for validity.
15385 * @return {jQuery.Promise} A promise that resolves if the value is valid, rejects if not.
15387 OO
.ui
.TextInputWidget
.prototype.getValidity = function () {
15388 var result
, promise
;
15390 function rejectOrResolve( valid
) {
15392 return $.Deferred().resolve().promise();
15394 return $.Deferred().reject().promise();
15398 if ( this.validate
instanceof Function
) {
15399 result
= this.validate( this.getValue() );
15401 if ( $.isFunction( result
.promise
) ) {
15402 promise
= $.Deferred();
15404 result
.then( function ( valid
) {
15414 return promise
.promise();
15416 return rejectOrResolve( result
);
15419 return rejectOrResolve( this.getValue().match( this.validate
) );
15424 * Set the position of the inline label relative to that of the value: `‘before’` or `‘after’`.
15426 * @param {string} labelPosition Label position, 'before' or 'after'
15429 OO
.ui
.TextInputWidget
.prototype.setLabelPosition = function ( labelPosition
) {
15430 this.labelPosition
= labelPosition
;
15431 this.updatePosition();
15436 * Deprecated alias of #setLabelPosition
15438 * @deprecated Use setLabelPosition instead.
15440 OO
.ui
.TextInputWidget
.prototype.setPosition
=
15441 OO
.ui
.TextInputWidget
.prototype.setLabelPosition
;
15444 * Update the position of the inline label.
15446 * This method is called by #setLabelPosition, and can also be called on its own if
15447 * something causes the label to be mispositioned.
15451 OO
.ui
.TextInputWidget
.prototype.updatePosition = function () {
15452 var after
= this.labelPosition
=== 'after';
15455 .toggleClass( 'oo-ui-textInputWidget-labelPosition-after', !!this.label
&& after
)
15456 .toggleClass( 'oo-ui-textInputWidget-labelPosition-before', !!this.label
&& !after
);
15458 this.positionLabel();
15464 * Update the 'clear' indicator displayed on type: 'search' text fields, hiding it when the field is
15465 * already empty or when it's not editable.
15467 OO
.ui
.TextInputWidget
.prototype.updateSearchIndicator = function () {
15468 if ( this.type
=== 'search' ) {
15469 if ( this.getValue() === '' || this.isDisabled() || this.isReadOnly() ) {
15470 this.setIndicator( null );
15472 this.setIndicator( 'clear' );
15478 * Position the label by setting the correct padding on the input.
15483 OO
.ui
.TextInputWidget
.prototype.positionLabel = function () {
15484 // Clear old values
15486 // Clear old values if present
15488 'padding-right': '',
15492 if ( this.label
) {
15493 this.$element
.append( this.$label
);
15495 this.$label
.detach();
15499 var after
= this.labelPosition
=== 'after',
15500 rtl
= this.$element
.css( 'direction' ) === 'rtl',
15501 property
= after
=== rtl
? 'padding-left' : 'padding-right';
15503 this.$input
.css( property
, this.$label
.outerWidth( true ) );
15511 OO
.ui
.TextInputWidget
.prototype.gatherPreInfuseState = function ( node
) {
15513 state
= OO
.ui
.TextInputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
),
15514 $input
= $( node
).find( '.oo-ui-inputWidget-input' );
15515 state
.$input
= $input
; // shortcut for performance, used in InputWidget
15516 if ( this.multiline
) {
15517 state
.scrollTop
= $input
.scrollTop();
15525 OO
.ui
.TextInputWidget
.prototype.restorePreInfuseState = function ( state
) {
15526 OO
.ui
.TextInputWidget
.parent
.prototype.restorePreInfuseState
.call( this, state
);
15527 if ( state
.scrollTop
!== undefined ) {
15528 this.$input
.scrollTop( state
.scrollTop
);
15533 * ComboBoxWidgets combine a {@link OO.ui.TextInputWidget text input} (where a value
15534 * can be entered manually) and a {@link OO.ui.MenuSelectWidget menu of options} (from which
15535 * a value can be chosen instead). Users can choose options from the combo box in one of two ways:
15537 * - by typing a value in the text input field. If the value exactly matches the value of a menu
15538 * option, that option will appear to be selected.
15539 * - by choosing a value from the menu. The value of the chosen option will then appear in the text
15542 * For more information about menus and options, please see the [OOjs UI documentation on MediaWiki][1].
15545 * // Example: A ComboBoxWidget.
15546 * var comboBox = new OO.ui.ComboBoxWidget( {
15547 * label: 'ComboBoxWidget',
15548 * input: { value: 'Option One' },
15551 * new OO.ui.MenuOptionWidget( {
15552 * data: 'Option 1',
15553 * label: 'Option One'
15555 * new OO.ui.MenuOptionWidget( {
15556 * data: 'Option 2',
15557 * label: 'Option Two'
15559 * new OO.ui.MenuOptionWidget( {
15560 * data: 'Option 3',
15561 * label: 'Option Three'
15563 * new OO.ui.MenuOptionWidget( {
15564 * data: 'Option 4',
15565 * label: 'Option Four'
15567 * new OO.ui.MenuOptionWidget( {
15568 * data: 'Option 5',
15569 * label: 'Option Five'
15574 * $( 'body' ).append( comboBox.$element );
15576 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Menu_selects_and_options
15579 * @extends OO.ui.Widget
15580 * @mixins OO.ui.mixin.TabIndexedElement
15583 * @param {Object} [config] Configuration options
15584 * @cfg {Object} [menu] Configuration options to pass to the {@link OO.ui.MenuSelectWidget menu select widget}.
15585 * @cfg {Object} [input] Configuration options to pass to the {@link OO.ui.TextInputWidget text input widget}.
15586 * @cfg {jQuery} [$overlay] Render the menu into a separate layer. This configuration is useful in cases where
15587 * the expanded menu is larger than its containing `<div>`. The specified overlay layer is usually on top of the
15588 * containing `<div>` and has a larger area. By default, the menu uses relative positioning.
15590 OO
.ui
.ComboBoxWidget
= function OoUiComboBoxWidget( config
) {
15591 // Configuration initialization
15592 config
= config
|| {};
15594 // Parent constructor
15595 OO
.ui
.ComboBoxWidget
.parent
.call( this, config
);
15597 // Properties (must be set before TabIndexedElement constructor call)
15598 this.$indicator
= this.$( '<span>' );
15600 // Mixin constructors
15601 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$indicator
} ) );
15604 this.$overlay
= config
.$overlay
|| this.$element
;
15605 this.input
= new OO
.ui
.TextInputWidget( $.extend(
15608 $indicator
: this.$indicator
,
15609 disabled
: this.isDisabled()
15613 this.input
.$input
.eq( 0 ).attr( {
15615 'aria-autocomplete': 'list'
15617 this.menu
= new OO
.ui
.TextInputMenuSelectWidget( this.input
, $.extend(
15621 disabled
: this.isDisabled()
15627 this.$indicator
.on( {
15628 click
: this.onClick
.bind( this ),
15629 keypress
: this.onKeyPress
.bind( this )
15631 this.input
.connect( this, {
15632 change
: 'onInputChange',
15633 enter
: 'onInputEnter'
15635 this.menu
.connect( this, {
15636 choose
: 'onMenuChoose',
15637 add
: 'onMenuItemsChange',
15638 remove
: 'onMenuItemsChange'
15642 this.$element
.addClass( 'oo-ui-comboBoxWidget' ).append( this.input
.$element
);
15643 this.$overlay
.append( this.menu
.$element
);
15644 this.onMenuItemsChange();
15649 OO
.inheritClass( OO
.ui
.ComboBoxWidget
, OO
.ui
.Widget
);
15650 OO
.mixinClass( OO
.ui
.ComboBoxWidget
, OO
.ui
.mixin
.TabIndexedElement
);
15655 * Get the combobox's menu.
15656 * @return {OO.ui.TextInputMenuSelectWidget} Menu widget
15658 OO
.ui
.ComboBoxWidget
.prototype.getMenu = function () {
15663 * Get the combobox's text input widget.
15664 * @return {OO.ui.TextInputWidget} Text input widget
15666 OO
.ui
.ComboBoxWidget
.prototype.getInput = function () {
15671 * Handle input change events.
15674 * @param {string} value New value
15676 OO
.ui
.ComboBoxWidget
.prototype.onInputChange = function ( value
) {
15677 var match
= this.menu
.getItemFromData( value
);
15679 this.menu
.selectItem( match
);
15680 if ( this.menu
.getHighlightedItem() ) {
15681 this.menu
.highlightItem( match
);
15684 if ( !this.isDisabled() ) {
15685 this.menu
.toggle( true );
15690 * Handle mouse click events.
15694 * @param {jQuery.Event} e Mouse click event
15696 OO
.ui
.ComboBoxWidget
.prototype.onClick = function ( e
) {
15697 if ( !this.isDisabled() && e
.which
=== 1 ) {
15698 this.menu
.toggle();
15699 this.input
.$input
[ 0 ].focus();
15705 * Handle key press events.
15709 * @param {jQuery.Event} e Key press event
15711 OO
.ui
.ComboBoxWidget
.prototype.onKeyPress = function ( e
) {
15712 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
15713 this.menu
.toggle();
15714 this.input
.$input
[ 0 ].focus();
15720 * Handle input enter events.
15724 OO
.ui
.ComboBoxWidget
.prototype.onInputEnter = function () {
15725 if ( !this.isDisabled() ) {
15726 this.menu
.toggle( false );
15731 * Handle menu choose events.
15734 * @param {OO.ui.OptionWidget} item Chosen item
15736 OO
.ui
.ComboBoxWidget
.prototype.onMenuChoose = function ( item
) {
15737 this.input
.setValue( item
.getData() );
15741 * Handle menu item change events.
15745 OO
.ui
.ComboBoxWidget
.prototype.onMenuItemsChange = function () {
15746 var match
= this.menu
.getItemFromData( this.input
.getValue() );
15747 this.menu
.selectItem( match
);
15748 if ( this.menu
.getHighlightedItem() ) {
15749 this.menu
.highlightItem( match
);
15751 this.$element
.toggleClass( 'oo-ui-comboBoxWidget-empty', this.menu
.isEmpty() );
15757 OO
.ui
.ComboBoxWidget
.prototype.setDisabled = function ( disabled
) {
15759 OO
.ui
.ComboBoxWidget
.parent
.prototype.setDisabled
.call( this, disabled
);
15761 if ( this.input
) {
15762 this.input
.setDisabled( this.isDisabled() );
15765 this.menu
.setDisabled( this.isDisabled() );
15772 * LabelWidgets help identify the function of interface elements. Each LabelWidget can
15773 * be configured with a `label` option that is set to a string, a label node, or a function:
15775 * - String: a plaintext string
15776 * - jQuery selection: a jQuery selection, used for anything other than a plaintext label, e.g., a
15777 * label that includes a link or special styling, such as a gray color or additional graphical elements.
15778 * - Function: a function that will produce a string in the future. Functions are used
15779 * in cases where the value of the label is not currently defined.
15781 * In addition, the LabelWidget can be associated with an {@link OO.ui.InputWidget input widget}, which
15782 * will come into focus when the label is clicked.
15785 * // Examples of LabelWidgets
15786 * var label1 = new OO.ui.LabelWidget( {
15787 * label: 'plaintext label'
15789 * var label2 = new OO.ui.LabelWidget( {
15790 * label: $( '<a href="default.html">jQuery label</a>' )
15792 * // Create a fieldset layout with fields for each example
15793 * var fieldset = new OO.ui.FieldsetLayout();
15794 * fieldset.addItems( [
15795 * new OO.ui.FieldLayout( label1 ),
15796 * new OO.ui.FieldLayout( label2 )
15798 * $( 'body' ).append( fieldset.$element );
15802 * @extends OO.ui.Widget
15803 * @mixins OO.ui.mixin.LabelElement
15806 * @param {Object} [config] Configuration options
15807 * @cfg {OO.ui.InputWidget} [input] {@link OO.ui.InputWidget Input widget} that uses the label.
15808 * Clicking the label will focus the specified input field.
15810 OO
.ui
.LabelWidget
= function OoUiLabelWidget( config
) {
15811 // Configuration initialization
15812 config
= config
|| {};
15814 // Parent constructor
15815 OO
.ui
.LabelWidget
.parent
.call( this, config
);
15817 // Mixin constructors
15818 OO
.ui
.mixin
.LabelElement
.call( this, $.extend( {}, config
, { $label
: this.$element
} ) );
15819 OO
.ui
.mixin
.TitledElement
.call( this, config
);
15822 this.input
= config
.input
;
15825 if ( this.input
instanceof OO
.ui
.InputWidget
) {
15826 this.$element
.on( 'click', this.onClick
.bind( this ) );
15830 this.$element
.addClass( 'oo-ui-labelWidget' );
15835 OO
.inheritClass( OO
.ui
.LabelWidget
, OO
.ui
.Widget
);
15836 OO
.mixinClass( OO
.ui
.LabelWidget
, OO
.ui
.mixin
.LabelElement
);
15837 OO
.mixinClass( OO
.ui
.LabelWidget
, OO
.ui
.mixin
.TitledElement
);
15839 /* Static Properties */
15841 OO
.ui
.LabelWidget
.static.tagName
= 'span';
15846 * Handles label mouse click events.
15849 * @param {jQuery.Event} e Mouse click event
15851 OO
.ui
.LabelWidget
.prototype.onClick = function () {
15852 this.input
.simulateLabelClick();
15857 * OptionWidgets are special elements that can be selected and configured with data. The
15858 * data is often unique for each option, but it does not have to be. OptionWidgets are used
15859 * with OO.ui.SelectWidget to create a selection of mutually exclusive options. For more information
15860 * and examples, please see the [OOjs UI documentation on MediaWiki][1].
15862 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
15865 * @extends OO.ui.Widget
15866 * @mixins OO.ui.mixin.LabelElement
15867 * @mixins OO.ui.mixin.FlaggedElement
15870 * @param {Object} [config] Configuration options
15872 OO
.ui
.OptionWidget
= function OoUiOptionWidget( config
) {
15873 // Configuration initialization
15874 config
= config
|| {};
15876 // Parent constructor
15877 OO
.ui
.OptionWidget
.parent
.call( this, config
);
15879 // Mixin constructors
15880 OO
.ui
.mixin
.ItemWidget
.call( this );
15881 OO
.ui
.mixin
.LabelElement
.call( this, config
);
15882 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
15885 this.selected
= false;
15886 this.highlighted
= false;
15887 this.pressed
= false;
15891 .data( 'oo-ui-optionWidget', this )
15892 .attr( 'role', 'option' )
15893 .attr( 'aria-selected', 'false' )
15894 .addClass( 'oo-ui-optionWidget' )
15895 .append( this.$label
);
15900 OO
.inheritClass( OO
.ui
.OptionWidget
, OO
.ui
.Widget
);
15901 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.mixin
.ItemWidget
);
15902 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.mixin
.LabelElement
);
15903 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.mixin
.FlaggedElement
);
15905 /* Static Properties */
15907 OO
.ui
.OptionWidget
.static.selectable
= true;
15909 OO
.ui
.OptionWidget
.static.highlightable
= true;
15911 OO
.ui
.OptionWidget
.static.pressable
= true;
15913 OO
.ui
.OptionWidget
.static.scrollIntoViewOnSelect
= false;
15918 * Check if the option can be selected.
15920 * @return {boolean} Item is selectable
15922 OO
.ui
.OptionWidget
.prototype.isSelectable = function () {
15923 return this.constructor.static.selectable
&& !this.isDisabled() && this.isVisible();
15927 * Check if the option can be highlighted. A highlight indicates that the option
15928 * may be selected when a user presses enter or clicks. Disabled items cannot
15931 * @return {boolean} Item is highlightable
15933 OO
.ui
.OptionWidget
.prototype.isHighlightable = function () {
15934 return this.constructor.static.highlightable
&& !this.isDisabled() && this.isVisible();
15938 * Check if the option can be pressed. The pressed state occurs when a user mouses
15939 * down on an item, but has not yet let go of the mouse.
15941 * @return {boolean} Item is pressable
15943 OO
.ui
.OptionWidget
.prototype.isPressable = function () {
15944 return this.constructor.static.pressable
&& !this.isDisabled() && this.isVisible();
15948 * Check if the option is selected.
15950 * @return {boolean} Item is selected
15952 OO
.ui
.OptionWidget
.prototype.isSelected = function () {
15953 return this.selected
;
15957 * Check if the option is highlighted. A highlight indicates that the
15958 * item may be selected when a user presses enter or clicks.
15960 * @return {boolean} Item is highlighted
15962 OO
.ui
.OptionWidget
.prototype.isHighlighted = function () {
15963 return this.highlighted
;
15967 * Check if the option is pressed. The pressed state occurs when a user mouses
15968 * down on an item, but has not yet let go of the mouse. The item may appear
15969 * selected, but it will not be selected until the user releases the mouse.
15971 * @return {boolean} Item is pressed
15973 OO
.ui
.OptionWidget
.prototype.isPressed = function () {
15974 return this.pressed
;
15978 * Set the option’s selected state. In general, all modifications to the selection
15979 * should be handled by the SelectWidget’s {@link OO.ui.SelectWidget#selectItem selectItem( [item] )}
15980 * method instead of this method.
15982 * @param {boolean} [state=false] Select option
15985 OO
.ui
.OptionWidget
.prototype.setSelected = function ( state
) {
15986 if ( this.constructor.static.selectable
) {
15987 this.selected
= !!state
;
15989 .toggleClass( 'oo-ui-optionWidget-selected', state
)
15990 .attr( 'aria-selected', state
.toString() );
15991 if ( state
&& this.constructor.static.scrollIntoViewOnSelect
) {
15992 this.scrollElementIntoView();
15994 this.updateThemeClasses();
16000 * Set the option’s highlighted state. In general, all programmatic
16001 * modifications to the highlight should be handled by the
16002 * SelectWidget’s {@link OO.ui.SelectWidget#highlightItem highlightItem( [item] )}
16003 * method instead of this method.
16005 * @param {boolean} [state=false] Highlight option
16008 OO
.ui
.OptionWidget
.prototype.setHighlighted = function ( state
) {
16009 if ( this.constructor.static.highlightable
) {
16010 this.highlighted
= !!state
;
16011 this.$element
.toggleClass( 'oo-ui-optionWidget-highlighted', state
);
16012 this.updateThemeClasses();
16018 * Set the option’s pressed state. In general, all
16019 * programmatic modifications to the pressed state should be handled by the
16020 * SelectWidget’s {@link OO.ui.SelectWidget#pressItem pressItem( [item] )}
16021 * method instead of this method.
16023 * @param {boolean} [state=false] Press option
16026 OO
.ui
.OptionWidget
.prototype.setPressed = function ( state
) {
16027 if ( this.constructor.static.pressable
) {
16028 this.pressed
= !!state
;
16029 this.$element
.toggleClass( 'oo-ui-optionWidget-pressed', state
);
16030 this.updateThemeClasses();
16036 * DecoratedOptionWidgets are {@link OO.ui.OptionWidget options} that can be configured
16037 * with an {@link OO.ui.mixin.IconElement icon} and/or {@link OO.ui.mixin.IndicatorElement indicator}.
16038 * This class is used with OO.ui.SelectWidget to create a selection of mutually exclusive
16039 * options. For more information about options and selects, please see the
16040 * [OOjs UI documentation on MediaWiki][1].
16043 * // Decorated options in a select widget
16044 * var select = new OO.ui.SelectWidget( {
16046 * new OO.ui.DecoratedOptionWidget( {
16048 * label: 'Option with icon',
16051 * new OO.ui.DecoratedOptionWidget( {
16053 * label: 'Option with indicator',
16054 * indicator: 'next'
16058 * $( 'body' ).append( select.$element );
16060 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
16063 * @extends OO.ui.OptionWidget
16064 * @mixins OO.ui.mixin.IconElement
16065 * @mixins OO.ui.mixin.IndicatorElement
16068 * @param {Object} [config] Configuration options
16070 OO
.ui
.DecoratedOptionWidget
= function OoUiDecoratedOptionWidget( config
) {
16071 // Parent constructor
16072 OO
.ui
.DecoratedOptionWidget
.parent
.call( this, config
);
16074 // Mixin constructors
16075 OO
.ui
.mixin
.IconElement
.call( this, config
);
16076 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
16080 .addClass( 'oo-ui-decoratedOptionWidget' )
16081 .prepend( this.$icon
)
16082 .append( this.$indicator
);
16087 OO
.inheritClass( OO
.ui
.DecoratedOptionWidget
, OO
.ui
.OptionWidget
);
16088 OO
.mixinClass( OO
.ui
.DecoratedOptionWidget
, OO
.ui
.mixin
.IconElement
);
16089 OO
.mixinClass( OO
.ui
.DecoratedOptionWidget
, OO
.ui
.mixin
.IndicatorElement
);
16092 * ButtonOptionWidget is a special type of {@link OO.ui.mixin.ButtonElement button element} that
16093 * can be selected and configured with data. The class is
16094 * used with OO.ui.ButtonSelectWidget to create a selection of button options. Please see the
16095 * [OOjs UI documentation on MediaWiki] [1] for more information.
16097 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Button_selects_and_options
16100 * @extends OO.ui.DecoratedOptionWidget
16101 * @mixins OO.ui.mixin.ButtonElement
16102 * @mixins OO.ui.mixin.TabIndexedElement
16105 * @param {Object} [config] Configuration options
16107 OO
.ui
.ButtonOptionWidget
= function OoUiButtonOptionWidget( config
) {
16108 // Configuration initialization
16109 config
= config
|| {};
16111 // Parent constructor
16112 OO
.ui
.ButtonOptionWidget
.parent
.call( this, config
);
16114 // Mixin constructors
16115 OO
.ui
.mixin
.ButtonElement
.call( this, config
);
16116 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, {
16117 $tabIndexed
: this.$button
,
16122 this.$element
.addClass( 'oo-ui-buttonOptionWidget' );
16123 this.$button
.append( this.$element
.contents() );
16124 this.$element
.append( this.$button
);
16129 OO
.inheritClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
16130 OO
.mixinClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.mixin
.ButtonElement
);
16131 OO
.mixinClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.mixin
.TabIndexedElement
);
16133 /* Static Properties */
16135 // Allow button mouse down events to pass through so they can be handled by the parent select widget
16136 OO
.ui
.ButtonOptionWidget
.static.cancelButtonMouseDownEvents
= false;
16138 OO
.ui
.ButtonOptionWidget
.static.highlightable
= false;
16145 OO
.ui
.ButtonOptionWidget
.prototype.setSelected = function ( state
) {
16146 OO
.ui
.ButtonOptionWidget
.parent
.prototype.setSelected
.call( this, state
);
16148 if ( this.constructor.static.selectable
) {
16149 this.setActive( state
);
16156 * RadioOptionWidget is an option widget that looks like a radio button.
16157 * The class is used with OO.ui.RadioSelectWidget to create a selection of radio options.
16158 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information.
16160 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Button_selects_and_option
16163 * @extends OO.ui.OptionWidget
16166 * @param {Object} [config] Configuration options
16168 OO
.ui
.RadioOptionWidget
= function OoUiRadioOptionWidget( config
) {
16169 // Configuration initialization
16170 config
= config
|| {};
16172 // Properties (must be done before parent constructor which calls #setDisabled)
16173 this.radio
= new OO
.ui
.RadioInputWidget( { value
: config
.data
, tabIndex
: -1 } );
16175 // Parent constructor
16176 OO
.ui
.RadioOptionWidget
.parent
.call( this, config
);
16179 this.radio
.$input
.on( 'focus', this.onInputFocus
.bind( this ) );
16182 // Remove implicit role, we're handling it ourselves
16183 this.radio
.$input
.attr( 'role', 'presentation' );
16185 .addClass( 'oo-ui-radioOptionWidget' )
16186 .attr( 'role', 'radio' )
16187 .attr( 'aria-checked', 'false' )
16188 .removeAttr( 'aria-selected' )
16189 .prepend( this.radio
.$element
);
16194 OO
.inheritClass( OO
.ui
.RadioOptionWidget
, OO
.ui
.OptionWidget
);
16196 /* Static Properties */
16198 OO
.ui
.RadioOptionWidget
.static.highlightable
= false;
16200 OO
.ui
.RadioOptionWidget
.static.scrollIntoViewOnSelect
= true;
16202 OO
.ui
.RadioOptionWidget
.static.pressable
= false;
16204 OO
.ui
.RadioOptionWidget
.static.tagName
= 'label';
16209 * @param {jQuery.Event} e Focus event
16212 OO
.ui
.RadioOptionWidget
.prototype.onInputFocus = function () {
16213 this.radio
.$input
.blur();
16214 this.$element
.parent().focus();
16220 OO
.ui
.RadioOptionWidget
.prototype.setSelected = function ( state
) {
16221 OO
.ui
.RadioOptionWidget
.parent
.prototype.setSelected
.call( this, state
);
16223 this.radio
.setSelected( state
);
16225 .attr( 'aria-checked', state
.toString() )
16226 .removeAttr( 'aria-selected' );
16234 OO
.ui
.RadioOptionWidget
.prototype.setDisabled = function ( disabled
) {
16235 OO
.ui
.RadioOptionWidget
.parent
.prototype.setDisabled
.call( this, disabled
);
16237 this.radio
.setDisabled( this.isDisabled() );
16243 * MenuOptionWidget is an option widget that looks like a menu item. The class is used with
16244 * OO.ui.MenuSelectWidget to create a menu of mutually exclusive options. Please see
16245 * the [OOjs UI documentation on MediaWiki] [1] for more information.
16247 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Menu_selects_and_options
16250 * @extends OO.ui.DecoratedOptionWidget
16253 * @param {Object} [config] Configuration options
16255 OO
.ui
.MenuOptionWidget
= function OoUiMenuOptionWidget( config
) {
16256 // Configuration initialization
16257 config
= $.extend( { icon
: 'check' }, config
);
16259 // Parent constructor
16260 OO
.ui
.MenuOptionWidget
.parent
.call( this, config
);
16264 .attr( 'role', 'menuitem' )
16265 .addClass( 'oo-ui-menuOptionWidget' );
16270 OO
.inheritClass( OO
.ui
.MenuOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
16272 /* Static Properties */
16274 OO
.ui
.MenuOptionWidget
.static.scrollIntoViewOnSelect
= true;
16277 * MenuSectionOptionWidgets are used inside {@link OO.ui.MenuSelectWidget menu select widgets} to group one or more related
16278 * {@link OO.ui.MenuOptionWidget menu options}. MenuSectionOptionWidgets cannot be highlighted or selected.
16281 * var myDropdown = new OO.ui.DropdownWidget( {
16284 * new OO.ui.MenuSectionOptionWidget( {
16287 * new OO.ui.MenuOptionWidget( {
16289 * label: 'Welsh Corgi'
16291 * new OO.ui.MenuOptionWidget( {
16293 * label: 'Standard Poodle'
16295 * new OO.ui.MenuSectionOptionWidget( {
16298 * new OO.ui.MenuOptionWidget( {
16305 * $( 'body' ).append( myDropdown.$element );
16309 * @extends OO.ui.DecoratedOptionWidget
16312 * @param {Object} [config] Configuration options
16314 OO
.ui
.MenuSectionOptionWidget
= function OoUiMenuSectionOptionWidget( config
) {
16315 // Parent constructor
16316 OO
.ui
.MenuSectionOptionWidget
.parent
.call( this, config
);
16319 this.$element
.addClass( 'oo-ui-menuSectionOptionWidget' );
16324 OO
.inheritClass( OO
.ui
.MenuSectionOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
16326 /* Static Properties */
16328 OO
.ui
.MenuSectionOptionWidget
.static.selectable
= false;
16330 OO
.ui
.MenuSectionOptionWidget
.static.highlightable
= false;
16333 * OutlineOptionWidget is an item in an {@link OO.ui.OutlineSelectWidget OutlineSelectWidget}.
16335 * Currently, this class is only used by {@link OO.ui.BookletLayout booklet layouts}, which contain
16336 * {@link OO.ui.PageLayout page layouts}. See {@link OO.ui.BookletLayout BookletLayout}
16340 * @extends OO.ui.DecoratedOptionWidget
16343 * @param {Object} [config] Configuration options
16344 * @cfg {number} [level] Indentation level
16345 * @cfg {boolean} [movable] Allow modification from {@link OO.ui.OutlineControlsWidget outline controls}.
16347 OO
.ui
.OutlineOptionWidget
= function OoUiOutlineOptionWidget( config
) {
16348 // Configuration initialization
16349 config
= config
|| {};
16351 // Parent constructor
16352 OO
.ui
.OutlineOptionWidget
.parent
.call( this, config
);
16356 this.movable
= !!config
.movable
;
16357 this.removable
= !!config
.removable
;
16360 this.$element
.addClass( 'oo-ui-outlineOptionWidget' );
16361 this.setLevel( config
.level
);
16366 OO
.inheritClass( OO
.ui
.OutlineOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
16368 /* Static Properties */
16370 OO
.ui
.OutlineOptionWidget
.static.highlightable
= false;
16372 OO
.ui
.OutlineOptionWidget
.static.scrollIntoViewOnSelect
= true;
16374 OO
.ui
.OutlineOptionWidget
.static.levelClass
= 'oo-ui-outlineOptionWidget-level-';
16376 OO
.ui
.OutlineOptionWidget
.static.levels
= 3;
16381 * Check if item is movable.
16383 * Movability is used by {@link OO.ui.OutlineControlsWidget outline controls}.
16385 * @return {boolean} Item is movable
16387 OO
.ui
.OutlineOptionWidget
.prototype.isMovable = function () {
16388 return this.movable
;
16392 * Check if item is removable.
16394 * Removability is used by {@link OO.ui.OutlineControlsWidget outline controls}.
16396 * @return {boolean} Item is removable
16398 OO
.ui
.OutlineOptionWidget
.prototype.isRemovable = function () {
16399 return this.removable
;
16403 * Get indentation level.
16405 * @return {number} Indentation level
16407 OO
.ui
.OutlineOptionWidget
.prototype.getLevel = function () {
16414 * Movability is used by {@link OO.ui.OutlineControlsWidget outline controls}.
16416 * @param {boolean} movable Item is movable
16419 OO
.ui
.OutlineOptionWidget
.prototype.setMovable = function ( movable
) {
16420 this.movable
= !!movable
;
16421 this.updateThemeClasses();
16426 * Set removability.
16428 * Removability is used by {@link OO.ui.OutlineControlsWidget outline controls}.
16430 * @param {boolean} movable Item is removable
16433 OO
.ui
.OutlineOptionWidget
.prototype.setRemovable = function ( removable
) {
16434 this.removable
= !!removable
;
16435 this.updateThemeClasses();
16440 * Set indentation level.
16442 * @param {number} [level=0] Indentation level, in the range of [0,#maxLevel]
16445 OO
.ui
.OutlineOptionWidget
.prototype.setLevel = function ( level
) {
16446 var levels
= this.constructor.static.levels
,
16447 levelClass
= this.constructor.static.levelClass
,
16450 this.level
= level
? Math
.max( 0, Math
.min( levels
- 1, level
) ) : 0;
16452 if ( this.level
=== i
) {
16453 this.$element
.addClass( levelClass
+ i
);
16455 this.$element
.removeClass( levelClass
+ i
);
16458 this.updateThemeClasses();
16464 * TabOptionWidget is an item in a {@link OO.ui.TabSelectWidget TabSelectWidget}.
16466 * Currently, this class is only used by {@link OO.ui.IndexLayout index layouts}, which contain
16467 * {@link OO.ui.CardLayout card layouts}. See {@link OO.ui.IndexLayout IndexLayout}
16471 * @extends OO.ui.OptionWidget
16474 * @param {Object} [config] Configuration options
16476 OO
.ui
.TabOptionWidget
= function OoUiTabOptionWidget( config
) {
16477 // Configuration initialization
16478 config
= config
|| {};
16480 // Parent constructor
16481 OO
.ui
.TabOptionWidget
.parent
.call( this, config
);
16484 this.$element
.addClass( 'oo-ui-tabOptionWidget' );
16489 OO
.inheritClass( OO
.ui
.TabOptionWidget
, OO
.ui
.OptionWidget
);
16491 /* Static Properties */
16493 OO
.ui
.TabOptionWidget
.static.highlightable
= false;
16496 * PopupWidget is a container for content. The popup is overlaid and positioned absolutely.
16497 * By default, each popup has an anchor that points toward its origin.
16498 * Please see the [OOjs UI documentation on Mediawiki] [1] for more information and examples.
16501 * // A popup widget.
16502 * var popup = new OO.ui.PopupWidget( {
16503 * $content: $( '<p>Hi there!</p>' ),
16508 * $( 'body' ).append( popup.$element );
16509 * // To display the popup, toggle the visibility to 'true'.
16510 * popup.toggle( true );
16512 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Popups
16515 * @extends OO.ui.Widget
16516 * @mixins OO.ui.mixin.LabelElement
16519 * @param {Object} [config] Configuration options
16520 * @cfg {number} [width=320] Width of popup in pixels
16521 * @cfg {number} [height] Height of popup in pixels. Omit to use the automatic height.
16522 * @cfg {boolean} [anchor=true] Show anchor pointing to origin of popup
16523 * @cfg {string} [align='center'] Alignment of the popup: `center`, `force-left`, `force-right`, `backwards` or `forwards`.
16524 * If the popup is forced-left the popup body is leaning towards the left. For force-right alignment, the body of the
16525 * popup is leaning towards the right of the screen.
16526 * Using 'backwards' is a logical direction which will result in the popup leaning towards the beginning of the sentence
16527 * in the given language, which means it will flip to the correct positioning in right-to-left languages.
16528 * Using 'forward' will also result in a logical alignment where the body of the popup leans towards the end of the
16529 * sentence in the given language.
16530 * @cfg {jQuery} [$container] Constrain the popup to the boundaries of the specified container.
16531 * See the [OOjs UI docs on MediaWiki][3] for an example.
16532 * [3]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Popups#containerExample
16533 * @cfg {number} [containerPadding=10] Padding between the popup and its container, specified as a number of pixels.
16534 * @cfg {jQuery} [$content] Content to append to the popup's body
16535 * @cfg {boolean} [autoClose=false] Automatically close the popup when it loses focus.
16536 * @cfg {jQuery} [$autoCloseIgnore] Elements that will not close the popup when clicked.
16537 * This config option is only relevant if #autoClose is set to `true`. See the [OOjs UI docs on MediaWiki][2]
16539 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Popups#autocloseExample
16540 * @cfg {boolean} [head] Show a popup header that contains a #label (if specified) and close
16542 * @cfg {boolean} [padded] Add padding to the popup's body
16544 OO
.ui
.PopupWidget
= function OoUiPopupWidget( config
) {
16545 // Configuration initialization
16546 config
= config
|| {};
16548 // Parent constructor
16549 OO
.ui
.PopupWidget
.parent
.call( this, config
);
16551 // Properties (must be set before ClippableElement constructor call)
16552 this.$body
= $( '<div>' );
16554 // Mixin constructors
16555 OO
.ui
.mixin
.LabelElement
.call( this, config
);
16556 OO
.ui
.mixin
.ClippableElement
.call( this, $.extend( {}, config
, { $clippable
: this.$body
} ) );
16559 this.$popup
= $( '<div>' );
16560 this.$head
= $( '<div>' );
16561 this.$anchor
= $( '<div>' );
16562 // If undefined, will be computed lazily in updateDimensions()
16563 this.$container
= config
.$container
;
16564 this.containerPadding
= config
.containerPadding
!== undefined ? config
.containerPadding
: 10;
16565 this.autoClose
= !!config
.autoClose
;
16566 this.$autoCloseIgnore
= config
.$autoCloseIgnore
;
16567 this.transitionTimeout
= null;
16568 this.anchor
= null;
16569 this.width
= config
.width
!== undefined ? config
.width
: 320;
16570 this.height
= config
.height
!== undefined ? config
.height
: null;
16571 this.setAlignment( config
.align
);
16572 this.closeButton
= new OO
.ui
.ButtonWidget( { framed
: false, icon
: 'close' } );
16573 this.onMouseDownHandler
= this.onMouseDown
.bind( this );
16574 this.onDocumentKeyDownHandler
= this.onDocumentKeyDown
.bind( this );
16577 this.closeButton
.connect( this, { click
: 'onCloseButtonClick' } );
16578 this.$element
.on( 'focusout', this.onFocusOut
.bind( this ) );
16579 if ( this.$autoCloseIgnore
) {
16580 this.$autoCloseIgnore
.on( 'focusout', this.onFocusOut
.bind( this ) );
16584 this.toggleAnchor( config
.anchor
=== undefined || config
.anchor
);
16585 this.$body
.addClass( 'oo-ui-popupWidget-body' );
16586 this.$anchor
.addClass( 'oo-ui-popupWidget-anchor' );
16588 .addClass( 'oo-ui-popupWidget-head' )
16589 .append( this.$label
, this.closeButton
.$element
);
16590 if ( !config
.head
) {
16591 this.$head
.addClass( 'oo-ui-element-hidden' );
16594 .addClass( 'oo-ui-popupWidget-popup' )
16595 .append( this.$head
, this.$body
);
16597 .addClass( 'oo-ui-popupWidget' )
16598 .append( this.$popup
, this.$anchor
);
16599 // Move content, which was added to #$element by OO.ui.Widget, to the body
16600 if ( config
.$content
instanceof jQuery
) {
16601 this.$body
.append( config
.$content
);
16603 if ( config
.padded
) {
16604 this.$body
.addClass( 'oo-ui-popupWidget-body-padded' );
16607 // Initially hidden - using #toggle may cause errors if subclasses override toggle with methods
16608 // that reference properties not initialized at that time of parent class construction
16609 // TODO: Find a better way to handle post-constructor setup
16610 this.visible
= false;
16611 this.$element
.addClass( 'oo-ui-element-hidden' );
16616 OO
.inheritClass( OO
.ui
.PopupWidget
, OO
.ui
.Widget
);
16617 OO
.mixinClass( OO
.ui
.PopupWidget
, OO
.ui
.mixin
.LabelElement
);
16618 OO
.mixinClass( OO
.ui
.PopupWidget
, OO
.ui
.mixin
.ClippableElement
);
16623 * Handles focus out events.
16626 * @param {Event} e Focus out event
16628 OO
.ui
.PopupWidget
.prototype.onFocusOut = function () {
16631 setTimeout( function () {
16633 widget
.isVisible() &&
16634 !OO
.ui
.contains( widget
.$element
, document
.activeElement
, true ) &&
16635 ( !widget
.$autoCloseIgnore
|| !widget
.$autoCloseIgnore
.has( document
.activeElement
).length
)
16637 widget
.toggle( false );
16643 * Handles mouse down events.
16646 * @param {MouseEvent} e Mouse down event
16648 OO
.ui
.PopupWidget
.prototype.onMouseDown = function ( e
) {
16650 this.isVisible() &&
16651 !$.contains( this.$element
[ 0 ], e
.target
) &&
16652 ( !this.$autoCloseIgnore
|| !this.$autoCloseIgnore
.has( e
.target
).length
)
16654 this.toggle( false );
16659 * Bind mouse down listener.
16663 OO
.ui
.PopupWidget
.prototype.bindMouseDownListener = function () {
16664 // Capture clicks outside popup
16665 this.getElementWindow().addEventListener( 'mousedown', this.onMouseDownHandler
, true );
16669 * Handles close button click events.
16673 OO
.ui
.PopupWidget
.prototype.onCloseButtonClick = function () {
16674 if ( this.isVisible() ) {
16675 this.toggle( false );
16680 * Unbind mouse down listener.
16684 OO
.ui
.PopupWidget
.prototype.unbindMouseDownListener = function () {
16685 this.getElementWindow().removeEventListener( 'mousedown', this.onMouseDownHandler
, true );
16689 * Handles key down events.
16692 * @param {KeyboardEvent} e Key down event
16694 OO
.ui
.PopupWidget
.prototype.onDocumentKeyDown = function ( e
) {
16696 e
.which
=== OO
.ui
.Keys
.ESCAPE
&&
16699 this.toggle( false );
16700 e
.preventDefault();
16701 e
.stopPropagation();
16706 * Bind key down listener.
16710 OO
.ui
.PopupWidget
.prototype.bindKeyDownListener = function () {
16711 this.getElementWindow().addEventListener( 'keydown', this.onDocumentKeyDownHandler
, true );
16715 * Unbind key down listener.
16719 OO
.ui
.PopupWidget
.prototype.unbindKeyDownListener = function () {
16720 this.getElementWindow().removeEventListener( 'keydown', this.onDocumentKeyDownHandler
, true );
16724 * Show, hide, or toggle the visibility of the anchor.
16726 * @param {boolean} [show] Show anchor, omit to toggle
16728 OO
.ui
.PopupWidget
.prototype.toggleAnchor = function ( show
) {
16729 show
= show
=== undefined ? !this.anchored
: !!show
;
16731 if ( this.anchored
!== show
) {
16733 this.$element
.addClass( 'oo-ui-popupWidget-anchored' );
16735 this.$element
.removeClass( 'oo-ui-popupWidget-anchored' );
16737 this.anchored
= show
;
16742 * Check if the anchor is visible.
16744 * @return {boolean} Anchor is visible
16746 OO
.ui
.PopupWidget
.prototype.hasAnchor = function () {
16747 return this.anchor
;
16753 OO
.ui
.PopupWidget
.prototype.toggle = function ( show
) {
16754 show
= show
=== undefined ? !this.isVisible() : !!show
;
16756 var change
= show
!== this.isVisible();
16759 OO
.ui
.PopupWidget
.parent
.prototype.toggle
.call( this, show
);
16763 if ( this.autoClose
) {
16764 this.bindMouseDownListener();
16765 this.bindKeyDownListener();
16767 this.updateDimensions();
16768 this.toggleClipping( true );
16770 this.toggleClipping( false );
16771 if ( this.autoClose
) {
16772 this.unbindMouseDownListener();
16773 this.unbindKeyDownListener();
16782 * Set the size of the popup.
16784 * Changing the size may also change the popup's position depending on the alignment.
16786 * @param {number} width Width in pixels
16787 * @param {number} height Height in pixels
16788 * @param {boolean} [transition=false] Use a smooth transition
16791 OO
.ui
.PopupWidget
.prototype.setSize = function ( width
, height
, transition
) {
16792 this.width
= width
;
16793 this.height
= height
!== undefined ? height
: null;
16794 if ( this.isVisible() ) {
16795 this.updateDimensions( transition
);
16800 * Update the size and position.
16802 * Only use this to keep the popup properly anchored. Use #setSize to change the size, and this will
16803 * be called automatically.
16805 * @param {boolean} [transition=false] Use a smooth transition
16808 OO
.ui
.PopupWidget
.prototype.updateDimensions = function ( transition
) {
16809 var popupOffset
, originOffset
, containerLeft
, containerWidth
, containerRight
,
16810 popupLeft
, popupRight
, overlapLeft
, overlapRight
, anchorWidth
,
16811 align
= this.align
,
16814 if ( !this.$container
) {
16815 // Lazy-initialize $container if not specified in constructor
16816 this.$container
= $( this.getClosestScrollableElementContainer() );
16819 // Set height and width before measuring things, since it might cause our measurements
16820 // to change (e.g. due to scrollbars appearing or disappearing)
16823 height
: this.height
!== null ? this.height
: 'auto'
16826 // If we are in RTL, we need to flip the alignment, unless it is center
16827 if ( align
=== 'forwards' || align
=== 'backwards' ) {
16828 if ( this.$container
.css( 'direction' ) === 'rtl' ) {
16829 align
= ( { forwards
: 'force-left', backwards
: 'force-right' } )[ this.align
];
16831 align
= ( { forwards
: 'force-right', backwards
: 'force-left' } )[ this.align
];
16836 // Compute initial popupOffset based on alignment
16837 popupOffset
= this.width
* ( { 'force-left': -1, center
: -0.5, 'force-right': 0 } )[ align
];
16839 // Figure out if this will cause the popup to go beyond the edge of the container
16840 originOffset
= this.$element
.offset().left
;
16841 containerLeft
= this.$container
.offset().left
;
16842 containerWidth
= this.$container
.innerWidth();
16843 containerRight
= containerLeft
+ containerWidth
;
16844 popupLeft
= popupOffset
- this.containerPadding
;
16845 popupRight
= popupOffset
+ this.containerPadding
+ this.width
+ this.containerPadding
;
16846 overlapLeft
= ( originOffset
+ popupLeft
) - containerLeft
;
16847 overlapRight
= containerRight
- ( originOffset
+ popupRight
);
16849 // Adjust offset to make the popup not go beyond the edge, if needed
16850 if ( overlapRight
< 0 ) {
16851 popupOffset
+= overlapRight
;
16852 } else if ( overlapLeft
< 0 ) {
16853 popupOffset
-= overlapLeft
;
16856 // Adjust offset to avoid anchor being rendered too close to the edge
16857 // $anchor.width() doesn't work with the pure CSS anchor (returns 0)
16858 // TODO: Find a measurement that works for CSS anchors and image anchors
16859 anchorWidth
= this.$anchor
[ 0 ].scrollWidth
* 2;
16860 if ( popupOffset
+ this.width
< anchorWidth
) {
16861 popupOffset
= anchorWidth
- this.width
;
16862 } else if ( -popupOffset
< anchorWidth
) {
16863 popupOffset
= -anchorWidth
;
16866 // Prevent transition from being interrupted
16867 clearTimeout( this.transitionTimeout
);
16868 if ( transition
) {
16869 // Enable transition
16870 this.$element
.addClass( 'oo-ui-popupWidget-transitioning' );
16873 // Position body relative to anchor
16874 this.$popup
.css( 'margin-left', popupOffset
);
16876 if ( transition
) {
16877 // Prevent transitioning after transition is complete
16878 this.transitionTimeout
= setTimeout( function () {
16879 widget
.$element
.removeClass( 'oo-ui-popupWidget-transitioning' );
16882 // Prevent transitioning immediately
16883 this.$element
.removeClass( 'oo-ui-popupWidget-transitioning' );
16886 // Reevaluate clipping state since we've relocated and resized the popup
16893 * Set popup alignment
16894 * @param {string} align Alignment of the popup, `center`, `force-left`, `force-right`,
16895 * `backwards` or `forwards`.
16897 OO
.ui
.PopupWidget
.prototype.setAlignment = function ( align
) {
16898 // Validate alignment and transform deprecated values
16899 if ( [ 'left', 'right', 'force-left', 'force-right', 'backwards', 'forwards', 'center' ].indexOf( align
) > -1 ) {
16900 this.align
= { left
: 'force-right', right
: 'force-left' }[ align
] || align
;
16902 this.align
= 'center';
16907 * Get popup alignment
16908 * @return {string} align Alignment of the popup, `center`, `force-left`, `force-right`,
16909 * `backwards` or `forwards`.
16911 OO
.ui
.PopupWidget
.prototype.getAlignment = function () {
16916 * Progress bars visually display the status of an operation, such as a download,
16917 * and can be either determinate or indeterminate:
16919 * - **determinate** process bars show the percent of an operation that is complete.
16921 * - **indeterminate** process bars use a visual display of motion to indicate that an operation
16922 * is taking place. Because the extent of an indeterminate operation is unknown, the bar does
16923 * not use percentages.
16925 * The value of the `progress` configuration determines whether the bar is determinate or indeterminate.
16928 * // Examples of determinate and indeterminate progress bars.
16929 * var progressBar1 = new OO.ui.ProgressBarWidget( {
16932 * var progressBar2 = new OO.ui.ProgressBarWidget();
16934 * // Create a FieldsetLayout to layout progress bars
16935 * var fieldset = new OO.ui.FieldsetLayout;
16936 * fieldset.addItems( [
16937 * new OO.ui.FieldLayout( progressBar1, {label: 'Determinate', align: 'top'}),
16938 * new OO.ui.FieldLayout( progressBar2, {label: 'Indeterminate', align: 'top'})
16940 * $( 'body' ).append( fieldset.$element );
16943 * @extends OO.ui.Widget
16946 * @param {Object} [config] Configuration options
16947 * @cfg {number|boolean} [progress=false] The type of progress bar (determinate or indeterminate).
16948 * To create a determinate progress bar, specify a number that reflects the initial percent complete.
16949 * By default, the progress bar is indeterminate.
16951 OO
.ui
.ProgressBarWidget
= function OoUiProgressBarWidget( config
) {
16952 // Configuration initialization
16953 config
= config
|| {};
16955 // Parent constructor
16956 OO
.ui
.ProgressBarWidget
.parent
.call( this, config
);
16959 this.$bar
= $( '<div>' );
16960 this.progress
= null;
16963 this.setProgress( config
.progress
!== undefined ? config
.progress
: false );
16964 this.$bar
.addClass( 'oo-ui-progressBarWidget-bar' );
16967 role
: 'progressbar',
16968 'aria-valuemin': 0,
16969 'aria-valuemax': 100
16971 .addClass( 'oo-ui-progressBarWidget' )
16972 .append( this.$bar
);
16977 OO
.inheritClass( OO
.ui
.ProgressBarWidget
, OO
.ui
.Widget
);
16979 /* Static Properties */
16981 OO
.ui
.ProgressBarWidget
.static.tagName
= 'div';
16986 * Get the percent of the progress that has been completed. Indeterminate progresses will return `false`.
16988 * @return {number|boolean} Progress percent
16990 OO
.ui
.ProgressBarWidget
.prototype.getProgress = function () {
16991 return this.progress
;
16995 * Set the percent of the process completed or `false` for an indeterminate process.
16997 * @param {number|boolean} progress Progress percent or `false` for indeterminate
16999 OO
.ui
.ProgressBarWidget
.prototype.setProgress = function ( progress
) {
17000 this.progress
= progress
;
17002 if ( progress
!== false ) {
17003 this.$bar
.css( 'width', this.progress
+ '%' );
17004 this.$element
.attr( 'aria-valuenow', this.progress
);
17006 this.$bar
.css( 'width', '' );
17007 this.$element
.removeAttr( 'aria-valuenow' );
17009 this.$element
.toggleClass( 'oo-ui-progressBarWidget-indeterminate', !progress
);
17013 * SearchWidgets combine a {@link OO.ui.TextInputWidget text input field}, where users can type a search query,
17014 * and a {@link OO.ui.TextInputMenuSelectWidget menu} of search results, which is displayed beneath the query
17015 * field. Unlike {@link OO.ui.mixin.LookupElement lookup menus}, search result menus are always visible to the user.
17016 * Users can choose an item from the menu or type a query into the text field to search for a matching result item.
17017 * In general, search widgets are used inside a separate {@link OO.ui.Dialog dialog} window.
17019 * Each time the query is changed, the search result menu is cleared and repopulated. Please see
17020 * the [OOjs UI demos][1] for an example.
17022 * [1]: https://tools.wmflabs.org/oojs-ui/oojs-ui/demos/#dialogs-mediawiki-vector-ltr
17025 * @extends OO.ui.Widget
17028 * @param {Object} [config] Configuration options
17029 * @cfg {string|jQuery} [placeholder] Placeholder text for query input
17030 * @cfg {string} [value] Initial query value
17032 OO
.ui
.SearchWidget
= function OoUiSearchWidget( config
) {
17033 // Configuration initialization
17034 config
= config
|| {};
17036 // Parent constructor
17037 OO
.ui
.SearchWidget
.parent
.call( this, config
);
17040 this.query
= new OO
.ui
.TextInputWidget( {
17042 placeholder
: config
.placeholder
,
17043 value
: config
.value
17045 this.results
= new OO
.ui
.SelectWidget();
17046 this.$query
= $( '<div>' );
17047 this.$results
= $( '<div>' );
17050 this.query
.connect( this, {
17051 change
: 'onQueryChange',
17052 enter
: 'onQueryEnter'
17054 this.query
.$input
.on( 'keydown', this.onQueryKeydown
.bind( this ) );
17058 .addClass( 'oo-ui-searchWidget-query' )
17059 .append( this.query
.$element
);
17061 .addClass( 'oo-ui-searchWidget-results' )
17062 .append( this.results
.$element
);
17064 .addClass( 'oo-ui-searchWidget' )
17065 .append( this.$results
, this.$query
);
17070 OO
.inheritClass( OO
.ui
.SearchWidget
, OO
.ui
.Widget
);
17075 * Handle query key down events.
17078 * @param {jQuery.Event} e Key down event
17080 OO
.ui
.SearchWidget
.prototype.onQueryKeydown = function ( e
) {
17081 var highlightedItem
, nextItem
,
17082 dir
= e
.which
=== OO
.ui
.Keys
.DOWN
? 1 : ( e
.which
=== OO
.ui
.Keys
.UP
? -1 : 0 );
17085 highlightedItem
= this.results
.getHighlightedItem();
17086 if ( !highlightedItem
) {
17087 highlightedItem
= this.results
.getSelectedItem();
17089 nextItem
= this.results
.getRelativeSelectableItem( highlightedItem
, dir
);
17090 this.results
.highlightItem( nextItem
);
17091 nextItem
.scrollElementIntoView();
17096 * Handle select widget select events.
17098 * Clears existing results. Subclasses should repopulate items according to new query.
17101 * @param {string} value New value
17103 OO
.ui
.SearchWidget
.prototype.onQueryChange = function () {
17105 this.results
.clearItems();
17109 * Handle select widget enter key events.
17111 * Chooses highlighted item.
17114 * @param {string} value New value
17116 OO
.ui
.SearchWidget
.prototype.onQueryEnter = function () {
17118 this.results
.chooseItem( this.results
.getHighlightedItem() );
17122 * Get the query input.
17124 * @return {OO.ui.TextInputWidget} Query input
17126 OO
.ui
.SearchWidget
.prototype.getQuery = function () {
17131 * Get the search results menu.
17133 * @return {OO.ui.SelectWidget} Menu of search results
17135 OO
.ui
.SearchWidget
.prototype.getResults = function () {
17136 return this.results
;
17140 * A SelectWidget is of a generic selection of options. The OOjs UI library contains several types of
17141 * select widgets, including {@link OO.ui.ButtonSelectWidget button selects},
17142 * {@link OO.ui.RadioSelectWidget radio selects}, and {@link OO.ui.MenuSelectWidget
17145 * This class should be used together with OO.ui.OptionWidget or OO.ui.DecoratedOptionWidget. For more
17146 * information, please see the [OOjs UI documentation on MediaWiki][1].
17149 * // Example of a select widget with three options
17150 * var select = new OO.ui.SelectWidget( {
17152 * new OO.ui.OptionWidget( {
17154 * label: 'Option One',
17156 * new OO.ui.OptionWidget( {
17158 * label: 'Option Two',
17160 * new OO.ui.OptionWidget( {
17162 * label: 'Option Three',
17166 * $( 'body' ).append( select.$element );
17168 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
17172 * @extends OO.ui.Widget
17173 * @mixins OO.ui.mixin.GroupWidget
17176 * @param {Object} [config] Configuration options
17177 * @cfg {OO.ui.OptionWidget[]} [items] An array of options to add to the select.
17178 * Options are created with {@link OO.ui.OptionWidget OptionWidget} classes. See
17179 * the [OOjs UI documentation on MediaWiki] [2] for examples.
17180 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
17182 OO
.ui
.SelectWidget
= function OoUiSelectWidget( config
) {
17183 // Configuration initialization
17184 config
= config
|| {};
17186 // Parent constructor
17187 OO
.ui
.SelectWidget
.parent
.call( this, config
);
17189 // Mixin constructors
17190 OO
.ui
.mixin
.GroupWidget
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
17193 this.pressed
= false;
17194 this.selecting
= null;
17195 this.onMouseUpHandler
= this.onMouseUp
.bind( this );
17196 this.onMouseMoveHandler
= this.onMouseMove
.bind( this );
17197 this.onKeyDownHandler
= this.onKeyDown
.bind( this );
17198 this.onKeyPressHandler
= this.onKeyPress
.bind( this );
17199 this.keyPressBuffer
= '';
17200 this.keyPressBufferTimer
= null;
17203 this.connect( this, {
17206 this.$element
.on( {
17207 mousedown
: this.onMouseDown
.bind( this ),
17208 mouseover
: this.onMouseOver
.bind( this ),
17209 mouseleave
: this.onMouseLeave
.bind( this )
17214 .addClass( 'oo-ui-selectWidget oo-ui-selectWidget-depressed' )
17215 .attr( 'role', 'listbox' );
17216 if ( Array
.isArray( config
.items
) ) {
17217 this.addItems( config
.items
);
17223 OO
.inheritClass( OO
.ui
.SelectWidget
, OO
.ui
.Widget
);
17225 // Need to mixin base class as well
17226 OO
.mixinClass( OO
.ui
.SelectWidget
, OO
.ui
.mixin
.GroupElement
);
17227 OO
.mixinClass( OO
.ui
.SelectWidget
, OO
.ui
.mixin
.GroupWidget
);
17230 OO
.ui
.SelectWidget
.static.passAllFilter = function () {
17239 * A `highlight` event is emitted when the highlight is changed with the #highlightItem method.
17241 * @param {OO.ui.OptionWidget|null} item Highlighted item
17247 * A `press` event is emitted when the #pressItem method is used to programmatically modify the
17248 * pressed state of an option.
17250 * @param {OO.ui.OptionWidget|null} item Pressed item
17256 * A `select` event is emitted when the selection is modified programmatically with the #selectItem method.
17258 * @param {OO.ui.OptionWidget|null} item Selected item
17263 * A `choose` event is emitted when an item is chosen with the #chooseItem method.
17264 * @param {OO.ui.OptionWidget} item Chosen item
17270 * An `add` event is emitted when options are added to the select with the #addItems method.
17272 * @param {OO.ui.OptionWidget[]} items Added items
17273 * @param {number} index Index of insertion point
17279 * A `remove` event is emitted when options are removed from the select with the #clearItems
17280 * or #removeItems methods.
17282 * @param {OO.ui.OptionWidget[]} items Removed items
17288 * Handle mouse down events.
17291 * @param {jQuery.Event} e Mouse down event
17293 OO
.ui
.SelectWidget
.prototype.onMouseDown = function ( e
) {
17296 if ( !this.isDisabled() && e
.which
=== 1 ) {
17297 this.togglePressed( true );
17298 item
= this.getTargetItem( e
);
17299 if ( item
&& item
.isSelectable() ) {
17300 this.pressItem( item
);
17301 this.selecting
= item
;
17302 this.getElementDocument().addEventListener(
17304 this.onMouseUpHandler
,
17307 this.getElementDocument().addEventListener(
17309 this.onMouseMoveHandler
,
17318 * Handle mouse up events.
17321 * @param {jQuery.Event} e Mouse up event
17323 OO
.ui
.SelectWidget
.prototype.onMouseUp = function ( e
) {
17326 this.togglePressed( false );
17327 if ( !this.selecting
) {
17328 item
= this.getTargetItem( e
);
17329 if ( item
&& item
.isSelectable() ) {
17330 this.selecting
= item
;
17333 if ( !this.isDisabled() && e
.which
=== 1 && this.selecting
) {
17334 this.pressItem( null );
17335 this.chooseItem( this.selecting
);
17336 this.selecting
= null;
17339 this.getElementDocument().removeEventListener(
17341 this.onMouseUpHandler
,
17344 this.getElementDocument().removeEventListener(
17346 this.onMouseMoveHandler
,
17354 * Handle mouse move events.
17357 * @param {jQuery.Event} e Mouse move event
17359 OO
.ui
.SelectWidget
.prototype.onMouseMove = function ( e
) {
17362 if ( !this.isDisabled() && this.pressed
) {
17363 item
= this.getTargetItem( e
);
17364 if ( item
&& item
!== this.selecting
&& item
.isSelectable() ) {
17365 this.pressItem( item
);
17366 this.selecting
= item
;
17373 * Handle mouse over events.
17376 * @param {jQuery.Event} e Mouse over event
17378 OO
.ui
.SelectWidget
.prototype.onMouseOver = function ( e
) {
17381 if ( !this.isDisabled() ) {
17382 item
= this.getTargetItem( e
);
17383 this.highlightItem( item
&& item
.isHighlightable() ? item
: null );
17389 * Handle mouse leave events.
17392 * @param {jQuery.Event} e Mouse over event
17394 OO
.ui
.SelectWidget
.prototype.onMouseLeave = function () {
17395 if ( !this.isDisabled() ) {
17396 this.highlightItem( null );
17402 * Handle key down events.
17405 * @param {jQuery.Event} e Key down event
17407 OO
.ui
.SelectWidget
.prototype.onKeyDown = function ( e
) {
17410 currentItem
= this.getHighlightedItem() || this.getSelectedItem();
17412 if ( !this.isDisabled() && this.isVisible() ) {
17413 switch ( e
.keyCode
) {
17414 case OO
.ui
.Keys
.ENTER
:
17415 if ( currentItem
&& currentItem
.constructor.static.highlightable
) {
17416 // Was only highlighted, now let's select it. No-op if already selected.
17417 this.chooseItem( currentItem
);
17421 case OO
.ui
.Keys
.UP
:
17422 case OO
.ui
.Keys
.LEFT
:
17423 this.clearKeyPressBuffer();
17424 nextItem
= this.getRelativeSelectableItem( currentItem
, -1 );
17427 case OO
.ui
.Keys
.DOWN
:
17428 case OO
.ui
.Keys
.RIGHT
:
17429 this.clearKeyPressBuffer();
17430 nextItem
= this.getRelativeSelectableItem( currentItem
, 1 );
17433 case OO
.ui
.Keys
.ESCAPE
:
17434 case OO
.ui
.Keys
.TAB
:
17435 if ( currentItem
&& currentItem
.constructor.static.highlightable
) {
17436 currentItem
.setHighlighted( false );
17438 this.unbindKeyDownListener();
17439 this.unbindKeyPressListener();
17440 // Don't prevent tabbing away / defocusing
17446 if ( nextItem
.constructor.static.highlightable
) {
17447 this.highlightItem( nextItem
);
17449 this.chooseItem( nextItem
);
17451 nextItem
.scrollElementIntoView();
17455 // Can't just return false, because e is not always a jQuery event
17456 e
.preventDefault();
17457 e
.stopPropagation();
17463 * Bind key down listener.
17467 OO
.ui
.SelectWidget
.prototype.bindKeyDownListener = function () {
17468 this.getElementWindow().addEventListener( 'keydown', this.onKeyDownHandler
, true );
17472 * Unbind key down listener.
17476 OO
.ui
.SelectWidget
.prototype.unbindKeyDownListener = function () {
17477 this.getElementWindow().removeEventListener( 'keydown', this.onKeyDownHandler
, true );
17481 * Clear the key-press buffer
17485 OO
.ui
.SelectWidget
.prototype.clearKeyPressBuffer = function () {
17486 if ( this.keyPressBufferTimer
) {
17487 clearTimeout( this.keyPressBufferTimer
);
17488 this.keyPressBufferTimer
= null;
17490 this.keyPressBuffer
= '';
17494 * Handle key press events.
17497 * @param {jQuery.Event} e Key press event
17499 OO
.ui
.SelectWidget
.prototype.onKeyPress = function ( e
) {
17500 var c
, filter
, item
;
17502 if ( !e
.charCode
) {
17503 if ( e
.keyCode
=== OO
.ui
.Keys
.BACKSPACE
&& this.keyPressBuffer
!== '' ) {
17504 this.keyPressBuffer
= this.keyPressBuffer
.substr( 0, this.keyPressBuffer
.length
- 1 );
17509 if ( String
.fromCodePoint
) {
17510 c
= String
.fromCodePoint( e
.charCode
);
17512 c
= String
.fromCharCode( e
.charCode
);
17515 if ( this.keyPressBufferTimer
) {
17516 clearTimeout( this.keyPressBufferTimer
);
17518 this.keyPressBufferTimer
= setTimeout( this.clearKeyPressBuffer
.bind( this ), 1500 );
17520 item
= this.getHighlightedItem() || this.getSelectedItem();
17522 if ( this.keyPressBuffer
=== c
) {
17523 // Common (if weird) special case: typing "xxxx" will cycle through all
17524 // the items beginning with "x".
17526 item
= this.getRelativeSelectableItem( item
, 1 );
17529 this.keyPressBuffer
+= c
;
17532 filter
= this.getItemMatcher( this.keyPressBuffer
, false );
17533 if ( !item
|| !filter( item
) ) {
17534 item
= this.getRelativeSelectableItem( item
, 1, filter
);
17537 if ( item
.constructor.static.highlightable
) {
17538 this.highlightItem( item
);
17540 this.chooseItem( item
);
17542 item
.scrollElementIntoView();
17549 * Get a matcher for the specific string
17552 * @param {string} s String to match against items
17553 * @param {boolean} [exact=false] Only accept exact matches
17554 * @return {Function} function ( OO.ui.OptionItem ) => boolean
17556 OO
.ui
.SelectWidget
.prototype.getItemMatcher = function ( s
, exact
) {
17559 if ( s
.normalize
) {
17562 s
= exact
? s
.trim() : s
.replace( /^\s+/, '' );
17563 re
= '^\\s*' + s
.replace( /([\\{}()|.?*+\-\^$\[\]])/g, '\\$1' ).replace( /\s+/g, '\\s+' );
17567 re
= new RegExp( re
, 'i' );
17568 return function ( item
) {
17569 var l
= item
.getLabel();
17570 if ( typeof l
!== 'string' ) {
17571 l
= item
.$label
.text();
17573 if ( l
.normalize
) {
17576 return re
.test( l
);
17581 * Bind key press listener.
17585 OO
.ui
.SelectWidget
.prototype.bindKeyPressListener = function () {
17586 this.getElementWindow().addEventListener( 'keypress', this.onKeyPressHandler
, true );
17590 * Unbind key down listener.
17592 * If you override this, be sure to call this.clearKeyPressBuffer() from your
17597 OO
.ui
.SelectWidget
.prototype.unbindKeyPressListener = function () {
17598 this.getElementWindow().removeEventListener( 'keypress', this.onKeyPressHandler
, true );
17599 this.clearKeyPressBuffer();
17603 * Visibility change handler
17606 * @param {boolean} visible
17608 OO
.ui
.SelectWidget
.prototype.onToggle = function ( visible
) {
17610 this.clearKeyPressBuffer();
17615 * Get the closest item to a jQuery.Event.
17618 * @param {jQuery.Event} e
17619 * @return {OO.ui.OptionWidget|null} Outline item widget, `null` if none was found
17621 OO
.ui
.SelectWidget
.prototype.getTargetItem = function ( e
) {
17622 return $( e
.target
).closest( '.oo-ui-optionWidget' ).data( 'oo-ui-optionWidget' ) || null;
17626 * Get selected item.
17628 * @return {OO.ui.OptionWidget|null} Selected item, `null` if no item is selected
17630 OO
.ui
.SelectWidget
.prototype.getSelectedItem = function () {
17633 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
17634 if ( this.items
[ i
].isSelected() ) {
17635 return this.items
[ i
];
17642 * Get highlighted item.
17644 * @return {OO.ui.OptionWidget|null} Highlighted item, `null` if no item is highlighted
17646 OO
.ui
.SelectWidget
.prototype.getHighlightedItem = function () {
17649 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
17650 if ( this.items
[ i
].isHighlighted() ) {
17651 return this.items
[ i
];
17658 * Toggle pressed state.
17660 * Press is a state that occurs when a user mouses down on an item, but
17661 * has not yet let go of the mouse. The item may appear selected, but it will not be selected
17662 * until the user releases the mouse.
17664 * @param {boolean} pressed An option is being pressed
17666 OO
.ui
.SelectWidget
.prototype.togglePressed = function ( pressed
) {
17667 if ( pressed
=== undefined ) {
17668 pressed
= !this.pressed
;
17670 if ( pressed
!== this.pressed
) {
17672 .toggleClass( 'oo-ui-selectWidget-pressed', pressed
)
17673 .toggleClass( 'oo-ui-selectWidget-depressed', !pressed
);
17674 this.pressed
= pressed
;
17679 * Highlight an option. If the `item` param is omitted, no options will be highlighted
17680 * and any existing highlight will be removed. The highlight is mutually exclusive.
17682 * @param {OO.ui.OptionWidget} [item] Item to highlight, omit for no highlight
17686 OO
.ui
.SelectWidget
.prototype.highlightItem = function ( item
) {
17687 var i
, len
, highlighted
,
17690 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
17691 highlighted
= this.items
[ i
] === item
;
17692 if ( this.items
[ i
].isHighlighted() !== highlighted
) {
17693 this.items
[ i
].setHighlighted( highlighted
);
17698 this.emit( 'highlight', item
);
17705 * Fetch an item by its label.
17707 * @param {string} label Label of the item to select.
17708 * @param {boolean} [prefix=false] Allow a prefix match, if only a single item matches
17709 * @return {OO.ui.Element|null} Item with equivalent label, `null` if none exists
17711 OO
.ui
.SelectWidget
.prototype.getItemFromLabel = function ( label
, prefix
) {
17712 var i
, item
, found
,
17713 len
= this.items
.length
,
17714 filter
= this.getItemMatcher( label
, true );
17716 for ( i
= 0; i
< len
; i
++ ) {
17717 item
= this.items
[i
];
17718 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() && filter( item
) ) {
17725 filter
= this.getItemMatcher( label
, false );
17726 for ( i
= 0; i
< len
; i
++ ) {
17727 item
= this.items
[i
];
17728 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() && filter( item
) ) {
17744 * Programmatically select an option by its label. If the item does not exist,
17745 * all options will be deselected.
17747 * @param {string} [label] Label of the item to select.
17748 * @param {boolean} [prefix=false] Allow a prefix match, if only a single item matches
17752 OO
.ui
.SelectWidget
.prototype.selectItemByLabel = function ( label
, prefix
) {
17753 var itemFromLabel
= this.getItemFromLabel( label
, !!prefix
);
17754 if ( label
=== undefined || !itemFromLabel
) {
17755 return this.selectItem();
17757 return this.selectItem( itemFromLabel
);
17761 * Programmatically select an option by its data. If the `data` parameter is omitted,
17762 * or if the item does not exist, all options will be deselected.
17764 * @param {Object|string} [data] Value of the item to select, omit to deselect all
17768 OO
.ui
.SelectWidget
.prototype.selectItemByData = function ( data
) {
17769 var itemFromData
= this.getItemFromData( data
);
17770 if ( data
=== undefined || !itemFromData
) {
17771 return this.selectItem();
17773 return this.selectItem( itemFromData
);
17777 * Programmatically select an option by its reference. If the `item` parameter is omitted,
17778 * all options will be deselected.
17780 * @param {OO.ui.OptionWidget} [item] Item to select, omit to deselect all
17784 OO
.ui
.SelectWidget
.prototype.selectItem = function ( item
) {
17785 var i
, len
, selected
,
17788 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
17789 selected
= this.items
[ i
] === item
;
17790 if ( this.items
[ i
].isSelected() !== selected
) {
17791 this.items
[ i
].setSelected( selected
);
17796 this.emit( 'select', item
);
17805 * Press is a state that occurs when a user mouses down on an item, but has not
17806 * yet let go of the mouse. The item may appear selected, but it will not be selected until the user
17807 * releases the mouse.
17809 * @param {OO.ui.OptionWidget} [item] Item to press, omit to depress all
17813 OO
.ui
.SelectWidget
.prototype.pressItem = function ( item
) {
17814 var i
, len
, pressed
,
17817 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
17818 pressed
= this.items
[ i
] === item
;
17819 if ( this.items
[ i
].isPressed() !== pressed
) {
17820 this.items
[ i
].setPressed( pressed
);
17825 this.emit( 'press', item
);
17834 * Note that ‘choose’ should never be modified programmatically. A user can choose
17835 * an option with the keyboard or mouse and it becomes selected. To select an item programmatically,
17836 * use the #selectItem method.
17838 * This method is identical to #selectItem, but may vary in subclasses that take additional action
17839 * when users choose an item with the keyboard or mouse.
17841 * @param {OO.ui.OptionWidget} item Item to choose
17845 OO
.ui
.SelectWidget
.prototype.chooseItem = function ( item
) {
17846 this.selectItem( item
);
17847 this.emit( 'choose', item
);
17853 * Get an option by its position relative to the specified item (or to the start of the option array,
17854 * if item is `null`). The direction in which to search through the option array is specified with a
17855 * number: -1 for reverse (the default) or 1 for forward. The method will return an option, or
17856 * `null` if there are no options in the array.
17858 * @param {OO.ui.OptionWidget|null} item Item to describe the start position, or `null` to start at the beginning of the array.
17859 * @param {number} direction Direction to move in: -1 to move backward, 1 to move forward
17860 * @param {Function} filter Only consider items for which this function returns
17861 * true. Function takes an OO.ui.OptionWidget and returns a boolean.
17862 * @return {OO.ui.OptionWidget|null} Item at position, `null` if there are no items in the select
17864 OO
.ui
.SelectWidget
.prototype.getRelativeSelectableItem = function ( item
, direction
, filter
) {
17865 var currentIndex
, nextIndex
, i
,
17866 increase
= direction
> 0 ? 1 : -1,
17867 len
= this.items
.length
;
17869 if ( !$.isFunction( filter
) ) {
17870 filter
= OO
.ui
.SelectWidget
.static.passAllFilter
;
17873 if ( item
instanceof OO
.ui
.OptionWidget
) {
17874 currentIndex
= $.inArray( item
, this.items
);
17875 nextIndex
= ( currentIndex
+ increase
+ len
) % len
;
17877 // If no item is selected and moving forward, start at the beginning.
17878 // If moving backward, start at the end.
17879 nextIndex
= direction
> 0 ? 0 : len
- 1;
17882 for ( i
= 0; i
< len
; i
++ ) {
17883 item
= this.items
[ nextIndex
];
17884 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() && filter( item
) ) {
17887 nextIndex
= ( nextIndex
+ increase
+ len
) % len
;
17893 * Get the next selectable item or `null` if there are no selectable items.
17894 * Disabled options and menu-section markers and breaks are not selectable.
17896 * @return {OO.ui.OptionWidget|null} Item, `null` if there aren't any selectable items
17898 OO
.ui
.SelectWidget
.prototype.getFirstSelectableItem = function () {
17901 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
17902 item
= this.items
[ i
];
17903 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() ) {
17912 * Add an array of options to the select. Optionally, an index number can be used to
17913 * specify an insertion point.
17915 * @param {OO.ui.OptionWidget[]} items Items to add
17916 * @param {number} [index] Index to insert items after
17920 OO
.ui
.SelectWidget
.prototype.addItems = function ( items
, index
) {
17922 OO
.ui
.mixin
.GroupWidget
.prototype.addItems
.call( this, items
, index
);
17924 // Always provide an index, even if it was omitted
17925 this.emit( 'add', items
, index
=== undefined ? this.items
.length
- items
.length
- 1 : index
);
17931 * Remove the specified array of options from the select. Options will be detached
17932 * from the DOM, not removed, so they can be reused later. To remove all options from
17933 * the select, you may wish to use the #clearItems method instead.
17935 * @param {OO.ui.OptionWidget[]} items Items to remove
17939 OO
.ui
.SelectWidget
.prototype.removeItems = function ( items
) {
17942 // Deselect items being removed
17943 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
17945 if ( item
.isSelected() ) {
17946 this.selectItem( null );
17951 OO
.ui
.mixin
.GroupWidget
.prototype.removeItems
.call( this, items
);
17953 this.emit( 'remove', items
);
17959 * Clear all options from the select. Options will be detached from the DOM, not removed,
17960 * so that they can be reused later. To remove a subset of options from the select, use
17961 * the #removeItems method.
17966 OO
.ui
.SelectWidget
.prototype.clearItems = function () {
17967 var items
= this.items
.slice();
17970 OO
.ui
.mixin
.GroupWidget
.prototype.clearItems
.call( this );
17973 this.selectItem( null );
17975 this.emit( 'remove', items
);
17981 * ButtonSelectWidget is a {@link OO.ui.SelectWidget select widget} that contains
17982 * button options and is used together with
17983 * OO.ui.ButtonOptionWidget. The ButtonSelectWidget provides an interface for
17984 * highlighting, choosing, and selecting mutually exclusive options. Please see
17985 * the [OOjs UI documentation on MediaWiki] [1] for more information.
17988 * // Example: A ButtonSelectWidget that contains three ButtonOptionWidgets
17989 * var option1 = new OO.ui.ButtonOptionWidget( {
17991 * label: 'Option 1',
17992 * title: 'Button option 1'
17995 * var option2 = new OO.ui.ButtonOptionWidget( {
17997 * label: 'Option 2',
17998 * title: 'Button option 2'
18001 * var option3 = new OO.ui.ButtonOptionWidget( {
18003 * label: 'Option 3',
18004 * title: 'Button option 3'
18007 * var buttonSelect=new OO.ui.ButtonSelectWidget( {
18008 * items: [ option1, option2, option3 ]
18010 * $( 'body' ).append( buttonSelect.$element );
18012 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
18015 * @extends OO.ui.SelectWidget
18016 * @mixins OO.ui.mixin.TabIndexedElement
18019 * @param {Object} [config] Configuration options
18021 OO
.ui
.ButtonSelectWidget
= function OoUiButtonSelectWidget( config
) {
18022 // Parent constructor
18023 OO
.ui
.ButtonSelectWidget
.parent
.call( this, config
);
18025 // Mixin constructors
18026 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
18029 this.$element
.on( {
18030 focus
: this.bindKeyDownListener
.bind( this ),
18031 blur
: this.unbindKeyDownListener
.bind( this )
18035 this.$element
.addClass( 'oo-ui-buttonSelectWidget' );
18040 OO
.inheritClass( OO
.ui
.ButtonSelectWidget
, OO
.ui
.SelectWidget
);
18041 OO
.mixinClass( OO
.ui
.ButtonSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
18044 * RadioSelectWidget is a {@link OO.ui.SelectWidget select widget} that contains radio
18045 * options and is used together with OO.ui.RadioOptionWidget. The RadioSelectWidget provides
18046 * an interface for adding, removing and selecting options.
18047 * Please see the [OOjs UI documentation on MediaWiki][1] for more information.
18049 * If you want to use this within a HTML form, such as a OO.ui.FormLayout, use
18050 * OO.ui.RadioSelectInputWidget instead.
18053 * // A RadioSelectWidget with RadioOptions.
18054 * var option1 = new OO.ui.RadioOptionWidget( {
18056 * label: 'Selected radio option'
18059 * var option2 = new OO.ui.RadioOptionWidget( {
18061 * label: 'Unselected radio option'
18064 * var radioSelect=new OO.ui.RadioSelectWidget( {
18065 * items: [ option1, option2 ]
18068 * // Select 'option 1' using the RadioSelectWidget's selectItem() method.
18069 * radioSelect.selectItem( option1 );
18071 * $( 'body' ).append( radioSelect.$element );
18073 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
18077 * @extends OO.ui.SelectWidget
18078 * @mixins OO.ui.mixin.TabIndexedElement
18081 * @param {Object} [config] Configuration options
18083 OO
.ui
.RadioSelectWidget
= function OoUiRadioSelectWidget( config
) {
18084 // Parent constructor
18085 OO
.ui
.RadioSelectWidget
.parent
.call( this, config
);
18087 // Mixin constructors
18088 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
18091 this.$element
.on( {
18092 focus
: this.bindKeyDownListener
.bind( this ),
18093 blur
: this.unbindKeyDownListener
.bind( this )
18098 .addClass( 'oo-ui-radioSelectWidget' )
18099 .attr( 'role', 'radiogroup' );
18104 OO
.inheritClass( OO
.ui
.RadioSelectWidget
, OO
.ui
.SelectWidget
);
18105 OO
.mixinClass( OO
.ui
.RadioSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
18108 * MenuSelectWidget is a {@link OO.ui.SelectWidget select widget} that contains options and
18109 * is used together with OO.ui.MenuOptionWidget. It is designed be used as part of another widget.
18110 * See {@link OO.ui.DropdownWidget DropdownWidget}, {@link OO.ui.ComboBoxWidget ComboBoxWidget},
18111 * and {@link OO.ui.mixin.LookupElement LookupElement} for examples of widgets that contain menus.
18112 * MenuSelectWidgets themselves are not instantiated directly, rather subclassed
18113 * and customized to be opened, closed, and displayed as needed.
18115 * By default, menus are clipped to the visible viewport and are not visible when a user presses the
18116 * mouse outside the menu.
18118 * Menus also have support for keyboard interaction:
18120 * - Enter/Return key: choose and select a menu option
18121 * - Up-arrow key: highlight the previous menu option
18122 * - Down-arrow key: highlight the next menu option
18123 * - Esc key: hide the menu
18125 * Please see the [OOjs UI documentation on MediaWiki][1] for more information.
18126 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
18129 * @extends OO.ui.SelectWidget
18130 * @mixins OO.ui.mixin.ClippableElement
18133 * @param {Object} [config] Configuration options
18134 * @cfg {OO.ui.TextInputWidget} [input] Text input used to implement option highlighting for menu items that match
18135 * the text the user types. This config is used by {@link OO.ui.ComboBoxWidget ComboBoxWidget}
18136 * and {@link OO.ui.mixin.LookupElement LookupElement}
18137 * @cfg {jQuery} [$input] Text input used to implement option highlighting for menu items that match
18138 * the text the user types. This config is used by {@link OO.ui.CapsuleMultiSelectWidget CapsuleMultiSelectWidget}
18139 * @cfg {OO.ui.Widget} [widget] Widget associated with the menu's active state. If the user clicks the mouse
18140 * anywhere on the page outside of this widget, the menu is hidden. For example, if there is a button
18141 * that toggles the menu's visibility on click, the menu will be hidden then re-shown when the user clicks
18142 * that button, unless the button (or its parent widget) is passed in here.
18143 * @cfg {boolean} [autoHide=true] Hide the menu when the mouse is pressed outside the menu.
18144 * @cfg {boolean} [filterFromInput=false] Filter the displayed options from the input
18146 OO
.ui
.MenuSelectWidget
= function OoUiMenuSelectWidget( config
) {
18147 // Configuration initialization
18148 config
= config
|| {};
18150 // Parent constructor
18151 OO
.ui
.MenuSelectWidget
.parent
.call( this, config
);
18153 // Mixin constructors
18154 OO
.ui
.mixin
.ClippableElement
.call( this, $.extend( {}, config
, { $clippable
: this.$group
} ) );
18157 this.newItems
= null;
18158 this.autoHide
= config
.autoHide
=== undefined || !!config
.autoHide
;
18159 this.filterFromInput
= !!config
.filterFromInput
;
18160 this.$input
= config
.$input
? config
.$input
: config
.input
? config
.input
.$input
: null;
18161 this.$widget
= config
.widget
? config
.widget
.$element
: null;
18162 this.onDocumentMouseDownHandler
= this.onDocumentMouseDown
.bind( this );
18163 this.onInputKeyPressHandler
= OO
.ui
.debounce( this.updateItemVisibility
.bind( this ), 100 );
18167 .addClass( 'oo-ui-menuSelectWidget' )
18168 .attr( 'role', 'menu' );
18170 // Initially hidden - using #toggle may cause errors if subclasses override toggle with methods
18171 // that reference properties not initialized at that time of parent class construction
18172 // TODO: Find a better way to handle post-constructor setup
18173 this.visible
= false;
18174 this.$element
.addClass( 'oo-ui-element-hidden' );
18179 OO
.inheritClass( OO
.ui
.MenuSelectWidget
, OO
.ui
.SelectWidget
);
18180 OO
.mixinClass( OO
.ui
.MenuSelectWidget
, OO
.ui
.mixin
.ClippableElement
);
18185 * Handles document mouse down events.
18188 * @param {jQuery.Event} e Key down event
18190 OO
.ui
.MenuSelectWidget
.prototype.onDocumentMouseDown = function ( e
) {
18192 !OO
.ui
.contains( this.$element
[ 0 ], e
.target
, true ) &&
18193 ( !this.$widget
|| !OO
.ui
.contains( this.$widget
[ 0 ], e
.target
, true ) )
18195 this.toggle( false );
18202 OO
.ui
.MenuSelectWidget
.prototype.onKeyDown = function ( e
) {
18203 var currentItem
= this.getHighlightedItem() || this.getSelectedItem();
18205 if ( !this.isDisabled() && this.isVisible() ) {
18206 switch ( e
.keyCode
) {
18207 case OO
.ui
.Keys
.LEFT
:
18208 case OO
.ui
.Keys
.RIGHT
:
18209 // Do nothing if a text field is associated, arrow keys will be handled natively
18210 if ( !this.$input
) {
18211 OO
.ui
.MenuSelectWidget
.parent
.prototype.onKeyDown
.call( this, e
);
18214 case OO
.ui
.Keys
.ESCAPE
:
18215 case OO
.ui
.Keys
.TAB
:
18216 if ( currentItem
) {
18217 currentItem
.setHighlighted( false );
18219 this.toggle( false );
18220 // Don't prevent tabbing away, prevent defocusing
18221 if ( e
.keyCode
=== OO
.ui
.Keys
.ESCAPE
) {
18222 e
.preventDefault();
18223 e
.stopPropagation();
18227 OO
.ui
.MenuSelectWidget
.parent
.prototype.onKeyDown
.call( this, e
);
18234 * Update menu item visibility after input key press
18237 OO
.ui
.MenuSelectWidget
.prototype.updateItemVisibility = function () {
18239 len
= this.items
.length
,
18240 showAll
= !this.isVisible(),
18241 filter
= showAll
? null : this.getItemMatcher( this.$input
.val() );
18243 for ( i
= 0; i
< len
; i
++ ) {
18244 item
= this.items
[i
];
18245 if ( item
instanceof OO
.ui
.OptionWidget
) {
18246 item
.toggle( showAll
|| filter( item
) );
18250 // Reevaluate clipping
18257 OO
.ui
.MenuSelectWidget
.prototype.bindKeyDownListener = function () {
18258 if ( this.$input
) {
18259 this.$input
.on( 'keydown', this.onKeyDownHandler
);
18261 OO
.ui
.MenuSelectWidget
.parent
.prototype.bindKeyDownListener
.call( this );
18268 OO
.ui
.MenuSelectWidget
.prototype.unbindKeyDownListener = function () {
18269 if ( this.$input
) {
18270 this.$input
.off( 'keydown', this.onKeyDownHandler
);
18272 OO
.ui
.MenuSelectWidget
.parent
.prototype.unbindKeyDownListener
.call( this );
18279 OO
.ui
.MenuSelectWidget
.prototype.bindKeyPressListener = function () {
18280 if ( this.$input
) {
18281 if ( this.filterFromInput
) {
18282 this.$input
.on( 'keypress', this.onInputKeyPressHandler
);
18285 OO
.ui
.MenuSelectWidget
.parent
.prototype.bindKeyPressListener
.call( this );
18292 OO
.ui
.MenuSelectWidget
.prototype.unbindKeyPressListener = function () {
18293 if ( this.$input
) {
18294 if ( this.filterFromInput
) {
18295 this.$input
.off( 'keypress', this.onInputKeyPressHandler
);
18296 this.updateItemVisibility();
18299 OO
.ui
.MenuSelectWidget
.parent
.prototype.unbindKeyPressListener
.call( this );
18306 * When a user chooses an item, the menu is closed.
18308 * Note that ‘choose’ should never be modified programmatically. A user can choose an option with the keyboard
18309 * or mouse and it becomes selected. To select an item programmatically, use the #selectItem method.
18310 * @param {OO.ui.OptionWidget} item Item to choose
18313 OO
.ui
.MenuSelectWidget
.prototype.chooseItem = function ( item
) {
18314 OO
.ui
.MenuSelectWidget
.parent
.prototype.chooseItem
.call( this, item
);
18315 this.toggle( false );
18322 OO
.ui
.MenuSelectWidget
.prototype.addItems = function ( items
, index
) {
18326 OO
.ui
.MenuSelectWidget
.parent
.prototype.addItems
.call( this, items
, index
);
18329 if ( !this.newItems
) {
18330 this.newItems
= [];
18333 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
18335 if ( this.isVisible() ) {
18336 // Defer fitting label until item has been attached
18339 this.newItems
.push( item
);
18343 // Reevaluate clipping
18352 OO
.ui
.MenuSelectWidget
.prototype.removeItems = function ( items
) {
18354 OO
.ui
.MenuSelectWidget
.parent
.prototype.removeItems
.call( this, items
);
18356 // Reevaluate clipping
18365 OO
.ui
.MenuSelectWidget
.prototype.clearItems = function () {
18367 OO
.ui
.MenuSelectWidget
.parent
.prototype.clearItems
.call( this );
18369 // Reevaluate clipping
18378 OO
.ui
.MenuSelectWidget
.prototype.toggle = function ( visible
) {
18379 visible
= ( visible
=== undefined ? !this.visible
: !!visible
) && !!this.items
.length
;
18382 change
= visible
!== this.isVisible();
18385 OO
.ui
.MenuSelectWidget
.parent
.prototype.toggle
.call( this, visible
);
18389 this.bindKeyDownListener();
18390 this.bindKeyPressListener();
18392 if ( this.newItems
&& this.newItems
.length
) {
18393 for ( i
= 0, len
= this.newItems
.length
; i
< len
; i
++ ) {
18394 this.newItems
[ i
].fitLabel();
18396 this.newItems
= null;
18398 this.toggleClipping( true );
18401 if ( this.autoHide
) {
18402 this.getElementDocument().addEventListener(
18403 'mousedown', this.onDocumentMouseDownHandler
, true
18407 this.unbindKeyDownListener();
18408 this.unbindKeyPressListener();
18409 this.getElementDocument().removeEventListener(
18410 'mousedown', this.onDocumentMouseDownHandler
, true
18412 this.toggleClipping( false );
18420 * TextInputMenuSelectWidget is a menu that is specially designed to be positioned beneath
18421 * a {@link OO.ui.TextInputWidget text input} field. The menu's position is automatically
18422 * calculated and maintained when the menu is toggled or the window is resized.
18423 * See OO.ui.ComboBoxWidget for an example of a widget that uses this class.
18426 * @extends OO.ui.MenuSelectWidget
18429 * @param {OO.ui.TextInputWidget} inputWidget Text input widget to provide menu for
18430 * @param {Object} [config] Configuration options
18431 * @cfg {jQuery} [$container=input.$element] Element to render menu under
18433 OO
.ui
.TextInputMenuSelectWidget
= function OoUiTextInputMenuSelectWidget( inputWidget
, config
) {
18434 // Allow passing positional parameters inside the config object
18435 if ( OO
.isPlainObject( inputWidget
) && config
=== undefined ) {
18436 config
= inputWidget
;
18437 inputWidget
= config
.inputWidget
;
18440 // Configuration initialization
18441 config
= config
|| {};
18443 // Parent constructor
18444 OO
.ui
.TextInputMenuSelectWidget
.parent
.call( this, config
);
18447 this.inputWidget
= inputWidget
;
18448 this.$container
= config
.$container
|| this.inputWidget
.$element
;
18449 this.onWindowResizeHandler
= this.onWindowResize
.bind( this );
18452 this.$element
.addClass( 'oo-ui-textInputMenuSelectWidget' );
18457 OO
.inheritClass( OO
.ui
.TextInputMenuSelectWidget
, OO
.ui
.MenuSelectWidget
);
18462 * Handle window resize event.
18465 * @param {jQuery.Event} e Window resize event
18467 OO
.ui
.TextInputMenuSelectWidget
.prototype.onWindowResize = function () {
18474 OO
.ui
.TextInputMenuSelectWidget
.prototype.toggle = function ( visible
) {
18475 visible
= visible
=== undefined ? !this.isVisible() : !!visible
;
18477 var change
= visible
!== this.isVisible();
18479 if ( change
&& visible
) {
18480 // Make sure the width is set before the parent method runs.
18481 // After this we have to call this.position(); again to actually
18482 // position ourselves correctly.
18487 OO
.ui
.TextInputMenuSelectWidget
.parent
.prototype.toggle
.call( this, visible
);
18490 if ( this.isVisible() ) {
18492 $( this.getElementWindow() ).on( 'resize', this.onWindowResizeHandler
);
18494 $( this.getElementWindow() ).off( 'resize', this.onWindowResizeHandler
);
18502 * Position the menu.
18507 OO
.ui
.TextInputMenuSelectWidget
.prototype.position = function () {
18508 var $container
= this.$container
,
18509 pos
= OO
.ui
.Element
.static.getRelativePosition( $container
, this.$element
.offsetParent() );
18511 // Position under input
18512 pos
.top
+= $container
.height();
18513 this.$element
.css( pos
);
18516 this.setIdealSize( $container
.width() );
18517 // We updated the position, so re-evaluate the clipping state
18524 * OutlineSelectWidget is a structured list that contains {@link OO.ui.OutlineOptionWidget outline options}
18525 * A set of controls can be provided with an {@link OO.ui.OutlineControlsWidget outline controls} widget.
18527 * **Currently, this class is only used by {@link OO.ui.BookletLayout booklet layouts}.**
18530 * @extends OO.ui.SelectWidget
18531 * @mixins OO.ui.mixin.TabIndexedElement
18534 * @param {Object} [config] Configuration options
18536 OO
.ui
.OutlineSelectWidget
= function OoUiOutlineSelectWidget( config
) {
18537 // Parent constructor
18538 OO
.ui
.OutlineSelectWidget
.parent
.call( this, config
);
18540 // Mixin constructors
18541 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
18544 this.$element
.on( {
18545 focus
: this.bindKeyDownListener
.bind( this ),
18546 blur
: this.unbindKeyDownListener
.bind( this )
18550 this.$element
.addClass( 'oo-ui-outlineSelectWidget' );
18555 OO
.inheritClass( OO
.ui
.OutlineSelectWidget
, OO
.ui
.SelectWidget
);
18556 OO
.mixinClass( OO
.ui
.OutlineSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
18559 * TabSelectWidget is a list that contains {@link OO.ui.TabOptionWidget tab options}
18561 * **Currently, this class is only used by {@link OO.ui.IndexLayout index layouts}.**
18564 * @extends OO.ui.SelectWidget
18565 * @mixins OO.ui.mixin.TabIndexedElement
18568 * @param {Object} [config] Configuration options
18570 OO
.ui
.TabSelectWidget
= function OoUiTabSelectWidget( config
) {
18571 // Parent constructor
18572 OO
.ui
.TabSelectWidget
.parent
.call( this, config
);
18574 // Mixin constructors
18575 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
18578 this.$element
.on( {
18579 focus
: this.bindKeyDownListener
.bind( this ),
18580 blur
: this.unbindKeyDownListener
.bind( this )
18584 this.$element
.addClass( 'oo-ui-tabSelectWidget' );
18589 OO
.inheritClass( OO
.ui
.TabSelectWidget
, OO
.ui
.SelectWidget
);
18590 OO
.mixinClass( OO
.ui
.TabSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
18593 * NumberInputWidgets combine a {@link OO.ui.TextInputWidget text input} (where a value
18594 * can be entered manually) and two {@link OO.ui.ButtonWidget button widgets}
18595 * (to adjust the value in increments) to allow the user to enter a number.
18598 * // Example: A NumberInputWidget.
18599 * var numberInput = new OO.ui.NumberInputWidget( {
18600 * label: 'NumberInputWidget',
18601 * input: { value: 5, min: 1, max: 10 }
18603 * $( 'body' ).append( numberInput.$element );
18606 * @extends OO.ui.Widget
18609 * @param {Object} [config] Configuration options
18610 * @cfg {Object} [input] Configuration options to pass to the {@link OO.ui.TextInputWidget text input widget}.
18611 * @cfg {Object} [minusButton] Configuration options to pass to the {@link OO.ui.ButtonWidget decrementing button widget}.
18612 * @cfg {Object} [plusButton] Configuration options to pass to the {@link OO.ui.ButtonWidget incrementing button widget}.
18613 * @cfg {boolean} [isInteger=false] Whether the field accepts only integer values.
18614 * @cfg {number} [min=-Infinity] Minimum allowed value
18615 * @cfg {number} [max=Infinity] Maximum allowed value
18616 * @cfg {number} [step=1] Delta when using the buttons or up/down arrow keys
18617 * @cfg {number|null} [pageStep] Delta when using the page-up/page-down keys. Defaults to 10 times #step.
18619 OO
.ui
.NumberInputWidget
= function OoUiNumberInputWidget( config
) {
18620 // Configuration initialization
18621 config
= $.extend( {
18629 // Parent constructor
18630 OO
.ui
.NumberInputWidget
.parent
.call( this, config
);
18633 this.input
= new OO
.ui
.TextInputWidget( $.extend(
18635 disabled
: this.isDisabled()
18639 this.minusButton
= new OO
.ui
.ButtonWidget( $.extend(
18641 disabled
: this.isDisabled(),
18644 config
.minusButton
,
18646 classes
: [ 'oo-ui-numberInputWidget-minusButton' ],
18650 this.plusButton
= new OO
.ui
.ButtonWidget( $.extend(
18652 disabled
: this.isDisabled(),
18657 classes
: [ 'oo-ui-numberInputWidget-plusButton' ],
18663 this.input
.connect( this, {
18664 change
: this.emit
.bind( this, 'change' ),
18665 enter
: this.emit
.bind( this, 'enter' )
18667 this.input
.$input
.on( {
18668 keydown
: this.onKeyDown
.bind( this ),
18669 'wheel mousewheel DOMMouseScroll': this.onWheel
.bind( this )
18671 this.plusButton
.connect( this, {
18672 click
: [ 'onButtonClick', +1 ]
18674 this.minusButton
.connect( this, {
18675 click
: [ 'onButtonClick', -1 ]
18679 this.setIsInteger( !!config
.isInteger
);
18680 this.setRange( config
.min
, config
.max
);
18681 this.setStep( config
.step
, config
.pageStep
);
18683 this.$field
= $( '<div>' ).addClass( 'oo-ui-numberInputWidget-field' )
18685 this.minusButton
.$element
,
18686 this.input
.$element
,
18687 this.plusButton
.$element
18689 this.$element
.addClass( 'oo-ui-numberInputWidget' ).append( this.$field
);
18690 this.input
.setValidation( this.validateNumber
.bind( this ) );
18695 OO
.inheritClass( OO
.ui
.NumberInputWidget
, OO
.ui
.Widget
);
18700 * A `change` event is emitted when the value of the input changes.
18706 * An `enter` event is emitted when the user presses 'enter' inside the text box.
18714 * Set whether only integers are allowed
18715 * @param {boolean} flag
18717 OO
.ui
.NumberInputWidget
.prototype.setIsInteger = function ( flag
) {
18718 this.isInteger
= !!flag
;
18719 this.input
.setValidityFlag();
18723 * Get whether only integers are allowed
18724 * @return {boolean} Flag value
18726 OO
.ui
.NumberInputWidget
.prototype.getIsInteger = function () {
18727 return this.isInteger
;
18731 * Set the range of allowed values
18732 * @param {number} min Minimum allowed value
18733 * @param {number} max Maximum allowed value
18735 OO
.ui
.NumberInputWidget
.prototype.setRange = function ( min
, max
) {
18737 throw new Error( 'Minimum (' + min
+ ') must not be greater than maximum (' + max
+ ')' );
18741 this.input
.setValidityFlag();
18745 * Get the current range
18746 * @return {number[]} Minimum and maximum values
18748 OO
.ui
.NumberInputWidget
.prototype.getRange = function () {
18749 return [ this.min
, this.max
];
18753 * Set the stepping deltas
18754 * @param {number} step Normal step
18755 * @param {number|null} pageStep Page step. If null, 10 * step will be used.
18757 OO
.ui
.NumberInputWidget
.prototype.setStep = function ( step
, pageStep
) {
18759 throw new Error( 'Step value must be positive' );
18761 if ( pageStep
=== null ) {
18762 pageStep
= step
* 10;
18763 } else if ( pageStep
<= 0 ) {
18764 throw new Error( 'Page step value must be positive' );
18767 this.pageStep
= pageStep
;
18771 * Get the current stepping values
18772 * @return {number[]} Step and page step
18774 OO
.ui
.NumberInputWidget
.prototype.getStep = function () {
18775 return [ this.step
, this.pageStep
];
18779 * Get the current value of the widget
18782 OO
.ui
.NumberInputWidget
.prototype.getValue = function () {
18783 return this.input
.getValue();
18787 * Get the current value of the widget as a number
18788 * @return {number} May be NaN, or an invalid number
18790 OO
.ui
.NumberInputWidget
.prototype.getNumericValue = function () {
18791 return +this.input
.getValue();
18795 * Set the value of the widget
18796 * @param {string} value Invalid values are allowed
18798 OO
.ui
.NumberInputWidget
.prototype.setValue = function ( value
) {
18799 this.input
.setValue( value
);
18803 * Adjust the value of the widget
18804 * @param {number} delta Adjustment amount
18806 OO
.ui
.NumberInputWidget
.prototype.adjustValue = function ( delta
) {
18807 var n
, v
= this.getNumericValue();
18810 if ( isNaN( delta
) || !isFinite( delta
) ) {
18811 throw new Error( 'Delta must be a finite number' );
18814 if ( isNaN( v
) ) {
18818 n
= Math
.max( Math
.min( n
, this.max
), this.min
);
18819 if ( this.isInteger
) {
18820 n
= Math
.round( n
);
18825 this.setValue( n
);
18832 * @param {string} value Field value
18833 * @return {boolean}
18835 OO
.ui
.NumberInputWidget
.prototype.validateNumber = function ( value
) {
18837 if ( isNaN( n
) || !isFinite( n
) ) {
18841 /*jshint bitwise: false */
18842 if ( this.isInteger
&& ( n
| 0 ) !== n
) {
18845 /*jshint bitwise: true */
18847 if ( n
< this.min
|| n
> this.max
) {
18855 * Handle mouse click events.
18858 * @param {number} dir +1 or -1
18860 OO
.ui
.NumberInputWidget
.prototype.onButtonClick = function ( dir
) {
18861 this.adjustValue( dir
* this.step
);
18865 * Handle mouse wheel events.
18868 * @param {jQuery.Event} event
18870 OO
.ui
.NumberInputWidget
.prototype.onWheel = function ( event
) {
18873 // Standard 'wheel' event
18874 if ( event
.originalEvent
.deltaMode
!== undefined ) {
18875 this.sawWheelEvent
= true;
18877 if ( event
.originalEvent
.deltaY
) {
18878 delta
= -event
.originalEvent
.deltaY
;
18879 } else if ( event
.originalEvent
.deltaX
) {
18880 delta
= event
.originalEvent
.deltaX
;
18883 // Non-standard events
18884 if ( !this.sawWheelEvent
) {
18885 if ( event
.originalEvent
.wheelDeltaX
) {
18886 delta
= -event
.originalEvent
.wheelDeltaX
;
18887 } else if ( event
.originalEvent
.wheelDeltaY
) {
18888 delta
= event
.originalEvent
.wheelDeltaY
;
18889 } else if ( event
.originalEvent
.wheelDelta
) {
18890 delta
= event
.originalEvent
.wheelDelta
;
18891 } else if ( event
.originalEvent
.detail
) {
18892 delta
= -event
.originalEvent
.detail
;
18897 delta
= delta
< 0 ? -1 : 1;
18898 this.adjustValue( delta
* this.step
);
18905 * Handle key down events.
18909 * @param {jQuery.Event} e Key down event
18911 OO
.ui
.NumberInputWidget
.prototype.onKeyDown = function ( e
) {
18912 if ( !this.isDisabled() ) {
18913 switch ( e
.which
) {
18914 case OO
.ui
.Keys
.UP
:
18915 this.adjustValue( this.step
);
18917 case OO
.ui
.Keys
.DOWN
:
18918 this.adjustValue( -this.step
);
18920 case OO
.ui
.Keys
.PAGEUP
:
18921 this.adjustValue( this.pageStep
);
18923 case OO
.ui
.Keys
.PAGEDOWN
:
18924 this.adjustValue( -this.pageStep
);
18933 OO
.ui
.NumberInputWidget
.prototype.setDisabled = function ( disabled
) {
18935 OO
.ui
.NumberInputWidget
.parent
.prototype.setDisabled
.call( this, disabled
);
18937 if ( this.input
) {
18938 this.input
.setDisabled( this.isDisabled() );
18940 if ( this.minusButton
) {
18941 this.minusButton
.setDisabled( this.isDisabled() );
18943 if ( this.plusButton
) {
18944 this.plusButton
.setDisabled( this.isDisabled() );
18951 * ToggleSwitches are switches that slide on and off. Their state is represented by a Boolean
18952 * value (`true` for ‘on’, and `false` otherwise, the default). The ‘off’ state is represented
18953 * visually by a slider in the leftmost position.
18956 * // Toggle switches in the 'off' and 'on' position.
18957 * var toggleSwitch1 = new OO.ui.ToggleSwitchWidget();
18958 * var toggleSwitch2 = new OO.ui.ToggleSwitchWidget( {
18962 * // Create a FieldsetLayout to layout and label switches
18963 * var fieldset = new OO.ui.FieldsetLayout( {
18964 * label: 'Toggle switches'
18966 * fieldset.addItems( [
18967 * new OO.ui.FieldLayout( toggleSwitch1, { label: 'Off', align: 'top' } ),
18968 * new OO.ui.FieldLayout( toggleSwitch2, { label: 'On', align: 'top' } )
18970 * $( 'body' ).append( fieldset.$element );
18973 * @extends OO.ui.ToggleWidget
18974 * @mixins OO.ui.mixin.TabIndexedElement
18977 * @param {Object} [config] Configuration options
18978 * @cfg {boolean} [value=false] The toggle switch’s initial on/off state.
18979 * By default, the toggle switch is in the 'off' position.
18981 OO
.ui
.ToggleSwitchWidget
= function OoUiToggleSwitchWidget( config
) {
18982 // Parent constructor
18983 OO
.ui
.ToggleSwitchWidget
.parent
.call( this, config
);
18985 // Mixin constructors
18986 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
18989 this.dragging
= false;
18990 this.dragStart
= null;
18991 this.sliding
= false;
18992 this.$glow
= $( '<span>' );
18993 this.$grip
= $( '<span>' );
18996 this.$element
.on( {
18997 click
: this.onClick
.bind( this ),
18998 keypress
: this.onKeyPress
.bind( this )
19002 this.$glow
.addClass( 'oo-ui-toggleSwitchWidget-glow' );
19003 this.$grip
.addClass( 'oo-ui-toggleSwitchWidget-grip' );
19005 .addClass( 'oo-ui-toggleSwitchWidget' )
19006 .attr( 'role', 'checkbox' )
19007 .append( this.$glow
, this.$grip
);
19012 OO
.inheritClass( OO
.ui
.ToggleSwitchWidget
, OO
.ui
.ToggleWidget
);
19013 OO
.mixinClass( OO
.ui
.ToggleSwitchWidget
, OO
.ui
.mixin
.TabIndexedElement
);
19018 * Handle mouse click events.
19021 * @param {jQuery.Event} e Mouse click event
19023 OO
.ui
.ToggleSwitchWidget
.prototype.onClick = function ( e
) {
19024 if ( !this.isDisabled() && e
.which
=== 1 ) {
19025 this.setValue( !this.value
);
19031 * Handle key press events.
19034 * @param {jQuery.Event} e Key press event
19036 OO
.ui
.ToggleSwitchWidget
.prototype.onKeyPress = function ( e
) {
19037 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
19038 this.setValue( !this.value
);
19044 * Deprecated aliases for classes in the `OO.ui.mixin` namespace.
19048 * @inheritdoc OO.ui.mixin.ButtonElement
19049 * @deprecated Use {@link OO.ui.mixin.ButtonElement} instead.
19051 OO
.ui
.ButtonElement
= OO
.ui
.mixin
.ButtonElement
;
19054 * @inheritdoc OO.ui.mixin.ClippableElement
19055 * @deprecated Use {@link OO.ui.mixin.ClippableElement} instead.
19057 OO
.ui
.ClippableElement
= OO
.ui
.mixin
.ClippableElement
;
19060 * @inheritdoc OO.ui.mixin.DraggableElement
19061 * @deprecated Use {@link OO.ui.mixin.DraggableElement} instead.
19063 OO
.ui
.DraggableElement
= OO
.ui
.mixin
.DraggableElement
;
19066 * @inheritdoc OO.ui.mixin.DraggableGroupElement
19067 * @deprecated Use {@link OO.ui.mixin.DraggableGroupElement} instead.
19069 OO
.ui
.DraggableGroupElement
= OO
.ui
.mixin
.DraggableGroupElement
;
19072 * @inheritdoc OO.ui.mixin.FlaggedElement
19073 * @deprecated Use {@link OO.ui.mixin.FlaggedElement} instead.
19075 OO
.ui
.FlaggedElement
= OO
.ui
.mixin
.FlaggedElement
;
19078 * @inheritdoc OO.ui.mixin.GroupElement
19079 * @deprecated Use {@link OO.ui.mixin.GroupElement} instead.
19081 OO
.ui
.GroupElement
= OO
.ui
.mixin
.GroupElement
;
19084 * @inheritdoc OO.ui.mixin.GroupWidget
19085 * @deprecated Use {@link OO.ui.mixin.GroupWidget} instead.
19087 OO
.ui
.GroupWidget
= OO
.ui
.mixin
.GroupWidget
;
19090 * @inheritdoc OO.ui.mixin.IconElement
19091 * @deprecated Use {@link OO.ui.mixin.IconElement} instead.
19093 OO
.ui
.IconElement
= OO
.ui
.mixin
.IconElement
;
19096 * @inheritdoc OO.ui.mixin.IndicatorElement
19097 * @deprecated Use {@link OO.ui.mixin.IndicatorElement} instead.
19099 OO
.ui
.IndicatorElement
= OO
.ui
.mixin
.IndicatorElement
;
19102 * @inheritdoc OO.ui.mixin.ItemWidget
19103 * @deprecated Use {@link OO.ui.mixin.ItemWidget} instead.
19105 OO
.ui
.ItemWidget
= OO
.ui
.mixin
.ItemWidget
;
19108 * @inheritdoc OO.ui.mixin.LabelElement
19109 * @deprecated Use {@link OO.ui.mixin.LabelElement} instead.
19111 OO
.ui
.LabelElement
= OO
.ui
.mixin
.LabelElement
;
19114 * @inheritdoc OO.ui.mixin.LookupElement
19115 * @deprecated Use {@link OO.ui.mixin.LookupElement} instead.
19117 OO
.ui
.LookupElement
= OO
.ui
.mixin
.LookupElement
;
19120 * @inheritdoc OO.ui.mixin.PendingElement
19121 * @deprecated Use {@link OO.ui.mixin.PendingElement} instead.
19123 OO
.ui
.PendingElement
= OO
.ui
.mixin
.PendingElement
;
19126 * @inheritdoc OO.ui.mixin.PopupElement
19127 * @deprecated Use {@link OO.ui.mixin.PopupElement} instead.
19129 OO
.ui
.PopupElement
= OO
.ui
.mixin
.PopupElement
;
19132 * @inheritdoc OO.ui.mixin.TabIndexedElement
19133 * @deprecated Use {@link OO.ui.mixin.TabIndexedElement} instead.
19135 OO
.ui
.TabIndexedElement
= OO
.ui
.mixin
.TabIndexedElement
;
19138 * @inheritdoc OO.ui.mixin.TitledElement
19139 * @deprecated Use {@link OO.ui.mixin.TitledElement} instead.
19141 OO
.ui
.TitledElement
= OO
.ui
.mixin
.TitledElement
;