mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-11 05:56:11 +00:00
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
// ToolbarView
|
|
es.ToolbarView = function( $container, surfaceView, config ) {
|
|
// Inheritance TODO: Do we still need it?
|
|
es.EventEmitter.call( this );
|
|
if ( !surfaceView ) {
|
|
return;
|
|
}
|
|
|
|
// References for use in closures
|
|
var _this = this,
|
|
$window = $( window );
|
|
|
|
// Properties
|
|
this.surfaceView = surfaceView;
|
|
this.$ = $container;
|
|
this.$groups = $( '<div class="es-toolbarGroups"></div>' ).prependTo( this.$ );
|
|
this.tools = [];
|
|
|
|
this.surfaceView.on( 'cursor', function( annotations, nodes ) {
|
|
for( var i = 0; i < _this.tools.length; i++ ) {
|
|
_this.tools[i].updateState( annotations, nodes );
|
|
}
|
|
} );
|
|
|
|
config = [];
|
|
this.config = config || [
|
|
{ 'name': 'history', 'items' : ['undo', 'redo'] },
|
|
{ 'name': 'textStyle', 'items' : ['format'] },
|
|
{ 'name': 'textStyle', 'items' : ['bold', 'italic', 'link', 'clear'] },
|
|
{ 'name': 'list', 'items' : ['number', 'bullet', 'outdent', 'indent'] }
|
|
];
|
|
this.setup();
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
es.ToolbarView.prototype.getSurfaceView = function() {
|
|
return this.surfaceView;
|
|
};
|
|
|
|
es.ToolbarView.prototype.setup = function() {
|
|
for ( var i = 0; i < this.config.length; i++ ) {
|
|
var $group = $( '<div>' )
|
|
.addClass( 'es-toolbarGroup' )
|
|
.addClass( 'es-toolbarGroup-' + this.config[i].name );
|
|
if ( this.config[i].label ) {
|
|
$group.append(
|
|
$( '<div>' ).addClass( 'es-toolbarLabel' ).html( this.config[i].label )
|
|
);
|
|
}
|
|
|
|
for ( var j = 0; j < this.config[i].items.length; j++ ) {
|
|
var toolDefintion = es.Tool.tools[ this.config[i].items[j] ];
|
|
if ( toolDefintion ) {
|
|
var tool = new toolDefintion.constructor(
|
|
this, toolDefintion.name, toolDefintion.title, toolDefintion.data
|
|
);
|
|
this.tools.push( tool );
|
|
$group.append( tool.$ );
|
|
}
|
|
}
|
|
|
|
this.$groups.append( $group );
|
|
}
|
|
};
|
|
|
|
es.extendClass( es.ToolbarView, es.EventEmitter );
|