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-10-07T20:48:15Z
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
69 OO
.ui
.isFocusableElement = function ( $element
) {
71 element
= $element
[ 0 ];
73 // Anything disabled is not focusable
74 if ( element
.disabled
) {
78 // Check if the element is visible
80 // This is quicker than calling $element.is( ':visible' )
81 $.expr
.filters
.visible( element
) &&
82 // Check that all parents are visible
83 !$element
.parents().addBack().filter( function () {
84 return $.css( this, 'visibility' ) === 'hidden';
90 // Check if the element is ContentEditable, which is the string 'true'
91 if ( element
.contentEditable
=== 'true' ) {
95 // Anything with a non-negative numeric tabIndex is focusable.
96 // Use .prop to avoid browser bugs
97 if ( $element
.prop( 'tabIndex' ) >= 0 ) {
101 // Some element types are naturally focusable
102 // (indexOf is much faster than regex in Chrome and about the
103 // same in FF: https://jsperf.com/regex-vs-indexof-array2)
104 nodeName
= element
.nodeName
.toLowerCase();
105 if ( [ 'input', 'select', 'textarea', 'button', 'object' ].indexOf( nodeName
) !== -1 ) {
109 // Links and areas are focusable if they have an href
110 if ( ( nodeName
=== 'a' || nodeName
=== 'area' ) && $element
.attr( 'href' ) !== undefined ) {
118 * Find a focusable child
120 * @param {jQuery} $container Container to search in
121 * @param {boolean} [backwards] Search backwards
122 * @return {jQuery} Focusable child, an empty jQuery object if none found
124 OO
.ui
.findFocusable = function ( $container
, backwards
) {
125 var $focusable
= $( [] ),
126 // $focusableCandidates is a superset of things that
127 // could get matched by isFocusableElement
128 $focusableCandidates
= $container
129 .find( 'input, select, textarea, button, object, a, area, [contenteditable], [tabindex]' );
132 $focusableCandidates
= Array
.prototype.reverse
.call( $focusableCandidates
);
135 $focusableCandidates
.each( function () {
136 var $this = $( this );
137 if ( OO
.ui
.isFocusableElement( $this ) ) {
146 * Get the user's language and any fallback languages.
148 * These language codes are used to localize user interface elements in the user's language.
150 * In environments that provide a localization system, this function should be overridden to
151 * return the user's language(s). The default implementation returns English (en) only.
153 * @return {string[]} Language codes, in descending order of priority
155 OO
.ui
.getUserLanguages = function () {
160 * Get a value in an object keyed by language code.
162 * @param {Object.<string,Mixed>} obj Object keyed by language code
163 * @param {string|null} [lang] Language code, if omitted or null defaults to any user language
164 * @param {string} [fallback] Fallback code, used if no matching language can be found
165 * @return {Mixed} Local value
167 OO
.ui
.getLocalValue = function ( obj
, lang
, fallback
) {
170 // Requested language
174 // Known user language
175 langs
= OO
.ui
.getUserLanguages();
176 for ( i
= 0, len
= langs
.length
; i
< len
; i
++ ) {
183 if ( obj
[ fallback
] ) {
184 return obj
[ fallback
];
186 // First existing language
187 for ( lang
in obj
) {
195 * Check if a node is contained within another node
197 * Similar to jQuery#contains except a list of containers can be supplied
198 * and a boolean argument allows you to include the container in the match list
200 * @param {HTMLElement|HTMLElement[]} containers Container node(s) to search in
201 * @param {HTMLElement} contained Node to find
202 * @param {boolean} [matchContainers] Include the container(s) in the list of nodes to match, otherwise only match descendants
203 * @return {boolean} The node is in the list of target nodes
205 OO
.ui
.contains = function ( containers
, contained
, matchContainers
) {
207 if ( !Array
.isArray( containers
) ) {
208 containers
= [ containers
];
210 for ( i
= containers
.length
- 1; i
>= 0; i
-- ) {
211 if ( ( matchContainers
&& contained
=== containers
[ i
] ) || $.contains( containers
[ i
], contained
) ) {
219 * Return a function, that, as long as it continues to be invoked, will not
220 * be triggered. The function will be called after it stops being called for
221 * N milliseconds. If `immediate` is passed, trigger the function on the
222 * leading edge, instead of the trailing.
224 * Ported from: http://underscorejs.org/underscore.js
226 * @param {Function} func
227 * @param {number} wait
228 * @param {boolean} immediate
231 OO
.ui
.debounce = function ( func
, wait
, immediate
) {
236 later = function () {
239 func
.apply( context
, args
);
242 if ( immediate
&& !timeout
) {
243 func
.apply( context
, args
);
245 clearTimeout( timeout
);
246 timeout
= setTimeout( later
, wait
);
251 * Proxy for `node.addEventListener( eventName, handler, true )`, if the browser supports it.
252 * Otherwise falls back to non-capturing event listeners.
254 * @param {HTMLElement} node
255 * @param {string} eventName
256 * @param {Function} handler
258 OO
.ui
.addCaptureEventListener = function ( node
, eventName
, handler
) {
259 if ( node
.addEventListener
) {
260 node
.addEventListener( eventName
, handler
, true );
262 node
.attachEvent( 'on' + eventName
, handler
);
267 * Proxy for `node.removeEventListener( eventName, handler, true )`, if the browser supports it.
268 * Otherwise falls back to non-capturing event listeners.
270 * @param {HTMLElement} node
271 * @param {string} eventName
272 * @param {Function} handler
274 OO
.ui
.removeCaptureEventListener = function ( node
, eventName
, handler
) {
275 if ( node
.addEventListener
) {
276 node
.removeEventListener( eventName
, handler
, true );
278 node
.detachEvent( 'on' + eventName
, handler
);
283 * Reconstitute a JavaScript object corresponding to a widget created by
284 * the PHP implementation.
286 * This is an alias for `OO.ui.Element.static.infuse()`.
288 * @param {string|HTMLElement|jQuery} idOrNode
289 * A DOM id (if a string) or node for the widget to infuse.
290 * @return {OO.ui.Element}
291 * The `OO.ui.Element` corresponding to this (infusable) document node.
293 OO
.ui
.infuse = function ( idOrNode
) {
294 return OO
.ui
.Element
.static.infuse( idOrNode
);
299 * Message store for the default implementation of OO.ui.msg
301 * Environments that provide a localization system should not use this, but should override
302 * OO.ui.msg altogether.
307 // Tool tip for a button that moves items in a list down one place
308 'ooui-outline-control-move-down': 'Move item down',
309 // Tool tip for a button that moves items in a list up one place
310 'ooui-outline-control-move-up': 'Move item up',
311 // Tool tip for a button that removes items from a list
312 'ooui-outline-control-remove': 'Remove item',
313 // Label for the toolbar group that contains a list of all other available tools
314 'ooui-toolbar-more': 'More',
315 // Label for the fake tool that expands the full list of tools in a toolbar group
316 'ooui-toolgroup-expand': 'More',
317 // Label for the fake tool that collapses the full list of tools in a toolbar group
318 'ooui-toolgroup-collapse': 'Fewer',
319 // Default label for the accept button of a confirmation dialog
320 'ooui-dialog-message-accept': 'OK',
321 // Default label for the reject button of a confirmation dialog
322 'ooui-dialog-message-reject': 'Cancel',
323 // Title for process dialog error description
324 'ooui-dialog-process-error': 'Something went wrong',
325 // Label for process dialog dismiss error button, visible when describing errors
326 'ooui-dialog-process-dismiss': 'Dismiss',
327 // Label for process dialog retry action button, visible when describing only recoverable errors
328 'ooui-dialog-process-retry': 'Try again',
329 // Label for process dialog retry action button, visible when describing only warnings
330 'ooui-dialog-process-continue': 'Continue',
331 // Label for the file selection widget's select file button
332 'ooui-selectfile-button-select': 'Select a file',
333 // Label for the file selection widget if file selection is not supported
334 'ooui-selectfile-not-supported': 'File selection is not supported',
335 // Label for the file selection widget when no file is currently selected
336 'ooui-selectfile-placeholder': 'No file is selected',
337 // Label for the file selection widget's drop target
338 'ooui-selectfile-dragdrop-placeholder': 'Drop file here'
342 * Get a localized message.
344 * In environments that provide a localization system, this function should be overridden to
345 * return the message translated in the user's language. The default implementation always returns
348 * After the message key, message parameters may optionally be passed. In the default implementation,
349 * any occurrences of $1 are replaced with the first parameter, $2 with the second parameter, etc.
350 * Alternative implementations of OO.ui.msg may use any substitution system they like, as long as
351 * they support unnamed, ordered message parameters.
354 * @param {string} key Message key
355 * @param {Mixed...} [params] Message parameters
356 * @return {string} Translated message with parameters substituted
358 OO
.ui
.msg = function ( key
) {
359 var message
= messages
[ key
],
360 params
= Array
.prototype.slice
.call( arguments
, 1 );
361 if ( typeof message
=== 'string' ) {
362 // Perform $1 substitution
363 message
= message
.replace( /\$(\d+)/g, function ( unused
, n
) {
364 var i
= parseInt( n
, 10 );
365 return params
[ i
- 1 ] !== undefined ? params
[ i
- 1 ] : '$' + n
;
368 // Return placeholder if message not found
369 message
= '[' + key
+ ']';
375 * Package a message and arguments for deferred resolution.
377 * Use this when you are statically specifying a message and the message may not yet be present.
379 * @param {string} key Message key
380 * @param {Mixed...} [params] Message parameters
381 * @return {Function} Function that returns the resolved message when executed
383 OO
.ui
.deferMsg = function () {
384 var args
= arguments
;
386 return OO
.ui
.msg
.apply( OO
.ui
, args
);
393 * If the message is a function it will be executed, otherwise it will pass through directly.
395 * @param {Function|string} msg Deferred message, or message text
396 * @return {string} Resolved message
398 OO
.ui
.resolveMsg = function ( msg
) {
399 if ( $.isFunction( msg
) ) {
406 * @param {string} url
409 OO
.ui
.isSafeUrl = function ( url
) {
411 // Keep in sync with php/Tag.php
413 'bitcoin:', 'ftp:', 'ftps:', 'geo:', 'git:', 'gopher:', 'http:', 'https:', 'irc:', 'ircs:',
414 'magnet:', 'mailto:', 'mms:', 'news:', 'nntp:', 'redis:', 'sftp:', 'sip:', 'sips:', 'sms:', 'ssh:',
415 'svn:', 'tel:', 'telnet:', 'urn:', 'worldwind:', 'xmpp:'
418 if ( url
.indexOf( ':' ) === -1 ) {
423 protocol
= url
.split( ':', 1 )[ 0 ] + ':';
424 if ( !protocol
.match( /^([A-za-z0-9\+\.\-])+:/ ) ) {
425 // Not a valid protocol, safe
429 // Safe if in the whitelist
430 return whitelist
.indexOf( protocol
) !== -1;
440 * Namespace for OOjs UI mixins.
442 * Mixins are named according to the type of object they are intended to
443 * be mixed in to. For example, OO.ui.mixin.GroupElement is intended to be
444 * mixed in to an instance of OO.ui.Element, and OO.ui.mixin.GroupWidget
445 * is intended to be mixed in to an instance of OO.ui.Widget.
453 * PendingElement is a mixin that is used to create elements that notify users that something is happening
454 * and that they should wait before proceeding. The pending state is visually represented with a pending
455 * texture that appears in the head of a pending {@link OO.ui.ProcessDialog process dialog} or in the input
456 * field of a {@link OO.ui.TextInputWidget text input widget}.
458 * Currently, {@link OO.ui.ActionWidget Action widgets}, which mix in this class, can also be marked as pending, but only when
459 * used in {@link OO.ui.MessageDialog message dialogs}. The behavior is not currently supported for action widgets used
460 * in process dialogs.
463 * function MessageDialog( config ) {
464 * MessageDialog.parent.call( this, config );
466 * OO.inheritClass( MessageDialog, OO.ui.MessageDialog );
468 * MessageDialog.static.actions = [
469 * { action: 'save', label: 'Done', flags: 'primary' },
470 * { label: 'Cancel', flags: 'safe' }
473 * MessageDialog.prototype.initialize = function () {
474 * MessageDialog.parent.prototype.initialize.apply( this, arguments );
475 * this.content = new OO.ui.PanelLayout( { $: this.$, padded: true } );
476 * 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>' );
477 * this.$body.append( this.content.$element );
479 * MessageDialog.prototype.getBodyHeight = function () {
482 * MessageDialog.prototype.getActionProcess = function ( action ) {
484 * if ( action === 'save' ) {
485 * dialog.getActions().get({actions: 'save'})[0].pushPending();
486 * return new OO.ui.Process()
488 * .next( function () {
489 * dialog.getActions().get({actions: 'save'})[0].popPending();
492 * return MessageDialog.parent.prototype.getActionProcess.call( this, action );
495 * var windowManager = new OO.ui.WindowManager();
496 * $( 'body' ).append( windowManager.$element );
498 * var dialog = new MessageDialog();
499 * windowManager.addWindows( [ dialog ] );
500 * windowManager.openWindow( dialog );
506 * @param {Object} [config] Configuration options
507 * @cfg {jQuery} [$pending] Element to mark as pending, defaults to this.$element
509 OO
.ui
.mixin
.PendingElement
= function OoUiMixinPendingElement( config
) {
510 // Configuration initialization
511 config
= config
|| {};
515 this.$pending
= null;
518 this.setPendingElement( config
.$pending
|| this.$element
);
523 OO
.initClass( OO
.ui
.mixin
.PendingElement
);
528 * Set the pending element (and clean up any existing one).
530 * @param {jQuery} $pending The element to set to pending.
532 OO
.ui
.mixin
.PendingElement
.prototype.setPendingElement = function ( $pending
) {
533 if ( this.$pending
) {
534 this.$pending
.removeClass( 'oo-ui-pendingElement-pending' );
537 this.$pending
= $pending
;
538 if ( this.pending
> 0 ) {
539 this.$pending
.addClass( 'oo-ui-pendingElement-pending' );
544 * Check if an element is pending.
546 * @return {boolean} Element is pending
548 OO
.ui
.mixin
.PendingElement
.prototype.isPending = function () {
549 return !!this.pending
;
553 * Increase the pending counter. The pending state will remain active until the counter is zero
554 * (i.e., the number of calls to #pushPending and #popPending is the same).
558 OO
.ui
.mixin
.PendingElement
.prototype.pushPending = function () {
559 if ( this.pending
=== 0 ) {
560 this.$pending
.addClass( 'oo-ui-pendingElement-pending' );
561 this.updateThemeClasses();
569 * Decrease the pending counter. The pending state will remain active until the counter is zero
570 * (i.e., the number of calls to #pushPending and #popPending is the same).
574 OO
.ui
.mixin
.PendingElement
.prototype.popPending = function () {
575 if ( this.pending
=== 1 ) {
576 this.$pending
.removeClass( 'oo-ui-pendingElement-pending' );
577 this.updateThemeClasses();
579 this.pending
= Math
.max( 0, this.pending
- 1 );
585 * ActionSets manage the behavior of the {@link OO.ui.ActionWidget action widgets} that comprise them.
586 * Actions can be made available for specific contexts (modes) and circumstances
587 * (abilities). Action sets are primarily used with {@link OO.ui.Dialog Dialogs}.
589 * ActionSets contain two types of actions:
591 * - 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.
592 * - Other: Other actions include all non-special visible actions.
594 * Please see the [OOjs UI documentation on MediaWiki][1] for more information.
597 * // Example: An action set used in a process dialog
598 * function MyProcessDialog( config ) {
599 * MyProcessDialog.parent.call( this, config );
601 * OO.inheritClass( MyProcessDialog, OO.ui.ProcessDialog );
602 * MyProcessDialog.static.title = 'An action set in a process dialog';
603 * // An action set that uses modes ('edit' and 'help' mode, in this example).
604 * MyProcessDialog.static.actions = [
605 * { action: 'continue', modes: 'edit', label: 'Continue', flags: [ 'primary', 'constructive' ] },
606 * { action: 'help', modes: 'edit', label: 'Help' },
607 * { modes: 'edit', label: 'Cancel', flags: 'safe' },
608 * { action: 'back', modes: 'help', label: 'Back', flags: 'safe' }
611 * MyProcessDialog.prototype.initialize = function () {
612 * MyProcessDialog.parent.prototype.initialize.apply( this, arguments );
613 * this.panel1 = new OO.ui.PanelLayout( { padded: true, expanded: false } );
614 * 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>' );
615 * this.panel2 = new OO.ui.PanelLayout( { padded: true, expanded: false } );
616 * 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>' );
617 * this.stackLayout = new OO.ui.StackLayout( {
618 * items: [ this.panel1, this.panel2 ]
620 * this.$body.append( this.stackLayout.$element );
622 * MyProcessDialog.prototype.getSetupProcess = function ( data ) {
623 * return MyProcessDialog.parent.prototype.getSetupProcess.call( this, data )
624 * .next( function () {
625 * this.actions.setMode( 'edit' );
628 * MyProcessDialog.prototype.getActionProcess = function ( action ) {
629 * if ( action === 'help' ) {
630 * this.actions.setMode( 'help' );
631 * this.stackLayout.setItem( this.panel2 );
632 * } else if ( action === 'back' ) {
633 * this.actions.setMode( 'edit' );
634 * this.stackLayout.setItem( this.panel1 );
635 * } else if ( action === 'continue' ) {
637 * return new OO.ui.Process( function () {
641 * return MyProcessDialog.parent.prototype.getActionProcess.call( this, action );
643 * MyProcessDialog.prototype.getBodyHeight = function () {
644 * return this.panel1.$element.outerHeight( true );
646 * var windowManager = new OO.ui.WindowManager();
647 * $( 'body' ).append( windowManager.$element );
648 * var dialog = new MyProcessDialog( {
651 * windowManager.addWindows( [ dialog ] );
652 * windowManager.openWindow( dialog );
654 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs#Action_sets
658 * @mixins OO.EventEmitter
661 * @param {Object} [config] Configuration options
663 OO
.ui
.ActionSet
= function OoUiActionSet( config
) {
664 // Configuration initialization
665 config
= config
|| {};
667 // Mixin constructors
668 OO
.EventEmitter
.call( this );
673 actions
: 'getAction',
677 this.categorized
= {};
680 this.organized
= false;
681 this.changing
= false;
682 this.changed
= false;
687 OO
.mixinClass( OO
.ui
.ActionSet
, OO
.EventEmitter
);
689 /* Static Properties */
692 * Symbolic name of the flags used to identify special actions. Special actions are displayed in the
693 * header of a {@link OO.ui.ProcessDialog process dialog}.
694 * See the [OOjs UI documentation on MediaWiki][2] for more information and examples.
696 * [2]:https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs
703 OO
.ui
.ActionSet
.static.specialFlags
= [ 'safe', 'primary' ];
710 * A 'click' event is emitted when an action is clicked.
712 * @param {OO.ui.ActionWidget} action Action that was clicked
718 * A 'resize' event is emitted when an action widget is resized.
720 * @param {OO.ui.ActionWidget} action Action that was resized
726 * An 'add' event is emitted when actions are {@link #method-add added} to the action set.
728 * @param {OO.ui.ActionWidget[]} added Actions added
734 * A 'remove' event is emitted when actions are {@link #method-remove removed}
735 * or {@link #clear cleared}.
737 * @param {OO.ui.ActionWidget[]} added Actions removed
743 * A 'change' event is emitted when actions are {@link #method-add added}, {@link #clear cleared},
744 * or {@link #method-remove removed} from the action set or when the {@link #setMode mode} is changed.
751 * Handle action change events.
756 OO
.ui
.ActionSet
.prototype.onActionChange = function () {
757 this.organized
= false;
758 if ( this.changing
) {
761 this.emit( 'change' );
766 * Check if an action is one of the special actions.
768 * @param {OO.ui.ActionWidget} action Action to check
769 * @return {boolean} Action is special
771 OO
.ui
.ActionSet
.prototype.isSpecial = function ( action
) {
774 for ( flag
in this.special
) {
775 if ( action
=== this.special
[ flag
] ) {
784 * Get action widgets based on the specified filter: ‘actions’, ‘flags’, ‘modes’, ‘visible’,
787 * @param {Object} [filters] Filters to use, omit to get all actions
788 * @param {string|string[]} [filters.actions] Actions that action widgets must have
789 * @param {string|string[]} [filters.flags] Flags that action widgets must have (e.g., 'safe')
790 * @param {string|string[]} [filters.modes] Modes that action widgets must have
791 * @param {boolean} [filters.visible] Action widgets must be visible
792 * @param {boolean} [filters.disabled] Action widgets must be disabled
793 * @return {OO.ui.ActionWidget[]} Action widgets matching all criteria
795 OO
.ui
.ActionSet
.prototype.get = function ( filters
) {
796 var i
, len
, list
, category
, actions
, index
, match
, matches
;
801 // Collect category candidates
803 for ( category
in this.categorized
) {
804 list
= filters
[ category
];
806 if ( !Array
.isArray( list
) ) {
809 for ( i
= 0, len
= list
.length
; i
< len
; i
++ ) {
810 actions
= this.categorized
[ category
][ list
[ i
] ];
811 if ( Array
.isArray( actions
) ) {
812 matches
.push
.apply( matches
, actions
);
817 // Remove by boolean filters
818 for ( i
= 0, len
= matches
.length
; i
< len
; i
++ ) {
819 match
= matches
[ i
];
821 ( filters
.visible
!== undefined && match
.isVisible() !== filters
.visible
) ||
822 ( filters
.disabled
!== undefined && match
.isDisabled() !== filters
.disabled
)
824 matches
.splice( i
, 1 );
830 for ( i
= 0, len
= matches
.length
; i
< len
; i
++ ) {
831 match
= matches
[ i
];
832 index
= matches
.lastIndexOf( match
);
833 while ( index
!== i
) {
834 matches
.splice( index
, 1 );
836 index
= matches
.lastIndexOf( match
);
841 return this.list
.slice();
845 * Get 'special' actions.
847 * Special actions are the first visible action widgets with special flags, such as 'safe' and 'primary'.
848 * Special flags can be configured in subclasses by changing the static #specialFlags property.
850 * @return {OO.ui.ActionWidget[]|null} 'Special' action widgets.
852 OO
.ui
.ActionSet
.prototype.getSpecial = function () {
854 return $.extend( {}, this.special
);
858 * Get 'other' actions.
860 * Other actions include all non-special visible action widgets.
862 * @return {OO.ui.ActionWidget[]} 'Other' action widgets
864 OO
.ui
.ActionSet
.prototype.getOthers = function () {
866 return this.others
.slice();
870 * Set the mode (e.g., ‘edit’ or ‘view’). Only {@link OO.ui.ActionWidget#modes actions} configured
871 * to be available in the specified mode will be made visible. All other actions will be hidden.
873 * @param {string} mode The mode. Only actions configured to be available in the specified
874 * mode will be made visible.
879 OO
.ui
.ActionSet
.prototype.setMode = function ( mode
) {
882 this.changing
= true;
883 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
884 action
= this.list
[ i
];
885 action
.toggle( action
.hasMode( mode
) );
888 this.organized
= false;
889 this.changing
= false;
890 this.emit( 'change' );
896 * Set the abilities of the specified actions.
898 * Action widgets that are configured with the specified actions will be enabled
899 * or disabled based on the boolean values specified in the `actions`
902 * @param {Object.<string,boolean>} actions A list keyed by action name with boolean
903 * values that indicate whether or not the action should be enabled.
906 OO
.ui
.ActionSet
.prototype.setAbilities = function ( actions
) {
907 var i
, len
, action
, item
;
909 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
910 item
= this.list
[ i
];
911 action
= item
.getAction();
912 if ( actions
[ action
] !== undefined ) {
913 item
.setDisabled( !actions
[ action
] );
921 * Executes a function once per action.
923 * When making changes to multiple actions, use this method instead of iterating over the actions
924 * manually to defer emitting a #change event until after all actions have been changed.
926 * @param {Object|null} actions Filters to use to determine which actions to iterate over; see #get
927 * @param {Function} callback Callback to run for each action; callback is invoked with three
928 * arguments: the action, the action's index, the list of actions being iterated over
931 OO
.ui
.ActionSet
.prototype.forEach = function ( filter
, callback
) {
932 this.changed
= false;
933 this.changing
= true;
934 this.get( filter
).forEach( callback
);
935 this.changing
= false;
936 if ( this.changed
) {
937 this.emit( 'change' );
944 * Add action widgets to the action set.
946 * @param {OO.ui.ActionWidget[]} actions Action widgets to add
951 OO
.ui
.ActionSet
.prototype.add = function ( actions
) {
954 this.changing
= true;
955 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
956 action
= actions
[ i
];
957 action
.connect( this, {
958 click
: [ 'emit', 'click', action
],
959 resize
: [ 'emit', 'resize', action
],
960 toggle
: [ 'onActionChange' ]
962 this.list
.push( action
);
964 this.organized
= false;
965 this.emit( 'add', actions
);
966 this.changing
= false;
967 this.emit( 'change' );
973 * Remove action widgets from the set.
975 * To remove all actions, you may wish to use the #clear method instead.
977 * @param {OO.ui.ActionWidget[]} actions Action widgets to remove
982 OO
.ui
.ActionSet
.prototype.remove = function ( actions
) {
983 var i
, len
, index
, action
;
985 this.changing
= true;
986 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
987 action
= actions
[ i
];
988 index
= this.list
.indexOf( action
);
989 if ( index
!== -1 ) {
990 action
.disconnect( this );
991 this.list
.splice( index
, 1 );
994 this.organized
= false;
995 this.emit( 'remove', actions
);
996 this.changing
= false;
997 this.emit( 'change' );
1003 * Remove all action widets from the set.
1005 * To remove only specified actions, use the {@link #method-remove remove} method instead.
1011 OO
.ui
.ActionSet
.prototype.clear = function () {
1013 removed
= this.list
.slice();
1015 this.changing
= true;
1016 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
1017 action
= this.list
[ i
];
1018 action
.disconnect( this );
1023 this.organized
= false;
1024 this.emit( 'remove', removed
);
1025 this.changing
= false;
1026 this.emit( 'change' );
1034 * This is called whenever organized information is requested. It will only reorganize the actions
1035 * if something has changed since the last time it ran.
1040 OO
.ui
.ActionSet
.prototype.organize = function () {
1041 var i
, iLen
, j
, jLen
, flag
, action
, category
, list
, item
, special
,
1042 specialFlags
= this.constructor.static.specialFlags
;
1044 if ( !this.organized
) {
1045 this.categorized
= {};
1048 for ( i
= 0, iLen
= this.list
.length
; i
< iLen
; i
++ ) {
1049 action
= this.list
[ i
];
1050 if ( action
.isVisible() ) {
1051 // Populate categories
1052 for ( category
in this.categories
) {
1053 if ( !this.categorized
[ category
] ) {
1054 this.categorized
[ category
] = {};
1056 list
= action
[ this.categories
[ category
] ]();
1057 if ( !Array
.isArray( list
) ) {
1060 for ( j
= 0, jLen
= list
.length
; j
< jLen
; j
++ ) {
1062 if ( !this.categorized
[ category
][ item
] ) {
1063 this.categorized
[ category
][ item
] = [];
1065 this.categorized
[ category
][ item
].push( action
);
1068 // Populate special/others
1070 for ( j
= 0, jLen
= specialFlags
.length
; j
< jLen
; j
++ ) {
1071 flag
= specialFlags
[ j
];
1072 if ( !this.special
[ flag
] && action
.hasFlag( flag
) ) {
1073 this.special
[ flag
] = action
;
1079 this.others
.push( action
);
1083 this.organized
= true;
1090 * Each Element represents a rendering in the DOM—a button or an icon, for example, or anything
1091 * that is visible to a user. Unlike {@link OO.ui.Widget widgets}, plain elements usually do not have events
1092 * connected to them and can't be interacted with.
1098 * @param {Object} [config] Configuration options
1099 * @cfg {string[]} [classes] The names of the CSS classes to apply to the element. CSS styles are added
1100 * to the top level (e.g., the outermost div) of the element. See the [OOjs UI documentation on MediaWiki][2]
1102 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Buttons_and_Switches#cssExample
1103 * @cfg {string} [id] The HTML id attribute used in the rendered tag.
1104 * @cfg {string} [text] Text to insert
1105 * @cfg {Array} [content] An array of content elements to append (after #text).
1106 * Strings will be html-escaped; use an OO.ui.HtmlSnippet to append raw HTML.
1107 * Instances of OO.ui.Element will have their $element appended.
1108 * @cfg {jQuery} [$content] Content elements to append (after #text)
1109 * @cfg {Mixed} [data] Custom data of any type or combination of types (e.g., string, number, array, object).
1110 * Data can also be specified with the #setData method.
1112 OO
.ui
.Element
= function OoUiElement( config
) {
1113 // Configuration initialization
1114 config
= config
|| {};
1118 this.visible
= true;
1119 this.data
= config
.data
;
1120 this.$element
= config
.$element
||
1121 $( document
.createElement( this.getTagName() ) );
1122 this.elementGroup
= null;
1123 this.debouncedUpdateThemeClassesHandler
= OO
.ui
.debounce( this.debouncedUpdateThemeClasses
);
1126 if ( Array
.isArray( config
.classes
) ) {
1127 this.$element
.addClass( config
.classes
.join( ' ' ) );
1130 this.$element
.attr( 'id', config
.id
);
1132 if ( config
.text
) {
1133 this.$element
.text( config
.text
);
1135 if ( config
.content
) {
1136 // The `content` property treats plain strings as text; use an
1137 // HtmlSnippet to append HTML content. `OO.ui.Element`s get their
1138 // appropriate $element appended.
1139 this.$element
.append( config
.content
.map( function ( v
) {
1140 if ( typeof v
=== 'string' ) {
1141 // Escape string so it is properly represented in HTML.
1142 return document
.createTextNode( v
);
1143 } else if ( v
instanceof OO
.ui
.HtmlSnippet
) {
1145 return v
.toString();
1146 } else if ( v
instanceof OO
.ui
.Element
) {
1152 if ( config
.$content
) {
1153 // The `$content` property treats plain strings as HTML.
1154 this.$element
.append( config
.$content
);
1160 OO
.initClass( OO
.ui
.Element
);
1162 /* Static Properties */
1165 * The name of the HTML tag used by the element.
1167 * The static value may be ignored if the #getTagName method is overridden.
1171 * @property {string}
1173 OO
.ui
.Element
.static.tagName
= 'div';
1175 /* Static Methods */
1178 * Reconstitute a JavaScript object corresponding to a widget created
1179 * by the PHP implementation.
1181 * @param {string|HTMLElement|jQuery} idOrNode
1182 * A DOM id (if a string) or node for the widget to infuse.
1183 * @return {OO.ui.Element}
1184 * The `OO.ui.Element` corresponding to this (infusable) document node.
1185 * For `Tag` objects emitted on the HTML side (used occasionally for content)
1186 * the value returned is a newly-created Element wrapping around the existing
1189 OO
.ui
.Element
.static.infuse = function ( idOrNode
) {
1190 var obj
= OO
.ui
.Element
.static.unsafeInfuse( idOrNode
, false );
1191 // Verify that the type matches up.
1192 // FIXME: uncomment after T89721 is fixed (see T90929)
1194 if ( !( obj instanceof this['class'] ) ) {
1195 throw new Error( 'Infusion type mismatch!' );
1202 * Implementation helper for `infuse`; skips the type check and has an
1203 * extra property so that only the top-level invocation touches the DOM.
1205 * @param {string|HTMLElement|jQuery} idOrNode
1206 * @param {jQuery.Promise|boolean} domPromise A promise that will be resolved
1207 * when the top-level widget of this infusion is inserted into DOM,
1208 * replacing the original node; or false for top-level invocation.
1209 * @return {OO.ui.Element}
1211 OO
.ui
.Element
.static.unsafeInfuse = function ( idOrNode
, domPromise
) {
1212 // look for a cached result of a previous infusion.
1213 var id
, $elem
, data
, cls
, parts
, parent
, obj
, top
, state
;
1214 if ( typeof idOrNode
=== 'string' ) {
1216 $elem
= $( document
.getElementById( id
) );
1218 $elem
= $( idOrNode
);
1219 id
= $elem
.attr( 'id' );
1221 if ( !$elem
.length
) {
1222 throw new Error( 'Widget not found: ' + id
);
1224 data
= $elem
.data( 'ooui-infused' ) || $elem
[ 0 ].oouiInfused
;
1227 if ( data
=== true ) {
1228 throw new Error( 'Circular dependency! ' + id
);
1232 data
= $elem
.attr( 'data-ooui' );
1234 throw new Error( 'No infusion data found: ' + id
);
1237 data
= $.parseJSON( data
);
1241 if ( !( data
&& data
._
) ) {
1242 throw new Error( 'No valid infusion data found: ' + id
);
1244 if ( data
._
=== 'Tag' ) {
1245 // Special case: this is a raw Tag; wrap existing node, don't rebuild.
1246 return new OO
.ui
.Element( { $element
: $elem
} );
1248 parts
= data
._
.split( '.' );
1249 cls
= OO
.getProp
.apply( OO
, [ window
].concat( parts
) );
1250 if ( cls
=== undefined ) {
1251 // The PHP output might be old and not including the "OO.ui" prefix
1252 // TODO: Remove this back-compat after next major release
1253 cls
= OO
.getProp
.apply( OO
, [ OO
.ui
].concat( parts
) );
1254 if ( cls
=== undefined ) {
1255 throw new Error( 'Unknown widget type: id: ' + id
+ ', class: ' + data
._
);
1259 // Verify that we're creating an OO.ui.Element instance
1260 parent
= cls
.parent
;
1262 while ( parent
!== undefined ) {
1263 if ( parent
=== OO
.ui
.Element
) {
1268 parent
= parent
.parent
;
1271 if ( parent
!== OO
.ui
.Element
) {
1272 throw new Error( 'Unknown widget type: id: ' + id
+ ', class: ' + data
._
);
1275 if ( domPromise
=== false ) {
1277 domPromise
= top
.promise();
1279 $elem
.data( 'ooui-infused', true ); // prevent loops
1280 data
.id
= id
; // implicit
1281 data
= OO
.copy( data
, null, function deserialize( value
) {
1282 if ( OO
.isPlainObject( value
) ) {
1284 return OO
.ui
.Element
.static.unsafeInfuse( value
.tag
, domPromise
);
1287 return new OO
.ui
.HtmlSnippet( value
.html
);
1291 // jscs:disable requireCapitalizedConstructors
1292 obj
= new cls( data
); // rebuild widget
1293 // pick up dynamic state, like focus, value of form inputs, scroll position, etc.
1294 state
= obj
.gatherPreInfuseState( $elem
);
1295 // now replace old DOM with this new DOM.
1297 $elem
.replaceWith( obj
.$element
);
1298 // This element is now gone from the DOM, but if anyone is holding a reference to it,
1299 // let's allow them to OO.ui.infuse() it and do what they expect (T105828).
1300 // Do not use jQuery.data(), as using it on detached nodes leaks memory in 1.x line by design.
1301 $elem
[ 0 ].oouiInfused
= obj
;
1304 obj
.$element
.data( 'ooui-infused', obj
);
1305 // set the 'data-ooui' attribute so we can identify infused widgets
1306 obj
.$element
.attr( 'data-ooui', '' );
1307 // restore dynamic state after the new element is inserted into DOM
1308 domPromise
.done( obj
.restorePreInfuseState
.bind( obj
, state
) );
1313 * Get a jQuery function within a specific document.
1316 * @param {jQuery|HTMLElement|HTMLDocument|Window} context Context to bind the function to
1317 * @param {jQuery} [$iframe] HTML iframe element that contains the document, omit if document is
1319 * @return {Function} Bound jQuery function
1321 OO
.ui
.Element
.static.getJQuery = function ( context
, $iframe
) {
1322 function wrapper( selector
) {
1323 return $( selector
, wrapper
.context
);
1326 wrapper
.context
= this.getDocument( context
);
1329 wrapper
.$iframe
= $iframe
;
1336 * Get the document of an element.
1339 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Object to get the document for
1340 * @return {HTMLDocument|null} Document object
1342 OO
.ui
.Element
.static.getDocument = function ( obj
) {
1343 // jQuery - selections created "offscreen" won't have a context, so .context isn't reliable
1344 return ( obj
[ 0 ] && obj
[ 0 ].ownerDocument
) ||
1345 // Empty jQuery selections might have a context
1348 obj
.ownerDocument
||
1352 ( obj
.nodeType
=== 9 && obj
) ||
1357 * Get the window of an element or document.
1360 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Context to get the window for
1361 * @return {Window} Window object
1363 OO
.ui
.Element
.static.getWindow = function ( obj
) {
1364 var doc
= this.getDocument( obj
);
1366 // Standard Document.defaultView is IE9+
1367 return doc
.parentWindow
|| doc
.defaultView
;
1371 * Get the direction of an element or document.
1374 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Context to get the direction for
1375 * @return {string} Text direction, either 'ltr' or 'rtl'
1377 OO
.ui
.Element
.static.getDir = function ( obj
) {
1380 if ( obj
instanceof jQuery
) {
1383 isDoc
= obj
.nodeType
=== 9;
1384 isWin
= obj
.document
!== undefined;
1385 if ( isDoc
|| isWin
) {
1391 return $( obj
).css( 'direction' );
1395 * Get the offset between two frames.
1397 * TODO: Make this function not use recursion.
1400 * @param {Window} from Window of the child frame
1401 * @param {Window} [to=window] Window of the parent frame
1402 * @param {Object} [offset] Offset to start with, used internally
1403 * @return {Object} Offset object, containing left and top properties
1405 OO
.ui
.Element
.static.getFrameOffset = function ( from, to
, offset
) {
1406 var i
, len
, frames
, frame
, rect
;
1412 offset
= { top
: 0, left
: 0 };
1414 if ( from.parent
=== from ) {
1418 // Get iframe element
1419 frames
= from.parent
.document
.getElementsByTagName( 'iframe' );
1420 for ( i
= 0, len
= frames
.length
; i
< len
; i
++ ) {
1421 if ( frames
[ i
].contentWindow
=== from ) {
1422 frame
= frames
[ i
];
1427 // Recursively accumulate offset values
1429 rect
= frame
.getBoundingClientRect();
1430 offset
.left
+= rect
.left
;
1431 offset
.top
+= rect
.top
;
1432 if ( from !== to
) {
1433 this.getFrameOffset( from.parent
, offset
);
1440 * Get the offset between two elements.
1442 * The two elements may be in a different frame, but in that case the frame $element is in must
1443 * be contained in the frame $anchor is in.
1446 * @param {jQuery} $element Element whose position to get
1447 * @param {jQuery} $anchor Element to get $element's position relative to
1448 * @return {Object} Translated position coordinates, containing top and left properties
1450 OO
.ui
.Element
.static.getRelativePosition = function ( $element
, $anchor
) {
1451 var iframe
, iframePos
,
1452 pos
= $element
.offset(),
1453 anchorPos
= $anchor
.offset(),
1454 elementDocument
= this.getDocument( $element
),
1455 anchorDocument
= this.getDocument( $anchor
);
1457 // If $element isn't in the same document as $anchor, traverse up
1458 while ( elementDocument
!== anchorDocument
) {
1459 iframe
= elementDocument
.defaultView
.frameElement
;
1461 throw new Error( '$element frame is not contained in $anchor frame' );
1463 iframePos
= $( iframe
).offset();
1464 pos
.left
+= iframePos
.left
;
1465 pos
.top
+= iframePos
.top
;
1466 elementDocument
= iframe
.ownerDocument
;
1468 pos
.left
-= anchorPos
.left
;
1469 pos
.top
-= anchorPos
.top
;
1474 * Get element border sizes.
1477 * @param {HTMLElement} el Element to measure
1478 * @return {Object} Dimensions object with `top`, `left`, `bottom` and `right` properties
1480 OO
.ui
.Element
.static.getBorders = function ( el
) {
1481 var doc
= el
.ownerDocument
,
1483 // Standard Document.defaultView is IE9+
1484 win
= doc
.parentWindow
|| doc
.defaultView
,
1485 style
= win
&& win
.getComputedStyle
?
1486 win
.getComputedStyle( el
, null ) :
1488 // Standard getComputedStyle() is IE9+
1491 top
= parseFloat( style
? style
.borderTopWidth
: $el
.css( 'borderTopWidth' ) ) || 0,
1492 left
= parseFloat( style
? style
.borderLeftWidth
: $el
.css( 'borderLeftWidth' ) ) || 0,
1493 bottom
= parseFloat( style
? style
.borderBottomWidth
: $el
.css( 'borderBottomWidth' ) ) || 0,
1494 right
= parseFloat( style
? style
.borderRightWidth
: $el
.css( 'borderRightWidth' ) ) || 0;
1505 * Get dimensions of an element or window.
1508 * @param {HTMLElement|Window} el Element to measure
1509 * @return {Object} Dimensions object with `borders`, `scroll`, `scrollbar` and `rect` properties
1511 OO
.ui
.Element
.static.getDimensions = function ( el
) {
1513 doc
= el
.ownerDocument
|| el
.document
,
1515 // Standard Document.defaultView is IE9+
1516 win
= doc
.parentWindow
|| doc
.defaultView
;
1518 if ( win
=== el
|| el
=== doc
.documentElement
) {
1521 borders
: { top
: 0, left
: 0, bottom
: 0, right
: 0 },
1523 top
: $win
.scrollTop(),
1524 left
: $win
.scrollLeft()
1526 scrollbar
: { right
: 0, bottom
: 0 },
1530 bottom
: $win
.innerHeight(),
1531 right
: $win
.innerWidth()
1537 borders
: this.getBorders( el
),
1539 top
: $el
.scrollTop(),
1540 left
: $el
.scrollLeft()
1543 right
: $el
.innerWidth() - el
.clientWidth
,
1544 bottom
: $el
.innerHeight() - el
.clientHeight
1546 rect
: el
.getBoundingClientRect()
1552 * Get scrollable object parent
1554 * documentElement can't be used to get or set the scrollTop
1555 * property on Blink. Changing and testing its value lets us
1556 * use 'body' or 'documentElement' based on what is working.
1558 * https://code.google.com/p/chromium/issues/detail?id=303131
1561 * @param {HTMLElement} el Element to find scrollable parent for
1562 * @return {HTMLElement} Scrollable parent
1564 OO
.ui
.Element
.static.getRootScrollableElement = function ( el
) {
1565 var scrollTop
, body
;
1567 if ( OO
.ui
.scrollableElement
=== undefined ) {
1568 body
= el
.ownerDocument
.body
;
1569 scrollTop
= body
.scrollTop
;
1572 if ( body
.scrollTop
=== 1 ) {
1573 body
.scrollTop
= scrollTop
;
1574 OO
.ui
.scrollableElement
= 'body';
1576 OO
.ui
.scrollableElement
= 'documentElement';
1580 return el
.ownerDocument
[ OO
.ui
.scrollableElement
];
1584 * Get closest scrollable container.
1586 * Traverses up until either a scrollable element or the root is reached, in which case the window
1590 * @param {HTMLElement} el Element to find scrollable container for
1591 * @param {string} [dimension] Dimension of scrolling to look for; `x`, `y` or omit for either
1592 * @return {HTMLElement} Closest scrollable container
1594 OO
.ui
.Element
.static.getClosestScrollableContainer = function ( el
, dimension
) {
1596 // props = [ 'overflow' ] doesn't work due to https://bugzilla.mozilla.org/show_bug.cgi?id=889091
1597 props
= [ 'overflow-x', 'overflow-y' ],
1598 $parent
= $( el
).parent();
1600 if ( dimension
=== 'x' || dimension
=== 'y' ) {
1601 props
= [ 'overflow-' + dimension
];
1604 while ( $parent
.length
) {
1605 if ( $parent
[ 0 ] === this.getRootScrollableElement( el
) ) {
1606 return $parent
[ 0 ];
1610 val
= $parent
.css( props
[ i
] );
1611 if ( val
=== 'auto' || val
=== 'scroll' ) {
1612 return $parent
[ 0 ];
1615 $parent
= $parent
.parent();
1617 return this.getDocument( el
).body
;
1621 * Scroll element into view.
1624 * @param {HTMLElement} el Element to scroll into view
1625 * @param {Object} [config] Configuration options
1626 * @param {string} [config.duration] jQuery animation duration value
1627 * @param {string} [config.direction] Scroll in only one direction, e.g. 'x' or 'y', omit
1628 * to scroll in both directions
1629 * @param {Function} [config.complete] Function to call when scrolling completes
1631 OO
.ui
.Element
.static.scrollIntoView = function ( el
, config
) {
1632 var rel
, anim
, callback
, sc
, $sc
, eld
, scd
, $win
;
1634 // Configuration initialization
1635 config
= config
|| {};
1638 callback
= typeof config
.complete
=== 'function' && config
.complete
;
1639 sc
= this.getClosestScrollableContainer( el
, config
.direction
);
1641 eld
= this.getDimensions( el
);
1642 scd
= this.getDimensions( sc
);
1643 $win
= $( this.getWindow( el
) );
1645 // Compute the distances between the edges of el and the edges of the scroll viewport
1646 if ( $sc
.is( 'html, body' ) ) {
1647 // If the scrollable container is the root, this is easy
1650 bottom
: $win
.innerHeight() - eld
.rect
.bottom
,
1651 left
: eld
.rect
.left
,
1652 right
: $win
.innerWidth() - eld
.rect
.right
1655 // Otherwise, we have to subtract el's coordinates from sc's coordinates
1657 top
: eld
.rect
.top
- ( scd
.rect
.top
+ scd
.borders
.top
),
1658 bottom
: scd
.rect
.bottom
- scd
.borders
.bottom
- scd
.scrollbar
.bottom
- eld
.rect
.bottom
,
1659 left
: eld
.rect
.left
- ( scd
.rect
.left
+ scd
.borders
.left
),
1660 right
: scd
.rect
.right
- scd
.borders
.right
- scd
.scrollbar
.right
- eld
.rect
.right
1664 if ( !config
.direction
|| config
.direction
=== 'y' ) {
1665 if ( rel
.top
< 0 ) {
1666 anim
.scrollTop
= scd
.scroll
.top
+ rel
.top
;
1667 } else if ( rel
.top
> 0 && rel
.bottom
< 0 ) {
1668 anim
.scrollTop
= scd
.scroll
.top
+ Math
.min( rel
.top
, -rel
.bottom
);
1671 if ( !config
.direction
|| config
.direction
=== 'x' ) {
1672 if ( rel
.left
< 0 ) {
1673 anim
.scrollLeft
= scd
.scroll
.left
+ rel
.left
;
1674 } else if ( rel
.left
> 0 && rel
.right
< 0 ) {
1675 anim
.scrollLeft
= scd
.scroll
.left
+ Math
.min( rel
.left
, -rel
.right
);
1678 if ( !$.isEmptyObject( anim
) ) {
1679 $sc
.stop( true ).animate( anim
, config
.duration
|| 'fast' );
1681 $sc
.queue( function ( next
) {
1694 * Force the browser to reconsider whether it really needs to render scrollbars inside the element
1695 * and reserve space for them, because it probably doesn't.
1697 * Workaround primarily for <https://code.google.com/p/chromium/issues/detail?id=387290>, but also
1698 * similar bugs in other browsers. "Just" forcing a reflow is not sufficient in all cases, we need
1699 * to first actually detach (or hide, but detaching is simpler) all children, *then* force a reflow,
1700 * and then reattach (or show) them back.
1703 * @param {HTMLElement} el Element to reconsider the scrollbars on
1705 OO
.ui
.Element
.static.reconsiderScrollbars = function ( el
) {
1706 var i
, len
, scrollLeft
, scrollTop
, nodes
= [];
1707 // Save scroll position
1708 scrollLeft
= el
.scrollLeft
;
1709 scrollTop
= el
.scrollTop
;
1710 // Detach all children
1711 while ( el
.firstChild
) {
1712 nodes
.push( el
.firstChild
);
1713 el
.removeChild( el
.firstChild
);
1716 void el
.offsetHeight
;
1717 // Reattach all children
1718 for ( i
= 0, len
= nodes
.length
; i
< len
; i
++ ) {
1719 el
.appendChild( nodes
[ i
] );
1721 // Restore scroll position (no-op if scrollbars disappeared)
1722 el
.scrollLeft
= scrollLeft
;
1723 el
.scrollTop
= scrollTop
;
1729 * Toggle visibility of an element.
1731 * @param {boolean} [show] Make element visible, omit to toggle visibility
1735 OO
.ui
.Element
.prototype.toggle = function ( show
) {
1736 show
= show
=== undefined ? !this.visible
: !!show
;
1738 if ( show
!== this.isVisible() ) {
1739 this.visible
= show
;
1740 this.$element
.toggleClass( 'oo-ui-element-hidden', !this.visible
);
1741 this.emit( 'toggle', show
);
1748 * Check if element is visible.
1750 * @return {boolean} element is visible
1752 OO
.ui
.Element
.prototype.isVisible = function () {
1753 return this.visible
;
1759 * @return {Mixed} Element data
1761 OO
.ui
.Element
.prototype.getData = function () {
1768 * @param {Mixed} Element data
1771 OO
.ui
.Element
.prototype.setData = function ( data
) {
1777 * Check if element supports one or more methods.
1779 * @param {string|string[]} methods Method or list of methods to check
1780 * @return {boolean} All methods are supported
1782 OO
.ui
.Element
.prototype.supports = function ( methods
) {
1786 methods
= Array
.isArray( methods
) ? methods
: [ methods
];
1787 for ( i
= 0, len
= methods
.length
; i
< len
; i
++ ) {
1788 if ( $.isFunction( this[ methods
[ i
] ] ) ) {
1793 return methods
.length
=== support
;
1797 * Update the theme-provided classes.
1799 * @localdoc This is called in element mixins and widget classes any time state changes.
1800 * Updating is debounced, minimizing overhead of changing multiple attributes and
1801 * guaranteeing that theme updates do not occur within an element's constructor
1803 OO
.ui
.Element
.prototype.updateThemeClasses = function () {
1804 this.debouncedUpdateThemeClassesHandler();
1809 * @localdoc This method is called directly from the QUnit tests instead of #updateThemeClasses, to
1810 * make them synchronous.
1812 OO
.ui
.Element
.prototype.debouncedUpdateThemeClasses = function () {
1813 OO
.ui
.theme
.updateElementClasses( this );
1817 * Get the HTML tag name.
1819 * Override this method to base the result on instance information.
1821 * @return {string} HTML tag name
1823 OO
.ui
.Element
.prototype.getTagName = function () {
1824 return this.constructor.static.tagName
;
1828 * Check if the element is attached to the DOM
1829 * @return {boolean} The element is attached to the DOM
1831 OO
.ui
.Element
.prototype.isElementAttached = function () {
1832 return $.contains( this.getElementDocument(), this.$element
[ 0 ] );
1836 * Get the DOM document.
1838 * @return {HTMLDocument} Document object
1840 OO
.ui
.Element
.prototype.getElementDocument = function () {
1841 // Don't cache this in other ways either because subclasses could can change this.$element
1842 return OO
.ui
.Element
.static.getDocument( this.$element
);
1846 * Get the DOM window.
1848 * @return {Window} Window object
1850 OO
.ui
.Element
.prototype.getElementWindow = function () {
1851 return OO
.ui
.Element
.static.getWindow( this.$element
);
1855 * Get closest scrollable container.
1857 OO
.ui
.Element
.prototype.getClosestScrollableElementContainer = function () {
1858 return OO
.ui
.Element
.static.getClosestScrollableContainer( this.$element
[ 0 ] );
1862 * Get group element is in.
1864 * @return {OO.ui.mixin.GroupElement|null} Group element, null if none
1866 OO
.ui
.Element
.prototype.getElementGroup = function () {
1867 return this.elementGroup
;
1871 * Set group element is in.
1873 * @param {OO.ui.mixin.GroupElement|null} group Group element, null if none
1876 OO
.ui
.Element
.prototype.setElementGroup = function ( group
) {
1877 this.elementGroup
= group
;
1882 * Scroll element into view.
1884 * @param {Object} [config] Configuration options
1886 OO
.ui
.Element
.prototype.scrollElementIntoView = function ( config
) {
1887 return OO
.ui
.Element
.static.scrollIntoView( this.$element
[ 0 ], config
);
1891 * Gather the dynamic state (focus, value of form inputs, scroll position, etc.) of a HTML DOM node
1892 * (and its children) that represent an Element of the same type and configuration as the current
1893 * one, generated by the PHP implementation.
1895 * This method is called just before `node` is detached from the DOM. The return value of this
1896 * function will be passed to #restorePreInfuseState after this widget's #$element is inserted into
1897 * DOM to replace `node`.
1900 * @param {HTMLElement} node
1903 OO
.ui
.Element
.prototype.gatherPreInfuseState = function () {
1908 * Restore the pre-infusion dynamic state for this widget.
1910 * This method is called after #$element has been inserted into DOM. The parameter is the return
1911 * value of #gatherPreInfuseState.
1914 * @param {Object} state
1916 OO
.ui
.Element
.prototype.restorePreInfuseState = function () {
1920 * Layouts are containers for elements and are used to arrange other widgets of arbitrary type in a way
1921 * that is centrally controlled and can be updated dynamically. Layouts can be, and usually are, combined.
1922 * See {@link OO.ui.FieldsetLayout FieldsetLayout}, {@link OO.ui.FieldLayout FieldLayout}, {@link OO.ui.FormLayout FormLayout},
1923 * {@link OO.ui.PanelLayout PanelLayout}, {@link OO.ui.StackLayout StackLayout}, {@link OO.ui.PageLayout PageLayout},
1924 * {@link OO.ui.HorizontalLayout HorizontalLayout}, and {@link OO.ui.BookletLayout BookletLayout} for more information and examples.
1928 * @extends OO.ui.Element
1929 * @mixins OO.EventEmitter
1932 * @param {Object} [config] Configuration options
1934 OO
.ui
.Layout
= function OoUiLayout( config
) {
1935 // Configuration initialization
1936 config
= config
|| {};
1938 // Parent constructor
1939 OO
.ui
.Layout
.parent
.call( this, config
);
1941 // Mixin constructors
1942 OO
.EventEmitter
.call( this );
1945 this.$element
.addClass( 'oo-ui-layout' );
1950 OO
.inheritClass( OO
.ui
.Layout
, OO
.ui
.Element
);
1951 OO
.mixinClass( OO
.ui
.Layout
, OO
.EventEmitter
);
1954 * Widgets are compositions of one or more OOjs UI elements that users can both view
1955 * and interact with. All widgets can be configured and modified via a standard API,
1956 * and their state can change dynamically according to a model.
1960 * @extends OO.ui.Element
1961 * @mixins OO.EventEmitter
1964 * @param {Object} [config] Configuration options
1965 * @cfg {boolean} [disabled=false] Disable the widget. Disabled widgets cannot be used and their
1966 * appearance reflects this state.
1968 OO
.ui
.Widget
= function OoUiWidget( config
) {
1969 // Initialize config
1970 config
= $.extend( { disabled
: false }, config
);
1972 // Parent constructor
1973 OO
.ui
.Widget
.parent
.call( this, config
);
1975 // Mixin constructors
1976 OO
.EventEmitter
.call( this );
1979 this.disabled
= null;
1980 this.wasDisabled
= null;
1983 this.$element
.addClass( 'oo-ui-widget' );
1984 this.setDisabled( !!config
.disabled
);
1989 OO
.inheritClass( OO
.ui
.Widget
, OO
.ui
.Element
);
1990 OO
.mixinClass( OO
.ui
.Widget
, OO
.EventEmitter
);
1992 /* Static Properties */
1995 * Whether this widget will behave reasonably when wrapped in a HTML `<label>`. If this is true,
1996 * wrappers such as OO.ui.FieldLayout may use a `<label>` instead of implementing own label click
2001 * @property {boolean}
2003 OO
.ui
.Widget
.static.supportsSimpleLabel
= false;
2010 * A 'disable' event is emitted when the disabled state of the widget changes
2011 * (i.e. on disable **and** enable).
2013 * @param {boolean} disabled Widget is disabled
2019 * A 'toggle' event is emitted when the visibility of the widget changes.
2021 * @param {boolean} visible Widget is visible
2027 * Check if the widget is disabled.
2029 * @return {boolean} Widget is disabled
2031 OO
.ui
.Widget
.prototype.isDisabled = function () {
2032 return this.disabled
;
2036 * Set the 'disabled' state of the widget.
2038 * When a widget is disabled, it cannot be used and its appearance is updated to reflect this state.
2040 * @param {boolean} disabled Disable widget
2043 OO
.ui
.Widget
.prototype.setDisabled = function ( disabled
) {
2046 this.disabled
= !!disabled
;
2047 isDisabled
= this.isDisabled();
2048 if ( isDisabled
!== this.wasDisabled
) {
2049 this.$element
.toggleClass( 'oo-ui-widget-disabled', isDisabled
);
2050 this.$element
.toggleClass( 'oo-ui-widget-enabled', !isDisabled
);
2051 this.$element
.attr( 'aria-disabled', isDisabled
.toString() );
2052 this.emit( 'disable', isDisabled
);
2053 this.updateThemeClasses();
2055 this.wasDisabled
= isDisabled
;
2061 * Update the disabled state, in case of changes in parent widget.
2065 OO
.ui
.Widget
.prototype.updateDisabled = function () {
2066 this.setDisabled( this.disabled
);
2071 * A window is a container for elements that are in a child frame. They are used with
2072 * a window manager (OO.ui.WindowManager), which is used to open and close the window and control
2073 * its presentation. The size of a window is specified using a symbolic name (e.g., ‘small’, ‘medium’,
2074 * ‘large’), which is interpreted by the window manager. If the requested size is not recognized,
2075 * the window manager will choose a sensible fallback.
2077 * The lifecycle of a window has three primary stages (opening, opened, and closing) in which
2078 * different processes are executed:
2080 * **opening**: The opening stage begins when the window manager's {@link OO.ui.WindowManager#openWindow
2081 * openWindow} or the window's {@link #open open} methods are used, and the window manager begins to open
2084 * - {@link #getSetupProcess} method is called and its result executed
2085 * - {@link #getReadyProcess} method is called and its result executed
2087 * **opened**: The window is now open
2089 * **closing**: The closing stage begins when the window manager's
2090 * {@link OO.ui.WindowManager#closeWindow closeWindow}
2091 * or the window's {@link #close} methods are used, and the window manager begins to close the window.
2093 * - {@link #getHoldProcess} method is called and its result executed
2094 * - {@link #getTeardownProcess} method is called and its result executed. The window is now closed
2096 * Each of the window's processes (setup, ready, hold, and teardown) can be extended in subclasses
2097 * by overriding the window's #getSetupProcess, #getReadyProcess, #getHoldProcess and #getTeardownProcess
2098 * methods. Note that each {@link OO.ui.Process process} is executed in series, so asynchronous
2099 * processing can complete. Always assume window processes are executed asynchronously.
2101 * For more information, please see the [OOjs UI documentation on MediaWiki] [1].
2103 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows
2107 * @extends OO.ui.Element
2108 * @mixins OO.EventEmitter
2111 * @param {Object} [config] Configuration options
2112 * @cfg {string} [size] Symbolic name of the dialog size: `small`, `medium`, `large`, `larger` or
2113 * `full`. If omitted, the value of the {@link #static-size static size} property will be used.
2115 OO
.ui
.Window
= function OoUiWindow( config
) {
2116 // Configuration initialization
2117 config
= config
|| {};
2119 // Parent constructor
2120 OO
.ui
.Window
.parent
.call( this, config
);
2122 // Mixin constructors
2123 OO
.EventEmitter
.call( this );
2126 this.manager
= null;
2127 this.size
= config
.size
|| this.constructor.static.size
;
2128 this.$frame
= $( '<div>' );
2129 this.$overlay
= $( '<div>' );
2130 this.$content
= $( '<div>' );
2132 this.$focusTrapBefore
= $( '<div>' ).prop( 'tabIndex', 0 );
2133 this.$focusTrapAfter
= $( '<div>' ).prop( 'tabIndex', 0 );
2134 this.$focusTraps
= this.$focusTrapBefore
.add( this.$focusTrapAfter
);
2137 this.$overlay
.addClass( 'oo-ui-window-overlay' );
2139 .addClass( 'oo-ui-window-content' )
2140 .attr( 'tabindex', 0 );
2142 .addClass( 'oo-ui-window-frame' )
2143 .append( this.$focusTrapBefore
, this.$content
, this.$focusTrapAfter
);
2146 .addClass( 'oo-ui-window' )
2147 .append( this.$frame
, this.$overlay
);
2149 // Initially hidden - using #toggle may cause errors if subclasses override toggle with methods
2150 // that reference properties not initialized at that time of parent class construction
2151 // TODO: Find a better way to handle post-constructor setup
2152 this.visible
= false;
2153 this.$element
.addClass( 'oo-ui-element-hidden' );
2158 OO
.inheritClass( OO
.ui
.Window
, OO
.ui
.Element
);
2159 OO
.mixinClass( OO
.ui
.Window
, OO
.EventEmitter
);
2161 /* Static Properties */
2164 * Symbolic name of the window size: `small`, `medium`, `large`, `larger` or `full`.
2166 * The static size is used if no #size is configured during construction.
2170 * @property {string}
2172 OO
.ui
.Window
.static.size
= 'medium';
2177 * Handle mouse down events.
2180 * @param {jQuery.Event} e Mouse down event
2182 OO
.ui
.Window
.prototype.onMouseDown = function ( e
) {
2183 // Prevent clicking on the click-block from stealing focus
2184 if ( e
.target
=== this.$element
[ 0 ] ) {
2190 * Check if the window has been initialized.
2192 * Initialization occurs when a window is added to a manager.
2194 * @return {boolean} Window has been initialized
2196 OO
.ui
.Window
.prototype.isInitialized = function () {
2197 return !!this.manager
;
2201 * Check if the window is visible.
2203 * @return {boolean} Window is visible
2205 OO
.ui
.Window
.prototype.isVisible = function () {
2206 return this.visible
;
2210 * Check if the window is opening.
2212 * This method is a wrapper around the window manager's {@link OO.ui.WindowManager#isOpening isOpening}
2215 * @return {boolean} Window is opening
2217 OO
.ui
.Window
.prototype.isOpening = function () {
2218 return this.manager
.isOpening( this );
2222 * Check if the window is closing.
2224 * This method is a wrapper around the window manager's {@link OO.ui.WindowManager#isClosing isClosing} method.
2226 * @return {boolean} Window is closing
2228 OO
.ui
.Window
.prototype.isClosing = function () {
2229 return this.manager
.isClosing( this );
2233 * Check if the window is opened.
2235 * This method is a wrapper around the window manager's {@link OO.ui.WindowManager#isOpened isOpened} method.
2237 * @return {boolean} Window is opened
2239 OO
.ui
.Window
.prototype.isOpened = function () {
2240 return this.manager
.isOpened( this );
2244 * Get the window manager.
2246 * All windows must be attached to a window manager, which is used to open
2247 * and close the window and control its presentation.
2249 * @return {OO.ui.WindowManager} Manager of window
2251 OO
.ui
.Window
.prototype.getManager = function () {
2252 return this.manager
;
2256 * Get the symbolic name of the window size (e.g., `small` or `medium`).
2258 * @return {string} Symbolic name of the size: `small`, `medium`, `large`, `larger`, `full`
2260 OO
.ui
.Window
.prototype.getSize = function () {
2261 var viewport
= OO
.ui
.Element
.static.getDimensions( this.getElementWindow() ),
2262 sizes
= this.manager
.constructor.static.sizes
,
2265 if ( !sizes
[ size
] ) {
2266 size
= this.manager
.constructor.static.defaultSize
;
2268 if ( size
!== 'full' && viewport
.rect
.right
- viewport
.rect
.left
< sizes
[ size
].width
) {
2276 * Get the size properties associated with the current window size
2278 * @return {Object} Size properties
2280 OO
.ui
.Window
.prototype.getSizeProperties = function () {
2281 return this.manager
.constructor.static.sizes
[ this.getSize() ];
2285 * Disable transitions on window's frame for the duration of the callback function, then enable them
2289 * @param {Function} callback Function to call while transitions are disabled
2291 OO
.ui
.Window
.prototype.withoutSizeTransitions = function ( callback
) {
2292 // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements.
2293 // Disable transitions first, otherwise we'll get values from when the window was animating.
2295 styleObj
= this.$frame
[ 0 ].style
;
2296 oldTransition
= styleObj
.transition
|| styleObj
.OTransition
|| styleObj
.MsTransition
||
2297 styleObj
.MozTransition
|| styleObj
.WebkitTransition
;
2298 styleObj
.transition
= styleObj
.OTransition
= styleObj
.MsTransition
=
2299 styleObj
.MozTransition
= styleObj
.WebkitTransition
= 'none';
2301 // Force reflow to make sure the style changes done inside callback really are not transitioned
2302 this.$frame
.height();
2303 styleObj
.transition
= styleObj
.OTransition
= styleObj
.MsTransition
=
2304 styleObj
.MozTransition
= styleObj
.WebkitTransition
= oldTransition
;
2308 * Get the height of the full window contents (i.e., the window head, body and foot together).
2310 * What consistitutes the head, body, and foot varies depending on the window type.
2311 * A {@link OO.ui.MessageDialog message dialog} displays a title and message in its body,
2312 * and any actions in the foot. A {@link OO.ui.ProcessDialog process dialog} displays a title
2313 * and special actions in the head, and dialog content in the body.
2315 * To get just the height of the dialog body, use the #getBodyHeight method.
2317 * @return {number} The height of the window contents (the dialog head, body and foot) in pixels
2319 OO
.ui
.Window
.prototype.getContentHeight = function () {
2322 bodyStyleObj
= this.$body
[ 0 ].style
,
2323 frameStyleObj
= this.$frame
[ 0 ].style
;
2325 // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements.
2326 // Disable transitions first, otherwise we'll get values from when the window was animating.
2327 this.withoutSizeTransitions( function () {
2328 var oldHeight
= frameStyleObj
.height
,
2329 oldPosition
= bodyStyleObj
.position
;
2330 frameStyleObj
.height
= '1px';
2331 // Force body to resize to new width
2332 bodyStyleObj
.position
= 'relative';
2333 bodyHeight
= win
.getBodyHeight();
2334 frameStyleObj
.height
= oldHeight
;
2335 bodyStyleObj
.position
= oldPosition
;
2339 // Add buffer for border
2340 ( this.$frame
.outerHeight() - this.$frame
.innerHeight() ) +
2341 // Use combined heights of children
2342 ( this.$head
.outerHeight( true ) + bodyHeight
+ this.$foot
.outerHeight( true ) )
2347 * Get the height of the window body.
2349 * To get the height of the full window contents (the window body, head, and foot together),
2350 * use #getContentHeight.
2352 * When this function is called, the window will temporarily have been resized
2353 * to height=1px, so .scrollHeight measurements can be taken accurately.
2355 * @return {number} Height of the window body in pixels
2357 OO
.ui
.Window
.prototype.getBodyHeight = function () {
2358 return this.$body
[ 0 ].scrollHeight
;
2362 * Get the directionality of the frame (right-to-left or left-to-right).
2364 * @return {string} Directionality: `'ltr'` or `'rtl'`
2366 OO
.ui
.Window
.prototype.getDir = function () {
2367 return OO
.ui
.Element
.static.getDir( this.$content
) || 'ltr';
2371 * Get the 'setup' process.
2373 * The setup process is used to set up a window for use in a particular context,
2374 * based on the `data` argument. This method is called during the opening phase of the window’s
2377 * Override this method to add additional steps to the ‘setup’ process the parent method provides
2378 * using the {@link OO.ui.Process#first first} and {@link OO.ui.Process#next next} methods
2381 * To add window content that persists between openings, you may wish to use the #initialize method
2385 * @param {Object} [data] Window opening data
2386 * @return {OO.ui.Process} Setup process
2388 OO
.ui
.Window
.prototype.getSetupProcess = function () {
2389 return new OO
.ui
.Process();
2393 * Get the ‘ready’ process.
2395 * The ready process is used to ready a window for use in a particular
2396 * context, based on the `data` argument. This method is called during the opening phase of
2397 * the window’s lifecycle, after the window has been {@link #getSetupProcess setup}.
2399 * Override this method to add additional steps to the ‘ready’ process the parent method
2400 * provides using the {@link OO.ui.Process#first first} and {@link OO.ui.Process#next next}
2401 * methods of OO.ui.Process.
2404 * @param {Object} [data] Window opening data
2405 * @return {OO.ui.Process} Ready process
2407 OO
.ui
.Window
.prototype.getReadyProcess = function () {
2408 return new OO
.ui
.Process();
2412 * Get the 'hold' process.
2414 * The hold proccess is used to keep a window from being used in a particular context,
2415 * based on the `data` argument. This method is called during the closing phase of the window’s
2418 * Override this method to add additional steps to the 'hold' process the parent method provides
2419 * using the {@link OO.ui.Process#first first} and {@link OO.ui.Process#next next} methods
2423 * @param {Object} [data] Window closing data
2424 * @return {OO.ui.Process} Hold process
2426 OO
.ui
.Window
.prototype.getHoldProcess = function () {
2427 return new OO
.ui
.Process();
2431 * Get the ‘teardown’ process.
2433 * The teardown process is used to teardown a window after use. During teardown,
2434 * user interactions within the window are conveyed and the window is closed, based on the `data`
2435 * argument. This method is called during the closing phase of the window’s lifecycle.
2437 * Override this method to add additional steps to the ‘teardown’ process the parent method provides
2438 * using the {@link OO.ui.Process#first first} and {@link OO.ui.Process#next next} methods
2442 * @param {Object} [data] Window closing data
2443 * @return {OO.ui.Process} Teardown process
2445 OO
.ui
.Window
.prototype.getTeardownProcess = function () {
2446 return new OO
.ui
.Process();
2450 * Set the window manager.
2452 * This will cause the window to initialize. Calling it more than once will cause an error.
2454 * @param {OO.ui.WindowManager} manager Manager for this window
2455 * @throws {Error} An error is thrown if the method is called more than once
2458 OO
.ui
.Window
.prototype.setManager = function ( manager
) {
2459 if ( this.manager
) {
2460 throw new Error( 'Cannot set window manager, window already has a manager' );
2463 this.manager
= manager
;
2470 * Set the window size by symbolic name (e.g., 'small' or 'medium')
2472 * @param {string} size Symbolic name of size: `small`, `medium`, `large`, `larger` or
2476 OO
.ui
.Window
.prototype.setSize = function ( size
) {
2483 * Update the window size.
2485 * @throws {Error} An error is thrown if the window is not attached to a window manager
2488 OO
.ui
.Window
.prototype.updateSize = function () {
2489 if ( !this.manager
) {
2490 throw new Error( 'Cannot update window size, must be attached to a manager' );
2493 this.manager
.updateWindowSize( this );
2499 * Set window dimensions. This method is called by the {@link OO.ui.WindowManager window manager}
2500 * when the window is opening. In general, setDimensions should not be called directly.
2502 * To set the size of the window, use the #setSize method.
2504 * @param {Object} dim CSS dimension properties
2505 * @param {string|number} [dim.width] Width
2506 * @param {string|number} [dim.minWidth] Minimum width
2507 * @param {string|number} [dim.maxWidth] Maximum width
2508 * @param {string|number} [dim.width] Height, omit to set based on height of contents
2509 * @param {string|number} [dim.minWidth] Minimum height
2510 * @param {string|number} [dim.maxWidth] Maximum height
2513 OO
.ui
.Window
.prototype.setDimensions = function ( dim
) {
2516 styleObj
= this.$frame
[ 0 ].style
;
2518 // Calculate the height we need to set using the correct width
2519 if ( dim
.height
=== undefined ) {
2520 this.withoutSizeTransitions( function () {
2521 var oldWidth
= styleObj
.width
;
2522 win
.$frame
.css( 'width', dim
.width
|| '' );
2523 height
= win
.getContentHeight();
2524 styleObj
.width
= oldWidth
;
2527 height
= dim
.height
;
2531 width
: dim
.width
|| '',
2532 minWidth
: dim
.minWidth
|| '',
2533 maxWidth
: dim
.maxWidth
|| '',
2534 height
: height
|| '',
2535 minHeight
: dim
.minHeight
|| '',
2536 maxHeight
: dim
.maxHeight
|| ''
2543 * Initialize window contents.
2545 * Before the window is opened for the first time, #initialize is called so that content that
2546 * persists between openings can be added to the window.
2548 * To set up a window with new content each time the window opens, use #getSetupProcess.
2550 * @throws {Error} An error is thrown if the window is not attached to a window manager
2553 OO
.ui
.Window
.prototype.initialize = function () {
2554 if ( !this.manager
) {
2555 throw new Error( 'Cannot initialize window, must be attached to a manager' );
2559 this.$head
= $( '<div>' );
2560 this.$body
= $( '<div>' );
2561 this.$foot
= $( '<div>' );
2562 this.$document
= $( this.getElementDocument() );
2565 this.$element
.on( 'mousedown', this.onMouseDown
.bind( this ) );
2568 this.$head
.addClass( 'oo-ui-window-head' );
2569 this.$body
.addClass( 'oo-ui-window-body' );
2570 this.$foot
.addClass( 'oo-ui-window-foot' );
2571 this.$content
.append( this.$head
, this.$body
, this.$foot
);
2577 * Called when someone tries to focus the hidden element at the end of the dialog.
2578 * Sends focus back to the start of the dialog.
2580 * @param {jQuery.Event} event Focus event
2582 OO
.ui
.Window
.prototype.onFocusTrapFocused = function ( event
) {
2583 if ( this.$focusTrapBefore
.is( event
.target
) ) {
2584 OO
.ui
.findFocusable( this.$content
, true ).focus();
2586 // this.$content is the part of the focus cycle, and is the first focusable element
2587 this.$content
.focus();
2594 * This method is a wrapper around a call to the window manager’s {@link OO.ui.WindowManager#openWindow openWindow}
2595 * method, which returns a promise resolved when the window is done opening.
2597 * To customize the window each time it opens, use #getSetupProcess or #getReadyProcess.
2599 * @param {Object} [data] Window opening data
2600 * @return {jQuery.Promise} Promise resolved with a value when the window is opened, or rejected
2601 * if the window fails to open. When the promise is resolved successfully, the first argument of the
2602 * value is a new promise, which is resolved when the window begins closing.
2603 * @throws {Error} An error is thrown if the window is not attached to a window manager
2605 OO
.ui
.Window
.prototype.open = function ( data
) {
2606 if ( !this.manager
) {
2607 throw new Error( 'Cannot open window, must be attached to a manager' );
2610 return this.manager
.openWindow( this, data
);
2616 * This method is a wrapper around a call to the window
2617 * manager’s {@link OO.ui.WindowManager#closeWindow closeWindow} method,
2618 * which returns a closing promise resolved when the window is done closing.
2620 * The window's #getHoldProcess and #getTeardownProcess methods are called during the closing
2621 * phase of the window’s lifecycle and can be used to specify closing behavior each time
2622 * the window closes.
2624 * @param {Object} [data] Window closing data
2625 * @return {jQuery.Promise} Promise resolved when window is closed
2626 * @throws {Error} An error is thrown if the window is not attached to a window manager
2628 OO
.ui
.Window
.prototype.close = function ( data
) {
2629 if ( !this.manager
) {
2630 throw new Error( 'Cannot close window, must be attached to a manager' );
2633 return this.manager
.closeWindow( this, data
);
2639 * This is called by OO.ui.WindowManager during window opening, and should not be called directly
2642 * @param {Object} [data] Window opening data
2643 * @return {jQuery.Promise} Promise resolved when window is setup
2645 OO
.ui
.Window
.prototype.setup = function ( data
) {
2647 deferred
= $.Deferred();
2649 this.toggle( true );
2651 this.focusTrapHandler
= OO
.ui
.bind( this.onFocusTrapFocused
, this );
2652 this.$focusTraps
.on( 'focus', this.focusTrapHandler
);
2654 this.getSetupProcess( data
).execute().done( function () {
2655 // Force redraw by asking the browser to measure the elements' widths
2656 win
.$element
.addClass( 'oo-ui-window-active oo-ui-window-setup' ).width();
2657 win
.$content
.addClass( 'oo-ui-window-content-setup' ).width();
2661 return deferred
.promise();
2667 * This is called by OO.ui.WindowManager during window opening, and should not be called directly
2670 * @param {Object} [data] Window opening data
2671 * @return {jQuery.Promise} Promise resolved when window is ready
2673 OO
.ui
.Window
.prototype.ready = function ( data
) {
2675 deferred
= $.Deferred();
2677 this.$content
.focus();
2678 this.getReadyProcess( data
).execute().done( function () {
2679 // Force redraw by asking the browser to measure the elements' widths
2680 win
.$element
.addClass( 'oo-ui-window-ready' ).width();
2681 win
.$content
.addClass( 'oo-ui-window-content-ready' ).width();
2685 return deferred
.promise();
2691 * This is called by OO.ui.WindowManager during window closing, and should not be called directly
2694 * @param {Object} [data] Window closing data
2695 * @return {jQuery.Promise} Promise resolved when window is held
2697 OO
.ui
.Window
.prototype.hold = function ( data
) {
2699 deferred
= $.Deferred();
2701 this.getHoldProcess( data
).execute().done( function () {
2702 // Get the focused element within the window's content
2703 var $focus
= win
.$content
.find( OO
.ui
.Element
.static.getDocument( win
.$content
).activeElement
);
2705 // Blur the focused element
2706 if ( $focus
.length
) {
2710 // Force redraw by asking the browser to measure the elements' widths
2711 win
.$element
.removeClass( 'oo-ui-window-ready' ).width();
2712 win
.$content
.removeClass( 'oo-ui-window-content-ready' ).width();
2716 return deferred
.promise();
2722 * This is called by OO.ui.WindowManager during window closing, and should not be called directly
2725 * @param {Object} [data] Window closing data
2726 * @return {jQuery.Promise} Promise resolved when window is torn down
2728 OO
.ui
.Window
.prototype.teardown = function ( data
) {
2731 return this.getTeardownProcess( data
).execute()
2732 .done( function () {
2733 // Force redraw by asking the browser to measure the elements' widths
2734 win
.$element
.removeClass( 'oo-ui-window-active oo-ui-window-setup' ).width();
2735 win
.$content
.removeClass( 'oo-ui-window-content-setup' ).width();
2736 win
.$focusTraps
.off( 'focus', win
.focusTrapHandler
);
2737 win
.toggle( false );
2742 * The Dialog class serves as the base class for the other types of dialogs.
2743 * Unless extended to include controls, the rendered dialog box is a simple window
2744 * that users can close by hitting the ‘Esc’ key. Dialog windows are used with OO.ui.WindowManager,
2745 * which opens, closes, and controls the presentation of the window. See the
2746 * [OOjs UI documentation on MediaWiki] [1] for more information.
2749 * // A simple dialog window.
2750 * function MyDialog( config ) {
2751 * MyDialog.parent.call( this, config );
2753 * OO.inheritClass( MyDialog, OO.ui.Dialog );
2754 * MyDialog.prototype.initialize = function () {
2755 * MyDialog.parent.prototype.initialize.call( this );
2756 * this.content = new OO.ui.PanelLayout( { padded: true, expanded: false } );
2757 * this.content.$element.append( '<p>A simple dialog window. Press \'Esc\' to close.</p>' );
2758 * this.$body.append( this.content.$element );
2760 * MyDialog.prototype.getBodyHeight = function () {
2761 * return this.content.$element.outerHeight( true );
2763 * var myDialog = new MyDialog( {
2766 * // Create and append a window manager, which opens and closes the window.
2767 * var windowManager = new OO.ui.WindowManager();
2768 * $( 'body' ).append( windowManager.$element );
2769 * windowManager.addWindows( [ myDialog ] );
2770 * // Open the window!
2771 * windowManager.openWindow( myDialog );
2773 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Dialogs
2777 * @extends OO.ui.Window
2778 * @mixins OO.ui.mixin.PendingElement
2781 * @param {Object} [config] Configuration options
2783 OO
.ui
.Dialog
= function OoUiDialog( config
) {
2784 // Parent constructor
2785 OO
.ui
.Dialog
.parent
.call( this, config
);
2787 // Mixin constructors
2788 OO
.ui
.mixin
.PendingElement
.call( this );
2791 this.actions
= new OO
.ui
.ActionSet();
2792 this.attachedActions
= [];
2793 this.currentAction
= null;
2794 this.onDialogKeyDownHandler
= this.onDialogKeyDown
.bind( this );
2797 this.actions
.connect( this, {
2798 click
: 'onActionClick',
2799 resize
: 'onActionResize',
2800 change
: 'onActionsChange'
2805 .addClass( 'oo-ui-dialog' )
2806 .attr( 'role', 'dialog' );
2811 OO
.inheritClass( OO
.ui
.Dialog
, OO
.ui
.Window
);
2812 OO
.mixinClass( OO
.ui
.Dialog
, OO
.ui
.mixin
.PendingElement
);
2814 /* Static Properties */
2817 * Symbolic name of dialog.
2819 * The dialog class must have a symbolic name in order to be registered with OO.Factory.
2820 * Please see the [OOjs UI documentation on MediaWiki] [3] for more information.
2822 * [3]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Window_managers
2827 * @property {string}
2829 OO
.ui
.Dialog
.static.name
= '';
2834 * The title can be specified as a plaintext string, a {@link OO.ui.mixin.LabelElement Label} node, or a function
2835 * that will produce a Label node or string. The title can also be specified with data passed to the
2836 * constructor (see #getSetupProcess). In this case, the static value will be overriden.
2841 * @property {jQuery|string|Function}
2843 OO
.ui
.Dialog
.static.title
= '';
2846 * An array of configured {@link OO.ui.ActionWidget action widgets}.
2848 * Actions can also be specified with data passed to the constructor (see #getSetupProcess). In this case, the static
2849 * value will be overriden.
2851 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs#Action_sets
2855 * @property {Object[]}
2857 OO
.ui
.Dialog
.static.actions
= [];
2860 * Close the dialog when the 'Esc' key is pressed.
2865 * @property {boolean}
2867 OO
.ui
.Dialog
.static.escapable
= true;
2872 * Handle frame document key down events.
2875 * @param {jQuery.Event} e Key down event
2877 OO
.ui
.Dialog
.prototype.onDialogKeyDown = function ( e
) {
2878 if ( e
.which
=== OO
.ui
.Keys
.ESCAPE
) {
2881 e
.stopPropagation();
2886 * Handle action resized events.
2889 * @param {OO.ui.ActionWidget} action Action that was resized
2891 OO
.ui
.Dialog
.prototype.onActionResize = function () {
2892 // Override in subclass
2896 * Handle action click events.
2899 * @param {OO.ui.ActionWidget} action Action that was clicked
2901 OO
.ui
.Dialog
.prototype.onActionClick = function ( action
) {
2902 if ( !this.isPending() ) {
2903 this.executeAction( action
.getAction() );
2908 * Handle actions change event.
2912 OO
.ui
.Dialog
.prototype.onActionsChange = function () {
2913 this.detachActions();
2914 if ( !this.isClosing() ) {
2915 this.attachActions();
2920 * Get the set of actions used by the dialog.
2922 * @return {OO.ui.ActionSet}
2924 OO
.ui
.Dialog
.prototype.getActions = function () {
2925 return this.actions
;
2929 * Get a process for taking action.
2931 * When you override this method, you can create a new OO.ui.Process and return it, or add additional
2932 * accept steps to the process the parent method provides using the {@link OO.ui.Process#first 'first'}
2933 * and {@link OO.ui.Process#next 'next'} methods of OO.ui.Process.
2936 * @param {string} [action] Symbolic name of action
2937 * @return {OO.ui.Process} Action process
2939 OO
.ui
.Dialog
.prototype.getActionProcess = function ( action
) {
2940 return new OO
.ui
.Process()
2941 .next( function () {
2943 // An empty action always closes the dialog without data, which should always be
2944 // safe and make no changes
2953 * @param {Object} [data] Dialog opening data
2954 * @param {jQuery|string|Function|null} [data.title] Dialog title, omit to use
2955 * the {@link #static-title static title}
2956 * @param {Object[]} [data.actions] List of configuration options for each
2957 * {@link OO.ui.ActionWidget action widget}, omit to use {@link #static-actions static actions}.
2959 OO
.ui
.Dialog
.prototype.getSetupProcess = function ( data
) {
2963 return OO
.ui
.Dialog
.parent
.prototype.getSetupProcess
.call( this, data
)
2964 .next( function () {
2965 var config
= this.constructor.static,
2966 actions
= data
.actions
!== undefined ? data
.actions
: config
.actions
;
2968 this.title
.setLabel(
2969 data
.title
!== undefined ? data
.title
: this.constructor.static.title
2971 this.actions
.add( this.getActionWidgets( actions
) );
2973 if ( this.constructor.static.escapable
) {
2974 this.$element
.on( 'keydown', this.onDialogKeyDownHandler
);
2982 OO
.ui
.Dialog
.prototype.getTeardownProcess = function ( data
) {
2984 return OO
.ui
.Dialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
2985 .first( function () {
2986 if ( this.constructor.static.escapable
) {
2987 this.$element
.off( 'keydown', this.onDialogKeyDownHandler
);
2990 this.actions
.clear();
2991 this.currentAction
= null;
2998 OO
.ui
.Dialog
.prototype.initialize = function () {
3002 OO
.ui
.Dialog
.parent
.prototype.initialize
.call( this );
3004 titleId
= OO
.ui
.generateElementId();
3007 this.title
= new OO
.ui
.LabelWidget( {
3012 this.$content
.addClass( 'oo-ui-dialog-content' );
3013 this.$element
.attr( 'aria-labelledby', titleId
);
3014 this.setPendingElement( this.$head
);
3018 * Get action widgets from a list of configs
3020 * @param {Object[]} actions Action widget configs
3021 * @return {OO.ui.ActionWidget[]} Action widgets
3023 OO
.ui
.Dialog
.prototype.getActionWidgets = function ( actions
) {
3024 var i
, len
, widgets
= [];
3025 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
3027 new OO
.ui
.ActionWidget( actions
[ i
] )
3034 * Attach action actions.
3038 OO
.ui
.Dialog
.prototype.attachActions = function () {
3039 // Remember the list of potentially attached actions
3040 this.attachedActions
= this.actions
.get();
3044 * Detach action actions.
3049 OO
.ui
.Dialog
.prototype.detachActions = function () {
3052 // Detach all actions that may have been previously attached
3053 for ( i
= 0, len
= this.attachedActions
.length
; i
< len
; i
++ ) {
3054 this.attachedActions
[ i
].$element
.detach();
3056 this.attachedActions
= [];
3060 * Execute an action.
3062 * @param {string} action Symbolic name of action to execute
3063 * @return {jQuery.Promise} Promise resolved when action completes, rejected if it fails
3065 OO
.ui
.Dialog
.prototype.executeAction = function ( action
) {
3067 this.currentAction
= action
;
3068 return this.getActionProcess( action
).execute()
3069 .always( this.popPending
.bind( this ) );
3073 * Window managers are used to open and close {@link OO.ui.Window windows} and control their presentation.
3074 * Managed windows are mutually exclusive. If a new window is opened while a current window is opening
3075 * or is opened, the current window will be closed and any ongoing {@link OO.ui.Process process} will be cancelled. Windows
3076 * themselves are persistent and—rather than being torn down when closed—can be repopulated with the
3077 * pertinent data and reused.
3079 * Over the lifecycle of a window, the window manager makes available three promises: `opening`,
3080 * `opened`, and `closing`, which represent the primary stages of the cycle:
3082 * **Opening**: the opening stage begins when the window manager’s #openWindow or a window’s
3083 * {@link OO.ui.Window#open open} method is used, and the window manager begins to open the window.
3085 * - an `opening` event is emitted with an `opening` promise
3086 * - the #getSetupDelay method is called and the returned value is used to time a pause in execution before
3087 * the window’s {@link OO.ui.Window#getSetupProcess getSetupProcess} method is called on the
3088 * window and its result executed
3089 * - a `setup` progress notification is emitted from the `opening` promise
3090 * - the #getReadyDelay method is called the returned value is used to time a pause in execution before
3091 * the window’s {@link OO.ui.Window#getReadyProcess getReadyProcess} method is called on the
3092 * window and its result executed
3093 * - a `ready` progress notification is emitted from the `opening` promise
3094 * - the `opening` promise is resolved with an `opened` promise
3096 * **Opened**: the window is now open.
3098 * **Closing**: the closing stage begins when the window manager's #closeWindow or the
3099 * window's {@link OO.ui.Window#close close} methods is used, and the window manager begins
3100 * to close the window.
3102 * - the `opened` promise is resolved with `closing` promise and a `closing` event is emitted
3103 * - the #getHoldDelay method is called and the returned value is used to time a pause in execution before
3104 * the window's {@link OO.ui.Window#getHoldProcess getHoldProces} method is called on the
3105 * window and its result executed
3106 * - a `hold` progress notification is emitted from the `closing` promise
3107 * - the #getTeardownDelay() method is called and the returned value is used to time a pause in execution before
3108 * the window's {@link OO.ui.Window#getTeardownProcess getTeardownProcess} method is called on the
3109 * window and its result executed
3110 * - a `teardown` progress notification is emitted from the `closing` promise
3111 * - the `closing` promise is resolved. The window is now closed
3113 * See the [OOjs UI documentation on MediaWiki][1] for more information.
3115 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Window_managers
3118 * @extends OO.ui.Element
3119 * @mixins OO.EventEmitter
3122 * @param {Object} [config] Configuration options
3123 * @cfg {OO.Factory} [factory] Window factory to use for automatic instantiation
3124 * Note that window classes that are instantiated with a factory must have
3125 * a {@link OO.ui.Dialog#static-name static name} property that specifies a symbolic name.
3126 * @cfg {boolean} [modal=true] Prevent interaction outside the dialog
3128 OO
.ui
.WindowManager
= function OoUiWindowManager( config
) {
3129 // Configuration initialization
3130 config
= config
|| {};
3132 // Parent constructor
3133 OO
.ui
.WindowManager
.parent
.call( this, config
);
3135 // Mixin constructors
3136 OO
.EventEmitter
.call( this );
3139 this.factory
= config
.factory
;
3140 this.modal
= config
.modal
=== undefined || !!config
.modal
;
3142 this.opening
= null;
3144 this.closing
= null;
3145 this.preparingToOpen
= null;
3146 this.preparingToClose
= null;
3147 this.currentWindow
= null;
3148 this.globalEvents
= false;
3149 this.$ariaHidden
= null;
3150 this.onWindowResizeTimeout
= null;
3151 this.onWindowResizeHandler
= this.onWindowResize
.bind( this );
3152 this.afterWindowResizeHandler
= this.afterWindowResize
.bind( this );
3156 .addClass( 'oo-ui-windowManager' )
3157 .toggleClass( 'oo-ui-windowManager-modal', this.modal
);
3162 OO
.inheritClass( OO
.ui
.WindowManager
, OO
.ui
.Element
);
3163 OO
.mixinClass( OO
.ui
.WindowManager
, OO
.EventEmitter
);
3168 * An 'opening' event is emitted when the window begins to be opened.
3171 * @param {OO.ui.Window} win Window that's being opened
3172 * @param {jQuery.Promise} opening An `opening` promise resolved with a value when the window is opened successfully.
3173 * When the `opening` promise is resolved, the first argument of the value is an 'opened' promise, the second argument
3174 * is the opening data. The `opening` promise emits `setup` and `ready` notifications when those processes are complete.
3175 * @param {Object} data Window opening data
3179 * A 'closing' event is emitted when the window begins to be closed.
3182 * @param {OO.ui.Window} win Window that's being closed
3183 * @param {jQuery.Promise} closing A `closing` promise is resolved with a value when the window
3184 * is closed successfully. The promise emits `hold` and `teardown` notifications when those
3185 * processes are complete. When the `closing` promise is resolved, the first argument of its value
3186 * is the closing data.
3187 * @param {Object} data Window closing data
3191 * A 'resize' event is emitted when a window is resized.
3194 * @param {OO.ui.Window} win Window that was resized
3197 /* Static Properties */
3200 * Map of the symbolic name of each window size and its CSS properties.
3204 * @property {Object}
3206 OO
.ui
.WindowManager
.static.sizes
= {
3220 // These can be non-numeric because they are never used in calculations
3227 * Symbolic name of the default window size.
3229 * The default size is used if the window's requested size is not recognized.
3233 * @property {string}
3235 OO
.ui
.WindowManager
.static.defaultSize
= 'medium';
3240 * Handle window resize events.
3243 * @param {jQuery.Event} e Window resize event
3245 OO
.ui
.WindowManager
.prototype.onWindowResize = function () {
3246 clearTimeout( this.onWindowResizeTimeout
);
3247 this.onWindowResizeTimeout
= setTimeout( this.afterWindowResizeHandler
, 200 );
3251 * Handle window resize events.
3254 * @param {jQuery.Event} e Window resize event
3256 OO
.ui
.WindowManager
.prototype.afterWindowResize = function () {
3257 if ( this.currentWindow
) {
3258 this.updateWindowSize( this.currentWindow
);
3263 * Check if window is opening.
3265 * @return {boolean} Window is opening
3267 OO
.ui
.WindowManager
.prototype.isOpening = function ( win
) {
3268 return win
=== this.currentWindow
&& !!this.opening
&& this.opening
.state() === 'pending';
3272 * Check if window is closing.
3274 * @return {boolean} Window is closing
3276 OO
.ui
.WindowManager
.prototype.isClosing = function ( win
) {
3277 return win
=== this.currentWindow
&& !!this.closing
&& this.closing
.state() === 'pending';
3281 * Check if window is opened.
3283 * @return {boolean} Window is opened
3285 OO
.ui
.WindowManager
.prototype.isOpened = function ( win
) {
3286 return win
=== this.currentWindow
&& !!this.opened
&& this.opened
.state() === 'pending';
3290 * Check if a window is being managed.
3292 * @param {OO.ui.Window} win Window to check
3293 * @return {boolean} Window is being managed
3295 OO
.ui
.WindowManager
.prototype.hasWindow = function ( win
) {
3298 for ( name
in this.windows
) {
3299 if ( this.windows
[ name
] === win
) {
3308 * Get the number of milliseconds to wait after opening begins before executing the ‘setup’ process.
3310 * @param {OO.ui.Window} win Window being opened
3311 * @param {Object} [data] Window opening data
3312 * @return {number} Milliseconds to wait
3314 OO
.ui
.WindowManager
.prototype.getSetupDelay = function () {
3319 * Get the number of milliseconds to wait after setup has finished before executing the ‘ready’ process.
3321 * @param {OO.ui.Window} win Window being opened
3322 * @param {Object} [data] Window opening data
3323 * @return {number} Milliseconds to wait
3325 OO
.ui
.WindowManager
.prototype.getReadyDelay = function () {
3330 * Get the number of milliseconds to wait after closing has begun before executing the 'hold' process.
3332 * @param {OO.ui.Window} win Window being closed
3333 * @param {Object} [data] Window closing data
3334 * @return {number} Milliseconds to wait
3336 OO
.ui
.WindowManager
.prototype.getHoldDelay = function () {
3341 * Get the number of milliseconds to wait after the ‘hold’ process has finished before
3342 * executing the ‘teardown’ process.
3344 * @param {OO.ui.Window} win Window being closed
3345 * @param {Object} [data] Window closing data
3346 * @return {number} Milliseconds to wait
3348 OO
.ui
.WindowManager
.prototype.getTeardownDelay = function () {
3349 return this.modal
? 250 : 0;
3353 * Get a window by its symbolic name.
3355 * If the window is not yet instantiated and its symbolic name is recognized by a factory, it will be
3356 * instantiated and added to the window manager automatically. Please see the [OOjs UI documentation on MediaWiki][3]
3357 * for more information about using factories.
3358 * [3]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Window_managers
3360 * @param {string} name Symbolic name of the window
3361 * @return {jQuery.Promise} Promise resolved with matching window, or rejected with an OO.ui.Error
3362 * @throws {Error} An error is thrown if the symbolic name is not recognized by the factory.
3363 * @throws {Error} An error is thrown if the named window is not recognized as a managed window.
3365 OO
.ui
.WindowManager
.prototype.getWindow = function ( name
) {
3366 var deferred
= $.Deferred(),
3367 win
= this.windows
[ name
];
3369 if ( !( win
instanceof OO
.ui
.Window
) ) {
3370 if ( this.factory
) {
3371 if ( !this.factory
.lookup( name
) ) {
3372 deferred
.reject( new OO
.ui
.Error(
3373 'Cannot auto-instantiate window: symbolic name is unrecognized by the factory'
3376 win
= this.factory
.create( name
);
3377 this.addWindows( [ win
] );
3378 deferred
.resolve( win
);
3381 deferred
.reject( new OO
.ui
.Error(
3382 'Cannot get unmanaged window: symbolic name unrecognized as a managed window'
3386 deferred
.resolve( win
);
3389 return deferred
.promise();
3393 * Get current window.
3395 * @return {OO.ui.Window|null} Currently opening/opened/closing window
3397 OO
.ui
.WindowManager
.prototype.getCurrentWindow = function () {
3398 return this.currentWindow
;
3404 * @param {OO.ui.Window|string} win Window object or symbolic name of window to open
3405 * @param {Object} [data] Window opening data
3406 * @return {jQuery.Promise} An `opening` promise resolved when the window is done opening.
3407 * See {@link #event-opening 'opening' event} for more information about `opening` promises.
3410 OO
.ui
.WindowManager
.prototype.openWindow = function ( win
, data
) {
3412 opening
= $.Deferred();
3414 // Argument handling
3415 if ( typeof win
=== 'string' ) {
3416 return this.getWindow( win
).then( function ( win
) {
3417 return manager
.openWindow( win
, data
);
3422 if ( !this.hasWindow( win
) ) {
3423 opening
.reject( new OO
.ui
.Error(
3424 'Cannot open window: window is not attached to manager'
3426 } else if ( this.preparingToOpen
|| this.opening
|| this.opened
) {
3427 opening
.reject( new OO
.ui
.Error(
3428 'Cannot open window: another window is opening or open'
3433 if ( opening
.state() !== 'rejected' ) {
3434 // If a window is currently closing, wait for it to complete
3435 this.preparingToOpen
= $.when( this.closing
);
3436 // Ensure handlers get called after preparingToOpen is set
3437 this.preparingToOpen
.done( function () {
3438 if ( manager
.modal
) {
3439 manager
.toggleGlobalEvents( true );
3440 manager
.toggleAriaIsolation( true );
3442 manager
.currentWindow
= win
;
3443 manager
.opening
= opening
;
3444 manager
.preparingToOpen
= null;
3445 manager
.emit( 'opening', win
, opening
, data
);
3446 setTimeout( function () {
3447 win
.setup( data
).then( function () {
3448 manager
.updateWindowSize( win
);
3449 manager
.opening
.notify( { state
: 'setup' } );
3450 setTimeout( function () {
3451 win
.ready( data
).then( function () {
3452 manager
.opening
.notify( { state
: 'ready' } );
3453 manager
.opening
= null;
3454 manager
.opened
= $.Deferred();
3455 opening
.resolve( manager
.opened
.promise(), data
);
3457 }, manager
.getReadyDelay() );
3459 }, manager
.getSetupDelay() );
3463 return opening
.promise();
3469 * @param {OO.ui.Window|string} win Window object or symbolic name of window to close
3470 * @param {Object} [data] Window closing data
3471 * @return {jQuery.Promise} A `closing` promise resolved when the window is done closing.
3472 * See {@link #event-closing 'closing' event} for more information about closing promises.
3473 * @throws {Error} An error is thrown if the window is not managed by the window manager.
3476 OO
.ui
.WindowManager
.prototype.closeWindow = function ( win
, data
) {
3478 closing
= $.Deferred(),
3481 // Argument handling
3482 if ( typeof win
=== 'string' ) {
3483 win
= this.windows
[ win
];
3484 } else if ( !this.hasWindow( win
) ) {
3490 closing
.reject( new OO
.ui
.Error(
3491 'Cannot close window: window is not attached to manager'
3493 } else if ( win
!== this.currentWindow
) {
3494 closing
.reject( new OO
.ui
.Error(
3495 'Cannot close window: window already closed with different data'
3497 } else if ( this.preparingToClose
|| this.closing
) {
3498 closing
.reject( new OO
.ui
.Error(
3499 'Cannot close window: window already closing with different data'
3504 if ( closing
.state() !== 'rejected' ) {
3505 // If the window is currently opening, close it when it's done
3506 this.preparingToClose
= $.when( this.opening
);
3507 // Ensure handlers get called after preparingToClose is set
3508 this.preparingToClose
.done( function () {
3509 manager
.closing
= closing
;
3510 manager
.preparingToClose
= null;
3511 manager
.emit( 'closing', win
, closing
, data
);
3512 opened
= manager
.opened
;
3513 manager
.opened
= null;
3514 opened
.resolve( closing
.promise(), data
);
3515 setTimeout( function () {
3516 win
.hold( data
).then( function () {
3517 closing
.notify( { state
: 'hold' } );
3518 setTimeout( function () {
3519 win
.teardown( data
).then( function () {
3520 closing
.notify( { state
: 'teardown' } );
3521 if ( manager
.modal
) {
3522 manager
.toggleGlobalEvents( false );
3523 manager
.toggleAriaIsolation( false );
3525 manager
.closing
= null;
3526 manager
.currentWindow
= null;
3527 closing
.resolve( data
);
3529 }, manager
.getTeardownDelay() );
3531 }, manager
.getHoldDelay() );
3535 return closing
.promise();
3539 * Add windows to the window manager.
3541 * Windows can be added by reference, symbolic name, or explicitly defined symbolic names.
3542 * See the [OOjs ui documentation on MediaWiki] [2] for examples.
3543 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Window_managers
3545 * @param {Object.<string,OO.ui.Window>|OO.ui.Window[]} windows An array of window objects specified
3546 * by reference, symbolic name, or explicitly defined symbolic names.
3547 * @throws {Error} An error is thrown if a window is added by symbolic name, but has neither an
3548 * explicit nor a statically configured symbolic name.
3550 OO
.ui
.WindowManager
.prototype.addWindows = function ( windows
) {
3551 var i
, len
, win
, name
, list
;
3553 if ( Array
.isArray( windows
) ) {
3554 // Convert to map of windows by looking up symbolic names from static configuration
3556 for ( i
= 0, len
= windows
.length
; i
< len
; i
++ ) {
3557 name
= windows
[ i
].constructor.static.name
;
3558 if ( typeof name
!== 'string' ) {
3559 throw new Error( 'Cannot add window' );
3561 list
[ name
] = windows
[ i
];
3563 } else if ( OO
.isPlainObject( windows
) ) {
3568 for ( name
in list
) {
3570 this.windows
[ name
] = win
.toggle( false );
3571 this.$element
.append( win
.$element
);
3572 win
.setManager( this );
3577 * Remove the specified windows from the windows manager.
3579 * Windows will be closed before they are removed. If you wish to remove all windows, you may wish to use
3580 * the #clearWindows method instead. If you no longer need the window manager and want to ensure that it no
3581 * longer listens to events, use the #destroy method.
3583 * @param {string[]} names Symbolic names of windows to remove
3584 * @return {jQuery.Promise} Promise resolved when window is closed and removed
3585 * @throws {Error} An error is thrown if the named windows are not managed by the window manager.
3587 OO
.ui
.WindowManager
.prototype.removeWindows = function ( names
) {
3588 var i
, len
, win
, name
, cleanupWindow
,
3591 cleanup = function ( name
, win
) {
3592 delete manager
.windows
[ name
];
3593 win
.$element
.detach();
3596 for ( i
= 0, len
= names
.length
; i
< len
; i
++ ) {
3598 win
= this.windows
[ name
];
3600 throw new Error( 'Cannot remove window' );
3602 cleanupWindow
= cleanup
.bind( null, name
, win
);
3603 promises
.push( this.closeWindow( name
).then( cleanupWindow
, cleanupWindow
) );
3606 return $.when
.apply( $, promises
);
3610 * Remove all windows from the window manager.
3612 * Windows will be closed before they are removed. Note that the window manager, though not in use, will still
3613 * listen to events. If the window manager will not be used again, you may wish to use the #destroy method instead.
3614 * To remove just a subset of windows, use the #removeWindows method.
3616 * @return {jQuery.Promise} Promise resolved when all windows are closed and removed
3618 OO
.ui
.WindowManager
.prototype.clearWindows = function () {
3619 return this.removeWindows( Object
.keys( this.windows
) );
3623 * Set dialog size. In general, this method should not be called directly.
3625 * Fullscreen mode will be used if the dialog is too wide to fit in the screen.
3629 OO
.ui
.WindowManager
.prototype.updateWindowSize = function ( win
) {
3632 // Bypass for non-current, and thus invisible, windows
3633 if ( win
!== this.currentWindow
) {
3637 isFullscreen
= win
.getSize() === 'full';
3639 this.$element
.toggleClass( 'oo-ui-windowManager-fullscreen', isFullscreen
);
3640 this.$element
.toggleClass( 'oo-ui-windowManager-floating', !isFullscreen
);
3641 win
.setDimensions( win
.getSizeProperties() );
3643 this.emit( 'resize', win
);
3649 * Bind or unbind global events for scrolling.
3652 * @param {boolean} [on] Bind global events
3655 OO
.ui
.WindowManager
.prototype.toggleGlobalEvents = function ( on
) {
3656 var scrollWidth
, bodyMargin
,
3657 $body
= $( this.getElementDocument().body
),
3658 // We could have multiple window managers open so only modify
3659 // the body css at the bottom of the stack
3660 stackDepth
= $body
.data( 'windowManagerGlobalEvents' ) || 0 ;
3662 on
= on
=== undefined ? !!this.globalEvents
: !!on
;
3665 if ( !this.globalEvents
) {
3666 $( this.getElementWindow() ).on( {
3667 // Start listening for top-level window dimension changes
3668 'orientationchange resize': this.onWindowResizeHandler
3670 if ( stackDepth
=== 0 ) {
3671 scrollWidth
= window
.innerWidth
- document
.documentElement
.clientWidth
;
3672 bodyMargin
= parseFloat( $body
.css( 'margin-right' ) ) || 0;
3675 'margin-right': bodyMargin
+ scrollWidth
3679 this.globalEvents
= true;
3681 } else if ( this.globalEvents
) {
3682 $( this.getElementWindow() ).off( {
3683 // Stop listening for top-level window dimension changes
3684 'orientationchange resize': this.onWindowResizeHandler
3687 if ( stackDepth
=== 0 ) {
3693 this.globalEvents
= false;
3695 $body
.data( 'windowManagerGlobalEvents', stackDepth
);
3701 * Toggle screen reader visibility of content other than the window manager.
3704 * @param {boolean} [isolate] Make only the window manager visible to screen readers
3707 OO
.ui
.WindowManager
.prototype.toggleAriaIsolation = function ( isolate
) {
3708 isolate
= isolate
=== undefined ? !this.$ariaHidden
: !!isolate
;
3711 if ( !this.$ariaHidden
) {
3712 // Hide everything other than the window manager from screen readers
3713 this.$ariaHidden
= $( 'body' )
3715 .not( this.$element
.parentsUntil( 'body' ).last() )
3716 .attr( 'aria-hidden', '' );
3718 } else if ( this.$ariaHidden
) {
3719 // Restore screen reader visibility
3720 this.$ariaHidden
.removeAttr( 'aria-hidden' );
3721 this.$ariaHidden
= null;
3728 * Destroy the window manager.
3730 * Destroying the window manager ensures that it will no longer listen to events. If you would like to
3731 * continue using the window manager, but wish to remove all windows from it, use the #clearWindows method
3734 OO
.ui
.WindowManager
.prototype.destroy = function () {
3735 this.toggleGlobalEvents( false );
3736 this.toggleAriaIsolation( false );
3737 this.clearWindows();
3738 this.$element
.remove();
3742 * Errors contain a required message (either a string or jQuery selection) that is used to describe what went wrong
3743 * in a {@link OO.ui.Process process}. The error's #recoverable and #warning configurations are used to customize the
3744 * appearance and functionality of the error interface.
3746 * The basic error interface contains a formatted error message as well as two buttons: 'Dismiss' and 'Try again' (i.e., the error
3747 * is 'recoverable' by default). If the error is not recoverable, the 'Try again' button will not be rendered and the widget
3748 * that initiated the failed process will be disabled.
3750 * If the error is a warning, the error interface will include a 'Dismiss' and a 'Continue' button, which will try the
3753 * For an example of error interfaces, please see the [OOjs UI documentation on MediaWiki][1].
3755 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs#Processes_and_errors
3760 * @param {string|jQuery} message Description of error
3761 * @param {Object} [config] Configuration options
3762 * @cfg {boolean} [recoverable=true] Error is recoverable.
3763 * By default, errors are recoverable, and users can try the process again.
3764 * @cfg {boolean} [warning=false] Error is a warning.
3765 * If the error is a warning, the error interface will include a
3766 * 'Dismiss' and a 'Continue' button. It is the responsibility of the developer to ensure that the warning
3767 * is not triggered a second time if the user chooses to continue.
3769 OO
.ui
.Error
= function OoUiError( message
, config
) {
3770 // Allow passing positional parameters inside the config object
3771 if ( OO
.isPlainObject( message
) && config
=== undefined ) {
3773 message
= config
.message
;
3776 // Configuration initialization
3777 config
= config
|| {};
3780 this.message
= message
instanceof jQuery
? message
: String( message
);
3781 this.recoverable
= config
.recoverable
=== undefined || !!config
.recoverable
;
3782 this.warning
= !!config
.warning
;
3787 OO
.initClass( OO
.ui
.Error
);
3792 * Check if the error is recoverable.
3794 * If the error is recoverable, users are able to try the process again.
3796 * @return {boolean} Error is recoverable
3798 OO
.ui
.Error
.prototype.isRecoverable = function () {
3799 return this.recoverable
;
3803 * Check if the error is a warning.
3805 * If the error is a warning, the error interface will include a 'Dismiss' and a 'Continue' button.
3807 * @return {boolean} Error is warning
3809 OO
.ui
.Error
.prototype.isWarning = function () {
3810 return this.warning
;
3814 * Get error message as DOM nodes.
3816 * @return {jQuery} Error message in DOM nodes
3818 OO
.ui
.Error
.prototype.getMessage = function () {
3819 return this.message
instanceof jQuery
?
3820 this.message
.clone() :
3821 $( '<div>' ).text( this.message
).contents();
3825 * Get the error message text.
3827 * @return {string} Error message
3829 OO
.ui
.Error
.prototype.getMessageText = function () {
3830 return this.message
instanceof jQuery
? this.message
.text() : this.message
;
3834 * Wraps an HTML snippet for use with configuration values which default
3835 * to strings. This bypasses the default html-escaping done to string
3841 * @param {string} [content] HTML content
3843 OO
.ui
.HtmlSnippet
= function OoUiHtmlSnippet( content
) {
3845 this.content
= content
;
3850 OO
.initClass( OO
.ui
.HtmlSnippet
);
3857 * @return {string} Unchanged HTML snippet.
3859 OO
.ui
.HtmlSnippet
.prototype.toString = function () {
3860 return this.content
;
3864 * A Process is a list of steps that are called in sequence. The step can be a number, a jQuery promise,
3867 * - **number**: the process will wait for the specified number of milliseconds before proceeding.
3868 * - **promise**: the process will continue to the next step when the promise is successfully resolved
3869 * or stop if the promise is rejected.
3870 * - **function**: the process will execute the function. The process will stop if the function returns
3871 * either a boolean `false` or a promise that is rejected; if the function returns a number, the process
3872 * will wait for that number of milliseconds before proceeding.
3874 * If the process fails, an {@link OO.ui.Error error} is generated. Depending on how the error is
3875 * configured, users can dismiss the error and try the process again, or not. If a process is stopped,
3876 * its remaining steps will not be performed.
3881 * @param {number|jQuery.Promise|Function} step Number of miliseconds to wait before proceeding, promise
3882 * that must be resolved before proceeding, or a function to execute. See #createStep for more information. see #createStep for more information
3883 * @param {Object} [context=null] Execution context of the function. The context is ignored if the step is
3884 * a number or promise.
3885 * @return {Object} Step object, with `callback` and `context` properties
3887 OO
.ui
.Process = function ( step
, context
) {
3892 if ( step
!== undefined ) {
3893 this.next( step
, context
);
3899 OO
.initClass( OO
.ui
.Process
);
3904 * Start the process.
3906 * @return {jQuery.Promise} Promise that is resolved when all steps have successfully completed.
3907 * If any of the steps return a promise that is rejected or a boolean false, this promise is rejected
3908 * and any remaining steps are not performed.
3910 OO
.ui
.Process
.prototype.execute = function () {
3911 var i
, len
, promise
;
3914 * Continue execution.
3917 * @param {Array} step A function and the context it should be called in
3918 * @return {Function} Function that continues the process
3920 function proceed( step
) {
3921 return function () {
3922 // Execute step in the correct context
3924 result
= step
.callback
.call( step
.context
);
3926 if ( result
=== false ) {
3927 // Use rejected promise for boolean false results
3928 return $.Deferred().reject( [] ).promise();
3930 if ( typeof result
=== 'number' ) {
3932 throw new Error( 'Cannot go back in time: flux capacitor is out of service' );
3934 // Use a delayed promise for numbers, expecting them to be in milliseconds
3935 deferred
= $.Deferred();
3936 setTimeout( deferred
.resolve
, result
);
3937 return deferred
.promise();
3939 if ( result
instanceof OO
.ui
.Error
) {
3940 // Use rejected promise for error
3941 return $.Deferred().reject( [ result
] ).promise();
3943 if ( Array
.isArray( result
) && result
.length
&& result
[ 0 ] instanceof OO
.ui
.Error
) {
3944 // Use rejected promise for list of errors
3945 return $.Deferred().reject( result
).promise();
3947 // Duck-type the object to see if it can produce a promise
3948 if ( result
&& $.isFunction( result
.promise
) ) {
3949 // Use a promise generated from the result
3950 return result
.promise();
3952 // Use resolved promise for other results
3953 return $.Deferred().resolve().promise();
3957 if ( this.steps
.length
) {
3958 // Generate a chain reaction of promises
3959 promise
= proceed( this.steps
[ 0 ] )();
3960 for ( i
= 1, len
= this.steps
.length
; i
< len
; i
++ ) {
3961 promise
= promise
.then( proceed( this.steps
[ i
] ) );
3964 promise
= $.Deferred().resolve().promise();
3971 * Create a process step.
3974 * @param {number|jQuery.Promise|Function} step
3976 * - Number of milliseconds to wait before proceeding
3977 * - Promise that must be resolved before proceeding
3978 * - Function to execute
3979 * - If the function returns a boolean false the process will stop
3980 * - If the function returns a promise, the process will continue to the next
3981 * step when the promise is resolved or stop if the promise is rejected
3982 * - If the function returns a number, the process will wait for that number of
3983 * milliseconds before proceeding
3984 * @param {Object} [context=null] Execution context of the function. The context is
3985 * ignored if the step is a number or promise.
3986 * @return {Object} Step object, with `callback` and `context` properties
3988 OO
.ui
.Process
.prototype.createStep = function ( step
, context
) {
3989 if ( typeof step
=== 'number' || $.isFunction( step
.promise
) ) {
3991 callback: function () {
3997 if ( $.isFunction( step
) ) {
4003 throw new Error( 'Cannot create process step: number, promise or function expected' );
4007 * Add step to the beginning of the process.
4009 * @inheritdoc #createStep
4010 * @return {OO.ui.Process} this
4013 OO
.ui
.Process
.prototype.first = function ( step
, context
) {
4014 this.steps
.unshift( this.createStep( step
, context
) );
4019 * Add step to the end of the process.
4021 * @inheritdoc #createStep
4022 * @return {OO.ui.Process} this
4025 OO
.ui
.Process
.prototype.next = function ( step
, context
) {
4026 this.steps
.push( this.createStep( step
, context
) );
4031 * A ToolFactory creates tools on demand. All tools ({@link OO.ui.Tool Tools}, {@link OO.ui.PopupTool PopupTools},
4032 * and {@link OO.ui.ToolGroupTool ToolGroupTools}) must be registered with a tool factory. Tools are
4033 * registered by their symbolic name. See {@link OO.ui.Toolbar toolbars} for an example.
4035 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki][1].
4037 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
4040 * @extends OO.Factory
4043 OO
.ui
.ToolFactory
= function OoUiToolFactory() {
4044 // Parent constructor
4045 OO
.ui
.ToolFactory
.parent
.call( this );
4050 OO
.inheritClass( OO
.ui
.ToolFactory
, OO
.Factory
);
4055 * Get tools from the factory
4057 * @param {Array} include Included tools
4058 * @param {Array} exclude Excluded tools
4059 * @param {Array} promote Promoted tools
4060 * @param {Array} demote Demoted tools
4061 * @return {string[]} List of tools
4063 OO
.ui
.ToolFactory
.prototype.getTools = function ( include
, exclude
, promote
, demote
) {
4064 var i
, len
, included
, promoted
, demoted
,
4068 // Collect included and not excluded tools
4069 included
= OO
.simpleArrayDifference( this.extract( include
), this.extract( exclude
) );
4072 promoted
= this.extract( promote
, used
);
4073 demoted
= this.extract( demote
, used
);
4076 for ( i
= 0, len
= included
.length
; i
< len
; i
++ ) {
4077 if ( !used
[ included
[ i
] ] ) {
4078 auto
.push( included
[ i
] );
4082 return promoted
.concat( auto
).concat( demoted
);
4086 * Get a flat list of names from a list of names or groups.
4088 * Tools can be specified in the following ways:
4090 * - A specific tool: `{ name: 'tool-name' }` or `'tool-name'`
4091 * - All tools in a group: `{ group: 'group-name' }`
4092 * - All tools: `'*'`
4095 * @param {Array|string} collection List of tools
4096 * @param {Object} [used] Object with names that should be skipped as properties; extracted
4097 * names will be added as properties
4098 * @return {string[]} List of extracted names
4100 OO
.ui
.ToolFactory
.prototype.extract = function ( collection
, used
) {
4101 var i
, len
, item
, name
, tool
,
4104 if ( collection
=== '*' ) {
4105 for ( name
in this.registry
) {
4106 tool
= this.registry
[ name
];
4108 // Only add tools by group name when auto-add is enabled
4109 tool
.static.autoAddToCatchall
&&
4110 // Exclude already used tools
4111 ( !used
|| !used
[ name
] )
4115 used
[ name
] = true;
4119 } else if ( Array
.isArray( collection
) ) {
4120 for ( i
= 0, len
= collection
.length
; i
< len
; i
++ ) {
4121 item
= collection
[ i
];
4122 // Allow plain strings as shorthand for named tools
4123 if ( typeof item
=== 'string' ) {
4124 item
= { name
: item
};
4126 if ( OO
.isPlainObject( item
) ) {
4128 for ( name
in this.registry
) {
4129 tool
= this.registry
[ name
];
4131 // Include tools with matching group
4132 tool
.static.group
=== item
.group
&&
4133 // Only add tools by group name when auto-add is enabled
4134 tool
.static.autoAddToGroup
&&
4135 // Exclude already used tools
4136 ( !used
|| !used
[ name
] )
4140 used
[ name
] = true;
4144 // Include tools with matching name and exclude already used tools
4145 } else if ( item
.name
&& ( !used
|| !used
[ item
.name
] ) ) {
4146 names
.push( item
.name
);
4148 used
[ item
.name
] = true;
4158 * ToolGroupFactories create {@link OO.ui.ToolGroup toolgroups} on demand. The toolgroup classes must
4159 * specify a symbolic name and be registered with the factory. The following classes are registered by
4162 * - {@link OO.ui.BarToolGroup BarToolGroups} (‘bar’)
4163 * - {@link OO.ui.MenuToolGroup MenuToolGroups} (‘menu’)
4164 * - {@link OO.ui.ListToolGroup ListToolGroups} (‘list’)
4166 * See {@link OO.ui.Toolbar toolbars} for an example.
4168 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki][1].
4170 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
4172 * @extends OO.Factory
4175 OO
.ui
.ToolGroupFactory
= function OoUiToolGroupFactory() {
4176 var i
, l
, defaultClasses
;
4177 // Parent constructor
4178 OO
.Factory
.call( this );
4180 defaultClasses
= this.constructor.static.getDefaultClasses();
4182 // Register default toolgroups
4183 for ( i
= 0, l
= defaultClasses
.length
; i
< l
; i
++ ) {
4184 this.register( defaultClasses
[ i
] );
4190 OO
.inheritClass( OO
.ui
.ToolGroupFactory
, OO
.Factory
);
4192 /* Static Methods */
4195 * Get a default set of classes to be registered on construction.
4197 * @return {Function[]} Default classes
4199 OO
.ui
.ToolGroupFactory
.static.getDefaultClasses = function () {
4202 OO
.ui
.ListToolGroup
,
4214 * @param {Object} [config] Configuration options
4216 OO
.ui
.Theme
= function OoUiTheme( config
) {
4217 // Configuration initialization
4218 config
= config
|| {};
4223 OO
.initClass( OO
.ui
.Theme
);
4228 * Get a list of classes to be applied to a widget.
4230 * The 'on' and 'off' lists combined MUST contain keys for all classes the theme adds or removes,
4231 * otherwise state transitions will not work properly.
4233 * @param {OO.ui.Element} element Element for which to get classes
4234 * @return {Object.<string,string[]>} Categorized class names with `on` and `off` lists
4236 OO
.ui
.Theme
.prototype.getElementClasses = function ( /* element */ ) {
4237 return { on
: [], off
: [] };
4241 * Update CSS classes provided by the theme.
4243 * For elements with theme logic hooks, this should be called any time there's a state change.
4245 * @param {OO.ui.Element} element Element for which to update classes
4246 * @return {Object.<string,string[]>} Categorized class names with `on` and `off` lists
4248 OO
.ui
.Theme
.prototype.updateElementClasses = function ( element
) {
4249 var $elements
= $( [] ),
4250 classes
= this.getElementClasses( element
);
4252 if ( element
.$icon
) {
4253 $elements
= $elements
.add( element
.$icon
);
4255 if ( element
.$indicator
) {
4256 $elements
= $elements
.add( element
.$indicator
);
4260 .removeClass( classes
.off
.join( ' ' ) )
4261 .addClass( classes
.on
.join( ' ' ) );
4265 * The TabIndexedElement class is an attribute mixin used to add additional functionality to an
4266 * element created by another class. The mixin provides a ‘tabIndex’ property, which specifies the
4267 * order in which users will navigate through the focusable elements via the "tab" key.
4270 * // TabIndexedElement is mixed into the ButtonWidget class
4271 * // to provide a tabIndex property.
4272 * var button1 = new OO.ui.ButtonWidget( {
4276 * var button2 = new OO.ui.ButtonWidget( {
4280 * var button3 = new OO.ui.ButtonWidget( {
4284 * var button4 = new OO.ui.ButtonWidget( {
4288 * $( 'body' ).append( button1.$element, button2.$element, button3.$element, button4.$element );
4294 * @param {Object} [config] Configuration options
4295 * @cfg {jQuery} [$tabIndexed] The element that should use the tabindex functionality. By default,
4296 * the functionality is applied to the element created by the class ($element). If a different element is specified, the tabindex
4297 * functionality will be applied to it instead.
4298 * @cfg {number|null} [tabIndex=0] Number that specifies the element’s position in the tab-navigation
4299 * order (e.g., 1 for the first focusable element). Use 0 to use the default navigation order; use -1
4300 * to remove the element from the tab-navigation flow.
4302 OO
.ui
.mixin
.TabIndexedElement
= function OoUiMixinTabIndexedElement( config
) {
4303 // Configuration initialization
4304 config
= $.extend( { tabIndex
: 0 }, config
);
4307 this.$tabIndexed
= null;
4308 this.tabIndex
= null;
4311 this.connect( this, { disable
: 'onTabIndexedElementDisable' } );
4314 this.setTabIndex( config
.tabIndex
);
4315 this.setTabIndexedElement( config
.$tabIndexed
|| this.$element
);
4320 OO
.initClass( OO
.ui
.mixin
.TabIndexedElement
);
4325 * Set the element that should use the tabindex functionality.
4327 * This method is used to retarget a tabindex mixin so that its functionality applies
4328 * to the specified element. If an element is currently using the functionality, the mixin’s
4329 * effect on that element is removed before the new element is set up.
4331 * @param {jQuery} $tabIndexed Element that should use the tabindex functionality
4334 OO
.ui
.mixin
.TabIndexedElement
.prototype.setTabIndexedElement = function ( $tabIndexed
) {
4335 var tabIndex
= this.tabIndex
;
4336 // Remove attributes from old $tabIndexed
4337 this.setTabIndex( null );
4338 // Force update of new $tabIndexed
4339 this.$tabIndexed
= $tabIndexed
;
4340 this.tabIndex
= tabIndex
;
4341 return this.updateTabIndex();
4345 * Set the value of the tabindex.
4347 * @param {number|null} tabIndex Tabindex value, or `null` for no tabindex
4350 OO
.ui
.mixin
.TabIndexedElement
.prototype.setTabIndex = function ( tabIndex
) {
4351 tabIndex
= typeof tabIndex
=== 'number' ? tabIndex
: null;
4353 if ( this.tabIndex
!== tabIndex
) {
4354 this.tabIndex
= tabIndex
;
4355 this.updateTabIndex();
4362 * Update the `tabindex` attribute, in case of changes to tab index or
4368 OO
.ui
.mixin
.TabIndexedElement
.prototype.updateTabIndex = function () {
4369 if ( this.$tabIndexed
) {
4370 if ( this.tabIndex
!== null ) {
4371 // Do not index over disabled elements
4372 this.$tabIndexed
.attr( {
4373 tabindex
: this.isDisabled() ? -1 : this.tabIndex
,
4374 // Support: ChromeVox and NVDA
4375 // These do not seem to inherit aria-disabled from parent elements
4376 'aria-disabled': this.isDisabled().toString()
4379 this.$tabIndexed
.removeAttr( 'tabindex aria-disabled' );
4386 * Handle disable events.
4389 * @param {boolean} disabled Element is disabled
4391 OO
.ui
.mixin
.TabIndexedElement
.prototype.onTabIndexedElementDisable = function () {
4392 this.updateTabIndex();
4396 * Get the value of the tabindex.
4398 * @return {number|null} Tabindex value
4400 OO
.ui
.mixin
.TabIndexedElement
.prototype.getTabIndex = function () {
4401 return this.tabIndex
;
4405 * ButtonElement is often mixed into other classes to generate a button, which is a clickable
4406 * interface element that can be configured with access keys for accessibility.
4407 * See the [OOjs UI documentation on MediaWiki] [1] for examples.
4409 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Buttons_and_Switches#Buttons
4414 * @param {Object} [config] Configuration options
4415 * @cfg {jQuery} [$button] The button element created by the class.
4416 * If this configuration is omitted, the button element will use a generated `<a>`.
4417 * @cfg {boolean} [framed=true] Render the button with a frame
4419 OO
.ui
.mixin
.ButtonElement
= function OoUiMixinButtonElement( config
) {
4420 // Configuration initialization
4421 config
= config
|| {};
4424 this.$button
= null;
4426 this.active
= false;
4427 this.onMouseUpHandler
= this.onMouseUp
.bind( this );
4428 this.onMouseDownHandler
= this.onMouseDown
.bind( this );
4429 this.onKeyDownHandler
= this.onKeyDown
.bind( this );
4430 this.onKeyUpHandler
= this.onKeyUp
.bind( this );
4431 this.onClickHandler
= this.onClick
.bind( this );
4432 this.onKeyPressHandler
= this.onKeyPress
.bind( this );
4435 this.$element
.addClass( 'oo-ui-buttonElement' );
4436 this.toggleFramed( config
.framed
=== undefined || config
.framed
);
4437 this.setButtonElement( config
.$button
|| $( '<a>' ) );
4442 OO
.initClass( OO
.ui
.mixin
.ButtonElement
);
4444 /* Static Properties */
4447 * Cancel mouse down events.
4449 * This property is usually set to `true` to prevent the focus from changing when the button is clicked.
4450 * Classes such as {@link OO.ui.mixin.DraggableElement DraggableElement} and {@link OO.ui.ButtonOptionWidget ButtonOptionWidget}
4451 * use a value of `false` so that dragging behavior is possible and mousedown events can be handled by a
4456 * @property {boolean}
4458 OO
.ui
.mixin
.ButtonElement
.static.cancelButtonMouseDownEvents
= true;
4463 * A 'click' event is emitted when the button element is clicked.
4471 * Set the button element.
4473 * This method is used to retarget a button mixin so that its functionality applies to
4474 * the specified button element instead of the one created by the class. If a button element
4475 * is already set, the method will remove the mixin’s effect on that element.
4477 * @param {jQuery} $button Element to use as button
4479 OO
.ui
.mixin
.ButtonElement
.prototype.setButtonElement = function ( $button
) {
4480 if ( this.$button
) {
4482 .removeClass( 'oo-ui-buttonElement-button' )
4483 .removeAttr( 'role accesskey' )
4485 mousedown
: this.onMouseDownHandler
,
4486 keydown
: this.onKeyDownHandler
,
4487 click
: this.onClickHandler
,
4488 keypress
: this.onKeyPressHandler
4492 this.$button
= $button
4493 .addClass( 'oo-ui-buttonElement-button' )
4494 .attr( { role
: 'button' } )
4496 mousedown
: this.onMouseDownHandler
,
4497 keydown
: this.onKeyDownHandler
,
4498 click
: this.onClickHandler
,
4499 keypress
: this.onKeyPressHandler
4504 * Handles mouse down events.
4507 * @param {jQuery.Event} e Mouse down event
4509 OO
.ui
.mixin
.ButtonElement
.prototype.onMouseDown = function ( e
) {
4510 if ( this.isDisabled() || e
.which
!== 1 ) {
4513 this.$element
.addClass( 'oo-ui-buttonElement-pressed' );
4514 // Run the mouseup handler no matter where the mouse is when the button is let go, so we can
4515 // reliably remove the pressed class
4516 OO
.ui
.addCaptureEventListener( this.getElementDocument(), 'mouseup', this.onMouseUpHandler
);
4517 // Prevent change of focus unless specifically configured otherwise
4518 if ( this.constructor.static.cancelButtonMouseDownEvents
) {
4524 * Handles mouse up events.
4527 * @param {jQuery.Event} e Mouse up event
4529 OO
.ui
.mixin
.ButtonElement
.prototype.onMouseUp = function ( e
) {
4530 if ( this.isDisabled() || e
.which
!== 1 ) {
4533 this.$element
.removeClass( 'oo-ui-buttonElement-pressed' );
4534 // Stop listening for mouseup, since we only needed this once
4535 OO
.ui
.removeCaptureEventListener( this.getElementDocument(), 'mouseup', this.onMouseUpHandler
);
4539 * Handles mouse click events.
4542 * @param {jQuery.Event} e Mouse click event
4545 OO
.ui
.mixin
.ButtonElement
.prototype.onClick = function ( e
) {
4546 if ( !this.isDisabled() && e
.which
=== 1 ) {
4547 if ( this.emit( 'click' ) ) {
4554 * Handles key down events.
4557 * @param {jQuery.Event} e Key down event
4559 OO
.ui
.mixin
.ButtonElement
.prototype.onKeyDown = function ( e
) {
4560 if ( this.isDisabled() || ( e
.which
!== OO
.ui
.Keys
.SPACE
&& e
.which
!== OO
.ui
.Keys
.ENTER
) ) {
4563 this.$element
.addClass( 'oo-ui-buttonElement-pressed' );
4564 // Run the keyup handler no matter where the key is when the button is let go, so we can
4565 // reliably remove the pressed class
4566 OO
.ui
.addCaptureEventListener( this.getElementDocument(), 'keyup', this.onKeyUpHandler
);
4570 * Handles key up events.
4573 * @param {jQuery.Event} e Key up event
4575 OO
.ui
.mixin
.ButtonElement
.prototype.onKeyUp = function ( e
) {
4576 if ( this.isDisabled() || ( e
.which
!== OO
.ui
.Keys
.SPACE
&& e
.which
!== OO
.ui
.Keys
.ENTER
) ) {
4579 this.$element
.removeClass( 'oo-ui-buttonElement-pressed' );
4580 // Stop listening for keyup, since we only needed this once
4581 OO
.ui
.removeCaptureEventListener( this.getElementDocument(), 'keyup', this.onKeyUpHandler
);
4585 * Handles key press events.
4588 * @param {jQuery.Event} e Key press event
4591 OO
.ui
.mixin
.ButtonElement
.prototype.onKeyPress = function ( e
) {
4592 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
4593 if ( this.emit( 'click' ) ) {
4600 * Check if button has a frame.
4602 * @return {boolean} Button is framed
4604 OO
.ui
.mixin
.ButtonElement
.prototype.isFramed = function () {
4609 * Render the button with or without a frame. Omit the `framed` parameter to toggle the button frame on and off.
4611 * @param {boolean} [framed] Make button framed, omit to toggle
4614 OO
.ui
.mixin
.ButtonElement
.prototype.toggleFramed = function ( framed
) {
4615 framed
= framed
=== undefined ? !this.framed
: !!framed
;
4616 if ( framed
!== this.framed
) {
4617 this.framed
= framed
;
4619 .toggleClass( 'oo-ui-buttonElement-frameless', !framed
)
4620 .toggleClass( 'oo-ui-buttonElement-framed', framed
);
4621 this.updateThemeClasses();
4628 * Set the button to its 'active' state.
4630 * The active state occurs when a {@link OO.ui.ButtonOptionWidget ButtonOptionWidget} or
4631 * a {@link OO.ui.ToggleButtonWidget ToggleButtonWidget} is pressed. This method does nothing
4632 * for other button types.
4634 * @param {boolean} [value] Make button active
4637 OO
.ui
.mixin
.ButtonElement
.prototype.setActive = function ( value
) {
4638 this.$element
.toggleClass( 'oo-ui-buttonElement-active', !!value
);
4643 * Any OOjs UI widget that contains other widgets (such as {@link OO.ui.ButtonWidget buttons} or
4644 * {@link OO.ui.OptionWidget options}) mixes in GroupElement. Adding, removing, and clearing
4645 * items from the group is done through the interface the class provides.
4646 * For more information, please see the [OOjs UI documentation on MediaWiki] [1].
4648 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Elements/Groups
4654 * @param {Object} [config] Configuration options
4655 * @cfg {jQuery} [$group] The container element created by the class. If this configuration
4656 * is omitted, the group element will use a generated `<div>`.
4658 OO
.ui
.mixin
.GroupElement
= function OoUiMixinGroupElement( config
) {
4659 // Configuration initialization
4660 config
= config
|| {};
4665 this.aggregateItemEvents
= {};
4668 this.setGroupElement( config
.$group
|| $( '<div>' ) );
4674 * Set the group element.
4676 * If an element is already set, items will be moved to the new element.
4678 * @param {jQuery} $group Element to use as group
4680 OO
.ui
.mixin
.GroupElement
.prototype.setGroupElement = function ( $group
) {
4683 this.$group
= $group
;
4684 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4685 this.$group
.append( this.items
[ i
].$element
);
4690 * Check if a group contains no items.
4692 * @return {boolean} Group is empty
4694 OO
.ui
.mixin
.GroupElement
.prototype.isEmpty = function () {
4695 return !this.items
.length
;
4699 * Get all items in the group.
4701 * The method returns an array of item references (e.g., [button1, button2, button3]) and is useful
4702 * when synchronizing groups of items, or whenever the references are required (e.g., when removing items
4705 * @return {OO.ui.Element[]} An array of items.
4707 OO
.ui
.mixin
.GroupElement
.prototype.getItems = function () {
4708 return this.items
.slice( 0 );
4712 * Get an item by its data.
4714 * Only the first item with matching data will be returned. To return all matching items,
4715 * use the #getItemsFromData method.
4717 * @param {Object} data Item data to search for
4718 * @return {OO.ui.Element|null} Item with equivalent data, `null` if none exists
4720 OO
.ui
.mixin
.GroupElement
.prototype.getItemFromData = function ( data
) {
4722 hash
= OO
.getHash( data
);
4724 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4725 item
= this.items
[ i
];
4726 if ( hash
=== OO
.getHash( item
.getData() ) ) {
4735 * Get items by their data.
4737 * All items with matching data will be returned. To return only the first match, use the #getItemFromData method instead.
4739 * @param {Object} data Item data to search for
4740 * @return {OO.ui.Element[]} Items with equivalent data
4742 OO
.ui
.mixin
.GroupElement
.prototype.getItemsFromData = function ( data
) {
4744 hash
= OO
.getHash( data
),
4747 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4748 item
= this.items
[ i
];
4749 if ( hash
=== OO
.getHash( item
.getData() ) ) {
4758 * Aggregate the events emitted by the group.
4760 * When events are aggregated, the group will listen to all contained items for the event,
4761 * and then emit the event under a new name. The new event will contain an additional leading
4762 * parameter containing the item that emitted the original event. Other arguments emitted from
4763 * the original event are passed through.
4765 * @param {Object.<string,string|null>} events An object keyed by the name of the event that should be
4766 * aggregated (e.g., ‘click’) and the value of the new name to use (e.g., ‘groupClick’).
4767 * A `null` value will remove aggregated events.
4769 * @throws {Error} An error is thrown if aggregation already exists.
4771 OO
.ui
.mixin
.GroupElement
.prototype.aggregate = function ( events
) {
4772 var i
, len
, item
, add
, remove
, itemEvent
, groupEvent
;
4774 for ( itemEvent
in events
) {
4775 groupEvent
= events
[ itemEvent
];
4777 // Remove existing aggregated event
4778 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
4779 // Don't allow duplicate aggregations
4781 throw new Error( 'Duplicate item event aggregation for ' + itemEvent
);
4783 // Remove event aggregation from existing items
4784 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4785 item
= this.items
[ i
];
4786 if ( item
.connect
&& item
.disconnect
) {
4788 remove
[ itemEvent
] = [ 'emit', this.aggregateItemEvents
[ itemEvent
], item
];
4789 item
.disconnect( this, remove
);
4792 // Prevent future items from aggregating event
4793 delete this.aggregateItemEvents
[ itemEvent
];
4796 // Add new aggregate event
4798 // Make future items aggregate event
4799 this.aggregateItemEvents
[ itemEvent
] = groupEvent
;
4800 // Add event aggregation to existing items
4801 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4802 item
= this.items
[ i
];
4803 if ( item
.connect
&& item
.disconnect
) {
4805 add
[ itemEvent
] = [ 'emit', groupEvent
, item
];
4806 item
.connect( this, add
);
4814 * Add items to the group.
4816 * Items will be added to the end of the group array unless the optional `index` parameter specifies
4817 * a different insertion point. Adding an existing item will move it to the end of the array or the point specified by the `index`.
4819 * @param {OO.ui.Element[]} items An array of items to add to the group
4820 * @param {number} [index] Index of the insertion point
4823 OO
.ui
.mixin
.GroupElement
.prototype.addItems = function ( items
, index
) {
4824 var i
, len
, item
, event
, events
, currentIndex
,
4827 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
4830 // Check if item exists then remove it first, effectively "moving" it
4831 currentIndex
= this.items
.indexOf( item
);
4832 if ( currentIndex
>= 0 ) {
4833 this.removeItems( [ item
] );
4834 // Adjust index to compensate for removal
4835 if ( currentIndex
< index
) {
4840 if ( item
.connect
&& item
.disconnect
&& !$.isEmptyObject( this.aggregateItemEvents
) ) {
4842 for ( event
in this.aggregateItemEvents
) {
4843 events
[ event
] = [ 'emit', this.aggregateItemEvents
[ event
], item
];
4845 item
.connect( this, events
);
4847 item
.setElementGroup( this );
4848 itemElements
.push( item
.$element
.get( 0 ) );
4851 if ( index
=== undefined || index
< 0 || index
>= this.items
.length
) {
4852 this.$group
.append( itemElements
);
4853 this.items
.push
.apply( this.items
, items
);
4854 } else if ( index
=== 0 ) {
4855 this.$group
.prepend( itemElements
);
4856 this.items
.unshift
.apply( this.items
, items
);
4858 this.items
[ index
].$element
.before( itemElements
);
4859 this.items
.splice
.apply( this.items
, [ index
, 0 ].concat( items
) );
4866 * Remove the specified items from a group.
4868 * Removed items are detached (not removed) from the DOM so that they may be reused.
4869 * To remove all items from a group, you may wish to use the #clearItems method instead.
4871 * @param {OO.ui.Element[]} items An array of items to remove
4874 OO
.ui
.mixin
.GroupElement
.prototype.removeItems = function ( items
) {
4875 var i
, len
, item
, index
, remove
, itemEvent
;
4877 // Remove specific items
4878 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
4880 index
= this.items
.indexOf( item
);
4881 if ( index
!== -1 ) {
4883 item
.connect
&& item
.disconnect
&&
4884 !$.isEmptyObject( this.aggregateItemEvents
)
4887 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
4888 remove
[ itemEvent
] = [ 'emit', this.aggregateItemEvents
[ itemEvent
], item
];
4890 item
.disconnect( this, remove
);
4892 item
.setElementGroup( null );
4893 this.items
.splice( index
, 1 );
4894 item
.$element
.detach();
4902 * Clear all items from the group.
4904 * Cleared items are detached from the DOM, not removed, so that they may be reused.
4905 * To remove only a subset of items from a group, use the #removeItems method.
4909 OO
.ui
.mixin
.GroupElement
.prototype.clearItems = function () {
4910 var i
, len
, item
, remove
, itemEvent
;
4913 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4914 item
= this.items
[ i
];
4916 item
.connect
&& item
.disconnect
&&
4917 !$.isEmptyObject( this.aggregateItemEvents
)
4920 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
4921 remove
[ itemEvent
] = [ 'emit', this.aggregateItemEvents
[ itemEvent
], item
];
4923 item
.disconnect( this, remove
);
4925 item
.setElementGroup( null );
4926 item
.$element
.detach();
4934 * DraggableElement is a mixin class used to create elements that can be clicked
4935 * and dragged by a mouse to a new position within a group. This class must be used
4936 * in conjunction with OO.ui.mixin.DraggableGroupElement, which provides a container for
4937 * the draggable elements.
4944 OO
.ui
.mixin
.DraggableElement
= function OoUiMixinDraggableElement() {
4948 // Initialize and events
4950 .attr( 'draggable', true )
4951 .addClass( 'oo-ui-draggableElement' )
4953 dragstart
: this.onDragStart
.bind( this ),
4954 dragover
: this.onDragOver
.bind( this ),
4955 dragend
: this.onDragEnd
.bind( this ),
4956 drop
: this.onDrop
.bind( this )
4960 OO
.initClass( OO
.ui
.mixin
.DraggableElement
);
4967 * A dragstart event is emitted when the user clicks and begins dragging an item.
4968 * @param {OO.ui.mixin.DraggableElement} item The item the user has clicked and is dragging with the mouse.
4973 * A dragend event is emitted when the user drags an item and releases the mouse,
4974 * thus terminating the drag operation.
4979 * A drop event is emitted when the user drags an item and then releases the mouse button
4980 * over a valid target.
4983 /* Static Properties */
4986 * @inheritdoc OO.ui.mixin.ButtonElement
4988 OO
.ui
.mixin
.DraggableElement
.static.cancelButtonMouseDownEvents
= false;
4993 * Respond to dragstart event.
4996 * @param {jQuery.Event} event jQuery event
4999 OO
.ui
.mixin
.DraggableElement
.prototype.onDragStart = function ( e
) {
5000 var dataTransfer
= e
.originalEvent
.dataTransfer
;
5001 // Define drop effect
5002 dataTransfer
.dropEffect
= 'none';
5003 dataTransfer
.effectAllowed
= 'move';
5005 // We must set up a dataTransfer data property or Firefox seems to
5006 // ignore the fact the element is draggable.
5008 dataTransfer
.setData( 'application-x/OOjs-UI-draggable', this.getIndex() );
5010 // The above is only for Firefox. Move on if it fails.
5012 // Add dragging class
5013 this.$element
.addClass( 'oo-ui-draggableElement-dragging' );
5015 this.emit( 'dragstart', this );
5020 * Respond to dragend event.
5025 OO
.ui
.mixin
.DraggableElement
.prototype.onDragEnd = function () {
5026 this.$element
.removeClass( 'oo-ui-draggableElement-dragging' );
5027 this.emit( 'dragend' );
5031 * Handle drop event.
5034 * @param {jQuery.Event} event jQuery event
5037 OO
.ui
.mixin
.DraggableElement
.prototype.onDrop = function ( e
) {
5039 this.emit( 'drop', e
);
5043 * In order for drag/drop to work, the dragover event must
5044 * return false and stop propogation.
5048 OO
.ui
.mixin
.DraggableElement
.prototype.onDragOver = function ( e
) {
5054 * Store it in the DOM so we can access from the widget drag event
5057 * @param {number} Item index
5059 OO
.ui
.mixin
.DraggableElement
.prototype.setIndex = function ( index
) {
5060 if ( this.index
!== index
) {
5062 this.$element
.data( 'index', index
);
5070 * @return {number} Item index
5072 OO
.ui
.mixin
.DraggableElement
.prototype.getIndex = function () {
5077 * DraggableGroupElement is a mixin class used to create a group element to
5078 * contain draggable elements, which are items that can be clicked and dragged by a mouse.
5079 * The class is used with OO.ui.mixin.DraggableElement.
5083 * @mixins OO.ui.mixin.GroupElement
5086 * @param {Object} [config] Configuration options
5087 * @cfg {string} [orientation] Item orientation: 'horizontal' or 'vertical'. The orientation
5088 * should match the layout of the items. Items displayed in a single row
5089 * or in several rows should use horizontal orientation. The vertical orientation should only be
5090 * used when the items are displayed in a single column. Defaults to 'vertical'
5092 OO
.ui
.mixin
.DraggableGroupElement
= function OoUiMixinDraggableGroupElement( config
) {
5093 // Configuration initialization
5094 config
= config
|| {};
5096 // Parent constructor
5097 OO
.ui
.mixin
.GroupElement
.call( this, config
);
5100 this.orientation
= config
.orientation
|| 'vertical';
5101 this.dragItem
= null;
5102 this.itemDragOver
= null;
5104 this.sideInsertion
= '';
5108 dragstart
: 'itemDragStart',
5109 dragend
: 'itemDragEnd',
5112 this.connect( this, {
5113 itemDragStart
: 'onItemDragStart',
5114 itemDrop
: 'onItemDrop',
5115 itemDragEnd
: 'onItemDragEnd'
5118 dragover
: this.onDragOver
.bind( this ),
5119 dragleave
: this.onDragLeave
.bind( this )
5123 if ( Array
.isArray( config
.items
) ) {
5124 this.addItems( config
.items
);
5126 this.$placeholder
= $( '<div>' )
5127 .addClass( 'oo-ui-draggableGroupElement-placeholder' );
5129 .addClass( 'oo-ui-draggableGroupElement' )
5130 .append( this.$status
)
5131 .toggleClass( 'oo-ui-draggableGroupElement-horizontal', this.orientation
=== 'horizontal' )
5132 .prepend( this.$placeholder
);
5136 OO
.mixinClass( OO
.ui
.mixin
.DraggableGroupElement
, OO
.ui
.mixin
.GroupElement
);
5141 * A 'reorder' event is emitted when the order of items in the group changes.
5144 * @param {OO.ui.mixin.DraggableElement} item Reordered item
5145 * @param {number} [newIndex] New index for the item
5151 * Respond to item drag start event
5154 * @param {OO.ui.mixin.DraggableElement} item Dragged item
5156 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onItemDragStart = function ( item
) {
5159 // Map the index of each object
5160 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
5161 this.items
[ i
].setIndex( i
);
5164 if ( this.orientation
=== 'horizontal' ) {
5165 // Set the height of the indicator
5166 this.$placeholder
.css( {
5167 height
: item
.$element
.outerHeight(),
5171 // Set the width of the indicator
5172 this.$placeholder
.css( {
5174 width
: item
.$element
.outerWidth()
5177 this.setDragItem( item
);
5181 * Respond to item drag end event
5185 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onItemDragEnd = function () {
5186 this.unsetDragItem();
5191 * Handle drop event and switch the order of the items accordingly
5194 * @param {OO.ui.mixin.DraggableElement} item Dropped item
5197 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onItemDrop = function ( item
) {
5198 var toIndex
= item
.getIndex();
5199 // Check if the dropped item is from the current group
5200 // TODO: Figure out a way to configure a list of legally droppable
5201 // elements even if they are not yet in the list
5202 if ( this.getDragItem() ) {
5203 // If the insertion point is 'after', the insertion index
5204 // is shifted to the right (or to the left in RTL, hence 'after')
5205 if ( this.sideInsertion
=== 'after' ) {
5208 // Emit change event
5209 this.emit( 'reorder', this.getDragItem(), toIndex
);
5211 this.unsetDragItem();
5212 // Return false to prevent propogation
5217 * Handle dragleave event.
5221 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onDragLeave = function () {
5222 // This means the item was dragged outside the widget
5225 .addClass( 'oo-ui-element-hidden' );
5229 * Respond to dragover event
5232 * @param {jQuery.Event} event Event details
5234 OO
.ui
.mixin
.DraggableGroupElement
.prototype.onDragOver = function ( e
) {
5235 var dragOverObj
, $optionWidget
, itemOffset
, itemMidpoint
, itemBoundingRect
,
5236 itemSize
, cssOutput
, dragPosition
, itemIndex
, itemPosition
,
5237 clientX
= e
.originalEvent
.clientX
,
5238 clientY
= e
.originalEvent
.clientY
;
5240 // Get the OptionWidget item we are dragging over
5241 dragOverObj
= this.getElementDocument().elementFromPoint( clientX
, clientY
);
5242 $optionWidget
= $( dragOverObj
).closest( '.oo-ui-draggableElement' );
5243 if ( $optionWidget
[ 0 ] ) {
5244 itemOffset
= $optionWidget
.offset();
5245 itemBoundingRect
= $optionWidget
[ 0 ].getBoundingClientRect();
5246 itemPosition
= $optionWidget
.position();
5247 itemIndex
= $optionWidget
.data( 'index' );
5252 this.isDragging() &&
5253 itemIndex
!== this.getDragItem().getIndex()
5255 if ( this.orientation
=== 'horizontal' ) {
5256 // Calculate where the mouse is relative to the item width
5257 itemSize
= itemBoundingRect
.width
;
5258 itemMidpoint
= itemBoundingRect
.left
+ itemSize
/ 2;
5259 dragPosition
= clientX
;
5260 // Which side of the item we hover over will dictate
5261 // where the placeholder will appear, on the left or
5264 left
: dragPosition
< itemMidpoint
? itemPosition
.left
: itemPosition
.left
+ itemSize
,
5265 top
: itemPosition
.top
5268 // Calculate where the mouse is relative to the item height
5269 itemSize
= itemBoundingRect
.height
;
5270 itemMidpoint
= itemBoundingRect
.top
+ itemSize
/ 2;
5271 dragPosition
= clientY
;
5272 // Which side of the item we hover over will dictate
5273 // where the placeholder will appear, on the top or
5276 top
: dragPosition
< itemMidpoint
? itemPosition
.top
: itemPosition
.top
+ itemSize
,
5277 left
: itemPosition
.left
5280 // Store whether we are before or after an item to rearrange
5281 // For horizontal layout, we need to account for RTL, as this is flipped
5282 if ( this.orientation
=== 'horizontal' && this.$element
.css( 'direction' ) === 'rtl' ) {
5283 this.sideInsertion
= dragPosition
< itemMidpoint
? 'after' : 'before';
5285 this.sideInsertion
= dragPosition
< itemMidpoint
? 'before' : 'after';
5287 // Add drop indicator between objects
5290 .removeClass( 'oo-ui-element-hidden' );
5292 // This means the item was dragged outside the widget
5295 .addClass( 'oo-ui-element-hidden' );
5302 * Set a dragged item
5304 * @param {OO.ui.mixin.DraggableElement} item Dragged item
5306 OO
.ui
.mixin
.DraggableGroupElement
.prototype.setDragItem = function ( item
) {
5307 this.dragItem
= item
;
5311 * Unset the current dragged item
5313 OO
.ui
.mixin
.DraggableGroupElement
.prototype.unsetDragItem = function () {
5314 this.dragItem
= null;
5315 this.itemDragOver
= null;
5316 this.$placeholder
.addClass( 'oo-ui-element-hidden' );
5317 this.sideInsertion
= '';
5321 * Get the item that is currently being dragged.
5323 * @return {OO.ui.mixin.DraggableElement|null} The currently dragged item, or `null` if no item is being dragged
5325 OO
.ui
.mixin
.DraggableGroupElement
.prototype.getDragItem = function () {
5326 return this.dragItem
;
5330 * Check if an item in the group is currently being dragged.
5332 * @return {Boolean} Item is being dragged
5334 OO
.ui
.mixin
.DraggableGroupElement
.prototype.isDragging = function () {
5335 return this.getDragItem() !== null;
5339 * IconElement is often mixed into other classes to generate an icon.
5340 * Icons are graphics, about the size of normal text. They are used to aid the user
5341 * in locating a control or to convey information in a space-efficient way. See the
5342 * [OOjs UI documentation on MediaWiki] [1] for a list of icons
5343 * included in the library.
5345 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Icons
5351 * @param {Object} [config] Configuration options
5352 * @cfg {jQuery} [$icon] The icon element created by the class. If this configuration is omitted,
5353 * the icon element will use a generated `<span>`. To use a different HTML tag, or to specify that
5354 * the icon element be set to an existing icon instead of the one generated by this class, set a
5355 * value using a jQuery selection. For example:
5357 * // Use a <div> tag instead of a <span>
5359 * // Use an existing icon element instead of the one generated by the class
5360 * $icon: this.$element
5361 * // Use an icon element from a child widget
5362 * $icon: this.childwidget.$element
5363 * @cfg {Object|string} [icon=''] The symbolic name of the icon (e.g., ‘remove’ or ‘menu’), or a map of
5364 * symbolic names. A map is used for i18n purposes and contains a `default` icon
5365 * name and additional names keyed by language code. The `default` name is used when no icon is keyed
5366 * by the user's language.
5368 * Example of an i18n map:
5370 * { default: 'bold-a', en: 'bold-b', de: 'bold-f' }
5371 * See the [OOjs UI documentation on MediaWiki] [2] for a list of icons included in the library.
5372 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Icons
5373 * @cfg {string|Function} [iconTitle] A text string used as the icon title, or a function that returns title
5374 * text. The icon title is displayed when users move the mouse over the icon.
5376 OO
.ui
.mixin
.IconElement
= function OoUiMixinIconElement( config
) {
5377 // Configuration initialization
5378 config
= config
|| {};
5383 this.iconTitle
= null;
5386 this.setIcon( config
.icon
|| this.constructor.static.icon
);
5387 this.setIconTitle( config
.iconTitle
|| this.constructor.static.iconTitle
);
5388 this.setIconElement( config
.$icon
|| $( '<span>' ) );
5393 OO
.initClass( OO
.ui
.mixin
.IconElement
);
5395 /* Static Properties */
5398 * The symbolic name of the icon (e.g., ‘remove’ or ‘menu’), or a map of symbolic names. A map is used
5399 * for i18n purposes and contains a `default` icon name and additional names keyed by
5400 * language code. The `default` name is used when no icon is keyed by the user's language.
5402 * Example of an i18n map:
5404 * { default: 'bold-a', en: 'bold-b', de: 'bold-f' }
5406 * Note: the static property will be overridden if the #icon configuration is used.
5410 * @property {Object|string}
5412 OO
.ui
.mixin
.IconElement
.static.icon
= null;
5415 * The icon title, displayed when users move the mouse over the icon. The value can be text, a
5416 * function that returns title text, or `null` for no title.
5418 * The static property will be overridden if the #iconTitle configuration is used.
5422 * @property {string|Function|null}
5424 OO
.ui
.mixin
.IconElement
.static.iconTitle
= null;
5429 * Set the icon element. This method is used to retarget an icon mixin so that its functionality
5430 * applies to the specified icon element instead of the one created by the class. If an icon
5431 * element is already set, the mixin’s effect on that element is removed. Generated CSS classes
5432 * and mixin methods will no longer affect the element.
5434 * @param {jQuery} $icon Element to use as icon
5436 OO
.ui
.mixin
.IconElement
.prototype.setIconElement = function ( $icon
) {
5439 .removeClass( 'oo-ui-iconElement-icon oo-ui-icon-' + this.icon
)
5440 .removeAttr( 'title' );
5444 .addClass( 'oo-ui-iconElement-icon' )
5445 .toggleClass( 'oo-ui-icon-' + this.icon
, !!this.icon
);
5446 if ( this.iconTitle
!== null ) {
5447 this.$icon
.attr( 'title', this.iconTitle
);
5450 this.updateThemeClasses();
5454 * Set icon by symbolic name (e.g., ‘remove’ or ‘menu’). Use `null` to remove an icon.
5455 * The icon parameter can also be set to a map of icon names. See the #icon config setting
5458 * @param {Object|string|null} icon A symbolic icon name, a {@link #icon map of icon names} keyed
5459 * by language code, or `null` to remove the icon.
5462 OO
.ui
.mixin
.IconElement
.prototype.setIcon = function ( icon
) {
5463 icon
= OO
.isPlainObject( icon
) ? OO
.ui
.getLocalValue( icon
, null, 'default' ) : icon
;
5464 icon
= typeof icon
=== 'string' && icon
.trim().length
? icon
.trim() : null;
5466 if ( this.icon
!== icon
) {
5468 if ( this.icon
!== null ) {
5469 this.$icon
.removeClass( 'oo-ui-icon-' + this.icon
);
5471 if ( icon
!== null ) {
5472 this.$icon
.addClass( 'oo-ui-icon-' + icon
);
5478 this.$element
.toggleClass( 'oo-ui-iconElement', !!this.icon
);
5479 this.updateThemeClasses();
5485 * Set the icon title. Use `null` to remove the title.
5487 * @param {string|Function|null} iconTitle A text string used as the icon title,
5488 * a function that returns title text, or `null` for no title.
5491 OO
.ui
.mixin
.IconElement
.prototype.setIconTitle = function ( iconTitle
) {
5492 iconTitle
= typeof iconTitle
=== 'function' ||
5493 ( typeof iconTitle
=== 'string' && iconTitle
.length
) ?
5494 OO
.ui
.resolveMsg( iconTitle
) : null;
5496 if ( this.iconTitle
!== iconTitle
) {
5497 this.iconTitle
= iconTitle
;
5499 if ( this.iconTitle
!== null ) {
5500 this.$icon
.attr( 'title', iconTitle
);
5502 this.$icon
.removeAttr( 'title' );
5511 * Get the symbolic name of the icon.
5513 * @return {string} Icon name
5515 OO
.ui
.mixin
.IconElement
.prototype.getIcon = function () {
5520 * Get the icon title. The title text is displayed when a user moves the mouse over the icon.
5522 * @return {string} Icon title text
5524 OO
.ui
.mixin
.IconElement
.prototype.getIconTitle = function () {
5525 return this.iconTitle
;
5529 * IndicatorElement is often mixed into other classes to generate an indicator.
5530 * Indicators are small graphics that are generally used in two ways:
5532 * - To draw attention to the status of an item. For example, an indicator might be
5533 * used to show that an item in a list has errors that need to be resolved.
5534 * - To clarify the function of a control that acts in an exceptional way (a button
5535 * that opens a menu instead of performing an action directly, for example).
5537 * For a list of indicators included in the library, please see the
5538 * [OOjs UI documentation on MediaWiki] [1].
5540 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Indicators
5546 * @param {Object} [config] Configuration options
5547 * @cfg {jQuery} [$indicator] The indicator element created by the class. If this
5548 * configuration is omitted, the indicator element will use a generated `<span>`.
5549 * @cfg {string} [indicator] Symbolic name of the indicator (e.g., ‘alert’ or ‘down’).
5550 * See the [OOjs UI documentation on MediaWiki][2] for a list of indicators included
5552 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Indicators
5553 * @cfg {string|Function} [indicatorTitle] A text string used as the indicator title,
5554 * or a function that returns title text. The indicator title is displayed when users move
5555 * the mouse over the indicator.
5557 OO
.ui
.mixin
.IndicatorElement
= function OoUiMixinIndicatorElement( config
) {
5558 // Configuration initialization
5559 config
= config
|| {};
5562 this.$indicator
= null;
5563 this.indicator
= null;
5564 this.indicatorTitle
= null;
5567 this.setIndicator( config
.indicator
|| this.constructor.static.indicator
);
5568 this.setIndicatorTitle( config
.indicatorTitle
|| this.constructor.static.indicatorTitle
);
5569 this.setIndicatorElement( config
.$indicator
|| $( '<span>' ) );
5574 OO
.initClass( OO
.ui
.mixin
.IndicatorElement
);
5576 /* Static Properties */
5579 * Symbolic name of the indicator (e.g., ‘alert’ or ‘down’).
5580 * The static property will be overridden if the #indicator configuration is used.
5584 * @property {string|null}
5586 OO
.ui
.mixin
.IndicatorElement
.static.indicator
= null;
5589 * A text string used as the indicator title, a function that returns title text, or `null`
5590 * for no title. The static property will be overridden if the #indicatorTitle configuration is used.
5594 * @property {string|Function|null}
5596 OO
.ui
.mixin
.IndicatorElement
.static.indicatorTitle
= null;
5601 * Set the indicator element.
5603 * If an element is already set, it will be cleaned up before setting up the new element.
5605 * @param {jQuery} $indicator Element to use as indicator
5607 OO
.ui
.mixin
.IndicatorElement
.prototype.setIndicatorElement = function ( $indicator
) {
5608 if ( this.$indicator
) {
5610 .removeClass( 'oo-ui-indicatorElement-indicator oo-ui-indicator-' + this.indicator
)
5611 .removeAttr( 'title' );
5614 this.$indicator
= $indicator
5615 .addClass( 'oo-ui-indicatorElement-indicator' )
5616 .toggleClass( 'oo-ui-indicator-' + this.indicator
, !!this.indicator
);
5617 if ( this.indicatorTitle
!== null ) {
5618 this.$indicator
.attr( 'title', this.indicatorTitle
);
5621 this.updateThemeClasses();
5625 * Set the indicator by its symbolic name: ‘alert’, ‘down’, ‘next’, ‘previous’, ‘required’, ‘up’. Use `null` to remove the indicator.
5627 * @param {string|null} indicator Symbolic name of indicator, or `null` for no indicator
5630 OO
.ui
.mixin
.IndicatorElement
.prototype.setIndicator = function ( indicator
) {
5631 indicator
= typeof indicator
=== 'string' && indicator
.length
? indicator
.trim() : null;
5633 if ( this.indicator
!== indicator
) {
5634 if ( this.$indicator
) {
5635 if ( this.indicator
!== null ) {
5636 this.$indicator
.removeClass( 'oo-ui-indicator-' + this.indicator
);
5638 if ( indicator
!== null ) {
5639 this.$indicator
.addClass( 'oo-ui-indicator-' + indicator
);
5642 this.indicator
= indicator
;
5645 this.$element
.toggleClass( 'oo-ui-indicatorElement', !!this.indicator
);
5646 this.updateThemeClasses();
5652 * Set the indicator title.
5654 * The title is displayed when a user moves the mouse over the indicator.
5656 * @param {string|Function|null} indicator Indicator title text, a function that returns text, or
5657 * `null` for no indicator title
5660 OO
.ui
.mixin
.IndicatorElement
.prototype.setIndicatorTitle = function ( indicatorTitle
) {
5661 indicatorTitle
= typeof indicatorTitle
=== 'function' ||
5662 ( typeof indicatorTitle
=== 'string' && indicatorTitle
.length
) ?
5663 OO
.ui
.resolveMsg( indicatorTitle
) : null;
5665 if ( this.indicatorTitle
!== indicatorTitle
) {
5666 this.indicatorTitle
= indicatorTitle
;
5667 if ( this.$indicator
) {
5668 if ( this.indicatorTitle
!== null ) {
5669 this.$indicator
.attr( 'title', indicatorTitle
);
5671 this.$indicator
.removeAttr( 'title' );
5680 * Get the symbolic name of the indicator (e.g., ‘alert’ or ‘down’).
5682 * @return {string} Symbolic name of indicator
5684 OO
.ui
.mixin
.IndicatorElement
.prototype.getIndicator = function () {
5685 return this.indicator
;
5689 * Get the indicator title.
5691 * The title is displayed when a user moves the mouse over the indicator.
5693 * @return {string} Indicator title text
5695 OO
.ui
.mixin
.IndicatorElement
.prototype.getIndicatorTitle = function () {
5696 return this.indicatorTitle
;
5700 * LabelElement is often mixed into other classes to generate a label, which
5701 * helps identify the function of an interface element.
5702 * See the [OOjs UI documentation on MediaWiki] [1] for more information.
5704 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Labels
5710 * @param {Object} [config] Configuration options
5711 * @cfg {jQuery} [$label] The label element created by the class. If this
5712 * configuration is omitted, the label element will use a generated `<span>`.
5713 * @cfg {jQuery|string|Function|OO.ui.HtmlSnippet} [label] The label text. The label can be specified
5714 * as a plaintext string, a jQuery selection of elements, or a function that will produce a string
5715 * in the future. See the [OOjs UI documentation on MediaWiki] [2] for examples.
5716 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Labels
5717 * @cfg {boolean} [autoFitLabel=true] Fit the label to the width of the parent element.
5718 * The label will be truncated to fit if necessary.
5720 OO
.ui
.mixin
.LabelElement
= function OoUiMixinLabelElement( config
) {
5721 // Configuration initialization
5722 config
= config
|| {};
5727 this.autoFitLabel
= config
.autoFitLabel
=== undefined || !!config
.autoFitLabel
;
5730 this.setLabel( config
.label
|| this.constructor.static.label
);
5731 this.setLabelElement( config
.$label
|| $( '<span>' ) );
5736 OO
.initClass( OO
.ui
.mixin
.LabelElement
);
5741 * @event labelChange
5742 * @param {string} value
5745 /* Static Properties */
5748 * The label text. The label can be specified as a plaintext string, a function that will
5749 * produce a string in the future, or `null` for no label. The static value will
5750 * be overridden if a label is specified with the #label config option.
5754 * @property {string|Function|null}
5756 OO
.ui
.mixin
.LabelElement
.static.label
= null;
5761 * Set the label element.
5763 * If an element is already set, it will be cleaned up before setting up the new element.
5765 * @param {jQuery} $label Element to use as label
5767 OO
.ui
.mixin
.LabelElement
.prototype.setLabelElement = function ( $label
) {
5768 if ( this.$label
) {
5769 this.$label
.removeClass( 'oo-ui-labelElement-label' ).empty();
5772 this.$label
= $label
.addClass( 'oo-ui-labelElement-label' );
5773 this.setLabelContent( this.label
);
5779 * An empty string will result in the label being hidden. A string containing only whitespace will
5780 * be converted to a single ` `.
5782 * @param {jQuery|string|OO.ui.HtmlSnippet|Function|null} label Label nodes; text; a function that returns nodes or
5783 * text; or null for no label
5786 OO
.ui
.mixin
.LabelElement
.prototype.setLabel = function ( label
) {
5787 label
= typeof label
=== 'function' ? OO
.ui
.resolveMsg( label
) : label
;
5788 label
= ( ( typeof label
=== 'string' && label
.length
) || label
instanceof jQuery
|| label
instanceof OO
.ui
.HtmlSnippet
) ? label
: null;
5790 this.$element
.toggleClass( 'oo-ui-labelElement', !!label
);
5792 if ( this.label
!== label
) {
5793 if ( this.$label
) {
5794 this.setLabelContent( label
);
5797 this.emit( 'labelChange' );
5806 * @return {jQuery|string|Function|null} Label nodes; text; a function that returns nodes or
5807 * text; or null for no label
5809 OO
.ui
.mixin
.LabelElement
.prototype.getLabel = function () {
5818 OO
.ui
.mixin
.LabelElement
.prototype.fitLabel = function () {
5819 if ( this.$label
&& this.$label
.autoEllipsis
&& this.autoFitLabel
) {
5820 this.$label
.autoEllipsis( { hasSpan
: false, tooltip
: true } );
5827 * Set the content of the label.
5829 * Do not call this method until after the label element has been set by #setLabelElement.
5832 * @param {jQuery|string|Function|null} label Label nodes; text; a function that returns nodes or
5833 * text; or null for no label
5835 OO
.ui
.mixin
.LabelElement
.prototype.setLabelContent = function ( label
) {
5836 if ( typeof label
=== 'string' ) {
5837 if ( label
.match( /^\s*$/ ) ) {
5838 // Convert whitespace only string to a single non-breaking space
5839 this.$label
.html( ' ' );
5841 this.$label
.text( label
);
5843 } else if ( label
instanceof OO
.ui
.HtmlSnippet
) {
5844 this.$label
.html( label
.toString() );
5845 } else if ( label
instanceof jQuery
) {
5846 this.$label
.empty().append( label
);
5848 this.$label
.empty();
5853 * LookupElement is a mixin that creates a {@link OO.ui.FloatingMenuSelectWidget menu} of suggested values for
5854 * a {@link OO.ui.TextInputWidget text input widget}. Suggested values are based on the characters the user types
5855 * into the text input field and, in general, the menu is only displayed when the user types. If a suggested value is chosen
5856 * from the lookup menu, that value becomes the value of the input field.
5858 * Note that a new menu of suggested items is displayed when a value is chosen from the lookup menu. If this is
5859 * not the desired behavior, disable lookup menus with the #setLookupsDisabled method, then set the value, then
5860 * re-enable lookups.
5862 * See the [OOjs UI demos][1] for an example.
5864 * [1]: https://tools.wmflabs.org/oojs-ui/oojs-ui/demos/index.html#widgets-apex-vector-ltr
5870 * @param {Object} [config] Configuration options
5871 * @cfg {jQuery} [$overlay] Overlay for the lookup menu; defaults to relative positioning
5872 * @cfg {jQuery} [$container=this.$element] The container element. The lookup menu is rendered beneath the specified element.
5873 * @cfg {boolean} [allowSuggestionsWhenEmpty=false] Request and display a lookup menu when the text input is empty.
5874 * By default, the lookup menu is not generated and displayed until the user begins to type.
5876 OO
.ui
.mixin
.LookupElement
= function OoUiMixinLookupElement( config
) {
5877 // Configuration initialization
5878 config
= config
|| {};
5881 this.$overlay
= config
.$overlay
|| this.$element
;
5882 this.lookupMenu
= new OO
.ui
.FloatingMenuSelectWidget( {
5885 $container
: config
.$container
|| this.$element
5888 this.allowSuggestionsWhenEmpty
= config
.allowSuggestionsWhenEmpty
|| false;
5890 this.lookupCache
= {};
5891 this.lookupQuery
= null;
5892 this.lookupRequest
= null;
5893 this.lookupsDisabled
= false;
5894 this.lookupInputFocused
= false;
5898 focus
: this.onLookupInputFocus
.bind( this ),
5899 blur
: this.onLookupInputBlur
.bind( this ),
5900 mousedown
: this.onLookupInputMouseDown
.bind( this )
5902 this.connect( this, { change
: 'onLookupInputChange' } );
5903 this.lookupMenu
.connect( this, {
5904 toggle
: 'onLookupMenuToggle',
5905 choose
: 'onLookupMenuItemChoose'
5909 this.$element
.addClass( 'oo-ui-lookupElement' );
5910 this.lookupMenu
.$element
.addClass( 'oo-ui-lookupElement-menu' );
5911 this.$overlay
.append( this.lookupMenu
.$element
);
5917 * Handle input focus event.
5920 * @param {jQuery.Event} e Input focus event
5922 OO
.ui
.mixin
.LookupElement
.prototype.onLookupInputFocus = function () {
5923 this.lookupInputFocused
= true;
5924 this.populateLookupMenu();
5928 * Handle input blur event.
5931 * @param {jQuery.Event} e Input blur event
5933 OO
.ui
.mixin
.LookupElement
.prototype.onLookupInputBlur = function () {
5934 this.closeLookupMenu();
5935 this.lookupInputFocused
= false;
5939 * Handle input mouse down event.
5942 * @param {jQuery.Event} e Input mouse down event
5944 OO
.ui
.mixin
.LookupElement
.prototype.onLookupInputMouseDown = function () {
5945 // Only open the menu if the input was already focused.
5946 // This way we allow the user to open the menu again after closing it with Esc
5947 // by clicking in the input. Opening (and populating) the menu when initially
5948 // clicking into the input is handled by the focus handler.
5949 if ( this.lookupInputFocused
&& !this.lookupMenu
.isVisible() ) {
5950 this.populateLookupMenu();
5955 * Handle input change event.
5958 * @param {string} value New input value
5960 OO
.ui
.mixin
.LookupElement
.prototype.onLookupInputChange = function () {
5961 if ( this.lookupInputFocused
) {
5962 this.populateLookupMenu();
5967 * Handle the lookup menu being shown/hidden.
5970 * @param {boolean} visible Whether the lookup menu is now visible.
5972 OO
.ui
.mixin
.LookupElement
.prototype.onLookupMenuToggle = function ( visible
) {
5974 // When the menu is hidden, abort any active request and clear the menu.
5975 // This has to be done here in addition to closeLookupMenu(), because
5976 // MenuSelectWidget will close itself when the user presses Esc.
5977 this.abortLookupRequest();
5978 this.lookupMenu
.clearItems();
5983 * Handle menu item 'choose' event, updating the text input value to the value of the clicked item.
5986 * @param {OO.ui.MenuOptionWidget} item Selected item
5988 OO
.ui
.mixin
.LookupElement
.prototype.onLookupMenuItemChoose = function ( item
) {
5989 this.setValue( item
.getData() );
5996 * @return {OO.ui.FloatingMenuSelectWidget}
5998 OO
.ui
.mixin
.LookupElement
.prototype.getLookupMenu = function () {
5999 return this.lookupMenu
;
6003 * Disable or re-enable lookups.
6005 * When lookups are disabled, calls to #populateLookupMenu will be ignored.
6007 * @param {boolean} disabled Disable lookups
6009 OO
.ui
.mixin
.LookupElement
.prototype.setLookupsDisabled = function ( disabled
) {
6010 this.lookupsDisabled
= !!disabled
;
6014 * Open the menu. If there are no entries in the menu, this does nothing.
6019 OO
.ui
.mixin
.LookupElement
.prototype.openLookupMenu = function () {
6020 if ( !this.lookupMenu
.isEmpty() ) {
6021 this.lookupMenu
.toggle( true );
6027 * Close the menu, empty it, and abort any pending request.
6032 OO
.ui
.mixin
.LookupElement
.prototype.closeLookupMenu = function () {
6033 this.lookupMenu
.toggle( false );
6034 this.abortLookupRequest();
6035 this.lookupMenu
.clearItems();
6040 * Request menu items based on the input's current value, and when they arrive,
6041 * populate the menu with these items and show the menu.
6043 * If lookups have been disabled with #setLookupsDisabled, this function does nothing.
6048 OO
.ui
.mixin
.LookupElement
.prototype.populateLookupMenu = function () {
6050 value
= this.getValue();
6052 if ( this.lookupsDisabled
|| this.isReadOnly() ) {
6056 // If the input is empty, clear the menu, unless suggestions when empty are allowed.
6057 if ( !this.allowSuggestionsWhenEmpty
&& value
=== '' ) {
6058 this.closeLookupMenu();
6059 // Skip population if there is already a request pending for the current value
6060 } else if ( value
!== this.lookupQuery
) {
6061 this.getLookupMenuItems()
6062 .done( function ( items
) {
6063 widget
.lookupMenu
.clearItems();
6064 if ( items
.length
) {
6068 widget
.initializeLookupMenuSelection();
6070 widget
.lookupMenu
.toggle( false );
6073 .fail( function () {
6074 widget
.lookupMenu
.clearItems();
6082 * Highlight the first selectable item in the menu.
6087 OO
.ui
.mixin
.LookupElement
.prototype.initializeLookupMenuSelection = function () {
6088 if ( !this.lookupMenu
.getSelectedItem() ) {
6089 this.lookupMenu
.highlightItem( this.lookupMenu
.getFirstSelectableItem() );
6094 * Get lookup menu items for the current query.
6097 * @return {jQuery.Promise} Promise object which will be passed menu items as the first argument of
6098 * the done event. If the request was aborted to make way for a subsequent request, this promise
6099 * will not be rejected: it will remain pending forever.
6101 OO
.ui
.mixin
.LookupElement
.prototype.getLookupMenuItems = function () {
6103 value
= this.getValue(),
6104 deferred
= $.Deferred(),
6107 this.abortLookupRequest();
6108 if ( Object
.prototype.hasOwnProperty
.call( this.lookupCache
, value
) ) {
6109 deferred
.resolve( this.getLookupMenuOptionsFromData( this.lookupCache
[ value
] ) );
6112 this.lookupQuery
= value
;
6113 ourRequest
= this.lookupRequest
= this.getLookupRequest();
6115 .always( function () {
6116 // We need to pop pending even if this is an old request, otherwise
6117 // the widget will remain pending forever.
6118 // TODO: this assumes that an aborted request will fail or succeed soon after
6119 // being aborted, or at least eventually. It would be nice if we could popPending()
6120 // at abort time, but only if we knew that we hadn't already called popPending()
6121 // for that request.
6122 widget
.popPending();
6124 .done( function ( response
) {
6125 // If this is an old request (and aborting it somehow caused it to still succeed),
6126 // ignore its success completely
6127 if ( ourRequest
=== widget
.lookupRequest
) {
6128 widget
.lookupQuery
= null;
6129 widget
.lookupRequest
= null;
6130 widget
.lookupCache
[ value
] = widget
.getLookupCacheDataFromResponse( response
);
6131 deferred
.resolve( widget
.getLookupMenuOptionsFromData( widget
.lookupCache
[ value
] ) );
6134 .fail( function () {
6135 // If this is an old request (or a request failing because it's being aborted),
6136 // ignore its failure completely
6137 if ( ourRequest
=== widget
.lookupRequest
) {
6138 widget
.lookupQuery
= null;
6139 widget
.lookupRequest
= null;
6144 return deferred
.promise();
6148 * Abort the currently pending lookup request, if any.
6152 OO
.ui
.mixin
.LookupElement
.prototype.abortLookupRequest = function () {
6153 var oldRequest
= this.lookupRequest
;
6155 // First unset this.lookupRequest to the fail handler will notice
6156 // that the request is no longer current
6157 this.lookupRequest
= null;
6158 this.lookupQuery
= null;
6164 * Get a new request object of the current lookup query value.
6168 * @return {jQuery.Promise} jQuery AJAX object, or promise object with an .abort() method
6170 OO
.ui
.mixin
.LookupElement
.prototype.getLookupRequest = function () {
6171 // Stub, implemented in subclass
6176 * Pre-process data returned by the request from #getLookupRequest.
6178 * The return value of this function will be cached, and any further queries for the given value
6179 * will use the cache rather than doing API requests.
6183 * @param {Mixed} response Response from server
6184 * @return {Mixed} Cached result data
6186 OO
.ui
.mixin
.LookupElement
.prototype.getLookupCacheDataFromResponse = function () {
6187 // Stub, implemented in subclass
6192 * Get a list of menu option widgets from the (possibly cached) data returned by
6193 * #getLookupCacheDataFromResponse.
6197 * @param {Mixed} data Cached result data, usually an array
6198 * @return {OO.ui.MenuOptionWidget[]} Menu items
6200 OO
.ui
.mixin
.LookupElement
.prototype.getLookupMenuOptionsFromData = function () {
6201 // Stub, implemented in subclass
6206 * Set the read-only state of the widget.
6208 * This will also disable/enable the lookups functionality.
6210 * @param {boolean} readOnly Make input read-only
6213 OO
.ui
.mixin
.LookupElement
.prototype.setReadOnly = function ( readOnly
) {
6215 // Note: Calling #setReadOnly this way assumes this is mixed into an OO.ui.TextInputWidget
6216 OO
.ui
.TextInputWidget
.prototype.setReadOnly
.call( this, readOnly
);
6218 // During construction, #setReadOnly is called before the OO.ui.mixin.LookupElement constructor
6219 if ( this.isReadOnly() && this.lookupMenu
) {
6220 this.closeLookupMenu();
6227 * PopupElement is mixed into other classes to generate a {@link OO.ui.PopupWidget popup widget}.
6228 * A popup is a container for content. It is overlaid and positioned absolutely. By default, each
6229 * popup has an anchor, which is an arrow-like protrusion that points toward the popup’s origin.
6230 * See {@link OO.ui.PopupWidget PopupWidget} for an example.
6236 * @param {Object} [config] Configuration options
6237 * @cfg {Object} [popup] Configuration to pass to popup
6238 * @cfg {boolean} [popup.autoClose=true] Popup auto-closes when it loses focus
6240 OO
.ui
.mixin
.PopupElement
= function OoUiMixinPopupElement( config
) {
6241 // Configuration initialization
6242 config
= config
|| {};
6245 this.popup
= new OO
.ui
.PopupWidget( $.extend(
6246 { autoClose
: true },
6248 { $autoCloseIgnore
: this.$element
}
6257 * @return {OO.ui.PopupWidget} Popup widget
6259 OO
.ui
.mixin
.PopupElement
.prototype.getPopup = function () {
6264 * The FlaggedElement class is an attribute mixin, meaning that it is used to add
6265 * additional functionality to an element created by another class. The class provides
6266 * a ‘flags’ property assigned the name (or an array of names) of styling flags,
6267 * which are used to customize the look and feel of a widget to better describe its
6268 * importance and functionality.
6270 * The library currently contains the following styling flags for general use:
6272 * - **progressive**: Progressive styling is applied to convey that the widget will move the user forward in a process.
6273 * - **destructive**: Destructive styling is applied to convey that the widget will remove something.
6274 * - **constructive**: Constructive styling is applied to convey that the widget will create something.
6276 * The flags affect the appearance of the buttons:
6279 * // FlaggedElement is mixed into ButtonWidget to provide styling flags
6280 * var button1 = new OO.ui.ButtonWidget( {
6281 * label: 'Constructive',
6282 * flags: 'constructive'
6284 * var button2 = new OO.ui.ButtonWidget( {
6285 * label: 'Destructive',
6286 * flags: 'destructive'
6288 * var button3 = new OO.ui.ButtonWidget( {
6289 * label: 'Progressive',
6290 * flags: 'progressive'
6292 * $( 'body' ).append( button1.$element, button2.$element, button3.$element );
6294 * {@link OO.ui.ActionWidget ActionWidgets}, which are a special kind of button that execute an action, use these flags: **primary** and **safe**.
6295 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information.
6297 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Elements/Flagged
6303 * @param {Object} [config] Configuration options
6304 * @cfg {string|string[]} [flags] The name or names of the flags (e.g., 'constructive' or 'primary') to apply.
6305 * Please see the [OOjs UI documentation on MediaWiki] [2] for more information about available flags.
6306 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Elements/Flagged
6307 * @cfg {jQuery} [$flagged] The flagged element. By default,
6308 * the flagged functionality is applied to the element created by the class ($element).
6309 * If a different element is specified, the flagged functionality will be applied to it instead.
6311 OO
.ui
.mixin
.FlaggedElement
= function OoUiMixinFlaggedElement( config
) {
6312 // Configuration initialization
6313 config
= config
|| {};
6317 this.$flagged
= null;
6320 this.setFlags( config
.flags
);
6321 this.setFlaggedElement( config
.$flagged
|| this.$element
);
6328 * A flag event is emitted when the #clearFlags or #setFlags methods are used. The `changes`
6329 * parameter contains the name of each modified flag and indicates whether it was
6332 * @param {Object.<string,boolean>} changes Object keyed by flag name. A Boolean `true` indicates
6333 * that the flag was added, `false` that the flag was removed.
6339 * Set the flagged element.
6341 * This method is used to retarget a flagged mixin so that its functionality applies to the specified element.
6342 * If an element is already set, the method will remove the mixin’s effect on that element.
6344 * @param {jQuery} $flagged Element that should be flagged
6346 OO
.ui
.mixin
.FlaggedElement
.prototype.setFlaggedElement = function ( $flagged
) {
6347 var classNames
= Object
.keys( this.flags
).map( function ( flag
) {
6348 return 'oo-ui-flaggedElement-' + flag
;
6351 if ( this.$flagged
) {
6352 this.$flagged
.removeClass( classNames
);
6355 this.$flagged
= $flagged
.addClass( classNames
);
6359 * Check if the specified flag is set.
6361 * @param {string} flag Name of flag
6362 * @return {boolean} The flag is set
6364 OO
.ui
.mixin
.FlaggedElement
.prototype.hasFlag = function ( flag
) {
6365 // This may be called before the constructor, thus before this.flags is set
6366 return this.flags
&& ( flag
in this.flags
);
6370 * Get the names of all flags set.
6372 * @return {string[]} Flag names
6374 OO
.ui
.mixin
.FlaggedElement
.prototype.getFlags = function () {
6375 // This may be called before the constructor, thus before this.flags is set
6376 return Object
.keys( this.flags
|| {} );
6385 OO
.ui
.mixin
.FlaggedElement
.prototype.clearFlags = function () {
6386 var flag
, className
,
6389 classPrefix
= 'oo-ui-flaggedElement-';
6391 for ( flag
in this.flags
) {
6392 className
= classPrefix
+ flag
;
6393 changes
[ flag
] = false;
6394 delete this.flags
[ flag
];
6395 remove
.push( className
);
6398 if ( this.$flagged
) {
6399 this.$flagged
.removeClass( remove
.join( ' ' ) );
6402 this.updateThemeClasses();
6403 this.emit( 'flag', changes
);
6409 * Add one or more flags.
6411 * @param {string|string[]|Object.<string, boolean>} flags A flag name, an array of flag names,
6412 * or an object keyed by flag name with a boolean value that indicates whether the flag should
6413 * be added (`true`) or removed (`false`).
6417 OO
.ui
.mixin
.FlaggedElement
.prototype.setFlags = function ( flags
) {
6418 var i
, len
, flag
, className
,
6422 classPrefix
= 'oo-ui-flaggedElement-';
6424 if ( typeof flags
=== 'string' ) {
6425 className
= classPrefix
+ flags
;
6427 if ( !this.flags
[ flags
] ) {
6428 this.flags
[ flags
] = true;
6429 add
.push( className
);
6431 } else if ( Array
.isArray( flags
) ) {
6432 for ( i
= 0, len
= flags
.length
; i
< len
; i
++ ) {
6434 className
= classPrefix
+ flag
;
6436 if ( !this.flags
[ flag
] ) {
6437 changes
[ flag
] = true;
6438 this.flags
[ flag
] = true;
6439 add
.push( className
);
6442 } else if ( OO
.isPlainObject( flags
) ) {
6443 for ( flag
in flags
) {
6444 className
= classPrefix
+ flag
;
6445 if ( flags
[ flag
] ) {
6447 if ( !this.flags
[ flag
] ) {
6448 changes
[ flag
] = true;
6449 this.flags
[ flag
] = true;
6450 add
.push( className
);
6454 if ( this.flags
[ flag
] ) {
6455 changes
[ flag
] = false;
6456 delete this.flags
[ flag
];
6457 remove
.push( className
);
6463 if ( this.$flagged
) {
6465 .addClass( add
.join( ' ' ) )
6466 .removeClass( remove
.join( ' ' ) );
6469 this.updateThemeClasses();
6470 this.emit( 'flag', changes
);
6476 * TitledElement is mixed into other classes to provide a `title` attribute.
6477 * Titles are rendered by the browser and are made visible when the user moves
6478 * the mouse over the element. Titles are not visible on touch devices.
6481 * // TitledElement provides a 'title' attribute to the
6482 * // ButtonWidget class
6483 * var button = new OO.ui.ButtonWidget( {
6484 * label: 'Button with Title',
6485 * title: 'I am a button'
6487 * $( 'body' ).append( button.$element );
6493 * @param {Object} [config] Configuration options
6494 * @cfg {jQuery} [$titled] The element to which the `title` attribute is applied.
6495 * If this config is omitted, the title functionality is applied to $element, the
6496 * element created by the class.
6497 * @cfg {string|Function} [title] The title text or a function that returns text. If
6498 * this config is omitted, the value of the {@link #static-title static title} property is used.
6500 OO
.ui
.mixin
.TitledElement
= function OoUiMixinTitledElement( config
) {
6501 // Configuration initialization
6502 config
= config
|| {};
6505 this.$titled
= null;
6509 this.setTitle( config
.title
|| this.constructor.static.title
);
6510 this.setTitledElement( config
.$titled
|| this.$element
);
6515 OO
.initClass( OO
.ui
.mixin
.TitledElement
);
6517 /* Static Properties */
6520 * The title text, a function that returns text, or `null` for no title. The value of the static property
6521 * is overridden if the #title config option is used.
6525 * @property {string|Function|null}
6527 OO
.ui
.mixin
.TitledElement
.static.title
= null;
6532 * Set the titled element.
6534 * This method is used to retarget a titledElement mixin so that its functionality applies to the specified element.
6535 * If an element is already set, the mixin’s effect on that element is removed before the new element is set up.
6537 * @param {jQuery} $titled Element that should use the 'titled' functionality
6539 OO
.ui
.mixin
.TitledElement
.prototype.setTitledElement = function ( $titled
) {
6540 if ( this.$titled
) {
6541 this.$titled
.removeAttr( 'title' );
6544 this.$titled
= $titled
;
6546 this.$titled
.attr( 'title', this.title
);
6553 * @param {string|Function|null} title Title text, a function that returns text, or `null` for no title
6556 OO
.ui
.mixin
.TitledElement
.prototype.setTitle = function ( title
) {
6557 title
= typeof title
=== 'string' ? OO
.ui
.resolveMsg( title
) : null;
6559 if ( this.title
!== title
) {
6560 if ( this.$titled
) {
6561 if ( title
!== null ) {
6562 this.$titled
.attr( 'title', title
);
6564 this.$titled
.removeAttr( 'title' );
6576 * @return {string} Title string
6578 OO
.ui
.mixin
.TitledElement
.prototype.getTitle = function () {
6583 * Element that can be automatically clipped to visible boundaries.
6585 * Whenever the element's natural height changes, you have to call
6586 * {@link OO.ui.mixin.ClippableElement#clip} to make sure it's still
6587 * clipping correctly.
6589 * The dimensions of #$clippableContainer will be compared to the boundaries of the
6590 * nearest scrollable container. If #$clippableContainer is too tall and/or too wide,
6591 * then #$clippable will be given a fixed reduced height and/or width and will be made
6592 * scrollable. By default, #$clippable and #$clippableContainer are the same element,
6593 * but you can build a static footer by setting #$clippableContainer to an element that contains
6594 * #$clippable and the footer.
6600 * @param {Object} [config] Configuration options
6601 * @cfg {jQuery} [$clippable] Node to clip, assigned to #$clippable, omit to use #$element
6602 * @cfg {jQuery} [$clippableContainer] Node to keep visible, assigned to #$clippableContainer,
6603 * omit to use #$clippable
6605 OO
.ui
.mixin
.ClippableElement
= function OoUiMixinClippableElement( config
) {
6606 // Configuration initialization
6607 config
= config
|| {};
6610 this.$clippable
= null;
6611 this.$clippableContainer
= null;
6612 this.clipping
= false;
6613 this.clippedHorizontally
= false;
6614 this.clippedVertically
= false;
6615 this.$clippableScrollableContainer
= null;
6616 this.$clippableScroller
= null;
6617 this.$clippableWindow
= null;
6618 this.idealWidth
= null;
6619 this.idealHeight
= null;
6620 this.onClippableScrollHandler
= this.clip
.bind( this );
6621 this.onClippableWindowResizeHandler
= this.clip
.bind( this );
6624 if ( config
.$clippableContainer
) {
6625 this.setClippableContainer( config
.$clippableContainer
);
6627 this.setClippableElement( config
.$clippable
|| this.$element
);
6633 * Set clippable element.
6635 * If an element is already set, it will be cleaned up before setting up the new element.
6637 * @param {jQuery} $clippable Element to make clippable
6639 OO
.ui
.mixin
.ClippableElement
.prototype.setClippableElement = function ( $clippable
) {
6640 if ( this.$clippable
) {
6641 this.$clippable
.removeClass( 'oo-ui-clippableElement-clippable' );
6642 this.$clippable
.css( { width
: '', height
: '', overflowX
: '', overflowY
: '' } );
6643 OO
.ui
.Element
.static.reconsiderScrollbars( this.$clippable
[ 0 ] );
6646 this.$clippable
= $clippable
.addClass( 'oo-ui-clippableElement-clippable' );
6651 * Set clippable container.
6653 * This is the container that will be measured when deciding whether to clip. When clipping,
6654 * #$clippable will be resized in order to keep the clippable container fully visible.
6656 * If the clippable container is unset, #$clippable will be used.
6658 * @param {jQuery|null} $clippableContainer Container to keep visible, or null to unset
6660 OO
.ui
.mixin
.ClippableElement
.prototype.setClippableContainer = function ( $clippableContainer
) {
6661 this.$clippableContainer
= $clippableContainer
;
6662 if ( this.$clippable
) {
6670 * Do not turn clipping on until after the element is attached to the DOM and visible.
6672 * @param {boolean} [clipping] Enable clipping, omit to toggle
6675 OO
.ui
.mixin
.ClippableElement
.prototype.toggleClipping = function ( clipping
) {
6676 clipping
= clipping
=== undefined ? !this.clipping
: !!clipping
;
6678 if ( this.clipping
!== clipping
) {
6679 this.clipping
= clipping
;
6681 this.$clippableScrollableContainer
= $( this.getClosestScrollableElementContainer() );
6682 // If the clippable container is the root, we have to listen to scroll events and check
6683 // jQuery.scrollTop on the window because of browser inconsistencies
6684 this.$clippableScroller
= this.$clippableScrollableContainer
.is( 'html, body' ) ?
6685 $( OO
.ui
.Element
.static.getWindow( this.$clippableScrollableContainer
) ) :
6686 this.$clippableScrollableContainer
;
6687 this.$clippableScroller
.on( 'scroll', this.onClippableScrollHandler
);
6688 this.$clippableWindow
= $( this.getElementWindow() )
6689 .on( 'resize', this.onClippableWindowResizeHandler
);
6690 // Initial clip after visible
6693 this.$clippable
.css( { width
: '', height
: '', overflowX
: '', overflowY
: '' } );
6694 OO
.ui
.Element
.static.reconsiderScrollbars( this.$clippable
[ 0 ] );
6696 this.$clippableScrollableContainer
= null;
6697 this.$clippableScroller
.off( 'scroll', this.onClippableScrollHandler
);
6698 this.$clippableScroller
= null;
6699 this.$clippableWindow
.off( 'resize', this.onClippableWindowResizeHandler
);
6700 this.$clippableWindow
= null;
6708 * Check if the element will be clipped to fit the visible area of the nearest scrollable container.
6710 * @return {boolean} Element will be clipped to the visible area
6712 OO
.ui
.mixin
.ClippableElement
.prototype.isClipping = function () {
6713 return this.clipping
;
6717 * Check if the bottom or right of the element is being clipped by the nearest scrollable container.
6719 * @return {boolean} Part of the element is being clipped
6721 OO
.ui
.mixin
.ClippableElement
.prototype.isClipped = function () {
6722 return this.clippedHorizontally
|| this.clippedVertically
;
6726 * Check if the right of the element is being clipped by the nearest scrollable container.
6728 * @return {boolean} Part of the element is being clipped
6730 OO
.ui
.mixin
.ClippableElement
.prototype.isClippedHorizontally = function () {
6731 return this.clippedHorizontally
;
6735 * Check if the bottom of the element is being clipped by the nearest scrollable container.
6737 * @return {boolean} Part of the element is being clipped
6739 OO
.ui
.mixin
.ClippableElement
.prototype.isClippedVertically = function () {
6740 return this.clippedVertically
;
6744 * Set the ideal size. These are the dimensions the element will have when it's not being clipped.
6746 * @param {number|string} [width] Width as a number of pixels or CSS string with unit suffix
6747 * @param {number|string} [height] Height as a number of pixels or CSS string with unit suffix
6749 OO
.ui
.mixin
.ClippableElement
.prototype.setIdealSize = function ( width
, height
) {
6750 this.idealWidth
= width
;
6751 this.idealHeight
= height
;
6753 if ( !this.clipping
) {
6754 // Update dimensions
6755 this.$clippable
.css( { width
: width
, height
: height
} );
6757 // While clipping, idealWidth and idealHeight are not considered
6761 * Clip element to visible boundaries and allow scrolling when needed. Call this method when
6762 * the element's natural height changes.
6764 * Element will be clipped the bottom or right of the element is within 10px of the edge of, or
6765 * overlapped by, the visible area of the nearest scrollable container.
6769 OO
.ui
.mixin
.ClippableElement
.prototype.clip = function () {
6770 var $container
, extraHeight
, extraWidth
, ccOffset
,
6771 $scrollableContainer
, scOffset
, scHeight
, scWidth
,
6772 ccWidth
, scrollerIsWindow
, scrollTop
, scrollLeft
,
6773 desiredWidth
, desiredHeight
, allotedWidth
, allotedHeight
,
6774 naturalWidth
, naturalHeight
, clipWidth
, clipHeight
,
6775 buffer
= 7; // Chosen by fair dice roll
6777 if ( !this.clipping
) {
6778 // this.$clippableScrollableContainer and this.$clippableWindow are null, so the below will fail
6782 $container
= this.$clippableContainer
|| this.$clippable
;
6783 extraHeight
= $container
.outerHeight() - this.$clippable
.outerHeight();
6784 extraWidth
= $container
.outerWidth() - this.$clippable
.outerWidth();
6785 ccOffset
= $container
.offset();
6786 $scrollableContainer
= this.$clippableScrollableContainer
.is( 'html, body' ) ?
6787 this.$clippableWindow
: this.$clippableScrollableContainer
;
6788 scOffset
= $scrollableContainer
.offset() || { top
: 0, left
: 0 };
6789 scHeight
= $scrollableContainer
.innerHeight() - buffer
;
6790 scWidth
= $scrollableContainer
.innerWidth() - buffer
;
6791 ccWidth
= $container
.outerWidth() + buffer
;
6792 scrollerIsWindow
= this.$clippableScroller
[ 0 ] === this.$clippableWindow
[ 0 ];
6793 scrollTop
= scrollerIsWindow
? this.$clippableScroller
.scrollTop() : 0;
6794 scrollLeft
= scrollerIsWindow
? this.$clippableScroller
.scrollLeft() : 0;
6795 desiredWidth
= ccOffset
.left
< 0 ?
6796 ccWidth
+ ccOffset
.left
:
6797 ( scOffset
.left
+ scrollLeft
+ scWidth
) - ccOffset
.left
;
6798 desiredHeight
= ( scOffset
.top
+ scrollTop
+ scHeight
) - ccOffset
.top
;
6799 allotedWidth
= desiredWidth
- extraWidth
;
6800 allotedHeight
= desiredHeight
- extraHeight
;
6801 naturalWidth
= this.$clippable
.prop( 'scrollWidth' );
6802 naturalHeight
= this.$clippable
.prop( 'scrollHeight' );
6803 clipWidth
= allotedWidth
< naturalWidth
;
6804 clipHeight
= allotedHeight
< naturalHeight
;
6807 this.$clippable
.css( { overflowX
: 'scroll', width
: Math
.max( 0, allotedWidth
) } );
6809 this.$clippable
.css( { width
: this.idealWidth
? this.idealWidth
- extraWidth
: '', overflowX
: '' } );
6812 this.$clippable
.css( { overflowY
: 'scroll', height
: Math
.max( 0, allotedHeight
) } );
6814 this.$clippable
.css( { height
: this.idealHeight
? this.idealHeight
- extraHeight
: '', overflowY
: '' } );
6817 // If we stopped clipping in at least one of the dimensions
6818 if ( ( this.clippedHorizontally
&& !clipWidth
) || ( this.clippedVertically
&& !clipHeight
) ) {
6819 OO
.ui
.Element
.static.reconsiderScrollbars( this.$clippable
[ 0 ] );
6822 this.clippedHorizontally
= clipWidth
;
6823 this.clippedVertically
= clipHeight
;
6829 * Element that will stick under a specified container, even when it is inserted elsewhere in the
6830 * document (for example, in a OO.ui.Window's $overlay).
6832 * The elements's position is automatically calculated and maintained when window is resized or the
6833 * page is scrolled. If you reposition the container manually, you have to call #position to make
6834 * sure the element is still placed correctly.
6836 * As positioning is only possible when both the element and the container are attached to the DOM
6837 * and visible, it's only done after you call #togglePositioning. You might want to do this inside
6838 * the #toggle method to display a floating popup, for example.
6844 * @param {Object} [config] Configuration options
6845 * @cfg {jQuery} [$floatable] Node to position, assigned to #$floatable, omit to use #$element
6846 * @cfg {jQuery} [$floatableContainer] Node to position below
6848 OO
.ui
.mixin
.FloatableElement
= function OoUiMixinFloatableElement( config
) {
6849 // Configuration initialization
6850 config
= config
|| {};
6853 this.$floatable
= null;
6854 this.$floatableContainer
= null;
6855 this.$floatableWindow
= null;
6856 this.$floatableClosestScrollable
= null;
6857 this.onFloatableScrollHandler
= this.position
.bind( this );
6858 this.onFloatableWindowResizeHandler
= this.position
.bind( this );
6861 this.setFloatableContainer( config
.$floatableContainer
);
6862 this.setFloatableElement( config
.$floatable
|| this.$element
);
6868 * Set floatable element.
6870 * If an element is already set, it will be cleaned up before setting up the new element.
6872 * @param {jQuery} $floatable Element to make floatable
6874 OO
.ui
.mixin
.FloatableElement
.prototype.setFloatableElement = function ( $floatable
) {
6875 if ( this.$floatable
) {
6876 this.$floatable
.removeClass( 'oo-ui-floatableElement-floatable' );
6877 this.$floatable
.css( { left
: '', top
: '' } );
6880 this.$floatable
= $floatable
.addClass( 'oo-ui-floatableElement-floatable' );
6885 * Set floatable container.
6887 * The element will be always positioned under the specified container.
6889 * @param {jQuery|null} $floatableContainer Container to keep visible, or null to unset
6891 OO
.ui
.mixin
.FloatableElement
.prototype.setFloatableContainer = function ( $floatableContainer
) {
6892 this.$floatableContainer
= $floatableContainer
;
6893 if ( this.$floatable
) {
6899 * Toggle positioning.
6901 * Do not turn positioning on until after the element is attached to the DOM and visible.
6903 * @param {boolean} [positioning] Enable positioning, omit to toggle
6906 OO
.ui
.mixin
.FloatableElement
.prototype.togglePositioning = function ( positioning
) {
6907 var closestScrollableOfContainer
, closestScrollableOfFloatable
;
6909 positioning
= positioning
=== undefined ? !this.positioning
: !!positioning
;
6911 if ( this.positioning
!== positioning
) {
6912 this.positioning
= positioning
;
6914 closestScrollableOfContainer
= OO
.ui
.Element
.static.getClosestScrollableContainer( this.$floatableContainer
[ 0 ] );
6915 closestScrollableOfFloatable
= OO
.ui
.Element
.static.getClosestScrollableContainer( this.$floatable
[ 0 ] );
6916 if ( closestScrollableOfContainer
!== closestScrollableOfFloatable
) {
6917 // If the scrollable is the root, we have to listen to scroll events
6918 // on the window because of browser inconsistencies (or do we? someone should verify this)
6919 if ( $( closestScrollableOfContainer
).is( 'html, body' ) ) {
6920 closestScrollableOfContainer
= OO
.ui
.Element
.static.getWindow( closestScrollableOfContainer
);
6924 if ( positioning
) {
6925 this.$floatableWindow
= $( this.getElementWindow() );
6926 this.$floatableWindow
.on( 'resize', this.onFloatableWindowResizeHandler
);
6928 if ( closestScrollableOfContainer
!== closestScrollableOfFloatable
) {
6929 this.$floatableClosestScrollable
= $( closestScrollableOfContainer
);
6930 this.$floatableClosestScrollable
.on( 'scroll', this.onFloatableScrollHandler
);
6933 // Initial position after visible
6936 if ( this.$floatableWindow
) {
6937 this.$floatableWindow
.off( 'resize', this.onFloatableWindowResizeHandler
);
6938 this.$floatableWindow
= null;
6941 if ( this.$floatableClosestScrollable
) {
6942 this.$floatableClosestScrollable
.off( 'scroll', this.onFloatableScrollHandler
);
6943 this.$floatableClosestScrollable
= null;
6946 this.$floatable
.css( { left
: '', top
: '' } );
6954 * Position the floatable below its container.
6956 * This should only be done when both of them are attached to the DOM and visible.
6960 OO
.ui
.mixin
.FloatableElement
.prototype.position = function () {
6963 if ( !this.positioning
) {
6967 pos
= OO
.ui
.Element
.static.getRelativePosition( this.$floatableContainer
, this.$floatable
.offsetParent() );
6969 // Position under container
6970 pos
.top
+= this.$floatableContainer
.height();
6971 this.$floatable
.css( pos
);
6973 // We updated the position, so re-evaluate the clipping state.
6974 // (ClippableElement does not listen to 'scroll' events on $floatableContainer's parent, and so
6975 // will not notice the need to update itself.)
6976 // TODO: This is terrible, we shouldn't need to know about ClippableElement at all here. Why does
6977 // it not listen to the right events in the right places?
6986 * AccessKeyedElement is mixed into other classes to provide an `accesskey` attribute.
6987 * Accesskeys allow an user to go to a specific element by using
6988 * a shortcut combination of a browser specific keys + the key
6992 * // AccessKeyedElement provides an 'accesskey' attribute to the
6993 * // ButtonWidget class
6994 * var button = new OO.ui.ButtonWidget( {
6995 * label: 'Button with Accesskey',
6998 * $( 'body' ).append( button.$element );
7004 * @param {Object} [config] Configuration options
7005 * @cfg {jQuery} [$accessKeyed] The element to which the `accesskey` attribute is applied.
7006 * If this config is omitted, the accesskey functionality is applied to $element, the
7007 * element created by the class.
7008 * @cfg {string|Function} [accessKey] The key or a function that returns the key. If
7009 * this config is omitted, no accesskey will be added.
7011 OO
.ui
.mixin
.AccessKeyedElement
= function OoUiMixinAccessKeyedElement( config
) {
7012 // Configuration initialization
7013 config
= config
|| {};
7016 this.$accessKeyed
= null;
7017 this.accessKey
= null;
7020 this.setAccessKey( config
.accessKey
|| null );
7021 this.setAccessKeyedElement( config
.$accessKeyed
|| this.$element
);
7026 OO
.initClass( OO
.ui
.mixin
.AccessKeyedElement
);
7028 /* Static Properties */
7031 * The access key, a function that returns a key, or `null` for no accesskey.
7035 * @property {string|Function|null}
7037 OO
.ui
.mixin
.AccessKeyedElement
.static.accessKey
= null;
7042 * Set the accesskeyed element.
7044 * This method is used to retarget a AccessKeyedElement mixin so that its functionality applies to the specified element.
7045 * If an element is already set, the mixin's effect on that element is removed before the new element is set up.
7047 * @param {jQuery} $accessKeyed Element that should use the 'accesskeyes' functionality
7049 OO
.ui
.mixin
.AccessKeyedElement
.prototype.setAccessKeyedElement = function ( $accessKeyed
) {
7050 if ( this.$accessKeyed
) {
7051 this.$accessKeyed
.removeAttr( 'accesskey' );
7054 this.$accessKeyed
= $accessKeyed
;
7055 if ( this.accessKey
) {
7056 this.$accessKeyed
.attr( 'accesskey', this.accessKey
);
7063 * @param {string|Function|null} accesskey Key, a function that returns a key, or `null` for no accesskey
7066 OO
.ui
.mixin
.AccessKeyedElement
.prototype.setAccessKey = function ( accessKey
) {
7067 accessKey
= typeof accessKey
=== 'string' ? OO
.ui
.resolveMsg( accessKey
) : null;
7069 if ( this.accessKey
!== accessKey
) {
7070 if ( this.$accessKeyed
) {
7071 if ( accessKey
!== null ) {
7072 this.$accessKeyed
.attr( 'accesskey', accessKey
);
7074 this.$accessKeyed
.removeAttr( 'accesskey' );
7077 this.accessKey
= accessKey
;
7086 * @return {string} accessKey string
7088 OO
.ui
.mixin
.AccessKeyedElement
.prototype.getAccessKey = function () {
7089 return this.accessKey
;
7093 * Tools, together with {@link OO.ui.ToolGroup toolgroups}, constitute {@link OO.ui.Toolbar toolbars}.
7094 * Each tool is configured with a static name, title, and icon and is customized with the command to carry
7095 * out when the tool is selected. Tools must also be registered with a {@link OO.ui.ToolFactory tool factory},
7096 * which creates the tools on demand.
7098 * Tools are added to toolgroups ({@link OO.ui.ListToolGroup ListToolGroup},
7099 * {@link OO.ui.BarToolGroup BarToolGroup}, or {@link OO.ui.MenuToolGroup MenuToolGroup}), which determine how
7100 * the tool is displayed in the toolbar. See {@link OO.ui.Toolbar toolbars} for an example.
7102 * For more information, please see the [OOjs UI documentation on MediaWiki][1].
7103 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
7107 * @extends OO.ui.Widget
7108 * @mixins OO.ui.mixin.IconElement
7109 * @mixins OO.ui.mixin.FlaggedElement
7110 * @mixins OO.ui.mixin.TabIndexedElement
7113 * @param {OO.ui.ToolGroup} toolGroup
7114 * @param {Object} [config] Configuration options
7115 * @cfg {string|Function} [title] Title text or a function that returns text. If this config is omitted, the value of
7116 * the {@link #static-title static title} property is used.
7118 * The title is used in different ways depending on the type of toolgroup that contains the tool. The
7119 * 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
7120 * part of a {@link OO.ui.ListToolGroup list} or {@link OO.ui.MenuToolGroup menu} toolgroup.
7122 * For bar toolgroups, a description of the accelerator key is appended to the title if an accelerator key
7123 * is associated with an action by the same name as the tool and accelerator functionality has been added to the application.
7124 * To add accelerator key functionality, you must subclass OO.ui.Toolbar and override the {@link OO.ui.Toolbar#getToolAccelerator getToolAccelerator} method.
7126 OO
.ui
.Tool
= function OoUiTool( toolGroup
, config
) {
7127 // Allow passing positional parameters inside the config object
7128 if ( OO
.isPlainObject( toolGroup
) && config
=== undefined ) {
7130 toolGroup
= config
.toolGroup
;
7133 // Configuration initialization
7134 config
= config
|| {};
7136 // Parent constructor
7137 OO
.ui
.Tool
.parent
.call( this, config
);
7140 this.toolGroup
= toolGroup
;
7141 this.toolbar
= this.toolGroup
.getToolbar();
7142 this.active
= false;
7143 this.$title
= $( '<span>' );
7144 this.$accel
= $( '<span>' );
7145 this.$link
= $( '<a>' );
7148 // Mixin constructors
7149 OO
.ui
.mixin
.IconElement
.call( this, config
);
7150 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
7151 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$link
} ) );
7154 this.toolbar
.connect( this, { updateState
: 'onUpdateState' } );
7157 this.$title
.addClass( 'oo-ui-tool-title' );
7159 .addClass( 'oo-ui-tool-accel' )
7161 // This may need to be changed if the key names are ever localized,
7162 // but for now they are essentially written in English
7167 .addClass( 'oo-ui-tool-link' )
7168 .append( this.$icon
, this.$title
, this.$accel
)
7169 .attr( 'role', 'button' );
7171 .data( 'oo-ui-tool', this )
7173 'oo-ui-tool ' + 'oo-ui-tool-name-' +
7174 this.constructor.static.name
.replace( /^([^\/]+)\/([^\/]+).*$/, '$1-$2' )
7176 .toggleClass( 'oo-ui-tool-with-label', this.constructor.static.displayBothIconAndLabel
)
7177 .append( this.$link
);
7178 this.setTitle( config
.title
|| this.constructor.static.title
);
7183 OO
.inheritClass( OO
.ui
.Tool
, OO
.ui
.Widget
);
7184 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.mixin
.IconElement
);
7185 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.mixin
.FlaggedElement
);
7186 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.mixin
.TabIndexedElement
);
7188 /* Static Properties */
7194 OO
.ui
.Tool
.static.tagName
= 'span';
7197 * Symbolic name of tool.
7199 * The symbolic name is used internally to register the tool with a {@link OO.ui.ToolFactory ToolFactory}. It can
7200 * also be used when adding tools to toolgroups.
7205 * @property {string}
7207 OO
.ui
.Tool
.static.name
= '';
7210 * Symbolic name of the group.
7212 * The group name is used to associate tools with each other so that they can be selected later by
7213 * a {@link OO.ui.ToolGroup toolgroup}.
7218 * @property {string}
7220 OO
.ui
.Tool
.static.group
= '';
7223 * 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.
7228 * @property {string|Function}
7230 OO
.ui
.Tool
.static.title
= '';
7233 * Display both icon and label when the tool is used in a {@link OO.ui.BarToolGroup bar} toolgroup.
7234 * Normally only the icon is displayed, or only the label if no icon is given.
7238 * @property {boolean}
7240 OO
.ui
.Tool
.static.displayBothIconAndLabel
= false;
7243 * Add tool to catch-all groups automatically.
7245 * A catch-all group, which contains all tools that do not currently belong to a toolgroup,
7246 * can be included in a toolgroup using the wildcard selector, an asterisk (*).
7250 * @property {boolean}
7252 OO
.ui
.Tool
.static.autoAddToCatchall
= true;
7255 * Add tool to named groups automatically.
7257 * By default, tools that are configured with a static ‘group’ property are added
7258 * to that group and will be selected when the symbolic name of the group is specified (e.g., when
7259 * toolgroups include tools by group name).
7262 * @property {boolean}
7265 OO
.ui
.Tool
.static.autoAddToGroup
= true;
7268 * Check if this tool is compatible with given data.
7270 * This is a stub that can be overriden to provide support for filtering tools based on an
7271 * arbitrary piece of information (e.g., where the cursor is in a document). The implementation
7272 * must also call this method so that the compatibility check can be performed.
7276 * @param {Mixed} data Data to check
7277 * @return {boolean} Tool can be used with data
7279 OO
.ui
.Tool
.static.isCompatibleWith = function () {
7286 * Handle the toolbar state being updated.
7288 * This is an abstract method that must be overridden in a concrete subclass.
7293 OO
.ui
.Tool
.prototype.onUpdateState = function () {
7295 'OO.ui.Tool.onUpdateState not implemented in this subclass:' + this.constructor
7300 * Handle the tool being selected.
7302 * This is an abstract method that must be overridden in a concrete subclass.
7307 OO
.ui
.Tool
.prototype.onSelect = function () {
7309 'OO.ui.Tool.onSelect not implemented in this subclass:' + this.constructor
7314 * Check if the tool is active.
7316 * Tools become active when their #onSelect or #onUpdateState handlers change them to appear pressed
7317 * with the #setActive method. Additional CSS is applied to the tool to reflect the active state.
7319 * @return {boolean} Tool is active
7321 OO
.ui
.Tool
.prototype.isActive = function () {
7326 * Make the tool appear active or inactive.
7328 * This method should be called within #onSelect or #onUpdateState event handlers to make the tool
7329 * appear pressed or not.
7331 * @param {boolean} state Make tool appear active
7333 OO
.ui
.Tool
.prototype.setActive = function ( state
) {
7334 this.active
= !!state
;
7335 if ( this.active
) {
7336 this.$element
.addClass( 'oo-ui-tool-active' );
7338 this.$element
.removeClass( 'oo-ui-tool-active' );
7343 * Set the tool #title.
7345 * @param {string|Function} title Title text or a function that returns text
7348 OO
.ui
.Tool
.prototype.setTitle = function ( title
) {
7349 this.title
= OO
.ui
.resolveMsg( title
);
7355 * Get the tool #title.
7357 * @return {string} Title text
7359 OO
.ui
.Tool
.prototype.getTitle = function () {
7364 * Get the tool's symbolic name.
7366 * @return {string} Symbolic name of tool
7368 OO
.ui
.Tool
.prototype.getName = function () {
7369 return this.constructor.static.name
;
7375 OO
.ui
.Tool
.prototype.updateTitle = function () {
7376 var titleTooltips
= this.toolGroup
.constructor.static.titleTooltips
,
7377 accelTooltips
= this.toolGroup
.constructor.static.accelTooltips
,
7378 accel
= this.toolbar
.getToolAccelerator( this.constructor.static.name
),
7381 this.$title
.text( this.title
);
7382 this.$accel
.text( accel
);
7384 if ( titleTooltips
&& typeof this.title
=== 'string' && this.title
.length
) {
7385 tooltipParts
.push( this.title
);
7387 if ( accelTooltips
&& typeof accel
=== 'string' && accel
.length
) {
7388 tooltipParts
.push( accel
);
7390 if ( tooltipParts
.length
) {
7391 this.$link
.attr( 'title', tooltipParts
.join( ' ' ) );
7393 this.$link
.removeAttr( 'title' );
7400 * Destroying the tool removes all event handlers and the tool’s DOM elements.
7401 * Call this method whenever you are done using a tool.
7403 OO
.ui
.Tool
.prototype.destroy = function () {
7404 this.toolbar
.disconnect( this );
7405 this.$element
.remove();
7409 * Toolbars are complex interface components that permit users to easily access a variety
7410 * of {@link OO.ui.Tool tools} (e.g., formatting commands) and actions, which are additional commands that are
7411 * part of the toolbar, but not configured as tools.
7413 * Individual tools are customized and then registered with a {@link OO.ui.ToolFactory tool factory}, which creates
7414 * the tools on demand. Each tool has a symbolic name (used when registering the tool), a title (e.g., ‘Insert
7415 * picture’), and an icon.
7417 * Individual tools are organized in {@link OO.ui.ToolGroup toolgroups}, which can be {@link OO.ui.MenuToolGroup menus}
7418 * of tools, {@link OO.ui.ListToolGroup lists} of tools, or a single {@link OO.ui.BarToolGroup bar} of tools.
7419 * The arrangement and order of the toolgroups is customized when the toolbar is set up. Tools can be presented in
7420 * any order, but each can only appear once in the toolbar.
7422 * The following is an example of a basic toolbar.
7425 * // Example of a toolbar
7426 * // Create the toolbar
7427 * var toolFactory = new OO.ui.ToolFactory();
7428 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
7429 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
7431 * // We will be placing status text in this element when tools are used
7432 * var $area = $( '<p>' ).text( 'Toolbar example' );
7434 * // Define the tools that we're going to place in our toolbar
7436 * // Create a class inheriting from OO.ui.Tool
7437 * function PictureTool() {
7438 * PictureTool.parent.apply( this, arguments );
7440 * OO.inheritClass( PictureTool, OO.ui.Tool );
7441 * // Each tool must have a 'name' (used as an internal identifier, see later) and at least one
7442 * // of 'icon' and 'title' (displayed icon and text).
7443 * PictureTool.static.name = 'picture';
7444 * PictureTool.static.icon = 'picture';
7445 * PictureTool.static.title = 'Insert picture';
7446 * // Defines the action that will happen when this tool is selected (clicked).
7447 * PictureTool.prototype.onSelect = function () {
7448 * $area.text( 'Picture tool clicked!' );
7449 * // Never display this tool as "active" (selected).
7450 * this.setActive( false );
7452 * // Make this tool available in our toolFactory and thus our toolbar
7453 * toolFactory.register( PictureTool );
7455 * // Register two more tools, nothing interesting here
7456 * function SettingsTool() {
7457 * SettingsTool.parent.apply( this, arguments );
7459 * OO.inheritClass( SettingsTool, OO.ui.Tool );
7460 * SettingsTool.static.name = 'settings';
7461 * SettingsTool.static.icon = 'settings';
7462 * SettingsTool.static.title = 'Change settings';
7463 * SettingsTool.prototype.onSelect = function () {
7464 * $area.text( 'Settings tool clicked!' );
7465 * this.setActive( false );
7467 * toolFactory.register( SettingsTool );
7469 * // Register two more tools, nothing interesting here
7470 * function StuffTool() {
7471 * StuffTool.parent.apply( this, arguments );
7473 * OO.inheritClass( StuffTool, OO.ui.Tool );
7474 * StuffTool.static.name = 'stuff';
7475 * StuffTool.static.icon = 'ellipsis';
7476 * StuffTool.static.title = 'More stuff';
7477 * StuffTool.prototype.onSelect = function () {
7478 * $area.text( 'More stuff tool clicked!' );
7479 * this.setActive( false );
7481 * toolFactory.register( StuffTool );
7483 * // This is a PopupTool. Rather than having a custom 'onSelect' action, it will display a
7484 * // little popup window (a PopupWidget).
7485 * function HelpTool( toolGroup, config ) {
7486 * OO.ui.PopupTool.call( this, toolGroup, $.extend( { popup: {
7491 * this.popup.$body.append( '<p>I am helpful!</p>' );
7493 * OO.inheritClass( HelpTool, OO.ui.PopupTool );
7494 * HelpTool.static.name = 'help';
7495 * HelpTool.static.icon = 'help';
7496 * HelpTool.static.title = 'Help';
7497 * toolFactory.register( HelpTool );
7499 * // Finally define which tools and in what order appear in the toolbar. Each tool may only be
7500 * // used once (but not all defined tools must be used).
7503 * // 'bar' tool groups display tools' icons only, side-by-side.
7505 * include: [ 'picture', 'help' ]
7508 * // 'list' tool groups display both the titles and icons, in a dropdown list.
7510 * indicator: 'down',
7512 * include: [ 'settings', 'stuff' ]
7514 * // Note how the tools themselves are toolgroup-agnostic - the same tool can be displayed
7515 * // either in a 'list' or a 'bar'. There is a 'menu' tool group too, not showcased here,
7516 * // since it's more complicated to use. (See the next example snippet on this page.)
7519 * // Create some UI around the toolbar and place it in the document
7520 * var frame = new OO.ui.PanelLayout( {
7524 * var contentFrame = new OO.ui.PanelLayout( {
7528 * frame.$element.append(
7530 * contentFrame.$element.append( $area )
7532 * $( 'body' ).append( frame.$element );
7534 * // Here is where the toolbar is actually built. This must be done after inserting it into the
7536 * toolbar.initialize();
7538 * The following example extends the previous one to illustrate 'menu' toolgroups and the usage of
7539 * 'updateState' event.
7542 * // Create the toolbar
7543 * var toolFactory = new OO.ui.ToolFactory();
7544 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
7545 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
7547 * // We will be placing status text in this element when tools are used
7548 * var $area = $( '<p>' ).text( 'Toolbar example' );
7550 * // Define the tools that we're going to place in our toolbar
7552 * // Create a class inheriting from OO.ui.Tool
7553 * function PictureTool() {
7554 * PictureTool.parent.apply( this, arguments );
7556 * OO.inheritClass( PictureTool, OO.ui.Tool );
7557 * // Each tool must have a 'name' (used as an internal identifier, see later) and at least one
7558 * // of 'icon' and 'title' (displayed icon and text).
7559 * PictureTool.static.name = 'picture';
7560 * PictureTool.static.icon = 'picture';
7561 * PictureTool.static.title = 'Insert picture';
7562 * // Defines the action that will happen when this tool is selected (clicked).
7563 * PictureTool.prototype.onSelect = function () {
7564 * $area.text( 'Picture tool clicked!' );
7565 * // Never display this tool as "active" (selected).
7566 * this.setActive( false );
7568 * // The toolbar can be synchronized with the state of some external stuff, like a text
7569 * // editor's editing area, highlighting the tools (e.g. a 'bold' tool would be shown as active
7570 * // when the text cursor was inside bolded text). Here we simply disable this feature.
7571 * PictureTool.prototype.onUpdateState = function () {
7573 * // Make this tool available in our toolFactory and thus our toolbar
7574 * toolFactory.register( PictureTool );
7576 * // Register two more tools, nothing interesting here
7577 * function SettingsTool() {
7578 * SettingsTool.parent.apply( this, arguments );
7579 * this.reallyActive = false;
7581 * OO.inheritClass( SettingsTool, OO.ui.Tool );
7582 * SettingsTool.static.name = 'settings';
7583 * SettingsTool.static.icon = 'settings';
7584 * SettingsTool.static.title = 'Change settings';
7585 * SettingsTool.prototype.onSelect = function () {
7586 * $area.text( 'Settings tool clicked!' );
7587 * // Toggle the active state on each click
7588 * this.reallyActive = !this.reallyActive;
7589 * this.setActive( this.reallyActive );
7590 * // To update the menu label
7591 * this.toolbar.emit( 'updateState' );
7593 * SettingsTool.prototype.onUpdateState = function () {
7595 * toolFactory.register( SettingsTool );
7597 * // Register two more tools, nothing interesting here
7598 * function StuffTool() {
7599 * StuffTool.parent.apply( this, arguments );
7600 * this.reallyActive = false;
7602 * OO.inheritClass( StuffTool, OO.ui.Tool );
7603 * StuffTool.static.name = 'stuff';
7604 * StuffTool.static.icon = 'ellipsis';
7605 * StuffTool.static.title = 'More stuff';
7606 * StuffTool.prototype.onSelect = function () {
7607 * $area.text( 'More stuff tool clicked!' );
7608 * // Toggle the active state on each click
7609 * this.reallyActive = !this.reallyActive;
7610 * this.setActive( this.reallyActive );
7611 * // To update the menu label
7612 * this.toolbar.emit( 'updateState' );
7614 * StuffTool.prototype.onUpdateState = function () {
7616 * toolFactory.register( StuffTool );
7618 * // This is a PopupTool. Rather than having a custom 'onSelect' action, it will display a
7619 * // little popup window (a PopupWidget). 'onUpdateState' is also already implemented.
7620 * function HelpTool( toolGroup, config ) {
7621 * OO.ui.PopupTool.call( this, toolGroup, $.extend( { popup: {
7626 * this.popup.$body.append( '<p>I am helpful!</p>' );
7628 * OO.inheritClass( HelpTool, OO.ui.PopupTool );
7629 * HelpTool.static.name = 'help';
7630 * HelpTool.static.icon = 'help';
7631 * HelpTool.static.title = 'Help';
7632 * toolFactory.register( HelpTool );
7634 * // Finally define which tools and in what order appear in the toolbar. Each tool may only be
7635 * // used once (but not all defined tools must be used).
7638 * // 'bar' tool groups display tools' icons only, side-by-side.
7640 * include: [ 'picture', 'help' ]
7643 * // 'menu' tool groups display both the titles and icons, in a dropdown menu.
7644 * // Menu label indicates which items are selected.
7646 * indicator: 'down',
7647 * include: [ 'settings', 'stuff' ]
7651 * // Create some UI around the toolbar and place it in the document
7652 * var frame = new OO.ui.PanelLayout( {
7656 * var contentFrame = new OO.ui.PanelLayout( {
7660 * frame.$element.append(
7662 * contentFrame.$element.append( $area )
7664 * $( 'body' ).append( frame.$element );
7666 * // Here is where the toolbar is actually built. This must be done after inserting it into the
7668 * toolbar.initialize();
7669 * toolbar.emit( 'updateState' );
7672 * @extends OO.ui.Element
7673 * @mixins OO.EventEmitter
7674 * @mixins OO.ui.mixin.GroupElement
7677 * @param {OO.ui.ToolFactory} toolFactory Factory for creating tools
7678 * @param {OO.ui.ToolGroupFactory} toolGroupFactory Factory for creating toolgroups
7679 * @param {Object} [config] Configuration options
7680 * @cfg {boolean} [actions] Add an actions section to the toolbar. Actions are commands that are included
7681 * in the toolbar, but are not configured as tools. By default, actions are displayed on the right side of
7683 * @cfg {boolean} [shadow] Add a shadow below the toolbar.
7685 OO
.ui
.Toolbar
= function OoUiToolbar( toolFactory
, toolGroupFactory
, config
) {
7686 // Allow passing positional parameters inside the config object
7687 if ( OO
.isPlainObject( toolFactory
) && config
=== undefined ) {
7688 config
= toolFactory
;
7689 toolFactory
= config
.toolFactory
;
7690 toolGroupFactory
= config
.toolGroupFactory
;
7693 // Configuration initialization
7694 config
= config
|| {};
7696 // Parent constructor
7697 OO
.ui
.Toolbar
.parent
.call( this, config
);
7699 // Mixin constructors
7700 OO
.EventEmitter
.call( this );
7701 OO
.ui
.mixin
.GroupElement
.call( this, config
);
7704 this.toolFactory
= toolFactory
;
7705 this.toolGroupFactory
= toolGroupFactory
;
7708 this.$bar
= $( '<div>' );
7709 this.$actions
= $( '<div>' );
7710 this.initialized
= false;
7711 this.onWindowResizeHandler
= this.onWindowResize
.bind( this );
7715 .add( this.$bar
).add( this.$group
).add( this.$actions
)
7716 .on( 'mousedown keydown', this.onPointerDown
.bind( this ) );
7719 this.$group
.addClass( 'oo-ui-toolbar-tools' );
7720 if ( config
.actions
) {
7721 this.$bar
.append( this.$actions
.addClass( 'oo-ui-toolbar-actions' ) );
7724 .addClass( 'oo-ui-toolbar-bar' )
7725 .append( this.$group
, '<div style="clear:both"></div>' );
7726 if ( config
.shadow
) {
7727 this.$bar
.append( '<div class="oo-ui-toolbar-shadow"></div>' );
7729 this.$element
.addClass( 'oo-ui-toolbar' ).append( this.$bar
);
7734 OO
.inheritClass( OO
.ui
.Toolbar
, OO
.ui
.Element
);
7735 OO
.mixinClass( OO
.ui
.Toolbar
, OO
.EventEmitter
);
7736 OO
.mixinClass( OO
.ui
.Toolbar
, OO
.ui
.mixin
.GroupElement
);
7741 * Get the tool factory.
7743 * @return {OO.ui.ToolFactory} Tool factory
7745 OO
.ui
.Toolbar
.prototype.getToolFactory = function () {
7746 return this.toolFactory
;
7750 * Get the toolgroup factory.
7752 * @return {OO.Factory} Toolgroup factory
7754 OO
.ui
.Toolbar
.prototype.getToolGroupFactory = function () {
7755 return this.toolGroupFactory
;
7759 * Handles mouse down events.
7762 * @param {jQuery.Event} e Mouse down event
7764 OO
.ui
.Toolbar
.prototype.onPointerDown = function ( e
) {
7765 var $closestWidgetToEvent
= $( e
.target
).closest( '.oo-ui-widget' ),
7766 $closestWidgetToToolbar
= this.$element
.closest( '.oo-ui-widget' );
7767 if ( !$closestWidgetToEvent
.length
|| $closestWidgetToEvent
[ 0 ] === $closestWidgetToToolbar
[ 0 ] ) {
7773 * Handle window resize event.
7776 * @param {jQuery.Event} e Window resize event
7778 OO
.ui
.Toolbar
.prototype.onWindowResize = function () {
7779 this.$element
.toggleClass(
7780 'oo-ui-toolbar-narrow',
7781 this.$bar
.width() <= this.narrowThreshold
7786 * Sets up handles and preloads required information for the toolbar to work.
7787 * This must be called after it is attached to a visible document and before doing anything else.
7789 OO
.ui
.Toolbar
.prototype.initialize = function () {
7790 if ( !this.initialized
) {
7791 this.initialized
= true;
7792 this.narrowThreshold
= this.$group
.width() + this.$actions
.width();
7793 $( this.getElementWindow() ).on( 'resize', this.onWindowResizeHandler
);
7794 this.onWindowResize();
7799 * Set up the toolbar.
7801 * The toolbar is set up with a list of toolgroup configurations that specify the type of
7802 * toolgroup ({@link OO.ui.BarToolGroup bar}, {@link OO.ui.MenuToolGroup menu}, or {@link OO.ui.ListToolGroup list})
7803 * to add and which tools to include, exclude, promote, or demote within that toolgroup. Please
7804 * see {@link OO.ui.ToolGroup toolgroups} for more information about including tools in toolgroups.
7806 * @param {Object.<string,Array>} groups List of toolgroup configurations
7807 * @param {Array|string} [groups.include] Tools to include in the toolgroup
7808 * @param {Array|string} [groups.exclude] Tools to exclude from the toolgroup
7809 * @param {Array|string} [groups.promote] Tools to promote to the beginning of the toolgroup
7810 * @param {Array|string} [groups.demote] Tools to demote to the end of the toolgroup
7812 OO
.ui
.Toolbar
.prototype.setup = function ( groups
) {
7813 var i
, len
, type
, group
,
7815 defaultType
= 'bar';
7817 // Cleanup previous groups
7820 // Build out new groups
7821 for ( i
= 0, len
= groups
.length
; i
< len
; i
++ ) {
7822 group
= groups
[ i
];
7823 if ( group
.include
=== '*' ) {
7824 // Apply defaults to catch-all groups
7825 if ( group
.type
=== undefined ) {
7826 group
.type
= 'list';
7828 if ( group
.label
=== undefined ) {
7829 group
.label
= OO
.ui
.msg( 'ooui-toolbar-more' );
7832 // Check type has been registered
7833 type
= this.getToolGroupFactory().lookup( group
.type
) ? group
.type
: defaultType
;
7835 this.getToolGroupFactory().create( type
, this, group
)
7838 this.addItems( items
);
7842 * Remove all tools and toolgroups from the toolbar.
7844 OO
.ui
.Toolbar
.prototype.reset = function () {
7849 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
7850 this.items
[ i
].destroy();
7856 * Destroy the toolbar.
7858 * Destroying the toolbar removes all event handlers and DOM elements that constitute the toolbar. Call
7859 * this method whenever you are done using a toolbar.
7861 OO
.ui
.Toolbar
.prototype.destroy = function () {
7862 $( this.getElementWindow() ).off( 'resize', this.onWindowResizeHandler
);
7864 this.$element
.remove();
7868 * Check if the tool is available.
7870 * Available tools are ones that have not yet been added to the toolbar.
7872 * @param {string} name Symbolic name of tool
7873 * @return {boolean} Tool is available
7875 OO
.ui
.Toolbar
.prototype.isToolAvailable = function ( name
) {
7876 return !this.tools
[ name
];
7880 * Prevent tool from being used again.
7882 * @param {OO.ui.Tool} tool Tool to reserve
7884 OO
.ui
.Toolbar
.prototype.reserveTool = function ( tool
) {
7885 this.tools
[ tool
.getName() ] = tool
;
7889 * Allow tool to be used again.
7891 * @param {OO.ui.Tool} tool Tool to release
7893 OO
.ui
.Toolbar
.prototype.releaseTool = function ( tool
) {
7894 delete this.tools
[ tool
.getName() ];
7898 * Get accelerator label for tool.
7900 * The OOjs UI library does not contain an accelerator system, but this is the hook for one. To
7901 * use an accelerator system, subclass the toolbar and override this method, which is meant to return a label
7902 * that describes the accelerator keys for the tool passed (by symbolic name) to the method.
7904 * @param {string} name Symbolic name of tool
7905 * @return {string|undefined} Tool accelerator label if available
7907 OO
.ui
.Toolbar
.prototype.getToolAccelerator = function () {
7912 * ToolGroups are collections of {@link OO.ui.Tool tools} that are used in a {@link OO.ui.Toolbar toolbar}.
7913 * The type of toolgroup ({@link OO.ui.ListToolGroup list}, {@link OO.ui.BarToolGroup bar}, or {@link OO.ui.MenuToolGroup menu})
7914 * to which a tool belongs determines how the tool is arranged and displayed in the toolbar. Toolgroups
7915 * themselves are created on demand with a {@link OO.ui.ToolGroupFactory toolgroup factory}.
7917 * Toolgroups can contain individual tools, groups of tools, or all available tools:
7919 * To include an individual tool (or array of individual tools), specify tools by symbolic name:
7921 * include: [ 'tool-name' ] or [ { name: 'tool-name' }]
7923 * 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.)
7925 * include: [ { group: 'group-name' } ]
7927 * To include all tools that are not yet assigned to a toolgroup, use the catch-all selector, an asterisk (*):
7931 * See {@link OO.ui.Toolbar toolbars} for a full example. For more information about toolbars in general,
7932 * please see the [OOjs UI documentation on MediaWiki][1].
7934 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
7938 * @extends OO.ui.Widget
7939 * @mixins OO.ui.mixin.GroupElement
7942 * @param {OO.ui.Toolbar} toolbar
7943 * @param {Object} [config] Configuration options
7944 * @cfg {Array|string} [include=[]] List of tools to include in the toolgroup.
7945 * @cfg {Array|string} [exclude=[]] List of tools to exclude from the toolgroup.
7946 * @cfg {Array|string} [promote=[]] List of tools to promote to the beginning of the toolgroup.
7947 * @cfg {Array|string} [demote=[]] List of tools to demote to the end of the toolgroup.
7948 * This setting is particularly useful when tools have been added to the toolgroup
7949 * en masse (e.g., via the catch-all selector).
7951 OO
.ui
.ToolGroup
= function OoUiToolGroup( toolbar
, config
) {
7952 // Allow passing positional parameters inside the config object
7953 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
7955 toolbar
= config
.toolbar
;
7958 // Configuration initialization
7959 config
= config
|| {};
7961 // Parent constructor
7962 OO
.ui
.ToolGroup
.parent
.call( this, config
);
7964 // Mixin constructors
7965 OO
.ui
.mixin
.GroupElement
.call( this, config
);
7968 this.toolbar
= toolbar
;
7970 this.pressed
= null;
7971 this.autoDisabled
= false;
7972 this.include
= config
.include
|| [];
7973 this.exclude
= config
.exclude
|| [];
7974 this.promote
= config
.promote
|| [];
7975 this.demote
= config
.demote
|| [];
7976 this.onCapturedMouseKeyUpHandler
= this.onCapturedMouseKeyUp
.bind( this );
7980 mousedown
: this.onMouseKeyDown
.bind( this ),
7981 mouseup
: this.onMouseKeyUp
.bind( this ),
7982 keydown
: this.onMouseKeyDown
.bind( this ),
7983 keyup
: this.onMouseKeyUp
.bind( this ),
7984 focus
: this.onMouseOverFocus
.bind( this ),
7985 blur
: this.onMouseOutBlur
.bind( this ),
7986 mouseover
: this.onMouseOverFocus
.bind( this ),
7987 mouseout
: this.onMouseOutBlur
.bind( this )
7989 this.toolbar
.getToolFactory().connect( this, { register
: 'onToolFactoryRegister' } );
7990 this.aggregate( { disable
: 'itemDisable' } );
7991 this.connect( this, { itemDisable
: 'updateDisabled' } );
7994 this.$group
.addClass( 'oo-ui-toolGroup-tools' );
7996 .addClass( 'oo-ui-toolGroup' )
7997 .append( this.$group
);
8003 OO
.inheritClass( OO
.ui
.ToolGroup
, OO
.ui
.Widget
);
8004 OO
.mixinClass( OO
.ui
.ToolGroup
, OO
.ui
.mixin
.GroupElement
);
8012 /* Static Properties */
8015 * Show labels in tooltips.
8019 * @property {boolean}
8021 OO
.ui
.ToolGroup
.static.titleTooltips
= false;
8024 * Show acceleration labels in tooltips.
8026 * Note: The OOjs UI library does not include an accelerator system, but does contain
8027 * a hook for one. To use an accelerator system, subclass the {@link OO.ui.Toolbar toolbar} and
8028 * override the {@link OO.ui.Toolbar#getToolAccelerator getToolAccelerator} method, which is
8029 * meant to return a label that describes the accelerator keys for a given tool (e.g., 'Ctrl + M').
8033 * @property {boolean}
8035 OO
.ui
.ToolGroup
.static.accelTooltips
= false;
8038 * Automatically disable the toolgroup when all tools are disabled
8042 * @property {boolean}
8044 OO
.ui
.ToolGroup
.static.autoDisable
= true;
8051 OO
.ui
.ToolGroup
.prototype.isDisabled = function () {
8052 return this.autoDisabled
|| OO
.ui
.ToolGroup
.parent
.prototype.isDisabled
.apply( this, arguments
);
8058 OO
.ui
.ToolGroup
.prototype.updateDisabled = function () {
8059 var i
, item
, allDisabled
= true;
8061 if ( this.constructor.static.autoDisable
) {
8062 for ( i
= this.items
.length
- 1; i
>= 0; i
-- ) {
8063 item
= this.items
[ i
];
8064 if ( !item
.isDisabled() ) {
8065 allDisabled
= false;
8069 this.autoDisabled
= allDisabled
;
8071 OO
.ui
.ToolGroup
.parent
.prototype.updateDisabled
.apply( this, arguments
);
8075 * Handle mouse down and key down events.
8078 * @param {jQuery.Event} e Mouse down or key down event
8080 OO
.ui
.ToolGroup
.prototype.onMouseKeyDown = function ( e
) {
8082 !this.isDisabled() &&
8083 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
8085 this.pressed
= this.getTargetTool( e
);
8086 if ( this.pressed
) {
8087 this.pressed
.setActive( true );
8088 OO
.ui
.addCaptureEventListener( this.getElementDocument(), 'mouseup', this.onCapturedMouseKeyUpHandler
);
8089 OO
.ui
.addCaptureEventListener( this.getElementDocument(), 'keyup', this.onCapturedMouseKeyUpHandler
);
8096 * Handle captured mouse up and key up events.
8099 * @param {Event} e Mouse up or key up event
8101 OO
.ui
.ToolGroup
.prototype.onCapturedMouseKeyUp = function ( e
) {
8102 OO
.ui
.removeCaptureEventListener( this.getElementDocument(), 'mouseup', this.onCapturedMouseKeyUpHandler
);
8103 OO
.ui
.removeCaptureEventListener( this.getElementDocument(), 'keyup', this.onCapturedMouseKeyUpHandler
);
8104 // onMouseKeyUp may be called a second time, depending on where the mouse is when the button is
8105 // released, but since `this.pressed` will no longer be true, the second call will be ignored.
8106 this.onMouseKeyUp( e
);
8110 * Handle mouse up and key up events.
8113 * @param {jQuery.Event} e Mouse up or key up event
8115 OO
.ui
.ToolGroup
.prototype.onMouseKeyUp = function ( e
) {
8116 var tool
= this.getTargetTool( e
);
8119 !this.isDisabled() && this.pressed
&& this.pressed
=== tool
&&
8120 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
8122 this.pressed
.onSelect();
8123 this.pressed
= null;
8127 this.pressed
= null;
8131 * Handle mouse over and focus events.
8134 * @param {jQuery.Event} e Mouse over or focus event
8136 OO
.ui
.ToolGroup
.prototype.onMouseOverFocus = function ( e
) {
8137 var tool
= this.getTargetTool( e
);
8139 if ( this.pressed
&& this.pressed
=== tool
) {
8140 this.pressed
.setActive( true );
8145 * Handle mouse out and blur events.
8148 * @param {jQuery.Event} e Mouse out or blur event
8150 OO
.ui
.ToolGroup
.prototype.onMouseOutBlur = function ( e
) {
8151 var tool
= this.getTargetTool( e
);
8153 if ( this.pressed
&& this.pressed
=== tool
) {
8154 this.pressed
.setActive( false );
8159 * Get the closest tool to a jQuery.Event.
8161 * Only tool links are considered, which prevents other elements in the tool such as popups from
8162 * triggering tool group interactions.
8165 * @param {jQuery.Event} e
8166 * @return {OO.ui.Tool|null} Tool, `null` if none was found
8168 OO
.ui
.ToolGroup
.prototype.getTargetTool = function ( e
) {
8170 $item
= $( e
.target
).closest( '.oo-ui-tool-link' );
8172 if ( $item
.length
) {
8173 tool
= $item
.parent().data( 'oo-ui-tool' );
8176 return tool
&& !tool
.isDisabled() ? tool
: null;
8180 * Handle tool registry register events.
8182 * If a tool is registered after the group is created, we must repopulate the list to account for:
8184 * - a tool being added that may be included
8185 * - a tool already included being overridden
8188 * @param {string} name Symbolic name of tool
8190 OO
.ui
.ToolGroup
.prototype.onToolFactoryRegister = function () {
8195 * Get the toolbar that contains the toolgroup.
8197 * @return {OO.ui.Toolbar} Toolbar that contains the toolgroup
8199 OO
.ui
.ToolGroup
.prototype.getToolbar = function () {
8200 return this.toolbar
;
8204 * Add and remove tools based on configuration.
8206 OO
.ui
.ToolGroup
.prototype.populate = function () {
8207 var i
, len
, name
, tool
,
8208 toolFactory
= this.toolbar
.getToolFactory(),
8212 list
= this.toolbar
.getToolFactory().getTools(
8213 this.include
, this.exclude
, this.promote
, this.demote
8216 // Build a list of needed tools
8217 for ( i
= 0, len
= list
.length
; i
< len
; i
++ ) {
8221 toolFactory
.lookup( name
) &&
8222 // Tool is available or is already in this group
8223 ( this.toolbar
.isToolAvailable( name
) || this.tools
[ name
] )
8225 // Hack to prevent infinite recursion via ToolGroupTool. We need to reserve the tool before
8226 // creating it, but we can't call reserveTool() yet because we haven't created the tool.
8227 this.toolbar
.tools
[ name
] = true;
8228 tool
= this.tools
[ name
];
8230 // Auto-initialize tools on first use
8231 this.tools
[ name
] = tool
= toolFactory
.create( name
, this );
8234 this.toolbar
.reserveTool( tool
);
8236 names
[ name
] = true;
8239 // Remove tools that are no longer needed
8240 for ( name
in this.tools
) {
8241 if ( !names
[ name
] ) {
8242 this.tools
[ name
].destroy();
8243 this.toolbar
.releaseTool( this.tools
[ name
] );
8244 remove
.push( this.tools
[ name
] );
8245 delete this.tools
[ name
];
8248 if ( remove
.length
) {
8249 this.removeItems( remove
);
8251 // Update emptiness state
8253 this.$element
.removeClass( 'oo-ui-toolGroup-empty' );
8255 this.$element
.addClass( 'oo-ui-toolGroup-empty' );
8257 // Re-add tools (moving existing ones to new locations)
8258 this.addItems( add
);
8259 // Disabled state may depend on items
8260 this.updateDisabled();
8264 * Destroy toolgroup.
8266 OO
.ui
.ToolGroup
.prototype.destroy = function () {
8270 this.toolbar
.getToolFactory().disconnect( this );
8271 for ( name
in this.tools
) {
8272 this.toolbar
.releaseTool( this.tools
[ name
] );
8273 this.tools
[ name
].disconnect( this ).destroy();
8274 delete this.tools
[ name
];
8276 this.$element
.remove();
8280 * MessageDialogs display a confirmation or alert message. By default, the rendered dialog box
8281 * consists of a header that contains the dialog title, a body with the message, and a footer that
8282 * contains any {@link OO.ui.ActionWidget action widgets}. The MessageDialog class is the only type
8283 * of {@link OO.ui.Dialog dialog} that is usually instantiated directly.
8285 * There are two basic types of message dialogs, confirmation and alert:
8287 * - **confirmation**: the dialog title describes what a progressive action will do and the message provides
8288 * more details about the consequences.
8289 * - **alert**: the dialog title describes which event occurred and the message provides more information
8290 * about why the event occurred.
8292 * The MessageDialog class specifies two actions: ‘accept’, the primary
8293 * action (e.g., ‘ok’) and ‘reject,’ the safe action (e.g., ‘cancel’). Both will close the window,
8294 * passing along the selected action.
8296 * For more information and examples, please see the [OOjs UI documentation on MediaWiki][1].
8299 * // Example: Creating and opening a message dialog window.
8300 * var messageDialog = new OO.ui.MessageDialog();
8302 * // Create and append a window manager.
8303 * var windowManager = new OO.ui.WindowManager();
8304 * $( 'body' ).append( windowManager.$element );
8305 * windowManager.addWindows( [ messageDialog ] );
8306 * // Open the window.
8307 * windowManager.openWindow( messageDialog, {
8308 * title: 'Basic message dialog',
8309 * message: 'This is the message'
8312 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Message_Dialogs
8315 * @extends OO.ui.Dialog
8318 * @param {Object} [config] Configuration options
8320 OO
.ui
.MessageDialog
= function OoUiMessageDialog( config
) {
8321 // Parent constructor
8322 OO
.ui
.MessageDialog
.parent
.call( this, config
);
8325 this.verticalActionLayout
= null;
8328 this.$element
.addClass( 'oo-ui-messageDialog' );
8333 OO
.inheritClass( OO
.ui
.MessageDialog
, OO
.ui
.Dialog
);
8335 /* Static Properties */
8337 OO
.ui
.MessageDialog
.static.name
= 'message';
8339 OO
.ui
.MessageDialog
.static.size
= 'small';
8341 OO
.ui
.MessageDialog
.static.verbose
= false;
8346 * The title of a confirmation dialog describes what a progressive action will do. The
8347 * title of an alert dialog describes which event occurred.
8351 * @property {jQuery|string|Function|null}
8353 OO
.ui
.MessageDialog
.static.title
= null;
8356 * The message displayed in the dialog body.
8358 * A confirmation message describes the consequences of a progressive action. An alert
8359 * message describes why an event occurred.
8363 * @property {jQuery|string|Function|null}
8365 OO
.ui
.MessageDialog
.static.message
= null;
8367 OO
.ui
.MessageDialog
.static.actions
= [
8368 { action
: 'accept', label
: OO
.ui
.deferMsg( 'ooui-dialog-message-accept' ), flags
: 'primary' },
8369 { action
: 'reject', label
: OO
.ui
.deferMsg( 'ooui-dialog-message-reject' ), flags
: 'safe' }
8377 OO
.ui
.MessageDialog
.prototype.setManager = function ( manager
) {
8378 OO
.ui
.MessageDialog
.parent
.prototype.setManager
.call( this, manager
);
8381 this.manager
.connect( this, {
8391 OO
.ui
.MessageDialog
.prototype.onActionResize = function ( action
) {
8393 return OO
.ui
.MessageDialog
.parent
.prototype.onActionResize
.call( this, action
);
8397 * Handle window resized events.
8401 OO
.ui
.MessageDialog
.prototype.onResize = function () {
8403 dialog
.fitActions();
8404 // Wait for CSS transition to finish and do it again :(
8405 setTimeout( function () {
8406 dialog
.fitActions();
8411 * Toggle action layout between vertical and horizontal.
8414 * @param {boolean} [value] Layout actions vertically, omit to toggle
8417 OO
.ui
.MessageDialog
.prototype.toggleVerticalActionLayout = function ( value
) {
8418 value
= value
=== undefined ? !this.verticalActionLayout
: !!value
;
8420 if ( value
!== this.verticalActionLayout
) {
8421 this.verticalActionLayout
= value
;
8423 .toggleClass( 'oo-ui-messageDialog-actions-vertical', value
)
8424 .toggleClass( 'oo-ui-messageDialog-actions-horizontal', !value
);
8433 OO
.ui
.MessageDialog
.prototype.getActionProcess = function ( action
) {
8435 return new OO
.ui
.Process( function () {
8436 this.close( { action
: action
} );
8439 return OO
.ui
.MessageDialog
.parent
.prototype.getActionProcess
.call( this, action
);
8445 * @param {Object} [data] Dialog opening data
8446 * @param {jQuery|string|Function|null} [data.title] Description of the action being confirmed
8447 * @param {jQuery|string|Function|null} [data.message] Description of the action's consequence
8448 * @param {boolean} [data.verbose] Message is verbose and should be styled as a long message
8449 * @param {Object[]} [data.actions] List of OO.ui.ActionOptionWidget configuration options for each
8452 OO
.ui
.MessageDialog
.prototype.getSetupProcess = function ( data
) {
8456 return OO
.ui
.MessageDialog
.parent
.prototype.getSetupProcess
.call( this, data
)
8457 .next( function () {
8458 this.title
.setLabel(
8459 data
.title
!== undefined ? data
.title
: this.constructor.static.title
8461 this.message
.setLabel(
8462 data
.message
!== undefined ? data
.message
: this.constructor.static.message
8464 this.message
.$element
.toggleClass(
8465 'oo-ui-messageDialog-message-verbose',
8466 data
.verbose
!== undefined ? data
.verbose
: this.constructor.static.verbose
8474 OO
.ui
.MessageDialog
.prototype.getReadyProcess = function ( data
) {
8478 return OO
.ui
.MessageDialog
.parent
.prototype.getReadyProcess
.call( this, data
)
8479 .next( function () {
8480 // Focus the primary action button
8481 var actions
= this.actions
.get();
8482 actions
= actions
.filter( function ( action
) {
8483 return action
.getFlags().indexOf( 'primary' ) > -1;
8485 if ( actions
.length
> 0 ) {
8486 actions
[ 0 ].$button
.focus();
8494 OO
.ui
.MessageDialog
.prototype.getBodyHeight = function () {
8495 var bodyHeight
, oldOverflow
,
8496 $scrollable
= this.container
.$element
;
8498 oldOverflow
= $scrollable
[ 0 ].style
.overflow
;
8499 $scrollable
[ 0 ].style
.overflow
= 'hidden';
8501 OO
.ui
.Element
.static.reconsiderScrollbars( $scrollable
[ 0 ] );
8503 bodyHeight
= this.text
.$element
.outerHeight( true );
8504 $scrollable
[ 0 ].style
.overflow
= oldOverflow
;
8512 OO
.ui
.MessageDialog
.prototype.setDimensions = function ( dim
) {
8513 var $scrollable
= this.container
.$element
;
8514 OO
.ui
.MessageDialog
.parent
.prototype.setDimensions
.call( this, dim
);
8516 // Twiddle the overflow property, otherwise an unnecessary scrollbar will be produced.
8517 // Need to do it after transition completes (250ms), add 50ms just in case.
8518 setTimeout( function () {
8519 var oldOverflow
= $scrollable
[ 0 ].style
.overflow
;
8520 $scrollable
[ 0 ].style
.overflow
= 'hidden';
8522 OO
.ui
.Element
.static.reconsiderScrollbars( $scrollable
[ 0 ] );
8524 $scrollable
[ 0 ].style
.overflow
= oldOverflow
;
8533 OO
.ui
.MessageDialog
.prototype.initialize = function () {
8535 OO
.ui
.MessageDialog
.parent
.prototype.initialize
.call( this );
8538 this.$actions
= $( '<div>' );
8539 this.container
= new OO
.ui
.PanelLayout( {
8540 scrollable
: true, classes
: [ 'oo-ui-messageDialog-container' ]
8542 this.text
= new OO
.ui
.PanelLayout( {
8543 padded
: true, expanded
: false, classes
: [ 'oo-ui-messageDialog-text' ]
8545 this.message
= new OO
.ui
.LabelWidget( {
8546 classes
: [ 'oo-ui-messageDialog-message' ]
8550 this.title
.$element
.addClass( 'oo-ui-messageDialog-title' );
8551 this.$content
.addClass( 'oo-ui-messageDialog-content' );
8552 this.container
.$element
.append( this.text
.$element
);
8553 this.text
.$element
.append( this.title
.$element
, this.message
.$element
);
8554 this.$body
.append( this.container
.$element
);
8555 this.$actions
.addClass( 'oo-ui-messageDialog-actions' );
8556 this.$foot
.append( this.$actions
);
8562 OO
.ui
.MessageDialog
.prototype.attachActions = function () {
8563 var i
, len
, other
, special
, others
;
8566 OO
.ui
.MessageDialog
.parent
.prototype.attachActions
.call( this );
8568 special
= this.actions
.getSpecial();
8569 others
= this.actions
.getOthers();
8571 if ( special
.safe
) {
8572 this.$actions
.append( special
.safe
.$element
);
8573 special
.safe
.toggleFramed( false );
8575 if ( others
.length
) {
8576 for ( i
= 0, len
= others
.length
; i
< len
; i
++ ) {
8577 other
= others
[ i
];
8578 this.$actions
.append( other
.$element
);
8579 other
.toggleFramed( false );
8582 if ( special
.primary
) {
8583 this.$actions
.append( special
.primary
.$element
);
8584 special
.primary
.toggleFramed( false );
8587 if ( !this.isOpening() ) {
8588 // If the dialog is currently opening, this will be called automatically soon.
8589 // This also calls #fitActions.
8595 * Fit action actions into columns or rows.
8597 * Columns will be used if all labels can fit without overflow, otherwise rows will be used.
8601 OO
.ui
.MessageDialog
.prototype.fitActions = function () {
8603 previous
= this.verticalActionLayout
,
8604 actions
= this.actions
.get();
8607 this.toggleVerticalActionLayout( false );
8608 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
8609 action
= actions
[ i
];
8610 if ( action
.$element
.innerWidth() < action
.$label
.outerWidth( true ) ) {
8611 this.toggleVerticalActionLayout( true );
8616 // Move the body out of the way of the foot
8617 this.$body
.css( 'bottom', this.$foot
.outerHeight( true ) );
8619 if ( this.verticalActionLayout
!== previous
) {
8620 // We changed the layout, window height might need to be updated.
8626 * ProcessDialog windows encapsulate a {@link OO.ui.Process process} and all of the code necessary
8627 * to complete it. If the process terminates with an error, a customizable {@link OO.ui.Error error
8628 * interface} alerts users to the trouble, permitting the user to dismiss the error and try again when
8629 * relevant. The ProcessDialog class is always extended and customized with the actions and content
8630 * required for each process.
8632 * The process dialog box consists of a header that visually represents the ‘working’ state of long
8633 * processes with an animation. The header contains the dialog title as well as
8634 * two {@link OO.ui.ActionWidget action widgets}: a ‘safe’ action on the left (e.g., ‘Cancel’) and
8635 * a ‘primary’ action on the right (e.g., ‘Done’).
8637 * Like other windows, the process dialog is managed by a {@link OO.ui.WindowManager window manager}.
8638 * Please see the [OOjs UI documentation on MediaWiki][1] for more information and examples.
8641 * // Example: Creating and opening a process dialog window.
8642 * function MyProcessDialog( config ) {
8643 * MyProcessDialog.parent.call( this, config );
8645 * OO.inheritClass( MyProcessDialog, OO.ui.ProcessDialog );
8647 * MyProcessDialog.static.title = 'Process dialog';
8648 * MyProcessDialog.static.actions = [
8649 * { action: 'save', label: 'Done', flags: 'primary' },
8650 * { label: 'Cancel', flags: 'safe' }
8653 * MyProcessDialog.prototype.initialize = function () {
8654 * MyProcessDialog.parent.prototype.initialize.apply( this, arguments );
8655 * this.content = new OO.ui.PanelLayout( { padded: true, expanded: false } );
8656 * 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>' );
8657 * this.$body.append( this.content.$element );
8659 * MyProcessDialog.prototype.getActionProcess = function ( action ) {
8660 * var dialog = this;
8662 * return new OO.ui.Process( function () {
8663 * dialog.close( { action: action } );
8666 * return MyProcessDialog.parent.prototype.getActionProcess.call( this, action );
8669 * var windowManager = new OO.ui.WindowManager();
8670 * $( 'body' ).append( windowManager.$element );
8672 * var dialog = new MyProcessDialog();
8673 * windowManager.addWindows( [ dialog ] );
8674 * windowManager.openWindow( dialog );
8676 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs
8680 * @extends OO.ui.Dialog
8683 * @param {Object} [config] Configuration options
8685 OO
.ui
.ProcessDialog
= function OoUiProcessDialog( config
) {
8686 // Parent constructor
8687 OO
.ui
.ProcessDialog
.parent
.call( this, config
);
8690 this.fitOnOpen
= false;
8693 this.$element
.addClass( 'oo-ui-processDialog' );
8698 OO
.inheritClass( OO
.ui
.ProcessDialog
, OO
.ui
.Dialog
);
8703 * Handle dismiss button click events.
8709 OO
.ui
.ProcessDialog
.prototype.onDismissErrorButtonClick = function () {
8714 * Handle retry button click events.
8716 * Hides errors and then tries again.
8720 OO
.ui
.ProcessDialog
.prototype.onRetryButtonClick = function () {
8722 this.executeAction( this.currentAction
);
8728 OO
.ui
.ProcessDialog
.prototype.onActionResize = function ( action
) {
8729 if ( this.actions
.isSpecial( action
) ) {
8732 return OO
.ui
.ProcessDialog
.parent
.prototype.onActionResize
.call( this, action
);
8738 OO
.ui
.ProcessDialog
.prototype.initialize = function () {
8740 OO
.ui
.ProcessDialog
.parent
.prototype.initialize
.call( this );
8743 this.$navigation
= $( '<div>' );
8744 this.$location
= $( '<div>' );
8745 this.$safeActions
= $( '<div>' );
8746 this.$primaryActions
= $( '<div>' );
8747 this.$otherActions
= $( '<div>' );
8748 this.dismissButton
= new OO
.ui
.ButtonWidget( {
8749 label
: OO
.ui
.msg( 'ooui-dialog-process-dismiss' )
8751 this.retryButton
= new OO
.ui
.ButtonWidget();
8752 this.$errors
= $( '<div>' );
8753 this.$errorsTitle
= $( '<div>' );
8756 this.dismissButton
.connect( this, { click
: 'onDismissErrorButtonClick' } );
8757 this.retryButton
.connect( this, { click
: 'onRetryButtonClick' } );
8760 this.title
.$element
.addClass( 'oo-ui-processDialog-title' );
8762 .append( this.title
.$element
)
8763 .addClass( 'oo-ui-processDialog-location' );
8764 this.$safeActions
.addClass( 'oo-ui-processDialog-actions-safe' );
8765 this.$primaryActions
.addClass( 'oo-ui-processDialog-actions-primary' );
8766 this.$otherActions
.addClass( 'oo-ui-processDialog-actions-other' );
8768 .addClass( 'oo-ui-processDialog-errors-title' )
8769 .text( OO
.ui
.msg( 'ooui-dialog-process-error' ) );
8771 .addClass( 'oo-ui-processDialog-errors oo-ui-element-hidden' )
8772 .append( this.$errorsTitle
, this.dismissButton
.$element
, this.retryButton
.$element
);
8774 .addClass( 'oo-ui-processDialog-content' )
8775 .append( this.$errors
);
8777 .addClass( 'oo-ui-processDialog-navigation' )
8778 .append( this.$safeActions
, this.$location
, this.$primaryActions
);
8779 this.$head
.append( this.$navigation
);
8780 this.$foot
.append( this.$otherActions
);
8786 OO
.ui
.ProcessDialog
.prototype.getActionWidgets = function ( actions
) {
8787 var i
, len
, widgets
= [];
8788 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
8790 new OO
.ui
.ActionWidget( $.extend( { framed
: true }, actions
[ i
] ) )
8799 OO
.ui
.ProcessDialog
.prototype.attachActions = function () {
8800 var i
, len
, other
, special
, others
;
8803 OO
.ui
.ProcessDialog
.parent
.prototype.attachActions
.call( this );
8805 special
= this.actions
.getSpecial();
8806 others
= this.actions
.getOthers();
8807 if ( special
.primary
) {
8808 this.$primaryActions
.append( special
.primary
.$element
);
8810 for ( i
= 0, len
= others
.length
; i
< len
; i
++ ) {
8811 other
= others
[ i
];
8812 this.$otherActions
.append( other
.$element
);
8814 if ( special
.safe
) {
8815 this.$safeActions
.append( special
.safe
.$element
);
8819 this.$body
.css( 'bottom', this.$foot
.outerHeight( true ) );
8825 OO
.ui
.ProcessDialog
.prototype.executeAction = function ( action
) {
8827 return OO
.ui
.ProcessDialog
.parent
.prototype.executeAction
.call( this, action
)
8828 .fail( function ( errors
) {
8829 process
.showErrors( errors
|| [] );
8836 OO
.ui
.ProcessDialog
.prototype.setDimensions = function () {
8838 OO
.ui
.ProcessDialog
.parent
.prototype.setDimensions
.apply( this, arguments
);
8844 * Fit label between actions.
8849 OO
.ui
.ProcessDialog
.prototype.fitLabel = function () {
8850 var safeWidth
, primaryWidth
, biggerWidth
, labelWidth
, navigationWidth
, leftWidth
, rightWidth
,
8851 size
= this.getSizeProperties();
8853 if ( typeof size
.width
!== 'number' ) {
8854 if ( this.isOpened() ) {
8855 navigationWidth
= this.$head
.width() - 20;
8856 } else if ( this.isOpening() ) {
8857 if ( !this.fitOnOpen
) {
8858 // Size is relative and the dialog isn't open yet, so wait.
8859 this.manager
.opening
.done( this.fitLabel
.bind( this ) );
8860 this.fitOnOpen
= true;
8867 navigationWidth
= size
.width
- 20;
8870 safeWidth
= this.$safeActions
.is( ':visible' ) ? this.$safeActions
.width() : 0;
8871 primaryWidth
= this.$primaryActions
.is( ':visible' ) ? this.$primaryActions
.width() : 0;
8872 biggerWidth
= Math
.max( safeWidth
, primaryWidth
);
8874 labelWidth
= this.title
.$element
.width();
8876 if ( 2 * biggerWidth
+ labelWidth
< navigationWidth
) {
8877 // We have enough space to center the label
8878 leftWidth
= rightWidth
= biggerWidth
;
8880 // Let's hope we at least have enough space not to overlap, because we can't wrap the label…
8881 if ( this.getDir() === 'ltr' ) {
8882 leftWidth
= safeWidth
;
8883 rightWidth
= primaryWidth
;
8885 leftWidth
= primaryWidth
;
8886 rightWidth
= safeWidth
;
8890 this.$location
.css( { paddingLeft
: leftWidth
, paddingRight
: rightWidth
} );
8896 * Handle errors that occurred during accept or reject processes.
8899 * @param {OO.ui.Error[]|OO.ui.Error} errors Errors to be handled
8901 OO
.ui
.ProcessDialog
.prototype.showErrors = function ( errors
) {
8902 var i
, len
, $item
, actions
,
8908 if ( errors
instanceof OO
.ui
.Error
) {
8909 errors
= [ errors
];
8912 for ( i
= 0, len
= errors
.length
; i
< len
; i
++ ) {
8913 if ( !errors
[ i
].isRecoverable() ) {
8914 recoverable
= false;
8916 if ( errors
[ i
].isWarning() ) {
8919 $item
= $( '<div>' )
8920 .addClass( 'oo-ui-processDialog-error' )
8921 .append( errors
[ i
].getMessage() );
8922 items
.push( $item
[ 0 ] );
8924 this.$errorItems
= $( items
);
8925 if ( recoverable
) {
8926 abilities
[ this.currentAction
] = true;
8927 // Copy the flags from the first matching action
8928 actions
= this.actions
.get( { actions
: this.currentAction
} );
8929 if ( actions
.length
) {
8930 this.retryButton
.clearFlags().setFlags( actions
[ 0 ].getFlags() );
8933 abilities
[ this.currentAction
] = false;
8934 this.actions
.setAbilities( abilities
);
8937 this.retryButton
.setLabel( OO
.ui
.msg( 'ooui-dialog-process-continue' ) );
8939 this.retryButton
.setLabel( OO
.ui
.msg( 'ooui-dialog-process-retry' ) );
8941 this.retryButton
.toggle( recoverable
);
8942 this.$errorsTitle
.after( this.$errorItems
);
8943 this.$errors
.removeClass( 'oo-ui-element-hidden' ).scrollTop( 0 );
8951 OO
.ui
.ProcessDialog
.prototype.hideErrors = function () {
8952 this.$errors
.addClass( 'oo-ui-element-hidden' );
8953 if ( this.$errorItems
) {
8954 this.$errorItems
.remove();
8955 this.$errorItems
= null;
8962 OO
.ui
.ProcessDialog
.prototype.getTeardownProcess = function ( data
) {
8964 return OO
.ui
.ProcessDialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
8965 .first( function () {
8966 // Make sure to hide errors
8968 this.fitOnOpen
= false;
8973 * FieldLayouts are used with OO.ui.FieldsetLayout. Each FieldLayout requires a field-widget,
8974 * which is a widget that is specified by reference before any optional configuration settings.
8976 * Field layouts can be configured with help text and/or labels. Labels are aligned in one of four ways:
8978 * - **left**: The label is placed before the field-widget and aligned with the left margin.
8979 * A left-alignment is used for forms with many fields.
8980 * - **right**: The label is placed before the field-widget and aligned to the right margin.
8981 * A right-alignment is used for long but familiar forms which users tab through,
8982 * verifying the current field with a quick glance at the label.
8983 * - **top**: The label is placed above the field-widget. A top-alignment is used for brief forms
8984 * that users fill out from top to bottom.
8985 * - **inline**: The label is placed after the field-widget and aligned to the left.
8986 * An inline-alignment is best used with checkboxes or radio buttons.
8988 * Help text is accessed via a help icon that appears in the upper right corner of the rendered field layout.
8989 * Please see the [OOjs UI documentation on MediaWiki] [1] for examples and more information.
8991 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Layouts/Fields_and_Fieldsets
8993 * @extends OO.ui.Layout
8994 * @mixins OO.ui.mixin.LabelElement
8995 * @mixins OO.ui.mixin.TitledElement
8998 * @param {OO.ui.Widget} fieldWidget Field widget
8999 * @param {Object} [config] Configuration options
9000 * @cfg {string} [align='left'] Alignment of the label: 'left', 'right', 'top' or 'inline'
9001 * @cfg {Array} [errors] Error messages about the widget, which will be displayed below the widget.
9002 * The array may contain strings or OO.ui.HtmlSnippet instances.
9003 * @cfg {Array} [notices] Notices about the widget, which will be displayed below the widget.
9004 * The array may contain strings or OO.ui.HtmlSnippet instances.
9005 * @cfg {string|OO.ui.HtmlSnippet} [help] Help text. When help text is specified, a "help" icon will appear
9006 * in the upper-right corner of the rendered field; clicking it will display the text in a popup.
9007 * For important messages, you are advised to use `notices`, as they are always shown.
9009 * @throws {Error} An error is thrown if no widget is specified
9011 OO
.ui
.FieldLayout
= function OoUiFieldLayout( fieldWidget
, config
) {
9012 var hasInputWidget
, div
, i
;
9014 // Allow passing positional parameters inside the config object
9015 if ( OO
.isPlainObject( fieldWidget
) && config
=== undefined ) {
9016 config
= fieldWidget
;
9017 fieldWidget
= config
.fieldWidget
;
9020 // Make sure we have required constructor arguments
9021 if ( fieldWidget
=== undefined ) {
9022 throw new Error( 'Widget not found' );
9025 hasInputWidget
= fieldWidget
.constructor.static.supportsSimpleLabel
;
9027 // Configuration initialization
9028 config
= $.extend( { align
: 'left' }, config
);
9030 // Parent constructor
9031 OO
.ui
.FieldLayout
.parent
.call( this, config
);
9033 // Mixin constructors
9034 OO
.ui
.mixin
.LabelElement
.call( this, config
);
9035 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$label
} ) );
9038 this.fieldWidget
= fieldWidget
;
9039 this.errors
= config
.errors
|| [];
9040 this.notices
= config
.notices
|| [];
9041 this.$field
= $( '<div>' );
9042 this.$messages
= $( '<ul>' );
9043 this.$body
= $( '<' + ( hasInputWidget
? 'label' : 'div' ) + '>' );
9045 if ( config
.help
) {
9046 this.popupButtonWidget
= new OO
.ui
.PopupButtonWidget( {
9047 classes
: [ 'oo-ui-fieldLayout-help' ],
9053 if ( config
.help
instanceof OO
.ui
.HtmlSnippet
) {
9054 div
.html( config
.help
.toString() );
9056 div
.text( config
.help
);
9058 this.popupButtonWidget
.getPopup().$body
.append(
9059 div
.addClass( 'oo-ui-fieldLayout-help-content' )
9061 this.$help
= this.popupButtonWidget
.$element
;
9063 this.$help
= $( [] );
9067 if ( hasInputWidget
) {
9068 this.$label
.on( 'click', this.onLabelClick
.bind( this ) );
9070 this.fieldWidget
.connect( this, { disable
: 'onFieldDisable' } );
9074 .addClass( 'oo-ui-fieldLayout' )
9075 .append( this.$help
, this.$body
);
9076 if ( this.errors
.length
|| this.notices
.length
) {
9077 this.$element
.append( this.$messages
);
9079 this.$body
.addClass( 'oo-ui-fieldLayout-body' );
9080 this.$messages
.addClass( 'oo-ui-fieldLayout-messages' );
9082 .addClass( 'oo-ui-fieldLayout-field' )
9083 .toggleClass( 'oo-ui-fieldLayout-disable', this.fieldWidget
.isDisabled() )
9084 .append( this.fieldWidget
.$element
);
9086 for ( i
= 0; i
< this.notices
.length
; i
++ ) {
9087 this.$messages
.append( this.makeMessage( 'notice', this.notices
[ i
] ) );
9089 for ( i
= 0; i
< this.errors
.length
; i
++ ) {
9090 this.$messages
.append( this.makeMessage( 'error', this.errors
[ i
] ) );
9093 this.setAlignment( config
.align
);
9098 OO
.inheritClass( OO
.ui
.FieldLayout
, OO
.ui
.Layout
);
9099 OO
.mixinClass( OO
.ui
.FieldLayout
, OO
.ui
.mixin
.LabelElement
);
9100 OO
.mixinClass( OO
.ui
.FieldLayout
, OO
.ui
.mixin
.TitledElement
);
9105 * Handle field disable events.
9108 * @param {boolean} value Field is disabled
9110 OO
.ui
.FieldLayout
.prototype.onFieldDisable = function ( value
) {
9111 this.$element
.toggleClass( 'oo-ui-fieldLayout-disabled', value
);
9115 * Handle label mouse click events.
9118 * @param {jQuery.Event} e Mouse click event
9120 OO
.ui
.FieldLayout
.prototype.onLabelClick = function () {
9121 this.fieldWidget
.simulateLabelClick();
9126 * Get the widget contained by the field.
9128 * @return {OO.ui.Widget} Field widget
9130 OO
.ui
.FieldLayout
.prototype.getField = function () {
9131 return this.fieldWidget
;
9135 * @param {string} kind 'error' or 'notice'
9136 * @param {string|OO.ui.HtmlSnippet} text
9139 OO
.ui
.FieldLayout
.prototype.makeMessage = function ( kind
, text
) {
9140 var $listItem
, $icon
, message
;
9141 $listItem
= $( '<li>' );
9142 if ( kind
=== 'error' ) {
9143 $icon
= new OO
.ui
.IconWidget( { icon
: 'alert', flags
: [ 'warning' ] } ).$element
;
9144 } else if ( kind
=== 'notice' ) {
9145 $icon
= new OO
.ui
.IconWidget( { icon
: 'info' } ).$element
;
9149 message
= new OO
.ui
.LabelWidget( { label
: text
} );
9151 .append( $icon
, message
.$element
)
9152 .addClass( 'oo-ui-fieldLayout-messages-' + kind
);
9157 * Set the field alignment mode.
9160 * @param {string} value Alignment mode, either 'left', 'right', 'top' or 'inline'
9163 OO
.ui
.FieldLayout
.prototype.setAlignment = function ( value
) {
9164 if ( value
!== this.align
) {
9165 // Default to 'left'
9166 if ( [ 'left', 'right', 'top', 'inline' ].indexOf( value
) === -1 ) {
9170 if ( value
=== 'inline' ) {
9171 this.$body
.append( this.$field
, this.$label
);
9173 this.$body
.append( this.$label
, this.$field
);
9175 // Set classes. The following classes can be used here:
9176 // * oo-ui-fieldLayout-align-left
9177 // * oo-ui-fieldLayout-align-right
9178 // * oo-ui-fieldLayout-align-top
9179 // * oo-ui-fieldLayout-align-inline
9181 this.$element
.removeClass( 'oo-ui-fieldLayout-align-' + this.align
);
9183 this.$element
.addClass( 'oo-ui-fieldLayout-align-' + value
);
9191 * ActionFieldLayouts are used with OO.ui.FieldsetLayout. The layout consists of a field-widget, a button,
9192 * and an optional label and/or help text. The field-widget (e.g., a {@link OO.ui.TextInputWidget TextInputWidget}),
9193 * is required and is specified before any optional configuration settings.
9195 * Labels can be aligned in one of four ways:
9197 * - **left**: The label is placed before the field-widget and aligned with the left margin.
9198 * A left-alignment is used for forms with many fields.
9199 * - **right**: The label is placed before the field-widget and aligned to the right margin.
9200 * A right-alignment is used for long but familiar forms which users tab through,
9201 * verifying the current field with a quick glance at the label.
9202 * - **top**: The label is placed above the field-widget. A top-alignment is used for brief forms
9203 * that users fill out from top to bottom.
9204 * - **inline**: The label is placed after the field-widget and aligned to the left.
9205 * An inline-alignment is best used with checkboxes or radio buttons.
9207 * Help text is accessed via a help icon that appears in the upper right corner of the rendered field layout when help
9208 * text is specified.
9211 * // Example of an ActionFieldLayout
9212 * var actionFieldLayout = new OO.ui.ActionFieldLayout(
9213 * new OO.ui.TextInputWidget( {
9214 * placeholder: 'Field widget'
9216 * new OO.ui.ButtonWidget( {
9220 * label: 'An ActionFieldLayout. This label is aligned top',
9222 * help: 'This is help text'
9226 * $( 'body' ).append( actionFieldLayout.$element );
9229 * @extends OO.ui.FieldLayout
9232 * @param {OO.ui.Widget} fieldWidget Field widget
9233 * @param {OO.ui.ButtonWidget} buttonWidget Button widget
9235 OO
.ui
.ActionFieldLayout
= function OoUiActionFieldLayout( fieldWidget
, buttonWidget
, config
) {
9236 // Allow passing positional parameters inside the config object
9237 if ( OO
.isPlainObject( fieldWidget
) && config
=== undefined ) {
9238 config
= fieldWidget
;
9239 fieldWidget
= config
.fieldWidget
;
9240 buttonWidget
= config
.buttonWidget
;
9243 // Parent constructor
9244 OO
.ui
.ActionFieldLayout
.parent
.call( this, fieldWidget
, config
);
9247 this.buttonWidget
= buttonWidget
;
9248 this.$button
= $( '<div>' );
9249 this.$input
= $( '<div>' );
9253 .addClass( 'oo-ui-actionFieldLayout' );
9255 .addClass( 'oo-ui-actionFieldLayout-button' )
9256 .append( this.buttonWidget
.$element
);
9258 .addClass( 'oo-ui-actionFieldLayout-input' )
9259 .append( this.fieldWidget
.$element
);
9261 .append( this.$input
, this.$button
);
9266 OO
.inheritClass( OO
.ui
.ActionFieldLayout
, OO
.ui
.FieldLayout
);
9269 * FieldsetLayouts are composed of one or more {@link OO.ui.FieldLayout FieldLayouts},
9270 * which each contain an individual widget and, optionally, a label. Each Fieldset can be
9271 * configured with a label as well. For more information and examples,
9272 * please see the [OOjs UI documentation on MediaWiki][1].
9275 * // Example of a fieldset layout
9276 * var input1 = new OO.ui.TextInputWidget( {
9277 * placeholder: 'A text input field'
9280 * var input2 = new OO.ui.TextInputWidget( {
9281 * placeholder: 'A text input field'
9284 * var fieldset = new OO.ui.FieldsetLayout( {
9285 * label: 'Example of a fieldset layout'
9288 * fieldset.addItems( [
9289 * new OO.ui.FieldLayout( input1, {
9290 * label: 'Field One'
9292 * new OO.ui.FieldLayout( input2, {
9293 * label: 'Field Two'
9296 * $( 'body' ).append( fieldset.$element );
9298 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Layouts/Fields_and_Fieldsets
9301 * @extends OO.ui.Layout
9302 * @mixins OO.ui.mixin.IconElement
9303 * @mixins OO.ui.mixin.LabelElement
9304 * @mixins OO.ui.mixin.GroupElement
9307 * @param {Object} [config] Configuration options
9308 * @cfg {OO.ui.FieldLayout[]} [items] An array of fields to add to the fieldset. See OO.ui.FieldLayout for more information about fields.
9310 OO
.ui
.FieldsetLayout
= function OoUiFieldsetLayout( config
) {
9311 // Configuration initialization
9312 config
= config
|| {};
9314 // Parent constructor
9315 OO
.ui
.FieldsetLayout
.parent
.call( this, config
);
9317 // Mixin constructors
9318 OO
.ui
.mixin
.IconElement
.call( this, config
);
9319 OO
.ui
.mixin
.LabelElement
.call( this, config
);
9320 OO
.ui
.mixin
.GroupElement
.call( this, config
);
9322 if ( config
.help
) {
9323 this.popupButtonWidget
= new OO
.ui
.PopupButtonWidget( {
9324 classes
: [ 'oo-ui-fieldsetLayout-help' ],
9329 this.popupButtonWidget
.getPopup().$body
.append(
9331 .text( config
.help
)
9332 .addClass( 'oo-ui-fieldsetLayout-help-content' )
9334 this.$help
= this.popupButtonWidget
.$element
;
9336 this.$help
= $( [] );
9341 .addClass( 'oo-ui-fieldsetLayout' )
9342 .prepend( this.$help
, this.$icon
, this.$label
, this.$group
);
9343 if ( Array
.isArray( config
.items
) ) {
9344 this.addItems( config
.items
);
9350 OO
.inheritClass( OO
.ui
.FieldsetLayout
, OO
.ui
.Layout
);
9351 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.mixin
.IconElement
);
9352 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.mixin
.LabelElement
);
9353 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.mixin
.GroupElement
);
9356 * FormLayouts are used to wrap {@link OO.ui.FieldsetLayout FieldsetLayouts} when you intend to use browser-based
9357 * form submission for the fields instead of handling them in JavaScript. Form layouts can be configured with an
9358 * HTML form action, an encoding type, and a method using the #action, #enctype, and #method configs, respectively.
9359 * See the [OOjs UI documentation on MediaWiki] [1] for more information and examples.
9361 * Only widgets from the {@link OO.ui.InputWidget InputWidget} family support form submission. It
9362 * includes standard form elements like {@link OO.ui.CheckboxInputWidget checkboxes}, {@link
9363 * OO.ui.RadioInputWidget radio buttons} and {@link OO.ui.TextInputWidget text fields}, as well as
9364 * some fancier controls. Some controls have both regular and InputWidget variants, for example
9365 * OO.ui.DropdownWidget and OO.ui.DropdownInputWidget – only the latter support form submission and
9366 * often have simplified APIs to match the capabilities of HTML forms.
9367 * See the [OOjs UI Inputs documentation on MediaWiki] [2] for more information about InputWidgets.
9369 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Layouts/Forms
9370 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
9373 * // Example of a form layout that wraps a fieldset layout
9374 * var input1 = new OO.ui.TextInputWidget( {
9375 * placeholder: 'Username'
9377 * var input2 = new OO.ui.TextInputWidget( {
9378 * placeholder: 'Password',
9381 * var submit = new OO.ui.ButtonInputWidget( {
9385 * var fieldset = new OO.ui.FieldsetLayout( {
9386 * label: 'A form layout'
9388 * fieldset.addItems( [
9389 * new OO.ui.FieldLayout( input1, {
9390 * label: 'Username',
9393 * new OO.ui.FieldLayout( input2, {
9394 * label: 'Password',
9397 * new OO.ui.FieldLayout( submit )
9399 * var form = new OO.ui.FormLayout( {
9400 * items: [ fieldset ],
9401 * action: '/api/formhandler',
9404 * $( 'body' ).append( form.$element );
9407 * @extends OO.ui.Layout
9408 * @mixins OO.ui.mixin.GroupElement
9411 * @param {Object} [config] Configuration options
9412 * @cfg {string} [method] HTML form `method` attribute
9413 * @cfg {string} [action] HTML form `action` attribute
9414 * @cfg {string} [enctype] HTML form `enctype` attribute
9415 * @cfg {OO.ui.FieldsetLayout[]} [items] Fieldset layouts to add to the form layout.
9417 OO
.ui
.FormLayout
= function OoUiFormLayout( config
) {
9418 // Configuration initialization
9419 config
= config
|| {};
9421 // Parent constructor
9422 OO
.ui
.FormLayout
.parent
.call( this, config
);
9424 // Mixin constructors
9425 OO
.ui
.mixin
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
9428 this.$element
.on( 'submit', this.onFormSubmit
.bind( this ) );
9430 // Make sure the action is safe
9431 if ( config
.action
!== undefined && !OO
.ui
.isSafeUrl( config
.action
) ) {
9432 throw new Error( 'Potentially unsafe action provided: ' + config
.action
);
9437 .addClass( 'oo-ui-formLayout' )
9439 method
: config
.method
,
9440 action
: config
.action
,
9441 enctype
: config
.enctype
9443 if ( Array
.isArray( config
.items
) ) {
9444 this.addItems( config
.items
);
9450 OO
.inheritClass( OO
.ui
.FormLayout
, OO
.ui
.Layout
);
9451 OO
.mixinClass( OO
.ui
.FormLayout
, OO
.ui
.mixin
.GroupElement
);
9456 * A 'submit' event is emitted when the form is submitted.
9461 /* Static Properties */
9463 OO
.ui
.FormLayout
.static.tagName
= 'form';
9468 * Handle form submit events.
9471 * @param {jQuery.Event} e Submit event
9474 OO
.ui
.FormLayout
.prototype.onFormSubmit = function () {
9475 if ( this.emit( 'submit' ) ) {
9481 * 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)
9482 * and its size is customized with the #menuSize config. The content area will fill all remaining space.
9485 * var menuLayout = new OO.ui.MenuLayout( {
9488 * menuPanel = new OO.ui.PanelLayout( { padded: true, expanded: true, scrollable: true } ),
9489 * contentPanel = new OO.ui.PanelLayout( { padded: true, expanded: true, scrollable: true } ),
9490 * select = new OO.ui.SelectWidget( {
9492 * new OO.ui.OptionWidget( {
9496 * new OO.ui.OptionWidget( {
9500 * new OO.ui.OptionWidget( {
9504 * new OO.ui.OptionWidget( {
9509 * } ).on( 'select', function ( item ) {
9510 * menuLayout.setMenuPosition( item.getData() );
9513 * menuLayout.$menu.append(
9514 * menuPanel.$element.append( '<b>Menu panel</b>', select.$element )
9516 * menuLayout.$content.append(
9517 * contentPanel.$element.append( '<b>Content panel</b>', '<p>Note that the menu is positioned relative to the content panel: top, bottom, after, before.</p>')
9519 * $( 'body' ).append( menuLayout.$element );
9521 * If menu size needs to be overridden, it can be accomplished using CSS similar to the snippet
9522 * below. MenuLayout's CSS will override the appropriate values with 'auto' or '0' to display the
9523 * menu correctly. If `menuPosition` is known beforehand, CSS rules corresponding to other positions
9526 * .oo-ui-menuLayout-menu {
9530 * .oo-ui-menuLayout-content {
9538 * @extends OO.ui.Layout
9541 * @param {Object} [config] Configuration options
9542 * @cfg {boolean} [showMenu=true] Show menu
9543 * @cfg {string} [menuPosition='before'] Position of menu: `top`, `after`, `bottom` or `before`
9545 OO
.ui
.MenuLayout
= function OoUiMenuLayout( config
) {
9546 // Configuration initialization
9547 config
= $.extend( {
9549 menuPosition
: 'before'
9552 // Parent constructor
9553 OO
.ui
.MenuLayout
.parent
.call( this, config
);
9558 * @property {jQuery}
9560 this.$menu
= $( '<div>' );
9564 * @property {jQuery}
9566 this.$content
= $( '<div>' );
9570 .addClass( 'oo-ui-menuLayout-menu' );
9571 this.$content
.addClass( 'oo-ui-menuLayout-content' );
9573 .addClass( 'oo-ui-menuLayout' )
9574 .append( this.$content
, this.$menu
);
9575 this.setMenuPosition( config
.menuPosition
);
9576 this.toggleMenu( config
.showMenu
);
9581 OO
.inheritClass( OO
.ui
.MenuLayout
, OO
.ui
.Layout
);
9588 * @param {boolean} showMenu Show menu, omit to toggle
9591 OO
.ui
.MenuLayout
.prototype.toggleMenu = function ( showMenu
) {
9592 showMenu
= showMenu
=== undefined ? !this.showMenu
: !!showMenu
;
9594 if ( this.showMenu
!== showMenu
) {
9595 this.showMenu
= showMenu
;
9597 .toggleClass( 'oo-ui-menuLayout-showMenu', this.showMenu
)
9598 .toggleClass( 'oo-ui-menuLayout-hideMenu', !this.showMenu
);
9605 * Check if menu is visible
9607 * @return {boolean} Menu is visible
9609 OO
.ui
.MenuLayout
.prototype.isMenuVisible = function () {
9610 return this.showMenu
;
9614 * Set menu position.
9616 * @param {string} position Position of menu, either `top`, `after`, `bottom` or `before`
9617 * @throws {Error} If position value is not supported
9620 OO
.ui
.MenuLayout
.prototype.setMenuPosition = function ( position
) {
9621 this.$element
.removeClass( 'oo-ui-menuLayout-' + this.menuPosition
);
9622 this.menuPosition
= position
;
9623 this.$element
.addClass( 'oo-ui-menuLayout-' + position
);
9629 * Get menu position.
9631 * @return {string} Menu position
9633 OO
.ui
.MenuLayout
.prototype.getMenuPosition = function () {
9634 return this.menuPosition
;
9638 * BookletLayouts contain {@link OO.ui.PageLayout page layouts} as well as
9639 * an {@link OO.ui.OutlineSelectWidget outline} that allows users to easily navigate
9640 * through the pages and select which one to display. By default, only one page is
9641 * displayed at a time and the outline is hidden. When a user navigates to a new page,
9642 * the booklet layout automatically focuses on the first focusable element, unless the
9643 * default setting is changed. Optionally, booklets can be configured to show
9644 * {@link OO.ui.OutlineControlsWidget controls} for adding, moving, and removing items.
9647 * // Example of a BookletLayout that contains two PageLayouts.
9649 * function PageOneLayout( name, config ) {
9650 * PageOneLayout.parent.call( this, name, config );
9651 * this.$element.append( '<p>First page</p><p>(This booklet has an outline, displayed on the left)</p>' );
9653 * OO.inheritClass( PageOneLayout, OO.ui.PageLayout );
9654 * PageOneLayout.prototype.setupOutlineItem = function () {
9655 * this.outlineItem.setLabel( 'Page One' );
9658 * function PageTwoLayout( name, config ) {
9659 * PageTwoLayout.parent.call( this, name, config );
9660 * this.$element.append( '<p>Second page</p>' );
9662 * OO.inheritClass( PageTwoLayout, OO.ui.PageLayout );
9663 * PageTwoLayout.prototype.setupOutlineItem = function () {
9664 * this.outlineItem.setLabel( 'Page Two' );
9667 * var page1 = new PageOneLayout( 'one' ),
9668 * page2 = new PageTwoLayout( 'two' );
9670 * var booklet = new OO.ui.BookletLayout( {
9674 * booklet.addPages ( [ page1, page2 ] );
9675 * $( 'body' ).append( booklet.$element );
9678 * @extends OO.ui.MenuLayout
9681 * @param {Object} [config] Configuration options
9682 * @cfg {boolean} [continuous=false] Show all pages, one after another
9683 * @cfg {boolean} [autoFocus=true] Focus on the first focusable element when a new page is displayed.
9684 * @cfg {boolean} [outlined=false] Show the outline. The outline is used to navigate through the pages of the booklet.
9685 * @cfg {boolean} [editable=false] Show controls for adding, removing and reordering pages
9687 OO
.ui
.BookletLayout
= function OoUiBookletLayout( config
) {
9688 // Configuration initialization
9689 config
= config
|| {};
9691 // Parent constructor
9692 OO
.ui
.BookletLayout
.parent
.call( this, config
);
9695 this.currentPageName
= null;
9697 this.ignoreFocus
= false;
9698 this.stackLayout
= new OO
.ui
.StackLayout( { continuous
: !!config
.continuous
} );
9699 this.$content
.append( this.stackLayout
.$element
);
9700 this.autoFocus
= config
.autoFocus
=== undefined || !!config
.autoFocus
;
9701 this.outlineVisible
= false;
9702 this.outlined
= !!config
.outlined
;
9703 if ( this.outlined
) {
9704 this.editable
= !!config
.editable
;
9705 this.outlineControlsWidget
= null;
9706 this.outlineSelectWidget
= new OO
.ui
.OutlineSelectWidget();
9707 this.outlinePanel
= new OO
.ui
.PanelLayout( { scrollable
: true } );
9708 this.$menu
.append( this.outlinePanel
.$element
);
9709 this.outlineVisible
= true;
9710 if ( this.editable
) {
9711 this.outlineControlsWidget
= new OO
.ui
.OutlineControlsWidget(
9712 this.outlineSelectWidget
9716 this.toggleMenu( this.outlined
);
9719 this.stackLayout
.connect( this, { set: 'onStackLayoutSet' } );
9720 if ( this.outlined
) {
9721 this.outlineSelectWidget
.connect( this, { select
: 'onOutlineSelectWidgetSelect' } );
9723 if ( this.autoFocus
) {
9724 // Event 'focus' does not bubble, but 'focusin' does
9725 this.stackLayout
.$element
.on( 'focusin', this.onStackLayoutFocus
.bind( this ) );
9729 this.$element
.addClass( 'oo-ui-bookletLayout' );
9730 this.stackLayout
.$element
.addClass( 'oo-ui-bookletLayout-stackLayout' );
9731 if ( this.outlined
) {
9732 this.outlinePanel
.$element
9733 .addClass( 'oo-ui-bookletLayout-outlinePanel' )
9734 .append( this.outlineSelectWidget
.$element
);
9735 if ( this.editable
) {
9736 this.outlinePanel
.$element
9737 .addClass( 'oo-ui-bookletLayout-outlinePanel-editable' )
9738 .append( this.outlineControlsWidget
.$element
);
9745 OO
.inheritClass( OO
.ui
.BookletLayout
, OO
.ui
.MenuLayout
);
9750 * A 'set' event is emitted when a page is {@link #setPage set} to be displayed by the booklet layout.
9752 * @param {OO.ui.PageLayout} page Current page
9756 * An 'add' event is emitted when pages are {@link #addPages added} to the booklet layout.
9759 * @param {OO.ui.PageLayout[]} page Added pages
9760 * @param {number} index Index pages were added at
9764 * A 'remove' event is emitted when pages are {@link #clearPages cleared} or
9765 * {@link #removePages removed} from the booklet.
9768 * @param {OO.ui.PageLayout[]} pages Removed pages
9774 * Handle stack layout focus.
9777 * @param {jQuery.Event} e Focusin event
9779 OO
.ui
.BookletLayout
.prototype.onStackLayoutFocus = function ( e
) {
9782 // Find the page that an element was focused within
9783 $target
= $( e
.target
).closest( '.oo-ui-pageLayout' );
9784 for ( name
in this.pages
) {
9785 // Check for page match, exclude current page to find only page changes
9786 if ( this.pages
[ name
].$element
[ 0 ] === $target
[ 0 ] && name
!== this.currentPageName
) {
9787 this.setPage( name
);
9794 * Handle stack layout set events.
9797 * @param {OO.ui.PanelLayout|null} page The page panel that is now the current panel
9799 OO
.ui
.BookletLayout
.prototype.onStackLayoutSet = function ( page
) {
9802 page
.scrollElementIntoView( { complete: function () {
9803 if ( layout
.autoFocus
) {
9811 * Focus the first input in the current page.
9813 * If no page is selected, the first selectable page will be selected.
9814 * If the focus is already in an element on the current page, nothing will happen.
9815 * @param {number} [itemIndex] A specific item to focus on
9817 OO
.ui
.BookletLayout
.prototype.focus = function ( itemIndex
) {
9819 items
= this.stackLayout
.getItems();
9821 if ( itemIndex
!== undefined && items
[ itemIndex
] ) {
9822 page
= items
[ itemIndex
];
9824 page
= this.stackLayout
.getCurrentItem();
9827 if ( !page
&& this.outlined
) {
9828 this.selectFirstSelectablePage();
9829 page
= this.stackLayout
.getCurrentItem();
9834 // Only change the focus if is not already in the current page
9835 if ( !OO
.ui
.contains( page
.$element
[ 0 ], this.getElementDocument().activeElement
, true ) ) {
9841 * Find the first focusable input in the booklet layout and focus
9844 OO
.ui
.BookletLayout
.prototype.focusFirstFocusable = function () {
9845 OO
.ui
.findFocusable( this.stackLayout
.$element
).focus();
9849 * Handle outline widget select events.
9852 * @param {OO.ui.OptionWidget|null} item Selected item
9854 OO
.ui
.BookletLayout
.prototype.onOutlineSelectWidgetSelect = function ( item
) {
9856 this.setPage( item
.getData() );
9861 * Check if booklet has an outline.
9863 * @return {boolean} Booklet has an outline
9865 OO
.ui
.BookletLayout
.prototype.isOutlined = function () {
9866 return this.outlined
;
9870 * Check if booklet has editing controls.
9872 * @return {boolean} Booklet is editable
9874 OO
.ui
.BookletLayout
.prototype.isEditable = function () {
9875 return this.editable
;
9879 * Check if booklet has a visible outline.
9881 * @return {boolean} Outline is visible
9883 OO
.ui
.BookletLayout
.prototype.isOutlineVisible = function () {
9884 return this.outlined
&& this.outlineVisible
;
9888 * Hide or show the outline.
9890 * @param {boolean} [show] Show outline, omit to invert current state
9893 OO
.ui
.BookletLayout
.prototype.toggleOutline = function ( show
) {
9894 if ( this.outlined
) {
9895 show
= show
=== undefined ? !this.outlineVisible
: !!show
;
9896 this.outlineVisible
= show
;
9897 this.toggleMenu( show
);
9904 * Get the page closest to the specified page.
9906 * @param {OO.ui.PageLayout} page Page to use as a reference point
9907 * @return {OO.ui.PageLayout|null} Page closest to the specified page
9909 OO
.ui
.BookletLayout
.prototype.getClosestPage = function ( page
) {
9910 var next
, prev
, level
,
9911 pages
= this.stackLayout
.getItems(),
9912 index
= pages
.indexOf( page
);
9914 if ( index
!== -1 ) {
9915 next
= pages
[ index
+ 1 ];
9916 prev
= pages
[ index
- 1 ];
9917 // Prefer adjacent pages at the same level
9918 if ( this.outlined
) {
9919 level
= this.outlineSelectWidget
.getItemFromData( page
.getName() ).getLevel();
9922 level
=== this.outlineSelectWidget
.getItemFromData( prev
.getName() ).getLevel()
9928 level
=== this.outlineSelectWidget
.getItemFromData( next
.getName() ).getLevel()
9934 return prev
|| next
|| null;
9938 * Get the outline widget.
9940 * If the booklet is not outlined, the method will return `null`.
9942 * @return {OO.ui.OutlineSelectWidget|null} Outline widget, or null if the booklet is not outlined
9944 OO
.ui
.BookletLayout
.prototype.getOutline = function () {
9945 return this.outlineSelectWidget
;
9949 * Get the outline controls widget.
9951 * If the outline is not editable, the method will return `null`.
9953 * @return {OO.ui.OutlineControlsWidget|null} The outline controls widget.
9955 OO
.ui
.BookletLayout
.prototype.getOutlineControls = function () {
9956 return this.outlineControlsWidget
;
9960 * Get a page by its symbolic name.
9962 * @param {string} name Symbolic name of page
9963 * @return {OO.ui.PageLayout|undefined} Page, if found
9965 OO
.ui
.BookletLayout
.prototype.getPage = function ( name
) {
9966 return this.pages
[ name
];
9970 * Get the current page.
9972 * @return {OO.ui.PageLayout|undefined} Current page, if found
9974 OO
.ui
.BookletLayout
.prototype.getCurrentPage = function () {
9975 var name
= this.getCurrentPageName();
9976 return name
? this.getPage( name
) : undefined;
9980 * Get the symbolic name of the current page.
9982 * @return {string|null} Symbolic name of the current page
9984 OO
.ui
.BookletLayout
.prototype.getCurrentPageName = function () {
9985 return this.currentPageName
;
9989 * Add pages to the booklet layout
9991 * When pages are added with the same names as existing pages, the existing pages will be
9992 * automatically removed before the new pages are added.
9994 * @param {OO.ui.PageLayout[]} pages Pages to add
9995 * @param {number} index Index of the insertion point
9999 OO
.ui
.BookletLayout
.prototype.addPages = function ( pages
, index
) {
10000 var i
, len
, name
, page
, item
, currentIndex
,
10001 stackLayoutPages
= this.stackLayout
.getItems(),
10005 // Remove pages with same names
10006 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
10008 name
= page
.getName();
10010 if ( Object
.prototype.hasOwnProperty
.call( this.pages
, name
) ) {
10011 // Correct the insertion index
10012 currentIndex
= stackLayoutPages
.indexOf( this.pages
[ name
] );
10013 if ( currentIndex
!== -1 && currentIndex
+ 1 < index
) {
10016 remove
.push( this.pages
[ name
] );
10019 if ( remove
.length
) {
10020 this.removePages( remove
);
10024 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
10026 name
= page
.getName();
10027 this.pages
[ page
.getName() ] = page
;
10028 if ( this.outlined
) {
10029 item
= new OO
.ui
.OutlineOptionWidget( { data
: name
} );
10030 page
.setOutlineItem( item
);
10031 items
.push( item
);
10035 if ( this.outlined
&& items
.length
) {
10036 this.outlineSelectWidget
.addItems( items
, index
);
10037 this.selectFirstSelectablePage();
10039 this.stackLayout
.addItems( pages
, index
);
10040 this.emit( 'add', pages
, index
);
10046 * Remove the specified pages from the booklet layout.
10048 * To remove all pages from the booklet, you may wish to use the #clearPages method instead.
10050 * @param {OO.ui.PageLayout[]} pages An array of pages to remove
10054 OO
.ui
.BookletLayout
.prototype.removePages = function ( pages
) {
10055 var i
, len
, name
, page
,
10058 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
10060 name
= page
.getName();
10061 delete this.pages
[ name
];
10062 if ( this.outlined
) {
10063 items
.push( this.outlineSelectWidget
.getItemFromData( name
) );
10064 page
.setOutlineItem( null );
10067 if ( this.outlined
&& items
.length
) {
10068 this.outlineSelectWidget
.removeItems( items
);
10069 this.selectFirstSelectablePage();
10071 this.stackLayout
.removeItems( pages
);
10072 this.emit( 'remove', pages
);
10078 * Clear all pages from the booklet layout.
10080 * To remove only a subset of pages from the booklet, use the #removePages method.
10085 OO
.ui
.BookletLayout
.prototype.clearPages = function () {
10087 pages
= this.stackLayout
.getItems();
10090 this.currentPageName
= null;
10091 if ( this.outlined
) {
10092 this.outlineSelectWidget
.clearItems();
10093 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
10094 pages
[ i
].setOutlineItem( null );
10097 this.stackLayout
.clearItems();
10099 this.emit( 'remove', pages
);
10105 * Set the current page by symbolic name.
10108 * @param {string} name Symbolic name of page
10110 OO
.ui
.BookletLayout
.prototype.setPage = function ( name
) {
10113 page
= this.pages
[ name
],
10114 previousPage
= this.currentPageName
&& this.pages
[ this.currentPageName
];
10116 if ( name
!== this.currentPageName
) {
10117 if ( this.outlined
) {
10118 selectedItem
= this.outlineSelectWidget
.getSelectedItem();
10119 if ( selectedItem
&& selectedItem
.getData() !== name
) {
10120 this.outlineSelectWidget
.selectItemByData( name
);
10124 if ( previousPage
) {
10125 previousPage
.setActive( false );
10126 // Blur anything focused if the next page doesn't have anything focusable.
10127 // This is not needed if the next page has something focusable (because once it is focused
10128 // this blur happens automatically). If the layout is non-continuous, this check is
10129 // meaningless because the next page is not visible yet and thus can't hold focus.
10132 this.stackLayout
.continuous
&&
10133 OO
.ui
.findFocusable( page
.$element
).length
!== 0
10135 $focused
= previousPage
.$element
.find( ':focus' );
10136 if ( $focused
.length
) {
10137 $focused
[ 0 ].blur();
10141 this.currentPageName
= name
;
10142 page
.setActive( true );
10143 this.stackLayout
.setItem( page
);
10144 if ( !this.stackLayout
.continuous
&& previousPage
) {
10145 // This should not be necessary, since any inputs on the previous page should have been
10146 // blurred when it was hidden, but browsers are not very consistent about this.
10147 $focused
= previousPage
.$element
.find( ':focus' );
10148 if ( $focused
.length
) {
10149 $focused
[ 0 ].blur();
10152 this.emit( 'set', page
);
10158 * Select the first selectable page.
10162 OO
.ui
.BookletLayout
.prototype.selectFirstSelectablePage = function () {
10163 if ( !this.outlineSelectWidget
.getSelectedItem() ) {
10164 this.outlineSelectWidget
.selectItem( this.outlineSelectWidget
.getFirstSelectableItem() );
10171 * IndexLayouts contain {@link OO.ui.CardLayout card layouts} as well as
10172 * {@link OO.ui.TabSelectWidget tabs} that allow users to easily navigate through the cards and
10173 * select which one to display. By default, only one card is displayed at a time. When a user
10174 * navigates to a new card, the index layout automatically focuses on the first focusable element,
10175 * unless the default setting is changed.
10177 * TODO: This class is similar to BookletLayout, we may want to refactor to reduce duplication
10180 * // Example of a IndexLayout that contains two CardLayouts.
10182 * function CardOneLayout( name, config ) {
10183 * CardOneLayout.parent.call( this, name, config );
10184 * this.$element.append( '<p>First card</p>' );
10186 * OO.inheritClass( CardOneLayout, OO.ui.CardLayout );
10187 * CardOneLayout.prototype.setupTabItem = function () {
10188 * this.tabItem.setLabel( 'Card one' );
10191 * var card1 = new CardOneLayout( 'one' ),
10192 * card2 = new CardLayout( 'two', { label: 'Card two' } );
10194 * card2.$element.append( '<p>Second card</p>' );
10196 * var index = new OO.ui.IndexLayout();
10198 * index.addCards ( [ card1, card2 ] );
10199 * $( 'body' ).append( index.$element );
10202 * @extends OO.ui.MenuLayout
10205 * @param {Object} [config] Configuration options
10206 * @cfg {boolean} [continuous=false] Show all cards, one after another
10207 * @cfg {boolean} [expanded=true] Expand the content panel to fill the entire parent element.
10208 * @cfg {boolean} [autoFocus=true] Focus on the first focusable element when a new card is displayed.
10210 OO
.ui
.IndexLayout
= function OoUiIndexLayout( config
) {
10211 // Configuration initialization
10212 config
= $.extend( {}, config
, { menuPosition
: 'top' } );
10214 // Parent constructor
10215 OO
.ui
.IndexLayout
.parent
.call( this, config
);
10218 this.currentCardName
= null;
10220 this.ignoreFocus
= false;
10221 this.stackLayout
= new OO
.ui
.StackLayout( {
10222 continuous
: !!config
.continuous
,
10223 expanded
: config
.expanded
10225 this.$content
.append( this.stackLayout
.$element
);
10226 this.autoFocus
= config
.autoFocus
=== undefined || !!config
.autoFocus
;
10228 this.tabSelectWidget
= new OO
.ui
.TabSelectWidget();
10229 this.tabPanel
= new OO
.ui
.PanelLayout();
10230 this.$menu
.append( this.tabPanel
.$element
);
10232 this.toggleMenu( true );
10235 this.stackLayout
.connect( this, { set: 'onStackLayoutSet' } );
10236 this.tabSelectWidget
.connect( this, { select
: 'onTabSelectWidgetSelect' } );
10237 if ( this.autoFocus
) {
10238 // Event 'focus' does not bubble, but 'focusin' does
10239 this.stackLayout
.$element
.on( 'focusin', this.onStackLayoutFocus
.bind( this ) );
10243 this.$element
.addClass( 'oo-ui-indexLayout' );
10244 this.stackLayout
.$element
.addClass( 'oo-ui-indexLayout-stackLayout' );
10245 this.tabPanel
.$element
10246 .addClass( 'oo-ui-indexLayout-tabPanel' )
10247 .append( this.tabSelectWidget
.$element
);
10252 OO
.inheritClass( OO
.ui
.IndexLayout
, OO
.ui
.MenuLayout
);
10257 * A 'set' event is emitted when a card is {@link #setCard set} to be displayed by the index layout.
10259 * @param {OO.ui.CardLayout} card Current card
10263 * An 'add' event is emitted when cards are {@link #addCards added} to the index layout.
10266 * @param {OO.ui.CardLayout[]} card Added cards
10267 * @param {number} index Index cards were added at
10271 * A 'remove' event is emitted when cards are {@link #clearCards cleared} or
10272 * {@link #removeCards removed} from the index.
10275 * @param {OO.ui.CardLayout[]} cards Removed cards
10281 * Handle stack layout focus.
10284 * @param {jQuery.Event} e Focusin event
10286 OO
.ui
.IndexLayout
.prototype.onStackLayoutFocus = function ( e
) {
10289 // Find the card that an element was focused within
10290 $target
= $( e
.target
).closest( '.oo-ui-cardLayout' );
10291 for ( name
in this.cards
) {
10292 // Check for card match, exclude current card to find only card changes
10293 if ( this.cards
[ name
].$element
[ 0 ] === $target
[ 0 ] && name
!== this.currentCardName
) {
10294 this.setCard( name
);
10301 * Handle stack layout set events.
10304 * @param {OO.ui.PanelLayout|null} card The card panel that is now the current panel
10306 OO
.ui
.IndexLayout
.prototype.onStackLayoutSet = function ( card
) {
10309 card
.scrollElementIntoView( { complete: function () {
10310 if ( layout
.autoFocus
) {
10318 * Focus the first input in the current card.
10320 * If no card is selected, the first selectable card will be selected.
10321 * If the focus is already in an element on the current card, nothing will happen.
10322 * @param {number} [itemIndex] A specific item to focus on
10324 OO
.ui
.IndexLayout
.prototype.focus = function ( itemIndex
) {
10326 items
= this.stackLayout
.getItems();
10328 if ( itemIndex
!== undefined && items
[ itemIndex
] ) {
10329 card
= items
[ itemIndex
];
10331 card
= this.stackLayout
.getCurrentItem();
10335 this.selectFirstSelectableCard();
10336 card
= this.stackLayout
.getCurrentItem();
10341 // Only change the focus if is not already in the current page
10342 if ( !OO
.ui
.contains( card
.$element
[ 0 ], this.getElementDocument().activeElement
, true ) ) {
10348 * Find the first focusable input in the index layout and focus
10351 OO
.ui
.IndexLayout
.prototype.focusFirstFocusable = function () {
10352 OO
.ui
.findFocusable( this.stackLayout
.$element
).focus();
10356 * Handle tab widget select events.
10359 * @param {OO.ui.OptionWidget|null} item Selected item
10361 OO
.ui
.IndexLayout
.prototype.onTabSelectWidgetSelect = function ( item
) {
10363 this.setCard( item
.getData() );
10368 * Get the card closest to the specified card.
10370 * @param {OO.ui.CardLayout} card Card to use as a reference point
10371 * @return {OO.ui.CardLayout|null} Card closest to the specified card
10373 OO
.ui
.IndexLayout
.prototype.getClosestCard = function ( card
) {
10374 var next
, prev
, level
,
10375 cards
= this.stackLayout
.getItems(),
10376 index
= cards
.indexOf( card
);
10378 if ( index
!== -1 ) {
10379 next
= cards
[ index
+ 1 ];
10380 prev
= cards
[ index
- 1 ];
10381 // Prefer adjacent cards at the same level
10382 level
= this.tabSelectWidget
.getItemFromData( card
.getName() ).getLevel();
10385 level
=== this.tabSelectWidget
.getItemFromData( prev
.getName() ).getLevel()
10391 level
=== this.tabSelectWidget
.getItemFromData( next
.getName() ).getLevel()
10396 return prev
|| next
|| null;
10400 * Get the tabs widget.
10402 * @return {OO.ui.TabSelectWidget} Tabs widget
10404 OO
.ui
.IndexLayout
.prototype.getTabs = function () {
10405 return this.tabSelectWidget
;
10409 * Get a card by its symbolic name.
10411 * @param {string} name Symbolic name of card
10412 * @return {OO.ui.CardLayout|undefined} Card, if found
10414 OO
.ui
.IndexLayout
.prototype.getCard = function ( name
) {
10415 return this.cards
[ name
];
10419 * Get the current card.
10421 * @return {OO.ui.CardLayout|undefined} Current card, if found
10423 OO
.ui
.IndexLayout
.prototype.getCurrentCard = function () {
10424 var name
= this.getCurrentCardName();
10425 return name
? this.getCard( name
) : undefined;
10429 * Get the symbolic name of the current card.
10431 * @return {string|null} Symbolic name of the current card
10433 OO
.ui
.IndexLayout
.prototype.getCurrentCardName = function () {
10434 return this.currentCardName
;
10438 * Add cards to the index layout
10440 * When cards are added with the same names as existing cards, the existing cards will be
10441 * automatically removed before the new cards are added.
10443 * @param {OO.ui.CardLayout[]} cards Cards to add
10444 * @param {number} index Index of the insertion point
10448 OO
.ui
.IndexLayout
.prototype.addCards = function ( cards
, index
) {
10449 var i
, len
, name
, card
, item
, currentIndex
,
10450 stackLayoutCards
= this.stackLayout
.getItems(),
10454 // Remove cards with same names
10455 for ( i
= 0, len
= cards
.length
; i
< len
; i
++ ) {
10457 name
= card
.getName();
10459 if ( Object
.prototype.hasOwnProperty
.call( this.cards
, name
) ) {
10460 // Correct the insertion index
10461 currentIndex
= stackLayoutCards
.indexOf( this.cards
[ name
] );
10462 if ( currentIndex
!== -1 && currentIndex
+ 1 < index
) {
10465 remove
.push( this.cards
[ name
] );
10468 if ( remove
.length
) {
10469 this.removeCards( remove
);
10473 for ( i
= 0, len
= cards
.length
; i
< len
; i
++ ) {
10475 name
= card
.getName();
10476 this.cards
[ card
.getName() ] = card
;
10477 item
= new OO
.ui
.TabOptionWidget( { data
: name
} );
10478 card
.setTabItem( item
);
10479 items
.push( item
);
10482 if ( items
.length
) {
10483 this.tabSelectWidget
.addItems( items
, index
);
10484 this.selectFirstSelectableCard();
10486 this.stackLayout
.addItems( cards
, index
);
10487 this.emit( 'add', cards
, index
);
10493 * Remove the specified cards from the index layout.
10495 * To remove all cards from the index, you may wish to use the #clearCards method instead.
10497 * @param {OO.ui.CardLayout[]} cards An array of cards to remove
10501 OO
.ui
.IndexLayout
.prototype.removeCards = function ( cards
) {
10502 var i
, len
, name
, card
,
10505 for ( i
= 0, len
= cards
.length
; i
< len
; i
++ ) {
10507 name
= card
.getName();
10508 delete this.cards
[ name
];
10509 items
.push( this.tabSelectWidget
.getItemFromData( name
) );
10510 card
.setTabItem( null );
10512 if ( items
.length
) {
10513 this.tabSelectWidget
.removeItems( items
);
10514 this.selectFirstSelectableCard();
10516 this.stackLayout
.removeItems( cards
);
10517 this.emit( 'remove', cards
);
10523 * Clear all cards from the index layout.
10525 * To remove only a subset of cards from the index, use the #removeCards method.
10530 OO
.ui
.IndexLayout
.prototype.clearCards = function () {
10532 cards
= this.stackLayout
.getItems();
10535 this.currentCardName
= null;
10536 this.tabSelectWidget
.clearItems();
10537 for ( i
= 0, len
= cards
.length
; i
< len
; i
++ ) {
10538 cards
[ i
].setTabItem( null );
10540 this.stackLayout
.clearItems();
10542 this.emit( 'remove', cards
);
10548 * Set the current card by symbolic name.
10551 * @param {string} name Symbolic name of card
10553 OO
.ui
.IndexLayout
.prototype.setCard = function ( name
) {
10556 card
= this.cards
[ name
],
10557 previousCard
= this.currentCardName
&& this.cards
[ this.currentCardName
];
10559 if ( name
!== this.currentCardName
) {
10560 selectedItem
= this.tabSelectWidget
.getSelectedItem();
10561 if ( selectedItem
&& selectedItem
.getData() !== name
) {
10562 this.tabSelectWidget
.selectItemByData( name
);
10565 if ( previousCard
) {
10566 previousCard
.setActive( false );
10567 // Blur anything focused if the next card doesn't have anything focusable.
10568 // This is not needed if the next card has something focusable (because once it is focused
10569 // this blur happens automatically). If the layout is non-continuous, this check is
10570 // meaningless because the next card is not visible yet and thus can't hold focus.
10573 this.stackLayout
.continuous
&&
10574 OO
.ui
.findFocusable( card
.$element
).length
!== 0
10576 $focused
= previousCard
.$element
.find( ':focus' );
10577 if ( $focused
.length
) {
10578 $focused
[ 0 ].blur();
10582 this.currentCardName
= name
;
10583 card
.setActive( true );
10584 this.stackLayout
.setItem( card
);
10585 if ( !this.stackLayout
.continuous
&& previousCard
) {
10586 // This should not be necessary, since any inputs on the previous card should have been
10587 // blurred when it was hidden, but browsers are not very consistent about this.
10588 $focused
= previousCard
.$element
.find( ':focus' );
10589 if ( $focused
.length
) {
10590 $focused
[ 0 ].blur();
10593 this.emit( 'set', card
);
10599 * Select the first selectable card.
10603 OO
.ui
.IndexLayout
.prototype.selectFirstSelectableCard = function () {
10604 if ( !this.tabSelectWidget
.getSelectedItem() ) {
10605 this.tabSelectWidget
.selectItem( this.tabSelectWidget
.getFirstSelectableItem() );
10612 * PanelLayouts expand to cover the entire area of their parent. They can be configured with scrolling, padding,
10613 * and a frame, and are often used together with {@link OO.ui.StackLayout StackLayouts}.
10616 * // Example of a panel layout
10617 * var panel = new OO.ui.PanelLayout( {
10621 * $content: $( '<p>A panel layout with padding and a frame.</p>' )
10623 * $( 'body' ).append( panel.$element );
10626 * @extends OO.ui.Layout
10629 * @param {Object} [config] Configuration options
10630 * @cfg {boolean} [scrollable=false] Allow vertical scrolling
10631 * @cfg {boolean} [padded=false] Add padding between the content and the edges of the panel.
10632 * @cfg {boolean} [expanded=true] Expand the panel to fill the entire parent element.
10633 * @cfg {boolean} [framed=false] Render the panel with a frame to visually separate it from outside content.
10635 OO
.ui
.PanelLayout
= function OoUiPanelLayout( config
) {
10636 // Configuration initialization
10637 config
= $.extend( {
10644 // Parent constructor
10645 OO
.ui
.PanelLayout
.parent
.call( this, config
);
10648 this.$element
.addClass( 'oo-ui-panelLayout' );
10649 if ( config
.scrollable
) {
10650 this.$element
.addClass( 'oo-ui-panelLayout-scrollable' );
10652 if ( config
.padded
) {
10653 this.$element
.addClass( 'oo-ui-panelLayout-padded' );
10655 if ( config
.expanded
) {
10656 this.$element
.addClass( 'oo-ui-panelLayout-expanded' );
10658 if ( config
.framed
) {
10659 this.$element
.addClass( 'oo-ui-panelLayout-framed' );
10665 OO
.inheritClass( OO
.ui
.PanelLayout
, OO
.ui
.Layout
);
10670 * Focus the panel layout
10672 * The default implementation just focuses the first focusable element in the panel
10674 OO
.ui
.PanelLayout
.prototype.focus = function () {
10675 OO
.ui
.findFocusable( this.$element
).focus();
10679 * CardLayouts are used within {@link OO.ui.IndexLayout index layouts} to create cards that users can select and display
10680 * from the index's optional {@link OO.ui.TabSelectWidget tab} navigation. Cards are usually not instantiated directly,
10681 * rather extended to include the required content and functionality.
10683 * Each card must have a unique symbolic name, which is passed to the constructor. In addition, the card's tab
10684 * item is customized (with a label) using the #setupTabItem method. See
10685 * {@link OO.ui.IndexLayout IndexLayout} for an example.
10688 * @extends OO.ui.PanelLayout
10691 * @param {string} name Unique symbolic name of card
10692 * @param {Object} [config] Configuration options
10693 * @cfg {jQuery|string|Function|OO.ui.HtmlSnippet} [label] Label for card's tab
10695 OO
.ui
.CardLayout
= function OoUiCardLayout( name
, config
) {
10696 // Allow passing positional parameters inside the config object
10697 if ( OO
.isPlainObject( name
) && config
=== undefined ) {
10699 name
= config
.name
;
10702 // Configuration initialization
10703 config
= $.extend( { scrollable
: true }, config
);
10705 // Parent constructor
10706 OO
.ui
.CardLayout
.parent
.call( this, config
);
10710 this.label
= config
.label
;
10711 this.tabItem
= null;
10712 this.active
= false;
10715 this.$element
.addClass( 'oo-ui-cardLayout' );
10720 OO
.inheritClass( OO
.ui
.CardLayout
, OO
.ui
.PanelLayout
);
10725 * An 'active' event is emitted when the card becomes active. Cards become active when they are
10726 * shown in a index layout that is configured to display only one card at a time.
10729 * @param {boolean} active Card is active
10735 * Get the symbolic name of the card.
10737 * @return {string} Symbolic name of card
10739 OO
.ui
.CardLayout
.prototype.getName = function () {
10744 * Check if card is active.
10746 * Cards become active when they are shown in a {@link OO.ui.IndexLayout index layout} that is configured to display
10747 * only one card at a time. Additional CSS is applied to the card's tab item to reflect the active state.
10749 * @return {boolean} Card is active
10751 OO
.ui
.CardLayout
.prototype.isActive = function () {
10752 return this.active
;
10758 * The tab item allows users to access the card from the index's tab
10759 * navigation. The tab item itself can be customized (with a label, level, etc.) using the #setupTabItem method.
10761 * @return {OO.ui.TabOptionWidget|null} Tab option widget
10763 OO
.ui
.CardLayout
.prototype.getTabItem = function () {
10764 return this.tabItem
;
10768 * Set or unset the tab item.
10770 * Specify a {@link OO.ui.TabOptionWidget tab option} to set it,
10771 * or `null` to clear the tab item. To customize the tab item itself (e.g., to set a label or tab
10772 * level), use #setupTabItem instead of this method.
10774 * @param {OO.ui.TabOptionWidget|null} tabItem Tab option widget, null to clear
10777 OO
.ui
.CardLayout
.prototype.setTabItem = function ( tabItem
) {
10778 this.tabItem
= tabItem
|| null;
10780 this.setupTabItem();
10786 * Set up the tab item.
10788 * Use this method to customize the tab item (e.g., to add a label or tab level). To set or unset
10789 * the tab item itself (with a {@link OO.ui.TabOptionWidget tab option} or `null`), use
10790 * the #setTabItem method instead.
10792 * @param {OO.ui.TabOptionWidget} tabItem Tab option widget to set up
10795 OO
.ui
.CardLayout
.prototype.setupTabItem = function () {
10796 if ( this.label
) {
10797 this.tabItem
.setLabel( this.label
);
10803 * Set the card to its 'active' state.
10805 * Cards become active when they are shown in a index layout that is configured to display only one card at a time. Additional
10806 * CSS is applied to the tab item to reflect the card's active state. Outside of the index
10807 * context, setting the active state on a card does nothing.
10809 * @param {boolean} value Card is active
10812 OO
.ui
.CardLayout
.prototype.setActive = function ( active
) {
10815 if ( active
!== this.active
) {
10816 this.active
= active
;
10817 this.$element
.toggleClass( 'oo-ui-cardLayout-active', this.active
);
10818 this.emit( 'active', this.active
);
10823 * PageLayouts are used within {@link OO.ui.BookletLayout booklet layouts} to create pages that users can select and display
10824 * from the booklet's optional {@link OO.ui.OutlineSelectWidget outline} navigation. Pages are usually not instantiated directly,
10825 * rather extended to include the required content and functionality.
10827 * Each page must have a unique symbolic name, which is passed to the constructor. In addition, the page's outline
10828 * item is customized (with a label, outline level, etc.) using the #setupOutlineItem method. See
10829 * {@link OO.ui.BookletLayout BookletLayout} for an example.
10832 * @extends OO.ui.PanelLayout
10835 * @param {string} name Unique symbolic name of page
10836 * @param {Object} [config] Configuration options
10838 OO
.ui
.PageLayout
= function OoUiPageLayout( name
, config
) {
10839 // Allow passing positional parameters inside the config object
10840 if ( OO
.isPlainObject( name
) && config
=== undefined ) {
10842 name
= config
.name
;
10845 // Configuration initialization
10846 config
= $.extend( { scrollable
: true }, config
);
10848 // Parent constructor
10849 OO
.ui
.PageLayout
.parent
.call( this, config
);
10853 this.outlineItem
= null;
10854 this.active
= false;
10857 this.$element
.addClass( 'oo-ui-pageLayout' );
10862 OO
.inheritClass( OO
.ui
.PageLayout
, OO
.ui
.PanelLayout
);
10867 * An 'active' event is emitted when the page becomes active. Pages become active when they are
10868 * shown in a booklet layout that is configured to display only one page at a time.
10871 * @param {boolean} active Page is active
10877 * Get the symbolic name of the page.
10879 * @return {string} Symbolic name of page
10881 OO
.ui
.PageLayout
.prototype.getName = function () {
10886 * Check if page is active.
10888 * Pages become active when they are shown in a {@link OO.ui.BookletLayout booklet layout} that is configured to display
10889 * only one page at a time. Additional CSS is applied to the page's outline item to reflect the active state.
10891 * @return {boolean} Page is active
10893 OO
.ui
.PageLayout
.prototype.isActive = function () {
10894 return this.active
;
10898 * Get outline item.
10900 * The outline item allows users to access the page from the booklet's outline
10901 * navigation. The outline item itself can be customized (with a label, level, etc.) using the #setupOutlineItem method.
10903 * @return {OO.ui.OutlineOptionWidget|null} Outline option widget
10905 OO
.ui
.PageLayout
.prototype.getOutlineItem = function () {
10906 return this.outlineItem
;
10910 * Set or unset the outline item.
10912 * Specify an {@link OO.ui.OutlineOptionWidget outline option} to set it,
10913 * or `null` to clear the outline item. To customize the outline item itself (e.g., to set a label or outline
10914 * level), use #setupOutlineItem instead of this method.
10916 * @param {OO.ui.OutlineOptionWidget|null} outlineItem Outline option widget, null to clear
10919 OO
.ui
.PageLayout
.prototype.setOutlineItem = function ( outlineItem
) {
10920 this.outlineItem
= outlineItem
|| null;
10921 if ( outlineItem
) {
10922 this.setupOutlineItem();
10928 * Set up the outline item.
10930 * Use this method to customize the outline item (e.g., to add a label or outline level). To set or unset
10931 * the outline item itself (with an {@link OO.ui.OutlineOptionWidget outline option} or `null`), use
10932 * the #setOutlineItem method instead.
10934 * @param {OO.ui.OutlineOptionWidget} outlineItem Outline option widget to set up
10937 OO
.ui
.PageLayout
.prototype.setupOutlineItem = function () {
10942 * Set the page to its 'active' state.
10944 * Pages become active when they are shown in a booklet layout that is configured to display only one page at a time. Additional
10945 * CSS is applied to the outline item to reflect the page's active state. Outside of the booklet
10946 * context, setting the active state on a page does nothing.
10948 * @param {boolean} value Page is active
10951 OO
.ui
.PageLayout
.prototype.setActive = function ( active
) {
10954 if ( active
!== this.active
) {
10955 this.active
= active
;
10956 this.$element
.toggleClass( 'oo-ui-pageLayout-active', active
);
10957 this.emit( 'active', this.active
);
10962 * StackLayouts contain a series of {@link OO.ui.PanelLayout panel layouts}. By default, only one panel is displayed
10963 * at a time, though the stack layout can also be configured to show all contained panels, one after another,
10964 * by setting the #continuous option to 'true'.
10967 * // A stack layout with two panels, configured to be displayed continously
10968 * var myStack = new OO.ui.StackLayout( {
10970 * new OO.ui.PanelLayout( {
10971 * $content: $( '<p>Panel One</p>' ),
10975 * new OO.ui.PanelLayout( {
10976 * $content: $( '<p>Panel Two</p>' ),
10983 * $( 'body' ).append( myStack.$element );
10986 * @extends OO.ui.PanelLayout
10987 * @mixins OO.ui.mixin.GroupElement
10990 * @param {Object} [config] Configuration options
10991 * @cfg {boolean} [continuous=false] Show all panels, one after another. By default, only one panel is displayed at a time.
10992 * @cfg {OO.ui.Layout[]} [items] Panel layouts to add to the stack layout.
10994 OO
.ui
.StackLayout
= function OoUiStackLayout( config
) {
10995 // Configuration initialization
10996 config
= $.extend( { scrollable
: true }, config
);
10998 // Parent constructor
10999 OO
.ui
.StackLayout
.parent
.call( this, config
);
11001 // Mixin constructors
11002 OO
.ui
.mixin
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
11005 this.currentItem
= null;
11006 this.continuous
= !!config
.continuous
;
11009 this.$element
.addClass( 'oo-ui-stackLayout' );
11010 if ( this.continuous
) {
11011 this.$element
.addClass( 'oo-ui-stackLayout-continuous' );
11013 if ( Array
.isArray( config
.items
) ) {
11014 this.addItems( config
.items
);
11020 OO
.inheritClass( OO
.ui
.StackLayout
, OO
.ui
.PanelLayout
);
11021 OO
.mixinClass( OO
.ui
.StackLayout
, OO
.ui
.mixin
.GroupElement
);
11026 * A 'set' event is emitted when panels are {@link #addItems added}, {@link #removeItems removed},
11027 * {@link #clearItems cleared} or {@link #setItem displayed}.
11030 * @param {OO.ui.Layout|null} item Current panel or `null` if no panel is shown
11036 * Get the current panel.
11038 * @return {OO.ui.Layout|null}
11040 OO
.ui
.StackLayout
.prototype.getCurrentItem = function () {
11041 return this.currentItem
;
11045 * Unset the current item.
11048 * @param {OO.ui.StackLayout} layout
11051 OO
.ui
.StackLayout
.prototype.unsetCurrentItem = function () {
11052 var prevItem
= this.currentItem
;
11053 if ( prevItem
=== null ) {
11057 this.currentItem
= null;
11058 this.emit( 'set', null );
11062 * Add panel layouts to the stack layout.
11064 * Panels will be added to the end of the stack layout array unless the optional index parameter specifies a different
11065 * insertion point. Adding a panel that is already in the stack will move it to the end of the array or the point specified
11068 * @param {OO.ui.Layout[]} items Panels to add
11069 * @param {number} [index] Index of the insertion point
11072 OO
.ui
.StackLayout
.prototype.addItems = function ( items
, index
) {
11073 // Update the visibility
11074 this.updateHiddenState( items
, this.currentItem
);
11077 OO
.ui
.mixin
.GroupElement
.prototype.addItems
.call( this, items
, index
);
11079 if ( !this.currentItem
&& items
.length
) {
11080 this.setItem( items
[ 0 ] );
11087 * Remove the specified panels from the stack layout.
11089 * Removed panels are detached from the DOM, not removed, so that they may be reused. To remove all panels,
11090 * you may wish to use the #clearItems method instead.
11092 * @param {OO.ui.Layout[]} items Panels to remove
11096 OO
.ui
.StackLayout
.prototype.removeItems = function ( items
) {
11098 OO
.ui
.mixin
.GroupElement
.prototype.removeItems
.call( this, items
);
11100 if ( items
.indexOf( this.currentItem
) !== -1 ) {
11101 if ( this.items
.length
) {
11102 this.setItem( this.items
[ 0 ] );
11104 this.unsetCurrentItem();
11112 * Clear all panels from the stack layout.
11114 * Cleared panels are detached from the DOM, not removed, so that they may be reused. To remove only
11115 * a subset of panels, use the #removeItems method.
11120 OO
.ui
.StackLayout
.prototype.clearItems = function () {
11121 this.unsetCurrentItem();
11122 OO
.ui
.mixin
.GroupElement
.prototype.clearItems
.call( this );
11128 * Show the specified panel.
11130 * If another panel is currently displayed, it will be hidden.
11132 * @param {OO.ui.Layout} item Panel to show
11136 OO
.ui
.StackLayout
.prototype.setItem = function ( item
) {
11137 if ( item
!== this.currentItem
) {
11138 this.updateHiddenState( this.items
, item
);
11140 if ( this.items
.indexOf( item
) !== -1 ) {
11141 this.currentItem
= item
;
11142 this.emit( 'set', item
);
11144 this.unsetCurrentItem();
11152 * Update the visibility of all items in case of non-continuous view.
11154 * Ensure all items are hidden except for the selected one.
11155 * This method does nothing when the stack is continuous.
11158 * @param {OO.ui.Layout[]} items Item list iterate over
11159 * @param {OO.ui.Layout} [selectedItem] Selected item to show
11161 OO
.ui
.StackLayout
.prototype.updateHiddenState = function ( items
, selectedItem
) {
11164 if ( !this.continuous
) {
11165 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
11166 if ( !selectedItem
|| selectedItem
!== items
[ i
] ) {
11167 items
[ i
].$element
.addClass( 'oo-ui-element-hidden' );
11170 if ( selectedItem
) {
11171 selectedItem
.$element
.removeClass( 'oo-ui-element-hidden' );
11177 * HorizontalLayout arranges its contents in a single line (using `display: inline-block` for its
11178 * items), with small margins between them. Convenient when you need to put a number of block-level
11179 * widgets on a single line next to each other.
11181 * Note that inline elements, such as OO.ui.ButtonWidgets, do not need this wrapper.
11184 * // HorizontalLayout with a text input and a label
11185 * var layout = new OO.ui.HorizontalLayout( {
11187 * new OO.ui.LabelWidget( { label: 'Label' } ),
11188 * new OO.ui.TextInputWidget( { value: 'Text' } )
11191 * $( 'body' ).append( layout.$element );
11194 * @extends OO.ui.Layout
11195 * @mixins OO.ui.mixin.GroupElement
11198 * @param {Object} [config] Configuration options
11199 * @cfg {OO.ui.Widget[]|OO.ui.Layout[]} [items] Widgets or other layouts to add to the layout.
11201 OO
.ui
.HorizontalLayout
= function OoUiHorizontalLayout( config
) {
11202 // Configuration initialization
11203 config
= config
|| {};
11205 // Parent constructor
11206 OO
.ui
.HorizontalLayout
.parent
.call( this, config
);
11208 // Mixin constructors
11209 OO
.ui
.mixin
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
11212 this.$element
.addClass( 'oo-ui-horizontalLayout' );
11213 if ( Array
.isArray( config
.items
) ) {
11214 this.addItems( config
.items
);
11220 OO
.inheritClass( OO
.ui
.HorizontalLayout
, OO
.ui
.Layout
);
11221 OO
.mixinClass( OO
.ui
.HorizontalLayout
, OO
.ui
.mixin
.GroupElement
);
11224 * BarToolGroups are one of three types of {@link OO.ui.ToolGroup toolgroups} that are used to
11225 * create {@link OO.ui.Toolbar toolbars} (the other types of groups are {@link OO.ui.MenuToolGroup MenuToolGroup}
11226 * and {@link OO.ui.ListToolGroup ListToolGroup}). The {@link OO.ui.Tool tools} in a BarToolGroup are
11227 * displayed by icon in a single row. The title of the tool is displayed when users move the mouse over
11230 * BarToolGroups are created by a {@link OO.ui.ToolGroupFactory tool group factory} when the toolbar is
11234 * // Example of a BarToolGroup with two tools
11235 * var toolFactory = new OO.ui.ToolFactory();
11236 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
11237 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
11239 * // We will be placing status text in this element when tools are used
11240 * var $area = $( '<p>' ).text( 'Example of a BarToolGroup with two tools.' );
11242 * // Define the tools that we're going to place in our toolbar
11244 * // Create a class inheriting from OO.ui.Tool
11245 * function PictureTool() {
11246 * PictureTool.parent.apply( this, arguments );
11248 * OO.inheritClass( PictureTool, OO.ui.Tool );
11249 * // Each tool must have a 'name' (used as an internal identifier, see later) and at least one
11250 * // of 'icon' and 'title' (displayed icon and text).
11251 * PictureTool.static.name = 'picture';
11252 * PictureTool.static.icon = 'picture';
11253 * PictureTool.static.title = 'Insert picture';
11254 * // Defines the action that will happen when this tool is selected (clicked).
11255 * PictureTool.prototype.onSelect = function () {
11256 * $area.text( 'Picture tool clicked!' );
11257 * // Never display this tool as "active" (selected).
11258 * this.setActive( false );
11260 * // Make this tool available in our toolFactory and thus our toolbar
11261 * toolFactory.register( PictureTool );
11263 * // This is a PopupTool. Rather than having a custom 'onSelect' action, it will display a
11264 * // little popup window (a PopupWidget).
11265 * function HelpTool( toolGroup, config ) {
11266 * OO.ui.PopupTool.call( this, toolGroup, $.extend( { popup: {
11271 * this.popup.$body.append( '<p>I am helpful!</p>' );
11273 * OO.inheritClass( HelpTool, OO.ui.PopupTool );
11274 * HelpTool.static.name = 'help';
11275 * HelpTool.static.icon = 'help';
11276 * HelpTool.static.title = 'Help';
11277 * toolFactory.register( HelpTool );
11279 * // Finally define which tools and in what order appear in the toolbar. Each tool may only be
11280 * // used once (but not all defined tools must be used).
11283 * // 'bar' tool groups display tools by icon only
11285 * include: [ 'picture', 'help' ]
11289 * // Create some UI around the toolbar and place it in the document
11290 * var frame = new OO.ui.PanelLayout( {
11294 * var contentFrame = new OO.ui.PanelLayout( {
11298 * frame.$element.append(
11299 * toolbar.$element,
11300 * contentFrame.$element.append( $area )
11302 * $( 'body' ).append( frame.$element );
11304 * // Here is where the toolbar is actually built. This must be done after inserting it into the
11306 * toolbar.initialize();
11308 * For more information about how to add tools to a bar tool group, please see {@link OO.ui.ToolGroup toolgroup}.
11309 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki][1].
11311 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
11314 * @extends OO.ui.ToolGroup
11317 * @param {OO.ui.Toolbar} toolbar
11318 * @param {Object} [config] Configuration options
11320 OO
.ui
.BarToolGroup
= function OoUiBarToolGroup( toolbar
, config
) {
11321 // Allow passing positional parameters inside the config object
11322 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
11324 toolbar
= config
.toolbar
;
11327 // Parent constructor
11328 OO
.ui
.BarToolGroup
.parent
.call( this, toolbar
, config
);
11331 this.$element
.addClass( 'oo-ui-barToolGroup' );
11336 OO
.inheritClass( OO
.ui
.BarToolGroup
, OO
.ui
.ToolGroup
);
11338 /* Static Properties */
11340 OO
.ui
.BarToolGroup
.static.titleTooltips
= true;
11342 OO
.ui
.BarToolGroup
.static.accelTooltips
= true;
11344 OO
.ui
.BarToolGroup
.static.name
= 'bar';
11347 * PopupToolGroup is an abstract base class used by both {@link OO.ui.MenuToolGroup MenuToolGroup}
11348 * and {@link OO.ui.ListToolGroup ListToolGroup} to provide a popup--an overlaid menu or list of tools with an
11349 * optional icon and label. This class can be used for other base classes that also use this functionality.
11353 * @extends OO.ui.ToolGroup
11354 * @mixins OO.ui.mixin.IconElement
11355 * @mixins OO.ui.mixin.IndicatorElement
11356 * @mixins OO.ui.mixin.LabelElement
11357 * @mixins OO.ui.mixin.TitledElement
11358 * @mixins OO.ui.mixin.ClippableElement
11359 * @mixins OO.ui.mixin.TabIndexedElement
11362 * @param {OO.ui.Toolbar} toolbar
11363 * @param {Object} [config] Configuration options
11364 * @cfg {string} [header] Text to display at the top of the popup
11366 OO
.ui
.PopupToolGroup
= function OoUiPopupToolGroup( toolbar
, config
) {
11367 // Allow passing positional parameters inside the config object
11368 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
11370 toolbar
= config
.toolbar
;
11373 // Configuration initialization
11374 config
= config
|| {};
11376 // Parent constructor
11377 OO
.ui
.PopupToolGroup
.parent
.call( this, toolbar
, config
);
11380 this.active
= false;
11381 this.dragging
= false;
11382 this.onBlurHandler
= this.onBlur
.bind( this );
11383 this.$handle
= $( '<span>' );
11385 // Mixin constructors
11386 OO
.ui
.mixin
.IconElement
.call( this, config
);
11387 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
11388 OO
.ui
.mixin
.LabelElement
.call( this, config
);
11389 OO
.ui
.mixin
.TitledElement
.call( this, config
);
11390 OO
.ui
.mixin
.ClippableElement
.call( this, $.extend( {}, config
, { $clippable
: this.$group
} ) );
11391 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$handle
} ) );
11395 keydown
: this.onHandleMouseKeyDown
.bind( this ),
11396 keyup
: this.onHandleMouseKeyUp
.bind( this ),
11397 mousedown
: this.onHandleMouseKeyDown
.bind( this ),
11398 mouseup
: this.onHandleMouseKeyUp
.bind( this )
11403 .addClass( 'oo-ui-popupToolGroup-handle' )
11404 .append( this.$icon
, this.$label
, this.$indicator
);
11405 // If the pop-up should have a header, add it to the top of the toolGroup.
11406 // Note: If this feature is useful for other widgets, we could abstract it into an
11407 // OO.ui.HeaderedElement mixin constructor.
11408 if ( config
.header
!== undefined ) {
11410 .prepend( $( '<span>' )
11411 .addClass( 'oo-ui-popupToolGroup-header' )
11412 .text( config
.header
)
11416 .addClass( 'oo-ui-popupToolGroup' )
11417 .prepend( this.$handle
);
11422 OO
.inheritClass( OO
.ui
.PopupToolGroup
, OO
.ui
.ToolGroup
);
11423 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.IconElement
);
11424 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.IndicatorElement
);
11425 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.LabelElement
);
11426 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.TitledElement
);
11427 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.ClippableElement
);
11428 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.mixin
.TabIndexedElement
);
11435 OO
.ui
.PopupToolGroup
.prototype.setDisabled = function () {
11437 OO
.ui
.PopupToolGroup
.parent
.prototype.setDisabled
.apply( this, arguments
);
11439 if ( this.isDisabled() && this.isElementAttached() ) {
11440 this.setActive( false );
11445 * Handle focus being lost.
11447 * The event is actually generated from a mouseup/keyup, so it is not a normal blur event object.
11450 * @param {jQuery.Event} e Mouse up or key up event
11452 OO
.ui
.PopupToolGroup
.prototype.onBlur = function ( e
) {
11453 // Only deactivate when clicking outside the dropdown element
11454 if ( $( e
.target
).closest( '.oo-ui-popupToolGroup' )[ 0 ] !== this.$element
[ 0 ] ) {
11455 this.setActive( false );
11462 OO
.ui
.PopupToolGroup
.prototype.onMouseKeyUp = function ( e
) {
11463 // Only close toolgroup when a tool was actually selected
11465 !this.isDisabled() && this.pressed
&& this.pressed
=== this.getTargetTool( e
) &&
11466 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
11468 this.setActive( false );
11470 return OO
.ui
.PopupToolGroup
.parent
.prototype.onMouseKeyUp
.call( this, e
);
11474 * Handle mouse up and key up events.
11477 * @param {jQuery.Event} e Mouse up or key up event
11479 OO
.ui
.PopupToolGroup
.prototype.onHandleMouseKeyUp = function ( e
) {
11481 !this.isDisabled() &&
11482 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
11489 * Handle mouse down and key down events.
11492 * @param {jQuery.Event} e Mouse down or key down event
11494 OO
.ui
.PopupToolGroup
.prototype.onHandleMouseKeyDown = function ( e
) {
11496 !this.isDisabled() &&
11497 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
11499 this.setActive( !this.active
);
11505 * Switch into 'active' mode.
11507 * When active, the popup is visible. A mouseup event anywhere in the document will trigger
11510 OO
.ui
.PopupToolGroup
.prototype.setActive = function ( value
) {
11511 var containerWidth
, containerLeft
;
11513 if ( this.active
!== value
) {
11514 this.active
= value
;
11516 OO
.ui
.addCaptureEventListener( this.getElementDocument(), 'mouseup', this.onBlurHandler
);
11517 OO
.ui
.addCaptureEventListener( this.getElementDocument(), 'keyup', this.onBlurHandler
);
11519 this.$clippable
.css( 'left', '' );
11520 // Try anchoring the popup to the left first
11521 this.$element
.addClass( 'oo-ui-popupToolGroup-active oo-ui-popupToolGroup-left' );
11522 this.toggleClipping( true );
11523 if ( this.isClippedHorizontally() ) {
11524 // Anchoring to the left caused the popup to clip, so anchor it to the right instead
11525 this.toggleClipping( false );
11527 .removeClass( 'oo-ui-popupToolGroup-left' )
11528 .addClass( 'oo-ui-popupToolGroup-right' );
11529 this.toggleClipping( true );
11531 if ( this.isClippedHorizontally() ) {
11532 // Anchoring to the right also caused the popup to clip, so just make it fill the container
11533 containerWidth
= this.$clippableScrollableContainer
.width();
11534 containerLeft
= this.$clippableScrollableContainer
.offset().left
;
11536 this.toggleClipping( false );
11537 this.$element
.removeClass( 'oo-ui-popupToolGroup-right' );
11539 this.$clippable
.css( {
11540 left
: -( this.$element
.offset().left
- containerLeft
),
11541 width
: containerWidth
11545 OO
.ui
.removeCaptureEventListener( this.getElementDocument(), 'mouseup', this.onBlurHandler
);
11546 OO
.ui
.removeCaptureEventListener( this.getElementDocument(), 'keyup', this.onBlurHandler
);
11547 this.$element
.removeClass(
11548 'oo-ui-popupToolGroup-active oo-ui-popupToolGroup-left oo-ui-popupToolGroup-right'
11550 this.toggleClipping( false );
11556 * ListToolGroups are one of three types of {@link OO.ui.ToolGroup toolgroups} that are used to
11557 * create {@link OO.ui.Toolbar toolbars} (the other types of groups are {@link OO.ui.MenuToolGroup MenuToolGroup}
11558 * and {@link OO.ui.BarToolGroup BarToolGroup}). The {@link OO.ui.Tool tools} in a ListToolGroup are displayed
11559 * by label in a dropdown menu. The title of the tool is used as the label text. The menu itself can be configured
11560 * with a label, icon, indicator, header, and title.
11562 * ListToolGroups can be configured to be expanded and collapsed. Collapsed lists will have a ‘More’ option that
11563 * users can select to see the full list of tools. If a collapsed toolgroup is expanded, a ‘Fewer’ option permits
11564 * users to collapse the list again.
11566 * ListToolGroups are created by a {@link OO.ui.ToolGroupFactory toolgroup factory} when the toolbar is set up. The factory
11567 * requires the ListToolGroup's symbolic name, 'list', which is specified along with the other configurations. For more
11568 * information about how to add tools to a ListToolGroup, please see {@link OO.ui.ToolGroup toolgroup}.
11571 * // Example of a ListToolGroup
11572 * var toolFactory = new OO.ui.ToolFactory();
11573 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
11574 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
11576 * // Configure and register two tools
11577 * function SettingsTool() {
11578 * SettingsTool.parent.apply( this, arguments );
11580 * OO.inheritClass( SettingsTool, OO.ui.Tool );
11581 * SettingsTool.static.name = 'settings';
11582 * SettingsTool.static.icon = 'settings';
11583 * SettingsTool.static.title = 'Change settings';
11584 * SettingsTool.prototype.onSelect = function () {
11585 * this.setActive( false );
11587 * toolFactory.register( SettingsTool );
11588 * // Register two more tools, nothing interesting here
11589 * function StuffTool() {
11590 * StuffTool.parent.apply( this, arguments );
11592 * OO.inheritClass( StuffTool, OO.ui.Tool );
11593 * StuffTool.static.name = 'stuff';
11594 * StuffTool.static.icon = 'ellipsis';
11595 * StuffTool.static.title = 'Change the world';
11596 * StuffTool.prototype.onSelect = function () {
11597 * this.setActive( false );
11599 * toolFactory.register( StuffTool );
11602 * // Configurations for list toolgroup.
11604 * label: 'ListToolGroup',
11605 * indicator: 'down',
11607 * title: 'This is the title, displayed when user moves the mouse over the list toolgroup',
11608 * header: 'This is the header',
11609 * include: [ 'settings', 'stuff' ],
11610 * allowCollapse: ['stuff']
11614 * // Create some UI around the toolbar and place it in the document
11615 * var frame = new OO.ui.PanelLayout( {
11619 * frame.$element.append(
11622 * $( 'body' ).append( frame.$element );
11623 * // Build the toolbar. This must be done after the toolbar has been appended to the document.
11624 * toolbar.initialize();
11626 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki][1].
11628 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
11631 * @extends OO.ui.PopupToolGroup
11634 * @param {OO.ui.Toolbar} toolbar
11635 * @param {Object} [config] Configuration options
11636 * @cfg {Array} [allowCollapse] Allow the specified tools to be collapsed. By default, collapsible tools
11637 * will only be displayed if users click the ‘More’ option displayed at the bottom of the list. If
11638 * the list is expanded, a ‘Fewer’ option permits users to collapse the list again. Any tools that
11639 * are included in the toolgroup, but are not designated as collapsible, will always be displayed.
11640 * To open a collapsible list in its expanded state, set #expanded to 'true'.
11641 * @cfg {Array} [forceExpand] Expand the specified tools. All other tools will be designated as collapsible.
11642 * Unless #expanded is set to true, the collapsible tools will be collapsed when the list is first opened.
11643 * @cfg {boolean} [expanded=false] Expand collapsible tools. This config is only relevant if tools have
11644 * been designated as collapsible. When expanded is set to true, all tools in the group will be displayed
11645 * when the list is first opened. Users can collapse the list with a ‘Fewer’ option at the bottom.
11647 OO
.ui
.ListToolGroup
= function OoUiListToolGroup( toolbar
, config
) {
11648 // Allow passing positional parameters inside the config object
11649 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
11651 toolbar
= config
.toolbar
;
11654 // Configuration initialization
11655 config
= config
|| {};
11657 // Properties (must be set before parent constructor, which calls #populate)
11658 this.allowCollapse
= config
.allowCollapse
;
11659 this.forceExpand
= config
.forceExpand
;
11660 this.expanded
= config
.expanded
!== undefined ? config
.expanded
: false;
11661 this.collapsibleTools
= [];
11663 // Parent constructor
11664 OO
.ui
.ListToolGroup
.parent
.call( this, toolbar
, config
);
11667 this.$element
.addClass( 'oo-ui-listToolGroup' );
11672 OO
.inheritClass( OO
.ui
.ListToolGroup
, OO
.ui
.PopupToolGroup
);
11674 /* Static Properties */
11676 OO
.ui
.ListToolGroup
.static.name
= 'list';
11683 OO
.ui
.ListToolGroup
.prototype.populate = function () {
11684 var i
, len
, allowCollapse
= [];
11686 OO
.ui
.ListToolGroup
.parent
.prototype.populate
.call( this );
11688 // Update the list of collapsible tools
11689 if ( this.allowCollapse
!== undefined ) {
11690 allowCollapse
= this.allowCollapse
;
11691 } else if ( this.forceExpand
!== undefined ) {
11692 allowCollapse
= OO
.simpleArrayDifference( Object
.keys( this.tools
), this.forceExpand
);
11695 this.collapsibleTools
= [];
11696 for ( i
= 0, len
= allowCollapse
.length
; i
< len
; i
++ ) {
11697 if ( this.tools
[ allowCollapse
[ i
] ] !== undefined ) {
11698 this.collapsibleTools
.push( this.tools
[ allowCollapse
[ i
] ] );
11702 // Keep at the end, even when tools are added
11703 this.$group
.append( this.getExpandCollapseTool().$element
);
11705 this.getExpandCollapseTool().toggle( this.collapsibleTools
.length
!== 0 );
11706 this.updateCollapsibleState();
11709 OO
.ui
.ListToolGroup
.prototype.getExpandCollapseTool = function () {
11710 var ExpandCollapseTool
;
11711 if ( this.expandCollapseTool
=== undefined ) {
11712 ExpandCollapseTool = function () {
11713 ExpandCollapseTool
.parent
.apply( this, arguments
);
11716 OO
.inheritClass( ExpandCollapseTool
, OO
.ui
.Tool
);
11718 ExpandCollapseTool
.prototype.onSelect = function () {
11719 this.toolGroup
.expanded
= !this.toolGroup
.expanded
;
11720 this.toolGroup
.updateCollapsibleState();
11721 this.setActive( false );
11723 ExpandCollapseTool
.prototype.onUpdateState = function () {
11724 // Do nothing. Tool interface requires an implementation of this function.
11727 ExpandCollapseTool
.static.name
= 'more-fewer';
11729 this.expandCollapseTool
= new ExpandCollapseTool( this );
11731 return this.expandCollapseTool
;
11737 OO
.ui
.ListToolGroup
.prototype.onMouseKeyUp = function ( e
) {
11738 // Do not close the popup when the user wants to show more/fewer tools
11740 $( e
.target
).closest( '.oo-ui-tool-name-more-fewer' ).length
&&
11741 ( e
.which
=== 1 || e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
11743 // HACK: Prevent the popup list from being hidden. Skip the PopupToolGroup implementation (which
11744 // hides the popup list when a tool is selected) and call ToolGroup's implementation directly.
11745 return OO
.ui
.ListToolGroup
.parent
.parent
.prototype.onMouseKeyUp
.call( this, e
);
11747 return OO
.ui
.ListToolGroup
.parent
.prototype.onMouseKeyUp
.call( this, e
);
11751 OO
.ui
.ListToolGroup
.prototype.updateCollapsibleState = function () {
11754 this.getExpandCollapseTool()
11755 .setIcon( this.expanded
? 'collapse' : 'expand' )
11756 .setTitle( OO
.ui
.msg( this.expanded
? 'ooui-toolgroup-collapse' : 'ooui-toolgroup-expand' ) );
11758 for ( i
= 0, len
= this.collapsibleTools
.length
; i
< len
; i
++ ) {
11759 this.collapsibleTools
[ i
].toggle( this.expanded
);
11764 * MenuToolGroups are one of three types of {@link OO.ui.ToolGroup toolgroups} that are used to
11765 * create {@link OO.ui.Toolbar toolbars} (the other types of groups are {@link OO.ui.BarToolGroup BarToolGroup}
11766 * and {@link OO.ui.ListToolGroup ListToolGroup}). MenuToolGroups contain selectable {@link OO.ui.Tool tools},
11767 * which are displayed by label in a dropdown menu. The tool's title is used as the label text, and the
11768 * menu label is updated to reflect which tool or tools are currently selected. If no tools are selected,
11769 * the menu label is empty. The menu can be configured with an indicator, icon, title, and/or header.
11771 * MenuToolGroups are created by a {@link OO.ui.ToolGroupFactory tool group factory} when the toolbar
11772 * is set up. Note that all tools must define an {@link OO.ui.Tool#onUpdateState onUpdateState} method if
11773 * a MenuToolGroup is used.
11776 * // Example of a MenuToolGroup
11777 * var toolFactory = new OO.ui.ToolFactory();
11778 * var toolGroupFactory = new OO.ui.ToolGroupFactory();
11779 * var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );
11781 * // We will be placing status text in this element when tools are used
11782 * var $area = $( '<p>' ).text( 'An example of a MenuToolGroup. Select a tool from the dropdown menu.' );
11784 * // Define the tools that we're going to place in our toolbar
11786 * function SettingsTool() {
11787 * SettingsTool.parent.apply( this, arguments );
11788 * this.reallyActive = false;
11790 * OO.inheritClass( SettingsTool, OO.ui.Tool );
11791 * SettingsTool.static.name = 'settings';
11792 * SettingsTool.static.icon = 'settings';
11793 * SettingsTool.static.title = 'Change settings';
11794 * SettingsTool.prototype.onSelect = function () {
11795 * $area.text( 'Settings tool clicked!' );
11796 * // Toggle the active state on each click
11797 * this.reallyActive = !this.reallyActive;
11798 * this.setActive( this.reallyActive );
11799 * // To update the menu label
11800 * this.toolbar.emit( 'updateState' );
11802 * SettingsTool.prototype.onUpdateState = function () {
11804 * toolFactory.register( SettingsTool );
11806 * function StuffTool() {
11807 * StuffTool.parent.apply( this, arguments );
11808 * this.reallyActive = false;
11810 * OO.inheritClass( StuffTool, OO.ui.Tool );
11811 * StuffTool.static.name = 'stuff';
11812 * StuffTool.static.icon = 'ellipsis';
11813 * StuffTool.static.title = 'More stuff';
11814 * StuffTool.prototype.onSelect = function () {
11815 * $area.text( 'More stuff tool clicked!' );
11816 * // Toggle the active state on each click
11817 * this.reallyActive = !this.reallyActive;
11818 * this.setActive( this.reallyActive );
11819 * // To update the menu label
11820 * this.toolbar.emit( 'updateState' );
11822 * StuffTool.prototype.onUpdateState = function () {
11824 * toolFactory.register( StuffTool );
11826 * // Finally define which tools and in what order appear in the toolbar. Each tool may only be
11827 * // used once (but not all defined tools must be used).
11831 * header: 'This is the (optional) header',
11832 * title: 'This is the (optional) title',
11833 * indicator: 'down',
11834 * include: [ 'settings', 'stuff' ]
11838 * // Create some UI around the toolbar and place it in the document
11839 * var frame = new OO.ui.PanelLayout( {
11843 * var contentFrame = new OO.ui.PanelLayout( {
11847 * frame.$element.append(
11848 * toolbar.$element,
11849 * contentFrame.$element.append( $area )
11851 * $( 'body' ).append( frame.$element );
11853 * // Here is where the toolbar is actually built. This must be done after inserting it into the
11855 * toolbar.initialize();
11856 * toolbar.emit( 'updateState' );
11858 * For more information about how to add tools to a MenuToolGroup, please see {@link OO.ui.ToolGroup toolgroup}.
11859 * For more information about toolbars in general, please see the [OOjs UI documentation on MediaWiki] [1].
11861 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
11864 * @extends OO.ui.PopupToolGroup
11867 * @param {OO.ui.Toolbar} toolbar
11868 * @param {Object} [config] Configuration options
11870 OO
.ui
.MenuToolGroup
= function OoUiMenuToolGroup( toolbar
, config
) {
11871 // Allow passing positional parameters inside the config object
11872 if ( OO
.isPlainObject( toolbar
) && config
=== undefined ) {
11874 toolbar
= config
.toolbar
;
11877 // Configuration initialization
11878 config
= config
|| {};
11880 // Parent constructor
11881 OO
.ui
.MenuToolGroup
.parent
.call( this, toolbar
, config
);
11884 this.toolbar
.connect( this, { updateState
: 'onUpdateState' } );
11887 this.$element
.addClass( 'oo-ui-menuToolGroup' );
11892 OO
.inheritClass( OO
.ui
.MenuToolGroup
, OO
.ui
.PopupToolGroup
);
11894 /* Static Properties */
11896 OO
.ui
.MenuToolGroup
.static.name
= 'menu';
11901 * Handle the toolbar state being updated.
11903 * When the state changes, the title of each active item in the menu will be joined together and
11904 * used as a label for the group. The label will be empty if none of the items are active.
11908 OO
.ui
.MenuToolGroup
.prototype.onUpdateState = function () {
11912 for ( name
in this.tools
) {
11913 if ( this.tools
[ name
].isActive() ) {
11914 labelTexts
.push( this.tools
[ name
].getTitle() );
11918 this.setLabel( labelTexts
.join( ', ' ) || ' ' );
11922 * Popup tools open a popup window when they are selected from the {@link OO.ui.Toolbar toolbar}. Each popup tool is configured
11923 * 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
11924 * an #onSelect or #onUpdateState method, as these methods have been implemented already.
11926 * // Example of a popup tool. When selected, a popup tool displays
11927 * // a popup window.
11928 * function HelpTool( toolGroup, config ) {
11929 * OO.ui.PopupTool.call( this, toolGroup, $.extend( { popup: {
11934 * this.popup.$body.append( '<p>I am helpful!</p>' );
11936 * OO.inheritClass( HelpTool, OO.ui.PopupTool );
11937 * HelpTool.static.name = 'help';
11938 * HelpTool.static.icon = 'help';
11939 * HelpTool.static.title = 'Help';
11940 * toolFactory.register( HelpTool );
11942 * For an example of a toolbar that contains a popup tool, see {@link OO.ui.Toolbar toolbars}. For more information about
11943 * toolbars in genreral, please see the [OOjs UI documentation on MediaWiki][1].
11945 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars
11949 * @extends OO.ui.Tool
11950 * @mixins OO.ui.mixin.PopupElement
11953 * @param {OO.ui.ToolGroup} toolGroup
11954 * @param {Object} [config] Configuration options
11956 OO
.ui
.PopupTool
= function OoUiPopupTool( toolGroup
, config
) {
11957 // Allow passing positional parameters inside the config object
11958 if ( OO
.isPlainObject( toolGroup
) && config
=== undefined ) {
11959 config
= toolGroup
;
11960 toolGroup
= config
.toolGroup
;
11963 // Parent constructor
11964 OO
.ui
.PopupTool
.parent
.call( this, toolGroup
, config
);
11966 // Mixin constructors
11967 OO
.ui
.mixin
.PopupElement
.call( this, config
);
11971 .addClass( 'oo-ui-popupTool' )
11972 .append( this.popup
.$element
);
11977 OO
.inheritClass( OO
.ui
.PopupTool
, OO
.ui
.Tool
);
11978 OO
.mixinClass( OO
.ui
.PopupTool
, OO
.ui
.mixin
.PopupElement
);
11983 * Handle the tool being selected.
11987 OO
.ui
.PopupTool
.prototype.onSelect = function () {
11988 if ( !this.isDisabled() ) {
11989 this.popup
.toggle();
11991 this.setActive( false );
11996 * Handle the toolbar state being updated.
12000 OO
.ui
.PopupTool
.prototype.onUpdateState = function () {
12001 this.setActive( false );
12005 * A ToolGroupTool is a special sort of tool that can contain other {@link OO.ui.Tool tools}
12006 * and {@link OO.ui.ToolGroup toolgroups}. The ToolGroupTool was specifically designed to be used
12007 * inside a {@link OO.ui.BarToolGroup bar} toolgroup to provide access to additional tools from
12008 * the bar item. Included tools will be displayed in a dropdown {@link OO.ui.ListToolGroup list}
12009 * when the ToolGroupTool is selected.
12011 * // Example: ToolGroupTool with two nested tools, 'setting1' and 'setting2', defined elsewhere.
12013 * function SettingsTool() {
12014 * SettingsTool.parent.apply( this, arguments );
12016 * OO.inheritClass( SettingsTool, OO.ui.ToolGroupTool );
12017 * SettingsTool.static.name = 'settings';
12018 * SettingsTool.static.title = 'Change settings';
12019 * SettingsTool.static.groupConfig = {
12020 * icon: 'settings',
12021 * label: 'ToolGroupTool',
12022 * include: [ 'setting1', 'setting2' ]
12024 * toolFactory.register( SettingsTool );
12026 * For more information, please see the [OOjs UI documentation on MediaWiki][1].
12028 * Please note that this implementation is subject to change per [T74159] [2].
12030 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Toolbars#ToolGroupTool
12031 * [2]: https://phabricator.wikimedia.org/T74159
12035 * @extends OO.ui.Tool
12038 * @param {OO.ui.ToolGroup} toolGroup
12039 * @param {Object} [config] Configuration options
12041 OO
.ui
.ToolGroupTool
= function OoUiToolGroupTool( toolGroup
, config
) {
12042 // Allow passing positional parameters inside the config object
12043 if ( OO
.isPlainObject( toolGroup
) && config
=== undefined ) {
12044 config
= toolGroup
;
12045 toolGroup
= config
.toolGroup
;
12048 // Parent constructor
12049 OO
.ui
.ToolGroupTool
.parent
.call( this, toolGroup
, config
);
12052 this.innerToolGroup
= this.createGroup( this.constructor.static.groupConfig
);
12055 this.innerToolGroup
.connect( this, { disable
: 'onToolGroupDisable' } );
12058 this.$link
.remove();
12060 .addClass( 'oo-ui-toolGroupTool' )
12061 .append( this.innerToolGroup
.$element
);
12066 OO
.inheritClass( OO
.ui
.ToolGroupTool
, OO
.ui
.Tool
);
12068 /* Static Properties */
12071 * Toolgroup configuration.
12073 * The toolgroup configuration consists of the tools to include, as well as an icon and label
12074 * to use for the bar item. Tools can be included by symbolic name, group, or with the
12075 * wildcard selector. Please see {@link OO.ui.ToolGroup toolgroup} for more information.
12077 * @property {Object.<string,Array>}
12079 OO
.ui
.ToolGroupTool
.static.groupConfig
= {};
12084 * Handle the tool being selected.
12088 OO
.ui
.ToolGroupTool
.prototype.onSelect = function () {
12089 this.innerToolGroup
.setActive( !this.innerToolGroup
.active
);
12094 * Synchronize disabledness state of the tool with the inner toolgroup.
12097 * @param {boolean} disabled Element is disabled
12099 OO
.ui
.ToolGroupTool
.prototype.onToolGroupDisable = function ( disabled
) {
12100 this.setDisabled( disabled
);
12104 * Handle the toolbar state being updated.
12108 OO
.ui
.ToolGroupTool
.prototype.onUpdateState = function () {
12109 this.setActive( false );
12113 * Build a {@link OO.ui.ToolGroup toolgroup} from the specified configuration.
12115 * @param {Object.<string,Array>} group Toolgroup configuration. Please see {@link OO.ui.ToolGroup toolgroup} for
12116 * more information.
12117 * @return {OO.ui.ListToolGroup}
12119 OO
.ui
.ToolGroupTool
.prototype.createGroup = function ( group
) {
12120 if ( group
.include
=== '*' ) {
12121 // Apply defaults to catch-all groups
12122 if ( group
.label
=== undefined ) {
12123 group
.label
= OO
.ui
.msg( 'ooui-toolbar-more' );
12127 return this.toolbar
.getToolGroupFactory().create( 'list', this.toolbar
, group
);
12131 * Mixin for OO.ui.Widget subclasses to provide OO.ui.mixin.GroupElement.
12133 * Use together with OO.ui.mixin.ItemWidget to make disabled state inheritable.
12138 * @extends OO.ui.mixin.GroupElement
12141 * @param {Object} [config] Configuration options
12143 OO
.ui
.mixin
.GroupWidget
= function OoUiMixinGroupWidget( config
) {
12144 // Parent constructor
12145 OO
.ui
.mixin
.GroupWidget
.parent
.call( this, config
);
12150 OO
.inheritClass( OO
.ui
.mixin
.GroupWidget
, OO
.ui
.mixin
.GroupElement
);
12155 * Set the disabled state of the widget.
12157 * This will also update the disabled state of child widgets.
12159 * @param {boolean} disabled Disable widget
12162 OO
.ui
.mixin
.GroupWidget
.prototype.setDisabled = function ( disabled
) {
12166 // Note: Calling #setDisabled this way assumes this is mixed into an OO.ui.Widget
12167 OO
.ui
.Widget
.prototype.setDisabled
.call( this, disabled
);
12169 // During construction, #setDisabled is called before the OO.ui.mixin.GroupElement constructor
12170 if ( this.items
) {
12171 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
12172 this.items
[ i
].updateDisabled();
12180 * Mixin for widgets used as items in widgets that mix in OO.ui.mixin.GroupWidget.
12182 * Item widgets have a reference to a OO.ui.mixin.GroupWidget while they are attached to the group. This
12183 * allows bidirectional communication.
12185 * Use together with OO.ui.mixin.GroupWidget to make disabled state inheritable.
12193 OO
.ui
.mixin
.ItemWidget
= function OoUiMixinItemWidget() {
12200 * Check if widget is disabled.
12202 * Checks parent if present, making disabled state inheritable.
12204 * @return {boolean} Widget is disabled
12206 OO
.ui
.mixin
.ItemWidget
.prototype.isDisabled = function () {
12207 return this.disabled
||
12208 ( this.elementGroup
instanceof OO
.ui
.Widget
&& this.elementGroup
.isDisabled() );
12212 * Set group element is in.
12214 * @param {OO.ui.mixin.GroupElement|null} group Group element, null if none
12217 OO
.ui
.mixin
.ItemWidget
.prototype.setElementGroup = function ( group
) {
12219 // Note: Calling #setElementGroup this way assumes this is mixed into an OO.ui.Element
12220 OO
.ui
.Element
.prototype.setElementGroup
.call( this, group
);
12222 // Initialize item disabled states
12223 this.updateDisabled();
12229 * OutlineControlsWidget is a set of controls for an {@link OO.ui.OutlineSelectWidget outline select widget}.
12230 * Controls include moving items up and down, removing items, and adding different kinds of items.
12232 * **Currently, this class is only used by {@link OO.ui.BookletLayout booklet layouts}.**
12235 * @extends OO.ui.Widget
12236 * @mixins OO.ui.mixin.GroupElement
12237 * @mixins OO.ui.mixin.IconElement
12240 * @param {OO.ui.OutlineSelectWidget} outline Outline to control
12241 * @param {Object} [config] Configuration options
12242 * @cfg {Object} [abilities] List of abilties
12243 * @cfg {boolean} [abilities.move=true] Allow moving movable items
12244 * @cfg {boolean} [abilities.remove=true] Allow removing removable items
12246 OO
.ui
.OutlineControlsWidget
= function OoUiOutlineControlsWidget( outline
, config
) {
12247 // Allow passing positional parameters inside the config object
12248 if ( OO
.isPlainObject( outline
) && config
=== undefined ) {
12250 outline
= config
.outline
;
12253 // Configuration initialization
12254 config
= $.extend( { icon
: 'add' }, config
);
12256 // Parent constructor
12257 OO
.ui
.OutlineControlsWidget
.parent
.call( this, config
);
12259 // Mixin constructors
12260 OO
.ui
.mixin
.GroupElement
.call( this, config
);
12261 OO
.ui
.mixin
.IconElement
.call( this, config
);
12264 this.outline
= outline
;
12265 this.$movers
= $( '<div>' );
12266 this.upButton
= new OO
.ui
.ButtonWidget( {
12269 title
: OO
.ui
.msg( 'ooui-outline-control-move-up' )
12271 this.downButton
= new OO
.ui
.ButtonWidget( {
12274 title
: OO
.ui
.msg( 'ooui-outline-control-move-down' )
12276 this.removeButton
= new OO
.ui
.ButtonWidget( {
12279 title
: OO
.ui
.msg( 'ooui-outline-control-remove' )
12281 this.abilities
= { move: true, remove
: true };
12284 outline
.connect( this, {
12285 select
: 'onOutlineChange',
12286 add
: 'onOutlineChange',
12287 remove
: 'onOutlineChange'
12289 this.upButton
.connect( this, { click
: [ 'emit', 'move', -1 ] } );
12290 this.downButton
.connect( this, { click
: [ 'emit', 'move', 1 ] } );
12291 this.removeButton
.connect( this, { click
: [ 'emit', 'remove' ] } );
12294 this.$element
.addClass( 'oo-ui-outlineControlsWidget' );
12295 this.$group
.addClass( 'oo-ui-outlineControlsWidget-items' );
12297 .addClass( 'oo-ui-outlineControlsWidget-movers' )
12298 .append( this.removeButton
.$element
, this.upButton
.$element
, this.downButton
.$element
);
12299 this.$element
.append( this.$icon
, this.$group
, this.$movers
);
12300 this.setAbilities( config
.abilities
|| {} );
12305 OO
.inheritClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.Widget
);
12306 OO
.mixinClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.mixin
.GroupElement
);
12307 OO
.mixinClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.mixin
.IconElement
);
12313 * @param {number} places Number of places to move
12325 * @param {Object} abilities List of abilties
12326 * @param {boolean} [abilities.move] Allow moving movable items
12327 * @param {boolean} [abilities.remove] Allow removing removable items
12329 OO
.ui
.OutlineControlsWidget
.prototype.setAbilities = function ( abilities
) {
12332 for ( ability
in this.abilities
) {
12333 if ( abilities
[ ability
] !== undefined ) {
12334 this.abilities
[ ability
] = !!abilities
[ ability
];
12338 this.onOutlineChange();
12343 * Handle outline change events.
12345 OO
.ui
.OutlineControlsWidget
.prototype.onOutlineChange = function () {
12346 var i
, len
, firstMovable
, lastMovable
,
12347 items
= this.outline
.getItems(),
12348 selectedItem
= this.outline
.getSelectedItem(),
12349 movable
= this.abilities
.move && selectedItem
&& selectedItem
.isMovable(),
12350 removable
= this.abilities
.remove
&& selectedItem
&& selectedItem
.isRemovable();
12354 len
= items
.length
;
12355 while ( ++i
< len
) {
12356 if ( items
[ i
].isMovable() ) {
12357 firstMovable
= items
[ i
];
12363 if ( items
[ i
].isMovable() ) {
12364 lastMovable
= items
[ i
];
12369 this.upButton
.setDisabled( !movable
|| selectedItem
=== firstMovable
);
12370 this.downButton
.setDisabled( !movable
|| selectedItem
=== lastMovable
);
12371 this.removeButton
.setDisabled( !removable
);
12375 * ToggleWidget implements basic behavior of widgets with an on/off state.
12376 * Please see OO.ui.ToggleButtonWidget and OO.ui.ToggleSwitchWidget for examples.
12380 * @extends OO.ui.Widget
12383 * @param {Object} [config] Configuration options
12384 * @cfg {boolean} [value=false] The toggle’s initial on/off state.
12385 * By default, the toggle is in the 'off' state.
12387 OO
.ui
.ToggleWidget
= function OoUiToggleWidget( config
) {
12388 // Configuration initialization
12389 config
= config
|| {};
12391 // Parent constructor
12392 OO
.ui
.ToggleWidget
.parent
.call( this, config
);
12398 this.$element
.addClass( 'oo-ui-toggleWidget' );
12399 this.setValue( !!config
.value
);
12404 OO
.inheritClass( OO
.ui
.ToggleWidget
, OO
.ui
.Widget
);
12411 * A change event is emitted when the on/off state of the toggle changes.
12413 * @param {boolean} value Value representing the new state of the toggle
12419 * Get the value representing the toggle’s state.
12421 * @return {boolean} The on/off state of the toggle
12423 OO
.ui
.ToggleWidget
.prototype.getValue = function () {
12428 * Set the state of the toggle: `true` for 'on', `false' for 'off'.
12430 * @param {boolean} value The state of the toggle
12434 OO
.ui
.ToggleWidget
.prototype.setValue = function ( value
) {
12436 if ( this.value
!== value
) {
12437 this.value
= value
;
12438 this.emit( 'change', value
);
12439 this.$element
.toggleClass( 'oo-ui-toggleWidget-on', value
);
12440 this.$element
.toggleClass( 'oo-ui-toggleWidget-off', !value
);
12441 this.$element
.attr( 'aria-checked', value
.toString() );
12447 * A ButtonGroupWidget groups related buttons and is used together with OO.ui.ButtonWidget and
12448 * its subclasses. Each button in a group is addressed by a unique reference. Buttons can be added,
12449 * removed, and cleared from the group.
12452 * // Example: A ButtonGroupWidget with two buttons
12453 * var button1 = new OO.ui.PopupButtonWidget( {
12454 * label: 'Select a category',
12457 * $content: $( '<p>List of categories...</p>' ),
12462 * var button2 = new OO.ui.ButtonWidget( {
12463 * label: 'Add item'
12465 * var buttonGroup = new OO.ui.ButtonGroupWidget( {
12466 * items: [button1, button2]
12468 * $( 'body' ).append( buttonGroup.$element );
12471 * @extends OO.ui.Widget
12472 * @mixins OO.ui.mixin.GroupElement
12475 * @param {Object} [config] Configuration options
12476 * @cfg {OO.ui.ButtonWidget[]} [items] Buttons to add
12478 OO
.ui
.ButtonGroupWidget
= function OoUiButtonGroupWidget( config
) {
12479 // Configuration initialization
12480 config
= config
|| {};
12482 // Parent constructor
12483 OO
.ui
.ButtonGroupWidget
.parent
.call( this, config
);
12485 // Mixin constructors
12486 OO
.ui
.mixin
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
12489 this.$element
.addClass( 'oo-ui-buttonGroupWidget' );
12490 if ( Array
.isArray( config
.items
) ) {
12491 this.addItems( config
.items
);
12497 OO
.inheritClass( OO
.ui
.ButtonGroupWidget
, OO
.ui
.Widget
);
12498 OO
.mixinClass( OO
.ui
.ButtonGroupWidget
, OO
.ui
.mixin
.GroupElement
);
12501 * ButtonWidget is a generic widget for buttons. A wide variety of looks,
12502 * feels, and functionality can be customized via the class’s configuration options
12503 * and methods. Please see the [OOjs UI documentation on MediaWiki] [1] for more information
12506 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Buttons_and_Switches
12509 * // A button widget
12510 * var button = new OO.ui.ButtonWidget( {
12511 * label: 'Button with Icon',
12513 * iconTitle: 'Remove'
12515 * $( 'body' ).append( button.$element );
12517 * NOTE: HTML form buttons should use the OO.ui.ButtonInputWidget class.
12520 * @extends OO.ui.Widget
12521 * @mixins OO.ui.mixin.ButtonElement
12522 * @mixins OO.ui.mixin.IconElement
12523 * @mixins OO.ui.mixin.IndicatorElement
12524 * @mixins OO.ui.mixin.LabelElement
12525 * @mixins OO.ui.mixin.TitledElement
12526 * @mixins OO.ui.mixin.FlaggedElement
12527 * @mixins OO.ui.mixin.TabIndexedElement
12528 * @mixins OO.ui.mixin.AccessKeyedElement
12531 * @param {Object} [config] Configuration options
12532 * @cfg {string} [href] Hyperlink to visit when the button is clicked.
12533 * @cfg {string} [target] The frame or window in which to open the hyperlink.
12534 * @cfg {boolean} [noFollow] Search engine traversal hint (default: true)
12536 OO
.ui
.ButtonWidget
= function OoUiButtonWidget( config
) {
12537 // Configuration initialization
12538 config
= config
|| {};
12540 // Parent constructor
12541 OO
.ui
.ButtonWidget
.parent
.call( this, config
);
12543 // Mixin constructors
12544 OO
.ui
.mixin
.ButtonElement
.call( this, config
);
12545 OO
.ui
.mixin
.IconElement
.call( this, config
);
12546 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
12547 OO
.ui
.mixin
.LabelElement
.call( this, config
);
12548 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$button
} ) );
12549 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
12550 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$button
} ) );
12551 OO
.ui
.mixin
.AccessKeyedElement
.call( this, $.extend( {}, config
, { $accessKeyed
: this.$button
} ) );
12555 this.target
= null;
12556 this.noFollow
= false;
12559 this.connect( this, { disable
: 'onDisable' } );
12562 this.$button
.append( this.$icon
, this.$label
, this.$indicator
);
12564 .addClass( 'oo-ui-buttonWidget' )
12565 .append( this.$button
);
12566 this.setHref( config
.href
);
12567 this.setTarget( config
.target
);
12568 this.setNoFollow( config
.noFollow
);
12573 OO
.inheritClass( OO
.ui
.ButtonWidget
, OO
.ui
.Widget
);
12574 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.ButtonElement
);
12575 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.IconElement
);
12576 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.IndicatorElement
);
12577 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.LabelElement
);
12578 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.TitledElement
);
12579 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.FlaggedElement
);
12580 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.TabIndexedElement
);
12581 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.mixin
.AccessKeyedElement
);
12588 OO
.ui
.ButtonWidget
.prototype.onMouseDown = function ( e
) {
12589 if ( !this.isDisabled() ) {
12590 // Remove the tab-index while the button is down to prevent the button from stealing focus
12591 this.$button
.removeAttr( 'tabindex' );
12594 return OO
.ui
.mixin
.ButtonElement
.prototype.onMouseDown
.call( this, e
);
12600 OO
.ui
.ButtonWidget
.prototype.onMouseUp = function ( e
) {
12601 if ( !this.isDisabled() ) {
12602 // Restore the tab-index after the button is up to restore the button's accessibility
12603 this.$button
.attr( 'tabindex', this.tabIndex
);
12606 return OO
.ui
.mixin
.ButtonElement
.prototype.onMouseUp
.call( this, e
);
12610 * Get hyperlink location.
12612 * @return {string} Hyperlink location
12614 OO
.ui
.ButtonWidget
.prototype.getHref = function () {
12619 * Get hyperlink target.
12621 * @return {string} Hyperlink target
12623 OO
.ui
.ButtonWidget
.prototype.getTarget = function () {
12624 return this.target
;
12628 * Get search engine traversal hint.
12630 * @return {boolean} Whether search engines should avoid traversing this hyperlink
12632 OO
.ui
.ButtonWidget
.prototype.getNoFollow = function () {
12633 return this.noFollow
;
12637 * Set hyperlink location.
12639 * @param {string|null} href Hyperlink location, null to remove
12641 OO
.ui
.ButtonWidget
.prototype.setHref = function ( href
) {
12642 href
= typeof href
=== 'string' ? href
: null;
12643 if ( href
!== null ) {
12644 if ( !OO
.ui
.isSafeUrl( href
) ) {
12645 throw new Error( 'Potentially unsafe href provided: ' + href
);
12650 if ( href
!== this.href
) {
12659 * Update the `href` attribute, in case of changes to href or
12665 OO
.ui
.ButtonWidget
.prototype.updateHref = function () {
12666 if ( this.href
!== null && !this.isDisabled() ) {
12667 this.$button
.attr( 'href', this.href
);
12669 this.$button
.removeAttr( 'href' );
12676 * Handle disable events.
12679 * @param {boolean} disabled Element is disabled
12681 OO
.ui
.ButtonWidget
.prototype.onDisable = function () {
12686 * Set hyperlink target.
12688 * @param {string|null} target Hyperlink target, null to remove
12690 OO
.ui
.ButtonWidget
.prototype.setTarget = function ( target
) {
12691 target
= typeof target
=== 'string' ? target
: null;
12693 if ( target
!== this.target
) {
12694 this.target
= target
;
12695 if ( target
!== null ) {
12696 this.$button
.attr( 'target', target
);
12698 this.$button
.removeAttr( 'target' );
12706 * Set search engine traversal hint.
12708 * @param {boolean} noFollow True if search engines should avoid traversing this hyperlink
12710 OO
.ui
.ButtonWidget
.prototype.setNoFollow = function ( noFollow
) {
12711 noFollow
= typeof noFollow
=== 'boolean' ? noFollow
: true;
12713 if ( noFollow
!== this.noFollow
) {
12714 this.noFollow
= noFollow
;
12716 this.$button
.attr( 'rel', 'nofollow' );
12718 this.$button
.removeAttr( 'rel' );
12726 * An ActionWidget is a {@link OO.ui.ButtonWidget button widget} that executes an action.
12727 * Action widgets are used with OO.ui.ActionSet, which manages the behavior and availability
12730 * Both actions and action sets are primarily used with {@link OO.ui.Dialog Dialogs}.
12731 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information
12734 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs#Action_sets
12737 * @extends OO.ui.ButtonWidget
12738 * @mixins OO.ui.mixin.PendingElement
12741 * @param {Object} [config] Configuration options
12742 * @cfg {string} [action] Symbolic name of the action (e.g., ‘continue’ or ‘cancel’).
12743 * @cfg {string[]} [modes] Symbolic names of the modes (e.g., ‘edit’ or ‘read’) in which the action
12744 * should be made available. See the action set's {@link OO.ui.ActionSet#setMode setMode} method
12745 * for more information about setting modes.
12746 * @cfg {boolean} [framed=false] Render the action button with a frame
12748 OO
.ui
.ActionWidget
= function OoUiActionWidget( config
) {
12749 // Configuration initialization
12750 config
= $.extend( { framed
: false }, config
);
12752 // Parent constructor
12753 OO
.ui
.ActionWidget
.parent
.call( this, config
);
12755 // Mixin constructors
12756 OO
.ui
.mixin
.PendingElement
.call( this, config
);
12759 this.action
= config
.action
|| '';
12760 this.modes
= config
.modes
|| [];
12765 this.$element
.addClass( 'oo-ui-actionWidget' );
12770 OO
.inheritClass( OO
.ui
.ActionWidget
, OO
.ui
.ButtonWidget
);
12771 OO
.mixinClass( OO
.ui
.ActionWidget
, OO
.ui
.mixin
.PendingElement
);
12776 * A resize event is emitted when the size of the widget changes.
12784 * Check if the action is configured to be available in the specified `mode`.
12786 * @param {string} mode Name of mode
12787 * @return {boolean} The action is configured with the mode
12789 OO
.ui
.ActionWidget
.prototype.hasMode = function ( mode
) {
12790 return this.modes
.indexOf( mode
) !== -1;
12794 * Get the symbolic name of the action (e.g., ‘continue’ or ‘cancel’).
12798 OO
.ui
.ActionWidget
.prototype.getAction = function () {
12799 return this.action
;
12803 * Get the symbolic name of the mode or modes for which the action is configured to be available.
12805 * The current mode is set with the action set's {@link OO.ui.ActionSet#setMode setMode} method.
12806 * Only actions that are configured to be avaiable in the current mode will be visible. All other actions
12809 * @return {string[]}
12811 OO
.ui
.ActionWidget
.prototype.getModes = function () {
12812 return this.modes
.slice();
12816 * Emit a resize event if the size has changed.
12821 OO
.ui
.ActionWidget
.prototype.propagateResize = function () {
12824 if ( this.isElementAttached() ) {
12825 width
= this.$element
.width();
12826 height
= this.$element
.height();
12828 if ( width
!== this.width
|| height
!== this.height
) {
12829 this.width
= width
;
12830 this.height
= height
;
12831 this.emit( 'resize' );
12841 OO
.ui
.ActionWidget
.prototype.setIcon = function () {
12843 OO
.ui
.mixin
.IconElement
.prototype.setIcon
.apply( this, arguments
);
12844 this.propagateResize();
12852 OO
.ui
.ActionWidget
.prototype.setLabel = function () {
12854 OO
.ui
.mixin
.LabelElement
.prototype.setLabel
.apply( this, arguments
);
12855 this.propagateResize();
12863 OO
.ui
.ActionWidget
.prototype.setFlags = function () {
12865 OO
.ui
.mixin
.FlaggedElement
.prototype.setFlags
.apply( this, arguments
);
12866 this.propagateResize();
12874 OO
.ui
.ActionWidget
.prototype.clearFlags = function () {
12876 OO
.ui
.mixin
.FlaggedElement
.prototype.clearFlags
.apply( this, arguments
);
12877 this.propagateResize();
12883 * Toggle the visibility of the action button.
12885 * @param {boolean} [show] Show button, omit to toggle visibility
12888 OO
.ui
.ActionWidget
.prototype.toggle = function () {
12890 OO
.ui
.ActionWidget
.parent
.prototype.toggle
.apply( this, arguments
);
12891 this.propagateResize();
12897 * PopupButtonWidgets toggle the visibility of a contained {@link OO.ui.PopupWidget PopupWidget},
12898 * which is used to display additional information or options.
12901 * // Example of a popup button.
12902 * var popupButton = new OO.ui.PopupButtonWidget( {
12903 * label: 'Popup button with options',
12906 * $content: $( '<p>Additional options here.</p>' ),
12908 * align: 'force-left'
12911 * // Append the button to the DOM.
12912 * $( 'body' ).append( popupButton.$element );
12915 * @extends OO.ui.ButtonWidget
12916 * @mixins OO.ui.mixin.PopupElement
12919 * @param {Object} [config] Configuration options
12921 OO
.ui
.PopupButtonWidget
= function OoUiPopupButtonWidget( config
) {
12922 // Parent constructor
12923 OO
.ui
.PopupButtonWidget
.parent
.call( this, config
);
12925 // Mixin constructors
12926 OO
.ui
.mixin
.PopupElement
.call( this, config
);
12929 this.connect( this, { click
: 'onAction' } );
12933 .addClass( 'oo-ui-popupButtonWidget' )
12934 .attr( 'aria-haspopup', 'true' )
12935 .append( this.popup
.$element
);
12940 OO
.inheritClass( OO
.ui
.PopupButtonWidget
, OO
.ui
.ButtonWidget
);
12941 OO
.mixinClass( OO
.ui
.PopupButtonWidget
, OO
.ui
.mixin
.PopupElement
);
12946 * Handle the button action being triggered.
12950 OO
.ui
.PopupButtonWidget
.prototype.onAction = function () {
12951 this.popup
.toggle();
12955 * ToggleButtons are buttons that have a state (‘on’ or ‘off’) that is represented by a
12956 * Boolean value. Like other {@link OO.ui.ButtonWidget buttons}, toggle buttons can be
12957 * configured with {@link OO.ui.mixin.IconElement icons}, {@link OO.ui.mixin.IndicatorElement indicators},
12958 * {@link OO.ui.mixin.TitledElement titles}, {@link OO.ui.mixin.FlaggedElement styling flags},
12959 * and {@link OO.ui.mixin.LabelElement labels}. Please see
12960 * the [OOjs UI documentation][1] on MediaWiki for more information.
12963 * // Toggle buttons in the 'off' and 'on' state.
12964 * var toggleButton1 = new OO.ui.ToggleButtonWidget( {
12965 * label: 'Toggle Button off'
12967 * var toggleButton2 = new OO.ui.ToggleButtonWidget( {
12968 * label: 'Toggle Button on',
12971 * // Append the buttons to the DOM.
12972 * $( 'body' ).append( toggleButton1.$element, toggleButton2.$element );
12974 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Buttons_and_Switches#Toggle_buttons
12977 * @extends OO.ui.ToggleWidget
12978 * @mixins OO.ui.mixin.ButtonElement
12979 * @mixins OO.ui.mixin.IconElement
12980 * @mixins OO.ui.mixin.IndicatorElement
12981 * @mixins OO.ui.mixin.LabelElement
12982 * @mixins OO.ui.mixin.TitledElement
12983 * @mixins OO.ui.mixin.FlaggedElement
12984 * @mixins OO.ui.mixin.TabIndexedElement
12987 * @param {Object} [config] Configuration options
12988 * @cfg {boolean} [value=false] The toggle button’s initial on/off
12989 * state. By default, the button is in the 'off' state.
12991 OO
.ui
.ToggleButtonWidget
= function OoUiToggleButtonWidget( config
) {
12992 // Configuration initialization
12993 config
= config
|| {};
12995 // Parent constructor
12996 OO
.ui
.ToggleButtonWidget
.parent
.call( this, config
);
12998 // Mixin constructors
12999 OO
.ui
.mixin
.ButtonElement
.call( this, config
);
13000 OO
.ui
.mixin
.IconElement
.call( this, config
);
13001 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
13002 OO
.ui
.mixin
.LabelElement
.call( this, config
);
13003 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$button
} ) );
13004 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
13005 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$button
} ) );
13008 this.connect( this, { click
: 'onAction' } );
13011 this.$button
.append( this.$icon
, this.$label
, this.$indicator
);
13013 .addClass( 'oo-ui-toggleButtonWidget' )
13014 .append( this.$button
);
13019 OO
.inheritClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.ToggleWidget
);
13020 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.ButtonElement
);
13021 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.IconElement
);
13022 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.IndicatorElement
);
13023 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.LabelElement
);
13024 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.TitledElement
);
13025 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.FlaggedElement
);
13026 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.mixin
.TabIndexedElement
);
13031 * Handle the button action being triggered.
13035 OO
.ui
.ToggleButtonWidget
.prototype.onAction = function () {
13036 this.setValue( !this.value
);
13042 OO
.ui
.ToggleButtonWidget
.prototype.setValue = function ( value
) {
13044 if ( value
!== this.value
) {
13045 // Might be called from parent constructor before ButtonElement constructor
13046 if ( this.$button
) {
13047 this.$button
.attr( 'aria-pressed', value
.toString() );
13049 this.setActive( value
);
13053 OO
.ui
.ToggleButtonWidget
.parent
.prototype.setValue
.call( this, value
);
13061 OO
.ui
.ToggleButtonWidget
.prototype.setButtonElement = function ( $button
) {
13062 if ( this.$button
) {
13063 this.$button
.removeAttr( 'aria-pressed' );
13065 OO
.ui
.mixin
.ButtonElement
.prototype.setButtonElement
.call( this, $button
);
13066 this.$button
.attr( 'aria-pressed', this.value
.toString() );
13070 * CapsuleMultiSelectWidgets are something like a {@link OO.ui.ComboBoxWidget combo box widget}
13071 * that allows for selecting multiple values.
13073 * For more information about menus and options, please see the [OOjs UI documentation on MediaWiki][1].
13076 * // Example: A CapsuleMultiSelectWidget.
13077 * var capsule = new OO.ui.CapsuleMultiSelectWidget( {
13078 * label: 'CapsuleMultiSelectWidget',
13079 * selected: [ 'Option 1', 'Option 3' ],
13082 * new OO.ui.MenuOptionWidget( {
13083 * data: 'Option 1',
13084 * label: 'Option One'
13086 * new OO.ui.MenuOptionWidget( {
13087 * data: 'Option 2',
13088 * label: 'Option Two'
13090 * new OO.ui.MenuOptionWidget( {
13091 * data: 'Option 3',
13092 * label: 'Option Three'
13094 * new OO.ui.MenuOptionWidget( {
13095 * data: 'Option 4',
13096 * label: 'Option Four'
13098 * new OO.ui.MenuOptionWidget( {
13099 * data: 'Option 5',
13100 * label: 'Option Five'
13105 * $( 'body' ).append( capsule.$element );
13107 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Menu_selects_and_options
13110 * @extends OO.ui.Widget
13111 * @mixins OO.ui.mixin.TabIndexedElement
13112 * @mixins OO.ui.mixin.GroupElement
13115 * @param {Object} [config] Configuration options
13116 * @cfg {boolean} [allowArbitrary=false] Allow data items to be added even if not present in the menu.
13117 * @cfg {Object} [menu] Configuration options to pass to the {@link OO.ui.MenuSelectWidget menu select widget}.
13118 * @cfg {Object} [popup] Configuration options to pass to the {@link OO.ui.PopupWidget popup widget}.
13119 * If specified, this popup will be shown instead of the menu (but the menu
13120 * will still be used for item labels and allowArbitrary=false). The widgets
13121 * in the popup should use this.addItemsFromData() or this.addItems() as necessary.
13122 * @cfg {jQuery} [$overlay] Render the menu or popup into a separate layer.
13123 * This configuration is useful in cases where the expanded menu is larger than
13124 * its containing `<div>`. The specified overlay layer is usually on top of
13125 * the containing `<div>` and has a larger area. By default, the menu uses
13126 * relative positioning.
13128 OO
.ui
.CapsuleMultiSelectWidget
= function OoUiCapsuleMultiSelectWidget( config
) {
13131 // Configuration initialization
13132 config
= config
|| {};
13134 // Parent constructor
13135 OO
.ui
.CapsuleMultiSelectWidget
.parent
.call( this, config
);
13137 // Properties (must be set before mixin constructor calls)
13138 this.$input
= config
.popup
? null : $( '<input>' );
13139 this.$handle
= $( '<div>' );
13141 // Mixin constructors
13142 OO
.ui
.mixin
.GroupElement
.call( this, config
);
13143 if ( config
.popup
) {
13144 config
.popup
= $.extend( {}, config
.popup
, {
13148 OO
.ui
.mixin
.PopupElement
.call( this, config
);
13149 $tabFocus
= $( '<span>' );
13150 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: $tabFocus
} ) );
13154 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$input
} ) );
13156 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
13157 OO
.ui
.mixin
.IconElement
.call( this, config
);
13160 this.allowArbitrary
= !!config
.allowArbitrary
;
13161 this.$overlay
= config
.$overlay
|| this.$element
;
13162 this.menu
= new OO
.ui
.FloatingMenuSelectWidget( $.extend(
13165 $input
: this.$input
,
13166 $container
: this.$element
,
13167 filterFromInput
: true,
13168 disabled
: this.isDisabled()
13174 if ( this.popup
) {
13176 focus
: this.onFocusForPopup
.bind( this )
13178 this.popup
.$element
.on( 'focusout', this.onPopupFocusOut
.bind( this ) );
13179 if ( this.popup
.$autoCloseIgnore
) {
13180 this.popup
.$autoCloseIgnore
.on( 'focusout', this.onPopupFocusOut
.bind( this ) );
13182 this.popup
.connect( this, {
13183 toggle: function ( visible
) {
13184 $tabFocus
.toggle( !visible
);
13189 focus
: this.onInputFocus
.bind( this ),
13190 blur
: this.onInputBlur
.bind( this ),
13191 'propertychange change click mouseup keydown keyup input cut paste select': this.onInputChange
.bind( this ),
13192 keydown
: this.onKeyDown
.bind( this ),
13193 keypress
: this.onKeyPress
.bind( this )
13196 this.menu
.connect( this, {
13197 choose
: 'onMenuChoose',
13198 add
: 'onMenuItemsChange',
13199 remove
: 'onMenuItemsChange'
13202 click
: this.onClick
.bind( this )
13206 if ( this.$input
) {
13207 this.$input
.prop( 'disabled', this.isDisabled() );
13208 this.$input
.attr( {
13210 'aria-autocomplete': 'list'
13212 this.$input
.width( '1em' );
13214 if ( config
.data
) {
13215 this.setItemsFromData( config
.data
);
13217 this.$group
.addClass( 'oo-ui-capsuleMultiSelectWidget-group' );
13218 this.$handle
.addClass( 'oo-ui-capsuleMultiSelectWidget-handle' )
13219 .append( this.$indicator
, this.$icon
, this.$group
);
13220 this.$element
.addClass( 'oo-ui-capsuleMultiSelectWidget' )
13221 .append( this.$handle
);
13222 if ( this.popup
) {
13223 this.$handle
.append( $tabFocus
);
13224 this.$overlay
.append( this.popup
.$element
);
13226 this.$handle
.append( this.$input
);
13227 this.$overlay
.append( this.menu
.$element
);
13229 this.onMenuItemsChange();
13234 OO
.inheritClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.Widget
);
13235 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.GroupElement
);
13236 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.PopupElement
);
13237 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
13238 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.IndicatorElement
);
13239 OO
.mixinClass( OO
.ui
.CapsuleMultiSelectWidget
, OO
.ui
.mixin
.IconElement
);
13246 * A change event is emitted when the set of selected items changes.
13248 * @param {Mixed[]} datas Data of the now-selected items
13254 * Construct a OO.ui.CapsuleItemWidget (or a subclass thereof) from given label and data.
13257 * @param {Mixed} data Custom data of any type.
13258 * @param {string} label The label text.
13259 * @return {OO.ui.CapsuleItemWidget}
13261 OO
.ui
.CapsuleMultiSelectWidget
.prototype.createItemWidget = function ( data
, label
) {
13262 return new OO
.ui
.CapsuleItemWidget( { data
: data
, label
: label
} );
13266 * Get the data of the items in the capsule
13267 * @return {Mixed[]}
13269 OO
.ui
.CapsuleMultiSelectWidget
.prototype.getItemsData = function () {
13270 return $.map( this.getItems(), function ( e
) { return e
.data
; } );
13274 * Set the items in the capsule by providing data
13276 * @param {Mixed[]} datas
13277 * @return {OO.ui.CapsuleMultiSelectWidget}
13279 OO
.ui
.CapsuleMultiSelectWidget
.prototype.setItemsFromData = function ( datas
) {
13282 items
= this.getItems();
13284 $.each( datas
, function ( i
, data
) {
13286 item
= menu
.getItemFromData( data
);
13289 label
= item
.label
;
13290 } else if ( widget
.allowArbitrary
) {
13291 label
= String( data
);
13297 for ( j
= 0; j
< items
.length
; j
++ ) {
13298 if ( items
[ j
].data
=== data
&& items
[ j
].label
=== label
) {
13300 items
.splice( j
, 1 );
13305 item
= widget
.createItemWidget( data
, label
);
13307 widget
.addItems( [ item
], i
);
13310 if ( items
.length
) {
13311 widget
.removeItems( items
);
13318 * Add items to the capsule by providing their data
13320 * @param {Mixed[]} datas
13321 * @return {OO.ui.CapsuleMultiSelectWidget}
13323 OO
.ui
.CapsuleMultiSelectWidget
.prototype.addItemsFromData = function ( datas
) {
13328 $.each( datas
, function ( i
, data
) {
13331 if ( !widget
.getItemFromData( data
) ) {
13332 item
= menu
.getItemFromData( data
);
13334 items
.push( widget
.createItemWidget( data
, item
.label
) );
13335 } else if ( widget
.allowArbitrary
) {
13336 items
.push( widget
.createItemWidget( data
, String( data
) ) );
13341 if ( items
.length
) {
13342 this.addItems( items
);
13349 * Remove items by data
13351 * @param {Mixed[]} datas
13352 * @return {OO.ui.CapsuleMultiSelectWidget}
13354 OO
.ui
.CapsuleMultiSelectWidget
.prototype.removeItemsFromData = function ( datas
) {
13358 $.each( datas
, function ( i
, data
) {
13359 var item
= widget
.getItemFromData( data
);
13361 items
.push( item
);
13365 if ( items
.length
) {
13366 this.removeItems( items
);
13375 OO
.ui
.CapsuleMultiSelectWidget
.prototype.addItems = function ( items
) {
13377 oldItems
= this.items
.slice();
13379 OO
.ui
.mixin
.GroupElement
.prototype.addItems
.call( this, items
);
13381 if ( this.items
.length
!== oldItems
.length
) {
13385 for ( i
= 0, l
= oldItems
.length
; same
&& i
< l
; i
++ ) {
13386 same
= same
&& this.items
[ i
] === oldItems
[ i
];
13390 this.emit( 'change', this.getItemsData() );
13399 OO
.ui
.CapsuleMultiSelectWidget
.prototype.removeItems = function ( items
) {
13401 oldItems
= this.items
.slice();
13403 OO
.ui
.mixin
.GroupElement
.prototype.removeItems
.call( this, items
);
13405 if ( this.items
.length
!== oldItems
.length
) {
13409 for ( i
= 0, l
= oldItems
.length
; same
&& i
< l
; i
++ ) {
13410 same
= same
&& this.items
[ i
] === oldItems
[ i
];
13414 this.emit( 'change', this.getItemsData() );
13423 OO
.ui
.CapsuleMultiSelectWidget
.prototype.clearItems = function () {
13424 if ( this.items
.length
) {
13425 OO
.ui
.mixin
.GroupElement
.prototype.clearItems
.call( this );
13426 this.emit( 'change', this.getItemsData() );
13432 * Get the capsule widget's menu.
13433 * @return {OO.ui.MenuSelectWidget} Menu widget
13435 OO
.ui
.CapsuleMultiSelectWidget
.prototype.getMenu = function () {
13440 * Handle focus events
13443 * @param {jQuery.Event} event
13445 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onInputFocus = function () {
13446 if ( !this.isDisabled() ) {
13447 this.menu
.toggle( true );
13452 * Handle blur events
13455 * @param {jQuery.Event} event
13457 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onInputBlur = function () {
13462 * Handle focus events
13465 * @param {jQuery.Event} event
13467 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onFocusForPopup = function () {
13468 if ( !this.isDisabled() ) {
13469 this.popup
.setSize( this.$handle
.width() );
13470 this.popup
.toggle( true );
13471 this.popup
.$element
.find( '*' )
13472 .filter( function () { return OO
.ui
.isFocusableElement( $( this ), true ); } )
13479 * Handles popup focus out events.
13482 * @param {Event} e Focus out event
13484 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onPopupFocusOut = function () {
13485 var widget
= this.popup
;
13487 setTimeout( function () {
13489 widget
.isVisible() &&
13490 !OO
.ui
.contains( widget
.$element
[ 0 ], document
.activeElement
, true ) &&
13491 ( !widget
.$autoCloseIgnore
|| !widget
.$autoCloseIgnore
.has( document
.activeElement
).length
)
13493 widget
.toggle( false );
13499 * Handle mouse click events.
13502 * @param {jQuery.Event} e Mouse click event
13504 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onClick = function ( e
) {
13505 if ( e
.which
=== 1 ) {
13512 * Handle key press events.
13515 * @param {jQuery.Event} e Key press event
13517 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onKeyPress = function ( e
) {
13520 if ( !this.isDisabled() ) {
13521 if ( e
.which
=== OO
.ui
.Keys
.ESCAPE
) {
13526 if ( !this.popup
) {
13527 this.menu
.toggle( true );
13528 if ( e
.which
=== OO
.ui
.Keys
.ENTER
) {
13529 item
= this.menu
.getItemFromLabel( this.$input
.val(), true );
13531 this.addItemsFromData( [ item
.data
] );
13533 } else if ( this.allowArbitrary
&& this.$input
.val().trim() !== '' ) {
13534 this.addItemsFromData( [ this.$input
.val() ] );
13540 // Make sure the input gets resized.
13541 setTimeout( this.onInputChange
.bind( this ), 0 );
13547 * Handle key down events.
13550 * @param {jQuery.Event} e Key down event
13552 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onKeyDown = function ( e
) {
13553 if ( !this.isDisabled() ) {
13554 // 'keypress' event is not triggered for Backspace
13555 if ( e
.keyCode
=== OO
.ui
.Keys
.BACKSPACE
&& this.$input
.val() === '' ) {
13556 if ( this.items
.length
) {
13557 this.removeItems( this.items
.slice( -1 ) );
13565 * Handle input change events.
13568 * @param {jQuery.Event} e Event of some sort
13570 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onInputChange = function () {
13571 if ( !this.isDisabled() ) {
13572 this.$input
.width( this.$input
.val().length
+ 'em' );
13577 * Handle menu choose events.
13580 * @param {OO.ui.OptionWidget} item Chosen item
13582 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onMenuChoose = function ( item
) {
13583 if ( item
&& item
.isVisible() ) {
13584 this.addItemsFromData( [ item
.getData() ] );
13590 * Handle menu item change events.
13594 OO
.ui
.CapsuleMultiSelectWidget
.prototype.onMenuItemsChange = function () {
13595 this.setItemsFromData( this.getItemsData() );
13596 this.$element
.toggleClass( 'oo-ui-capsuleMultiSelectWidget-empty', this.menu
.isEmpty() );
13600 * Clear the input field
13603 OO
.ui
.CapsuleMultiSelectWidget
.prototype.clearInput = function () {
13604 if ( this.$input
) {
13605 this.$input
.val( '' );
13606 this.$input
.width( '1em' );
13608 if ( this.popup
) {
13609 this.popup
.toggle( false );
13611 this.menu
.toggle( false );
13612 this.menu
.selectItem();
13613 this.menu
.highlightItem();
13619 OO
.ui
.CapsuleMultiSelectWidget
.prototype.setDisabled = function ( disabled
) {
13623 OO
.ui
.CapsuleMultiSelectWidget
.parent
.prototype.setDisabled
.call( this, disabled
);
13625 if ( this.$input
) {
13626 this.$input
.prop( 'disabled', this.isDisabled() );
13629 this.menu
.setDisabled( this.isDisabled() );
13631 if ( this.popup
) {
13632 this.popup
.setDisabled( this.isDisabled() );
13635 if ( this.items
) {
13636 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
13637 this.items
[ i
].updateDisabled();
13647 * @return {OO.ui.CapsuleMultiSelectWidget}
13649 OO
.ui
.CapsuleMultiSelectWidget
.prototype.focus = function () {
13650 if ( !this.isDisabled() ) {
13651 if ( this.popup
) {
13652 this.popup
.setSize( this.$handle
.width() );
13653 this.popup
.toggle( true );
13654 this.popup
.$element
.find( '*' )
13655 .filter( function () { return OO
.ui
.isFocusableElement( $( this ), true ); } )
13659 this.menu
.toggle( true );
13660 this.$input
.focus();
13667 * CapsuleItemWidgets are used within a {@link OO.ui.CapsuleMultiSelectWidget
13668 * CapsuleMultiSelectWidget} to display the selected items.
13671 * @extends OO.ui.Widget
13672 * @mixins OO.ui.mixin.ItemWidget
13673 * @mixins OO.ui.mixin.IndicatorElement
13674 * @mixins OO.ui.mixin.LabelElement
13675 * @mixins OO.ui.mixin.FlaggedElement
13676 * @mixins OO.ui.mixin.TabIndexedElement
13679 * @param {Object} [config] Configuration options
13681 OO
.ui
.CapsuleItemWidget
= function OoUiCapsuleItemWidget( config
) {
13682 // Configuration initialization
13683 config
= config
|| {};
13685 // Parent constructor
13686 OO
.ui
.CapsuleItemWidget
.parent
.call( this, config
);
13688 // Properties (must be set before mixin constructor calls)
13689 this.$indicator
= $( '<span>' );
13691 // Mixin constructors
13692 OO
.ui
.mixin
.ItemWidget
.call( this );
13693 OO
.ui
.mixin
.IndicatorElement
.call( this, $.extend( {}, config
, { $indicator
: this.$indicator
, indicator
: 'clear' } ) );
13694 OO
.ui
.mixin
.LabelElement
.call( this, config
);
13695 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
13696 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$indicator
} ) );
13699 this.$indicator
.on( {
13700 keydown
: this.onCloseKeyDown
.bind( this ),
13701 click
: this.onCloseClick
.bind( this )
13706 .addClass( 'oo-ui-capsuleItemWidget' )
13707 .append( this.$indicator
, this.$label
);
13712 OO
.inheritClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.Widget
);
13713 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.ItemWidget
);
13714 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.IndicatorElement
);
13715 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.LabelElement
);
13716 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.FlaggedElement
);
13717 OO
.mixinClass( OO
.ui
.CapsuleItemWidget
, OO
.ui
.mixin
.TabIndexedElement
);
13722 * Handle close icon clicks
13723 * @param {jQuery.Event} event
13725 OO
.ui
.CapsuleItemWidget
.prototype.onCloseClick = function () {
13726 var element
= this.getElementGroup();
13728 if ( !this.isDisabled() && element
&& $.isFunction( element
.removeItems
) ) {
13729 element
.removeItems( [ this ] );
13735 * Handle close keyboard events
13736 * @param {jQuery.Event} event Key down event
13738 OO
.ui
.CapsuleItemWidget
.prototype.onCloseKeyDown = function ( e
) {
13739 if ( !this.isDisabled() && $.isFunction( this.getElementGroup().removeItems
) ) {
13740 switch ( e
.which
) {
13741 case OO
.ui
.Keys
.ENTER
:
13742 case OO
.ui
.Keys
.BACKSPACE
:
13743 case OO
.ui
.Keys
.SPACE
:
13744 this.getElementGroup().removeItems( [ this ] );
13751 * DropdownWidgets are not menus themselves, rather they contain a menu of options created with
13752 * OO.ui.MenuOptionWidget. The DropdownWidget takes care of opening and displaying the menu so that
13753 * users can interact with it.
13755 * If you want to use this within a HTML form, such as a OO.ui.FormLayout, use
13756 * OO.ui.DropdownInputWidget instead.
13759 * // Example: A DropdownWidget with a menu that contains three options
13760 * var dropDown = new OO.ui.DropdownWidget( {
13761 * label: 'Dropdown menu: Select a menu option',
13764 * new OO.ui.MenuOptionWidget( {
13768 * new OO.ui.MenuOptionWidget( {
13772 * new OO.ui.MenuOptionWidget( {
13780 * $( 'body' ).append( dropDown.$element );
13782 * dropDown.getMenu().selectItemByData( 'b' );
13784 * dropDown.getMenu().getSelectedItem().getData(); // returns 'b'
13786 * For more information, please see the [OOjs UI documentation on MediaWiki] [1].
13788 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Menu_selects_and_options
13791 * @extends OO.ui.Widget
13792 * @mixins OO.ui.mixin.IconElement
13793 * @mixins OO.ui.mixin.IndicatorElement
13794 * @mixins OO.ui.mixin.LabelElement
13795 * @mixins OO.ui.mixin.TitledElement
13796 * @mixins OO.ui.mixin.TabIndexedElement
13799 * @param {Object} [config] Configuration options
13800 * @cfg {Object} [menu] Configuration options to pass to {@link OO.ui.FloatingMenuSelectWidget menu select widget}
13801 * @cfg {jQuery} [$overlay] Render the menu into a separate layer. This configuration is useful in cases where
13802 * the expanded menu is larger than its containing `<div>`. The specified overlay layer is usually on top of the
13803 * containing `<div>` and has a larger area. By default, the menu uses relative positioning.
13805 OO
.ui
.DropdownWidget
= function OoUiDropdownWidget( config
) {
13806 // Configuration initialization
13807 config
= $.extend( { indicator
: 'down' }, config
);
13809 // Parent constructor
13810 OO
.ui
.DropdownWidget
.parent
.call( this, config
);
13812 // Properties (must be set before TabIndexedElement constructor call)
13813 this.$handle
= this.$( '<span>' );
13814 this.$overlay
= config
.$overlay
|| this.$element
;
13816 // Mixin constructors
13817 OO
.ui
.mixin
.IconElement
.call( this, config
);
13818 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
13819 OO
.ui
.mixin
.LabelElement
.call( this, config
);
13820 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$label
} ) );
13821 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$handle
} ) );
13824 this.menu
= new OO
.ui
.FloatingMenuSelectWidget( $.extend( {
13826 $container
: this.$element
13827 }, config
.menu
) );
13831 click
: this.onClick
.bind( this ),
13832 keypress
: this.onKeyPress
.bind( this )
13834 this.menu
.connect( this, { select
: 'onMenuSelect' } );
13838 .addClass( 'oo-ui-dropdownWidget-handle' )
13839 .append( this.$icon
, this.$label
, this.$indicator
);
13841 .addClass( 'oo-ui-dropdownWidget' )
13842 .append( this.$handle
);
13843 this.$overlay
.append( this.menu
.$element
);
13848 OO
.inheritClass( OO
.ui
.DropdownWidget
, OO
.ui
.Widget
);
13849 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.IconElement
);
13850 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.IndicatorElement
);
13851 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.LabelElement
);
13852 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.TitledElement
);
13853 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.mixin
.TabIndexedElement
);
13860 * @return {OO.ui.MenuSelectWidget} Menu of widget
13862 OO
.ui
.DropdownWidget
.prototype.getMenu = function () {
13867 * Handles menu select events.
13870 * @param {OO.ui.MenuOptionWidget} item Selected menu item
13872 OO
.ui
.DropdownWidget
.prototype.onMenuSelect = function ( item
) {
13876 this.setLabel( null );
13880 selectedLabel
= item
.getLabel();
13882 // If the label is a DOM element, clone it, because setLabel will append() it
13883 if ( selectedLabel
instanceof jQuery
) {
13884 selectedLabel
= selectedLabel
.clone();
13887 this.setLabel( selectedLabel
);
13891 * Handle mouse click events.
13894 * @param {jQuery.Event} e Mouse click event
13896 OO
.ui
.DropdownWidget
.prototype.onClick = function ( e
) {
13897 if ( !this.isDisabled() && e
.which
=== 1 ) {
13898 this.menu
.toggle();
13904 * Handle key press events.
13907 * @param {jQuery.Event} e Key press event
13909 OO
.ui
.DropdownWidget
.prototype.onKeyPress = function ( e
) {
13910 if ( !this.isDisabled() &&
13911 ( ( e
.which
=== OO
.ui
.Keys
.SPACE
&& !this.menu
.isVisible() ) || e
.which
=== OO
.ui
.Keys
.ENTER
)
13913 this.menu
.toggle();
13919 * SelectFileWidgets allow for selecting files, using the HTML5 File API. These
13920 * widgets can be configured with {@link OO.ui.mixin.IconElement icons} and {@link
13921 * OO.ui.mixin.IndicatorElement indicators}.
13922 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information and examples.
13925 * // Example of a file select widget
13926 * var selectFile = new OO.ui.SelectFileWidget();
13927 * $( 'body' ).append( selectFile.$element );
13929 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets
13932 * @extends OO.ui.Widget
13933 * @mixins OO.ui.mixin.IconElement
13934 * @mixins OO.ui.mixin.IndicatorElement
13935 * @mixins OO.ui.mixin.PendingElement
13936 * @mixins OO.ui.mixin.LabelElement
13939 * @param {Object} [config] Configuration options
13940 * @cfg {string[]|null} [accept=null] MIME types to accept. null accepts all types.
13941 * @cfg {string} [placeholder] Text to display when no file is selected.
13942 * @cfg {string} [notsupported] Text to display when file support is missing in the browser.
13943 * @cfg {boolean} [droppable=true] Whether to accept files by drag and drop.
13944 * @cfg {boolean} [showDropTarget=false] Whether to show a drop target. Requires droppable to be true.
13945 * @cfg {boolean} [dragDropUI=false] Deprecated alias for showDropTarget
13947 OO
.ui
.SelectFileWidget
= function OoUiSelectFileWidget( config
) {
13950 // TODO: Remove in next release
13951 if ( config
&& config
.dragDropUI
) {
13952 config
.showDropTarget
= true;
13955 // Configuration initialization
13956 config
= $.extend( {
13958 placeholder
: OO
.ui
.msg( 'ooui-selectfile-placeholder' ),
13959 notsupported
: OO
.ui
.msg( 'ooui-selectfile-not-supported' ),
13961 showDropTarget
: false
13964 // Parent constructor
13965 OO
.ui
.SelectFileWidget
.parent
.call( this, config
);
13967 // Mixin constructors
13968 OO
.ui
.mixin
.IconElement
.call( this, config
);
13969 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
13970 OO
.ui
.mixin
.PendingElement
.call( this, $.extend( {}, config
, { $pending
: this.$info
} ) );
13971 OO
.ui
.mixin
.LabelElement
.call( this, $.extend( {}, config
, { autoFitLabel
: true } ) );
13974 this.$info
= $( '<span>' );
13977 this.showDropTarget
= config
.showDropTarget
;
13978 this.isSupported
= this.constructor.static.isSupported();
13979 this.currentFile
= null;
13980 if ( Array
.isArray( config
.accept
) ) {
13981 this.accept
= config
.accept
;
13983 this.accept
= null;
13985 this.placeholder
= config
.placeholder
;
13986 this.notsupported
= config
.notsupported
;
13987 this.onFileSelectedHandler
= this.onFileSelected
.bind( this );
13989 this.selectButton
= new OO
.ui
.ButtonWidget( {
13990 classes
: [ 'oo-ui-selectFileWidget-selectButton' ],
13991 label
: 'Select a file',
13992 disabled
: this.disabled
|| !this.isSupported
13995 this.clearButton
= new OO
.ui
.ButtonWidget( {
13996 classes
: [ 'oo-ui-selectFileWidget-clearButton' ],
13999 disabled
: this.disabled
14003 this.selectButton
.$button
.on( {
14004 keypress
: this.onKeyPress
.bind( this )
14006 this.clearButton
.connect( this, {
14007 click
: 'onClearClick'
14009 if ( config
.droppable
) {
14010 dragHandler
= this.onDragEnterOrOver
.bind( this );
14011 this.$element
.on( {
14012 dragenter
: dragHandler
,
14013 dragover
: dragHandler
,
14014 dragleave
: this.onDragLeave
.bind( this ),
14015 drop
: this.onDrop
.bind( this )
14022 this.$label
.addClass( 'oo-ui-selectFileWidget-label' );
14024 .addClass( 'oo-ui-selectFileWidget-info' )
14025 .append( this.$icon
, this.$label
, this.clearButton
.$element
, this.$indicator
);
14027 .addClass( 'oo-ui-selectFileWidget' )
14028 .append( this.$info
, this.selectButton
.$element
);
14029 if ( config
.droppable
&& config
.showDropTarget
) {
14030 this.$dropTarget
= $( '<div>' )
14031 .addClass( 'oo-ui-selectFileWidget-dropTarget' )
14032 .text( OO
.ui
.msg( 'ooui-selectfile-dragdrop-placeholder' ) )
14034 click
: this.onDropTargetClick
.bind( this )
14036 this.$element
.prepend( this.$dropTarget
);
14042 OO
.inheritClass( OO
.ui
.SelectFileWidget
, OO
.ui
.Widget
);
14043 OO
.mixinClass( OO
.ui
.SelectFileWidget
, OO
.ui
.mixin
.IconElement
);
14044 OO
.mixinClass( OO
.ui
.SelectFileWidget
, OO
.ui
.mixin
.IndicatorElement
);
14045 OO
.mixinClass( OO
.ui
.SelectFileWidget
, OO
.ui
.mixin
.PendingElement
);
14046 OO
.mixinClass( OO
.ui
.SelectFileWidget
, OO
.ui
.mixin
.LabelElement
);
14048 /* Static Properties */
14051 * Check if this widget is supported
14054 * @return {boolean}
14056 OO
.ui
.SelectFileWidget
.static.isSupported = function () {
14058 if ( OO
.ui
.SelectFileWidget
.static.isSupportedCache
=== null ) {
14059 $input
= $( '<input type="file">' );
14060 OO
.ui
.SelectFileWidget
.static.isSupportedCache
= $input
[ 0 ].files
!== undefined;
14062 return OO
.ui
.SelectFileWidget
.static.isSupportedCache
;
14065 OO
.ui
.SelectFileWidget
.static.isSupportedCache
= null;
14072 * A change event is emitted when the on/off state of the toggle changes.
14074 * @param {File|null} value New value
14080 * Get the current value of the field
14082 * @return {File|null}
14084 OO
.ui
.SelectFileWidget
.prototype.getValue = function () {
14085 return this.currentFile
;
14089 * Set the current value of the field
14091 * @param {File|null} file File to select
14093 OO
.ui
.SelectFileWidget
.prototype.setValue = function ( file
) {
14094 if ( this.currentFile
!== file
) {
14095 this.currentFile
= file
;
14097 this.emit( 'change', this.currentFile
);
14102 * Update the user interface when a file is selected or unselected
14106 OO
.ui
.SelectFileWidget
.prototype.updateUI = function () {
14108 if ( !this.isSupported
) {
14109 this.$element
.addClass( 'oo-ui-selectFileWidget-notsupported' );
14110 this.$element
.removeClass( 'oo-ui-selectFileWidget-empty' );
14111 this.setLabel( this.notsupported
);
14113 this.$element
.addClass( 'oo-ui-selectFileWidget-supported' );
14114 if ( this.currentFile
) {
14115 this.$element
.removeClass( 'oo-ui-selectFileWidget-empty' );
14117 if ( this.currentFile
.type
!== '' ) {
14118 $label
= $label
.add( $( '<span>' ).addClass( 'oo-ui-selectFileWidget-fileType' ).text( this.currentFile
.type
) );
14120 $label
= $label
.add( $( '<span>' ).text( this.currentFile
.name
) );
14121 this.setLabel( $label
);
14123 this.$element
.addClass( 'oo-ui-selectFileWidget-empty' );
14124 this.setLabel( this.placeholder
);
14128 if ( this.$input
) {
14129 this.$input
.attr( 'title', this.getLabel() );
14134 * Add the input to the widget
14138 OO
.ui
.SelectFileWidget
.prototype.addInput = function () {
14139 if ( this.$input
) {
14140 this.$input
.remove();
14143 if ( !this.isSupported
) {
14144 this.$input
= null;
14148 this.$input
= $( '<input type="file">' );
14149 this.$input
.on( 'change', this.onFileSelectedHandler
);
14150 this.$input
.attr( {
14152 title
: this.getLabel()
14154 if ( this.accept
) {
14155 this.$input
.attr( 'accept', this.accept
.join( ', ' ) );
14157 this.selectButton
.$button
.append( this.$input
);
14161 * Determine if we should accept this file
14164 * @param {string} File MIME type
14165 * @return {boolean}
14167 OO
.ui
.SelectFileWidget
.prototype.isAllowedType = function ( mimeType
) {
14170 if ( !this.accept
|| !mimeType
) {
14174 for ( i
= 0; i
< this.accept
.length
; i
++ ) {
14175 mimeTest
= this.accept
[ i
];
14176 if ( mimeTest
=== mimeType
) {
14178 } else if ( mimeTest
.substr( -2 ) === '/*' ) {
14179 mimeTest
= mimeTest
.substr( 0, mimeTest
.length
- 1 );
14180 if ( mimeType
.substr( 0, mimeTest
.length
) === mimeTest
) {
14190 * Handle file selection from the input
14193 * @param {jQuery.Event} e
14195 OO
.ui
.SelectFileWidget
.prototype.onFileSelected = function ( e
) {
14196 var file
= OO
.getProp( e
.target
, 'files', 0 ) || null;
14198 if ( file
&& !this.isAllowedType( file
.type
) ) {
14202 this.setValue( file
);
14207 * Handle clear button click events.
14211 OO
.ui
.SelectFileWidget
.prototype.onClearClick = function () {
14212 this.setValue( null );
14217 * Handle key press events.
14220 * @param {jQuery.Event} e Key press event
14222 OO
.ui
.SelectFileWidget
.prototype.onKeyPress = function ( e
) {
14223 if ( this.isSupported
&& !this.isDisabled() && this.$input
&&
14224 ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
)
14226 this.$input
.click();
14232 * Handle drop target click events.
14235 * @param {jQuery.Event} e Key press event
14237 OO
.ui
.SelectFileWidget
.prototype.onDropTargetClick = function () {
14238 if ( this.isSupported
&& !this.isDisabled() && this.$input
) {
14239 this.$input
.click();
14245 * Handle drag enter and over events
14248 * @param {jQuery.Event} e Drag event
14250 OO
.ui
.SelectFileWidget
.prototype.onDragEnterOrOver = function ( e
) {
14252 droppableFile
= false,
14253 dt
= e
.originalEvent
.dataTransfer
;
14255 e
.preventDefault();
14256 e
.stopPropagation();
14258 if ( this.isDisabled() || !this.isSupported
) {
14259 this.$element
.removeClass( 'oo-ui-selectFileWidget-canDrop' );
14260 dt
.dropEffect
= 'none';
14264 // DataTransferItem and File both have a type property, but in Chrome files
14265 // have no information at this point.
14266 itemOrFile
= OO
.getProp( dt
, 'items', 0 ) || OO
.getProp( dt
, 'files', 0 );
14267 if ( itemOrFile
) {
14268 if ( this.isAllowedType( itemOrFile
.type
) ) {
14269 droppableFile
= true;
14271 // dt.types is Array-like, but not an Array
14272 } else if ( Array
.prototype.indexOf
.call( OO
.getProp( dt
, 'types' ) || [], 'Files' ) !== -1 ) {
14273 // File information is not available at this point for security so just assume
14274 // it is acceptable for now.
14275 // https://bugzilla.mozilla.org/show_bug.cgi?id=640534
14276 droppableFile
= true;
14279 this.$element
.toggleClass( 'oo-ui-selectFileWidget-canDrop', droppableFile
);
14280 if ( !droppableFile
) {
14281 dt
.dropEffect
= 'none';
14288 * Handle drag leave events
14291 * @param {jQuery.Event} e Drag event
14293 OO
.ui
.SelectFileWidget
.prototype.onDragLeave = function () {
14294 this.$element
.removeClass( 'oo-ui-selectFileWidget-canDrop' );
14298 * Handle drop events
14301 * @param {jQuery.Event} e Drop event
14303 OO
.ui
.SelectFileWidget
.prototype.onDrop = function ( e
) {
14305 dt
= e
.originalEvent
.dataTransfer
;
14307 e
.preventDefault();
14308 e
.stopPropagation();
14309 this.$element
.removeClass( 'oo-ui-selectFileWidget-canDrop' );
14311 if ( this.isDisabled() || !this.isSupported
) {
14315 file
= OO
.getProp( dt
, 'files', 0 );
14316 if ( file
&& !this.isAllowedType( file
.type
) ) {
14320 this.setValue( file
);
14329 OO
.ui
.SelectFileWidget
.prototype.setDisabled = function ( disabled
) {
14330 OO
.ui
.SelectFileWidget
.parent
.prototype.setDisabled
.call( this, disabled
);
14331 if ( this.selectButton
) {
14332 this.selectButton
.setDisabled( disabled
);
14334 if ( this.clearButton
) {
14335 this.clearButton
.setDisabled( disabled
);
14341 * IconWidget is a generic widget for {@link OO.ui.mixin.IconElement icons}. In general, IconWidgets should be used with OO.ui.LabelWidget,
14342 * which creates a label that identifies the icon’s function. See the [OOjs UI documentation on MediaWiki] [1]
14343 * for a list of icons included in the library.
14346 * // An icon widget with a label
14347 * var myIcon = new OO.ui.IconWidget( {
14349 * iconTitle: 'Help'
14351 * // Create a label.
14352 * var iconLabel = new OO.ui.LabelWidget( {
14355 * $( 'body' ).append( myIcon.$element, iconLabel.$element );
14357 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Icons
14360 * @extends OO.ui.Widget
14361 * @mixins OO.ui.mixin.IconElement
14362 * @mixins OO.ui.mixin.TitledElement
14363 * @mixins OO.ui.mixin.FlaggedElement
14366 * @param {Object} [config] Configuration options
14368 OO
.ui
.IconWidget
= function OoUiIconWidget( config
) {
14369 // Configuration initialization
14370 config
= config
|| {};
14372 // Parent constructor
14373 OO
.ui
.IconWidget
.parent
.call( this, config
);
14375 // Mixin constructors
14376 OO
.ui
.mixin
.IconElement
.call( this, $.extend( {}, config
, { $icon
: this.$element
} ) );
14377 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$element
} ) );
14378 OO
.ui
.mixin
.FlaggedElement
.call( this, $.extend( {}, config
, { $flagged
: this.$element
} ) );
14381 this.$element
.addClass( 'oo-ui-iconWidget' );
14386 OO
.inheritClass( OO
.ui
.IconWidget
, OO
.ui
.Widget
);
14387 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.mixin
.IconElement
);
14388 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.mixin
.TitledElement
);
14389 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.mixin
.FlaggedElement
);
14391 /* Static Properties */
14393 OO
.ui
.IconWidget
.static.tagName
= 'span';
14396 * IndicatorWidgets create indicators, which are small graphics that are generally used to draw
14397 * attention to the status of an item or to clarify the function of a control. For a list of
14398 * indicators included in the library, please see the [OOjs UI documentation on MediaWiki][1].
14401 * // Example of an indicator widget
14402 * var indicator1 = new OO.ui.IndicatorWidget( {
14403 * indicator: 'alert'
14406 * // Create a fieldset layout to add a label
14407 * var fieldset = new OO.ui.FieldsetLayout();
14408 * fieldset.addItems( [
14409 * new OO.ui.FieldLayout( indicator1, { label: 'An alert indicator:' } )
14411 * $( 'body' ).append( fieldset.$element );
14413 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Icons,_Indicators,_and_Labels#Indicators
14416 * @extends OO.ui.Widget
14417 * @mixins OO.ui.mixin.IndicatorElement
14418 * @mixins OO.ui.mixin.TitledElement
14421 * @param {Object} [config] Configuration options
14423 OO
.ui
.IndicatorWidget
= function OoUiIndicatorWidget( config
) {
14424 // Configuration initialization
14425 config
= config
|| {};
14427 // Parent constructor
14428 OO
.ui
.IndicatorWidget
.parent
.call( this, config
);
14430 // Mixin constructors
14431 OO
.ui
.mixin
.IndicatorElement
.call( this, $.extend( {}, config
, { $indicator
: this.$element
} ) );
14432 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$element
} ) );
14435 this.$element
.addClass( 'oo-ui-indicatorWidget' );
14440 OO
.inheritClass( OO
.ui
.IndicatorWidget
, OO
.ui
.Widget
);
14441 OO
.mixinClass( OO
.ui
.IndicatorWidget
, OO
.ui
.mixin
.IndicatorElement
);
14442 OO
.mixinClass( OO
.ui
.IndicatorWidget
, OO
.ui
.mixin
.TitledElement
);
14444 /* Static Properties */
14446 OO
.ui
.IndicatorWidget
.static.tagName
= 'span';
14449 * InputWidget is the base class for all input widgets, which
14450 * include {@link OO.ui.TextInputWidget text inputs}, {@link OO.ui.CheckboxInputWidget checkbox inputs},
14451 * {@link OO.ui.RadioInputWidget radio inputs}, and {@link OO.ui.ButtonInputWidget button inputs}.
14452 * See the [OOjs UI documentation on MediaWiki] [1] for more information and examples.
14454 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
14458 * @extends OO.ui.Widget
14459 * @mixins OO.ui.mixin.FlaggedElement
14460 * @mixins OO.ui.mixin.TabIndexedElement
14461 * @mixins OO.ui.mixin.TitledElement
14462 * @mixins OO.ui.mixin.AccessKeyedElement
14465 * @param {Object} [config] Configuration options
14466 * @cfg {string} [name=''] The value of the input’s HTML `name` attribute.
14467 * @cfg {string} [value=''] The value of the input.
14468 * @cfg {string} [accessKey=''] The access key of the input.
14469 * @cfg {Function} [inputFilter] The name of an input filter function. Input filters modify the value of an input
14470 * before it is accepted.
14472 OO
.ui
.InputWidget
= function OoUiInputWidget( config
) {
14473 // Configuration initialization
14474 config
= config
|| {};
14476 // Parent constructor
14477 OO
.ui
.InputWidget
.parent
.call( this, config
);
14480 this.$input
= this.getInputElement( config
);
14482 this.inputFilter
= config
.inputFilter
;
14484 // Mixin constructors
14485 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
14486 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$input
} ) );
14487 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$input
} ) );
14488 OO
.ui
.mixin
.AccessKeyedElement
.call( this, $.extend( {}, config
, { $accessKeyed
: this.$input
} ) );
14491 this.$input
.on( 'keydown mouseup cut paste change input select', this.onEdit
.bind( this ) );
14495 .addClass( 'oo-ui-inputWidget-input' )
14496 .attr( 'name', config
.name
)
14497 .prop( 'disabled', this.isDisabled() );
14499 .addClass( 'oo-ui-inputWidget' )
14500 .append( this.$input
);
14501 this.setValue( config
.value
);
14502 this.setAccessKey( config
.accessKey
);
14507 OO
.inheritClass( OO
.ui
.InputWidget
, OO
.ui
.Widget
);
14508 OO
.mixinClass( OO
.ui
.InputWidget
, OO
.ui
.mixin
.FlaggedElement
);
14509 OO
.mixinClass( OO
.ui
.InputWidget
, OO
.ui
.mixin
.TabIndexedElement
);
14510 OO
.mixinClass( OO
.ui
.InputWidget
, OO
.ui
.mixin
.TitledElement
);
14511 OO
.mixinClass( OO
.ui
.InputWidget
, OO
.ui
.mixin
.AccessKeyedElement
);
14513 /* Static Properties */
14515 OO
.ui
.InputWidget
.static.supportsSimpleLabel
= true;
14522 * A change event is emitted when the value of the input changes.
14524 * @param {string} value
14530 * Get input element.
14532 * Subclasses of OO.ui.InputWidget use the `config` parameter to produce different elements in
14533 * different circumstances. The element must have a `value` property (like form elements).
14536 * @param {Object} config Configuration options
14537 * @return {jQuery} Input element
14539 OO
.ui
.InputWidget
.prototype.getInputElement = function () {
14540 return $( '<input>' );
14544 * Handle potentially value-changing events.
14547 * @param {jQuery.Event} e Key down, mouse up, cut, paste, change, input, or select event
14549 OO
.ui
.InputWidget
.prototype.onEdit = function () {
14551 if ( !this.isDisabled() ) {
14552 // Allow the stack to clear so the value will be updated
14553 setTimeout( function () {
14554 widget
.setValue( widget
.$input
.val() );
14560 * Get the value of the input.
14562 * @return {string} Input value
14564 OO
.ui
.InputWidget
.prototype.getValue = function () {
14565 // Resynchronize our internal data with DOM data. Other scripts executing on the page can modify
14566 // it, and we won't know unless they're kind enough to trigger a 'change' event.
14567 var value
= this.$input
.val();
14568 if ( this.value
!== value
) {
14569 this.setValue( value
);
14575 * Set the direction of the input, either RTL (right-to-left) or LTR (left-to-right).
14577 * @param {boolean} isRTL
14578 * Direction is right-to-left
14580 OO
.ui
.InputWidget
.prototype.setRTL = function ( isRTL
) {
14581 this.$input
.prop( 'dir', isRTL
? 'rtl' : 'ltr' );
14585 * Set the value of the input.
14587 * @param {string} value New value
14591 OO
.ui
.InputWidget
.prototype.setValue = function ( value
) {
14592 value
= this.cleanUpValue( value
);
14593 // Update the DOM if it has changed. Note that with cleanUpValue, it
14594 // is possible for the DOM value to change without this.value changing.
14595 if ( this.$input
.val() !== value
) {
14596 this.$input
.val( value
);
14598 if ( this.value
!== value
) {
14599 this.value
= value
;
14600 this.emit( 'change', this.value
);
14606 * Set the input's access key.
14607 * FIXME: This is the same code as in OO.ui.mixin.ButtonElement, maybe find a better place for it?
14609 * @param {string} accessKey Input's access key, use empty string to remove
14612 OO
.ui
.InputWidget
.prototype.setAccessKey = function ( accessKey
) {
14613 accessKey
= typeof accessKey
=== 'string' && accessKey
.length
? accessKey
: null;
14615 if ( this.accessKey
!== accessKey
) {
14616 if ( this.$input
) {
14617 if ( accessKey
!== null ) {
14618 this.$input
.attr( 'accesskey', accessKey
);
14620 this.$input
.removeAttr( 'accesskey' );
14623 this.accessKey
= accessKey
;
14630 * Clean up incoming value.
14632 * Ensures value is a string, and converts undefined and null to empty string.
14635 * @param {string} value Original value
14636 * @return {string} Cleaned up value
14638 OO
.ui
.InputWidget
.prototype.cleanUpValue = function ( value
) {
14639 if ( value
=== undefined || value
=== null ) {
14641 } else if ( this.inputFilter
) {
14642 return this.inputFilter( String( value
) );
14644 return String( value
);
14649 * Simulate the behavior of clicking on a label bound to this input. This method is only called by
14650 * {@link OO.ui.LabelWidget LabelWidget} and {@link OO.ui.FieldLayout FieldLayout}. It should not be
14653 OO
.ui
.InputWidget
.prototype.simulateLabelClick = function () {
14654 if ( !this.isDisabled() ) {
14655 if ( this.$input
.is( ':checkbox, :radio' ) ) {
14656 this.$input
.click();
14658 if ( this.$input
.is( ':input' ) ) {
14659 this.$input
[ 0 ].focus();
14667 OO
.ui
.InputWidget
.prototype.setDisabled = function ( state
) {
14668 OO
.ui
.InputWidget
.parent
.prototype.setDisabled
.call( this, state
);
14669 if ( this.$input
) {
14670 this.$input
.prop( 'disabled', this.isDisabled() );
14680 OO
.ui
.InputWidget
.prototype.focus = function () {
14681 this.$input
[ 0 ].focus();
14690 OO
.ui
.InputWidget
.prototype.blur = function () {
14691 this.$input
[ 0 ].blur();
14698 OO
.ui
.InputWidget
.prototype.gatherPreInfuseState = function ( node
) {
14700 state
= OO
.ui
.InputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
),
14701 $input
= state
.$input
|| $( node
).find( '.oo-ui-inputWidget-input' );
14702 state
.value
= $input
.val();
14703 // Might be better in TabIndexedElement, but it's awkward to do there because mixins are awkward
14704 state
.focus
= $input
.is( ':focus' );
14711 OO
.ui
.InputWidget
.prototype.restorePreInfuseState = function ( state
) {
14712 OO
.ui
.InputWidget
.parent
.prototype.restorePreInfuseState
.call( this, state
);
14713 if ( state
.value
!== undefined && state
.value
!== this.getValue() ) {
14714 this.setValue( state
.value
);
14716 if ( state
.focus
) {
14722 * ButtonInputWidget is used to submit HTML forms and is intended to be used within
14723 * a OO.ui.FormLayout. If you do not need the button to work with HTML forms, you probably
14724 * want to use OO.ui.ButtonWidget instead. Button input widgets can be rendered as either an
14725 * HTML `<button/>` (the default) or an HTML `<input/>` tags. See the
14726 * [OOjs UI documentation on MediaWiki] [1] for more information.
14729 * // A ButtonInputWidget rendered as an HTML button, the default.
14730 * var button = new OO.ui.ButtonInputWidget( {
14731 * label: 'Input button',
14735 * $( 'body' ).append( button.$element );
14737 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs#Button_inputs
14740 * @extends OO.ui.InputWidget
14741 * @mixins OO.ui.mixin.ButtonElement
14742 * @mixins OO.ui.mixin.IconElement
14743 * @mixins OO.ui.mixin.IndicatorElement
14744 * @mixins OO.ui.mixin.LabelElement
14745 * @mixins OO.ui.mixin.TitledElement
14748 * @param {Object} [config] Configuration options
14749 * @cfg {string} [type='button'] The value of the HTML `'type'` attribute: 'button', 'submit' or 'reset'.
14750 * @cfg {boolean} [useInputTag=false] Use an `<input/>` tag instead of a `<button/>` tag, the default.
14751 * Widgets configured to be an `<input/>` do not support {@link #icon icons} and {@link #indicator indicators},
14752 * non-plaintext {@link #label labels}, or {@link #value values}. In general, useInputTag should only
14753 * be set to `true` when there’s need to support IE6 in a form with multiple buttons.
14755 OO
.ui
.ButtonInputWidget
= function OoUiButtonInputWidget( config
) {
14756 // Configuration initialization
14757 config
= $.extend( { type
: 'button', useInputTag
: false }, config
);
14759 // Properties (must be set before parent constructor, which calls #setValue)
14760 this.useInputTag
= config
.useInputTag
;
14762 // Parent constructor
14763 OO
.ui
.ButtonInputWidget
.parent
.call( this, config
);
14765 // Mixin constructors
14766 OO
.ui
.mixin
.ButtonElement
.call( this, $.extend( {}, config
, { $button
: this.$input
} ) );
14767 OO
.ui
.mixin
.IconElement
.call( this, config
);
14768 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
14769 OO
.ui
.mixin
.LabelElement
.call( this, config
);
14770 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$input
} ) );
14773 if ( !config
.useInputTag
) {
14774 this.$input
.append( this.$icon
, this.$label
, this.$indicator
);
14776 this.$element
.addClass( 'oo-ui-buttonInputWidget' );
14781 OO
.inheritClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.InputWidget
);
14782 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.ButtonElement
);
14783 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.IconElement
);
14784 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.IndicatorElement
);
14785 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.LabelElement
);
14786 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.mixin
.TitledElement
);
14788 /* Static Properties */
14791 * Disable generating `<label>` elements for buttons. One would very rarely need additional label
14792 * for a button, and it's already a big clickable target, and it causes unexpected rendering.
14794 OO
.ui
.ButtonInputWidget
.static.supportsSimpleLabel
= false;
14802 OO
.ui
.ButtonInputWidget
.prototype.getInputElement = function ( config
) {
14803 var type
= [ 'button', 'submit', 'reset' ].indexOf( config
.type
) !== -1 ?
14806 return $( '<' + ( config
.useInputTag
? 'input' : 'button' ) + ' type="' + type
+ '">' );
14812 * If #useInputTag is `true`, the label is set as the `value` of the `<input/>` tag.
14814 * @param {jQuery|string|Function|null} label Label nodes, text, a function that returns nodes or
14815 * text, or `null` for no label
14818 OO
.ui
.ButtonInputWidget
.prototype.setLabel = function ( label
) {
14819 OO
.ui
.mixin
.LabelElement
.prototype.setLabel
.call( this, label
);
14821 if ( this.useInputTag
) {
14822 if ( typeof label
=== 'function' ) {
14823 label
= OO
.ui
.resolveMsg( label
);
14825 if ( label
instanceof jQuery
) {
14826 label
= label
.text();
14831 this.$input
.val( label
);
14838 * Set the value of the input.
14840 * This method is disabled for button inputs configured as {@link #useInputTag <input/> tags}, as
14841 * they do not support {@link #value values}.
14843 * @param {string} value New value
14846 OO
.ui
.ButtonInputWidget
.prototype.setValue = function ( value
) {
14847 if ( !this.useInputTag
) {
14848 OO
.ui
.ButtonInputWidget
.parent
.prototype.setValue
.call( this, value
);
14854 * CheckboxInputWidgets, like HTML checkboxes, can be selected and/or configured with a value.
14855 * Note that these {@link OO.ui.InputWidget input widgets} are best laid out
14856 * in {@link OO.ui.FieldLayout field layouts} that use the {@link OO.ui.FieldLayout#align inline}
14857 * alignment. For more information, please see the [OOjs UI documentation on MediaWiki][1].
14859 * This widget can be used inside a HTML form, such as a OO.ui.FormLayout.
14862 * // An example of selected, unselected, and disabled checkbox inputs
14863 * var checkbox1=new OO.ui.CheckboxInputWidget( {
14867 * var checkbox2=new OO.ui.CheckboxInputWidget( {
14870 * var checkbox3=new OO.ui.CheckboxInputWidget( {
14874 * // Create a fieldset layout with fields for each checkbox.
14875 * var fieldset = new OO.ui.FieldsetLayout( {
14876 * label: 'Checkboxes'
14878 * fieldset.addItems( [
14879 * new OO.ui.FieldLayout( checkbox1, { label: 'Selected checkbox', align: 'inline' } ),
14880 * new OO.ui.FieldLayout( checkbox2, { label: 'Unselected checkbox', align: 'inline' } ),
14881 * new OO.ui.FieldLayout( checkbox3, { label: 'Disabled checkbox', align: 'inline' } ),
14883 * $( 'body' ).append( fieldset.$element );
14885 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
14888 * @extends OO.ui.InputWidget
14891 * @param {Object} [config] Configuration options
14892 * @cfg {boolean} [selected=false] Select the checkbox initially. By default, the checkbox is not selected.
14894 OO
.ui
.CheckboxInputWidget
= function OoUiCheckboxInputWidget( config
) {
14895 // Configuration initialization
14896 config
= config
|| {};
14898 // Parent constructor
14899 OO
.ui
.CheckboxInputWidget
.parent
.call( this, config
);
14903 .addClass( 'oo-ui-checkboxInputWidget' )
14904 // Required for pretty styling in MediaWiki theme
14905 .append( $( '<span>' ) );
14906 this.setSelected( config
.selected
!== undefined ? config
.selected
: false );
14911 OO
.inheritClass( OO
.ui
.CheckboxInputWidget
, OO
.ui
.InputWidget
);
14919 OO
.ui
.CheckboxInputWidget
.prototype.getInputElement = function () {
14920 return $( '<input type="checkbox" />' );
14926 OO
.ui
.CheckboxInputWidget
.prototype.onEdit = function () {
14928 if ( !this.isDisabled() ) {
14929 // Allow the stack to clear so the value will be updated
14930 setTimeout( function () {
14931 widget
.setSelected( widget
.$input
.prop( 'checked' ) );
14937 * Set selection state of this checkbox.
14939 * @param {boolean} state `true` for selected
14942 OO
.ui
.CheckboxInputWidget
.prototype.setSelected = function ( state
) {
14944 if ( this.selected
!== state
) {
14945 this.selected
= state
;
14946 this.$input
.prop( 'checked', this.selected
);
14947 this.emit( 'change', this.selected
);
14953 * Check if this checkbox is selected.
14955 * @return {boolean} Checkbox is selected
14957 OO
.ui
.CheckboxInputWidget
.prototype.isSelected = function () {
14958 // Resynchronize our internal data with DOM data. Other scripts executing on the page can modify
14959 // it, and we won't know unless they're kind enough to trigger a 'change' event.
14960 var selected
= this.$input
.prop( 'checked' );
14961 if ( this.selected
!== selected
) {
14962 this.setSelected( selected
);
14964 return this.selected
;
14970 OO
.ui
.CheckboxInputWidget
.prototype.gatherPreInfuseState = function ( node
) {
14972 state
= OO
.ui
.CheckboxInputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
),
14973 $input
= $( node
).find( '.oo-ui-inputWidget-input' );
14974 state
.$input
= $input
; // shortcut for performance, used in InputWidget
14975 state
.checked
= $input
.prop( 'checked' );
14982 OO
.ui
.CheckboxInputWidget
.prototype.restorePreInfuseState = function ( state
) {
14983 OO
.ui
.CheckboxInputWidget
.parent
.prototype.restorePreInfuseState
.call( this, state
);
14984 if ( state
.checked
!== undefined && state
.checked
!== this.isSelected() ) {
14985 this.setSelected( state
.checked
);
14990 * DropdownInputWidget is a {@link OO.ui.DropdownWidget DropdownWidget} intended to be used
14991 * within a HTML form, such as a OO.ui.FormLayout. The selected value is synchronized with the value
14992 * of a hidden HTML `input` tag. Please see the [OOjs UI documentation on MediaWiki][1] for
14993 * more information about input widgets.
14995 * A DropdownInputWidget always has a value (one of the options is always selected), unless there
14996 * are no options. If no `value` configuration option is provided, the first option is selected.
14997 * If you need a state representing no value (no option being selected), use a DropdownWidget.
14999 * This and OO.ui.RadioSelectInputWidget support the same configuration options.
15002 * // Example: A DropdownInputWidget with three options
15003 * var dropdownInput = new OO.ui.DropdownInputWidget( {
15005 * { data: 'a', label: 'First' },
15006 * { data: 'b', label: 'Second'},
15007 * { data: 'c', label: 'Third' }
15010 * $( 'body' ).append( dropdownInput.$element );
15012 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
15015 * @extends OO.ui.InputWidget
15016 * @mixins OO.ui.mixin.TitledElement
15019 * @param {Object} [config] Configuration options
15020 * @cfg {Object[]} [options=[]] Array of menu options in the format `{ data: …, label: … }`
15021 * @cfg {Object} [dropdown] Configuration options for {@link OO.ui.DropdownWidget DropdownWidget}
15023 OO
.ui
.DropdownInputWidget
= function OoUiDropdownInputWidget( config
) {
15024 // Configuration initialization
15025 config
= config
|| {};
15027 // Properties (must be done before parent constructor which calls #setDisabled)
15028 this.dropdownWidget
= new OO
.ui
.DropdownWidget( config
.dropdown
);
15030 // Parent constructor
15031 OO
.ui
.DropdownInputWidget
.parent
.call( this, config
);
15033 // Mixin constructors
15034 OO
.ui
.mixin
.TitledElement
.call( this, config
);
15037 this.dropdownWidget
.getMenu().connect( this, { select
: 'onMenuSelect' } );
15040 this.setOptions( config
.options
|| [] );
15042 .addClass( 'oo-ui-dropdownInputWidget' )
15043 .append( this.dropdownWidget
.$element
);
15048 OO
.inheritClass( OO
.ui
.DropdownInputWidget
, OO
.ui
.InputWidget
);
15049 OO
.mixinClass( OO
.ui
.DropdownInputWidget
, OO
.ui
.mixin
.TitledElement
);
15057 OO
.ui
.DropdownInputWidget
.prototype.getInputElement = function () {
15058 return $( '<input type="hidden">' );
15062 * Handles menu select events.
15065 * @param {OO.ui.MenuOptionWidget} item Selected menu item
15067 OO
.ui
.DropdownInputWidget
.prototype.onMenuSelect = function ( item
) {
15068 this.setValue( item
.getData() );
15074 OO
.ui
.DropdownInputWidget
.prototype.setValue = function ( value
) {
15075 value
= this.cleanUpValue( value
);
15076 this.dropdownWidget
.getMenu().selectItemByData( value
);
15077 OO
.ui
.DropdownInputWidget
.parent
.prototype.setValue
.call( this, value
);
15084 OO
.ui
.DropdownInputWidget
.prototype.setDisabled = function ( state
) {
15085 this.dropdownWidget
.setDisabled( state
);
15086 OO
.ui
.DropdownInputWidget
.parent
.prototype.setDisabled
.call( this, state
);
15091 * Set the options available for this input.
15093 * @param {Object[]} options Array of menu options in the format `{ data: …, label: … }`
15096 OO
.ui
.DropdownInputWidget
.prototype.setOptions = function ( options
) {
15098 value
= this.getValue(),
15101 // Rebuild the dropdown menu
15102 this.dropdownWidget
.getMenu()
15104 .addItems( options
.map( function ( opt
) {
15105 var optValue
= widget
.cleanUpValue( opt
.data
);
15106 return new OO
.ui
.MenuOptionWidget( {
15108 label
: opt
.label
!== undefined ? opt
.label
: optValue
15112 // Restore the previous value, or reset to something sensible
15113 if ( this.dropdownWidget
.getMenu().getItemFromData( value
) ) {
15114 // Previous value is still available, ensure consistency with the dropdown
15115 this.setValue( value
);
15117 // No longer valid, reset
15118 if ( options
.length
) {
15119 this.setValue( options
[ 0 ].data
);
15129 OO
.ui
.DropdownInputWidget
.prototype.focus = function () {
15130 this.dropdownWidget
.getMenu().toggle( true );
15137 OO
.ui
.DropdownInputWidget
.prototype.blur = function () {
15138 this.dropdownWidget
.getMenu().toggle( false );
15143 * RadioInputWidget creates a single radio button. Because radio buttons are usually used as a set,
15144 * in most cases you will want to use a {@link OO.ui.RadioSelectWidget radio select}
15145 * with {@link OO.ui.RadioOptionWidget radio options} instead of this class. For more information,
15146 * please see the [OOjs UI documentation on MediaWiki][1].
15148 * This widget can be used inside a HTML form, such as a OO.ui.FormLayout.
15151 * // An example of selected, unselected, and disabled radio inputs
15152 * var radio1 = new OO.ui.RadioInputWidget( {
15156 * var radio2 = new OO.ui.RadioInputWidget( {
15159 * var radio3 = new OO.ui.RadioInputWidget( {
15163 * // Create a fieldset layout with fields for each radio button.
15164 * var fieldset = new OO.ui.FieldsetLayout( {
15165 * label: 'Radio inputs'
15167 * fieldset.addItems( [
15168 * new OO.ui.FieldLayout( radio1, { label: 'Selected', align: 'inline' } ),
15169 * new OO.ui.FieldLayout( radio2, { label: 'Unselected', align: 'inline' } ),
15170 * new OO.ui.FieldLayout( radio3, { label: 'Disabled', align: 'inline' } ),
15172 * $( 'body' ).append( fieldset.$element );
15174 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
15177 * @extends OO.ui.InputWidget
15180 * @param {Object} [config] Configuration options
15181 * @cfg {boolean} [selected=false] Select the radio button initially. By default, the radio button is not selected.
15183 OO
.ui
.RadioInputWidget
= function OoUiRadioInputWidget( config
) {
15184 // Configuration initialization
15185 config
= config
|| {};
15187 // Parent constructor
15188 OO
.ui
.RadioInputWidget
.parent
.call( this, config
);
15192 .addClass( 'oo-ui-radioInputWidget' )
15193 // Required for pretty styling in MediaWiki theme
15194 .append( $( '<span>' ) );
15195 this.setSelected( config
.selected
!== undefined ? config
.selected
: false );
15200 OO
.inheritClass( OO
.ui
.RadioInputWidget
, OO
.ui
.InputWidget
);
15208 OO
.ui
.RadioInputWidget
.prototype.getInputElement = function () {
15209 return $( '<input type="radio" />' );
15215 OO
.ui
.RadioInputWidget
.prototype.onEdit = function () {
15216 // RadioInputWidget doesn't track its state.
15220 * Set selection state of this radio button.
15222 * @param {boolean} state `true` for selected
15225 OO
.ui
.RadioInputWidget
.prototype.setSelected = function ( state
) {
15226 // RadioInputWidget doesn't track its state.
15227 this.$input
.prop( 'checked', state
);
15232 * Check if this radio button is selected.
15234 * @return {boolean} Radio is selected
15236 OO
.ui
.RadioInputWidget
.prototype.isSelected = function () {
15237 return this.$input
.prop( 'checked' );
15243 OO
.ui
.RadioInputWidget
.prototype.gatherPreInfuseState = function ( node
) {
15245 state
= OO
.ui
.RadioInputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
),
15246 $input
= $( node
).find( '.oo-ui-inputWidget-input' );
15247 state
.$input
= $input
; // shortcut for performance, used in InputWidget
15248 state
.checked
= $input
.prop( 'checked' );
15255 OO
.ui
.RadioInputWidget
.prototype.restorePreInfuseState = function ( state
) {
15256 OO
.ui
.RadioInputWidget
.parent
.prototype.restorePreInfuseState
.call( this, state
);
15257 if ( state
.checked
!== undefined && state
.checked
!== this.isSelected() ) {
15258 this.setSelected( state
.checked
);
15263 * RadioSelectInputWidget is a {@link OO.ui.RadioSelectWidget RadioSelectWidget} intended to be used
15264 * within a HTML form, such as a OO.ui.FormLayout. The selected value is synchronized with the value
15265 * of a hidden HTML `input` tag. Please see the [OOjs UI documentation on MediaWiki][1] for
15266 * more information about input widgets.
15268 * This and OO.ui.DropdownInputWidget support the same configuration options.
15271 * // Example: A RadioSelectInputWidget with three options
15272 * var radioSelectInput = new OO.ui.RadioSelectInputWidget( {
15274 * { data: 'a', label: 'First' },
15275 * { data: 'b', label: 'Second'},
15276 * { data: 'c', label: 'Third' }
15279 * $( 'body' ).append( radioSelectInput.$element );
15281 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
15284 * @extends OO.ui.InputWidget
15287 * @param {Object} [config] Configuration options
15288 * @cfg {Object[]} [options=[]] Array of menu options in the format `{ data: …, label: … }`
15290 OO
.ui
.RadioSelectInputWidget
= function OoUiRadioSelectInputWidget( config
) {
15291 // Configuration initialization
15292 config
= config
|| {};
15294 // Properties (must be done before parent constructor which calls #setDisabled)
15295 this.radioSelectWidget
= new OO
.ui
.RadioSelectWidget();
15297 // Parent constructor
15298 OO
.ui
.RadioSelectInputWidget
.parent
.call( this, config
);
15301 this.radioSelectWidget
.connect( this, { select
: 'onMenuSelect' } );
15304 this.setOptions( config
.options
|| [] );
15306 .addClass( 'oo-ui-radioSelectInputWidget' )
15307 .append( this.radioSelectWidget
.$element
);
15312 OO
.inheritClass( OO
.ui
.RadioSelectInputWidget
, OO
.ui
.InputWidget
);
15314 /* Static Properties */
15316 OO
.ui
.RadioSelectInputWidget
.static.supportsSimpleLabel
= false;
15324 OO
.ui
.RadioSelectInputWidget
.prototype.getInputElement = function () {
15325 return $( '<input type="hidden">' );
15329 * Handles menu select events.
15332 * @param {OO.ui.RadioOptionWidget} item Selected menu item
15334 OO
.ui
.RadioSelectInputWidget
.prototype.onMenuSelect = function ( item
) {
15335 this.setValue( item
.getData() );
15341 OO
.ui
.RadioSelectInputWidget
.prototype.setValue = function ( value
) {
15342 value
= this.cleanUpValue( value
);
15343 this.radioSelectWidget
.selectItemByData( value
);
15344 OO
.ui
.RadioSelectInputWidget
.parent
.prototype.setValue
.call( this, value
);
15351 OO
.ui
.RadioSelectInputWidget
.prototype.setDisabled = function ( state
) {
15352 this.radioSelectWidget
.setDisabled( state
);
15353 OO
.ui
.RadioSelectInputWidget
.parent
.prototype.setDisabled
.call( this, state
);
15358 * Set the options available for this input.
15360 * @param {Object[]} options Array of menu options in the format `{ data: …, label: … }`
15363 OO
.ui
.RadioSelectInputWidget
.prototype.setOptions = function ( options
) {
15365 value
= this.getValue(),
15368 // Rebuild the radioSelect menu
15369 this.radioSelectWidget
15371 .addItems( options
.map( function ( opt
) {
15372 var optValue
= widget
.cleanUpValue( opt
.data
);
15373 return new OO
.ui
.RadioOptionWidget( {
15375 label
: opt
.label
!== undefined ? opt
.label
: optValue
15379 // Restore the previous value, or reset to something sensible
15380 if ( this.radioSelectWidget
.getItemFromData( value
) ) {
15381 // Previous value is still available, ensure consistency with the radioSelect
15382 this.setValue( value
);
15384 // No longer valid, reset
15385 if ( options
.length
) {
15386 this.setValue( options
[ 0 ].data
);
15396 OO
.ui
.RadioSelectInputWidget
.prototype.gatherPreInfuseState = function ( node
) {
15397 var state
= OO
.ui
.RadioSelectInputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
);
15398 state
.value
= $( node
).find( '.oo-ui-radioInputWidget .oo-ui-inputWidget-input:checked' ).val();
15403 * TextInputWidgets, like HTML text inputs, can be configured with options that customize the
15404 * size of the field as well as its presentation. In addition, these widgets can be configured
15405 * with {@link OO.ui.mixin.IconElement icons}, {@link OO.ui.mixin.IndicatorElement indicators}, an optional
15406 * validation-pattern (used to determine if an input value is valid or not) and an input filter,
15407 * which modifies incoming values rather than validating them.
15408 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information and examples.
15410 * This widget can be used inside a HTML form, such as a OO.ui.FormLayout.
15413 * // Example of a text input widget
15414 * var textInput = new OO.ui.TextInputWidget( {
15415 * value: 'Text input'
15417 * $( 'body' ).append( textInput.$element );
15419 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
15422 * @extends OO.ui.InputWidget
15423 * @mixins OO.ui.mixin.IconElement
15424 * @mixins OO.ui.mixin.IndicatorElement
15425 * @mixins OO.ui.mixin.PendingElement
15426 * @mixins OO.ui.mixin.LabelElement
15429 * @param {Object} [config] Configuration options
15430 * @cfg {string} [type='text'] The value of the HTML `type` attribute: 'text', 'password', 'search',
15431 * 'email' or 'url'. Ignored if `multiline` is true.
15433 * Some values of `type` result in additional behaviors:
15435 * - `search`: implies `icon: 'search'` and `indicator: 'clear'`; when clicked, the indicator
15436 * empties the text field
15437 * @cfg {string} [placeholder] Placeholder text
15438 * @cfg {boolean} [autofocus=false] Use an HTML `autofocus` attribute to
15439 * instruct the browser to focus this widget.
15440 * @cfg {boolean} [readOnly=false] Prevent changes to the value of the text input.
15441 * @cfg {number} [maxLength] Maximum number of characters allowed in the input.
15442 * @cfg {boolean} [multiline=false] Allow multiple lines of text
15443 * @cfg {number} [rows] If multiline, number of visible lines in textarea. If used with `autosize`,
15444 * specifies minimum number of rows to display.
15445 * @cfg {boolean} [autosize=false] Automatically resize the text input to fit its content.
15446 * Use the #maxRows config to specify a maximum number of displayed rows.
15447 * @cfg {boolean} [maxRows] Maximum number of rows to display when #autosize is set to true.
15448 * Defaults to the maximum of `10` and `2 * rows`, or `10` if `rows` isn't provided.
15449 * @cfg {string} [labelPosition='after'] The position of the inline label relative to that of
15450 * the value or placeholder text: `'before'` or `'after'`
15451 * @cfg {boolean} [required=false] Mark the field as required. Implies `indicator: 'required'`.
15452 * @cfg {boolean} [autocomplete=true] Should the browser support autocomplete for this field
15453 * @cfg {RegExp|Function|string} [validate] Validation pattern: when string, a symbolic name of a
15454 * pattern defined by the class: 'non-empty' (the value cannot be an empty string) or 'integer'
15455 * (the value must contain only numbers); when RegExp, a regular expression that must match the
15456 * value for it to be considered valid; when Function, a function receiving the value as parameter
15457 * that must return true, or promise resolving to true, for it to be considered valid.
15459 OO
.ui
.TextInputWidget
= function OoUiTextInputWidget( config
) {
15460 // Configuration initialization
15461 config
= $.extend( {
15463 labelPosition
: 'after'
15465 if ( config
.type
=== 'search' ) {
15466 if ( config
.icon
=== undefined ) {
15467 config
.icon
= 'search';
15469 // indicator: 'clear' is set dynamically later, depending on value
15471 if ( config
.required
) {
15472 if ( config
.indicator
=== undefined ) {
15473 config
.indicator
= 'required';
15477 // Parent constructor
15478 OO
.ui
.TextInputWidget
.parent
.call( this, config
);
15480 // Mixin constructors
15481 OO
.ui
.mixin
.IconElement
.call( this, config
);
15482 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
15483 OO
.ui
.mixin
.PendingElement
.call( this, $.extend( {}, config
, { $pending
: this.$input
} ) );
15484 OO
.ui
.mixin
.LabelElement
.call( this, config
);
15487 this.type
= this.getSaneType( config
);
15488 this.readOnly
= false;
15489 this.multiline
= !!config
.multiline
;
15490 this.autosize
= !!config
.autosize
;
15491 this.minRows
= config
.rows
!== undefined ? config
.rows
: '';
15492 this.maxRows
= config
.maxRows
|| Math
.max( 2 * ( this.minRows
|| 0 ), 10 );
15493 this.validate
= null;
15495 // Clone for resizing
15496 if ( this.autosize
) {
15497 this.$clone
= this.$input
15499 .insertAfter( this.$input
)
15500 .attr( 'aria-hidden', 'true' )
15501 .addClass( 'oo-ui-element-hidden' );
15504 this.setValidation( config
.validate
);
15505 this.setLabelPosition( config
.labelPosition
);
15509 keypress
: this.onKeyPress
.bind( this ),
15510 blur
: this.onBlur
.bind( this )
15513 focus
: this.onElementAttach
.bind( this )
15515 this.$icon
.on( 'mousedown', this.onIconMouseDown
.bind( this ) );
15516 this.$indicator
.on( 'mousedown', this.onIndicatorMouseDown
.bind( this ) );
15517 this.on( 'labelChange', this.updatePosition
.bind( this ) );
15518 this.connect( this, {
15519 change
: 'onChange',
15520 disable
: 'onDisable'
15525 .addClass( 'oo-ui-textInputWidget oo-ui-textInputWidget-type-' + this.type
)
15526 .append( this.$icon
, this.$indicator
);
15527 this.setReadOnly( !!config
.readOnly
);
15528 this.updateSearchIndicator();
15529 if ( config
.placeholder
) {
15530 this.$input
.attr( 'placeholder', config
.placeholder
);
15532 if ( config
.maxLength
!== undefined ) {
15533 this.$input
.attr( 'maxlength', config
.maxLength
);
15535 if ( config
.autofocus
) {
15536 this.$input
.attr( 'autofocus', 'autofocus' );
15538 if ( config
.required
) {
15539 this.$input
.attr( 'required', 'required' );
15540 this.$input
.attr( 'aria-required', 'true' );
15542 if ( config
.autocomplete
=== false ) {
15543 this.$input
.attr( 'autocomplete', 'off' );
15544 // Turning off autocompletion also disables "form caching" when the user navigates to a
15545 // different page and then clicks "Back". Re-enable it when leaving. Borrowed from jQuery UI.
15547 beforeunload: function () {
15548 this.$input
.removeAttr( 'autocomplete' );
15550 pageshow: function () {
15551 // Browsers don't seem to actually fire this event on "Back", they instead just reload the
15552 // whole page... it shouldn't hurt, though.
15553 this.$input
.attr( 'autocomplete', 'off' );
15557 if ( this.multiline
&& config
.rows
) {
15558 this.$input
.attr( 'rows', config
.rows
);
15560 if ( this.label
|| config
.autosize
) {
15561 this.installParentChangeDetector();
15567 OO
.inheritClass( OO
.ui
.TextInputWidget
, OO
.ui
.InputWidget
);
15568 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.mixin
.IconElement
);
15569 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.mixin
.IndicatorElement
);
15570 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.mixin
.PendingElement
);
15571 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.mixin
.LabelElement
);
15573 /* Static Properties */
15575 OO
.ui
.TextInputWidget
.static.validationPatterns
= {
15583 * An `enter` event is emitted when the user presses 'enter' inside the text box.
15585 * Not emitted if the input is multiline.
15593 * Handle icon mouse down events.
15596 * @param {jQuery.Event} e Mouse down event
15599 OO
.ui
.TextInputWidget
.prototype.onIconMouseDown = function ( e
) {
15600 if ( e
.which
=== 1 ) {
15601 this.$input
[ 0 ].focus();
15607 * Handle indicator mouse down events.
15610 * @param {jQuery.Event} e Mouse down event
15613 OO
.ui
.TextInputWidget
.prototype.onIndicatorMouseDown = function ( e
) {
15614 if ( e
.which
=== 1 ) {
15615 if ( this.type
=== 'search' ) {
15616 // Clear the text field
15617 this.setValue( '' );
15619 this.$input
[ 0 ].focus();
15625 * Handle key press events.
15628 * @param {jQuery.Event} e Key press event
15629 * @fires enter If enter key is pressed and input is not multiline
15631 OO
.ui
.TextInputWidget
.prototype.onKeyPress = function ( e
) {
15632 if ( e
.which
=== OO
.ui
.Keys
.ENTER
&& !this.multiline
) {
15633 this.emit( 'enter', e
);
15638 * Handle blur events.
15641 * @param {jQuery.Event} e Blur event
15643 OO
.ui
.TextInputWidget
.prototype.onBlur = function () {
15644 this.setValidityFlag();
15648 * Handle element attach events.
15651 * @param {jQuery.Event} e Element attach event
15653 OO
.ui
.TextInputWidget
.prototype.onElementAttach = function () {
15654 // Any previously calculated size is now probably invalid if we reattached elsewhere
15655 this.valCache
= null;
15657 this.positionLabel();
15661 * Handle change events.
15663 * @param {string} value
15666 OO
.ui
.TextInputWidget
.prototype.onChange = function () {
15667 this.updateSearchIndicator();
15668 this.setValidityFlag();
15673 * Handle disable events.
15675 * @param {boolean} disabled Element is disabled
15678 OO
.ui
.TextInputWidget
.prototype.onDisable = function () {
15679 this.updateSearchIndicator();
15683 * Check if the input is {@link #readOnly read-only}.
15685 * @return {boolean}
15687 OO
.ui
.TextInputWidget
.prototype.isReadOnly = function () {
15688 return this.readOnly
;
15692 * Set the {@link #readOnly read-only} state of the input.
15694 * @param {boolean} state Make input read-only
15697 OO
.ui
.TextInputWidget
.prototype.setReadOnly = function ( state
) {
15698 this.readOnly
= !!state
;
15699 this.$input
.prop( 'readOnly', this.readOnly
);
15700 this.updateSearchIndicator();
15705 * Support function for making #onElementAttach work across browsers.
15707 * This whole function could be replaced with one line of code using the DOMNodeInsertedIntoDocument
15708 * event, but it's not supported by Firefox and allegedly deprecated, so we only use it as fallback.
15710 * Due to MutationObserver performance woes, #onElementAttach is only somewhat reliably called the
15711 * first time that the element gets attached to the documented.
15713 OO
.ui
.TextInputWidget
.prototype.installParentChangeDetector = function () {
15714 var mutationObserver
, onRemove
, topmostNode
, fakeParentNode
,
15715 MutationObserver
= window
.MutationObserver
|| window
.WebKitMutationObserver
|| window
.MozMutationObserver
,
15718 if ( MutationObserver
) {
15719 // The new way. If only it wasn't so ugly.
15721 if ( this.$element
.closest( 'html' ).length
) {
15722 // Widget is attached already, do nothing. This breaks the functionality of this function when
15723 // the widget is detached and reattached. Alas, doing this correctly with MutationObserver
15724 // would require observation of the whole document, which would hurt performance of other,
15725 // more important code.
15729 // Find topmost node in the tree
15730 topmostNode
= this.$element
[ 0 ];
15731 while ( topmostNode
.parentNode
) {
15732 topmostNode
= topmostNode
.parentNode
;
15735 // We have no way to detect the $element being attached somewhere without observing the entire
15736 // DOM with subtree modifications, which would hurt performance. So we cheat: we hook to the
15737 // parent node of $element, and instead detect when $element is removed from it (and thus
15738 // probably attached somewhere else). If there is no parent, we create a "fake" one. If it
15739 // doesn't get attached, we end up back here and create the parent.
15741 mutationObserver
= new MutationObserver( function ( mutations
) {
15742 var i
, j
, removedNodes
;
15743 for ( i
= 0; i
< mutations
.length
; i
++ ) {
15744 removedNodes
= mutations
[ i
].removedNodes
;
15745 for ( j
= 0; j
< removedNodes
.length
; j
++ ) {
15746 if ( removedNodes
[ j
] === topmostNode
) {
15747 setTimeout( onRemove
, 0 );
15754 onRemove = function () {
15755 // If the node was attached somewhere else, report it
15756 if ( widget
.$element
.closest( 'html' ).length
) {
15757 widget
.onElementAttach();
15759 mutationObserver
.disconnect();
15760 widget
.installParentChangeDetector();
15763 // Create a fake parent and observe it
15764 fakeParentNode
= $( '<div>' ).append( topmostNode
)[ 0 ];
15765 mutationObserver
.observe( fakeParentNode
, { childList
: true } );
15767 // Using the DOMNodeInsertedIntoDocument event is much nicer and less magical, and works for
15768 // detachment and reattachment, but it's not supported by Firefox and allegedly deprecated.
15769 this.$element
.on( 'DOMNodeInsertedIntoDocument', this.onElementAttach
.bind( this ) );
15774 * Automatically adjust the size of the text input.
15776 * This only affects #multiline inputs that are {@link #autosize autosized}.
15780 OO
.ui
.TextInputWidget
.prototype.adjustSize = function () {
15781 var scrollHeight
, innerHeight
, outerHeight
, maxInnerHeight
, measurementError
, idealHeight
;
15783 if ( this.multiline
&& this.autosize
&& this.$input
.val() !== this.valCache
) {
15785 .val( this.$input
.val() )
15786 .attr( 'rows', this.minRows
)
15787 // Set inline height property to 0 to measure scroll height
15788 .css( 'height', 0 );
15790 this.$clone
.removeClass( 'oo-ui-element-hidden' );
15792 this.valCache
= this.$input
.val();
15794 scrollHeight
= this.$clone
[ 0 ].scrollHeight
;
15796 // Remove inline height property to measure natural heights
15797 this.$clone
.css( 'height', '' );
15798 innerHeight
= this.$clone
.innerHeight();
15799 outerHeight
= this.$clone
.outerHeight();
15801 // Measure max rows height
15803 .attr( 'rows', this.maxRows
)
15804 .css( 'height', 'auto' )
15806 maxInnerHeight
= this.$clone
.innerHeight();
15808 // Difference between reported innerHeight and scrollHeight with no scrollbars present
15809 // Equals 1 on Blink-based browsers and 0 everywhere else
15810 measurementError
= maxInnerHeight
- this.$clone
[ 0 ].scrollHeight
;
15811 idealHeight
= Math
.min( maxInnerHeight
, scrollHeight
+ measurementError
);
15813 this.$clone
.addClass( 'oo-ui-element-hidden' );
15815 // Only apply inline height when expansion beyond natural height is needed
15816 if ( idealHeight
> innerHeight
) {
15817 // Use the difference between the inner and outer height as a buffer
15818 this.$input
.css( 'height', idealHeight
+ ( outerHeight
- innerHeight
) );
15820 this.$input
.css( 'height', '' );
15830 OO
.ui
.TextInputWidget
.prototype.getInputElement = function ( config
) {
15831 return config
.multiline
?
15832 $( '<textarea>' ) :
15833 $( '<input type="' + this.getSaneType( config
) + '" />' );
15837 * Get sanitized value for 'type' for given config.
15839 * @param {Object} config Configuration options
15840 * @return {string|null}
15843 OO
.ui
.TextInputWidget
.prototype.getSaneType = function ( config
) {
15844 var type
= [ 'text', 'password', 'search', 'email', 'url' ].indexOf( config
.type
) !== -1 ?
15847 return config
.multiline
? 'multiline' : type
;
15851 * Check if the input supports multiple lines.
15853 * @return {boolean}
15855 OO
.ui
.TextInputWidget
.prototype.isMultiline = function () {
15856 return !!this.multiline
;
15860 * Check if the input automatically adjusts its size.
15862 * @return {boolean}
15864 OO
.ui
.TextInputWidget
.prototype.isAutosizing = function () {
15865 return !!this.autosize
;
15869 * Select the entire text of the input.
15873 OO
.ui
.TextInputWidget
.prototype.select = function () {
15874 this.$input
.select();
15879 * Focus the input and move the cursor to the end.
15881 OO
.ui
.TextInputWidget
.prototype.moveCursorToEnd = function () {
15883 element
= this.$input
[ 0 ];
15885 if ( element
.selectionStart
!== undefined ) {
15886 element
.selectionStart
= element
.selectionEnd
= element
.value
.length
;
15887 } else if ( element
.createTextRange
) {
15889 textRange
= element
.createTextRange();
15890 textRange
.collapse( false );
15891 textRange
.select();
15896 * Set the validation pattern.
15898 * The validation pattern is either a regular expression, a function, or the symbolic name of a
15899 * pattern defined by the class: 'non-empty' (the value cannot be an empty string) or 'integer' (the
15900 * value must contain only numbers).
15902 * @param {RegExp|Function|string|null} validate Regular expression, function, or the symbolic name
15903 * of a pattern (either ‘integer’ or ‘non-empty’) defined by the class.
15905 OO
.ui
.TextInputWidget
.prototype.setValidation = function ( validate
) {
15906 if ( validate
instanceof RegExp
|| validate
instanceof Function
) {
15907 this.validate
= validate
;
15909 this.validate
= this.constructor.static.validationPatterns
[ validate
] || /.*/;
15914 * Sets the 'invalid' flag appropriately.
15916 * @param {boolean} [isValid] Optionally override validation result
15918 OO
.ui
.TextInputWidget
.prototype.setValidityFlag = function ( isValid
) {
15920 setFlag = function ( valid
) {
15922 widget
.$input
.attr( 'aria-invalid', 'true' );
15924 widget
.$input
.removeAttr( 'aria-invalid' );
15926 widget
.setFlags( { invalid
: !valid
} );
15929 if ( isValid
!== undefined ) {
15930 setFlag( isValid
);
15932 this.getValidity().then( function () {
15941 * Check if a value is valid.
15943 * This method returns a promise that resolves with a boolean `true` if the current value is
15944 * considered valid according to the supplied {@link #validate validation pattern}.
15947 * @return {jQuery.Promise} A promise that resolves to a boolean `true` if the value is valid.
15949 OO
.ui
.TextInputWidget
.prototype.isValid = function () {
15952 if ( this.validate
instanceof Function
) {
15953 result
= this.validate( this.getValue() );
15954 if ( $.isFunction( result
.promise
) ) {
15955 return result
.promise();
15957 return $.Deferred().resolve( !!result
).promise();
15960 return $.Deferred().resolve( !!this.getValue().match( this.validate
) ).promise();
15965 * Get the validity of current value.
15967 * This method returns a promise that resolves if the value is valid and rejects if
15968 * it isn't. Uses the {@link #validate validation pattern} to check for validity.
15970 * @return {jQuery.Promise} A promise that resolves if the value is valid, rejects if not.
15972 OO
.ui
.TextInputWidget
.prototype.getValidity = function () {
15973 var result
, promise
;
15975 function rejectOrResolve( valid
) {
15977 return $.Deferred().resolve().promise();
15979 return $.Deferred().reject().promise();
15983 if ( this.validate
instanceof Function
) {
15984 result
= this.validate( this.getValue() );
15986 if ( $.isFunction( result
.promise
) ) {
15987 promise
= $.Deferred();
15989 result
.then( function ( valid
) {
15999 return promise
.promise();
16001 return rejectOrResolve( result
);
16004 return rejectOrResolve( this.getValue().match( this.validate
) );
16009 * Set the position of the inline label relative to that of the value: `‘before’` or `‘after’`.
16011 * @param {string} labelPosition Label position, 'before' or 'after'
16014 OO
.ui
.TextInputWidget
.prototype.setLabelPosition = function ( labelPosition
) {
16015 this.labelPosition
= labelPosition
;
16016 this.updatePosition();
16021 * Deprecated alias of #setLabelPosition
16023 * @deprecated Use setLabelPosition instead.
16025 OO
.ui
.TextInputWidget
.prototype.setPosition
=
16026 OO
.ui
.TextInputWidget
.prototype.setLabelPosition
;
16029 * Update the position of the inline label.
16031 * This method is called by #setLabelPosition, and can also be called on its own if
16032 * something causes the label to be mispositioned.
16036 OO
.ui
.TextInputWidget
.prototype.updatePosition = function () {
16037 var after
= this.labelPosition
=== 'after';
16040 .toggleClass( 'oo-ui-textInputWidget-labelPosition-after', !!this.label
&& after
)
16041 .toggleClass( 'oo-ui-textInputWidget-labelPosition-before', !!this.label
&& !after
);
16043 this.positionLabel();
16049 * Update the 'clear' indicator displayed on type: 'search' text fields, hiding it when the field is
16050 * already empty or when it's not editable.
16052 OO
.ui
.TextInputWidget
.prototype.updateSearchIndicator = function () {
16053 if ( this.type
=== 'search' ) {
16054 if ( this.getValue() === '' || this.isDisabled() || this.isReadOnly() ) {
16055 this.setIndicator( null );
16057 this.setIndicator( 'clear' );
16063 * Position the label by setting the correct padding on the input.
16068 OO
.ui
.TextInputWidget
.prototype.positionLabel = function () {
16069 var after
, rtl
, property
;
16070 // Clear old values
16072 // Clear old values if present
16074 'padding-right': '',
16078 if ( this.label
) {
16079 this.$element
.append( this.$label
);
16081 this.$label
.detach();
16085 after
= this.labelPosition
=== 'after';
16086 rtl
= this.$element
.css( 'direction' ) === 'rtl';
16087 property
= after
=== rtl
? 'padding-left' : 'padding-right';
16089 this.$input
.css( property
, this.$label
.outerWidth( true ) );
16097 OO
.ui
.TextInputWidget
.prototype.gatherPreInfuseState = function ( node
) {
16099 state
= OO
.ui
.TextInputWidget
.parent
.prototype.gatherPreInfuseState
.call( this, node
),
16100 $input
= $( node
).find( '.oo-ui-inputWidget-input' );
16101 state
.$input
= $input
; // shortcut for performance, used in InputWidget
16102 if ( this.multiline
) {
16103 state
.scrollTop
= $input
.scrollTop();
16111 OO
.ui
.TextInputWidget
.prototype.restorePreInfuseState = function ( state
) {
16112 OO
.ui
.TextInputWidget
.parent
.prototype.restorePreInfuseState
.call( this, state
);
16113 if ( state
.scrollTop
!== undefined ) {
16114 this.$input
.scrollTop( state
.scrollTop
);
16119 * ComboBoxWidgets combine a {@link OO.ui.TextInputWidget text input} (where a value
16120 * can be entered manually) and a {@link OO.ui.MenuSelectWidget menu of options} (from which
16121 * a value can be chosen instead). Users can choose options from the combo box in one of two ways:
16123 * - by typing a value in the text input field. If the value exactly matches the value of a menu
16124 * option, that option will appear to be selected.
16125 * - by choosing a value from the menu. The value of the chosen option will then appear in the text
16128 * For more information about menus and options, please see the [OOjs UI documentation on MediaWiki][1].
16131 * // Example: A ComboBoxWidget.
16132 * var comboBox = new OO.ui.ComboBoxWidget( {
16133 * label: 'ComboBoxWidget',
16134 * input: { value: 'Option One' },
16137 * new OO.ui.MenuOptionWidget( {
16138 * data: 'Option 1',
16139 * label: 'Option One'
16141 * new OO.ui.MenuOptionWidget( {
16142 * data: 'Option 2',
16143 * label: 'Option Two'
16145 * new OO.ui.MenuOptionWidget( {
16146 * data: 'Option 3',
16147 * label: 'Option Three'
16149 * new OO.ui.MenuOptionWidget( {
16150 * data: 'Option 4',
16151 * label: 'Option Four'
16153 * new OO.ui.MenuOptionWidget( {
16154 * data: 'Option 5',
16155 * label: 'Option Five'
16160 * $( 'body' ).append( comboBox.$element );
16162 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Menu_selects_and_options
16165 * @extends OO.ui.Widget
16166 * @mixins OO.ui.mixin.TabIndexedElement
16169 * @param {Object} [config] Configuration options
16170 * @cfg {Object} [menu] Configuration options to pass to the {@link OO.ui.FloatingMenuSelectWidget menu select widget}.
16171 * @cfg {Object} [input] Configuration options to pass to the {@link OO.ui.TextInputWidget text input widget}.
16172 * @cfg {jQuery} [$overlay] Render the menu into a separate layer. This configuration is useful in cases where
16173 * the expanded menu is larger than its containing `<div>`. The specified overlay layer is usually on top of the
16174 * containing `<div>` and has a larger area. By default, the menu uses relative positioning.
16176 OO
.ui
.ComboBoxWidget
= function OoUiComboBoxWidget( config
) {
16177 // Configuration initialization
16178 config
= config
|| {};
16180 // Parent constructor
16181 OO
.ui
.ComboBoxWidget
.parent
.call( this, config
);
16183 // Properties (must be set before TabIndexedElement constructor call)
16184 this.$indicator
= this.$( '<span>' );
16186 // Mixin constructors
16187 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$indicator
} ) );
16190 this.$overlay
= config
.$overlay
|| this.$element
;
16191 this.input
= new OO
.ui
.TextInputWidget( $.extend(
16194 $indicator
: this.$indicator
,
16195 disabled
: this.isDisabled()
16199 this.input
.$input
.eq( 0 ).attr( {
16201 'aria-autocomplete': 'list'
16203 this.menu
= new OO
.ui
.FloatingMenuSelectWidget( $.extend(
16207 $container
: this.input
.$element
,
16208 disabled
: this.isDisabled()
16214 this.$indicator
.on( {
16215 click
: this.onClick
.bind( this ),
16216 keypress
: this.onKeyPress
.bind( this )
16218 this.input
.connect( this, {
16219 change
: 'onInputChange',
16220 enter
: 'onInputEnter'
16222 this.menu
.connect( this, {
16223 choose
: 'onMenuChoose',
16224 add
: 'onMenuItemsChange',
16225 remove
: 'onMenuItemsChange'
16229 this.$element
.addClass( 'oo-ui-comboBoxWidget' ).append( this.input
.$element
);
16230 this.$overlay
.append( this.menu
.$element
);
16231 this.onMenuItemsChange();
16236 OO
.inheritClass( OO
.ui
.ComboBoxWidget
, OO
.ui
.Widget
);
16237 OO
.mixinClass( OO
.ui
.ComboBoxWidget
, OO
.ui
.mixin
.TabIndexedElement
);
16242 * Get the combobox's menu.
16243 * @return {OO.ui.FloatingMenuSelectWidget} Menu widget
16245 OO
.ui
.ComboBoxWidget
.prototype.getMenu = function () {
16250 * Get the combobox's text input widget.
16251 * @return {OO.ui.TextInputWidget} Text input widget
16253 OO
.ui
.ComboBoxWidget
.prototype.getInput = function () {
16258 * Handle input change events.
16261 * @param {string} value New value
16263 OO
.ui
.ComboBoxWidget
.prototype.onInputChange = function ( value
) {
16264 var match
= this.menu
.getItemFromData( value
);
16266 this.menu
.selectItem( match
);
16267 if ( this.menu
.getHighlightedItem() ) {
16268 this.menu
.highlightItem( match
);
16271 if ( !this.isDisabled() ) {
16272 this.menu
.toggle( true );
16277 * Handle mouse click events.
16280 * @param {jQuery.Event} e Mouse click event
16282 OO
.ui
.ComboBoxWidget
.prototype.onClick = function ( e
) {
16283 if ( !this.isDisabled() && e
.which
=== 1 ) {
16284 this.menu
.toggle();
16285 this.input
.$input
[ 0 ].focus();
16291 * Handle key press events.
16294 * @param {jQuery.Event} e Key press event
16296 OO
.ui
.ComboBoxWidget
.prototype.onKeyPress = function ( e
) {
16297 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
16298 this.menu
.toggle();
16299 this.input
.$input
[ 0 ].focus();
16305 * Handle input enter events.
16309 OO
.ui
.ComboBoxWidget
.prototype.onInputEnter = function () {
16310 if ( !this.isDisabled() ) {
16311 this.menu
.toggle( false );
16316 * Handle menu choose events.
16319 * @param {OO.ui.OptionWidget} item Chosen item
16321 OO
.ui
.ComboBoxWidget
.prototype.onMenuChoose = function ( item
) {
16322 this.input
.setValue( item
.getData() );
16326 * Handle menu item change events.
16330 OO
.ui
.ComboBoxWidget
.prototype.onMenuItemsChange = function () {
16331 var match
= this.menu
.getItemFromData( this.input
.getValue() );
16332 this.menu
.selectItem( match
);
16333 if ( this.menu
.getHighlightedItem() ) {
16334 this.menu
.highlightItem( match
);
16336 this.$element
.toggleClass( 'oo-ui-comboBoxWidget-empty', this.menu
.isEmpty() );
16342 OO
.ui
.ComboBoxWidget
.prototype.setDisabled = function ( disabled
) {
16344 OO
.ui
.ComboBoxWidget
.parent
.prototype.setDisabled
.call( this, disabled
);
16346 if ( this.input
) {
16347 this.input
.setDisabled( this.isDisabled() );
16350 this.menu
.setDisabled( this.isDisabled() );
16357 * LabelWidgets help identify the function of interface elements. Each LabelWidget can
16358 * be configured with a `label` option that is set to a string, a label node, or a function:
16360 * - String: a plaintext string
16361 * - jQuery selection: a jQuery selection, used for anything other than a plaintext label, e.g., a
16362 * label that includes a link or special styling, such as a gray color or additional graphical elements.
16363 * - Function: a function that will produce a string in the future. Functions are used
16364 * in cases where the value of the label is not currently defined.
16366 * In addition, the LabelWidget can be associated with an {@link OO.ui.InputWidget input widget}, which
16367 * will come into focus when the label is clicked.
16370 * // Examples of LabelWidgets
16371 * var label1 = new OO.ui.LabelWidget( {
16372 * label: 'plaintext label'
16374 * var label2 = new OO.ui.LabelWidget( {
16375 * label: $( '<a href="default.html">jQuery label</a>' )
16377 * // Create a fieldset layout with fields for each example
16378 * var fieldset = new OO.ui.FieldsetLayout();
16379 * fieldset.addItems( [
16380 * new OO.ui.FieldLayout( label1 ),
16381 * new OO.ui.FieldLayout( label2 )
16383 * $( 'body' ).append( fieldset.$element );
16386 * @extends OO.ui.Widget
16387 * @mixins OO.ui.mixin.LabelElement
16390 * @param {Object} [config] Configuration options
16391 * @cfg {OO.ui.InputWidget} [input] {@link OO.ui.InputWidget Input widget} that uses the label.
16392 * Clicking the label will focus the specified input field.
16394 OO
.ui
.LabelWidget
= function OoUiLabelWidget( config
) {
16395 // Configuration initialization
16396 config
= config
|| {};
16398 // Parent constructor
16399 OO
.ui
.LabelWidget
.parent
.call( this, config
);
16401 // Mixin constructors
16402 OO
.ui
.mixin
.LabelElement
.call( this, $.extend( {}, config
, { $label
: this.$element
} ) );
16403 OO
.ui
.mixin
.TitledElement
.call( this, config
);
16406 this.input
= config
.input
;
16409 if ( this.input
instanceof OO
.ui
.InputWidget
) {
16410 this.$element
.on( 'click', this.onClick
.bind( this ) );
16414 this.$element
.addClass( 'oo-ui-labelWidget' );
16419 OO
.inheritClass( OO
.ui
.LabelWidget
, OO
.ui
.Widget
);
16420 OO
.mixinClass( OO
.ui
.LabelWidget
, OO
.ui
.mixin
.LabelElement
);
16421 OO
.mixinClass( OO
.ui
.LabelWidget
, OO
.ui
.mixin
.TitledElement
);
16423 /* Static Properties */
16425 OO
.ui
.LabelWidget
.static.tagName
= 'span';
16430 * Handles label mouse click events.
16433 * @param {jQuery.Event} e Mouse click event
16435 OO
.ui
.LabelWidget
.prototype.onClick = function () {
16436 this.input
.simulateLabelClick();
16441 * OptionWidgets are special elements that can be selected and configured with data. The
16442 * data is often unique for each option, but it does not have to be. OptionWidgets are used
16443 * with OO.ui.SelectWidget to create a selection of mutually exclusive options. For more information
16444 * and examples, please see the [OOjs UI documentation on MediaWiki][1].
16446 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
16449 * @extends OO.ui.Widget
16450 * @mixins OO.ui.mixin.LabelElement
16451 * @mixins OO.ui.mixin.FlaggedElement
16454 * @param {Object} [config] Configuration options
16456 OO
.ui
.OptionWidget
= function OoUiOptionWidget( config
) {
16457 // Configuration initialization
16458 config
= config
|| {};
16460 // Parent constructor
16461 OO
.ui
.OptionWidget
.parent
.call( this, config
);
16463 // Mixin constructors
16464 OO
.ui
.mixin
.ItemWidget
.call( this );
16465 OO
.ui
.mixin
.LabelElement
.call( this, config
);
16466 OO
.ui
.mixin
.FlaggedElement
.call( this, config
);
16469 this.selected
= false;
16470 this.highlighted
= false;
16471 this.pressed
= false;
16475 .data( 'oo-ui-optionWidget', this )
16476 .attr( 'role', 'option' )
16477 .attr( 'aria-selected', 'false' )
16478 .addClass( 'oo-ui-optionWidget' )
16479 .append( this.$label
);
16484 OO
.inheritClass( OO
.ui
.OptionWidget
, OO
.ui
.Widget
);
16485 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.mixin
.ItemWidget
);
16486 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.mixin
.LabelElement
);
16487 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.mixin
.FlaggedElement
);
16489 /* Static Properties */
16491 OO
.ui
.OptionWidget
.static.selectable
= true;
16493 OO
.ui
.OptionWidget
.static.highlightable
= true;
16495 OO
.ui
.OptionWidget
.static.pressable
= true;
16497 OO
.ui
.OptionWidget
.static.scrollIntoViewOnSelect
= false;
16502 * Check if the option can be selected.
16504 * @return {boolean} Item is selectable
16506 OO
.ui
.OptionWidget
.prototype.isSelectable = function () {
16507 return this.constructor.static.selectable
&& !this.isDisabled() && this.isVisible();
16511 * Check if the option can be highlighted. A highlight indicates that the option
16512 * may be selected when a user presses enter or clicks. Disabled items cannot
16515 * @return {boolean} Item is highlightable
16517 OO
.ui
.OptionWidget
.prototype.isHighlightable = function () {
16518 return this.constructor.static.highlightable
&& !this.isDisabled() && this.isVisible();
16522 * Check if the option can be pressed. The pressed state occurs when a user mouses
16523 * down on an item, but has not yet let go of the mouse.
16525 * @return {boolean} Item is pressable
16527 OO
.ui
.OptionWidget
.prototype.isPressable = function () {
16528 return this.constructor.static.pressable
&& !this.isDisabled() && this.isVisible();
16532 * Check if the option is selected.
16534 * @return {boolean} Item is selected
16536 OO
.ui
.OptionWidget
.prototype.isSelected = function () {
16537 return this.selected
;
16541 * Check if the option is highlighted. A highlight indicates that the
16542 * item may be selected when a user presses enter or clicks.
16544 * @return {boolean} Item is highlighted
16546 OO
.ui
.OptionWidget
.prototype.isHighlighted = function () {
16547 return this.highlighted
;
16551 * Check if the option is pressed. The pressed state occurs when a user mouses
16552 * down on an item, but has not yet let go of the mouse. The item may appear
16553 * selected, but it will not be selected until the user releases the mouse.
16555 * @return {boolean} Item is pressed
16557 OO
.ui
.OptionWidget
.prototype.isPressed = function () {
16558 return this.pressed
;
16562 * Set the option’s selected state. In general, all modifications to the selection
16563 * should be handled by the SelectWidget’s {@link OO.ui.SelectWidget#selectItem selectItem( [item] )}
16564 * method instead of this method.
16566 * @param {boolean} [state=false] Select option
16569 OO
.ui
.OptionWidget
.prototype.setSelected = function ( state
) {
16570 if ( this.constructor.static.selectable
) {
16571 this.selected
= !!state
;
16573 .toggleClass( 'oo-ui-optionWidget-selected', state
)
16574 .attr( 'aria-selected', state
.toString() );
16575 if ( state
&& this.constructor.static.scrollIntoViewOnSelect
) {
16576 this.scrollElementIntoView();
16578 this.updateThemeClasses();
16584 * Set the option’s highlighted state. In general, all programmatic
16585 * modifications to the highlight should be handled by the
16586 * SelectWidget’s {@link OO.ui.SelectWidget#highlightItem highlightItem( [item] )}
16587 * method instead of this method.
16589 * @param {boolean} [state=false] Highlight option
16592 OO
.ui
.OptionWidget
.prototype.setHighlighted = function ( state
) {
16593 if ( this.constructor.static.highlightable
) {
16594 this.highlighted
= !!state
;
16595 this.$element
.toggleClass( 'oo-ui-optionWidget-highlighted', state
);
16596 this.updateThemeClasses();
16602 * Set the option’s pressed state. In general, all
16603 * programmatic modifications to the pressed state should be handled by the
16604 * SelectWidget’s {@link OO.ui.SelectWidget#pressItem pressItem( [item] )}
16605 * method instead of this method.
16607 * @param {boolean} [state=false] Press option
16610 OO
.ui
.OptionWidget
.prototype.setPressed = function ( state
) {
16611 if ( this.constructor.static.pressable
) {
16612 this.pressed
= !!state
;
16613 this.$element
.toggleClass( 'oo-ui-optionWidget-pressed', state
);
16614 this.updateThemeClasses();
16620 * DecoratedOptionWidgets are {@link OO.ui.OptionWidget options} that can be configured
16621 * with an {@link OO.ui.mixin.IconElement icon} and/or {@link OO.ui.mixin.IndicatorElement indicator}.
16622 * This class is used with OO.ui.SelectWidget to create a selection of mutually exclusive
16623 * options. For more information about options and selects, please see the
16624 * [OOjs UI documentation on MediaWiki][1].
16627 * // Decorated options in a select widget
16628 * var select = new OO.ui.SelectWidget( {
16630 * new OO.ui.DecoratedOptionWidget( {
16632 * label: 'Option with icon',
16635 * new OO.ui.DecoratedOptionWidget( {
16637 * label: 'Option with indicator',
16638 * indicator: 'next'
16642 * $( 'body' ).append( select.$element );
16644 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
16647 * @extends OO.ui.OptionWidget
16648 * @mixins OO.ui.mixin.IconElement
16649 * @mixins OO.ui.mixin.IndicatorElement
16652 * @param {Object} [config] Configuration options
16654 OO
.ui
.DecoratedOptionWidget
= function OoUiDecoratedOptionWidget( config
) {
16655 // Parent constructor
16656 OO
.ui
.DecoratedOptionWidget
.parent
.call( this, config
);
16658 // Mixin constructors
16659 OO
.ui
.mixin
.IconElement
.call( this, config
);
16660 OO
.ui
.mixin
.IndicatorElement
.call( this, config
);
16664 .addClass( 'oo-ui-decoratedOptionWidget' )
16665 .prepend( this.$icon
)
16666 .append( this.$indicator
);
16671 OO
.inheritClass( OO
.ui
.DecoratedOptionWidget
, OO
.ui
.OptionWidget
);
16672 OO
.mixinClass( OO
.ui
.DecoratedOptionWidget
, OO
.ui
.mixin
.IconElement
);
16673 OO
.mixinClass( OO
.ui
.DecoratedOptionWidget
, OO
.ui
.mixin
.IndicatorElement
);
16676 * ButtonOptionWidget is a special type of {@link OO.ui.mixin.ButtonElement button element} that
16677 * can be selected and configured with data. The class is
16678 * used with OO.ui.ButtonSelectWidget to create a selection of button options. Please see the
16679 * [OOjs UI documentation on MediaWiki] [1] for more information.
16681 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Button_selects_and_options
16684 * @extends OO.ui.DecoratedOptionWidget
16685 * @mixins OO.ui.mixin.ButtonElement
16686 * @mixins OO.ui.mixin.TabIndexedElement
16687 * @mixins OO.ui.mixin.TitledElement
16690 * @param {Object} [config] Configuration options
16692 OO
.ui
.ButtonOptionWidget
= function OoUiButtonOptionWidget( config
) {
16693 // Configuration initialization
16694 config
= config
|| {};
16696 // Parent constructor
16697 OO
.ui
.ButtonOptionWidget
.parent
.call( this, config
);
16699 // Mixin constructors
16700 OO
.ui
.mixin
.ButtonElement
.call( this, config
);
16701 OO
.ui
.mixin
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$button
} ) );
16702 OO
.ui
.mixin
.TabIndexedElement
.call( this, $.extend( {}, config
, {
16703 $tabIndexed
: this.$button
,
16708 this.$element
.addClass( 'oo-ui-buttonOptionWidget' );
16709 this.$button
.append( this.$element
.contents() );
16710 this.$element
.append( this.$button
);
16715 OO
.inheritClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
16716 OO
.mixinClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.mixin
.ButtonElement
);
16717 OO
.mixinClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.mixin
.TitledElement
);
16718 OO
.mixinClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.mixin
.TabIndexedElement
);
16720 /* Static Properties */
16722 // Allow button mouse down events to pass through so they can be handled by the parent select widget
16723 OO
.ui
.ButtonOptionWidget
.static.cancelButtonMouseDownEvents
= false;
16725 OO
.ui
.ButtonOptionWidget
.static.highlightable
= false;
16732 OO
.ui
.ButtonOptionWidget
.prototype.setSelected = function ( state
) {
16733 OO
.ui
.ButtonOptionWidget
.parent
.prototype.setSelected
.call( this, state
);
16735 if ( this.constructor.static.selectable
) {
16736 this.setActive( state
);
16743 * RadioOptionWidget is an option widget that looks like a radio button.
16744 * The class is used with OO.ui.RadioSelectWidget to create a selection of radio options.
16745 * Please see the [OOjs UI documentation on MediaWiki] [1] for more information.
16747 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Button_selects_and_option
16750 * @extends OO.ui.OptionWidget
16753 * @param {Object} [config] Configuration options
16755 OO
.ui
.RadioOptionWidget
= function OoUiRadioOptionWidget( config
) {
16756 // Configuration initialization
16757 config
= config
|| {};
16759 // Properties (must be done before parent constructor which calls #setDisabled)
16760 this.radio
= new OO
.ui
.RadioInputWidget( { value
: config
.data
, tabIndex
: -1 } );
16762 // Parent constructor
16763 OO
.ui
.RadioOptionWidget
.parent
.call( this, config
);
16766 this.radio
.$input
.on( 'focus', this.onInputFocus
.bind( this ) );
16769 // Remove implicit role, we're handling it ourselves
16770 this.radio
.$input
.attr( 'role', 'presentation' );
16772 .addClass( 'oo-ui-radioOptionWidget' )
16773 .attr( 'role', 'radio' )
16774 .attr( 'aria-checked', 'false' )
16775 .removeAttr( 'aria-selected' )
16776 .prepend( this.radio
.$element
);
16781 OO
.inheritClass( OO
.ui
.RadioOptionWidget
, OO
.ui
.OptionWidget
);
16783 /* Static Properties */
16785 OO
.ui
.RadioOptionWidget
.static.highlightable
= false;
16787 OO
.ui
.RadioOptionWidget
.static.scrollIntoViewOnSelect
= true;
16789 OO
.ui
.RadioOptionWidget
.static.pressable
= false;
16791 OO
.ui
.RadioOptionWidget
.static.tagName
= 'label';
16796 * @param {jQuery.Event} e Focus event
16799 OO
.ui
.RadioOptionWidget
.prototype.onInputFocus = function () {
16800 this.radio
.$input
.blur();
16801 this.$element
.parent().focus();
16807 OO
.ui
.RadioOptionWidget
.prototype.setSelected = function ( state
) {
16808 OO
.ui
.RadioOptionWidget
.parent
.prototype.setSelected
.call( this, state
);
16810 this.radio
.setSelected( state
);
16812 .attr( 'aria-checked', state
.toString() )
16813 .removeAttr( 'aria-selected' );
16821 OO
.ui
.RadioOptionWidget
.prototype.setDisabled = function ( disabled
) {
16822 OO
.ui
.RadioOptionWidget
.parent
.prototype.setDisabled
.call( this, disabled
);
16824 this.radio
.setDisabled( this.isDisabled() );
16830 * MenuOptionWidget is an option widget that looks like a menu item. The class is used with
16831 * OO.ui.MenuSelectWidget to create a menu of mutually exclusive options. Please see
16832 * the [OOjs UI documentation on MediaWiki] [1] for more information.
16834 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options#Menu_selects_and_options
16837 * @extends OO.ui.DecoratedOptionWidget
16840 * @param {Object} [config] Configuration options
16842 OO
.ui
.MenuOptionWidget
= function OoUiMenuOptionWidget( config
) {
16843 // Configuration initialization
16844 config
= $.extend( { icon
: 'check' }, config
);
16846 // Parent constructor
16847 OO
.ui
.MenuOptionWidget
.parent
.call( this, config
);
16851 .attr( 'role', 'menuitem' )
16852 .addClass( 'oo-ui-menuOptionWidget' );
16857 OO
.inheritClass( OO
.ui
.MenuOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
16859 /* Static Properties */
16861 OO
.ui
.MenuOptionWidget
.static.scrollIntoViewOnSelect
= true;
16864 * MenuSectionOptionWidgets are used inside {@link OO.ui.MenuSelectWidget menu select widgets} to group one or more related
16865 * {@link OO.ui.MenuOptionWidget menu options}. MenuSectionOptionWidgets cannot be highlighted or selected.
16868 * var myDropdown = new OO.ui.DropdownWidget( {
16871 * new OO.ui.MenuSectionOptionWidget( {
16874 * new OO.ui.MenuOptionWidget( {
16876 * label: 'Welsh Corgi'
16878 * new OO.ui.MenuOptionWidget( {
16880 * label: 'Standard Poodle'
16882 * new OO.ui.MenuSectionOptionWidget( {
16885 * new OO.ui.MenuOptionWidget( {
16892 * $( 'body' ).append( myDropdown.$element );
16895 * @extends OO.ui.DecoratedOptionWidget
16898 * @param {Object} [config] Configuration options
16900 OO
.ui
.MenuSectionOptionWidget
= function OoUiMenuSectionOptionWidget( config
) {
16901 // Parent constructor
16902 OO
.ui
.MenuSectionOptionWidget
.parent
.call( this, config
);
16905 this.$element
.addClass( 'oo-ui-menuSectionOptionWidget' );
16910 OO
.inheritClass( OO
.ui
.MenuSectionOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
16912 /* Static Properties */
16914 OO
.ui
.MenuSectionOptionWidget
.static.selectable
= false;
16916 OO
.ui
.MenuSectionOptionWidget
.static.highlightable
= false;
16919 * OutlineOptionWidget is an item in an {@link OO.ui.OutlineSelectWidget OutlineSelectWidget}.
16921 * Currently, this class is only used by {@link OO.ui.BookletLayout booklet layouts}, which contain
16922 * {@link OO.ui.PageLayout page layouts}. See {@link OO.ui.BookletLayout BookletLayout}
16926 * @extends OO.ui.DecoratedOptionWidget
16929 * @param {Object} [config] Configuration options
16930 * @cfg {number} [level] Indentation level
16931 * @cfg {boolean} [movable] Allow modification from {@link OO.ui.OutlineControlsWidget outline controls}.
16933 OO
.ui
.OutlineOptionWidget
= function OoUiOutlineOptionWidget( config
) {
16934 // Configuration initialization
16935 config
= config
|| {};
16937 // Parent constructor
16938 OO
.ui
.OutlineOptionWidget
.parent
.call( this, config
);
16942 this.movable
= !!config
.movable
;
16943 this.removable
= !!config
.removable
;
16946 this.$element
.addClass( 'oo-ui-outlineOptionWidget' );
16947 this.setLevel( config
.level
);
16952 OO
.inheritClass( OO
.ui
.OutlineOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
16954 /* Static Properties */
16956 OO
.ui
.OutlineOptionWidget
.static.highlightable
= false;
16958 OO
.ui
.OutlineOptionWidget
.static.scrollIntoViewOnSelect
= true;
16960 OO
.ui
.OutlineOptionWidget
.static.levelClass
= 'oo-ui-outlineOptionWidget-level-';
16962 OO
.ui
.OutlineOptionWidget
.static.levels
= 3;
16967 * Check if item is movable.
16969 * Movability is used by {@link OO.ui.OutlineControlsWidget outline controls}.
16971 * @return {boolean} Item is movable
16973 OO
.ui
.OutlineOptionWidget
.prototype.isMovable = function () {
16974 return this.movable
;
16978 * Check if item is removable.
16980 * Removability is used by {@link OO.ui.OutlineControlsWidget outline controls}.
16982 * @return {boolean} Item is removable
16984 OO
.ui
.OutlineOptionWidget
.prototype.isRemovable = function () {
16985 return this.removable
;
16989 * Get indentation level.
16991 * @return {number} Indentation level
16993 OO
.ui
.OutlineOptionWidget
.prototype.getLevel = function () {
17000 * Movability is used by {@link OO.ui.OutlineControlsWidget outline controls}.
17002 * @param {boolean} movable Item is movable
17005 OO
.ui
.OutlineOptionWidget
.prototype.setMovable = function ( movable
) {
17006 this.movable
= !!movable
;
17007 this.updateThemeClasses();
17012 * Set removability.
17014 * Removability is used by {@link OO.ui.OutlineControlsWidget outline controls}.
17016 * @param {boolean} movable Item is removable
17019 OO
.ui
.OutlineOptionWidget
.prototype.setRemovable = function ( removable
) {
17020 this.removable
= !!removable
;
17021 this.updateThemeClasses();
17026 * Set indentation level.
17028 * @param {number} [level=0] Indentation level, in the range of [0,#maxLevel]
17031 OO
.ui
.OutlineOptionWidget
.prototype.setLevel = function ( level
) {
17032 var levels
= this.constructor.static.levels
,
17033 levelClass
= this.constructor.static.levelClass
,
17036 this.level
= level
? Math
.max( 0, Math
.min( levels
- 1, level
) ) : 0;
17038 if ( this.level
=== i
) {
17039 this.$element
.addClass( levelClass
+ i
);
17041 this.$element
.removeClass( levelClass
+ i
);
17044 this.updateThemeClasses();
17050 * TabOptionWidget is an item in a {@link OO.ui.TabSelectWidget TabSelectWidget}.
17052 * Currently, this class is only used by {@link OO.ui.IndexLayout index layouts}, which contain
17053 * {@link OO.ui.CardLayout card layouts}. See {@link OO.ui.IndexLayout IndexLayout}
17057 * @extends OO.ui.OptionWidget
17060 * @param {Object} [config] Configuration options
17062 OO
.ui
.TabOptionWidget
= function OoUiTabOptionWidget( config
) {
17063 // Configuration initialization
17064 config
= config
|| {};
17066 // Parent constructor
17067 OO
.ui
.TabOptionWidget
.parent
.call( this, config
);
17070 this.$element
.addClass( 'oo-ui-tabOptionWidget' );
17075 OO
.inheritClass( OO
.ui
.TabOptionWidget
, OO
.ui
.OptionWidget
);
17077 /* Static Properties */
17079 OO
.ui
.TabOptionWidget
.static.highlightable
= false;
17082 * PopupWidget is a container for content. The popup is overlaid and positioned absolutely.
17083 * By default, each popup has an anchor that points toward its origin.
17084 * Please see the [OOjs UI documentation on Mediawiki] [1] for more information and examples.
17087 * // A popup widget.
17088 * var popup = new OO.ui.PopupWidget( {
17089 * $content: $( '<p>Hi there!</p>' ),
17094 * $( 'body' ).append( popup.$element );
17095 * // To display the popup, toggle the visibility to 'true'.
17096 * popup.toggle( true );
17098 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Popups
17101 * @extends OO.ui.Widget
17102 * @mixins OO.ui.mixin.LabelElement
17103 * @mixins OO.ui.mixin.ClippableElement
17106 * @param {Object} [config] Configuration options
17107 * @cfg {number} [width=320] Width of popup in pixels
17108 * @cfg {number} [height] Height of popup in pixels. Omit to use the automatic height.
17109 * @cfg {boolean} [anchor=true] Show anchor pointing to origin of popup
17110 * @cfg {string} [align='center'] Alignment of the popup: `center`, `force-left`, `force-right`, `backwards` or `forwards`.
17111 * If the popup is forced-left the popup body is leaning towards the left. For force-right alignment, the body of the
17112 * popup is leaning towards the right of the screen.
17113 * Using 'backwards' is a logical direction which will result in the popup leaning towards the beginning of the sentence
17114 * in the given language, which means it will flip to the correct positioning in right-to-left languages.
17115 * Using 'forward' will also result in a logical alignment where the body of the popup leans towards the end of the
17116 * sentence in the given language.
17117 * @cfg {jQuery} [$container] Constrain the popup to the boundaries of the specified container.
17118 * See the [OOjs UI docs on MediaWiki][3] for an example.
17119 * [3]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Popups#containerExample
17120 * @cfg {number} [containerPadding=10] Padding between the popup and its container, specified as a number of pixels.
17121 * @cfg {jQuery} [$content] Content to append to the popup's body
17122 * @cfg {jQuery} [$footer] Content to append to the popup's footer
17123 * @cfg {boolean} [autoClose=false] Automatically close the popup when it loses focus.
17124 * @cfg {jQuery} [$autoCloseIgnore] Elements that will not close the popup when clicked.
17125 * This config option is only relevant if #autoClose is set to `true`. See the [OOjs UI docs on MediaWiki][2]
17127 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Popups#autocloseExample
17128 * @cfg {boolean} [head] Show a popup header that contains a #label (if specified) and close
17130 * @cfg {boolean} [padded] Add padding to the popup's body
17132 OO
.ui
.PopupWidget
= function OoUiPopupWidget( config
) {
17133 // Configuration initialization
17134 config
= config
|| {};
17136 // Parent constructor
17137 OO
.ui
.PopupWidget
.parent
.call( this, config
);
17139 // Properties (must be set before ClippableElement constructor call)
17140 this.$body
= $( '<div>' );
17141 this.$popup
= $( '<div>' );
17143 // Mixin constructors
17144 OO
.ui
.mixin
.LabelElement
.call( this, config
);
17145 OO
.ui
.mixin
.ClippableElement
.call( this, $.extend( {}, config
, {
17146 $clippable
: this.$body
,
17147 $clippableContainer
: this.$popup
17151 this.$head
= $( '<div>' );
17152 this.$footer
= $( '<div>' );
17153 this.$anchor
= $( '<div>' );
17154 // If undefined, will be computed lazily in updateDimensions()
17155 this.$container
= config
.$container
;
17156 this.containerPadding
= config
.containerPadding
!== undefined ? config
.containerPadding
: 10;
17157 this.autoClose
= !!config
.autoClose
;
17158 this.$autoCloseIgnore
= config
.$autoCloseIgnore
;
17159 this.transitionTimeout
= null;
17160 this.anchor
= null;
17161 this.width
= config
.width
!== undefined ? config
.width
: 320;
17162 this.height
= config
.height
!== undefined ? config
.height
: null;
17163 this.setAlignment( config
.align
);
17164 this.closeButton
= new OO
.ui
.ButtonWidget( { framed
: false, icon
: 'close' } );
17165 this.onMouseDownHandler
= this.onMouseDown
.bind( this );
17166 this.onDocumentKeyDownHandler
= this.onDocumentKeyDown
.bind( this );
17169 this.closeButton
.connect( this, { click
: 'onCloseButtonClick' } );
17172 this.toggleAnchor( config
.anchor
=== undefined || config
.anchor
);
17173 this.$body
.addClass( 'oo-ui-popupWidget-body' );
17174 this.$anchor
.addClass( 'oo-ui-popupWidget-anchor' );
17176 .addClass( 'oo-ui-popupWidget-head' )
17177 .append( this.$label
, this.closeButton
.$element
);
17178 this.$footer
.addClass( 'oo-ui-popupWidget-footer' );
17179 if ( !config
.head
) {
17180 this.$head
.addClass( 'oo-ui-element-hidden' );
17182 if ( !config
.$footer
) {
17183 this.$footer
.addClass( 'oo-ui-element-hidden' );
17186 .addClass( 'oo-ui-popupWidget-popup' )
17187 .append( this.$head
, this.$body
, this.$footer
);
17189 .addClass( 'oo-ui-popupWidget' )
17190 .append( this.$popup
, this.$anchor
);
17191 // Move content, which was added to #$element by OO.ui.Widget, to the body
17192 if ( config
.$content
instanceof jQuery
) {
17193 this.$body
.append( config
.$content
);
17195 if ( config
.$footer
instanceof jQuery
) {
17196 this.$footer
.append( config
.$footer
);
17198 if ( config
.padded
) {
17199 this.$body
.addClass( 'oo-ui-popupWidget-body-padded' );
17202 // Initially hidden - using #toggle may cause errors if subclasses override toggle with methods
17203 // that reference properties not initialized at that time of parent class construction
17204 // TODO: Find a better way to handle post-constructor setup
17205 this.visible
= false;
17206 this.$element
.addClass( 'oo-ui-element-hidden' );
17211 OO
.inheritClass( OO
.ui
.PopupWidget
, OO
.ui
.Widget
);
17212 OO
.mixinClass( OO
.ui
.PopupWidget
, OO
.ui
.mixin
.LabelElement
);
17213 OO
.mixinClass( OO
.ui
.PopupWidget
, OO
.ui
.mixin
.ClippableElement
);
17218 * Handles mouse down events.
17221 * @param {MouseEvent} e Mouse down event
17223 OO
.ui
.PopupWidget
.prototype.onMouseDown = function ( e
) {
17225 this.isVisible() &&
17226 !$.contains( this.$element
[ 0 ], e
.target
) &&
17227 ( !this.$autoCloseIgnore
|| !this.$autoCloseIgnore
.has( e
.target
).length
)
17229 this.toggle( false );
17234 * Bind mouse down listener.
17238 OO
.ui
.PopupWidget
.prototype.bindMouseDownListener = function () {
17239 // Capture clicks outside popup
17240 OO
.ui
.addCaptureEventListener( this.getElementWindow(), 'mousedown', this.onMouseDownHandler
);
17244 * Handles close button click events.
17248 OO
.ui
.PopupWidget
.prototype.onCloseButtonClick = function () {
17249 if ( this.isVisible() ) {
17250 this.toggle( false );
17255 * Unbind mouse down listener.
17259 OO
.ui
.PopupWidget
.prototype.unbindMouseDownListener = function () {
17260 OO
.ui
.removeCaptureEventListener( this.getElementWindow(), 'mousedown', this.onMouseDownHandler
);
17264 * Handles key down events.
17267 * @param {KeyboardEvent} e Key down event
17269 OO
.ui
.PopupWidget
.prototype.onDocumentKeyDown = function ( e
) {
17271 e
.which
=== OO
.ui
.Keys
.ESCAPE
&&
17274 this.toggle( false );
17275 e
.preventDefault();
17276 e
.stopPropagation();
17281 * Bind key down listener.
17285 OO
.ui
.PopupWidget
.prototype.bindKeyDownListener = function () {
17286 OO
.ui
.addCaptureEventListener( this.getElementWindow(), 'keydown', this.onDocumentKeyDownHandler
);
17290 * Unbind key down listener.
17294 OO
.ui
.PopupWidget
.prototype.unbindKeyDownListener = function () {
17295 OO
.ui
.removeCaptureEventListener( this.getElementWindow(), 'keydown', this.onDocumentKeyDownHandler
);
17299 * Show, hide, or toggle the visibility of the anchor.
17301 * @param {boolean} [show] Show anchor, omit to toggle
17303 OO
.ui
.PopupWidget
.prototype.toggleAnchor = function ( show
) {
17304 show
= show
=== undefined ? !this.anchored
: !!show
;
17306 if ( this.anchored
!== show
) {
17308 this.$element
.addClass( 'oo-ui-popupWidget-anchored' );
17310 this.$element
.removeClass( 'oo-ui-popupWidget-anchored' );
17312 this.anchored
= show
;
17317 * Check if the anchor is visible.
17319 * @return {boolean} Anchor is visible
17321 OO
.ui
.PopupWidget
.prototype.hasAnchor = function () {
17322 return this.anchor
;
17328 OO
.ui
.PopupWidget
.prototype.toggle = function ( show
) {
17330 show
= show
=== undefined ? !this.isVisible() : !!show
;
17332 change
= show
!== this.isVisible();
17335 OO
.ui
.PopupWidget
.parent
.prototype.toggle
.call( this, show
);
17339 if ( this.autoClose
) {
17340 this.bindMouseDownListener();
17341 this.bindKeyDownListener();
17343 this.updateDimensions();
17344 this.toggleClipping( true );
17346 this.toggleClipping( false );
17347 if ( this.autoClose
) {
17348 this.unbindMouseDownListener();
17349 this.unbindKeyDownListener();
17358 * Set the size of the popup.
17360 * Changing the size may also change the popup's position depending on the alignment.
17362 * @param {number} width Width in pixels
17363 * @param {number} height Height in pixels
17364 * @param {boolean} [transition=false] Use a smooth transition
17367 OO
.ui
.PopupWidget
.prototype.setSize = function ( width
, height
, transition
) {
17368 this.width
= width
;
17369 this.height
= height
!== undefined ? height
: null;
17370 if ( this.isVisible() ) {
17371 this.updateDimensions( transition
);
17376 * Update the size and position.
17378 * Only use this to keep the popup properly anchored. Use #setSize to change the size, and this will
17379 * be called automatically.
17381 * @param {boolean} [transition=false] Use a smooth transition
17384 OO
.ui
.PopupWidget
.prototype.updateDimensions = function ( transition
) {
17385 var popupOffset
, originOffset
, containerLeft
, containerWidth
, containerRight
,
17386 popupLeft
, popupRight
, overlapLeft
, overlapRight
, anchorWidth
,
17387 align
= this.align
,
17390 if ( !this.$container
) {
17391 // Lazy-initialize $container if not specified in constructor
17392 this.$container
= $( this.getClosestScrollableElementContainer() );
17395 // Set height and width before measuring things, since it might cause our measurements
17396 // to change (e.g. due to scrollbars appearing or disappearing)
17399 height
: this.height
!== null ? this.height
: 'auto'
17402 // If we are in RTL, we need to flip the alignment, unless it is center
17403 if ( align
=== 'forwards' || align
=== 'backwards' ) {
17404 if ( this.$container
.css( 'direction' ) === 'rtl' ) {
17405 align
= ( { forwards
: 'force-left', backwards
: 'force-right' } )[ this.align
];
17407 align
= ( { forwards
: 'force-right', backwards
: 'force-left' } )[ this.align
];
17412 // Compute initial popupOffset based on alignment
17413 popupOffset
= this.width
* ( { 'force-left': -1, center
: -0.5, 'force-right': 0 } )[ align
];
17415 // Figure out if this will cause the popup to go beyond the edge of the container
17416 originOffset
= this.$element
.offset().left
;
17417 containerLeft
= this.$container
.offset().left
;
17418 containerWidth
= this.$container
.innerWidth();
17419 containerRight
= containerLeft
+ containerWidth
;
17420 popupLeft
= popupOffset
- this.containerPadding
;
17421 popupRight
= popupOffset
+ this.containerPadding
+ this.width
+ this.containerPadding
;
17422 overlapLeft
= ( originOffset
+ popupLeft
) - containerLeft
;
17423 overlapRight
= containerRight
- ( originOffset
+ popupRight
);
17425 // Adjust offset to make the popup not go beyond the edge, if needed
17426 if ( overlapRight
< 0 ) {
17427 popupOffset
+= overlapRight
;
17428 } else if ( overlapLeft
< 0 ) {
17429 popupOffset
-= overlapLeft
;
17432 // Adjust offset to avoid anchor being rendered too close to the edge
17433 // $anchor.width() doesn't work with the pure CSS anchor (returns 0)
17434 // TODO: Find a measurement that works for CSS anchors and image anchors
17435 anchorWidth
= this.$anchor
[ 0 ].scrollWidth
* 2;
17436 if ( popupOffset
+ this.width
< anchorWidth
) {
17437 popupOffset
= anchorWidth
- this.width
;
17438 } else if ( -popupOffset
< anchorWidth
) {
17439 popupOffset
= -anchorWidth
;
17442 // Prevent transition from being interrupted
17443 clearTimeout( this.transitionTimeout
);
17444 if ( transition
) {
17445 // Enable transition
17446 this.$element
.addClass( 'oo-ui-popupWidget-transitioning' );
17449 // Position body relative to anchor
17450 this.$popup
.css( 'margin-left', popupOffset
);
17452 if ( transition
) {
17453 // Prevent transitioning after transition is complete
17454 this.transitionTimeout
= setTimeout( function () {
17455 widget
.$element
.removeClass( 'oo-ui-popupWidget-transitioning' );
17458 // Prevent transitioning immediately
17459 this.$element
.removeClass( 'oo-ui-popupWidget-transitioning' );
17462 // Reevaluate clipping state since we've relocated and resized the popup
17469 * Set popup alignment
17470 * @param {string} align Alignment of the popup, `center`, `force-left`, `force-right`,
17471 * `backwards` or `forwards`.
17473 OO
.ui
.PopupWidget
.prototype.setAlignment = function ( align
) {
17474 // Validate alignment and transform deprecated values
17475 if ( [ 'left', 'right', 'force-left', 'force-right', 'backwards', 'forwards', 'center' ].indexOf( align
) > -1 ) {
17476 this.align
= { left
: 'force-right', right
: 'force-left' }[ align
] || align
;
17478 this.align
= 'center';
17483 * Get popup alignment
17484 * @return {string} align Alignment of the popup, `center`, `force-left`, `force-right`,
17485 * `backwards` or `forwards`.
17487 OO
.ui
.PopupWidget
.prototype.getAlignment = function () {
17492 * Progress bars visually display the status of an operation, such as a download,
17493 * and can be either determinate or indeterminate:
17495 * - **determinate** process bars show the percent of an operation that is complete.
17497 * - **indeterminate** process bars use a visual display of motion to indicate that an operation
17498 * is taking place. Because the extent of an indeterminate operation is unknown, the bar does
17499 * not use percentages.
17501 * The value of the `progress` configuration determines whether the bar is determinate or indeterminate.
17504 * // Examples of determinate and indeterminate progress bars.
17505 * var progressBar1 = new OO.ui.ProgressBarWidget( {
17508 * var progressBar2 = new OO.ui.ProgressBarWidget();
17510 * // Create a FieldsetLayout to layout progress bars
17511 * var fieldset = new OO.ui.FieldsetLayout;
17512 * fieldset.addItems( [
17513 * new OO.ui.FieldLayout( progressBar1, {label: 'Determinate', align: 'top'}),
17514 * new OO.ui.FieldLayout( progressBar2, {label: 'Indeterminate', align: 'top'})
17516 * $( 'body' ).append( fieldset.$element );
17519 * @extends OO.ui.Widget
17522 * @param {Object} [config] Configuration options
17523 * @cfg {number|boolean} [progress=false] The type of progress bar (determinate or indeterminate).
17524 * To create a determinate progress bar, specify a number that reflects the initial percent complete.
17525 * By default, the progress bar is indeterminate.
17527 OO
.ui
.ProgressBarWidget
= function OoUiProgressBarWidget( config
) {
17528 // Configuration initialization
17529 config
= config
|| {};
17531 // Parent constructor
17532 OO
.ui
.ProgressBarWidget
.parent
.call( this, config
);
17535 this.$bar
= $( '<div>' );
17536 this.progress
= null;
17539 this.setProgress( config
.progress
!== undefined ? config
.progress
: false );
17540 this.$bar
.addClass( 'oo-ui-progressBarWidget-bar' );
17543 role
: 'progressbar',
17544 'aria-valuemin': 0,
17545 'aria-valuemax': 100
17547 .addClass( 'oo-ui-progressBarWidget' )
17548 .append( this.$bar
);
17553 OO
.inheritClass( OO
.ui
.ProgressBarWidget
, OO
.ui
.Widget
);
17555 /* Static Properties */
17557 OO
.ui
.ProgressBarWidget
.static.tagName
= 'div';
17562 * Get the percent of the progress that has been completed. Indeterminate progresses will return `false`.
17564 * @return {number|boolean} Progress percent
17566 OO
.ui
.ProgressBarWidget
.prototype.getProgress = function () {
17567 return this.progress
;
17571 * Set the percent of the process completed or `false` for an indeterminate process.
17573 * @param {number|boolean} progress Progress percent or `false` for indeterminate
17575 OO
.ui
.ProgressBarWidget
.prototype.setProgress = function ( progress
) {
17576 this.progress
= progress
;
17578 if ( progress
!== false ) {
17579 this.$bar
.css( 'width', this.progress
+ '%' );
17580 this.$element
.attr( 'aria-valuenow', this.progress
);
17582 this.$bar
.css( 'width', '' );
17583 this.$element
.removeAttr( 'aria-valuenow' );
17585 this.$element
.toggleClass( 'oo-ui-progressBarWidget-indeterminate', !progress
);
17589 * SearchWidgets combine a {@link OO.ui.TextInputWidget text input field}, where users can type a search query,
17590 * and a menu of search results, which is displayed beneath the query
17591 * field. Unlike {@link OO.ui.mixin.LookupElement lookup menus}, search result menus are always visible to the user.
17592 * Users can choose an item from the menu or type a query into the text field to search for a matching result item.
17593 * In general, search widgets are used inside a separate {@link OO.ui.Dialog dialog} window.
17595 * Each time the query is changed, the search result menu is cleared and repopulated. Please see
17596 * the [OOjs UI demos][1] for an example.
17598 * [1]: https://tools.wmflabs.org/oojs-ui/oojs-ui/demos/#dialogs-mediawiki-vector-ltr
17601 * @extends OO.ui.Widget
17604 * @param {Object} [config] Configuration options
17605 * @cfg {string|jQuery} [placeholder] Placeholder text for query input
17606 * @cfg {string} [value] Initial query value
17608 OO
.ui
.SearchWidget
= function OoUiSearchWidget( config
) {
17609 // Configuration initialization
17610 config
= config
|| {};
17612 // Parent constructor
17613 OO
.ui
.SearchWidget
.parent
.call( this, config
);
17616 this.query
= new OO
.ui
.TextInputWidget( {
17618 placeholder
: config
.placeholder
,
17619 value
: config
.value
17621 this.results
= new OO
.ui
.SelectWidget();
17622 this.$query
= $( '<div>' );
17623 this.$results
= $( '<div>' );
17626 this.query
.connect( this, {
17627 change
: 'onQueryChange',
17628 enter
: 'onQueryEnter'
17630 this.query
.$input
.on( 'keydown', this.onQueryKeydown
.bind( this ) );
17634 .addClass( 'oo-ui-searchWidget-query' )
17635 .append( this.query
.$element
);
17637 .addClass( 'oo-ui-searchWidget-results' )
17638 .append( this.results
.$element
);
17640 .addClass( 'oo-ui-searchWidget' )
17641 .append( this.$results
, this.$query
);
17646 OO
.inheritClass( OO
.ui
.SearchWidget
, OO
.ui
.Widget
);
17651 * Handle query key down events.
17654 * @param {jQuery.Event} e Key down event
17656 OO
.ui
.SearchWidget
.prototype.onQueryKeydown = function ( e
) {
17657 var highlightedItem
, nextItem
,
17658 dir
= e
.which
=== OO
.ui
.Keys
.DOWN
? 1 : ( e
.which
=== OO
.ui
.Keys
.UP
? -1 : 0 );
17661 highlightedItem
= this.results
.getHighlightedItem();
17662 if ( !highlightedItem
) {
17663 highlightedItem
= this.results
.getSelectedItem();
17665 nextItem
= this.results
.getRelativeSelectableItem( highlightedItem
, dir
);
17666 this.results
.highlightItem( nextItem
);
17667 nextItem
.scrollElementIntoView();
17672 * Handle select widget select events.
17674 * Clears existing results. Subclasses should repopulate items according to new query.
17677 * @param {string} value New value
17679 OO
.ui
.SearchWidget
.prototype.onQueryChange = function () {
17681 this.results
.clearItems();
17685 * Handle select widget enter key events.
17687 * Chooses highlighted item.
17690 * @param {string} value New value
17692 OO
.ui
.SearchWidget
.prototype.onQueryEnter = function () {
17693 var highlightedItem
= this.results
.getHighlightedItem();
17694 if ( highlightedItem
) {
17695 this.results
.chooseItem( highlightedItem
);
17700 * Get the query input.
17702 * @return {OO.ui.TextInputWidget} Query input
17704 OO
.ui
.SearchWidget
.prototype.getQuery = function () {
17709 * Get the search results menu.
17711 * @return {OO.ui.SelectWidget} Menu of search results
17713 OO
.ui
.SearchWidget
.prototype.getResults = function () {
17714 return this.results
;
17718 * A SelectWidget is of a generic selection of options. The OOjs UI library contains several types of
17719 * select widgets, including {@link OO.ui.ButtonSelectWidget button selects},
17720 * {@link OO.ui.RadioSelectWidget radio selects}, and {@link OO.ui.MenuSelectWidget
17723 * This class should be used together with OO.ui.OptionWidget or OO.ui.DecoratedOptionWidget. For more
17724 * information, please see the [OOjs UI documentation on MediaWiki][1].
17727 * // Example of a select widget with three options
17728 * var select = new OO.ui.SelectWidget( {
17730 * new OO.ui.OptionWidget( {
17732 * label: 'Option One',
17734 * new OO.ui.OptionWidget( {
17736 * label: 'Option Two',
17738 * new OO.ui.OptionWidget( {
17740 * label: 'Option Three',
17744 * $( 'body' ).append( select.$element );
17746 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
17750 * @extends OO.ui.Widget
17751 * @mixins OO.ui.mixin.GroupWidget
17754 * @param {Object} [config] Configuration options
17755 * @cfg {OO.ui.OptionWidget[]} [items] An array of options to add to the select.
17756 * Options are created with {@link OO.ui.OptionWidget OptionWidget} classes. See
17757 * the [OOjs UI documentation on MediaWiki] [2] for examples.
17758 * [2]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
17760 OO
.ui
.SelectWidget
= function OoUiSelectWidget( config
) {
17761 // Configuration initialization
17762 config
= config
|| {};
17764 // Parent constructor
17765 OO
.ui
.SelectWidget
.parent
.call( this, config
);
17767 // Mixin constructors
17768 OO
.ui
.mixin
.GroupWidget
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
17771 this.pressed
= false;
17772 this.selecting
= null;
17773 this.onMouseUpHandler
= this.onMouseUp
.bind( this );
17774 this.onMouseMoveHandler
= this.onMouseMove
.bind( this );
17775 this.onKeyDownHandler
= this.onKeyDown
.bind( this );
17776 this.onKeyPressHandler
= this.onKeyPress
.bind( this );
17777 this.keyPressBuffer
= '';
17778 this.keyPressBufferTimer
= null;
17781 this.connect( this, {
17784 this.$element
.on( {
17785 mousedown
: this.onMouseDown
.bind( this ),
17786 mouseover
: this.onMouseOver
.bind( this ),
17787 mouseleave
: this.onMouseLeave
.bind( this )
17792 .addClass( 'oo-ui-selectWidget oo-ui-selectWidget-depressed' )
17793 .attr( 'role', 'listbox' );
17794 if ( Array
.isArray( config
.items
) ) {
17795 this.addItems( config
.items
);
17801 OO
.inheritClass( OO
.ui
.SelectWidget
, OO
.ui
.Widget
);
17803 // Need to mixin base class as well
17804 OO
.mixinClass( OO
.ui
.SelectWidget
, OO
.ui
.mixin
.GroupElement
);
17805 OO
.mixinClass( OO
.ui
.SelectWidget
, OO
.ui
.mixin
.GroupWidget
);
17808 OO
.ui
.SelectWidget
.static.passAllFilter = function () {
17817 * A `highlight` event is emitted when the highlight is changed with the #highlightItem method.
17819 * @param {OO.ui.OptionWidget|null} item Highlighted item
17825 * A `press` event is emitted when the #pressItem method is used to programmatically modify the
17826 * pressed state of an option.
17828 * @param {OO.ui.OptionWidget|null} item Pressed item
17834 * A `select` event is emitted when the selection is modified programmatically with the #selectItem method.
17836 * @param {OO.ui.OptionWidget|null} item Selected item
17841 * A `choose` event is emitted when an item is chosen with the #chooseItem method.
17842 * @param {OO.ui.OptionWidget} item Chosen item
17848 * An `add` event is emitted when options are added to the select with the #addItems method.
17850 * @param {OO.ui.OptionWidget[]} items Added items
17851 * @param {number} index Index of insertion point
17857 * A `remove` event is emitted when options are removed from the select with the #clearItems
17858 * or #removeItems methods.
17860 * @param {OO.ui.OptionWidget[]} items Removed items
17866 * Handle mouse down events.
17869 * @param {jQuery.Event} e Mouse down event
17871 OO
.ui
.SelectWidget
.prototype.onMouseDown = function ( e
) {
17874 if ( !this.isDisabled() && e
.which
=== 1 ) {
17875 this.togglePressed( true );
17876 item
= this.getTargetItem( e
);
17877 if ( item
&& item
.isSelectable() ) {
17878 this.pressItem( item
);
17879 this.selecting
= item
;
17880 OO
.ui
.addCaptureEventListener(
17881 this.getElementDocument(),
17883 this.onMouseUpHandler
17885 OO
.ui
.addCaptureEventListener(
17886 this.getElementDocument(),
17888 this.onMouseMoveHandler
17896 * Handle mouse up events.
17899 * @param {jQuery.Event} e Mouse up event
17901 OO
.ui
.SelectWidget
.prototype.onMouseUp = function ( e
) {
17904 this.togglePressed( false );
17905 if ( !this.selecting
) {
17906 item
= this.getTargetItem( e
);
17907 if ( item
&& item
.isSelectable() ) {
17908 this.selecting
= item
;
17911 if ( !this.isDisabled() && e
.which
=== 1 && this.selecting
) {
17912 this.pressItem( null );
17913 this.chooseItem( this.selecting
);
17914 this.selecting
= null;
17917 OO
.ui
.removeCaptureEventListener( this.getElementDocument(), 'mouseup',
17918 this.onMouseUpHandler
);
17919 OO
.ui
.removeCaptureEventListener( this.getElementDocument(), 'mousemove',
17920 this.onMouseMoveHandler
);
17926 * Handle mouse move events.
17929 * @param {jQuery.Event} e Mouse move event
17931 OO
.ui
.SelectWidget
.prototype.onMouseMove = function ( e
) {
17934 if ( !this.isDisabled() && this.pressed
) {
17935 item
= this.getTargetItem( e
);
17936 if ( item
&& item
!== this.selecting
&& item
.isSelectable() ) {
17937 this.pressItem( item
);
17938 this.selecting
= item
;
17945 * Handle mouse over events.
17948 * @param {jQuery.Event} e Mouse over event
17950 OO
.ui
.SelectWidget
.prototype.onMouseOver = function ( e
) {
17953 if ( !this.isDisabled() ) {
17954 item
= this.getTargetItem( e
);
17955 this.highlightItem( item
&& item
.isHighlightable() ? item
: null );
17961 * Handle mouse leave events.
17964 * @param {jQuery.Event} e Mouse over event
17966 OO
.ui
.SelectWidget
.prototype.onMouseLeave = function () {
17967 if ( !this.isDisabled() ) {
17968 this.highlightItem( null );
17974 * Handle key down events.
17977 * @param {jQuery.Event} e Key down event
17979 OO
.ui
.SelectWidget
.prototype.onKeyDown = function ( e
) {
17982 currentItem
= this.getHighlightedItem() || this.getSelectedItem();
17984 if ( !this.isDisabled() && this.isVisible() ) {
17985 switch ( e
.keyCode
) {
17986 case OO
.ui
.Keys
.ENTER
:
17987 if ( currentItem
&& currentItem
.constructor.static.highlightable
) {
17988 // Was only highlighted, now let's select it. No-op if already selected.
17989 this.chooseItem( currentItem
);
17993 case OO
.ui
.Keys
.UP
:
17994 case OO
.ui
.Keys
.LEFT
:
17995 this.clearKeyPressBuffer();
17996 nextItem
= this.getRelativeSelectableItem( currentItem
, -1 );
17999 case OO
.ui
.Keys
.DOWN
:
18000 case OO
.ui
.Keys
.RIGHT
:
18001 this.clearKeyPressBuffer();
18002 nextItem
= this.getRelativeSelectableItem( currentItem
, 1 );
18005 case OO
.ui
.Keys
.ESCAPE
:
18006 case OO
.ui
.Keys
.TAB
:
18007 if ( currentItem
&& currentItem
.constructor.static.highlightable
) {
18008 currentItem
.setHighlighted( false );
18010 this.unbindKeyDownListener();
18011 this.unbindKeyPressListener();
18012 // Don't prevent tabbing away / defocusing
18018 if ( nextItem
.constructor.static.highlightable
) {
18019 this.highlightItem( nextItem
);
18021 this.chooseItem( nextItem
);
18023 nextItem
.scrollElementIntoView();
18027 // Can't just return false, because e is not always a jQuery event
18028 e
.preventDefault();
18029 e
.stopPropagation();
18035 * Bind key down listener.
18039 OO
.ui
.SelectWidget
.prototype.bindKeyDownListener = function () {
18040 OO
.ui
.addCaptureEventListener( this.getElementWindow(), 'keydown', this.onKeyDownHandler
);
18044 * Unbind key down listener.
18048 OO
.ui
.SelectWidget
.prototype.unbindKeyDownListener = function () {
18049 OO
.ui
.removeCaptureEventListener( this.getElementWindow(), 'keydown', this.onKeyDownHandler
);
18053 * Clear the key-press buffer
18057 OO
.ui
.SelectWidget
.prototype.clearKeyPressBuffer = function () {
18058 if ( this.keyPressBufferTimer
) {
18059 clearTimeout( this.keyPressBufferTimer
);
18060 this.keyPressBufferTimer
= null;
18062 this.keyPressBuffer
= '';
18066 * Handle key press events.
18069 * @param {jQuery.Event} e Key press event
18071 OO
.ui
.SelectWidget
.prototype.onKeyPress = function ( e
) {
18072 var c
, filter
, item
;
18074 if ( !e
.charCode
) {
18075 if ( e
.keyCode
=== OO
.ui
.Keys
.BACKSPACE
&& this.keyPressBuffer
!== '' ) {
18076 this.keyPressBuffer
= this.keyPressBuffer
.substr( 0, this.keyPressBuffer
.length
- 1 );
18081 if ( String
.fromCodePoint
) {
18082 c
= String
.fromCodePoint( e
.charCode
);
18084 c
= String
.fromCharCode( e
.charCode
);
18087 if ( this.keyPressBufferTimer
) {
18088 clearTimeout( this.keyPressBufferTimer
);
18090 this.keyPressBufferTimer
= setTimeout( this.clearKeyPressBuffer
.bind( this ), 1500 );
18092 item
= this.getHighlightedItem() || this.getSelectedItem();
18094 if ( this.keyPressBuffer
=== c
) {
18095 // Common (if weird) special case: typing "xxxx" will cycle through all
18096 // the items beginning with "x".
18098 item
= this.getRelativeSelectableItem( item
, 1 );
18101 this.keyPressBuffer
+= c
;
18104 filter
= this.getItemMatcher( this.keyPressBuffer
, false );
18105 if ( !item
|| !filter( item
) ) {
18106 item
= this.getRelativeSelectableItem( item
, 1, filter
);
18109 if ( item
.constructor.static.highlightable
) {
18110 this.highlightItem( item
);
18112 this.chooseItem( item
);
18114 item
.scrollElementIntoView();
18121 * Get a matcher for the specific string
18124 * @param {string} s String to match against items
18125 * @param {boolean} [exact=false] Only accept exact matches
18126 * @return {Function} function ( OO.ui.OptionItem ) => boolean
18128 OO
.ui
.SelectWidget
.prototype.getItemMatcher = function ( s
, exact
) {
18131 if ( s
.normalize
) {
18134 s
= exact
? s
.trim() : s
.replace( /^\s+/, '' );
18135 re
= '^\\s*' + s
.replace( /([\\{}()|.?*+\-\^$\[\]])/g, '\\$1' ).replace( /\s+/g, '\\s+' );
18139 re
= new RegExp( re
, 'i' );
18140 return function ( item
) {
18141 var l
= item
.getLabel();
18142 if ( typeof l
!== 'string' ) {
18143 l
= item
.$label
.text();
18145 if ( l
.normalize
) {
18148 return re
.test( l
);
18153 * Bind key press listener.
18157 OO
.ui
.SelectWidget
.prototype.bindKeyPressListener = function () {
18158 OO
.ui
.addCaptureEventListener( this.getElementWindow(), 'keypress', this.onKeyPressHandler
);
18162 * Unbind key down listener.
18164 * If you override this, be sure to call this.clearKeyPressBuffer() from your
18169 OO
.ui
.SelectWidget
.prototype.unbindKeyPressListener = function () {
18170 OO
.ui
.removeCaptureEventListener( this.getElementWindow(), 'keypress', this.onKeyPressHandler
);
18171 this.clearKeyPressBuffer();
18175 * Visibility change handler
18178 * @param {boolean} visible
18180 OO
.ui
.SelectWidget
.prototype.onToggle = function ( visible
) {
18182 this.clearKeyPressBuffer();
18187 * Get the closest item to a jQuery.Event.
18190 * @param {jQuery.Event} e
18191 * @return {OO.ui.OptionWidget|null} Outline item widget, `null` if none was found
18193 OO
.ui
.SelectWidget
.prototype.getTargetItem = function ( e
) {
18194 return $( e
.target
).closest( '.oo-ui-optionWidget' ).data( 'oo-ui-optionWidget' ) || null;
18198 * Get selected item.
18200 * @return {OO.ui.OptionWidget|null} Selected item, `null` if no item is selected
18202 OO
.ui
.SelectWidget
.prototype.getSelectedItem = function () {
18205 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
18206 if ( this.items
[ i
].isSelected() ) {
18207 return this.items
[ i
];
18214 * Get highlighted item.
18216 * @return {OO.ui.OptionWidget|null} Highlighted item, `null` if no item is highlighted
18218 OO
.ui
.SelectWidget
.prototype.getHighlightedItem = function () {
18221 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
18222 if ( this.items
[ i
].isHighlighted() ) {
18223 return this.items
[ i
];
18230 * Toggle pressed state.
18232 * Press is a state that occurs when a user mouses down on an item, but
18233 * has not yet let go of the mouse. The item may appear selected, but it will not be selected
18234 * until the user releases the mouse.
18236 * @param {boolean} pressed An option is being pressed
18238 OO
.ui
.SelectWidget
.prototype.togglePressed = function ( pressed
) {
18239 if ( pressed
=== undefined ) {
18240 pressed
= !this.pressed
;
18242 if ( pressed
!== this.pressed
) {
18244 .toggleClass( 'oo-ui-selectWidget-pressed', pressed
)
18245 .toggleClass( 'oo-ui-selectWidget-depressed', !pressed
);
18246 this.pressed
= pressed
;
18251 * Highlight an option. If the `item` param is omitted, no options will be highlighted
18252 * and any existing highlight will be removed. The highlight is mutually exclusive.
18254 * @param {OO.ui.OptionWidget} [item] Item to highlight, omit for no highlight
18258 OO
.ui
.SelectWidget
.prototype.highlightItem = function ( item
) {
18259 var i
, len
, highlighted
,
18262 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
18263 highlighted
= this.items
[ i
] === item
;
18264 if ( this.items
[ i
].isHighlighted() !== highlighted
) {
18265 this.items
[ i
].setHighlighted( highlighted
);
18270 this.emit( 'highlight', item
);
18277 * Fetch an item by its label.
18279 * @param {string} label Label of the item to select.
18280 * @param {boolean} [prefix=false] Allow a prefix match, if only a single item matches
18281 * @return {OO.ui.Element|null} Item with equivalent label, `null` if none exists
18283 OO
.ui
.SelectWidget
.prototype.getItemFromLabel = function ( label
, prefix
) {
18284 var i
, item
, found
,
18285 len
= this.items
.length
,
18286 filter
= this.getItemMatcher( label
, true );
18288 for ( i
= 0; i
< len
; i
++ ) {
18289 item
= this.items
[ i
];
18290 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() && filter( item
) ) {
18297 filter
= this.getItemMatcher( label
, false );
18298 for ( i
= 0; i
< len
; i
++ ) {
18299 item
= this.items
[ i
];
18300 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() && filter( item
) ) {
18316 * Programmatically select an option by its label. If the item does not exist,
18317 * all options will be deselected.
18319 * @param {string} [label] Label of the item to select.
18320 * @param {boolean} [prefix=false] Allow a prefix match, if only a single item matches
18324 OO
.ui
.SelectWidget
.prototype.selectItemByLabel = function ( label
, prefix
) {
18325 var itemFromLabel
= this.getItemFromLabel( label
, !!prefix
);
18326 if ( label
=== undefined || !itemFromLabel
) {
18327 return this.selectItem();
18329 return this.selectItem( itemFromLabel
);
18333 * Programmatically select an option by its data. If the `data` parameter is omitted,
18334 * or if the item does not exist, all options will be deselected.
18336 * @param {Object|string} [data] Value of the item to select, omit to deselect all
18340 OO
.ui
.SelectWidget
.prototype.selectItemByData = function ( data
) {
18341 var itemFromData
= this.getItemFromData( data
);
18342 if ( data
=== undefined || !itemFromData
) {
18343 return this.selectItem();
18345 return this.selectItem( itemFromData
);
18349 * Programmatically select an option by its reference. If the `item` parameter is omitted,
18350 * all options will be deselected.
18352 * @param {OO.ui.OptionWidget} [item] Item to select, omit to deselect all
18356 OO
.ui
.SelectWidget
.prototype.selectItem = function ( item
) {
18357 var i
, len
, selected
,
18360 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
18361 selected
= this.items
[ i
] === item
;
18362 if ( this.items
[ i
].isSelected() !== selected
) {
18363 this.items
[ i
].setSelected( selected
);
18368 this.emit( 'select', item
);
18377 * Press is a state that occurs when a user mouses down on an item, but has not
18378 * yet let go of the mouse. The item may appear selected, but it will not be selected until the user
18379 * releases the mouse.
18381 * @param {OO.ui.OptionWidget} [item] Item to press, omit to depress all
18385 OO
.ui
.SelectWidget
.prototype.pressItem = function ( item
) {
18386 var i
, len
, pressed
,
18389 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
18390 pressed
= this.items
[ i
] === item
;
18391 if ( this.items
[ i
].isPressed() !== pressed
) {
18392 this.items
[ i
].setPressed( pressed
);
18397 this.emit( 'press', item
);
18406 * Note that ‘choose’ should never be modified programmatically. A user can choose
18407 * an option with the keyboard or mouse and it becomes selected. To select an item programmatically,
18408 * use the #selectItem method.
18410 * This method is identical to #selectItem, but may vary in subclasses that take additional action
18411 * when users choose an item with the keyboard or mouse.
18413 * @param {OO.ui.OptionWidget} item Item to choose
18417 OO
.ui
.SelectWidget
.prototype.chooseItem = function ( item
) {
18419 this.selectItem( item
);
18420 this.emit( 'choose', item
);
18427 * Get an option by its position relative to the specified item (or to the start of the option array,
18428 * if item is `null`). The direction in which to search through the option array is specified with a
18429 * number: -1 for reverse (the default) or 1 for forward. The method will return an option, or
18430 * `null` if there are no options in the array.
18432 * @param {OO.ui.OptionWidget|null} item Item to describe the start position, or `null` to start at the beginning of the array.
18433 * @param {number} direction Direction to move in: -1 to move backward, 1 to move forward
18434 * @param {Function} filter Only consider items for which this function returns
18435 * true. Function takes an OO.ui.OptionWidget and returns a boolean.
18436 * @return {OO.ui.OptionWidget|null} Item at position, `null` if there are no items in the select
18438 OO
.ui
.SelectWidget
.prototype.getRelativeSelectableItem = function ( item
, direction
, filter
) {
18439 var currentIndex
, nextIndex
, i
,
18440 increase
= direction
> 0 ? 1 : -1,
18441 len
= this.items
.length
;
18443 if ( !$.isFunction( filter
) ) {
18444 filter
= OO
.ui
.SelectWidget
.static.passAllFilter
;
18447 if ( item
instanceof OO
.ui
.OptionWidget
) {
18448 currentIndex
= this.items
.indexOf( item
);
18449 nextIndex
= ( currentIndex
+ increase
+ len
) % len
;
18451 // If no item is selected and moving forward, start at the beginning.
18452 // If moving backward, start at the end.
18453 nextIndex
= direction
> 0 ? 0 : len
- 1;
18456 for ( i
= 0; i
< len
; i
++ ) {
18457 item
= this.items
[ nextIndex
];
18458 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() && filter( item
) ) {
18461 nextIndex
= ( nextIndex
+ increase
+ len
) % len
;
18467 * Get the next selectable item or `null` if there are no selectable items.
18468 * Disabled options and menu-section markers and breaks are not selectable.
18470 * @return {OO.ui.OptionWidget|null} Item, `null` if there aren't any selectable items
18472 OO
.ui
.SelectWidget
.prototype.getFirstSelectableItem = function () {
18475 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
18476 item
= this.items
[ i
];
18477 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() ) {
18486 * Add an array of options to the select. Optionally, an index number can be used to
18487 * specify an insertion point.
18489 * @param {OO.ui.OptionWidget[]} items Items to add
18490 * @param {number} [index] Index to insert items after
18494 OO
.ui
.SelectWidget
.prototype.addItems = function ( items
, index
) {
18496 OO
.ui
.mixin
.GroupWidget
.prototype.addItems
.call( this, items
, index
);
18498 // Always provide an index, even if it was omitted
18499 this.emit( 'add', items
, index
=== undefined ? this.items
.length
- items
.length
- 1 : index
);
18505 * Remove the specified array of options from the select. Options will be detached
18506 * from the DOM, not removed, so they can be reused later. To remove all options from
18507 * the select, you may wish to use the #clearItems method instead.
18509 * @param {OO.ui.OptionWidget[]} items Items to remove
18513 OO
.ui
.SelectWidget
.prototype.removeItems = function ( items
) {
18516 // Deselect items being removed
18517 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
18519 if ( item
.isSelected() ) {
18520 this.selectItem( null );
18525 OO
.ui
.mixin
.GroupWidget
.prototype.removeItems
.call( this, items
);
18527 this.emit( 'remove', items
);
18533 * Clear all options from the select. Options will be detached from the DOM, not removed,
18534 * so that they can be reused later. To remove a subset of options from the select, use
18535 * the #removeItems method.
18540 OO
.ui
.SelectWidget
.prototype.clearItems = function () {
18541 var items
= this.items
.slice();
18544 OO
.ui
.mixin
.GroupWidget
.prototype.clearItems
.call( this );
18547 this.selectItem( null );
18549 this.emit( 'remove', items
);
18555 * ButtonSelectWidget is a {@link OO.ui.SelectWidget select widget} that contains
18556 * button options and is used together with
18557 * OO.ui.ButtonOptionWidget. The ButtonSelectWidget provides an interface for
18558 * highlighting, choosing, and selecting mutually exclusive options. Please see
18559 * the [OOjs UI documentation on MediaWiki] [1] for more information.
18562 * // Example: A ButtonSelectWidget that contains three ButtonOptionWidgets
18563 * var option1 = new OO.ui.ButtonOptionWidget( {
18565 * label: 'Option 1',
18566 * title: 'Button option 1'
18569 * var option2 = new OO.ui.ButtonOptionWidget( {
18571 * label: 'Option 2',
18572 * title: 'Button option 2'
18575 * var option3 = new OO.ui.ButtonOptionWidget( {
18577 * label: 'Option 3',
18578 * title: 'Button option 3'
18581 * var buttonSelect=new OO.ui.ButtonSelectWidget( {
18582 * items: [ option1, option2, option3 ]
18584 * $( 'body' ).append( buttonSelect.$element );
18586 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
18589 * @extends OO.ui.SelectWidget
18590 * @mixins OO.ui.mixin.TabIndexedElement
18593 * @param {Object} [config] Configuration options
18595 OO
.ui
.ButtonSelectWidget
= function OoUiButtonSelectWidget( config
) {
18596 // Parent constructor
18597 OO
.ui
.ButtonSelectWidget
.parent
.call( this, config
);
18599 // Mixin constructors
18600 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
18603 this.$element
.on( {
18604 focus
: this.bindKeyDownListener
.bind( this ),
18605 blur
: this.unbindKeyDownListener
.bind( this )
18609 this.$element
.addClass( 'oo-ui-buttonSelectWidget' );
18614 OO
.inheritClass( OO
.ui
.ButtonSelectWidget
, OO
.ui
.SelectWidget
);
18615 OO
.mixinClass( OO
.ui
.ButtonSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
18618 * RadioSelectWidget is a {@link OO.ui.SelectWidget select widget} that contains radio
18619 * options and is used together with OO.ui.RadioOptionWidget. The RadioSelectWidget provides
18620 * an interface for adding, removing and selecting options.
18621 * Please see the [OOjs UI documentation on MediaWiki][1] for more information.
18623 * If you want to use this within a HTML form, such as a OO.ui.FormLayout, use
18624 * OO.ui.RadioSelectInputWidget instead.
18627 * // A RadioSelectWidget with RadioOptions.
18628 * var option1 = new OO.ui.RadioOptionWidget( {
18630 * label: 'Selected radio option'
18633 * var option2 = new OO.ui.RadioOptionWidget( {
18635 * label: 'Unselected radio option'
18638 * var radioSelect=new OO.ui.RadioSelectWidget( {
18639 * items: [ option1, option2 ]
18642 * // Select 'option 1' using the RadioSelectWidget's selectItem() method.
18643 * radioSelect.selectItem( option1 );
18645 * $( 'body' ).append( radioSelect.$element );
18647 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
18651 * @extends OO.ui.SelectWidget
18652 * @mixins OO.ui.mixin.TabIndexedElement
18655 * @param {Object} [config] Configuration options
18657 OO
.ui
.RadioSelectWidget
= function OoUiRadioSelectWidget( config
) {
18658 // Parent constructor
18659 OO
.ui
.RadioSelectWidget
.parent
.call( this, config
);
18661 // Mixin constructors
18662 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
18665 this.$element
.on( {
18666 focus
: this.bindKeyDownListener
.bind( this ),
18667 blur
: this.unbindKeyDownListener
.bind( this )
18672 .addClass( 'oo-ui-radioSelectWidget' )
18673 .attr( 'role', 'radiogroup' );
18678 OO
.inheritClass( OO
.ui
.RadioSelectWidget
, OO
.ui
.SelectWidget
);
18679 OO
.mixinClass( OO
.ui
.RadioSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
18682 * MenuSelectWidget is a {@link OO.ui.SelectWidget select widget} that contains options and
18683 * is used together with OO.ui.MenuOptionWidget. It is designed be used as part of another widget.
18684 * See {@link OO.ui.DropdownWidget DropdownWidget}, {@link OO.ui.ComboBoxWidget ComboBoxWidget},
18685 * and {@link OO.ui.mixin.LookupElement LookupElement} for examples of widgets that contain menus.
18686 * MenuSelectWidgets themselves are not instantiated directly, rather subclassed
18687 * and customized to be opened, closed, and displayed as needed.
18689 * By default, menus are clipped to the visible viewport and are not visible when a user presses the
18690 * mouse outside the menu.
18692 * Menus also have support for keyboard interaction:
18694 * - Enter/Return key: choose and select a menu option
18695 * - Up-arrow key: highlight the previous menu option
18696 * - Down-arrow key: highlight the next menu option
18697 * - Esc key: hide the menu
18699 * Please see the [OOjs UI documentation on MediaWiki][1] for more information.
18700 * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Selects_and_Options
18703 * @extends OO.ui.SelectWidget
18704 * @mixins OO.ui.mixin.ClippableElement
18707 * @param {Object} [config] Configuration options
18708 * @cfg {OO.ui.TextInputWidget} [input] Text input used to implement option highlighting for menu items that match
18709 * the text the user types. This config is used by {@link OO.ui.ComboBoxWidget ComboBoxWidget}
18710 * and {@link OO.ui.mixin.LookupElement LookupElement}
18711 * @cfg {jQuery} [$input] Text input used to implement option highlighting for menu items that match
18712 * the text the user types. This config is used by {@link OO.ui.CapsuleMultiSelectWidget CapsuleMultiSelectWidget}
18713 * @cfg {OO.ui.Widget} [widget] Widget associated with the menu's active state. If the user clicks the mouse
18714 * anywhere on the page outside of this widget, the menu is hidden. For example, if there is a button
18715 * that toggles the menu's visibility on click, the menu will be hidden then re-shown when the user clicks
18716 * that button, unless the button (or its parent widget) is passed in here.
18717 * @cfg {boolean} [autoHide=true] Hide the menu when the mouse is pressed outside the menu.
18718 * @cfg {boolean} [filterFromInput=false] Filter the displayed options from the input
18720 OO
.ui
.MenuSelectWidget
= function OoUiMenuSelectWidget( config
) {
18721 // Configuration initialization
18722 config
= config
|| {};
18724 // Parent constructor
18725 OO
.ui
.MenuSelectWidget
.parent
.call( this, config
);
18727 // Mixin constructors
18728 OO
.ui
.mixin
.ClippableElement
.call( this, $.extend( {}, config
, { $clippable
: this.$group
} ) );
18731 this.newItems
= null;
18732 this.autoHide
= config
.autoHide
=== undefined || !!config
.autoHide
;
18733 this.filterFromInput
= !!config
.filterFromInput
;
18734 this.$input
= config
.$input
? config
.$input
: config
.input
? config
.input
.$input
: null;
18735 this.$widget
= config
.widget
? config
.widget
.$element
: null;
18736 this.onDocumentMouseDownHandler
= this.onDocumentMouseDown
.bind( this );
18737 this.onInputEditHandler
= OO
.ui
.debounce( this.updateItemVisibility
.bind( this ), 100 );
18741 .addClass( 'oo-ui-menuSelectWidget' )
18742 .attr( 'role', 'menu' );
18744 // Initially hidden - using #toggle may cause errors if subclasses override toggle with methods
18745 // that reference properties not initialized at that time of parent class construction
18746 // TODO: Find a better way to handle post-constructor setup
18747 this.visible
= false;
18748 this.$element
.addClass( 'oo-ui-element-hidden' );
18753 OO
.inheritClass( OO
.ui
.MenuSelectWidget
, OO
.ui
.SelectWidget
);
18754 OO
.mixinClass( OO
.ui
.MenuSelectWidget
, OO
.ui
.mixin
.ClippableElement
);
18759 * Handles document mouse down events.
18762 * @param {jQuery.Event} e Key down event
18764 OO
.ui
.MenuSelectWidget
.prototype.onDocumentMouseDown = function ( e
) {
18766 !OO
.ui
.contains( this.$element
[ 0 ], e
.target
, true ) &&
18767 ( !this.$widget
|| !OO
.ui
.contains( this.$widget
[ 0 ], e
.target
, true ) )
18769 this.toggle( false );
18776 OO
.ui
.MenuSelectWidget
.prototype.onKeyDown = function ( e
) {
18777 var currentItem
= this.getHighlightedItem() || this.getSelectedItem();
18779 if ( !this.isDisabled() && this.isVisible() ) {
18780 switch ( e
.keyCode
) {
18781 case OO
.ui
.Keys
.LEFT
:
18782 case OO
.ui
.Keys
.RIGHT
:
18783 // Do nothing if a text field is associated, arrow keys will be handled natively
18784 if ( !this.$input
) {
18785 OO
.ui
.MenuSelectWidget
.parent
.prototype.onKeyDown
.call( this, e
);
18788 case OO
.ui
.Keys
.ESCAPE
:
18789 case OO
.ui
.Keys
.TAB
:
18790 if ( currentItem
) {
18791 currentItem
.setHighlighted( false );
18793 this.toggle( false );
18794 // Don't prevent tabbing away, prevent defocusing
18795 if ( e
.keyCode
=== OO
.ui
.Keys
.ESCAPE
) {
18796 e
.preventDefault();
18797 e
.stopPropagation();
18801 OO
.ui
.MenuSelectWidget
.parent
.prototype.onKeyDown
.call( this, e
);
18808 * Update menu item visibility after input changes.
18811 OO
.ui
.MenuSelectWidget
.prototype.updateItemVisibility = function () {
18813 len
= this.items
.length
,
18814 showAll
= !this.isVisible(),
18815 filter
= showAll
? null : this.getItemMatcher( this.$input
.val() );
18817 for ( i
= 0; i
< len
; i
++ ) {
18818 item
= this.items
[ i
];
18819 if ( item
instanceof OO
.ui
.OptionWidget
) {
18820 item
.toggle( showAll
|| filter( item
) );
18824 // Reevaluate clipping
18831 OO
.ui
.MenuSelectWidget
.prototype.bindKeyDownListener = function () {
18832 if ( this.$input
) {
18833 this.$input
.on( 'keydown', this.onKeyDownHandler
);
18835 OO
.ui
.MenuSelectWidget
.parent
.prototype.bindKeyDownListener
.call( this );
18842 OO
.ui
.MenuSelectWidget
.prototype.unbindKeyDownListener = function () {
18843 if ( this.$input
) {
18844 this.$input
.off( 'keydown', this.onKeyDownHandler
);
18846 OO
.ui
.MenuSelectWidget
.parent
.prototype.unbindKeyDownListener
.call( this );
18853 OO
.ui
.MenuSelectWidget
.prototype.bindKeyPressListener = function () {
18854 if ( this.$input
) {
18855 if ( this.filterFromInput
) {
18856 this.$input
.on( 'keydown mouseup cut paste change input select', this.onInputEditHandler
);
18859 OO
.ui
.MenuSelectWidget
.parent
.prototype.bindKeyPressListener
.call( this );
18866 OO
.ui
.MenuSelectWidget
.prototype.unbindKeyPressListener = function () {
18867 if ( this.$input
) {
18868 if ( this.filterFromInput
) {
18869 this.$input
.off( 'keydown mouseup cut paste change input select', this.onInputEditHandler
);
18870 this.updateItemVisibility();
18873 OO
.ui
.MenuSelectWidget
.parent
.prototype.unbindKeyPressListener
.call( this );
18880 * When a user chooses an item, the menu is closed.
18882 * Note that ‘choose’ should never be modified programmatically. A user can choose an option with the keyboard
18883 * or mouse and it becomes selected. To select an item programmatically, use the #selectItem method.
18884 * @param {OO.ui.OptionWidget} item Item to choose
18887 OO
.ui
.MenuSelectWidget
.prototype.chooseItem = function ( item
) {
18888 OO
.ui
.MenuSelectWidget
.parent
.prototype.chooseItem
.call( this, item
);
18889 this.toggle( false );
18896 OO
.ui
.MenuSelectWidget
.prototype.addItems = function ( items
, index
) {
18900 OO
.ui
.MenuSelectWidget
.parent
.prototype.addItems
.call( this, items
, index
);
18903 if ( !this.newItems
) {
18904 this.newItems
= [];
18907 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
18909 if ( this.isVisible() ) {
18910 // Defer fitting label until item has been attached
18913 this.newItems
.push( item
);
18917 // Reevaluate clipping
18926 OO
.ui
.MenuSelectWidget
.prototype.removeItems = function ( items
) {
18928 OO
.ui
.MenuSelectWidget
.parent
.prototype.removeItems
.call( this, items
);
18930 // Reevaluate clipping
18939 OO
.ui
.MenuSelectWidget
.prototype.clearItems = function () {
18941 OO
.ui
.MenuSelectWidget
.parent
.prototype.clearItems
.call( this );
18943 // Reevaluate clipping
18952 OO
.ui
.MenuSelectWidget
.prototype.toggle = function ( visible
) {
18953 var i
, len
, change
;
18955 visible
= ( visible
=== undefined ? !this.visible
: !!visible
) && !!this.items
.length
;
18956 change
= visible
!== this.isVisible();
18959 OO
.ui
.MenuSelectWidget
.parent
.prototype.toggle
.call( this, visible
);
18963 this.bindKeyDownListener();
18964 this.bindKeyPressListener();
18966 if ( this.newItems
&& this.newItems
.length
) {
18967 for ( i
= 0, len
= this.newItems
.length
; i
< len
; i
++ ) {
18968 this.newItems
[ i
].fitLabel();
18970 this.newItems
= null;
18972 this.toggleClipping( true );
18975 if ( this.autoHide
) {
18976 OO
.ui
.addCaptureEventListener( this.getElementDocument(), 'mousedown', this.onDocumentMouseDownHandler
);
18979 this.unbindKeyDownListener();
18980 this.unbindKeyPressListener();
18981 OO
.ui
.removeCaptureEventListener( this.getElementDocument(), 'mousedown', this.onDocumentMouseDownHandler
);
18982 this.toggleClipping( false );
18990 * FloatingMenuSelectWidget is a menu that will stick under a specified
18991 * container, even when it is inserted elsewhere in the document (for example,
18992 * in a OO.ui.Window's $overlay). This is sometimes necessary to prevent the
18993 * menu from being clipped too aggresively.
18995 * The menu's position is automatically calculated and maintained when the menu
18996 * is toggled or the window is resized.
18998 * See OO.ui.ComboBoxWidget for an example of a widget that uses this class.
19001 * @extends OO.ui.MenuSelectWidget
19002 * @mixins OO.ui.mixin.FloatableElement
19005 * @param {OO.ui.Widget} [inputWidget] Widget to provide the menu for.
19006 * Deprecated, omit this parameter and specify `$container` instead.
19007 * @param {Object} [config] Configuration options
19008 * @cfg {jQuery} [$container=inputWidget.$element] Element to render menu under
19010 OO
.ui
.FloatingMenuSelectWidget
= function OoUiFloatingMenuSelectWidget( inputWidget
, config
) {
19011 // Allow 'inputWidget' parameter and config for backwards compatibility
19012 if ( OO
.isPlainObject( inputWidget
) && config
=== undefined ) {
19013 config
= inputWidget
;
19014 inputWidget
= config
.inputWidget
;
19017 // Configuration initialization
19018 config
= config
|| {};
19020 // Parent constructor
19021 OO
.ui
.FloatingMenuSelectWidget
.parent
.call( this, config
);
19023 // Properties (must be set before mixin constructors)
19024 this.inputWidget
= inputWidget
; // For backwards compatibility
19025 this.$container
= config
.$container
|| this.inputWidget
.$element
;
19027 // Mixins constructors
19028 OO
.ui
.mixin
.FloatableElement
.call( this, $.extend( {}, config
, { $floatableContainer
: this.$container
} ) );
19031 this.$element
.addClass( 'oo-ui-floatingMenuSelectWidget' );
19032 // For backwards compatibility
19033 this.$element
.addClass( 'oo-ui-textInputMenuSelectWidget' );
19038 OO
.inheritClass( OO
.ui
.FloatingMenuSelectWidget
, OO
.ui
.MenuSelectWidget
);
19039 OO
.mixinClass( OO
.ui
.FloatingMenuSelectWidget
, OO
.ui
.mixin
.FloatableElement
);
19041 // For backwards compatibility
19042 OO
.ui
.TextInputMenuSelectWidget
= OO
.ui
.FloatingMenuSelectWidget
;
19049 OO
.ui
.FloatingMenuSelectWidget
.prototype.toggle = function ( visible
) {
19051 visible
= visible
=== undefined ? !this.isVisible() : !!visible
;
19052 change
= visible
!== this.isVisible();
19054 if ( change
&& visible
) {
19055 // Make sure the width is set before the parent method runs.
19056 this.setIdealSize( this.$container
.width() );
19060 // This will call this.clip(), which is nonsensical since we're not positioned yet...
19061 OO
.ui
.FloatingMenuSelectWidget
.parent
.prototype.toggle
.call( this, visible
);
19064 this.togglePositioning( this.isVisible() );
19071 * OutlineSelectWidget is a structured list that contains {@link OO.ui.OutlineOptionWidget outline options}
19072 * A set of controls can be provided with an {@link OO.ui.OutlineControlsWidget outline controls} widget.
19074 * **Currently, this class is only used by {@link OO.ui.BookletLayout booklet layouts}.**
19077 * @extends OO.ui.SelectWidget
19078 * @mixins OO.ui.mixin.TabIndexedElement
19081 * @param {Object} [config] Configuration options
19083 OO
.ui
.OutlineSelectWidget
= function OoUiOutlineSelectWidget( config
) {
19084 // Parent constructor
19085 OO
.ui
.OutlineSelectWidget
.parent
.call( this, config
);
19087 // Mixin constructors
19088 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
19091 this.$element
.on( {
19092 focus
: this.bindKeyDownListener
.bind( this ),
19093 blur
: this.unbindKeyDownListener
.bind( this )
19097 this.$element
.addClass( 'oo-ui-outlineSelectWidget' );
19102 OO
.inheritClass( OO
.ui
.OutlineSelectWidget
, OO
.ui
.SelectWidget
);
19103 OO
.mixinClass( OO
.ui
.OutlineSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
19106 * TabSelectWidget is a list that contains {@link OO.ui.TabOptionWidget tab options}
19108 * **Currently, this class is only used by {@link OO.ui.IndexLayout index layouts}.**
19111 * @extends OO.ui.SelectWidget
19112 * @mixins OO.ui.mixin.TabIndexedElement
19115 * @param {Object} [config] Configuration options
19117 OO
.ui
.TabSelectWidget
= function OoUiTabSelectWidget( config
) {
19118 // Parent constructor
19119 OO
.ui
.TabSelectWidget
.parent
.call( this, config
);
19121 // Mixin constructors
19122 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
19125 this.$element
.on( {
19126 focus
: this.bindKeyDownListener
.bind( this ),
19127 blur
: this.unbindKeyDownListener
.bind( this )
19131 this.$element
.addClass( 'oo-ui-tabSelectWidget' );
19136 OO
.inheritClass( OO
.ui
.TabSelectWidget
, OO
.ui
.SelectWidget
);
19137 OO
.mixinClass( OO
.ui
.TabSelectWidget
, OO
.ui
.mixin
.TabIndexedElement
);
19140 * NumberInputWidgets combine a {@link OO.ui.TextInputWidget text input} (where a value
19141 * can be entered manually) and two {@link OO.ui.ButtonWidget button widgets}
19142 * (to adjust the value in increments) to allow the user to enter a number.
19145 * // Example: A NumberInputWidget.
19146 * var numberInput = new OO.ui.NumberInputWidget( {
19147 * label: 'NumberInputWidget',
19148 * input: { value: 5, min: 1, max: 10 }
19150 * $( 'body' ).append( numberInput.$element );
19153 * @extends OO.ui.Widget
19156 * @param {Object} [config] Configuration options
19157 * @cfg {Object} [input] Configuration options to pass to the {@link OO.ui.TextInputWidget text input widget}.
19158 * @cfg {Object} [minusButton] Configuration options to pass to the {@link OO.ui.ButtonWidget decrementing button widget}.
19159 * @cfg {Object} [plusButton] Configuration options to pass to the {@link OO.ui.ButtonWidget incrementing button widget}.
19160 * @cfg {boolean} [isInteger=false] Whether the field accepts only integer values.
19161 * @cfg {number} [min=-Infinity] Minimum allowed value
19162 * @cfg {number} [max=Infinity] Maximum allowed value
19163 * @cfg {number} [step=1] Delta when using the buttons or up/down arrow keys
19164 * @cfg {number|null} [pageStep] Delta when using the page-up/page-down keys. Defaults to 10 times #step.
19166 OO
.ui
.NumberInputWidget
= function OoUiNumberInputWidget( config
) {
19167 // Configuration initialization
19168 config
= $.extend( {
19176 // Parent constructor
19177 OO
.ui
.NumberInputWidget
.parent
.call( this, config
);
19180 this.input
= new OO
.ui
.TextInputWidget( $.extend(
19182 disabled
: this.isDisabled()
19186 this.minusButton
= new OO
.ui
.ButtonWidget( $.extend(
19188 disabled
: this.isDisabled(),
19191 config
.minusButton
,
19193 classes
: [ 'oo-ui-numberInputWidget-minusButton' ],
19197 this.plusButton
= new OO
.ui
.ButtonWidget( $.extend(
19199 disabled
: this.isDisabled(),
19204 classes
: [ 'oo-ui-numberInputWidget-plusButton' ],
19210 this.input
.connect( this, {
19211 change
: this.emit
.bind( this, 'change' ),
19212 enter
: this.emit
.bind( this, 'enter' )
19214 this.input
.$input
.on( {
19215 keydown
: this.onKeyDown
.bind( this ),
19216 'wheel mousewheel DOMMouseScroll': this.onWheel
.bind( this )
19218 this.plusButton
.connect( this, {
19219 click
: [ 'onButtonClick', +1 ]
19221 this.minusButton
.connect( this, {
19222 click
: [ 'onButtonClick', -1 ]
19226 this.setIsInteger( !!config
.isInteger
);
19227 this.setRange( config
.min
, config
.max
);
19228 this.setStep( config
.step
, config
.pageStep
);
19230 this.$field
= $( '<div>' ).addClass( 'oo-ui-numberInputWidget-field' )
19232 this.minusButton
.$element
,
19233 this.input
.$element
,
19234 this.plusButton
.$element
19236 this.$element
.addClass( 'oo-ui-numberInputWidget' ).append( this.$field
);
19237 this.input
.setValidation( this.validateNumber
.bind( this ) );
19242 OO
.inheritClass( OO
.ui
.NumberInputWidget
, OO
.ui
.Widget
);
19247 * A `change` event is emitted when the value of the input changes.
19253 * An `enter` event is emitted when the user presses 'enter' inside the text box.
19261 * Set whether only integers are allowed
19262 * @param {boolean} flag
19264 OO
.ui
.NumberInputWidget
.prototype.setIsInteger = function ( flag
) {
19265 this.isInteger
= !!flag
;
19266 this.input
.setValidityFlag();
19270 * Get whether only integers are allowed
19271 * @return {boolean} Flag value
19273 OO
.ui
.NumberInputWidget
.prototype.getIsInteger = function () {
19274 return this.isInteger
;
19278 * Set the range of allowed values
19279 * @param {number} min Minimum allowed value
19280 * @param {number} max Maximum allowed value
19282 OO
.ui
.NumberInputWidget
.prototype.setRange = function ( min
, max
) {
19284 throw new Error( 'Minimum (' + min
+ ') must not be greater than maximum (' + max
+ ')' );
19288 this.input
.setValidityFlag();
19292 * Get the current range
19293 * @return {number[]} Minimum and maximum values
19295 OO
.ui
.NumberInputWidget
.prototype.getRange = function () {
19296 return [ this.min
, this.max
];
19300 * Set the stepping deltas
19301 * @param {number} step Normal step
19302 * @param {number|null} pageStep Page step. If null, 10 * step will be used.
19304 OO
.ui
.NumberInputWidget
.prototype.setStep = function ( step
, pageStep
) {
19306 throw new Error( 'Step value must be positive' );
19308 if ( pageStep
=== null ) {
19309 pageStep
= step
* 10;
19310 } else if ( pageStep
<= 0 ) {
19311 throw new Error( 'Page step value must be positive' );
19314 this.pageStep
= pageStep
;
19318 * Get the current stepping values
19319 * @return {number[]} Step and page step
19321 OO
.ui
.NumberInputWidget
.prototype.getStep = function () {
19322 return [ this.step
, this.pageStep
];
19326 * Get the current value of the widget
19329 OO
.ui
.NumberInputWidget
.prototype.getValue = function () {
19330 return this.input
.getValue();
19334 * Get the current value of the widget as a number
19335 * @return {number} May be NaN, or an invalid number
19337 OO
.ui
.NumberInputWidget
.prototype.getNumericValue = function () {
19338 return +this.input
.getValue();
19342 * Set the value of the widget
19343 * @param {string} value Invalid values are allowed
19345 OO
.ui
.NumberInputWidget
.prototype.setValue = function ( value
) {
19346 this.input
.setValue( value
);
19350 * Adjust the value of the widget
19351 * @param {number} delta Adjustment amount
19353 OO
.ui
.NumberInputWidget
.prototype.adjustValue = function ( delta
) {
19354 var n
, v
= this.getNumericValue();
19357 if ( isNaN( delta
) || !isFinite( delta
) ) {
19358 throw new Error( 'Delta must be a finite number' );
19361 if ( isNaN( v
) ) {
19365 n
= Math
.max( Math
.min( n
, this.max
), this.min
);
19366 if ( this.isInteger
) {
19367 n
= Math
.round( n
);
19372 this.setValue( n
);
19379 * @param {string} value Field value
19380 * @return {boolean}
19382 OO
.ui
.NumberInputWidget
.prototype.validateNumber = function ( value
) {
19384 if ( isNaN( n
) || !isFinite( n
) ) {
19388 /*jshint bitwise: false */
19389 if ( this.isInteger
&& ( n
| 0 ) !== n
) {
19392 /*jshint bitwise: true */
19394 if ( n
< this.min
|| n
> this.max
) {
19402 * Handle mouse click events.
19405 * @param {number} dir +1 or -1
19407 OO
.ui
.NumberInputWidget
.prototype.onButtonClick = function ( dir
) {
19408 this.adjustValue( dir
* this.step
);
19412 * Handle mouse wheel events.
19415 * @param {jQuery.Event} event
19417 OO
.ui
.NumberInputWidget
.prototype.onWheel = function ( event
) {
19420 // Standard 'wheel' event
19421 if ( event
.originalEvent
.deltaMode
!== undefined ) {
19422 this.sawWheelEvent
= true;
19424 if ( event
.originalEvent
.deltaY
) {
19425 delta
= -event
.originalEvent
.deltaY
;
19426 } else if ( event
.originalEvent
.deltaX
) {
19427 delta
= event
.originalEvent
.deltaX
;
19430 // Non-standard events
19431 if ( !this.sawWheelEvent
) {
19432 if ( event
.originalEvent
.wheelDeltaX
) {
19433 delta
= -event
.originalEvent
.wheelDeltaX
;
19434 } else if ( event
.originalEvent
.wheelDeltaY
) {
19435 delta
= event
.originalEvent
.wheelDeltaY
;
19436 } else if ( event
.originalEvent
.wheelDelta
) {
19437 delta
= event
.originalEvent
.wheelDelta
;
19438 } else if ( event
.originalEvent
.detail
) {
19439 delta
= -event
.originalEvent
.detail
;
19444 delta
= delta
< 0 ? -1 : 1;
19445 this.adjustValue( delta
* this.step
);
19452 * Handle key down events.
19455 * @param {jQuery.Event} e Key down event
19457 OO
.ui
.NumberInputWidget
.prototype.onKeyDown = function ( e
) {
19458 if ( !this.isDisabled() ) {
19459 switch ( e
.which
) {
19460 case OO
.ui
.Keys
.UP
:
19461 this.adjustValue( this.step
);
19463 case OO
.ui
.Keys
.DOWN
:
19464 this.adjustValue( -this.step
);
19466 case OO
.ui
.Keys
.PAGEUP
:
19467 this.adjustValue( this.pageStep
);
19469 case OO
.ui
.Keys
.PAGEDOWN
:
19470 this.adjustValue( -this.pageStep
);
19479 OO
.ui
.NumberInputWidget
.prototype.setDisabled = function ( disabled
) {
19481 OO
.ui
.NumberInputWidget
.parent
.prototype.setDisabled
.call( this, disabled
);
19483 if ( this.input
) {
19484 this.input
.setDisabled( this.isDisabled() );
19486 if ( this.minusButton
) {
19487 this.minusButton
.setDisabled( this.isDisabled() );
19489 if ( this.plusButton
) {
19490 this.plusButton
.setDisabled( this.isDisabled() );
19497 * ToggleSwitches are switches that slide on and off. Their state is represented by a Boolean
19498 * value (`true` for ‘on’, and `false` otherwise, the default). The ‘off’ state is represented
19499 * visually by a slider in the leftmost position.
19502 * // Toggle switches in the 'off' and 'on' position.
19503 * var toggleSwitch1 = new OO.ui.ToggleSwitchWidget();
19504 * var toggleSwitch2 = new OO.ui.ToggleSwitchWidget( {
19508 * // Create a FieldsetLayout to layout and label switches
19509 * var fieldset = new OO.ui.FieldsetLayout( {
19510 * label: 'Toggle switches'
19512 * fieldset.addItems( [
19513 * new OO.ui.FieldLayout( toggleSwitch1, { label: 'Off', align: 'top' } ),
19514 * new OO.ui.FieldLayout( toggleSwitch2, { label: 'On', align: 'top' } )
19516 * $( 'body' ).append( fieldset.$element );
19519 * @extends OO.ui.ToggleWidget
19520 * @mixins OO.ui.mixin.TabIndexedElement
19523 * @param {Object} [config] Configuration options
19524 * @cfg {boolean} [value=false] The toggle switch’s initial on/off state.
19525 * By default, the toggle switch is in the 'off' position.
19527 OO
.ui
.ToggleSwitchWidget
= function OoUiToggleSwitchWidget( config
) {
19528 // Parent constructor
19529 OO
.ui
.ToggleSwitchWidget
.parent
.call( this, config
);
19531 // Mixin constructors
19532 OO
.ui
.mixin
.TabIndexedElement
.call( this, config
);
19535 this.dragging
= false;
19536 this.dragStart
= null;
19537 this.sliding
= false;
19538 this.$glow
= $( '<span>' );
19539 this.$grip
= $( '<span>' );
19542 this.$element
.on( {
19543 click
: this.onClick
.bind( this ),
19544 keypress
: this.onKeyPress
.bind( this )
19548 this.$glow
.addClass( 'oo-ui-toggleSwitchWidget-glow' );
19549 this.$grip
.addClass( 'oo-ui-toggleSwitchWidget-grip' );
19551 .addClass( 'oo-ui-toggleSwitchWidget' )
19552 .attr( 'role', 'checkbox' )
19553 .append( this.$glow
, this.$grip
);
19558 OO
.inheritClass( OO
.ui
.ToggleSwitchWidget
, OO
.ui
.ToggleWidget
);
19559 OO
.mixinClass( OO
.ui
.ToggleSwitchWidget
, OO
.ui
.mixin
.TabIndexedElement
);
19564 * Handle mouse click events.
19567 * @param {jQuery.Event} e Mouse click event
19569 OO
.ui
.ToggleSwitchWidget
.prototype.onClick = function ( e
) {
19570 if ( !this.isDisabled() && e
.which
=== 1 ) {
19571 this.setValue( !this.value
);
19577 * Handle key press events.
19580 * @param {jQuery.Event} e Key press event
19582 OO
.ui
.ToggleSwitchWidget
.prototype.onKeyPress = function ( e
) {
19583 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
19584 this.setValue( !this.value
);
19590 * Deprecated aliases for classes in the `OO.ui.mixin` namespace.
19594 * @inheritdoc OO.ui.mixin.ButtonElement
19595 * @deprecated Use {@link OO.ui.mixin.ButtonElement} instead.
19597 OO
.ui
.ButtonElement
= OO
.ui
.mixin
.ButtonElement
;
19600 * @inheritdoc OO.ui.mixin.ClippableElement
19601 * @deprecated Use {@link OO.ui.mixin.ClippableElement} instead.
19603 OO
.ui
.ClippableElement
= OO
.ui
.mixin
.ClippableElement
;
19606 * @inheritdoc OO.ui.mixin.DraggableElement
19607 * @deprecated Use {@link OO.ui.mixin.DraggableElement} instead.
19609 OO
.ui
.DraggableElement
= OO
.ui
.mixin
.DraggableElement
;
19612 * @inheritdoc OO.ui.mixin.DraggableGroupElement
19613 * @deprecated Use {@link OO.ui.mixin.DraggableGroupElement} instead.
19615 OO
.ui
.DraggableGroupElement
= OO
.ui
.mixin
.DraggableGroupElement
;
19618 * @inheritdoc OO.ui.mixin.FlaggedElement
19619 * @deprecated Use {@link OO.ui.mixin.FlaggedElement} instead.
19621 OO
.ui
.FlaggedElement
= OO
.ui
.mixin
.FlaggedElement
;
19624 * @inheritdoc OO.ui.mixin.GroupElement
19625 * @deprecated Use {@link OO.ui.mixin.GroupElement} instead.
19627 OO
.ui
.GroupElement
= OO
.ui
.mixin
.GroupElement
;
19630 * @inheritdoc OO.ui.mixin.GroupWidget
19631 * @deprecated Use {@link OO.ui.mixin.GroupWidget} instead.
19633 OO
.ui
.GroupWidget
= OO
.ui
.mixin
.GroupWidget
;
19636 * @inheritdoc OO.ui.mixin.IconElement
19637 * @deprecated Use {@link OO.ui.mixin.IconElement} instead.
19639 OO
.ui
.IconElement
= OO
.ui
.mixin
.IconElement
;
19642 * @inheritdoc OO.ui.mixin.IndicatorElement
19643 * @deprecated Use {@link OO.ui.mixin.IndicatorElement} instead.
19645 OO
.ui
.IndicatorElement
= OO
.ui
.mixin
.IndicatorElement
;
19648 * @inheritdoc OO.ui.mixin.ItemWidget
19649 * @deprecated Use {@link OO.ui.mixin.ItemWidget} instead.
19651 OO
.ui
.ItemWidget
= OO
.ui
.mixin
.ItemWidget
;
19654 * @inheritdoc OO.ui.mixin.LabelElement
19655 * @deprecated Use {@link OO.ui.mixin.LabelElement} instead.
19657 OO
.ui
.LabelElement
= OO
.ui
.mixin
.LabelElement
;
19660 * @inheritdoc OO.ui.mixin.LookupElement
19661 * @deprecated Use {@link OO.ui.mixin.LookupElement} instead.
19663 OO
.ui
.LookupElement
= OO
.ui
.mixin
.LookupElement
;
19666 * @inheritdoc OO.ui.mixin.PendingElement
19667 * @deprecated Use {@link OO.ui.mixin.PendingElement} instead.
19669 OO
.ui
.PendingElement
= OO
.ui
.mixin
.PendingElement
;
19672 * @inheritdoc OO.ui.mixin.PopupElement
19673 * @deprecated Use {@link OO.ui.mixin.PopupElement} instead.
19675 OO
.ui
.PopupElement
= OO
.ui
.mixin
.PopupElement
;
19678 * @inheritdoc OO.ui.mixin.TabIndexedElement
19679 * @deprecated Use {@link OO.ui.mixin.TabIndexedElement} instead.
19681 OO
.ui
.TabIndexedElement
= OO
.ui
.mixin
.TabIndexedElement
;
19684 * @inheritdoc OO.ui.mixin.TitledElement
19685 * @deprecated Use {@link OO.ui.mixin.TitledElement} instead.
19687 OO
.ui
.TitledElement
= OO
.ui
.mixin
.TitledElement
;