Index: trunk/parsers/wikidom/lib/synth/models/es.HeadingBlockModel.js |
— | — | @@ -10,8 +10,12 @@ |
11 | 11 | */ |
12 | 12 | es.HeadingBlockModel = function( content, level ) { |
13 | 13 | es.BlockModel.call( this, ['hasContent', 'isAnnotatable'] ); |
14 | | - this.content = content || null; |
| 14 | + this.content = content || new es.ContentModel(); |
15 | 15 | this.level = level || 0; |
| 16 | + var model = this; |
| 17 | + this.content.on( 'change', function() { |
| 18 | + model.emit( 'update' ); |
| 19 | + } ); |
16 | 20 | }; |
17 | 21 | |
18 | 22 | /* Static Methods */ |
— | — | @@ -24,7 +28,7 @@ |
25 | 29 | * @param obj {Object} |
26 | 30 | */ |
27 | 31 | es.HeadingBlockModel.newFromPlainObject = function( obj ) { |
28 | | - return new es.HeadingBlockModel( obj.content, obj.level ); |
| 32 | + return new es.HeadingBlockModel( es.ContentModel.newFromPlainObject( obj.content ), obj.level ); |
29 | 33 | }; |
30 | 34 | |
31 | 35 | /* Methods */ |
— | — | @@ -89,7 +93,7 @@ |
90 | 94 | }; |
91 | 95 | |
92 | 96 | // Register constructor |
93 | | -es.BlockModel.constructors['heading'] = es.HeadingBlockModel; |
| 97 | +es.BlockModel.constructors['heading'] = es.HeadingBlockModel.newFromPlainObject; |
94 | 98 | |
95 | 99 | /* Inheritance */ |
96 | 100 | |
Index: trunk/parsers/wikidom/lib/synth/es.Surface.css |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | -webkit-user-select: none; |
27 | 27 | } |
28 | 28 | |
| 29 | +.editSurface-headingBlock, |
29 | 30 | .editSurface-tableBlock, |
30 | 31 | .editSurface-listBlock, |
31 | 32 | .editSurface-paragraphBlock { |
Index: trunk/parsers/wikidom/lib/synth/views/es.HeadingBlockView.js |
— | — | @@ -0,0 +1,31 @@ |
| 2 | +es.HeadingBlockView = function( model ) { |
| 3 | + es.BlockView.call( this, model, $('<h' + model.level +'/>') ); |
| 4 | + this.$.addClass( 'editSurface-headingBlock' ); |
| 5 | + this.contentView = new es.ContentView( this.$, this.model.content ); |
| 6 | + var view = this; |
| 7 | + this.contentView.on( 'update', function() { |
| 8 | + view.emit('update'); |
| 9 | + } ); |
| 10 | +}; |
| 11 | + |
| 12 | +es.HeadingBlockView.prototype.drawSelection = function( range ) { |
| 13 | + this.contentView.drawSelection( range ); |
| 14 | +}; |
| 15 | + |
| 16 | +es.HeadingBlockView.prototype.clearSelection = function( range ) { |
| 17 | + this.contentView.clearSelection(); |
| 18 | +}; |
| 19 | + |
| 20 | +es.HeadingBlockView.prototype.renderContent = function() { |
| 21 | + this.contentView.render(); |
| 22 | +}; |
| 23 | + |
| 24 | +es.HeadingBlockView.prototype.getLength = function() { |
| 25 | + return this.model.getContentLength(); |
| 26 | +}; |
| 27 | + |
| 28 | +es.HeadingBlockView.prototype.getOffsetFromPosition = function( position ) { |
| 29 | + return this.contentView.getOffset( position ); |
| 30 | +}; |
| 31 | + |
| 32 | +es.extend( es.HeadingBlockView, es.BlockView ); |
Index: trunk/parsers/wikidom/demos/synth/es.js |
— | — | @@ -1,6 +1,22 @@ |
2 | 2 | $(document).ready( function() { |
3 | 3 | var doc = es.DocumentModel.newFromPlainObject( { 'blocks': [ |
4 | 4 | { |
| 5 | + 'type': 'heading', |
| 6 | + 'level': 2, |
| 7 | + 'content': { |
| 8 | + 'text': 'This is a heading', |
| 9 | + 'annotations': [ |
| 10 | + { |
| 11 | + 'type': 'italic', |
| 12 | + 'range': { |
| 13 | + 'start': 10, |
| 14 | + 'end': 17 |
| 15 | + } |
| 16 | + } |
| 17 | + ] |
| 18 | + } |
| 19 | + }, |
| 20 | + { |
5 | 21 | 'type': 'paragraph', |
6 | 22 | 'content': { |
7 | 23 | 'text': 'In text display, line wrap is the feature of continuing on a new line when a line is full, such that each line fits in the viewable window, allowing text to be read from top to bottom without any horizontal scrolling.\nWord wrap is the additional feature of most text editors, word processors, and web browsers, of breaking lines between and not within words, except when a single word is longer than a line.', |
Index: trunk/parsers/wikidom/demos/synth/index.html |
— | — | @@ -79,6 +79,7 @@ |
80 | 80 | <script src="../../lib/synth/models/es.TableBlockModel.js"></script> |
81 | 81 | <script src="../../lib/synth/models/es.TableBlockRowModel.js"></script> |
82 | 82 | <script src="../../lib/synth/models/es.TableBlockCellModel.js"></script> |
| 83 | + <script src="../../lib/synth/models/es.HeadingBlockModel.js"></script> |
83 | 84 | |
84 | 85 | <!-- Views --> |
85 | 86 | <script src="../../lib/synth/views/es.BlockView.js"></script> |
— | — | @@ -91,6 +92,7 @@ |
92 | 93 | <script src="../../lib/synth/views/es.TableBlockView.js"></script> |
93 | 94 | <script src="../../lib/synth/views/es.TableBlockRowView.js"></script> |
94 | 95 | <script src="../../lib/synth/views/es.TableBlockCellView.js"></script> |
| 96 | + <script src="../../lib/synth/views/es.HeadingBlockView.js"></script> |
95 | 97 | |
96 | 98 | <!-- Demo --> |
97 | 99 | <script src="es.js"></script> |