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

Revision: 96702
Author:   tparscal
Date:     2011-09-09 22:51:09 +0000 (Fri, 09 Sep 2011)
Log Message:
-----------
Added es.SurfaceModel and basic version of es.Selection

Modified Paths:
--------------
    trunk/parsers/wikidom/demos/synth/es.js
    trunk/parsers/wikidom/demos/synth/index.html
    trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js

Added Paths:
-----------
    trunk/parsers/wikidom/lib/synth/controllers/es.SurfaceController.js
    trunk/parsers/wikidom/lib/synth/es.Selection.js
    trunk/parsers/wikidom/lib/synth/models/es.SurfaceModel.js

Modified: trunk/parsers/wikidom/demos/synth/es.js
===================================================================
--- trunk/parsers/wikidom/demos/synth/es.js     2011-09-09 22:48:14 UTC (rev 
96701)
+++ trunk/parsers/wikidom/demos/synth/es.js     2011-09-09 22:51:09 UTC (rev 
96702)
@@ -139,5 +139,5 @@
                        ]
                }
        ] } );
-       var surface = new es.SurfaceView( $('#es-editor'), doc );
+       var surface = new es.SurfaceView( $('#es-editor'), new es.SurfaceModel( 
doc ) );
 } );

Modified: trunk/parsers/wikidom/demos/synth/index.html
===================================================================
--- trunk/parsers/wikidom/demos/synth/index.html        2011-09-09 22:48:14 UTC 
(rev 96701)
+++ trunk/parsers/wikidom/demos/synth/index.html        2011-09-09 22:51:09 UTC 
(rev 96702)
@@ -56,12 +56,14 @@
                <script src="../../lib/jquery.js"></script>
                <script src="../../lib/synth/es.js"></script>
                <script src="../../lib/synth/es.Range.js"></script>
+               <script src="../../lib/synth/es.Selection.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.SurfaceModel.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>

Added: trunk/parsers/wikidom/lib/synth/controllers/es.SurfaceController.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/controllers/es.SurfaceController.js         
                (rev 0)
+++ trunk/parsers/wikidom/lib/synth/controllers/es.SurfaceController.js 
2011-09-09 22:51:09 UTC (rev 96702)
@@ -0,0 +1,4 @@
+es.SurfaceController = function() {
+       
+};
+

Added: trunk/parsers/wikidom/lib/synth/es.Selection.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/es.Selection.js                             
(rev 0)
+++ trunk/parsers/wikidom/lib/synth/es.Selection.js     2011-09-09 22:51:09 UTC 
(rev 96702)
@@ -0,0 +1,38 @@
+/**
+ * Content selection, a pair of locations.
+ * 
+ * @class
+ * @constructor
+ * @param from {es.Location} Starting location
+ * @param to {es.Location} Ending location
+ * @property from {es.Location} Starting location
+ * @property to {es.Location} Ending location
+ * @property start {es.Location} Normalized starting location
+ * @property end {es.Location} Normalized ending location
+ */
+es.Selection = function( from, to ) {
+       this.from = from;
+       this.to = to;
+       this.start = from;
+       this.end = to;
+}
+
+/* Methods */
+
+/**
+ * Sets start and end properties, ensuring start is always before end.
+ * 
+ * This should always be called before using the start or end properties. Do 
not call this unless
+ * you are about to use these properties.
+ * 
+ * @method
+ */
+es.Selection.prototype.normalize = function() {
+       if ( this.from.compareWith( this.to ) < 1 ) {
+               this.start = this.from;
+               this.end = this.to;
+       } else {
+               this.start = this.to;
+               this.end = this.from;
+       }
+};

Added: trunk/parsers/wikidom/lib/synth/models/es.SurfaceModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.SurfaceModel.js                   
        (rev 0)
+++ trunk/parsers/wikidom/lib/synth/models/es.SurfaceModel.js   2011-09-09 
22:51:09 UTC (rev 96702)
@@ -0,0 +1,25 @@
+es.SurfaceModel = function( doc ) {
+       es.EventEmitter.call( this );
+       this.selection = new es.Selection();
+       this.doc = doc || new es.DocumentModel();
+       
+       var model = this;
+       this.doc.on( 'update', function() {
+               model.emit( 'update' );
+       } );
+};
+
+es.SurfaceModel.prototype.getSelection = function() {
+       return this.selection;
+};
+
+es.SurfaceModel.prototype.setSelection = function( selection ) {
+       this.selection = selection;
+       this.emit( 'select', this.selection );
+};
+
+es.SurfaceModel.prototype.getDocument = function() {
+       return this.doc;
+};
+
+es.extend( es.SurfaceModel, es.EventEmitter );

Modified: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js     2011-09-09 
22:48:14 UTC (rev 96701)
+++ trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js     2011-09-09 
22:51:09 UTC (rev 96702)
@@ -1,10 +1,10 @@
 /**
  * Creates an es.SurfaceView object.
  */
-es.SurfaceView = function( $container, documentModel ) {
+es.SurfaceView = function( $container, surfaceModel ) {
        this.$ = $container.addClass( 'editSurface' );
-       this.documentModel = documentModel;
-       this.documentView = new es.DocumentView( this.documentModel );
+       this.model = surfaceModel;
+       this.documentView = new es.DocumentView( this.model.getDocument() );
        this.$.append( this.documentView.$ );
        this.width = null;
        


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

Reply via email to