3 * https://www.mediawiki.org/wiki/OOjs_UI
5 * Copyright 2011–2015 OOjs Team and other contributors.
6 * Released under the MIT license
7 * http://oojs.mit-license.org
9 * Date: 2015-02-02T03:28:54Z
16 * Namespace for all classes, static methods and static properties.
48 * Get the user's language and any fallback languages.
50 * These language codes are used to localize user interface elements in the user's language.
52 * In environments that provide a localization system, this function should be overridden to
53 * return the user's language(s). The default implementation returns English (en) only.
55 * @return {string[]} Language codes, in descending order of priority
57 OO
.ui
.getUserLanguages = function () {
62 * Get a value in an object keyed by language code.
64 * @param {Object.<string,Mixed>} obj Object keyed by language code
65 * @param {string|null} [lang] Language code, if omitted or null defaults to any user language
66 * @param {string} [fallback] Fallback code, used if no matching language can be found
67 * @return {Mixed} Local value
69 OO
.ui
.getLocalValue = function ( obj
, lang
, fallback
) {
76 // Known user language
77 langs
= OO
.ui
.getUserLanguages();
78 for ( i
= 0, len
= langs
.length
; i
< len
; i
++ ) {
85 if ( obj
[ fallback
] ) {
86 return obj
[ fallback
];
88 // First existing language
97 * Check if a node is contained within another node
99 * Similar to jQuery#contains except a list of containers can be supplied
100 * and a boolean argument allows you to include the container in the match list
102 * @param {HTMLElement|HTMLElement[]} containers Container node(s) to search in
103 * @param {HTMLElement} contained Node to find
104 * @param {boolean} [matchContainers] Include the container(s) in the list of nodes to match, otherwise only match descendants
105 * @return {boolean} The node is in the list of target nodes
107 OO
.ui
.contains = function ( containers
, contained
, matchContainers
) {
109 if ( !Array
.isArray( containers
) ) {
110 containers
= [ containers
];
112 for ( i
= containers
.length
- 1; i
>= 0; i
-- ) {
113 if ( ( matchContainers
&& contained
=== containers
[ i
] ) || $.contains( containers
[ i
], contained
) ) {
122 * Message store for the default implementation of OO.ui.msg
124 * Environments that provide a localization system should not use this, but should override
125 * OO.ui.msg altogether.
130 // Tool tip for a button that moves items in a list down one place
131 'ooui-outline-control-move-down': 'Move item down',
132 // Tool tip for a button that moves items in a list up one place
133 'ooui-outline-control-move-up': 'Move item up',
134 // Tool tip for a button that removes items from a list
135 'ooui-outline-control-remove': 'Remove item',
136 // Label for the toolbar group that contains a list of all other available tools
137 'ooui-toolbar-more': 'More',
138 // Label for the fake tool that expands the full list of tools in a toolbar group
139 'ooui-toolgroup-expand': 'More',
140 // Label for the fake tool that collapses the full list of tools in a toolbar group
141 'ooui-toolgroup-collapse': 'Fewer',
142 // Default label for the accept button of a confirmation dialog
143 'ooui-dialog-message-accept': 'OK',
144 // Default label for the reject button of a confirmation dialog
145 'ooui-dialog-message-reject': 'Cancel',
146 // Title for process dialog error description
147 'ooui-dialog-process-error': 'Something went wrong',
148 // Label for process dialog dismiss error button, visible when describing errors
149 'ooui-dialog-process-dismiss': 'Dismiss',
150 // Label for process dialog retry action button, visible when describing only recoverable errors
151 'ooui-dialog-process-retry': 'Try again',
152 // Label for process dialog retry action button, visible when describing only warnings
153 'ooui-dialog-process-continue': 'Continue'
157 * Get a localized message.
159 * In environments that provide a localization system, this function should be overridden to
160 * return the message translated in the user's language. The default implementation always returns
163 * After the message key, message parameters may optionally be passed. In the default implementation,
164 * any occurrences of $1 are replaced with the first parameter, $2 with the second parameter, etc.
165 * Alternative implementations of OO.ui.msg may use any substitution system they like, as long as
166 * they support unnamed, ordered message parameters.
169 * @param {string} key Message key
170 * @param {Mixed...} [params] Message parameters
171 * @return {string} Translated message with parameters substituted
173 OO
.ui
.msg = function ( key
) {
174 var message
= messages
[ key
],
175 params
= Array
.prototype.slice
.call( arguments
, 1 );
176 if ( typeof message
=== 'string' ) {
177 // Perform $1 substitution
178 message
= message
.replace( /\$(\d+)/g, function ( unused
, n
) {
179 var i
= parseInt( n
, 10 );
180 return params
[ i
- 1 ] !== undefined ? params
[ i
- 1 ] : '$' + n
;
183 // Return placeholder if message not found
184 message
= '[' + key
+ ']';
190 * Package a message and arguments for deferred resolution.
192 * Use this when you are statically specifying a message and the message may not yet be present.
194 * @param {string} key Message key
195 * @param {Mixed...} [params] Message parameters
196 * @return {Function} Function that returns the resolved message when executed
198 OO
.ui
.deferMsg = function () {
199 var args
= arguments
;
201 return OO
.ui
.msg
.apply( OO
.ui
, args
);
208 * If the message is a function it will be executed, otherwise it will pass through directly.
210 * @param {Function|string} msg Deferred message, or message text
211 * @return {string} Resolved message
213 OO
.ui
.resolveMsg = function ( msg
) {
214 if ( $.isFunction( msg
) ) {
223 * Element that can be marked as pending.
229 * @param {Object} [config] Configuration options
230 * @cfg {jQuery} [$pending] Element to mark as pending, defaults to this.$element
232 OO
.ui
.PendingElement
= function OoUiPendingElement( config
) {
233 // Configuration initialization
234 config
= config
|| {};
238 this.$pending
= null;
241 this.setPendingElement( config
.$pending
|| this.$element
);
246 OO
.initClass( OO
.ui
.PendingElement
);
251 * Set the pending element (and clean up any existing one).
253 * @param {jQuery} $pending The element to set to pending.
255 OO
.ui
.PendingElement
.prototype.setPendingElement = function ( $pending
) {
256 if ( this.$pending
) {
257 this.$pending
.removeClass( 'oo-ui-pendingElement-pending' );
260 this.$pending
= $pending
;
261 if ( this.pending
> 0 ) {
262 this.$pending
.addClass( 'oo-ui-pendingElement-pending' );
267 * Check if input is pending.
271 OO
.ui
.PendingElement
.prototype.isPending = function () {
272 return !!this.pending
;
276 * Increase the pending stack.
280 OO
.ui
.PendingElement
.prototype.pushPending = function () {
281 if ( this.pending
=== 0 ) {
282 this.$pending
.addClass( 'oo-ui-pendingElement-pending' );
283 this.updateThemeClasses();
291 * Reduce the pending stack.
297 OO
.ui
.PendingElement
.prototype.popPending = function () {
298 if ( this.pending
=== 1 ) {
299 this.$pending
.removeClass( 'oo-ui-pendingElement-pending' );
300 this.updateThemeClasses();
302 this.pending
= Math
.max( 0, this.pending
- 1 );
312 * @mixins OO.EventEmitter
315 * @param {Object} [config] Configuration options
317 OO
.ui
.ActionSet
= function OoUiActionSet( config
) {
318 // Configuration initialization
319 config
= config
|| {};
321 // Mixin constructors
322 OO
.EventEmitter
.call( this );
327 actions
: 'getAction',
331 this.categorized
= {};
334 this.organized
= false;
335 this.changing
= false;
336 this.changed
= false;
341 OO
.mixinClass( OO
.ui
.ActionSet
, OO
.EventEmitter
);
343 /* Static Properties */
346 * Symbolic name of dialog.
353 OO
.ui
.ActionSet
.static.specialFlags
= [ 'safe', 'primary' ];
359 * @param {OO.ui.ActionWidget} action Action that was clicked
364 * @param {OO.ui.ActionWidget} action Action that was resized
369 * @param {OO.ui.ActionWidget[]} added Actions added
374 * @param {OO.ui.ActionWidget[]} added Actions removed
384 * Handle action change events.
388 OO
.ui
.ActionSet
.prototype.onActionChange = function () {
389 this.organized
= false;
390 if ( this.changing
) {
393 this.emit( 'change' );
398 * Check if a action is one of the special actions.
400 * @param {OO.ui.ActionWidget} action Action to check
401 * @return {boolean} Action is special
403 OO
.ui
.ActionSet
.prototype.isSpecial = function ( action
) {
406 for ( flag
in this.special
) {
407 if ( action
=== this.special
[ flag
] ) {
418 * @param {Object} [filters] Filters to use, omit to get all actions
419 * @param {string|string[]} [filters.actions] Actions that actions must have
420 * @param {string|string[]} [filters.flags] Flags that actions must have
421 * @param {string|string[]} [filters.modes] Modes that actions must have
422 * @param {boolean} [filters.visible] Actions must be visible
423 * @param {boolean} [filters.disabled] Actions must be disabled
424 * @return {OO.ui.ActionWidget[]} Actions matching all criteria
426 OO
.ui
.ActionSet
.prototype.get = function ( filters
) {
427 var i
, len
, list
, category
, actions
, index
, match
, matches
;
432 // Collect category candidates
434 for ( category
in this.categorized
) {
435 list
= filters
[ category
];
437 if ( !Array
.isArray( list
) ) {
440 for ( i
= 0, len
= list
.length
; i
< len
; i
++ ) {
441 actions
= this.categorized
[ category
][ list
[ i
] ];
442 if ( Array
.isArray( actions
) ) {
443 matches
.push
.apply( matches
, actions
);
448 // Remove by boolean filters
449 for ( i
= 0, len
= matches
.length
; i
< len
; i
++ ) {
450 match
= matches
[ i
];
452 ( filters
.visible
!== undefined && match
.isVisible() !== filters
.visible
) ||
453 ( filters
.disabled
!== undefined && match
.isDisabled() !== filters
.disabled
)
455 matches
.splice( i
, 1 );
461 for ( i
= 0, len
= matches
.length
; i
< len
; i
++ ) {
462 match
= matches
[ i
];
463 index
= matches
.lastIndexOf( match
);
464 while ( index
!== i
) {
465 matches
.splice( index
, 1 );
467 index
= matches
.lastIndexOf( match
);
472 return this.list
.slice();
476 * Get special actions.
478 * Special actions are the first visible actions with special flags, such as 'safe' and 'primary'.
479 * Special flags can be configured by changing #static-specialFlags in a subclass.
481 * @return {OO.ui.ActionWidget|null} Safe action
483 OO
.ui
.ActionSet
.prototype.getSpecial = function () {
485 return $.extend( {}, this.special
);
491 * Other actions include all non-special visible actions.
493 * @return {OO.ui.ActionWidget[]} Other actions
495 OO
.ui
.ActionSet
.prototype.getOthers = function () {
497 return this.others
.slice();
501 * Toggle actions based on their modes.
503 * Unlike calling toggle on actions with matching flags, this will enforce mutually exclusive
504 * visibility; matching actions will be shown, non-matching actions will be hidden.
506 * @param {string} mode Mode actions must have
511 OO
.ui
.ActionSet
.prototype.setMode = function ( mode
) {
514 this.changing
= true;
515 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
516 action
= this.list
[ i
];
517 action
.toggle( action
.hasMode( mode
) );
520 this.organized
= false;
521 this.changing
= false;
522 this.emit( 'change' );
528 * Change which actions are able to be performed.
530 * Actions with matching actions will be disabled/enabled. Other actions will not be changed.
532 * @param {Object.<string,boolean>} actions List of abilities, keyed by action name, values
533 * indicate actions are able to be performed
536 OO
.ui
.ActionSet
.prototype.setAbilities = function ( actions
) {
537 var i
, len
, action
, item
;
539 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
540 item
= this.list
[ i
];
541 action
= item
.getAction();
542 if ( actions
[ action
] !== undefined ) {
543 item
.setDisabled( !actions
[ action
] );
551 * Executes a function once per action.
553 * When making changes to multiple actions, use this method instead of iterating over the actions
554 * manually to defer emitting a change event until after all actions have been changed.
556 * @param {Object|null} actions Filters to use for which actions to iterate over; see #get
557 * @param {Function} callback Callback to run for each action; callback is invoked with three
558 * arguments: the action, the action's index, the list of actions being iterated over
561 OO
.ui
.ActionSet
.prototype.forEach = function ( filter
, callback
) {
562 this.changed
= false;
563 this.changing
= true;
564 this.get( filter
).forEach( callback
);
565 this.changing
= false;
566 if ( this.changed
) {
567 this.emit( 'change' );
576 * @param {OO.ui.ActionWidget[]} actions Actions to add
581 OO
.ui
.ActionSet
.prototype.add = function ( actions
) {
584 this.changing
= true;
585 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
586 action
= actions
[ i
];
587 action
.connect( this, {
588 click
: [ 'emit', 'click', action
],
589 resize
: [ 'emit', 'resize', action
],
590 toggle
: [ 'onActionChange' ]
592 this.list
.push( action
);
594 this.organized
= false;
595 this.emit( 'add', actions
);
596 this.changing
= false;
597 this.emit( 'change' );
605 * @param {OO.ui.ActionWidget[]} actions Actions to remove
610 OO
.ui
.ActionSet
.prototype.remove = function ( actions
) {
611 var i
, len
, index
, action
;
613 this.changing
= true;
614 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
615 action
= actions
[ i
];
616 index
= this.list
.indexOf( action
);
617 if ( index
!== -1 ) {
618 action
.disconnect( this );
619 this.list
.splice( index
, 1 );
622 this.organized
= false;
623 this.emit( 'remove', actions
);
624 this.changing
= false;
625 this.emit( 'change' );
631 * Remove all actions.
637 OO
.ui
.ActionSet
.prototype.clear = function () {
639 removed
= this.list
.slice();
641 this.changing
= true;
642 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
643 action
= this.list
[ i
];
644 action
.disconnect( this );
649 this.organized
= false;
650 this.emit( 'remove', removed
);
651 this.changing
= false;
652 this.emit( 'change' );
660 * This is called whenever organized information is requested. It will only reorganize the actions
661 * if something has changed since the last time it ran.
666 OO
.ui
.ActionSet
.prototype.organize = function () {
667 var i
, iLen
, j
, jLen
, flag
, action
, category
, list
, item
, special
,
668 specialFlags
= this.constructor.static.specialFlags
;
670 if ( !this.organized
) {
671 this.categorized
= {};
674 for ( i
= 0, iLen
= this.list
.length
; i
< iLen
; i
++ ) {
675 action
= this.list
[ i
];
676 if ( action
.isVisible() ) {
677 // Populate categories
678 for ( category
in this.categories
) {
679 if ( !this.categorized
[ category
] ) {
680 this.categorized
[ category
] = {};
682 list
= action
[ this.categories
[ category
] ]();
683 if ( !Array
.isArray( list
) ) {
686 for ( j
= 0, jLen
= list
.length
; j
< jLen
; j
++ ) {
688 if ( !this.categorized
[ category
][ item
] ) {
689 this.categorized
[ category
][ item
] = [];
691 this.categorized
[ category
][ item
].push( action
);
694 // Populate special/others
696 for ( j
= 0, jLen
= specialFlags
.length
; j
< jLen
; j
++ ) {
697 flag
= specialFlags
[ j
];
698 if ( !this.special
[ flag
] && action
.hasFlag( flag
) ) {
699 this.special
[ flag
] = action
;
705 this.others
.push( action
);
709 this.organized
= true;
716 * DOM element abstraction.
722 * @param {Object} [config] Configuration options
723 * @cfg {Function} [$] jQuery for the frame the widget is in
724 * @cfg {string[]} [classes] CSS class names to add
725 * @cfg {string} [id] HTML id attribute
726 * @cfg {string} [text] Text to insert
727 * @cfg {jQuery} [$content] Content elements to append (after text)
728 * @cfg {Mixed} [data] Element data
730 OO
.ui
.Element
= function OoUiElement( config
) {
731 // Configuration initialization
732 config
= config
|| {};
735 this.$ = config
.$ || OO
.ui
.Element
.static.getJQuery( document
);
736 this.data
= config
.data
;
737 this.$element
= this.$( this.$.context
.createElement( this.getTagName() ) );
738 this.elementGroup
= null;
739 this.debouncedUpdateThemeClassesHandler
= this.debouncedUpdateThemeClasses
.bind( this );
740 this.updateThemeClassesPending
= false;
743 if ( $.isArray( config
.classes
) ) {
744 this.$element
.addClass( config
.classes
.join( ' ' ) );
747 this.$element
.attr( 'id', config
.id
);
750 this.$element
.text( config
.text
);
752 if ( config
.$content
) {
753 this.$element
.append( config
.$content
);
759 OO
.initClass( OO
.ui
.Element
);
761 /* Static Properties */
766 * This may be ignored if #getTagName is overridden.
772 OO
.ui
.Element
.static.tagName
= 'div';
777 * Get a jQuery function within a specific document.
780 * @param {jQuery|HTMLElement|HTMLDocument|Window} context Context to bind the function to
781 * @param {jQuery} [$iframe] HTML iframe element that contains the document, omit if document is
783 * @return {Function} Bound jQuery function
785 OO
.ui
.Element
.static.getJQuery = function ( context
, $iframe
) {
786 function wrapper( selector
) {
787 return $( selector
, wrapper
.context
);
790 wrapper
.context
= this.getDocument( context
);
793 wrapper
.$iframe
= $iframe
;
800 * Get the document of an element.
803 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Object to get the document for
804 * @return {HTMLDocument|null} Document object
806 OO
.ui
.Element
.static.getDocument = function ( obj
) {
807 // jQuery - selections created "offscreen" won't have a context, so .context isn't reliable
808 return ( obj
[ 0 ] && obj
[ 0 ].ownerDocument
) ||
809 // Empty jQuery selections might have a context
816 ( obj
.nodeType
=== 9 && obj
) ||
821 * Get the window of an element or document.
824 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Context to get the window for
825 * @return {Window} Window object
827 OO
.ui
.Element
.static.getWindow = function ( obj
) {
828 var doc
= this.getDocument( obj
);
829 return doc
.parentWindow
|| doc
.defaultView
;
833 * Get the direction of an element or document.
836 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Context to get the direction for
837 * @return {string} Text direction, either 'ltr' or 'rtl'
839 OO
.ui
.Element
.static.getDir = function ( obj
) {
842 if ( obj
instanceof jQuery
) {
845 isDoc
= obj
.nodeType
=== 9;
846 isWin
= obj
.document
!== undefined;
847 if ( isDoc
|| isWin
) {
853 return $( obj
).css( 'direction' );
857 * Get the offset between two frames.
859 * TODO: Make this function not use recursion.
862 * @param {Window} from Window of the child frame
863 * @param {Window} [to=window] Window of the parent frame
864 * @param {Object} [offset] Offset to start with, used internally
865 * @return {Object} Offset object, containing left and top properties
867 OO
.ui
.Element
.static.getFrameOffset = function ( from, to
, offset
) {
868 var i
, len
, frames
, frame
, rect
;
874 offset
= { top
: 0, left
: 0 };
876 if ( from.parent
=== from ) {
880 // Get iframe element
881 frames
= from.parent
.document
.getElementsByTagName( 'iframe' );
882 for ( i
= 0, len
= frames
.length
; i
< len
; i
++ ) {
883 if ( frames
[ i
].contentWindow
=== from ) {
889 // Recursively accumulate offset values
891 rect
= frame
.getBoundingClientRect();
892 offset
.left
+= rect
.left
;
893 offset
.top
+= rect
.top
;
895 this.getFrameOffset( from.parent
, offset
);
902 * Get the offset between two elements.
904 * The two elements may be in a different frame, but in that case the frame $element is in must
905 * be contained in the frame $anchor is in.
908 * @param {jQuery} $element Element whose position to get
909 * @param {jQuery} $anchor Element to get $element's position relative to
910 * @return {Object} Translated position coordinates, containing top and left properties
912 OO
.ui
.Element
.static.getRelativePosition = function ( $element
, $anchor
) {
913 var iframe
, iframePos
,
914 pos
= $element
.offset(),
915 anchorPos
= $anchor
.offset(),
916 elementDocument
= this.getDocument( $element
),
917 anchorDocument
= this.getDocument( $anchor
);
919 // If $element isn't in the same document as $anchor, traverse up
920 while ( elementDocument
!== anchorDocument
) {
921 iframe
= elementDocument
.defaultView
.frameElement
;
923 throw new Error( '$element frame is not contained in $anchor frame' );
925 iframePos
= $( iframe
).offset();
926 pos
.left
+= iframePos
.left
;
927 pos
.top
+= iframePos
.top
;
928 elementDocument
= iframe
.ownerDocument
;
930 pos
.left
-= anchorPos
.left
;
931 pos
.top
-= anchorPos
.top
;
936 * Get element border sizes.
939 * @param {HTMLElement} el Element to measure
940 * @return {Object} Dimensions object with `top`, `left`, `bottom` and `right` properties
942 OO
.ui
.Element
.static.getBorders = function ( el
) {
943 var doc
= el
.ownerDocument
,
944 win
= doc
.parentWindow
|| doc
.defaultView
,
945 style
= win
&& win
.getComputedStyle
?
946 win
.getComputedStyle( el
, null ) :
949 top
= parseFloat( style
? style
.borderTopWidth
: $el
.css( 'borderTopWidth' ) ) || 0,
950 left
= parseFloat( style
? style
.borderLeftWidth
: $el
.css( 'borderLeftWidth' ) ) || 0,
951 bottom
= parseFloat( style
? style
.borderBottomWidth
: $el
.css( 'borderBottomWidth' ) ) || 0,
952 right
= parseFloat( style
? style
.borderRightWidth
: $el
.css( 'borderRightWidth' ) ) || 0;
963 * Get dimensions of an element or window.
966 * @param {HTMLElement|Window} el Element to measure
967 * @return {Object} Dimensions object with `borders`, `scroll`, `scrollbar` and `rect` properties
969 OO
.ui
.Element
.static.getDimensions = function ( el
) {
971 doc
= el
.ownerDocument
|| el
.document
,
972 win
= doc
.parentWindow
|| doc
.defaultView
;
974 if ( win
=== el
|| el
=== doc
.documentElement
) {
977 borders
: { top
: 0, left
: 0, bottom
: 0, right
: 0 },
979 top
: $win
.scrollTop(),
980 left
: $win
.scrollLeft()
982 scrollbar
: { right
: 0, bottom
: 0 },
986 bottom
: $win
.innerHeight(),
987 right
: $win
.innerWidth()
993 borders
: this.getBorders( el
),
995 top
: $el
.scrollTop(),
996 left
: $el
.scrollLeft()
999 right
: $el
.innerWidth() - el
.clientWidth
,
1000 bottom
: $el
.innerHeight() - el
.clientHeight
1002 rect
: el
.getBoundingClientRect()
1008 * Get scrollable object parent
1010 * documentElement can't be used to get or set the scrollTop
1011 * property on Blink. Changing and testing its value lets us
1012 * use 'body' or 'documentElement' based on what is working.
1014 * https://code.google.com/p/chromium/issues/detail?id=303131
1017 * @param {HTMLElement} el Element to find scrollable parent for
1018 * @return {HTMLElement} Scrollable parent
1020 OO
.ui
.Element
.static.getRootScrollableElement = function ( el
) {
1021 var scrollTop
, body
;
1023 if ( OO
.ui
.scrollableElement
=== undefined ) {
1024 body
= el
.ownerDocument
.body
;
1025 scrollTop
= body
.scrollTop
;
1028 if ( body
.scrollTop
=== 1 ) {
1029 body
.scrollTop
= scrollTop
;
1030 OO
.ui
.scrollableElement
= 'body';
1032 OO
.ui
.scrollableElement
= 'documentElement';
1036 return el
.ownerDocument
[ OO
.ui
.scrollableElement
];
1040 * Get closest scrollable container.
1042 * Traverses up until either a scrollable element or the root is reached, in which case the window
1046 * @param {HTMLElement} el Element to find scrollable container for
1047 * @param {string} [dimension] Dimension of scrolling to look for; `x`, `y` or omit for either
1048 * @return {HTMLElement} Closest scrollable container
1050 OO
.ui
.Element
.static.getClosestScrollableContainer = function ( el
, dimension
) {
1052 props
= [ 'overflow' ],
1053 $parent
= $( el
).parent();
1055 if ( dimension
=== 'x' || dimension
=== 'y' ) {
1056 props
.push( 'overflow-' + dimension
);
1059 while ( $parent
.length
) {
1060 if ( $parent
[ 0 ] === this.getRootScrollableElement( el
) ) {
1061 return $parent
[ 0 ];
1065 val
= $parent
.css( props
[ i
] );
1066 if ( val
=== 'auto' || val
=== 'scroll' ) {
1067 return $parent
[ 0 ];
1070 $parent
= $parent
.parent();
1072 return this.getDocument( el
).body
;
1076 * Scroll element into view.
1079 * @param {HTMLElement} el Element to scroll into view
1080 * @param {Object} [config] Configuration options
1081 * @param {string} [config.duration] jQuery animation duration value
1082 * @param {string} [config.direction] Scroll in only one direction, e.g. 'x' or 'y', omit
1083 * to scroll in both directions
1084 * @param {Function} [config.complete] Function to call when scrolling completes
1086 OO
.ui
.Element
.static.scrollIntoView = function ( el
, config
) {
1087 // Configuration initialization
1088 config
= config
|| {};
1091 callback
= typeof config
.complete
=== 'function' && config
.complete
,
1092 sc
= this.getClosestScrollableContainer( el
, config
.direction
),
1094 eld
= this.getDimensions( el
),
1095 scd
= this.getDimensions( sc
),
1096 $win
= $( this.getWindow( el
) );
1098 // Compute the distances between the edges of el and the edges of the scroll viewport
1099 if ( $sc
.is( 'html, body' ) ) {
1100 // If the scrollable container is the root, this is easy
1103 bottom
: $win
.innerHeight() - eld
.rect
.bottom
,
1104 left
: eld
.rect
.left
,
1105 right
: $win
.innerWidth() - eld
.rect
.right
1108 // Otherwise, we have to subtract el's coordinates from sc's coordinates
1110 top
: eld
.rect
.top
- ( scd
.rect
.top
+ scd
.borders
.top
),
1111 bottom
: scd
.rect
.bottom
- scd
.borders
.bottom
- scd
.scrollbar
.bottom
- eld
.rect
.bottom
,
1112 left
: eld
.rect
.left
- ( scd
.rect
.left
+ scd
.borders
.left
),
1113 right
: scd
.rect
.right
- scd
.borders
.right
- scd
.scrollbar
.right
- eld
.rect
.right
1117 if ( !config
.direction
|| config
.direction
=== 'y' ) {
1118 if ( rel
.top
< 0 ) {
1119 anim
.scrollTop
= scd
.scroll
.top
+ rel
.top
;
1120 } else if ( rel
.top
> 0 && rel
.bottom
< 0 ) {
1121 anim
.scrollTop
= scd
.scroll
.top
+ Math
.min( rel
.top
, -rel
.bottom
);
1124 if ( !config
.direction
|| config
.direction
=== 'x' ) {
1125 if ( rel
.left
< 0 ) {
1126 anim
.scrollLeft
= scd
.scroll
.left
+ rel
.left
;
1127 } else if ( rel
.left
> 0 && rel
.right
< 0 ) {
1128 anim
.scrollLeft
= scd
.scroll
.left
+ Math
.min( rel
.left
, -rel
.right
);
1131 if ( !$.isEmptyObject( anim
) ) {
1132 $sc
.stop( true ).animate( anim
, config
.duration
|| 'fast' );
1134 $sc
.queue( function ( next
) {
1147 * Force the browser to reconsider whether it really needs to render scrollbars inside the element
1148 * and reserve space for them, because it probably doesn't.
1150 * Workaround primarily for <https://code.google.com/p/chromium/issues/detail?id=387290>, but also
1151 * similar bugs in other browsers. "Just" forcing a reflow is not sufficient in all cases, we need
1152 * to first actually detach (or hide, but detaching is simpler) all children, *then* force a reflow,
1153 * and then reattach (or show) them back.
1156 * @param {HTMLElement} el Element to reconsider the scrollbars on
1158 OO
.ui
.Element
.static.reconsiderScrollbars = function ( el
) {
1159 var i
, len
, nodes
= [];
1160 // Detach all children
1161 while ( el
.firstChild
) {
1162 nodes
.push( el
.firstChild
);
1163 el
.removeChild( el
.firstChild
);
1166 void el
.offsetHeight
;
1167 // Reattach all children
1168 for ( i
= 0, len
= nodes
.length
; i
< len
; i
++ ) {
1169 el
.appendChild( nodes
[ i
] );
1178 * @return {Mixed} Element data
1180 OO
.ui
.Element
.prototype.getData = function () {
1187 * @param {Mixed} Element data
1190 OO
.ui
.Element
.prototype.setData = function ( data
) {
1196 * Check if element supports one or more methods.
1198 * @param {string|string[]} methods Method or list of methods to check
1199 * @return {boolean} All methods are supported
1201 OO
.ui
.Element
.prototype.supports = function ( methods
) {
1205 methods
= $.isArray( methods
) ? methods
: [ methods
];
1206 for ( i
= 0, len
= methods
.length
; i
< len
; i
++ ) {
1207 if ( $.isFunction( this[ methods
[ i
] ] ) ) {
1212 return methods
.length
=== support
;
1216 * Update the theme-provided classes.
1218 * @localdoc This is called in element mixins and widget classes any time state changes.
1219 * Updating is debounced, minimizing overhead of changing multiple attributes and
1220 * guaranteeing that theme updates do not occur within an element's constructor
1222 OO
.ui
.Element
.prototype.updateThemeClasses = function () {
1223 if ( !this.updateThemeClassesPending
) {
1224 this.updateThemeClassesPending
= true;
1225 setTimeout( this.debouncedUpdateThemeClassesHandler
);
1232 OO
.ui
.Element
.prototype.debouncedUpdateThemeClasses = function () {
1233 OO
.ui
.theme
.updateElementClasses( this );
1234 this.updateThemeClassesPending
= false;
1238 * Get the HTML tag name.
1240 * Override this method to base the result on instance information.
1242 * @return {string} HTML tag name
1244 OO
.ui
.Element
.prototype.getTagName = function () {
1245 return this.constructor.static.tagName
;
1249 * Check if the element is attached to the DOM
1250 * @return {boolean} The element is attached to the DOM
1252 OO
.ui
.Element
.prototype.isElementAttached = function () {
1253 return $.contains( this.getElementDocument(), this.$element
[ 0 ] );
1257 * Get the DOM document.
1259 * @return {HTMLDocument} Document object
1261 OO
.ui
.Element
.prototype.getElementDocument = function () {
1262 // Don't use this.$.context because subclasses can rebind this.$
1263 // Don't cache this in other ways either because subclasses could can change this.$element
1264 return OO
.ui
.Element
.static.getDocument( this.$element
);
1268 * Get the DOM window.
1270 * @return {Window} Window object
1272 OO
.ui
.Element
.prototype.getElementWindow = function () {
1273 return OO
.ui
.Element
.static.getWindow( this.$element
);
1277 * Get closest scrollable container.
1279 OO
.ui
.Element
.prototype.getClosestScrollableElementContainer = function () {
1280 return OO
.ui
.Element
.static.getClosestScrollableContainer( this.$element
[ 0 ] );
1284 * Get group element is in.
1286 * @return {OO.ui.GroupElement|null} Group element, null if none
1288 OO
.ui
.Element
.prototype.getElementGroup = function () {
1289 return this.elementGroup
;
1293 * Set group element is in.
1295 * @param {OO.ui.GroupElement|null} group Group element, null if none
1298 OO
.ui
.Element
.prototype.setElementGroup = function ( group
) {
1299 this.elementGroup
= group
;
1304 * Scroll element into view.
1306 * @param {Object} [config] Configuration options
1308 OO
.ui
.Element
.prototype.scrollElementIntoView = function ( config
) {
1309 return OO
.ui
.Element
.static.scrollIntoView( this.$element
[ 0 ], config
);
1313 * Container for elements.
1317 * @extends OO.ui.Element
1318 * @mixins OO.EventEmitter
1321 * @param {Object} [config] Configuration options
1323 OO
.ui
.Layout
= function OoUiLayout( config
) {
1324 // Configuration initialization
1325 config
= config
|| {};
1327 // Parent constructor
1328 OO
.ui
.Layout
.super.call( this, config
);
1330 // Mixin constructors
1331 OO
.EventEmitter
.call( this );
1334 this.$element
.addClass( 'oo-ui-layout' );
1339 OO
.inheritClass( OO
.ui
.Layout
, OO
.ui
.Element
);
1340 OO
.mixinClass( OO
.ui
.Layout
, OO
.EventEmitter
);
1343 * User interface control.
1347 * @extends OO.ui.Element
1348 * @mixins OO.EventEmitter
1351 * @param {Object} [config] Configuration options
1352 * @cfg {boolean} [disabled=false] Disable
1354 OO
.ui
.Widget
= function OoUiWidget( config
) {
1355 // Initialize config
1356 config
= $.extend( { disabled
: false }, config
);
1358 // Parent constructor
1359 OO
.ui
.Widget
.super.call( this, config
);
1361 // Mixin constructors
1362 OO
.EventEmitter
.call( this );
1365 this.visible
= true;
1366 this.disabled
= null;
1367 this.wasDisabled
= null;
1370 this.$element
.addClass( 'oo-ui-widget' );
1371 this.setDisabled( !!config
.disabled
);
1376 OO
.inheritClass( OO
.ui
.Widget
, OO
.ui
.Element
);
1377 OO
.mixinClass( OO
.ui
.Widget
, OO
.EventEmitter
);
1383 * @param {boolean} disabled Widget is disabled
1388 * @param {boolean} visible Widget is visible
1394 * Check if the widget is disabled.
1396 * @return {boolean} Button is disabled
1398 OO
.ui
.Widget
.prototype.isDisabled = function () {
1399 return this.disabled
;
1403 * Check if widget is visible.
1405 * @return {boolean} Widget is visible
1407 OO
.ui
.Widget
.prototype.isVisible = function () {
1408 return this.visible
;
1412 * Set the disabled state of the widget.
1414 * This should probably change the widgets' appearance and prevent it from being used.
1416 * @param {boolean} disabled Disable widget
1419 OO
.ui
.Widget
.prototype.setDisabled = function ( disabled
) {
1422 this.disabled
= !!disabled
;
1423 isDisabled
= this.isDisabled();
1424 if ( isDisabled
!== this.wasDisabled
) {
1425 this.$element
.toggleClass( 'oo-ui-widget-disabled', isDisabled
);
1426 this.$element
.toggleClass( 'oo-ui-widget-enabled', !isDisabled
);
1427 this.$element
.attr( 'aria-disabled', isDisabled
.toString() );
1428 this.emit( 'disable', isDisabled
);
1429 this.updateThemeClasses();
1431 this.wasDisabled
= isDisabled
;
1437 * Toggle visibility of widget.
1439 * @param {boolean} [show] Make widget visible, omit to toggle visibility
1443 OO
.ui
.Widget
.prototype.toggle = function ( show
) {
1444 show
= show
=== undefined ? !this.visible
: !!show
;
1446 if ( show
!== this.isVisible() ) {
1447 this.visible
= show
;
1448 this.$element
.toggle( show
);
1449 this.emit( 'toggle', show
);
1456 * Update the disabled state, in case of changes in parent widget.
1460 OO
.ui
.Widget
.prototype.updateDisabled = function () {
1461 this.setDisabled( this.disabled
);
1466 * Container for elements in a child frame.
1468 * Use together with OO.ui.WindowManager.
1472 * @extends OO.ui.Element
1473 * @mixins OO.EventEmitter
1475 * When a window is opened, the setup and ready processes are executed. Similarly, the hold and
1476 * teardown processes are executed when the window is closed.
1478 * - {@link OO.ui.WindowManager#openWindow} or {@link #open} methods are used to start opening
1479 * - Window manager begins opening window
1480 * - {@link #getSetupProcess} method is called and its result executed
1481 * - {@link #getReadyProcess} method is called and its result executed
1482 * - Window is now open
1484 * - {@link OO.ui.WindowManager#closeWindow} or {@link #close} methods are used to start closing
1485 * - Window manager begins closing window
1486 * - {@link #getHoldProcess} method is called and its result executed
1487 * - {@link #getTeardownProcess} method is called and its result executed
1488 * - Window is now closed
1490 * Each process (setup, ready, hold and teardown) can be extended in subclasses by overriding
1491 * {@link #getSetupProcess}, {@link #getReadyProcess}, {@link #getHoldProcess} and
1492 * {@link #getTeardownProcess} respectively. Each process is executed in series, so asynchronous
1493 * processing can complete. Always assume window processes are executed asynchronously. See
1494 * OO.ui.Process for more details about how to work with processes. Some events, as well as the
1495 * #open and #close methods, provide promises which are resolved when the window enters a new state.
1497 * Sizing of windows is specified using symbolic names which are interpreted by the window manager.
1498 * If the requested size is not recognized, the window manager will choose a sensible fallback.
1501 * @param {Object} [config] Configuration options
1502 * @cfg {string} [size] Symbolic name of dialog size, `small`, `medium`, `large`, `larger` or
1503 * `full`; omit to use #static-size
1505 OO
.ui
.Window
= function OoUiWindow( config
) {
1506 // Configuration initialization
1507 config
= config
|| {};
1509 // Parent constructor
1510 OO
.ui
.Window
.super.call( this, config
);
1512 // Mixin constructors
1513 OO
.EventEmitter
.call( this );
1516 this.manager
= null;
1517 this.initialized
= false;
1518 this.visible
= false;
1519 this.opening
= null;
1520 this.closing
= null;
1523 this.loading
= null;
1524 this.size
= config
.size
|| this.constructor.static.size
;
1525 this.$frame
= this.$( '<div>' );
1526 this.$overlay
= this.$( '<div>' );
1530 .addClass( 'oo-ui-window' )
1531 .append( this.$frame
, this.$overlay
);
1532 this.$frame
.addClass( 'oo-ui-window-frame' );
1533 this.$overlay
.addClass( 'oo-ui-window-overlay' );
1535 // NOTE: Additional initialization will occur when #setManager is called
1540 OO
.inheritClass( OO
.ui
.Window
, OO
.ui
.Element
);
1541 OO
.mixinClass( OO
.ui
.Window
, OO
.EventEmitter
);
1543 /* Static Properties */
1546 * Symbolic name of size.
1548 * Size is used if no size is configured during construction.
1552 * @property {string}
1554 OO
.ui
.Window
.static.size
= 'medium';
1556 /* Static Methods */
1559 * Transplant the CSS styles from as parent document to a frame's document.
1561 * This loops over the style sheets in the parent document, and copies their nodes to the
1562 * frame's document. It then polls the document to see when all styles have loaded, and once they
1563 * have, resolves the promise.
1565 * If the styles still haven't loaded after a long time (5 seconds by default), we give up waiting
1566 * and resolve the promise anyway. This protects against cases like a display: none; iframe in
1567 * Firefox, where the styles won't load until the iframe becomes visible.
1569 * For details of how we arrived at the strategy used in this function, see #load.
1573 * @param {HTMLDocument} parentDoc Document to transplant styles from
1574 * @param {HTMLDocument} frameDoc Document to transplant styles to
1575 * @param {number} [timeout=5000] How long to wait before giving up (in ms). If 0, never give up.
1576 * @return {jQuery.Promise} Promise resolved when styles have loaded
1578 OO
.ui
.Window
.static.transplantStyles = function ( parentDoc
, frameDoc
, timeout
) {
1579 var i
, numSheets
, styleNode
, styleText
, newNode
, timeoutID
, pollNodeId
, $pendingPollNodes
,
1580 $pollNodes
= $( [] ),
1581 // Fake font-family value
1582 fontFamily
= 'oo-ui-frame-transplantStyles-loaded',
1583 nextIndex
= parentDoc
.oouiFrameTransplantStylesNextIndex
|| 0,
1584 deferred
= $.Deferred();
1586 for ( i
= 0, numSheets
= parentDoc
.styleSheets
.length
; i
< numSheets
; i
++ ) {
1587 styleNode
= parentDoc
.styleSheets
[ i
].ownerNode
;
1588 if ( styleNode
.disabled
) {
1592 if ( styleNode
.nodeName
.toLowerCase() === 'link' ) {
1593 // External stylesheet; use @import
1594 styleText
= '@import url(' + styleNode
.href
+ ');';
1596 // Internal stylesheet; just copy the text
1597 // For IE10 we need to fall back to .cssText, BUT that's undefined in
1598 // other browsers, so fall back to '' rather than 'undefined'
1599 styleText
= styleNode
.textContent
|| parentDoc
.styleSheets
[ i
].cssText
|| '';
1602 // Create a node with a unique ID that we're going to monitor to see when the CSS
1604 if ( styleNode
.oouiFrameTransplantStylesId
) {
1605 // If we're nesting transplantStyles operations and this node already has
1606 // a CSS rule to wait for loading, reuse it
1607 pollNodeId
= styleNode
.oouiFrameTransplantStylesId
;
1609 // Otherwise, create a new ID
1610 pollNodeId
= 'oo-ui-frame-transplantStyles-loaded-' + nextIndex
;
1613 // Add #pollNodeId { font-family: ... } to the end of the stylesheet / after the @import
1614 // The font-family rule will only take effect once the @import finishes
1615 styleText
+= '\n' + '#' + pollNodeId
+ ' { font-family: ' + fontFamily
+ '; }';
1618 // Create a node with id=pollNodeId
1619 $pollNodes
= $pollNodes
.add( $( '<div>', frameDoc
)
1620 .attr( 'id', pollNodeId
)
1621 .appendTo( frameDoc
.body
)
1624 // Add our modified CSS as a <style> tag
1625 newNode
= frameDoc
.createElement( 'style' );
1626 newNode
.textContent
= styleText
;
1627 newNode
.oouiFrameTransplantStylesId
= pollNodeId
;
1628 frameDoc
.head
.appendChild( newNode
);
1630 frameDoc
.oouiFrameTransplantStylesNextIndex
= nextIndex
;
1632 // Poll every 100ms until all external stylesheets have loaded
1633 $pendingPollNodes
= $pollNodes
;
1634 timeoutID
= setTimeout( function pollExternalStylesheets() {
1636 $pendingPollNodes
.length
> 0 &&
1637 $pendingPollNodes
.eq( 0 ).css( 'font-family' ) === fontFamily
1639 $pendingPollNodes
= $pendingPollNodes
.slice( 1 );
1642 if ( $pendingPollNodes
.length
=== 0 ) {
1644 if ( timeoutID
!== null ) {
1646 $pollNodes
.remove();
1650 timeoutID
= setTimeout( pollExternalStylesheets
, 100 );
1653 // ...but give up after a while
1654 if ( timeout
!== 0 ) {
1655 setTimeout( function () {
1657 clearTimeout( timeoutID
);
1659 $pollNodes
.remove();
1662 }, timeout
|| 5000 );
1665 return deferred
.promise();
1671 * Handle mouse down events.
1673 * @param {jQuery.Event} e Mouse down event
1675 OO
.ui
.Window
.prototype.onMouseDown = function ( e
) {
1676 // Prevent clicking on the click-block from stealing focus
1677 if ( e
.target
=== this.$element
[ 0 ] ) {
1683 * Check if window has been initialized.
1685 * @return {boolean} Window has been initialized
1687 OO
.ui
.Window
.prototype.isInitialized = function () {
1688 return this.initialized
;
1692 * Check if window is visible.
1694 * @return {boolean} Window is visible
1696 OO
.ui
.Window
.prototype.isVisible = function () {
1697 return this.visible
;
1701 * Check if window is loading.
1703 * @return {boolean} Window is loading
1705 OO
.ui
.Window
.prototype.isLoading = function () {
1706 return this.loading
&& this.loading
.state() === 'pending';
1710 * Check if window is loaded.
1712 * @return {boolean} Window is loaded
1714 OO
.ui
.Window
.prototype.isLoaded = function () {
1715 return this.loading
&& this.loading
.state() === 'resolved';
1719 * Check if window is opening.
1721 * This is a wrapper around OO.ui.WindowManager#isOpening.
1723 * @return {boolean} Window is opening
1725 OO
.ui
.Window
.prototype.isOpening = function () {
1726 return this.manager
.isOpening( this );
1730 * Check if window is closing.
1732 * This is a wrapper around OO.ui.WindowManager#isClosing.
1734 * @return {boolean} Window is closing
1736 OO
.ui
.Window
.prototype.isClosing = function () {
1737 return this.manager
.isClosing( this );
1741 * Check if window is opened.
1743 * This is a wrapper around OO.ui.WindowManager#isOpened.
1745 * @return {boolean} Window is opened
1747 OO
.ui
.Window
.prototype.isOpened = function () {
1748 return this.manager
.isOpened( this );
1752 * Get the window manager.
1754 * @return {OO.ui.WindowManager} Manager of window
1756 OO
.ui
.Window
.prototype.getManager = function () {
1757 return this.manager
;
1761 * Get the window size.
1763 * @return {string} Symbolic size name, e.g. `small`, `medium`, `large`, `larger`, `full`
1765 OO
.ui
.Window
.prototype.getSize = function () {
1770 * Disable transitions on window's frame for the duration of the callback function, then enable them
1774 * @param {Function} callback Function to call while transitions are disabled
1776 OO
.ui
.Window
.prototype.withoutSizeTransitions = function ( callback
) {
1777 // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements.
1778 // Disable transitions first, otherwise we'll get values from when the window was animating.
1780 styleObj
= this.$frame
[ 0 ].style
;
1781 oldTransition
= styleObj
.transition
|| styleObj
.OTransition
|| styleObj
.MsTransition
||
1782 styleObj
.MozTransition
|| styleObj
.WebkitTransition
;
1783 styleObj
.transition
= styleObj
.OTransition
= styleObj
.MsTransition
=
1784 styleObj
.MozTransition
= styleObj
.WebkitTransition
= 'none';
1786 // Force reflow to make sure the style changes done inside callback really are not transitioned
1787 this.$frame
.height();
1788 styleObj
.transition
= styleObj
.OTransition
= styleObj
.MsTransition
=
1789 styleObj
.MozTransition
= styleObj
.WebkitTransition
= oldTransition
;
1793 * Get the height of the dialog contents.
1795 * @return {number} Content height
1797 OO
.ui
.Window
.prototype.getContentHeight = function () {
1800 bodyStyleObj
= this.$body
[ 0 ].style
,
1801 frameStyleObj
= this.$frame
[ 0 ].style
;
1803 // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements.
1804 // Disable transitions first, otherwise we'll get values from when the window was animating.
1805 this.withoutSizeTransitions( function () {
1806 var oldHeight
= frameStyleObj
.height
,
1807 oldPosition
= bodyStyleObj
.position
;
1808 frameStyleObj
.height
= '1px';
1809 // Force body to resize to new width
1810 bodyStyleObj
.position
= 'relative';
1811 bodyHeight
= win
.getBodyHeight();
1812 frameStyleObj
.height
= oldHeight
;
1813 bodyStyleObj
.position
= oldPosition
;
1817 // Add buffer for border
1818 ( this.$frame
.outerHeight() - this.$frame
.innerHeight() ) +
1819 // Use combined heights of children
1820 ( this.$head
.outerHeight( true ) + bodyHeight
+ this.$foot
.outerHeight( true ) )
1825 * Get the height of the dialog contents.
1827 * When this function is called, the dialog will temporarily have been resized
1828 * to height=1px, so .scrollHeight measurements can be taken accurately.
1830 * @return {number} Height of content
1832 OO
.ui
.Window
.prototype.getBodyHeight = function () {
1833 return this.$body
[ 0 ].scrollHeight
;
1837 * Get the directionality of the frame
1839 * @return {string} Directionality, 'ltr' or 'rtl'
1841 OO
.ui
.Window
.prototype.getDir = function () {
1846 * Get a process for setting up a window for use.
1848 * Each time the window is opened this process will set it up for use in a particular context, based
1849 * on the `data` argument.
1851 * When you override this method, you can add additional setup steps to the process the parent
1852 * method provides using the 'first' and 'next' methods.
1855 * @param {Object} [data] Window opening data
1856 * @return {OO.ui.Process} Setup process
1858 OO
.ui
.Window
.prototype.getSetupProcess = function () {
1859 return new OO
.ui
.Process();
1863 * Get a process for readying a window for use.
1865 * Each time the window is open and setup, this process will ready it up for use in a particular
1866 * context, based on the `data` argument.
1868 * When you override this method, you can add additional setup steps to the process the parent
1869 * method provides using the 'first' and 'next' methods.
1872 * @param {Object} [data] Window opening data
1873 * @return {OO.ui.Process} Setup process
1875 OO
.ui
.Window
.prototype.getReadyProcess = function () {
1876 return new OO
.ui
.Process();
1880 * Get a process for holding a window from use.
1882 * Each time the window is closed, this process will hold it from use in a particular context, based
1883 * on the `data` argument.
1885 * When you override this method, you can add additional setup steps to the process the parent
1886 * method provides using the 'first' and 'next' methods.
1889 * @param {Object} [data] Window closing data
1890 * @return {OO.ui.Process} Hold process
1892 OO
.ui
.Window
.prototype.getHoldProcess = function () {
1893 return new OO
.ui
.Process();
1897 * Get a process for tearing down a window after use.
1899 * Each time the window is closed this process will tear it down and do something with the user's
1900 * interactions within the window, based on the `data` argument.
1902 * When you override this method, you can add additional teardown steps to the process the parent
1903 * method provides using the 'first' and 'next' methods.
1906 * @param {Object} [data] Window closing data
1907 * @return {OO.ui.Process} Teardown process
1909 OO
.ui
.Window
.prototype.getTeardownProcess = function () {
1910 return new OO
.ui
.Process();
1914 * Toggle visibility of window.
1916 * If the window is isolated and hasn't fully loaded yet, the visibility property will be used
1917 * instead of display.
1919 * @param {boolean} [show] Make window visible, omit to toggle visibility
1923 OO
.ui
.Window
.prototype.toggle = function ( show
) {
1924 show
= show
=== undefined ? !this.visible
: !!show
;
1926 if ( show
!== this.isVisible() ) {
1927 this.visible
= show
;
1929 if ( this.isolated
&& !this.isLoaded() ) {
1930 // Hide the window using visibility instead of display until loading is complete
1931 // Can't use display: none; because that prevents the iframe from loading in Firefox
1932 this.$element
.css( 'visibility', show
? 'visible' : 'hidden' );
1934 this.$element
.toggle( show
).css( 'visibility', '' );
1936 this.emit( 'toggle', show
);
1943 * Set the window manager.
1945 * This must be called before initialize. Calling it more than once will cause an error.
1947 * @param {OO.ui.WindowManager} manager Manager for this window
1948 * @throws {Error} If called more than once
1951 OO
.ui
.Window
.prototype.setManager = function ( manager
) {
1952 if ( this.manager
) {
1953 throw new Error( 'Cannot set window manager, window already has a manager' );
1957 this.manager
= manager
;
1958 this.isolated
= manager
.shouldIsolate();
1961 if ( this.isolated
) {
1962 this.$iframe
= this.$( '<iframe>' );
1963 this.$iframe
.attr( { frameborder
: 0, scrolling
: 'no' } );
1964 this.$frame
.append( this.$iframe
);
1965 this.$ = function () {
1966 throw new Error( 'this.$() cannot be used until the frame has been initialized.' );
1968 // WARNING: Do not use this.$ again until #initialize is called
1970 this.$content
= this.$( '<div>' );
1971 this.$document
= $( this.getElementDocument() );
1972 this.$content
.addClass( 'oo-ui-window-content' ).attr( 'tabIndex', 0 );
1973 this.$frame
.append( this.$content
);
1975 this.toggle( false );
1977 // Figure out directionality:
1978 this.dir
= OO
.ui
.Element
.static.getDir( this.$iframe
|| this.$content
) || 'ltr';
1984 * Set the window size.
1986 * @param {string} size Symbolic size name, e.g. 'small', 'medium', 'large', 'full'
1989 OO
.ui
.Window
.prototype.setSize = function ( size
) {
1996 * Update the window size.
2000 OO
.ui
.Window
.prototype.updateSize = function () {
2001 this.manager
.updateWindowSize( this );
2006 * Set window dimensions.
2008 * Properties are applied to the frame container.
2010 * @param {Object} dim CSS dimension properties
2011 * @param {string|number} [dim.width] Width
2012 * @param {string|number} [dim.minWidth] Minimum width
2013 * @param {string|number} [dim.maxWidth] Maximum width
2014 * @param {string|number} [dim.width] Height, omit to set based on height of contents
2015 * @param {string|number} [dim.minWidth] Minimum height
2016 * @param {string|number} [dim.maxWidth] Maximum height
2019 OO
.ui
.Window
.prototype.setDimensions = function ( dim
) {
2022 styleObj
= this.$frame
[ 0 ].style
;
2024 // Calculate the height we need to set using the correct width
2025 if ( dim
.height
=== undefined ) {
2026 this.withoutSizeTransitions( function () {
2027 var oldWidth
= styleObj
.width
;
2028 win
.$frame
.css( 'width', dim
.width
|| '' );
2029 height
= win
.getContentHeight();
2030 styleObj
.width
= oldWidth
;
2033 height
= dim
.height
;
2037 width
: dim
.width
|| '',
2038 minWidth
: dim
.minWidth
|| '',
2039 maxWidth
: dim
.maxWidth
|| '',
2040 height
: height
|| '',
2041 minHeight
: dim
.minHeight
|| '',
2042 maxHeight
: dim
.maxHeight
|| ''
2049 * Initialize window contents.
2051 * The first time the window is opened, #initialize is called when it's safe to begin populating
2052 * its contents. See #getSetupProcess for a way to make changes each time the window opens.
2054 * Once this method is called, this.$ can be used to create elements within the frame.
2056 * @throws {Error} If not attached to a manager
2059 OO
.ui
.Window
.prototype.initialize = function () {
2060 if ( !this.manager
) {
2061 throw new Error( 'Cannot initialize window, must be attached to a manager' );
2065 this.$head
= this.$( '<div>' );
2066 this.$body
= this.$( '<div>' );
2067 this.$foot
= this.$( '<div>' );
2068 this.$innerOverlay
= this.$( '<div>' );
2071 this.$element
.on( 'mousedown', this.onMouseDown
.bind( this ) );
2074 this.$head
.addClass( 'oo-ui-window-head' );
2075 this.$body
.addClass( 'oo-ui-window-body' );
2076 this.$foot
.addClass( 'oo-ui-window-foot' );
2077 this.$innerOverlay
.addClass( 'oo-ui-window-inner-overlay' );
2078 this.$content
.append( this.$head
, this.$body
, this.$foot
, this.$innerOverlay
);
2086 * This is a wrapper around calling {@link OO.ui.WindowManager#openWindow} on the window manager.
2087 * To do something each time the window opens, use #getSetupProcess or #getReadyProcess.
2089 * @param {Object} [data] Window opening data
2090 * @return {jQuery.Promise} Promise resolved when window is opened; when the promise is resolved the
2091 * first argument will be a promise which will be resolved when the window begins closing
2093 OO
.ui
.Window
.prototype.open = function ( data
) {
2094 return this.manager
.openWindow( this, data
);
2100 * This is a wrapper around calling OO.ui.WindowManager#closeWindow on the window manager.
2101 * To do something each time the window closes, use #getHoldProcess or #getTeardownProcess.
2103 * @param {Object} [data] Window closing data
2104 * @return {jQuery.Promise} Promise resolved when window is closed
2106 OO
.ui
.Window
.prototype.close = function ( data
) {
2107 return this.manager
.closeWindow( this, data
);
2113 * This is called by OO.ui.WindowManager during window opening, and should not be called directly
2116 * @param {Object} [data] Window opening data
2117 * @return {jQuery.Promise} Promise resolved when window is setup
2119 OO
.ui
.Window
.prototype.setup = function ( data
) {
2121 deferred
= $.Deferred();
2123 this.$element
.show();
2124 this.visible
= true;
2125 this.getSetupProcess( data
).execute().done( function () {
2126 // Force redraw by asking the browser to measure the elements' widths
2127 win
.$element
.addClass( 'oo-ui-window-setup' ).width();
2128 win
.$content
.addClass( 'oo-ui-window-content-setup' ).width();
2132 return deferred
.promise();
2138 * This is called by OO.ui.WindowManager during window opening, and should not be called directly
2141 * @param {Object} [data] Window opening data
2142 * @return {jQuery.Promise} Promise resolved when window is ready
2144 OO
.ui
.Window
.prototype.ready = function ( data
) {
2146 deferred
= $.Deferred();
2148 this.$content
.focus();
2149 this.getReadyProcess( data
).execute().done( function () {
2150 // Force redraw by asking the browser to measure the elements' widths
2151 win
.$element
.addClass( 'oo-ui-window-ready' ).width();
2152 win
.$content
.addClass( 'oo-ui-window-content-ready' ).width();
2156 return deferred
.promise();
2162 * This is called by OO.ui.WindowManager during window closing, and should not be called directly
2165 * @param {Object} [data] Window closing data
2166 * @return {jQuery.Promise} Promise resolved when window is held
2168 OO
.ui
.Window
.prototype.hold = function ( data
) {
2170 deferred
= $.Deferred();
2172 this.getHoldProcess( data
).execute().done( function () {
2173 // Get the focused element within the window's content
2174 var $focus
= win
.$content
.find( OO
.ui
.Element
.static.getDocument( win
.$content
).activeElement
);
2176 // Blur the focused element
2177 if ( $focus
.length
) {
2181 // Force redraw by asking the browser to measure the elements' widths
2182 win
.$element
.removeClass( 'oo-ui-window-ready' ).width();
2183 win
.$content
.removeClass( 'oo-ui-window-content-ready' ).width();
2187 return deferred
.promise();
2193 * This is called by OO.ui.WindowManager during window closing, and should not be called directly
2196 * @param {Object} [data] Window closing data
2197 * @return {jQuery.Promise} Promise resolved when window is torn down
2199 OO
.ui
.Window
.prototype.teardown = function ( data
) {
2201 deferred
= $.Deferred();
2203 this.getTeardownProcess( data
).execute().done( function () {
2204 // Force redraw by asking the browser to measure the elements' widths
2205 win
.$element
.removeClass( 'oo-ui-window-load oo-ui-window-setup' ).width();
2206 win
.$content
.removeClass( 'oo-ui-window-content-setup' ).width();
2207 win
.$element
.hide();
2208 win
.visible
= false;
2212 return deferred
.promise();
2216 * Load the frame contents.
2218 * Once the iframe's stylesheets are loaded the returned promise will be resolved. Calling while
2219 * loading will return a promise but not trigger a new loading cycle. Calling after loading is
2220 * complete will return a promise that's already been resolved.
2222 * Sounds simple right? Read on...
2224 * When you create a dynamic iframe using open/write/close, the window.load event for the
2225 * iframe is triggered when you call close, and there's no further load event to indicate that
2226 * everything is actually loaded.
2228 * In Chrome, stylesheets don't show up in document.styleSheets until they have loaded, so we could
2229 * just poll that array and wait for it to have the right length. However, in Firefox, stylesheets
2230 * are added to document.styleSheets immediately, and the only way you can determine whether they've
2231 * loaded is to attempt to access .cssRules and wait for that to stop throwing an exception. But
2232 * cross-domain stylesheets never allow .cssRules to be accessed even after they have loaded.
2234 * The workaround is to change all `<link href="...">` tags to `<style>@import url(...)</style>`
2235 * tags. Because `@import` is blocking, Chrome won't add the stylesheet to document.styleSheets
2236 * until the `@import` has finished, and Firefox won't allow .cssRules to be accessed until the
2237 * `@import` has finished. And because the contents of the `<style>` tag are from the same origin,
2238 * accessing .cssRules is allowed.
2240 * However, now that we control the styles we're injecting, we might as well do away with
2241 * browser-specific polling hacks like document.styleSheets and .cssRules, and instead inject
2242 * `<style>@import url(...); #foo { font-family: someValue; }</style>`, then create `<div id="foo">`
2243 * and wait for its font-family to change to someValue. Because `@import` is blocking, the
2244 * font-family rule is not applied until after the `@import` finishes.
2246 * All this stylesheet injection and polling magic is in #transplantStyles.
2248 * @return {jQuery.Promise} Promise resolved when loading is complete
2250 OO
.ui
.Window
.prototype.load = function () {
2251 var sub
, doc
, loading
,
2254 this.$element
.addClass( 'oo-ui-window-load' );
2256 // Non-isolated windows are already "loaded"
2257 if ( !this.loading
&& !this.isolated
) {
2258 this.loading
= $.Deferred().resolve();
2260 // Set initialized state after so sub-classes aren't confused by it being set by calling
2261 // their parent initialize method
2262 this.initialized
= true;
2265 // Return existing promise if already loading or loaded
2266 if ( this.loading
) {
2267 return this.loading
.promise();
2271 loading
= this.loading
= $.Deferred();
2272 sub
= this.$iframe
.prop( 'contentWindow' );
2275 // Initialize contents
2280 '<body class="oo-ui-window-isolated oo-ui-' + this.dir
+ '"' +
2281 ' style="direction:' + this.dir
+ ';" dir="' + this.dir
+ '">' +
2282 '<div class="oo-ui-window-content"></div>' +
2289 this.$ = OO
.ui
.Element
.static.getJQuery( doc
, this.$iframe
);
2290 this.$content
= this.$( '.oo-ui-window-content' ).attr( 'tabIndex', 0 );
2291 this.$document
= this.$( doc
);
2294 this.constructor.static.transplantStyles( this.getElementDocument(), this.$document
[ 0 ] )
2295 .always( function () {
2296 // Initialize isolated windows
2298 // Set initialized state after so sub-classes aren't confused by it being set by calling
2299 // their parent initialize method
2300 win
.initialized
= true;
2301 // Undo the visibility: hidden; hack and apply display: none;
2302 // We can do this safely now that the iframe has initialized
2303 // (don't do this from within #initialize because it has to happen
2304 // after the all subclasses have been handled as well).
2305 win
.toggle( win
.isVisible() );
2310 return loading
.promise();
2314 * Base class for all dialogs.
2317 * - Manage the window (open and close, etc.).
2318 * - Store the internal name and display title.
2319 * - A stack to track one or more pending actions.
2320 * - Manage a set of actions that can be performed.
2321 * - Configure and create action widgets.
2324 * - Close the dialog with Escape key.
2325 * - Visually lock the dialog while an action is in
2326 * progress (aka "pending").
2328 * Subclass responsibilities:
2329 * - Display the title somewhere.
2330 * - Add content to the dialog.
2331 * - Provide a UI to close the dialog.
2332 * - Display the action widgets somewhere.
2336 * @extends OO.ui.Window
2337 * @mixins OO.ui.PendingElement
2340 * @param {Object} [config] Configuration options
2342 OO
.ui
.Dialog
= function OoUiDialog( config
) {
2343 // Parent constructor
2344 OO
.ui
.Dialog
.super.call( this, config
);
2346 // Mixin constructors
2347 OO
.ui
.PendingElement
.call( this );
2350 this.actions
= new OO
.ui
.ActionSet();
2351 this.attachedActions
= [];
2352 this.currentAction
= null;
2353 this.onDocumentKeyDownHandler
= this.onDocumentKeyDown
.bind( this );
2356 this.actions
.connect( this, {
2357 click
: 'onActionClick',
2358 resize
: 'onActionResize',
2359 change
: 'onActionsChange'
2364 .addClass( 'oo-ui-dialog' )
2365 .attr( 'role', 'dialog' );
2370 OO
.inheritClass( OO
.ui
.Dialog
, OO
.ui
.Window
);
2371 OO
.mixinClass( OO
.ui
.Dialog
, OO
.ui
.PendingElement
);
2373 /* Static Properties */
2376 * Symbolic name of dialog.
2381 * @property {string}
2383 OO
.ui
.Dialog
.static.name
= '';
2391 * @property {jQuery|string|Function} Label nodes, text or a function that returns nodes or text
2393 OO
.ui
.Dialog
.static.title
= '';
2396 * List of OO.ui.ActionWidget configuration options.
2400 * @property {Object[]}
2402 OO
.ui
.Dialog
.static.actions
= [];
2405 * Close dialog when the escape key is pressed.
2410 * @property {boolean}
2412 OO
.ui
.Dialog
.static.escapable
= true;
2417 * Handle frame document key down events.
2419 * @param {jQuery.Event} e Key down event
2421 OO
.ui
.Dialog
.prototype.onDocumentKeyDown = function ( e
) {
2422 if ( e
.which
=== OO
.ui
.Keys
.ESCAPE
) {
2425 e
.stopPropagation();
2430 * Handle action resized events.
2432 * @param {OO.ui.ActionWidget} action Action that was resized
2434 OO
.ui
.Dialog
.prototype.onActionResize = function () {
2435 // Override in subclass
2439 * Handle action click events.
2441 * @param {OO.ui.ActionWidget} action Action that was clicked
2443 OO
.ui
.Dialog
.prototype.onActionClick = function ( action
) {
2444 if ( !this.isPending() ) {
2445 this.currentAction
= action
;
2446 this.executeAction( action
.getAction() );
2451 * Handle actions change event.
2453 OO
.ui
.Dialog
.prototype.onActionsChange = function () {
2454 this.detachActions();
2455 if ( !this.isClosing() ) {
2456 this.attachActions();
2461 * Get set of actions.
2463 * @return {OO.ui.ActionSet}
2465 OO
.ui
.Dialog
.prototype.getActions = function () {
2466 return this.actions
;
2470 * Get a process for taking action.
2472 * When you override this method, you can add additional accept steps to the process the parent
2473 * method provides using the 'first' and 'next' methods.
2476 * @param {string} [action] Symbolic name of action
2477 * @return {OO.ui.Process} Action process
2479 OO
.ui
.Dialog
.prototype.getActionProcess = function ( action
) {
2480 return new OO
.ui
.Process()
2481 .next( function () {
2483 // An empty action always closes the dialog without data, which should always be
2484 // safe and make no changes
2493 * @param {Object} [data] Dialog opening data
2494 * @param {jQuery|string|Function|null} [data.title] Dialog title, omit to use #static-title
2495 * @param {Object[]} [data.actions] List of OO.ui.ActionWidget configuration options for each
2496 * action item, omit to use #static-actions
2498 OO
.ui
.Dialog
.prototype.getSetupProcess = function ( data
) {
2502 return OO
.ui
.Dialog
.super.prototype.getSetupProcess
.call( this, data
)
2503 .next( function () {
2506 config
= this.constructor.static,
2507 actions
= data
.actions
!== undefined ? data
.actions
: config
.actions
;
2509 this.title
.setLabel(
2510 data
.title
!== undefined ? data
.title
: this.constructor.static.title
2512 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
2514 new OO
.ui
.ActionWidget( $.extend( { $: this.$ }, actions
[ i
] ) )
2517 this.actions
.add( items
);
2519 if ( this.constructor.static.escapable
) {
2520 this.$document
.on( 'keydown', this.onDocumentKeyDownHandler
);
2528 OO
.ui
.Dialog
.prototype.getTeardownProcess = function ( data
) {
2530 return OO
.ui
.Dialog
.super.prototype.getTeardownProcess
.call( this, data
)
2531 .first( function () {
2532 if ( this.constructor.static.escapable
) {
2533 this.$document
.off( 'keydown', this.onDocumentKeyDownHandler
);
2536 this.actions
.clear();
2537 this.currentAction
= null;
2544 OO
.ui
.Dialog
.prototype.initialize = function () {
2546 OO
.ui
.Dialog
.super.prototype.initialize
.call( this );
2549 this.title
= new OO
.ui
.LabelWidget( { $: this.$ } );
2552 this.$content
.addClass( 'oo-ui-dialog-content' );
2553 this.setPendingElement( this.$head
);
2557 * Attach action actions.
2559 OO
.ui
.Dialog
.prototype.attachActions = function () {
2560 // Remember the list of potentially attached actions
2561 this.attachedActions
= this.actions
.get();
2565 * Detach action actions.
2569 OO
.ui
.Dialog
.prototype.detachActions = function () {
2572 // Detach all actions that may have been previously attached
2573 for ( i
= 0, len
= this.attachedActions
.length
; i
< len
; i
++ ) {
2574 this.attachedActions
[ i
].$element
.detach();
2576 this.attachedActions
= [];
2580 * Execute an action.
2582 * @param {string} action Symbolic name of action to execute
2583 * @return {jQuery.Promise} Promise resolved when action completes, rejected if it fails
2585 OO
.ui
.Dialog
.prototype.executeAction = function ( action
) {
2587 return this.getActionProcess( action
).execute()
2588 .always( this.popPending
.bind( this ) );
2592 * Collection of windows.
2595 * @extends OO.ui.Element
2596 * @mixins OO.EventEmitter
2598 * Managed windows are mutually exclusive. If a window is opened while there is a current window
2599 * already opening or opened, the current window will be closed without data. Empty closing data
2600 * should always result in the window being closed without causing constructive or destructive
2603 * As a window is opened and closed, it passes through several stages and the manager emits several
2604 * corresponding events.
2606 * - {@link #openWindow} or {@link OO.ui.Window#open} methods are used to start opening
2607 * - {@link #event-opening} is emitted with `opening` promise
2608 * - {@link #getSetupDelay} is called the returned value is used to time a pause in execution
2609 * - {@link OO.ui.Window#getSetupProcess} method is called on the window and its result executed
2610 * - `setup` progress notification is emitted from opening promise
2611 * - {@link #getReadyDelay} is called the returned value is used to time a pause in execution
2612 * - {@link OO.ui.Window#getReadyProcess} method is called on the window and its result executed
2613 * - `ready` progress notification is emitted from opening promise
2614 * - `opening` promise is resolved with `opened` promise
2615 * - Window is now open
2617 * - {@link #closeWindow} or {@link OO.ui.Window#close} methods are used to start closing
2618 * - `opened` promise is resolved with `closing` promise
2619 * - {@link #event-closing} is emitted with `closing` promise
2620 * - {@link #getHoldDelay} is called the returned value is used to time a pause in execution
2621 * - {@link OO.ui.Window#getHoldProcess} method is called on the window and its result executed
2622 * - `hold` progress notification is emitted from opening promise
2623 * - {@link #getTeardownDelay} is called the returned value is used to time a pause in execution
2624 * - {@link OO.ui.Window#getTeardownProcess} method is called on the window and its result executed
2625 * - `teardown` progress notification is emitted from opening promise
2626 * - Closing promise is resolved
2627 * - Window is now closed
2630 * @param {Object} [config] Configuration options
2631 * @cfg {boolean} [isolate] Configure managed windows to isolate their content using inline frames
2632 * @cfg {OO.Factory} [factory] Window factory to use for automatic instantiation
2633 * @cfg {boolean} [modal=true] Prevent interaction outside the dialog
2635 OO
.ui
.WindowManager
= function OoUiWindowManager( config
) {
2636 // Configuration initialization
2637 config
= config
|| {};
2639 // Parent constructor
2640 OO
.ui
.WindowManager
.super.call( this, config
);
2642 // Mixin constructors
2643 OO
.EventEmitter
.call( this );
2646 this.factory
= config
.factory
;
2647 this.modal
= config
.modal
=== undefined || !!config
.modal
;
2648 this.isolate
= !!config
.isolate
;
2650 this.opening
= null;
2652 this.closing
= null;
2653 this.preparingToOpen
= null;
2654 this.preparingToClose
= null;
2656 this.currentWindow
= null;
2657 this.$ariaHidden
= null;
2658 this.requestedSize
= null;
2659 this.onWindowResizeTimeout
= null;
2660 this.onWindowResizeHandler
= this.onWindowResize
.bind( this );
2661 this.afterWindowResizeHandler
= this.afterWindowResize
.bind( this );
2662 this.onWindowMouseWheelHandler
= this.onWindowMouseWheel
.bind( this );
2663 this.onDocumentKeyDownHandler
= this.onDocumentKeyDown
.bind( this );
2667 .addClass( 'oo-ui-windowManager' )
2668 .toggleClass( 'oo-ui-windowManager-modal', this.modal
);
2673 OO
.inheritClass( OO
.ui
.WindowManager
, OO
.ui
.Element
);
2674 OO
.mixinClass( OO
.ui
.WindowManager
, OO
.EventEmitter
);
2679 * Window is opening.
2681 * Fired when the window begins to be opened.
2684 * @param {OO.ui.Window} win Window that's being opened
2685 * @param {jQuery.Promise} opening Promise resolved when window is opened; when the promise is
2686 * resolved the first argument will be a promise which will be resolved when the window begins
2687 * closing, the second argument will be the opening data; progress notifications will be fired on
2688 * the promise for `setup` and `ready` when those processes are completed respectively.
2689 * @param {Object} data Window opening data
2693 * Window is closing.
2695 * Fired when the window begins to be closed.
2698 * @param {OO.ui.Window} win Window that's being closed
2699 * @param {jQuery.Promise} opening Promise resolved when window is closed; when the promise
2700 * is resolved the first argument will be a the closing data; progress notifications will be fired
2701 * on the promise for `hold` and `teardown` when those processes are completed respectively.
2702 * @param {Object} data Window closing data
2706 * Window was resized.
2709 * @param {OO.ui.Window} win Window that was resized
2712 /* Static Properties */
2715 * Map of symbolic size names and CSS properties.
2719 * @property {Object}
2721 OO
.ui
.WindowManager
.static.sizes
= {
2735 // These can be non-numeric because they are never used in calculations
2742 * Symbolic name of default size.
2744 * Default size is used if the window's requested size is not recognized.
2748 * @property {string}
2750 OO
.ui
.WindowManager
.static.defaultSize
= 'medium';
2755 * Handle window resize events.
2757 * @param {jQuery.Event} e Window resize event
2759 OO
.ui
.WindowManager
.prototype.onWindowResize = function () {
2760 clearTimeout( this.onWindowResizeTimeout
);
2761 this.onWindowResizeTimeout
= setTimeout( this.afterWindowResizeHandler
, 200 );
2765 * Handle window resize events.
2767 * @param {jQuery.Event} e Window resize event
2769 OO
.ui
.WindowManager
.prototype.afterWindowResize = function () {
2770 if ( this.currentWindow
) {
2771 this.updateWindowSize( this.currentWindow
);
2776 * Handle window mouse wheel events.
2778 * @param {jQuery.Event} e Mouse wheel event
2780 OO
.ui
.WindowManager
.prototype.onWindowMouseWheel = function () {
2781 // Kill all events in the parent window if the child window is isolated
2782 return !this.shouldIsolate();
2786 * Handle document key down events.
2788 * @param {jQuery.Event} e Key down event
2790 OO
.ui
.WindowManager
.prototype.onDocumentKeyDown = function ( e
) {
2791 switch ( e
.which
) {
2792 case OO
.ui
.Keys
.PAGEUP
:
2793 case OO
.ui
.Keys
.PAGEDOWN
:
2794 case OO
.ui
.Keys
.END
:
2795 case OO
.ui
.Keys
.HOME
:
2796 case OO
.ui
.Keys
.LEFT
:
2798 case OO
.ui
.Keys
.RIGHT
:
2799 case OO
.ui
.Keys
.DOWN
:
2800 // Kill all events in the parent window if the child window is isolated
2801 return !this.shouldIsolate();
2806 * Check if window is opening.
2808 * @return {boolean} Window is opening
2810 OO
.ui
.WindowManager
.prototype.isOpening = function ( win
) {
2811 return win
=== this.currentWindow
&& !!this.opening
&& this.opening
.state() === 'pending';
2815 * Check if window is closing.
2817 * @return {boolean} Window is closing
2819 OO
.ui
.WindowManager
.prototype.isClosing = function ( win
) {
2820 return win
=== this.currentWindow
&& !!this.closing
&& this.closing
.state() === 'pending';
2824 * Check if window is opened.
2826 * @return {boolean} Window is opened
2828 OO
.ui
.WindowManager
.prototype.isOpened = function ( win
) {
2829 return win
=== this.currentWindow
&& !!this.opened
&& this.opened
.state() === 'pending';
2833 * Check if window contents should be isolated.
2835 * Window content isolation is done using inline frames.
2837 * @return {boolean} Window contents should be isolated
2839 OO
.ui
.WindowManager
.prototype.shouldIsolate = function () {
2840 return this.isolate
;
2844 * Check if a window is being managed.
2846 * @param {OO.ui.Window} win Window to check
2847 * @return {boolean} Window is being managed
2849 OO
.ui
.WindowManager
.prototype.hasWindow = function ( win
) {
2852 for ( name
in this.windows
) {
2853 if ( this.windows
[ name
] === win
) {
2862 * Get the number of milliseconds to wait between beginning opening and executing setup process.
2864 * @param {OO.ui.Window} win Window being opened
2865 * @param {Object} [data] Window opening data
2866 * @return {number} Milliseconds to wait
2868 OO
.ui
.WindowManager
.prototype.getSetupDelay = function () {
2873 * Get the number of milliseconds to wait between finishing setup and executing ready process.
2875 * @param {OO.ui.Window} win Window being opened
2876 * @param {Object} [data] Window opening data
2877 * @return {number} Milliseconds to wait
2879 OO
.ui
.WindowManager
.prototype.getReadyDelay = function () {
2884 * Get the number of milliseconds to wait between beginning closing and executing hold process.
2886 * @param {OO.ui.Window} win Window being closed
2887 * @param {Object} [data] Window closing data
2888 * @return {number} Milliseconds to wait
2890 OO
.ui
.WindowManager
.prototype.getHoldDelay = function () {
2895 * Get the number of milliseconds to wait between finishing hold and executing teardown process.
2897 * @param {OO.ui.Window} win Window being closed
2898 * @param {Object} [data] Window closing data
2899 * @return {number} Milliseconds to wait
2901 OO
.ui
.WindowManager
.prototype.getTeardownDelay = function () {
2902 return this.modal
? 250 : 0;
2906 * Get managed window by symbolic name.
2908 * If window is not yet instantiated, it will be instantiated and added automatically.
2910 * @param {string} name Symbolic window name
2911 * @return {jQuery.Promise} Promise resolved with matching window, or rejected with an OO.ui.Error
2912 * @throws {Error} If the symbolic name is unrecognized by the factory
2913 * @throws {Error} If the symbolic name unrecognized as a managed window
2915 OO
.ui
.WindowManager
.prototype.getWindow = function ( name
) {
2916 var deferred
= $.Deferred(),
2917 win
= this.windows
[ name
];
2919 if ( !( win
instanceof OO
.ui
.Window
) ) {
2920 if ( this.factory
) {
2921 if ( !this.factory
.lookup( name
) ) {
2922 deferred
.reject( new OO
.ui
.Error(
2923 'Cannot auto-instantiate window: symbolic name is unrecognized by the factory'
2926 win
= this.factory
.create( name
, this, { $: this.$ } );
2927 this.addWindows( [ win
] );
2928 deferred
.resolve( win
);
2931 deferred
.reject( new OO
.ui
.Error(
2932 'Cannot get unmanaged window: symbolic name unrecognized as a managed window'
2936 deferred
.resolve( win
);
2939 return deferred
.promise();
2943 * Get current window.
2945 * @return {OO.ui.Window|null} Currently opening/opened/closing window
2947 OO
.ui
.WindowManager
.prototype.getCurrentWindow = function () {
2948 return this.currentWindow
;
2954 * @param {OO.ui.Window|string} win Window object or symbolic name of window to open
2955 * @param {Object} [data] Window opening data
2956 * @return {jQuery.Promise} Promise resolved when window is done opening; see {@link #event-opening}
2957 * for more details about the `opening` promise
2960 OO
.ui
.WindowManager
.prototype.openWindow = function ( win
, data
) {
2963 opening
= $.Deferred();
2965 // Argument handling
2966 if ( typeof win
=== 'string' ) {
2967 return this.getWindow( win
).then( function ( win
) {
2968 return manager
.openWindow( win
, data
);
2973 if ( !this.hasWindow( win
) ) {
2974 opening
.reject( new OO
.ui
.Error(
2975 'Cannot open window: window is not attached to manager'
2977 } else if ( this.preparingToOpen
|| this.opening
|| this.opened
) {
2978 opening
.reject( new OO
.ui
.Error(
2979 'Cannot open window: another window is opening or open'
2984 if ( opening
.state() !== 'rejected' ) {
2985 if ( !win
.getManager() ) {
2986 win
.setManager( this );
2988 preparing
.push( win
.load() );
2990 if ( this.closing
) {
2991 // If a window is currently closing, wait for it to complete
2992 preparing
.push( this.closing
);
2995 this.preparingToOpen
= $.when
.apply( $, preparing
);
2996 // Ensure handlers get called after preparingToOpen is set
2997 this.preparingToOpen
.done( function () {
2998 if ( manager
.modal
) {
2999 manager
.toggleGlobalEvents( true );
3000 manager
.toggleAriaIsolation( true );
3002 manager
.currentWindow
= win
;
3003 manager
.opening
= opening
;
3004 manager
.preparingToOpen
= null;
3005 manager
.emit( 'opening', win
, opening
, data
);
3006 setTimeout( function () {
3007 win
.setup( data
).then( function () {
3008 manager
.updateWindowSize( win
);
3009 manager
.opening
.notify( { state
: 'setup' } );
3010 setTimeout( function () {
3011 win
.ready( data
).then( function () {
3012 manager
.opening
.notify( { state
: 'ready' } );
3013 manager
.opening
= null;
3014 manager
.opened
= $.Deferred();
3015 opening
.resolve( manager
.opened
.promise(), data
);
3017 }, manager
.getReadyDelay() );
3019 }, manager
.getSetupDelay() );
3023 return opening
.promise();
3029 * @param {OO.ui.Window|string} win Window object or symbolic name of window to close
3030 * @param {Object} [data] Window closing data
3031 * @return {jQuery.Promise} Promise resolved when window is done closing; see {@link #event-closing}
3032 * for more details about the `closing` promise
3033 * @throws {Error} If no window by that name is being managed
3036 OO
.ui
.WindowManager
.prototype.closeWindow = function ( win
, data
) {
3039 closing
= $.Deferred(),
3042 // Argument handling
3043 if ( typeof win
=== 'string' ) {
3044 win
= this.windows
[ win
];
3045 } else if ( !this.hasWindow( win
) ) {
3051 closing
.reject( new OO
.ui
.Error(
3052 'Cannot close window: window is not attached to manager'
3054 } else if ( win
!== this.currentWindow
) {
3055 closing
.reject( new OO
.ui
.Error(
3056 'Cannot close window: window already closed with different data'
3058 } else if ( this.preparingToClose
|| this.closing
) {
3059 closing
.reject( new OO
.ui
.Error(
3060 'Cannot close window: window already closing with different data'
3065 if ( closing
.state() !== 'rejected' ) {
3066 if ( this.opening
) {
3067 // If the window is currently opening, close it when it's done
3068 preparing
.push( this.opening
);
3071 this.preparingToClose
= $.when
.apply( $, preparing
);
3072 // Ensure handlers get called after preparingToClose is set
3073 this.preparingToClose
.done( function () {
3074 manager
.closing
= closing
;
3075 manager
.preparingToClose
= null;
3076 manager
.emit( 'closing', win
, closing
, data
);
3077 opened
= manager
.opened
;
3078 manager
.opened
= null;
3079 opened
.resolve( closing
.promise(), data
);
3080 setTimeout( function () {
3081 win
.hold( data
).then( function () {
3082 closing
.notify( { state
: 'hold' } );
3083 setTimeout( function () {
3084 win
.teardown( data
).then( function () {
3085 closing
.notify( { state
: 'teardown' } );
3086 if ( manager
.modal
) {
3087 manager
.toggleGlobalEvents( false );
3088 manager
.toggleAriaIsolation( false );
3090 manager
.closing
= null;
3091 manager
.currentWindow
= null;
3092 closing
.resolve( data
);
3094 }, manager
.getTeardownDelay() );
3096 }, manager
.getHoldDelay() );
3100 return closing
.promise();
3106 * @param {Object.<string,OO.ui.Window>|OO.ui.Window[]} windows Windows to add
3107 * @throws {Error} If one of the windows being added without an explicit symbolic name does not have
3108 * a statically configured symbolic name
3110 OO
.ui
.WindowManager
.prototype.addWindows = function ( windows
) {
3111 var i
, len
, win
, name
, list
;
3113 if ( $.isArray( windows
) ) {
3114 // Convert to map of windows by looking up symbolic names from static configuration
3116 for ( i
= 0, len
= windows
.length
; i
< len
; i
++ ) {
3117 name
= windows
[ i
].constructor.static.name
;
3118 if ( typeof name
!== 'string' ) {
3119 throw new Error( 'Cannot add window' );
3121 list
[ name
] = windows
[ i
];
3123 } else if ( $.isPlainObject( windows
) ) {
3128 for ( name
in list
) {
3130 this.windows
[ name
] = win
;
3131 this.$element
.append( win
.$element
);
3138 * Windows will be closed before they are removed.
3140 * @param {string[]} names Symbolic names of windows to remove
3141 * @return {jQuery.Promise} Promise resolved when window is closed and removed
3142 * @throws {Error} If windows being removed are not being managed
3144 OO
.ui
.WindowManager
.prototype.removeWindows = function ( names
) {
3145 var i
, len
, win
, name
, cleanupWindow
,
3148 cleanup = function ( name
, win
) {
3149 delete manager
.windows
[ name
];
3150 win
.$element
.detach();
3153 for ( i
= 0, len
= names
.length
; i
< len
; i
++ ) {
3155 win
= this.windows
[ name
];
3157 throw new Error( 'Cannot remove window' );
3159 cleanupWindow
= cleanup
.bind( null, name
, win
);
3160 promises
.push( this.closeWindow( name
).then( cleanupWindow
, cleanupWindow
) );
3163 return $.when
.apply( $, promises
);
3167 * Remove all windows.
3169 * Windows will be closed before they are removed.
3171 * @return {jQuery.Promise} Promise resolved when all windows are closed and removed
3173 OO
.ui
.WindowManager
.prototype.clearWindows = function () {
3174 return this.removeWindows( Object
.keys( this.windows
) );
3180 * Fullscreen mode will be used if the dialog is too wide to fit in the screen.
3184 OO
.ui
.WindowManager
.prototype.updateWindowSize = function ( win
) {
3185 // Bypass for non-current, and thus invisible, windows
3186 if ( win
!== this.currentWindow
) {
3190 var viewport
= OO
.ui
.Element
.static.getDimensions( win
.getElementWindow() ),
3191 sizes
= this.constructor.static.sizes
,
3192 size
= win
.getSize();
3194 if ( !sizes
[ size
] ) {
3195 size
= this.constructor.static.defaultSize
;
3197 if ( size
!== 'full' && viewport
.rect
.right
- viewport
.rect
.left
< sizes
[ size
].width
) {
3201 this.$element
.toggleClass( 'oo-ui-windowManager-fullscreen', size
=== 'full' );
3202 this.$element
.toggleClass( 'oo-ui-windowManager-floating', size
!== 'full' );
3203 win
.setDimensions( sizes
[ size
] );
3205 this.emit( 'resize', win
);
3211 * Bind or unbind global events for scrolling.
3213 * @param {boolean} [on] Bind global events
3216 OO
.ui
.WindowManager
.prototype.toggleGlobalEvents = function ( on
) {
3217 on
= on
=== undefined ? !!this.globalEvents
: !!on
;
3220 if ( !this.globalEvents
) {
3221 this.$( this.getElementDocument() ).on( {
3222 // Prevent scrolling by keys in top-level window
3223 keydown
: this.onDocumentKeyDownHandler
3225 this.$( this.getElementWindow() ).on( {
3226 // Prevent scrolling by wheel in top-level window
3227 mousewheel
: this.onWindowMouseWheelHandler
,
3228 // Start listening for top-level window dimension changes
3229 'orientationchange resize': this.onWindowResizeHandler
3231 // Disable window scrolling in isolated windows
3232 if ( !this.shouldIsolate() ) {
3233 $( this.getElementDocument().body
).css( 'overflow', 'hidden' );
3235 this.globalEvents
= true;
3237 } else if ( this.globalEvents
) {
3238 // Unbind global events
3239 this.$( this.getElementDocument() ).off( {
3240 // Allow scrolling by keys in top-level window
3241 keydown
: this.onDocumentKeyDownHandler
3243 this.$( this.getElementWindow() ).off( {
3244 // Allow scrolling by wheel in top-level window
3245 mousewheel
: this.onWindowMouseWheelHandler
,
3246 // Stop listening for top-level window dimension changes
3247 'orientationchange resize': this.onWindowResizeHandler
3249 if ( !this.shouldIsolate() ) {
3250 $( this.getElementDocument().body
).css( 'overflow', '' );
3252 this.globalEvents
= false;
3259 * Toggle screen reader visibility of content other than the window manager.
3261 * @param {boolean} [isolate] Make only the window manager visible to screen readers
3264 OO
.ui
.WindowManager
.prototype.toggleAriaIsolation = function ( isolate
) {
3265 isolate
= isolate
=== undefined ? !this.$ariaHidden
: !!isolate
;
3268 if ( !this.$ariaHidden
) {
3269 // Hide everything other than the window manager from screen readers
3270 this.$ariaHidden
= $( 'body' )
3272 .not( this.$element
.parentsUntil( 'body' ).last() )
3273 .attr( 'aria-hidden', '' );
3275 } else if ( this.$ariaHidden
) {
3276 // Restore screen reader visibility
3277 this.$ariaHidden
.removeAttr( 'aria-hidden' );
3278 this.$ariaHidden
= null;
3285 * Destroy window manager.
3287 OO
.ui
.WindowManager
.prototype.destroy = function () {
3288 this.toggleGlobalEvents( false );
3289 this.toggleAriaIsolation( false );
3290 this.clearWindows();
3291 this.$element
.remove();
3298 * @param {string|jQuery} message Description of error
3299 * @param {Object} [config] Configuration options
3300 * @cfg {boolean} [recoverable=true] Error is recoverable
3301 * @cfg {boolean} [warning=false] Whether this error is a warning or not.
3303 OO
.ui
.Error
= function OoUiElement( message
, config
) {
3304 // Configuration initialization
3305 config
= config
|| {};
3308 this.message
= message
instanceof jQuery
? message
: String( message
);
3309 this.recoverable
= config
.recoverable
=== undefined || !!config
.recoverable
;
3310 this.warning
= !!config
.warning
;
3315 OO
.initClass( OO
.ui
.Error
);
3320 * Check if error can be recovered from.
3322 * @return {boolean} Error is recoverable
3324 OO
.ui
.Error
.prototype.isRecoverable = function () {
3325 return this.recoverable
;
3329 * Check if the error is a warning
3331 * @return {boolean} Error is warning
3333 OO
.ui
.Error
.prototype.isWarning = function () {
3334 return this.warning
;
3338 * Get error message as DOM nodes.
3340 * @return {jQuery} Error message in DOM nodes
3342 OO
.ui
.Error
.prototype.getMessage = function () {
3343 return this.message
instanceof jQuery
?
3344 this.message
.clone() :
3345 $( '<div>' ).text( this.message
).contents();
3349 * Get error message as text.
3351 * @return {string} Error message
3353 OO
.ui
.Error
.prototype.getMessageText = function () {
3354 return this.message
instanceof jQuery
? this.message
.text() : this.message
;
3358 * A list of functions, called in sequence.
3360 * If a function added to a process returns boolean false the process will stop; if it returns an
3361 * object with a `promise` method the process will use the promise to either continue to the next
3362 * step when the promise is resolved or stop when the promise is rejected.
3367 * @param {number|jQuery.Promise|Function} step Time to wait, promise to wait for or function to
3368 * call, see #createStep for more information
3369 * @param {Object} [context=null] Context to call the step function in, ignored if step is a number
3371 * @return {Object} Step object, with `callback` and `context` properties
3373 OO
.ui
.Process = function ( step
, context
) {
3378 if ( step
!== undefined ) {
3379 this.next( step
, context
);
3385 OO
.initClass( OO
.ui
.Process
);
3390 * Start the process.
3392 * @return {jQuery.Promise} Promise that is resolved when all steps have completed or rejected when
3393 * any of the steps return boolean false or a promise which gets rejected; upon stopping the
3394 * process, the remaining steps will not be taken
3396 OO
.ui
.Process
.prototype.execute = function () {
3397 var i
, len
, promise
;
3400 * Continue execution.
3403 * @param {Array} step A function and the context it should be called in
3404 * @return {Function} Function that continues the process
3406 function proceed( step
) {
3407 return function () {
3408 // Execute step in the correct context
3410 result
= step
.callback
.call( step
.context
);
3412 if ( result
=== false ) {
3413 // Use rejected promise for boolean false results
3414 return $.Deferred().reject( [] ).promise();
3416 if ( typeof result
=== 'number' ) {
3418 throw new Error( 'Cannot go back in time: flux capacitor is out of service' );
3420 // Use a delayed promise for numbers, expecting them to be in milliseconds
3421 deferred
= $.Deferred();
3422 setTimeout( deferred
.resolve
, result
);
3423 return deferred
.promise();
3425 if ( result
instanceof OO
.ui
.Error
) {
3426 // Use rejected promise for error
3427 return $.Deferred().reject( [ result
] ).promise();
3429 if ( $.isArray( result
) && result
.length
&& result
[ 0 ] instanceof OO
.ui
.Error
) {
3430 // Use rejected promise for list of errors
3431 return $.Deferred().reject( result
).promise();
3433 // Duck-type the object to see if it can produce a promise
3434 if ( result
&& $.isFunction( result
.promise
) ) {
3435 // Use a promise generated from the result
3436 return result
.promise();
3438 // Use resolved promise for other results
3439 return $.Deferred().resolve().promise();
3443 if ( this.steps
.length
) {
3444 // Generate a chain reaction of promises
3445 promise
= proceed( this.steps
[ 0 ] )();
3446 for ( i
= 1, len
= this.steps
.length
; i
< len
; i
++ ) {
3447 promise
= promise
.then( proceed( this.steps
[ i
] ) );
3450 promise
= $.Deferred().resolve().promise();
3457 * Create a process step.
3460 * @param {number|jQuery.Promise|Function} step
3462 * - Number of milliseconds to wait; or
3463 * - Promise to wait to be resolved; or
3464 * - Function to execute
3465 * - If it returns boolean false the process will stop
3466 * - If it returns an object with a `promise` method the process will use the promise to either
3467 * continue to the next step when the promise is resolved or stop when the promise is rejected
3468 * - If it returns a number, the process will wait for that number of milliseconds before
3470 * @param {Object} [context=null] Context to call the step function in, ignored if step is a number
3472 * @return {Object} Step object, with `callback` and `context` properties
3474 OO
.ui
.Process
.prototype.createStep = function ( step
, context
) {
3475 if ( typeof step
=== 'number' || $.isFunction( step
.promise
) ) {
3477 callback: function () {
3483 if ( $.isFunction( step
) ) {
3489 throw new Error( 'Cannot create process step: number, promise or function expected' );
3493 * Add step to the beginning of the process.
3495 * @inheritdoc #createStep
3496 * @return {OO.ui.Process} this
3499 OO
.ui
.Process
.prototype.first = function ( step
, context
) {
3500 this.steps
.unshift( this.createStep( step
, context
) );
3505 * Add step to the end of the process.
3507 * @inheritdoc #createStep
3508 * @return {OO.ui.Process} this
3511 OO
.ui
.Process
.prototype.next = function ( step
, context
) {
3512 this.steps
.push( this.createStep( step
, context
) );
3517 * Factory for tools.
3520 * @extends OO.Factory
3523 OO
.ui
.ToolFactory
= function OoUiToolFactory() {
3524 // Parent constructor
3525 OO
.ui
.ToolFactory
.super.call( this );
3530 OO
.inheritClass( OO
.ui
.ToolFactory
, OO
.Factory
);
3535 * Get tools from the factory
3537 * @param {Array} include Included tools
3538 * @param {Array} exclude Excluded tools
3539 * @param {Array} promote Promoted tools
3540 * @param {Array} demote Demoted tools
3541 * @return {string[]} List of tools
3543 OO
.ui
.ToolFactory
.prototype.getTools = function ( include
, exclude
, promote
, demote
) {
3544 var i
, len
, included
, promoted
, demoted
,
3548 // Collect included and not excluded tools
3549 included
= OO
.simpleArrayDifference( this.extract( include
), this.extract( exclude
) );
3552 promoted
= this.extract( promote
, used
);
3553 demoted
= this.extract( demote
, used
);
3556 for ( i
= 0, len
= included
.length
; i
< len
; i
++ ) {
3557 if ( !used
[ included
[ i
] ] ) {
3558 auto
.push( included
[ i
] );
3562 return promoted
.concat( auto
).concat( demoted
);
3566 * Get a flat list of names from a list of names or groups.
3568 * Tools can be specified in the following ways:
3570 * - A specific tool: `{ name: 'tool-name' }` or `'tool-name'`
3571 * - All tools in a group: `{ group: 'group-name' }`
3572 * - All tools: `'*'`
3575 * @param {Array|string} collection List of tools
3576 * @param {Object} [used] Object with names that should be skipped as properties; extracted
3577 * names will be added as properties
3578 * @return {string[]} List of extracted names
3580 OO
.ui
.ToolFactory
.prototype.extract = function ( collection
, used
) {
3581 var i
, len
, item
, name
, tool
,
3584 if ( collection
=== '*' ) {
3585 for ( name
in this.registry
) {
3586 tool
= this.registry
[ name
];
3588 // Only add tools by group name when auto-add is enabled
3589 tool
.static.autoAddToCatchall
&&
3590 // Exclude already used tools
3591 ( !used
|| !used
[ name
] )
3595 used
[ name
] = true;
3599 } else if ( $.isArray( collection
) ) {
3600 for ( i
= 0, len
= collection
.length
; i
< len
; i
++ ) {
3601 item
= collection
[ i
];
3602 // Allow plain strings as shorthand for named tools
3603 if ( typeof item
=== 'string' ) {
3604 item
= { name
: item
};
3606 if ( OO
.isPlainObject( item
) ) {
3608 for ( name
in this.registry
) {
3609 tool
= this.registry
[ name
];
3611 // Include tools with matching group
3612 tool
.static.group
=== item
.group
&&
3613 // Only add tools by group name when auto-add is enabled
3614 tool
.static.autoAddToGroup
&&
3615 // Exclude already used tools
3616 ( !used
|| !used
[ name
] )
3620 used
[ name
] = true;
3624 // Include tools with matching name and exclude already used tools
3625 } else if ( item
.name
&& ( !used
|| !used
[ item
.name
] ) ) {
3626 names
.push( item
.name
);
3628 used
[ item
.name
] = true;
3638 * Factory for tool groups.
3641 * @extends OO.Factory
3644 OO
.ui
.ToolGroupFactory
= function OoUiToolGroupFactory() {
3645 // Parent constructor
3646 OO
.Factory
.call( this );
3649 defaultClasses
= this.constructor.static.getDefaultClasses();
3651 // Register default toolgroups
3652 for ( i
= 0, l
= defaultClasses
.length
; i
< l
; i
++ ) {
3653 this.register( defaultClasses
[ i
] );
3659 OO
.inheritClass( OO
.ui
.ToolGroupFactory
, OO
.Factory
);
3661 /* Static Methods */
3664 * Get a default set of classes to be registered on construction
3666 * @return {Function[]} Default classes
3668 OO
.ui
.ToolGroupFactory
.static.getDefaultClasses = function () {
3671 OO
.ui
.ListToolGroup
,
3683 * @param {Object} [config] Configuration options
3685 OO
.ui
.Theme
= function OoUiTheme( config
) {
3686 // Configuration initialization
3687 config
= config
|| {};
3692 OO
.initClass( OO
.ui
.Theme
);
3697 * Get a list of classes to be applied to a widget.
3699 * The 'on' and 'off' lists combined MUST contain keys for all classes the theme adds or removes,
3700 * otherwise state transitions will not work properly.
3702 * @param {OO.ui.Element} element Element for which to get classes
3703 * @return {Object.<string,string[]>} Categorized class names with `on` and `off` lists
3705 OO
.ui
.Theme
.prototype.getElementClasses = function ( /* element */ ) {
3706 return { on
: [], off
: [] };
3710 * Update CSS classes provided by the theme.
3712 * For elements with theme logic hooks, this should be called any time there's a state change.
3714 * @param {OO.ui.Element} element Element for which to update classes
3715 * @return {Object.<string,string[]>} Categorized class names with `on` and `off` lists
3717 OO
.ui
.Theme
.prototype.updateElementClasses = function ( element
) {
3718 var classes
= this.getElementClasses( element
);
3721 .removeClass( classes
.off
.join( ' ' ) )
3722 .addClass( classes
.on
.join( ' ' ) );
3726 * Element supporting "sequential focus navigation" using the 'tabindex' attribute.
3732 * @param {Object} [config] Configuration options
3733 * @cfg {jQuery} [$tabIndexed] tabIndexed node, assigned to #$tabIndexed, omit to use #$element
3734 * @cfg {number|Function} [tabIndex=0] Tab index value. Use 0 to use default ordering, use -1 to
3735 * prevent tab focusing. (default: 0)
3737 OO
.ui
.TabIndexedElement
= function OoUiTabIndexedElement( config
) {
3738 // Configuration initialization
3739 config
= config
|| {};
3742 this.$tabIndexed
= null;
3743 this.tabIndex
= null;
3746 this.setTabIndex( config
.tabIndex
|| 0 );
3747 this.setTabIndexedElement( config
.$tabIndexed
|| this.$element
);
3752 OO
.initClass( OO
.ui
.TabIndexedElement
);
3757 * Set the element with 'tabindex' attribute.
3759 * If an element is already set, it will be cleaned up before setting up the new element.
3761 * @param {jQuery} $tabIndexed Element to set tab index on
3763 OO
.ui
.TabIndexedElement
.prototype.setTabIndexedElement = function ( $tabIndexed
) {
3764 if ( this.$tabIndexed
) {
3765 this.$tabIndexed
.removeAttr( 'tabindex' );
3768 this.$tabIndexed
= $tabIndexed
;
3769 if ( this.tabIndex
!== null ) {
3770 this.$tabIndexed
.attr( 'tabindex', this.tabIndex
);
3775 * Set tab index value.
3777 * @param {number|null} tabIndex Tab index value or null for no tabIndex
3780 OO
.ui
.TabIndexedElement
.prototype.setTabIndex = function ( tabIndex
) {
3781 tabIndex
= typeof tabIndex
=== 'number' && tabIndex
>= 0 ? tabIndex
: null;
3783 if ( this.tabIndex
!== tabIndex
) {
3784 if ( this.$tabIndexed
) {
3785 if ( tabIndex
!== null ) {
3786 this.$tabIndexed
.attr( 'tabindex', tabIndex
);
3788 this.$tabIndexed
.removeAttr( 'tabindex' );
3791 this.tabIndex
= tabIndex
;
3798 * Get tab index value.
3800 * @return {number} Tab index value
3802 OO
.ui
.TabIndexedElement
.prototype.getTabIndex = function () {
3803 return this.tabIndex
;
3807 * Element with a button.
3809 * Buttons are used for controls which can be clicked. They can be configured to use tab indexing
3810 * and access keys for accessibility purposes.
3816 * @param {Object} [config] Configuration options
3817 * @cfg {jQuery} [$button] Button node, assigned to #$button, omit to use a generated `<a>`
3818 * @cfg {boolean} [framed=true] Render button with a frame
3819 * @cfg {string} [accessKey] Button's access key
3821 OO
.ui
.ButtonElement
= function OoUiButtonElement( config
) {
3822 // Configuration initialization
3823 config
= config
|| {};
3826 this.$button
= config
.$button
|| this.$( '<a>' );
3828 this.accessKey
= null;
3829 this.active
= false;
3830 this.onMouseUpHandler
= this.onMouseUp
.bind( this );
3831 this.onMouseDownHandler
= this.onMouseDown
.bind( this );
3834 this.$element
.addClass( 'oo-ui-buttonElement' );
3835 this.toggleFramed( config
.framed
=== undefined || config
.framed
);
3836 this.setAccessKey( config
.accessKey
);
3837 this.setButtonElement( this.$button
);
3842 OO
.initClass( OO
.ui
.ButtonElement
);
3844 /* Static Properties */
3847 * Cancel mouse down events.
3851 * @property {boolean}
3853 OO
.ui
.ButtonElement
.static.cancelButtonMouseDownEvents
= true;
3858 * Set the button element.
3860 * If an element is already set, it will be cleaned up before setting up the new element.
3862 * @param {jQuery} $button Element to use as button
3864 OO
.ui
.ButtonElement
.prototype.setButtonElement = function ( $button
) {
3865 if ( this.$button
) {
3867 .removeClass( 'oo-ui-buttonElement-button' )
3868 .removeAttr( 'role accesskey' )
3869 .off( 'mousedown', this.onMouseDownHandler
);
3872 this.$button
= $button
3873 .addClass( 'oo-ui-buttonElement-button' )
3874 .attr( { role
: 'button', accesskey
: this.accessKey
} )
3875 .on( 'mousedown', this.onMouseDownHandler
);
3879 * Handles mouse down events.
3881 * @param {jQuery.Event} e Mouse down event
3883 OO
.ui
.ButtonElement
.prototype.onMouseDown = function ( e
) {
3884 if ( this.isDisabled() || e
.which
!== 1 ) {
3887 this.$element
.addClass( 'oo-ui-buttonElement-pressed' );
3888 // Run the mouseup handler no matter where the mouse is when the button is let go, so we can
3889 // reliably remove the pressed class
3890 this.getElementDocument().addEventListener( 'mouseup', this.onMouseUpHandler
, true );
3891 // Prevent change of focus unless specifically configured otherwise
3892 if ( this.constructor.static.cancelButtonMouseDownEvents
) {
3898 * Handles mouse up events.
3900 * @param {jQuery.Event} e Mouse up event
3902 OO
.ui
.ButtonElement
.prototype.onMouseUp = function ( e
) {
3903 if ( this.isDisabled() || e
.which
!== 1 ) {
3906 this.$element
.removeClass( 'oo-ui-buttonElement-pressed' );
3907 // Stop listening for mouseup, since we only needed this once
3908 this.getElementDocument().removeEventListener( 'mouseup', this.onMouseUpHandler
, true );
3912 * Check if button has a frame.
3914 * @return {boolean} Button is framed
3916 OO
.ui
.ButtonElement
.prototype.isFramed = function () {
3923 * @param {boolean} [framed] Make button framed, omit to toggle
3926 OO
.ui
.ButtonElement
.prototype.toggleFramed = function ( framed
) {
3927 framed
= framed
=== undefined ? !this.framed
: !!framed
;
3928 if ( framed
!== this.framed
) {
3929 this.framed
= framed
;
3931 .toggleClass( 'oo-ui-buttonElement-frameless', !framed
)
3932 .toggleClass( 'oo-ui-buttonElement-framed', framed
);
3933 this.updateThemeClasses();
3942 * @param {string} accessKey Button's access key, use empty string to remove
3945 OO
.ui
.ButtonElement
.prototype.setAccessKey = function ( accessKey
) {
3946 accessKey
= typeof accessKey
=== 'string' && accessKey
.length
? accessKey
: null;
3948 if ( this.accessKey
!== accessKey
) {
3949 if ( this.$button
) {
3950 if ( accessKey
!== null ) {
3951 this.$button
.attr( 'accesskey', accessKey
);
3953 this.$button
.removeAttr( 'accesskey' );
3956 this.accessKey
= accessKey
;
3965 * @param {boolean} [value] Make button active
3968 OO
.ui
.ButtonElement
.prototype.setActive = function ( value
) {
3969 this.$element
.toggleClass( 'oo-ui-buttonElement-active', !!value
);
3974 * Element containing a sequence of child elements.
3980 * @param {Object} [config] Configuration options
3981 * @cfg {jQuery} [$group] Container node, assigned to #$group, omit to use a generated `<div>`
3983 OO
.ui
.GroupElement
= function OoUiGroupElement( config
) {
3984 // Configuration initialization
3985 config
= config
|| {};
3990 this.aggregateItemEvents
= {};
3993 this.setGroupElement( config
.$group
|| this.$( '<div>' ) );
3999 * Set the group element.
4001 * If an element is already set, items will be moved to the new element.
4003 * @param {jQuery} $group Element to use as group
4005 OO
.ui
.GroupElement
.prototype.setGroupElement = function ( $group
) {
4008 this.$group
= $group
;
4009 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4010 this.$group
.append( this.items
[ i
].$element
);
4015 * Check if there are no items.
4017 * @return {boolean} Group is empty
4019 OO
.ui
.GroupElement
.prototype.isEmpty = function () {
4020 return !this.items
.length
;
4026 * @return {OO.ui.Element[]} Items
4028 OO
.ui
.GroupElement
.prototype.getItems = function () {
4029 return this.items
.slice( 0 );
4033 * Get an item by its data.
4035 * Data is compared by a hash of its value. Only the first item with matching data will be returned.
4037 * @param {Object} data Item data to search for
4038 * @return {OO.ui.Element|null} Item with equivalent data, `null` if none exists
4040 OO
.ui
.GroupElement
.prototype.getItemFromData = function ( data
) {
4042 hash
= OO
.getHash( data
);
4044 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4045 item
= this.items
[ i
];
4046 if ( hash
=== OO
.getHash( item
.getData() ) ) {
4055 * Get items by their data.
4057 * Data is compared by a hash of its value. All items with matching data will be returned.
4059 * @param {Object} data Item data to search for
4060 * @return {OO.ui.Element[]} Items with equivalent data
4062 OO
.ui
.GroupElement
.prototype.getItemsFromData = function ( data
) {
4064 hash
= OO
.getHash( data
),
4067 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4068 item
= this.items
[ i
];
4069 if ( hash
=== OO
.getHash( item
.getData() ) ) {
4078 * Add an aggregate item event.
4080 * Aggregated events are listened to on each item and then emitted by the group under a new name,
4081 * and with an additional leading parameter containing the item that emitted the original event.
4082 * Other arguments that were emitted from the original event are passed through.
4084 * @param {Object.<string,string|null>} events Aggregate events emitted by group, keyed by item
4085 * event, use null value to remove aggregation
4086 * @throws {Error} If aggregation already exists
4088 OO
.ui
.GroupElement
.prototype.aggregate = function ( events
) {
4089 var i
, len
, item
, add
, remove
, itemEvent
, groupEvent
;
4091 for ( itemEvent
in events
) {
4092 groupEvent
= events
[ itemEvent
];
4094 // Remove existing aggregated event
4095 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
4096 // Don't allow duplicate aggregations
4098 throw new Error( 'Duplicate item event aggregation for ' + itemEvent
);
4100 // Remove event aggregation from existing items
4101 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4102 item
= this.items
[ i
];
4103 if ( item
.connect
&& item
.disconnect
) {
4105 remove
[ itemEvent
] = [ 'emit', groupEvent
, item
];
4106 item
.disconnect( this, remove
);
4109 // Prevent future items from aggregating event
4110 delete this.aggregateItemEvents
[ itemEvent
];
4113 // Add new aggregate event
4115 // Make future items aggregate event
4116 this.aggregateItemEvents
[ itemEvent
] = groupEvent
;
4117 // Add event aggregation to existing items
4118 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4119 item
= this.items
[ i
];
4120 if ( item
.connect
&& item
.disconnect
) {
4122 add
[ itemEvent
] = [ 'emit', groupEvent
, item
];
4123 item
.connect( this, add
);
4133 * Adding an existing item will move it.
4135 * @param {OO.ui.Element[]} items Items
4136 * @param {number} [index] Index to insert items at
4139 OO
.ui
.GroupElement
.prototype.addItems = function ( items
, index
) {
4140 var i
, len
, item
, event
, events
, currentIndex
,
4143 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
4146 // Check if item exists then remove it first, effectively "moving" it
4147 currentIndex
= $.inArray( item
, this.items
);
4148 if ( currentIndex
>= 0 ) {
4149 this.removeItems( [ item
] );
4150 // Adjust index to compensate for removal
4151 if ( currentIndex
< index
) {
4156 if ( item
.connect
&& item
.disconnect
&& !$.isEmptyObject( this.aggregateItemEvents
) ) {
4158 for ( event
in this.aggregateItemEvents
) {
4159 events
[ event
] = [ 'emit', this.aggregateItemEvents
[ event
], item
];
4161 item
.connect( this, events
);
4163 item
.setElementGroup( this );
4164 itemElements
.push( item
.$element
.get( 0 ) );
4167 if ( index
=== undefined || index
< 0 || index
>= this.items
.length
) {
4168 this.$group
.append( itemElements
);
4169 this.items
.push
.apply( this.items
, items
);
4170 } else if ( index
=== 0 ) {
4171 this.$group
.prepend( itemElements
);
4172 this.items
.unshift
.apply( this.items
, items
);
4174 this.items
[ index
].$element
.before( itemElements
);
4175 this.items
.splice
.apply( this.items
, [ index
, 0 ].concat( items
) );
4184 * Items will be detached, not removed, so they can be used later.
4186 * @param {OO.ui.Element[]} items Items to remove
4189 OO
.ui
.GroupElement
.prototype.removeItems = function ( items
) {
4190 var i
, len
, item
, index
, remove
, itemEvent
;
4192 // Remove specific items
4193 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
4195 index
= $.inArray( item
, this.items
);
4196 if ( index
!== -1 ) {
4198 item
.connect
&& item
.disconnect
&&
4199 !$.isEmptyObject( this.aggregateItemEvents
)
4202 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
4203 remove
[ itemEvent
] = [ 'emit', this.aggregateItemEvents
[ itemEvent
], item
];
4205 item
.disconnect( this, remove
);
4207 item
.setElementGroup( null );
4208 this.items
.splice( index
, 1 );
4209 item
.$element
.detach();
4219 * Items will be detached, not removed, so they can be used later.
4223 OO
.ui
.GroupElement
.prototype.clearItems = function () {
4224 var i
, len
, item
, remove
, itemEvent
;
4227 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4228 item
= this.items
[ i
];
4230 item
.connect
&& item
.disconnect
&&
4231 !$.isEmptyObject( this.aggregateItemEvents
)
4234 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
4235 remove
[ itemEvent
] = [ 'emit', this.aggregateItemEvents
[ itemEvent
], item
];
4237 item
.disconnect( this, remove
);
4239 item
.setElementGroup( null );
4240 item
.$element
.detach();
4248 * A mixin for an element that can be dragged and dropped.
4249 * Use in conjunction with DragGroupWidget
4256 OO
.ui
.DraggableElement
= function OoUiDraggableElement() {
4260 // Initialize and events
4262 .attr( 'draggable', true )
4263 .addClass( 'oo-ui-draggableElement' )
4265 dragstart
: this.onDragStart
.bind( this ),
4266 dragover
: this.onDragOver
.bind( this ),
4267 dragend
: this.onDragEnd
.bind( this ),
4268 drop
: this.onDrop
.bind( this )
4276 * @param {OO.ui.DraggableElement} item Dragging item
4290 * Respond to dragstart event.
4291 * @param {jQuery.Event} event jQuery event
4294 OO
.ui
.DraggableElement
.prototype.onDragStart = function ( e
) {
4295 var dataTransfer
= e
.originalEvent
.dataTransfer
;
4296 // Define drop effect
4297 dataTransfer
.dropEffect
= 'none';
4298 dataTransfer
.effectAllowed
= 'move';
4299 // We must set up a dataTransfer data property or Firefox seems to
4300 // ignore the fact the element is draggable.
4302 dataTransfer
.setData( 'application-x/OOjs-UI-draggable', this.getIndex() );
4304 // The above is only for firefox. No need to set a catch clause
4305 // if it fails, move on.
4307 // Add dragging class
4308 this.$element
.addClass( 'oo-ui-draggableElement-dragging' );
4310 this.emit( 'dragstart', this );
4315 * Respond to dragend event.
4318 OO
.ui
.DraggableElement
.prototype.onDragEnd = function () {
4319 this.$element
.removeClass( 'oo-ui-draggableElement-dragging' );
4320 this.emit( 'dragend' );
4324 * Handle drop event.
4325 * @param {jQuery.Event} event jQuery event
4328 OO
.ui
.DraggableElement
.prototype.onDrop = function ( e
) {
4330 this.emit( 'drop', e
);
4334 * In order for drag/drop to work, the dragover event must
4335 * return false and stop propogation.
4337 OO
.ui
.DraggableElement
.prototype.onDragOver = function ( e
) {
4343 * Store it in the DOM so we can access from the widget drag event
4344 * @param {number} Item index
4346 OO
.ui
.DraggableElement
.prototype.setIndex = function ( index
) {
4347 if ( this.index
!== index
) {
4349 this.$element
.data( 'index', index
);
4355 * @return {number} Item index
4357 OO
.ui
.DraggableElement
.prototype.getIndex = function () {
4362 * Element containing a sequence of child elements that can be dragged
4369 * @param {Object} [config] Configuration options
4370 * @cfg {jQuery} [$group] Container node, assigned to #$group, omit to use a generated `<div>`
4371 * @cfg {string} [orientation] Item orientation, 'horizontal' or 'vertical'. Defaults to 'vertical'
4373 OO
.ui
.DraggableGroupElement
= function OoUiDraggableGroupElement( config
) {
4374 // Configuration initialization
4375 config
= config
|| {};
4377 // Parent constructor
4378 OO
.ui
.GroupElement
.call( this, config
);
4381 this.orientation
= config
.orientation
|| 'vertical';
4382 this.dragItem
= null;
4383 this.itemDragOver
= null;
4385 this.sideInsertion
= '';
4389 dragstart
: 'itemDragStart',
4390 dragend
: 'itemDragEnd',
4393 this.connect( this, {
4394 itemDragStart
: 'onItemDragStart',
4395 itemDrop
: 'onItemDrop',
4396 itemDragEnd
: 'onItemDragEnd'
4399 dragover
: $.proxy( this.onDragOver
, this ),
4400 dragleave
: $.proxy( this.onDragLeave
, this )
4404 if ( $.isArray( config
.items
) ) {
4405 this.addItems( config
.items
);
4407 this.$placeholder
= $( '<div>' )
4408 .addClass( 'oo-ui-draggableGroupElement-placeholder' );
4410 .addClass( 'oo-ui-draggableGroupElement' )
4411 .append( this.$status
)
4412 .toggleClass( 'oo-ui-draggableGroupElement-horizontal', this.orientation
=== 'horizontal' )
4413 .prepend( this.$placeholder
);
4417 OO
.mixinClass( OO
.ui
.DraggableGroupElement
, OO
.ui
.GroupElement
);
4423 * @param {OO.ui.DraggableElement} item Reordered item
4424 * @param {number} [newIndex] New index for the item
4430 * Respond to item drag start event
4431 * @param {OO.ui.DraggableElement} item Dragged item
4433 OO
.ui
.DraggableGroupElement
.prototype.onItemDragStart = function ( item
) {
4436 // Map the index of each object
4437 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
4438 this.items
[ i
].setIndex( i
);
4441 if ( this.orientation
=== 'horizontal' ) {
4442 // Set the height of the indicator
4443 this.$placeholder
.css( {
4444 height
: item
.$element
.outerHeight(),
4448 // Set the width of the indicator
4449 this.$placeholder
.css( {
4451 width
: item
.$element
.outerWidth()
4454 this.setDragItem( item
);
4458 * Respond to item drag end event
4460 OO
.ui
.DraggableGroupElement
.prototype.onItemDragEnd = function () {
4461 this.unsetDragItem();
4466 * Handle drop event and switch the order of the items accordingly
4467 * @param {OO.ui.DraggableElement} item Dropped item
4470 OO
.ui
.DraggableGroupElement
.prototype.onItemDrop = function ( item
) {
4471 var toIndex
= item
.getIndex();
4472 // Check if the dropped item is from the current group
4473 // TODO: Figure out a way to configure a list of legally droppable
4474 // elements even if they are not yet in the list
4475 if ( this.getDragItem() ) {
4476 // If the insertion point is 'after', the insertion index
4477 // is shifted to the right (or to the left in RTL, hence 'after')
4478 if ( this.sideInsertion
=== 'after' ) {
4481 // Emit change event
4482 this.emit( 'reorder', this.getDragItem(), toIndex
);
4484 // Return false to prevent propogation
4489 * Handle dragleave event.
4491 OO
.ui
.DraggableGroupElement
.prototype.onDragLeave = function () {
4492 // This means the item was dragged outside the widget
4499 * Respond to dragover event
4500 * @param {jQuery.Event} event Event details
4502 OO
.ui
.DraggableGroupElement
.prototype.onDragOver = function ( e
) {
4503 var dragOverObj
, $optionWidget
, itemOffset
, itemMidpoint
, itemBoundingRect
,
4504 itemSize
, cssOutput
, dragPosition
, itemIndex
, itemPosition
,
4505 clientX
= e
.originalEvent
.clientX
,
4506 clientY
= e
.originalEvent
.clientY
;
4508 // Get the OptionWidget item we are dragging over
4509 dragOverObj
= this.getElementDocument().elementFromPoint( clientX
, clientY
);
4510 $optionWidget
= $( dragOverObj
).closest( '.oo-ui-draggableElement' );
4511 if ( $optionWidget
[ 0 ] ) {
4512 itemOffset
= $optionWidget
.offset();
4513 itemBoundingRect
= $optionWidget
[ 0 ].getBoundingClientRect();
4514 itemPosition
= $optionWidget
.position();
4515 itemIndex
= $optionWidget
.data( 'index' );
4520 this.isDragging() &&
4521 itemIndex
!== this.getDragItem().getIndex()
4523 if ( this.orientation
=== 'horizontal' ) {
4524 // Calculate where the mouse is relative to the item width
4525 itemSize
= itemBoundingRect
.width
;
4526 itemMidpoint
= itemBoundingRect
.left
+ itemSize
/ 2;
4527 dragPosition
= clientX
;
4528 // Which side of the item we hover over will dictate
4529 // where the placeholder will appear, on the left or
4532 left
: dragPosition
< itemMidpoint
? itemPosition
.left
: itemPosition
.left
+ itemSize
,
4533 top
: itemPosition
.top
4536 // Calculate where the mouse is relative to the item height
4537 itemSize
= itemBoundingRect
.height
;
4538 itemMidpoint
= itemBoundingRect
.top
+ itemSize
/ 2;
4539 dragPosition
= clientY
;
4540 // Which side of the item we hover over will dictate
4541 // where the placeholder will appear, on the top or
4544 top
: dragPosition
< itemMidpoint
? itemPosition
.top
: itemPosition
.top
+ itemSize
,
4545 left
: itemPosition
.left
4548 // Store whether we are before or after an item to rearrange
4549 // For horizontal layout, we need to account for RTL, as this is flipped
4550 if ( this.orientation
=== 'horizontal' && this.$element
.css( 'direction' ) === 'rtl' ) {
4551 this.sideInsertion
= dragPosition
< itemMidpoint
? 'after' : 'before';
4553 this.sideInsertion
= dragPosition
< itemMidpoint
? 'before' : 'after';
4555 // Add drop indicator between objects
4556 if ( this.sideInsertion
) {
4569 // This means the item was dragged outside the widget
4579 * Set a dragged item
4580 * @param {OO.ui.DraggableElement} item Dragged item
4582 OO
.ui
.DraggableGroupElement
.prototype.setDragItem = function ( item
) {
4583 this.dragItem
= item
;
4587 * Unset the current dragged item
4589 OO
.ui
.DraggableGroupElement
.prototype.unsetDragItem = function () {
4590 this.dragItem
= null;
4591 this.itemDragOver
= null;
4592 this.$placeholder
.hide();
4593 this.sideInsertion
= '';
4597 * Get the current dragged item
4598 * @return {OO.ui.DraggableElement|null} item Dragged item or null if no item is dragged
4600 OO
.ui
.DraggableGroupElement
.prototype.getDragItem = function () {
4601 return this.dragItem
;
4605 * Check if there's an item being dragged.
4606 * @return {Boolean} Item is being dragged
4608 OO
.ui
.DraggableGroupElement
.prototype.isDragging = function () {
4609 return this.getDragItem() !== null;
4613 * Element containing an icon.
4615 * Icons are graphics, about the size of normal text. They can be used to aid the user in locating
4616 * a control or convey information in a more space efficient way. Icons should rarely be used
4617 * without labels; such as in a toolbar where space is at a premium or within a context where the
4618 * meaning is very clear to the user.
4624 * @param {Object} [config] Configuration options
4625 * @cfg {jQuery} [$icon] Icon node, assigned to #$icon, omit to use a generated `<span>`
4626 * @cfg {Object|string} [icon=''] Symbolic icon name, or map of icon names keyed by language ID;
4627 * use the 'default' key to specify the icon to be used when there is no icon in the user's
4629 * @cfg {string} [iconTitle] Icon title text or a function that returns text
4631 OO
.ui
.IconElement
= function OoUiIconElement( config
) {
4632 // Configuration initialization
4633 config
= config
|| {};
4638 this.iconTitle
= null;
4641 this.setIcon( config
.icon
|| this.constructor.static.icon
);
4642 this.setIconTitle( config
.iconTitle
|| this.constructor.static.iconTitle
);
4643 this.setIconElement( config
.$icon
|| this.$( '<span>' ) );
4648 OO
.initClass( OO
.ui
.IconElement
);
4650 /* Static Properties */
4655 * Value should be the unique portion of an icon CSS class name, such as 'up' for 'oo-ui-icon-up'.
4657 * For i18n purposes, this property can be an object containing a `default` icon name property and
4658 * additional icon names keyed by language code.
4660 * Example of i18n icon definition:
4661 * { default: 'bold-a', en: 'bold-b', de: 'bold-f' }
4665 * @property {Object|string} Symbolic icon name, or map of icon names keyed by language ID;
4666 * use the 'default' key to specify the icon to be used when there is no icon in the user's
4669 OO
.ui
.IconElement
.static.icon
= null;
4676 * @property {string|Function|null} Icon title text, a function that returns text or null for no
4679 OO
.ui
.IconElement
.static.iconTitle
= null;
4684 * Set the icon element.
4686 * If an element is already set, it will be cleaned up before setting up the new element.
4688 * @param {jQuery} $icon Element to use as icon
4690 OO
.ui
.IconElement
.prototype.setIconElement = function ( $icon
) {
4693 .removeClass( 'oo-ui-iconElement-icon oo-ui-icon-' + this.icon
)
4694 .removeAttr( 'title' );
4698 .addClass( 'oo-ui-iconElement-icon' )
4699 .toggleClass( 'oo-ui-icon-' + this.icon
, !!this.icon
);
4700 if ( this.iconTitle
!== null ) {
4701 this.$icon
.attr( 'title', this.iconTitle
);
4708 * @param {Object|string|null} icon Symbolic icon name, or map of icon names keyed by language ID;
4709 * use the 'default' key to specify the icon to be used when there is no icon in the user's
4710 * language, use null to remove icon
4713 OO
.ui
.IconElement
.prototype.setIcon = function ( icon
) {
4714 icon
= OO
.isPlainObject( icon
) ? OO
.ui
.getLocalValue( icon
, null, 'default' ) : icon
;
4715 icon
= typeof icon
=== 'string' && icon
.trim().length
? icon
.trim() : null;
4717 if ( this.icon
!== icon
) {
4719 if ( this.icon
!== null ) {
4720 this.$icon
.removeClass( 'oo-ui-icon-' + this.icon
);
4722 if ( icon
!== null ) {
4723 this.$icon
.addClass( 'oo-ui-icon-' + icon
);
4729 this.$element
.toggleClass( 'oo-ui-iconElement', !!this.icon
);
4730 this.updateThemeClasses();
4738 * @param {string|Function|null} icon Icon title text, a function that returns text or null
4742 OO
.ui
.IconElement
.prototype.setIconTitle = function ( iconTitle
) {
4743 iconTitle
= typeof iconTitle
=== 'function' ||
4744 ( typeof iconTitle
=== 'string' && iconTitle
.length
) ?
4745 OO
.ui
.resolveMsg( iconTitle
) : null;
4747 if ( this.iconTitle
!== iconTitle
) {
4748 this.iconTitle
= iconTitle
;
4750 if ( this.iconTitle
!== null ) {
4751 this.$icon
.attr( 'title', iconTitle
);
4753 this.$icon
.removeAttr( 'title' );
4764 * @return {string} Icon name
4766 OO
.ui
.IconElement
.prototype.getIcon = function () {
4773 * @return {string} Icon title text
4775 OO
.ui
.IconElement
.prototype.getIconTitle = function () {
4776 return this.iconTitle
;
4780 * Element containing an indicator.
4782 * Indicators are graphics, smaller than normal text. They can be used to describe unique status or
4783 * behavior. Indicators should only be used in exceptional cases; such as a button that opens a menu
4784 * instead of performing an action directly, or an item in a list which has errors that need to be
4791 * @param {Object} [config] Configuration options
4792 * @cfg {jQuery} [$indicator] Indicator node, assigned to #$indicator, omit to use a generated
4794 * @cfg {string} [indicator] Symbolic indicator name
4795 * @cfg {string} [indicatorTitle] Indicator title text or a function that returns text
4797 OO
.ui
.IndicatorElement
= function OoUiIndicatorElement( config
) {
4798 // Configuration initialization
4799 config
= config
|| {};
4802 this.$indicator
= null;
4803 this.indicator
= null;
4804 this.indicatorTitle
= null;
4807 this.setIndicator( config
.indicator
|| this.constructor.static.indicator
);
4808 this.setIndicatorTitle( config
.indicatorTitle
|| this.constructor.static.indicatorTitle
);
4809 this.setIndicatorElement( config
.$indicator
|| this.$( '<span>' ) );
4814 OO
.initClass( OO
.ui
.IndicatorElement
);
4816 /* Static Properties */
4823 * @property {string|null} Symbolic indicator name
4825 OO
.ui
.IndicatorElement
.static.indicator
= null;
4832 * @property {string|Function|null} Indicator title text, a function that returns text or null for no
4835 OO
.ui
.IndicatorElement
.static.indicatorTitle
= null;
4840 * Set the indicator element.
4842 * If an element is already set, it will be cleaned up before setting up the new element.
4844 * @param {jQuery} $indicator Element to use as indicator
4846 OO
.ui
.IndicatorElement
.prototype.setIndicatorElement = function ( $indicator
) {
4847 if ( this.$indicator
) {
4849 .removeClass( 'oo-ui-indicatorElement-indicator oo-ui-indicator-' + this.indicator
)
4850 .removeAttr( 'title' );
4853 this.$indicator
= $indicator
4854 .addClass( 'oo-ui-indicatorElement-indicator' )
4855 .toggleClass( 'oo-ui-indicator-' + this.indicator
, !!this.indicator
);
4856 if ( this.indicatorTitle
!== null ) {
4857 this.$indicator
.attr( 'title', this.indicatorTitle
);
4862 * Set indicator name.
4864 * @param {string|null} indicator Symbolic name of indicator to use or null for no indicator
4867 OO
.ui
.IndicatorElement
.prototype.setIndicator = function ( indicator
) {
4868 indicator
= typeof indicator
=== 'string' && indicator
.length
? indicator
.trim() : null;
4870 if ( this.indicator
!== indicator
) {
4871 if ( this.$indicator
) {
4872 if ( this.indicator
!== null ) {
4873 this.$indicator
.removeClass( 'oo-ui-indicator-' + this.indicator
);
4875 if ( indicator
!== null ) {
4876 this.$indicator
.addClass( 'oo-ui-indicator-' + indicator
);
4879 this.indicator
= indicator
;
4882 this.$element
.toggleClass( 'oo-ui-indicatorElement', !!this.indicator
);
4883 this.updateThemeClasses();
4889 * Set indicator title.
4891 * @param {string|Function|null} indicator Indicator title text, a function that returns text or
4892 * null for no indicator title
4895 OO
.ui
.IndicatorElement
.prototype.setIndicatorTitle = function ( indicatorTitle
) {
4896 indicatorTitle
= typeof indicatorTitle
=== 'function' ||
4897 ( typeof indicatorTitle
=== 'string' && indicatorTitle
.length
) ?
4898 OO
.ui
.resolveMsg( indicatorTitle
) : null;
4900 if ( this.indicatorTitle
!== indicatorTitle
) {
4901 this.indicatorTitle
= indicatorTitle
;
4902 if ( this.$indicator
) {
4903 if ( this.indicatorTitle
!== null ) {
4904 this.$indicator
.attr( 'title', indicatorTitle
);
4906 this.$indicator
.removeAttr( 'title' );
4915 * Get indicator name.
4917 * @return {string} Symbolic name of indicator
4919 OO
.ui
.IndicatorElement
.prototype.getIndicator = function () {
4920 return this.indicator
;
4924 * Get indicator title.
4926 * @return {string} Indicator title text
4928 OO
.ui
.IndicatorElement
.prototype.getIndicatorTitle = function () {
4929 return this.indicatorTitle
;
4933 * Element containing a label.
4939 * @param {Object} [config] Configuration options
4940 * @cfg {jQuery} [$label] Label node, assigned to #$label, omit to use a generated `<span>`
4941 * @cfg {jQuery|string|Function} [label] Label nodes, text or a function that returns nodes or text
4942 * @cfg {boolean} [autoFitLabel=true] Whether to fit the label or not.
4944 OO
.ui
.LabelElement
= function OoUiLabelElement( config
) {
4945 // Configuration initialization
4946 config
= config
|| {};
4951 this.autoFitLabel
= config
.autoFitLabel
=== undefined || !!config
.autoFitLabel
;
4954 this.setLabel( config
.label
|| this.constructor.static.label
);
4955 this.setLabelElement( config
.$label
|| this.$( '<span>' ) );
4960 OO
.initClass( OO
.ui
.LabelElement
);
4965 * @event labelChange
4966 * @param {string} value
4969 /* Static Properties */
4976 * @property {string|Function|null} Label text; a function that returns nodes or text; or null for
4979 OO
.ui
.LabelElement
.static.label
= null;
4984 * Set the label element.
4986 * If an element is already set, it will be cleaned up before setting up the new element.
4988 * @param {jQuery} $label Element to use as label
4990 OO
.ui
.LabelElement
.prototype.setLabelElement = function ( $label
) {
4991 if ( this.$label
) {
4992 this.$label
.removeClass( 'oo-ui-labelElement-label' ).empty();
4995 this.$label
= $label
.addClass( 'oo-ui-labelElement-label' );
4996 this.setLabelContent( this.label
);
5002 * An empty string will result in the label being hidden. A string containing only whitespace will
5003 * be converted to a single ` `.
5005 * @param {jQuery|string|Function|null} label Label nodes; text; a function that returns nodes or
5006 * text; or null for no label
5009 OO
.ui
.LabelElement
.prototype.setLabel = function ( label
) {
5010 label
= typeof label
=== 'function' ? OO
.ui
.resolveMsg( label
) : label
;
5011 label
= ( typeof label
=== 'string' && label
.length
) || label
instanceof jQuery
? label
: null;
5013 this.$element
.toggleClass( 'oo-ui-labelElement', !!label
);
5015 if ( this.label
!== label
) {
5016 if ( this.$label
) {
5017 this.setLabelContent( label
);
5020 this.emit( 'labelChange' );
5029 * @return {jQuery|string|Function|null} Label nodes; text; a function that returns nodes or
5030 * text; or null for no label
5032 OO
.ui
.LabelElement
.prototype.getLabel = function () {
5041 OO
.ui
.LabelElement
.prototype.fitLabel = function () {
5042 if ( this.$label
&& this.$label
.autoEllipsis
&& this.autoFitLabel
) {
5043 this.$label
.autoEllipsis( { hasSpan
: false, tooltip
: true } );
5050 * Set the content of the label.
5052 * Do not call this method until after the label element has been set by #setLabelElement.
5055 * @param {jQuery|string|Function|null} label Label nodes; text; a function that returns nodes or
5056 * text; or null for no label
5058 OO
.ui
.LabelElement
.prototype.setLabelContent = function ( label
) {
5059 if ( typeof label
=== 'string' ) {
5060 if ( label
.match( /^\s*$/ ) ) {
5061 // Convert whitespace only string to a single non-breaking space
5062 this.$label
.html( ' ' );
5064 this.$label
.text( label
);
5066 } else if ( label
instanceof jQuery
) {
5067 this.$label
.empty().append( label
);
5069 this.$label
.empty();
5074 * Mixin that adds a menu showing suggested values for a OO.ui.TextInputWidget.
5076 * Subclasses that set the value of #lookupInput from #onLookupMenuItemChoose should
5077 * be aware that this will cause new suggestions to be looked up for the new value. If this is
5078 * not desired, disable lookups with #setLookupsDisabled, then set the value, then re-enable lookups.
5084 * @param {Object} [config] Configuration options
5085 * @cfg {jQuery} [$overlay] Overlay for dropdown; defaults to relative positioning
5086 * @cfg {jQuery} [$container=this.$element] Element to render menu under
5088 OO
.ui
.LookupElement
= function OoUiLookupElement( config
) {
5089 // Configuration initialization
5090 config
= config
|| {};
5093 this.$overlay
= config
.$overlay
|| this.$element
;
5094 this.lookupMenu
= new OO
.ui
.TextInputMenuSelectWidget( this, {
5095 $: OO
.ui
.Element
.static.getJQuery( this.$overlay
),
5096 $container
: config
.$container
5098 this.lookupCache
= {};
5099 this.lookupQuery
= null;
5100 this.lookupRequest
= null;
5101 this.lookupsDisabled
= false;
5102 this.lookupInputFocused
= false;
5106 focus
: this.onLookupInputFocus
.bind( this ),
5107 blur
: this.onLookupInputBlur
.bind( this ),
5108 mousedown
: this.onLookupInputMouseDown
.bind( this )
5110 this.connect( this, { change
: 'onLookupInputChange' } );
5111 this.lookupMenu
.connect( this, {
5112 toggle
: 'onLookupMenuToggle',
5113 choose
: 'onLookupMenuItemChoose'
5117 this.$element
.addClass( 'oo-ui-lookupElement' );
5118 this.lookupMenu
.$element
.addClass( 'oo-ui-lookupElement-menu' );
5119 this.$overlay
.append( this.lookupMenu
.$element
);
5125 * Handle input focus event.
5127 * @param {jQuery.Event} e Input focus event
5129 OO
.ui
.LookupElement
.prototype.onLookupInputFocus = function () {
5130 this.lookupInputFocused
= true;
5131 this.populateLookupMenu();
5135 * Handle input blur event.
5137 * @param {jQuery.Event} e Input blur event
5139 OO
.ui
.LookupElement
.prototype.onLookupInputBlur = function () {
5140 this.closeLookupMenu();
5141 this.lookupInputFocused
= false;
5145 * Handle input mouse down event.
5147 * @param {jQuery.Event} e Input mouse down event
5149 OO
.ui
.LookupElement
.prototype.onLookupInputMouseDown = function () {
5150 // Only open the menu if the input was already focused.
5151 // This way we allow the user to open the menu again after closing it with Esc
5152 // by clicking in the input. Opening (and populating) the menu when initially
5153 // clicking into the input is handled by the focus handler.
5154 if ( this.lookupInputFocused
&& !this.lookupMenu
.isVisible() ) {
5155 this.populateLookupMenu();
5160 * Handle input change event.
5162 * @param {string} value New input value
5164 OO
.ui
.LookupElement
.prototype.onLookupInputChange = function () {
5165 if ( this.lookupInputFocused
) {
5166 this.populateLookupMenu();
5171 * Handle the lookup menu being shown/hidden.
5173 * @param {boolean} visible Whether the lookup menu is now visible.
5175 OO
.ui
.LookupElement
.prototype.onLookupMenuToggle = function ( visible
) {
5177 // When the menu is hidden, abort any active request and clear the menu.
5178 // This has to be done here in addition to closeLookupMenu(), because
5179 // MenuSelectWidget will close itself when the user presses Esc.
5180 this.abortLookupRequest();
5181 this.lookupMenu
.clearItems();
5186 * Handle menu item 'choose' event, updating the text input value to the value of the clicked item.
5188 * @param {OO.ui.MenuOptionWidget|null} item Selected item
5190 OO
.ui
.LookupElement
.prototype.onLookupMenuItemChoose = function ( item
) {
5192 this.setValue( item
.getData() );
5199 * @return {OO.ui.TextInputMenuSelectWidget}
5201 OO
.ui
.LookupElement
.prototype.getLookupMenu = function () {
5202 return this.lookupMenu
;
5206 * Disable or re-enable lookups.
5208 * When lookups are disabled, calls to #populateLookupMenu will be ignored.
5210 * @param {boolean} disabled Disable lookups
5212 OO
.ui
.LookupElement
.prototype.setLookupsDisabled = function ( disabled
) {
5213 this.lookupsDisabled
= !!disabled
;
5217 * Open the menu. If there are no entries in the menu, this does nothing.
5221 OO
.ui
.LookupElement
.prototype.openLookupMenu = function () {
5222 if ( !this.lookupMenu
.isEmpty() ) {
5223 this.lookupMenu
.toggle( true );
5229 * Close the menu, empty it, and abort any pending request.
5233 OO
.ui
.LookupElement
.prototype.closeLookupMenu = function () {
5234 this.lookupMenu
.toggle( false );
5235 this.abortLookupRequest();
5236 this.lookupMenu
.clearItems();
5241 * Request menu items based on the input's current value, and when they arrive,
5242 * populate the menu with these items and show the menu.
5244 * If lookups have been disabled with #setLookupsDisabled, this function does nothing.
5248 OO
.ui
.LookupElement
.prototype.populateLookupMenu = function () {
5250 value
= this.getValue();
5252 if ( this.lookupsDisabled
) {
5256 // If the input is empty, clear the menu
5257 if ( value
=== '' ) {
5258 this.closeLookupMenu();
5259 // Skip population if there is already a request pending for the current value
5260 } else if ( value
!== this.lookupQuery
) {
5261 this.getLookupMenuItems()
5262 .done( function ( items
) {
5263 widget
.lookupMenu
.clearItems();
5264 if ( items
.length
) {
5268 widget
.initializeLookupMenuSelection();
5270 widget
.lookupMenu
.toggle( false );
5273 .fail( function () {
5274 widget
.lookupMenu
.clearItems();
5282 * Select and highlight the first selectable item in the menu.
5286 OO
.ui
.LookupElement
.prototype.initializeLookupMenuSelection = function () {
5287 if ( !this.lookupMenu
.getSelectedItem() ) {
5288 this.lookupMenu
.selectItem( this.lookupMenu
.getFirstSelectableItem() );
5290 this.lookupMenu
.highlightItem( this.lookupMenu
.getSelectedItem() );
5294 * Get lookup menu items for the current query.
5296 * @return {jQuery.Promise} Promise object which will be passed menu items as the first argument of
5297 * the done event. If the request was aborted to make way for a subsequent request, this promise
5298 * will not be rejected: it will remain pending forever.
5300 OO
.ui
.LookupElement
.prototype.getLookupMenuItems = function () {
5302 value
= this.getValue(),
5303 deferred
= $.Deferred(),
5306 this.abortLookupRequest();
5307 if ( Object
.prototype.hasOwnProperty
.call( this.lookupCache
, value
) ) {
5308 deferred
.resolve( this.getLookupMenuOptionsFromData( this.lookupCache
[ value
] ) );
5311 this.lookupQuery
= value
;
5312 ourRequest
= this.lookupRequest
= this.getLookupRequest();
5314 .always( function () {
5315 // We need to pop pending even if this is an old request, otherwise
5316 // the widget will remain pending forever.
5317 // TODO: this assumes that an aborted request will fail or succeed soon after
5318 // being aborted, or at least eventually. It would be nice if we could popPending()
5319 // at abort time, but only if we knew that we hadn't already called popPending()
5320 // for that request.
5321 widget
.popPending();
5323 .done( function ( data
) {
5324 // If this is an old request (and aborting it somehow caused it to still succeed),
5325 // ignore its success completely
5326 if ( ourRequest
=== widget
.lookupRequest
) {
5327 widget
.lookupQuery
= null;
5328 widget
.lookupRequest
= null;
5329 widget
.lookupCache
[ value
] = widget
.getLookupCacheDataFromResponse( data
);
5330 deferred
.resolve( widget
.getLookupMenuOptionsFromData( widget
.lookupCache
[ value
] ) );
5333 .fail( function () {
5334 // If this is an old request (or a request failing because it's being aborted),
5335 // ignore its failure completely
5336 if ( ourRequest
=== widget
.lookupRequest
) {
5337 widget
.lookupQuery
= null;
5338 widget
.lookupRequest
= null;
5343 return deferred
.promise();
5347 * Abort the currently pending lookup request, if any.
5349 OO
.ui
.LookupElement
.prototype.abortLookupRequest = function () {
5350 var oldRequest
= this.lookupRequest
;
5352 // First unset this.lookupRequest to the fail handler will notice
5353 // that the request is no longer current
5354 this.lookupRequest
= null;
5355 this.lookupQuery
= null;
5361 * Get a new request object of the current lookup query value.
5364 * @return {jQuery.Promise} jQuery AJAX object, or promise object with an .abort() method
5366 OO
.ui
.LookupElement
.prototype.getLookupRequest = function () {
5367 // Stub, implemented in subclass
5372 * Pre-process data returned by the request from #getLookupRequest.
5374 * The return value of this function will be cached, and any further queries for the given value
5375 * will use the cache rather than doing API requests.
5378 * @param {Mixed} data Response from server
5379 * @return {Mixed} Cached result data
5381 OO
.ui
.LookupElement
.prototype.getLookupCacheDataFromResponse = function () {
5382 // Stub, implemented in subclass
5387 * Get a list of menu option widgets from the (possibly cached) data returned by
5388 * #getLookupCacheDataFromResponse.
5391 * @param {Mixed} data Cached result data, usually an array
5392 * @return {OO.ui.MenuOptionWidget[]} Menu items
5394 OO
.ui
.LookupElement
.prototype.getLookupMenuOptionsFromData = function () {
5395 // Stub, implemented in subclass
5400 * Element containing an OO.ui.PopupWidget object.
5406 * @param {Object} [config] Configuration options
5407 * @cfg {Object} [popup] Configuration to pass to popup
5408 * @cfg {boolean} [autoClose=true] Popup auto-closes when it loses focus
5410 OO
.ui
.PopupElement
= function OoUiPopupElement( config
) {
5411 // Configuration initialization
5412 config
= config
|| {};
5415 this.popup
= new OO
.ui
.PopupWidget( $.extend(
5416 { autoClose
: true },
5418 { $: this.$, $autoCloseIgnore
: this.$element
}
5427 * @return {OO.ui.PopupWidget} Popup widget
5429 OO
.ui
.PopupElement
.prototype.getPopup = function () {
5434 * Element with named flags that can be added, removed, listed and checked.
5436 * A flag, when set, adds a CSS class on the `$element` by combining `oo-ui-flaggedElement-` with
5437 * the flag name. Flags are primarily useful for styling.
5443 * @param {Object} [config] Configuration options
5444 * @cfg {string|string[]} [flags] Flags describing importance and functionality, e.g. 'primary',
5445 * 'safe', 'progressive', 'destructive' or 'constructive'
5446 * @cfg {jQuery} [$flagged] Flagged node, assigned to #$flagged, omit to use #$element
5448 OO
.ui
.FlaggedElement
= function OoUiFlaggedElement( config
) {
5449 // Configuration initialization
5450 config
= config
|| {};
5454 this.$flagged
= null;
5457 this.setFlags( config
.flags
);
5458 this.setFlaggedElement( config
.$flagged
|| this.$element
);
5465 * @param {Object.<string,boolean>} changes Object keyed by flag name containing boolean
5466 * added/removed properties
5472 * Set the flagged element.
5474 * If an element is already set, it will be cleaned up before setting up the new element.
5476 * @param {jQuery} $flagged Element to add flags to
5478 OO
.ui
.FlaggedElement
.prototype.setFlaggedElement = function ( $flagged
) {
5479 var classNames
= Object
.keys( this.flags
).map( function ( flag
) {
5480 return 'oo-ui-flaggedElement-' + flag
;
5483 if ( this.$flagged
) {
5484 this.$flagged
.removeClass( classNames
);
5487 this.$flagged
= $flagged
.addClass( classNames
);
5491 * Check if a flag is set.
5493 * @param {string} flag Name of flag
5494 * @return {boolean} Has flag
5496 OO
.ui
.FlaggedElement
.prototype.hasFlag = function ( flag
) {
5497 return flag
in this.flags
;
5501 * Get the names of all flags set.
5503 * @return {string[]} Flag names
5505 OO
.ui
.FlaggedElement
.prototype.getFlags = function () {
5506 return Object
.keys( this.flags
);
5515 OO
.ui
.FlaggedElement
.prototype.clearFlags = function () {
5516 var flag
, className
,
5519 classPrefix
= 'oo-ui-flaggedElement-';
5521 for ( flag
in this.flags
) {
5522 className
= classPrefix
+ flag
;
5523 changes
[ flag
] = false;
5524 delete this.flags
[ flag
];
5525 remove
.push( className
);
5528 if ( this.$flagged
) {
5529 this.$flagged
.removeClass( remove
.join( ' ' ) );
5532 this.updateThemeClasses();
5533 this.emit( 'flag', changes
);
5539 * Add one or more flags.
5541 * @param {string|string[]|Object.<string, boolean>} flags One or more flags to add, or an object
5542 * keyed by flag name containing boolean set/remove instructions.
5546 OO
.ui
.FlaggedElement
.prototype.setFlags = function ( flags
) {
5547 var i
, len
, flag
, className
,
5551 classPrefix
= 'oo-ui-flaggedElement-';
5553 if ( typeof flags
=== 'string' ) {
5554 className
= classPrefix
+ flags
;
5556 if ( !this.flags
[ flags
] ) {
5557 this.flags
[ flags
] = true;
5558 add
.push( className
);
5560 } else if ( $.isArray( flags
) ) {
5561 for ( i
= 0, len
= flags
.length
; i
< len
; i
++ ) {
5563 className
= classPrefix
+ flag
;
5565 if ( !this.flags
[ flag
] ) {
5566 changes
[ flag
] = true;
5567 this.flags
[ flag
] = true;
5568 add
.push( className
);
5571 } else if ( OO
.isPlainObject( flags
) ) {
5572 for ( flag
in flags
) {
5573 className
= classPrefix
+ flag
;
5574 if ( flags
[ flag
] ) {
5576 if ( !this.flags
[ flag
] ) {
5577 changes
[ flag
] = true;
5578 this.flags
[ flag
] = true;
5579 add
.push( className
);
5583 if ( this.flags
[ flag
] ) {
5584 changes
[ flag
] = false;
5585 delete this.flags
[ flag
];
5586 remove
.push( className
);
5592 if ( this.$flagged
) {
5594 .addClass( add
.join( ' ' ) )
5595 .removeClass( remove
.join( ' ' ) );
5598 this.updateThemeClasses();
5599 this.emit( 'flag', changes
);
5605 * Element with a title.
5607 * Titles are rendered by the browser and are made visible when hovering the element. Titles are
5608 * not visible on touch devices.
5614 * @param {Object} [config] Configuration options
5615 * @cfg {jQuery} [$titled] Titled node, assigned to #$titled, omit to use #$element
5616 * @cfg {string|Function} [title] Title text or a function that returns text. If not provided, the
5617 * static property 'title' is used.
5619 OO
.ui
.TitledElement
= function OoUiTitledElement( config
) {
5620 // Configuration initialization
5621 config
= config
|| {};
5624 this.$titled
= null;
5628 this.setTitle( config
.title
|| this.constructor.static.title
);
5629 this.setTitledElement( config
.$titled
|| this.$element
);
5634 OO
.initClass( OO
.ui
.TitledElement
);
5636 /* Static Properties */
5643 * @property {string|Function} Title text or a function that returns text
5645 OO
.ui
.TitledElement
.static.title
= null;
5650 * Set the titled element.
5652 * If an element is already set, it will be cleaned up before setting up the new element.
5654 * @param {jQuery} $titled Element to set title on
5656 OO
.ui
.TitledElement
.prototype.setTitledElement = function ( $titled
) {
5657 if ( this.$titled
) {
5658 this.$titled
.removeAttr( 'title' );
5661 this.$titled
= $titled
;
5663 this.$titled
.attr( 'title', this.title
);
5670 * @param {string|Function|null} title Title text, a function that returns text or null for no title
5673 OO
.ui
.TitledElement
.prototype.setTitle = function ( title
) {
5674 title
= typeof title
=== 'string' ? OO
.ui
.resolveMsg( title
) : null;
5676 if ( this.title
!== title
) {
5677 if ( this.$titled
) {
5678 if ( title
!== null ) {
5679 this.$titled
.attr( 'title', title
);
5681 this.$titled
.removeAttr( 'title' );
5693 * @return {string} Title string
5695 OO
.ui
.TitledElement
.prototype.getTitle = function () {
5700 * Element that can be automatically clipped to visible boundaries.
5702 * Whenever the element's natural height changes, you have to call
5703 * #clip to make sure it's still clipping correctly.
5709 * @param {Object} [config] Configuration options
5710 * @cfg {jQuery} [$clippable] Nodes to clip, assigned to #$clippable, omit to use #$element
5712 OO
.ui
.ClippableElement
= function OoUiClippableElement( config
) {
5713 // Configuration initialization
5714 config
= config
|| {};
5717 this.$clippable
= null;
5718 this.clipping
= false;
5719 this.clippedHorizontally
= false;
5720 this.clippedVertically
= false;
5721 this.$clippableContainer
= null;
5722 this.$clippableScroller
= null;
5723 this.$clippableWindow
= null;
5724 this.idealWidth
= null;
5725 this.idealHeight
= null;
5726 this.onClippableContainerScrollHandler
= this.clip
.bind( this );
5727 this.onClippableWindowResizeHandler
= this.clip
.bind( this );
5730 this.setClippableElement( config
.$clippable
|| this.$element
);
5736 * Set clippable element.
5738 * If an element is already set, it will be cleaned up before setting up the new element.
5740 * @param {jQuery} $clippable Element to make clippable
5742 OO
.ui
.ClippableElement
.prototype.setClippableElement = function ( $clippable
) {
5743 if ( this.$clippable
) {
5744 this.$clippable
.removeClass( 'oo-ui-clippableElement-clippable' );
5745 this.$clippable
.css( { width
: '', height
: '', overflowX
: '', overflowY
: '' } );
5746 OO
.ui
.Element
.static.reconsiderScrollbars( this.$clippable
[ 0 ] );
5749 this.$clippable
= $clippable
.addClass( 'oo-ui-clippableElement-clippable' );
5756 * Do not turn clipping on until after the element is attached to the DOM and visible.
5758 * @param {boolean} [clipping] Enable clipping, omit to toggle
5761 OO
.ui
.ClippableElement
.prototype.toggleClipping = function ( clipping
) {
5762 clipping
= clipping
=== undefined ? !this.clipping
: !!clipping
;
5764 if ( this.clipping
!== clipping
) {
5765 this.clipping
= clipping
;
5767 this.$clippableContainer
= this.$( this.getClosestScrollableElementContainer() );
5768 // If the clippable container is the root, we have to listen to scroll events and check
5769 // jQuery.scrollTop on the window because of browser inconsistencies
5770 this.$clippableScroller
= this.$clippableContainer
.is( 'html, body' ) ?
5771 this.$( OO
.ui
.Element
.static.getWindow( this.$clippableContainer
) ) :
5772 this.$clippableContainer
;
5773 this.$clippableScroller
.on( 'scroll', this.onClippableContainerScrollHandler
);
5774 this.$clippableWindow
= this.$( this.getElementWindow() )
5775 .on( 'resize', this.onClippableWindowResizeHandler
);
5776 // Initial clip after visible
5779 this.$clippable
.css( { width
: '', height
: '', overflowX
: '', overflowY
: '' } );
5780 OO
.ui
.Element
.static.reconsiderScrollbars( this.$clippable
[ 0 ] );
5782 this.$clippableContainer
= null;
5783 this.$clippableScroller
.off( 'scroll', this.onClippableContainerScrollHandler
);
5784 this.$clippableScroller
= null;
5785 this.$clippableWindow
.off( 'resize', this.onClippableWindowResizeHandler
);
5786 this.$clippableWindow
= null;
5794 * Check if the element will be clipped to fit the visible area of the nearest scrollable container.
5796 * @return {boolean} Element will be clipped to the visible area
5798 OO
.ui
.ClippableElement
.prototype.isClipping = function () {
5799 return this.clipping
;
5803 * Check if the bottom or right of the element is being clipped by the nearest scrollable container.
5805 * @return {boolean} Part of the element is being clipped
5807 OO
.ui
.ClippableElement
.prototype.isClipped = function () {
5808 return this.clippedHorizontally
|| this.clippedVertically
;
5812 * Check if the right of the element is being clipped by the nearest scrollable container.
5814 * @return {boolean} Part of the element is being clipped
5816 OO
.ui
.ClippableElement
.prototype.isClippedHorizontally = function () {
5817 return this.clippedHorizontally
;
5821 * Check if the bottom of the element is being clipped by the nearest scrollable container.
5823 * @return {boolean} Part of the element is being clipped
5825 OO
.ui
.ClippableElement
.prototype.isClippedVertically = function () {
5826 return this.clippedVertically
;
5830 * Set the ideal size. These are the dimensions the element will have when it's not being clipped.
5832 * @param {number|string} [width] Width as a number of pixels or CSS string with unit suffix
5833 * @param {number|string} [height] Height as a number of pixels or CSS string with unit suffix
5835 OO
.ui
.ClippableElement
.prototype.setIdealSize = function ( width
, height
) {
5836 this.idealWidth
= width
;
5837 this.idealHeight
= height
;
5839 if ( !this.clipping
) {
5840 // Update dimensions
5841 this.$clippable
.css( { width
: width
, height
: height
} );
5843 // While clipping, idealWidth and idealHeight are not considered
5847 * Clip element to visible boundaries and allow scrolling when needed. Call this method when
5848 * the element's natural height changes.
5850 * Element will be clipped the bottom or right of the element is within 10px of the edge of, or
5851 * overlapped by, the visible area of the nearest scrollable container.
5855 OO
.ui
.ClippableElement
.prototype.clip = function () {
5856 if ( !this.clipping
) {
5857 // this.$clippableContainer and this.$clippableWindow are null, so the below will fail
5861 var buffer
= 7, // Chosen by fair dice roll
5862 cOffset
= this.$clippable
.offset(),
5863 $container
= this.$clippableContainer
.is( 'html, body' ) ?
5864 this.$clippableWindow
: this.$clippableContainer
,
5865 ccOffset
= $container
.offset() || { top
: 0, left
: 0 },
5866 ccHeight
= $container
.innerHeight() - buffer
,
5867 ccWidth
= $container
.innerWidth() - buffer
,
5868 cHeight
= this.$clippable
.outerHeight() + buffer
,
5869 cWidth
= this.$clippable
.outerWidth() + buffer
,
5870 scrollTop
= this.$clippableScroller
.scrollTop(),
5871 scrollLeft
= this.$clippableScroller
.scrollLeft(),
5872 desiredWidth
= cOffset
.left
< 0 ?
5873 cWidth
+ cOffset
.left
:
5874 ( ccOffset
.left
+ scrollLeft
+ ccWidth
) - cOffset
.left
,
5875 desiredHeight
= cOffset
.top
< 0 ?
5876 cHeight
+ cOffset
.top
:
5877 ( ccOffset
.top
+ scrollTop
+ ccHeight
) - cOffset
.top
,
5878 naturalWidth
= this.$clippable
.prop( 'scrollWidth' ),
5879 naturalHeight
= this.$clippable
.prop( 'scrollHeight' ),
5880 clipWidth
= desiredWidth
< naturalWidth
,
5881 clipHeight
= desiredHeight
< naturalHeight
;
5884 this.$clippable
.css( { overflowX
: 'scroll', width
: desiredWidth
} );
5886 this.$clippable
.css( { width
: this.idealWidth
|| '', overflowX
: '' } );
5889 this.$clippable
.css( { overflowY
: 'scroll', height
: desiredHeight
} );
5891 this.$clippable
.css( { height
: this.idealHeight
|| '', overflowY
: '' } );
5894 // If we stopped clipping in at least one of the dimensions
5895 if ( !clipWidth
|| !clipHeight
) {
5896 OO
.ui
.Element
.static.reconsiderScrollbars( this.$clippable
[ 0 ] );
5899 this.clippedHorizontally
= clipWidth
;
5900 this.clippedVertically
= clipHeight
;
5906 * Generic toolbar tool.
5910 * @extends OO.ui.Widget
5911 * @mixins OO.ui.IconElement
5912 * @mixins OO.ui.FlaggedElement
5915 * @param {OO.ui.ToolGroup} toolGroup
5916 * @param {Object} [config] Configuration options
5917 * @cfg {string|Function} [title] Title text or a function that returns text
5919 OO
.ui
.Tool
= function OoUiTool( toolGroup
, config
) {
5920 // Configuration initialization
5921 config
= config
|| {};
5923 // Parent constructor
5924 OO
.ui
.Tool
.super.call( this, config
);
5926 // Mixin constructors
5927 OO
.ui
.IconElement
.call( this, config
);
5928 OO
.ui
.FlaggedElement
.call( this, config
);
5931 this.toolGroup
= toolGroup
;
5932 this.toolbar
= this.toolGroup
.getToolbar();
5933 this.active
= false;
5934 this.$title
= this.$( '<span>' );
5935 this.$accel
= this.$( '<span>' );
5936 this.$link
= this.$( '<a>' );
5940 this.toolbar
.connect( this, { updateState
: 'onUpdateState' } );
5943 this.$title
.addClass( 'oo-ui-tool-title' );
5945 .addClass( 'oo-ui-tool-accel' )
5947 // This may need to be changed if the key names are ever localized,
5948 // but for now they are essentially written in English
5953 .addClass( 'oo-ui-tool-link' )
5954 .append( this.$icon
, this.$title
, this.$accel
)
5955 .prop( 'tabIndex', 0 )
5956 .attr( 'role', 'button' );
5958 .data( 'oo-ui-tool', this )
5960 'oo-ui-tool ' + 'oo-ui-tool-name-' +
5961 this.constructor.static.name
.replace( /^([^\/]+)\/([^\/]+).*$/, '$1-$2' )
5963 .append( this.$link
);
5964 this.setTitle( config
.title
|| this.constructor.static.title
);
5969 OO
.inheritClass( OO
.ui
.Tool
, OO
.ui
.Widget
);
5970 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.IconElement
);
5971 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.FlaggedElement
);
5979 /* Static Properties */
5985 OO
.ui
.Tool
.static.tagName
= 'span';
5988 * Symbolic name of tool.
5993 * @property {string}
5995 OO
.ui
.Tool
.static.name
= '';
6003 * @property {string}
6005 OO
.ui
.Tool
.static.group
= '';
6010 * Title is used as a tooltip when the tool is part of a bar tool group, or a label when the tool
6011 * is part of a list or menu tool group. If a trigger is associated with an action by the same name
6012 * as the tool, a description of its keyboard shortcut for the appropriate platform will be
6013 * appended to the title if the tool is part of a bar tool group.
6018 * @property {string|Function} Title text or a function that returns text
6020 OO
.ui
.Tool
.static.title
= '';
6023 * Tool can be automatically added to catch-all groups.
6027 * @property {boolean}
6029 OO
.ui
.Tool
.static.autoAddToCatchall
= true;
6032 * Tool can be automatically added to named groups.
6035 * @property {boolean}
6038 OO
.ui
.Tool
.static.autoAddToGroup
= true;
6041 * Check if this tool is compatible with given data.
6045 * @param {Mixed} data Data to check
6046 * @return {boolean} Tool can be used with data
6048 OO
.ui
.Tool
.static.isCompatibleWith = function () {
6055 * Handle the toolbar state being updated.
6057 * This is an abstract method that must be overridden in a concrete subclass.
6061 OO
.ui
.Tool
.prototype.onUpdateState = function () {
6063 'OO.ui.Tool.onUpdateState not implemented in this subclass:' + this.constructor
6068 * Handle the tool being selected.
6070 * This is an abstract method that must be overridden in a concrete subclass.
6074 OO
.ui
.Tool
.prototype.onSelect = function () {
6076 'OO.ui.Tool.onSelect not implemented in this subclass:' + this.constructor
6081 * Check if the button is active.
6083 * @return {boolean} Button is active
6085 OO
.ui
.Tool
.prototype.isActive = function () {
6090 * Make the button appear active or inactive.
6092 * @param {boolean} state Make button appear active
6094 OO
.ui
.Tool
.prototype.setActive = function ( state
) {
6095 this.active
= !!state
;
6096 if ( this.active
) {
6097 this.$element
.addClass( 'oo-ui-tool-active' );
6099 this.$element
.removeClass( 'oo-ui-tool-active' );
6104 * Get the tool title.
6106 * @param {string|Function} title Title text or a function that returns text
6109 OO
.ui
.Tool
.prototype.setTitle = function ( title
) {
6110 this.title
= OO
.ui
.resolveMsg( title
);
6116 * Get the tool title.
6118 * @return {string} Title text
6120 OO
.ui
.Tool
.prototype.getTitle = function () {
6125 * Get the tool's symbolic name.
6127 * @return {string} Symbolic name of tool
6129 OO
.ui
.Tool
.prototype.getName = function () {
6130 return this.constructor.static.name
;
6136 OO
.ui
.Tool
.prototype.updateTitle = function () {
6137 var titleTooltips
= this.toolGroup
.constructor.static.titleTooltips
,
6138 accelTooltips
= this.toolGroup
.constructor.static.accelTooltips
,
6139 accel
= this.toolbar
.getToolAccelerator( this.constructor.static.name
),
6142 this.$title
.text( this.title
);
6143 this.$accel
.text( accel
);
6145 if ( titleTooltips
&& typeof this.title
=== 'string' && this.title
.length
) {
6146 tooltipParts
.push( this.title
);
6148 if ( accelTooltips
&& typeof accel
=== 'string' && accel
.length
) {
6149 tooltipParts
.push( accel
);
6151 if ( tooltipParts
.length
) {
6152 this.$link
.attr( 'title', tooltipParts
.join( ' ' ) );
6154 this.$link
.removeAttr( 'title' );
6161 OO
.ui
.Tool
.prototype.destroy = function () {
6162 this.toolbar
.disconnect( this );
6163 this.$element
.remove();
6167 * Collection of tool groups.
6170 * @extends OO.ui.Element
6171 * @mixins OO.EventEmitter
6172 * @mixins OO.ui.GroupElement
6175 * @param {OO.ui.ToolFactory} toolFactory Factory for creating tools
6176 * @param {OO.ui.ToolGroupFactory} toolGroupFactory Factory for creating tool groups
6177 * @param {Object} [config] Configuration options
6178 * @cfg {boolean} [actions] Add an actions section opposite to the tools
6179 * @cfg {boolean} [shadow] Add a shadow below the toolbar
6181 OO
.ui
.Toolbar
= function OoUiToolbar( toolFactory
, toolGroupFactory
, config
) {
6182 // Configuration initialization
6183 config
= config
|| {};
6185 // Parent constructor
6186 OO
.ui
.Toolbar
.super.call( this, config
);
6188 // Mixin constructors
6189 OO
.EventEmitter
.call( this );
6190 OO
.ui
.GroupElement
.call( this, config
);
6193 this.toolFactory
= toolFactory
;
6194 this.toolGroupFactory
= toolGroupFactory
;
6197 this.$bar
= this.$( '<div>' );
6198 this.$actions
= this.$( '<div>' );
6199 this.initialized
= false;
6203 .add( this.$bar
).add( this.$group
).add( this.$actions
)
6204 .on( 'mousedown touchstart', this.onPointerDown
.bind( this ) );
6207 this.$group
.addClass( 'oo-ui-toolbar-tools' );
6208 if ( config
.actions
) {
6209 this.$bar
.append( this.$actions
.addClass( 'oo-ui-toolbar-actions' ) );
6212 .addClass( 'oo-ui-toolbar-bar' )
6213 .append( this.$group
, '<div style="clear:both"></div>' );
6214 if ( config
.shadow
) {
6215 this.$bar
.append( '<div class="oo-ui-toolbar-shadow"></div>' );
6217 this.$element
.addClass( 'oo-ui-toolbar' ).append( this.$bar
);
6222 OO
.inheritClass( OO
.ui
.Toolbar
, OO
.ui
.Element
);
6223 OO
.mixinClass( OO
.ui
.Toolbar
, OO
.EventEmitter
);
6224 OO
.mixinClass( OO
.ui
.Toolbar
, OO
.ui
.GroupElement
);
6229 * Get the tool factory.
6231 * @return {OO.ui.ToolFactory} Tool factory
6233 OO
.ui
.Toolbar
.prototype.getToolFactory = function () {
6234 return this.toolFactory
;
6238 * Get the tool group factory.
6240 * @return {OO.Factory} Tool group factory
6242 OO
.ui
.Toolbar
.prototype.getToolGroupFactory = function () {
6243 return this.toolGroupFactory
;
6247 * Handles mouse down events.
6249 * @param {jQuery.Event} e Mouse down event
6251 OO
.ui
.Toolbar
.prototype.onPointerDown = function ( e
) {
6252 var $closestWidgetToEvent
= this.$( e
.target
).closest( '.oo-ui-widget' ),
6253 $closestWidgetToToolbar
= this.$element
.closest( '.oo-ui-widget' );
6254 if ( !$closestWidgetToEvent
.length
|| $closestWidgetToEvent
[ 0 ] === $closestWidgetToToolbar
[ 0 ] ) {
6260 * Sets up handles and preloads required information for the toolbar to work.
6261 * This must be called after it is attached to a visible document and before doing anything else.
6263 OO
.ui
.Toolbar
.prototype.initialize = function () {
6264 this.initialized
= true;
6270 * Tools can be specified in the following ways:
6272 * - A specific tool: `{ name: 'tool-name' }` or `'tool-name'`
6273 * - All tools in a group: `{ group: 'group-name' }`
6274 * - All tools: `'*'` - Using this will make the group a list with a "More" label by default
6276 * @param {Object.<string,Array>} groups List of tool group configurations
6277 * @param {Array|string} [groups.include] Tools to include
6278 * @param {Array|string} [groups.exclude] Tools to exclude
6279 * @param {Array|string} [groups.promote] Tools to promote to the beginning
6280 * @param {Array|string} [groups.demote] Tools to demote to the end
6282 OO
.ui
.Toolbar
.prototype.setup = function ( groups
) {
6283 var i
, len
, type
, group
,
6285 defaultType
= 'bar';
6287 // Cleanup previous groups
6290 // Build out new groups
6291 for ( i
= 0, len
= groups
.length
; i
< len
; i
++ ) {
6292 group
= groups
[ i
];
6293 if ( group
.include
=== '*' ) {
6294 // Apply defaults to catch-all groups
6295 if ( group
.type
=== undefined ) {
6296 group
.type
= 'list';
6298 if ( group
.label
=== undefined ) {
6299 group
.label
= OO
.ui
.msg( 'ooui-toolbar-more' );
6302 // Check type has been registered
6303 type
= this.getToolGroupFactory().lookup( group
.type
) ? group
.type
: defaultType
;
6305 this.getToolGroupFactory().create( type
, this, $.extend( { $: this.$ }, group
) )
6308 this.addItems( items
);
6312 * Remove all tools and groups from the toolbar.
6314 OO
.ui
.Toolbar
.prototype.reset = function () {
6319 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
6320 this.items
[ i
].destroy();
6326 * Destroys toolbar, removing event handlers and DOM elements.
6328 * Call this whenever you are done using a toolbar.
6330 OO
.ui
.Toolbar
.prototype.destroy = function () {
6332 this.$element
.remove();
6336 * Check if tool has not been used yet.
6338 * @param {string} name Symbolic name of tool
6339 * @return {boolean} Tool is available
6341 OO
.ui
.Toolbar
.prototype.isToolAvailable = function ( name
) {
6342 return !this.tools
[ name
];
6346 * Prevent tool from being used again.
6348 * @param {OO.ui.Tool} tool Tool to reserve
6350 OO
.ui
.Toolbar
.prototype.reserveTool = function ( tool
) {
6351 this.tools
[ tool
.getName() ] = tool
;
6355 * Allow tool to be used again.
6357 * @param {OO.ui.Tool} tool Tool to release
6359 OO
.ui
.Toolbar
.prototype.releaseTool = function ( tool
) {
6360 delete this.tools
[ tool
.getName() ];
6364 * Get accelerator label for tool.
6366 * This is a stub that should be overridden to provide access to accelerator information.
6368 * @param {string} name Symbolic name of tool
6369 * @return {string|undefined} Tool accelerator label if available
6371 OO
.ui
.Toolbar
.prototype.getToolAccelerator = function () {
6376 * Collection of tools.
6378 * Tools can be specified in the following ways:
6380 * - A specific tool: `{ name: 'tool-name' }` or `'tool-name'`
6381 * - All tools in a group: `{ group: 'group-name' }`
6382 * - All tools: `'*'`
6386 * @extends OO.ui.Widget
6387 * @mixins OO.ui.GroupElement
6390 * @param {OO.ui.Toolbar} toolbar
6391 * @param {Object} [config] Configuration options
6392 * @cfg {Array|string} [include=[]] List of tools to include
6393 * @cfg {Array|string} [exclude=[]] List of tools to exclude
6394 * @cfg {Array|string} [promote=[]] List of tools to promote to the beginning
6395 * @cfg {Array|string} [demote=[]] List of tools to demote to the end
6397 OO
.ui
.ToolGroup
= function OoUiToolGroup( toolbar
, config
) {
6398 // Configuration initialization
6399 config
= config
|| {};
6401 // Parent constructor
6402 OO
.ui
.ToolGroup
.super.call( this, config
);
6404 // Mixin constructors
6405 OO
.ui
.GroupElement
.call( this, config
);
6408 this.toolbar
= toolbar
;
6410 this.pressed
= null;
6411 this.autoDisabled
= false;
6412 this.include
= config
.include
|| [];
6413 this.exclude
= config
.exclude
|| [];
6414 this.promote
= config
.promote
|| [];
6415 this.demote
= config
.demote
|| [];
6416 this.onCapturedMouseUpHandler
= this.onCapturedMouseUp
.bind( this );
6420 'mousedown touchstart': this.onPointerDown
.bind( this ),
6421 'mouseup touchend': this.onPointerUp
.bind( this ),
6422 mouseover
: this.onMouseOver
.bind( this ),
6423 mouseout
: this.onMouseOut
.bind( this )
6425 this.toolbar
.getToolFactory().connect( this, { register
: 'onToolFactoryRegister' } );
6426 this.aggregate( { disable
: 'itemDisable' } );
6427 this.connect( this, { itemDisable
: 'updateDisabled' } );
6430 this.$group
.addClass( 'oo-ui-toolGroup-tools' );
6432 .addClass( 'oo-ui-toolGroup' )
6433 .append( this.$group
);
6439 OO
.inheritClass( OO
.ui
.ToolGroup
, OO
.ui
.Widget
);
6440 OO
.mixinClass( OO
.ui
.ToolGroup
, OO
.ui
.GroupElement
);
6448 /* Static Properties */
6451 * Show labels in tooltips.
6455 * @property {boolean}
6457 OO
.ui
.ToolGroup
.static.titleTooltips
= false;
6460 * Show acceleration labels in tooltips.
6464 * @property {boolean}
6466 OO
.ui
.ToolGroup
.static.accelTooltips
= false;
6469 * Automatically disable the toolgroup when all tools are disabled
6473 * @property {boolean}
6475 OO
.ui
.ToolGroup
.static.autoDisable
= true;
6482 OO
.ui
.ToolGroup
.prototype.isDisabled = function () {
6483 return this.autoDisabled
|| OO
.ui
.ToolGroup
.super.prototype.isDisabled
.apply( this, arguments
);
6489 OO
.ui
.ToolGroup
.prototype.updateDisabled = function () {
6490 var i
, item
, allDisabled
= true;
6492 if ( this.constructor.static.autoDisable
) {
6493 for ( i
= this.items
.length
- 1; i
>= 0; i
-- ) {
6494 item
= this.items
[ i
];
6495 if ( !item
.isDisabled() ) {
6496 allDisabled
= false;
6500 this.autoDisabled
= allDisabled
;
6502 OO
.ui
.ToolGroup
.super.prototype.updateDisabled
.apply( this, arguments
);
6506 * Handle mouse down events.
6508 * @param {jQuery.Event} e Mouse down event
6510 OO
.ui
.ToolGroup
.prototype.onPointerDown = function ( e
) {
6511 // e.which is 0 for touch events, 1 for left mouse button
6512 if ( !this.isDisabled() && e
.which
<= 1 ) {
6513 this.pressed
= this.getTargetTool( e
);
6514 if ( this.pressed
) {
6515 this.pressed
.setActive( true );
6516 this.getElementDocument().addEventListener(
6517 'mouseup', this.onCapturedMouseUpHandler
, true
6525 * Handle captured mouse up events.
6527 * @param {Event} e Mouse up event
6529 OO
.ui
.ToolGroup
.prototype.onCapturedMouseUp = function ( e
) {
6530 this.getElementDocument().removeEventListener( 'mouseup', this.onCapturedMouseUpHandler
, true );
6531 // onPointerUp may be called a second time, depending on where the mouse is when the button is
6532 // released, but since `this.pressed` will no longer be true, the second call will be ignored.
6533 this.onPointerUp( e
);
6537 * Handle mouse up events.
6539 * @param {jQuery.Event} e Mouse up event
6541 OO
.ui
.ToolGroup
.prototype.onPointerUp = function ( e
) {
6542 var tool
= this.getTargetTool( e
);
6544 // e.which is 0 for touch events, 1 for left mouse button
6545 if ( !this.isDisabled() && e
.which
<= 1 && this.pressed
&& this.pressed
=== tool
) {
6546 this.pressed
.onSelect();
6549 this.pressed
= null;
6554 * Handle mouse over events.
6556 * @param {jQuery.Event} e Mouse over event
6558 OO
.ui
.ToolGroup
.prototype.onMouseOver = function ( e
) {
6559 var tool
= this.getTargetTool( e
);
6561 if ( this.pressed
&& this.pressed
=== tool
) {
6562 this.pressed
.setActive( true );
6567 * Handle mouse out events.
6569 * @param {jQuery.Event} e Mouse out event
6571 OO
.ui
.ToolGroup
.prototype.onMouseOut = function ( e
) {
6572 var tool
= this.getTargetTool( e
);
6574 if ( this.pressed
&& this.pressed
=== tool
) {
6575 this.pressed
.setActive( false );
6580 * Get the closest tool to a jQuery.Event.
6582 * Only tool links are considered, which prevents other elements in the tool such as popups from
6583 * triggering tool group interactions.
6586 * @param {jQuery.Event} e
6587 * @return {OO.ui.Tool|null} Tool, `null` if none was found
6589 OO
.ui
.ToolGroup
.prototype.getTargetTool = function ( e
) {
6591 $item
= this.$( e
.target
).closest( '.oo-ui-tool-link' );
6593 if ( $item
.length
) {
6594 tool
= $item
.parent().data( 'oo-ui-tool' );
6597 return tool
&& !tool
.isDisabled() ? tool
: null;
6601 * Handle tool registry register events.
6603 * If a tool is registered after the group is created, we must repopulate the list to account for:
6605 * - a tool being added that may be included
6606 * - a tool already included being overridden
6608 * @param {string} name Symbolic name of tool
6610 OO
.ui
.ToolGroup
.prototype.onToolFactoryRegister = function () {
6615 * Get the toolbar this group is in.
6617 * @return {OO.ui.Toolbar} Toolbar of group
6619 OO
.ui
.ToolGroup
.prototype.getToolbar = function () {
6620 return this.toolbar
;
6624 * Add and remove tools based on configuration.
6626 OO
.ui
.ToolGroup
.prototype.populate = function () {
6627 var i
, len
, name
, tool
,
6628 toolFactory
= this.toolbar
.getToolFactory(),
6632 list
= this.toolbar
.getToolFactory().getTools(
6633 this.include
, this.exclude
, this.promote
, this.demote
6636 // Build a list of needed tools
6637 for ( i
= 0, len
= list
.length
; i
< len
; i
++ ) {
6641 toolFactory
.lookup( name
) &&
6642 // Tool is available or is already in this group
6643 ( this.toolbar
.isToolAvailable( name
) || this.tools
[ name
] )
6645 tool
= this.tools
[ name
];
6647 // Auto-initialize tools on first use
6648 this.tools
[ name
] = tool
= toolFactory
.create( name
, this );
6651 this.toolbar
.reserveTool( tool
);
6653 names
[ name
] = true;
6656 // Remove tools that are no longer needed
6657 for ( name
in this.tools
) {
6658 if ( !names
[ name
] ) {
6659 this.tools
[ name
].destroy();
6660 this.toolbar
.releaseTool( this.tools
[ name
] );
6661 remove
.push( this.tools
[ name
] );
6662 delete this.tools
[ name
];
6665 if ( remove
.length
) {
6666 this.removeItems( remove
);
6668 // Update emptiness state
6670 this.$element
.removeClass( 'oo-ui-toolGroup-empty' );
6672 this.$element
.addClass( 'oo-ui-toolGroup-empty' );
6674 // Re-add tools (moving existing ones to new locations)
6675 this.addItems( add
);
6676 // Disabled state may depend on items
6677 this.updateDisabled();
6681 * Destroy tool group.
6683 OO
.ui
.ToolGroup
.prototype.destroy = function () {
6687 this.toolbar
.getToolFactory().disconnect( this );
6688 for ( name
in this.tools
) {
6689 this.toolbar
.releaseTool( this.tools
[ name
] );
6690 this.tools
[ name
].disconnect( this ).destroy();
6691 delete this.tools
[ name
];
6693 this.$element
.remove();
6697 * Dialog for showing a message.
6700 * - Registers two actions by default (safe and primary).
6701 * - Renders action widgets in the footer.
6704 * @extends OO.ui.Dialog
6707 * @param {Object} [config] Configuration options
6709 OO
.ui
.MessageDialog
= function OoUiMessageDialog( config
) {
6710 // Parent constructor
6711 OO
.ui
.MessageDialog
.super.call( this, config
);
6714 this.verticalActionLayout
= null;
6717 this.$element
.addClass( 'oo-ui-messageDialog' );
6722 OO
.inheritClass( OO
.ui
.MessageDialog
, OO
.ui
.Dialog
);
6724 /* Static Properties */
6726 OO
.ui
.MessageDialog
.static.name
= 'message';
6728 OO
.ui
.MessageDialog
.static.size
= 'small';
6730 OO
.ui
.MessageDialog
.static.verbose
= false;
6735 * A confirmation dialog's title should describe what the progressive action will do. An alert
6736 * dialog's title should describe what event occurred.
6740 * @property {jQuery|string|Function|null}
6742 OO
.ui
.MessageDialog
.static.title
= null;
6745 * A confirmation dialog's message should describe the consequences of the progressive action. An
6746 * alert dialog's message should describe why the event occurred.
6750 * @property {jQuery|string|Function|null}
6752 OO
.ui
.MessageDialog
.static.message
= null;
6754 OO
.ui
.MessageDialog
.static.actions
= [
6755 { action
: 'accept', label
: OO
.ui
.deferMsg( 'ooui-dialog-message-accept' ), flags
: 'primary' },
6756 { action
: 'reject', label
: OO
.ui
.deferMsg( 'ooui-dialog-message-reject' ), flags
: 'safe' }
6764 OO
.ui
.MessageDialog
.prototype.setManager = function ( manager
) {
6765 OO
.ui
.MessageDialog
.super.prototype.setManager
.call( this, manager
);
6768 this.manager
.connect( this, {
6778 OO
.ui
.MessageDialog
.prototype.onActionResize = function ( action
) {
6780 return OO
.ui
.MessageDialog
.super.prototype.onActionResize
.call( this, action
);
6784 * Handle window resized events.
6786 OO
.ui
.MessageDialog
.prototype.onResize = function () {
6788 dialog
.fitActions();
6789 // Wait for CSS transition to finish and do it again :(
6790 setTimeout( function () {
6791 dialog
.fitActions();
6796 * Toggle action layout between vertical and horizontal.
6798 * @param {boolean} [value] Layout actions vertically, omit to toggle
6801 OO
.ui
.MessageDialog
.prototype.toggleVerticalActionLayout = function ( value
) {
6802 value
= value
=== undefined ? !this.verticalActionLayout
: !!value
;
6804 if ( value
!== this.verticalActionLayout
) {
6805 this.verticalActionLayout
= value
;
6807 .toggleClass( 'oo-ui-messageDialog-actions-vertical', value
)
6808 .toggleClass( 'oo-ui-messageDialog-actions-horizontal', !value
);
6817 OO
.ui
.MessageDialog
.prototype.getActionProcess = function ( action
) {
6819 return new OO
.ui
.Process( function () {
6820 this.close( { action
: action
} );
6823 return OO
.ui
.MessageDialog
.super.prototype.getActionProcess
.call( this, action
);
6829 * @param {Object} [data] Dialog opening data
6830 * @param {jQuery|string|Function|null} [data.title] Description of the action being confirmed
6831 * @param {jQuery|string|Function|null} [data.message] Description of the action's consequence
6832 * @param {boolean} [data.verbose] Message is verbose and should be styled as a long message
6833 * @param {Object[]} [data.actions] List of OO.ui.ActionOptionWidget configuration options for each
6836 OO
.ui
.MessageDialog
.prototype.getSetupProcess = function ( data
) {
6840 return OO
.ui
.MessageDialog
.super.prototype.getSetupProcess
.call( this, data
)
6841 .next( function () {
6842 this.title
.setLabel(
6843 data
.title
!== undefined ? data
.title
: this.constructor.static.title
6845 this.message
.setLabel(
6846 data
.message
!== undefined ? data
.message
: this.constructor.static.message
6848 this.message
.$element
.toggleClass(
6849 'oo-ui-messageDialog-message-verbose',
6850 data
.verbose
!== undefined ? data
.verbose
: this.constructor.static.verbose
6858 OO
.ui
.MessageDialog
.prototype.getBodyHeight = function () {
6859 var bodyHeight
, oldOverflow
,
6860 $scrollable
= this.container
.$element
;
6862 oldOverflow
= $scrollable
[ 0 ].style
.overflow
;
6863 $scrollable
[ 0 ].style
.overflow
= 'hidden';
6865 OO
.ui
.Element
.static.reconsiderScrollbars( $scrollable
[ 0 ] );
6867 bodyHeight
= this.text
.$element
.outerHeight( true );
6868 $scrollable
[ 0 ].style
.overflow
= oldOverflow
;
6876 OO
.ui
.MessageDialog
.prototype.setDimensions = function ( dim
) {
6877 var $scrollable
= this.container
.$element
;
6878 OO
.ui
.MessageDialog
.super.prototype.setDimensions
.call( this, dim
);
6880 // Twiddle the overflow property, otherwise an unnecessary scrollbar will be produced.
6881 // Need to do it after transition completes (250ms), add 50ms just in case.
6882 setTimeout( function () {
6883 var oldOverflow
= $scrollable
[ 0 ].style
.overflow
;
6884 $scrollable
[ 0 ].style
.overflow
= 'hidden';
6886 OO
.ui
.Element
.static.reconsiderScrollbars( $scrollable
[ 0 ] );
6888 $scrollable
[ 0 ].style
.overflow
= oldOverflow
;
6897 OO
.ui
.MessageDialog
.prototype.initialize = function () {
6899 OO
.ui
.MessageDialog
.super.prototype.initialize
.call( this );
6902 this.$actions
= this.$( '<div>' );
6903 this.container
= new OO
.ui
.PanelLayout( {
6904 $: this.$, scrollable
: true, classes
: [ 'oo-ui-messageDialog-container' ]
6906 this.text
= new OO
.ui
.PanelLayout( {
6907 $: this.$, padded
: true, expanded
: false, classes
: [ 'oo-ui-messageDialog-text' ]
6909 this.message
= new OO
.ui
.LabelWidget( {
6910 $: this.$, classes
: [ 'oo-ui-messageDialog-message' ]
6914 this.title
.$element
.addClass( 'oo-ui-messageDialog-title' );
6915 this.$content
.addClass( 'oo-ui-messageDialog-content' );
6916 this.container
.$element
.append( this.text
.$element
);
6917 this.text
.$element
.append( this.title
.$element
, this.message
.$element
);
6918 this.$body
.append( this.container
.$element
);
6919 this.$actions
.addClass( 'oo-ui-messageDialog-actions' );
6920 this.$foot
.append( this.$actions
);
6926 OO
.ui
.MessageDialog
.prototype.attachActions = function () {
6927 var i
, len
, other
, special
, others
;
6930 OO
.ui
.MessageDialog
.super.prototype.attachActions
.call( this );
6932 special
= this.actions
.getSpecial();
6933 others
= this.actions
.getOthers();
6934 if ( special
.safe
) {
6935 this.$actions
.append( special
.safe
.$element
);
6936 special
.safe
.toggleFramed( false );
6938 if ( others
.length
) {
6939 for ( i
= 0, len
= others
.length
; i
< len
; i
++ ) {
6940 other
= others
[ i
];
6941 this.$actions
.append( other
.$element
);
6942 other
.toggleFramed( false );
6945 if ( special
.primary
) {
6946 this.$actions
.append( special
.primary
.$element
);
6947 special
.primary
.toggleFramed( false );
6950 if ( !this.isOpening() ) {
6951 // If the dialog is currently opening, this will be called automatically soon.
6952 // This also calls #fitActions.
6958 * Fit action actions into columns or rows.
6960 * Columns will be used if all labels can fit without overflow, otherwise rows will be used.
6962 OO
.ui
.MessageDialog
.prototype.fitActions = function () {
6964 previous
= this.verticalActionLayout
,
6965 actions
= this.actions
.get();
6968 this.toggleVerticalActionLayout( false );
6969 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
6970 action
= actions
[ i
];
6971 if ( action
.$element
.innerWidth() < action
.$label
.outerWidth( true ) ) {
6972 this.toggleVerticalActionLayout( true );
6977 if ( this.verticalActionLayout
!== previous
) {
6978 this.$body
.css( 'bottom', this.$foot
.outerHeight( true ) );
6979 // We changed the layout, window height might need to be updated.
6985 * Navigation dialog window.
6988 * - Show and hide errors.
6989 * - Retry an action.
6992 * - Renders header with dialog title and one action widget on either side
6993 * (a 'safe' button on the left, and a 'primary' button on the right, both of
6994 * which close the dialog).
6995 * - Displays any action widgets in the footer (none by default).
6996 * - Ability to dismiss errors.
6998 * Subclass responsibilities:
6999 * - Register a 'safe' action.
7000 * - Register a 'primary' action.
7001 * - Add content to the dialog.
7005 * @extends OO.ui.Dialog
7008 * @param {Object} [config] Configuration options
7010 OO
.ui
.ProcessDialog
= function OoUiProcessDialog( config
) {
7011 // Parent constructor
7012 OO
.ui
.ProcessDialog
.super.call( this, config
);
7015 this.$element
.addClass( 'oo-ui-processDialog' );
7020 OO
.inheritClass( OO
.ui
.ProcessDialog
, OO
.ui
.Dialog
);
7025 * Handle dismiss button click events.
7029 OO
.ui
.ProcessDialog
.prototype.onDismissErrorButtonClick = function () {
7034 * Handle retry button click events.
7036 * Hides errors and then tries again.
7038 OO
.ui
.ProcessDialog
.prototype.onRetryButtonClick = function () {
7040 this.executeAction( this.currentAction
.getAction() );
7046 OO
.ui
.ProcessDialog
.prototype.onActionResize = function ( action
) {
7047 if ( this.actions
.isSpecial( action
) ) {
7050 return OO
.ui
.ProcessDialog
.super.prototype.onActionResize
.call( this, action
);
7056 OO
.ui
.ProcessDialog
.prototype.initialize = function () {
7058 OO
.ui
.ProcessDialog
.super.prototype.initialize
.call( this );
7061 this.$navigation
= this.$( '<div>' );
7062 this.$location
= this.$( '<div>' );
7063 this.$safeActions
= this.$( '<div>' );
7064 this.$primaryActions
= this.$( '<div>' );
7065 this.$otherActions
= this.$( '<div>' );
7066 this.dismissButton
= new OO
.ui
.ButtonWidget( {
7068 label
: OO
.ui
.msg( 'ooui-dialog-process-dismiss' )
7070 this.retryButton
= new OO
.ui
.ButtonWidget( { $: this.$ } );
7071 this.$errors
= this.$( '<div>' );
7072 this.$errorsTitle
= this.$( '<div>' );
7075 this.dismissButton
.connect( this, { click
: 'onDismissErrorButtonClick' } );
7076 this.retryButton
.connect( this, { click
: 'onRetryButtonClick' } );
7079 this.title
.$element
.addClass( 'oo-ui-processDialog-title' );
7081 .append( this.title
.$element
)
7082 .addClass( 'oo-ui-processDialog-location' );
7083 this.$safeActions
.addClass( 'oo-ui-processDialog-actions-safe' );
7084 this.$primaryActions
.addClass( 'oo-ui-processDialog-actions-primary' );
7085 this.$otherActions
.addClass( 'oo-ui-processDialog-actions-other' );
7087 .addClass( 'oo-ui-processDialog-errors-title' )
7088 .text( OO
.ui
.msg( 'ooui-dialog-process-error' ) );
7090 .addClass( 'oo-ui-processDialog-errors' )
7091 .append( this.$errorsTitle
, this.dismissButton
.$element
, this.retryButton
.$element
);
7093 .addClass( 'oo-ui-processDialog-content' )
7094 .append( this.$errors
);
7096 .addClass( 'oo-ui-processDialog-navigation' )
7097 .append( this.$safeActions
, this.$location
, this.$primaryActions
);
7098 this.$head
.append( this.$navigation
);
7099 this.$foot
.append( this.$otherActions
);
7105 OO
.ui
.ProcessDialog
.prototype.attachActions = function () {
7106 var i
, len
, other
, special
, others
;
7109 OO
.ui
.ProcessDialog
.super.prototype.attachActions
.call( this );
7111 special
= this.actions
.getSpecial();
7112 others
= this.actions
.getOthers();
7113 if ( special
.primary
) {
7114 this.$primaryActions
.append( special
.primary
.$element
);
7115 special
.primary
.toggleFramed( true );
7117 if ( others
.length
) {
7118 for ( i
= 0, len
= others
.length
; i
< len
; i
++ ) {
7119 other
= others
[ i
];
7120 this.$otherActions
.append( other
.$element
);
7121 other
.toggleFramed( true );
7124 if ( special
.safe
) {
7125 this.$safeActions
.append( special
.safe
.$element
);
7126 special
.safe
.toggleFramed( true );
7130 this.$body
.css( 'bottom', this.$foot
.outerHeight( true ) );
7136 OO
.ui
.ProcessDialog
.prototype.executeAction = function ( action
) {
7137 OO
.ui
.ProcessDialog
.super.prototype.executeAction
.call( this, action
)
7138 .fail( this.showErrors
.bind( this ) );
7142 * Fit label between actions.
7146 OO
.ui
.ProcessDialog
.prototype.fitLabel = function () {
7147 var width
= Math
.max(
7148 this.$safeActions
.is( ':visible' ) ? this.$safeActions
.width() : 0,
7149 this.$primaryActions
.is( ':visible' ) ? this.$primaryActions
.width() : 0
7151 this.$location
.css( { paddingLeft
: width
, paddingRight
: width
} );
7157 * Handle errors that occurred during accept or reject processes.
7159 * @param {OO.ui.Error[]} errors Errors to be handled
7161 OO
.ui
.ProcessDialog
.prototype.showErrors = function ( errors
) {
7167 for ( i
= 0, len
= errors
.length
; i
< len
; i
++ ) {
7168 if ( !errors
[ i
].isRecoverable() ) {
7169 recoverable
= false;
7171 if ( errors
[ i
].isWarning() ) {
7174 $item
= this.$( '<div>' )
7175 .addClass( 'oo-ui-processDialog-error' )
7176 .append( errors
[ i
].getMessage() );
7177 items
.push( $item
[ 0 ] );
7179 this.$errorItems
= this.$( items
);
7180 if ( recoverable
) {
7181 this.retryButton
.clearFlags().setFlags( this.currentAction
.getFlags() );
7183 this.currentAction
.setDisabled( true );
7186 this.retryButton
.setLabel( OO
.ui
.msg( 'ooui-dialog-process-continue' ) );
7188 this.retryButton
.setLabel( OO
.ui
.msg( 'ooui-dialog-process-retry' ) );
7190 this.retryButton
.toggle( recoverable
);
7191 this.$errorsTitle
.after( this.$errorItems
);
7192 this.$errors
.show().scrollTop( 0 );
7198 OO
.ui
.ProcessDialog
.prototype.hideErrors = function () {
7199 this.$errors
.hide();
7200 this.$errorItems
.remove();
7201 this.$errorItems
= null;
7205 * Layout made of a field and optional label.
7207 * Available label alignment modes include:
7208 * - left: Label is before the field and aligned away from it, best for when the user will be
7209 * scanning for a specific label in a form with many fields
7210 * - right: Label is before the field and aligned toward it, best for forms the user is very
7211 * familiar with and will tab through field checking quickly to verify which field they are in
7212 * - top: Label is before the field and above it, best for when the user will need to fill out all
7213 * fields from top to bottom in a form with few fields
7214 * - inline: Label is after the field and aligned toward it, best for small boolean fields like
7215 * checkboxes or radio buttons
7218 * @extends OO.ui.Layout
7219 * @mixins OO.ui.LabelElement
7222 * @param {OO.ui.Widget} fieldWidget Field widget
7223 * @param {Object} [config] Configuration options
7224 * @cfg {string} [align='left'] Alignment mode, either 'left', 'right', 'top' or 'inline'
7225 * @cfg {string} [help] Explanatory text shown as a '?' icon.
7227 OO
.ui
.FieldLayout
= function OoUiFieldLayout( fieldWidget
, config
) {
7228 var hasInputWidget
= fieldWidget
instanceof OO
.ui
.InputWidget
;
7230 // Configuration initialization
7231 config
= $.extend( { align
: 'left' }, config
);
7233 // Properties (must be set before parent constructor, which calls #getTagName)
7234 this.fieldWidget
= fieldWidget
;
7236 // Parent constructor
7237 OO
.ui
.FieldLayout
.super.call( this, config
);
7239 // Mixin constructors
7240 OO
.ui
.LabelElement
.call( this, config
);
7243 this.$field
= this.$( '<div>' );
7244 this.$body
= this.$( '<' + ( hasInputWidget
? 'label' : 'div' ) + '>' );
7246 if ( config
.help
) {
7247 this.popupButtonWidget
= new OO
.ui
.PopupButtonWidget( {
7249 classes
: [ 'oo-ui-fieldLayout-help' ],
7254 this.popupButtonWidget
.getPopup().$body
.append(
7256 .text( config
.help
)
7257 .addClass( 'oo-ui-fieldLayout-help-content' )
7259 this.$help
= this.popupButtonWidget
.$element
;
7261 this.$help
= this.$( [] );
7265 if ( hasInputWidget
) {
7266 this.$label
.on( 'click', this.onLabelClick
.bind( this ) );
7268 this.fieldWidget
.connect( this, { disable
: 'onFieldDisable' } );
7272 .addClass( 'oo-ui-fieldLayout' )
7273 .append( this.$help
, this.$body
);
7274 this.$body
.addClass( 'oo-ui-fieldLayout-body' );
7276 .addClass( 'oo-ui-fieldLayout-field' )
7277 .toggleClass( 'oo-ui-fieldLayout-disable', this.fieldWidget
.isDisabled() )
7278 .append( this.fieldWidget
.$element
);
7280 this.setAlignment( config
.align
);
7285 OO
.inheritClass( OO
.ui
.FieldLayout
, OO
.ui
.Layout
);
7286 OO
.mixinClass( OO
.ui
.FieldLayout
, OO
.ui
.LabelElement
);
7291 * Handle field disable events.
7293 * @param {boolean} value Field is disabled
7295 OO
.ui
.FieldLayout
.prototype.onFieldDisable = function ( value
) {
7296 this.$element
.toggleClass( 'oo-ui-fieldLayout-disabled', value
);
7300 * Handle label mouse click events.
7302 * @param {jQuery.Event} e Mouse click event
7304 OO
.ui
.FieldLayout
.prototype.onLabelClick = function () {
7305 this.fieldWidget
.simulateLabelClick();
7312 * @return {OO.ui.Widget} Field widget
7314 OO
.ui
.FieldLayout
.prototype.getField = function () {
7315 return this.fieldWidget
;
7319 * Set the field alignment mode.
7322 * @param {string} value Alignment mode, either 'left', 'right', 'top' or 'inline'
7325 OO
.ui
.FieldLayout
.prototype.setAlignment = function ( value
) {
7326 if ( value
!== this.align
) {
7327 // Default to 'left'
7328 if ( [ 'left', 'right', 'top', 'inline' ].indexOf( value
) === -1 ) {
7332 if ( value
=== 'inline' ) {
7333 this.$body
.append( this.$field
, this.$label
);
7335 this.$body
.append( this.$label
, this.$field
);
7337 // Set classes. The following classes can be used here:
7338 // * oo-ui-fieldLayout-align-left
7339 // * oo-ui-fieldLayout-align-right
7340 // * oo-ui-fieldLayout-align-top
7341 // * oo-ui-fieldLayout-align-inline
7343 this.$element
.removeClass( 'oo-ui-fieldLayout-align-' + this.align
);
7345 this.$element
.addClass( 'oo-ui-fieldLayout-align-' + value
);
7353 * Layout made of a field, a button, and an optional label.
7356 * @extends OO.ui.FieldLayout
7359 * @param {OO.ui.Widget} fieldWidget Field widget
7360 * @param {OO.ui.ButtonWidget} buttonWidget Button widget
7361 * @param {Object} [config] Configuration options
7362 * @cfg {string} [align='left'] Alignment mode, either 'left', 'right', 'top' or 'inline'
7363 * @cfg {string} [help] Explanatory text shown as a '?' icon.
7365 OO
.ui
.ActionFieldLayout
= function OoUiActionFieldLayout( fieldWidget
, buttonWidget
, config
) {
7366 // Configuration initialization
7367 config
= $.extend( { align
: 'left' }, config
);
7369 // Properties (must be set before parent constructor, which calls #getTagName)
7370 this.fieldWidget
= fieldWidget
;
7371 this.buttonWidget
= buttonWidget
;
7373 // Parent constructor
7374 OO
.ui
.ActionFieldLayout
.super.call( this, fieldWidget
, config
);
7376 // Mixin constructors
7377 OO
.ui
.LabelElement
.call( this, config
);
7380 this.$button
= this.$( '<div>' )
7381 .addClass( 'oo-ui-actionFieldLayout-button' )
7382 .append( this.buttonWidget
.$element
);
7384 this.$input
= this.$( '<div>' )
7385 .addClass( 'oo-ui-actionFieldLayout-input' )
7386 .append( this.fieldWidget
.$element
);
7389 .addClass( 'oo-ui-actionFieldLayout' )
7390 .append( this.$input
, this.$button
);
7395 OO
.inheritClass( OO
.ui
.ActionFieldLayout
, OO
.ui
.FieldLayout
);
7398 * Layout made of a fieldset and optional legend.
7400 * Just add OO.ui.FieldLayout items.
7403 * @extends OO.ui.Layout
7404 * @mixins OO.ui.IconElement
7405 * @mixins OO.ui.LabelElement
7406 * @mixins OO.ui.GroupElement
7409 * @param {Object} [config] Configuration options
7410 * @cfg {OO.ui.FieldLayout[]} [items] Items to add
7412 OO
.ui
.FieldsetLayout
= function OoUiFieldsetLayout( config
) {
7413 // Configuration initialization
7414 config
= config
|| {};
7416 // Parent constructor
7417 OO
.ui
.FieldsetLayout
.super.call( this, config
);
7419 // Mixin constructors
7420 OO
.ui
.IconElement
.call( this, config
);
7421 OO
.ui
.LabelElement
.call( this, config
);
7422 OO
.ui
.GroupElement
.call( this, config
);
7424 if ( config
.help
) {
7425 this.popupButtonWidget
= new OO
.ui
.PopupButtonWidget( {
7427 classes
: [ 'oo-ui-fieldsetLayout-help' ],
7432 this.popupButtonWidget
.getPopup().$body
.append(
7434 .text( config
.help
)
7435 .addClass( 'oo-ui-fieldsetLayout-help-content' )
7437 this.$help
= this.popupButtonWidget
.$element
;
7439 this.$help
= this.$( [] );
7444 .addClass( 'oo-ui-fieldsetLayout' )
7445 .prepend( this.$help
, this.$icon
, this.$label
, this.$group
);
7446 if ( $.isArray( config
.items
) ) {
7447 this.addItems( config
.items
);
7453 OO
.inheritClass( OO
.ui
.FieldsetLayout
, OO
.ui
.Layout
);
7454 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.IconElement
);
7455 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.LabelElement
);
7456 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.GroupElement
);
7459 * Layout with an HTML form.
7462 * @extends OO.ui.Layout
7465 * @param {Object} [config] Configuration options
7466 * @cfg {string} [method] HTML form `method` attribute
7467 * @cfg {string} [action] HTML form `action` attribute
7468 * @cfg {string} [enctype] HTML form `enctype` attribute
7470 OO
.ui
.FormLayout
= function OoUiFormLayout( config
) {
7471 // Configuration initialization
7472 config
= config
|| {};
7474 // Parent constructor
7475 OO
.ui
.FormLayout
.super.call( this, config
);
7478 this.$element
.on( 'submit', this.onFormSubmit
.bind( this ) );
7482 .addClass( 'oo-ui-formLayout' )
7484 method
: config
.method
,
7485 action
: config
.action
,
7486 enctype
: config
.enctype
7492 OO
.inheritClass( OO
.ui
.FormLayout
, OO
.ui
.Layout
);
7500 /* Static Properties */
7502 OO
.ui
.FormLayout
.static.tagName
= 'form';
7507 * Handle form submit events.
7509 * @param {jQuery.Event} e Submit event
7512 OO
.ui
.FormLayout
.prototype.onFormSubmit = function () {
7513 this.emit( 'submit' );
7518 * Layout made of proportionally sized columns and rows.
7521 * @extends OO.ui.Layout
7524 * @param {OO.ui.PanelLayout[]} panels Panels in the grid
7525 * @param {Object} [config] Configuration options
7526 * @cfg {number[]} [widths] Widths of columns as ratios
7527 * @cfg {number[]} [heights] Heights of rows as ratios
7529 OO
.ui
.GridLayout
= function OoUiGridLayout( panels
, config
) {
7532 // Configuration initialization
7533 config
= config
|| {};
7535 // Parent constructor
7536 OO
.ui
.GridLayout
.super.call( this, config
);
7544 this.$element
.addClass( 'oo-ui-gridLayout' );
7545 for ( i
= 0, len
= panels
.length
; i
< len
; i
++ ) {
7546 this.panels
.push( panels
[ i
] );
7547 this.$element
.append( panels
[ i
].$element
);
7549 if ( config
.widths
|| config
.heights
) {
7550 this.layout( config
.widths
|| [ 1 ], config
.heights
|| [ 1 ] );
7552 // Arrange in columns by default
7553 widths
= this.panels
.map( function () { return 1; } );
7554 this.layout( widths
, [ 1 ] );
7560 OO
.inheritClass( OO
.ui
.GridLayout
, OO
.ui
.Layout
);
7575 * Set grid dimensions.
7577 * @param {number[]} widths Widths of columns as ratios
7578 * @param {number[]} heights Heights of rows as ratios
7580 * @throws {Error} If grid is not large enough to fit all panels
7582 OO
.ui
.GridLayout
.prototype.layout = function ( widths
, heights
) {
7586 cols
= widths
.length
,
7587 rows
= heights
.length
;
7589 // Verify grid is big enough to fit panels
7590 if ( cols
* rows
< this.panels
.length
) {
7591 throw new Error( 'Grid is not large enough to fit ' + this.panels
.length
+ 'panels' );
7594 // Sum up denominators
7595 for ( x
= 0; x
< cols
; x
++ ) {
7598 for ( y
= 0; y
< rows
; y
++ ) {
7604 for ( x
= 0; x
< cols
; x
++ ) {
7605 this.widths
[ x
] = widths
[ x
] / xd
;
7607 for ( y
= 0; y
< rows
; y
++ ) {
7608 this.heights
[ y
] = heights
[ y
] / yd
;
7612 this.emit( 'layout' );
7616 * Update panel positions and sizes.
7620 OO
.ui
.GridLayout
.prototype.update = function () {
7621 var x
, y
, panel
, width
, height
, dimensions
,
7625 cols
= this.widths
.length
,
7626 rows
= this.heights
.length
;
7628 for ( y
= 0; y
< rows
; y
++ ) {
7629 height
= this.heights
[ y
];
7630 for ( x
= 0; x
< cols
; x
++ ) {
7631 width
= this.widths
[ x
];
7632 panel
= this.panels
[ i
];
7634 width
: ( width
* 100 ) + '%',
7635 height
: ( height
* 100 ) + '%',
7636 top
: ( top
* 100 ) + '%'
7639 if ( OO
.ui
.Element
.static.getDir( this.$.context
) === 'rtl' ) {
7640 dimensions
.right
= ( left
* 100 ) + '%';
7642 dimensions
.left
= ( left
* 100 ) + '%';
7644 // HACK: Work around IE bug by setting visibility: hidden; if width or height is zero
7645 if ( width
=== 0 || height
=== 0 ) {
7646 dimensions
.visibility
= 'hidden';
7648 dimensions
.visibility
= '';
7650 panel
.$element
.css( dimensions
);
7658 this.emit( 'update' );
7662 * Get a panel at a given position.
7664 * The x and y position is affected by the current grid layout.
7666 * @param {number} x Horizontal position
7667 * @param {number} y Vertical position
7668 * @return {OO.ui.PanelLayout} The panel at the given position
7670 OO
.ui
.GridLayout
.prototype.getPanel = function ( x
, y
) {
7671 return this.panels
[ ( x
* this.widths
.length
) + y
];
7675 * Layout with a content and menu area.
7677 * The menu area can be positioned at the top, after, bottom or before. The content area will fill
7678 * all remaining space.
7681 * @extends OO.ui.Layout
7684 * @param {Object} [config] Configuration options
7685 * @cfg {number|string} [menuSize='18em'] Size of menu in pixels or any CSS unit
7686 * @cfg {boolean} [showMenu=true] Show menu
7687 * @cfg {string} [position='before'] Position of menu, either `top`, `after`, `bottom` or `before`
7688 * @cfg {boolean} [collapse] Collapse the menu out of view
7690 OO
.ui
.MenuLayout
= function OoUiMenuLayout( config
) {
7691 var positions
= this.constructor.static.menuPositions
;
7693 // Configuration initialization
7694 config
= config
|| {};
7696 // Parent constructor
7697 OO
.ui
.MenuLayout
.super.call( this, config
);
7700 this.showMenu
= config
.showMenu
!== false;
7701 this.menuSize
= config
.menuSize
|| '18em';
7702 this.menuPosition
= positions
[ config
.menuPosition
] || positions
.before
;
7707 * @property {jQuery}
7709 this.$menu
= this.$( '<div>' );
7713 * @property {jQuery}
7715 this.$content
= this.$( '<div>' );
7718 this.$element
.on( 'DOMNodeInsertedIntoDocument', this.onElementAttach
.bind( this ) );
7721 this.toggleMenu( this.showMenu
);
7723 .addClass( 'oo-ui-menuLayout-menu' )
7724 .css( this.menuPosition
.sizeProperty
, this.menuSize
);
7725 this.$content
.addClass( 'oo-ui-menuLayout-content' );
7727 .addClass( 'oo-ui-menuLayout ' + this.menuPosition
.className
)
7728 .append( this.$content
, this.$menu
);
7733 OO
.inheritClass( OO
.ui
.MenuLayout
, OO
.ui
.Layout
);
7735 /* Static Properties */
7737 OO
.ui
.MenuLayout
.static.menuPositions
= {
7739 sizeProperty
: 'height',
7740 positionProperty
: 'top',
7741 className
: 'oo-ui-menuLayout-top'
7744 sizeProperty
: 'width',
7745 positionProperty
: 'right',
7746 rtlPositionProperty
: 'left',
7747 className
: 'oo-ui-menuLayout-after'
7750 sizeProperty
: 'height',
7751 positionProperty
: 'bottom',
7752 className
: 'oo-ui-menuLayout-bottom'
7755 sizeProperty
: 'width',
7756 positionProperty
: 'left',
7757 rtlPositionProperty
: 'right',
7758 className
: 'oo-ui-menuLayout-before'
7765 * Handle DOM attachment events
7767 OO
.ui
.MenuLayout
.prototype.onElementAttach = function () {
7768 // getPositionProperty won't know about directionality until the layout is attached
7769 if ( this.showMenu
) {
7770 this.$content
.css( this.getPositionProperty(), this.menuSize
);
7777 * @param {boolean} showMenu Show menu, omit to toggle
7780 OO
.ui
.MenuLayout
.prototype.toggleMenu = function ( showMenu
) {
7781 showMenu
= showMenu
=== undefined ? !this.showMenu
: !!showMenu
;
7783 if ( this.showMenu
!== showMenu
) {
7784 this.showMenu
= showMenu
;
7792 * Check if menu is visible
7794 * @return {boolean} Menu is visible
7796 OO
.ui
.MenuLayout
.prototype.isMenuVisible = function () {
7797 return this.showMenu
;
7803 * @param {number|string} size Size of menu in pixels or any CSS unit
7806 OO
.ui
.MenuLayout
.prototype.setMenuSize = function ( size
) {
7807 this.menuSize
= size
;
7814 * Update menu and content CSS based on current menu size and visibility
7816 OO
.ui
.MenuLayout
.prototype.updateSizes = function () {
7817 if ( this.showMenu
) {
7819 .css( this.menuPosition
.sizeProperty
, this.menuSize
)
7820 .css( 'overflow', '' );
7821 this.$content
.css( this.getPositionProperty(), this.menuSize
);
7824 .css( this.menuPosition
.sizeProperty
, 0 )
7825 .css( 'overflow', 'hidden' );
7826 this.$content
.css( this.getPositionProperty(), 0 );
7833 * @return {number|string} Menu size
7835 OO
.ui
.MenuLayout
.prototype.getMenuSize = function () {
7836 return this.menuSize
;
7840 * Set menu position.
7842 * @param {string} position Position of menu, either `top`, `after`, `bottom` or `before`
7843 * @throws {Error} If position value is not supported
7846 OO
.ui
.MenuLayout
.prototype.setMenuPosition = function ( position
) {
7847 var positionProperty
, positions
= this.constructor.static.menuPositions
;
7849 if ( !positions
[ position
] ) {
7850 throw new Error( 'Cannot set position; unsupported position value: ' + position
);
7853 positionProperty
= this.getPositionProperty();
7854 this.$menu
.css( this.menuPosition
.sizeProperty
, '' );
7855 this.$content
.css( positionProperty
, '' );
7856 this.$element
.removeClass( this.menuPosition
.className
);
7858 this.menuPosition
= positions
[ position
];
7861 this.$element
.addClass( this.menuPosition
.className
);
7867 * Get menu position.
7869 * @return {string} Menu position
7871 OO
.ui
.MenuLayout
.prototype.getMenuPosition = function () {
7872 return this.menuPosition
;
7876 * Get the menu position property.
7878 * @return {string} Menu position CSS property
7880 OO
.ui
.MenuLayout
.prototype.getPositionProperty = function () {
7881 if ( this.menuPosition
.rtlPositionProperty
&& this.$element
.css( 'direction' ) === 'rtl' ) {
7882 return this.menuPosition
.rtlPositionProperty
;
7884 return this.menuPosition
.positionProperty
;
7889 * Layout containing a series of pages.
7892 * @extends OO.ui.MenuLayout
7895 * @param {Object} [config] Configuration options
7896 * @cfg {boolean} [continuous=false] Show all pages, one after another
7897 * @cfg {boolean} [autoFocus=true] Focus on the first focusable element when changing to a page
7898 * @cfg {boolean} [outlined=false] Show an outline
7899 * @cfg {boolean} [editable=false] Show controls for adding, removing and reordering pages
7901 OO
.ui
.BookletLayout
= function OoUiBookletLayout( config
) {
7902 // Configuration initialization
7903 config
= config
|| {};
7905 // Parent constructor
7906 OO
.ui
.BookletLayout
.super.call( this, config
);
7909 this.currentPageName
= null;
7911 this.ignoreFocus
= false;
7912 this.stackLayout
= new OO
.ui
.StackLayout( { $: this.$, continuous
: !!config
.continuous
} );
7913 this.$content
.append( this.stackLayout
.$element
);
7914 this.autoFocus
= config
.autoFocus
=== undefined || !!config
.autoFocus
;
7915 this.outlineVisible
= false;
7916 this.outlined
= !!config
.outlined
;
7917 if ( this.outlined
) {
7918 this.editable
= !!config
.editable
;
7919 this.outlineControlsWidget
= null;
7920 this.outlineSelectWidget
= new OO
.ui
.OutlineSelectWidget( { $: this.$ } );
7921 this.outlinePanel
= new OO
.ui
.PanelLayout( { $: this.$, scrollable
: true } );
7922 this.$menu
.append( this.outlinePanel
.$element
);
7923 this.outlineVisible
= true;
7924 if ( this.editable
) {
7925 this.outlineControlsWidget
= new OO
.ui
.OutlineControlsWidget(
7926 this.outlineSelectWidget
, { $: this.$ }
7930 this.toggleMenu( this.outlined
);
7933 this.stackLayout
.connect( this, { set: 'onStackLayoutSet' } );
7934 if ( this.outlined
) {
7935 this.outlineSelectWidget
.connect( this, { select
: 'onOutlineSelectWidgetSelect' } );
7937 if ( this.autoFocus
) {
7938 // Event 'focus' does not bubble, but 'focusin' does
7939 this.stackLayout
.$element
.on( 'focusin', this.onStackLayoutFocus
.bind( this ) );
7943 this.$element
.addClass( 'oo-ui-bookletLayout' );
7944 this.stackLayout
.$element
.addClass( 'oo-ui-bookletLayout-stackLayout' );
7945 if ( this.outlined
) {
7946 this.outlinePanel
.$element
7947 .addClass( 'oo-ui-bookletLayout-outlinePanel' )
7948 .append( this.outlineSelectWidget
.$element
);
7949 if ( this.editable
) {
7950 this.outlinePanel
.$element
7951 .addClass( 'oo-ui-bookletLayout-outlinePanel-editable' )
7952 .append( this.outlineControlsWidget
.$element
);
7959 OO
.inheritClass( OO
.ui
.BookletLayout
, OO
.ui
.MenuLayout
);
7965 * @param {OO.ui.PageLayout} page Current page
7970 * @param {OO.ui.PageLayout[]} page Added pages
7971 * @param {number} index Index pages were added at
7976 * @param {OO.ui.PageLayout[]} pages Removed pages
7982 * Handle stack layout focus.
7984 * @param {jQuery.Event} e Focusin event
7986 OO
.ui
.BookletLayout
.prototype.onStackLayoutFocus = function ( e
) {
7989 // Find the page that an element was focused within
7990 $target
= $( e
.target
).closest( '.oo-ui-pageLayout' );
7991 for ( name
in this.pages
) {
7992 // Check for page match, exclude current page to find only page changes
7993 if ( this.pages
[ name
].$element
[ 0 ] === $target
[ 0 ] && name
!== this.currentPageName
) {
7994 this.setPage( name
);
8001 * Handle stack layout set events.
8003 * @param {OO.ui.PanelLayout|null} page The page panel that is now the current panel
8005 OO
.ui
.BookletLayout
.prototype.onStackLayoutSet = function ( page
) {
8008 page
.scrollElementIntoView( { complete: function () {
8009 if ( layout
.autoFocus
) {
8017 * Focus the first input in the current page.
8019 * If no page is selected, the first selectable page will be selected.
8020 * If the focus is already in an element on the current page, nothing will happen.
8022 OO
.ui
.BookletLayout
.prototype.focus = function () {
8023 var $input
, page
= this.stackLayout
.getCurrentItem();
8024 if ( !page
&& this.outlined
) {
8025 this.selectFirstSelectablePage();
8026 page
= this.stackLayout
.getCurrentItem();
8031 // Only change the focus if is not already in the current page
8032 if ( !page
.$element
.find( ':focus' ).length
) {
8033 $input
= page
.$element
.find( ':input:first' );
8034 if ( $input
.length
) {
8035 $input
[ 0 ].focus();
8041 * Handle outline widget select events.
8043 * @param {OO.ui.OptionWidget|null} item Selected item
8045 OO
.ui
.BookletLayout
.prototype.onOutlineSelectWidgetSelect = function ( item
) {
8047 this.setPage( item
.getData() );
8052 * Check if booklet has an outline.
8056 OO
.ui
.BookletLayout
.prototype.isOutlined = function () {
8057 return this.outlined
;
8061 * Check if booklet has editing controls.
8065 OO
.ui
.BookletLayout
.prototype.isEditable = function () {
8066 return this.editable
;
8070 * Check if booklet has a visible outline.
8074 OO
.ui
.BookletLayout
.prototype.isOutlineVisible = function () {
8075 return this.outlined
&& this.outlineVisible
;
8079 * Hide or show the outline.
8081 * @param {boolean} [show] Show outline, omit to invert current state
8084 OO
.ui
.BookletLayout
.prototype.toggleOutline = function ( show
) {
8085 if ( this.outlined
) {
8086 show
= show
=== undefined ? !this.outlineVisible
: !!show
;
8087 this.outlineVisible
= show
;
8088 this.gridLayout
.layout( show
? [ 1, 2 ] : [ 0, 1 ], [ 1 ] );
8095 * Get the outline widget.
8097 * @param {OO.ui.PageLayout} page Page to be selected
8098 * @return {OO.ui.PageLayout|null} Closest page to another
8100 OO
.ui
.BookletLayout
.prototype.getClosestPage = function ( page
) {
8101 var next
, prev
, level
,
8102 pages
= this.stackLayout
.getItems(),
8103 index
= $.inArray( page
, pages
);
8105 if ( index
!== -1 ) {
8106 next
= pages
[ index
+ 1 ];
8107 prev
= pages
[ index
- 1 ];
8108 // Prefer adjacent pages at the same level
8109 if ( this.outlined
) {
8110 level
= this.outlineSelectWidget
.getItemFromData( page
.getName() ).getLevel();
8113 level
=== this.outlineSelectWidget
.getItemFromData( prev
.getName() ).getLevel()
8119 level
=== this.outlineSelectWidget
.getItemFromData( next
.getName() ).getLevel()
8125 return prev
|| next
|| null;
8129 * Get the outline widget.
8131 * @return {OO.ui.OutlineSelectWidget|null} Outline widget, or null if booklet has no outline
8133 OO
.ui
.BookletLayout
.prototype.getOutline = function () {
8134 return this.outlineSelectWidget
;
8138 * Get the outline controls widget. If the outline is not editable, null is returned.
8140 * @return {OO.ui.OutlineControlsWidget|null} The outline controls widget.
8142 OO
.ui
.BookletLayout
.prototype.getOutlineControls = function () {
8143 return this.outlineControlsWidget
;
8147 * Get a page by name.
8149 * @param {string} name Symbolic name of page
8150 * @return {OO.ui.PageLayout|undefined} Page, if found
8152 OO
.ui
.BookletLayout
.prototype.getPage = function ( name
) {
8153 return this.pages
[ name
];
8157 * Get the current page
8159 * @return {OO.ui.PageLayout|undefined} Current page, if found
8161 OO
.ui
.BookletLayout
.prototype.getCurrentPage = function () {
8162 var name
= this.getCurrentPageName();
8163 return name
? this.getPage( name
) : undefined;
8167 * Get the current page name.
8169 * @return {string|null} Current page name
8171 OO
.ui
.BookletLayout
.prototype.getCurrentPageName = function () {
8172 return this.currentPageName
;
8176 * Add a page to the layout.
8178 * When pages are added with the same names as existing pages, the existing pages will be
8179 * automatically removed before the new pages are added.
8181 * @param {OO.ui.PageLayout[]} pages Pages to add
8182 * @param {number} index Index to insert pages after
8186 OO
.ui
.BookletLayout
.prototype.addPages = function ( pages
, index
) {
8187 var i
, len
, name
, page
, item
, currentIndex
,
8188 stackLayoutPages
= this.stackLayout
.getItems(),
8192 // Remove pages with same names
8193 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
8195 name
= page
.getName();
8197 if ( Object
.prototype.hasOwnProperty
.call( this.pages
, name
) ) {
8198 // Correct the insertion index
8199 currentIndex
= $.inArray( this.pages
[ name
], stackLayoutPages
);
8200 if ( currentIndex
!== -1 && currentIndex
+ 1 < index
) {
8203 remove
.push( this.pages
[ name
] );
8206 if ( remove
.length
) {
8207 this.removePages( remove
);
8211 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
8213 name
= page
.getName();
8214 this.pages
[ page
.getName() ] = page
;
8215 if ( this.outlined
) {
8216 item
= new OO
.ui
.OutlineOptionWidget( { $: this.$, data
: name
} );
8217 page
.setOutlineItem( item
);
8222 if ( this.outlined
&& items
.length
) {
8223 this.outlineSelectWidget
.addItems( items
, index
);
8224 this.selectFirstSelectablePage();
8226 this.stackLayout
.addItems( pages
, index
);
8227 this.emit( 'add', pages
, index
);
8233 * Remove a page from the layout.
8238 OO
.ui
.BookletLayout
.prototype.removePages = function ( pages
) {
8239 var i
, len
, name
, page
,
8242 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
8244 name
= page
.getName();
8245 delete this.pages
[ name
];
8246 if ( this.outlined
) {
8247 items
.push( this.outlineSelectWidget
.getItemFromData( name
) );
8248 page
.setOutlineItem( null );
8251 if ( this.outlined
&& items
.length
) {
8252 this.outlineSelectWidget
.removeItems( items
);
8253 this.selectFirstSelectablePage();
8255 this.stackLayout
.removeItems( pages
);
8256 this.emit( 'remove', pages
);
8262 * Clear all pages from the layout.
8267 OO
.ui
.BookletLayout
.prototype.clearPages = function () {
8269 pages
= this.stackLayout
.getItems();
8272 this.currentPageName
= null;
8273 if ( this.outlined
) {
8274 this.outlineSelectWidget
.clearItems();
8275 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
8276 pages
[ i
].setOutlineItem( null );
8279 this.stackLayout
.clearItems();
8281 this.emit( 'remove', pages
);
8287 * Set the current page by name.
8290 * @param {string} name Symbolic name of page
8292 OO
.ui
.BookletLayout
.prototype.setPage = function ( name
) {
8295 page
= this.pages
[ name
];
8297 if ( name
!== this.currentPageName
) {
8298 if ( this.outlined
) {
8299 selectedItem
= this.outlineSelectWidget
.getSelectedItem();
8300 if ( selectedItem
&& selectedItem
.getData() !== name
) {
8301 this.outlineSelectWidget
.selectItem( this.outlineSelectWidget
.getItemFromData( name
) );
8305 if ( this.currentPageName
&& this.pages
[ this.currentPageName
] ) {
8306 this.pages
[ this.currentPageName
].setActive( false );
8307 // Blur anything focused if the next page doesn't have anything focusable - this
8308 // is not needed if the next page has something focusable because once it is focused
8309 // this blur happens automatically
8310 if ( this.autoFocus
&& !page
.$element
.find( ':input' ).length
) {
8311 $focused
= this.pages
[ this.currentPageName
].$element
.find( ':focus' );
8312 if ( $focused
.length
) {
8313 $focused
[ 0 ].blur();
8317 this.currentPageName
= name
;
8318 this.stackLayout
.setItem( page
);
8319 page
.setActive( true );
8320 this.emit( 'set', page
);
8326 * Select the first selectable page.
8330 OO
.ui
.BookletLayout
.prototype.selectFirstSelectablePage = function () {
8331 if ( !this.outlineSelectWidget
.getSelectedItem() ) {
8332 this.outlineSelectWidget
.selectItem( this.outlineSelectWidget
.getFirstSelectableItem() );
8339 * Layout that expands to cover the entire area of its parent, with optional scrolling and padding.
8342 * @extends OO.ui.Layout
8345 * @param {Object} [config] Configuration options
8346 * @cfg {boolean} [scrollable=false] Allow vertical scrolling
8347 * @cfg {boolean} [padded=false] Pad the content from the edges
8348 * @cfg {boolean} [expanded=true] Expand size to fill the entire parent element
8350 OO
.ui
.PanelLayout
= function OoUiPanelLayout( config
) {
8351 // Configuration initialization
8352 config
= $.extend( {
8358 // Parent constructor
8359 OO
.ui
.PanelLayout
.super.call( this, config
);
8362 this.$element
.addClass( 'oo-ui-panelLayout' );
8363 if ( config
.scrollable
) {
8364 this.$element
.addClass( 'oo-ui-panelLayout-scrollable' );
8366 if ( config
.padded
) {
8367 this.$element
.addClass( 'oo-ui-panelLayout-padded' );
8369 if ( config
.expanded
) {
8370 this.$element
.addClass( 'oo-ui-panelLayout-expanded' );
8376 OO
.inheritClass( OO
.ui
.PanelLayout
, OO
.ui
.Layout
);
8379 * Page within an booklet layout.
8382 * @extends OO.ui.PanelLayout
8385 * @param {string} name Unique symbolic name of page
8386 * @param {Object} [config] Configuration options
8388 OO
.ui
.PageLayout
= function OoUiPageLayout( name
, config
) {
8389 // Configuration initialization
8390 config
= $.extend( { scrollable
: true }, config
);
8392 // Parent constructor
8393 OO
.ui
.PageLayout
.super.call( this, config
);
8397 this.outlineItem
= null;
8398 this.active
= false;
8401 this.$element
.addClass( 'oo-ui-pageLayout' );
8406 OO
.inheritClass( OO
.ui
.PageLayout
, OO
.ui
.PanelLayout
);
8412 * @param {boolean} active Page is active
8420 * @return {string} Symbolic name of page
8422 OO
.ui
.PageLayout
.prototype.getName = function () {
8427 * Check if page is active.
8429 * @return {boolean} Page is active
8431 OO
.ui
.PageLayout
.prototype.isActive = function () {
8438 * @return {OO.ui.OutlineOptionWidget|null} Outline item widget
8440 OO
.ui
.PageLayout
.prototype.getOutlineItem = function () {
8441 return this.outlineItem
;
8447 * @localdoc Subclasses should override #setupOutlineItem instead of this method to adjust the
8448 * outline item as desired; this method is called for setting (with an object) and unsetting
8449 * (with null) and overriding methods would have to check the value of `outlineItem` to avoid
8450 * operating on null instead of an OO.ui.OutlineOptionWidget object.
8452 * @param {OO.ui.OutlineOptionWidget|null} outlineItem Outline item widget, null to clear
8455 OO
.ui
.PageLayout
.prototype.setOutlineItem = function ( outlineItem
) {
8456 this.outlineItem
= outlineItem
|| null;
8457 if ( outlineItem
) {
8458 this.setupOutlineItem();
8464 * Setup outline item.
8466 * @localdoc Subclasses should override this method to adjust the outline item as desired.
8468 * @param {OO.ui.OutlineOptionWidget} outlineItem Outline item widget to setup
8471 OO
.ui
.PageLayout
.prototype.setupOutlineItem = function () {
8476 * Set page active state.
8478 * @param {boolean} Page is active
8481 OO
.ui
.PageLayout
.prototype.setActive = function ( active
) {
8484 if ( active
!== this.active
) {
8485 this.active
= active
;
8486 this.$element
.toggleClass( 'oo-ui-pageLayout-active', active
);
8487 this.emit( 'active', this.active
);
8492 * Layout containing a series of mutually exclusive pages.
8495 * @extends OO.ui.PanelLayout
8496 * @mixins OO.ui.GroupElement
8499 * @param {Object} [config] Configuration options
8500 * @cfg {boolean} [continuous=false] Show all pages, one after another
8501 * @cfg {OO.ui.Layout[]} [items] Layouts to add
8503 OO
.ui
.StackLayout
= function OoUiStackLayout( config
) {
8504 // Configuration initialization
8505 config
= $.extend( { scrollable
: true }, config
);
8507 // Parent constructor
8508 OO
.ui
.StackLayout
.super.call( this, config
);
8510 // Mixin constructors
8511 OO
.ui
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
8514 this.currentItem
= null;
8515 this.continuous
= !!config
.continuous
;
8518 this.$element
.addClass( 'oo-ui-stackLayout' );
8519 if ( this.continuous
) {
8520 this.$element
.addClass( 'oo-ui-stackLayout-continuous' );
8522 if ( $.isArray( config
.items
) ) {
8523 this.addItems( config
.items
);
8529 OO
.inheritClass( OO
.ui
.StackLayout
, OO
.ui
.PanelLayout
);
8530 OO
.mixinClass( OO
.ui
.StackLayout
, OO
.ui
.GroupElement
);
8536 * @param {OO.ui.Layout|null} item Current item or null if there is no longer a layout shown
8542 * Get the current item.
8544 * @return {OO.ui.Layout|null}
8546 OO
.ui
.StackLayout
.prototype.getCurrentItem = function () {
8547 return this.currentItem
;
8551 * Unset the current item.
8554 * @param {OO.ui.StackLayout} layout
8557 OO
.ui
.StackLayout
.prototype.unsetCurrentItem = function () {
8558 var prevItem
= this.currentItem
;
8559 if ( prevItem
=== null ) {
8563 this.currentItem
= null;
8564 this.emit( 'set', null );
8570 * Adding an existing item (by value) will move it.
8572 * @param {OO.ui.Layout[]} items Items to add
8573 * @param {number} [index] Index to insert items after
8576 OO
.ui
.StackLayout
.prototype.addItems = function ( items
, index
) {
8578 OO
.ui
.GroupElement
.prototype.addItems
.call( this, items
, index
);
8580 if ( !this.currentItem
&& items
.length
) {
8581 this.setItem( items
[ 0 ] );
8590 * Items will be detached, not removed, so they can be used later.
8592 * @param {OO.ui.Layout[]} items Items to remove
8596 OO
.ui
.StackLayout
.prototype.removeItems = function ( items
) {
8598 OO
.ui
.GroupElement
.prototype.removeItems
.call( this, items
);
8600 if ( $.inArray( this.currentItem
, items
) !== -1 ) {
8601 if ( this.items
.length
) {
8602 this.setItem( this.items
[ 0 ] );
8604 this.unsetCurrentItem();
8614 * Items will be detached, not removed, so they can be used later.
8619 OO
.ui
.StackLayout
.prototype.clearItems = function () {
8620 this.unsetCurrentItem();
8621 OO
.ui
.GroupElement
.prototype.clearItems
.call( this );
8629 * Any currently shown item will be hidden.
8631 * FIXME: If the passed item to show has not been added in the items list, then
8632 * this method drops it and unsets the current item.
8634 * @param {OO.ui.Layout} item Item to show
8638 OO
.ui
.StackLayout
.prototype.setItem = function ( item
) {
8641 if ( item
!== this.currentItem
) {
8642 if ( !this.continuous
) {
8643 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
8644 this.items
[ i
].$element
.css( 'display', '' );
8647 if ( $.inArray( item
, this.items
) !== -1 ) {
8648 if ( !this.continuous
) {
8649 item
.$element
.css( 'display', 'block' );
8651 this.currentItem
= item
;
8652 this.emit( 'set', item
);
8654 this.unsetCurrentItem();
8662 * Horizontal bar layout of tools as icon buttons.
8665 * @extends OO.ui.ToolGroup
8668 * @param {OO.ui.Toolbar} toolbar
8669 * @param {Object} [config] Configuration options
8671 OO
.ui
.BarToolGroup
= function OoUiBarToolGroup( toolbar
, config
) {
8672 // Parent constructor
8673 OO
.ui
.BarToolGroup
.super.call( this, toolbar
, config
);
8676 this.$element
.addClass( 'oo-ui-barToolGroup' );
8681 OO
.inheritClass( OO
.ui
.BarToolGroup
, OO
.ui
.ToolGroup
);
8683 /* Static Properties */
8685 OO
.ui
.BarToolGroup
.static.titleTooltips
= true;
8687 OO
.ui
.BarToolGroup
.static.accelTooltips
= true;
8689 OO
.ui
.BarToolGroup
.static.name
= 'bar';
8692 * Popup list of tools with an icon and optional label.
8696 * @extends OO.ui.ToolGroup
8697 * @mixins OO.ui.IconElement
8698 * @mixins OO.ui.IndicatorElement
8699 * @mixins OO.ui.LabelElement
8700 * @mixins OO.ui.TitledElement
8701 * @mixins OO.ui.ClippableElement
8704 * @param {OO.ui.Toolbar} toolbar
8705 * @param {Object} [config] Configuration options
8706 * @cfg {string} [header] Text to display at the top of the pop-up
8708 OO
.ui
.PopupToolGroup
= function OoUiPopupToolGroup( toolbar
, config
) {
8709 // Configuration initialization
8710 config
= config
|| {};
8712 // Parent constructor
8713 OO
.ui
.PopupToolGroup
.super.call( this, toolbar
, config
);
8715 // Mixin constructors
8716 OO
.ui
.IconElement
.call( this, config
);
8717 OO
.ui
.IndicatorElement
.call( this, config
);
8718 OO
.ui
.LabelElement
.call( this, config
);
8719 OO
.ui
.TitledElement
.call( this, config
);
8720 OO
.ui
.ClippableElement
.call( this, $.extend( {}, config
, { $clippable
: this.$group
} ) );
8723 this.active
= false;
8724 this.dragging
= false;
8725 this.onBlurHandler
= this.onBlur
.bind( this );
8726 this.$handle
= this.$( '<span>' );
8730 'mousedown touchstart': this.onHandlePointerDown
.bind( this ),
8731 'mouseup touchend': this.onHandlePointerUp
.bind( this )
8736 .addClass( 'oo-ui-popupToolGroup-handle' )
8737 .append( this.$icon
, this.$label
, this.$indicator
);
8738 // If the pop-up should have a header, add it to the top of the toolGroup.
8739 // Note: If this feature is useful for other widgets, we could abstract it into an
8740 // OO.ui.HeaderedElement mixin constructor.
8741 if ( config
.header
!== undefined ) {
8743 .prepend( this.$( '<span>' )
8744 .addClass( 'oo-ui-popupToolGroup-header' )
8745 .text( config
.header
)
8749 .addClass( 'oo-ui-popupToolGroup' )
8750 .prepend( this.$handle
);
8755 OO
.inheritClass( OO
.ui
.PopupToolGroup
, OO
.ui
.ToolGroup
);
8756 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.IconElement
);
8757 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.IndicatorElement
);
8758 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.LabelElement
);
8759 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.TitledElement
);
8760 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.ClippableElement
);
8762 /* Static Properties */
8769 OO
.ui
.PopupToolGroup
.prototype.setDisabled = function () {
8771 OO
.ui
.PopupToolGroup
.super.prototype.setDisabled
.apply( this, arguments
);
8773 if ( this.isDisabled() && this.isElementAttached() ) {
8774 this.setActive( false );
8779 * Handle focus being lost.
8781 * The event is actually generated from a mouseup, so it is not a normal blur event object.
8783 * @param {jQuery.Event} e Mouse up event
8785 OO
.ui
.PopupToolGroup
.prototype.onBlur = function ( e
) {
8786 // Only deactivate when clicking outside the dropdown element
8787 if ( this.$( e
.target
).closest( '.oo-ui-popupToolGroup' )[ 0 ] !== this.$element
[ 0 ] ) {
8788 this.setActive( false );
8795 OO
.ui
.PopupToolGroup
.prototype.onPointerUp = function ( e
) {
8796 // e.which is 0 for touch events, 1 for left mouse button
8797 // Only close toolgroup when a tool was actually selected
8798 // FIXME: this duplicates logic from the parent class
8799 if ( !this.isDisabled() && e
.which
<= 1 && this.pressed
&& this.pressed
=== this.getTargetTool( e
) ) {
8800 this.setActive( false );
8802 return OO
.ui
.PopupToolGroup
.super.prototype.onPointerUp
.call( this, e
);
8806 * Handle mouse up events.
8808 * @param {jQuery.Event} e Mouse up event
8810 OO
.ui
.PopupToolGroup
.prototype.onHandlePointerUp = function () {
8815 * Handle mouse down events.
8817 * @param {jQuery.Event} e Mouse down event
8819 OO
.ui
.PopupToolGroup
.prototype.onHandlePointerDown = function ( e
) {
8820 // e.which is 0 for touch events, 1 for left mouse button
8821 if ( !this.isDisabled() && e
.which
<= 1 ) {
8822 this.setActive( !this.active
);
8828 * Switch into active mode.
8830 * When active, mouseup events anywhere in the document will trigger deactivation.
8832 OO
.ui
.PopupToolGroup
.prototype.setActive = function ( value
) {
8834 if ( this.active
!== value
) {
8835 this.active
= value
;
8837 this.getElementDocument().addEventListener( 'mouseup', this.onBlurHandler
, true );
8839 // Try anchoring the popup to the left first
8840 this.$element
.addClass( 'oo-ui-popupToolGroup-active oo-ui-popupToolGroup-left' );
8841 this.toggleClipping( true );
8842 if ( this.isClippedHorizontally() ) {
8843 // Anchoring to the left caused the popup to clip, so anchor it to the right instead
8844 this.toggleClipping( false );
8846 .removeClass( 'oo-ui-popupToolGroup-left' )
8847 .addClass( 'oo-ui-popupToolGroup-right' );
8848 this.toggleClipping( true );
8851 this.getElementDocument().removeEventListener( 'mouseup', this.onBlurHandler
, true );
8852 this.$element
.removeClass(
8853 'oo-ui-popupToolGroup-active oo-ui-popupToolGroup-left oo-ui-popupToolGroup-right'
8855 this.toggleClipping( false );
8861 * Drop down list layout of tools as labeled icon buttons.
8863 * This layout allows some tools to be collapsible, controlled by a "More" / "Fewer" option at the
8864 * bottom of the main list. These are not automatically positioned at the bottom of the list; you
8865 * may want to use the 'promote' and 'demote' configuration options to achieve this.
8868 * @extends OO.ui.PopupToolGroup
8871 * @param {OO.ui.Toolbar} toolbar
8872 * @param {Object} [config] Configuration options
8873 * @cfg {Array} [allowCollapse] List of tools that can be collapsed. Remaining tools will be always
8875 * @cfg {Array} [forceExpand] List of tools that *may not* be collapsed. All remaining tools will be
8876 * allowed to be collapsed.
8877 * @cfg {boolean} [expanded=false] Whether the collapsible tools are expanded by default
8879 OO
.ui
.ListToolGroup
= function OoUiListToolGroup( toolbar
, config
) {
8880 // Configuration initialization
8881 config
= config
|| {};
8883 // Properties (must be set before parent constructor, which calls #populate)
8884 this.allowCollapse
= config
.allowCollapse
;
8885 this.forceExpand
= config
.forceExpand
;
8886 this.expanded
= config
.expanded
!== undefined ? config
.expanded
: false;
8887 this.collapsibleTools
= [];
8889 // Parent constructor
8890 OO
.ui
.ListToolGroup
.super.call( this, toolbar
, config
);
8893 this.$element
.addClass( 'oo-ui-listToolGroup' );
8898 OO
.inheritClass( OO
.ui
.ListToolGroup
, OO
.ui
.PopupToolGroup
);
8900 /* Static Properties */
8902 OO
.ui
.ListToolGroup
.static.accelTooltips
= true;
8904 OO
.ui
.ListToolGroup
.static.name
= 'list';
8911 OO
.ui
.ListToolGroup
.prototype.populate = function () {
8912 var i
, len
, allowCollapse
= [];
8914 OO
.ui
.ListToolGroup
.super.prototype.populate
.call( this );
8916 // Update the list of collapsible tools
8917 if ( this.allowCollapse
!== undefined ) {
8918 allowCollapse
= this.allowCollapse
;
8919 } else if ( this.forceExpand
!== undefined ) {
8920 allowCollapse
= OO
.simpleArrayDifference( Object
.keys( this.tools
), this.forceExpand
);
8923 this.collapsibleTools
= [];
8924 for ( i
= 0, len
= allowCollapse
.length
; i
< len
; i
++ ) {
8925 if ( this.tools
[ allowCollapse
[ i
] ] !== undefined ) {
8926 this.collapsibleTools
.push( this.tools
[ allowCollapse
[ i
] ] );
8930 // Keep at the end, even when tools are added
8931 this.$group
.append( this.getExpandCollapseTool().$element
);
8933 this.getExpandCollapseTool().toggle( this.collapsibleTools
.length
!== 0 );
8935 // Calling jQuery's .hide() and then .show() on a detached element caches the default value of its
8936 // 'display' attribute and restores it, and the tool uses a <span> and can be hidden and re-shown.
8937 // Is this a jQuery bug? http://jsfiddle.net/gtj4hu3h/
8938 if ( this.getExpandCollapseTool().$element
.css( 'display' ) === 'inline' ) {
8939 this.getExpandCollapseTool().$element
.css( 'display', 'block' );
8942 this.updateCollapsibleState();
8945 OO
.ui
.ListToolGroup
.prototype.getExpandCollapseTool = function () {
8946 if ( this.expandCollapseTool
=== undefined ) {
8947 var ExpandCollapseTool = function () {
8948 ExpandCollapseTool
.super.apply( this, arguments
);
8951 OO
.inheritClass( ExpandCollapseTool
, OO
.ui
.Tool
);
8953 ExpandCollapseTool
.prototype.onSelect = function () {
8954 this.toolGroup
.expanded
= !this.toolGroup
.expanded
;
8955 this.toolGroup
.updateCollapsibleState();
8956 this.setActive( false );
8958 ExpandCollapseTool
.prototype.onUpdateState = function () {
8959 // Do nothing. Tool interface requires an implementation of this function.
8962 ExpandCollapseTool
.static.name
= 'more-fewer';
8964 this.expandCollapseTool
= new ExpandCollapseTool( this );
8966 return this.expandCollapseTool
;
8972 OO
.ui
.ListToolGroup
.prototype.onPointerUp = function ( e
) {
8973 var ret
= OO
.ui
.ListToolGroup
.super.prototype.onPointerUp
.call( this, e
);
8975 // Do not close the popup when the user wants to show more/fewer tools
8976 if ( this.$( e
.target
).closest( '.oo-ui-tool-name-more-fewer' ).length
) {
8977 // Prevent the popup list from being hidden
8978 this.setActive( true );
8984 OO
.ui
.ListToolGroup
.prototype.updateCollapsibleState = function () {
8987 this.getExpandCollapseTool()
8988 .setIcon( this.expanded
? 'collapse' : 'expand' )
8989 .setTitle( OO
.ui
.msg( this.expanded
? 'ooui-toolgroup-collapse' : 'ooui-toolgroup-expand' ) );
8991 for ( i
= 0, len
= this.collapsibleTools
.length
; i
< len
; i
++ ) {
8992 this.collapsibleTools
[ i
].toggle( this.expanded
);
8997 * Drop down menu layout of tools as selectable menu items.
9000 * @extends OO.ui.PopupToolGroup
9003 * @param {OO.ui.Toolbar} toolbar
9004 * @param {Object} [config] Configuration options
9006 OO
.ui
.MenuToolGroup
= function OoUiMenuToolGroup( toolbar
, config
) {
9007 // Configuration initialization
9008 config
= config
|| {};
9010 // Parent constructor
9011 OO
.ui
.MenuToolGroup
.super.call( this, toolbar
, config
);
9014 this.toolbar
.connect( this, { updateState
: 'onUpdateState' } );
9017 this.$element
.addClass( 'oo-ui-menuToolGroup' );
9022 OO
.inheritClass( OO
.ui
.MenuToolGroup
, OO
.ui
.PopupToolGroup
);
9024 /* Static Properties */
9026 OO
.ui
.MenuToolGroup
.static.accelTooltips
= true;
9028 OO
.ui
.MenuToolGroup
.static.name
= 'menu';
9033 * Handle the toolbar state being updated.
9035 * When the state changes, the title of each active item in the menu will be joined together and
9036 * used as a label for the group. The label will be empty if none of the items are active.
9038 OO
.ui
.MenuToolGroup
.prototype.onUpdateState = function () {
9042 for ( name
in this.tools
) {
9043 if ( this.tools
[ name
].isActive() ) {
9044 labelTexts
.push( this.tools
[ name
].getTitle() );
9048 this.setLabel( labelTexts
.join( ', ' ) || ' ' );
9052 * Tool that shows a popup when selected.
9056 * @extends OO.ui.Tool
9057 * @mixins OO.ui.PopupElement
9060 * @param {OO.ui.Toolbar} toolbar
9061 * @param {Object} [config] Configuration options
9063 OO
.ui
.PopupTool
= function OoUiPopupTool( toolbar
, config
) {
9064 // Parent constructor
9065 OO
.ui
.PopupTool
.super.call( this, toolbar
, config
);
9067 // Mixin constructors
9068 OO
.ui
.PopupElement
.call( this, config
);
9072 .addClass( 'oo-ui-popupTool' )
9073 .append( this.popup
.$element
);
9078 OO
.inheritClass( OO
.ui
.PopupTool
, OO
.ui
.Tool
);
9079 OO
.mixinClass( OO
.ui
.PopupTool
, OO
.ui
.PopupElement
);
9084 * Handle the tool being selected.
9088 OO
.ui
.PopupTool
.prototype.onSelect = function () {
9089 if ( !this.isDisabled() ) {
9090 this.popup
.toggle();
9092 this.setActive( false );
9097 * Handle the toolbar state being updated.
9101 OO
.ui
.PopupTool
.prototype.onUpdateState = function () {
9102 this.setActive( false );
9106 * Mixin for OO.ui.Widget subclasses to provide OO.ui.GroupElement.
9108 * Use together with OO.ui.ItemWidget to make disabled state inheritable.
9112 * @extends OO.ui.GroupElement
9115 * @param {Object} [config] Configuration options
9117 OO
.ui
.GroupWidget
= function OoUiGroupWidget( config
) {
9118 // Parent constructor
9119 OO
.ui
.GroupWidget
.super.call( this, config
);
9124 OO
.inheritClass( OO
.ui
.GroupWidget
, OO
.ui
.GroupElement
);
9129 * Set the disabled state of the widget.
9131 * This will also update the disabled state of child widgets.
9133 * @param {boolean} disabled Disable widget
9136 OO
.ui
.GroupWidget
.prototype.setDisabled = function ( disabled
) {
9140 // Note: Calling #setDisabled this way assumes this is mixed into an OO.ui.Widget
9141 OO
.ui
.Widget
.prototype.setDisabled
.call( this, disabled
);
9143 // During construction, #setDisabled is called before the OO.ui.GroupElement constructor
9145 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
9146 this.items
[ i
].updateDisabled();
9154 * Mixin for widgets used as items in widgets that inherit OO.ui.GroupWidget.
9156 * Item widgets have a reference to a OO.ui.GroupWidget while they are attached to the group. This
9157 * allows bidirectional communication.
9159 * Use together with OO.ui.GroupWidget to make disabled state inheritable.
9166 OO
.ui
.ItemWidget
= function OoUiItemWidget() {
9173 * Check if widget is disabled.
9175 * Checks parent if present, making disabled state inheritable.
9177 * @return {boolean} Widget is disabled
9179 OO
.ui
.ItemWidget
.prototype.isDisabled = function () {
9180 return this.disabled
||
9181 ( this.elementGroup
instanceof OO
.ui
.Widget
&& this.elementGroup
.isDisabled() );
9185 * Set group element is in.
9187 * @param {OO.ui.GroupElement|null} group Group element, null if none
9190 OO
.ui
.ItemWidget
.prototype.setElementGroup = function ( group
) {
9192 // Note: Calling #setElementGroup this way assumes this is mixed into an OO.ui.Element
9193 OO
.ui
.Element
.prototype.setElementGroup
.call( this, group
);
9195 // Initialize item disabled states
9196 this.updateDisabled();
9202 * Mixin that adds a menu showing suggested values for a text input.
9204 * Subclasses must handle `select` and `choose` events on #lookupMenu to make use of selections.
9206 * Subclasses that set the value of #lookupInput from their `choose` or `select` handler should
9207 * be aware that this will cause new suggestions to be looked up for the new value. If this is
9208 * not desired, disable lookups with #setLookupsDisabled, then set the value, then re-enable lookups.
9212 * @deprecated Use LookupElement instead.
9215 * @param {OO.ui.TextInputWidget} input Input widget
9216 * @param {Object} [config] Configuration options
9217 * @cfg {jQuery} [$overlay] Overlay for dropdown; defaults to relative positioning
9218 * @cfg {jQuery} [$container=input.$element] Element to render menu under
9220 OO
.ui
.LookupInputWidget
= function OoUiLookupInputWidget( input
, config
) {
9221 // Configuration initialization
9222 config
= config
|| {};
9225 this.lookupInput
= input
;
9226 this.$overlay
= config
.$overlay
|| this.$element
;
9227 this.lookupMenu
= new OO
.ui
.TextInputMenuSelectWidget( this, {
9228 $: OO
.ui
.Element
.static.getJQuery( this.$overlay
),
9229 input
: this.lookupInput
,
9230 $container
: config
.$container
9232 this.lookupCache
= {};
9233 this.lookupQuery
= null;
9234 this.lookupRequest
= null;
9235 this.lookupsDisabled
= false;
9236 this.lookupInputFocused
= false;
9239 this.lookupInput
.$input
.on( {
9240 focus
: this.onLookupInputFocus
.bind( this ),
9241 blur
: this.onLookupInputBlur
.bind( this ),
9242 mousedown
: this.onLookupInputMouseDown
.bind( this )
9244 this.lookupInput
.connect( this, { change
: 'onLookupInputChange' } );
9245 this.lookupMenu
.connect( this, { toggle
: 'onLookupMenuToggle' } );
9248 this.$element
.addClass( 'oo-ui-lookupWidget' );
9249 this.lookupMenu
.$element
.addClass( 'oo-ui-lookupWidget-menu' );
9250 this.$overlay
.append( this.lookupMenu
.$element
);
9256 * Handle input focus event.
9258 * @param {jQuery.Event} e Input focus event
9260 OO
.ui
.LookupInputWidget
.prototype.onLookupInputFocus = function () {
9261 this.lookupInputFocused
= true;
9262 this.populateLookupMenu();
9266 * Handle input blur event.
9268 * @param {jQuery.Event} e Input blur event
9270 OO
.ui
.LookupInputWidget
.prototype.onLookupInputBlur = function () {
9271 this.closeLookupMenu();
9272 this.lookupInputFocused
= false;
9276 * Handle input mouse down event.
9278 * @param {jQuery.Event} e Input mouse down event
9280 OO
.ui
.LookupInputWidget
.prototype.onLookupInputMouseDown = function () {
9281 // Only open the menu if the input was already focused.
9282 // This way we allow the user to open the menu again after closing it with Esc
9283 // by clicking in the input. Opening (and populating) the menu when initially
9284 // clicking into the input is handled by the focus handler.
9285 if ( this.lookupInputFocused
&& !this.lookupMenu
.isVisible() ) {
9286 this.populateLookupMenu();
9291 * Handle input change event.
9293 * @param {string} value New input value
9295 OO
.ui
.LookupInputWidget
.prototype.onLookupInputChange = function () {
9296 if ( this.lookupInputFocused
) {
9297 this.populateLookupMenu();
9302 * Handle the lookup menu being shown/hidden.
9303 * @param {boolean} visible Whether the lookup menu is now visible.
9305 OO
.ui
.LookupInputWidget
.prototype.onLookupMenuToggle = function ( visible
) {
9307 // When the menu is hidden, abort any active request and clear the menu.
9308 // This has to be done here in addition to closeLookupMenu(), because
9309 // MenuSelectWidget will close itself when the user presses Esc.
9310 this.abortLookupRequest();
9311 this.lookupMenu
.clearItems();
9318 * @return {OO.ui.TextInputMenuSelectWidget}
9320 OO
.ui
.LookupInputWidget
.prototype.getLookupMenu = function () {
9321 return this.lookupMenu
;
9325 * Disable or re-enable lookups.
9327 * When lookups are disabled, calls to #populateLookupMenu will be ignored.
9329 * @param {boolean} disabled Disable lookups
9331 OO
.ui
.LookupInputWidget
.prototype.setLookupsDisabled = function ( disabled
) {
9332 this.lookupsDisabled
= !!disabled
;
9336 * Open the menu. If there are no entries in the menu, this does nothing.
9340 OO
.ui
.LookupInputWidget
.prototype.openLookupMenu = function () {
9341 if ( !this.lookupMenu
.isEmpty() ) {
9342 this.lookupMenu
.toggle( true );
9348 * Close the menu, empty it, and abort any pending request.
9352 OO
.ui
.LookupInputWidget
.prototype.closeLookupMenu = function () {
9353 this.lookupMenu
.toggle( false );
9354 this.abortLookupRequest();
9355 this.lookupMenu
.clearItems();
9360 * Request menu items based on the input's current value, and when they arrive,
9361 * populate the menu with these items and show the menu.
9363 * If lookups have been disabled with #setLookupsDisabled, this function does nothing.
9367 OO
.ui
.LookupInputWidget
.prototype.populateLookupMenu = function () {
9369 value
= this.lookupInput
.getValue();
9371 if ( this.lookupsDisabled
) {
9375 // If the input is empty, clear the menu
9376 if ( value
=== '' ) {
9377 this.closeLookupMenu();
9378 // Skip population if there is already a request pending for the current value
9379 } else if ( value
!== this.lookupQuery
) {
9380 this.getLookupMenuItems()
9381 .done( function ( items
) {
9382 widget
.lookupMenu
.clearItems();
9383 if ( items
.length
) {
9387 widget
.initializeLookupMenuSelection();
9389 widget
.lookupMenu
.toggle( false );
9392 .fail( function () {
9393 widget
.lookupMenu
.clearItems();
9401 * Select and highlight the first selectable item in the menu.
9405 OO
.ui
.LookupInputWidget
.prototype.initializeLookupMenuSelection = function () {
9406 if ( !this.lookupMenu
.getSelectedItem() ) {
9407 this.lookupMenu
.selectItem( this.lookupMenu
.getFirstSelectableItem() );
9409 this.lookupMenu
.highlightItem( this.lookupMenu
.getSelectedItem() );
9413 * Get lookup menu items for the current query.
9415 * @return {jQuery.Promise} Promise object which will be passed menu items as the first argument
9416 * of the done event. If the request was aborted to make way for a subsequent request,
9417 * this promise will not be rejected: it will remain pending forever.
9419 OO
.ui
.LookupInputWidget
.prototype.getLookupMenuItems = function () {
9421 value
= this.lookupInput
.getValue(),
9422 deferred
= $.Deferred(),
9425 this.abortLookupRequest();
9426 if ( Object
.prototype.hasOwnProperty
.call( this.lookupCache
, value
) ) {
9427 deferred
.resolve( this.getLookupMenuItemsFromData( this.lookupCache
[ value
] ) );
9429 this.lookupInput
.pushPending();
9430 this.lookupQuery
= value
;
9431 ourRequest
= this.lookupRequest
= this.getLookupRequest();
9433 .always( function () {
9434 // We need to pop pending even if this is an old request, otherwise
9435 // the widget will remain pending forever.
9436 // TODO: this assumes that an aborted request will fail or succeed soon after
9437 // being aborted, or at least eventually. It would be nice if we could popPending()
9438 // at abort time, but only if we knew that we hadn't already called popPending()
9439 // for that request.
9440 widget
.lookupInput
.popPending();
9442 .done( function ( data
) {
9443 // If this is an old request (and aborting it somehow caused it to still succeed),
9444 // ignore its success completely
9445 if ( ourRequest
=== widget
.lookupRequest
) {
9446 widget
.lookupQuery
= null;
9447 widget
.lookupRequest
= null;
9448 widget
.lookupCache
[ value
] = widget
.getLookupCacheItemFromData( data
);
9449 deferred
.resolve( widget
.getLookupMenuItemsFromData( widget
.lookupCache
[ value
] ) );
9452 .fail( function () {
9453 // If this is an old request (or a request failing because it's being aborted),
9454 // ignore its failure completely
9455 if ( ourRequest
=== widget
.lookupRequest
) {
9456 widget
.lookupQuery
= null;
9457 widget
.lookupRequest
= null;
9462 return deferred
.promise();
9466 * Abort the currently pending lookup request, if any.
9468 OO
.ui
.LookupInputWidget
.prototype.abortLookupRequest = function () {
9469 var oldRequest
= this.lookupRequest
;
9471 // First unset this.lookupRequest to the fail handler will notice
9472 // that the request is no longer current
9473 this.lookupRequest
= null;
9474 this.lookupQuery
= null;
9480 * Get a new request object of the current lookup query value.
9483 * @return {jQuery.Promise} jQuery AJAX object, or promise object with an .abort() method
9485 OO
.ui
.LookupInputWidget
.prototype.getLookupRequest = function () {
9486 // Stub, implemented in subclass
9491 * Get a list of menu item widgets from the data stored by the lookup request's done handler.
9494 * @param {Mixed} data Cached result data, usually an array
9495 * @return {OO.ui.MenuOptionWidget[]} Menu items
9497 OO
.ui
.LookupInputWidget
.prototype.getLookupMenuItemsFromData = function () {
9498 // Stub, implemented in subclass
9503 * Get lookup cache item from server response data.
9506 * @param {Mixed} data Response from server
9507 * @return {Mixed} Cached result data
9509 OO
.ui
.LookupInputWidget
.prototype.getLookupCacheItemFromData = function () {
9510 // Stub, implemented in subclass
9515 * Set of controls for an OO.ui.OutlineSelectWidget.
9517 * Controls include moving items up and down, removing items, and adding different kinds of items.
9520 * @extends OO.ui.Widget
9521 * @mixins OO.ui.GroupElement
9522 * @mixins OO.ui.IconElement
9525 * @param {OO.ui.OutlineSelectWidget} outline Outline to control
9526 * @param {Object} [config] Configuration options
9528 OO
.ui
.OutlineControlsWidget
= function OoUiOutlineControlsWidget( outline
, config
) {
9529 // Configuration initialization
9530 config
= $.extend( { icon
: 'add' }, config
);
9532 // Parent constructor
9533 OO
.ui
.OutlineControlsWidget
.super.call( this, config
);
9535 // Mixin constructors
9536 OO
.ui
.GroupElement
.call( this, config
);
9537 OO
.ui
.IconElement
.call( this, config
);
9540 this.outline
= outline
;
9541 this.$movers
= this.$( '<div>' );
9542 this.upButton
= new OO
.ui
.ButtonWidget( {
9546 title
: OO
.ui
.msg( 'ooui-outline-control-move-up' )
9548 this.downButton
= new OO
.ui
.ButtonWidget( {
9552 title
: OO
.ui
.msg( 'ooui-outline-control-move-down' )
9554 this.removeButton
= new OO
.ui
.ButtonWidget( {
9558 title
: OO
.ui
.msg( 'ooui-outline-control-remove' )
9562 outline
.connect( this, {
9563 select
: 'onOutlineChange',
9564 add
: 'onOutlineChange',
9565 remove
: 'onOutlineChange'
9567 this.upButton
.connect( this, { click
: [ 'emit', 'move', -1 ] } );
9568 this.downButton
.connect( this, { click
: [ 'emit', 'move', 1 ] } );
9569 this.removeButton
.connect( this, { click
: [ 'emit', 'remove' ] } );
9572 this.$element
.addClass( 'oo-ui-outlineControlsWidget' );
9573 this.$group
.addClass( 'oo-ui-outlineControlsWidget-items' );
9575 .addClass( 'oo-ui-outlineControlsWidget-movers' )
9576 .append( this.removeButton
.$element
, this.upButton
.$element
, this.downButton
.$element
);
9577 this.$element
.append( this.$icon
, this.$group
, this.$movers
);
9582 OO
.inheritClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.Widget
);
9583 OO
.mixinClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.GroupElement
);
9584 OO
.mixinClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.IconElement
);
9590 * @param {number} places Number of places to move
9600 * Handle outline change events.
9602 OO
.ui
.OutlineControlsWidget
.prototype.onOutlineChange = function () {
9603 var i
, len
, firstMovable
, lastMovable
,
9604 items
= this.outline
.getItems(),
9605 selectedItem
= this.outline
.getSelectedItem(),
9606 movable
= selectedItem
&& selectedItem
.isMovable(),
9607 removable
= selectedItem
&& selectedItem
.isRemovable();
9612 while ( ++i
< len
) {
9613 if ( items
[ i
].isMovable() ) {
9614 firstMovable
= items
[ i
];
9620 if ( items
[ i
].isMovable() ) {
9621 lastMovable
= items
[ i
];
9626 this.upButton
.setDisabled( !movable
|| selectedItem
=== firstMovable
);
9627 this.downButton
.setDisabled( !movable
|| selectedItem
=== lastMovable
);
9628 this.removeButton
.setDisabled( !removable
);
9632 * Mixin for widgets with a boolean on/off state.
9638 * @param {Object} [config] Configuration options
9639 * @cfg {boolean} [value=false] Initial value
9641 OO
.ui
.ToggleWidget
= function OoUiToggleWidget( config
) {
9642 // Configuration initialization
9643 config
= config
|| {};
9649 this.$element
.addClass( 'oo-ui-toggleWidget' );
9650 this.setValue( !!config
.value
);
9657 * @param {boolean} value Changed value
9663 * Get the value of the toggle.
9667 OO
.ui
.ToggleWidget
.prototype.getValue = function () {
9672 * Set the value of the toggle.
9674 * @param {boolean} value New value
9678 OO
.ui
.ToggleWidget
.prototype.setValue = function ( value
) {
9680 if ( this.value
!== value
) {
9682 this.emit( 'change', value
);
9683 this.$element
.toggleClass( 'oo-ui-toggleWidget-on', value
);
9684 this.$element
.toggleClass( 'oo-ui-toggleWidget-off', !value
);
9685 this.$element
.attr( 'aria-checked', value
.toString() );
9691 * Group widget for multiple related buttons.
9693 * Use together with OO.ui.ButtonWidget.
9696 * @extends OO.ui.Widget
9697 * @mixins OO.ui.GroupElement
9700 * @param {Object} [config] Configuration options
9701 * @cfg {OO.ui.ButtonWidget[]} [items] Buttons to add
9703 OO
.ui
.ButtonGroupWidget
= function OoUiButtonGroupWidget( config
) {
9704 // Configuration initialization
9705 config
= config
|| {};
9707 // Parent constructor
9708 OO
.ui
.ButtonGroupWidget
.super.call( this, config
);
9710 // Mixin constructors
9711 OO
.ui
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
9714 this.$element
.addClass( 'oo-ui-buttonGroupWidget' );
9715 if ( $.isArray( config
.items
) ) {
9716 this.addItems( config
.items
);
9722 OO
.inheritClass( OO
.ui
.ButtonGroupWidget
, OO
.ui
.Widget
);
9723 OO
.mixinClass( OO
.ui
.ButtonGroupWidget
, OO
.ui
.GroupElement
);
9726 * Generic widget for buttons.
9729 * @extends OO.ui.Widget
9730 * @mixins OO.ui.ButtonElement
9731 * @mixins OO.ui.IconElement
9732 * @mixins OO.ui.IndicatorElement
9733 * @mixins OO.ui.LabelElement
9734 * @mixins OO.ui.TitledElement
9735 * @mixins OO.ui.FlaggedElement
9736 * @mixins OO.ui.TabIndexedElement
9739 * @param {Object} [config] Configuration options
9740 * @cfg {string} [href] Hyperlink to visit when clicked
9741 * @cfg {string} [target] Target to open hyperlink in
9743 OO
.ui
.ButtonWidget
= function OoUiButtonWidget( config
) {
9744 // Configuration initialization
9745 config
= config
|| {};
9747 // Parent constructor
9748 OO
.ui
.ButtonWidget
.super.call( this, config
);
9750 // Mixin constructors
9751 OO
.ui
.ButtonElement
.call( this, config
);
9752 OO
.ui
.IconElement
.call( this, config
);
9753 OO
.ui
.IndicatorElement
.call( this, config
);
9754 OO
.ui
.LabelElement
.call( this, config
);
9755 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$button
} ) );
9756 OO
.ui
.FlaggedElement
.call( this, config
);
9757 OO
.ui
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$button
} ) );
9762 this.isHyperlink
= false;
9766 click
: this.onClick
.bind( this ),
9767 keypress
: this.onKeyPress
.bind( this )
9771 this.$button
.append( this.$icon
, this.$label
, this.$indicator
);
9773 .addClass( 'oo-ui-buttonWidget' )
9774 .append( this.$button
);
9775 this.setHref( config
.href
);
9776 this.setTarget( config
.target
);
9781 OO
.inheritClass( OO
.ui
.ButtonWidget
, OO
.ui
.Widget
);
9782 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.ButtonElement
);
9783 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.IconElement
);
9784 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.IndicatorElement
);
9785 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.LabelElement
);
9786 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.TitledElement
);
9787 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.FlaggedElement
);
9788 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.TabIndexedElement
);
9799 * Handles mouse click events.
9801 * @param {jQuery.Event} e Mouse click event
9804 OO
.ui
.ButtonWidget
.prototype.onClick = function () {
9805 if ( !this.isDisabled() ) {
9806 this.emit( 'click' );
9807 if ( this.isHyperlink
) {
9817 OO
.ui
.ButtonWidget
.prototype.onMouseDown = function ( e
) {
9818 // Remove the tab-index while the button is down to prevent the button from stealing focus
9819 this.$button
.removeAttr( 'tabindex' );
9820 return OO
.ui
.ButtonElement
.prototype.onMouseDown
.call( this, e
);
9826 OO
.ui
.ButtonWidget
.prototype.onMouseUp = function ( e
) {
9827 // Restore the tab-index after the button is up to restore the button's accessibility
9828 this.$button
.attr( 'tabindex', this.tabIndex
);
9829 return OO
.ui
.ButtonElement
.prototype.onMouseUp
.call( this, e
);
9833 * Handles keypress events.
9835 * @param {jQuery.Event} e Keypress event
9838 OO
.ui
.ButtonWidget
.prototype.onKeyPress = function ( e
) {
9839 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
9840 this.emit( 'click' );
9841 if ( this.isHyperlink
) {
9849 * Get hyperlink location.
9851 * @return {string} Hyperlink location
9853 OO
.ui
.ButtonWidget
.prototype.getHref = function () {
9858 * Get hyperlink target.
9860 * @return {string} Hyperlink target
9862 OO
.ui
.ButtonWidget
.prototype.getTarget = function () {
9867 * Set hyperlink location.
9869 * @param {string|null} href Hyperlink location, null to remove
9871 OO
.ui
.ButtonWidget
.prototype.setHref = function ( href
) {
9872 href
= typeof href
=== 'string' ? href
: null;
9874 if ( href
!== this.href
) {
9876 if ( href
!== null ) {
9877 this.$button
.attr( 'href', href
);
9878 this.isHyperlink
= true;
9880 this.$button
.removeAttr( 'href' );
9881 this.isHyperlink
= false;
9889 * Set hyperlink target.
9891 * @param {string|null} target Hyperlink target, null to remove
9893 OO
.ui
.ButtonWidget
.prototype.setTarget = function ( target
) {
9894 target
= typeof target
=== 'string' ? target
: null;
9896 if ( target
!== this.target
) {
9897 this.target
= target
;
9898 if ( target
!== null ) {
9899 this.$button
.attr( 'target', target
);
9901 this.$button
.removeAttr( 'target' );
9909 * Button widget that executes an action and is managed by an OO.ui.ActionSet.
9912 * @extends OO.ui.ButtonWidget
9913 * @mixins OO.ui.PendingElement
9916 * @param {Object} [config] Configuration options
9917 * @cfg {string} [action] Symbolic action name
9918 * @cfg {string[]} [modes] Symbolic mode names
9919 * @cfg {boolean} [framed=false] Render button with a frame
9921 OO
.ui
.ActionWidget
= function OoUiActionWidget( config
) {
9922 // Configuration initialization
9923 config
= $.extend( { framed
: false }, config
);
9925 // Parent constructor
9926 OO
.ui
.ActionWidget
.super.call( this, config
);
9928 // Mixin constructors
9929 OO
.ui
.PendingElement
.call( this, config
);
9932 this.action
= config
.action
|| '';
9933 this.modes
= config
.modes
|| [];
9938 this.$element
.addClass( 'oo-ui-actionWidget' );
9943 OO
.inheritClass( OO
.ui
.ActionWidget
, OO
.ui
.ButtonWidget
);
9944 OO
.mixinClass( OO
.ui
.ActionWidget
, OO
.ui
.PendingElement
);
9955 * Check if action is available in a certain mode.
9957 * @param {string} mode Name of mode
9958 * @return {boolean} Has mode
9960 OO
.ui
.ActionWidget
.prototype.hasMode = function ( mode
) {
9961 return this.modes
.indexOf( mode
) !== -1;
9965 * Get symbolic action name.
9969 OO
.ui
.ActionWidget
.prototype.getAction = function () {
9974 * Get symbolic action name.
9978 OO
.ui
.ActionWidget
.prototype.getModes = function () {
9979 return this.modes
.slice();
9983 * Emit a resize event if the size has changed.
9987 OO
.ui
.ActionWidget
.prototype.propagateResize = function () {
9990 if ( this.isElementAttached() ) {
9991 width
= this.$element
.width();
9992 height
= this.$element
.height();
9994 if ( width
!== this.width
|| height
!== this.height
) {
9996 this.height
= height
;
9997 this.emit( 'resize' );
10007 OO
.ui
.ActionWidget
.prototype.setIcon = function () {
10009 OO
.ui
.IconElement
.prototype.setIcon
.apply( this, arguments
);
10010 this.propagateResize();
10018 OO
.ui
.ActionWidget
.prototype.setLabel = function () {
10020 OO
.ui
.LabelElement
.prototype.setLabel
.apply( this, arguments
);
10021 this.propagateResize();
10029 OO
.ui
.ActionWidget
.prototype.setFlags = function () {
10031 OO
.ui
.FlaggedElement
.prototype.setFlags
.apply( this, arguments
);
10032 this.propagateResize();
10040 OO
.ui
.ActionWidget
.prototype.clearFlags = function () {
10042 OO
.ui
.FlaggedElement
.prototype.clearFlags
.apply( this, arguments
);
10043 this.propagateResize();
10049 * Toggle visibility of button.
10051 * @param {boolean} [show] Show button, omit to toggle visibility
10054 OO
.ui
.ActionWidget
.prototype.toggle = function () {
10056 OO
.ui
.ActionWidget
.super.prototype.toggle
.apply( this, arguments
);
10057 this.propagateResize();
10063 * Button that shows and hides a popup.
10066 * @extends OO.ui.ButtonWidget
10067 * @mixins OO.ui.PopupElement
10070 * @param {Object} [config] Configuration options
10072 OO
.ui
.PopupButtonWidget
= function OoUiPopupButtonWidget( config
) {
10073 // Parent constructor
10074 OO
.ui
.PopupButtonWidget
.super.call( this, config
);
10076 // Mixin constructors
10077 OO
.ui
.PopupElement
.call( this, config
);
10081 .addClass( 'oo-ui-popupButtonWidget' )
10082 .attr( 'aria-haspopup', 'true' )
10083 .append( this.popup
.$element
);
10088 OO
.inheritClass( OO
.ui
.PopupButtonWidget
, OO
.ui
.ButtonWidget
);
10089 OO
.mixinClass( OO
.ui
.PopupButtonWidget
, OO
.ui
.PopupElement
);
10094 * Handles mouse click events.
10096 * @param {jQuery.Event} e Mouse click event
10098 OO
.ui
.PopupButtonWidget
.prototype.onClick = function ( e
) {
10099 // Skip clicks within the popup
10100 if ( $.contains( this.popup
.$element
[ 0 ], e
.target
) ) {
10104 if ( !this.isDisabled() ) {
10105 this.popup
.toggle();
10107 OO
.ui
.PopupButtonWidget
.super.prototype.onClick
.call( this );
10113 * Button that toggles on and off.
10116 * @extends OO.ui.ButtonWidget
10117 * @mixins OO.ui.ToggleWidget
10120 * @param {Object} [config] Configuration options
10121 * @cfg {boolean} [value=false] Initial value
10123 OO
.ui
.ToggleButtonWidget
= function OoUiToggleButtonWidget( config
) {
10124 // Configuration initialization
10125 config
= config
|| {};
10127 // Parent constructor
10128 OO
.ui
.ToggleButtonWidget
.super.call( this, config
);
10130 // Mixin constructors
10131 OO
.ui
.ToggleWidget
.call( this, config
);
10134 this.$element
.addClass( 'oo-ui-toggleButtonWidget' );
10139 OO
.inheritClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.ButtonWidget
);
10140 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.ToggleWidget
);
10147 OO
.ui
.ToggleButtonWidget
.prototype.onClick = function () {
10148 if ( !this.isDisabled() ) {
10149 this.setValue( !this.value
);
10153 return OO
.ui
.ToggleButtonWidget
.super.prototype.onClick
.call( this );
10159 OO
.ui
.ToggleButtonWidget
.prototype.setValue = function ( value
) {
10161 if ( value
!== this.value
) {
10162 this.$button
.attr( 'aria-pressed', value
.toString() );
10163 this.setActive( value
);
10166 // Parent method (from mixin)
10167 OO
.ui
.ToggleWidget
.prototype.setValue
.call( this, value
);
10173 * Dropdown menu of options.
10175 * Dropdown menus provide a control for accessing a menu and compose a menu within the widget, which
10176 * can be accessed using the #getMenu method.
10178 * Use with OO.ui.MenuOptionWidget.
10181 * @extends OO.ui.Widget
10182 * @mixins OO.ui.IconElement
10183 * @mixins OO.ui.IndicatorElement
10184 * @mixins OO.ui.LabelElement
10185 * @mixins OO.ui.TitledElement
10188 * @param {Object} [config] Configuration options
10189 * @cfg {Object} [menu] Configuration options to pass to menu widget
10191 OO
.ui
.DropdownWidget
= function OoUiDropdownWidget( config
) {
10192 // Configuration initialization
10193 config
= $.extend( { indicator
: 'down' }, config
);
10195 // Parent constructor
10196 OO
.ui
.DropdownWidget
.super.call( this, config
);
10198 // Mixin constructors
10199 OO
.ui
.IconElement
.call( this, config
);
10200 OO
.ui
.IndicatorElement
.call( this, config
);
10201 OO
.ui
.LabelElement
.call( this, config
);
10202 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$label
} ) );
10205 this.menu
= new OO
.ui
.MenuSelectWidget( $.extend( { $: this.$, widget
: this }, config
.menu
) );
10206 this.$handle
= this.$( '<span>' );
10209 this.$element
.on( { click
: this.onClick
.bind( this ) } );
10210 this.menu
.connect( this, { select
: 'onMenuSelect' } );
10214 .addClass( 'oo-ui-dropdownWidget-handle' )
10215 .append( this.$icon
, this.$label
, this.$indicator
);
10217 .addClass( 'oo-ui-dropdownWidget' )
10218 .append( this.$handle
, this.menu
.$element
);
10223 OO
.inheritClass( OO
.ui
.DropdownWidget
, OO
.ui
.Widget
);
10224 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.IconElement
);
10225 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.IndicatorElement
);
10226 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.LabelElement
);
10227 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.TitledElement
);
10234 * @return {OO.ui.MenuSelectWidget} Menu of widget
10236 OO
.ui
.DropdownWidget
.prototype.getMenu = function () {
10241 * Handles menu select events.
10243 * @param {OO.ui.MenuOptionWidget} item Selected menu item
10245 OO
.ui
.DropdownWidget
.prototype.onMenuSelect = function ( item
) {
10252 selectedLabel
= item
.getLabel();
10254 // If the label is a DOM element, clone it, because setLabel will append() it
10255 if ( selectedLabel
instanceof jQuery
) {
10256 selectedLabel
= selectedLabel
.clone();
10259 this.setLabel( selectedLabel
);
10263 * Handles mouse click events.
10265 * @param {jQuery.Event} e Mouse click event
10267 OO
.ui
.DropdownWidget
.prototype.onClick = function ( e
) {
10268 // Skip clicks within the menu
10269 if ( $.contains( this.menu
.$element
[ 0 ], e
.target
) ) {
10273 if ( !this.isDisabled() ) {
10274 if ( this.menu
.isVisible() ) {
10275 this.menu
.toggle( false );
10277 this.menu
.toggle( true );
10286 * See OO.ui.IconElement for more information.
10289 * @extends OO.ui.Widget
10290 * @mixins OO.ui.IconElement
10291 * @mixins OO.ui.TitledElement
10294 * @param {Object} [config] Configuration options
10296 OO
.ui
.IconWidget
= function OoUiIconWidget( config
) {
10297 // Configuration initialization
10298 config
= config
|| {};
10300 // Parent constructor
10301 OO
.ui
.IconWidget
.super.call( this, config
);
10303 // Mixin constructors
10304 OO
.ui
.IconElement
.call( this, $.extend( {}, config
, { $icon
: this.$element
} ) );
10305 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$element
} ) );
10308 this.$element
.addClass( 'oo-ui-iconWidget' );
10313 OO
.inheritClass( OO
.ui
.IconWidget
, OO
.ui
.Widget
);
10314 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.IconElement
);
10315 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.TitledElement
);
10317 /* Static Properties */
10319 OO
.ui
.IconWidget
.static.tagName
= 'span';
10322 * Indicator widget.
10324 * See OO.ui.IndicatorElement for more information.
10327 * @extends OO.ui.Widget
10328 * @mixins OO.ui.IndicatorElement
10329 * @mixins OO.ui.TitledElement
10332 * @param {Object} [config] Configuration options
10334 OO
.ui
.IndicatorWidget
= function OoUiIndicatorWidget( config
) {
10335 // Configuration initialization
10336 config
= config
|| {};
10338 // Parent constructor
10339 OO
.ui
.IndicatorWidget
.super.call( this, config
);
10341 // Mixin constructors
10342 OO
.ui
.IndicatorElement
.call( this, $.extend( {}, config
, { $indicator
: this.$element
} ) );
10343 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$element
} ) );
10346 this.$element
.addClass( 'oo-ui-indicatorWidget' );
10351 OO
.inheritClass( OO
.ui
.IndicatorWidget
, OO
.ui
.Widget
);
10352 OO
.mixinClass( OO
.ui
.IndicatorWidget
, OO
.ui
.IndicatorElement
);
10353 OO
.mixinClass( OO
.ui
.IndicatorWidget
, OO
.ui
.TitledElement
);
10355 /* Static Properties */
10357 OO
.ui
.IndicatorWidget
.static.tagName
= 'span';
10360 * Base class for input widgets.
10364 * @extends OO.ui.Widget
10365 * @mixins OO.ui.FlaggedElement
10366 * @mixins OO.ui.TabIndexedElement
10369 * @param {Object} [config] Configuration options
10370 * @cfg {string} [name=''] HTML input name
10371 * @cfg {string} [value=''] Input value
10372 * @cfg {Function} [inputFilter] Filter function to apply to the input. Takes a string argument and returns a string.
10374 OO
.ui
.InputWidget
= function OoUiInputWidget( config
) {
10375 // Configuration initialization
10376 config
= config
|| {};
10378 // Parent constructor
10379 OO
.ui
.InputWidget
.super.call( this, config
);
10382 this.$input
= this.getInputElement( config
);
10384 this.inputFilter
= config
.inputFilter
;
10386 // Mixin constructors
10387 OO
.ui
.FlaggedElement
.call( this, config
);
10388 OO
.ui
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$input
} ) );
10391 this.$input
.on( 'keydown mouseup cut paste change input select', this.onEdit
.bind( this ) );
10395 .attr( 'name', config
.name
)
10396 .prop( 'disabled', this.isDisabled() );
10397 this.$element
.addClass( 'oo-ui-inputWidget' ).append( this.$input
, $( '<span>' ) );
10398 this.setValue( config
.value
);
10403 OO
.inheritClass( OO
.ui
.InputWidget
, OO
.ui
.Widget
);
10404 OO
.mixinClass( OO
.ui
.InputWidget
, OO
.ui
.FlaggedElement
);
10405 OO
.mixinClass( OO
.ui
.InputWidget
, OO
.ui
.TabIndexedElement
);
10411 * @param {string} value
10417 * Get input element.
10419 * Subclasses of OO.ui.InputWidget use the `config` parameter to produce different elements in
10420 * different circumstances. The element must have a `value` property (like form elements).
10423 * @param {Object} config Configuration options
10424 * @return {jQuery} Input element
10426 OO
.ui
.InputWidget
.prototype.getInputElement = function () {
10427 return this.$( '<input>' );
10431 * Handle potentially value-changing events.
10433 * @param {jQuery.Event} e Key down, mouse up, cut, paste, change, input, or select event
10435 OO
.ui
.InputWidget
.prototype.onEdit = function () {
10437 if ( !this.isDisabled() ) {
10438 // Allow the stack to clear so the value will be updated
10439 setTimeout( function () {
10440 widget
.setValue( widget
.$input
.val() );
10446 * Get the value of the input.
10448 * @return {string} Input value
10450 OO
.ui
.InputWidget
.prototype.getValue = function () {
10451 // Resynchronize our internal data with DOM data. Other scripts executing on the page can modify
10452 // it, and we won't know unless they're kind enough to trigger a 'change' event.
10453 var value
= this.$input
.val();
10454 if ( this.value
!== value
) {
10455 this.setValue( value
);
10461 * Sets the direction of the current input, either RTL or LTR
10463 * @param {boolean} isRTL
10465 OO
.ui
.InputWidget
.prototype.setRTL = function ( isRTL
) {
10466 this.$input
.prop( 'dir', isRTL
? 'rtl' : 'ltr' );
10470 * Set the value of the input.
10472 * @param {string} value New value
10476 OO
.ui
.InputWidget
.prototype.setValue = function ( value
) {
10477 value
= this.cleanUpValue( value
);
10478 // Update the DOM if it has changed. Note that with cleanUpValue, it
10479 // is possible for the DOM value to change without this.value changing.
10480 if ( this.$input
.val() !== value
) {
10481 this.$input
.val( value
);
10483 if ( this.value
!== value
) {
10484 this.value
= value
;
10485 this.emit( 'change', this.value
);
10491 * Clean up incoming value.
10493 * Ensures value is a string, and converts undefined and null to empty string.
10496 * @param {string} value Original value
10497 * @return {string} Cleaned up value
10499 OO
.ui
.InputWidget
.prototype.cleanUpValue = function ( value
) {
10500 if ( value
=== undefined || value
=== null ) {
10502 } else if ( this.inputFilter
) {
10503 return this.inputFilter( String( value
) );
10505 return String( value
);
10510 * Simulate the behavior of clicking on a label bound to this input.
10512 OO
.ui
.InputWidget
.prototype.simulateLabelClick = function () {
10513 if ( !this.isDisabled() ) {
10514 if ( this.$input
.is( ':checkbox,:radio' ) ) {
10515 this.$input
.click();
10516 } else if ( this.$input
.is( ':input' ) ) {
10517 this.$input
[ 0 ].focus();
10525 OO
.ui
.InputWidget
.prototype.setDisabled = function ( state
) {
10526 OO
.ui
.InputWidget
.super.prototype.setDisabled
.call( this, state
);
10527 if ( this.$input
) {
10528 this.$input
.prop( 'disabled', this.isDisabled() );
10538 OO
.ui
.InputWidget
.prototype.focus = function () {
10539 this.$input
[ 0 ].focus();
10548 OO
.ui
.InputWidget
.prototype.blur = function () {
10549 this.$input
[ 0 ].blur();
10554 * A button that is an input widget. Intended to be used within a OO.ui.FormLayout.
10557 * @extends OO.ui.InputWidget
10558 * @mixins OO.ui.ButtonElement
10559 * @mixins OO.ui.IconElement
10560 * @mixins OO.ui.IndicatorElement
10561 * @mixins OO.ui.LabelElement
10562 * @mixins OO.ui.TitledElement
10563 * @mixins OO.ui.FlaggedElement
10566 * @param {Object} [config] Configuration options
10567 * @cfg {string} [type='button'] HTML tag `type` attribute, may be 'button', 'submit' or 'reset'
10568 * @cfg {boolean} [useInputTag=false] Whether to use `<input/>` rather than `<button/>`. Only useful
10569 * if you need IE 6 support in a form with multiple buttons. If you use this option, icons and
10570 * indicators will not be displayed, it won't be possible to have a non-plaintext label, and it
10571 * won't be possible to set a value (which will internally become identical to the label).
10573 OO
.ui
.ButtonInputWidget
= function OoUiButtonInputWidget( config
) {
10574 // Configuration initialization
10575 config
= $.extend( { type
: 'button', useInputTag
: false }, config
);
10577 // Properties (must be set before parent constructor, which calls #setValue)
10578 this.useInputTag
= config
.useInputTag
;
10580 // Parent constructor
10581 OO
.ui
.ButtonInputWidget
.super.call( this, config
);
10583 // Mixin constructors
10584 OO
.ui
.ButtonElement
.call( this, $.extend( {}, config
, { $button
: this.$input
} ) );
10585 OO
.ui
.IconElement
.call( this, config
);
10586 OO
.ui
.IndicatorElement
.call( this, config
);
10587 OO
.ui
.LabelElement
.call( this, config
);
10588 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$input
} ) );
10589 OO
.ui
.FlaggedElement
.call( this, config
);
10593 click
: this.onClick
.bind( this ),
10594 keypress
: this.onKeyPress
.bind( this )
10598 if ( !config
.useInputTag
) {
10599 this.$input
.append( this.$icon
, this.$label
, this.$indicator
);
10601 this.$element
.addClass( 'oo-ui-buttonInputWidget' );
10606 OO
.inheritClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.InputWidget
);
10607 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.ButtonElement
);
10608 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.IconElement
);
10609 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.IndicatorElement
);
10610 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.LabelElement
);
10611 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.TitledElement
);
10612 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.FlaggedElement
);
10626 OO
.ui
.ButtonInputWidget
.prototype.getInputElement = function ( config
) {
10627 var html
= '<' + ( config
.useInputTag
? 'input' : 'button' ) + ' type="' + config
.type
+ '">';
10628 return this.$( html
);
10634 * Overridden to support setting the 'value' of `<input/>` elements.
10636 * @param {jQuery|string|Function|null} label Label nodes; text; a function that returns nodes or
10637 * text; or null for no label
10640 OO
.ui
.ButtonInputWidget
.prototype.setLabel = function ( label
) {
10641 OO
.ui
.LabelElement
.prototype.setLabel
.call( this, label
);
10643 if ( this.useInputTag
) {
10644 if ( typeof label
=== 'function' ) {
10645 label
= OO
.ui
.resolveMsg( label
);
10647 if ( label
instanceof jQuery
) {
10648 label
= label
.text();
10653 this.$input
.val( label
);
10660 * Set the value of the input.
10662 * Overridden to disable for `<input/>` elements, which have value identical to the label.
10664 * @param {string} value New value
10667 OO
.ui
.ButtonInputWidget
.prototype.setValue = function ( value
) {
10668 if ( !this.useInputTag
) {
10669 OO
.ui
.ButtonInputWidget
.super.prototype.setValue
.call( this, value
);
10675 * Handles mouse click events.
10677 * @param {jQuery.Event} e Mouse click event
10680 OO
.ui
.ButtonInputWidget
.prototype.onClick = function () {
10681 if ( !this.isDisabled() ) {
10682 this.emit( 'click' );
10688 * Handles keypress events.
10690 * @param {jQuery.Event} e Keypress event
10693 OO
.ui
.ButtonInputWidget
.prototype.onKeyPress = function ( e
) {
10694 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
10695 this.emit( 'click' );
10701 * Checkbox input widget.
10704 * @extends OO.ui.InputWidget
10707 * @param {Object} [config] Configuration options
10708 * @cfg {boolean} [selected=false] Whether the checkbox is initially selected
10710 OO
.ui
.CheckboxInputWidget
= function OoUiCheckboxInputWidget( config
) {
10711 // Parent constructor
10712 OO
.ui
.CheckboxInputWidget
.super.call( this, config
);
10715 this.$element
.addClass( 'oo-ui-checkboxInputWidget' );
10716 this.setSelected( config
.selected
!== undefined ? config
.selected
: false );
10721 OO
.inheritClass( OO
.ui
.CheckboxInputWidget
, OO
.ui
.InputWidget
);
10729 OO
.ui
.CheckboxInputWidget
.prototype.getInputElement = function () {
10730 return this.$( '<input type="checkbox" />' );
10736 OO
.ui
.CheckboxInputWidget
.prototype.onEdit = function () {
10738 if ( !this.isDisabled() ) {
10739 // Allow the stack to clear so the value will be updated
10740 setTimeout( function () {
10741 widget
.setSelected( widget
.$input
.prop( 'checked' ) );
10747 * Set selection state of this checkbox.
10749 * @param {boolean} state Whether the checkbox is selected
10752 OO
.ui
.CheckboxInputWidget
.prototype.setSelected = function ( state
) {
10754 if ( this.selected
!== state
) {
10755 this.selected
= state
;
10756 this.$input
.prop( 'checked', this.selected
);
10757 this.emit( 'change', this.selected
);
10763 * Check if this checkbox is selected.
10765 * @return {boolean} Checkbox is selected
10767 OO
.ui
.CheckboxInputWidget
.prototype.isSelected = function () {
10768 // Resynchronize our internal data with DOM data. Other scripts executing on the page can modify
10769 // it, and we won't know unless they're kind enough to trigger a 'change' event.
10770 var selected
= this.$input
.prop( 'checked' );
10771 if ( this.selected
!== selected
) {
10772 this.setSelected( selected
);
10774 return this.selected
;
10778 * A OO.ui.DropdownWidget synchronized with a `<input type=hidden>` for form submission. Intended to
10779 * be used within a OO.ui.FormLayout.
10782 * @extends OO.ui.InputWidget
10785 * @param {Object} [config] Configuration options
10786 * @cfg {Object[]} [options=[]] Array of menu options in the format `{ data: …, label: … }`
10788 OO
.ui
.DropdownInputWidget
= function OoUiDropdownInputWidget( config
) {
10789 // Configuration initialization
10790 config
= config
|| {};
10792 // Properties (must be done before parent constructor which calls #setDisabled)
10793 this.dropdownWidget
= new OO
.ui
.DropdownWidget( {
10797 // Parent constructor
10798 OO
.ui
.DropdownInputWidget
.super.call( this, config
);
10801 this.dropdownWidget
.getMenu().connect( this, { select
: 'onMenuSelect' } );
10804 this.setOptions( config
.options
|| [] );
10806 .addClass( 'oo-ui-dropdownInputWidget' )
10807 .append( this.dropdownWidget
.$element
);
10812 OO
.inheritClass( OO
.ui
.DropdownInputWidget
, OO
.ui
.InputWidget
);
10820 OO
.ui
.DropdownInputWidget
.prototype.getInputElement = function () {
10821 return this.$( '<input type="hidden">' );
10825 * Handles menu select events.
10827 * @param {OO.ui.MenuOptionWidget} item Selected menu item
10829 OO
.ui
.DropdownInputWidget
.prototype.onMenuSelect = function ( item
) {
10830 this.setValue( item
.getData() );
10836 OO
.ui
.DropdownInputWidget
.prototype.setValue = function ( value
) {
10837 var item
= this.dropdownWidget
.getMenu().getItemFromData( value
);
10839 this.dropdownWidget
.getMenu().selectItem( item
);
10841 OO
.ui
.DropdownInputWidget
.super.prototype.setValue
.call( this, value
);
10848 OO
.ui
.DropdownInputWidget
.prototype.setDisabled = function ( state
) {
10849 this.dropdownWidget
.setDisabled( state
);
10850 OO
.ui
.DropdownInputWidget
.super.prototype.setDisabled
.call( this, state
);
10855 * Set the options available for this input.
10857 * @param {Object[]} options Array of menu options in the format `{ data: …, label: … }`
10860 OO
.ui
.DropdownInputWidget
.prototype.setOptions = function ( options
) {
10861 var value
= this.getValue();
10863 // Rebuild the dropdown menu
10864 this.dropdownWidget
.getMenu()
10866 .addItems( options
.map( function ( opt
) {
10867 return new OO
.ui
.MenuOptionWidget( {
10869 label
: opt
.label
!== undefined ? opt
.label
: opt
.data
10873 // Restore the previous value, or reset to something sensible
10874 if ( this.dropdownWidget
.getMenu().getItemFromData( value
) ) {
10875 // Previous value is still available, ensure consistency with the dropdown
10876 this.setValue( value
);
10878 // No longer valid, reset
10879 if ( options
.length
) {
10880 this.setValue( options
[ 0 ].data
);
10890 OO
.ui
.DropdownInputWidget
.prototype.focus = function () {
10891 this.dropdownWidget
.getMenu().toggle( true );
10898 OO
.ui
.DropdownInputWidget
.prototype.blur = function () {
10899 this.dropdownWidget
.getMenu().toggle( false );
10904 * Radio input widget.
10906 * Radio buttons only make sense as a set, and you probably want to use the OO.ui.RadioSelectWidget
10907 * class instead of using this class directly.
10910 * @extends OO.ui.InputWidget
10913 * @param {Object} [config] Configuration options
10914 * @cfg {boolean} [selected=false] Whether the radio button is initially selected
10916 OO
.ui
.RadioInputWidget
= function OoUiRadioInputWidget( config
) {
10917 // Parent constructor
10918 OO
.ui
.RadioInputWidget
.super.call( this, config
);
10921 this.$element
.addClass( 'oo-ui-radioInputWidget' );
10922 this.setSelected( config
.selected
!== undefined ? config
.selected
: false );
10927 OO
.inheritClass( OO
.ui
.RadioInputWidget
, OO
.ui
.InputWidget
);
10935 OO
.ui
.RadioInputWidget
.prototype.getInputElement = function () {
10936 return this.$( '<input type="radio" />' );
10942 OO
.ui
.RadioInputWidget
.prototype.onEdit = function () {
10943 // RadioInputWidget doesn't track its state.
10947 * Set selection state of this radio button.
10949 * @param {boolean} state Whether the button is selected
10952 OO
.ui
.RadioInputWidget
.prototype.setSelected = function ( state
) {
10953 // RadioInputWidget doesn't track its state.
10954 this.$input
.prop( 'checked', state
);
10959 * Check if this radio button is selected.
10961 * @return {boolean} Radio is selected
10963 OO
.ui
.RadioInputWidget
.prototype.isSelected = function () {
10964 return this.$input
.prop( 'checked' );
10968 * Input widget with a text field.
10971 * @extends OO.ui.InputWidget
10972 * @mixins OO.ui.IconElement
10973 * @mixins OO.ui.IndicatorElement
10974 * @mixins OO.ui.PendingElement
10977 * @param {Object} [config] Configuration options
10978 * @cfg {string} [type='text'] HTML tag `type` attribute
10979 * @cfg {string} [placeholder] Placeholder text
10980 * @cfg {boolean} [autofocus=false] Ask the browser to focus this widget, using the 'autofocus' HTML
10982 * @cfg {boolean} [readOnly=false] Prevent changes
10983 * @cfg {number} [maxLength] Maximum allowed number of characters to input
10984 * @cfg {boolean} [multiline=false] Allow multiple lines of text
10985 * @cfg {boolean} [autosize=false] Automatically resize to fit content
10986 * @cfg {boolean} [maxRows=10] Maximum number of rows to make visible when autosizing
10987 * @cfg {string} [labelPosition='after'] Label position, 'before' or 'after'
10988 * @cfg {RegExp|string} [validate] Regular expression to validate against (or symbolic name referencing
10989 * one, see #static-validationPatterns)
10991 OO
.ui
.TextInputWidget
= function OoUiTextInputWidget( config
) {
10992 // Configuration initialization
10993 config
= $.extend( {
10995 labelPosition
: 'after',
10999 // Parent constructor
11000 OO
.ui
.TextInputWidget
.super.call( this, config
);
11002 // Mixin constructors
11003 OO
.ui
.IconElement
.call( this, config
);
11004 OO
.ui
.IndicatorElement
.call( this, config
);
11005 OO
.ui
.PendingElement
.call( this, config
);
11006 OO
.ui
.LabelElement
.call( this, config
);
11009 this.readOnly
= false;
11010 this.multiline
= !!config
.multiline
;
11011 this.autosize
= !!config
.autosize
;
11012 this.maxRows
= config
.maxRows
;
11013 this.validate
= null;
11014 this.attached
= false;
11016 // Clone for resizing
11017 if ( this.autosize
) {
11018 this.$clone
= this.$input
11020 .insertAfter( this.$input
)
11024 this.setValidation( config
.validate
);
11025 this.setPosition( config
.labelPosition
);
11029 keypress
: this.onKeyPress
.bind( this ),
11030 blur
: this.setValidityFlag
.bind( this )
11032 this.$element
.on( 'DOMNodeInsertedIntoDocument', this.onElementAttach
.bind( this ) );
11033 this.$element
.on( 'DOMNodeRemovedFromDocument', this.onElementDetach
.bind( this ) );
11034 this.$icon
.on( 'mousedown', this.onIconMouseDown
.bind( this ) );
11035 this.$indicator
.on( 'mousedown', this.onIndicatorMouseDown
.bind( this ) );
11036 this.on( 'labelChange', this.updatePosition
.bind( this ) );
11040 .addClass( 'oo-ui-textInputWidget' )
11041 .append( this.$icon
, this.$indicator
, this.$label
);
11042 this.setReadOnly( !!config
.readOnly
);
11043 if ( config
.placeholder
) {
11044 this.$input
.attr( 'placeholder', config
.placeholder
);
11046 if ( config
.maxLength
) {
11047 this.$input
.attr( 'maxlength', config
.maxLength
);
11049 if ( config
.autofocus
) {
11050 this.$input
.attr( 'autofocus', 'autofocus' );
11056 OO
.inheritClass( OO
.ui
.TextInputWidget
, OO
.ui
.InputWidget
);
11057 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.IconElement
);
11058 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.IndicatorElement
);
11059 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.PendingElement
);
11060 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.LabelElement
);
11062 /* Static properties */
11064 OO
.ui
.TextInputWidget
.static.validationPatterns
= {
11072 * User presses enter inside the text box.
11074 * Not called if input is multiline.
11080 * User clicks the icon.
11086 * User clicks the indicator.
11094 * Handle icon mouse down events.
11096 * @param {jQuery.Event} e Mouse down event
11099 OO
.ui
.TextInputWidget
.prototype.onIconMouseDown = function ( e
) {
11100 if ( e
.which
=== 1 ) {
11101 this.$input
[ 0 ].focus();
11102 this.emit( 'icon' );
11108 * Handle indicator mouse down events.
11110 * @param {jQuery.Event} e Mouse down event
11113 OO
.ui
.TextInputWidget
.prototype.onIndicatorMouseDown = function ( e
) {
11114 if ( e
.which
=== 1 ) {
11115 this.$input
[ 0 ].focus();
11116 this.emit( 'indicator' );
11122 * Handle key press events.
11124 * @param {jQuery.Event} e Key press event
11125 * @fires enter If enter key is pressed and input is not multiline
11127 OO
.ui
.TextInputWidget
.prototype.onKeyPress = function ( e
) {
11128 if ( e
.which
=== OO
.ui
.Keys
.ENTER
&& !this.multiline
) {
11129 this.emit( 'enter', e
);
11134 * Handle element attach events.
11136 * @param {jQuery.Event} e Element attach event
11138 OO
.ui
.TextInputWidget
.prototype.onElementAttach = function () {
11139 this.attached
= true;
11140 // If we reattached elsewhere, the valCache is now invalid
11141 this.valCache
= null;
11143 this.positionLabel();
11147 * Handle element detach events.
11149 * @param {jQuery.Event} e Element detach event
11151 OO
.ui
.TextInputWidget
.prototype.onElementDetach = function () {
11152 this.attached
= false;
11158 OO
.ui
.TextInputWidget
.prototype.onEdit = function () {
11162 return OO
.ui
.TextInputWidget
.super.prototype.onEdit
.call( this );
11168 OO
.ui
.TextInputWidget
.prototype.setValue = function ( value
) {
11170 OO
.ui
.TextInputWidget
.super.prototype.setValue
.call( this, value
);
11172 this.setValidityFlag();
11178 * Check if the widget is read-only.
11180 * @return {boolean}
11182 OO
.ui
.TextInputWidget
.prototype.isReadOnly = function () {
11183 return this.readOnly
;
11187 * Set the read-only state of the widget.
11189 * This should probably change the widget's appearance and prevent it from being used.
11191 * @param {boolean} state Make input read-only
11194 OO
.ui
.TextInputWidget
.prototype.setReadOnly = function ( state
) {
11195 this.readOnly
= !!state
;
11196 this.$input
.prop( 'readOnly', this.readOnly
);
11201 * Automatically adjust the size of the text input.
11203 * This only affects multi-line inputs that are auto-sized.
11207 OO
.ui
.TextInputWidget
.prototype.adjustSize = function () {
11208 var scrollHeight
, innerHeight
, outerHeight
, maxInnerHeight
, measurementError
, idealHeight
;
11210 if ( this.multiline
&& this.autosize
&& this.attached
&& this.$input
.val() !== this.valCache
) {
11212 .val( this.$input
.val() )
11213 .attr( 'rows', '' )
11214 // Set inline height property to 0 to measure scroll height
11215 .css( 'height', 0 );
11217 this.$clone
[ 0 ].style
.display
= 'block';
11219 this.valCache
= this.$input
.val();
11221 scrollHeight
= this.$clone
[ 0 ].scrollHeight
;
11223 // Remove inline height property to measure natural heights
11224 this.$clone
.css( 'height', '' );
11225 innerHeight
= this.$clone
.innerHeight();
11226 outerHeight
= this.$clone
.outerHeight();
11228 // Measure max rows height
11230 .attr( 'rows', this.maxRows
)
11231 .css( 'height', 'auto' )
11233 maxInnerHeight
= this.$clone
.innerHeight();
11235 // Difference between reported innerHeight and scrollHeight with no scrollbars present
11236 // Equals 1 on Blink-based browsers and 0 everywhere else
11237 measurementError
= maxInnerHeight
- this.$clone
[ 0 ].scrollHeight
;
11238 idealHeight
= Math
.min( maxInnerHeight
, scrollHeight
+ measurementError
);
11240 this.$clone
[ 0 ].style
.display
= 'none';
11242 // Only apply inline height when expansion beyond natural height is needed
11243 if ( idealHeight
> innerHeight
) {
11244 // Use the difference between the inner and outer height as a buffer
11245 this.$input
.css( 'height', idealHeight
+ ( outerHeight
- innerHeight
) );
11247 this.$input
.css( 'height', '' );
11257 OO
.ui
.TextInputWidget
.prototype.getInputElement = function ( config
) {
11258 return config
.multiline
? this.$( '<textarea>' ) : this.$( '<input type="' + config
.type
+ '" />' );
11262 * Check if input supports multiple lines.
11264 * @return {boolean}
11266 OO
.ui
.TextInputWidget
.prototype.isMultiline = function () {
11267 return !!this.multiline
;
11271 * Check if input automatically adjusts its size.
11273 * @return {boolean}
11275 OO
.ui
.TextInputWidget
.prototype.isAutosizing = function () {
11276 return !!this.autosize
;
11280 * Select the contents of the input.
11284 OO
.ui
.TextInputWidget
.prototype.select = function () {
11285 this.$input
.select();
11290 * Sets the validation pattern to use.
11291 * @param {RegExp|string|null} validate Regular expression (or symbolic name referencing
11292 * one, see #static-validationPatterns)
11294 OO
.ui
.TextInputWidget
.prototype.setValidation = function ( validate
) {
11295 if ( validate
instanceof RegExp
) {
11296 this.validate
= validate
;
11298 this.validate
= this.constructor.static.validationPatterns
[ validate
] || /.*/;
11303 * Sets the 'invalid' flag appropriately.
11305 OO
.ui
.TextInputWidget
.prototype.setValidityFlag = function () {
11307 this.isValid().done( function ( valid
) {
11308 widget
.setFlags( { invalid
: !valid
} );
11313 * Returns whether or not the current value is considered valid, according to the
11314 * supplied validation pattern.
11316 * @return {jQuery.Deferred}
11318 OO
.ui
.TextInputWidget
.prototype.isValid = function () {
11319 return $.Deferred().resolve( !!this.getValue().match( this.validate
) ).promise();
11323 * Set the position of the inline label.
11325 * @param {string} labelPosition Label position, 'before' or 'after'
11328 OO
.ui
.TextInputWidget
.prototype.setPosition = function ( labelPosition
) {
11329 this.labelPosition
= labelPosition
;
11330 this.updatePosition();
11335 * Update the position of the inline label.
11339 OO
.ui
.TextInputWidget
.prototype.updatePosition = function () {
11340 var after
= this.labelPosition
=== 'after';
11343 .toggleClass( 'oo-ui-textInputWidget-labelPosition-after', this.label
&& after
)
11344 .toggleClass( 'oo-ui-textInputWidget-labelPosition-before', this.label
&& !after
);
11346 if ( this.label
) {
11347 this.positionLabel();
11354 * Position the label by setting the correct padding on the input.
11358 OO
.ui
.TextInputWidget
.prototype.positionLabel = function () {
11359 // Clear old values
11361 // Clear old values if present
11363 'padding-right': '',
11367 if ( !this.$label
.text() ) {
11371 var after
= this.labelPosition
=== 'after',
11372 rtl
= this.$element
.css( 'direction' ) === 'rtl',
11373 property
= after
=== rtl
? 'padding-left' : 'padding-right';
11375 this.$input
.css( property
, this.$label
.outerWidth() );
11381 * Text input with a menu of optional values.
11384 * @extends OO.ui.Widget
11387 * @param {Object} [config] Configuration options
11388 * @cfg {Object} [menu] Configuration options to pass to menu widget
11389 * @cfg {Object} [input] Configuration options to pass to input widget
11390 * @cfg {jQuery} [$overlay] Overlay layer; defaults to relative positioning
11392 OO
.ui
.ComboBoxWidget
= function OoUiComboBoxWidget( config
) {
11393 // Configuration initialization
11394 config
= config
|| {};
11396 // Parent constructor
11397 OO
.ui
.ComboBoxWidget
.super.call( this, config
);
11400 this.$overlay
= config
.$overlay
|| this.$element
;
11401 this.input
= new OO
.ui
.TextInputWidget( $.extend(
11402 { $: this.$, indicator
: 'down', disabled
: this.isDisabled() },
11405 this.menu
= new OO
.ui
.TextInputMenuSelectWidget( this.input
, $.extend(
11407 $: OO
.ui
.Element
.static.getJQuery( this.$overlay
),
11410 disabled
: this.isDisabled()
11416 this.input
.connect( this, {
11417 change
: 'onInputChange',
11418 indicator
: 'onInputIndicator',
11419 enter
: 'onInputEnter'
11421 this.menu
.connect( this, {
11422 choose
: 'onMenuChoose',
11423 add
: 'onMenuItemsChange',
11424 remove
: 'onMenuItemsChange'
11428 this.$element
.addClass( 'oo-ui-comboBoxWidget' ).append( this.input
.$element
);
11429 this.$overlay
.append( this.menu
.$element
);
11430 this.onMenuItemsChange();
11435 OO
.inheritClass( OO
.ui
.ComboBoxWidget
, OO
.ui
.Widget
);
11440 * Get the combobox's menu.
11441 * @return {OO.ui.TextInputMenuSelectWidget} Menu widget
11443 OO
.ui
.ComboBoxWidget
.prototype.getMenu = function () {
11448 * Handle input change events.
11450 * @param {string} value New value
11452 OO
.ui
.ComboBoxWidget
.prototype.onInputChange = function ( value
) {
11453 var match
= this.menu
.getItemFromData( value
);
11455 this.menu
.selectItem( match
);
11457 if ( !this.isDisabled() ) {
11458 this.menu
.toggle( true );
11463 * Handle input indicator events.
11465 OO
.ui
.ComboBoxWidget
.prototype.onInputIndicator = function () {
11466 if ( !this.isDisabled() ) {
11467 this.menu
.toggle();
11472 * Handle input enter events.
11474 OO
.ui
.ComboBoxWidget
.prototype.onInputEnter = function () {
11475 if ( !this.isDisabled() ) {
11476 this.menu
.toggle( false );
11481 * Handle menu choose events.
11483 * @param {OO.ui.OptionWidget} item Chosen item
11485 OO
.ui
.ComboBoxWidget
.prototype.onMenuChoose = function ( item
) {
11487 this.input
.setValue( item
.getData() );
11492 * Handle menu item change events.
11494 OO
.ui
.ComboBoxWidget
.prototype.onMenuItemsChange = function () {
11495 var match
= this.menu
.getItemFromData( this.input
.getValue() );
11496 this.menu
.selectItem( match
);
11497 this.$element
.toggleClass( 'oo-ui-comboBoxWidget-empty', this.menu
.isEmpty() );
11503 OO
.ui
.ComboBoxWidget
.prototype.setDisabled = function ( disabled
) {
11505 OO
.ui
.ComboBoxWidget
.super.prototype.setDisabled
.call( this, disabled
);
11507 if ( this.input
) {
11508 this.input
.setDisabled( this.isDisabled() );
11511 this.menu
.setDisabled( this.isDisabled() );
11521 * @extends OO.ui.Widget
11522 * @mixins OO.ui.LabelElement
11525 * @param {Object} [config] Configuration options
11526 * @cfg {OO.ui.InputWidget} [input] Input widget this label is for
11528 OO
.ui
.LabelWidget
= function OoUiLabelWidget( config
) {
11529 // Configuration initialization
11530 config
= config
|| {};
11532 // Parent constructor
11533 OO
.ui
.LabelWidget
.super.call( this, config
);
11535 // Mixin constructors
11536 OO
.ui
.LabelElement
.call( this, $.extend( {}, config
, { $label
: this.$element
} ) );
11537 OO
.ui
.TitledElement
.call( this, config
);
11540 this.input
= config
.input
;
11543 if ( this.input
instanceof OO
.ui
.InputWidget
) {
11544 this.$element
.on( 'click', this.onClick
.bind( this ) );
11548 this.$element
.addClass( 'oo-ui-labelWidget' );
11553 OO
.inheritClass( OO
.ui
.LabelWidget
, OO
.ui
.Widget
);
11554 OO
.mixinClass( OO
.ui
.LabelWidget
, OO
.ui
.LabelElement
);
11555 OO
.mixinClass( OO
.ui
.LabelWidget
, OO
.ui
.TitledElement
);
11557 /* Static Properties */
11559 OO
.ui
.LabelWidget
.static.tagName
= 'span';
11564 * Handles label mouse click events.
11566 * @param {jQuery.Event} e Mouse click event
11568 OO
.ui
.LabelWidget
.prototype.onClick = function () {
11569 this.input
.simulateLabelClick();
11574 * Generic option widget for use with OO.ui.SelectWidget.
11577 * @extends OO.ui.Widget
11578 * @mixins OO.ui.LabelElement
11579 * @mixins OO.ui.FlaggedElement
11582 * @param {Object} [config] Configuration options
11584 OO
.ui
.OptionWidget
= function OoUiOptionWidget( config
) {
11585 // Configuration initialization
11586 config
= config
|| {};
11588 // Parent constructor
11589 OO
.ui
.OptionWidget
.super.call( this, config
);
11591 // Mixin constructors
11592 OO
.ui
.ItemWidget
.call( this );
11593 OO
.ui
.LabelElement
.call( this, config
);
11594 OO
.ui
.FlaggedElement
.call( this, config
);
11597 this.selected
= false;
11598 this.highlighted
= false;
11599 this.pressed
= false;
11603 .data( 'oo-ui-optionWidget', this )
11604 .attr( 'role', 'option' )
11605 .addClass( 'oo-ui-optionWidget' )
11606 .append( this.$label
);
11611 OO
.inheritClass( OO
.ui
.OptionWidget
, OO
.ui
.Widget
);
11612 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.ItemWidget
);
11613 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.LabelElement
);
11614 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.FlaggedElement
);
11616 /* Static Properties */
11618 OO
.ui
.OptionWidget
.static.selectable
= true;
11620 OO
.ui
.OptionWidget
.static.highlightable
= true;
11622 OO
.ui
.OptionWidget
.static.pressable
= true;
11624 OO
.ui
.OptionWidget
.static.scrollIntoViewOnSelect
= false;
11629 * Check if option can be selected.
11631 * @return {boolean} Item is selectable
11633 OO
.ui
.OptionWidget
.prototype.isSelectable = function () {
11634 return this.constructor.static.selectable
&& !this.isDisabled();
11638 * Check if option can be highlighted.
11640 * @return {boolean} Item is highlightable
11642 OO
.ui
.OptionWidget
.prototype.isHighlightable = function () {
11643 return this.constructor.static.highlightable
&& !this.isDisabled();
11647 * Check if option can be pressed.
11649 * @return {boolean} Item is pressable
11651 OO
.ui
.OptionWidget
.prototype.isPressable = function () {
11652 return this.constructor.static.pressable
&& !this.isDisabled();
11656 * Check if option is selected.
11658 * @return {boolean} Item is selected
11660 OO
.ui
.OptionWidget
.prototype.isSelected = function () {
11661 return this.selected
;
11665 * Check if option is highlighted.
11667 * @return {boolean} Item is highlighted
11669 OO
.ui
.OptionWidget
.prototype.isHighlighted = function () {
11670 return this.highlighted
;
11674 * Check if option is pressed.
11676 * @return {boolean} Item is pressed
11678 OO
.ui
.OptionWidget
.prototype.isPressed = function () {
11679 return this.pressed
;
11683 * Set selected state.
11685 * @param {boolean} [state=false] Select option
11688 OO
.ui
.OptionWidget
.prototype.setSelected = function ( state
) {
11689 if ( this.constructor.static.selectable
) {
11690 this.selected
= !!state
;
11691 this.$element
.toggleClass( 'oo-ui-optionWidget-selected', state
);
11692 if ( state
&& this.constructor.static.scrollIntoViewOnSelect
) {
11693 this.scrollElementIntoView();
11695 this.updateThemeClasses();
11701 * Set highlighted state.
11703 * @param {boolean} [state=false] Highlight option
11706 OO
.ui
.OptionWidget
.prototype.setHighlighted = function ( state
) {
11707 if ( this.constructor.static.highlightable
) {
11708 this.highlighted
= !!state
;
11709 this.$element
.toggleClass( 'oo-ui-optionWidget-highlighted', state
);
11710 this.updateThemeClasses();
11716 * Set pressed state.
11718 * @param {boolean} [state=false] Press option
11721 OO
.ui
.OptionWidget
.prototype.setPressed = function ( state
) {
11722 if ( this.constructor.static.pressable
) {
11723 this.pressed
= !!state
;
11724 this.$element
.toggleClass( 'oo-ui-optionWidget-pressed', state
);
11725 this.updateThemeClasses();
11731 * Option widget with an option icon and indicator.
11733 * Use together with OO.ui.SelectWidget.
11736 * @extends OO.ui.OptionWidget
11737 * @mixins OO.ui.IconElement
11738 * @mixins OO.ui.IndicatorElement
11741 * @param {Object} [config] Configuration options
11743 OO
.ui
.DecoratedOptionWidget
= function OoUiDecoratedOptionWidget( config
) {
11744 // Parent constructor
11745 OO
.ui
.DecoratedOptionWidget
.super.call( this, config
);
11747 // Mixin constructors
11748 OO
.ui
.IconElement
.call( this, config
);
11749 OO
.ui
.IndicatorElement
.call( this, config
);
11753 .addClass( 'oo-ui-decoratedOptionWidget' )
11754 .prepend( this.$icon
)
11755 .append( this.$indicator
);
11760 OO
.inheritClass( OO
.ui
.DecoratedOptionWidget
, OO
.ui
.OptionWidget
);
11761 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.IconElement
);
11762 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.IndicatorElement
);
11765 * Option widget that looks like a button.
11767 * Use together with OO.ui.ButtonSelectWidget.
11770 * @extends OO.ui.DecoratedOptionWidget
11771 * @mixins OO.ui.ButtonElement
11772 * @mixins OO.ui.TabIndexedElement
11775 * @param {Object} [config] Configuration options
11777 OO
.ui
.ButtonOptionWidget
= function OoUiButtonOptionWidget( config
) {
11778 // Parent constructor
11779 OO
.ui
.ButtonOptionWidget
.super.call( this, config
);
11781 // Mixin constructors
11782 OO
.ui
.ButtonElement
.call( this, config
);
11783 OO
.ui
.TabIndexedElement
.call( this, $.extend( {}, config
, { $tabIndexed
: this.$button
} ) );
11786 this.$element
.addClass( 'oo-ui-buttonOptionWidget' );
11787 this.$button
.append( this.$element
.contents() );
11788 this.$element
.append( this.$button
);
11793 OO
.inheritClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
11794 OO
.mixinClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.ButtonElement
);
11795 OO
.mixinClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.TabIndexedElement
);
11797 /* Static Properties */
11799 // Allow button mouse down events to pass through so they can be handled by the parent select widget
11800 OO
.ui
.ButtonOptionWidget
.static.cancelButtonMouseDownEvents
= false;
11807 OO
.ui
.ButtonOptionWidget
.prototype.setSelected = function ( state
) {
11808 OO
.ui
.ButtonOptionWidget
.super.prototype.setSelected
.call( this, state
);
11810 if ( this.constructor.static.selectable
) {
11811 this.setActive( state
);
11818 * Option widget that looks like a radio button.
11820 * Use together with OO.ui.RadioSelectWidget.
11823 * @extends OO.ui.OptionWidget
11826 * @param {Object} [config] Configuration options
11828 OO
.ui
.RadioOptionWidget
= function OoUiRadioOptionWidget( config
) {
11829 // Parent constructor
11830 OO
.ui
.RadioOptionWidget
.super.call( this, config
);
11833 this.radio
= new OO
.ui
.RadioInputWidget( { value
: config
.data
} );
11837 .addClass( 'oo-ui-radioOptionWidget' )
11838 .prepend( this.radio
.$element
);
11843 OO
.inheritClass( OO
.ui
.RadioOptionWidget
, OO
.ui
.OptionWidget
);
11845 /* Static Properties */
11847 OO
.ui
.RadioOptionWidget
.static.highlightable
= false;
11849 OO
.ui
.RadioOptionWidget
.static.pressable
= false;
11856 OO
.ui
.RadioOptionWidget
.prototype.setSelected = function ( state
) {
11857 OO
.ui
.RadioOptionWidget
.super.prototype.setSelected
.call( this, state
);
11859 this.radio
.setSelected( state
);
11865 * Item of an OO.ui.MenuSelectWidget.
11868 * @extends OO.ui.DecoratedOptionWidget
11871 * @param {Object} [config] Configuration options
11873 OO
.ui
.MenuOptionWidget
= function OoUiMenuOptionWidget( config
) {
11874 // Configuration initialization
11875 config
= $.extend( { icon
: 'check' }, config
);
11877 // Parent constructor
11878 OO
.ui
.MenuOptionWidget
.super.call( this, config
);
11882 .attr( 'role', 'menuitem' )
11883 .addClass( 'oo-ui-menuOptionWidget' );
11888 OO
.inheritClass( OO
.ui
.MenuOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
11891 * Section to group one or more items in a OO.ui.MenuSelectWidget.
11894 * @extends OO.ui.DecoratedOptionWidget
11897 * @param {Object} [config] Configuration options
11899 OO
.ui
.MenuSectionOptionWidget
= function OoUiMenuSectionOptionWidget( config
) {
11900 // Parent constructor
11901 OO
.ui
.MenuSectionOptionWidget
.super.call( this, config
);
11904 this.$element
.addClass( 'oo-ui-menuSectionOptionWidget' );
11909 OO
.inheritClass( OO
.ui
.MenuSectionOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
11911 /* Static Properties */
11913 OO
.ui
.MenuSectionOptionWidget
.static.selectable
= false;
11915 OO
.ui
.MenuSectionOptionWidget
.static.highlightable
= false;
11918 * Items for an OO.ui.OutlineSelectWidget.
11921 * @extends OO.ui.DecoratedOptionWidget
11924 * @param {Object} [config] Configuration options
11925 * @cfg {number} [level] Indentation level
11926 * @cfg {boolean} [movable] Allow modification from outline controls
11928 OO
.ui
.OutlineOptionWidget
= function OoUiOutlineOptionWidget( config
) {
11929 // Configuration initialization
11930 config
= config
|| {};
11932 // Parent constructor
11933 OO
.ui
.OutlineOptionWidget
.super.call( this, config
);
11937 this.movable
= !!config
.movable
;
11938 this.removable
= !!config
.removable
;
11941 this.$element
.addClass( 'oo-ui-outlineOptionWidget' );
11942 this.setLevel( config
.level
);
11947 OO
.inheritClass( OO
.ui
.OutlineOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
11949 /* Static Properties */
11951 OO
.ui
.OutlineOptionWidget
.static.highlightable
= false;
11953 OO
.ui
.OutlineOptionWidget
.static.scrollIntoViewOnSelect
= true;
11955 OO
.ui
.OutlineOptionWidget
.static.levelClass
= 'oo-ui-outlineOptionWidget-level-';
11957 OO
.ui
.OutlineOptionWidget
.static.levels
= 3;
11962 * Check if item is movable.
11964 * Movability is used by outline controls.
11966 * @return {boolean} Item is movable
11968 OO
.ui
.OutlineOptionWidget
.prototype.isMovable = function () {
11969 return this.movable
;
11973 * Check if item is removable.
11975 * Removability is used by outline controls.
11977 * @return {boolean} Item is removable
11979 OO
.ui
.OutlineOptionWidget
.prototype.isRemovable = function () {
11980 return this.removable
;
11984 * Get indentation level.
11986 * @return {number} Indentation level
11988 OO
.ui
.OutlineOptionWidget
.prototype.getLevel = function () {
11995 * Movability is used by outline controls.
11997 * @param {boolean} movable Item is movable
12000 OO
.ui
.OutlineOptionWidget
.prototype.setMovable = function ( movable
) {
12001 this.movable
= !!movable
;
12002 this.updateThemeClasses();
12007 * Set removability.
12009 * Removability is used by outline controls.
12011 * @param {boolean} movable Item is removable
12014 OO
.ui
.OutlineOptionWidget
.prototype.setRemovable = function ( removable
) {
12015 this.removable
= !!removable
;
12016 this.updateThemeClasses();
12021 * Set indentation level.
12023 * @param {number} [level=0] Indentation level, in the range of [0,#maxLevel]
12026 OO
.ui
.OutlineOptionWidget
.prototype.setLevel = function ( level
) {
12027 var levels
= this.constructor.static.levels
,
12028 levelClass
= this.constructor.static.levelClass
,
12031 this.level
= level
? Math
.max( 0, Math
.min( levels
- 1, level
) ) : 0;
12033 if ( this.level
=== i
) {
12034 this.$element
.addClass( levelClass
+ i
);
12036 this.$element
.removeClass( levelClass
+ i
);
12039 this.updateThemeClasses();
12045 * Container for content that is overlaid and positioned absolutely.
12048 * @extends OO.ui.Widget
12049 * @mixins OO.ui.LabelElement
12052 * @param {Object} [config] Configuration options
12053 * @cfg {number} [width=320] Width of popup in pixels
12054 * @cfg {number} [height] Height of popup, omit to use automatic height
12055 * @cfg {boolean} [anchor=true] Show anchor pointing to origin of popup
12056 * @cfg {string} [align='center'] Alignment of popup to origin
12057 * @cfg {jQuery} [$container] Container to prevent popup from rendering outside of
12058 * @cfg {number} [containerPadding=10] How much padding to keep between popup and container
12059 * @cfg {jQuery} [$content] Content to append to the popup's body
12060 * @cfg {boolean} [autoClose=false] Popup auto-closes when it loses focus
12061 * @cfg {jQuery} [$autoCloseIgnore] Elements to not auto close when clicked
12062 * @cfg {boolean} [head] Show label and close button at the top
12063 * @cfg {boolean} [padded] Add padding to the body
12065 OO
.ui
.PopupWidget
= function OoUiPopupWidget( config
) {
12066 // Configuration initialization
12067 config
= config
|| {};
12069 // Parent constructor
12070 OO
.ui
.PopupWidget
.super.call( this, config
);
12072 // Mixin constructors
12073 OO
.ui
.LabelElement
.call( this, config
);
12074 OO
.ui
.ClippableElement
.call( this, config
);
12077 this.visible
= false;
12078 this.$popup
= this.$( '<div>' );
12079 this.$head
= this.$( '<div>' );
12080 this.$body
= this.$( '<div>' );
12081 this.$anchor
= this.$( '<div>' );
12082 // If undefined, will be computed lazily in updateDimensions()
12083 this.$container
= config
.$container
;
12084 this.containerPadding
= config
.containerPadding
!== undefined ? config
.containerPadding
: 10;
12085 this.autoClose
= !!config
.autoClose
;
12086 this.$autoCloseIgnore
= config
.$autoCloseIgnore
;
12087 this.transitionTimeout
= null;
12088 this.anchor
= null;
12089 this.width
= config
.width
!== undefined ? config
.width
: 320;
12090 this.height
= config
.height
!== undefined ? config
.height
: null;
12091 this.align
= config
.align
|| 'center';
12092 this.closeButton
= new OO
.ui
.ButtonWidget( { $: this.$, framed
: false, icon
: 'close' } );
12093 this.onMouseDownHandler
= this.onMouseDown
.bind( this );
12096 this.closeButton
.connect( this, { click
: 'onCloseButtonClick' } );
12099 this.toggleAnchor( config
.anchor
=== undefined || config
.anchor
);
12100 this.$body
.addClass( 'oo-ui-popupWidget-body' );
12101 this.$anchor
.addClass( 'oo-ui-popupWidget-anchor' );
12103 .addClass( 'oo-ui-popupWidget-head' )
12104 .append( this.$label
, this.closeButton
.$element
);
12105 if ( !config
.head
) {
12109 .addClass( 'oo-ui-popupWidget-popup' )
12110 .append( this.$head
, this.$body
);
12113 .addClass( 'oo-ui-popupWidget' )
12114 .append( this.$popup
, this.$anchor
);
12115 // Move content, which was added to #$element by OO.ui.Widget, to the body
12116 if ( config
.$content
instanceof jQuery
) {
12117 this.$body
.append( config
.$content
);
12119 if ( config
.padded
) {
12120 this.$body
.addClass( 'oo-ui-popupWidget-body-padded' );
12122 this.setClippableElement( this.$body
);
12127 OO
.inheritClass( OO
.ui
.PopupWidget
, OO
.ui
.Widget
);
12128 OO
.mixinClass( OO
.ui
.PopupWidget
, OO
.ui
.LabelElement
);
12129 OO
.mixinClass( OO
.ui
.PopupWidget
, OO
.ui
.ClippableElement
);
12134 * Handles mouse down events.
12136 * @param {jQuery.Event} e Mouse down event
12138 OO
.ui
.PopupWidget
.prototype.onMouseDown = function ( e
) {
12140 this.isVisible() &&
12141 !$.contains( this.$element
[ 0 ], e
.target
) &&
12142 ( !this.$autoCloseIgnore
|| !this.$autoCloseIgnore
.has( e
.target
).length
)
12144 this.toggle( false );
12149 * Bind mouse down listener.
12151 OO
.ui
.PopupWidget
.prototype.bindMouseDownListener = function () {
12152 // Capture clicks outside popup
12153 this.getElementWindow().addEventListener( 'mousedown', this.onMouseDownHandler
, true );
12157 * Handles close button click events.
12159 OO
.ui
.PopupWidget
.prototype.onCloseButtonClick = function () {
12160 if ( this.isVisible() ) {
12161 this.toggle( false );
12166 * Unbind mouse down listener.
12168 OO
.ui
.PopupWidget
.prototype.unbindMouseDownListener = function () {
12169 this.getElementWindow().removeEventListener( 'mousedown', this.onMouseDownHandler
, true );
12173 * Set whether to show a anchor.
12175 * @param {boolean} [show] Show anchor, omit to toggle
12177 OO
.ui
.PopupWidget
.prototype.toggleAnchor = function ( show
) {
12178 show
= show
=== undefined ? !this.anchored
: !!show
;
12180 if ( this.anchored
!== show
) {
12182 this.$element
.addClass( 'oo-ui-popupWidget-anchored' );
12184 this.$element
.removeClass( 'oo-ui-popupWidget-anchored' );
12186 this.anchored
= show
;
12191 * Check if showing a anchor.
12193 * @return {boolean} anchor is visible
12195 OO
.ui
.PopupWidget
.prototype.hasAnchor = function () {
12196 return this.anchor
;
12202 OO
.ui
.PopupWidget
.prototype.toggle = function ( show
) {
12203 show
= show
=== undefined ? !this.isVisible() : !!show
;
12205 var change
= show
!== this.isVisible();
12208 OO
.ui
.PopupWidget
.super.prototype.toggle
.call( this, show
);
12212 if ( this.autoClose
) {
12213 this.bindMouseDownListener();
12215 this.updateDimensions();
12216 this.toggleClipping( true );
12218 this.toggleClipping( false );
12219 if ( this.autoClose
) {
12220 this.unbindMouseDownListener();
12229 * Set the size of the popup.
12231 * Changing the size may also change the popup's position depending on the alignment.
12233 * @param {number} width Width
12234 * @param {number} height Height
12235 * @param {boolean} [transition=false] Use a smooth transition
12238 OO
.ui
.PopupWidget
.prototype.setSize = function ( width
, height
, transition
) {
12239 this.width
= width
;
12240 this.height
= height
!== undefined ? height
: null;
12241 if ( this.isVisible() ) {
12242 this.updateDimensions( transition
);
12247 * Update the size and position.
12249 * Only use this to keep the popup properly anchored. Use #setSize to change the size, and this will
12250 * be called automatically.
12252 * @param {boolean} [transition=false] Use a smooth transition
12255 OO
.ui
.PopupWidget
.prototype.updateDimensions = function ( transition
) {
12256 var popupOffset
, originOffset
, containerLeft
, containerWidth
, containerRight
,
12257 popupLeft
, popupRight
, overlapLeft
, overlapRight
, anchorWidth
,
12260 if ( !this.$container
) {
12261 // Lazy-initialize $container if not specified in constructor
12262 this.$container
= this.$( this.getClosestScrollableElementContainer() );
12265 // Set height and width before measuring things, since it might cause our measurements
12266 // to change (e.g. due to scrollbars appearing or disappearing)
12269 height
: this.height
!== null ? this.height
: 'auto'
12272 // Compute initial popupOffset based on alignment
12273 popupOffset
= this.width
* ( { left
: 0, center
: -0.5, right
: -1 } )[ this.align
];
12275 // Figure out if this will cause the popup to go beyond the edge of the container
12276 originOffset
= this.$element
.offset().left
;
12277 containerLeft
= this.$container
.offset().left
;
12278 containerWidth
= this.$container
.innerWidth();
12279 containerRight
= containerLeft
+ containerWidth
;
12280 popupLeft
= popupOffset
- this.containerPadding
;
12281 popupRight
= popupOffset
+ this.containerPadding
+ this.width
+ this.containerPadding
;
12282 overlapLeft
= ( originOffset
+ popupLeft
) - containerLeft
;
12283 overlapRight
= containerRight
- ( originOffset
+ popupRight
);
12285 // Adjust offset to make the popup not go beyond the edge, if needed
12286 if ( overlapRight
< 0 ) {
12287 popupOffset
+= overlapRight
;
12288 } else if ( overlapLeft
< 0 ) {
12289 popupOffset
-= overlapLeft
;
12292 // Adjust offset to avoid anchor being rendered too close to the edge
12293 // $anchor.width() doesn't work with the pure CSS anchor (returns 0)
12294 // TODO: Find a measurement that works for CSS anchors and image anchors
12295 anchorWidth
= this.$anchor
[ 0 ].scrollWidth
* 2;
12296 if ( popupOffset
+ this.width
< anchorWidth
) {
12297 popupOffset
= anchorWidth
- this.width
;
12298 } else if ( -popupOffset
< anchorWidth
) {
12299 popupOffset
= -anchorWidth
;
12302 // Prevent transition from being interrupted
12303 clearTimeout( this.transitionTimeout
);
12304 if ( transition
) {
12305 // Enable transition
12306 this.$element
.addClass( 'oo-ui-popupWidget-transitioning' );
12309 // Position body relative to anchor
12310 this.$popup
.css( 'margin-left', popupOffset
);
12312 if ( transition
) {
12313 // Prevent transitioning after transition is complete
12314 this.transitionTimeout
= setTimeout( function () {
12315 widget
.$element
.removeClass( 'oo-ui-popupWidget-transitioning' );
12318 // Prevent transitioning immediately
12319 this.$element
.removeClass( 'oo-ui-popupWidget-transitioning' );
12322 // Reevaluate clipping state since we've relocated and resized the popup
12329 * Progress bar widget.
12332 * @extends OO.ui.Widget
12335 * @param {Object} [config] Configuration options
12336 * @cfg {number|boolean} [progress=false] Initial progress percent or false for indeterminate
12338 OO
.ui
.ProgressBarWidget
= function OoUiProgressBarWidget( config
) {
12339 // Configuration initialization
12340 config
= config
|| {};
12342 // Parent constructor
12343 OO
.ui
.ProgressBarWidget
.super.call( this, config
);
12346 this.$bar
= this.$( '<div>' );
12347 this.progress
= null;
12350 this.setProgress( config
.progress
!== undefined ? config
.progress
: false );
12351 this.$bar
.addClass( 'oo-ui-progressBarWidget-bar' );
12354 role
: 'progressbar',
12355 'aria-valuemin': 0,
12356 'aria-valuemax': 100
12358 .addClass( 'oo-ui-progressBarWidget' )
12359 .append( this.$bar
);
12364 OO
.inheritClass( OO
.ui
.ProgressBarWidget
, OO
.ui
.Widget
);
12366 /* Static Properties */
12368 OO
.ui
.ProgressBarWidget
.static.tagName
= 'div';
12373 * Get progress percent
12375 * @return {number} Progress percent
12377 OO
.ui
.ProgressBarWidget
.prototype.getProgress = function () {
12378 return this.progress
;
12382 * Set progress percent
12384 * @param {number|boolean} progress Progress percent or false for indeterminate
12386 OO
.ui
.ProgressBarWidget
.prototype.setProgress = function ( progress
) {
12387 this.progress
= progress
;
12389 if ( progress
!== false ) {
12390 this.$bar
.css( 'width', this.progress
+ '%' );
12391 this.$element
.attr( 'aria-valuenow', this.progress
);
12393 this.$bar
.css( 'width', '' );
12394 this.$element
.removeAttr( 'aria-valuenow' );
12396 this.$element
.toggleClass( 'oo-ui-progressBarWidget-indeterminate', !progress
);
12402 * Search widgets combine a query input, placed above, and a results selection widget, placed below.
12403 * Results are cleared and populated each time the query is changed.
12406 * @extends OO.ui.Widget
12409 * @param {Object} [config] Configuration options
12410 * @cfg {string|jQuery} [placeholder] Placeholder text for query input
12411 * @cfg {string} [value] Initial query value
12413 OO
.ui
.SearchWidget
= function OoUiSearchWidget( config
) {
12414 // Configuration initialization
12415 config
= config
|| {};
12417 // Parent constructor
12418 OO
.ui
.SearchWidget
.super.call( this, config
);
12421 this.query
= new OO
.ui
.TextInputWidget( {
12424 placeholder
: config
.placeholder
,
12425 value
: config
.value
12427 this.results
= new OO
.ui
.SelectWidget( { $: this.$ } );
12428 this.$query
= this.$( '<div>' );
12429 this.$results
= this.$( '<div>' );
12432 this.query
.connect( this, {
12433 change
: 'onQueryChange',
12434 enter
: 'onQueryEnter'
12436 this.results
.connect( this, {
12437 highlight
: 'onResultsHighlight',
12438 select
: 'onResultsSelect'
12440 this.query
.$input
.on( 'keydown', this.onQueryKeydown
.bind( this ) );
12444 .addClass( 'oo-ui-searchWidget-query' )
12445 .append( this.query
.$element
);
12447 .addClass( 'oo-ui-searchWidget-results' )
12448 .append( this.results
.$element
);
12450 .addClass( 'oo-ui-searchWidget' )
12451 .append( this.$results
, this.$query
);
12456 OO
.inheritClass( OO
.ui
.SearchWidget
, OO
.ui
.Widget
);
12462 * @param {Object|null} item Item data or null if no item is highlighted
12467 * @param {Object|null} item Item data or null if no item is selected
12473 * Handle query key down events.
12475 * @param {jQuery.Event} e Key down event
12477 OO
.ui
.SearchWidget
.prototype.onQueryKeydown = function ( e
) {
12478 var highlightedItem
, nextItem
,
12479 dir
= e
.which
=== OO
.ui
.Keys
.DOWN
? 1 : ( e
.which
=== OO
.ui
.Keys
.UP
? -1 : 0 );
12482 highlightedItem
= this.results
.getHighlightedItem();
12483 if ( !highlightedItem
) {
12484 highlightedItem
= this.results
.getSelectedItem();
12486 nextItem
= this.results
.getRelativeSelectableItem( highlightedItem
, dir
);
12487 this.results
.highlightItem( nextItem
);
12488 nextItem
.scrollElementIntoView();
12493 * Handle select widget select events.
12495 * Clears existing results. Subclasses should repopulate items according to new query.
12497 * @param {string} value New value
12499 OO
.ui
.SearchWidget
.prototype.onQueryChange = function () {
12501 this.results
.clearItems();
12505 * Handle select widget enter key events.
12507 * Selects highlighted item.
12509 * @param {string} value New value
12511 OO
.ui
.SearchWidget
.prototype.onQueryEnter = function () {
12513 this.results
.selectItem( this.results
.getHighlightedItem() );
12517 * Handle select widget highlight events.
12519 * @param {OO.ui.OptionWidget} item Highlighted item
12522 OO
.ui
.SearchWidget
.prototype.onResultsHighlight = function ( item
) {
12523 this.emit( 'highlight', item
? item
.getData() : null );
12527 * Handle select widget select events.
12529 * @param {OO.ui.OptionWidget} item Selected item
12532 OO
.ui
.SearchWidget
.prototype.onResultsSelect = function ( item
) {
12533 this.emit( 'select', item
? item
.getData() : null );
12537 * Get the query input.
12539 * @return {OO.ui.TextInputWidget} Query input
12541 OO
.ui
.SearchWidget
.prototype.getQuery = function () {
12546 * Get the results list.
12548 * @return {OO.ui.SelectWidget} Select list
12550 OO
.ui
.SearchWidget
.prototype.getResults = function () {
12551 return this.results
;
12555 * Generic selection of options.
12557 * Items can contain any rendering. Any widget that provides options, from which the user must
12558 * choose one, should be built on this class.
12560 * Use together with OO.ui.OptionWidget.
12563 * @extends OO.ui.Widget
12564 * @mixins OO.ui.GroupElement
12567 * @param {Object} [config] Configuration options
12568 * @cfg {OO.ui.OptionWidget[]} [items] Options to add
12570 OO
.ui
.SelectWidget
= function OoUiSelectWidget( config
) {
12571 // Configuration initialization
12572 config
= config
|| {};
12574 // Parent constructor
12575 OO
.ui
.SelectWidget
.super.call( this, config
);
12577 // Mixin constructors
12578 OO
.ui
.GroupWidget
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
12581 this.pressed
= false;
12582 this.selecting
= null;
12583 this.onMouseUpHandler
= this.onMouseUp
.bind( this );
12584 this.onMouseMoveHandler
= this.onMouseMove
.bind( this );
12587 this.$element
.on( {
12588 mousedown
: this.onMouseDown
.bind( this ),
12589 mouseover
: this.onMouseOver
.bind( this ),
12590 mouseleave
: this.onMouseLeave
.bind( this )
12594 this.$element
.addClass( 'oo-ui-selectWidget oo-ui-selectWidget-depressed' );
12595 if ( $.isArray( config
.items
) ) {
12596 this.addItems( config
.items
);
12602 OO
.inheritClass( OO
.ui
.SelectWidget
, OO
.ui
.Widget
);
12604 // Need to mixin base class as well
12605 OO
.mixinClass( OO
.ui
.SelectWidget
, OO
.ui
.GroupElement
);
12606 OO
.mixinClass( OO
.ui
.SelectWidget
, OO
.ui
.GroupWidget
);
12612 * @param {OO.ui.OptionWidget|null} item Highlighted item
12617 * @param {OO.ui.OptionWidget|null} item Pressed item
12622 * @param {OO.ui.OptionWidget|null} item Selected item
12627 * @param {OO.ui.OptionWidget|null} item Chosen item
12632 * @param {OO.ui.OptionWidget[]} items Added items
12633 * @param {number} index Index items were added at
12638 * @param {OO.ui.OptionWidget[]} items Removed items
12644 * Handle mouse down events.
12647 * @param {jQuery.Event} e Mouse down event
12649 OO
.ui
.SelectWidget
.prototype.onMouseDown = function ( e
) {
12652 if ( !this.isDisabled() && e
.which
=== 1 ) {
12653 this.togglePressed( true );
12654 item
= this.getTargetItem( e
);
12655 if ( item
&& item
.isSelectable() ) {
12656 this.pressItem( item
);
12657 this.selecting
= item
;
12658 this.getElementDocument().addEventListener(
12660 this.onMouseUpHandler
,
12663 this.getElementDocument().addEventListener(
12665 this.onMouseMoveHandler
,
12674 * Handle mouse up events.
12677 * @param {jQuery.Event} e Mouse up event
12679 OO
.ui
.SelectWidget
.prototype.onMouseUp = function ( e
) {
12682 this.togglePressed( false );
12683 if ( !this.selecting
) {
12684 item
= this.getTargetItem( e
);
12685 if ( item
&& item
.isSelectable() ) {
12686 this.selecting
= item
;
12689 if ( !this.isDisabled() && e
.which
=== 1 && this.selecting
) {
12690 this.pressItem( null );
12691 this.chooseItem( this.selecting
);
12692 this.selecting
= null;
12695 this.getElementDocument().removeEventListener(
12697 this.onMouseUpHandler
,
12700 this.getElementDocument().removeEventListener(
12702 this.onMouseMoveHandler
,
12710 * Handle mouse move events.
12713 * @param {jQuery.Event} e Mouse move event
12715 OO
.ui
.SelectWidget
.prototype.onMouseMove = function ( e
) {
12718 if ( !this.isDisabled() && this.pressed
) {
12719 item
= this.getTargetItem( e
);
12720 if ( item
&& item
!== this.selecting
&& item
.isSelectable() ) {
12721 this.pressItem( item
);
12722 this.selecting
= item
;
12729 * Handle mouse over events.
12732 * @param {jQuery.Event} e Mouse over event
12734 OO
.ui
.SelectWidget
.prototype.onMouseOver = function ( e
) {
12737 if ( !this.isDisabled() ) {
12738 item
= this.getTargetItem( e
);
12739 this.highlightItem( item
&& item
.isHighlightable() ? item
: null );
12745 * Handle mouse leave events.
12748 * @param {jQuery.Event} e Mouse over event
12750 OO
.ui
.SelectWidget
.prototype.onMouseLeave = function () {
12751 if ( !this.isDisabled() ) {
12752 this.highlightItem( null );
12758 * Get the closest item to a jQuery.Event.
12761 * @param {jQuery.Event} e
12762 * @return {OO.ui.OptionWidget|null} Outline item widget, `null` if none was found
12764 OO
.ui
.SelectWidget
.prototype.getTargetItem = function ( e
) {
12765 var $item
= this.$( e
.target
).closest( '.oo-ui-optionWidget' );
12766 if ( $item
.length
) {
12767 return $item
.data( 'oo-ui-optionWidget' );
12773 * Get selected item.
12775 * @return {OO.ui.OptionWidget|null} Selected item, `null` if no item is selected
12777 OO
.ui
.SelectWidget
.prototype.getSelectedItem = function () {
12780 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
12781 if ( this.items
[ i
].isSelected() ) {
12782 return this.items
[ i
];
12789 * Get highlighted item.
12791 * @return {OO.ui.OptionWidget|null} Highlighted item, `null` if no item is highlighted
12793 OO
.ui
.SelectWidget
.prototype.getHighlightedItem = function () {
12796 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
12797 if ( this.items
[ i
].isHighlighted() ) {
12798 return this.items
[ i
];
12805 * Toggle pressed state.
12807 * @param {boolean} pressed An option is being pressed
12809 OO
.ui
.SelectWidget
.prototype.togglePressed = function ( pressed
) {
12810 if ( pressed
=== undefined ) {
12811 pressed
= !this.pressed
;
12813 if ( pressed
!== this.pressed
) {
12815 .toggleClass( 'oo-ui-selectWidget-pressed', pressed
)
12816 .toggleClass( 'oo-ui-selectWidget-depressed', !pressed
);
12817 this.pressed
= pressed
;
12822 * Highlight an item.
12824 * Highlighting is mutually exclusive.
12826 * @param {OO.ui.OptionWidget} [item] Item to highlight, omit to deselect all
12830 OO
.ui
.SelectWidget
.prototype.highlightItem = function ( item
) {
12831 var i
, len
, highlighted
,
12834 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
12835 highlighted
= this.items
[ i
] === item
;
12836 if ( this.items
[ i
].isHighlighted() !== highlighted
) {
12837 this.items
[ i
].setHighlighted( highlighted
);
12842 this.emit( 'highlight', item
);
12851 * @param {OO.ui.OptionWidget} [item] Item to select, omit to deselect all
12855 OO
.ui
.SelectWidget
.prototype.selectItem = function ( item
) {
12856 var i
, len
, selected
,
12859 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
12860 selected
= this.items
[ i
] === item
;
12861 if ( this.items
[ i
].isSelected() !== selected
) {
12862 this.items
[ i
].setSelected( selected
);
12867 this.emit( 'select', item
);
12876 * @param {OO.ui.OptionWidget} [item] Item to press, omit to depress all
12880 OO
.ui
.SelectWidget
.prototype.pressItem = function ( item
) {
12881 var i
, len
, pressed
,
12884 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
12885 pressed
= this.items
[ i
] === item
;
12886 if ( this.items
[ i
].isPressed() !== pressed
) {
12887 this.items
[ i
].setPressed( pressed
);
12892 this.emit( 'press', item
);
12901 * Identical to #selectItem, but may vary in subclasses that want to take additional action when
12902 * an item is selected using the keyboard or mouse.
12904 * @param {OO.ui.OptionWidget} item Item to choose
12908 OO
.ui
.SelectWidget
.prototype.chooseItem = function ( item
) {
12909 this.selectItem( item
);
12910 this.emit( 'choose', item
);
12916 * Get an item relative to another one.
12918 * @param {OO.ui.OptionWidget|null} item Item to start at, null to get relative to list start
12919 * @param {number} direction Direction to move in, -1 to move backward, 1 to move forward
12920 * @return {OO.ui.OptionWidget|null} Item at position, `null` if there are no items in the menu
12922 OO
.ui
.SelectWidget
.prototype.getRelativeSelectableItem = function ( item
, direction
) {
12923 var currentIndex
, nextIndex
, i
,
12924 increase
= direction
> 0 ? 1 : -1,
12925 len
= this.items
.length
;
12927 if ( item
instanceof OO
.ui
.OptionWidget
) {
12928 currentIndex
= $.inArray( item
, this.items
);
12929 nextIndex
= ( currentIndex
+ increase
+ len
) % len
;
12931 // If no item is selected and moving forward, start at the beginning.
12932 // If moving backward, start at the end.
12933 nextIndex
= direction
> 0 ? 0 : len
- 1;
12936 for ( i
= 0; i
< len
; i
++ ) {
12937 item
= this.items
[ nextIndex
];
12938 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() ) {
12941 nextIndex
= ( nextIndex
+ increase
+ len
) % len
;
12947 * Get the next selectable item.
12949 * @return {OO.ui.OptionWidget|null} Item, `null` if there aren't any selectable items
12951 OO
.ui
.SelectWidget
.prototype.getFirstSelectableItem = function () {
12954 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
12955 item
= this.items
[ i
];
12956 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() ) {
12967 * @param {OO.ui.OptionWidget[]} items Items to add
12968 * @param {number} [index] Index to insert items after
12972 OO
.ui
.SelectWidget
.prototype.addItems = function ( items
, index
) {
12974 OO
.ui
.GroupWidget
.prototype.addItems
.call( this, items
, index
);
12976 // Always provide an index, even if it was omitted
12977 this.emit( 'add', items
, index
=== undefined ? this.items
.length
- items
.length
- 1 : index
);
12985 * Items will be detached, not removed, so they can be used later.
12987 * @param {OO.ui.OptionWidget[]} items Items to remove
12991 OO
.ui
.SelectWidget
.prototype.removeItems = function ( items
) {
12994 // Deselect items being removed
12995 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
12997 if ( item
.isSelected() ) {
12998 this.selectItem( null );
13003 OO
.ui
.GroupWidget
.prototype.removeItems
.call( this, items
);
13005 this.emit( 'remove', items
);
13013 * Items will be detached, not removed, so they can be used later.
13018 OO
.ui
.SelectWidget
.prototype.clearItems = function () {
13019 var items
= this.items
.slice();
13022 OO
.ui
.GroupWidget
.prototype.clearItems
.call( this );
13025 this.selectItem( null );
13027 this.emit( 'remove', items
);
13033 * Select widget containing button options.
13035 * Use together with OO.ui.ButtonOptionWidget.
13038 * @extends OO.ui.SelectWidget
13041 * @param {Object} [config] Configuration options
13043 OO
.ui
.ButtonSelectWidget
= function OoUiButtonSelectWidget( config
) {
13044 // Parent constructor
13045 OO
.ui
.ButtonSelectWidget
.super.call( this, config
);
13048 this.$element
.addClass( 'oo-ui-buttonSelectWidget' );
13053 OO
.inheritClass( OO
.ui
.ButtonSelectWidget
, OO
.ui
.SelectWidget
);
13056 * Select widget containing radio button options.
13058 * Use together with OO.ui.RadioOptionWidget.
13061 * @extends OO.ui.SelectWidget
13064 * @param {Object} [config] Configuration options
13066 OO
.ui
.RadioSelectWidget
= function OoUiRadioSelectWidget( config
) {
13067 // Parent constructor
13068 OO
.ui
.RadioSelectWidget
.super.call( this, config
);
13071 this.$element
.addClass( 'oo-ui-radioSelectWidget' );
13076 OO
.inheritClass( OO
.ui
.RadioSelectWidget
, OO
.ui
.SelectWidget
);
13079 * Overlaid menu of options.
13081 * Menus are clipped to the visible viewport. They do not provide a control for opening or closing
13084 * Use together with OO.ui.MenuOptionWidget.
13087 * @extends OO.ui.SelectWidget
13088 * @mixins OO.ui.ClippableElement
13091 * @param {Object} [config] Configuration options
13092 * @cfg {OO.ui.InputWidget} [input] Input to bind keyboard handlers to
13093 * @cfg {OO.ui.Widget} [widget] Widget to bind mouse handlers to
13094 * @cfg {boolean} [autoHide=true] Hide the menu when the mouse is pressed outside the menu
13096 OO
.ui
.MenuSelectWidget
= function OoUiMenuSelectWidget( config
) {
13097 // Configuration initialization
13098 config
= config
|| {};
13100 // Parent constructor
13101 OO
.ui
.MenuSelectWidget
.super.call( this, config
);
13103 // Mixin constructors
13104 OO
.ui
.ClippableElement
.call( this, $.extend( {}, config
, { $clippable
: this.$group
} ) );
13107 this.visible
= false;
13108 this.newItems
= null;
13109 this.autoHide
= config
.autoHide
=== undefined || !!config
.autoHide
;
13110 this.$input
= config
.input
? config
.input
.$input
: null;
13111 this.$widget
= config
.widget
? config
.widget
.$element
: null;
13112 this.$previousFocus
= null;
13113 this.isolated
= !config
.input
;
13114 this.onKeyDownHandler
= this.onKeyDown
.bind( this );
13115 this.onDocumentMouseDownHandler
= this.onDocumentMouseDown
.bind( this );
13120 .attr( 'role', 'menu' )
13121 .addClass( 'oo-ui-menuSelectWidget' );
13126 OO
.inheritClass( OO
.ui
.MenuSelectWidget
, OO
.ui
.SelectWidget
);
13127 OO
.mixinClass( OO
.ui
.MenuSelectWidget
, OO
.ui
.ClippableElement
);
13132 * Handles document mouse down events.
13134 * @param {jQuery.Event} e Key down event
13136 OO
.ui
.MenuSelectWidget
.prototype.onDocumentMouseDown = function ( e
) {
13138 !OO
.ui
.contains( this.$element
[ 0 ], e
.target
, true ) &&
13139 ( !this.$widget
|| !OO
.ui
.contains( this.$widget
[ 0 ], e
.target
, true ) )
13141 this.toggle( false );
13146 * Handles key down events.
13148 * @param {jQuery.Event} e Key down event
13150 OO
.ui
.MenuSelectWidget
.prototype.onKeyDown = function ( e
) {
13153 highlightItem
= this.getHighlightedItem();
13155 if ( !this.isDisabled() && this.isVisible() ) {
13156 if ( !highlightItem
) {
13157 highlightItem
= this.getSelectedItem();
13159 switch ( e
.keyCode
) {
13160 case OO
.ui
.Keys
.ENTER
:
13161 this.chooseItem( highlightItem
);
13164 case OO
.ui
.Keys
.UP
:
13165 nextItem
= this.getRelativeSelectableItem( highlightItem
, -1 );
13168 case OO
.ui
.Keys
.DOWN
:
13169 nextItem
= this.getRelativeSelectableItem( highlightItem
, 1 );
13172 case OO
.ui
.Keys
.ESCAPE
:
13173 if ( highlightItem
) {
13174 highlightItem
.setHighlighted( false );
13176 this.toggle( false );
13182 this.highlightItem( nextItem
);
13183 nextItem
.scrollElementIntoView();
13187 e
.preventDefault();
13188 e
.stopPropagation();
13195 * Bind key down listener.
13197 OO
.ui
.MenuSelectWidget
.prototype.bindKeyDownListener = function () {
13198 if ( this.$input
) {
13199 this.$input
.on( 'keydown', this.onKeyDownHandler
);
13201 // Capture menu navigation keys
13202 this.getElementWindow().addEventListener( 'keydown', this.onKeyDownHandler
, true );
13207 * Unbind key down listener.
13209 OO
.ui
.MenuSelectWidget
.prototype.unbindKeyDownListener = function () {
13210 if ( this.$input
) {
13211 this.$input
.off( 'keydown' );
13213 this.getElementWindow().removeEventListener( 'keydown', this.onKeyDownHandler
, true );
13220 * This will close the menu, unlike #selectItem which only changes selection.
13222 * @param {OO.ui.OptionWidget} item Item to choose
13225 OO
.ui
.MenuSelectWidget
.prototype.chooseItem = function ( item
) {
13226 OO
.ui
.MenuSelectWidget
.super.prototype.chooseItem
.call( this, item
);
13227 this.toggle( false );
13234 OO
.ui
.MenuSelectWidget
.prototype.addItems = function ( items
, index
) {
13238 OO
.ui
.MenuSelectWidget
.super.prototype.addItems
.call( this, items
, index
);
13241 if ( !this.newItems
) {
13242 this.newItems
= [];
13245 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
13247 if ( this.isVisible() ) {
13248 // Defer fitting label until item has been attached
13251 this.newItems
.push( item
);
13255 // Reevaluate clipping
13264 OO
.ui
.MenuSelectWidget
.prototype.removeItems = function ( items
) {
13266 OO
.ui
.MenuSelectWidget
.super.prototype.removeItems
.call( this, items
);
13268 // Reevaluate clipping
13277 OO
.ui
.MenuSelectWidget
.prototype.clearItems = function () {
13279 OO
.ui
.MenuSelectWidget
.super.prototype.clearItems
.call( this );
13281 // Reevaluate clipping
13290 OO
.ui
.MenuSelectWidget
.prototype.toggle = function ( visible
) {
13291 visible
= ( visible
=== undefined ? !this.visible
: !!visible
) && !!this.items
.length
;
13294 change
= visible
!== this.isVisible(),
13295 elementDoc
= this.getElementDocument(),
13296 widgetDoc
= this.$widget
? this.$widget
[ 0 ].ownerDocument
: null;
13299 OO
.ui
.MenuSelectWidget
.super.prototype.toggle
.call( this, visible
);
13303 this.bindKeyDownListener();
13305 // Change focus to enable keyboard navigation
13306 if ( this.isolated
&& this.$input
&& !this.$input
.is( ':focus' ) ) {
13307 this.$previousFocus
= this.$( ':focus' );
13308 this.$input
[ 0 ].focus();
13310 if ( this.newItems
&& this.newItems
.length
) {
13311 for ( i
= 0, len
= this.newItems
.length
; i
< len
; i
++ ) {
13312 this.newItems
[ i
].fitLabel();
13314 this.newItems
= null;
13316 this.toggleClipping( true );
13319 if ( this.autoHide
) {
13320 elementDoc
.addEventListener(
13321 'mousedown', this.onDocumentMouseDownHandler
, true
13323 // Support $widget being in a different document
13324 if ( widgetDoc
&& widgetDoc
!== elementDoc
) {
13325 widgetDoc
.addEventListener(
13326 'mousedown', this.onDocumentMouseDownHandler
, true
13331 this.unbindKeyDownListener();
13332 if ( this.isolated
&& this.$previousFocus
) {
13333 this.$previousFocus
[ 0 ].focus();
13334 this.$previousFocus
= null;
13336 elementDoc
.removeEventListener(
13337 'mousedown', this.onDocumentMouseDownHandler
, true
13339 // Support $widget being in a different document
13340 if ( widgetDoc
&& widgetDoc
!== elementDoc
) {
13341 widgetDoc
.removeEventListener(
13342 'mousedown', this.onDocumentMouseDownHandler
, true
13345 this.toggleClipping( false );
13353 * Menu for a text input widget.
13355 * This menu is specially designed to be positioned beneath the text input widget. Even if the input
13356 * is in a different frame, the menu's position is automatically calculated and maintained when the
13357 * menu is toggled or the window is resized.
13360 * @extends OO.ui.MenuSelectWidget
13363 * @param {OO.ui.TextInputWidget} input Text input widget to provide menu for
13364 * @param {Object} [config] Configuration options
13365 * @cfg {jQuery} [$container=input.$element] Element to render menu under
13367 OO
.ui
.TextInputMenuSelectWidget
= function OoUiTextInputMenuSelectWidget( input
, config
) {
13368 // Configuration initialization
13369 config
= config
|| {};
13371 // Parent constructor
13372 OO
.ui
.TextInputMenuSelectWidget
.super.call( this, config
);
13375 this.input
= input
;
13376 this.$container
= config
.$container
|| this.input
.$element
;
13377 this.onWindowResizeHandler
= this.onWindowResize
.bind( this );
13380 this.$element
.addClass( 'oo-ui-textInputMenuSelectWidget' );
13385 OO
.inheritClass( OO
.ui
.TextInputMenuSelectWidget
, OO
.ui
.MenuSelectWidget
);
13390 * Handle window resize event.
13392 * @param {jQuery.Event} e Window resize event
13394 OO
.ui
.TextInputMenuSelectWidget
.prototype.onWindowResize = function () {
13401 OO
.ui
.TextInputMenuSelectWidget
.prototype.toggle = function ( visible
) {
13402 visible
= visible
=== undefined ? !this.isVisible() : !!visible
;
13404 var change
= visible
!== this.isVisible();
13406 if ( change
&& visible
) {
13407 // Make sure the width is set before the parent method runs.
13408 // After this we have to call this.position(); again to actually
13409 // position ourselves correctly.
13414 OO
.ui
.TextInputMenuSelectWidget
.super.prototype.toggle
.call( this, visible
);
13417 if ( this.isVisible() ) {
13419 this.$( this.getElementWindow() ).on( 'resize', this.onWindowResizeHandler
);
13421 this.$( this.getElementWindow() ).off( 'resize', this.onWindowResizeHandler
);
13429 * Position the menu.
13433 OO
.ui
.TextInputMenuSelectWidget
.prototype.position = function () {
13434 var $container
= this.$container
,
13435 pos
= OO
.ui
.Element
.static.getRelativePosition( $container
, this.$element
.offsetParent() );
13437 // Position under input
13438 pos
.top
+= $container
.height();
13439 this.$element
.css( pos
);
13442 this.setIdealSize( $container
.width() );
13443 // We updated the position, so re-evaluate the clipping state
13450 * Structured list of items.
13452 * Use with OO.ui.OutlineOptionWidget.
13455 * @extends OO.ui.SelectWidget
13458 * @param {Object} [config] Configuration options
13460 OO
.ui
.OutlineSelectWidget
= function OoUiOutlineSelectWidget( config
) {
13461 // Configuration initialization
13462 config
= config
|| {};
13464 // Parent constructor
13465 OO
.ui
.OutlineSelectWidget
.super.call( this, config
);
13468 this.$element
.addClass( 'oo-ui-outlineSelectWidget' );
13473 OO
.inheritClass( OO
.ui
.OutlineSelectWidget
, OO
.ui
.SelectWidget
);
13476 * Switch that slides on and off.
13479 * @extends OO.ui.Widget
13480 * @mixins OO.ui.ToggleWidget
13483 * @param {Object} [config] Configuration options
13484 * @cfg {boolean} [value=false] Initial value
13486 OO
.ui
.ToggleSwitchWidget
= function OoUiToggleSwitchWidget( config
) {
13487 // Parent constructor
13488 OO
.ui
.ToggleSwitchWidget
.super.call( this, config
);
13490 // Mixin constructors
13491 OO
.ui
.ToggleWidget
.call( this, config
);
13494 this.dragging
= false;
13495 this.dragStart
= null;
13496 this.sliding
= false;
13497 this.$glow
= this.$( '<span>' );
13498 this.$grip
= this.$( '<span>' );
13501 this.$element
.on( 'click', this.onClick
.bind( this ) );
13504 this.$glow
.addClass( 'oo-ui-toggleSwitchWidget-glow' );
13505 this.$grip
.addClass( 'oo-ui-toggleSwitchWidget-grip' );
13507 .addClass( 'oo-ui-toggleSwitchWidget' )
13508 .append( this.$glow
, this.$grip
);
13513 OO
.inheritClass( OO
.ui
.ToggleSwitchWidget
, OO
.ui
.Widget
);
13514 OO
.mixinClass( OO
.ui
.ToggleSwitchWidget
, OO
.ui
.ToggleWidget
);
13519 * Handle mouse down events.
13521 * @param {jQuery.Event} e Mouse down event
13523 OO
.ui
.ToggleSwitchWidget
.prototype.onClick = function ( e
) {
13524 if ( !this.isDisabled() && e
.which
=== 1 ) {
13525 this.setValue( !this.value
);