diff --git a/demos/ce/main.js b/demos/ce/main.js index 368febbda0..a19df6236e 100644 --- a/demos/ce/main.js +++ b/demos/ce/main.js @@ -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 ) ); diff --git a/modules/ve/ce/ve.es.Surface.js b/modules/ve/ce/ve.es.Surface.js index efab3591cf..f1f38d62d3 100644 --- a/modules/ve/ce/ve.es.Surface.js +++ b/modules/ve/ce/ve.es.Surface.js @@ -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(), diff --git a/modules/ve/ui/tools/ve.ui.FormatDropdownTool.js b/modules/ve/ui/tools/ve.ui.FormatDropdownTool.js index 5c3082c292..40e3fb5615 100644 --- a/modules/ve/ui/tools/ve.ui.FormatDropdownTool.js +++ b/modules/ve/ui/tools/ve.ui.FormatDropdownTool.js @@ -11,7 +11,7 @@ ve.FormatDropdownTool = function( toolbar, name, title ) { // Inheritance ve.ui.DropdownTool.call( this, toolbar, name, title, [ - { + { 'name': 'paragraph', 'label': 'Paragraph', 'type' : 'paragraph'