2 * OOjs UI v0.1.0-pre (05f0fefc3f)
3 * https://www.mediawiki.org/wiki/OOjs_UI
5 * Copyright 2011–2014 OOjs Team and other contributors.
6 * Released under the MIT license
7 * http://oojs.mit-license.org
9 * Date: 2014-11-11T16:29:49Z
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
] ) {
88 // First existing language
98 * Message store for the default implementation of OO.ui.msg
100 * Environments that provide a localization system should not use this, but should override
101 * OO.ui.msg altogether.
106 // Tool tip for a button that moves items in a list down one place
107 'ooui-outline-control-move-down': 'Move item down',
108 // Tool tip for a button that moves items in a list up one place
109 'ooui-outline-control-move-up': 'Move item up',
110 // Tool tip for a button that removes items from a list
111 'ooui-outline-control-remove': 'Remove item',
112 // Label for the toolbar group that contains a list of all other available tools
113 'ooui-toolbar-more': 'More',
114 // Label for the fake tool that expands the full list of tools in a toolbar group
115 'ooui-toolgroup-expand': 'More',
116 // Label for the fake tool that collapses the full list of tools in a toolbar group
117 'ooui-toolgroup-collapse': 'Fewer',
118 // Default label for the accept button of a confirmation dialog
119 'ooui-dialog-message-accept': 'OK',
120 // Default label for the reject button of a confirmation dialog
121 'ooui-dialog-message-reject': 'Cancel',
122 // Title for process dialog error description
123 'ooui-dialog-process-error': 'Something went wrong',
124 // Label for process dialog dismiss error button, visible when describing errors
125 'ooui-dialog-process-dismiss': 'Dismiss',
126 // Label for process dialog retry action button, visible when describing only recoverable errors
127 'ooui-dialog-process-retry': 'Try again',
128 // Label for process dialog retry action button, visible when describing only warnings
129 'ooui-dialog-process-continue': 'Continue'
133 * Get a localized message.
135 * In environments that provide a localization system, this function should be overridden to
136 * return the message translated in the user's language. The default implementation always returns
139 * After the message key, message parameters may optionally be passed. In the default implementation,
140 * any occurrences of $1 are replaced with the first parameter, $2 with the second parameter, etc.
141 * Alternative implementations of OO.ui.msg may use any substitution system they like, as long as
142 * they support unnamed, ordered message parameters.
145 * @param {string} key Message key
146 * @param {Mixed...} [params] Message parameters
147 * @return {string} Translated message with parameters substituted
149 OO
.ui
.msg = function ( key
) {
150 var message
= messages
[key
], params
= Array
.prototype.slice
.call( arguments
, 1 );
151 if ( typeof message
=== 'string' ) {
152 // Perform $1 substitution
153 message
= message
.replace( /\$(\d+)/g, function ( unused
, n
) {
154 var i
= parseInt( n
, 10 );
155 return params
[i
- 1] !== undefined ? params
[i
- 1] : '$' + n
;
158 // Return placeholder if message not found
159 message
= '[' + key
+ ']';
165 * Package a message and arguments for deferred resolution.
167 * Use this when you are statically specifying a message and the message may not yet be present.
169 * @param {string} key Message key
170 * @param {Mixed...} [params] Message parameters
171 * @return {Function} Function that returns the resolved message when executed
173 OO
.ui
.deferMsg = function () {
174 var args
= arguments
;
176 return OO
.ui
.msg
.apply( OO
.ui
, args
);
183 * If the message is a function it will be executed, otherwise it will pass through directly.
185 * @param {Function|string} msg Deferred message, or message text
186 * @return {string} Resolved message
188 OO
.ui
.resolveMsg = function ( msg
) {
189 if ( $.isFunction( msg
) ) {
198 * Element that can be marked as pending.
204 * @param {Object} [config] Configuration options
205 * @cfg {jQuery} [$pending] Element to mark as pending, defaults to this.$element
207 OO
.ui
.PendingElement
= function OoUiPendingElement( config
) {
208 // Configuration initialization
209 config
= config
|| {};
213 this.$pending
= null;
216 this.setPendingElement( config
.$pending
|| this.$element
);
221 OO
.initClass( OO
.ui
.PendingElement
);
226 * Set the pending element (and clean up any existing one).
228 * @param {jQuery} $pending The element to set to pending.
230 OO
.ui
.PendingElement
.prototype.setPendingElement = function ( $pending
) {
231 if ( this.$pending
) {
232 this.$pending
.removeClass( 'oo-ui-pendingElement-pending' );
235 this.$pending
= $pending
;
236 if ( this.pending
> 0 ) {
237 this.$pending
.addClass( 'oo-ui-pendingElement-pending' );
242 * Check if input is pending.
246 OO
.ui
.PendingElement
.prototype.isPending = function () {
247 return !!this.pending
;
251 * Increase the pending stack.
255 OO
.ui
.PendingElement
.prototype.pushPending = function () {
256 if ( this.pending
=== 0 ) {
257 this.$pending
.addClass( 'oo-ui-pendingElement-pending' );
258 this.updateThemeClasses();
266 * Reduce the pending stack.
272 OO
.ui
.PendingElement
.prototype.popPending = function () {
273 if ( this.pending
=== 1 ) {
274 this.$pending
.removeClass( 'oo-ui-pendingElement-pending' );
275 this.updateThemeClasses();
277 this.pending
= Math
.max( 0, this.pending
- 1 );
287 * @mixins OO.EventEmitter
290 * @param {Object} [config] Configuration options
292 OO
.ui
.ActionSet
= function OoUiActionSet( config
) {
293 // Configuration intialization
294 config
= config
|| {};
296 // Mixin constructors
297 OO
.EventEmitter
.call( this );
302 actions
: 'getAction',
306 this.categorized
= {};
309 this.organized
= false;
310 this.changing
= false;
311 this.changed
= false;
316 OO
.mixinClass( OO
.ui
.ActionSet
, OO
.EventEmitter
);
318 /* Static Properties */
321 * Symbolic name of dialog.
328 OO
.ui
.ActionSet
.static.specialFlags
= [ 'safe', 'primary' ];
334 * @param {OO.ui.ActionWidget} action Action that was clicked
339 * @param {OO.ui.ActionWidget} action Action that was resized
344 * @param {OO.ui.ActionWidget[]} added Actions added
349 * @param {OO.ui.ActionWidget[]} added Actions removed
359 * Handle action change events.
363 OO
.ui
.ActionSet
.prototype.onActionChange = function () {
364 this.organized
= false;
365 if ( this.changing
) {
368 this.emit( 'change' );
373 * Check if a action is one of the special actions.
375 * @param {OO.ui.ActionWidget} action Action to check
376 * @return {boolean} Action is special
378 OO
.ui
.ActionSet
.prototype.isSpecial = function ( action
) {
381 for ( flag
in this.special
) {
382 if ( action
=== this.special
[flag
] ) {
393 * @param {Object} [filters] Filters to use, omit to get all actions
394 * @param {string|string[]} [filters.actions] Actions that actions must have
395 * @param {string|string[]} [filters.flags] Flags that actions must have
396 * @param {string|string[]} [filters.modes] Modes that actions must have
397 * @param {boolean} [filters.visible] Actions must be visible
398 * @param {boolean} [filters.disabled] Actions must be disabled
399 * @return {OO.ui.ActionWidget[]} Actions matching all criteria
401 OO
.ui
.ActionSet
.prototype.get = function ( filters
) {
402 var i
, len
, list
, category
, actions
, index
, match
, matches
;
407 // Collect category candidates
409 for ( category
in this.categorized
) {
410 list
= filters
[category
];
412 if ( !Array
.isArray( list
) ) {
415 for ( i
= 0, len
= list
.length
; i
< len
; i
++ ) {
416 actions
= this.categorized
[category
][list
[i
]];
417 if ( Array
.isArray( actions
) ) {
418 matches
.push
.apply( matches
, actions
);
423 // Remove by boolean filters
424 for ( i
= 0, len
= matches
.length
; i
< len
; i
++ ) {
427 ( filters
.visible
!== undefined && match
.isVisible() !== filters
.visible
) ||
428 ( filters
.disabled
!== undefined && match
.isDisabled() !== filters
.disabled
)
430 matches
.splice( i
, 1 );
436 for ( i
= 0, len
= matches
.length
; i
< len
; i
++ ) {
438 index
= matches
.lastIndexOf( match
);
439 while ( index
!== i
) {
440 matches
.splice( index
, 1 );
442 index
= matches
.lastIndexOf( match
);
447 return this.list
.slice();
451 * Get special actions.
453 * Special actions are the first visible actions with special flags, such as 'safe' and 'primary'.
454 * Special flags can be configured by changing #static-specialFlags in a subclass.
456 * @return {OO.ui.ActionWidget|null} Safe action
458 OO
.ui
.ActionSet
.prototype.getSpecial = function () {
460 return $.extend( {}, this.special
);
466 * Other actions include all non-special visible actions.
468 * @return {OO.ui.ActionWidget[]} Other actions
470 OO
.ui
.ActionSet
.prototype.getOthers = function () {
472 return this.others
.slice();
476 * Toggle actions based on their modes.
478 * Unlike calling toggle on actions with matching flags, this will enforce mutually exclusive
479 * visibility; matching actions will be shown, non-matching actions will be hidden.
481 * @param {string} mode Mode actions must have
486 OO
.ui
.ActionSet
.prototype.setMode = function ( mode
) {
489 this.changing
= true;
490 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
491 action
= this.list
[i
];
492 action
.toggle( action
.hasMode( mode
) );
495 this.organized
= false;
496 this.changing
= false;
497 this.emit( 'change' );
503 * Change which actions are able to be performed.
505 * Actions with matching actions will be disabled/enabled. Other actions will not be changed.
507 * @param {Object.<string,boolean>} actions List of abilities, keyed by action name, values
508 * indicate actions are able to be performed
511 OO
.ui
.ActionSet
.prototype.setAbilities = function ( actions
) {
512 var i
, len
, action
, item
;
514 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
516 action
= item
.getAction();
517 if ( actions
[action
] !== undefined ) {
518 item
.setDisabled( !actions
[action
] );
526 * Executes a function once per action.
528 * When making changes to multiple actions, use this method instead of iterating over the actions
529 * manually to defer emitting a change event until after all actions have been changed.
531 * @param {Object|null} actions Filters to use for which actions to iterate over; see #get
532 * @param {Function} callback Callback to run for each action; callback is invoked with three
533 * arguments: the action, the action's index, the list of actions being iterated over
536 OO
.ui
.ActionSet
.prototype.forEach = function ( filter
, callback
) {
537 this.changed
= false;
538 this.changing
= true;
539 this.get( filter
).forEach( callback
);
540 this.changing
= false;
541 if ( this.changed
) {
542 this.emit( 'change' );
551 * @param {OO.ui.ActionWidget[]} actions Actions to add
556 OO
.ui
.ActionSet
.prototype.add = function ( actions
) {
559 this.changing
= true;
560 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
562 action
.connect( this, {
563 click
: [ 'emit', 'click', action
],
564 resize
: [ 'emit', 'resize', action
],
565 toggle
: [ 'onActionChange' ]
567 this.list
.push( action
);
569 this.organized
= false;
570 this.emit( 'add', actions
);
571 this.changing
= false;
572 this.emit( 'change' );
580 * @param {OO.ui.ActionWidget[]} actions Actions to remove
585 OO
.ui
.ActionSet
.prototype.remove = function ( actions
) {
586 var i
, len
, index
, action
;
588 this.changing
= true;
589 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
591 index
= this.list
.indexOf( action
);
592 if ( index
!== -1 ) {
593 action
.disconnect( this );
594 this.list
.splice( index
, 1 );
597 this.organized
= false;
598 this.emit( 'remove', actions
);
599 this.changing
= false;
600 this.emit( 'change' );
606 * Remove all actions.
612 OO
.ui
.ActionSet
.prototype.clear = function () {
614 removed
= this.list
.slice();
616 this.changing
= true;
617 for ( i
= 0, len
= this.list
.length
; i
< len
; i
++ ) {
618 action
= this.list
[i
];
619 action
.disconnect( this );
624 this.organized
= false;
625 this.emit( 'remove', removed
);
626 this.changing
= false;
627 this.emit( 'change' );
635 * This is called whenver organized information is requested. It will only reorganize the actions
636 * if something has changed since the last time it ran.
641 OO
.ui
.ActionSet
.prototype.organize = function () {
642 var i
, iLen
, j
, jLen
, flag
, action
, category
, list
, item
, special
,
643 specialFlags
= this.constructor.static.specialFlags
;
645 if ( !this.organized
) {
646 this.categorized
= {};
649 for ( i
= 0, iLen
= this.list
.length
; i
< iLen
; i
++ ) {
650 action
= this.list
[i
];
651 if ( action
.isVisible() ) {
652 // Populate catgeories
653 for ( category
in this.categories
) {
654 if ( !this.categorized
[category
] ) {
655 this.categorized
[category
] = {};
657 list
= action
[this.categories
[category
]]();
658 if ( !Array
.isArray( list
) ) {
661 for ( j
= 0, jLen
= list
.length
; j
< jLen
; j
++ ) {
663 if ( !this.categorized
[category
][item
] ) {
664 this.categorized
[category
][item
] = [];
666 this.categorized
[category
][item
].push( action
);
669 // Populate special/others
671 for ( j
= 0, jLen
= specialFlags
.length
; j
< jLen
; j
++ ) {
672 flag
= specialFlags
[j
];
673 if ( !this.special
[flag
] && action
.hasFlag( flag
) ) {
674 this.special
[flag
] = action
;
680 this.others
.push( action
);
684 this.organized
= true;
691 * DOM element abstraction.
697 * @param {Object} [config] Configuration options
698 * @cfg {Function} [$] jQuery for the frame the widget is in
699 * @cfg {string[]} [classes] CSS class names to add
700 * @cfg {string} [text] Text to insert
701 * @cfg {jQuery} [$content] Content elements to append (after text)
703 OO
.ui
.Element
= function OoUiElement( config
) {
704 // Configuration initialization
705 config
= config
|| {};
708 this.$ = config
.$ || OO
.ui
.Element
.getJQuery( document
);
709 this.$element
= this.$( this.$.context
.createElement( this.getTagName() ) );
710 this.elementGroup
= null;
711 this.debouncedUpdateThemeClassesHandler
= this.debouncedUpdateThemeClasses
.bind( this );
712 this.updateThemeClassesPending
= false;
715 if ( $.isArray( config
.classes
) ) {
716 this.$element
.addClass( config
.classes
.join( ' ' ) );
719 this.$element
.text( config
.text
);
721 if ( config
.$content
) {
722 this.$element
.append( config
.$content
);
728 OO
.initClass( OO
.ui
.Element
);
730 /* Static Properties */
735 * This may be ignored if #getTagName is overridden.
741 OO
.ui
.Element
.static.tagName
= 'div';
746 * Get a jQuery function within a specific document.
749 * @param {jQuery|HTMLElement|HTMLDocument|Window} context Context to bind the function to
750 * @param {jQuery} [$iframe] HTML iframe element that contains the document, omit if document is
752 * @return {Function} Bound jQuery function
754 OO
.ui
.Element
.getJQuery = function ( context
, $iframe
) {
755 function wrapper( selector
) {
756 return $( selector
, wrapper
.context
);
759 wrapper
.context
= this.getDocument( context
);
762 wrapper
.$iframe
= $iframe
;
769 * Get the document of an element.
772 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Object to get the document for
773 * @return {HTMLDocument|null} Document object
775 OO
.ui
.Element
.getDocument = function ( obj
) {
776 // jQuery - selections created "offscreen" won't have a context, so .context isn't reliable
777 return ( obj
[0] && obj
[0].ownerDocument
) ||
778 // Empty jQuery selections might have a context
785 ( obj
.nodeType
=== 9 && obj
) ||
790 * Get the window of an element or document.
793 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Context to get the window for
794 * @return {Window} Window object
796 OO
.ui
.Element
.getWindow = function ( obj
) {
797 var doc
= this.getDocument( obj
);
798 return doc
.parentWindow
|| doc
.defaultView
;
802 * Get the direction of an element or document.
805 * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Context to get the direction for
806 * @return {string} Text direction, either 'ltr' or 'rtl'
808 OO
.ui
.Element
.getDir = function ( obj
) {
811 if ( obj
instanceof jQuery
) {
814 isDoc
= obj
.nodeType
=== 9;
815 isWin
= obj
.document
!== undefined;
816 if ( isDoc
|| isWin
) {
822 return $( obj
).css( 'direction' );
826 * Get the offset between two frames.
828 * TODO: Make this function not use recursion.
831 * @param {Window} from Window of the child frame
832 * @param {Window} [to=window] Window of the parent frame
833 * @param {Object} [offset] Offset to start with, used internally
834 * @return {Object} Offset object, containing left and top properties
836 OO
.ui
.Element
.getFrameOffset = function ( from, to
, offset
) {
837 var i
, len
, frames
, frame
, rect
;
843 offset
= { top
: 0, left
: 0 };
845 if ( from.parent
=== from ) {
849 // Get iframe element
850 frames
= from.parent
.document
.getElementsByTagName( 'iframe' );
851 for ( i
= 0, len
= frames
.length
; i
< len
; i
++ ) {
852 if ( frames
[i
].contentWindow
=== from ) {
858 // Recursively accumulate offset values
860 rect
= frame
.getBoundingClientRect();
861 offset
.left
+= rect
.left
;
862 offset
.top
+= rect
.top
;
864 this.getFrameOffset( from.parent
, offset
);
871 * Get the offset between two elements.
873 * The two elements may be in a different frame, but in that case the frame $element is in must
874 * be contained in the frame $anchor is in.
877 * @param {jQuery} $element Element whose position to get
878 * @param {jQuery} $anchor Element to get $element's position relative to
879 * @return {Object} Translated position coordinates, containing top and left properties
881 OO
.ui
.Element
.getRelativePosition = function ( $element
, $anchor
) {
882 var iframe
, iframePos
,
883 pos
= $element
.offset(),
884 anchorPos
= $anchor
.offset(),
885 elementDocument
= this.getDocument( $element
),
886 anchorDocument
= this.getDocument( $anchor
);
888 // If $element isn't in the same document as $anchor, traverse up
889 while ( elementDocument
!== anchorDocument
) {
890 iframe
= elementDocument
.defaultView
.frameElement
;
892 throw new Error( '$element frame is not contained in $anchor frame' );
894 iframePos
= $( iframe
).offset();
895 pos
.left
+= iframePos
.left
;
896 pos
.top
+= iframePos
.top
;
897 elementDocument
= iframe
.ownerDocument
;
899 pos
.left
-= anchorPos
.left
;
900 pos
.top
-= anchorPos
.top
;
905 * Get element border sizes.
908 * @param {HTMLElement} el Element to measure
909 * @return {Object} Dimensions object with `top`, `left`, `bottom` and `right` properties
911 OO
.ui
.Element
.getBorders = function ( el
) {
912 var doc
= el
.ownerDocument
,
913 win
= doc
.parentWindow
|| doc
.defaultView
,
914 style
= win
&& win
.getComputedStyle
?
915 win
.getComputedStyle( el
, null ) :
918 top
= parseFloat( style
? style
.borderTopWidth
: $el
.css( 'borderTopWidth' ) ) || 0,
919 left
= parseFloat( style
? style
.borderLeftWidth
: $el
.css( 'borderLeftWidth' ) ) || 0,
920 bottom
= parseFloat( style
? style
.borderBottomWidth
: $el
.css( 'borderBottomWidth' ) ) || 0,
921 right
= parseFloat( style
? style
.borderRightWidth
: $el
.css( 'borderRightWidth' ) ) || 0;
924 top
: Math
.round( top
),
925 left
: Math
.round( left
),
926 bottom
: Math
.round( bottom
),
927 right
: Math
.round( right
)
932 * Get dimensions of an element or window.
935 * @param {HTMLElement|Window} el Element to measure
936 * @return {Object} Dimensions object with `borders`, `scroll`, `scrollbar` and `rect` properties
938 OO
.ui
.Element
.getDimensions = function ( el
) {
940 doc
= el
.ownerDocument
|| el
.document
,
941 win
= doc
.parentWindow
|| doc
.defaultView
;
943 if ( win
=== el
|| el
=== doc
.documentElement
) {
946 borders
: { top
: 0, left
: 0, bottom
: 0, right
: 0 },
948 top
: $win
.scrollTop(),
949 left
: $win
.scrollLeft()
951 scrollbar
: { right
: 0, bottom
: 0 },
955 bottom
: $win
.innerHeight(),
956 right
: $win
.innerWidth()
962 borders
: this.getBorders( el
),
964 top
: $el
.scrollTop(),
965 left
: $el
.scrollLeft()
968 right
: $el
.innerWidth() - el
.clientWidth
,
969 bottom
: $el
.innerHeight() - el
.clientHeight
971 rect
: el
.getBoundingClientRect()
977 * Get closest scrollable container.
979 * Traverses up until either a scrollable element or the root is reached, in which case the window
983 * @param {HTMLElement} el Element to find scrollable container for
984 * @param {string} [dimension] Dimension of scrolling to look for; `x`, `y` or omit for either
985 * @return {HTMLElement} Closest scrollable container
987 OO
.ui
.Element
.getClosestScrollableContainer = function ( el
, dimension
) {
989 props
= [ 'overflow' ],
990 $parent
= $( el
).parent();
992 if ( dimension
=== 'x' || dimension
=== 'y' ) {
993 props
.push( 'overflow-' + dimension
);
996 while ( $parent
.length
) {
997 if ( $parent
[0] === el
.ownerDocument
.body
) {
1002 val
= $parent
.css( props
[i
] );
1003 if ( val
=== 'auto' || val
=== 'scroll' ) {
1007 $parent
= $parent
.parent();
1009 return this.getDocument( el
).body
;
1013 * Scroll element into view.
1016 * @param {HTMLElement} el Element to scroll into view
1017 * @param {Object} [config] Configuration options
1018 * @param {string} [config.duration] jQuery animation duration value
1019 * @param {string} [config.direction] Scroll in only one direction, e.g. 'x' or 'y', omit
1020 * to scroll in both directions
1021 * @param {Function} [config.complete] Function to call when scrolling completes
1023 OO
.ui
.Element
.scrollIntoView = function ( el
, config
) {
1024 // Configuration initialization
1025 config
= config
|| {};
1028 callback
= typeof config
.complete
=== 'function' && config
.complete
,
1029 sc
= this.getClosestScrollableContainer( el
, config
.direction
),
1031 eld
= this.getDimensions( el
),
1032 scd
= this.getDimensions( sc
),
1033 $win
= $( this.getWindow( el
) );
1035 // Compute the distances between the edges of el and the edges of the scroll viewport
1036 if ( $sc
.is( 'body' ) ) {
1037 // If the scrollable container is the <body> this is easy
1040 bottom
: $win
.innerHeight() - eld
.rect
.bottom
,
1041 left
: eld
.rect
.left
,
1042 right
: $win
.innerWidth() - eld
.rect
.right
1045 // Otherwise, we have to subtract el's coordinates from sc's coordinates
1047 top
: eld
.rect
.top
- ( scd
.rect
.top
+ scd
.borders
.top
),
1048 bottom
: scd
.rect
.bottom
- scd
.borders
.bottom
- scd
.scrollbar
.bottom
- eld
.rect
.bottom
,
1049 left
: eld
.rect
.left
- ( scd
.rect
.left
+ scd
.borders
.left
),
1050 right
: scd
.rect
.right
- scd
.borders
.right
- scd
.scrollbar
.right
- eld
.rect
.right
1054 if ( !config
.direction
|| config
.direction
=== 'y' ) {
1055 if ( rel
.top
< 0 ) {
1056 anim
.scrollTop
= scd
.scroll
.top
+ rel
.top
;
1057 } else if ( rel
.top
> 0 && rel
.bottom
< 0 ) {
1058 anim
.scrollTop
= scd
.scroll
.top
+ Math
.min( rel
.top
, -rel
.bottom
);
1061 if ( !config
.direction
|| config
.direction
=== 'x' ) {
1062 if ( rel
.left
< 0 ) {
1063 anim
.scrollLeft
= scd
.scroll
.left
+ rel
.left
;
1064 } else if ( rel
.left
> 0 && rel
.right
< 0 ) {
1065 anim
.scrollLeft
= scd
.scroll
.left
+ Math
.min( rel
.left
, -rel
.right
);
1068 if ( !$.isEmptyObject( anim
) ) {
1069 $sc
.stop( true ).animate( anim
, config
.duration
|| 'fast' );
1071 $sc
.queue( function ( next
) {
1084 * Bind a handler for an event on a DOM element.
1086 * Used to be for working around a jQuery bug (jqbug.com/14180),
1087 * but obsolete as of jQuery 1.11.0.
1090 * @deprecated Use jQuery#on instead.
1091 * @param {HTMLElement|jQuery} el DOM element
1092 * @param {string} event Event to bind
1093 * @param {Function} callback Callback to call when the event fires
1095 OO
.ui
.Element
.onDOMEvent = function ( el
, event
, callback
) {
1096 $( el
).on( event
, callback
);
1100 * Unbind a handler bound with #static-method-onDOMEvent.
1102 * @deprecated Use jQuery#off instead.
1104 * @param {HTMLElement|jQuery} el DOM element
1105 * @param {string} event Event to unbind
1106 * @param {Function} [callback] Callback to unbind
1108 OO
.ui
.Element
.offDOMEvent = function ( el
, event
, callback
) {
1109 $( el
).off( event
, callback
);
1115 * Check if element supports one or more methods.
1117 * @param {string|string[]} methods Method or list of methods to check
1118 * @return {boolean} All methods are supported
1120 OO
.ui
.Element
.prototype.supports = function ( methods
) {
1124 methods
= $.isArray( methods
) ? methods
: [ methods
];
1125 for ( i
= 0, len
= methods
.length
; i
< len
; i
++ ) {
1126 if ( $.isFunction( this[methods
[i
]] ) ) {
1131 return methods
.length
=== support
;
1135 * Update the theme-provided classes.
1137 * @localdoc This is called in element mixins and widget classes anytime state changes.
1138 * Updating is debounced, minimizing overhead of changing multiple attributes and
1139 * guaranteeing that theme updates do not occur within an element's constructor
1141 OO
.ui
.Element
.prototype.updateThemeClasses = function () {
1142 if ( !this.updateThemeClassesPending
) {
1143 this.updateThemeClassesPending
= true;
1144 setTimeout( this.debouncedUpdateThemeClassesHandler
);
1151 OO
.ui
.Element
.prototype.debouncedUpdateThemeClasses = function () {
1152 OO
.ui
.theme
.updateElementClasses( this );
1153 this.updateThemeClassesPending
= false;
1157 * Get the HTML tag name.
1159 * Override this method to base the result on instance information.
1161 * @return {string} HTML tag name
1163 OO
.ui
.Element
.prototype.getTagName = function () {
1164 return this.constructor.static.tagName
;
1168 * Check if the element is attached to the DOM
1169 * @return {boolean} The element is attached to the DOM
1171 OO
.ui
.Element
.prototype.isElementAttached = function () {
1172 return $.contains( this.getElementDocument(), this.$element
[0] );
1176 * Get the DOM document.
1178 * @return {HTMLDocument} Document object
1180 OO
.ui
.Element
.prototype.getElementDocument = function () {
1181 return OO
.ui
.Element
.getDocument( this.$element
);
1185 * Get the DOM window.
1187 * @return {Window} Window object
1189 OO
.ui
.Element
.prototype.getElementWindow = function () {
1190 return OO
.ui
.Element
.getWindow( this.$element
);
1194 * Get closest scrollable container.
1196 OO
.ui
.Element
.prototype.getClosestScrollableElementContainer = function () {
1197 return OO
.ui
.Element
.getClosestScrollableContainer( this.$element
[0] );
1201 * Get group element is in.
1203 * @return {OO.ui.GroupElement|null} Group element, null if none
1205 OO
.ui
.Element
.prototype.getElementGroup = function () {
1206 return this.elementGroup
;
1210 * Set group element is in.
1212 * @param {OO.ui.GroupElement|null} group Group element, null if none
1215 OO
.ui
.Element
.prototype.setElementGroup = function ( group
) {
1216 this.elementGroup
= group
;
1221 * Scroll element into view.
1223 * @param {Object} [config] Configuration options
1225 OO
.ui
.Element
.prototype.scrollElementIntoView = function ( config
) {
1226 return OO
.ui
.Element
.scrollIntoView( this.$element
[0], config
);
1230 * Bind a handler for an event on this.$element
1232 * @deprecated Use jQuery#on instead.
1233 * @param {string} event
1234 * @param {Function} callback
1236 OO
.ui
.Element
.prototype.onDOMEvent = function ( event
, callback
) {
1237 OO
.ui
.Element
.onDOMEvent( this.$element
, event
, callback
);
1241 * Unbind a handler bound with #offDOMEvent
1243 * @deprecated Use jQuery#off instead.
1244 * @param {string} event
1245 * @param {Function} callback
1247 OO
.ui
.Element
.prototype.offDOMEvent = function ( event
, callback
) {
1248 OO
.ui
.Element
.offDOMEvent( this.$element
, event
, callback
);
1252 * Container for elements.
1256 * @extends OO.ui.Element
1257 * @mixins OO.EventEmitter
1260 * @param {Object} [config] Configuration options
1262 OO
.ui
.Layout
= function OoUiLayout( config
) {
1263 // Configuration initialization
1264 config
= config
|| {};
1266 // Parent constructor
1267 OO
.ui
.Layout
.super.call( this, config
);
1269 // Mixin constructors
1270 OO
.EventEmitter
.call( this );
1273 this.$element
.addClass( 'oo-ui-layout' );
1278 OO
.inheritClass( OO
.ui
.Layout
, OO
.ui
.Element
);
1279 OO
.mixinClass( OO
.ui
.Layout
, OO
.EventEmitter
);
1282 * User interface control.
1286 * @extends OO.ui.Element
1287 * @mixins OO.EventEmitter
1290 * @param {Object} [config] Configuration options
1291 * @cfg {boolean} [disabled=false] Disable
1293 OO
.ui
.Widget
= function OoUiWidget( config
) {
1294 // Initialize config
1295 config
= $.extend( { disabled
: false }, config
);
1297 // Parent constructor
1298 OO
.ui
.Widget
.super.call( this, config
);
1300 // Mixin constructors
1301 OO
.EventEmitter
.call( this );
1304 this.visible
= true;
1305 this.disabled
= null;
1306 this.wasDisabled
= null;
1309 this.$element
.addClass( 'oo-ui-widget' );
1310 this.setDisabled( !!config
.disabled
);
1315 OO
.inheritClass( OO
.ui
.Widget
, OO
.ui
.Element
);
1316 OO
.mixinClass( OO
.ui
.Widget
, OO
.EventEmitter
);
1322 * @param {boolean} disabled Widget is disabled
1327 * @param {boolean} visible Widget is visible
1333 * Check if the widget is disabled.
1335 * @return {boolean} Button is disabled
1337 OO
.ui
.Widget
.prototype.isDisabled = function () {
1338 return this.disabled
;
1342 * Check if widget is visible.
1344 * @return {boolean} Widget is visible
1346 OO
.ui
.Widget
.prototype.isVisible = function () {
1347 return this.visible
;
1351 * Set the disabled state of the widget.
1353 * This should probably change the widgets' appearance and prevent it from being used.
1355 * @param {boolean} disabled Disable widget
1358 OO
.ui
.Widget
.prototype.setDisabled = function ( disabled
) {
1361 this.disabled
= !!disabled
;
1362 isDisabled
= this.isDisabled();
1363 if ( isDisabled
!== this.wasDisabled
) {
1364 this.$element
.toggleClass( 'oo-ui-widget-disabled', isDisabled
);
1365 this.$element
.toggleClass( 'oo-ui-widget-enabled', !isDisabled
);
1366 this.emit( 'disable', isDisabled
);
1367 this.updateThemeClasses();
1369 this.wasDisabled
= isDisabled
;
1375 * Toggle visibility of widget.
1377 * @param {boolean} [show] Make widget visible, omit to toggle visibility
1381 OO
.ui
.Widget
.prototype.toggle = function ( show
) {
1382 show
= show
=== undefined ? !this.visible
: !!show
;
1384 if ( show
!== this.isVisible() ) {
1385 this.visible
= show
;
1386 this.$element
.toggle( show
);
1387 this.emit( 'toggle', show
);
1394 * Update the disabled state, in case of changes in parent widget.
1398 OO
.ui
.Widget
.prototype.updateDisabled = function () {
1399 this.setDisabled( this.disabled
);
1404 * Container for elements in a child frame.
1406 * Use together with OO.ui.WindowManager.
1410 * @extends OO.ui.Element
1411 * @mixins OO.EventEmitter
1413 * When a window is opened, the setup and ready processes are executed. Similarly, the hold and
1414 * teardown processes are executed when the window is closed.
1416 * - {@link OO.ui.WindowManager#openWindow} or {@link #open} methods are used to start opening
1417 * - Window manager begins opening window
1418 * - {@link #getSetupProcess} method is called and its result executed
1419 * - {@link #getReadyProcess} method is called and its result executed
1420 * - Window is now open
1422 * - {@link OO.ui.WindowManager#closeWindow} or {@link #close} methods are used to start closing
1423 * - Window manager begins closing window
1424 * - {@link #getHoldProcess} method is called and its result executed
1425 * - {@link #getTeardownProcess} method is called and its result executed
1426 * - Window is now closed
1428 * Each process (setup, ready, hold and teardown) can be extended in subclasses by overriding
1429 * {@link #getSetupProcess}, {@link #getReadyProcess}, {@link #getHoldProcess} and
1430 * {@link #getTeardownProcess} respectively. Each process is executed in series, so asynchonous
1431 * processing can complete. Always assume window processes are executed asychronously. See
1432 * OO.ui.Process for more details about how to work with processes. Some events, as well as the
1433 * #open and #close methods, provide promises which are resolved when the window enters a new state.
1435 * Sizing of windows is specified using symbolic names which are interpreted by the window manager.
1436 * If the requested size is not recognized, the window manager will choose a sensible fallback.
1439 * @param {Object} [config] Configuration options
1440 * @cfg {string} [size] Symbolic name of dialog size, `small`, `medium`, `large` or `full`; omit to
1443 OO
.ui
.Window
= function OoUiWindow( config
) {
1444 // Configuration initialization
1445 config
= config
|| {};
1447 // Parent constructor
1448 OO
.ui
.Window
.super.call( this, config
);
1450 // Mixin constructors
1451 OO
.EventEmitter
.call( this );
1454 this.manager
= null;
1455 this.initialized
= false;
1456 this.visible
= false;
1457 this.opening
= null;
1458 this.closing
= null;
1461 this.loading
= null;
1462 this.size
= config
.size
|| this.constructor.static.size
;
1463 this.$frame
= this.$( '<div>' );
1464 this.$overlay
= this.$( '<div>' );
1468 .addClass( 'oo-ui-window' )
1469 .append( this.$frame
, this.$overlay
);
1470 this.$frame
.addClass( 'oo-ui-window-frame' );
1471 this.$overlay
.addClass( 'oo-ui-window-overlay' );
1473 // NOTE: Additional intitialization will occur when #setManager is called
1478 OO
.inheritClass( OO
.ui
.Window
, OO
.ui
.Element
);
1479 OO
.mixinClass( OO
.ui
.Window
, OO
.EventEmitter
);
1481 /* Static Properties */
1484 * Symbolic name of size.
1486 * Size is used if no size is configured during construction.
1490 * @property {string}
1492 OO
.ui
.Window
.static.size
= 'medium';
1494 /* Static Methods */
1497 * Transplant the CSS styles from as parent document to a frame's document.
1499 * This loops over the style sheets in the parent document, and copies their nodes to the
1500 * frame's document. It then polls the document to see when all styles have loaded, and once they
1501 * have, resolves the promise.
1503 * If the styles still haven't loaded after a long time (5 seconds by default), we give up waiting
1504 * and resolve the promise anyway. This protects against cases like a display: none; iframe in
1505 * Firefox, where the styles won't load until the iframe becomes visible.
1507 * For details of how we arrived at the strategy used in this function, see #load.
1511 * @param {HTMLDocument} parentDoc Document to transplant styles from
1512 * @param {HTMLDocument} frameDoc Document to transplant styles to
1513 * @param {number} [timeout=5000] How long to wait before giving up (in ms). If 0, never give up.
1514 * @return {jQuery.Promise} Promise resolved when styles have loaded
1516 OO
.ui
.Window
.static.transplantStyles = function ( parentDoc
, frameDoc
, timeout
) {
1517 var i
, numSheets
, styleNode
, styleText
, newNode
, timeoutID
, pollNodeId
, $pendingPollNodes
,
1518 $pollNodes
= $( [] ),
1519 // Fake font-family value
1520 fontFamily
= 'oo-ui-frame-transplantStyles-loaded',
1521 nextIndex
= parentDoc
.oouiFrameTransplantStylesNextIndex
|| 0,
1522 deferred
= $.Deferred();
1524 for ( i
= 0, numSheets
= parentDoc
.styleSheets
.length
; i
< numSheets
; i
++ ) {
1525 styleNode
= parentDoc
.styleSheets
[i
].ownerNode
;
1526 if ( styleNode
.disabled
) {
1530 if ( styleNode
.nodeName
.toLowerCase() === 'link' ) {
1531 // External stylesheet; use @import
1532 styleText
= '@import url(' + styleNode
.href
+ ');';
1534 // Internal stylesheet; just copy the text
1535 // For IE10 we need to fall back to .cssText, BUT that's undefined in
1536 // other browsers, so fall back to '' rather than 'undefined'
1537 styleText
= styleNode
.textContent
|| parentDoc
.styleSheets
[i
].cssText
|| '';
1540 // Create a node with a unique ID that we're going to monitor to see when the CSS
1542 if ( styleNode
.oouiFrameTransplantStylesId
) {
1543 // If we're nesting transplantStyles operations and this node already has
1544 // a CSS rule to wait for loading, reuse it
1545 pollNodeId
= styleNode
.oouiFrameTransplantStylesId
;
1547 // Otherwise, create a new ID
1548 pollNodeId
= 'oo-ui-frame-transplantStyles-loaded-' + nextIndex
;
1551 // Add #pollNodeId { font-family: ... } to the end of the stylesheet / after the @import
1552 // The font-family rule will only take effect once the @import finishes
1553 styleText
+= '\n' + '#' + pollNodeId
+ ' { font-family: ' + fontFamily
+ '; }';
1556 // Create a node with id=pollNodeId
1557 $pollNodes
= $pollNodes
.add( $( '<div>', frameDoc
)
1558 .attr( 'id', pollNodeId
)
1559 .appendTo( frameDoc
.body
)
1562 // Add our modified CSS as a <style> tag
1563 newNode
= frameDoc
.createElement( 'style' );
1564 newNode
.textContent
= styleText
;
1565 newNode
.oouiFrameTransplantStylesId
= pollNodeId
;
1566 frameDoc
.head
.appendChild( newNode
);
1568 frameDoc
.oouiFrameTransplantStylesNextIndex
= nextIndex
;
1570 // Poll every 100ms until all external stylesheets have loaded
1571 $pendingPollNodes
= $pollNodes
;
1572 timeoutID
= setTimeout( function pollExternalStylesheets() {
1574 $pendingPollNodes
.length
> 0 &&
1575 $pendingPollNodes
.eq( 0 ).css( 'font-family' ) === fontFamily
1577 $pendingPollNodes
= $pendingPollNodes
.slice( 1 );
1580 if ( $pendingPollNodes
.length
=== 0 ) {
1582 if ( timeoutID
!== null ) {
1584 $pollNodes
.remove();
1588 timeoutID
= setTimeout( pollExternalStylesheets
, 100 );
1591 // ...but give up after a while
1592 if ( timeout
!== 0 ) {
1593 setTimeout( function () {
1595 clearTimeout( timeoutID
);
1597 $pollNodes
.remove();
1600 }, timeout
|| 5000 );
1603 return deferred
.promise();
1609 * Handle mouse down events.
1611 * @param {jQuery.Event} e Mouse down event
1613 OO
.ui
.Window
.prototype.onMouseDown = function ( e
) {
1614 // Prevent clicking on the click-block from stealing focus
1615 if ( e
.target
=== this.$element
[0] ) {
1621 * Check if window has been initialized.
1623 * @return {boolean} Window has been initialized
1625 OO
.ui
.Window
.prototype.isInitialized = function () {
1626 return this.initialized
;
1630 * Check if window is visible.
1632 * @return {boolean} Window is visible
1634 OO
.ui
.Window
.prototype.isVisible = function () {
1635 return this.visible
;
1639 * Check if window is loading.
1641 * @return {boolean} Window is loading
1643 OO
.ui
.Window
.prototype.isLoading = function () {
1644 return this.loading
&& this.loading
.state() === 'pending';
1648 * Check if window is loaded.
1650 * @return {boolean} Window is loaded
1652 OO
.ui
.Window
.prototype.isLoaded = function () {
1653 return this.loading
&& this.loading
.state() === 'resolved';
1657 * Check if window is opening.
1659 * This is a wrapper around OO.ui.WindowManager#isOpening.
1661 * @return {boolean} Window is opening
1663 OO
.ui
.Window
.prototype.isOpening = function () {
1664 return this.manager
.isOpening( this );
1668 * Check if window is closing.
1670 * This is a wrapper around OO.ui.WindowManager#isClosing.
1672 * @return {boolean} Window is closing
1674 OO
.ui
.Window
.prototype.isClosing = function () {
1675 return this.manager
.isClosing( this );
1679 * Check if window is opened.
1681 * This is a wrapper around OO.ui.WindowManager#isOpened.
1683 * @return {boolean} Window is opened
1685 OO
.ui
.Window
.prototype.isOpened = function () {
1686 return this.manager
.isOpened( this );
1690 * Get the window manager.
1692 * @return {OO.ui.WindowManager} Manager of window
1694 OO
.ui
.Window
.prototype.getManager = function () {
1695 return this.manager
;
1699 * Get the window size.
1701 * @return {string} Symbolic size name, e.g. 'small', 'medium', 'large', 'full'
1703 OO
.ui
.Window
.prototype.getSize = function () {
1708 * Get the height of the dialog contents.
1710 * @return {number} Content height
1712 OO
.ui
.Window
.prototype.getContentHeight = function () {
1713 // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements
1714 var bodyHeight
, oldHeight
= this.$frame
[0].style
.height
;
1715 this.$frame
[0].style
.height
= '1px';
1716 bodyHeight
= this.getBodyHeight();
1717 this.$frame
[0].style
.height
= oldHeight
;
1720 // Add buffer for border
1721 ( this.$frame
.outerHeight() - this.$frame
.innerHeight() ) +
1722 // Use combined heights of children
1723 ( this.$head
.outerHeight( true ) + bodyHeight
+ this.$foot
.outerHeight( true ) )
1728 * Get the height of the dialog contents.
1730 * When this function is called, the dialog will temporarily have been resized
1731 * to height=1px, so .scrollHeight measurements can be taken accurately.
1733 * @return {number} Height of content
1735 OO
.ui
.Window
.prototype.getBodyHeight = function () {
1736 return this.$body
[0].scrollHeight
;
1740 * Get the directionality of the frame
1742 * @return {string} Directionality, 'ltr' or 'rtl'
1744 OO
.ui
.Window
.prototype.getDir = function () {
1749 * Get a process for setting up a window for use.
1751 * Each time the window is opened this process will set it up for use in a particular context, based
1752 * on the `data` argument.
1754 * When you override this method, you can add additional setup steps to the process the parent
1755 * method provides using the 'first' and 'next' methods.
1758 * @param {Object} [data] Window opening data
1759 * @return {OO.ui.Process} Setup process
1761 OO
.ui
.Window
.prototype.getSetupProcess = function () {
1762 return new OO
.ui
.Process();
1766 * Get a process for readying a window for use.
1768 * Each time the window is open and setup, this process will ready it up for use in a particular
1769 * context, based on the `data` argument.
1771 * When you override this method, you can add additional setup steps to the process the parent
1772 * method provides using the 'first' and 'next' methods.
1775 * @param {Object} [data] Window opening data
1776 * @return {OO.ui.Process} Setup process
1778 OO
.ui
.Window
.prototype.getReadyProcess = function () {
1779 return new OO
.ui
.Process();
1783 * Get a process for holding a window from use.
1785 * Each time the window is closed, this process will hold it from use in a particular context, based
1786 * on the `data` argument.
1788 * When you override this method, you can add additional setup steps to the process the parent
1789 * method provides using the 'first' and 'next' methods.
1792 * @param {Object} [data] Window closing data
1793 * @return {OO.ui.Process} Hold process
1795 OO
.ui
.Window
.prototype.getHoldProcess = function () {
1796 return new OO
.ui
.Process();
1800 * Get a process for tearing down a window after use.
1802 * Each time the window is closed this process will tear it down and do something with the user's
1803 * interactions within the window, based on the `data` argument.
1805 * When you override this method, you can add additional teardown steps to the process the parent
1806 * method provides using the 'first' and 'next' methods.
1809 * @param {Object} [data] Window closing data
1810 * @return {OO.ui.Process} Teardown process
1812 OO
.ui
.Window
.prototype.getTeardownProcess = function () {
1813 return new OO
.ui
.Process();
1817 * Toggle visibility of window.
1819 * If the window is isolated and hasn't fully loaded yet, the visiblity property will be used
1820 * instead of display.
1822 * @param {boolean} [show] Make window visible, omit to toggle visibility
1826 OO
.ui
.Window
.prototype.toggle = function ( show
) {
1827 show
= show
=== undefined ? !this.visible
: !!show
;
1829 if ( show
!== this.isVisible() ) {
1830 this.visible
= show
;
1832 if ( this.isolated
&& !this.isLoaded() ) {
1833 // Hide the window using visibility instead of display until loading is complete
1834 // Can't use display: none; because that prevents the iframe from loading in Firefox
1835 this.$element
.css( 'visibility', show
? 'visible' : 'hidden' );
1837 this.$element
.toggle( show
).css( 'visibility', '' );
1839 this.emit( 'toggle', show
);
1846 * Set the window manager.
1848 * This must be called before initialize. Calling it more than once will cause an error.
1850 * @param {OO.ui.WindowManager} manager Manager for this window
1851 * @throws {Error} If called more than once
1854 OO
.ui
.Window
.prototype.setManager = function ( manager
) {
1855 if ( this.manager
) {
1856 throw new Error( 'Cannot set window manager, window already has a manager' );
1860 this.manager
= manager
;
1861 this.isolated
= manager
.shouldIsolate();
1864 if ( this.isolated
) {
1865 this.$iframe
= this.$( '<iframe>' );
1866 this.$iframe
.attr( { frameborder
: 0, scrolling
: 'no' } );
1867 this.$frame
.append( this.$iframe
);
1868 this.$ = function () {
1869 throw new Error( 'this.$() cannot be used until the frame has been initialized.' );
1871 // WARNING: Do not use this.$ again until #initialize is called
1873 this.$content
= this.$( '<div>' );
1874 this.$document
= $( this.getElementDocument() );
1875 this.$content
.addClass( 'oo-ui-window-content' );
1876 this.$frame
.append( this.$content
);
1878 this.toggle( false );
1880 // Figure out directionality:
1881 this.dir
= OO
.ui
.Element
.getDir( this.$iframe
|| this.$content
) || 'ltr';
1887 * Set the window size.
1889 * @param {string} size Symbolic size name, e.g. 'small', 'medium', 'large', 'full'
1892 OO
.ui
.Window
.prototype.setSize = function ( size
) {
1894 this.manager
.updateWindowSize( this );
1899 * Set window dimensions.
1901 * Properties are applied to the frame container.
1903 * @param {Object} dim CSS dimension properties
1904 * @param {string|number} [dim.width] Width
1905 * @param {string|number} [dim.minWidth] Minimum width
1906 * @param {string|number} [dim.maxWidth] Maximum width
1907 * @param {string|number} [dim.width] Height, omit to set based on height of contents
1908 * @param {string|number} [dim.minWidth] Minimum height
1909 * @param {string|number} [dim.maxWidth] Maximum height
1912 OO
.ui
.Window
.prototype.setDimensions = function ( dim
) {
1913 // Apply width before height so height is not based on wrapping content using the wrong width
1915 width
: dim
.width
|| '',
1916 minWidth
: dim
.minWidth
|| '',
1917 maxWidth
: dim
.maxWidth
|| ''
1920 height
: ( dim
.height
!== undefined ? dim
.height
: this.getContentHeight() ) || '',
1921 minHeight
: dim
.minHeight
|| '',
1922 maxHeight
: dim
.maxHeight
|| ''
1928 * Initialize window contents.
1930 * The first time the window is opened, #initialize is called when it's safe to begin populating
1931 * its contents. See #getSetupProcess for a way to make changes each time the window opens.
1933 * Once this method is called, this.$ can be used to create elements within the frame.
1935 * @throws {Error} If not attached to a manager
1938 OO
.ui
.Window
.prototype.initialize = function () {
1939 if ( !this.manager
) {
1940 throw new Error( 'Cannot initialize window, must be attached to a manager' );
1944 this.$head
= this.$( '<div>' );
1945 this.$body
= this.$( '<div>' );
1946 this.$foot
= this.$( '<div>' );
1947 this.$innerOverlay
= this.$( '<div>' );
1950 this.$element
.on( 'mousedown', this.onMouseDown
.bind( this ) );
1953 this.$head
.addClass( 'oo-ui-window-head' );
1954 this.$body
.addClass( 'oo-ui-window-body' );
1955 this.$foot
.addClass( 'oo-ui-window-foot' );
1956 this.$innerOverlay
.addClass( 'oo-ui-window-inner-overlay' );
1957 this.$content
.append( this.$head
, this.$body
, this.$foot
, this.$innerOverlay
);
1965 * This is a wrapper around calling {@link OO.ui.WindowManager#openWindow} on the window manager.
1966 * To do something each time the window opens, use #getSetupProcess or #getReadyProcess.
1968 * @param {Object} [data] Window opening data
1969 * @return {jQuery.Promise} Promise resolved when window is opened; when the promise is resolved the
1970 * first argument will be a promise which will be resolved when the window begins closing
1972 OO
.ui
.Window
.prototype.open = function ( data
) {
1973 return this.manager
.openWindow( this, data
);
1979 * This is a wrapper around calling OO.ui.WindowManager#closeWindow on the window manager.
1980 * To do something each time the window closes, use #getHoldProcess or #getTeardownProcess.
1982 * @param {Object} [data] Window closing data
1983 * @return {jQuery.Promise} Promise resolved when window is closed
1985 OO
.ui
.Window
.prototype.close = function ( data
) {
1986 return this.manager
.closeWindow( this, data
);
1992 * This is called by OO.ui.WindowManager durring window opening, and should not be called directly
1995 * @param {Object} [data] Window opening data
1996 * @return {jQuery.Promise} Promise resolved when window is setup
1998 OO
.ui
.Window
.prototype.setup = function ( data
) {
2000 deferred
= $.Deferred();
2002 this.$element
.show();
2003 this.visible
= true;
2004 this.getSetupProcess( data
).execute().done( function () {
2005 // Force redraw by asking the browser to measure the elements' widths
2006 win
.$element
.addClass( 'oo-ui-window-setup' ).width();
2007 win
.$content
.addClass( 'oo-ui-window-content-setup' ).width();
2011 return deferred
.promise();
2017 * This is called by OO.ui.WindowManager durring window opening, and should not be called directly
2020 * @param {Object} [data] Window opening data
2021 * @return {jQuery.Promise} Promise resolved when window is ready
2023 OO
.ui
.Window
.prototype.ready = function ( data
) {
2025 deferred
= $.Deferred();
2027 this.$content
.focus();
2028 this.getReadyProcess( data
).execute().done( function () {
2029 // Force redraw by asking the browser to measure the elements' widths
2030 win
.$element
.addClass( 'oo-ui-window-ready' ).width();
2031 win
.$content
.addClass( 'oo-ui-window-content-ready' ).width();
2035 return deferred
.promise();
2041 * This is called by OO.ui.WindowManager durring window closing, and should not be called directly
2044 * @param {Object} [data] Window closing data
2045 * @return {jQuery.Promise} Promise resolved when window is held
2047 OO
.ui
.Window
.prototype.hold = function ( data
) {
2049 deferred
= $.Deferred();
2051 this.getHoldProcess( data
).execute().done( function () {
2052 // Get the focused element within the window's content
2053 var $focus
= win
.$content
.find( OO
.ui
.Element
.getDocument( win
.$content
).activeElement
);
2055 // Blur the focused element
2056 if ( $focus
.length
) {
2060 // Force redraw by asking the browser to measure the elements' widths
2061 win
.$element
.removeClass( 'oo-ui-window-ready' ).width();
2062 win
.$content
.removeClass( 'oo-ui-window-content-ready' ).width();
2066 return deferred
.promise();
2072 * This is called by OO.ui.WindowManager durring window closing, and should not be called directly
2075 * @param {Object} [data] Window closing data
2076 * @return {jQuery.Promise} Promise resolved when window is torn down
2078 OO
.ui
.Window
.prototype.teardown = function ( data
) {
2080 deferred
= $.Deferred();
2082 this.getTeardownProcess( data
).execute().done( function () {
2083 // Force redraw by asking the browser to measure the elements' widths
2084 win
.$element
.removeClass( 'oo-ui-window-load oo-ui-window-setup' ).width();
2085 win
.$content
.removeClass( 'oo-ui-window-content-setup' ).width();
2086 win
.$element
.hide();
2087 win
.visible
= false;
2091 return deferred
.promise();
2095 * Load the frame contents.
2097 * Once the iframe's stylesheets are loaded the returned promise will be resolved. Calling while
2098 * loading will return a promise but not trigger a new loading cycle. Calling after loading is
2099 * complete will return a promise that's already been resolved.
2101 * Sounds simple right? Read on...
2103 * When you create a dynamic iframe using open/write/close, the window.load event for the
2104 * iframe is triggered when you call close, and there's no further load event to indicate that
2105 * everything is actually loaded.
2107 * In Chrome, stylesheets don't show up in document.styleSheets until they have loaded, so we could
2108 * just poll that array and wait for it to have the right length. However, in Firefox, stylesheets
2109 * are added to document.styleSheets immediately, and the only way you can determine whether they've
2110 * loaded is to attempt to access .cssRules and wait for that to stop throwing an exception. But
2111 * cross-domain stylesheets never allow .cssRules to be accessed even after they have loaded.
2113 * The workaround is to change all `<link href="...">` tags to `<style>@import url(...)</style>`
2114 * tags. Because `@import` is blocking, Chrome won't add the stylesheet to document.styleSheets
2115 * until the `@import` has finished, and Firefox won't allow .cssRules to be accessed until the
2116 * `@import` has finished. And because the contents of the `<style>` tag are from the same origin,
2117 * accessing .cssRules is allowed.
2119 * However, now that we control the styles we're injecting, we might as well do away with
2120 * browser-specific polling hacks like document.styleSheets and .cssRules, and instead inject
2121 * `<style>@import url(...); #foo { font-family: someValue; }</style>`, then create `<div id="foo">`
2122 * and wait for its font-family to change to someValue. Because `@import` is blocking, the
2123 * font-family rule is not applied until after the `@import` finishes.
2125 * All this stylesheet injection and polling magic is in #transplantStyles.
2127 * @return {jQuery.Promise} Promise resolved when loading is complete
2129 OO
.ui
.Window
.prototype.load = function () {
2130 var sub
, doc
, loading
,
2133 this.$element
.addClass( 'oo-ui-window-load' );
2135 // Non-isolated windows are already "loaded"
2136 if ( !this.loading
&& !this.isolated
) {
2137 this.loading
= $.Deferred().resolve();
2139 // Set initialized state after so sub-classes aren't confused by it being set by calling
2140 // their parent initialize method
2141 this.initialized
= true;
2144 // Return existing promise if already loading or loaded
2145 if ( this.loading
) {
2146 return this.loading
.promise();
2150 loading
= this.loading
= $.Deferred();
2151 sub
= this.$iframe
.prop( 'contentWindow' );
2154 // Initialize contents
2159 '<body class="oo-ui-window-isolated oo-ui-' + this.dir
+ '"' +
2160 ' style="direction:' + this.dir
+ ';" dir="' + this.dir
+ '">' +
2161 '<div class="oo-ui-window-content"></div>' +
2168 this.$ = OO
.ui
.Element
.getJQuery( doc
, this.$iframe
);
2169 this.$content
= this.$( '.oo-ui-window-content' ).attr( 'tabIndex', 0 );
2170 this.$document
= this.$( doc
);
2173 this.constructor.static.transplantStyles( this.getElementDocument(), this.$document
[0] )
2174 .always( function () {
2175 // Initialize isolated windows
2177 // Set initialized state after so sub-classes aren't confused by it being set by calling
2178 // their parent initialize method
2179 win
.initialized
= true;
2180 // Undo the visibility: hidden; hack and apply display: none;
2181 // We can do this safely now that the iframe has initialized
2182 // (don't do this from within #initialize because it has to happen
2183 // after the all subclasses have been handled as well).
2184 win
.toggle( win
.isVisible() );
2189 return loading
.promise();
2193 * Base class for all dialogs.
2196 * - Manage the window (open and close, etc.).
2197 * - Store the internal name and display title.
2198 * - A stack to track one or more pending actions.
2199 * - Manage a set of actions that can be performed.
2200 * - Configure and create action widgets.
2203 * - Close the dialog with Escape key.
2204 * - Visually lock the dialog while an action is in
2205 * progress (aka "pending").
2207 * Subclass responsibilities:
2208 * - Display the title somewhere.
2209 * - Add content to the dialog.
2210 * - Provide a UI to close the dialog.
2211 * - Display the action widgets somewhere.
2215 * @extends OO.ui.Window
2216 * @mixins OO.ui.PendingElement
2219 * @param {Object} [config] Configuration options
2221 OO
.ui
.Dialog
= function OoUiDialog( config
) {
2222 // Parent constructor
2223 OO
.ui
.Dialog
.super.call( this, config
);
2225 // Mixin constructors
2226 OO
.ui
.PendingElement
.call( this );
2229 this.actions
= new OO
.ui
.ActionSet();
2230 this.attachedActions
= [];
2231 this.currentAction
= null;
2234 this.actions
.connect( this, {
2235 click
: 'onActionClick',
2236 resize
: 'onActionResize',
2237 change
: 'onActionsChange'
2242 .addClass( 'oo-ui-dialog' )
2243 .attr( 'role', 'dialog' );
2248 OO
.inheritClass( OO
.ui
.Dialog
, OO
.ui
.Window
);
2249 OO
.mixinClass( OO
.ui
.Dialog
, OO
.ui
.PendingElement
);
2251 /* Static Properties */
2254 * Symbolic name of dialog.
2259 * @property {string}
2261 OO
.ui
.Dialog
.static.name
= '';
2269 * @property {jQuery|string|Function} Label nodes, text or a function that returns nodes or text
2271 OO
.ui
.Dialog
.static.title
= '';
2274 * List of OO.ui.ActionWidget configuration options.
2278 * @property {Object[]}
2280 OO
.ui
.Dialog
.static.actions
= [];
2283 * Close dialog when the escape key is pressed.
2288 * @property {boolean}
2290 OO
.ui
.Dialog
.static.escapable
= true;
2295 * Handle frame document key down events.
2297 * @param {jQuery.Event} e Key down event
2299 OO
.ui
.Dialog
.prototype.onDocumentKeyDown = function ( e
) {
2300 if ( e
.which
=== OO
.ui
.Keys
.ESCAPE
) {
2307 * Handle action resized events.
2309 * @param {OO.ui.ActionWidget} action Action that was resized
2311 OO
.ui
.Dialog
.prototype.onActionResize = function () {
2312 // Override in subclass
2316 * Handle action click events.
2318 * @param {OO.ui.ActionWidget} action Action that was clicked
2320 OO
.ui
.Dialog
.prototype.onActionClick = function ( action
) {
2321 if ( !this.isPending() ) {
2322 this.currentAction
= action
;
2323 this.executeAction( action
.getAction() );
2328 * Handle actions change event.
2330 OO
.ui
.Dialog
.prototype.onActionsChange = function () {
2331 this.detachActions();
2332 if ( !this.isClosing() ) {
2333 this.attachActions();
2338 * Get set of actions.
2340 * @return {OO.ui.ActionSet}
2342 OO
.ui
.Dialog
.prototype.getActions = function () {
2343 return this.actions
;
2347 * Get a process for taking action.
2349 * When you override this method, you can add additional accept steps to the process the parent
2350 * method provides using the 'first' and 'next' methods.
2353 * @param {string} [action] Symbolic name of action
2354 * @return {OO.ui.Process} Action process
2356 OO
.ui
.Dialog
.prototype.getActionProcess = function ( action
) {
2357 return new OO
.ui
.Process()
2358 .next( function () {
2360 // An empty action always closes the dialog without data, which should always be
2361 // safe and make no changes
2370 * @param {Object} [data] Dialog opening data
2371 * @param {jQuery|string|Function|null} [data.title] Dialog title, omit to use #static-title
2372 * @param {Object[]} [data.actions] List of OO.ui.ActionWidget configuration options for each
2373 * action item, omit to use #static-actions
2375 OO
.ui
.Dialog
.prototype.getSetupProcess = function ( data
) {
2379 return OO
.ui
.Dialog
.super.prototype.getSetupProcess
.call( this, data
)
2380 .next( function () {
2383 config
= this.constructor.static,
2384 actions
= data
.actions
!== undefined ? data
.actions
: config
.actions
;
2386 this.title
.setLabel(
2387 data
.title
!== undefined ? data
.title
: this.constructor.static.title
2389 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
2391 new OO
.ui
.ActionWidget( $.extend( { $: this.$ }, actions
[i
] ) )
2394 this.actions
.add( items
);
2401 OO
.ui
.Dialog
.prototype.getTeardownProcess = function ( data
) {
2403 return OO
.ui
.Dialog
.super.prototype.getTeardownProcess
.call( this, data
)
2404 .first( function () {
2405 this.actions
.clear();
2406 this.currentAction
= null;
2413 OO
.ui
.Dialog
.prototype.initialize = function () {
2415 OO
.ui
.Dialog
.super.prototype.initialize
.call( this );
2418 this.title
= new OO
.ui
.LabelWidget( { $: this.$ } );
2421 if ( this.constructor.static.escapable
) {
2422 this.$document
.on( 'keydown', this.onDocumentKeyDown
.bind( this ) );
2426 this.$content
.addClass( 'oo-ui-dialog-content' );
2427 this.setPendingElement( this.$head
);
2431 * Attach action actions.
2433 OO
.ui
.Dialog
.prototype.attachActions = function () {
2434 // Remember the list of potentially attached actions
2435 this.attachedActions
= this.actions
.get();
2439 * Detach action actions.
2443 OO
.ui
.Dialog
.prototype.detachActions = function () {
2446 // Detach all actions that may have been previously attached
2447 for ( i
= 0, len
= this.attachedActions
.length
; i
< len
; i
++ ) {
2448 this.attachedActions
[i
].$element
.detach();
2450 this.attachedActions
= [];
2454 * Execute an action.
2456 * @param {string} action Symbolic name of action to execute
2457 * @return {jQuery.Promise} Promise resolved when action completes, rejected if it fails
2459 OO
.ui
.Dialog
.prototype.executeAction = function ( action
) {
2461 return this.getActionProcess( action
).execute()
2462 .always( this.popPending
.bind( this ) );
2466 * Collection of windows.
2469 * @extends OO.ui.Element
2470 * @mixins OO.EventEmitter
2472 * Managed windows are mutually exclusive. If a window is opened while there is a current window
2473 * already opening or opened, the current window will be closed without data. Empty closing data
2474 * should always result in the window being closed without causing constructive or destructive
2477 * As a window is opened and closed, it passes through several stages and the manager emits several
2478 * corresponding events.
2480 * - {@link #openWindow} or {@link OO.ui.Window#open} methods are used to start opening
2481 * - {@link #event-opening} is emitted with `opening` promise
2482 * - {@link #getSetupDelay} is called the returned value is used to time a pause in execution
2483 * - {@link OO.ui.Window#getSetupProcess} method is called on the window and its result executed
2484 * - `setup` progress notification is emitted from opening promise
2485 * - {@link #getReadyDelay} is called the returned value is used to time a pause in execution
2486 * - {@link OO.ui.Window#getReadyProcess} method is called on the window and its result executed
2487 * - `ready` progress notification is emitted from opening promise
2488 * - `opening` promise is resolved with `opened` promise
2489 * - Window is now open
2491 * - {@link #closeWindow} or {@link OO.ui.Window#close} methods are used to start closing
2492 * - `opened` promise is resolved with `closing` promise
2493 * - {@link #event-closing} is emitted with `closing` promise
2494 * - {@link #getHoldDelay} is called the returned value is used to time a pause in execution
2495 * - {@link OO.ui.Window#getHoldProcess} method is called on the window and its result executed
2496 * - `hold` progress notification is emitted from opening promise
2497 * - {@link #getTeardownDelay} is called the returned value is used to time a pause in execution
2498 * - {@link OO.ui.Window#getTeardownProcess} method is called on the window and its result executed
2499 * - `teardown` progress notification is emitted from opening promise
2500 * - Closing promise is resolved
2501 * - Window is now closed
2504 * @param {Object} [config] Configuration options
2505 * @cfg {boolean} [isolate] Configure managed windows to isolate their content using inline frames
2506 * @cfg {OO.Factory} [factory] Window factory to use for automatic instantiation
2507 * @cfg {boolean} [modal=true] Prevent interaction outside the dialog
2509 OO
.ui
.WindowManager
= function OoUiWindowManager( config
) {
2510 // Configuration initialization
2511 config
= config
|| {};
2513 // Parent constructor
2514 OO
.ui
.WindowManager
.super.call( this, config
);
2516 // Mixin constructors
2517 OO
.EventEmitter
.call( this );
2520 this.factory
= config
.factory
;
2521 this.modal
= config
.modal
=== undefined || !!config
.modal
;
2522 this.isolate
= !!config
.isolate
;
2524 this.opening
= null;
2526 this.closing
= null;
2527 this.preparingToOpen
= null;
2528 this.preparingToClose
= null;
2530 this.currentWindow
= null;
2531 this.$ariaHidden
= null;
2532 this.requestedSize
= null;
2533 this.onWindowResizeTimeout
= null;
2534 this.onWindowResizeHandler
= this.onWindowResize
.bind( this );
2535 this.afterWindowResizeHandler
= this.afterWindowResize
.bind( this );
2536 this.onWindowMouseWheelHandler
= this.onWindowMouseWheel
.bind( this );
2537 this.onDocumentKeyDownHandler
= this.onDocumentKeyDown
.bind( this );
2541 .addClass( 'oo-ui-windowManager' )
2542 .toggleClass( 'oo-ui-windowManager-modal', this.modal
);
2547 OO
.inheritClass( OO
.ui
.WindowManager
, OO
.ui
.Element
);
2548 OO
.mixinClass( OO
.ui
.WindowManager
, OO
.EventEmitter
);
2553 * Window is opening.
2555 * Fired when the window begins to be opened.
2558 * @param {OO.ui.Window} win Window that's being opened
2559 * @param {jQuery.Promise} opening Promise resolved when window is opened; when the promise is
2560 * resolved the first argument will be a promise which will be resolved when the window begins
2561 * closing, the second argument will be the opening data; progress notifications will be fired on
2562 * the promise for `setup` and `ready` when those processes are completed respectively.
2563 * @param {Object} data Window opening data
2567 * Window is closing.
2569 * Fired when the window begins to be closed.
2572 * @param {OO.ui.Window} win Window that's being closed
2573 * @param {jQuery.Promise} opening Promise resolved when window is closed; when the promise
2574 * is resolved the first argument will be a the closing data; progress notifications will be fired
2575 * on the promise for `hold` and `teardown` when those processes are completed respectively.
2576 * @param {Object} data Window closing data
2580 * Window was resized.
2583 * @param {OO.ui.Window} win Window that was resized
2586 /* Static Properties */
2589 * Map of symbolic size names and CSS properties.
2593 * @property {Object}
2595 OO
.ui
.WindowManager
.static.sizes
= {
2606 // These can be non-numeric because they are never used in calculations
2613 * Symbolic name of default size.
2615 * Default size is used if the window's requested size is not recognized.
2619 * @property {string}
2621 OO
.ui
.WindowManager
.static.defaultSize
= 'medium';
2626 * Handle window resize events.
2628 * @param {jQuery.Event} e Window resize event
2630 OO
.ui
.WindowManager
.prototype.onWindowResize = function () {
2631 clearTimeout( this.onWindowResizeTimeout
);
2632 this.onWindowResizeTimeout
= setTimeout( this.afterWindowResizeHandler
, 200 );
2636 * Handle window resize events.
2638 * @param {jQuery.Event} e Window resize event
2640 OO
.ui
.WindowManager
.prototype.afterWindowResize = function () {
2641 if ( this.currentWindow
) {
2642 this.updateWindowSize( this.currentWindow
);
2647 * Handle window mouse wheel events.
2649 * @param {jQuery.Event} e Mouse wheel event
2651 OO
.ui
.WindowManager
.prototype.onWindowMouseWheel = function ( e
) {
2652 // Kill all events in the parent window if the child window is isolated,
2653 // or if the event didn't come from the child window
2654 return !( this.shouldIsolate() || !$.contains( this.getCurrentWindow().$frame
[0], e
.target
) );
2658 * Handle document key down events.
2660 * @param {jQuery.Event} e Key down event
2662 OO
.ui
.WindowManager
.prototype.onDocumentKeyDown = function ( e
) {
2663 switch ( e
.which
) {
2664 case OO
.ui
.Keys
.PAGEUP
:
2665 case OO
.ui
.Keys
.PAGEDOWN
:
2666 case OO
.ui
.Keys
.END
:
2667 case OO
.ui
.Keys
.HOME
:
2668 case OO
.ui
.Keys
.LEFT
:
2670 case OO
.ui
.Keys
.RIGHT
:
2671 case OO
.ui
.Keys
.DOWN
:
2672 // Kill all events in the parent window if the child window is isolated,
2673 // or if the event didn't come from the child window
2674 return !( this.shouldIsolate() || !$.contains( this.getCurrentWindow().$frame
[0], e
.target
) );
2679 * Check if window is opening.
2681 * @return {boolean} Window is opening
2683 OO
.ui
.WindowManager
.prototype.isOpening = function ( win
) {
2684 return win
=== this.currentWindow
&& !!this.opening
&& this.opening
.state() === 'pending';
2688 * Check if window is closing.
2690 * @return {boolean} Window is closing
2692 OO
.ui
.WindowManager
.prototype.isClosing = function ( win
) {
2693 return win
=== this.currentWindow
&& !!this.closing
&& this.closing
.state() === 'pending';
2697 * Check if window is opened.
2699 * @return {boolean} Window is opened
2701 OO
.ui
.WindowManager
.prototype.isOpened = function ( win
) {
2702 return win
=== this.currentWindow
&& !!this.opened
&& this.opened
.state() === 'pending';
2706 * Check if window contents should be isolated.
2708 * Window content isolation is done using inline frames.
2710 * @return {boolean} Window contents should be isolated
2712 OO
.ui
.WindowManager
.prototype.shouldIsolate = function () {
2713 return this.isolate
;
2717 * Check if a window is being managed.
2719 * @param {OO.ui.Window} win Window to check
2720 * @return {boolean} Window is being managed
2722 OO
.ui
.WindowManager
.prototype.hasWindow = function ( win
) {
2725 for ( name
in this.windows
) {
2726 if ( this.windows
[name
] === win
) {
2735 * Get the number of milliseconds to wait between beginning opening and executing setup process.
2737 * @param {OO.ui.Window} win Window being opened
2738 * @param {Object} [data] Window opening data
2739 * @return {number} Milliseconds to wait
2741 OO
.ui
.WindowManager
.prototype.getSetupDelay = function () {
2746 * Get the number of milliseconds to wait between finishing setup and executing ready process.
2748 * @param {OO.ui.Window} win Window being opened
2749 * @param {Object} [data] Window opening data
2750 * @return {number} Milliseconds to wait
2752 OO
.ui
.WindowManager
.prototype.getReadyDelay = function () {
2757 * Get the number of milliseconds to wait between beginning closing and executing hold process.
2759 * @param {OO.ui.Window} win Window being closed
2760 * @param {Object} [data] Window closing data
2761 * @return {number} Milliseconds to wait
2763 OO
.ui
.WindowManager
.prototype.getHoldDelay = function () {
2768 * Get the number of milliseconds to wait between finishing hold and executing teardown process.
2770 * @param {OO.ui.Window} win Window being closed
2771 * @param {Object} [data] Window closing data
2772 * @return {number} Milliseconds to wait
2774 OO
.ui
.WindowManager
.prototype.getTeardownDelay = function () {
2775 return this.modal
? 250 : 0;
2779 * Get managed window by symbolic name.
2781 * If window is not yet instantiated, it will be instantiated and added automatically.
2783 * @param {string} name Symbolic window name
2784 * @return {jQuery.Promise} Promise resolved with matching window, or rejected with an OO.ui.Error
2785 * @throws {Error} If the symbolic name is unrecognized by the factory
2786 * @throws {Error} If the symbolic name unrecognized as a managed window
2788 OO
.ui
.WindowManager
.prototype.getWindow = function ( name
) {
2789 var deferred
= $.Deferred(),
2790 win
= this.windows
[name
];
2792 if ( !( win
instanceof OO
.ui
.Window
) ) {
2793 if ( this.factory
) {
2794 if ( !this.factory
.lookup( name
) ) {
2795 deferred
.reject( new OO
.ui
.Error(
2796 'Cannot auto-instantiate window: symbolic name is unrecognized by the factory'
2799 win
= this.factory
.create( name
, this, { $: this.$ } );
2800 this.addWindows( [ win
] );
2801 deferred
.resolve( win
);
2804 deferred
.reject( new OO
.ui
.Error(
2805 'Cannot get unmanaged window: symbolic name unrecognized as a managed window'
2809 deferred
.resolve( win
);
2812 return deferred
.promise();
2816 * Get current window.
2818 * @return {OO.ui.Window|null} Currently opening/opened/closing window
2820 OO
.ui
.WindowManager
.prototype.getCurrentWindow = function () {
2821 return this.currentWindow
;
2827 * @param {OO.ui.Window|string} win Window object or symbolic name of window to open
2828 * @param {Object} [data] Window opening data
2829 * @return {jQuery.Promise} Promise resolved when window is done opening; see {@link #event-opening}
2830 * for more details about the `opening` promise
2833 OO
.ui
.WindowManager
.prototype.openWindow = function ( win
, data
) {
2836 opening
= $.Deferred();
2838 // Argument handling
2839 if ( typeof win
=== 'string' ) {
2840 return this.getWindow( win
).then( function ( win
) {
2841 return manager
.openWindow( win
, data
);
2846 if ( !this.hasWindow( win
) ) {
2847 opening
.reject( new OO
.ui
.Error(
2848 'Cannot open window: window is not attached to manager'
2850 } else if ( this.preparingToOpen
|| this.opening
|| this.opened
) {
2851 opening
.reject( new OO
.ui
.Error(
2852 'Cannot open window: another window is opening or open'
2857 if ( opening
.state() !== 'rejected' ) {
2858 if ( !win
.getManager() ) {
2859 win
.setManager( this );
2861 preparing
.push( win
.load() );
2863 if ( this.closing
) {
2864 // If a window is currently closing, wait for it to complete
2865 preparing
.push( this.closing
);
2868 this.preparingToOpen
= $.when
.apply( $, preparing
);
2869 // Ensure handlers get called after preparingToOpen is set
2870 this.preparingToOpen
.done( function () {
2871 if ( manager
.modal
) {
2872 manager
.toggleGlobalEvents( true );
2873 manager
.toggleAriaIsolation( true );
2875 manager
.currentWindow
= win
;
2876 manager
.opening
= opening
;
2877 manager
.preparingToOpen
= null;
2878 manager
.emit( 'opening', win
, opening
, data
);
2879 setTimeout( function () {
2880 win
.setup( data
).then( function () {
2881 manager
.updateWindowSize( win
);
2882 manager
.opening
.notify( { state
: 'setup' } );
2883 setTimeout( function () {
2884 win
.ready( data
).then( function () {
2885 manager
.opening
.notify( { state
: 'ready' } );
2886 manager
.opening
= null;
2887 manager
.opened
= $.Deferred();
2888 opening
.resolve( manager
.opened
.promise(), data
);
2890 }, manager
.getReadyDelay() );
2892 }, manager
.getSetupDelay() );
2896 return opening
.promise();
2902 * @param {OO.ui.Window|string} win Window object or symbolic name of window to close
2903 * @param {Object} [data] Window closing data
2904 * @return {jQuery.Promise} Promise resolved when window is done closing; see {@link #event-closing}
2905 * for more details about the `closing` promise
2906 * @throws {Error} If no window by that name is being managed
2909 OO
.ui
.WindowManager
.prototype.closeWindow = function ( win
, data
) {
2912 closing
= $.Deferred(),
2915 // Argument handling
2916 if ( typeof win
=== 'string' ) {
2917 win
= this.windows
[win
];
2918 } else if ( !this.hasWindow( win
) ) {
2924 closing
.reject( new OO
.ui
.Error(
2925 'Cannot close window: window is not attached to manager'
2927 } else if ( win
!== this.currentWindow
) {
2928 closing
.reject( new OO
.ui
.Error(
2929 'Cannot close window: window already closed with different data'
2931 } else if ( this.preparingToClose
|| this.closing
) {
2932 closing
.reject( new OO
.ui
.Error(
2933 'Cannot close window: window already closing with different data'
2938 if ( closing
.state() !== 'rejected' ) {
2939 if ( this.opening
) {
2940 // If the window is currently opening, close it when it's done
2941 preparing
.push( this.opening
);
2944 this.preparingToClose
= $.when
.apply( $, preparing
);
2945 // Ensure handlers get called after preparingToClose is set
2946 this.preparingToClose
.done( function () {
2947 manager
.closing
= closing
;
2948 manager
.preparingToClose
= null;
2949 manager
.emit( 'closing', win
, closing
, data
);
2950 opened
= manager
.opened
;
2951 manager
.opened
= null;
2952 opened
.resolve( closing
.promise(), data
);
2953 setTimeout( function () {
2954 win
.hold( data
).then( function () {
2955 closing
.notify( { state
: 'hold' } );
2956 setTimeout( function () {
2957 win
.teardown( data
).then( function () {
2958 closing
.notify( { state
: 'teardown' } );
2959 if ( manager
.modal
) {
2960 manager
.toggleGlobalEvents( false );
2961 manager
.toggleAriaIsolation( false );
2963 manager
.closing
= null;
2964 manager
.currentWindow
= null;
2965 closing
.resolve( data
);
2967 }, manager
.getTeardownDelay() );
2969 }, manager
.getHoldDelay() );
2973 return closing
.promise();
2979 * @param {Object.<string,OO.ui.Window>|OO.ui.Window[]} windows Windows to add
2980 * @throws {Error} If one of the windows being added without an explicit symbolic name does not have
2981 * a statically configured symbolic name
2983 OO
.ui
.WindowManager
.prototype.addWindows = function ( windows
) {
2984 var i
, len
, win
, name
, list
;
2986 if ( $.isArray( windows
) ) {
2987 // Convert to map of windows by looking up symbolic names from static configuration
2989 for ( i
= 0, len
= windows
.length
; i
< len
; i
++ ) {
2990 name
= windows
[i
].constructor.static.name
;
2991 if ( typeof name
!== 'string' ) {
2992 throw new Error( 'Cannot add window' );
2994 list
[name
] = windows
[i
];
2996 } else if ( $.isPlainObject( windows
) ) {
3001 for ( name
in list
) {
3003 this.windows
[name
] = win
;
3004 this.$element
.append( win
.$element
);
3011 * Windows will be closed before they are removed.
3013 * @param {string} name Symbolic name of window to remove
3014 * @return {jQuery.Promise} Promise resolved when window is closed and removed
3015 * @throws {Error} If windows being removed are not being managed
3017 OO
.ui
.WindowManager
.prototype.removeWindows = function ( names
) {
3018 var i
, len
, win
, name
,
3021 cleanup = function ( name
, win
) {
3022 delete manager
.windows
[name
];
3023 win
.$element
.detach();
3026 for ( i
= 0, len
= names
.length
; i
< len
; i
++ ) {
3028 win
= this.windows
[name
];
3030 throw new Error( 'Cannot remove window' );
3032 promises
.push( this.closeWindow( name
).then( cleanup
.bind( null, name
, win
) ) );
3035 return $.when
.apply( $, promises
);
3039 * Remove all windows.
3041 * Windows will be closed before they are removed.
3043 * @return {jQuery.Promise} Promise resolved when all windows are closed and removed
3045 OO
.ui
.WindowManager
.prototype.clearWindows = function () {
3046 return this.removeWindows( Object
.keys( this.windows
) );
3052 * Fullscreen mode will be used if the dialog is too wide to fit in the screen.
3056 OO
.ui
.WindowManager
.prototype.updateWindowSize = function ( win
) {
3057 // Bypass for non-current, and thus invisible, windows
3058 if ( win
!== this.currentWindow
) {
3062 var viewport
= OO
.ui
.Element
.getDimensions( win
.getElementWindow() ),
3063 sizes
= this.constructor.static.sizes
,
3064 size
= win
.getSize();
3066 if ( !sizes
[size
] ) {
3067 size
= this.constructor.static.defaultSize
;
3069 if ( size
!== 'full' && viewport
.rect
.right
- viewport
.rect
.left
< sizes
[size
].width
) {
3073 this.$element
.toggleClass( 'oo-ui-windowManager-fullscreen', size
=== 'full' );
3074 this.$element
.toggleClass( 'oo-ui-windowManager-floating', size
!== 'full' );
3075 win
.setDimensions( sizes
[size
] );
3077 this.emit( 'resize', win
);
3083 * Bind or unbind global events for scrolling.
3085 * @param {boolean} [on] Bind global events
3088 OO
.ui
.WindowManager
.prototype.toggleGlobalEvents = function ( on
) {
3089 on
= on
=== undefined ? !!this.globalEvents
: !!on
;
3092 if ( !this.globalEvents
) {
3093 this.$( this.getElementDocument() ).on( {
3094 // Prevent scrolling by keys in top-level window
3095 keydown
: this.onDocumentKeyDownHandler
3097 this.$( this.getElementWindow() ).on( {
3098 // Prevent scrolling by wheel in top-level window
3099 mousewheel
: this.onWindowMouseWheelHandler
,
3100 // Start listening for top-level window dimension changes
3101 'orientationchange resize': this.onWindowResizeHandler
3103 this.globalEvents
= true;
3105 } else if ( this.globalEvents
) {
3106 // Unbind global events
3107 this.$( this.getElementDocument() ).off( {
3108 // Allow scrolling by keys in top-level window
3109 keydown
: this.onDocumentKeyDownHandler
3111 this.$( this.getElementWindow() ).off( {
3112 // Allow scrolling by wheel in top-level window
3113 mousewheel
: this.onWindowMouseWheelHandler
,
3114 // Stop listening for top-level window dimension changes
3115 'orientationchange resize': this.onWindowResizeHandler
3117 this.globalEvents
= false;
3124 * Toggle screen reader visibility of content other than the window manager.
3126 * @param {boolean} [isolate] Make only the window manager visible to screen readers
3129 OO
.ui
.WindowManager
.prototype.toggleAriaIsolation = function ( isolate
) {
3130 isolate
= isolate
=== undefined ? !this.$ariaHidden
: !!isolate
;
3133 if ( !this.$ariaHidden
) {
3134 // Hide everything other than the window manager from screen readers
3135 this.$ariaHidden
= $( 'body' )
3137 .not( this.$element
.parentsUntil( 'body' ).last() )
3138 .attr( 'aria-hidden', '' );
3140 } else if ( this.$ariaHidden
) {
3141 // Restore screen reader visiblity
3142 this.$ariaHidden
.removeAttr( 'aria-hidden' );
3143 this.$ariaHidden
= null;
3150 * Destroy window manager.
3152 * Windows will not be closed, only removed from the DOM.
3154 OO
.ui
.WindowManager
.prototype.destroy = function () {
3155 this.toggleGlobalEvents( false );
3156 this.toggleAriaIsolation( false );
3157 this.$element
.remove();
3165 * @param {string|jQuery} message Description of error
3166 * @param {Object} [config] Configuration options
3167 * @cfg {boolean} [recoverable=true] Error is recoverable
3168 * @cfg {boolean} [warning=false] Whether this error is a warning or not.
3170 OO
.ui
.Error
= function OoUiElement( message
, config
) {
3171 // Configuration initialization
3172 config
= config
|| {};
3175 this.message
= message
instanceof jQuery
? message
: String( message
);
3176 this.recoverable
= config
.recoverable
=== undefined || !!config
.recoverable
;
3177 this.warning
= !!config
.warning
;
3182 OO
.initClass( OO
.ui
.Error
);
3187 * Check if error can be recovered from.
3189 * @return {boolean} Error is recoverable
3191 OO
.ui
.Error
.prototype.isRecoverable = function () {
3192 return this.recoverable
;
3196 * Check if the error is a warning
3198 * @return {boolean} Error is warning
3200 OO
.ui
.Error
.prototype.isWarning = function () {
3201 return this.warning
;
3205 * Get error message as DOM nodes.
3207 * @return {jQuery} Error message in DOM nodes
3209 OO
.ui
.Error
.prototype.getMessage = function () {
3210 return this.message
instanceof jQuery
?
3211 this.message
.clone() :
3212 $( '<div>' ).text( this.message
).contents();
3216 * Get error message as text.
3218 * @return {string} Error message
3220 OO
.ui
.Error
.prototype.getMessageText = function () {
3221 return this.message
instanceof jQuery
? this.message
.text() : this.message
;
3225 * A list of functions, called in sequence.
3227 * If a function added to a process returns boolean false the process will stop; if it returns an
3228 * object with a `promise` method the process will use the promise to either continue to the next
3229 * step when the promise is resolved or stop when the promise is rejected.
3234 * @param {number|jQuery.Promise|Function} step Time to wait, promise to wait for or function to
3235 * call, see #createStep for more information
3236 * @param {Object} [context=null] Context to call the step function in, ignored if step is a number
3238 * @return {Object} Step object, with `callback` and `context` properties
3240 OO
.ui
.Process = function ( step
, context
) {
3245 if ( step
!== undefined ) {
3246 this.next( step
, context
);
3252 OO
.initClass( OO
.ui
.Process
);
3257 * Start the process.
3259 * @return {jQuery.Promise} Promise that is resolved when all steps have completed or rejected when
3260 * any of the steps return boolean false or a promise which gets rejected; upon stopping the
3261 * process, the remaining steps will not be taken
3263 OO
.ui
.Process
.prototype.execute = function () {
3264 var i
, len
, promise
;
3267 * Continue execution.
3270 * @param {Array} step A function and the context it should be called in
3271 * @return {Function} Function that continues the process
3273 function proceed( step
) {
3274 return function () {
3275 // Execute step in the correct context
3277 result
= step
.callback
.call( step
.context
);
3279 if ( result
=== false ) {
3280 // Use rejected promise for boolean false results
3281 return $.Deferred().reject( [] ).promise();
3283 if ( typeof result
=== 'number' ) {
3285 throw new Error( 'Cannot go back in time: flux capacitor is out of service' );
3287 // Use a delayed promise for numbers, expecting them to be in milliseconds
3288 deferred
= $.Deferred();
3289 setTimeout( deferred
.resolve
, result
);
3290 return deferred
.promise();
3292 if ( result
instanceof OO
.ui
.Error
) {
3293 // Use rejected promise for error
3294 return $.Deferred().reject( [ result
] ).promise();
3296 if ( $.isArray( result
) && result
.length
&& result
[0] instanceof OO
.ui
.Error
) {
3297 // Use rejected promise for list of errors
3298 return $.Deferred().reject( result
).promise();
3300 // Duck-type the object to see if it can produce a promise
3301 if ( result
&& $.isFunction( result
.promise
) ) {
3302 // Use a promise generated from the result
3303 return result
.promise();
3305 // Use resolved promise for other results
3306 return $.Deferred().resolve().promise();
3310 if ( this.steps
.length
) {
3311 // Generate a chain reaction of promises
3312 promise
= proceed( this.steps
[0] )();
3313 for ( i
= 1, len
= this.steps
.length
; i
< len
; i
++ ) {
3314 promise
= promise
.then( proceed( this.steps
[i
] ) );
3317 promise
= $.Deferred().resolve().promise();
3324 * Create a process step.
3327 * @param {number|jQuery.Promise|Function} step
3329 * - Number of milliseconds to wait; or
3330 * - Promise to wait to be resolved; or
3331 * - Function to execute
3332 * - If it returns boolean false the process will stop
3333 * - If it returns an object with a `promise` method the process will use the promise to either
3334 * continue to the next step when the promise is resolved or stop when the promise is rejected
3335 * - If it returns a number, the process will wait for that number of milliseconds before
3337 * @param {Object} [context=null] Context to call the step function in, ignored if step is a number
3339 * @return {Object} Step object, with `callback` and `context` properties
3341 OO
.ui
.Process
.prototype.createStep = function ( step
, context
) {
3342 if ( typeof step
=== 'number' || $.isFunction( step
.promise
) ) {
3344 callback: function () {
3350 if ( $.isFunction( step
) ) {
3356 throw new Error( 'Cannot create process step: number, promise or function expected' );
3360 * Add step to the beginning of the process.
3362 * @inheritdoc #createStep
3363 * @return {OO.ui.Process} this
3366 OO
.ui
.Process
.prototype.first = function ( step
, context
) {
3367 this.steps
.unshift( this.createStep( step
, context
) );
3372 * Add step to the end of the process.
3374 * @inheritdoc #createStep
3375 * @return {OO.ui.Process} this
3378 OO
.ui
.Process
.prototype.next = function ( step
, context
) {
3379 this.steps
.push( this.createStep( step
, context
) );
3384 * Factory for tools.
3387 * @extends OO.Factory
3390 OO
.ui
.ToolFactory
= function OoUiToolFactory() {
3391 // Parent constructor
3392 OO
.ui
.ToolFactory
.super.call( this );
3397 OO
.inheritClass( OO
.ui
.ToolFactory
, OO
.Factory
);
3402 OO
.ui
.ToolFactory
.prototype.getTools = function ( include
, exclude
, promote
, demote
) {
3403 var i
, len
, included
, promoted
, demoted
,
3407 // Collect included and not excluded tools
3408 included
= OO
.simpleArrayDifference( this.extract( include
), this.extract( exclude
) );
3411 promoted
= this.extract( promote
, used
);
3412 demoted
= this.extract( demote
, used
);
3415 for ( i
= 0, len
= included
.length
; i
< len
; i
++ ) {
3416 if ( !used
[included
[i
]] ) {
3417 auto
.push( included
[i
] );
3421 return promoted
.concat( auto
).concat( demoted
);
3425 * Get a flat list of names from a list of names or groups.
3427 * Tools can be specified in the following ways:
3429 * - A specific tool: `{ name: 'tool-name' }` or `'tool-name'`
3430 * - All tools in a group: `{ group: 'group-name' }`
3431 * - All tools: `'*'`
3434 * @param {Array|string} collection List of tools
3435 * @param {Object} [used] Object with names that should be skipped as properties; extracted
3436 * names will be added as properties
3437 * @return {string[]} List of extracted names
3439 OO
.ui
.ToolFactory
.prototype.extract = function ( collection
, used
) {
3440 var i
, len
, item
, name
, tool
,
3443 if ( collection
=== '*' ) {
3444 for ( name
in this.registry
) {
3445 tool
= this.registry
[name
];
3447 // Only add tools by group name when auto-add is enabled
3448 tool
.static.autoAddToCatchall
&&
3449 // Exclude already used tools
3450 ( !used
|| !used
[name
] )
3458 } else if ( $.isArray( collection
) ) {
3459 for ( i
= 0, len
= collection
.length
; i
< len
; i
++ ) {
3460 item
= collection
[i
];
3461 // Allow plain strings as shorthand for named tools
3462 if ( typeof item
=== 'string' ) {
3463 item
= { name
: item
};
3465 if ( OO
.isPlainObject( item
) ) {
3467 for ( name
in this.registry
) {
3468 tool
= this.registry
[name
];
3470 // Include tools with matching group
3471 tool
.static.group
=== item
.group
&&
3472 // Only add tools by group name when auto-add is enabled
3473 tool
.static.autoAddToGroup
&&
3474 // Exclude already used tools
3475 ( !used
|| !used
[name
] )
3483 // Include tools with matching name and exclude already used tools
3484 } else if ( item
.name
&& ( !used
|| !used
[item
.name
] ) ) {
3485 names
.push( item
.name
);
3487 used
[item
.name
] = true;
3497 * Factory for tool groups.
3500 * @extends OO.Factory
3503 OO
.ui
.ToolGroupFactory
= function OoUiToolGroupFactory() {
3504 // Parent constructor
3505 OO
.Factory
.call( this );
3508 defaultClasses
= this.constructor.static.getDefaultClasses();
3510 // Register default toolgroups
3511 for ( i
= 0, l
= defaultClasses
.length
; i
< l
; i
++ ) {
3512 this.register( defaultClasses
[i
] );
3518 OO
.inheritClass( OO
.ui
.ToolGroupFactory
, OO
.Factory
);
3520 /* Static Methods */
3523 * Get a default set of classes to be registered on construction
3525 * @return {Function[]} Default classes
3527 OO
.ui
.ToolGroupFactory
.static.getDefaultClasses = function () {
3530 OO
.ui
.ListToolGroup
,
3542 * @param {Object} [config] Configuration options
3544 OO
.ui
.Theme
= function OoUiTheme( config
) {
3545 // Configuration initialization
3546 config
= config
|| {};
3551 OO
.initClass( OO
.ui
.Theme
);
3556 * Get a list of classes to be applied to a widget.
3558 * The 'on' and 'off' lists combined MUST contain keys for all classes the theme adds or removes,
3559 * otherwise state transitions will not work properly.
3561 * @param {OO.ui.Element} element Element for which to get classes
3562 * @return {Object.<string,string[]>} Categorized class names with `on` and `off` lists
3564 OO
.ui
.Theme
.prototype.getElementClasses = function ( /* element */ ) {
3565 return { on
: [], off
: [] };
3569 * Update CSS classes provided by the theme.
3571 * For elements with theme logic hooks, this should be called anytime there's a state change.
3573 * @param {OO.ui.Element} element Element for which to update classes
3574 * @return {Object.<string,string[]>} Categorized class names with `on` and `off` lists
3576 OO
.ui
.Theme
.prototype.updateElementClasses = function ( element
) {
3577 var classes
= this.getElementClasses( element
);
3580 .removeClass( classes
.off
.join( ' ' ) )
3581 .addClass( classes
.on
.join( ' ' ) );
3585 * Element with a button.
3587 * Buttons are used for controls which can be clicked. They can be configured to use tab indexing
3588 * and access keys for accessibility purposes.
3594 * @param {Object} [config] Configuration options
3595 * @cfg {jQuery} [$button] Button node, assigned to #$button, omit to use a generated `<a>`
3596 * @cfg {boolean} [framed=true] Render button with a frame
3597 * @cfg {number} [tabIndex=0] Button's tab index. Use 0 to use default ordering, use -1 to prevent
3599 * @cfg {string} [accessKey] Button's access key
3601 OO
.ui
.ButtonElement
= function OoUiButtonElement( config
) {
3602 // Configuration initialization
3603 config
= config
|| {};
3606 this.$button
= null;
3608 this.tabIndex
= null;
3609 this.accessKey
= null;
3610 this.active
= false;
3611 this.onMouseUpHandler
= this.onMouseUp
.bind( this );
3612 this.onMouseDownHandler
= this.onMouseDown
.bind( this );
3615 this.$element
.addClass( 'oo-ui-buttonElement' );
3616 this.toggleFramed( config
.framed
=== undefined || config
.framed
);
3617 this.setTabIndex( config
.tabIndex
|| 0 );
3618 this.setAccessKey( config
.accessKey
);
3619 this.setButtonElement( config
.$button
|| this.$( '<a>' ) );
3624 OO
.initClass( OO
.ui
.ButtonElement
);
3626 /* Static Properties */
3629 * Cancel mouse down events.
3633 * @property {boolean}
3635 OO
.ui
.ButtonElement
.static.cancelButtonMouseDownEvents
= true;
3640 * Set the button element.
3642 * If an element is already set, it will be cleaned up before setting up the new element.
3644 * @param {jQuery} $button Element to use as button
3646 OO
.ui
.ButtonElement
.prototype.setButtonElement = function ( $button
) {
3647 if ( this.$button
) {
3649 .removeClass( 'oo-ui-buttonElement-button' )
3650 .removeAttr( 'role accesskey tabindex' )
3651 .off( this.onMouseDownHandler
);
3654 this.$button
= $button
3655 .addClass( 'oo-ui-buttonElement-button' )
3656 .attr( { role
: 'button', accesskey
: this.accessKey
, tabindex
: this.tabIndex
} )
3657 .on( 'mousedown', this.onMouseDownHandler
);
3661 * Handles mouse down events.
3663 * @param {jQuery.Event} e Mouse down event
3665 OO
.ui
.ButtonElement
.prototype.onMouseDown = function ( e
) {
3666 if ( this.isDisabled() || e
.which
!== 1 ) {
3669 // Remove the tab-index while the button is down to prevent the button from stealing focus
3670 this.$button
.removeAttr( 'tabindex' );
3671 this.$element
.addClass( 'oo-ui-buttonElement-pressed' );
3672 // Run the mouseup handler no matter where the mouse is when the button is let go, so we can
3673 // reliably reapply the tabindex and remove the pressed class
3674 this.getElementDocument().addEventListener( 'mouseup', this.onMouseUpHandler
, true );
3675 // Prevent change of focus unless specifically configured otherwise
3676 if ( this.constructor.static.cancelButtonMouseDownEvents
) {
3682 * Handles mouse up events.
3684 * @param {jQuery.Event} e Mouse up event
3686 OO
.ui
.ButtonElement
.prototype.onMouseUp = function ( e
) {
3687 if ( this.isDisabled() || e
.which
!== 1 ) {
3690 // Restore the tab-index after the button is up to restore the button's accesssibility
3691 this.$button
.attr( 'tabindex', this.tabIndex
);
3692 this.$element
.removeClass( 'oo-ui-buttonElement-pressed' );
3693 // Stop listening for mouseup, since we only needed this once
3694 this.getElementDocument().removeEventListener( 'mouseup', this.onMouseUpHandler
, true );
3698 * Check if button has a frame.
3700 * @return {boolean} Button is framed
3702 OO
.ui
.ButtonElement
.prototype.isFramed = function () {
3709 * @param {boolean} [framed] Make button framed, omit to toggle
3712 OO
.ui
.ButtonElement
.prototype.toggleFramed = function ( framed
) {
3713 framed
= framed
=== undefined ? !this.framed
: !!framed
;
3714 if ( framed
!== this.framed
) {
3715 this.framed
= framed
;
3717 .toggleClass( 'oo-ui-buttonElement-frameless', !framed
)
3718 .toggleClass( 'oo-ui-buttonElement-framed', framed
);
3719 this.updateThemeClasses();
3728 * @param {number|null} tabIndex Button's tab index, use null to remove
3731 OO
.ui
.ButtonElement
.prototype.setTabIndex = function ( tabIndex
) {
3732 tabIndex
= typeof tabIndex
=== 'number' && tabIndex
>= 0 ? tabIndex
: null;
3734 if ( this.tabIndex
!== tabIndex
) {
3735 if ( this.$button
) {
3736 if ( tabIndex
!== null ) {
3737 this.$button
.attr( 'tabindex', tabIndex
);
3739 this.$button
.removeAttr( 'tabindex' );
3742 this.tabIndex
= tabIndex
;
3751 * @param {string} accessKey Button's access key, use empty string to remove
3754 OO
.ui
.ButtonElement
.prototype.setAccessKey = function ( accessKey
) {
3755 accessKey
= typeof accessKey
=== 'string' && accessKey
.length
? accessKey
: null;
3757 if ( this.accessKey
!== accessKey
) {
3758 if ( this.$button
) {
3759 if ( accessKey
!== null ) {
3760 this.$button
.attr( 'accesskey', accessKey
);
3762 this.$button
.removeAttr( 'accesskey' );
3765 this.accessKey
= accessKey
;
3774 * @param {boolean} [value] Make button active
3777 OO
.ui
.ButtonElement
.prototype.setActive = function ( value
) {
3778 this.$element
.toggleClass( 'oo-ui-buttonElement-active', !!value
);
3783 * Element containing a sequence of child elements.
3789 * @param {Object} [config] Configuration options
3790 * @cfg {jQuery} [$group] Container node, assigned to #$group, omit to use a generated `<div>`
3792 OO
.ui
.GroupElement
= function OoUiGroupElement( config
) {
3793 // Configuration intialization
3794 config
= config
|| {};
3799 this.aggregateItemEvents
= {};
3802 this.setGroupElement( config
.$group
|| this.$( '<div>' ) );
3808 * Set the group element.
3810 * If an element is already set, items will be moved to the new element.
3812 * @param {jQuery} $group Element to use as group
3814 OO
.ui
.GroupElement
.prototype.setGroupElement = function ( $group
) {
3817 this.$group
= $group
;
3818 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
3819 this.$group
.append( this.items
[i
].$element
);
3824 * Check if there are no items.
3826 * @return {boolean} Group is empty
3828 OO
.ui
.GroupElement
.prototype.isEmpty = function () {
3829 return !this.items
.length
;
3835 * @return {OO.ui.Element[]} Items
3837 OO
.ui
.GroupElement
.prototype.getItems = function () {
3838 return this.items
.slice( 0 );
3842 * Add an aggregate item event.
3844 * Aggregated events are listened to on each item and then emitted by the group under a new name,
3845 * and with an additional leading parameter containing the item that emitted the original event.
3846 * Other arguments that were emitted from the original event are passed through.
3848 * @param {Object.<string,string|null>} events Aggregate events emitted by group, keyed by item
3849 * event, use null value to remove aggregation
3850 * @throws {Error} If aggregation already exists
3852 OO
.ui
.GroupElement
.prototype.aggregate = function ( events
) {
3853 var i
, len
, item
, add
, remove
, itemEvent
, groupEvent
;
3855 for ( itemEvent
in events
) {
3856 groupEvent
= events
[itemEvent
];
3858 // Remove existing aggregated event
3859 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
3860 // Don't allow duplicate aggregations
3862 throw new Error( 'Duplicate item event aggregation for ' + itemEvent
);
3864 // Remove event aggregation from existing items
3865 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
3866 item
= this.items
[i
];
3867 if ( item
.connect
&& item
.disconnect
) {
3869 remove
[itemEvent
] = [ 'emit', groupEvent
, item
];
3870 item
.disconnect( this, remove
);
3873 // Prevent future items from aggregating event
3874 delete this.aggregateItemEvents
[itemEvent
];
3877 // Add new aggregate event
3879 // Make future items aggregate event
3880 this.aggregateItemEvents
[itemEvent
] = groupEvent
;
3881 // Add event aggregation to existing items
3882 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
3883 item
= this.items
[i
];
3884 if ( item
.connect
&& item
.disconnect
) {
3886 add
[itemEvent
] = [ 'emit', groupEvent
, item
];
3887 item
.connect( this, add
);
3897 * Adding an existing item will move it.
3899 * @param {OO.ui.Element[]} items Items
3900 * @param {number} [index] Index to insert items at
3903 OO
.ui
.GroupElement
.prototype.addItems = function ( items
, index
) {
3904 var i
, len
, item
, event
, events
, currentIndex
,
3907 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
3910 // Check if item exists then remove it first, effectively "moving" it
3911 currentIndex
= $.inArray( item
, this.items
);
3912 if ( currentIndex
>= 0 ) {
3913 this.removeItems( [ item
] );
3914 // Adjust index to compensate for removal
3915 if ( currentIndex
< index
) {
3920 if ( item
.connect
&& item
.disconnect
&& !$.isEmptyObject( this.aggregateItemEvents
) ) {
3922 for ( event
in this.aggregateItemEvents
) {
3923 events
[event
] = [ 'emit', this.aggregateItemEvents
[event
], item
];
3925 item
.connect( this, events
);
3927 item
.setElementGroup( this );
3928 itemElements
.push( item
.$element
.get( 0 ) );
3931 if ( index
=== undefined || index
< 0 || index
>= this.items
.length
) {
3932 this.$group
.append( itemElements
);
3933 this.items
.push
.apply( this.items
, items
);
3934 } else if ( index
=== 0 ) {
3935 this.$group
.prepend( itemElements
);
3936 this.items
.unshift
.apply( this.items
, items
);
3938 this.items
[index
].$element
.before( itemElements
);
3939 this.items
.splice
.apply( this.items
, [ index
, 0 ].concat( items
) );
3948 * Items will be detached, not removed, so they can be used later.
3950 * @param {OO.ui.Element[]} items Items to remove
3953 OO
.ui
.GroupElement
.prototype.removeItems = function ( items
) {
3954 var i
, len
, item
, index
, remove
, itemEvent
;
3956 // Remove specific items
3957 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
3959 index
= $.inArray( item
, this.items
);
3960 if ( index
!== -1 ) {
3962 item
.connect
&& item
.disconnect
&&
3963 !$.isEmptyObject( this.aggregateItemEvents
)
3966 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
3967 remove
[itemEvent
] = [ 'emit', this.aggregateItemEvents
[itemEvent
], item
];
3969 item
.disconnect( this, remove
);
3971 item
.setElementGroup( null );
3972 this.items
.splice( index
, 1 );
3973 item
.$element
.detach();
3983 * Items will be detached, not removed, so they can be used later.
3987 OO
.ui
.GroupElement
.prototype.clearItems = function () {
3988 var i
, len
, item
, remove
, itemEvent
;
3991 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
3992 item
= this.items
[i
];
3994 item
.connect
&& item
.disconnect
&&
3995 !$.isEmptyObject( this.aggregateItemEvents
)
3998 if ( Object
.prototype.hasOwnProperty
.call( this.aggregateItemEvents
, itemEvent
) ) {
3999 remove
[itemEvent
] = [ 'emit', this.aggregateItemEvents
[itemEvent
], item
];
4001 item
.disconnect( this, remove
);
4003 item
.setElementGroup( null );
4004 item
.$element
.detach();
4012 * Element containing an icon.
4014 * Icons are graphics, about the size of normal text. They can be used to aid the user in locating
4015 * a control or convey information in a more space efficient way. Icons should rarely be used
4016 * without labels; such as in a toolbar where space is at a premium or within a context where the
4017 * meaning is very clear to the user.
4023 * @param {Object} [config] Configuration options
4024 * @cfg {jQuery} [$icon] Icon node, assigned to #$icon, omit to use a generated `<span>`
4025 * @cfg {Object|string} [icon=''] Symbolic icon name, or map of icon names keyed by language ID;
4026 * use the 'default' key to specify the icon to be used when there is no icon in the user's
4028 * @cfg {string} [iconTitle] Icon title text or a function that returns text
4030 OO
.ui
.IconElement
= function OoUiIconElement( config
) {
4031 // Configuration intialization
4032 config
= config
|| {};
4037 this.iconTitle
= null;
4040 this.setIcon( config
.icon
|| this.constructor.static.icon
);
4041 this.setIconTitle( config
.iconTitle
|| this.constructor.static.iconTitle
);
4042 this.setIconElement( config
.$icon
|| this.$( '<span>' ) );
4047 OO
.initClass( OO
.ui
.IconElement
);
4049 /* Static Properties */
4054 * Value should be the unique portion of an icon CSS class name, such as 'up' for 'oo-ui-icon-up'.
4056 * For i18n purposes, this property can be an object containing a `default` icon name property and
4057 * additional icon names keyed by language code.
4059 * Example of i18n icon definition:
4060 * { default: 'bold-a', en: 'bold-b', de: 'bold-f' }
4064 * @property {Object|string} Symbolic icon name, or map of icon names keyed by language ID;
4065 * use the 'default' key to specify the icon to be used when there is no icon in the user's
4068 OO
.ui
.IconElement
.static.icon
= null;
4075 * @property {string|Function|null} Icon title text, a function that returns text or null for no
4078 OO
.ui
.IconElement
.static.iconTitle
= null;
4083 * Set the icon element.
4085 * If an element is already set, it will be cleaned up before setting up the new element.
4087 * @param {jQuery} $icon Element to use as icon
4089 OO
.ui
.IconElement
.prototype.setIconElement = function ( $icon
) {
4092 .removeClass( 'oo-ui-iconElement-icon oo-ui-icon-' + this.icon
)
4093 .removeAttr( 'title' );
4097 .addClass( 'oo-ui-iconElement-icon' )
4098 .toggleClass( 'oo-ui-icon-' + this.icon
, !!this.icon
);
4099 if ( this.iconTitle
!== null ) {
4100 this.$icon
.attr( 'title', this.iconTitle
);
4107 * @param {Object|string|null} icon Symbolic icon name, or map of icon names keyed by language ID;
4108 * use the 'default' key to specify the icon to be used when there is no icon in the user's
4109 * language, use null to remove icon
4112 OO
.ui
.IconElement
.prototype.setIcon = function ( icon
) {
4113 icon
= OO
.isPlainObject( icon
) ? OO
.ui
.getLocalValue( icon
, null, 'default' ) : icon
;
4114 icon
= typeof icon
=== 'string' && icon
.trim().length
? icon
.trim() : null;
4116 if ( this.icon
!== icon
) {
4118 if ( this.icon
!== null ) {
4119 this.$icon
.removeClass( 'oo-ui-icon-' + this.icon
);
4121 if ( icon
!== null ) {
4122 this.$icon
.addClass( 'oo-ui-icon-' + icon
);
4128 this.$element
.toggleClass( 'oo-ui-iconElement', !!this.icon
);
4129 this.updateThemeClasses();
4137 * @param {string|Function|null} icon Icon title text, a function that returns text or null
4141 OO
.ui
.IconElement
.prototype.setIconTitle = function ( iconTitle
) {
4142 iconTitle
= typeof iconTitle
=== 'function' ||
4143 ( typeof iconTitle
=== 'string' && iconTitle
.length
) ?
4144 OO
.ui
.resolveMsg( iconTitle
) : null;
4146 if ( this.iconTitle
!== iconTitle
) {
4147 this.iconTitle
= iconTitle
;
4149 if ( this.iconTitle
!== null ) {
4150 this.$icon
.attr( 'title', iconTitle
);
4152 this.$icon
.removeAttr( 'title' );
4163 * @return {string} Icon name
4165 OO
.ui
.IconElement
.prototype.getIcon = function () {
4170 * Element containing an indicator.
4172 * Indicators are graphics, smaller than normal text. They can be used to describe unique status or
4173 * behavior. Indicators should only be used in exceptional cases; such as a button that opens a menu
4174 * instead of performing an action directly, or an item in a list which has errors that need to be
4181 * @param {Object} [config] Configuration options
4182 * @cfg {jQuery} [$indicator] Indicator node, assigned to #$indicator, omit to use a generated
4184 * @cfg {string} [indicator] Symbolic indicator name
4185 * @cfg {string} [indicatorTitle] Indicator title text or a function that returns text
4187 OO
.ui
.IndicatorElement
= function OoUiIndicatorElement( config
) {
4188 // Configuration initialization
4189 config
= config
|| {};
4192 this.$indicator
= null;
4193 this.indicator
= null;
4194 this.indicatorTitle
= null;
4197 this.setIndicator( config
.indicator
|| this.constructor.static.indicator
);
4198 this.setIndicatorTitle( config
.indicatorTitle
|| this.constructor.static.indicatorTitle
);
4199 this.setIndicatorElement( config
.$indicator
|| this.$( '<span>' ) );
4204 OO
.initClass( OO
.ui
.IndicatorElement
);
4206 /* Static Properties */
4213 * @property {string|null} Symbolic indicator name
4215 OO
.ui
.IndicatorElement
.static.indicator
= null;
4222 * @property {string|Function|null} Indicator title text, a function that returns text or null for no
4225 OO
.ui
.IndicatorElement
.static.indicatorTitle
= null;
4230 * Set the indicator element.
4232 * If an element is already set, it will be cleaned up before setting up the new element.
4234 * @param {jQuery} $indicator Element to use as indicator
4236 OO
.ui
.IndicatorElement
.prototype.setIndicatorElement = function ( $indicator
) {
4237 if ( this.$indicator
) {
4239 .removeClass( 'oo-ui-indicatorElement-indicator oo-ui-indicator-' + this.indicator
)
4240 .removeAttr( 'title' );
4243 this.$indicator
= $indicator
4244 .addClass( 'oo-ui-indicatorElement-indicator' )
4245 .toggleClass( 'oo-ui-indicator-' + this.indicator
, !!this.indicator
);
4246 if ( this.indicatorTitle
!== null ) {
4247 this.$indicatorTitle
.attr( 'title', this.indicatorTitle
);
4252 * Set indicator name.
4254 * @param {string|null} indicator Symbolic name of indicator to use or null for no indicator
4257 OO
.ui
.IndicatorElement
.prototype.setIndicator = function ( indicator
) {
4258 indicator
= typeof indicator
=== 'string' && indicator
.length
? indicator
.trim() : null;
4260 if ( this.indicator
!== indicator
) {
4261 if ( this.$indicator
) {
4262 if ( this.indicator
!== null ) {
4263 this.$indicator
.removeClass( 'oo-ui-indicator-' + this.indicator
);
4265 if ( indicator
!== null ) {
4266 this.$indicator
.addClass( 'oo-ui-indicator-' + indicator
);
4269 this.indicator
= indicator
;
4272 this.$element
.toggleClass( 'oo-ui-indicatorElement', !!this.indicator
);
4273 this.updateThemeClasses();
4279 * Set indicator title.
4281 * @param {string|Function|null} indicator Indicator title text, a function that returns text or
4282 * null for no indicator title
4285 OO
.ui
.IndicatorElement
.prototype.setIndicatorTitle = function ( indicatorTitle
) {
4286 indicatorTitle
= typeof indicatorTitle
=== 'function' ||
4287 ( typeof indicatorTitle
=== 'string' && indicatorTitle
.length
) ?
4288 OO
.ui
.resolveMsg( indicatorTitle
) : null;
4290 if ( this.indicatorTitle
!== indicatorTitle
) {
4291 this.indicatorTitle
= indicatorTitle
;
4292 if ( this.$indicator
) {
4293 if ( this.indicatorTitle
!== null ) {
4294 this.$indicator
.attr( 'title', indicatorTitle
);
4296 this.$indicator
.removeAttr( 'title' );
4305 * Get indicator name.
4307 * @return {string} Symbolic name of indicator
4309 OO
.ui
.IndicatorElement
.prototype.getIndicator = function () {
4310 return this.indicator
;
4314 * Get indicator title.
4316 * @return {string} Indicator title text
4318 OO
.ui
.IndicatorElement
.prototype.getIndicatorTitle = function () {
4319 return this.indicatorTitle
;
4323 * Element containing a label.
4329 * @param {Object} [config] Configuration options
4330 * @cfg {jQuery} [$label] Label node, assigned to #$label, omit to use a generated `<span>`
4331 * @cfg {jQuery|string|Function} [label] Label nodes, text or a function that returns nodes or text
4332 * @cfg {boolean} [autoFitLabel=true] Whether to fit the label or not.
4334 OO
.ui
.LabelElement
= function OoUiLabelElement( config
) {
4335 // Configuration initialization
4336 config
= config
|| {};
4341 this.autoFitLabel
= config
.autoFitLabel
=== undefined || !!config
.autoFitLabel
;
4344 this.setLabel( config
.label
|| this.constructor.static.label
);
4345 this.setLabelElement( config
.$label
|| this.$( '<span>' ) );
4350 OO
.initClass( OO
.ui
.LabelElement
);
4352 /* Static Properties */
4359 * @property {string|Function|null} Label text; a function that returns nodes or text; or null for
4362 OO
.ui
.LabelElement
.static.label
= null;
4367 * Set the label element.
4369 * If an element is already set, it will be cleaned up before setting up the new element.
4371 * @param {jQuery} $label Element to use as label
4373 OO
.ui
.LabelElement
.prototype.setLabelElement = function ( $label
) {
4374 if ( this.$label
) {
4375 this.$label
.removeClass( 'oo-ui-labelElement-label' ).empty();
4378 this.$label
= $label
.addClass( 'oo-ui-labelElement-label' );
4379 this.setLabelContent( this.label
);
4385 * An empty string will result in the label being hidden. A string containing only whitespace will
4386 * be converted to a single ` `.
4388 * @param {jQuery|string|Function|null} label Label nodes; text; a function that returns nodes or
4389 * text; or null for no label
4392 OO
.ui
.LabelElement
.prototype.setLabel = function ( label
) {
4393 label
= typeof label
=== 'function' ? OO
.ui
.resolveMsg( label
) : label
;
4394 label
= ( typeof label
=== 'string' && label
.length
) || label
instanceof jQuery
? label
: null;
4396 if ( this.label
!== label
) {
4397 if ( this.$label
) {
4398 this.setLabelContent( label
);
4403 this.$element
.toggleClass( 'oo-ui-labelElement', !!this.label
);
4411 * @return {jQuery|string|Function|null} Label nodes; text; a function that returns nodes or
4412 * text; or null for no label
4414 OO
.ui
.LabelElement
.prototype.getLabel = function () {
4423 OO
.ui
.LabelElement
.prototype.fitLabel = function () {
4424 if ( this.$label
&& this.$label
.autoEllipsis
&& this.autoFitLabel
) {
4425 this.$label
.autoEllipsis( { hasSpan
: false, tooltip
: true } );
4432 * Set the content of the label.
4434 * Do not call this method until after the label element has been set by #setLabelElement.
4437 * @param {jQuery|string|Function|null} label Label nodes; text; a function that returns nodes or
4438 * text; or null for no label
4440 OO
.ui
.LabelElement
.prototype.setLabelContent = function ( label
) {
4441 if ( typeof label
=== 'string' ) {
4442 if ( label
.match( /^\s*$/ ) ) {
4443 // Convert whitespace only string to a single non-breaking space
4444 this.$label
.html( ' ' );
4446 this.$label
.text( label
);
4448 } else if ( label
instanceof jQuery
) {
4449 this.$label
.empty().append( label
);
4451 this.$label
.empty();
4453 this.$label
.css( 'display', !label
? 'none' : '' );
4457 * Element containing an OO.ui.PopupWidget object.
4463 * @param {Object} [config] Configuration options
4464 * @cfg {Object} [popup] Configuration to pass to popup
4465 * @cfg {boolean} [autoClose=true] Popup auto-closes when it loses focus
4467 OO
.ui
.PopupElement
= function OoUiPopupElement( config
) {
4468 // Configuration initialization
4469 config
= config
|| {};
4472 this.popup
= new OO
.ui
.PopupWidget( $.extend(
4473 { autoClose
: true },
4475 { $: this.$, $autoCloseIgnore
: this.$element
}
4484 * @return {OO.ui.PopupWidget} Popup widget
4486 OO
.ui
.PopupElement
.prototype.getPopup = function () {
4491 * Element with named flags that can be added, removed, listed and checked.
4493 * A flag, when set, adds a CSS class on the `$element` by combining `oo-ui-flaggedElement-` with
4494 * the flag name. Flags are primarily useful for styling.
4500 * @param {Object} [config] Configuration options
4501 * @cfg {string|string[]} [flags] Styling flags, e.g. 'primary', 'destructive' or 'constructive'
4502 * @cfg {jQuery} [$flagged] Flagged node, assigned to #$flagged, omit to use #$element
4504 OO
.ui
.FlaggedElement
= function OoUiFlaggedElement( config
) {
4505 // Configuration initialization
4506 config
= config
|| {};
4510 this.$flagged
= null;
4513 this.setFlags( config
.flags
);
4514 this.setFlaggedElement( config
.$flagged
|| this.$element
);
4521 * @param {Object.<string,boolean>} changes Object keyed by flag name containing boolean
4522 * added/removed properties
4528 * Set the flagged element.
4530 * If an element is already set, it will be cleaned up before setting up the new element.
4532 * @param {jQuery} $flagged Element to add flags to
4534 OO
.ui
.FlaggedElement
.prototype.setFlaggedElement = function ( $flagged
) {
4535 var classNames
= Object
.keys( this.flags
).map( function ( flag
) {
4536 return 'oo-ui-flaggedElement-' + flag
;
4539 if ( this.$flagged
) {
4540 this.$flagged
.removeClass( classNames
);
4543 this.$flagged
= $flagged
.addClass( classNames
);
4547 * Check if a flag is set.
4549 * @param {string} flag Name of flag
4550 * @return {boolean} Has flag
4552 OO
.ui
.FlaggedElement
.prototype.hasFlag = function ( flag
) {
4553 return flag
in this.flags
;
4557 * Get the names of all flags set.
4559 * @return {string[]} Flag names
4561 OO
.ui
.FlaggedElement
.prototype.getFlags = function () {
4562 return Object
.keys( this.flags
);
4571 OO
.ui
.FlaggedElement
.prototype.clearFlags = function () {
4572 var flag
, className
,
4575 classPrefix
= 'oo-ui-flaggedElement-';
4577 for ( flag
in this.flags
) {
4578 className
= classPrefix
+ flag
;
4579 changes
[flag
] = false;
4580 delete this.flags
[flag
];
4581 remove
.push( className
);
4584 if ( this.$flagged
) {
4585 this.$flagged
.removeClass( remove
.join( ' ' ) );
4588 this.updateThemeClasses();
4589 this.emit( 'flag', changes
);
4595 * Add one or more flags.
4597 * @param {string|string[]|Object.<string, boolean>} flags One or more flags to add, or an object
4598 * keyed by flag name containing boolean set/remove instructions.
4602 OO
.ui
.FlaggedElement
.prototype.setFlags = function ( flags
) {
4603 var i
, len
, flag
, className
,
4607 classPrefix
= 'oo-ui-flaggedElement-';
4609 if ( typeof flags
=== 'string' ) {
4610 className
= classPrefix
+ flags
;
4612 if ( !this.flags
[flags
] ) {
4613 this.flags
[flags
] = true;
4614 add
.push( className
);
4616 } else if ( $.isArray( flags
) ) {
4617 for ( i
= 0, len
= flags
.length
; i
< len
; i
++ ) {
4619 className
= classPrefix
+ flag
;
4621 if ( !this.flags
[flag
] ) {
4622 changes
[flag
] = true;
4623 this.flags
[flag
] = true;
4624 add
.push( className
);
4627 } else if ( OO
.isPlainObject( flags
) ) {
4628 for ( flag
in flags
) {
4629 className
= classPrefix
+ flag
;
4630 if ( flags
[flag
] ) {
4632 if ( !this.flags
[flag
] ) {
4633 changes
[flag
] = true;
4634 this.flags
[flag
] = true;
4635 add
.push( className
);
4639 if ( this.flags
[flag
] ) {
4640 changes
[flag
] = false;
4641 delete this.flags
[flag
];
4642 remove
.push( className
);
4648 if ( this.$flagged
) {
4650 .addClass( add
.join( ' ' ) )
4651 .removeClass( remove
.join( ' ' ) );
4654 this.updateThemeClasses();
4655 this.emit( 'flag', changes
);
4661 * Element with a title.
4663 * Titles are rendered by the browser and are made visible when hovering the element. Titles are
4664 * not visible on touch devices.
4670 * @param {Object} [config] Configuration options
4671 * @cfg {jQuery} [$titled] Titled node, assigned to #$titled, omit to use #$element
4672 * @cfg {string|Function} [title] Title text or a function that returns text. If not provided, the
4673 * static property 'title' is used.
4675 OO
.ui
.TitledElement
= function OoUiTitledElement( config
) {
4676 // Configuration initialization
4677 config
= config
|| {};
4680 this.$titled
= null;
4684 this.setTitle( config
.title
|| this.constructor.static.title
);
4685 this.setTitledElement( config
.$titled
|| this.$element
);
4690 OO
.initClass( OO
.ui
.TitledElement
);
4692 /* Static Properties */
4699 * @property {string|Function} Title text or a function that returns text
4701 OO
.ui
.TitledElement
.static.title
= null;
4706 * Set the titled element.
4708 * If an element is already set, it will be cleaned up before setting up the new element.
4710 * @param {jQuery} $titled Element to set title on
4712 OO
.ui
.TitledElement
.prototype.setTitledElement = function ( $titled
) {
4713 if ( this.$titled
) {
4714 this.$titled
.removeAttr( 'title' );
4717 this.$titled
= $titled
;
4719 this.$titled
.attr( 'title', this.title
);
4726 * @param {string|Function|null} title Title text, a function that returns text or null for no title
4729 OO
.ui
.TitledElement
.prototype.setTitle = function ( title
) {
4730 title
= typeof title
=== 'string' ? OO
.ui
.resolveMsg( title
) : null;
4732 if ( this.title
!== title
) {
4733 if ( this.$titled
) {
4734 if ( title
!== null ) {
4735 this.$titled
.attr( 'title', title
);
4737 this.$titled
.removeAttr( 'title' );
4749 * @return {string} Title string
4751 OO
.ui
.TitledElement
.prototype.getTitle = function () {
4756 * Element that can be automatically clipped to visible boundaries.
4758 * Whenever the element's natural height changes, you have to call
4759 * #clip to make sure it's still clipping correctly.
4765 * @param {Object} [config] Configuration options
4766 * @cfg {jQuery} [$clippable] Nodes to clip, assigned to #$clippable, omit to use #$element
4768 OO
.ui
.ClippableElement
= function OoUiClippableElement( config
) {
4769 // Configuration initialization
4770 config
= config
|| {};
4773 this.$clippable
= null;
4774 this.clipping
= false;
4775 this.clippedHorizontally
= false;
4776 this.clippedVertically
= false;
4777 this.$clippableContainer
= null;
4778 this.$clippableScroller
= null;
4779 this.$clippableWindow
= null;
4780 this.idealWidth
= null;
4781 this.idealHeight
= null;
4782 this.onClippableContainerScrollHandler
= this.clip
.bind( this );
4783 this.onClippableWindowResizeHandler
= this.clip
.bind( this );
4786 this.setClippableElement( config
.$clippable
|| this.$element
);
4792 * Set clippable element.
4794 * If an element is already set, it will be cleaned up before setting up the new element.
4796 * @param {jQuery} $clippable Element to make clippable
4798 OO
.ui
.ClippableElement
.prototype.setClippableElement = function ( $clippable
) {
4799 if ( this.$clippable
) {
4800 this.$clippable
.removeClass( 'oo-ui-clippableElement-clippable' );
4801 this.$clippable
.css( { width
: '', height
: '' } );
4802 this.$clippable
.width(); // Force reflow for https://code.google.com/p/chromium/issues/detail?id=387290
4803 this.$clippable
.css( { overflowX
: '', overflowY
: '' } );
4806 this.$clippable
= $clippable
.addClass( 'oo-ui-clippableElement-clippable' );
4813 * Do not turn clipping on until after the element is attached to the DOM and visible.
4815 * @param {boolean} [clipping] Enable clipping, omit to toggle
4818 OO
.ui
.ClippableElement
.prototype.toggleClipping = function ( clipping
) {
4819 clipping
= clipping
=== undefined ? !this.clipping
: !!clipping
;
4821 if ( this.clipping
!== clipping
) {
4822 this.clipping
= clipping
;
4824 this.$clippableContainer
= this.$( this.getClosestScrollableElementContainer() );
4825 // If the clippable container is the body, we have to listen to scroll events and check
4826 // jQuery.scrollTop on the window because of browser inconsistencies
4827 this.$clippableScroller
= this.$clippableContainer
.is( 'body' ) ?
4828 this.$( OO
.ui
.Element
.getWindow( this.$clippableContainer
) ) :
4829 this.$clippableContainer
;
4830 this.$clippableScroller
.on( 'scroll', this.onClippableContainerScrollHandler
);
4831 this.$clippableWindow
= this.$( this.getElementWindow() )
4832 .on( 'resize', this.onClippableWindowResizeHandler
);
4833 // Initial clip after visible
4836 this.$clippable
.css( { width
: '', height
: '' } );
4837 this.$clippable
.width(); // Force reflow for https://code.google.com/p/chromium/issues/detail?id=387290
4838 this.$clippable
.css( { overflowX
: '', overflowY
: '' } );
4840 this.$clippableContainer
= null;
4841 this.$clippableScroller
.off( 'scroll', this.onClippableContainerScrollHandler
);
4842 this.$clippableScroller
= null;
4843 this.$clippableWindow
.off( 'resize', this.onClippableWindowResizeHandler
);
4844 this.$clippableWindow
= null;
4852 * Check if the element will be clipped to fit the visible area of the nearest scrollable container.
4854 * @return {boolean} Element will be clipped to the visible area
4856 OO
.ui
.ClippableElement
.prototype.isClipping = function () {
4857 return this.clipping
;
4861 * Check if the bottom or right of the element is being clipped by the nearest scrollable container.
4863 * @return {boolean} Part of the element is being clipped
4865 OO
.ui
.ClippableElement
.prototype.isClipped = function () {
4866 return this.clippedHorizontally
|| this.clippedVertically
;
4870 * Check if the right of the element is being clipped by the nearest scrollable container.
4872 * @return {boolean} Part of the element is being clipped
4874 OO
.ui
.ClippableElement
.prototype.isClippedHorizontally = function () {
4875 return this.clippedHorizontally
;
4879 * Check if the bottom of the element is being clipped by the nearest scrollable container.
4881 * @return {boolean} Part of the element is being clipped
4883 OO
.ui
.ClippableElement
.prototype.isClippedVertically = function () {
4884 return this.clippedVertically
;
4888 * Set the ideal size. These are the dimensions the element will have when it's not being clipped.
4890 * @param {number|string} [width] Width as a number of pixels or CSS string with unit suffix
4891 * @param {number|string} [height] Height as a number of pixels or CSS string with unit suffix
4893 OO
.ui
.ClippableElement
.prototype.setIdealSize = function ( width
, height
) {
4894 this.idealWidth
= width
;
4895 this.idealHeight
= height
;
4897 if ( !this.clipping
) {
4898 // Update dimensions
4899 this.$clippable
.css( { width
: width
, height
: height
} );
4901 // While clipping, idealWidth and idealHeight are not considered
4905 * Clip element to visible boundaries and allow scrolling when needed. Call this method when
4906 * the element's natural height changes.
4908 * Element will be clipped the bottom or right of the element is within 10px of the edge of, or
4909 * overlapped by, the visible area of the nearest scrollable container.
4913 OO
.ui
.ClippableElement
.prototype.clip = function () {
4914 if ( !this.clipping
) {
4915 // this.$clippableContainer and this.$clippableWindow are null, so the below will fail
4920 cOffset
= this.$clippable
.offset(),
4921 $container
= this.$clippableContainer
.is( 'body' ) ?
4922 this.$clippableWindow
: this.$clippableContainer
,
4923 ccOffset
= $container
.offset() || { top
: 0, left
: 0 },
4924 ccHeight
= $container
.innerHeight() - buffer
,
4925 ccWidth
= $container
.innerWidth() - buffer
,
4926 scrollTop
= this.$clippableScroller
.scrollTop(),
4927 scrollLeft
= this.$clippableScroller
.scrollLeft(),
4928 desiredWidth
= ( ccOffset
.left
+ scrollLeft
+ ccWidth
) - cOffset
.left
,
4929 desiredHeight
= ( ccOffset
.top
+ scrollTop
+ ccHeight
) - cOffset
.top
,
4930 naturalWidth
= this.$clippable
.prop( 'scrollWidth' ),
4931 naturalHeight
= this.$clippable
.prop( 'scrollHeight' ),
4932 clipWidth
= desiredWidth
< naturalWidth
,
4933 clipHeight
= desiredHeight
< naturalHeight
;
4936 this.$clippable
.css( { overflowX
: 'scroll', width
: desiredWidth
} );
4938 this.$clippable
.css( 'width', this.idealWidth
|| '' );
4939 this.$clippable
.width(); // Force reflow for https://code.google.com/p/chromium/issues/detail?id=387290
4940 this.$clippable
.css( 'overflowX', '' );
4943 this.$clippable
.css( { overflowY
: 'scroll', height
: desiredHeight
} );
4945 this.$clippable
.css( 'height', this.idealHeight
|| '' );
4946 this.$clippable
.height(); // Force reflow for https://code.google.com/p/chromium/issues/detail?id=387290
4947 this.$clippable
.css( 'overflowY', '' );
4950 this.clippedHorizontally
= clipWidth
;
4951 this.clippedVertically
= clipHeight
;
4957 * Generic toolbar tool.
4961 * @extends OO.ui.Widget
4962 * @mixins OO.ui.IconElement
4963 * @mixins OO.ui.FlaggedElement
4966 * @param {OO.ui.ToolGroup} toolGroup
4967 * @param {Object} [config] Configuration options
4968 * @cfg {string|Function} [title] Title text or a function that returns text
4970 OO
.ui
.Tool
= function OoUiTool( toolGroup
, config
) {
4971 // Configuration initialization
4972 config
= config
|| {};
4974 // Parent constructor
4975 OO
.ui
.Tool
.super.call( this, config
);
4977 // Mixin constructors
4978 OO
.ui
.IconElement
.call( this, config
);
4979 OO
.ui
.FlaggedElement
.call( this, config
);
4982 this.toolGroup
= toolGroup
;
4983 this.toolbar
= this.toolGroup
.getToolbar();
4984 this.active
= false;
4985 this.$title
= this.$( '<span>' );
4986 this.$titleText
= this.$( '<span>' );
4987 this.$accel
= this.$( '<span>' );
4988 this.$link
= this.$( '<a>' );
4992 this.toolbar
.connect( this, { updateState
: 'onUpdateState' } );
4995 this.$titleText
.addClass( 'oo-ui-tool-title-text' );
4996 this.$accel
.addClass( 'oo-ui-tool-accel' );
4998 .addClass( 'oo-ui-tool-title' )
4999 .append( this.$titleText
, this.$accel
);
5001 .addClass( 'oo-ui-tool-link' )
5002 .append( this.$icon
, this.$title
)
5003 .prop( 'tabIndex', 0 )
5004 .attr( 'role', 'button' );
5006 .data( 'oo-ui-tool', this )
5008 'oo-ui-tool ' + 'oo-ui-tool-name-' +
5009 this.constructor.static.name
.replace( /^([^\/]+)\/([^\/]+).*$/, '$1-$2' )
5011 .append( this.$link
);
5012 this.setTitle( config
.title
|| this.constructor.static.title
);
5017 OO
.inheritClass( OO
.ui
.Tool
, OO
.ui
.Widget
);
5018 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.IconElement
);
5019 OO
.mixinClass( OO
.ui
.Tool
, OO
.ui
.FlaggedElement
);
5027 /* Static Properties */
5033 OO
.ui
.Tool
.static.tagName
= 'span';
5036 * Symbolic name of tool.
5041 * @property {string}
5043 OO
.ui
.Tool
.static.name
= '';
5051 * @property {string}
5053 OO
.ui
.Tool
.static.group
= '';
5058 * Title is used as a tooltip when the tool is part of a bar tool group, or a label when the tool
5059 * is part of a list or menu tool group. If a trigger is associated with an action by the same name
5060 * as the tool, a description of its keyboard shortcut for the appropriate platform will be
5061 * appended to the title if the tool is part of a bar tool group.
5066 * @property {string|Function} Title text or a function that returns text
5068 OO
.ui
.Tool
.static.title
= '';
5071 * Tool can be automatically added to catch-all groups.
5075 * @property {boolean}
5077 OO
.ui
.Tool
.static.autoAddToCatchall
= true;
5080 * Tool can be automatically added to named groups.
5083 * @property {boolean}
5086 OO
.ui
.Tool
.static.autoAddToGroup
= true;
5089 * Check if this tool is compatible with given data.
5093 * @param {Mixed} data Data to check
5094 * @return {boolean} Tool can be used with data
5096 OO
.ui
.Tool
.static.isCompatibleWith = function () {
5103 * Handle the toolbar state being updated.
5105 * This is an abstract method that must be overridden in a concrete subclass.
5109 OO
.ui
.Tool
.prototype.onUpdateState = function () {
5111 'OO.ui.Tool.onUpdateState not implemented in this subclass:' + this.constructor
5116 * Handle the tool being selected.
5118 * This is an abstract method that must be overridden in a concrete subclass.
5122 OO
.ui
.Tool
.prototype.onSelect = function () {
5124 'OO.ui.Tool.onSelect not implemented in this subclass:' + this.constructor
5129 * Check if the button is active.
5131 * @return {boolean} Button is active
5133 OO
.ui
.Tool
.prototype.isActive = function () {
5138 * Make the button appear active or inactive.
5140 * @param {boolean} state Make button appear active
5142 OO
.ui
.Tool
.prototype.setActive = function ( state
) {
5143 this.active
= !!state
;
5144 if ( this.active
) {
5145 this.$element
.addClass( 'oo-ui-tool-active' );
5147 this.$element
.removeClass( 'oo-ui-tool-active' );
5152 * Get the tool title.
5154 * @param {string|Function} title Title text or a function that returns text
5157 OO
.ui
.Tool
.prototype.setTitle = function ( title
) {
5158 this.title
= OO
.ui
.resolveMsg( title
);
5164 * Get the tool title.
5166 * @return {string} Title text
5168 OO
.ui
.Tool
.prototype.getTitle = function () {
5173 * Get the tool's symbolic name.
5175 * @return {string} Symbolic name of tool
5177 OO
.ui
.Tool
.prototype.getName = function () {
5178 return this.constructor.static.name
;
5184 OO
.ui
.Tool
.prototype.updateTitle = function () {
5185 var titleTooltips
= this.toolGroup
.constructor.static.titleTooltips
,
5186 accelTooltips
= this.toolGroup
.constructor.static.accelTooltips
,
5187 accel
= this.toolbar
.getToolAccelerator( this.constructor.static.name
),
5190 this.$titleText
.text( this.title
);
5191 this.$accel
.text( accel
);
5193 if ( titleTooltips
&& typeof this.title
=== 'string' && this.title
.length
) {
5194 tooltipParts
.push( this.title
);
5196 if ( accelTooltips
&& typeof accel
=== 'string' && accel
.length
) {
5197 tooltipParts
.push( accel
);
5199 if ( tooltipParts
.length
) {
5200 this.$link
.attr( 'title', tooltipParts
.join( ' ' ) );
5202 this.$link
.removeAttr( 'title' );
5209 OO
.ui
.Tool
.prototype.destroy = function () {
5210 this.toolbar
.disconnect( this );
5211 this.$element
.remove();
5215 * Collection of tool groups.
5218 * @extends OO.ui.Element
5219 * @mixins OO.EventEmitter
5220 * @mixins OO.ui.GroupElement
5223 * @param {OO.ui.ToolFactory} toolFactory Factory for creating tools
5224 * @param {OO.ui.ToolGroupFactory} toolGroupFactory Factory for creating tool groups
5225 * @param {Object} [config] Configuration options
5226 * @cfg {boolean} [actions] Add an actions section opposite to the tools
5227 * @cfg {boolean} [shadow] Add a shadow below the toolbar
5229 OO
.ui
.Toolbar
= function OoUiToolbar( toolFactory
, toolGroupFactory
, config
) {
5230 // Configuration initialization
5231 config
= config
|| {};
5233 // Parent constructor
5234 OO
.ui
.Toolbar
.super.call( this, config
);
5236 // Mixin constructors
5237 OO
.EventEmitter
.call( this );
5238 OO
.ui
.GroupElement
.call( this, config
);
5241 this.toolFactory
= toolFactory
;
5242 this.toolGroupFactory
= toolGroupFactory
;
5245 this.$bar
= this.$( '<div>' );
5246 this.$actions
= this.$( '<div>' );
5247 this.initialized
= false;
5251 .add( this.$bar
).add( this.$group
).add( this.$actions
)
5252 .on( 'mousedown touchstart', this.onPointerDown
.bind( this ) );
5255 this.$group
.addClass( 'oo-ui-toolbar-tools' );
5256 this.$bar
.addClass( 'oo-ui-toolbar-bar' ).append( this.$group
);
5257 if ( config
.actions
) {
5258 this.$actions
.addClass( 'oo-ui-toolbar-actions' );
5259 this.$bar
.append( this.$actions
);
5261 this.$bar
.append( '<div style="clear:both"></div>' );
5262 if ( config
.shadow
) {
5263 this.$bar
.append( '<div class="oo-ui-toolbar-shadow"></div>' );
5265 this.$element
.addClass( 'oo-ui-toolbar' ).append( this.$bar
);
5270 OO
.inheritClass( OO
.ui
.Toolbar
, OO
.ui
.Element
);
5271 OO
.mixinClass( OO
.ui
.Toolbar
, OO
.EventEmitter
);
5272 OO
.mixinClass( OO
.ui
.Toolbar
, OO
.ui
.GroupElement
);
5277 * Get the tool factory.
5279 * @return {OO.ui.ToolFactory} Tool factory
5281 OO
.ui
.Toolbar
.prototype.getToolFactory = function () {
5282 return this.toolFactory
;
5286 * Get the tool group factory.
5288 * @return {OO.Factory} Tool group factory
5290 OO
.ui
.Toolbar
.prototype.getToolGroupFactory = function () {
5291 return this.toolGroupFactory
;
5295 * Handles mouse down events.
5297 * @param {jQuery.Event} e Mouse down event
5299 OO
.ui
.Toolbar
.prototype.onPointerDown = function ( e
) {
5300 var $closestWidgetToEvent
= this.$( e
.target
).closest( '.oo-ui-widget' ),
5301 $closestWidgetToToolbar
= this.$element
.closest( '.oo-ui-widget' );
5302 if ( !$closestWidgetToEvent
.length
|| $closestWidgetToEvent
[0] === $closestWidgetToToolbar
[0] ) {
5308 * Sets up handles and preloads required information for the toolbar to work.
5309 * This must be called immediately after it is attached to a visible document.
5311 OO
.ui
.Toolbar
.prototype.initialize = function () {
5312 this.initialized
= true;
5318 * Tools can be specified in the following ways:
5320 * - A specific tool: `{ name: 'tool-name' }` or `'tool-name'`
5321 * - All tools in a group: `{ group: 'group-name' }`
5322 * - All tools: `'*'` - Using this will make the group a list with a "More" label by default
5324 * @param {Object.<string,Array>} groups List of tool group configurations
5325 * @param {Array|string} [groups.include] Tools to include
5326 * @param {Array|string} [groups.exclude] Tools to exclude
5327 * @param {Array|string} [groups.promote] Tools to promote to the beginning
5328 * @param {Array|string} [groups.demote] Tools to demote to the end
5330 OO
.ui
.Toolbar
.prototype.setup = function ( groups
) {
5331 var i
, len
, type
, group
,
5333 defaultType
= 'bar';
5335 // Cleanup previous groups
5338 // Build out new groups
5339 for ( i
= 0, len
= groups
.length
; i
< len
; i
++ ) {
5341 if ( group
.include
=== '*' ) {
5342 // Apply defaults to catch-all groups
5343 if ( group
.type
=== undefined ) {
5344 group
.type
= 'list';
5346 if ( group
.label
=== undefined ) {
5347 group
.label
= OO
.ui
.msg( 'ooui-toolbar-more' );
5350 // Check type has been registered
5351 type
= this.getToolGroupFactory().lookup( group
.type
) ? group
.type
: defaultType
;
5353 this.getToolGroupFactory().create( type
, this, $.extend( { $: this.$ }, group
) )
5356 this.addItems( items
);
5360 * Remove all tools and groups from the toolbar.
5362 OO
.ui
.Toolbar
.prototype.reset = function () {
5367 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
5368 this.items
[i
].destroy();
5374 * Destroys toolbar, removing event handlers and DOM elements.
5376 * Call this whenever you are done using a toolbar.
5378 OO
.ui
.Toolbar
.prototype.destroy = function () {
5380 this.$element
.remove();
5384 * Check if tool has not been used yet.
5386 * @param {string} name Symbolic name of tool
5387 * @return {boolean} Tool is available
5389 OO
.ui
.Toolbar
.prototype.isToolAvailable = function ( name
) {
5390 return !this.tools
[name
];
5394 * Prevent tool from being used again.
5396 * @param {OO.ui.Tool} tool Tool to reserve
5398 OO
.ui
.Toolbar
.prototype.reserveTool = function ( tool
) {
5399 this.tools
[tool
.getName()] = tool
;
5403 * Allow tool to be used again.
5405 * @param {OO.ui.Tool} tool Tool to release
5407 OO
.ui
.Toolbar
.prototype.releaseTool = function ( tool
) {
5408 delete this.tools
[tool
.getName()];
5412 * Get accelerator label for tool.
5414 * This is a stub that should be overridden to provide access to accelerator information.
5416 * @param {string} name Symbolic name of tool
5417 * @return {string|undefined} Tool accelerator label if available
5419 OO
.ui
.Toolbar
.prototype.getToolAccelerator = function () {
5424 * Collection of tools.
5426 * Tools can be specified in the following ways:
5428 * - A specific tool: `{ name: 'tool-name' }` or `'tool-name'`
5429 * - All tools in a group: `{ group: 'group-name' }`
5430 * - All tools: `'*'`
5434 * @extends OO.ui.Widget
5435 * @mixins OO.ui.GroupElement
5438 * @param {OO.ui.Toolbar} toolbar
5439 * @param {Object} [config] Configuration options
5440 * @cfg {Array|string} [include=[]] List of tools to include
5441 * @cfg {Array|string} [exclude=[]] List of tools to exclude
5442 * @cfg {Array|string} [promote=[]] List of tools to promote to the beginning
5443 * @cfg {Array|string} [demote=[]] List of tools to demote to the end
5445 OO
.ui
.ToolGroup
= function OoUiToolGroup( toolbar
, config
) {
5446 // Configuration initialization
5447 config
= config
|| {};
5449 // Parent constructor
5450 OO
.ui
.ToolGroup
.super.call( this, config
);
5452 // Mixin constructors
5453 OO
.ui
.GroupElement
.call( this, config
);
5456 this.toolbar
= toolbar
;
5458 this.pressed
= null;
5459 this.autoDisabled
= false;
5460 this.include
= config
.include
|| [];
5461 this.exclude
= config
.exclude
|| [];
5462 this.promote
= config
.promote
|| [];
5463 this.demote
= config
.demote
|| [];
5464 this.onCapturedMouseUpHandler
= this.onCapturedMouseUp
.bind( this );
5468 'mousedown touchstart': this.onPointerDown
.bind( this ),
5469 'mouseup touchend': this.onPointerUp
.bind( this ),
5470 mouseover
: this.onMouseOver
.bind( this ),
5471 mouseout
: this.onMouseOut
.bind( this )
5473 this.toolbar
.getToolFactory().connect( this, { register
: 'onToolFactoryRegister' } );
5474 this.aggregate( { disable
: 'itemDisable' } );
5475 this.connect( this, { itemDisable
: 'updateDisabled' } );
5478 this.$group
.addClass( 'oo-ui-toolGroup-tools' );
5480 .addClass( 'oo-ui-toolGroup' )
5481 .append( this.$group
);
5487 OO
.inheritClass( OO
.ui
.ToolGroup
, OO
.ui
.Widget
);
5488 OO
.mixinClass( OO
.ui
.ToolGroup
, OO
.ui
.GroupElement
);
5496 /* Static Properties */
5499 * Show labels in tooltips.
5503 * @property {boolean}
5505 OO
.ui
.ToolGroup
.static.titleTooltips
= false;
5508 * Show acceleration labels in tooltips.
5512 * @property {boolean}
5514 OO
.ui
.ToolGroup
.static.accelTooltips
= false;
5517 * Automatically disable the toolgroup when all tools are disabled
5521 * @property {boolean}
5523 OO
.ui
.ToolGroup
.static.autoDisable
= true;
5530 OO
.ui
.ToolGroup
.prototype.isDisabled = function () {
5531 return this.autoDisabled
|| OO
.ui
.ToolGroup
.super.prototype.isDisabled
.apply( this, arguments
);
5537 OO
.ui
.ToolGroup
.prototype.updateDisabled = function () {
5538 var i
, item
, allDisabled
= true;
5540 if ( this.constructor.static.autoDisable
) {
5541 for ( i
= this.items
.length
- 1; i
>= 0; i
-- ) {
5542 item
= this.items
[i
];
5543 if ( !item
.isDisabled() ) {
5544 allDisabled
= false;
5548 this.autoDisabled
= allDisabled
;
5550 OO
.ui
.ToolGroup
.super.prototype.updateDisabled
.apply( this, arguments
);
5554 * Handle mouse down events.
5556 * @param {jQuery.Event} e Mouse down event
5558 OO
.ui
.ToolGroup
.prototype.onPointerDown = function ( e
) {
5559 // e.which is 0 for touch events, 1 for left mouse button
5560 if ( !this.isDisabled() && e
.which
<= 1 ) {
5561 this.pressed
= this.getTargetTool( e
);
5562 if ( this.pressed
) {
5563 this.pressed
.setActive( true );
5564 this.getElementDocument().addEventListener(
5565 'mouseup', this.onCapturedMouseUpHandler
, true
5573 * Handle captured mouse up events.
5575 * @param {Event} e Mouse up event
5577 OO
.ui
.ToolGroup
.prototype.onCapturedMouseUp = function ( e
) {
5578 this.getElementDocument().removeEventListener( 'mouseup', this.onCapturedMouseUpHandler
, true );
5579 // onPointerUp may be called a second time, depending on where the mouse is when the button is
5580 // released, but since `this.pressed` will no longer be true, the second call will be ignored.
5581 this.onPointerUp( e
);
5585 * Handle mouse up events.
5587 * @param {jQuery.Event} e Mouse up event
5589 OO
.ui
.ToolGroup
.prototype.onPointerUp = function ( e
) {
5590 var tool
= this.getTargetTool( e
);
5592 // e.which is 0 for touch events, 1 for left mouse button
5593 if ( !this.isDisabled() && e
.which
<= 1 && this.pressed
&& this.pressed
=== tool
) {
5594 this.pressed
.onSelect();
5597 this.pressed
= null;
5602 * Handle mouse over events.
5604 * @param {jQuery.Event} e Mouse over event
5606 OO
.ui
.ToolGroup
.prototype.onMouseOver = function ( e
) {
5607 var tool
= this.getTargetTool( e
);
5609 if ( this.pressed
&& this.pressed
=== tool
) {
5610 this.pressed
.setActive( true );
5615 * Handle mouse out events.
5617 * @param {jQuery.Event} e Mouse out event
5619 OO
.ui
.ToolGroup
.prototype.onMouseOut = function ( e
) {
5620 var tool
= this.getTargetTool( e
);
5622 if ( this.pressed
&& this.pressed
=== tool
) {
5623 this.pressed
.setActive( false );
5628 * Get the closest tool to a jQuery.Event.
5630 * Only tool links are considered, which prevents other elements in the tool such as popups from
5631 * triggering tool group interactions.
5634 * @param {jQuery.Event} e
5635 * @return {OO.ui.Tool|null} Tool, `null` if none was found
5637 OO
.ui
.ToolGroup
.prototype.getTargetTool = function ( e
) {
5639 $item
= this.$( e
.target
).closest( '.oo-ui-tool-link' );
5641 if ( $item
.length
) {
5642 tool
= $item
.parent().data( 'oo-ui-tool' );
5645 return tool
&& !tool
.isDisabled() ? tool
: null;
5649 * Handle tool registry register events.
5651 * If a tool is registered after the group is created, we must repopulate the list to account for:
5653 * - a tool being added that may be included
5654 * - a tool already included being overridden
5656 * @param {string} name Symbolic name of tool
5658 OO
.ui
.ToolGroup
.prototype.onToolFactoryRegister = function () {
5663 * Get the toolbar this group is in.
5665 * @return {OO.ui.Toolbar} Toolbar of group
5667 OO
.ui
.ToolGroup
.prototype.getToolbar = function () {
5668 return this.toolbar
;
5672 * Add and remove tools based on configuration.
5674 OO
.ui
.ToolGroup
.prototype.populate = function () {
5675 var i
, len
, name
, tool
,
5676 toolFactory
= this.toolbar
.getToolFactory(),
5680 list
= this.toolbar
.getToolFactory().getTools(
5681 this.include
, this.exclude
, this.promote
, this.demote
5684 // Build a list of needed tools
5685 for ( i
= 0, len
= list
.length
; i
< len
; i
++ ) {
5689 toolFactory
.lookup( name
) &&
5690 // Tool is available or is already in this group
5691 ( this.toolbar
.isToolAvailable( name
) || this.tools
[name
] )
5693 tool
= this.tools
[name
];
5695 // Auto-initialize tools on first use
5696 this.tools
[name
] = tool
= toolFactory
.create( name
, this );
5699 this.toolbar
.reserveTool( tool
);
5704 // Remove tools that are no longer needed
5705 for ( name
in this.tools
) {
5706 if ( !names
[name
] ) {
5707 this.tools
[name
].destroy();
5708 this.toolbar
.releaseTool( this.tools
[name
] );
5709 remove
.push( this.tools
[name
] );
5710 delete this.tools
[name
];
5713 if ( remove
.length
) {
5714 this.removeItems( remove
);
5716 // Update emptiness state
5718 this.$element
.removeClass( 'oo-ui-toolGroup-empty' );
5720 this.$element
.addClass( 'oo-ui-toolGroup-empty' );
5722 // Re-add tools (moving existing ones to new locations)
5723 this.addItems( add
);
5724 // Disabled state may depend on items
5725 this.updateDisabled();
5729 * Destroy tool group.
5731 OO
.ui
.ToolGroup
.prototype.destroy = function () {
5735 this.toolbar
.getToolFactory().disconnect( this );
5736 for ( name
in this.tools
) {
5737 this.toolbar
.releaseTool( this.tools
[name
] );
5738 this.tools
[name
].disconnect( this ).destroy();
5739 delete this.tools
[name
];
5741 this.$element
.remove();
5745 * Dialog for showing a message.
5748 * - Registers two actions by default (safe and primary).
5749 * - Renders action widgets in the footer.
5752 * @extends OO.ui.Dialog
5755 * @param {Object} [config] Configuration options
5757 OO
.ui
.MessageDialog
= function OoUiMessageDialog( config
) {
5758 // Parent constructor
5759 OO
.ui
.MessageDialog
.super.call( this, config
);
5762 this.verticalActionLayout
= null;
5765 this.$element
.addClass( 'oo-ui-messageDialog' );
5770 OO
.inheritClass( OO
.ui
.MessageDialog
, OO
.ui
.Dialog
);
5772 /* Static Properties */
5774 OO
.ui
.MessageDialog
.static.name
= 'message';
5776 OO
.ui
.MessageDialog
.static.size
= 'small';
5778 OO
.ui
.MessageDialog
.static.verbose
= false;
5783 * A confirmation dialog's title should describe what the progressive action will do. An alert
5784 * dialog's title should describe what event occured.
5788 * @property {jQuery|string|Function|null}
5790 OO
.ui
.MessageDialog
.static.title
= null;
5793 * A confirmation dialog's message should describe the consequences of the progressive action. An
5794 * alert dialog's message should describe why the event occured.
5798 * @property {jQuery|string|Function|null}
5800 OO
.ui
.MessageDialog
.static.message
= null;
5802 OO
.ui
.MessageDialog
.static.actions
= [
5803 { action
: 'accept', label
: OO
.ui
.deferMsg( 'ooui-dialog-message-accept' ), flags
: 'primary' },
5804 { action
: 'reject', label
: OO
.ui
.deferMsg( 'ooui-dialog-message-reject' ), flags
: 'safe' }
5812 OO
.ui
.MessageDialog
.prototype.onActionResize = function ( action
) {
5814 return OO
.ui
.ProcessDialog
.super.prototype.onActionResize
.call( this, action
);
5818 * Toggle action layout between vertical and horizontal.
5820 * @param {boolean} [value] Layout actions vertically, omit to toggle
5823 OO
.ui
.MessageDialog
.prototype.toggleVerticalActionLayout = function ( value
) {
5824 value
= value
=== undefined ? !this.verticalActionLayout
: !!value
;
5826 if ( value
!== this.verticalActionLayout
) {
5827 this.verticalActionLayout
= value
;
5829 .toggleClass( 'oo-ui-messageDialog-actions-vertical', value
)
5830 .toggleClass( 'oo-ui-messageDialog-actions-horizontal', !value
);
5839 OO
.ui
.MessageDialog
.prototype.getActionProcess = function ( action
) {
5841 return new OO
.ui
.Process( function () {
5842 this.close( { action
: action
} );
5845 return OO
.ui
.MessageDialog
.super.prototype.getActionProcess
.call( this, action
);
5851 * @param {Object} [data] Dialog opening data
5852 * @param {jQuery|string|Function|null} [data.title] Description of the action being confirmed
5853 * @param {jQuery|string|Function|null} [data.message] Description of the action's consequence
5854 * @param {boolean} [data.verbose] Message is verbose and should be styled as a long message
5855 * @param {Object[]} [data.actions] List of OO.ui.ActionOptionWidget configuration options for each
5858 OO
.ui
.MessageDialog
.prototype.getSetupProcess = function ( data
) {
5862 return OO
.ui
.MessageDialog
.super.prototype.getSetupProcess
.call( this, data
)
5863 .next( function () {
5864 this.title
.setLabel(
5865 data
.title
!== undefined ? data
.title
: this.constructor.static.title
5867 this.message
.setLabel(
5868 data
.message
!== undefined ? data
.message
: this.constructor.static.message
5870 this.message
.$element
.toggleClass(
5871 'oo-ui-messageDialog-message-verbose',
5872 data
.verbose
!== undefined ? data
.verbose
: this.constructor.static.verbose
5880 OO
.ui
.MessageDialog
.prototype.getBodyHeight = function () {
5881 return Math
.round( this.text
.$element
.outerHeight( true ) );
5887 OO
.ui
.MessageDialog
.prototype.initialize = function () {
5889 OO
.ui
.MessageDialog
.super.prototype.initialize
.call( this );
5892 this.$actions
= this.$( '<div>' );
5893 this.container
= new OO
.ui
.PanelLayout( {
5894 $: this.$, scrollable
: true, classes
: [ 'oo-ui-messageDialog-container' ]
5896 this.text
= new OO
.ui
.PanelLayout( {
5897 $: this.$, padded
: true, expanded
: false, classes
: [ 'oo-ui-messageDialog-text' ]
5899 this.message
= new OO
.ui
.LabelWidget( {
5900 $: this.$, classes
: [ 'oo-ui-messageDialog-message' ]
5904 this.title
.$element
.addClass( 'oo-ui-messageDialog-title' );
5905 this.$content
.addClass( 'oo-ui-messageDialog-content' );
5906 this.container
.$element
.append( this.text
.$element
);
5907 this.text
.$element
.append( this.title
.$element
, this.message
.$element
);
5908 this.$body
.append( this.container
.$element
);
5909 this.$actions
.addClass( 'oo-ui-messageDialog-actions' );
5910 this.$foot
.append( this.$actions
);
5916 OO
.ui
.MessageDialog
.prototype.attachActions = function () {
5917 var i
, len
, other
, special
, others
;
5920 OO
.ui
.MessageDialog
.super.prototype.attachActions
.call( this );
5922 special
= this.actions
.getSpecial();
5923 others
= this.actions
.getOthers();
5924 if ( special
.safe
) {
5925 this.$actions
.append( special
.safe
.$element
);
5926 special
.safe
.toggleFramed( false );
5928 if ( others
.length
) {
5929 for ( i
= 0, len
= others
.length
; i
< len
; i
++ ) {
5931 this.$actions
.append( other
.$element
);
5932 other
.toggleFramed( false );
5935 if ( special
.primary
) {
5936 this.$actions
.append( special
.primary
.$element
);
5937 special
.primary
.toggleFramed( false );
5941 if ( !this.isOpening() ) {
5942 this.manager
.updateWindowSize( this );
5944 this.$body
.css( 'bottom', this.$foot
.outerHeight( true ) );
5948 * Fit action actions into columns or rows.
5950 * Columns will be used if all labels can fit without overflow, otherwise rows will be used.
5952 OO
.ui
.MessageDialog
.prototype.fitActions = function () {
5954 actions
= this.actions
.get();
5957 this.toggleVerticalActionLayout( false );
5958 for ( i
= 0, len
= actions
.length
; i
< len
; i
++ ) {
5959 action
= actions
[i
];
5960 if ( action
.$element
.innerWidth() < action
.$label
.outerWidth( true ) ) {
5961 this.toggleVerticalActionLayout( true );
5968 * Navigation dialog window.
5971 * - Show and hide errors.
5972 * - Retry an action.
5975 * - Renders header with dialog title and one action widget on either side
5976 * (a 'safe' button on the left, and a 'primary' button on the right, both of
5977 * which close the dialog).
5978 * - Displays any action widgets in the footer (none by default).
5979 * - Ability to dismiss errors.
5981 * Subclass responsibilities:
5982 * - Register a 'safe' action.
5983 * - Register a 'primary' action.
5984 * - Add content to the dialog.
5988 * @extends OO.ui.Dialog
5991 * @param {Object} [config] Configuration options
5993 OO
.ui
.ProcessDialog
= function OoUiProcessDialog( config
) {
5994 // Parent constructor
5995 OO
.ui
.ProcessDialog
.super.call( this, config
);
5998 this.$element
.addClass( 'oo-ui-processDialog' );
6003 OO
.inheritClass( OO
.ui
.ProcessDialog
, OO
.ui
.Dialog
);
6008 * Handle dismiss button click events.
6012 OO
.ui
.ProcessDialog
.prototype.onDismissErrorButtonClick = function () {
6017 * Handle retry button click events.
6019 * Hides errors and then tries again.
6021 OO
.ui
.ProcessDialog
.prototype.onRetryButtonClick = function () {
6023 this.executeAction( this.currentAction
.getAction() );
6029 OO
.ui
.ProcessDialog
.prototype.onActionResize = function ( action
) {
6030 if ( this.actions
.isSpecial( action
) ) {
6033 return OO
.ui
.ProcessDialog
.super.prototype.onActionResize
.call( this, action
);
6039 OO
.ui
.ProcessDialog
.prototype.initialize = function () {
6041 OO
.ui
.ProcessDialog
.super.prototype.initialize
.call( this );
6044 this.$navigation
= this.$( '<div>' );
6045 this.$location
= this.$( '<div>' );
6046 this.$safeActions
= this.$( '<div>' );
6047 this.$primaryActions
= this.$( '<div>' );
6048 this.$otherActions
= this.$( '<div>' );
6049 this.dismissButton
= new OO
.ui
.ButtonWidget( {
6051 label
: OO
.ui
.msg( 'ooui-dialog-process-dismiss' )
6053 this.retryButton
= new OO
.ui
.ButtonWidget( { $: this.$ } );
6054 this.$errors
= this.$( '<div>' );
6055 this.$errorsTitle
= this.$( '<div>' );
6058 this.dismissButton
.connect( this, { click
: 'onDismissErrorButtonClick' } );
6059 this.retryButton
.connect( this, { click
: 'onRetryButtonClick' } );
6062 this.title
.$element
.addClass( 'oo-ui-processDialog-title' );
6064 .append( this.title
.$element
)
6065 .addClass( 'oo-ui-processDialog-location' );
6066 this.$safeActions
.addClass( 'oo-ui-processDialog-actions-safe' );
6067 this.$primaryActions
.addClass( 'oo-ui-processDialog-actions-primary' );
6068 this.$otherActions
.addClass( 'oo-ui-processDialog-actions-other' );
6070 .addClass( 'oo-ui-processDialog-errors-title' )
6071 .text( OO
.ui
.msg( 'ooui-dialog-process-error' ) );
6073 .addClass( 'oo-ui-processDialog-errors' )
6074 .append( this.$errorsTitle
, this.dismissButton
.$element
, this.retryButton
.$element
);
6076 .addClass( 'oo-ui-processDialog-content' )
6077 .append( this.$errors
);
6079 .addClass( 'oo-ui-processDialog-navigation' )
6080 .append( this.$safeActions
, this.$location
, this.$primaryActions
);
6081 this.$head
.append( this.$navigation
);
6082 this.$foot
.append( this.$otherActions
);
6088 OO
.ui
.ProcessDialog
.prototype.attachActions = function () {
6089 var i
, len
, other
, special
, others
;
6092 OO
.ui
.ProcessDialog
.super.prototype.attachActions
.call( this );
6094 special
= this.actions
.getSpecial();
6095 others
= this.actions
.getOthers();
6096 if ( special
.primary
) {
6097 this.$primaryActions
.append( special
.primary
.$element
);
6098 special
.primary
.toggleFramed( true );
6100 if ( others
.length
) {
6101 for ( i
= 0, len
= others
.length
; i
< len
; i
++ ) {
6103 this.$otherActions
.append( other
.$element
);
6104 other
.toggleFramed( true );
6107 if ( special
.safe
) {
6108 this.$safeActions
.append( special
.safe
.$element
);
6109 special
.safe
.toggleFramed( true );
6113 this.$body
.css( 'bottom', this.$foot
.outerHeight( true ) );
6119 OO
.ui
.ProcessDialog
.prototype.executeAction = function ( action
) {
6120 OO
.ui
.ProcessDialog
.super.prototype.executeAction
.call( this, action
)
6121 .fail( this.showErrors
.bind( this ) );
6125 * Fit label between actions.
6129 OO
.ui
.ProcessDialog
.prototype.fitLabel = function () {
6130 var width
= Math
.max(
6131 this.$safeActions
.is( ':visible' ) ? this.$safeActions
.width() : 0,
6132 this.$primaryActions
.is( ':visible' ) ? this.$primaryActions
.width() : 0
6134 this.$location
.css( { paddingLeft
: width
, paddingRight
: width
} );
6140 * Handle errors that occured durring accept or reject processes.
6142 * @param {OO.ui.Error[]} errors Errors to be handled
6144 OO
.ui
.ProcessDialog
.prototype.showErrors = function ( errors
) {
6150 for ( i
= 0, len
= errors
.length
; i
< len
; i
++ ) {
6151 if ( !errors
[i
].isRecoverable() ) {
6152 recoverable
= false;
6154 if ( errors
[i
].isWarning() ) {
6157 $item
= this.$( '<div>' )
6158 .addClass( 'oo-ui-processDialog-error' )
6159 .append( errors
[i
].getMessage() );
6160 items
.push( $item
[0] );
6162 this.$errorItems
= this.$( items
);
6163 if ( recoverable
) {
6164 this.retryButton
.clearFlags().setFlags( this.currentAction
.getFlags() );
6166 this.currentAction
.setDisabled( true );
6169 this.retryButton
.setLabel( OO
.ui
.msg( 'ooui-dialog-process-continue' ) );
6171 this.retryButton
.setLabel( OO
.ui
.msg( 'ooui-dialog-process-retry' ) );
6173 this.retryButton
.toggle( recoverable
);
6174 this.$errorsTitle
.after( this.$errorItems
);
6175 this.$errors
.show().scrollTop( 0 );
6181 OO
.ui
.ProcessDialog
.prototype.hideErrors = function () {
6182 this.$errors
.hide();
6183 this.$errorItems
.remove();
6184 this.$errorItems
= null;
6188 * Layout containing a series of pages.
6191 * @extends OO.ui.Layout
6194 * @param {Object} [config] Configuration options
6195 * @cfg {boolean} [continuous=false] Show all pages, one after another
6196 * @cfg {boolean} [autoFocus=true] Focus on the first focusable element when changing to a page
6197 * @cfg {boolean} [outlined=false] Show an outline
6198 * @cfg {boolean} [editable=false] Show controls for adding, removing and reordering pages
6200 OO
.ui
.BookletLayout
= function OoUiBookletLayout( config
) {
6201 // Configuration initialization
6202 config
= config
|| {};
6204 // Parent constructor
6205 OO
.ui
.BookletLayout
.super.call( this, config
);
6208 this.currentPageName
= null;
6210 this.ignoreFocus
= false;
6211 this.stackLayout
= new OO
.ui
.StackLayout( { $: this.$, continuous
: !!config
.continuous
} );
6212 this.autoFocus
= config
.autoFocus
=== undefined || !!config
.autoFocus
;
6213 this.outlineVisible
= false;
6214 this.outlined
= !!config
.outlined
;
6215 if ( this.outlined
) {
6216 this.editable
= !!config
.editable
;
6217 this.outlineControlsWidget
= null;
6218 this.outlineWidget
= new OO
.ui
.OutlineWidget( { $: this.$ } );
6219 this.outlinePanel
= new OO
.ui
.PanelLayout( { $: this.$, scrollable
: true } );
6220 this.gridLayout
= new OO
.ui
.GridLayout(
6221 [ this.outlinePanel
, this.stackLayout
],
6222 { $: this.$, widths
: [ 1, 2 ] }
6224 this.outlineVisible
= true;
6225 if ( this.editable
) {
6226 this.outlineControlsWidget
= new OO
.ui
.OutlineControlsWidget(
6227 this.outlineWidget
, { $: this.$ }
6233 this.stackLayout
.connect( this, { set: 'onStackLayoutSet' } );
6234 if ( this.outlined
) {
6235 this.outlineWidget
.connect( this, { select
: 'onOutlineWidgetSelect' } );
6237 if ( this.autoFocus
) {
6238 // Event 'focus' does not bubble, but 'focusin' does
6239 this.stackLayout
.onDOMEvent( 'focusin', this.onStackLayoutFocus
.bind( this ) );
6243 this.$element
.addClass( 'oo-ui-bookletLayout' );
6244 this.stackLayout
.$element
.addClass( 'oo-ui-bookletLayout-stackLayout' );
6245 if ( this.outlined
) {
6246 this.outlinePanel
.$element
6247 .addClass( 'oo-ui-bookletLayout-outlinePanel' )
6248 .append( this.outlineWidget
.$element
);
6249 if ( this.editable
) {
6250 this.outlinePanel
.$element
6251 .addClass( 'oo-ui-bookletLayout-outlinePanel-editable' )
6252 .append( this.outlineControlsWidget
.$element
);
6254 this.$element
.append( this.gridLayout
.$element
);
6256 this.$element
.append( this.stackLayout
.$element
);
6262 OO
.inheritClass( OO
.ui
.BookletLayout
, OO
.ui
.Layout
);
6268 * @param {OO.ui.PageLayout} page Current page
6273 * @param {OO.ui.PageLayout[]} page Added pages
6274 * @param {number} index Index pages were added at
6279 * @param {OO.ui.PageLayout[]} pages Removed pages
6285 * Handle stack layout focus.
6287 * @param {jQuery.Event} e Focusin event
6289 OO
.ui
.BookletLayout
.prototype.onStackLayoutFocus = function ( e
) {
6292 // Find the page that an element was focused within
6293 $target
= $( e
.target
).closest( '.oo-ui-pageLayout' );
6294 for ( name
in this.pages
) {
6295 // Check for page match, exclude current page to find only page changes
6296 if ( this.pages
[name
].$element
[0] === $target
[0] && name
!== this.currentPageName
) {
6297 this.setPage( name
);
6304 * Handle stack layout set events.
6306 * @param {OO.ui.PanelLayout|null} page The page panel that is now the current panel
6308 OO
.ui
.BookletLayout
.prototype.onStackLayoutSet = function ( page
) {
6309 var $input
, layout
= this;
6311 page
.scrollElementIntoView( { complete: function () {
6312 if ( layout
.autoFocus
) {
6313 // Set focus to the first input if nothing on the page is focused yet
6314 if ( !page
.$element
.find( ':focus' ).length
) {
6315 $input
= page
.$element
.find( ':input:first' );
6316 if ( $input
.length
) {
6326 * Handle outline widget select events.
6328 * @param {OO.ui.OptionWidget|null} item Selected item
6330 OO
.ui
.BookletLayout
.prototype.onOutlineWidgetSelect = function ( item
) {
6332 this.setPage( item
.getData() );
6337 * Check if booklet has an outline.
6341 OO
.ui
.BookletLayout
.prototype.isOutlined = function () {
6342 return this.outlined
;
6346 * Check if booklet has editing controls.
6350 OO
.ui
.BookletLayout
.prototype.isEditable = function () {
6351 return this.editable
;
6355 * Check if booklet has a visible outline.
6359 OO
.ui
.BookletLayout
.prototype.isOutlineVisible = function () {
6360 return this.outlined
&& this.outlineVisible
;
6364 * Hide or show the outline.
6366 * @param {boolean} [show] Show outline, omit to invert current state
6369 OO
.ui
.BookletLayout
.prototype.toggleOutline = function ( show
) {
6370 if ( this.outlined
) {
6371 show
= show
=== undefined ? !this.outlineVisible
: !!show
;
6372 this.outlineVisible
= show
;
6373 this.gridLayout
.layout( show
? [ 1, 2 ] : [ 0, 1 ], [ 1 ] );
6380 * Get the outline widget.
6382 * @param {OO.ui.PageLayout} page Page to be selected
6383 * @return {OO.ui.PageLayout|null} Closest page to another
6385 OO
.ui
.BookletLayout
.prototype.getClosestPage = function ( page
) {
6386 var next
, prev
, level
,
6387 pages
= this.stackLayout
.getItems(),
6388 index
= $.inArray( page
, pages
);
6390 if ( index
!== -1 ) {
6391 next
= pages
[index
+ 1];
6392 prev
= pages
[index
- 1];
6393 // Prefer adjacent pages at the same level
6394 if ( this.outlined
) {
6395 level
= this.outlineWidget
.getItemFromData( page
.getName() ).getLevel();
6398 level
=== this.outlineWidget
.getItemFromData( prev
.getName() ).getLevel()
6404 level
=== this.outlineWidget
.getItemFromData( next
.getName() ).getLevel()
6410 return prev
|| next
|| null;
6414 * Get the outline widget.
6416 * @return {OO.ui.OutlineWidget|null} Outline widget, or null if boolet has no outline
6418 OO
.ui
.BookletLayout
.prototype.getOutline = function () {
6419 return this.outlineWidget
;
6423 * Get the outline controls widget. If the outline is not editable, null is returned.
6425 * @return {OO.ui.OutlineControlsWidget|null} The outline controls widget.
6427 OO
.ui
.BookletLayout
.prototype.getOutlineControls = function () {
6428 return this.outlineControlsWidget
;
6432 * Get a page by name.
6434 * @param {string} name Symbolic name of page
6435 * @return {OO.ui.PageLayout|undefined} Page, if found
6437 OO
.ui
.BookletLayout
.prototype.getPage = function ( name
) {
6438 return this.pages
[name
];
6442 * Get the current page name.
6444 * @return {string|null} Current page name
6446 OO
.ui
.BookletLayout
.prototype.getPageName = function () {
6447 return this.currentPageName
;
6451 * Add a page to the layout.
6453 * When pages are added with the same names as existing pages, the existing pages will be
6454 * automatically removed before the new pages are added.
6456 * @param {OO.ui.PageLayout[]} pages Pages to add
6457 * @param {number} index Index to insert pages after
6461 OO
.ui
.BookletLayout
.prototype.addPages = function ( pages
, index
) {
6462 var i
, len
, name
, page
, item
, currentIndex
,
6463 stackLayoutPages
= this.stackLayout
.getItems(),
6467 // Remove pages with same names
6468 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
6470 name
= page
.getName();
6472 if ( Object
.prototype.hasOwnProperty
.call( this.pages
, name
) ) {
6473 // Correct the insertion index
6474 currentIndex
= $.inArray( this.pages
[name
], stackLayoutPages
);
6475 if ( currentIndex
!== -1 && currentIndex
+ 1 < index
) {
6478 remove
.push( this.pages
[name
] );
6481 if ( remove
.length
) {
6482 this.removePages( remove
);
6486 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
6488 name
= page
.getName();
6489 this.pages
[page
.getName()] = page
;
6490 if ( this.outlined
) {
6491 item
= new OO
.ui
.OutlineItemWidget( name
, page
, { $: this.$ } );
6492 page
.setOutlineItem( item
);
6497 if ( this.outlined
&& items
.length
) {
6498 this.outlineWidget
.addItems( items
, index
);
6499 this.updateOutlineWidget();
6501 this.stackLayout
.addItems( pages
, index
);
6502 this.emit( 'add', pages
, index
);
6508 * Remove a page from the layout.
6513 OO
.ui
.BookletLayout
.prototype.removePages = function ( pages
) {
6514 var i
, len
, name
, page
,
6517 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
6519 name
= page
.getName();
6520 delete this.pages
[name
];
6521 if ( this.outlined
) {
6522 items
.push( this.outlineWidget
.getItemFromData( name
) );
6523 page
.setOutlineItem( null );
6526 if ( this.outlined
&& items
.length
) {
6527 this.outlineWidget
.removeItems( items
);
6528 this.updateOutlineWidget();
6530 this.stackLayout
.removeItems( pages
);
6531 this.emit( 'remove', pages
);
6537 * Clear all pages from the layout.
6542 OO
.ui
.BookletLayout
.prototype.clearPages = function () {
6544 pages
= this.stackLayout
.getItems();
6547 this.currentPageName
= null;
6548 if ( this.outlined
) {
6549 this.outlineWidget
.clearItems();
6550 for ( i
= 0, len
= pages
.length
; i
< len
; i
++ ) {
6551 pages
[i
].setOutlineItem( null );
6554 this.stackLayout
.clearItems();
6556 this.emit( 'remove', pages
);
6562 * Set the current page by name.
6565 * @param {string} name Symbolic name of page
6567 OO
.ui
.BookletLayout
.prototype.setPage = function ( name
) {
6570 page
= this.pages
[name
];
6572 if ( name
!== this.currentPageName
) {
6573 if ( this.outlined
) {
6574 selectedItem
= this.outlineWidget
.getSelectedItem();
6575 if ( selectedItem
&& selectedItem
.getData() !== name
) {
6576 this.outlineWidget
.selectItem( this.outlineWidget
.getItemFromData( name
) );
6580 if ( this.currentPageName
&& this.pages
[this.currentPageName
] ) {
6581 this.pages
[this.currentPageName
].setActive( false );
6582 // Blur anything focused if the next page doesn't have anything focusable - this
6583 // is not needed if the next page has something focusable because once it is focused
6584 // this blur happens automatically
6585 if ( this.autoFocus
&& !page
.$element
.find( ':input' ).length
) {
6586 $focused
= this.pages
[this.currentPageName
].$element
.find( ':focus' );
6587 if ( $focused
.length
) {
6592 this.currentPageName
= name
;
6593 this.stackLayout
.setItem( page
);
6594 page
.setActive( true );
6595 this.emit( 'set', page
);
6601 * Call this after adding or removing items from the OutlineWidget.
6605 OO
.ui
.BookletLayout
.prototype.updateOutlineWidget = function () {
6606 // Auto-select first item when nothing is selected anymore
6607 if ( !this.outlineWidget
.getSelectedItem() ) {
6608 this.outlineWidget
.selectItem( this.outlineWidget
.getFirstSelectableItem() );
6615 * Layout made of a field and optional label.
6617 * Available label alignment modes include:
6618 * - left: Label is before the field and aligned away from it, best for when the user will be
6619 * scanning for a specific label in a form with many fields
6620 * - right: Label is before the field and aligned toward it, best for forms the user is very
6621 * familiar with and will tab through field checking quickly to verify which field they are in
6622 * - top: Label is before the field and above it, best for when the user will need to fill out all
6623 * fields from top to bottom in a form with few fields
6624 * - inline: Label is after the field and aligned toward it, best for small boolean fields like
6625 * checkboxes or radio buttons
6628 * @extends OO.ui.Layout
6629 * @mixins OO.ui.LabelElement
6632 * @param {OO.ui.Widget} fieldWidget Field widget
6633 * @param {Object} [config] Configuration options
6634 * @cfg {string} [align='left'] Alignment mode, either 'left', 'right', 'top' or 'inline'
6635 * @cfg {string} [help] Explanatory text shown as a '?' icon.
6637 OO
.ui
.FieldLayout
= function OoUiFieldLayout( fieldWidget
, config
) {
6638 // Configuration initialization
6639 config
= $.extend( { align
: 'left' }, config
);
6641 // Parent constructor
6642 OO
.ui
.FieldLayout
.super.call( this, config
);
6644 // Mixin constructors
6645 OO
.ui
.LabelElement
.call( this, config
);
6648 this.$field
= this.$( '<div>' );
6649 this.fieldWidget
= fieldWidget
;
6651 if ( config
.help
) {
6652 this.popupButtonWidget
= new OO
.ui
.PopupButtonWidget( {
6654 classes
: [ 'oo-ui-fieldLayout-help' ],
6659 this.popupButtonWidget
.getPopup().$body
.append(
6661 .text( config
.help
)
6662 .addClass( 'oo-ui-fieldLayout-help-content' )
6664 this.$help
= this.popupButtonWidget
.$element
;
6666 this.$help
= this.$( [] );
6670 if ( this.fieldWidget
instanceof OO
.ui
.InputWidget
) {
6671 this.$label
.on( 'click', this.onLabelClick
.bind( this ) );
6673 this.fieldWidget
.connect( this, { disable
: 'onFieldDisable' } );
6676 this.$element
.addClass( 'oo-ui-fieldLayout' );
6678 .addClass( 'oo-ui-fieldLayout-field' )
6679 .toggleClass( 'oo-ui-fieldLayout-disable', this.fieldWidget
.isDisabled() )
6680 .append( this.fieldWidget
.$element
);
6681 this.setAlignment( config
.align
);
6686 OO
.inheritClass( OO
.ui
.FieldLayout
, OO
.ui
.Layout
);
6687 OO
.mixinClass( OO
.ui
.FieldLayout
, OO
.ui
.LabelElement
);
6689 /* Static Properties */
6691 OO
.ui
.FieldLayout
.static.tagName
= 'label';
6696 * Handle field disable events.
6698 * @param {boolean} value Field is disabled
6700 OO
.ui
.FieldLayout
.prototype.onFieldDisable = function ( value
) {
6701 this.$element
.toggleClass( 'oo-ui-fieldLayout-disabled', value
);
6705 * Handle label mouse click events.
6707 * @param {jQuery.Event} e Mouse click event
6709 OO
.ui
.FieldLayout
.prototype.onLabelClick = function () {
6710 this.fieldWidget
.simulateLabelClick();
6717 * @return {OO.ui.Widget} Field widget
6719 OO
.ui
.FieldLayout
.prototype.getField = function () {
6720 return this.fieldWidget
;
6724 * Set the field alignment mode.
6727 * @param {string} value Alignment mode, either 'left', 'right', 'top' or 'inline'
6730 OO
.ui
.FieldLayout
.prototype.setAlignment = function ( value
) {
6731 if ( value
!== this.align
) {
6732 // Default to 'left'
6733 if ( [ 'left', 'right', 'top', 'inline' ].indexOf( value
) === -1 ) {
6737 if ( value
=== 'inline' ) {
6738 this.$element
.append( this.$field
, this.$label
, this.$help
);
6740 this.$element
.append( this.$help
, this.$label
, this.$field
);
6742 // Set classes. The following classes can be used here:
6743 // * oo-ui-fieldLayout-align-left
6744 // * oo-ui-fieldLayout-align-right
6745 // * oo-ui-fieldLayout-align-top
6746 // * oo-ui-fieldLayout-align-inline
6748 this.$element
.removeClass( 'oo-ui-fieldLayout-align-' + this.align
);
6750 this.$element
.addClass( 'oo-ui-fieldLayout-align-' + value
);
6758 * Layout made of a fieldset and optional legend.
6760 * Just add OO.ui.FieldLayout items.
6763 * @extends OO.ui.Layout
6764 * @mixins OO.ui.IconElement
6765 * @mixins OO.ui.LabelElement
6766 * @mixins OO.ui.GroupElement
6769 * @param {Object} [config] Configuration options
6770 * @cfg {OO.ui.FieldLayout[]} [items] Items to add
6772 OO
.ui
.FieldsetLayout
= function OoUiFieldsetLayout( config
) {
6773 // Configuration initialization
6774 config
= config
|| {};
6776 // Parent constructor
6777 OO
.ui
.FieldsetLayout
.super.call( this, config
);
6779 // Mixin constructors
6780 OO
.ui
.IconElement
.call( this, config
);
6781 OO
.ui
.LabelElement
.call( this, config
);
6782 OO
.ui
.GroupElement
.call( this, config
);
6786 .addClass( 'oo-ui-fieldsetLayout' )
6787 .prepend( this.$icon
, this.$label
, this.$group
);
6788 if ( $.isArray( config
.items
) ) {
6789 this.addItems( config
.items
);
6795 OO
.inheritClass( OO
.ui
.FieldsetLayout
, OO
.ui
.Layout
);
6796 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.IconElement
);
6797 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.LabelElement
);
6798 OO
.mixinClass( OO
.ui
.FieldsetLayout
, OO
.ui
.GroupElement
);
6801 * Layout with an HTML form.
6804 * @extends OO.ui.Layout
6807 * @param {Object} [config] Configuration options
6808 * @cfg {string} [method] HTML form `method` attribute
6809 * @cfg {string} [action] HTML form `action` attribute
6810 * @cfg {string} [enctype] HTML form `enctype` attribute
6812 OO
.ui
.FormLayout
= function OoUiFormLayout( config
) {
6813 // Configuration initialization
6814 config
= config
|| {};
6816 // Parent constructor
6817 OO
.ui
.FormLayout
.super.call( this, config
);
6820 this.$element
.on( 'submit', this.onFormSubmit
.bind( this ) );
6824 .addClass( 'oo-ui-formLayout' )
6826 method
: config
.method
,
6827 action
: config
.action
,
6828 enctype
: config
.enctype
6834 OO
.inheritClass( OO
.ui
.FormLayout
, OO
.ui
.Layout
);
6842 /* Static Properties */
6844 OO
.ui
.FormLayout
.static.tagName
= 'form';
6849 * Handle form submit events.
6851 * @param {jQuery.Event} e Submit event
6854 OO
.ui
.FormLayout
.prototype.onFormSubmit = function () {
6855 this.emit( 'submit' );
6860 * Layout made of proportionally sized columns and rows.
6863 * @extends OO.ui.Layout
6866 * @param {OO.ui.PanelLayout[]} panels Panels in the grid
6867 * @param {Object} [config] Configuration options
6868 * @cfg {number[]} [widths] Widths of columns as ratios
6869 * @cfg {number[]} [heights] Heights of rows as ratios
6871 OO
.ui
.GridLayout
= function OoUiGridLayout( panels
, config
) {
6874 // Configuration initialization
6875 config
= config
|| {};
6877 // Parent constructor
6878 OO
.ui
.GridLayout
.super.call( this, config
);
6886 this.$element
.addClass( 'oo-ui-gridLayout' );
6887 for ( i
= 0, len
= panels
.length
; i
< len
; i
++ ) {
6888 this.panels
.push( panels
[i
] );
6889 this.$element
.append( panels
[i
].$element
);
6891 if ( config
.widths
|| config
.heights
) {
6892 this.layout( config
.widths
|| [ 1 ], config
.heights
|| [ 1 ] );
6894 // Arrange in columns by default
6895 widths
= this.panels
.map( function () { return 1; } );
6896 this.layout( widths
, [ 1 ] );
6902 OO
.inheritClass( OO
.ui
.GridLayout
, OO
.ui
.Layout
);
6917 * Set grid dimensions.
6919 * @param {number[]} widths Widths of columns as ratios
6920 * @param {number[]} heights Heights of rows as ratios
6922 * @throws {Error} If grid is not large enough to fit all panels
6924 OO
.ui
.GridLayout
.prototype.layout = function ( widths
, heights
) {
6928 cols
= widths
.length
,
6929 rows
= heights
.length
;
6931 // Verify grid is big enough to fit panels
6932 if ( cols
* rows
< this.panels
.length
) {
6933 throw new Error( 'Grid is not large enough to fit ' + this.panels
.length
+ 'panels' );
6936 // Sum up denominators
6937 for ( x
= 0; x
< cols
; x
++ ) {
6940 for ( y
= 0; y
< rows
; y
++ ) {
6946 for ( x
= 0; x
< cols
; x
++ ) {
6947 this.widths
[x
] = widths
[x
] / xd
;
6949 for ( y
= 0; y
< rows
; y
++ ) {
6950 this.heights
[y
] = heights
[y
] / yd
;
6954 this.emit( 'layout' );
6958 * Update panel positions and sizes.
6962 OO
.ui
.GridLayout
.prototype.update = function () {
6963 var x
, y
, panel
, width
, height
, dimensions
,
6967 cols
= this.widths
.length
,
6968 rows
= this.heights
.length
;
6970 for ( y
= 0; y
< rows
; y
++ ) {
6971 height
= this.heights
[y
];
6972 for ( x
= 0; x
< cols
; x
++ ) {
6973 width
= this.widths
[x
];
6974 panel
= this.panels
[i
];
6976 width
: Math
.round( width
* 100 ) + '%',
6977 height
: Math
.round( height
* 100 ) + '%',
6978 top
: Math
.round( top
* 100 ) + '%'
6981 if ( OO
.ui
.Element
.getDir( this.$.context
) === 'rtl' ) {
6982 dimensions
.right
= Math
.round( left
* 100 ) + '%';
6984 dimensions
.left
= Math
.round( left
* 100 ) + '%';
6986 // HACK: Work around IE bug by setting visibility: hidden; if width or height is zero
6987 if ( width
=== 0 || height
=== 0 ) {
6988 dimensions
.visibility
= 'hidden';
6990 dimensions
.visibility
= '';
6992 panel
.$element
.css( dimensions
);
7000 this.emit( 'update' );
7004 * Get a panel at a given position.
7006 * The x and y position is affected by the current grid layout.
7008 * @param {number} x Horizontal position
7009 * @param {number} y Vertical position
7010 * @return {OO.ui.PanelLayout} The panel at the given postion
7012 OO
.ui
.GridLayout
.prototype.getPanel = function ( x
, y
) {
7013 return this.panels
[ ( x
* this.widths
.length
) + y
];
7017 * Layout that expands to cover the entire area of its parent, with optional scrolling and padding.
7020 * @extends OO.ui.Layout
7023 * @param {Object} [config] Configuration options
7024 * @cfg {boolean} [scrollable=false] Allow vertical scrolling
7025 * @cfg {boolean} [padded=false] Pad the content from the edges
7026 * @cfg {boolean} [expanded=true] Expand size to fill the entire parent element
7028 OO
.ui
.PanelLayout
= function OoUiPanelLayout( config
) {
7029 // Configuration initialization
7030 config
= $.extend( {
7036 // Parent constructor
7037 OO
.ui
.PanelLayout
.super.call( this, config
);
7040 this.$element
.addClass( 'oo-ui-panelLayout' );
7041 if ( config
.scrollable
) {
7042 this.$element
.addClass( 'oo-ui-panelLayout-scrollable' );
7044 if ( config
.padded
) {
7045 this.$element
.addClass( 'oo-ui-panelLayout-padded' );
7047 if ( config
.expanded
) {
7048 this.$element
.addClass( 'oo-ui-panelLayout-expanded' );
7054 OO
.inheritClass( OO
.ui
.PanelLayout
, OO
.ui
.Layout
);
7057 * Page within an booklet layout.
7060 * @extends OO.ui.PanelLayout
7063 * @param {string} name Unique symbolic name of page
7064 * @param {Object} [config] Configuration options
7065 * @param {string} [outlineItem] Outline item widget
7067 OO
.ui
.PageLayout
= function OoUiPageLayout( name
, config
) {
7068 // Configuration initialization
7069 config
= $.extend( { scrollable
: true }, config
);
7071 // Parent constructor
7072 OO
.ui
.PageLayout
.super.call( this, config
);
7076 this.outlineItem
= config
.outlineItem
|| null;
7077 this.active
= false;
7080 this.$element
.addClass( 'oo-ui-pageLayout' );
7085 OO
.inheritClass( OO
.ui
.PageLayout
, OO
.ui
.PanelLayout
);
7091 * @param {boolean} active Page is active
7099 * @return {string} Symbolic name of page
7101 OO
.ui
.PageLayout
.prototype.getName = function () {
7106 * Check if page is active.
7108 * @return {boolean} Page is active
7110 OO
.ui
.PageLayout
.prototype.isActive = function () {
7117 * @return {OO.ui.OutlineItemWidget|null} Outline item widget
7119 OO
.ui
.PageLayout
.prototype.getOutlineItem = function () {
7120 return this.outlineItem
;
7126 * @localdoc Subclasses should override #setupOutlineItem instead of this method to adjust the
7127 * outline item as desired; this method is called for setting (with an object) and unsetting
7128 * (with null) and overriding methods would have to check the value of `outlineItem` to avoid
7129 * operating on null instead of an OO.ui.OutlineItemWidget object.
7131 * @param {OO.ui.OutlineItemWidget|null} outlineItem Outline item widget, null to clear
7134 OO
.ui
.PageLayout
.prototype.setOutlineItem = function ( outlineItem
) {
7135 this.outlineItem
= outlineItem
|| null;
7136 if ( outlineItem
) {
7137 this.setupOutlineItem();
7143 * Setup outline item.
7145 * @localdoc Subclasses should override this method to adjust the outline item as desired.
7147 * @param {OO.ui.OutlineItemWidget} outlineItem Outline item widget to setup
7150 OO
.ui
.PageLayout
.prototype.setupOutlineItem = function () {
7155 * Set page active state.
7157 * @param {boolean} Page is active
7160 OO
.ui
.PageLayout
.prototype.setActive = function ( active
) {
7163 if ( active
!== this.active
) {
7164 this.active
= active
;
7165 this.$element
.toggleClass( 'oo-ui-pageLayout-active', active
);
7166 this.emit( 'active', this.active
);
7171 * Layout containing a series of mutually exclusive pages.
7174 * @extends OO.ui.PanelLayout
7175 * @mixins OO.ui.GroupElement
7178 * @param {Object} [config] Configuration options
7179 * @cfg {boolean} [continuous=false] Show all pages, one after another
7180 * @cfg {string} [icon=''] Symbolic icon name
7181 * @cfg {OO.ui.Layout[]} [items] Layouts to add
7183 OO
.ui
.StackLayout
= function OoUiStackLayout( config
) {
7184 // Configuration initialization
7185 config
= $.extend( { scrollable
: true }, config
);
7187 // Parent constructor
7188 OO
.ui
.StackLayout
.super.call( this, config
);
7190 // Mixin constructors
7191 OO
.ui
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
7194 this.currentItem
= null;
7195 this.continuous
= !!config
.continuous
;
7198 this.$element
.addClass( 'oo-ui-stackLayout' );
7199 if ( this.continuous
) {
7200 this.$element
.addClass( 'oo-ui-stackLayout-continuous' );
7202 if ( $.isArray( config
.items
) ) {
7203 this.addItems( config
.items
);
7209 OO
.inheritClass( OO
.ui
.StackLayout
, OO
.ui
.PanelLayout
);
7210 OO
.mixinClass( OO
.ui
.StackLayout
, OO
.ui
.GroupElement
);
7216 * @param {OO.ui.Layout|null} item Current item or null if there is no longer a layout shown
7222 * Get the current item.
7224 * @return {OO.ui.Layout|null}
7226 OO
.ui
.StackLayout
.prototype.getCurrentItem = function () {
7227 return this.currentItem
;
7231 * Unset the current item.
7234 * @param {OO.ui.StackLayout} layout
7237 OO
.ui
.StackLayout
.prototype.unsetCurrentItem = function () {
7238 var prevItem
= this.currentItem
;
7239 if ( prevItem
=== null ) {
7243 this.currentItem
= null;
7244 this.emit( 'set', null );
7250 * Adding an existing item (by value) will move it.
7252 * @param {OO.ui.Layout[]} items Items to add
7253 * @param {number} [index] Index to insert items after
7256 OO
.ui
.StackLayout
.prototype.addItems = function ( items
, index
) {
7258 OO
.ui
.GroupElement
.prototype.addItems
.call( this, items
, index
);
7260 if ( !this.currentItem
&& items
.length
) {
7261 this.setItem( items
[0] );
7270 * Items will be detached, not removed, so they can be used later.
7272 * @param {OO.ui.Layout[]} items Items to remove
7276 OO
.ui
.StackLayout
.prototype.removeItems = function ( items
) {
7278 OO
.ui
.GroupElement
.prototype.removeItems
.call( this, items
);
7280 if ( $.inArray( this.currentItem
, items
) !== -1 ) {
7281 if ( this.items
.length
) {
7282 this.setItem( this.items
[0] );
7284 this.unsetCurrentItem();
7294 * Items will be detached, not removed, so they can be used later.
7299 OO
.ui
.StackLayout
.prototype.clearItems = function () {
7300 this.unsetCurrentItem();
7301 OO
.ui
.GroupElement
.prototype.clearItems
.call( this );
7309 * Any currently shown item will be hidden.
7311 * FIXME: If the passed item to show has not been added in the items list, then
7312 * this method drops it and unsets the current item.
7314 * @param {OO.ui.Layout} item Item to show
7318 OO
.ui
.StackLayout
.prototype.setItem = function ( item
) {
7321 if ( item
!== this.currentItem
) {
7322 if ( !this.continuous
) {
7323 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
7324 this.items
[i
].$element
.css( 'display', '' );
7327 if ( $.inArray( item
, this.items
) !== -1 ) {
7328 if ( !this.continuous
) {
7329 item
.$element
.css( 'display', 'block' );
7331 this.currentItem
= item
;
7332 this.emit( 'set', item
);
7334 this.unsetCurrentItem();
7342 * Horizontal bar layout of tools as icon buttons.
7345 * @extends OO.ui.ToolGroup
7348 * @param {OO.ui.Toolbar} toolbar
7349 * @param {Object} [config] Configuration options
7351 OO
.ui
.BarToolGroup
= function OoUiBarToolGroup( toolbar
, config
) {
7352 // Parent constructor
7353 OO
.ui
.BarToolGroup
.super.call( this, toolbar
, config
);
7356 this.$element
.addClass( 'oo-ui-barToolGroup' );
7361 OO
.inheritClass( OO
.ui
.BarToolGroup
, OO
.ui
.ToolGroup
);
7363 /* Static Properties */
7365 OO
.ui
.BarToolGroup
.static.titleTooltips
= true;
7367 OO
.ui
.BarToolGroup
.static.accelTooltips
= true;
7369 OO
.ui
.BarToolGroup
.static.name
= 'bar';
7372 * Popup list of tools with an icon and optional label.
7376 * @extends OO.ui.ToolGroup
7377 * @mixins OO.ui.IconElement
7378 * @mixins OO.ui.IndicatorElement
7379 * @mixins OO.ui.LabelElement
7380 * @mixins OO.ui.TitledElement
7381 * @mixins OO.ui.ClippableElement
7384 * @param {OO.ui.Toolbar} toolbar
7385 * @param {Object} [config] Configuration options
7386 * @cfg {string} [header] Text to display at the top of the pop-up
7388 OO
.ui
.PopupToolGroup
= function OoUiPopupToolGroup( toolbar
, config
) {
7389 // Configuration initialization
7390 config
= config
|| {};
7392 // Parent constructor
7393 OO
.ui
.PopupToolGroup
.super.call( this, toolbar
, config
);
7395 // Mixin constructors
7396 OO
.ui
.IconElement
.call( this, config
);
7397 OO
.ui
.IndicatorElement
.call( this, config
);
7398 OO
.ui
.LabelElement
.call( this, config
);
7399 OO
.ui
.TitledElement
.call( this, config
);
7400 OO
.ui
.ClippableElement
.call( this, $.extend( {}, config
, { $clippable
: this.$group
} ) );
7403 this.active
= false;
7404 this.dragging
= false;
7405 this.onBlurHandler
= this.onBlur
.bind( this );
7406 this.$handle
= this.$( '<span>' );
7410 'mousedown touchstart': this.onHandlePointerDown
.bind( this ),
7411 'mouseup touchend': this.onHandlePointerUp
.bind( this )
7416 .addClass( 'oo-ui-popupToolGroup-handle' )
7417 .append( this.$icon
, this.$label
, this.$indicator
);
7418 // If the pop-up should have a header, add it to the top of the toolGroup.
7419 // Note: If this feature is useful for other widgets, we could abstract it into an
7420 // OO.ui.HeaderedElement mixin constructor.
7421 if ( config
.header
!== undefined ) {
7423 .prepend( this.$( '<span>' )
7424 .addClass( 'oo-ui-popupToolGroup-header' )
7425 .text( config
.header
)
7429 .addClass( 'oo-ui-popupToolGroup' )
7430 .prepend( this.$handle
);
7435 OO
.inheritClass( OO
.ui
.PopupToolGroup
, OO
.ui
.ToolGroup
);
7436 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.IconElement
);
7437 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.IndicatorElement
);
7438 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.LabelElement
);
7439 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.TitledElement
);
7440 OO
.mixinClass( OO
.ui
.PopupToolGroup
, OO
.ui
.ClippableElement
);
7442 /* Static Properties */
7449 OO
.ui
.PopupToolGroup
.prototype.setDisabled = function () {
7451 OO
.ui
.PopupToolGroup
.super.prototype.setDisabled
.apply( this, arguments
);
7453 if ( this.isDisabled() && this.isElementAttached() ) {
7454 this.setActive( false );
7459 * Handle focus being lost.
7461 * The event is actually generated from a mouseup, so it is not a normal blur event object.
7463 * @param {jQuery.Event} e Mouse up event
7465 OO
.ui
.PopupToolGroup
.prototype.onBlur = function ( e
) {
7466 // Only deactivate when clicking outside the dropdown element
7467 if ( this.$( e
.target
).closest( '.oo-ui-popupToolGroup' )[0] !== this.$element
[0] ) {
7468 this.setActive( false );
7475 OO
.ui
.PopupToolGroup
.prototype.onPointerUp = function ( e
) {
7476 // e.which is 0 for touch events, 1 for left mouse button
7477 if ( !this.isDisabled() && e
.which
<= 1 ) {
7478 this.setActive( false );
7480 return OO
.ui
.PopupToolGroup
.super.prototype.onPointerUp
.call( this, e
);
7484 * Handle mouse up events.
7486 * @param {jQuery.Event} e Mouse up event
7488 OO
.ui
.PopupToolGroup
.prototype.onHandlePointerUp = function () {
7493 * Handle mouse down events.
7495 * @param {jQuery.Event} e Mouse down event
7497 OO
.ui
.PopupToolGroup
.prototype.onHandlePointerDown = function ( e
) {
7498 // e.which is 0 for touch events, 1 for left mouse button
7499 if ( !this.isDisabled() && e
.which
<= 1 ) {
7500 this.setActive( !this.active
);
7506 * Switch into active mode.
7508 * When active, mouseup events anywhere in the document will trigger deactivation.
7510 OO
.ui
.PopupToolGroup
.prototype.setActive = function ( value
) {
7512 if ( this.active
!== value
) {
7513 this.active
= value
;
7515 this.getElementDocument().addEventListener( 'mouseup', this.onBlurHandler
, true );
7517 // Try anchoring the popup to the left first
7518 this.$element
.addClass( 'oo-ui-popupToolGroup-active oo-ui-popupToolGroup-left' );
7519 this.toggleClipping( true );
7520 if ( this.isClippedHorizontally() ) {
7521 // Anchoring to the left caused the popup to clip, so anchor it to the right instead
7522 this.toggleClipping( false );
7524 .removeClass( 'oo-ui-popupToolGroup-left' )
7525 .addClass( 'oo-ui-popupToolGroup-right' );
7526 this.toggleClipping( true );
7529 this.getElementDocument().removeEventListener( 'mouseup', this.onBlurHandler
, true );
7530 this.$element
.removeClass(
7531 'oo-ui-popupToolGroup-active oo-ui-popupToolGroup-left oo-ui-popupToolGroup-right'
7533 this.toggleClipping( false );
7539 * Drop down list layout of tools as labeled icon buttons.
7541 * This layout allows some tools to be collapsible, controlled by a "More" / "Fewer" option at the
7542 * bottom of the main list. These are not automatically positioned at the bottom of the list; you
7543 * may want to use the 'promote' and 'demote' configuration options to achieve this.
7546 * @extends OO.ui.PopupToolGroup
7549 * @param {OO.ui.Toolbar} toolbar
7550 * @param {Object} [config] Configuration options
7551 * @cfg {Array} [allowCollapse] List of tools that can be collapsed. Remaining tools will be always
7553 * @cfg {Array} [forceExpand] List of tools that *may not* be collapsed. All remaining tools will be
7554 * allowed to be collapsed.
7555 * @cfg {boolean} [expanded=false] Whether the collapsible tools are expanded by default
7557 OO
.ui
.ListToolGroup
= function OoUiListToolGroup( toolbar
, config
) {
7558 // Configuration intialization
7559 config
= config
|| {};
7561 // Properties (must be set before parent constructor, which calls #populate)
7562 this.allowCollapse
= config
.allowCollapse
;
7563 this.forceExpand
= config
.forceExpand
;
7564 this.expanded
= config
.expanded
!== undefined ? config
.expanded
: false;
7565 this.collapsibleTools
= [];
7567 // Parent constructor
7568 OO
.ui
.ListToolGroup
.super.call( this, toolbar
, config
);
7571 this.$element
.addClass( 'oo-ui-listToolGroup' );
7576 OO
.inheritClass( OO
.ui
.ListToolGroup
, OO
.ui
.PopupToolGroup
);
7578 /* Static Properties */
7580 OO
.ui
.ListToolGroup
.static.accelTooltips
= true;
7582 OO
.ui
.ListToolGroup
.static.name
= 'list';
7589 OO
.ui
.ListToolGroup
.prototype.populate = function () {
7590 var i
, len
, allowCollapse
= [];
7592 OO
.ui
.ListToolGroup
.super.prototype.populate
.call( this );
7594 // Update the list of collapsible tools
7595 if ( this.allowCollapse
!== undefined ) {
7596 allowCollapse
= this.allowCollapse
;
7597 } else if ( this.forceExpand
!== undefined ) {
7598 allowCollapse
= OO
.simpleArrayDifference( Object
.keys( this.tools
), this.forceExpand
);
7601 this.collapsibleTools
= [];
7602 for ( i
= 0, len
= allowCollapse
.length
; i
< len
; i
++ ) {
7603 if ( this.tools
[ allowCollapse
[i
] ] !== undefined ) {
7604 this.collapsibleTools
.push( this.tools
[ allowCollapse
[i
] ] );
7608 // Keep at the end, even when tools are added
7609 this.$group
.append( this.getExpandCollapseTool().$element
);
7611 this.getExpandCollapseTool().toggle( this.collapsibleTools
.length
!== 0 );
7613 // Calling jQuery's .hide() and then .show() on a detached element caches the default value of its
7614 // 'display' attribute and restores it, and the tool uses a <span> and can be hidden and re-shown.
7615 // Is this a jQuery bug? http://jsfiddle.net/gtj4hu3h/
7616 if ( this.getExpandCollapseTool().$element
.css( 'display' ) === 'inline' ) {
7617 this.getExpandCollapseTool().$element
.css( 'display', 'inline-block' );
7620 this.updateCollapsibleState();
7623 OO
.ui
.ListToolGroup
.prototype.getExpandCollapseTool = function () {
7624 if ( this.expandCollapseTool
=== undefined ) {
7625 var ExpandCollapseTool = function () {
7626 ExpandCollapseTool
.super.apply( this, arguments
);
7629 OO
.inheritClass( ExpandCollapseTool
, OO
.ui
.Tool
);
7631 ExpandCollapseTool
.prototype.onSelect = function () {
7632 this.toolGroup
.expanded
= !this.toolGroup
.expanded
;
7633 this.toolGroup
.updateCollapsibleState();
7634 this.setActive( false );
7636 ExpandCollapseTool
.prototype.onUpdateState = function () {
7637 // Do nothing. Tool interface requires an implementation of this function.
7640 ExpandCollapseTool
.static.name
= 'more-fewer';
7642 this.expandCollapseTool
= new ExpandCollapseTool( this );
7644 return this.expandCollapseTool
;
7650 OO
.ui
.ListToolGroup
.prototype.onPointerUp = function ( e
) {
7651 var ret
= OO
.ui
.ListToolGroup
.super.prototype.onPointerUp
.call( this, e
);
7653 // Do not close the popup when the user wants to show more/fewer tools
7654 if ( this.$( e
.target
).closest( '.oo-ui-tool-name-more-fewer' ).length
) {
7655 // Prevent the popup list from being hidden
7656 this.setActive( true );
7662 OO
.ui
.ListToolGroup
.prototype.updateCollapsibleState = function () {
7665 this.getExpandCollapseTool()
7666 .setIcon( this.expanded
? 'collapse' : 'expand' )
7667 .setTitle( OO
.ui
.msg( this.expanded
? 'ooui-toolgroup-collapse' : 'ooui-toolgroup-expand' ) );
7669 for ( i
= 0, len
= this.collapsibleTools
.length
; i
< len
; i
++ ) {
7670 this.collapsibleTools
[i
].toggle( this.expanded
);
7675 * Drop down menu layout of tools as selectable menu items.
7678 * @extends OO.ui.PopupToolGroup
7681 * @param {OO.ui.Toolbar} toolbar
7682 * @param {Object} [config] Configuration options
7684 OO
.ui
.MenuToolGroup
= function OoUiMenuToolGroup( toolbar
, config
) {
7685 // Configuration initialization
7686 config
= config
|| {};
7688 // Parent constructor
7689 OO
.ui
.MenuToolGroup
.super.call( this, toolbar
, config
);
7692 this.toolbar
.connect( this, { updateState
: 'onUpdateState' } );
7695 this.$element
.addClass( 'oo-ui-menuToolGroup' );
7700 OO
.inheritClass( OO
.ui
.MenuToolGroup
, OO
.ui
.PopupToolGroup
);
7702 /* Static Properties */
7704 OO
.ui
.MenuToolGroup
.static.accelTooltips
= true;
7706 OO
.ui
.MenuToolGroup
.static.name
= 'menu';
7711 * Handle the toolbar state being updated.
7713 * When the state changes, the title of each active item in the menu will be joined together and
7714 * used as a label for the group. The label will be empty if none of the items are active.
7716 OO
.ui
.MenuToolGroup
.prototype.onUpdateState = function () {
7720 for ( name
in this.tools
) {
7721 if ( this.tools
[name
].isActive() ) {
7722 labelTexts
.push( this.tools
[name
].getTitle() );
7726 this.setLabel( labelTexts
.join( ', ' ) || ' ' );
7730 * Tool that shows a popup when selected.
7734 * @extends OO.ui.Tool
7735 * @mixins OO.ui.PopupElement
7738 * @param {OO.ui.Toolbar} toolbar
7739 * @param {Object} [config] Configuration options
7741 OO
.ui
.PopupTool
= function OoUiPopupTool( toolbar
, config
) {
7742 // Parent constructor
7743 OO
.ui
.PopupTool
.super.call( this, toolbar
, config
);
7745 // Mixin constructors
7746 OO
.ui
.PopupElement
.call( this, config
);
7750 .addClass( 'oo-ui-popupTool' )
7751 .append( this.popup
.$element
);
7756 OO
.inheritClass( OO
.ui
.PopupTool
, OO
.ui
.Tool
);
7757 OO
.mixinClass( OO
.ui
.PopupTool
, OO
.ui
.PopupElement
);
7762 * Handle the tool being selected.
7766 OO
.ui
.PopupTool
.prototype.onSelect = function () {
7767 if ( !this.isDisabled() ) {
7768 this.popup
.toggle();
7770 this.setActive( false );
7775 * Handle the toolbar state being updated.
7779 OO
.ui
.PopupTool
.prototype.onUpdateState = function () {
7780 this.setActive( false );
7784 * Mixin for OO.ui.Widget subclasses to provide OO.ui.GroupElement.
7786 * Use together with OO.ui.ItemWidget to make disabled state inheritable.
7790 * @extends OO.ui.GroupElement
7793 * @param {Object} [config] Configuration options
7795 OO
.ui
.GroupWidget
= function OoUiGroupWidget( config
) {
7796 // Parent constructor
7797 OO
.ui
.GroupWidget
.super.call( this, config
);
7802 OO
.inheritClass( OO
.ui
.GroupWidget
, OO
.ui
.GroupElement
);
7807 * Set the disabled state of the widget.
7809 * This will also update the disabled state of child widgets.
7811 * @param {boolean} disabled Disable widget
7814 OO
.ui
.GroupWidget
.prototype.setDisabled = function ( disabled
) {
7818 // Note: Calling #setDisabled this way assumes this is mixed into an OO.ui.Widget
7819 OO
.ui
.Widget
.prototype.setDisabled
.call( this, disabled
);
7821 // During construction, #setDisabled is called before the OO.ui.GroupElement constructor
7823 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
7824 this.items
[i
].updateDisabled();
7832 * Mixin for widgets used as items in widgets that inherit OO.ui.GroupWidget.
7834 * Item widgets have a reference to a OO.ui.GroupWidget while they are attached to the group. This
7835 * allows bidrectional communication.
7837 * Use together with OO.ui.GroupWidget to make disabled state inheritable.
7844 OO
.ui
.ItemWidget
= function OoUiItemWidget() {
7851 * Check if widget is disabled.
7853 * Checks parent if present, making disabled state inheritable.
7855 * @return {boolean} Widget is disabled
7857 OO
.ui
.ItemWidget
.prototype.isDisabled = function () {
7858 return this.disabled
||
7859 ( this.elementGroup
instanceof OO
.ui
.Widget
&& this.elementGroup
.isDisabled() );
7863 * Set group element is in.
7865 * @param {OO.ui.GroupElement|null} group Group element, null if none
7868 OO
.ui
.ItemWidget
.prototype.setElementGroup = function ( group
) {
7870 // Note: Calling #setElementGroup this way assumes this is mixed into an OO.ui.Element
7871 OO
.ui
.Element
.prototype.setElementGroup
.call( this, group
);
7873 // Initialize item disabled states
7874 this.updateDisabled();
7880 * Mixin that adds a menu showing suggested values for a text input.
7882 * Subclasses must handle `select` and `choose` events on #lookupMenu to make use of selections.
7884 * Subclasses that set the value of #lookupInput from their `choose` or `select` handler should
7885 * be aware that this will cause new suggestions to be looked up for the new value. If this is
7886 * not desired, disable lookups with #setLookupsDisabled, then set the value, then re-enable lookups.
7892 * @param {OO.ui.TextInputWidget} input Input widget
7893 * @param {Object} [config] Configuration options
7894 * @cfg {jQuery} [$overlay] Overlay for dropdown; defaults to relative positioning
7895 * @cfg {jQuery} [$container=input.$element] Element to render menu under
7897 OO
.ui
.LookupInputWidget
= function OoUiLookupInputWidget( input
, config
) {
7898 // Configuration initialization
7899 config
= config
|| {};
7902 this.lookupInput
= input
;
7903 this.$overlay
= config
.$overlay
|| this.$element
;
7904 this.lookupMenu
= new OO
.ui
.TextInputMenuWidget( this, {
7905 $: OO
.ui
.Element
.getJQuery( this.$overlay
),
7906 input
: this.lookupInput
,
7907 $container
: config
.$container
7909 this.lookupCache
= {};
7910 this.lookupQuery
= null;
7911 this.lookupRequest
= null;
7912 this.lookupsDisabled
= false;
7913 this.lookupInputFocused
= false;
7916 this.lookupInput
.$input
.on( {
7917 focus
: this.onLookupInputFocus
.bind( this ),
7918 blur
: this.onLookupInputBlur
.bind( this ),
7919 mousedown
: this.onLookupInputMouseDown
.bind( this )
7921 this.lookupInput
.connect( this, { change
: 'onLookupInputChange' } );
7922 this.lookupMenu
.connect( this, { toggle
: 'onLookupMenuToggle' } );
7925 this.$element
.addClass( 'oo-ui-lookupWidget' );
7926 this.lookupMenu
.$element
.addClass( 'oo-ui-lookupWidget-menu' );
7927 this.$overlay
.append( this.lookupMenu
.$element
);
7933 * Handle input focus event.
7935 * @param {jQuery.Event} e Input focus event
7937 OO
.ui
.LookupInputWidget
.prototype.onLookupInputFocus = function () {
7938 this.lookupInputFocused
= true;
7939 this.populateLookupMenu();
7943 * Handle input blur event.
7945 * @param {jQuery.Event} e Input blur event
7947 OO
.ui
.LookupInputWidget
.prototype.onLookupInputBlur = function () {
7948 this.closeLookupMenu();
7949 this.lookupInputFocused
= false;
7953 * Handle input mouse down event.
7955 * @param {jQuery.Event} e Input mouse down event
7957 OO
.ui
.LookupInputWidget
.prototype.onLookupInputMouseDown = function () {
7958 // Only open the menu if the input was already focused.
7959 // This way we allow the user to open the menu again after closing it with Esc
7960 // by clicking in the input. Opening (and populating) the menu when initially
7961 // clicking into the input is handled by the focus handler.
7962 if ( this.lookupInputFocused
&& !this.lookupMenu
.isVisible() ) {
7963 this.populateLookupMenu();
7968 * Handle input change event.
7970 * @param {string} value New input value
7972 OO
.ui
.LookupInputWidget
.prototype.onLookupInputChange = function () {
7973 if ( this.lookupInputFocused
) {
7974 this.populateLookupMenu();
7979 * Handle the lookup menu being shown/hidden.
7980 * @param {boolean} visible Whether the lookup menu is now visible.
7982 OO
.ui
.LookupInputWidget
.prototype.onLookupMenuToggle = function ( visible
) {
7984 // When the menu is hidden, abort any active request and clear the menu.
7985 // This has to be done here in addition to closeLookupMenu(), because
7986 // MenuWidget will close itself when the user presses Esc.
7987 this.abortLookupRequest();
7988 this.lookupMenu
.clearItems();
7995 * @return {OO.ui.TextInputMenuWidget}
7997 OO
.ui
.LookupInputWidget
.prototype.getLookupMenu = function () {
7998 return this.lookupMenu
;
8002 * Disable or re-enable lookups.
8004 * When lookups are disabled, calls to #populateLookupMenu will be ignored.
8006 * @param {boolean} disabled Disable lookups
8008 OO
.ui
.LookupInputWidget
.prototype.setLookupsDisabled = function ( disabled
) {
8009 this.lookupsDisabled
= !!disabled
;
8013 * Open the menu. If there are no entries in the menu, this does nothing.
8017 OO
.ui
.LookupInputWidget
.prototype.openLookupMenu = function () {
8018 if ( !this.lookupMenu
.isEmpty() ) {
8019 this.lookupMenu
.toggle( true );
8025 * Close the menu, empty it, and abort any pending request.
8029 OO
.ui
.LookupInputWidget
.prototype.closeLookupMenu = function () {
8030 this.lookupMenu
.toggle( false );
8031 this.abortLookupRequest();
8032 this.lookupMenu
.clearItems();
8037 * Request menu items based on the input's current value, and when they arrive,
8038 * populate the menu with these items and show the menu.
8040 * If lookups have been disabled with #setLookupsDisabled, this function does nothing.
8044 OO
.ui
.LookupInputWidget
.prototype.populateLookupMenu = function () {
8046 value
= this.lookupInput
.getValue();
8048 if ( this.lookupsDisabled
) {
8052 // If the input is empty, clear the menu
8053 if ( value
=== '' ) {
8054 this.closeLookupMenu();
8055 // Skip population if there is already a request pending for the current value
8056 } else if ( value
!== this.lookupQuery
) {
8057 this.getLookupMenuItems()
8058 .done( function ( items
) {
8059 widget
.lookupMenu
.clearItems();
8060 if ( items
.length
) {
8064 widget
.initializeLookupMenuSelection();
8066 widget
.lookupMenu
.toggle( false );
8069 .fail( function () {
8070 widget
.lookupMenu
.clearItems();
8078 * Select and highlight the first selectable item in the menu.
8082 OO
.ui
.LookupInputWidget
.prototype.initializeLookupMenuSelection = function () {
8083 if ( !this.lookupMenu
.getSelectedItem() ) {
8084 this.lookupMenu
.selectItem( this.lookupMenu
.getFirstSelectableItem() );
8086 this.lookupMenu
.highlightItem( this.lookupMenu
.getSelectedItem() );
8090 * Get lookup menu items for the current query.
8092 * @return {jQuery.Promise} Promise object which will be passed menu items as the first argument
8093 * of the done event. If the request was aborted to make way for a subsequent request,
8094 * this promise will not be rejected: it will remain pending forever.
8096 OO
.ui
.LookupInputWidget
.prototype.getLookupMenuItems = function () {
8098 value
= this.lookupInput
.getValue(),
8099 deferred
= $.Deferred(),
8102 this.abortLookupRequest();
8103 if ( Object
.prototype.hasOwnProperty
.call( this.lookupCache
, value
) ) {
8104 deferred
.resolve( this.getLookupMenuItemsFromData( this.lookupCache
[value
] ) );
8106 this.lookupInput
.pushPending();
8107 this.lookupQuery
= value
;
8108 ourRequest
= this.lookupRequest
= this.getLookupRequest();
8110 .always( function () {
8111 // We need to pop pending even if this is an old request, otherwise
8112 // the widget will remain pending forever.
8113 // TODO: this assumes that an aborted request will fail or succeed soon after
8114 // being aborted, or at least eventually. It would be nice if we could popPending()
8115 // at abort time, but only if we knew that we hadn't already called popPending()
8116 // for that request.
8117 widget
.lookupInput
.popPending();
8119 .done( function ( data
) {
8120 // If this is an old request (and aborting it somehow caused it to still succeed),
8121 // ignore its success completely
8122 if ( ourRequest
=== widget
.lookupRequest
) {
8123 widget
.lookupQuery
= null;
8124 widget
.lookupRequest
= null;
8125 widget
.lookupCache
[value
] = widget
.getLookupCacheItemFromData( data
);
8126 deferred
.resolve( widget
.getLookupMenuItemsFromData( widget
.lookupCache
[value
] ) );
8129 .fail( function () {
8130 // If this is an old request (or a request failing because it's being aborted),
8131 // ignore its failure completely
8132 if ( ourRequest
=== widget
.lookupRequest
) {
8133 widget
.lookupQuery
= null;
8134 widget
.lookupRequest
= null;
8139 return deferred
.promise();
8143 * Abort the currently pending lookup request, if any.
8145 OO
.ui
.LookupInputWidget
.prototype.abortLookupRequest = function () {
8146 var oldRequest
= this.lookupRequest
;
8148 // First unset this.lookupRequest to the fail handler will notice
8149 // that the request is no longer current
8150 this.lookupRequest
= null;
8151 this.lookupQuery
= null;
8157 * Get a new request object of the current lookup query value.
8160 * @return {jQuery.Promise} jQuery AJAX object, or promise object with an .abort() method
8162 OO
.ui
.LookupInputWidget
.prototype.getLookupRequest = function () {
8163 // Stub, implemented in subclass
8168 * Get a list of menu item widgets from the data stored by the lookup request's done handler.
8171 * @param {Mixed} data Cached result data, usually an array
8172 * @return {OO.ui.MenuItemWidget[]} Menu items
8174 OO
.ui
.LookupInputWidget
.prototype.getLookupMenuItemsFromData = function () {
8175 // Stub, implemented in subclass
8180 * Get lookup cache item from server response data.
8183 * @param {Mixed} data Response from server
8184 * @return {Mixed} Cached result data
8186 OO
.ui
.LookupInputWidget
.prototype.getLookupCacheItemFromData = function () {
8187 // Stub, implemented in subclass
8192 * Set of controls for an OO.ui.OutlineWidget.
8194 * Controls include moving items up and down, removing items, and adding different kinds of items.
8197 * @extends OO.ui.Widget
8198 * @mixins OO.ui.GroupElement
8199 * @mixins OO.ui.IconElement
8202 * @param {OO.ui.OutlineWidget} outline Outline to control
8203 * @param {Object} [config] Configuration options
8205 OO
.ui
.OutlineControlsWidget
= function OoUiOutlineControlsWidget( outline
, config
) {
8206 // Configuration initialization
8207 config
= $.extend( { icon
: 'add' }, config
);
8209 // Parent constructor
8210 OO
.ui
.OutlineControlsWidget
.super.call( this, config
);
8212 // Mixin constructors
8213 OO
.ui
.GroupElement
.call( this, config
);
8214 OO
.ui
.IconElement
.call( this, config
);
8217 this.outline
= outline
;
8218 this.$movers
= this.$( '<div>' );
8219 this.upButton
= new OO
.ui
.ButtonWidget( {
8223 title
: OO
.ui
.msg( 'ooui-outline-control-move-up' )
8225 this.downButton
= new OO
.ui
.ButtonWidget( {
8229 title
: OO
.ui
.msg( 'ooui-outline-control-move-down' )
8231 this.removeButton
= new OO
.ui
.ButtonWidget( {
8235 title
: OO
.ui
.msg( 'ooui-outline-control-remove' )
8239 outline
.connect( this, {
8240 select
: 'onOutlineChange',
8241 add
: 'onOutlineChange',
8242 remove
: 'onOutlineChange'
8244 this.upButton
.connect( this, { click
: [ 'emit', 'move', -1 ] } );
8245 this.downButton
.connect( this, { click
: [ 'emit', 'move', 1 ] } );
8246 this.removeButton
.connect( this, { click
: [ 'emit', 'remove' ] } );
8249 this.$element
.addClass( 'oo-ui-outlineControlsWidget' );
8250 this.$group
.addClass( 'oo-ui-outlineControlsWidget-items' );
8252 .addClass( 'oo-ui-outlineControlsWidget-movers' )
8253 .append( this.removeButton
.$element
, this.upButton
.$element
, this.downButton
.$element
);
8254 this.$element
.append( this.$icon
, this.$group
, this.$movers
);
8259 OO
.inheritClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.Widget
);
8260 OO
.mixinClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.GroupElement
);
8261 OO
.mixinClass( OO
.ui
.OutlineControlsWidget
, OO
.ui
.IconElement
);
8267 * @param {number} places Number of places to move
8277 * Handle outline change events.
8279 OO
.ui
.OutlineControlsWidget
.prototype.onOutlineChange = function () {
8280 var i
, len
, firstMovable
, lastMovable
,
8281 items
= this.outline
.getItems(),
8282 selectedItem
= this.outline
.getSelectedItem(),
8283 movable
= selectedItem
&& selectedItem
.isMovable(),
8284 removable
= selectedItem
&& selectedItem
.isRemovable();
8289 while ( ++i
< len
) {
8290 if ( items
[i
].isMovable() ) {
8291 firstMovable
= items
[i
];
8297 if ( items
[i
].isMovable() ) {
8298 lastMovable
= items
[i
];
8303 this.upButton
.setDisabled( !movable
|| selectedItem
=== firstMovable
);
8304 this.downButton
.setDisabled( !movable
|| selectedItem
=== lastMovable
);
8305 this.removeButton
.setDisabled( !removable
);
8309 * Mixin for widgets with a boolean on/off state.
8315 * @param {Object} [config] Configuration options
8316 * @cfg {boolean} [value=false] Initial value
8318 OO
.ui
.ToggleWidget
= function OoUiToggleWidget( config
) {
8319 // Configuration initialization
8320 config
= config
|| {};
8326 this.$element
.addClass( 'oo-ui-toggleWidget' );
8327 this.setValue( !!config
.value
);
8334 * @param {boolean} value Changed value
8340 * Get the value of the toggle.
8344 OO
.ui
.ToggleWidget
.prototype.getValue = function () {
8349 * Set the value of the toggle.
8351 * @param {boolean} value New value
8355 OO
.ui
.ToggleWidget
.prototype.setValue = function ( value
) {
8357 if ( this.value
!== value
) {
8359 this.emit( 'change', value
);
8360 this.$element
.toggleClass( 'oo-ui-toggleWidget-on', value
);
8361 this.$element
.toggleClass( 'oo-ui-toggleWidget-off', !value
);
8367 * Group widget for multiple related buttons.
8369 * Use together with OO.ui.ButtonWidget.
8372 * @extends OO.ui.Widget
8373 * @mixins OO.ui.GroupElement
8376 * @param {Object} [config] Configuration options
8377 * @cfg {OO.ui.ButtonWidget[]} [items] Buttons to add
8379 OO
.ui
.ButtonGroupWidget
= function OoUiButtonGroupWidget( config
) {
8380 // Configuration initialization
8381 config
= config
|| {};
8383 // Parent constructor
8384 OO
.ui
.ButtonGroupWidget
.super.call( this, config
);
8386 // Mixin constructors
8387 OO
.ui
.GroupElement
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
8390 this.$element
.addClass( 'oo-ui-buttonGroupWidget' );
8391 if ( $.isArray( config
.items
) ) {
8392 this.addItems( config
.items
);
8398 OO
.inheritClass( OO
.ui
.ButtonGroupWidget
, OO
.ui
.Widget
);
8399 OO
.mixinClass( OO
.ui
.ButtonGroupWidget
, OO
.ui
.GroupElement
);
8402 * Generic widget for buttons.
8405 * @extends OO.ui.Widget
8406 * @mixins OO.ui.ButtonElement
8407 * @mixins OO.ui.IconElement
8408 * @mixins OO.ui.IndicatorElement
8409 * @mixins OO.ui.LabelElement
8410 * @mixins OO.ui.TitledElement
8411 * @mixins OO.ui.FlaggedElement
8414 * @param {Object} [config] Configuration options
8415 * @cfg {string} [href] Hyperlink to visit when clicked
8416 * @cfg {string} [target] Target to open hyperlink in
8418 OO
.ui
.ButtonWidget
= function OoUiButtonWidget( config
) {
8419 // Configuration initialization
8420 config
= $.extend( { target
: '_blank' }, config
);
8422 // Parent constructor
8423 OO
.ui
.ButtonWidget
.super.call( this, config
);
8425 // Mixin constructors
8426 OO
.ui
.ButtonElement
.call( this, config
);
8427 OO
.ui
.IconElement
.call( this, config
);
8428 OO
.ui
.IndicatorElement
.call( this, config
);
8429 OO
.ui
.LabelElement
.call( this, config
);
8430 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$button
} ) );
8431 OO
.ui
.FlaggedElement
.call( this, config
);
8436 this.isHyperlink
= false;
8440 click
: this.onClick
.bind( this ),
8441 keypress
: this.onKeyPress
.bind( this )
8445 this.$button
.append( this.$icon
, this.$label
, this.$indicator
);
8447 .addClass( 'oo-ui-buttonWidget' )
8448 .append( this.$button
);
8449 this.setHref( config
.href
);
8450 this.setTarget( config
.target
);
8455 OO
.inheritClass( OO
.ui
.ButtonWidget
, OO
.ui
.Widget
);
8456 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.ButtonElement
);
8457 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.IconElement
);
8458 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.IndicatorElement
);
8459 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.LabelElement
);
8460 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.TitledElement
);
8461 OO
.mixinClass( OO
.ui
.ButtonWidget
, OO
.ui
.FlaggedElement
);
8472 * Handles mouse click events.
8474 * @param {jQuery.Event} e Mouse click event
8477 OO
.ui
.ButtonWidget
.prototype.onClick = function () {
8478 if ( !this.isDisabled() ) {
8479 this.emit( 'click' );
8480 if ( this.isHyperlink
) {
8488 * Handles keypress events.
8490 * @param {jQuery.Event} e Keypress event
8493 OO
.ui
.ButtonWidget
.prototype.onKeyPress = function ( e
) {
8494 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
8495 this.emit( 'click' );
8496 if ( this.isHyperlink
) {
8504 * Get hyperlink location.
8506 * @return {string} Hyperlink location
8508 OO
.ui
.ButtonWidget
.prototype.getHref = function () {
8513 * Get hyperlink target.
8515 * @return {string} Hyperlink target
8517 OO
.ui
.ButtonWidget
.prototype.getTarget = function () {
8522 * Set hyperlink location.
8524 * @param {string|null} href Hyperlink location, null to remove
8526 OO
.ui
.ButtonWidget
.prototype.setHref = function ( href
) {
8527 href
= typeof href
=== 'string' ? href
: null;
8529 if ( href
!== this.href
) {
8531 if ( href
!== null ) {
8532 this.$button
.attr( 'href', href
);
8533 this.isHyperlink
= true;
8535 this.$button
.removeAttr( 'href' );
8536 this.isHyperlink
= false;
8544 * Set hyperlink target.
8546 * @param {string|null} target Hyperlink target, null to remove
8548 OO
.ui
.ButtonWidget
.prototype.setTarget = function ( target
) {
8549 target
= typeof target
=== 'string' ? target
: null;
8551 if ( target
!== this.target
) {
8552 this.target
= target
;
8553 if ( target
!== null ) {
8554 this.$button
.attr( 'target', target
);
8556 this.$button
.removeAttr( 'target' );
8564 * Button widget that executes an action and is managed by an OO.ui.ActionSet.
8567 * @extends OO.ui.ButtonWidget
8568 * @mixins OO.ui.PendingElement
8571 * @param {Object} [config] Configuration options
8572 * @cfg {string} [action] Symbolic action name
8573 * @cfg {string[]} [modes] Symbolic mode names
8574 * @cfg {boolean} [framed=false] Render button with a frame
8576 OO
.ui
.ActionWidget
= function OoUiActionWidget( config
) {
8577 // Configuration initialization
8578 config
= $.extend( { framed
: false }, config
);
8580 // Parent constructor
8581 OO
.ui
.ActionWidget
.super.call( this, config
);
8583 // Mixin constructors
8584 OO
.ui
.PendingElement
.call( this, config
);
8587 this.action
= config
.action
|| '';
8588 this.modes
= config
.modes
|| [];
8593 this.$element
.addClass( 'oo-ui-actionWidget' );
8598 OO
.inheritClass( OO
.ui
.ActionWidget
, OO
.ui
.ButtonWidget
);
8599 OO
.mixinClass( OO
.ui
.ActionWidget
, OO
.ui
.PendingElement
);
8610 * Check if action is available in a certain mode.
8612 * @param {string} mode Name of mode
8613 * @return {boolean} Has mode
8615 OO
.ui
.ActionWidget
.prototype.hasMode = function ( mode
) {
8616 return this.modes
.indexOf( mode
) !== -1;
8620 * Get symbolic action name.
8624 OO
.ui
.ActionWidget
.prototype.getAction = function () {
8629 * Get symbolic action name.
8633 OO
.ui
.ActionWidget
.prototype.getModes = function () {
8634 return this.modes
.slice();
8638 * Emit a resize event if the size has changed.
8642 OO
.ui
.ActionWidget
.prototype.propagateResize = function () {
8645 if ( this.isElementAttached() ) {
8646 width
= this.$element
.width();
8647 height
= this.$element
.height();
8649 if ( width
!== this.width
|| height
!== this.height
) {
8651 this.height
= height
;
8652 this.emit( 'resize' );
8662 OO
.ui
.ActionWidget
.prototype.setIcon = function () {
8664 OO
.ui
.IconElement
.prototype.setIcon
.apply( this, arguments
);
8665 this.propagateResize();
8673 OO
.ui
.ActionWidget
.prototype.setLabel = function () {
8675 OO
.ui
.LabelElement
.prototype.setLabel
.apply( this, arguments
);
8676 this.propagateResize();
8684 OO
.ui
.ActionWidget
.prototype.setFlags = function () {
8686 OO
.ui
.FlaggedElement
.prototype.setFlags
.apply( this, arguments
);
8687 this.propagateResize();
8695 OO
.ui
.ActionWidget
.prototype.clearFlags = function () {
8697 OO
.ui
.FlaggedElement
.prototype.clearFlags
.apply( this, arguments
);
8698 this.propagateResize();
8704 * Toggle visibility of button.
8706 * @param {boolean} [show] Show button, omit to toggle visibility
8709 OO
.ui
.ActionWidget
.prototype.toggle = function () {
8711 OO
.ui
.ActionWidget
.super.prototype.toggle
.apply( this, arguments
);
8712 this.propagateResize();
8718 * Button that shows and hides a popup.
8721 * @extends OO.ui.ButtonWidget
8722 * @mixins OO.ui.PopupElement
8725 * @param {Object} [config] Configuration options
8727 OO
.ui
.PopupButtonWidget
= function OoUiPopupButtonWidget( config
) {
8728 // Parent constructor
8729 OO
.ui
.PopupButtonWidget
.super.call( this, config
);
8731 // Mixin constructors
8732 OO
.ui
.PopupElement
.call( this, config
);
8736 .addClass( 'oo-ui-popupButtonWidget' )
8737 .append( this.popup
.$element
);
8742 OO
.inheritClass( OO
.ui
.PopupButtonWidget
, OO
.ui
.ButtonWidget
);
8743 OO
.mixinClass( OO
.ui
.PopupButtonWidget
, OO
.ui
.PopupElement
);
8748 * Handles mouse click events.
8750 * @param {jQuery.Event} e Mouse click event
8752 OO
.ui
.PopupButtonWidget
.prototype.onClick = function ( e
) {
8753 // Skip clicks within the popup
8754 if ( $.contains( this.popup
.$element
[0], e
.target
) ) {
8758 if ( !this.isDisabled() ) {
8759 this.popup
.toggle();
8761 OO
.ui
.PopupButtonWidget
.super.prototype.onClick
.call( this );
8767 * Button that toggles on and off.
8770 * @extends OO.ui.ButtonWidget
8771 * @mixins OO.ui.ToggleWidget
8774 * @param {Object} [config] Configuration options
8775 * @cfg {boolean} [value=false] Initial value
8777 OO
.ui
.ToggleButtonWidget
= function OoUiToggleButtonWidget( config
) {
8778 // Configuration initialization
8779 config
= config
|| {};
8781 // Parent constructor
8782 OO
.ui
.ToggleButtonWidget
.super.call( this, config
);
8784 // Mixin constructors
8785 OO
.ui
.ToggleWidget
.call( this, config
);
8788 this.$element
.addClass( 'oo-ui-toggleButtonWidget' );
8793 OO
.inheritClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.ButtonWidget
);
8794 OO
.mixinClass( OO
.ui
.ToggleButtonWidget
, OO
.ui
.ToggleWidget
);
8801 OO
.ui
.ToggleButtonWidget
.prototype.onClick = function () {
8802 if ( !this.isDisabled() ) {
8803 this.setValue( !this.value
);
8807 return OO
.ui
.ToggleButtonWidget
.super.prototype.onClick
.call( this );
8813 OO
.ui
.ToggleButtonWidget
.prototype.setValue = function ( value
) {
8815 if ( value
!== this.value
) {
8816 this.setActive( value
);
8819 // Parent method (from mixin)
8820 OO
.ui
.ToggleWidget
.prototype.setValue
.call( this, value
);
8826 * Dropdown menu of options.
8828 * Dropdown menus provide a control for accessing a menu and compose a menu within the widget, which
8829 * can be accessed using the #getMenu method.
8831 * Use with OO.ui.MenuItemWidget.
8834 * @extends OO.ui.Widget
8835 * @mixins OO.ui.IconElement
8836 * @mixins OO.ui.IndicatorElement
8837 * @mixins OO.ui.LabelElement
8838 * @mixins OO.ui.TitledElement
8841 * @param {Object} [config] Configuration options
8842 * @cfg {Object} [menu] Configuration options to pass to menu widget
8844 OO
.ui
.DropdownWidget
= function OoUiDropdownWidget( config
) {
8845 // Configuration initialization
8846 config
= $.extend( { indicator
: 'down' }, config
);
8848 // Parent constructor
8849 OO
.ui
.DropdownWidget
.super.call( this, config
);
8851 // Mixin constructors
8852 OO
.ui
.IconElement
.call( this, config
);
8853 OO
.ui
.IndicatorElement
.call( this, config
);
8854 OO
.ui
.LabelElement
.call( this, config
);
8855 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$label
} ) );
8858 this.menu
= new OO
.ui
.MenuWidget( $.extend( { $: this.$, widget
: this }, config
.menu
) );
8859 this.$handle
= this.$( '<span>' );
8862 this.$element
.on( { click
: this.onClick
.bind( this ) } );
8863 this.menu
.connect( this, { select
: 'onMenuSelect' } );
8867 .addClass( 'oo-ui-dropdownWidget-handle' )
8868 .append( this.$icon
, this.$label
, this.$indicator
);
8870 .addClass( 'oo-ui-dropdownWidget' )
8871 .append( this.$handle
, this.menu
.$element
);
8876 OO
.inheritClass( OO
.ui
.DropdownWidget
, OO
.ui
.Widget
);
8877 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.IconElement
);
8878 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.IndicatorElement
);
8879 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.LabelElement
);
8880 OO
.mixinClass( OO
.ui
.DropdownWidget
, OO
.ui
.TitledElement
);
8887 * @return {OO.ui.MenuWidget} Menu of widget
8889 OO
.ui
.DropdownWidget
.prototype.getMenu = function () {
8894 * Handles menu select events.
8896 * @param {OO.ui.MenuItemWidget} item Selected menu item
8898 OO
.ui
.DropdownWidget
.prototype.onMenuSelect = function ( item
) {
8905 selectedLabel
= item
.getLabel();
8907 // If the label is a DOM element, clone it, because setLabel will append() it
8908 if ( selectedLabel
instanceof jQuery
) {
8909 selectedLabel
= selectedLabel
.clone();
8912 this.setLabel( selectedLabel
);
8916 * Handles mouse click events.
8918 * @param {jQuery.Event} e Mouse click event
8920 OO
.ui
.DropdownWidget
.prototype.onClick = function ( e
) {
8921 // Skip clicks within the menu
8922 if ( $.contains( this.menu
.$element
[0], e
.target
) ) {
8926 if ( !this.isDisabled() ) {
8927 if ( this.menu
.isVisible() ) {
8928 this.menu
.toggle( false );
8930 this.menu
.toggle( true );
8939 * See OO.ui.IconElement for more information.
8942 * @extends OO.ui.Widget
8943 * @mixins OO.ui.IconElement
8944 * @mixins OO.ui.TitledElement
8947 * @param {Object} [config] Configuration options
8949 OO
.ui
.IconWidget
= function OoUiIconWidget( config
) {
8950 // Configuration initialization
8951 config
= config
|| {};
8953 // Parent constructor
8954 OO
.ui
.IconWidget
.super.call( this, config
);
8956 // Mixin constructors
8957 OO
.ui
.IconElement
.call( this, $.extend( {}, config
, { $icon
: this.$element
} ) );
8958 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$element
} ) );
8961 this.$element
.addClass( 'oo-ui-iconWidget' );
8966 OO
.inheritClass( OO
.ui
.IconWidget
, OO
.ui
.Widget
);
8967 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.IconElement
);
8968 OO
.mixinClass( OO
.ui
.IconWidget
, OO
.ui
.TitledElement
);
8970 /* Static Properties */
8972 OO
.ui
.IconWidget
.static.tagName
= 'span';
8977 * See OO.ui.IndicatorElement for more information.
8980 * @extends OO.ui.Widget
8981 * @mixins OO.ui.IndicatorElement
8982 * @mixins OO.ui.TitledElement
8985 * @param {Object} [config] Configuration options
8987 OO
.ui
.IndicatorWidget
= function OoUiIndicatorWidget( config
) {
8988 // Configuration initialization
8989 config
= config
|| {};
8991 // Parent constructor
8992 OO
.ui
.IndicatorWidget
.super.call( this, config
);
8994 // Mixin constructors
8995 OO
.ui
.IndicatorElement
.call( this, $.extend( {}, config
, { $indicator
: this.$element
} ) );
8996 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$element
} ) );
8999 this.$element
.addClass( 'oo-ui-indicatorWidget' );
9004 OO
.inheritClass( OO
.ui
.IndicatorWidget
, OO
.ui
.Widget
);
9005 OO
.mixinClass( OO
.ui
.IndicatorWidget
, OO
.ui
.IndicatorElement
);
9006 OO
.mixinClass( OO
.ui
.IndicatorWidget
, OO
.ui
.TitledElement
);
9008 /* Static Properties */
9010 OO
.ui
.IndicatorWidget
.static.tagName
= 'span';
9013 * Base class for input widgets.
9017 * @extends OO.ui.Widget
9018 * @mixins OO.ui.FlaggedElement
9021 * @param {Object} [config] Configuration options
9022 * @cfg {string} [name=''] HTML input name
9023 * @cfg {string} [value=''] Input value
9024 * @cfg {Function} [inputFilter] Filter function to apply to the input. Takes a string argument and returns a string.
9026 OO
.ui
.InputWidget
= function OoUiInputWidget( config
) {
9027 // Configuration initialization
9028 config
= config
|| {};
9030 // Parent constructor
9031 OO
.ui
.InputWidget
.super.call( this, config
);
9033 // Mixin constructors
9034 OO
.ui
.FlaggedElement
.call( this, config
);
9037 this.$input
= this.getInputElement( config
);
9039 this.inputFilter
= config
.inputFilter
;
9042 this.$input
.on( 'keydown mouseup cut paste change input select', this.onEdit
.bind( this ) );
9046 .attr( 'name', config
.name
)
9047 .prop( 'disabled', this.isDisabled() );
9048 this.$element
.addClass( 'oo-ui-inputWidget' ).append( this.$input
, $( '<span>' ) );
9049 this.setValue( config
.value
);
9054 OO
.inheritClass( OO
.ui
.InputWidget
, OO
.ui
.Widget
);
9055 OO
.mixinClass( OO
.ui
.InputWidget
, OO
.ui
.FlaggedElement
);
9061 * @param {string} value
9067 * Get input element.
9070 * @param {Object} [config] Configuration options
9071 * @return {jQuery} Input element
9073 OO
.ui
.InputWidget
.prototype.getInputElement = function () {
9074 return this.$( '<input>' );
9078 * Handle potentially value-changing events.
9080 * @param {jQuery.Event} e Key down, mouse up, cut, paste, change, input, or select event
9082 OO
.ui
.InputWidget
.prototype.onEdit = function () {
9084 if ( !this.isDisabled() ) {
9085 // Allow the stack to clear so the value will be updated
9086 setTimeout( function () {
9087 widget
.setValue( widget
.$input
.val() );
9093 * Get the value of the input.
9095 * @return {string} Input value
9097 OO
.ui
.InputWidget
.prototype.getValue = function () {
9102 * Sets the direction of the current input, either RTL or LTR
9104 * @param {boolean} isRTL
9106 OO
.ui
.InputWidget
.prototype.setRTL = function ( isRTL
) {
9108 this.$input
.removeClass( 'oo-ui-ltr' );
9109 this.$input
.addClass( 'oo-ui-rtl' );
9111 this.$input
.removeClass( 'oo-ui-rtl' );
9112 this.$input
.addClass( 'oo-ui-ltr' );
9117 * Set the value of the input.
9119 * @param {string} value New value
9123 OO
.ui
.InputWidget
.prototype.setValue = function ( value
) {
9124 value
= this.sanitizeValue( value
);
9125 if ( this.value
!== value
) {
9127 this.emit( 'change', this.value
);
9129 // Update the DOM if it has changed. Note that with sanitizeValue, it
9130 // is possible for the DOM value to change without this.value changing.
9131 if ( this.$input
.val() !== this.value
) {
9132 this.$input
.val( this.value
);
9138 * Sanitize incoming value.
9140 * Ensures value is a string, and converts undefined and null to empty string.
9143 * @param {string} value Original value
9144 * @return {string} Sanitized value
9146 OO
.ui
.InputWidget
.prototype.sanitizeValue = function ( value
) {
9147 if ( value
=== undefined || value
=== null ) {
9149 } else if ( this.inputFilter
) {
9150 return this.inputFilter( String( value
) );
9152 return String( value
);
9157 * Simulate the behavior of clicking on a label bound to this input.
9159 OO
.ui
.InputWidget
.prototype.simulateLabelClick = function () {
9160 if ( !this.isDisabled() ) {
9161 if ( this.$input
.is( ':checkbox,:radio' ) ) {
9162 this.$input
.click();
9163 } else if ( this.$input
.is( ':input' ) ) {
9164 this.$input
[0].focus();
9172 OO
.ui
.InputWidget
.prototype.setDisabled = function ( state
) {
9173 OO
.ui
.InputWidget
.super.prototype.setDisabled
.call( this, state
);
9174 if ( this.$input
) {
9175 this.$input
.prop( 'disabled', this.isDisabled() );
9185 OO
.ui
.InputWidget
.prototype.focus = function () {
9186 this.$input
[0].focus();
9195 OO
.ui
.InputWidget
.prototype.blur = function () {
9196 this.$input
[0].blur();
9201 * A button that is an input widget. Intended to be used within a OO.ui.FormLayout.
9204 * @extends OO.ui.InputWidget
9205 * @mixins OO.ui.ButtonElement
9206 * @mixins OO.ui.IconElement
9207 * @mixins OO.ui.IndicatorElement
9208 * @mixins OO.ui.LabelElement
9209 * @mixins OO.ui.TitledElement
9210 * @mixins OO.ui.FlaggedElement
9213 * @param {Object} [config] Configuration options
9214 * @cfg {string} [type='button'] HTML tag `type` attribute, may be 'button', 'submit' or 'reset'
9215 * @cfg {boolean} [useInputTag=false] Whether to use `<input/>` rather than `<button/>`. Only useful
9216 * if you need IE 6 support in a form with multiple buttons. If you use this option, icons and
9217 * indicators will not be displayed, it won't be possible to have a non-plaintext label, and it
9218 * won't be possible to set a value (which will internally become identical to the label).
9220 OO
.ui
.ButtonInputWidget
= function OoUiButtonInputWidget( config
) {
9221 // Configuration initialization
9222 config
= $.extend( { type
: 'button', useInputTag
: false }, config
);
9224 // Properties (must be set before parent constructor, which calls #setValue)
9225 this.useInputTag
= config
.useInputTag
;
9227 // Parent constructor
9228 OO
.ui
.ButtonInputWidget
.super.call( this, config
);
9230 // Mixin constructors
9231 OO
.ui
.ButtonElement
.call( this, $.extend( {}, config
, { $button
: this.$input
} ) );
9232 OO
.ui
.IconElement
.call( this, config
);
9233 OO
.ui
.IndicatorElement
.call( this, config
);
9234 OO
.ui
.LabelElement
.call( this, config
);
9235 OO
.ui
.TitledElement
.call( this, $.extend( {}, config
, { $titled
: this.$input
} ) );
9236 OO
.ui
.FlaggedElement
.call( this, config
);
9240 click
: this.onClick
.bind( this ),
9241 keypress
: this.onKeyPress
.bind( this )
9245 if ( !config
.useInputTag
) {
9246 this.$input
.append( this.$icon
, this.$label
, this.$indicator
);
9248 this.$element
.addClass( 'oo-ui-buttonInputWidget' );
9253 OO
.inheritClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.InputWidget
);
9254 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.ButtonElement
);
9255 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.IconElement
);
9256 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.IndicatorElement
);
9257 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.LabelElement
);
9258 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.TitledElement
);
9259 OO
.mixinClass( OO
.ui
.ButtonInputWidget
, OO
.ui
.FlaggedElement
);
9270 * Get input element.
9273 * @param {Object} [config] Configuration options
9274 * @return {jQuery} Input element
9276 OO
.ui
.ButtonInputWidget
.prototype.getInputElement = function ( config
) {
9277 // Configuration intialization
9278 config
= config
|| {};
9280 var html
= '<' + ( config
.useInputTag
? 'input' : 'button' ) + ' type="' + config
.type
+ '">';
9282 return this.$( html
);
9288 * Overridden to support setting the 'value' of `<input/>` elements.
9290 * @param {jQuery|string|Function|null} label Label nodes; text; a function that returns nodes or
9291 * text; or null for no label
9294 OO
.ui
.ButtonInputWidget
.prototype.setLabel = function ( label
) {
9295 OO
.ui
.LabelElement
.prototype.setLabel
.call( this, label
);
9297 if ( this.useInputTag
) {
9298 if ( typeof label
=== 'function' ) {
9299 label
= OO
.ui
.resolveMsg( label
);
9301 if ( label
instanceof jQuery
) {
9302 label
= label
.text();
9307 this.$input
.val( label
);
9314 * Set the value of the input.
9316 * Overridden to disable for `<input/>` elements, which have value identical to the label.
9318 * @param {string} value New value
9321 OO
.ui
.ButtonInputWidget
.prototype.setValue = function ( value
) {
9322 if ( !this.useInputTag
) {
9323 OO
.ui
.ButtonInputWidget
.super.prototype.setValue
.call( this, value
);
9329 * Handles mouse click events.
9331 * @param {jQuery.Event} e Mouse click event
9334 OO
.ui
.ButtonInputWidget
.prototype.onClick = function () {
9335 if ( !this.isDisabled() ) {
9336 this.emit( 'click' );
9342 * Handles keypress events.
9344 * @param {jQuery.Event} e Keypress event
9347 OO
.ui
.ButtonInputWidget
.prototype.onKeyPress = function ( e
) {
9348 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
9349 this.emit( 'click' );
9355 * Checkbox input widget.
9358 * @extends OO.ui.InputWidget
9361 * @param {Object} [config] Configuration options
9363 OO
.ui
.CheckboxInputWidget
= function OoUiCheckboxInputWidget( config
) {
9364 // Parent constructor
9365 OO
.ui
.CheckboxInputWidget
.super.call( this, config
);
9368 this.$element
.addClass( 'oo-ui-checkboxInputWidget' );
9373 OO
.inheritClass( OO
.ui
.CheckboxInputWidget
, OO
.ui
.InputWidget
);
9378 * Get input element.
9381 * @return {jQuery} Input element
9383 OO
.ui
.CheckboxInputWidget
.prototype.getInputElement = function () {
9384 return this.$( '<input type="checkbox" />' );
9388 * Get checked state of the checkbox
9390 * @return {boolean} If the checkbox is checked
9392 OO
.ui
.CheckboxInputWidget
.prototype.getValue = function () {
9397 * Set checked state of the checkbox
9399 * @param {boolean} value New value
9401 OO
.ui
.CheckboxInputWidget
.prototype.setValue = function ( value
) {
9403 if ( this.value
!== value
) {
9405 this.$input
.prop( 'checked', this.value
);
9406 this.emit( 'change', this.value
);
9413 OO
.ui
.CheckboxInputWidget
.prototype.onEdit = function () {
9415 if ( !this.isDisabled() ) {
9416 // Allow the stack to clear so the value will be updated
9417 setTimeout( function () {
9418 widget
.setValue( widget
.$input
.prop( 'checked' ) );
9424 * Input widget with a text field.
9427 * @extends OO.ui.InputWidget
9428 * @mixins OO.ui.IconElement
9429 * @mixins OO.ui.IndicatorElement
9430 * @mixins OO.ui.PendingElement
9433 * @param {Object} [config] Configuration options
9434 * @cfg {string} [type='text'] HTML tag `type` attribute
9435 * @cfg {string} [placeholder] Placeholder text
9436 * @cfg {boolean} [readOnly=false] Prevent changes
9437 * @cfg {boolean} [multiline=false] Allow multiple lines of text
9438 * @cfg {boolean} [autosize=false] Automatically resize to fit content
9439 * @cfg {boolean} [maxRows=10] Maximum number of rows to make visible when autosizing
9440 * @cfg {RegExp|string} [validate] Regular expression (or symbolic name referencing
9441 * one, see #static-validationPatterns)
9443 OO
.ui
.TextInputWidget
= function OoUiTextInputWidget( config
) {
9444 // Configuration initialization
9445 config
= $.extend( { readOnly
: false }, config
);
9447 // Parent constructor
9448 OO
.ui
.TextInputWidget
.super.call( this, config
);
9450 // Mixin constructors
9451 OO
.ui
.IconElement
.call( this, config
);
9452 OO
.ui
.IndicatorElement
.call( this, config
);
9453 OO
.ui
.PendingElement
.call( this, config
);
9456 this.readOnly
= false;
9457 this.multiline
= !!config
.multiline
;
9458 this.autosize
= !!config
.autosize
;
9459 this.maxRows
= config
.maxRows
!== undefined ? config
.maxRows
: 10;
9460 this.validate
= null;
9462 this.setValidation( config
.validate
);
9466 keypress
: this.onKeyPress
.bind( this ),
9467 blur
: this.setValidityFlag
.bind( this )
9469 this.$element
.on( 'DOMNodeInsertedIntoDocument', this.onElementAttach
.bind( this ) );
9470 this.$icon
.on( 'mousedown', this.onIconMouseDown
.bind( this ) );
9471 this.$indicator
.on( 'mousedown', this.onIndicatorMouseDown
.bind( this ) );
9475 .addClass( 'oo-ui-textInputWidget' )
9476 .append( this.$icon
, this.$indicator
);
9477 this.setReadOnly( config
.readOnly
);
9478 if ( config
.placeholder
) {
9479 this.$input
.attr( 'placeholder', config
.placeholder
);
9481 this.$element
.attr( 'role', 'textbox' );
9486 OO
.inheritClass( OO
.ui
.TextInputWidget
, OO
.ui
.InputWidget
);
9487 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.IconElement
);
9488 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.IndicatorElement
);
9489 OO
.mixinClass( OO
.ui
.TextInputWidget
, OO
.ui
.PendingElement
);
9491 /* Static properties */
9493 OO
.ui
.TextInputWidget
.static.validationPatterns
= {
9501 * User presses enter inside the text box.
9503 * Not called if input is multiline.
9509 * User clicks the icon.
9515 * User clicks the indicator.
9523 * Handle icon mouse down events.
9525 * @param {jQuery.Event} e Mouse down event
9528 OO
.ui
.TextInputWidget
.prototype.onIconMouseDown = function ( e
) {
9529 if ( e
.which
=== 1 ) {
9530 this.$input
[0].focus();
9531 this.emit( 'icon' );
9537 * Handle indicator mouse down events.
9539 * @param {jQuery.Event} e Mouse down event
9542 OO
.ui
.TextInputWidget
.prototype.onIndicatorMouseDown = function ( e
) {
9543 if ( e
.which
=== 1 ) {
9544 this.$input
[0].focus();
9545 this.emit( 'indicator' );
9551 * Handle key press events.
9553 * @param {jQuery.Event} e Key press event
9554 * @fires enter If enter key is pressed and input is not multiline
9556 OO
.ui
.TextInputWidget
.prototype.onKeyPress = function ( e
) {
9557 if ( e
.which
=== OO
.ui
.Keys
.ENTER
&& !this.multiline
) {
9558 this.emit( 'enter' );
9563 * Handle element attach events.
9565 * @param {jQuery.Event} e Element attach event
9567 OO
.ui
.TextInputWidget
.prototype.onElementAttach = function () {
9574 OO
.ui
.TextInputWidget
.prototype.onEdit = function () {
9578 return OO
.ui
.TextInputWidget
.super.prototype.onEdit
.call( this );
9584 OO
.ui
.TextInputWidget
.prototype.setValue = function ( value
) {
9586 OO
.ui
.TextInputWidget
.super.prototype.setValue
.call( this, value
);
9588 this.setValidityFlag();
9594 * Check if the widget is read-only.
9598 OO
.ui
.TextInputWidget
.prototype.isReadOnly = function () {
9599 return this.readOnly
;
9603 * Set the read-only state of the widget.
9605 * This should probably change the widgets's appearance and prevent it from being used.
9607 * @param {boolean} state Make input read-only
9610 OO
.ui
.TextInputWidget
.prototype.setReadOnly = function ( state
) {
9611 this.readOnly
= !!state
;
9612 this.$input
.prop( 'readOnly', this.readOnly
);
9617 * Automatically adjust the size of the text input.
9619 * This only affects multi-line inputs that are auto-sized.
9623 OO
.ui
.TextInputWidget
.prototype.adjustSize = function () {
9624 var $clone
, scrollHeight
, innerHeight
, outerHeight
, maxInnerHeight
, measurementError
, idealHeight
;
9626 if ( this.multiline
&& this.autosize
) {
9627 $clone
= this.$input
.clone()
9628 .val( this.$input
.val() )
9629 // Set inline height property to 0 to measure scroll height
9630 .css( { height
: 0 } )
9631 .insertAfter( this.$input
);
9632 scrollHeight
= $clone
[0].scrollHeight
;
9633 // Remove inline height property to measure natural heights
9634 $clone
.css( 'height', '' );
9635 innerHeight
= $clone
.innerHeight();
9636 outerHeight
= $clone
.outerHeight();
9637 // Measure max rows height
9638 $clone
.attr( 'rows', this.maxRows
).css( 'height', 'auto' ).val( '' );
9639 maxInnerHeight
= $clone
.innerHeight();
9640 // Difference between reported innerHeight and scrollHeight with no scrollbars present
9641 // Equals 1 on Blink-based browsers and 0 everywhere else
9642 measurementError
= maxInnerHeight
- $clone
[0].scrollHeight
;
9644 idealHeight
= Math
.min( maxInnerHeight
, scrollHeight
+ measurementError
);
9645 // Only apply inline height when expansion beyond natural height is needed
9646 if ( idealHeight
> innerHeight
) {
9647 // Use the difference between the inner and outer height as a buffer
9648 this.$input
.css( 'height', idealHeight
+ ( outerHeight
- innerHeight
) );
9650 this.$input
.css( 'height', '' );
9657 * Get input element.
9660 * @param {Object} [config] Configuration options
9661 * @return {jQuery} Input element
9663 OO
.ui
.TextInputWidget
.prototype.getInputElement = function ( config
) {
9664 // Configuration initialization
9665 config
= config
|| {};
9667 var type
= config
.type
|| 'text';
9669 return config
.multiline
? this.$( '<textarea>' ) : this.$( '<input type="' + type
+ '" />' );
9673 * Check if input supports multiple lines.
9677 OO
.ui
.TextInputWidget
.prototype.isMultiline = function () {
9678 return !!this.multiline
;
9682 * Check if input automatically adjusts its size.
9686 OO
.ui
.TextInputWidget
.prototype.isAutosizing = function () {
9687 return !!this.autosize
;
9691 * Select the contents of the input.
9695 OO
.ui
.TextInputWidget
.prototype.select = function () {
9696 this.$input
.select();
9701 * Sets the validation pattern to use.
9702 * @param {RegExp|string|null} validate Regular expression (or symbolic name referencing
9703 * one, see #static-validationPatterns)
9705 OO
.ui
.TextInputWidget
.prototype.setValidation = function ( validate
) {
9706 if ( validate
instanceof RegExp
) {
9707 this.validate
= validate
;
9709 this.validate
= this.constructor.static.validationPatterns
[validate
] || /.*/;
9714 * Sets the 'invalid' flag appropriately.
9716 OO
.ui
.TextInputWidget
.prototype.setValidityFlag = function () {
9718 this.isValid().done( function ( valid
) {
9719 widget
.setFlags( { invalid
: !valid
} );
9724 * Returns whether or not the current value is considered valid, according to the
9725 * supplied validation pattern.
9727 * @return {jQuery.Deferred}
9729 OO
.ui
.TextInputWidget
.prototype.isValid = function () {
9730 return $.Deferred().resolve( !!this.getValue().match( this.validate
) ).promise();
9734 * Text input with a menu of optional values.
9737 * @extends OO.ui.Widget
9740 * @param {Object} [config] Configuration options
9741 * @cfg {Object} [menu] Configuration options to pass to menu widget
9742 * @cfg {Object} [input] Configuration options to pass to input widget
9743 * @cfg {jQuery} [$overlay] Overlay layer; defaults to relative positioning
9745 OO
.ui
.ComboBoxWidget
= function OoUiComboBoxWidget( config
) {
9746 // Configuration initialization
9747 config
= config
|| {};
9749 // Parent constructor
9750 OO
.ui
.ComboBoxWidget
.super.call( this, config
);
9753 this.$overlay
= config
.$overlay
|| this.$element
;
9754 this.input
= new OO
.ui
.TextInputWidget( $.extend(
9755 { $: this.$, indicator
: 'down', disabled
: this.isDisabled() },
9758 this.menu
= new OO
.ui
.TextInputMenuWidget( this.input
, $.extend(
9760 $: OO
.ui
.Element
.getJQuery( this.$overlay
),
9763 disabled
: this.isDisabled()
9769 this.input
.connect( this, {
9770 change
: 'onInputChange',
9771 indicator
: 'onInputIndicator',
9772 enter
: 'onInputEnter'
9774 this.menu
.connect( this, {
9775 choose
: 'onMenuChoose',
9776 add
: 'onMenuItemsChange',
9777 remove
: 'onMenuItemsChange'
9781 this.$element
.addClass( 'oo-ui-comboBoxWidget' ).append( this.input
.$element
);
9782 this.$overlay
.append( this.menu
.$element
);
9783 this.onMenuItemsChange();
9788 OO
.inheritClass( OO
.ui
.ComboBoxWidget
, OO
.ui
.Widget
);
9793 * Handle input change events.
9795 * @param {string} value New value
9797 OO
.ui
.ComboBoxWidget
.prototype.onInputChange = function ( value
) {
9798 var match
= this.menu
.getItemFromData( value
);
9800 this.menu
.selectItem( match
);
9802 if ( !this.isDisabled() ) {
9803 this.menu
.toggle( true );
9808 * Handle input indicator events.
9810 OO
.ui
.ComboBoxWidget
.prototype.onInputIndicator = function () {
9811 if ( !this.isDisabled() ) {
9817 * Handle input enter events.
9819 OO
.ui
.ComboBoxWidget
.prototype.onInputEnter = function () {
9820 if ( !this.isDisabled() ) {
9821 this.menu
.toggle( false );
9826 * Handle menu choose events.
9828 * @param {OO.ui.OptionWidget} item Chosen item
9830 OO
.ui
.ComboBoxWidget
.prototype.onMenuChoose = function ( item
) {
9832 this.input
.setValue( item
.getData() );
9837 * Handle menu item change events.
9839 OO
.ui
.ComboBoxWidget
.prototype.onMenuItemsChange = function () {
9840 var match
= this.menu
.getItemFromData( this.input
.getValue() );
9841 this.menu
.selectItem( match
);
9842 this.$element
.toggleClass( 'oo-ui-comboBoxWidget-empty', this.menu
.isEmpty() );
9848 OO
.ui
.ComboBoxWidget
.prototype.setDisabled = function ( disabled
) {
9850 OO
.ui
.ComboBoxWidget
.super.prototype.setDisabled
.call( this, disabled
);
9853 this.input
.setDisabled( this.isDisabled() );
9856 this.menu
.setDisabled( this.isDisabled() );
9866 * @extends OO.ui.Widget
9867 * @mixins OO.ui.LabelElement
9870 * @param {Object} [config] Configuration options
9872 OO
.ui
.LabelWidget
= function OoUiLabelWidget( config
) {
9873 // Configuration initialization
9874 config
= config
|| {};
9876 // Parent constructor
9877 OO
.ui
.LabelWidget
.super.call( this, config
);
9879 // Mixin constructors
9880 OO
.ui
.LabelElement
.call( this, $.extend( {}, config
, { $label
: this.$element
} ) );
9881 OO
.ui
.TitledElement
.call( this, config
);
9884 this.input
= config
.input
;
9887 if ( this.input
instanceof OO
.ui
.InputWidget
) {
9888 this.$element
.on( 'click', this.onClick
.bind( this ) );
9892 this.$element
.addClass( 'oo-ui-labelWidget' );
9897 OO
.inheritClass( OO
.ui
.LabelWidget
, OO
.ui
.Widget
);
9898 OO
.mixinClass( OO
.ui
.LabelWidget
, OO
.ui
.LabelElement
);
9899 OO
.mixinClass( OO
.ui
.LabelWidget
, OO
.ui
.TitledElement
);
9901 /* Static Properties */
9903 OO
.ui
.LabelWidget
.static.tagName
= 'span';
9908 * Handles label mouse click events.
9910 * @param {jQuery.Event} e Mouse click event
9912 OO
.ui
.LabelWidget
.prototype.onClick = function () {
9913 this.input
.simulateLabelClick();
9918 * Generic option widget for use with OO.ui.SelectWidget.
9921 * @extends OO.ui.Widget
9922 * @mixins OO.ui.LabelElement
9923 * @mixins OO.ui.FlaggedElement
9926 * @param {Mixed} data Option data
9927 * @param {Object} [config] Configuration options
9929 OO
.ui
.OptionWidget
= function OoUiOptionWidget( data
, config
) {
9930 // Configuration initialization
9931 config
= config
|| {};
9933 // Parent constructor
9934 OO
.ui
.OptionWidget
.super.call( this, config
);
9936 // Mixin constructors
9937 OO
.ui
.ItemWidget
.call( this );
9938 OO
.ui
.LabelElement
.call( this, config
);
9939 OO
.ui
.FlaggedElement
.call( this, config
);
9943 this.selected
= false;
9944 this.highlighted
= false;
9945 this.pressed
= false;
9949 .data( 'oo-ui-optionWidget', this )
9950 .attr( 'role', 'option' )
9951 .addClass( 'oo-ui-optionWidget' )
9952 .append( this.$label
);
9957 OO
.inheritClass( OO
.ui
.OptionWidget
, OO
.ui
.Widget
);
9958 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.ItemWidget
);
9959 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.LabelElement
);
9960 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.FlaggedElement
);
9962 /* Static Properties */
9964 OO
.ui
.OptionWidget
.static.selectable
= true;
9966 OO
.ui
.OptionWidget
.static.highlightable
= true;
9968 OO
.ui
.OptionWidget
.static.pressable
= true;
9970 OO
.ui
.OptionWidget
.static.scrollIntoViewOnSelect
= false;
9975 * Check if option can be selected.
9977 * @return {boolean} Item is selectable
9979 OO
.ui
.OptionWidget
.prototype.isSelectable = function () {
9980 return this.constructor.static.selectable
&& !this.isDisabled();
9984 * Check if option can be highlighted.
9986 * @return {boolean} Item is highlightable
9988 OO
.ui
.OptionWidget
.prototype.isHighlightable = function () {
9989 return this.constructor.static.highlightable
&& !this.isDisabled();
9993 * Check if option can be pressed.
9995 * @return {boolean} Item is pressable
9997 OO
.ui
.OptionWidget
.prototype.isPressable = function () {
9998 return this.constructor.static.pressable
&& !this.isDisabled();
10002 * Check if option is selected.
10004 * @return {boolean} Item is selected
10006 OO
.ui
.OptionWidget
.prototype.isSelected = function () {
10007 return this.selected
;
10011 * Check if option is highlighted.
10013 * @return {boolean} Item is highlighted
10015 OO
.ui
.OptionWidget
.prototype.isHighlighted = function () {
10016 return this.highlighted
;
10020 * Check if option is pressed.
10022 * @return {boolean} Item is pressed
10024 OO
.ui
.OptionWidget
.prototype.isPressed = function () {
10025 return this.pressed
;
10029 * Set selected state.
10031 * @param {boolean} [state=false] Select option
10034 OO
.ui
.OptionWidget
.prototype.setSelected = function ( state
) {
10035 if ( this.constructor.static.selectable
) {
10036 this.selected
= !!state
;
10037 this.$element
.toggleClass( 'oo-ui-optionWidget-selected', state
);
10038 if ( state
&& this.constructor.static.scrollIntoViewOnSelect
) {
10039 this.scrollElementIntoView();
10041 this.updateThemeClasses();
10047 * Set highlighted state.
10049 * @param {boolean} [state=false] Highlight option
10052 OO
.ui
.OptionWidget
.prototype.setHighlighted = function ( state
) {
10053 if ( this.constructor.static.highlightable
) {
10054 this.highlighted
= !!state
;
10055 this.$element
.toggleClass( 'oo-ui-optionWidget-highlighted', state
);
10056 this.updateThemeClasses();
10062 * Set pressed state.
10064 * @param {boolean} [state=false] Press option
10067 OO
.ui
.OptionWidget
.prototype.setPressed = function ( state
) {
10068 if ( this.constructor.static.pressable
) {
10069 this.pressed
= !!state
;
10070 this.$element
.toggleClass( 'oo-ui-optionWidget-pressed', state
);
10071 this.updateThemeClasses();
10077 * Make the option's highlight flash.
10079 * While flashing, the visual style of the pressed state is removed if present.
10081 * @return {jQuery.Promise} Promise resolved when flashing is done
10083 OO
.ui
.OptionWidget
.prototype.flash = function () {
10085 $element
= this.$element
,
10086 deferred
= $.Deferred();
10088 if ( !this.isDisabled() && this.constructor.static.pressable
) {
10089 $element
.removeClass( 'oo-ui-optionWidget-highlighted oo-ui-optionWidget-pressed' );
10090 setTimeout( function () {
10091 // Restore original classes
10093 .toggleClass( 'oo-ui-optionWidget-highlighted', widget
.highlighted
)
10094 .toggleClass( 'oo-ui-optionWidget-pressed', widget
.pressed
);
10096 setTimeout( function () {
10097 deferred
.resolve();
10103 return deferred
.promise();
10109 * @return {Mixed} Option data
10111 OO
.ui
.OptionWidget
.prototype.getData = function () {
10116 * Option widget with an option icon and indicator.
10118 * Use together with OO.ui.SelectWidget.
10121 * @extends OO.ui.OptionWidget
10122 * @mixins OO.ui.IconElement
10123 * @mixins OO.ui.IndicatorElement
10126 * @param {Mixed} data Option data
10127 * @param {Object} [config] Configuration options
10129 OO
.ui
.DecoratedOptionWidget
= function OoUiDecoratedOptionWidget( data
, config
) {
10130 // Parent constructor
10131 OO
.ui
.DecoratedOptionWidget
.super.call( this, data
, config
);
10133 // Mixin constructors
10134 OO
.ui
.IconElement
.call( this, config
);
10135 OO
.ui
.IndicatorElement
.call( this, config
);
10139 .addClass( 'oo-ui-decoratedOptionWidget' )
10140 .prepend( this.$icon
)
10141 .append( this.$indicator
);
10146 OO
.inheritClass( OO
.ui
.DecoratedOptionWidget
, OO
.ui
.OptionWidget
);
10147 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.IconElement
);
10148 OO
.mixinClass( OO
.ui
.OptionWidget
, OO
.ui
.IndicatorElement
);
10151 * Option widget that looks like a button.
10153 * Use together with OO.ui.ButtonSelectWidget.
10156 * @extends OO.ui.DecoratedOptionWidget
10157 * @mixins OO.ui.ButtonElement
10160 * @param {Mixed} data Option data
10161 * @param {Object} [config] Configuration options
10163 OO
.ui
.ButtonOptionWidget
= function OoUiButtonOptionWidget( data
, config
) {
10164 // Parent constructor
10165 OO
.ui
.ButtonOptionWidget
.super.call( this, data
, config
);
10167 // Mixin constructors
10168 OO
.ui
.ButtonElement
.call( this, config
);
10171 this.$element
.addClass( 'oo-ui-buttonOptionWidget' );
10172 this.$button
.append( this.$element
.contents() );
10173 this.$element
.append( this.$button
);
10178 OO
.inheritClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.DecoratedOptionWidget
);
10179 OO
.mixinClass( OO
.ui
.ButtonOptionWidget
, OO
.ui
.ButtonElement
);
10181 /* Static Properties */
10183 // Allow button mouse down events to pass through so they can be handled by the parent select widget
10184 OO
.ui
.ButtonOptionWidget
.static.cancelButtonMouseDownEvents
= false;
10191 OO
.ui
.ButtonOptionWidget
.prototype.setSelected = function ( state
) {
10192 OO
.ui
.ButtonOptionWidget
.super.prototype.setSelected
.call( this, state
);
10194 if ( this.constructor.static.selectable
) {
10195 this.setActive( state
);
10202 * Item of an OO.ui.MenuWidget.
10205 * @extends OO.ui.DecoratedOptionWidget
10208 * @param {Mixed} data Item data
10209 * @param {Object} [config] Configuration options
10211 OO
.ui
.MenuItemWidget
= function OoUiMenuItemWidget( data
, config
) {
10212 // Configuration initialization
10213 config
= $.extend( { icon
: 'check' }, config
);
10215 // Parent constructor
10216 OO
.ui
.MenuItemWidget
.super.call( this, data
, config
);
10220 .attr( 'role', 'menuitem' )
10221 .addClass( 'oo-ui-menuItemWidget' );
10226 OO
.inheritClass( OO
.ui
.MenuItemWidget
, OO
.ui
.DecoratedOptionWidget
);
10229 * Section to group one or more items in a OO.ui.MenuWidget.
10232 * @extends OO.ui.DecoratedOptionWidget
10235 * @param {Mixed} data Item data
10236 * @param {Object} [config] Configuration options
10238 OO
.ui
.MenuSectionItemWidget
= function OoUiMenuSectionItemWidget( data
, config
) {
10239 // Parent constructor
10240 OO
.ui
.MenuSectionItemWidget
.super.call( this, data
, config
);
10243 this.$element
.addClass( 'oo-ui-menuSectionItemWidget' );
10248 OO
.inheritClass( OO
.ui
.MenuSectionItemWidget
, OO
.ui
.DecoratedOptionWidget
);
10250 /* Static Properties */
10252 OO
.ui
.MenuSectionItemWidget
.static.selectable
= false;
10254 OO
.ui
.MenuSectionItemWidget
.static.highlightable
= false;
10257 * Items for an OO.ui.OutlineWidget.
10260 * @extends OO.ui.DecoratedOptionWidget
10263 * @param {Mixed} data Item data
10264 * @param {Object} [config] Configuration options
10265 * @cfg {number} [level] Indentation level
10266 * @cfg {boolean} [movable] Allow modification from outline controls
10268 OO
.ui
.OutlineItemWidget
= function OoUiOutlineItemWidget( data
, config
) {
10269 // Configuration initialization
10270 config
= config
|| {};
10272 // Parent constructor
10273 OO
.ui
.OutlineItemWidget
.super.call( this, data
, config
);
10277 this.movable
= !!config
.movable
;
10278 this.removable
= !!config
.removable
;
10281 this.$element
.addClass( 'oo-ui-outlineItemWidget' );
10282 this.setLevel( config
.level
);
10287 OO
.inheritClass( OO
.ui
.OutlineItemWidget
, OO
.ui
.DecoratedOptionWidget
);
10289 /* Static Properties */
10291 OO
.ui
.OutlineItemWidget
.static.highlightable
= false;
10293 OO
.ui
.OutlineItemWidget
.static.scrollIntoViewOnSelect
= true;
10295 OO
.ui
.OutlineItemWidget
.static.levelClass
= 'oo-ui-outlineItemWidget-level-';
10297 OO
.ui
.OutlineItemWidget
.static.levels
= 3;
10302 * Check if item is movable.
10304 * Movablilty is used by outline controls.
10306 * @return {boolean} Item is movable
10308 OO
.ui
.OutlineItemWidget
.prototype.isMovable = function () {
10309 return this.movable
;
10313 * Check if item is removable.
10315 * Removablilty is used by outline controls.
10317 * @return {boolean} Item is removable
10319 OO
.ui
.OutlineItemWidget
.prototype.isRemovable = function () {
10320 return this.removable
;
10324 * Get indentation level.
10326 * @return {number} Indentation level
10328 OO
.ui
.OutlineItemWidget
.prototype.getLevel = function () {
10335 * Movablilty is used by outline controls.
10337 * @param {boolean} movable Item is movable
10340 OO
.ui
.OutlineItemWidget
.prototype.setMovable = function ( movable
) {
10341 this.movable
= !!movable
;
10342 this.updateThemeClasses();
10347 * Set removability.
10349 * Removablilty is used by outline controls.
10351 * @param {boolean} movable Item is removable
10354 OO
.ui
.OutlineItemWidget
.prototype.setRemovable = function ( removable
) {
10355 this.removable
= !!removable
;
10356 this.updateThemeClasses();
10361 * Set indentation level.
10363 * @param {number} [level=0] Indentation level, in the range of [0,#maxLevel]
10366 OO
.ui
.OutlineItemWidget
.prototype.setLevel = function ( level
) {
10367 var levels
= this.constructor.static.levels
,
10368 levelClass
= this.constructor.static.levelClass
,
10371 this.level
= level
? Math
.max( 0, Math
.min( levels
- 1, level
) ) : 0;
10373 if ( this.level
=== i
) {
10374 this.$element
.addClass( levelClass
+ i
);
10376 this.$element
.removeClass( levelClass
+ i
);
10379 this.updateThemeClasses();
10385 * Container for content that is overlaid and positioned absolutely.
10388 * @extends OO.ui.Widget
10389 * @mixins OO.ui.LabelElement
10392 * @param {Object} [config] Configuration options
10393 * @cfg {number} [width=320] Width of popup in pixels
10394 * @cfg {number} [height] Height of popup, omit to use automatic height
10395 * @cfg {boolean} [anchor=true] Show anchor pointing to origin of popup
10396 * @cfg {string} [align='center'] Alignment of popup to origin
10397 * @cfg {jQuery} [$container] Container to prevent popup from rendering outside of
10398 * @cfg {number} [containerPadding=10] How much padding to keep between popup and container
10399 * @cfg {jQuery} [$content] Content to append to the popup's body
10400 * @cfg {boolean} [autoClose=false] Popup auto-closes when it loses focus
10401 * @cfg {jQuery} [$autoCloseIgnore] Elements to not auto close when clicked
10402 * @cfg {boolean} [head] Show label and close button at the top
10403 * @cfg {boolean} [padded] Add padding to the body
10405 OO
.ui
.PopupWidget
= function OoUiPopupWidget( config
) {
10406 // Configuration initialization
10407 config
= config
|| {};
10409 // Parent constructor
10410 OO
.ui
.PopupWidget
.super.call( this, config
);
10412 // Mixin constructors
10413 OO
.ui
.LabelElement
.call( this, config
);
10414 OO
.ui
.ClippableElement
.call( this, config
);
10417 this.visible
= false;
10418 this.$popup
= this.$( '<div>' );
10419 this.$head
= this.$( '<div>' );
10420 this.$body
= this.$( '<div>' );
10421 this.$anchor
= this.$( '<div>' );
10422 // If undefined, will be computed lazily in updateDimensions()
10423 this.$container
= config
.$container
;
10424 this.containerPadding
= config
.containerPadding
!== undefined ? config
.containerPadding
: 10;
10425 this.autoClose
= !!config
.autoClose
;
10426 this.$autoCloseIgnore
= config
.$autoCloseIgnore
;
10427 this.transitionTimeout
= null;
10428 this.anchor
= null;
10429 this.width
= config
.width
!== undefined ? config
.width
: 320;
10430 this.height
= config
.height
!== undefined ? config
.height
: null;
10431 this.align
= config
.align
|| 'center';
10432 this.closeButton
= new OO
.ui
.ButtonWidget( { $: this.$, framed
: false, icon
: 'close' } );
10433 this.onMouseDownHandler
= this.onMouseDown
.bind( this );
10436 this.closeButton
.connect( this, { click
: 'onCloseButtonClick' } );
10439 this.toggleAnchor( config
.anchor
=== undefined || config
.anchor
);
10440 this.$body
.addClass( 'oo-ui-popupWidget-body' );
10441 this.$anchor
.addClass( 'oo-ui-popupWidget-anchor' );
10443 .addClass( 'oo-ui-popupWidget-head' )
10444 .append( this.$label
, this.closeButton
.$element
);
10445 if ( !config
.head
) {
10449 .addClass( 'oo-ui-popupWidget-popup' )
10450 .append( this.$head
, this.$body
);
10453 .addClass( 'oo-ui-popupWidget' )
10454 .append( this.$popup
, this.$anchor
);
10455 // Move content, which was added to #$element by OO.ui.Widget, to the body
10456 if ( config
.$content
instanceof jQuery
) {
10457 this.$body
.append( config
.$content
);
10459 if ( config
.padded
) {
10460 this.$body
.addClass( 'oo-ui-popupWidget-body-padded' );
10462 this.setClippableElement( this.$body
);
10467 OO
.inheritClass( OO
.ui
.PopupWidget
, OO
.ui
.Widget
);
10468 OO
.mixinClass( OO
.ui
.PopupWidget
, OO
.ui
.LabelElement
);
10469 OO
.mixinClass( OO
.ui
.PopupWidget
, OO
.ui
.ClippableElement
);
10474 * Handles mouse down events.
10476 * @param {jQuery.Event} e Mouse down event
10478 OO
.ui
.PopupWidget
.prototype.onMouseDown = function ( e
) {
10480 this.isVisible() &&
10481 !$.contains( this.$element
[0], e
.target
) &&
10482 ( !this.$autoCloseIgnore
|| !this.$autoCloseIgnore
.has( e
.target
).length
)
10484 this.toggle( false );
10489 * Bind mouse down listener.
10491 OO
.ui
.PopupWidget
.prototype.bindMouseDownListener = function () {
10492 // Capture clicks outside popup
10493 this.getElementWindow().addEventListener( 'mousedown', this.onMouseDownHandler
, true );
10497 * Handles close button click events.
10499 OO
.ui
.PopupWidget
.prototype.onCloseButtonClick = function () {
10500 if ( this.isVisible() ) {
10501 this.toggle( false );
10506 * Unbind mouse down listener.
10508 OO
.ui
.PopupWidget
.prototype.unbindMouseDownListener = function () {
10509 this.getElementWindow().removeEventListener( 'mousedown', this.onMouseDownHandler
, true );
10513 * Set whether to show a anchor.
10515 * @param {boolean} [show] Show anchor, omit to toggle
10517 OO
.ui
.PopupWidget
.prototype.toggleAnchor = function ( show
) {
10518 show
= show
=== undefined ? !this.anchored
: !!show
;
10520 if ( this.anchored
!== show
) {
10522 this.$element
.addClass( 'oo-ui-popupWidget-anchored' );
10524 this.$element
.removeClass( 'oo-ui-popupWidget-anchored' );
10526 this.anchored
= show
;
10531 * Check if showing a anchor.
10533 * @return {boolean} anchor is visible
10535 OO
.ui
.PopupWidget
.prototype.hasAnchor = function () {
10536 return this.anchor
;
10542 OO
.ui
.PopupWidget
.prototype.toggle = function ( show
) {
10543 show
= show
=== undefined ? !this.isVisible() : !!show
;
10545 var change
= show
!== this.isVisible();
10548 OO
.ui
.PopupWidget
.super.prototype.toggle
.call( this, show
);
10552 if ( this.autoClose
) {
10553 this.bindMouseDownListener();
10555 this.updateDimensions();
10556 this.toggleClipping( true );
10558 this.toggleClipping( false );
10559 if ( this.autoClose
) {
10560 this.unbindMouseDownListener();
10569 * Set the size of the popup.
10571 * Changing the size may also change the popup's position depending on the alignment.
10573 * @param {number} width Width
10574 * @param {number} height Height
10575 * @param {boolean} [transition=false] Use a smooth transition
10578 OO
.ui
.PopupWidget
.prototype.setSize = function ( width
, height
, transition
) {
10579 this.width
= width
;
10580 this.height
= height
!== undefined ? height
: null;
10581 if ( this.isVisible() ) {
10582 this.updateDimensions( transition
);
10587 * Update the size and position.
10589 * Only use this to keep the popup properly anchored. Use #setSize to change the size, and this will
10590 * be called automatically.
10592 * @param {boolean} [transition=false] Use a smooth transition
10595 OO
.ui
.PopupWidget
.prototype.updateDimensions = function ( transition
) {
10596 var popupOffset
, originOffset
, containerLeft
, containerWidth
, containerRight
,
10597 popupLeft
, popupRight
, overlapLeft
, overlapRight
, anchorWidth
,
10600 if ( !this.$container
) {
10601 // Lazy-initialize $container if not specified in constructor
10602 this.$container
= this.$( this.getClosestScrollableElementContainer() );
10605 // Set height and width before measuring things, since it might cause our measurements
10606 // to change (e.g. due to scrollbars appearing or disappearing)
10609 height
: this.height
!== null ? this.height
: 'auto'
10612 // Compute initial popupOffset based on alignment
10613 popupOffset
= this.width
* ( { left
: 0, center
: -0.5, right
: -1 } )[this.align
];
10615 // Figure out if this will cause the popup to go beyond the edge of the container
10616 originOffset
= Math
.round( this.$element
.offset().left
);
10617 containerLeft
= Math
.round( this.$container
.offset().left
);
10618 containerWidth
= this.$container
.innerWidth();
10619 containerRight
= containerLeft
+ containerWidth
;
10620 popupLeft
= popupOffset
- this.containerPadding
;
10621 popupRight
= popupOffset
+ this.containerPadding
+ this.width
+ this.containerPadding
;
10622 overlapLeft
= ( originOffset
+ popupLeft
) - containerLeft
;
10623 overlapRight
= containerRight
- ( originOffset
+ popupRight
);
10625 // Adjust offset to make the popup not go beyond the edge, if needed
10626 if ( overlapRight
< 0 ) {
10627 popupOffset
+= overlapRight
;
10628 } else if ( overlapLeft
< 0 ) {
10629 popupOffset
-= overlapLeft
;
10632 // Adjust offset to avoid anchor being rendered too close to the edge
10633 // $anchor.width() doesn't work with the pure CSS anchor (returns 0)
10634 // TODO: Find a measurement that works for CSS anchors and image anchors
10635 anchorWidth
= this.$anchor
[0].scrollWidth
* 2;
10636 if ( popupOffset
+ this.width
< anchorWidth
) {
10637 popupOffset
= anchorWidth
- this.width
;
10638 } else if ( -popupOffset
< anchorWidth
) {
10639 popupOffset
= -anchorWidth
;
10642 // Prevent transition from being interrupted
10643 clearTimeout( this.transitionTimeout
);
10644 if ( transition
) {
10645 // Enable transition
10646 this.$element
.addClass( 'oo-ui-popupWidget-transitioning' );
10649 // Position body relative to anchor
10650 this.$popup
.css( 'margin-left', popupOffset
);
10652 if ( transition
) {
10653 // Prevent transitioning after transition is complete
10654 this.transitionTimeout
= setTimeout( function () {
10655 widget
.$element
.removeClass( 'oo-ui-popupWidget-transitioning' );
10658 // Prevent transitioning immediately
10659 this.$element
.removeClass( 'oo-ui-popupWidget-transitioning' );
10662 // Reevaluate clipping state since we've relocated and resized the popup
10669 * Progress bar widget.
10672 * @extends OO.ui.Widget
10675 * @param {Object} [config] Configuration options
10676 * @cfg {number} [progress=0] Initial progress
10678 OO
.ui
.ProgressBarWidget
= function OoUiProgressBarWidget( config
) {
10679 // Configuration initialization
10680 config
= config
|| {};
10682 // Parent constructor
10683 OO
.ui
.ProgressBarWidget
.super.call( this, config
);
10686 this.$bar
= this.$( '<div>' );
10687 this.progress
= null;
10690 this.setProgress( config
.progress
|| 0 );
10691 this.$bar
.addClass( 'oo-ui-progressBarWidget-bar');
10694 role
: 'progressbar',
10695 'aria-valuemin': 0,
10696 'aria-valuemax': 100
10698 .addClass( 'oo-ui-progressBarWidget' )
10699 .append( this.$bar
);
10704 OO
.inheritClass( OO
.ui
.ProgressBarWidget
, OO
.ui
.Widget
);
10706 /* Static Properties */
10708 OO
.ui
.ProgressBarWidget
.static.tagName
= 'div';
10713 * Get progress percent
10715 * @return {number} Progress percent
10717 OO
.ui
.ProgressBarWidget
.prototype.getProgress = function () {
10718 return this.progress
;
10722 * Set progress percent
10724 * @param {number} progress Progress percent
10726 OO
.ui
.ProgressBarWidget
.prototype.setProgress = function ( progress
) {
10727 this.progress
= progress
;
10729 this.$bar
.css( 'width', this.progress
+ '%' );
10730 this.$element
.attr( 'aria-valuenow', this.progress
);
10736 * Search widgets combine a query input, placed above, and a results selection widget, placed below.
10737 * Results are cleared and populated each time the query is changed.
10740 * @extends OO.ui.Widget
10743 * @param {Object} [config] Configuration options
10744 * @cfg {string|jQuery} [placeholder] Placeholder text for query input
10745 * @cfg {string} [value] Initial query value
10747 OO
.ui
.SearchWidget
= function OoUiSearchWidget( config
) {
10748 // Configuration intialization
10749 config
= config
|| {};
10751 // Parent constructor
10752 OO
.ui
.SearchWidget
.super.call( this, config
);
10755 this.query
= new OO
.ui
.TextInputWidget( {
10758 placeholder
: config
.placeholder
,
10759 value
: config
.value
10761 this.results
= new OO
.ui
.SelectWidget( { $: this.$ } );
10762 this.$query
= this.$( '<div>' );
10763 this.$results
= this.$( '<div>' );
10766 this.query
.connect( this, {
10767 change
: 'onQueryChange',
10768 enter
: 'onQueryEnter'
10770 this.results
.connect( this, {
10771 highlight
: 'onResultsHighlight',
10772 select
: 'onResultsSelect'
10774 this.query
.$input
.on( 'keydown', this.onQueryKeydown
.bind( this ) );
10778 .addClass( 'oo-ui-searchWidget-query' )
10779 .append( this.query
.$element
);
10781 .addClass( 'oo-ui-searchWidget-results' )
10782 .append( this.results
.$element
);
10784 .addClass( 'oo-ui-searchWidget' )
10785 .append( this.$results
, this.$query
);
10790 OO
.inheritClass( OO
.ui
.SearchWidget
, OO
.ui
.Widget
);
10796 * @param {Object|null} item Item data or null if no item is highlighted
10801 * @param {Object|null} item Item data or null if no item is selected
10807 * Handle query key down events.
10809 * @param {jQuery.Event} e Key down event
10811 OO
.ui
.SearchWidget
.prototype.onQueryKeydown = function ( e
) {
10812 var highlightedItem
, nextItem
,
10813 dir
= e
.which
=== OO
.ui
.Keys
.DOWN
? 1 : ( e
.which
=== OO
.ui
.Keys
.UP
? -1 : 0 );
10816 highlightedItem
= this.results
.getHighlightedItem();
10817 if ( !highlightedItem
) {
10818 highlightedItem
= this.results
.getSelectedItem();
10820 nextItem
= this.results
.getRelativeSelectableItem( highlightedItem
, dir
);
10821 this.results
.highlightItem( nextItem
);
10822 nextItem
.scrollElementIntoView();
10827 * Handle select widget select events.
10829 * Clears existing results. Subclasses should repopulate items according to new query.
10831 * @param {string} value New value
10833 OO
.ui
.SearchWidget
.prototype.onQueryChange = function () {
10835 this.results
.clearItems();
10839 * Handle select widget enter key events.
10841 * Selects highlighted item.
10843 * @param {string} value New value
10845 OO
.ui
.SearchWidget
.prototype.onQueryEnter = function () {
10847 this.results
.selectItem( this.results
.getHighlightedItem() );
10851 * Handle select widget highlight events.
10853 * @param {OO.ui.OptionWidget} item Highlighted item
10856 OO
.ui
.SearchWidget
.prototype.onResultsHighlight = function ( item
) {
10857 this.emit( 'highlight', item
? item
.getData() : null );
10861 * Handle select widget select events.
10863 * @param {OO.ui.OptionWidget} item Selected item
10866 OO
.ui
.SearchWidget
.prototype.onResultsSelect = function ( item
) {
10867 this.emit( 'select', item
? item
.getData() : null );
10871 * Get the query input.
10873 * @return {OO.ui.TextInputWidget} Query input
10875 OO
.ui
.SearchWidget
.prototype.getQuery = function () {
10880 * Get the results list.
10882 * @return {OO.ui.SelectWidget} Select list
10884 OO
.ui
.SearchWidget
.prototype.getResults = function () {
10885 return this.results
;
10889 * Generic selection of options.
10891 * Items can contain any rendering, and are uniquely identified by a hash of their data. Any widget
10892 * that provides options, from which the user must choose one, should be built on this class.
10894 * Use together with OO.ui.OptionWidget.
10897 * @extends OO.ui.Widget
10898 * @mixins OO.ui.GroupElement
10901 * @param {Object} [config] Configuration options
10902 * @cfg {OO.ui.OptionWidget[]} [items] Options to add
10904 OO
.ui
.SelectWidget
= function OoUiSelectWidget( config
) {
10905 // Configuration initialization
10906 config
= config
|| {};
10908 // Parent constructor
10909 OO
.ui
.SelectWidget
.super.call( this, config
);
10911 // Mixin constructors
10912 OO
.ui
.GroupWidget
.call( this, $.extend( {}, config
, { $group
: this.$element
} ) );
10915 this.pressed
= false;
10916 this.selecting
= null;
10918 this.onMouseUpHandler
= this.onMouseUp
.bind( this );
10919 this.onMouseMoveHandler
= this.onMouseMove
.bind( this );
10922 this.$element
.on( {
10923 mousedown
: this.onMouseDown
.bind( this ),
10924 mouseover
: this.onMouseOver
.bind( this ),
10925 mouseleave
: this.onMouseLeave
.bind( this )
10929 this.$element
.addClass( 'oo-ui-selectWidget oo-ui-selectWidget-depressed' );
10930 if ( $.isArray( config
.items
) ) {
10931 this.addItems( config
.items
);
10937 OO
.inheritClass( OO
.ui
.SelectWidget
, OO
.ui
.Widget
);
10939 // Need to mixin base class as well
10940 OO
.mixinClass( OO
.ui
.SelectWidget
, OO
.ui
.GroupElement
);
10941 OO
.mixinClass( OO
.ui
.SelectWidget
, OO
.ui
.GroupWidget
);
10947 * @param {OO.ui.OptionWidget|null} item Highlighted item
10952 * @param {OO.ui.OptionWidget|null} item Pressed item
10957 * @param {OO.ui.OptionWidget|null} item Selected item
10962 * @param {OO.ui.OptionWidget|null} item Chosen item
10967 * @param {OO.ui.OptionWidget[]} items Added items
10968 * @param {number} index Index items were added at
10973 * @param {OO.ui.OptionWidget[]} items Removed items
10979 * Handle mouse down events.
10982 * @param {jQuery.Event} e Mouse down event
10984 OO
.ui
.SelectWidget
.prototype.onMouseDown = function ( e
) {
10987 if ( !this.isDisabled() && e
.which
=== 1 ) {
10988 this.togglePressed( true );
10989 item
= this.getTargetItem( e
);
10990 if ( item
&& item
.isSelectable() ) {
10991 this.pressItem( item
);
10992 this.selecting
= item
;
10993 this.getElementDocument().addEventListener(
10995 this.onMouseUpHandler
,
10998 this.getElementDocument().addEventListener(
11000 this.onMouseMoveHandler
,
11009 * Handle mouse up events.
11012 * @param {jQuery.Event} e Mouse up event
11014 OO
.ui
.SelectWidget
.prototype.onMouseUp = function ( e
) {
11017 this.togglePressed( false );
11018 if ( !this.selecting
) {
11019 item
= this.getTargetItem( e
);
11020 if ( item
&& item
.isSelectable() ) {
11021 this.selecting
= item
;
11024 if ( !this.isDisabled() && e
.which
=== 1 && this.selecting
) {
11025 this.pressItem( null );
11026 this.chooseItem( this.selecting
);
11027 this.selecting
= null;
11030 this.getElementDocument().removeEventListener(
11032 this.onMouseUpHandler
,
11035 this.getElementDocument().removeEventListener(
11037 this.onMouseMoveHandler
,
11045 * Handle mouse move events.
11048 * @param {jQuery.Event} e Mouse move event
11050 OO
.ui
.SelectWidget
.prototype.onMouseMove = function ( e
) {
11053 if ( !this.isDisabled() && this.pressed
) {
11054 item
= this.getTargetItem( e
);
11055 if ( item
&& item
!== this.selecting
&& item
.isSelectable() ) {
11056 this.pressItem( item
);
11057 this.selecting
= item
;
11064 * Handle mouse over events.
11067 * @param {jQuery.Event} e Mouse over event
11069 OO
.ui
.SelectWidget
.prototype.onMouseOver = function ( e
) {
11072 if ( !this.isDisabled() ) {
11073 item
= this.getTargetItem( e
);
11074 this.highlightItem( item
&& item
.isHighlightable() ? item
: null );
11080 * Handle mouse leave events.
11083 * @param {jQuery.Event} e Mouse over event
11085 OO
.ui
.SelectWidget
.prototype.onMouseLeave = function () {
11086 if ( !this.isDisabled() ) {
11087 this.highlightItem( null );
11093 * Get the closest item to a jQuery.Event.
11096 * @param {jQuery.Event} e
11097 * @return {OO.ui.OptionWidget|null} Outline item widget, `null` if none was found
11099 OO
.ui
.SelectWidget
.prototype.getTargetItem = function ( e
) {
11100 var $item
= this.$( e
.target
).closest( '.oo-ui-optionWidget' );
11101 if ( $item
.length
) {
11102 return $item
.data( 'oo-ui-optionWidget' );
11108 * Get selected item.
11110 * @return {OO.ui.OptionWidget|null} Selected item, `null` if no item is selected
11112 OO
.ui
.SelectWidget
.prototype.getSelectedItem = function () {
11115 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
11116 if ( this.items
[i
].isSelected() ) {
11117 return this.items
[i
];
11124 * Get highlighted item.
11126 * @return {OO.ui.OptionWidget|null} Highlighted item, `null` if no item is highlighted
11128 OO
.ui
.SelectWidget
.prototype.getHighlightedItem = function () {
11131 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
11132 if ( this.items
[i
].isHighlighted() ) {
11133 return this.items
[i
];
11140 * Get an existing item with equivilant data.
11142 * @param {Object} data Item data to search for
11143 * @return {OO.ui.OptionWidget|null} Item with equivilent value, `null` if none exists
11145 OO
.ui
.SelectWidget
.prototype.getItemFromData = function ( data
) {
11146 var hash
= OO
.getHash( data
);
11148 if ( Object
.prototype.hasOwnProperty
.call( this.hashes
, hash
) ) {
11149 return this.hashes
[hash
];
11156 * Toggle pressed state.
11158 * @param {boolean} pressed An option is being pressed
11160 OO
.ui
.SelectWidget
.prototype.togglePressed = function ( pressed
) {
11161 if ( pressed
=== undefined ) {
11162 pressed
= !this.pressed
;
11164 if ( pressed
!== this.pressed
) {
11166 .toggleClass( 'oo-ui-selectWidget-pressed', pressed
)
11167 .toggleClass( 'oo-ui-selectWidget-depressed', !pressed
);
11168 this.pressed
= pressed
;
11173 * Highlight an item.
11175 * Highlighting is mutually exclusive.
11177 * @param {OO.ui.OptionWidget} [item] Item to highlight, omit to deselect all
11181 OO
.ui
.SelectWidget
.prototype.highlightItem = function ( item
) {
11182 var i
, len
, highlighted
,
11185 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
11186 highlighted
= this.items
[i
] === item
;
11187 if ( this.items
[i
].isHighlighted() !== highlighted
) {
11188 this.items
[i
].setHighlighted( highlighted
);
11193 this.emit( 'highlight', item
);
11202 * @param {OO.ui.OptionWidget} [item] Item to select, omit to deselect all
11206 OO
.ui
.SelectWidget
.prototype.selectItem = function ( item
) {
11207 var i
, len
, selected
,
11210 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
11211 selected
= this.items
[i
] === item
;
11212 if ( this.items
[i
].isSelected() !== selected
) {
11213 this.items
[i
].setSelected( selected
);
11218 this.emit( 'select', item
);
11227 * @param {OO.ui.OptionWidget} [item] Item to press, omit to depress all
11231 OO
.ui
.SelectWidget
.prototype.pressItem = function ( item
) {
11232 var i
, len
, pressed
,
11235 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
11236 pressed
= this.items
[i
] === item
;
11237 if ( this.items
[i
].isPressed() !== pressed
) {
11238 this.items
[i
].setPressed( pressed
);
11243 this.emit( 'press', item
);
11252 * Identical to #selectItem, but may vary in subclasses that want to take additional action when
11253 * an item is selected using the keyboard or mouse.
11255 * @param {OO.ui.OptionWidget} item Item to choose
11259 OO
.ui
.SelectWidget
.prototype.chooseItem = function ( item
) {
11260 this.selectItem( item
);
11261 this.emit( 'choose', item
);
11267 * Get an item relative to another one.
11269 * @param {OO.ui.OptionWidget} item Item to start at
11270 * @param {number} direction Direction to move in
11271 * @return {OO.ui.OptionWidget|null} Item at position, `null` if there are no items in the menu
11273 OO
.ui
.SelectWidget
.prototype.getRelativeSelectableItem = function ( item
, direction
) {
11274 var inc
= direction
> 0 ? 1 : -1,
11275 len
= this.items
.length
,
11276 index
= item
instanceof OO
.ui
.OptionWidget
?
11277 $.inArray( item
, this.items
) : ( inc
> 0 ? -1 : 0 ),
11278 stopAt
= Math
.max( Math
.min( index
, len
- 1 ), 0 ),
11280 // Default to 0 instead of -1, if nothing is selected let's start at the beginning
11281 Math
.max( index
, -1 ) :
11282 // Default to n-1 instead of -1, if nothing is selected let's start at the end
11283 Math
.min( index
, len
);
11285 while ( len
!== 0 ) {
11286 i
= ( i
+ inc
+ len
) % len
;
11287 item
= this.items
[i
];
11288 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() ) {
11291 // Stop iterating when we've looped all the way around
11292 if ( i
=== stopAt
) {
11300 * Get the next selectable item.
11302 * @return {OO.ui.OptionWidget|null} Item, `null` if ther aren't any selectable items
11304 OO
.ui
.SelectWidget
.prototype.getFirstSelectableItem = function () {
11307 for ( i
= 0, len
= this.items
.length
; i
< len
; i
++ ) {
11308 item
= this.items
[i
];
11309 if ( item
instanceof OO
.ui
.OptionWidget
&& item
.isSelectable() ) {
11320 * When items are added with the same values as existing items, the existing items will be
11321 * automatically removed before the new items are added.
11323 * @param {OO.ui.OptionWidget[]} items Items to add
11324 * @param {number} [index] Index to insert items after
11328 OO
.ui
.SelectWidget
.prototype.addItems = function ( items
, index
) {
11329 var i
, len
, item
, hash
,
11332 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
11334 hash
= OO
.getHash( item
.getData() );
11335 if ( Object
.prototype.hasOwnProperty
.call( this.hashes
, hash
) ) {
11336 // Remove item with same value
11337 remove
.push( this.hashes
[hash
] );
11339 this.hashes
[hash
] = item
;
11341 if ( remove
.length
) {
11342 this.removeItems( remove
);
11346 OO
.ui
.GroupWidget
.prototype.addItems
.call( this, items
, index
);
11348 // Always provide an index, even if it was omitted
11349 this.emit( 'add', items
, index
=== undefined ? this.items
.length
- items
.length
- 1 : index
);
11357 * Items will be detached, not removed, so they can be used later.
11359 * @param {OO.ui.OptionWidget[]} items Items to remove
11363 OO
.ui
.SelectWidget
.prototype.removeItems = function ( items
) {
11364 var i
, len
, item
, hash
;
11366 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
11368 hash
= OO
.getHash( item
.getData() );
11369 if ( Object
.prototype.hasOwnProperty
.call( this.hashes
, hash
) ) {
11370 // Remove existing item
11371 delete this.hashes
[hash
];
11373 if ( item
.isSelected() ) {
11374 this.selectItem( null );
11379 OO
.ui
.GroupWidget
.prototype.removeItems
.call( this, items
);
11381 this.emit( 'remove', items
);
11389 * Items will be detached, not removed, so they can be used later.
11394 OO
.ui
.SelectWidget
.prototype.clearItems = function () {
11395 var items
= this.items
.slice();
11400 OO
.ui
.GroupWidget
.prototype.clearItems
.call( this );
11401 this.selectItem( null );
11403 this.emit( 'remove', items
);
11409 * Select widget containing button options.
11411 * Use together with OO.ui.ButtonOptionWidget.
11414 * @extends OO.ui.SelectWidget
11417 * @param {Object} [config] Configuration options
11419 OO
.ui
.ButtonSelectWidget
= function OoUiButtonSelectWidget( config
) {
11420 // Parent constructor
11421 OO
.ui
.ButtonSelectWidget
.super.call( this, config
);
11424 this.$element
.addClass( 'oo-ui-buttonSelectWidget' );
11429 OO
.inheritClass( OO
.ui
.ButtonSelectWidget
, OO
.ui
.SelectWidget
);
11432 * Overlaid menu of options.
11434 * Menus are clipped to the visible viewport. They do not provide a control for opening or closing
11437 * Use together with OO.ui.MenuItemWidget.
11440 * @extends OO.ui.SelectWidget
11441 * @mixins OO.ui.ClippableElement
11444 * @param {Object} [config] Configuration options
11445 * @cfg {OO.ui.InputWidget} [input] Input to bind keyboard handlers to
11446 * @cfg {OO.ui.Widget} [widget] Widget to bind mouse handlers to
11447 * @cfg {boolean} [autoHide=true] Hide the menu when the mouse is pressed outside the menu
11449 OO
.ui
.MenuWidget
= function OoUiMenuWidget( config
) {
11450 // Configuration initialization
11451 config
= config
|| {};
11453 // Parent constructor
11454 OO
.ui
.MenuWidget
.super.call( this, config
);
11456 // Mixin constructors
11457 OO
.ui
.ClippableElement
.call( this, $.extend( {}, config
, { $clippable
: this.$group
} ) );
11460 this.flashing
= false;
11461 this.visible
= false;
11462 this.newItems
= null;
11463 this.autoHide
= config
.autoHide
=== undefined || !!config
.autoHide
;
11464 this.$input
= config
.input
? config
.input
.$input
: null;
11465 this.$widget
= config
.widget
? config
.widget
.$element
: null;
11466 this.$previousFocus
= null;
11467 this.isolated
= !config
.input
;
11468 this.onKeyDownHandler
= this.onKeyDown
.bind( this );
11469 this.onDocumentMouseDownHandler
= this.onDocumentMouseDown
.bind( this );
11474 .attr( 'role', 'menu' )
11475 .addClass( 'oo-ui-menuWidget' );
11480 OO
.inheritClass( OO
.ui
.MenuWidget
, OO
.ui
.SelectWidget
);
11481 OO
.mixinClass( OO
.ui
.MenuWidget
, OO
.ui
.ClippableElement
);
11486 * Handles document mouse down events.
11488 * @param {jQuery.Event} e Key down event
11490 OO
.ui
.MenuWidget
.prototype.onDocumentMouseDown = function ( e
) {
11491 if ( !$.contains( this.$element
[0], e
.target
) && ( !this.$widget
|| !$.contains( this.$widget
[0], e
.target
) ) ) {
11492 this.toggle( false );
11497 * Handles key down events.
11499 * @param {jQuery.Event} e Key down event
11501 OO
.ui
.MenuWidget
.prototype.onKeyDown = function ( e
) {
11504 highlightItem
= this.getHighlightedItem();
11506 if ( !this.isDisabled() && this.isVisible() ) {
11507 if ( !highlightItem
) {
11508 highlightItem
= this.getSelectedItem();
11510 switch ( e
.keyCode
) {
11511 case OO
.ui
.Keys
.ENTER
:
11512 this.chooseItem( highlightItem
);
11515 case OO
.ui
.Keys
.UP
:
11516 nextItem
= this.getRelativeSelectableItem( highlightItem
, -1 );
11519 case OO
.ui
.Keys
.DOWN
:
11520 nextItem
= this.getRelativeSelectableItem( highlightItem
, 1 );
11523 case OO
.ui
.Keys
.ESCAPE
:
11524 if ( highlightItem
) {
11525 highlightItem
.setHighlighted( false );
11527 this.toggle( false );
11533 this.highlightItem( nextItem
);
11534 nextItem
.scrollElementIntoView();
11538 e
.preventDefault();
11539 e
.stopPropagation();
11546 * Bind key down listener.
11548 OO
.ui
.MenuWidget
.prototype.bindKeyDownListener = function () {
11549 if ( this.$input
) {
11550 this.$input
.on( 'keydown', this.onKeyDownHandler
);
11552 // Capture menu navigation keys
11553 this.getElementWindow().addEventListener( 'keydown', this.onKeyDownHandler
, true );
11558 * Unbind key down listener.
11560 OO
.ui
.MenuWidget
.prototype.unbindKeyDownListener = function () {
11561 if ( this.$input
) {
11562 this.$input
.off( 'keydown' );
11564 this.getElementWindow().removeEventListener( 'keydown', this.onKeyDownHandler
, true );
11571 * This will close the menu when done, unlike selectItem which only changes selection.
11573 * @param {OO.ui.OptionWidget} item Item to choose
11576 OO
.ui
.MenuWidget
.prototype.chooseItem = function ( item
) {
11580 OO
.ui
.MenuWidget
.super.prototype.chooseItem
.call( this, item
);
11582 if ( item
&& !this.flashing
) {
11583 this.flashing
= true;
11584 item
.flash().done( function () {
11585 widget
.toggle( false );
11586 widget
.flashing
= false;
11589 this.toggle( false );
11598 OO
.ui
.MenuWidget
.prototype.addItems = function ( items
, index
) {
11602 OO
.ui
.MenuWidget
.super.prototype.addItems
.call( this, items
, index
);
11605 if ( !this.newItems
) {
11606 this.newItems
= [];
11609 for ( i
= 0, len
= items
.length
; i
< len
; i
++ ) {
11611 if ( this.isVisible() ) {
11612 // Defer fitting label until item has been attached
11615 this.newItems
.push( item
);
11619 // Reevaluate clipping
11628 OO
.ui
.MenuWidget
.prototype.removeItems = function ( items
) {
11630 OO
.ui
.MenuWidget
.super.prototype.removeItems
.call( this, items
);
11632 // Reevaluate clipping
11641 OO
.ui
.MenuWidget
.prototype.clearItems = function () {
11643 OO
.ui
.MenuWidget
.super.prototype.clearItems
.call( this );
11645 // Reevaluate clipping
11654 OO
.ui
.MenuWidget
.prototype.toggle = function ( visible
) {
11655 visible
= ( visible
=== undefined ? !this.visible
: !!visible
) && !!this.items
.length
;
11658 change
= visible
!== this.isVisible(),
11659 elementDoc
= this.getElementDocument(),
11660 widgetDoc
= this.$widget
? this.$widget
[0].ownerDocument
: null;
11663 OO
.ui
.MenuWidget
.super.prototype.toggle
.call( this, visible
);
11667 this.bindKeyDownListener();
11669 // Change focus to enable keyboard navigation
11670 if ( this.isolated
&& this.$input
&& !this.$input
.is( ':focus' ) ) {
11671 this.$previousFocus
= this.$( ':focus' );
11672 this.$input
[0].focus();
11674 if ( this.newItems
&& this.newItems
.length
) {
11675 for ( i
= 0, len
= this.newItems
.length
; i
< len
; i
++ ) {
11676 this.newItems
[i
].fitLabel();
11678 this.newItems
= null;
11680 this.toggleClipping( true );
11683 if ( this.autoHide
) {
11684 elementDoc
.addEventListener(
11685 'mousedown', this.onDocumentMouseDownHandler
, true
11687 // Support $widget being in a different document
11688 if ( widgetDoc
&& widgetDoc
!== elementDoc
) {
11689 widgetDoc
.addEventListener(
11690 'mousedown', this.onDocumentMouseDownHandler
, true
11695 this.unbindKeyDownListener();
11696 if ( this.isolated
&& this.$previousFocus
) {
11697 this.$previousFocus
[0].focus();
11698 this.$previousFocus
= null;
11700 elementDoc
.removeEventListener(
11701 'mousedown', this.onDocumentMouseDownHandler
, true
11703 // Support $widget being in a different document
11704 if ( widgetDoc
&& widgetDoc
!== elementDoc
) {
11705 widgetDoc
.removeEventListener(
11706 'mousedown', this.onDocumentMouseDownHandler
, true
11709 this.toggleClipping( false );
11717 * Menu for a text input widget.
11719 * This menu is specially designed to be positioned beneath the text input widget. Even if the input
11720 * is in a different frame, the menu's position is automatically calculated and maintained when the
11721 * menu is toggled or the window is resized.
11724 * @extends OO.ui.MenuWidget
11727 * @param {OO.ui.TextInputWidget} input Text input widget to provide menu for
11728 * @param {Object} [config] Configuration options
11729 * @cfg {jQuery} [$container=input.$element] Element to render menu under
11731 OO
.ui
.TextInputMenuWidget
= function OoUiTextInputMenuWidget( input
, config
) {
11732 // Configuration intialization
11733 config
= config
|| {};
11735 // Parent constructor
11736 OO
.ui
.TextInputMenuWidget
.super.call( this, config
);
11739 this.input
= input
;
11740 this.$container
= config
.$container
|| this.input
.$element
;
11741 this.onWindowResizeHandler
= this.onWindowResize
.bind( this );
11744 this.$element
.addClass( 'oo-ui-textInputMenuWidget' );
11749 OO
.inheritClass( OO
.ui
.TextInputMenuWidget
, OO
.ui
.MenuWidget
);
11754 * Handle window resize event.
11756 * @param {jQuery.Event} e Window resize event
11758 OO
.ui
.TextInputMenuWidget
.prototype.onWindowResize = function () {
11765 OO
.ui
.TextInputMenuWidget
.prototype.toggle = function ( visible
) {
11766 visible
= visible
=== undefined ? !this.isVisible() : !!visible
;
11768 var change
= visible
!== this.isVisible();
11770 if ( change
&& visible
) {
11771 // Make sure the width is set before the parent method runs.
11772 // After this we have to call this.position(); again to actually
11773 // position ourselves correctly.
11778 OO
.ui
.TextInputMenuWidget
.super.prototype.toggle
.call( this, visible
);
11781 if ( this.isVisible() ) {
11783 this.$( this.getElementWindow() ).on( 'resize', this.onWindowResizeHandler
);
11785 this.$( this.getElementWindow() ).off( 'resize', this.onWindowResizeHandler
);
11793 * Position the menu.
11797 OO
.ui
.TextInputMenuWidget
.prototype.position = function () {
11798 var $container
= this.$container
,
11799 pos
= OO
.ui
.Element
.getRelativePosition( $container
, this.$element
.offsetParent() );
11801 // Position under input
11802 pos
.top
+= $container
.height();
11803 this.$element
.css( pos
);
11806 this.setIdealSize( $container
.width() );
11807 // We updated the position, so re-evaluate the clipping state
11814 * Structured list of items.
11816 * Use with OO.ui.OutlineItemWidget.
11819 * @extends OO.ui.SelectWidget
11822 * @param {Object} [config] Configuration options
11824 OO
.ui
.OutlineWidget
= function OoUiOutlineWidget( config
) {
11825 // Configuration initialization
11826 config
= config
|| {};
11828 // Parent constructor
11829 OO
.ui
.OutlineWidget
.super.call( this, config
);
11832 this.$element
.addClass( 'oo-ui-outlineWidget' );
11837 OO
.inheritClass( OO
.ui
.OutlineWidget
, OO
.ui
.SelectWidget
);
11840 * Switch that slides on and off.
11843 * @extends OO.ui.Widget
11844 * @mixins OO.ui.ToggleWidget
11847 * @param {Object} [config] Configuration options
11848 * @cfg {boolean} [value=false] Initial value
11850 OO
.ui
.ToggleSwitchWidget
= function OoUiToggleSwitchWidget( config
) {
11851 // Parent constructor
11852 OO
.ui
.ToggleSwitchWidget
.super.call( this, config
);
11854 // Mixin constructors
11855 OO
.ui
.ToggleWidget
.call( this, config
);
11858 this.dragging
= false;
11859 this.dragStart
= null;
11860 this.sliding
= false;
11861 this.$glow
= this.$( '<span>' );
11862 this.$grip
= this.$( '<span>' );
11865 this.$element
.on( 'click', this.onClick
.bind( this ) );
11868 this.$glow
.addClass( 'oo-ui-toggleSwitchWidget-glow' );
11869 this.$grip
.addClass( 'oo-ui-toggleSwitchWidget-grip' );
11871 .addClass( 'oo-ui-toggleSwitchWidget' )
11872 .append( this.$glow
, this.$grip
);
11877 OO
.inheritClass( OO
.ui
.ToggleSwitchWidget
, OO
.ui
.Widget
);
11878 OO
.mixinClass( OO
.ui
.ToggleSwitchWidget
, OO
.ui
.ToggleWidget
);
11883 * Handle mouse down events.
11885 * @param {jQuery.Event} e Mouse down event
11887 OO
.ui
.ToggleSwitchWidget
.prototype.onClick = function ( e
) {
11888 if ( !this.isDisabled() && e
.which
=== 1 ) {
11889 this.setValue( !this.value
);