2013-02-14 02:04:04 +00:00
|
|
|
/*!
|
2013-10-09 20:09:59 +00:00
|
|
|
* ObjectOriented UserInterface ButtonWidget class.
|
2013-02-14 02:04:04 +00:00
|
|
|
*
|
2013-10-09 20:09:59 +00:00
|
|
|
* @copyright 2011-2013 OOJS Team and others; see AUTHORS.txt
|
2013-02-14 02:04:04 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-10-09 20:09:59 +00:00
|
|
|
* Creates an OO.ui.ButtonWidget object.
|
2013-02-14 02:04:04 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-10-02 00:00:57 +00:00
|
|
|
* @abstract
|
2013-10-09 20:09:59 +00:00
|
|
|
* @extends OO.ui.Widget
|
|
|
|
* @mixins OO.ui.FlaggableElement
|
|
|
|
* @mixins OO.ui.LabeledElement
|
Major UI refactoring and improvements
Objective:
Refactor UI widgets, improve usability and accessibility of menus, general cleanup and style improvements.
Extras:
Fixed documentation in a few other files to make descriptions of jQuery event arguments more consistent, classes inherit correctly, and made use of the @cfg functionality in jsduck.
Changes:
.docs/config.json
* Added window, HTMLDocument, HTMLElement, DocumentFragment and XMLHttpRequest to externals, so jsduck doesn't throw warnings when they are used
demos/ve/index.php, modules/ve/test/index.php, VisualEditor.php
* Moved widgets above tools (since tools use widgets)
demos/ve/index.php
* Refactored widget initialization to use options
* Renamed variables to match widget names
ve.init.mw.ViewPageTarget.css
* Adjusted text sizes to make widgets work normally
* Added margins for buttons in toolbar (since button widgets
don't have any)
* Removed styles for init buttons (button widgets now)
ve.init.mw.ViewPageTarget.js
* Switched to using button widgets (involved moving things around
a bit)
ve.ui.LinkInspector.js, ve.ui.MWLinkInspector.js
* Renamed static property "inputWidget" to
"linkTargetInputWidget" to better reflect the required base class
for the properties value
icons.ai, check.png, check.svg
* Added "check" icon, used in menu right now to show which item
is selected
ve.ui.Icons-raster.css, ve.ui.Icons-vector.css
* Added check icon
* Removed :before pseudo selectors from most of the icon classes (not need by button tool anymore, makes them more reusable now)
ve.ui.Tool.css
* Adjusted drop down tool styles so menu appears below, instead
of on top, of the label
* Adjusted paragraph font size to better match actual content
* Updated class names to still work with menu widget changes
(items are their own widgets now)
* Updated selectors as per changes in the structure of button tools
ve.ui.Widget.css
* Added styles for buttons and menu items
* Adjusted menu styles
ve.ui.*ButtonTool.js
* Added config options argument passthrough
ve.ui.ButtonTool.js
* Moved var statement to the top inside constructor
* Switched to using "a" tag to get cross-browser :active support
* Added icon to inside of button to make icon styles more reusable
* Removed disabled support (now provided by widget parent class)
ve.ui.FormatDropDownTool.js
* Updated options initialization to construct menu item objects
* Modified handling of items to account for changes in menu and
item classes
* Optimized onUpdateState method a bit, adding early exit to
inner loop
ve.ui.ButtonTool.js, ve.ui.DropdownTool.js, ve.ui.Context.js,
ve.ui.Frame, ve.ui.Tool.js, ve.ui.Widget.js
* Added chain ability to non-getter methods
ve.ui.DropdownTool.js
* Removed items argument to constructor
* Updated code as per changes in menu class
* Fixed inconsistent naming of event handler methods
* Removed item event handling (now handled by items directly)
* Made use of this.$$ to ensure tool works in other frames
ve.ui.Tool.js
* Made tools inherit from widget
* Moved trigger registry event handler to a method
ve.ui.Context.js
* Switched from using menu to contain toolbar to a simple wrapper
ve.ui.js
* Added get$$ method, a convenience function for binding jQuery
to a specific document context
ve.ui.*Widget.js
* Switched to using a config options object instead of individual arguments
* Added options
* Factored out flags and labels into their own classes
* Refactored value setting methods for inputs
ve.ui.MenuWidget.js, ve.ui.MenuItemWidget.js
* Broke items out into their own classes
* Redesigned API
* Updated code that uses these classes
* Added support for keyboard interaction
* Made items flash when selected (delaying the hiding of the menu for 200ms)
ve.ui.LinkTargetInputWidget.js, ve.ui.MWLinkTargetInputWidget
* Refactored annotation setting methods
Change-Id: I7769bd5a5b79f1ab36f258ef9f2be583ca503ce6
2013-02-20 23:25:12 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-07-24 13:45:42 +00:00
|
|
|
* @cfg {number} [tabIndex] Button's tab index
|
2013-10-02 00:00:57 +00:00
|
|
|
* @cfg {string} [title=''] Title text
|
|
|
|
* @cfg {string} [href] Hyperlink to visit when clicked
|
|
|
|
* @cfg {string} [target] Target to open hyperlink in
|
2013-02-14 02:04:04 +00:00
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.ButtonWidget = function OoUiButtonWidget( config ) {
|
2013-10-02 00:00:57 +00:00
|
|
|
// Configuration initialization
|
2013-10-09 20:09:59 +00:00
|
|
|
config = OO.ui.extendObject( { 'target': '_blank' }, config );
|
2013-10-02 00:00:57 +00:00
|
|
|
|
2013-02-14 02:04:04 +00:00
|
|
|
// Parent constructor
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.Widget.call( this, config );
|
2013-02-14 02:04:04 +00:00
|
|
|
|
Major UI refactoring and improvements
Objective:
Refactor UI widgets, improve usability and accessibility of menus, general cleanup and style improvements.
Extras:
Fixed documentation in a few other files to make descriptions of jQuery event arguments more consistent, classes inherit correctly, and made use of the @cfg functionality in jsduck.
Changes:
.docs/config.json
* Added window, HTMLDocument, HTMLElement, DocumentFragment and XMLHttpRequest to externals, so jsduck doesn't throw warnings when they are used
demos/ve/index.php, modules/ve/test/index.php, VisualEditor.php
* Moved widgets above tools (since tools use widgets)
demos/ve/index.php
* Refactored widget initialization to use options
* Renamed variables to match widget names
ve.init.mw.ViewPageTarget.css
* Adjusted text sizes to make widgets work normally
* Added margins for buttons in toolbar (since button widgets
don't have any)
* Removed styles for init buttons (button widgets now)
ve.init.mw.ViewPageTarget.js
* Switched to using button widgets (involved moving things around
a bit)
ve.ui.LinkInspector.js, ve.ui.MWLinkInspector.js
* Renamed static property "inputWidget" to
"linkTargetInputWidget" to better reflect the required base class
for the properties value
icons.ai, check.png, check.svg
* Added "check" icon, used in menu right now to show which item
is selected
ve.ui.Icons-raster.css, ve.ui.Icons-vector.css
* Added check icon
* Removed :before pseudo selectors from most of the icon classes (not need by button tool anymore, makes them more reusable now)
ve.ui.Tool.css
* Adjusted drop down tool styles so menu appears below, instead
of on top, of the label
* Adjusted paragraph font size to better match actual content
* Updated class names to still work with menu widget changes
(items are their own widgets now)
* Updated selectors as per changes in the structure of button tools
ve.ui.Widget.css
* Added styles for buttons and menu items
* Adjusted menu styles
ve.ui.*ButtonTool.js
* Added config options argument passthrough
ve.ui.ButtonTool.js
* Moved var statement to the top inside constructor
* Switched to using "a" tag to get cross-browser :active support
* Added icon to inside of button to make icon styles more reusable
* Removed disabled support (now provided by widget parent class)
ve.ui.FormatDropDownTool.js
* Updated options initialization to construct menu item objects
* Modified handling of items to account for changes in menu and
item classes
* Optimized onUpdateState method a bit, adding early exit to
inner loop
ve.ui.ButtonTool.js, ve.ui.DropdownTool.js, ve.ui.Context.js,
ve.ui.Frame, ve.ui.Tool.js, ve.ui.Widget.js
* Added chain ability to non-getter methods
ve.ui.DropdownTool.js
* Removed items argument to constructor
* Updated code as per changes in menu class
* Fixed inconsistent naming of event handler methods
* Removed item event handling (now handled by items directly)
* Made use of this.$$ to ensure tool works in other frames
ve.ui.Tool.js
* Made tools inherit from widget
* Moved trigger registry event handler to a method
ve.ui.Context.js
* Switched from using menu to contain toolbar to a simple wrapper
ve.ui.js
* Added get$$ method, a convenience function for binding jQuery
to a specific document context
ve.ui.*Widget.js
* Switched to using a config options object instead of individual arguments
* Added options
* Factored out flags and labels into their own classes
* Refactored value setting methods for inputs
ve.ui.MenuWidget.js, ve.ui.MenuItemWidget.js
* Broke items out into their own classes
* Redesigned API
* Updated code that uses these classes
* Added support for keyboard interaction
* Made items flash when selected (delaying the hiding of the menu for 200ms)
ve.ui.LinkTargetInputWidget.js, ve.ui.MWLinkTargetInputWidget
* Refactored annotation setting methods
Change-Id: I7769bd5a5b79f1ab36f258ef9f2be583ca503ce6
2013-02-20 23:25:12 +00:00
|
|
|
// Mixin constructors
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.FlaggableElement.call( this, config );
|
|
|
|
OO.ui.LabeledElement.call( this, this.$$( '<span>' ), config );
|
2013-02-14 02:04:04 +00:00
|
|
|
|
2013-10-02 00:00:57 +00:00
|
|
|
// Properties
|
|
|
|
this.$button = this.$$( '<a>' );
|
|
|
|
this.isHyperlink = typeof config.href === 'string';
|
|
|
|
this.tabIndex = null;
|
|
|
|
|
2013-02-14 02:04:04 +00:00
|
|
|
// Events
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$button.on( {
|
2013-10-09 20:09:59 +00:00
|
|
|
'mousedown': OO.ui.bind( this.onMouseDown, this ),
|
|
|
|
'mouseup': OO.ui.bind( this.onMouseUp, this ),
|
|
|
|
'click': OO.ui.bind( this.onClick, this ),
|
|
|
|
'keypress': OO.ui.bind( this.onKeyPress, this )
|
2013-10-02 00:00:57 +00:00
|
|
|
} );
|
2013-02-14 02:04:04 +00:00
|
|
|
|
|
|
|
// Initialization
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$button
|
2013-10-09 20:09:59 +00:00
|
|
|
.addClass( 'oo-ui-buttonWidget-button' )
|
2013-10-02 00:00:57 +00:00
|
|
|
.append( this.$label )
|
|
|
|
.attr( {
|
|
|
|
'role': 'button',
|
|
|
|
'title': config.title,
|
|
|
|
'href': config.href,
|
|
|
|
'target': config.target
|
2013-10-07 10:01:43 +00:00
|
|
|
} )
|
|
|
|
.prop( 'tabIndex', config.tabIndex || 0 );
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$
|
2013-10-09 20:09:59 +00:00
|
|
|
.addClass( 'oo-ui-buttonWidget' )
|
2013-10-02 00:00:57 +00:00
|
|
|
.append( this.$button );
|
2013-02-14 02:04:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.inheritClass( OO.ui.ButtonWidget, OO.ui.Widget );
|
2013-02-14 02:04:04 +00:00
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.FlaggableElement );
|
|
|
|
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.LabeledElement );
|
Major UI refactoring and improvements
Objective:
Refactor UI widgets, improve usability and accessibility of menus, general cleanup and style improvements.
Extras:
Fixed documentation in a few other files to make descriptions of jQuery event arguments more consistent, classes inherit correctly, and made use of the @cfg functionality in jsduck.
Changes:
.docs/config.json
* Added window, HTMLDocument, HTMLElement, DocumentFragment and XMLHttpRequest to externals, so jsduck doesn't throw warnings when they are used
demos/ve/index.php, modules/ve/test/index.php, VisualEditor.php
* Moved widgets above tools (since tools use widgets)
demos/ve/index.php
* Refactored widget initialization to use options
* Renamed variables to match widget names
ve.init.mw.ViewPageTarget.css
* Adjusted text sizes to make widgets work normally
* Added margins for buttons in toolbar (since button widgets
don't have any)
* Removed styles for init buttons (button widgets now)
ve.init.mw.ViewPageTarget.js
* Switched to using button widgets (involved moving things around
a bit)
ve.ui.LinkInspector.js, ve.ui.MWLinkInspector.js
* Renamed static property "inputWidget" to
"linkTargetInputWidget" to better reflect the required base class
for the properties value
icons.ai, check.png, check.svg
* Added "check" icon, used in menu right now to show which item
is selected
ve.ui.Icons-raster.css, ve.ui.Icons-vector.css
* Added check icon
* Removed :before pseudo selectors from most of the icon classes (not need by button tool anymore, makes them more reusable now)
ve.ui.Tool.css
* Adjusted drop down tool styles so menu appears below, instead
of on top, of the label
* Adjusted paragraph font size to better match actual content
* Updated class names to still work with menu widget changes
(items are their own widgets now)
* Updated selectors as per changes in the structure of button tools
ve.ui.Widget.css
* Added styles for buttons and menu items
* Adjusted menu styles
ve.ui.*ButtonTool.js
* Added config options argument passthrough
ve.ui.ButtonTool.js
* Moved var statement to the top inside constructor
* Switched to using "a" tag to get cross-browser :active support
* Added icon to inside of button to make icon styles more reusable
* Removed disabled support (now provided by widget parent class)
ve.ui.FormatDropDownTool.js
* Updated options initialization to construct menu item objects
* Modified handling of items to account for changes in menu and
item classes
* Optimized onUpdateState method a bit, adding early exit to
inner loop
ve.ui.ButtonTool.js, ve.ui.DropdownTool.js, ve.ui.Context.js,
ve.ui.Frame, ve.ui.Tool.js, ve.ui.Widget.js
* Added chain ability to non-getter methods
ve.ui.DropdownTool.js
* Removed items argument to constructor
* Updated code as per changes in menu class
* Fixed inconsistent naming of event handler methods
* Removed item event handling (now handled by items directly)
* Made use of this.$$ to ensure tool works in other frames
ve.ui.Tool.js
* Made tools inherit from widget
* Moved trigger registry event handler to a method
ve.ui.Context.js
* Switched from using menu to contain toolbar to a simple wrapper
ve.ui.js
* Added get$$ method, a convenience function for binding jQuery
to a specific document context
ve.ui.*Widget.js
* Switched to using a config options object instead of individual arguments
* Added options
* Factored out flags and labels into their own classes
* Refactored value setting methods for inputs
ve.ui.MenuWidget.js, ve.ui.MenuItemWidget.js
* Broke items out into their own classes
* Redesigned API
* Updated code that uses these classes
* Added support for keyboard interaction
* Made items flash when selected (delaying the hiding of the menu for 200ms)
ve.ui.LinkTargetInputWidget.js, ve.ui.MWLinkTargetInputWidget
* Refactored annotation setting methods
Change-Id: I7769bd5a5b79f1ab36f258ef9f2be583ca503ce6
2013-02-20 23:25:12 +00:00
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
2013-02-14 02:04:04 +00:00
|
|
|
/**
|
|
|
|
* @event click
|
|
|
|
*/
|
2013-02-14 21:41:59 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2013-10-02 00:00:57 +00:00
|
|
|
/**
|
|
|
|
* Handles mouse down events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Mouse down event
|
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.ButtonWidget.prototype.onMouseDown = function () {
|
2013-10-02 00:00:57 +00:00
|
|
|
this.tabIndex = this.$button.attr( 'tabIndex' );
|
|
|
|
// Remove the tab-index while the button is down to prevent the button from stealing focus
|
|
|
|
this.$button.removeAttr( 'tabIndex' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles mouse up events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Mouse up event
|
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.ButtonWidget.prototype.onMouseUp = function () {
|
2013-10-02 00:00:57 +00:00
|
|
|
// Restore the tab-index after the button is up to restore the button's accesssibility
|
|
|
|
this.$button.attr( 'tabIndex', this.tabIndex );
|
|
|
|
};
|
|
|
|
|
2013-02-14 21:41:59 +00:00
|
|
|
/**
|
|
|
|
* Handles mouse click events.
|
|
|
|
*
|
|
|
|
* @method
|
Major UI refactoring and improvements
Objective:
Refactor UI widgets, improve usability and accessibility of menus, general cleanup and style improvements.
Extras:
Fixed documentation in a few other files to make descriptions of jQuery event arguments more consistent, classes inherit correctly, and made use of the @cfg functionality in jsduck.
Changes:
.docs/config.json
* Added window, HTMLDocument, HTMLElement, DocumentFragment and XMLHttpRequest to externals, so jsduck doesn't throw warnings when they are used
demos/ve/index.php, modules/ve/test/index.php, VisualEditor.php
* Moved widgets above tools (since tools use widgets)
demos/ve/index.php
* Refactored widget initialization to use options
* Renamed variables to match widget names
ve.init.mw.ViewPageTarget.css
* Adjusted text sizes to make widgets work normally
* Added margins for buttons in toolbar (since button widgets
don't have any)
* Removed styles for init buttons (button widgets now)
ve.init.mw.ViewPageTarget.js
* Switched to using button widgets (involved moving things around
a bit)
ve.ui.LinkInspector.js, ve.ui.MWLinkInspector.js
* Renamed static property "inputWidget" to
"linkTargetInputWidget" to better reflect the required base class
for the properties value
icons.ai, check.png, check.svg
* Added "check" icon, used in menu right now to show which item
is selected
ve.ui.Icons-raster.css, ve.ui.Icons-vector.css
* Added check icon
* Removed :before pseudo selectors from most of the icon classes (not need by button tool anymore, makes them more reusable now)
ve.ui.Tool.css
* Adjusted drop down tool styles so menu appears below, instead
of on top, of the label
* Adjusted paragraph font size to better match actual content
* Updated class names to still work with menu widget changes
(items are their own widgets now)
* Updated selectors as per changes in the structure of button tools
ve.ui.Widget.css
* Added styles for buttons and menu items
* Adjusted menu styles
ve.ui.*ButtonTool.js
* Added config options argument passthrough
ve.ui.ButtonTool.js
* Moved var statement to the top inside constructor
* Switched to using "a" tag to get cross-browser :active support
* Added icon to inside of button to make icon styles more reusable
* Removed disabled support (now provided by widget parent class)
ve.ui.FormatDropDownTool.js
* Updated options initialization to construct menu item objects
* Modified handling of items to account for changes in menu and
item classes
* Optimized onUpdateState method a bit, adding early exit to
inner loop
ve.ui.ButtonTool.js, ve.ui.DropdownTool.js, ve.ui.Context.js,
ve.ui.Frame, ve.ui.Tool.js, ve.ui.Widget.js
* Added chain ability to non-getter methods
ve.ui.DropdownTool.js
* Removed items argument to constructor
* Updated code as per changes in menu class
* Fixed inconsistent naming of event handler methods
* Removed item event handling (now handled by items directly)
* Made use of this.$$ to ensure tool works in other frames
ve.ui.Tool.js
* Made tools inherit from widget
* Moved trigger registry event handler to a method
ve.ui.Context.js
* Switched from using menu to contain toolbar to a simple wrapper
ve.ui.js
* Added get$$ method, a convenience function for binding jQuery
to a specific document context
ve.ui.*Widget.js
* Switched to using a config options object instead of individual arguments
* Added options
* Factored out flags and labels into their own classes
* Refactored value setting methods for inputs
ve.ui.MenuWidget.js, ve.ui.MenuItemWidget.js
* Broke items out into their own classes
* Redesigned API
* Updated code that uses these classes
* Added support for keyboard interaction
* Made items flash when selected (delaying the hiding of the menu for 200ms)
ve.ui.LinkTargetInputWidget.js, ve.ui.MWLinkTargetInputWidget
* Refactored annotation setting methods
Change-Id: I7769bd5a5b79f1ab36f258ef9f2be583ca503ce6
2013-02-20 23:25:12 +00:00
|
|
|
* @param {jQuery.Event} e Mouse click event
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires click
|
2013-02-14 21:41:59 +00:00
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.ButtonWidget.prototype.onClick = function () {
|
2013-02-14 21:41:59 +00:00
|
|
|
if ( !this.disabled ) {
|
|
|
|
this.emit( 'click' );
|
2013-10-02 00:00:57 +00:00
|
|
|
if ( this.isHyperlink ) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-14 21:41:59 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2013-07-24 13:45:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles keypress events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Keypress event
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires click
|
2013-07-24 13:45:42 +00:00
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.ButtonWidget.prototype.onKeyPress = function ( e ) {
|
|
|
|
if ( !this.disabled && e.which === OO.ui.Keys.SPACE ) {
|
2013-10-02 00:00:57 +00:00
|
|
|
if ( this.isHyperlink ) {
|
|
|
|
this.onClick();
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-24 13:45:42 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|