http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96584

Revision: 96584
Author:   tparscal
Date:     2011-09-08 16:45:38 +0000 (Thu, 08 Sep 2011)
Log Message:
-----------
Got synth (the great refactoring of 2011) working!

Modified Paths:
--------------
    trunk/parsers/wikidom/demos/synth/es.js
    trunk/parsers/wikidom/demos/synth/index.html
    trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js
    trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js
    trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js
    trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js
    trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js
    trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js
    trunk/parsers/wikidom/lib/synth/models/es.TableBlockCellModel.js
    trunk/parsers/wikidom/lib/synth/views/es.BlockView.js
    trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js
    trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js

Added Paths:
-----------
    trunk/parsers/wikidom/demos/synth/
    trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js

Modified: trunk/parsers/wikidom/demos/synth/es.js
===================================================================
--- trunk/parsers/wikidom/demos/es/es.js        2011-09-08 14:55:51 UTC (rev 
96570)
+++ trunk/parsers/wikidom/demos/synth/es.js     2011-09-08 16:45:38 UTC (rev 
96584)
@@ -1,251 +1,43 @@
 $(document).ready( function() {
-       var showData = false;
-       var doc = es.Document.newFromWikiDomDocument( { 'blocks': [
+       var doc = es.DocumentModel.newFromPlainObject( { 'blocks': [
                {
-                       "type": "paragraph",
-                       "lines": [
-                               {
-                                       '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.",
-                                       'annotations': [
-                                               // "In text display" should be 
bold
-                                               { 'type': 'bold', 'range': { 
'start': 0, 'end': 15 } },
-                                               // "line wrap" should be italic
-                                               { 'type': 'italic', 'range': { 
'start': 17, 'end': 26 } },
-                                               // "wrap is" should be a link 
to "#"
-                                               {
-                                                       'type': 'xlink',
-                                                       'data': { 'href': '#' },
-                                                       'range': { 'start': 22, 
'end': 29 }
-                                               },
-                                       ]
-                               },
-                               { 'text': "Word 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." 
},
-                       ]
+                       'type': 'paragraph',
+                       'content': {
+                               '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.',
+                               'annotations': [
+                                       // 'In text display' should be bold
+                                       { 'type': 'bold', 'range': { 'start': 
0, 'end': 15 } },
+                                       // 'line wrap' should be italic
+                                       { 'type': 'italic', 'range': { 'start': 
17, 'end': 26 } },
+                                       // 'wrap is' should be a link to '#'
+                                       {
+                                               'type': 'xlink',
+                                               'data': { 'href': '#' },
+                                               'range': { 'start': 22, 'end': 
29 }
+                                       },
+                               ]
+                       }
                },
                {
-                       "type": "paragraph",
-                       "lines": [
-                               {
-                                       'text': "It is usually done on the fly 
when viewing or printing a document, so no line break code is manually entered, 
or stored.  If the user changes the margins, the editor will either 
automatically reposition the line breaks to ensure that all the text will 
\"flow\" within the margins and remain visible, or provide the typist some 
convenient way to reposition the line breaks.",
-                                       'annotations': [
-                                               // "[citation needed]" should 
be super
-                                               {
-                                                       'type': 'template',
-                                                       'data': {
-                                                               'html': 
'<sup><small><a href="#">[citation needed]</a></small></sup>'
-                                                       },
-                                                       'range': { 'start': 
120, 'end': 121 }
-                                               }
-                                       ]
-                               },
-                               { 'text': "A soft return is the break resulting 
from line wrap or word wrap, whereas a hard return is an intentional break, 
creating a new paragraph." },
-                       ]
-               },
-               {
-                       'type': 'list',
-                       'style': 'number',
-                       'items': [
-                               {
-                                       'line': { 'text': 'Operating Systems' },
-                                       'lists': [
-                                               {
-                                                       'style': 'bullet',
-                                                       'items': [
-                                                               {
-                                                                       'line': 
{ 'text': 'Linux' },
-                                                                       
'lists': [
-                                                                               
{
-                                                                               
        'style': 'bullet',
-                                                                               
        'items': [
-                                                                               
                {
-                                                                               
                        'line': { 'text': 'Ubuntu' },
-                                                                               
                        'lists': [
-                                                                               
                                {
-                                                                               
                                        'style': 'bullet',
-                                                                               
                                        'items': [
-                                                                               
                                                {
-                                                                               
                                                        'line': {
-                                                                               
                                                                'text': 
'Desktop: Intuitive office apps, safe and fast web browsing, and seamless 
integration.  Ubuntu brings the very best technologies straight to the 
desktop.',
-                                                                               
                                                                'annotations': [
-                                                                               
                                                                        // 
"[citation needed 2]" should be super
-                                                                               
                                                                        {
-                                                                               
                                                                                
'type': 'template',
-                                                                               
                                                                                
'data': {
-                                                                               
                                                                                
        'html': '<sup><small><a href="#">[citation needed 2]</a></small></sup>'
-                                                                               
                                                                                
},
-                                                                               
                                                                                
'range': { 'start': 85, 'end': 86 }
-                                                                               
                                                                        }
-                                                                               
                                                                ]
-                                                                               
                                                        }
-                                                                               
                                                },
-                                                                               
                                                { 'line': { 'text': 'Server: 
Secure, fast and powerful, Ubuntu Server is transforming IT environments 
worldwide. Realise the full potential of your infrastructure with a reliable, 
easy-to-integrate technology platform. Lorem ipsum.. Lorem ipsum.. Lorem 
ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. 
Lorem ipsum.. Lorem ipsum.. ' } },
-                                                                               
                                                { 'line': { 'text': 'Cloud: 
Ubuntu cloud computing puts you in control of your IT infrastructure. It helps 
you access computing power as and when you need it so you can meet user demand 
more effectively.' } }
-                                                                               
                                        ]
-                                                                               
                                }
-                                                                               
                        ]
-                                                                               
                },
-                                                                               
                { 'line': { 'text': 'Fedora' } },
-                                                                               
                { 'line': { 'text': 'Gentoo' } }
-                                                                               
        ]
-                                                                               
}
-                                                                       ]
-                                                               },
-                                                               { 'line': { 
'text': 'Windows' } },
-                                                               { 'line': { 
'text': 'Mac' } }
-                                                       ]
-                                               }
-                                       ]
-                               },
-                               {
-                                       'line': {
-                                               'text': 'Second item',
-                                               'annotations': [
-                                                       {
-                                                               'type': 
'italic',
-                                                               'range': {
-                                                                       
'start': 0,
-                                                                       'end': 6
-                                                               }
-                                                       }
-                                               ]
+                       'type': 'paragraph',
+                       'content': {
+                               'text': 'It is usually done on the fly when 
viewing or printing a document, so no line break code is manually entered, or 
stored.  If the user changes the margins, the editor will either automatically 
reposition the line breaks to ensure that all the text will "flow" within the 
margins and remain visible, or provide the typist some convenient way to 
reposition the line breaks.\nA soft return is the break resulting from line 
wrap or word wrap, whereas a hard return is an intentional break, creating a 
new paragraph.',
+                               'annotations': [
+                                       // '[citation needed]' should be super
+                                       {
+                                               'type': 'template',
+                                               'data': {
+                                                       'html': '<sup><small><a 
href="#">[citation needed]</a></small></sup>'
+                                               },
+                                               'range': { 'start': 120, 'end': 
121 }
                                        }
-                               },
-                               {
-                                       'line': {
-                                               'text': 'Third item',
-                                               'annotations': [
-                                                       {
-                                                               'type': 'bold',
-                                                               'range': {
-                                                                       
'start': 0,
-                                                                       'end': 5
-                                                               }
-                                                       }
-                                               ]
-                                       }
-                               },
-                               {
-                                       'line': {
-                                               'text': 'Fourth item',
-                                               'annotations': [
-                                                       {
-                                                               'type': 'ilink',
-                                                               'range': {
-                                                                       
'start': 7,
-                                                                       'end': 
11
-                                                               },
-                                                               'data': { 
'title': 'User:JohnDoe' }
-                                                       }
-                                               ]
-                                       }
-                               }
-                       ]
+                               ]
+                       }
                },
                {
                        'type': 'paragraph',
-                       'lines': [
-                               { 'text': 'The soft returns are usually placed 
after the ends of complete words, or after the punctuation that follows 
complete words. However, word wrap may also occur following a hyphen.' },
-                               { 'text': 'Word wrap following hyphens is 
sometimes not desired, and can be avoided by using a so-called non-breaking 
hyphen instead of a regular hyphen. On the other hand, when using word 
processors, invisible hyphens, called soft hyphens, can also be inserted inside 
words so that word wrap can occur following the soft hyphens.' },
-                               { 'text': 'Sometimes, word wrap is not 
desirable between words. In such cases, word wrap can usually be avoided by 
using a hard space or non-breaking space between the words, instead of regular 
spaces.' },
-                               { 'text': 
'OccasionallyThereAreWordsThatAreSoLongTheyExceedTheWidthOfTheLineAndEndUpWrappingBetweenMultipleLines.'
 },
-                               { 'text': 'Text might have\ttabs\tin it too. 
Not all text will end in a line breaking character' }
-                       ]
+                       'content': { 'text': 'The soft returns are usually 
placed after the ends of complete words, or after the punctuation that follows 
complete words. However, word wrap may also occur following a hyphen.\nWord 
wrap following hyphens is sometimes not desired, and can be avoided by using a 
so-called non-breaking hyphen instead of a regular hyphen. On the other hand, 
when using word processors, invisible hyphens, called soft hyphens, can also be 
inserted inside words so that word wrap can occur following the soft 
hyphens.\nSometimes, word wrap is not desirable between words. In such cases, 
word wrap can usually be avoided by using a hard space or non-breaking space 
between the words, instead of regular 
spaces.\nOccasionallyThereAreWordsThatAreSoLongTheyExceedTheWidthOfTheLineAndEndUpWrappingBetweenMultipleLines.\nText
 might have\ttabs\tin it too. Not all text will end in a line breaking 
character' }
                }
        ] } );
-       var surface = new es.Surface( $('#es-editor'), doc );
-       
-       $( '#es-toolbar .es-toolbarTool' ).mousedown( function( e ) {
-               e.preventDefault();
-               return false;
-       } );
-       $( '#es-toolbar-bold' ).click( function() {
-                       surface.annotateContent( 'toggle', { 'type': 'bold' } );
-                       return false;
-               } );
-       $( '#es-toolbar-italic' ).click( function() {
-               surface.annotateContent( 'toggle', { 'type': 'italic' } );
-               return false;
-       } );
-       $( '#es-toolbar-small' ).click( function() {
-               surface.annotateContent( 'toggle', {
-                       'type': 'size',
-                       'data': { 'type': 'small' }
-               } );
-               return false;
-       } );
-       $( '#es-toolbar-big' ).click( function() {
-               surface.annotateContent( 'toggle', {
-                       'type': 'size',
-                       'data': { 'type': 'big' }
-               } );
-               return false;
-       } );
-       $( '#es-toolbar-sub' ).click( function() {
-               surface.annotateContent( 'toggle', {
-                       'type': 'script',
-                       'data': { 'type': 'sub' }
-               } );
-               return false;
-       } );
-       $( '#es-toolbar-super' ).click( function() {
-               surface.annotateContent( 'toggle', {
-                       'type': 'script',
-                       'data': { 'type': 'super' }
-               } );
-               return false;
-       } );
-       $( '#es-toolbar-link' ).click( function() {
-               surface.annotateContent( 'toggle', {
-                       'type': 'xlink',
-                       'data': { 'href': '#' }
-               } );
-               return false;
-       } );
-       $( '#es-toolbar-clear' ).click( function() {
-               surface.annotateContent( 'remove', { 'type': 'all' } );
-               return false;
-       } );
-       $( '.es-toolbarGroup-preview .es-toolbarTool' ).click( function() {
-               var type = $(this).attr( 'rel' );
-               showData = showData === type ? false : type;
-               if ( showData ) {
-                       $( 'body' ).addClass( 'es-showData' );
-                       $( '.es-preview' ).hide();
-                       $( '#es-preview-' + type ).show();
-                       $( '.es-toolbarGroup-preview .es-toolbarTool' 
).removeClass( 'es-toolbarTool-down' );
-                       $(this).addClass( 'es-toolbarTool-down' );
-               } else {
-                       $( 'body' ).removeClass( 'es-showData' );
-                       $(this).removeClass( 'es-toolbarTool-down' );
-               }
-               doc.renderBlocks();
-               doc.emit( 'update' );
-       } );
-       // Setup data updates
-       var previewTimeout = null,
-               context = new es.Document.Context();
-       doc.on( 'update', function() {
-               if ( showData ) {
-                       if ( previewTimeout !== null ) {
-                               clearTimeout( previewTimeout );
-                       }
-                       previewTimeout = setTimeout( function () {
-                               switch ( showData ) {
-                                       case 'json':
-                                               $( '#es-preview-json' )
-                                                       .text( doc.serialize( 
'json', context, { 'indentWith': '  ' } ) );
-                                               break;
-                                       case 'wikitext':
-                                               $( '#es-preview-wikitext' 
).text( doc.serialize( 'wikitext', context ) );
-                                               break;
-                                       case 'html':
-                                               $( '#es-preview-html' ).text( 
doc.serialize( 'html', context ) );
-                                               break;
-                                       case 'render':
-                                               $( '#es-preview-render' ).html( 
doc.serialize( 'html', context ) );
-                                               break;
-                               }
-                       }, 100 );
-               }
-       } );
-} );
\ No newline at end of file
+       var surface = new es.SurfaceView( $('#es-editor'), doc );
+} );

Modified: trunk/parsers/wikidom/demos/synth/index.html
===================================================================
--- trunk/parsers/wikidom/demos/es/index.html   2011-09-08 14:55:51 UTC (rev 
96570)
+++ trunk/parsers/wikidom/demos/synth/index.html        2011-09-08 16:45:38 UTC 
(rev 96584)
@@ -54,30 +54,23 @@
                
                <!-- EditSurface -->
                <script src="../../lib/jquery.js"></script>
-               <script src="../../lib/es/es.js"></script>
-               <script src="../../lib/es/es.EventEmitter.js"></script>
-               <script src="../../lib/es/es.Position.js"></script>
-               <script src="../../lib/es/es.Location.js"></script>
-               <script src="../../lib/es/es.Range.js"></script>
-               <script src="../../lib/es/es.Selection.js"></script>
-               <script src="../../lib/es/es.Content.js"></script>
-               <script src="../../lib/es/es.ContentFlow.js"></script>
-               <script src="../../lib/es/es.Container.js"></script>
-               <script src="../../lib/es/es.DomContainer.js"></script>
-               <script src="../../lib/es/es.Block.js"></script>
-               <script src="../../lib/es/es.Document.js"></script>
-               <script src="../../lib/es/es.AnnotationSerializer.js"></script>
-               <script src="../../lib/es/es.Document.Context.js"></script>
-               <script src="../../lib/es/es.Document.Serializer.js"></script>
-               <script 
src="../../lib/es/es.Document.WikitextSerializer.js"></script>
-               <script 
src="../../lib/es/es.Document.HtmlSerializer.js"></script>
-               <script 
src="../../lib/es/es.Document.JsonSerializer.js"></script>
-               <script src="../../lib/es/es.Surface.js"></script>
-               <script src="../../lib/es/es.ParagraphBlock.js"></script>
-               <script src="../../lib/es/es.ListBlockList.js"></script>
-               <script src="../../lib/es/es.ListBlockItem.js"></script>
-               <script src="../../lib/es/es.ListBlock.js"></script>
-               <script src="../../lib/es/es.Cursor.js"></script>
+               <script src="../../lib/synth/es.js"></script>
+               <script src="../../lib/synth/es.Range.js"></script>
+               <script src="../../lib/synth/bases/es.EventEmitter.js"></script>
+               <script 
src="../../lib/synth/bases/es.AggregateArray.js"></script>
+               <script 
src="../../lib/synth/bases/es.ModelContainer.js"></script>
+               <script 
src="../../lib/synth/bases/es.ModelContainerItem.js"></script>
+               <script 
src="../../lib/synth/bases/es.ViewContainer.js"></script>
+               <script 
src="../../lib/synth/bases/es.ViewContainerItem.js"></script>
+               <script 
src="../../lib/synth/models/es.DocumentModel.js"></script>
+               <script src="../../lib/synth/models/es.BlockModel.js"></script>
+               <script 
src="../../lib/synth/models/es.ContentModel.js"></script>
+               <script 
src="../../lib/synth/models/es.ParagraphBlockModel.js"></script>
+               <script src="../../lib/synth/views/es.BlockView.js"></script>
+               <script src="../../lib/synth/views/es.ContentView.js"></script>
+               <script src="../../lib/synth/views/es.DocumentView.js"></script>
+               <script 
src="../../lib/synth/views/es.ParagraphBlockView.js"></script>
+               <script src="../../lib/synth/views/es.SurfaceView.js"></script>
                
                <!-- Demo -->
                <script src="es.js"></script>

Modified: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js   2011-09-08 
16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js   2011-09-08 
16:45:38 UTC (rev 96584)
@@ -16,6 +16,9 @@
 es.ViewContainer = function( containerModel, typeName, tagName ) {
        es.EventEmitter.call( this );
        this.containerModel = containerModel;
+       if ( !this.containerModel ) {
+               return;
+       }
        this.views = [];
        if ( typeof typeName !== 'string' ) {
                typeName = 'viewContainer';
@@ -86,7 +89,9 @@
        // Auto-add views for existing items
        var itemModels = this.containerModel.all();
        for ( var i = 0; i < itemModels.length; i++ ) {
-               this.views.push( itemModels[i].createView() );
+               var itemView = itemModels[i].createView();
+               this.views.push( itemView );
+               this.$.append( itemView.$ );
        }
 };
 

Modified: trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js     2011-09-08 
16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js     2011-09-08 
16:45:38 UTC (rev 96584)
@@ -10,7 +10,7 @@
  */
 es.BlockModel = function( traits ) {
        es.EventEmitter.call( this );
-       es.ContainerItem.call( this, 'document' );
+       es.ModelContainerItem.call( this, 'document' );
        this.traits = traits || [];
 };
 
@@ -37,7 +37,7 @@
  */
 es.BlockModel.newFromPlainObject = function( obj ) {
        if ( obj.type in es.BlockModel.constructors ) {
-               return new es.BlockModel.constructors[obj.type]( obj );
+               return es.BlockModel.constructors[obj.type]( obj );
        }
        return null;
 };
@@ -174,4 +174,4 @@
 };
 
 es.extend( es.BlockModel, es.EventEmitter );
-es.extend( es.BlockModel, es.ContainerItem );
+es.extend( es.BlockModel, es.ModelContainerItem );

Modified: trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js   2011-09-08 
16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js   2011-09-08 
16:45:38 UTC (rev 96584)
@@ -24,7 +24,7 @@
  * @param text {String} Text to convert
  * @returns {es.ContentModel} Content object containing converted text
  */
-es.Content.newFromText = function( text ) {
+es.ContentModel.newFromText = function( text ) {
        return new es.ContentModel( text.split('') );
 };
 
@@ -73,7 +73,7 @@
                attributes = !$.isPlainObject( obj.attributes ) ? {} : 
$.extend( true, {}, obj.attributes );
                // Render annotations
                if ( $.isArray( obj.annotations ) ) {
-                       $.each( obj.annotations, function( src ) {
+                       $.each( obj.annotations, function( i, src ) {
                                // Build simplified annotation object
                                var dst = { 'type': src.type };
                                if ( 'data' in src ) {
@@ -108,7 +108,7 @@
  * @method
  * @returns {Integer} Length of content data
  */
-es.Content.prototype.getLength = function() {
+es.ContentModel.prototype.getLength = function() {
        return this.data.length; 
 };
 
@@ -119,7 +119,7 @@
  * @param name {String} Name of attribute to get value for
  * @returns {Mixed} Value of attribute, or undefined if attribute does not 
exist
  */
-es.Content.prototype.getAttribute = function( name ) {
+es.ContentModel.prototype.getAttribute = function( name ) {
        return this.attributes[name];
 };
 
@@ -130,7 +130,7 @@
  * @param name {String} Name of attribute to set value for
  * @param value {Mixed} Value to set attribute to
  */
-es.Content.prototype.setAttribute = function( name, value ) {
+es.ContentModel.prototype.setAttribute = function( name, value ) {
        this.attributes[name] = value;
 };
 
@@ -150,7 +150,7 @@
  * @param render {Boolean} If annotations should have any influence on output
  * @returns {String} Text within given range
  */
-es.Content.prototype.getText = function( range, render ) {
+es.ContentModel.prototype.getText = function( range, render ) {
        if ( !range ) {
                range = new es.Range( 0, this.data.length );
        } else {
@@ -175,7 +175,7 @@
  * @param range {es.Range} Range of content to get
  * @returns {es.ContentModel} Content object containing data within range
  */
-es.Content.prototype.getContent = function( range ) {
+es.ContentModel.prototype.getContent = function( range ) {
        if ( !range ) {
                range = new es.Range( 0, this.data.length );
        }
@@ -190,7 +190,7 @@
  * @param range {es.Range} Range of data to get
  * @returns {Array} Array of plain text and/or annotated characters within 
range
  */
-es.Content.prototype.getData = function( range ) {
+es.ContentModel.prototype.getData = function( range ) {
        if ( !range ) {
                range = new es.Range( 0, this.data.length );
        }
@@ -205,7 +205,7 @@
  * @param range {es.Range} Range of content to check
  * @returns {Boolean} If there's any floating objects in range
  */
-es.Content.prototype.hasFloatingObjects = function( range ) {
+es.ContentModel.prototype.hasFloatingObjects = function( range ) {
        if ( !range ) {
                range = new es.Range( 0, this.data.length );
        }
@@ -213,7 +213,7 @@
        for ( var i = 0; i < this.data.length; i++ ) {
                if ( this.data[i].length > 1 ) {
                        for ( var j = 1; j < this.data[i].length; j++ ) {
-                               var isFloating = 
es.Content.annotationRenderers[this.data[i][j].type].float;
+                               var isFloating = 
es.ContentModel.annotationRenderers[this.data[i][j].type].float;
                                if ( isFloating && typeof isFloating === 
'function' ) {
                                        isFloating = isFloating( 
this.data[i][j].data );
                                }
@@ -233,7 +233,7 @@
  * @param offset {Integer} Offset to find word nearest to
  * @returns {Object} Range object of boundaries
  */
-es.Content.prototype.getWordBoundaries = function( offset ) {
+es.ContentModel.prototype.getWordBoundaries = function( offset ) {
        if ( offset < 0 || offset > this.data.length ) {
                throw 'Out of bounds error. Offset expected to be >= 0 and <= 
to ' + this.data.length;
        }
@@ -264,7 +264,7 @@
  * @method
  * @returns {Object}
  */
-es.Content.prototype.getPlainObject = function() {
+es.ContentModel.prototype.getPlainObject = function() {
        var stack = [];
        // Text and annotations
        function start( offset, annotation ) {
@@ -350,7 +350,7 @@
  * @param strict {Boolean} Optionally compare annotation data as well as type
  * @returns {Array} List of indexes of covered characters within content data
  */
-es.Content.prototype.coverageOfAnnotation = function( range, annotation, 
strict ) {
+es.ContentModel.prototype.coverageOfAnnotation = function( range, annotation, 
strict ) {
        var coverage = [];
        var i, index;
        for ( i = range.start; i < range.end; i++ ) {
@@ -383,7 +383,7 @@
  * @param strict {Boolean} Optionally compare annotation data as well as type
  * @returns {Integer} Index of first instance of annotation in content
  */
-es.Content.prototype.indexOfAnnotation = function( offset, annotation, strict 
) {
+es.ContentModel.prototype.indexOfAnnotation = function( offset, annotation, 
strict ) {
        var annotatedChar = this.data[offset];
        var i;
        if ( typeof annotatedChar !== 'string' ) {
@@ -413,7 +413,7 @@
  * @emits "insert" with offset and content data properties
  * @emits "change" with type:"insert" data property
  */
-es.Content.prototype.insert = function( offset, content, autoAnnotate ) {
+es.ContentModel.prototype.insert = function( offset, content, autoAnnotate ) {
        if ( autoAnnotate ) {
                // TODO: Prefer to not take annotations from a neighbor that's 
a space character
                var neighbor = this.data[Math.max( offset - 1, 0 )];
@@ -444,7 +444,7 @@
  * @emits "remove" with range data property
  * @emits "change" with type:"remove" data property
  */
-es.Content.prototype.remove = function( range ) {
+es.ContentModel.prototype.remove = function( range ) {
        range.normalize();
        this.data.splice( range.start, range.getLength() );
        this.emit( 'remove', {
@@ -460,7 +460,7 @@
  * @emits "clear"
  * @emits "change" with type:"clear" data property
  */
-es.Content.prototype.clear = function() {
+es.ContentModel.prototype.clear = function() {
        this.data = [];
        this.emit( 'clear' );
        this.emit( 'change', { 'type': 'clear' } );
@@ -482,7 +482,7 @@
  * @emits "annotate" with method, annotation and range data properties
  * @emits "change" with type:"annotate" data property
  */
-es.Content.prototype.annotate = function( method, annotation, range ) {
+es.ContentModel.prototype.annotate = function( method, annotation, range ) {
        // Support calling without a range argument, using the full content 
range as default
        if ( !range ) {
                range = new es.Range( 0, this.data.length );

Modified: trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js  2011-09-08 
16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js  2011-09-08 
16:45:38 UTC (rev 96584)
@@ -9,9 +9,8 @@
  * @property attributes {Object}
  */
 es.DocumentModel = function( blocks, attributes ) {
-       es.EventEmitter.call( this );
-       es.Container.call( this, 'blocks' );
-       this.blocks = new es.ContentSeries( blocks || [] );
+       es.ModelContainer.call( this, 'blocks' );
+       this.blocks = new es.AggregateArray( blocks || [] );
        this.attributes = attributes || {};
 };
 
@@ -61,5 +60,4 @@
        return this.blocks.getContentLength();
 };
 
-es.extend( es.DocumentModel, es.EventEmitter );
-es.extend( es.DocumentModel, es.Container );
+es.extend( es.DocumentModel, es.ModelContainer );

Modified: trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js 2011-09-08 
16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js 2011-09-08 
16:45:38 UTC (rev 96584)
@@ -34,7 +34,7 @@
        styles.push( obj.style || 'bullet' );
        var items = [];
        if ( $.isArray( obj.items ) ) {
-               $.each( obj.items, function( item ) {
+               $.each( obj.items, function( i, item ) {
                        if ( $.isPlainObject( item.content ) ) {
                                items.push(
                                        new es.ListBlockItemModel(
@@ -44,7 +44,7 @@
                                );
                        }
                        if ( $.isArray( item.lists ) ) {
-                               $.each( item.lists, function( list ) {
+                               $.each( item.lists, function( i, list ) {
                                        items = items.concat( 
es.ListBlockList.flattenList( list, styles ) );
                                } );
                        }

Modified: trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js    
2011-09-08 16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js    
2011-09-08 16:45:38 UTC (rev 96584)
@@ -21,7 +21,7 @@
  * @param obj {Object}
  */
 es.ParagraphBlockModel.newFromPlainObject = function( obj ) {
-       return new es.ParagraphBlockModel( es.ContentModel.newFromPlainObject( 
obj ) );
+       return new es.ParagraphBlockModel( es.ContentModel.newFromPlainObject( 
obj.content ) );
 };
 
 /* Methods */
@@ -54,7 +54,7 @@
 };
 
 // Register constructor
-es.BlockModel.constructors['paragraph'] = es.ParagraphBlockModel;
+es.BlockModel.constructors['paragraph'] = 
es.ParagraphBlockModel.newFromPlainObject;
 
 /* Inheritance */
 

Modified: trunk/parsers/wikidom/lib/synth/models/es.TableBlockCellModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.TableBlockCellModel.js    
2011-09-08 16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/models/es.TableBlockCellModel.js    
2011-09-08 16:45:38 UTC (rev 96584)
@@ -3,13 +3,13 @@
  * 
  * @class
  * @constructor
- * @param doc {es.DocumentModel}
+ * @param documentModel {es.DocumentModel}
  * @param attributes {Object}
- * @property document {es.DocumentModel}
+ * @property documentModel {es.DocumentModel}
  * @property attributes {Object}
  */
-es.TableBlockCellModel = function( doc, attributes ) {
-       this.document = doc || null;
+es.TableBlockCellModel = function( documentModel, attributes ) {
+       this.documentModel = documentModel || null;
        this.attributes = attributes || {};
 };
 
@@ -49,8 +49,8 @@
  */
 es.TableBlockRowModel.prototype.getPlainObject = function() {
        var obj = {};
-       if ( this.document ) {
-               obj.document = this.document;
+       if ( this.documentModel ) {
+               obj.document = this.documentModel;
        }
        if ( !$.isEmptyObject( this.attributes ) ) {
                obj.attributes = $.extend( true, {}, this.attributes );

Modified: trunk/parsers/wikidom/lib/synth/views/es.BlockView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.BlockView.js       2011-09-08 
16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/views/es.BlockView.js       2011-09-08 
16:45:38 UTC (rev 96584)
@@ -8,8 +8,9 @@
  * @param typeName {String} Name of block type (optional, default: "block")
  * @param tagName {String} HTML tag name to use in rendering (optional, 
default: "div")
  */
-es.BlockView = function( typeName, tagName ) {
-       es.ViewContainerItem.call( this, 'document', typeName || 'block', 
tagName || 'div' );
+es.BlockView = function( blockModel, typeName, tagName ) {
+       es.ViewContainerItem.call( this, blockModel, typeName || 'block', 
tagName || 'div' );
+       this.$.addClass( 'editSurface-block' );
 };
 
 /**

Modified: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js    2011-09-08 
16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js    2011-09-08 
16:45:38 UTC (rev 96584)
@@ -1,7 +1,16 @@
 es.DocumentView = function( documentModel ) {
-       es.ViewContainer.call( this, documentModel, 'blocks' );
+       es.ViewContainer.call( this, documentModel, 'document' );
 };
 
+/**
+ * Render content.
+ */
+es.DocumentView.prototype.renderContent = function() {
+       for ( var i = 0; i < this.views.length; i++ ) {
+               this.views[i].renderContent();
+       }
+};
+
 /* Inheritance */
 
 es.extend( es.DocumentView, es.ViewContainer );

Modified: trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js      
2011-09-08 16:34:59 UTC (rev 96583)
+++ trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js      
2011-09-08 16:45:38 UTC (rev 96584)
@@ -1,9 +1,37 @@
 /**
- * 
+ * Creates an es.ParagraphBlockView object.
  */
 es.ParagraphBlockView = function( model ) {
-       es.BlockView.call( this, 'paragraph' );
-       this.model = model;
+       es.BlockView.call( this, model, 'paragraph' );
+       this.contentView = new es.ContentView( this.$, this.model.content );
 };
 
+/**
+ * Render content.
+ */
+es.ParagraphBlockView.prototype.renderContent = function() {
+       this.contentView.render();
+};
+
+/**
+ * Gets offset within content of position.
+ */
+es.ParagraphBlockView.getContentOffset = function( position ) {
+       return this.contentView.getOffset( position );
+};
+
+/**
+ * Gets rendered position of offset within content.
+ */
+es.ParagraphBlockView.getRenderedPosition = function( offset ) {
+       return this.contentView.getPosition( position );
+};
+
+/**
+ * Gets rendered line index of offset within content.
+ */
+es.ParagraphBlockView.getRenderedLineIndex = function( offset ) {
+       return this.contentView.getLineIndex( position );
+};
+
 es.extend( es.ParagraphBlockView, es.BlockView );

Added: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js                     
        (rev 0)
+++ trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js     2011-09-08 
16:45:38 UTC (rev 96584)
@@ -0,0 +1,22 @@
+/**
+ * Creates an es.SurfaceView object.
+ */
+es.SurfaceView = function( $container, documentModel ) {
+       this.$ = $container.addClass( 'editSurface' );
+       this.documentModel = documentModel;
+       this.documentView = new es.DocumentView( this.documentModel );
+       this.$.append( this.documentView.$ );
+       this.width = null;
+       
+       var surface = this;
+       $(window).resize( function() {
+               var width = surface.$.width();
+               if ( surface.width !== width ) {
+                       surface.width = width;
+                       surface.documentView.renderContent();
+               }
+       } );
+       
+       // First render
+       this.documentView.renderContent();
+};


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to