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

Revision: 97749
Author:   tparscal
Date:     2011-09-21 17:27:21 +0000 (Wed, 21 Sep 2011)
Log Message:
-----------
Merging controller and view together

Modified Paths:
--------------
    trunk/parsers/wikidom/demos/synth/es.js
    trunk/parsers/wikidom/demos/synth/index.html
    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/views/es.SurfaceView.js

Removed Paths:
-------------
    trunk/parsers/wikidom/lib/synth/bases/es.ControllerItem.js
    trunk/parsers/wikidom/lib/synth/bases/es.ControllerList.js
    trunk/parsers/wikidom/lib/synth/controllers/

Modified: trunk/parsers/wikidom/demos/synth/es.js
===================================================================
--- trunk/parsers/wikidom/demos/synth/es.js     2011-09-21 17:23:31 UTC (rev 
97748)
+++ trunk/parsers/wikidom/demos/synth/es.js     2011-09-21 17:27:21 UTC (rev 
97749)
@@ -259,7 +259,6 @@
                }
        ] } );
        var surfaceView = new es.SurfaceView( $( '#es-editor' ), new 
es.SurfaceModel( doc ) );
-       var surfaceController = new es.SurfaceController( surfaceView );
        // Use the global space for debugging purposes
        window.surfaceView = surfaceView;
 } );

Modified: trunk/parsers/wikidom/demos/synth/index.html
===================================================================
--- trunk/parsers/wikidom/demos/synth/index.html        2011-09-21 17:23:31 UTC 
(rev 97748)
+++ trunk/parsers/wikidom/demos/synth/index.html        2011-09-21 17:27:21 UTC 
(rev 97749)
@@ -66,9 +66,6 @@
                <script src="../../lib/synth/bases/es.ViewList.js"></script>
                <script src="../../lib/synth/bases/es.ViewListItem.js"></script>
                
-               <!-- Controllers -->
-               <script 
src="../../lib/synth/controllers/es.SurfaceController.js"></script>
-               
                <!-- Models -->
                <script 
src="../../lib/synth/models/es.SurfaceModel.js"></script>
                <script 
src="../../lib/synth/models/es.DocumentModel.js"></script>

Deleted: trunk/parsers/wikidom/lib/synth/bases/es.ControllerItem.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/bases/es.ControllerItem.js  2011-09-21 
17:23:31 UTC (rev 97748)
+++ trunk/parsers/wikidom/lib/synth/bases/es.ControllerItem.js  2011-09-21 
17:27:21 UTC (rev 97749)
@@ -1,50 +0,0 @@
-/**
- * Creates an es.ControllerItem object.
- * 
- * Controller item objects are controllers for individual models in a model 
list.
- * 
- * @class
- * @constructor
- * @extends {es.EventEmitter}
- * @property itemView {es.ModelItem} Model this controller is connected to
- */
-es.ViewContainerItem = function( itemView ) {
-       es.EventEmitter.call( this );
-       this.itemView = itemView;
-};
-
-/**
- * Gets the model this controller is connected to.
- * 
- * @method
- * @returns {es.ModelItem} Model this controller is connected to
- */
-es.ControllerItem.prototype.getModel = function() {
-       return this.itemView.getModel();
-};
-
-/**
- * Gets the view this controller is connected to.
- * 
- * @method
- * @returns {es.ViewItem} View this controller is connected to
- */
-es.ControllerItem.prototype.getView = function() {
-       return this.itemView;
-};
-
-/**
- * Gets the index of this item within it's container.
- * 
- * This method simply delegates to the model.
- * 
- * @method
- * @returns {Integer} Index of item in it's container
- */
-es.ControllerItem.prototype.getIndex = function() {
-       return this.itemView.getModel().getIndex();
-};
-
-/* Inheritance */
-
-es.extend( es.ControllerItem, es.EventEmitter );

Deleted: trunk/parsers/wikidom/lib/synth/bases/es.ControllerList.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/bases/es.ControllerList.js  2011-09-21 
17:23:31 UTC (rev 97748)
+++ trunk/parsers/wikidom/lib/synth/bases/es.ControllerList.js  2011-09-21 
17:27:21 UTC (rev 97749)
@@ -1,98 +0,0 @@
-/**
- * Creates an es.ControllerList object.
- * 
- * Controller lists follow the structural changes of a list of views, keeping 
a list of controllers
- * in sync at all times.
- * 
- * @class
- * @constructor
- * @extends {es.EventEmitter}
- * @param listView {es.ViewList} List of views to mimic
- * @property items {Array} List of controllers, correlating to the connected 
list of views
- */
-es.ControllerList = function( listView ) {
-       es.EventEmitter.call( this );
-       this.listView = listView;
-       if ( !this.listView ) {
-               return;
-       }
-       this.items = new es.AggregateArray();
-       var list = this;
-       this.relayUpdate = function() {
-               list.emit( 'update' );
-       };
-       function recycleItemController( itemView, autoCreate ) {
-               var itemController = list.lookupItemController( itemView );
-               if ( itemController ) {
-                       list.items.splice( list.items.indexOf( itemController 
), 1 );
-               }
-               if ( autoCreate && itemController === null ) {
-                       itemController = itemView.createController();
-               }
-               return itemController;
-       }
-       this.listView.on( 'prepend', function( itemView ) {
-               var itemController = recycleItemController( itemView, true );
-               itemController.on( 'update', list.relayUpdate );
-               list.items.unshift( itemController );
-               list.emit( 'prepend', itemController );
-               list.emit( 'update' );
-       } );
-       this.listView.on( 'append', function( itemView ) {
-               var itemController = recycleItemController( itemView, true );
-               itemController.on( 'update', list.relayUpdate );
-               list.items.push( itemController );
-               list.emit( 'append', itemController );
-               list.emit( 'update' );
-       } );
-       this.listView.on( 'insertBefore', function( itemView, beforeView ) {
-               var beforeController = list.lookupItemController( beforeView ),
-                       itemController = recycleItemController( itemView, true 
);
-               itemController.on( 'update', list.relayUpdate );
-               if ( beforeController ) {
-                       list.items.splice( list.items.indexOf( beforeController 
), 0, itemController );
-               } else {
-                       list.items.unshift( itemController );
-               }
-               list.emit( 'insertBefore', itemController, beforeController );
-               list.emit( 'update' );
-       } );
-       this.listView.on( 'insertAfter', function( itemView, afterView ) {
-               var afterController = list.lookupItemController( afterView ),
-                       itemController = recycleItemController( itemView, true 
);
-               itemController.on( 'update', list.relayUpdate );
-               if ( afterController ) {
-                       list.items.splice( list.items.indexOf( afterController 
) + 1, 0, itemController );
-               } else {
-                       list.items.push( itemController );
-               }
-               list.emit( 'insertAfter', itemController, afterController );
-               list.emit( 'update' );
-       } );
-       this.listView.on( 'remove', function( itemView ) {
-               var itemController = recycleItemController( itemView );
-               itemController.removeListener( 'update', list.relayUpdate );
-               list.emit( 'remove', itemController );
-               list.emit( 'update' );
-       } );
-       // Auto-add items for existing items
-       var itemViews = this.listView.all();
-       for ( var i = 0; i < itemViews.length; i++ ) {
-               var itemController = itemViews[i].createController();
-               itemController.on( 'update', list.relayUpdate );
-               this.items.push( itemController );
-       }
-};
-
-es.ControllerList.prototype.lookupItemController = function( itemView ) {
-       for ( var i = 0; i < this.items.length; i++ ) {
-               if ( this.items[i].getView() === itemView ) {
-                       return this.items[i];
-               }
-       }
-       return null;
-};
-
-/* Inheritance */
-
-es.extend( es.ControllerList, es.EventEmitter );

Modified: trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js     2011-09-21 
17:23:31 UTC (rev 97748)
+++ trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js     2011-09-21 
17:27:21 UTC (rev 97749)
@@ -163,6 +163,26 @@
        throw 'BlockModel.getSectionBoundaries not implemented in this 
subclass.';
 };
 
+es.BlockModel.prototype.commit = function( transaction ) {
+       // commit transaction
+};
+
+es.BlockModel.prototype.rollback = function( transaction ) {
+       // rollback transaction
+};
+
+es.BlockModel.prototype.prepareInsertContent = function( offset, content ) {
+       // generate transaction
+};
+
+es.BlockModel.prototype.prepareRemoveContent = function( range ) {
+       // generate transaction
+};
+
+es.BlockModel.prototype.prepareAnnotateContent = function( range, annotation ) 
{
+       // generate transaction
+};
+
 /**
  * Gets a plain object representation of block, for serialization.
  * 

Modified: trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js   2011-09-21 
17:23:31 UTC (rev 97748)
+++ trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js   2011-09-21 
17:27:21 UTC (rev 97749)
@@ -258,6 +258,26 @@
        return new es.Range( start, end );
 };
 
+es.ContentModel.prototype.commit = function( transaction ) {
+       // commit transaction
+};
+
+es.ContentModel.prototype.rollback = function( transaction ) {
+       // rollback transaction
+};
+
+es.ContentModel.prototype.prepareInsertContent = function( offset, content ) {
+       // generate transaction
+};
+
+es.ContentModel.prototype.prepareRemoveContent = function( range ) {
+       // generate transaction
+};
+
+es.ContentModel.prototype.prepareAnnotateContent = function( range, annotation 
) {
+       // generate transaction
+};
+
 /**
  * Get a plain content object.
  * 

Modified: trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js  2011-09-21 
17:23:31 UTC (rev 97748)
+++ trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js  2011-09-21 
17:27:21 UTC (rev 97749)
@@ -37,6 +37,26 @@
 
 /* Methods */
 
+es.DocumentModel.prototype.commit = function( transaction ) {
+       // commit transaction
+};
+
+es.DocumentModel.prototype.rollback = function( transaction ) {
+       // rollback transaction
+};
+
+es.DocumentModel.prototype.prepareInsertContent = function( offset, content ) {
+       // generate transaction
+};
+
+es.DocumentModel.prototype.prepareRemoveContent = function( range ) {
+       // generate transaction
+};
+
+es.DocumentModel.prototype.prepareAnnotateContent = function( range, 
annotation ) {
+       // generate transaction
+};
+
 es.DocumentModel.prototype.getPlainObject = function() {
        var obj = {};
        if ( this.items.length ) {

Modified: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js     2011-09-21 
17:23:31 UTC (rev 97748)
+++ trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js     2011-09-21 
17:27:21 UTC (rev 97749)
@@ -10,6 +10,25 @@
        this.documentView = new es.DocumentView( this.model.getDocument() );
        this.$.append( this.documentView.$ );
        this.width = null;
+       this.mouse = {
+               'selecting': false,
+               'clicks': 0,
+               'clickDelay': 500,
+               'clickTimeout': null,
+               'clickPosition': null,
+               'hotSpotRadius': 1
+       };
+       this.keyboard = {
+               'selecting': false,
+               'cursorAnchor': null,
+               'keydownTimeout': null,
+               'keys': {
+                       'shift': false,
+                       'control': false,
+                       'command': false,
+                       'alt': false
+               }
+       };
        
        // Selection
        this.$ranges = $( '<div class="editSurface-ranges"></div>' ).prependTo( 
this.$ );
@@ -21,15 +40,64 @@
        this.blinkInterval = null;
        this.$cursor = $( '<div class="editSurface-cursor"></div>' ).appendTo( 
this.$ );
        
-       var surface = this;
+       // Resize
+       var surfaceView = this;
        $(window).resize( function() {
                var width = surface.$.width();
-               if ( surface.width !== width ) {
-                       surface.width = width;
-                       surface.documentView.renderContent();
+               if ( surfaceView.width !== width ) {
+                       surfaceView.width = width;
+                       surfaceView.documentView.renderContent();
                }
        } );
        
+       // MouseDown on surface
+       this.view.$.bind( {
+               'mousedown' : function(e) {
+                       return surfaceView.onMouseDown( e );
+               }
+       } );
+       
+       // Hidden input
+       var $document = $(document);
+       this.$input = $( '<input class="editSurface-input" />' )
+               .prependTo( this.view.$ )
+               .bind( {
+                       'focus' : function() {
+                               $(document).bind({
+                                       'mousemove.editSurface' : function(e) {
+                                               return surfaceView.onMouseMove( 
e );
+                                       },
+                                       'mouseup.editSurface' : function(e) {
+                                               return surfaceView.onMouseUp( e 
);
+                                       },
+                                       'keydown.editSurface' : function( e ) {
+                                               return surfaceView.onKeyDown( e 
);                      
+                                       },
+                                       'keyup.editSurface' : function( e ) {
+                                               return surfaceView.onKeyUp( e 
);                        
+                                       }
+                               });
+                       },
+                       'blur': function( e ) {
+                               $document.unbind('.editSurface');
+                               surfaceView.hideCursor();
+                       },
+                       'cut': function( e ) {
+                               return surfaceView.onCut( e );                  
+                       },
+                       'copy': function( e ) {
+                               return surfaceView.onCopy( e );                 
+                       },
+                       'paste': function( e ) {
+                               return surfaceView.onPaste( e );                
        
+                       }
+               } );
+       
+       $(window).resize( function() {
+               surfaceView.view.hideCursor();
+               surfaceView.view.renderContent();
+       } );
+       
        // First render
        this.documentView.renderContent();
 };
@@ -111,6 +179,106 @@
        
 };
 
+es.SurfaceView.prototype.onKeyDown = function( e ) {
+       switch ( e.keyCode ) {
+               case 16: // Shift
+                       this.keyboard.keys.shift = true;
+                       break;
+               case 17: // Control
+                       this.keyboard.keys.control = true;
+                       break;
+               case 18: // Alt
+                       this.keyboard.keys.alt = true;
+                       break;
+               case 91: // Command
+                       this.keyboard.keys.command = true;
+                       break;
+               case 36: // Home
+                       break;
+               case 35: // End
+                       break;
+               case 37: // Left arrow
+                       break;
+               case 38: // Up arrow
+                       break;
+               case 39: // Right arrow
+                       break;
+               case 40: // Down arrow
+                       break;
+               case 8: // Backspace
+                       break;
+               case 46: // Delete
+                       break;
+               default: // Insert content (maybe)
+                       break;
+       }
+       return true;
+};
+
+es.SurfaceView.prototype.onKeyUp = function( e ) {
+       switch ( e.keyCode ) {
+               case 16: // Shift
+                       this.keyboard.keys.shift = false;
+                       if ( this.keyboard.selecting ) {
+                               this.keyboard.selecting = false;
+                       }
+                       break;
+               case 17: // Control
+                       this.keyboard.keys.control = false;
+                       break;
+               case 18: // Alt
+                       this.keyboard.keys.alt = false;
+                       break;
+               case 91: // Command
+                       this.keyboard.keys.command = false;
+                       break;
+               default:
+                       break;
+       }
+       return true;
+};
+
+es.SurfaceView.prototype.onMouseDown = function( e ) {
+       // TODO: Respond to mouse down event, moving cursor and possibly 
beginning selection painting
+       return false;
+};
+
+es.SurfaceView.prototype.onMouseMove = function( e ) {
+       // TODO: Respond to mouse move event, updating selection while painting
+};
+
+es.SurfaceView.prototype.onMouseUp = function( e ) {
+       // TODO: Respond to mouse up event, possibly ending selection painting
+};
+
+es.SurfaceView.prototype.onCut = function( e ) {
+       // TODO: Keep a Content object copy of the selection
+};
+
+es.SurfaceView.prototype.onCopy = function( e ) {
+       // TODO: Keep a Content object copy of the selection
+};
+
+es.SurfaceView.prototype.onPaste = function( e ) {
+       // TODO: Respond to paste event, using the object copy if possible
+};
+
+es.SurfaceView.prototype.handleBackspace = function() {
+       // TODO: Respond to backspace event
+};
+
+es.SurfaceView.prototype.handleDelete = function() {
+       // TODO: Respond to delete event
+};
+
+es.SurfaceView.prototype.getInputContent = function() {
+       // TODO: Get content from this.$input
+};
+
+es.SurfaceView.prototype.setInputContent = function( content ) {
+       // TODO: Set the value of this.$input
+};
+
 /* Inheritance */
 
 es.SurfaceView.prototype.getLocationFromPosition = function( position ) {


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

Reply via email to