mediawiki-extensions-Visual.../modules/ve/ui/widgets/ve.ui.OutlineControlsWidget.js

129 lines
3.5 KiB
JavaScript
Raw Normal View History

Outline controls Objectives: * Allow reordering items in outline widgets using an outline control widget * Use an outline control widget to reorder transclusion parts Changes: ve.ui.SelectWidget.js * Emit add and remove events ve.ui.OutlineItemWidget.js * Add movable config options * Add isMovable method ve.ui.OutlineControlsWidget.js * New class * Displays move up/down buttons which are synchronized with an outline widget * Doesn't actually move items (since an outline widget is probably data-driven) just emits events ve.ui.Widget.css * Add disabled style for icon button widgets * Add styles for outline controls widget ve.ui.Icons*.css * Add missing icon styles ve.ui.Dialog.css * Add styles for outline and controls in editable paged dialogs ve.ui.GroupElement.js * Fix bug where items are insertions are in the wrong place when "moving" them ve.ui.PagedDialog.js * Add editable config option which shows outline controls under the outline * Pass through movable config option when creating pages ve.ui.MWTranclusionDialog.js * Configure paged dialog outline as editable * Add initialize method to connect outline controls widget events * Make addPart method automatically add parameters when templates are added * Add handler for outline controls move event which re-orders parts * Make parts movable (params are automatically ordered, so they aren't movable) ve.dm.MWTransclusionModel.js * Add addPart method and use it within the addContent and addTemplate methods * Fix documentation lies * Add getPartFromId method *.php * Add links to new files and messages Change-Id: I919d4c3e9b85d07a97a99c0b2e8739a859bdf2b1
2013-06-14 00:46:45 +00:00
/*!
* VisualEditor UserInterface OutlineControlsWidget class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.OutlineControlsWidget object.
*
* @class
*
* @constructor
* @param {ve.ui.OutlineWidget} outline Outline to control
* @param {Object} [config] Config options
* @cfg {Object[]} [adders] List of icons to show as addable item types, each an object with
* name, title and icon properties
Outline controls Objectives: * Allow reordering items in outline widgets using an outline control widget * Use an outline control widget to reorder transclusion parts Changes: ve.ui.SelectWidget.js * Emit add and remove events ve.ui.OutlineItemWidget.js * Add movable config options * Add isMovable method ve.ui.OutlineControlsWidget.js * New class * Displays move up/down buttons which are synchronized with an outline widget * Doesn't actually move items (since an outline widget is probably data-driven) just emits events ve.ui.Widget.css * Add disabled style for icon button widgets * Add styles for outline controls widget ve.ui.Icons*.css * Add missing icon styles ve.ui.Dialog.css * Add styles for outline and controls in editable paged dialogs ve.ui.GroupElement.js * Fix bug where items are insertions are in the wrong place when "moving" them ve.ui.PagedDialog.js * Add editable config option which shows outline controls under the outline * Pass through movable config option when creating pages ve.ui.MWTranclusionDialog.js * Configure paged dialog outline as editable * Add initialize method to connect outline controls widget events * Make addPart method automatically add parameters when templates are added * Add handler for outline controls move event which re-orders parts * Make parts movable (params are automatically ordered, so they aren't movable) ve.dm.MWTransclusionModel.js * Add addPart method and use it within the addContent and addTemplate methods * Fix documentation lies * Add getPartFromId method *.php * Add links to new files and messages Change-Id: I919d4c3e9b85d07a97a99c0b2e8739a859bdf2b1
2013-06-14 00:46:45 +00:00
*/
ve.ui.OutlineControlsWidget = function VeUiOutlineControlsWidget( outline, config ) {
// Configuration initialization
config = config || {};
Outline controls Objectives: * Allow reordering items in outline widgets using an outline control widget * Use an outline control widget to reorder transclusion parts Changes: ve.ui.SelectWidget.js * Emit add and remove events ve.ui.OutlineItemWidget.js * Add movable config options * Add isMovable method ve.ui.OutlineControlsWidget.js * New class * Displays move up/down buttons which are synchronized with an outline widget * Doesn't actually move items (since an outline widget is probably data-driven) just emits events ve.ui.Widget.css * Add disabled style for icon button widgets * Add styles for outline controls widget ve.ui.Icons*.css * Add missing icon styles ve.ui.Dialog.css * Add styles for outline and controls in editable paged dialogs ve.ui.GroupElement.js * Fix bug where items are insertions are in the wrong place when "moving" them ve.ui.PagedDialog.js * Add editable config option which shows outline controls under the outline * Pass through movable config option when creating pages ve.ui.MWTranclusionDialog.js * Configure paged dialog outline as editable * Add initialize method to connect outline controls widget events * Make addPart method automatically add parameters when templates are added * Add handler for outline controls move event which re-orders parts * Make parts movable (params are automatically ordered, so they aren't movable) ve.dm.MWTransclusionModel.js * Add addPart method and use it within the addContent and addTemplate methods * Fix documentation lies * Add getPartFromId method *.php * Add links to new files and messages Change-Id: I919d4c3e9b85d07a97a99c0b2e8739a859bdf2b1
2013-06-14 00:46:45 +00:00
// Parent constructor
ve.ui.Widget.call( this, config );
// Properties
this.outline = outline;
this.adders = {};
this.$adders = this.$$( '<div>' );
this.$movers = this.$$( '<div>' );
this.addButton = new ve.ui.IconButtonWidget( { '$$': this.$$, 'icon': 'add-item' } );
Outline controls Objectives: * Allow reordering items in outline widgets using an outline control widget * Use an outline control widget to reorder transclusion parts Changes: ve.ui.SelectWidget.js * Emit add and remove events ve.ui.OutlineItemWidget.js * Add movable config options * Add isMovable method ve.ui.OutlineControlsWidget.js * New class * Displays move up/down buttons which are synchronized with an outline widget * Doesn't actually move items (since an outline widget is probably data-driven) just emits events ve.ui.Widget.css * Add disabled style for icon button widgets * Add styles for outline controls widget ve.ui.Icons*.css * Add missing icon styles ve.ui.Dialog.css * Add styles for outline and controls in editable paged dialogs ve.ui.GroupElement.js * Fix bug where items are insertions are in the wrong place when "moving" them ve.ui.PagedDialog.js * Add editable config option which shows outline controls under the outline * Pass through movable config option when creating pages ve.ui.MWTranclusionDialog.js * Configure paged dialog outline as editable * Add initialize method to connect outline controls widget events * Make addPart method automatically add parameters when templates are added * Add handler for outline controls move event which re-orders parts * Make parts movable (params are automatically ordered, so they aren't movable) ve.dm.MWTransclusionModel.js * Add addPart method and use it within the addContent and addTemplate methods * Fix documentation lies * Add getPartFromId method *.php * Add links to new files and messages Change-Id: I919d4c3e9b85d07a97a99c0b2e8739a859bdf2b1
2013-06-14 00:46:45 +00:00
this.upButton = new ve.ui.IconButtonWidget( {
'$$': this.$$, 'icon': 'collapse', 'title': ve.msg( 'visualeditor-outline-control-move-up' )
} );
this.downButton = new ve.ui.IconButtonWidget( {
'$$': this.$$, 'icon': 'expand', 'title': ve.msg( 'visualeditor-outline-control-move-down' )
} );
// Events
outline.connect( this, {
'select': 'onOutlineChange',
'add': 'onOutlineChange',
'remove': 'onOutlineChange'
} );
this.upButton.connect( this, { 'click': ['emit', 'move', -1] } );
this.downButton.connect( this, { 'click': ['emit', 'move', 1] } );
// Initialization
this.$.addClass( 've-ui-outlineControlsWidget' );
this.$adders.addClass( 've-ui-outlineControlsWidget-adders' );
this.$movers
.addClass( 've-ui-outlineControlsWidget-movers' )
.append( this.upButton.$, this.downButton.$ );
this.$.append( this.$adders, this.$movers );
if ( config.adders && config.adders.length ) {
this.setupAdders( config.adders );
}
Outline controls Objectives: * Allow reordering items in outline widgets using an outline control widget * Use an outline control widget to reorder transclusion parts Changes: ve.ui.SelectWidget.js * Emit add and remove events ve.ui.OutlineItemWidget.js * Add movable config options * Add isMovable method ve.ui.OutlineControlsWidget.js * New class * Displays move up/down buttons which are synchronized with an outline widget * Doesn't actually move items (since an outline widget is probably data-driven) just emits events ve.ui.Widget.css * Add disabled style for icon button widgets * Add styles for outline controls widget ve.ui.Icons*.css * Add missing icon styles ve.ui.Dialog.css * Add styles for outline and controls in editable paged dialogs ve.ui.GroupElement.js * Fix bug where items are insertions are in the wrong place when "moving" them ve.ui.PagedDialog.js * Add editable config option which shows outline controls under the outline * Pass through movable config option when creating pages ve.ui.MWTranclusionDialog.js * Configure paged dialog outline as editable * Add initialize method to connect outline controls widget events * Make addPart method automatically add parameters when templates are added * Add handler for outline controls move event which re-orders parts * Make parts movable (params are automatically ordered, so they aren't movable) ve.dm.MWTransclusionModel.js * Add addPart method and use it within the addContent and addTemplate methods * Fix documentation lies * Add getPartFromId method *.php * Add links to new files and messages Change-Id: I919d4c3e9b85d07a97a99c0b2e8739a859bdf2b1
2013-06-14 00:46:45 +00:00
};
/* Inheritance */
ve.inheritClass( ve.ui.OutlineControlsWidget, ve.ui.Widget );
/* Events */
/**
* @event move
* @param {number} places Number of places to move
*/
/* Methods */
/**
* Handle outline change events.
*
* @method
*/
Outline controls Objectives: * Allow reordering items in outline widgets using an outline control widget * Use an outline control widget to reorder transclusion parts Changes: ve.ui.SelectWidget.js * Emit add and remove events ve.ui.OutlineItemWidget.js * Add movable config options * Add isMovable method ve.ui.OutlineControlsWidget.js * New class * Displays move up/down buttons which are synchronized with an outline widget * Doesn't actually move items (since an outline widget is probably data-driven) just emits events ve.ui.Widget.css * Add disabled style for icon button widgets * Add styles for outline controls widget ve.ui.Icons*.css * Add missing icon styles ve.ui.Dialog.css * Add styles for outline and controls in editable paged dialogs ve.ui.GroupElement.js * Fix bug where items are insertions are in the wrong place when "moving" them ve.ui.PagedDialog.js * Add editable config option which shows outline controls under the outline * Pass through movable config option when creating pages ve.ui.MWTranclusionDialog.js * Configure paged dialog outline as editable * Add initialize method to connect outline controls widget events * Make addPart method automatically add parameters when templates are added * Add handler for outline controls move event which re-orders parts * Make parts movable (params are automatically ordered, so they aren't movable) ve.dm.MWTransclusionModel.js * Add addPart method and use it within the addContent and addTemplate methods * Fix documentation lies * Add getPartFromId method *.php * Add links to new files and messages Change-Id: I919d4c3e9b85d07a97a99c0b2e8739a859bdf2b1
2013-06-14 00:46:45 +00:00
ve.ui.OutlineControlsWidget.prototype.onOutlineChange = function () {
var i, len, firstMoveable, lastMoveable,
moveable = false,
items = this.outline.getItems(),
selectedItem = this.outline.getSelectedItem();
if ( selectedItem && selectedItem.isMoveable() ) {
moveable = true;
i = -1;
len = items.length;
while ( ++i < len ) {
if ( items[i].isMoveable() ) {
firstMoveable = items[i];
break;
}
}
i = len;
while ( i-- ) {
if ( items[i].isMoveable() ) {
lastMoveable = items[i];
break;
}
}
}
this.upButton.setDisabled( !moveable || selectedItem === firstMoveable );
this.downButton.setDisabled( !moveable || selectedItem === lastMoveable );
};
/**
* Setup adders icons.
*
* @method
* @param {Object[]} adders List of configuations for adder buttons, each containing a name, title
* and icon property
*/
ve.ui.OutlineControlsWidget.prototype.setupAdders = function ( adders ) {
var i, len, addition, button,
$buttons = this.$$( [] );
this.$adders.append( this.addButton.$ );
for ( i = 0, len = adders.length; i < len; i++ ) {
addition = adders[i];
button = new ve.ui.IconButtonWidget( {
'$$': this.$$, 'icon': addition.icon, 'title': addition.title
} );
button.connect( this, { 'click': ['emit', 'add', addition.name] } );
this.adders[addition.name] = button;
this.$adders.append( button.$ );
$buttons = $buttons.add( button.$ );
}
};