2011-12-05 21:10:19 +00:00
|
|
|
/**
|
|
|
|
* Creates an es.ListButtonTool object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {es.ButtonTool}
|
|
|
|
* @param {es.ToolbarView} toolbar
|
|
|
|
* @param {String} name
|
|
|
|
*/
|
|
|
|
es.ListButtonTool = function( toolbar, name, data ) {
|
|
|
|
// Inheritance
|
2011-12-04 02:59:53 +00:00
|
|
|
es.ButtonTool.call( this, toolbar, name );
|
2011-12-05 21:10:19 +00:00
|
|
|
|
|
|
|
// Properties
|
2011-12-04 02:59:53 +00:00
|
|
|
this.data = data;
|
|
|
|
this.nodes = [];
|
|
|
|
};
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2011-12-04 02:59:53 +00:00
|
|
|
es.ListButtonTool.prototype.onClick = function() {
|
|
|
|
/*
|
|
|
|
var parent;
|
|
|
|
for( var i = 0; i < this.nodes.length; i++ ) {
|
|
|
|
parent = this.nodes[i].getParent();
|
|
|
|
if ( parent.getElementType() !== 'listItem' ) {
|
|
|
|
console.log( this.nodes[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
es.ListButtonTool.prototype.updateState = function( annotations, nodes ) {
|
|
|
|
// checks if all passed nodes are listItems of passed style
|
|
|
|
function check( nodes, style ) {
|
|
|
|
var parent, styles;
|
|
|
|
for( var i = 0; i < nodes.length; i++ ) {
|
|
|
|
parent = nodes[i].getParent();
|
|
|
|
if ( parent.getElementType() !== 'listItem' ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
styles = parent.getElementAttribute( 'styles' );
|
|
|
|
if ( styles[ styles.length - 1] !== style ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.nodes = nodes;
|
|
|
|
if ( check( this.nodes, this.name ) ) {
|
|
|
|
this.$.addClass( 'es-toolbarButtonTool-down' );
|
|
|
|
} else {
|
|
|
|
this.$.removeClass( 'es-toolbarButtonTool-down' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2011-12-04 02:59:53 +00:00
|
|
|
es.Tool.tools.number = {
|
|
|
|
constructor: es.ListButtonTool,
|
|
|
|
name: 'number'
|
|
|
|
};
|
|
|
|
|
|
|
|
es.Tool.tools.bullet = {
|
|
|
|
constructor: es.ListButtonTool,
|
|
|
|
name: 'bullet'
|
|
|
|
};
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
es.extendClass( es.ListButtonTool, es.ButtonTool );
|