Index: trunk/extensions/VisualEditor/VisualEditor.php |
— | — | @@ -104,7 +104,10 @@ |
105 | 105 | 'es/tools/es.ButtonTool.js', |
106 | 106 | 'es/tools/es.AnnotationButtonTool.js', |
107 | 107 | 'es/tools/es.ClearButtonTool.js', |
108 | | - 'es/tools/es.HistoryButtonTool.js' |
| 108 | + 'es/tools/es.HistoryButtonTool.js', |
| 109 | + 'es/tools/es.DropdownTool.js', |
| 110 | + 'es/tools/es.FormatDropdownTool.js' |
| 111 | + |
109 | 112 | ), |
110 | 113 | 'styles' => array( |
111 | 114 | 'es/styles/es.SurfaceView.css', |
Index: trunk/extensions/VisualEditor/demo/index.html |
— | — | @@ -137,6 +137,8 @@ |
138 | 138 | <script src="../modules/es/tools/es.AnnotationButtonTool.js"></script> |
139 | 139 | <script src="../modules/es/tools/es.ClearButtonTool.js"></script> |
140 | 140 | <script src="../modules/es/tools/es.HistoryButtonTool.js"></script> |
| 141 | + <script src="../modules/es/tools/es.DropdownTool.js"></script> |
| 142 | + <script src="../modules/es/tools/es.FormatDropdownTool.js"></script> |
141 | 143 | |
142 | 144 | <!-- Demo --> |
143 | 145 | <script src="../modules/sandbox/sandbox.js"></script> |
Index: trunk/extensions/VisualEditor/modules/es/tools/es.FormatDropdownTool.js |
— | — | @@ -0,0 +1,45 @@ |
| 2 | +es.FormatDropdownTool = function( toolbar, name ) {
|
| 3 | + es.DropdownTool.call( this, toolbar, name );
|
| 4 | +
|
| 5 | + this.formats = [
|
| 6 | + { 'name': 'Paragraph', 'type' : 'paragraph' },
|
| 7 | + { 'name': 'Heading Level 1', 'type' : 'heading', 'attributes': { 'level': 1 } },
|
| 8 | + { 'name': 'Heading Level 2', 'type' : 'heading', 'attributes': { 'level': 2 } },
|
| 9 | + { 'name': 'Heading Level 3', 'type' : 'heading', 'attributes': { 'level': 3 } },
|
| 10 | + { 'name': 'Heading Level 4', 'type' : 'heading', 'attributes': { 'level': 4 } },
|
| 11 | + { 'name': 'Heading Level 5', 'type' : 'heading', 'attributes': { 'level': 5 } },
|
| 12 | + { 'name': 'Heading Level 6', 'type' : 'heading', 'attributes': { 'level': 6 } },
|
| 13 | + { 'name': 'Preformatted', 'type' : 'pre' }
|
| 14 | + ];
|
| 15 | +
|
| 16 | + this.$select.append( '<option>' );
|
| 17 | +
|
| 18 | + for ( var i = 0; i < this.formats.length; i++ ) {
|
| 19 | + $( '<option>' ).val( i ).html( this.formats[i].name ).appendTo( this.$select );
|
| 20 | + }
|
| 21 | +};
|
| 22 | +
|
| 23 | +es.FormatDropdownTool.prototype.onChange = function() {
|
| 24 | + var index = this.$select.val();
|
| 25 | + if ( index in this.formats ) {
|
| 26 | + var txs = this.toolbar.surfaceView.model.getDocument().prepareLeafConversion(
|
| 27 | + this.toolbar.surfaceView.currentSelection,
|
| 28 | + this.formats[index].type,
|
| 29 | + this.formats[index].attributes
|
| 30 | + )
|
| 31 | + for ( var i = 0; i < txs.length; i++ ) {
|
| 32 | + this.toolbar.surfaceView.model.transact( txs[i] );
|
| 33 | + }
|
| 34 | + }
|
| 35 | +};
|
| 36 | +
|
| 37 | +es.FormatDropdownTool.prototype.updateState = function( annotations ) {
|
| 38 | + // ...
|
| 39 | +};
|
| 40 | +
|
| 41 | +es.Tool.tools.format = {
|
| 42 | + constructor: es.FormatDropdownTool,
|
| 43 | + name: 'format'
|
| 44 | +};
|
| 45 | +
|
| 46 | +es.extendClass( es.FormatDropdownTool, es.DropdownTool ); |
\ No newline at end of file |
Index: trunk/extensions/VisualEditor/modules/es/tools/es.DropdownTool.js |
— | — | @@ -0,0 +1,28 @@ |
| 2 | +es.DropdownTool = function( toolbar, name ) {
|
| 3 | + es.Tool.call( this, toolbar, name );
|
| 4 | +
|
| 5 | + // for es.extendClass
|
| 6 | + if ( !name ) {
|
| 7 | + return;
|
| 8 | + }
|
| 9 | +
|
| 10 | + this.$.addClass( 'es-toolbarDropdownTool' ).addClass( 'es-toolbarDropdownTool-' + name );
|
| 11 | +
|
| 12 | + this.$select = $( '<select>' );
|
| 13 | + this.$.append( this.$select );
|
| 14 | +
|
| 15 | + var _this = this;
|
| 16 | +
|
| 17 | + this.$.bind( {
|
| 18 | + 'change': function( e ) {
|
| 19 | + _this.onChange( e );
|
| 20 | + }
|
| 21 | + } );
|
| 22 | +
|
| 23 | +};
|
| 24 | +
|
| 25 | +es.DropdownTool.prototype.onChange = function() {
|
| 26 | + throw 'DropdownTool.onChange not implemented in this subclass:' + this.constructor;
|
| 27 | +};
|
| 28 | +
|
| 29 | +es.extendClass( es.DropdownTool, es.Tool ); |
\ No newline at end of file |
Index: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js |
— | — | @@ -1194,8 +1194,6 @@ |
1195 | 1195 | } |
1196 | 1196 | }, fromNode ); |
1197 | 1197 | |
1198 | | - attributes = attributes || {}; // or maybe should be null instead of empty collection |
1199 | | - |
1200 | 1198 | // TODO: skip nodes which have the same type and attributes as the target |
1201 | 1199 | |
1202 | 1200 | for ( var i = 0; i < nodes.length; i++ ) { |
Index: trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | } ); |
50 | 50 | |
51 | 51 | this.config = config || [ |
52 | | - { 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'link', 'clear' ] }, |
| 52 | + { 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'link', 'clear', 'format' ] }, |
53 | 53 | { 'name': 'history', 'items' : [ 'undo', 'redo' ] } |
54 | 54 | ]; |
55 | 55 | this.setup(); |