Modify VE constructor to have the default set of tool configuration

Configuration options are to extend base options in the constructor.

Change-Id: Ic430a6489d8cf9a703e374c3f416feaf0e3d2521
This commit is contained in:
Rob Moen 2012-04-19 15:14:57 -07:00
parent e2ca8c24c7
commit 1a68c42049
2 changed files with 12 additions and 16 deletions

View file

@ -503,18 +503,8 @@ $(document).ready( function() {
} }
}; };
/* TODO: Make the config better */ /* Create a new instance of VE, optional third param for ve configuration options */
var options = { var sandboxEditor = new ve.Surface('sandbox', wikidoms['Wikipedia article'] /*, options */),
toolbars: {
'top': [ { 'name': 'history', 'items' : ['undo', 'redo'] },
{ 'name': 'textStyle', 'items' : ['format'] },
{ 'name': 'textStyle', 'items' : ['bold', 'italic', 'link', 'clear'] },
{ 'name': 'list', 'items' : ['number', 'bullet', 'outdent', 'indent'] } ]
}
};
//create a new instance of VE
var sandboxEditor = new ve.Surface('sandbox', wikidoms['Wikipedia article'], options ),
surfaceModel = sandboxEditor.getSurfaceModel(), surfaceModel = sandboxEditor.getSurfaceModel(),
documentModel = sandboxEditor.getDocumentModel(), documentModel = sandboxEditor.getDocumentModel(),
editorID = sandboxEditor.getID(); editorID = sandboxEditor.getID();

View file

@ -1,8 +1,8 @@
/** /**
* Creates an ve.Surface object. * Creates an ve.Surface object.
* *
* A surface is a top-level object which contains both a surface model and a surface view. * A surface is a top-level object which contains both a surface model and a surface view.
* *
* @class * @class
* @constructor * @constructor
* @param {String} id Unique name of editor instance * @param {String} id Unique name of editor instance
@ -14,7 +14,13 @@ ve.Surface = function( id, data, options ) {
this.id = id; this.id = id;
this.options = ve.extendObject( { this.options = ve.extendObject( {
// Default options // Default options
}, this.options ); toolbars: {
'top': [{ 'name': 'history', 'items' : ['undo', 'redo'] },
{ 'name': 'textStyle', 'items' : ['format'] },
{ 'name': 'textStyle', 'items' : ['bold', 'italic', 'link', 'clear'] },
{ 'name': 'list', 'items' : ['number', 'bullet', 'outdent', 'indent'] }]
}
}, options );
this.documentModel = ve.dm.DocumentNode.newFromPlainObject( data ); this.documentModel = ve.dm.DocumentNode.newFromPlainObject( data );
this.surfaceModel = new ve.dm.Surface( this.documentModel ); this.surfaceModel = new ve.dm.Surface( this.documentModel );
@ -24,7 +30,7 @@ ve.Surface = function( id, data, options ) {
this.context = new ve.ui.Context( this.view ); this.context = new ve.ui.Context( this.view );
//TODO: Configure toolbar based on this.options. //TODO: Configure toolbar based on this.options.
this.toolbar = new ve.ui.Toolbar( $( '#es-toolbar'), this.view, options.toolbars.top ); this.toolbar = new ve.ui.Toolbar( $( '#es-toolbar' ), this.view, this.options.toolbars.top );
// Registration // Registration
ve.instances.push( this ); ve.instances.push( this );
}; };