mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
References dialog cleanup
Objectives: * Remove the whole toolbar subset thing, it's up to the creator of the subsurface to know what is and is now allowed, and the commands were still passing through unfiltered * Correctly separate initialization from opening - fix issue where opening the reference dialog multiple times will keep adding more and more controls Changes: ve.init.Target.js * Remove getToolbarSubset method ve.ui.MWReferenceDialog.js * Add toolbar tools and surface commands configs to reference dialog, including the things that are safe to use in references * Move creation of field sets and reused controls to initialize method to prevent re-creation each time the dialog is opened * Move static initialization stuff to the top near the other static stuff Change-Id: I1c8577d17c506bac76e61b2b036655c59ef5a218
This commit is contained in:
parent
2bccb3da85
commit
2d044518bd
|
@ -39,24 +39,3 @@ ve.init.Target.static.toolbarTools = [
|
||||||
ve.init.Target.static.surfaceCommands = [
|
ve.init.Target.static.surfaceCommands = [
|
||||||
'bold', 'italic', 'link', 'undo', 'redo', 'indent', 'outdent'
|
'bold', 'italic', 'link', 'undo', 'redo', 'indent', 'outdent'
|
||||||
];
|
];
|
||||||
|
|
||||||
/* Static Methods */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a subset of toolbarTools excluding certain tools.
|
|
||||||
*
|
|
||||||
* @param {string[]} exclude List of tools to exclude
|
|
||||||
* @returns {Object} Toolbar tools object
|
|
||||||
*/
|
|
||||||
ve.init.Target.static.getToolbarSubset = function ( exclude ) {
|
|
||||||
var i, iLen, items, group, toolbarSubset = [];
|
|
||||||
for ( i = 0, iLen = this.toolbarTools.length; i < iLen; i++ ) {
|
|
||||||
items = ve.simpleArrayDifference( this.toolbarTools[i].items, exclude );
|
|
||||||
if ( items.length ) {
|
|
||||||
group = ve.copyObject( this.toolbarTools[i] );
|
|
||||||
group.items = items;
|
|
||||||
toolbarSubset.push( group );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return toolbarSubset;
|
|
||||||
};
|
|
||||||
|
|
|
@ -35,6 +35,27 @@ ve.ui.MWReferenceDialog.static.icon = 'reference';
|
||||||
|
|
||||||
ve.ui.MWReferenceDialog.static.modelClasses = [ ve.dm.MWReferenceNode ];
|
ve.ui.MWReferenceDialog.static.modelClasses = [ ve.dm.MWReferenceNode ];
|
||||||
|
|
||||||
|
ve.ui.MWReferenceDialog.static.toolbarTools = [
|
||||||
|
{ 'items': ['undo', 'redo'] },
|
||||||
|
{ 'items': ['mwFormat'] },
|
||||||
|
{ 'items': ['bold', 'italic', 'mwLink', 'clear', 'mwMediaInsert'] }
|
||||||
|
];
|
||||||
|
|
||||||
|
ve.ui.MWReferenceDialog.static.surfaceCommands = [
|
||||||
|
'bold', 'italic', 'mwLink', 'undo', 'redo'
|
||||||
|
];
|
||||||
|
|
||||||
|
/* Static Initialization */
|
||||||
|
|
||||||
|
ve.ui.MWReferenceDialog.static.addLocalStylesheets( [
|
||||||
|
've.ce.Node.css',
|
||||||
|
've.ce.Surface.css',
|
||||||
|
've.ui.Surface.css',
|
||||||
|
've.ui.Context.css',
|
||||||
|
've.ui.Tool.css',
|
||||||
|
've.ui.Toolbar.css'
|
||||||
|
] );
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,8 +67,27 @@ ve.ui.MWReferenceDialog.prototype.initialize = function () {
|
||||||
// Call parent method
|
// Call parent method
|
||||||
ve.ui.Dialog.prototype.initialize.call( this );
|
ve.ui.Dialog.prototype.initialize.call( this );
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
this.contentFieldset = new ve.ui.FieldsetLayout( {
|
||||||
|
// TODO: use message string
|
||||||
|
'$$': this.frame.$$, 'label': 'Content', 'icon': 'parameter'
|
||||||
|
} );
|
||||||
|
this.nameFieldset = new ve.ui.FieldsetLayout( {
|
||||||
|
// TODO: use message string
|
||||||
|
'$$': this.frame.$$, 'label': 'Name', 'icon': 'parameter'
|
||||||
|
} );
|
||||||
|
this.nameInput = new ve.ui.TextInputWidget( { '$$': this.frame.$$ } );
|
||||||
|
this.nameLabel = new ve.ui.InputLabelWidget( {
|
||||||
|
'$$': this.frame.$$,
|
||||||
|
'input': this.nameInput,
|
||||||
|
// TODO: use message string
|
||||||
|
'label': 'Reuse this reference by this name'
|
||||||
|
} );
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
this.$body.addClass( 've-ui-mwReferenceDialog-body' );
|
this.$body.addClass( 've-ui-mwReferenceDialog-body' );
|
||||||
|
this.$body.append( this.contentFieldset.$, this.nameFieldset.$ );
|
||||||
|
this.nameFieldset.$.append( this.nameLabel.$, this.nameInput.$ );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,32 +96,20 @@ ve.ui.MWReferenceDialog.prototype.initialize = function () {
|
||||||
* @method
|
* @method
|
||||||
*/
|
*/
|
||||||
ve.ui.MWReferenceDialog.prototype.onOpen = function () {
|
ve.ui.MWReferenceDialog.prototype.onOpen = function () {
|
||||||
var focusedNode, doc, data,
|
var focusedNode, data,
|
||||||
// Remove mwReference tool as you can't have nested references
|
doc = this.surface.getModel().getDocument();
|
||||||
toolbarSubset = ve.init.mw.ViewPageTarget.static.getToolbarSubset( [
|
|
||||||
// Can't have nested references
|
|
||||||
'mwReference',
|
|
||||||
// Lists not properly supported by PHP parser
|
|
||||||
'number', 'bullet', 'outdent', 'indent'
|
|
||||||
] );
|
|
||||||
|
|
||||||
// Parent method
|
// Parent method
|
||||||
ve.ui.Dialog.prototype.onOpen.call( this );
|
ve.ui.Dialog.prototype.onOpen.call( this );
|
||||||
|
|
||||||
// Get data from selection
|
// Get reference content
|
||||||
focusedNode = this.surface.getView().getFocusedNode();
|
focusedNode = this.surface.getView().getFocusedNode();
|
||||||
doc = this.surface.getModel().getDocument();
|
|
||||||
if ( focusedNode instanceof ve.ce.MWReferenceNode ) {
|
if ( focusedNode instanceof ve.ce.MWReferenceNode ) {
|
||||||
this.internalItem = focusedNode.getModel().getInternalItem();
|
this.internalItem = focusedNode.getModel().getInternalItem();
|
||||||
data = doc.getData( this.internalItem.getRange(), true );
|
data = doc.getData( this.internalItem.getRange(), true );
|
||||||
} else {
|
} else {
|
||||||
data = [
|
data = [
|
||||||
{
|
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
|
||||||
'type': 'paragraph',
|
|
||||||
'internal': {
|
|
||||||
'generated': 'wrapper'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ 'type': '/paragraph' }
|
{ 'type': '/paragraph' }
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -94,9 +122,9 @@ ve.ui.MWReferenceDialog.prototype.onOpen = function () {
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
this.referenceToolbar.$.addClass( 've-ui-mwReferenceDialog-toolbar' );
|
this.referenceToolbar.$.addClass( 've-ui-mwReferenceDialog-toolbar' );
|
||||||
this.$body.append( this.referenceToolbar.$, this.referenceSurface.$ );
|
this.contentFieldset.$.append( this.referenceToolbar.$, this.referenceSurface.$ );
|
||||||
this.referenceToolbar.addTools( toolbarSubset );
|
this.referenceToolbar.addTools( this.constructor.static.toolbarTools );
|
||||||
this.referenceSurface.addCommands( ve.init.mw.ViewPageTarget.static.surfaceCommands );
|
this.referenceSurface.addCommands( this.constructor.static.surfaceCommands );
|
||||||
this.referenceSurface.initialize();
|
this.referenceSurface.initialize();
|
||||||
this.referenceSurface.view.documentView.documentNode.$.focus();
|
this.referenceSurface.view.documentView.documentNode.$.focus();
|
||||||
};
|
};
|
||||||
|
@ -138,9 +166,7 @@ ve.ui.MWReferenceDialog.prototype.onClose = function ( action ) {
|
||||||
{
|
{
|
||||||
'type': 'mwReference',
|
'type': 'mwReference',
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'mw': {
|
'mw': { 'name': 'ref' },
|
||||||
'name': 'ref'
|
|
||||||
},
|
|
||||||
'listIndex': newItem.index,
|
'listIndex': newItem.index,
|
||||||
'listGroup': 'mwReference/' + groupName,
|
'listGroup': 'mwReference/' + groupName,
|
||||||
'listKey': key,
|
'listKey': key,
|
||||||
|
@ -158,17 +184,6 @@ ve.ui.MWReferenceDialog.prototype.onClose = function ( action ) {
|
||||||
this.referenceToolbar.destroy();
|
this.referenceToolbar.destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Initialization */
|
|
||||||
|
|
||||||
ve.ui.MWReferenceDialog.static.addLocalStylesheets( [
|
|
||||||
've.ce.Node.css',
|
|
||||||
've.ce.Surface.css',
|
|
||||||
've.ui.Surface.css',
|
|
||||||
've.ui.Context.css',
|
|
||||||
've.ui.Tool.css',
|
|
||||||
've.ui.Toolbar.css'
|
|
||||||
] );
|
|
||||||
|
|
||||||
/* Registration */
|
/* Registration */
|
||||||
|
|
||||||
ve.ui.dialogFactory.register( 'mwReference', ve.ui.MWReferenceDialog );
|
ve.ui.dialogFactory.register( 'mwReference', ve.ui.MWReferenceDialog );
|
||||||
|
|
Loading…
Reference in a new issue