r98141 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98140‎ | r98141 | r98142 >
Date:15:42, 26 September 2011
Author:inez
Status:deferred
Tags:
Comment:
Very early - just proof of concept - implementation of wikidom/text headings
Modified paths:
  • /trunk/parsers/wikidom/demos/synth/es.js (modified) (history)
  • /trunk/parsers/wikidom/demos/synth/index.html (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/es.Surface.css (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.HeadingBlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.HeadingBlockView.js (added) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/models/es.HeadingBlockModel.js
@@ -10,8 +10,12 @@
1111 */
1212 es.HeadingBlockModel = function( content, level ) {
1313 es.BlockModel.call( this, ['hasContent', 'isAnnotatable'] );
14 - this.content = content || null;
 14+ this.content = content || new es.ContentModel();
1515 this.level = level || 0;
 16+ var model = this;
 17+ this.content.on( 'change', function() {
 18+ model.emit( 'update' );
 19+ } );
1620 };
1721
1822 /* Static Methods */
@@ -24,7 +28,7 @@
2529 * @param obj {Object}
2630 */
2731 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 );
2933 };
3034
3135 /* Methods */
@@ -89,7 +93,7 @@
9094 };
9195
9296 // Register constructor
93 -es.BlockModel.constructors['heading'] = es.HeadingBlockModel;
 97+es.BlockModel.constructors['heading'] = es.HeadingBlockModel.newFromPlainObject;
9498
9599 /* Inheritance */
96100
Index: trunk/parsers/wikidom/lib/synth/es.Surface.css
@@ -25,6 +25,7 @@
2626 -webkit-user-select: none;
2727 }
2828
 29+.editSurface-headingBlock,
2930 .editSurface-tableBlock,
3031 .editSurface-listBlock,
3132 .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 @@
22 $(document).ready( function() {
33 var doc = es.DocumentModel.newFromPlainObject( { 'blocks': [
44 {
 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+ {
521 'type': 'paragraph',
622 'content': {
723 '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 @@
8080 <script src="../../lib/synth/models/es.TableBlockModel.js"></script>
8181 <script src="../../lib/synth/models/es.TableBlockRowModel.js"></script>
8282 <script src="../../lib/synth/models/es.TableBlockCellModel.js"></script>
 83+ <script src="../../lib/synth/models/es.HeadingBlockModel.js"></script>
8384
8485 <!-- Views -->
8586 <script src="../../lib/synth/views/es.BlockView.js"></script>
@@ -91,6 +92,7 @@
9293 <script src="../../lib/synth/views/es.TableBlockView.js"></script>
9394 <script src="../../lib/synth/views/es.TableBlockRowView.js"></script>
9495 <script src="../../lib/synth/views/es.TableBlockCellView.js"></script>
 96+ <script src="../../lib/synth/views/es.HeadingBlockView.js"></script>
9597
9698 <!-- Demo -->
9799 <script src="es.js"></script>

Status & tagging log