enable CE demo toolbar, added annnotation and renderDomNode methods

This commit is contained in:
Rob Moen 2012-03-05 22:08:35 +00:00
parent 19fe9726a2
commit 809df81282
Notes: Rob Moen 2012-03-05 22:08:35 +00:00
3 changed files with 32 additions and 2 deletions

View file

@ -473,7 +473,7 @@ $(document).ready( function() {
window.documentModel = ve.dm.DocumentNode.newFromPlainObject( wikidoms['Wikipedia article'] );
window.surfaceModel = new ve.dm.Surface( window.documentModel );
window.surfaceView = new ve.es.Surface( $( '#es-editor' ), window.surfaceModel );
window.toolbarView = new ve.ui.Toolbar( $( '#es-toolbar' ), window.surfaceView, [] );
window.toolbarView = new ve.ui.Toolbar( $( '#es-toolbar' ), window.surfaceView );
window.contextView = new ve.ui.Context( window.surfaceView );
window.surfaceModel.select( new ve.Range( 1, 1 ) );

View file

@ -81,6 +81,36 @@ ve.es.Surface = function( $container, model ) {
/* Methods */
ve.es.Surface.prototype.annotate = function( method, annotation ) {
var range = this.getSelection();
if ( method === 'toggle' ) {
var annotations = this.getAnnotations();
if ( ve.dm.DocumentNode.getIndexOfAnnotation( annotations.full, annotation ) !== -1 ) {
method = 'clear';
} else {
method = 'set';
}
}
if ( range.getLength() ) {
var tx = this.model.getDocument().prepareContentAnnotation(
range, method, annotation
);
this.model.transact( tx );
// re-render Node
this.renderDomNode ( rangy.getSelection().anchorNode );
} else {
if ( method === 'set' ) {
this.addInsertionAnnotation( annotation );
} else if ( method === 'clear' ) {
this.removeInsertionAnnotation( annotation );
}
}
};
ve.es.Surface.prototype.renderDomNode = function ( node ) {
this.getLeafNode( node ).data( 'view' ).renderContent();
};
ve.es.Surface.prototype.onCutCopy = function( e ) {
var _this = this,
rangySel = rangy.getSelection(),