r97749 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97748‎ | r97749 | r97750 >
Date:17:27, 21 September 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Merging controller and view together
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/bases/es.ControllerItem.js (deleted) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ControllerList.js (deleted) (history)
  • /trunk/parsers/wikidom/lib/synth/controllers (deleted) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js
@@ -37,6 +37,26 @@
3838
3939 /* Methods */
4040
 41+es.DocumentModel.prototype.commit = function( transaction ) {
 42+ // commit transaction
 43+};
 44+
 45+es.DocumentModel.prototype.rollback = function( transaction ) {
 46+ // rollback transaction
 47+};
 48+
 49+es.DocumentModel.prototype.prepareInsertContent = function( offset, content ) {
 50+ // generate transaction
 51+};
 52+
 53+es.DocumentModel.prototype.prepareRemoveContent = function( range ) {
 54+ // generate transaction
 55+};
 56+
 57+es.DocumentModel.prototype.prepareAnnotateContent = function( range, annotation ) {
 58+ // generate transaction
 59+};
 60+
4161 es.DocumentModel.prototype.getPlainObject = function() {
4262 var obj = {};
4363 if ( this.items.length ) {
Index: trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js
@@ -163,6 +163,26 @@
164164 throw 'BlockModel.getSectionBoundaries not implemented in this subclass.';
165165 };
166166
 167+es.BlockModel.prototype.commit = function( transaction ) {
 168+ // commit transaction
 169+};
 170+
 171+es.BlockModel.prototype.rollback = function( transaction ) {
 172+ // rollback transaction
 173+};
 174+
 175+es.BlockModel.prototype.prepareInsertContent = function( offset, content ) {
 176+ // generate transaction
 177+};
 178+
 179+es.BlockModel.prototype.prepareRemoveContent = function( range ) {
 180+ // generate transaction
 181+};
 182+
 183+es.BlockModel.prototype.prepareAnnotateContent = function( range, annotation ) {
 184+ // generate transaction
 185+};
 186+
167187 /**
168188 * Gets a plain object representation of block, for serialization.
169189 *
Index: trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js
@@ -258,6 +258,26 @@
259259 return new es.Range( start, end );
260260 };
261261
 262+es.ContentModel.prototype.commit = function( transaction ) {
 263+ // commit transaction
 264+};
 265+
 266+es.ContentModel.prototype.rollback = function( transaction ) {
 267+ // rollback transaction
 268+};
 269+
 270+es.ContentModel.prototype.prepareInsertContent = function( offset, content ) {
 271+ // generate transaction
 272+};
 273+
 274+es.ContentModel.prototype.prepareRemoveContent = function( range ) {
 275+ // generate transaction
 276+};
 277+
 278+es.ContentModel.prototype.prepareAnnotateContent = function( range, annotation ) {
 279+ // generate transaction
 280+};
 281+
262282 /**
263283 * Get a plain content object.
264284 *
Index: trunk/parsers/wikidom/lib/synth/bases/es.ControllerList.js
@@ -1,98 +0,0 @@
2 -/**
3 - * Creates an es.ControllerList object.
4 - *
5 - * Controller lists follow the structural changes of a list of views, keeping a list of controllers
6 - * in sync at all times.
7 - *
8 - * @class
9 - * @constructor
10 - * @extends {es.EventEmitter}
11 - * @param listView {es.ViewList} List of views to mimic
12 - * @property items {Array} List of controllers, correlating to the connected list of views
13 - */
14 -es.ControllerList = function( listView ) {
15 - es.EventEmitter.call( this );
16 - this.listView = listView;
17 - if ( !this.listView ) {
18 - return;
19 - }
20 - this.items = new es.AggregateArray();
21 - var list = this;
22 - this.relayUpdate = function() {
23 - list.emit( 'update' );
24 - };
25 - function recycleItemController( itemView, autoCreate ) {
26 - var itemController = list.lookupItemController( itemView );
27 - if ( itemController ) {
28 - list.items.splice( list.items.indexOf( itemController ), 1 );
29 - }
30 - if ( autoCreate && itemController === null ) {
31 - itemController = itemView.createController();
32 - }
33 - return itemController;
34 - }
35 - this.listView.on( 'prepend', function( itemView ) {
36 - var itemController = recycleItemController( itemView, true );
37 - itemController.on( 'update', list.relayUpdate );
38 - list.items.unshift( itemController );
39 - list.emit( 'prepend', itemController );
40 - list.emit( 'update' );
41 - } );
42 - this.listView.on( 'append', function( itemView ) {
43 - var itemController = recycleItemController( itemView, true );
44 - itemController.on( 'update', list.relayUpdate );
45 - list.items.push( itemController );
46 - list.emit( 'append', itemController );
47 - list.emit( 'update' );
48 - } );
49 - this.listView.on( 'insertBefore', function( itemView, beforeView ) {
50 - var beforeController = list.lookupItemController( beforeView ),
51 - itemController = recycleItemController( itemView, true );
52 - itemController.on( 'update', list.relayUpdate );
53 - if ( beforeController ) {
54 - list.items.splice( list.items.indexOf( beforeController ), 0, itemController );
55 - } else {
56 - list.items.unshift( itemController );
57 - }
58 - list.emit( 'insertBefore', itemController, beforeController );
59 - list.emit( 'update' );
60 - } );
61 - this.listView.on( 'insertAfter', function( itemView, afterView ) {
62 - var afterController = list.lookupItemController( afterView ),
63 - itemController = recycleItemController( itemView, true );
64 - itemController.on( 'update', list.relayUpdate );
65 - if ( afterController ) {
66 - list.items.splice( list.items.indexOf( afterController ) + 1, 0, itemController );
67 - } else {
68 - list.items.push( itemController );
69 - }
70 - list.emit( 'insertAfter', itemController, afterController );
71 - list.emit( 'update' );
72 - } );
73 - this.listView.on( 'remove', function( itemView ) {
74 - var itemController = recycleItemController( itemView );
75 - itemController.removeListener( 'update', list.relayUpdate );
76 - list.emit( 'remove', itemController );
77 - list.emit( 'update' );
78 - } );
79 - // Auto-add items for existing items
80 - var itemViews = this.listView.all();
81 - for ( var i = 0; i < itemViews.length; i++ ) {
82 - var itemController = itemViews[i].createController();
83 - itemController.on( 'update', list.relayUpdate );
84 - this.items.push( itemController );
85 - }
86 -};
87 -
88 -es.ControllerList.prototype.lookupItemController = function( itemView ) {
89 - for ( var i = 0; i < this.items.length; i++ ) {
90 - if ( this.items[i].getView() === itemView ) {
91 - return this.items[i];
92 - }
93 - }
94 - return null;
95 -};
96 -
97 -/* Inheritance */
98 -
99 -es.extend( es.ControllerList, es.EventEmitter );
Index: trunk/parsers/wikidom/lib/synth/bases/es.ControllerItem.js
@@ -1,50 +0,0 @@
2 -/**
3 - * Creates an es.ControllerItem object.
4 - *
5 - * Controller item objects are controllers for individual models in a model list.
6 - *
7 - * @class
8 - * @constructor
9 - * @extends {es.EventEmitter}
10 - * @property itemView {es.ModelItem} Model this controller is connected to
11 - */
12 -es.ViewContainerItem = function( itemView ) {
13 - es.EventEmitter.call( this );
14 - this.itemView = itemView;
15 -};
16 -
17 -/**
18 - * Gets the model this controller is connected to.
19 - *
20 - * @method
21 - * @returns {es.ModelItem} Model this controller is connected to
22 - */
23 -es.ControllerItem.prototype.getModel = function() {
24 - return this.itemView.getModel();
25 -};
26 -
27 -/**
28 - * Gets the view this controller is connected to.
29 - *
30 - * @method
31 - * @returns {es.ViewItem} View this controller is connected to
32 - */
33 -es.ControllerItem.prototype.getView = function() {
34 - return this.itemView;
35 -};
36 -
37 -/**
38 - * Gets the index of this item within it's container.
39 - *
40 - * This method simply delegates to the model.
41 - *
42 - * @method
43 - * @returns {Integer} Index of item in it's container
44 - */
45 -es.ControllerItem.prototype.getIndex = function() {
46 - return this.itemView.getModel().getIndex();
47 -};
48 -
49 -/* Inheritance */
50 -
51 -es.extend( es.ControllerItem, es.EventEmitter );
Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
@@ -10,6 +10,25 @@
1111 this.documentView = new es.DocumentView( this.model.getDocument() );
1212 this.$.append( this.documentView.$ );
1313 this.width = null;
 14+ this.mouse = {
 15+ 'selecting': false,
 16+ 'clicks': 0,
 17+ 'clickDelay': 500,
 18+ 'clickTimeout': null,
 19+ 'clickPosition': null,
 20+ 'hotSpotRadius': 1
 21+ };
 22+ this.keyboard = {
 23+ 'selecting': false,
 24+ 'cursorAnchor': null,
 25+ 'keydownTimeout': null,
 26+ 'keys': {
 27+ 'shift': false,
 28+ 'control': false,
 29+ 'command': false,
 30+ 'alt': false
 31+ }
 32+ };
1433
1534 // Selection
1635 this.$ranges = $( '<div class="editSurface-ranges"></div>' ).prependTo( this.$ );
@@ -21,15 +40,64 @@
2241 this.blinkInterval = null;
2342 this.$cursor = $( '<div class="editSurface-cursor"></div>' ).appendTo( this.$ );
2443
25 - var surface = this;
 44+ // Resize
 45+ var surfaceView = this;
2646 $(window).resize( function() {
2747 var width = surface.$.width();
28 - if ( surface.width !== width ) {
29 - surface.width = width;
30 - surface.documentView.renderContent();
 48+ if ( surfaceView.width !== width ) {
 49+ surfaceView.width = width;
 50+ surfaceView.documentView.renderContent();
3151 }
3252 } );
3353
 54+ // MouseDown on surface
 55+ this.view.$.bind( {
 56+ 'mousedown' : function(e) {
 57+ return surfaceView.onMouseDown( e );
 58+ }
 59+ } );
 60+
 61+ // Hidden input
 62+ var $document = $(document);
 63+ this.$input = $( '<input class="editSurface-input" />' )
 64+ .prependTo( this.view.$ )
 65+ .bind( {
 66+ 'focus' : function() {
 67+ $(document).bind({
 68+ 'mousemove.editSurface' : function(e) {
 69+ return surfaceView.onMouseMove( e );
 70+ },
 71+ 'mouseup.editSurface' : function(e) {
 72+ return surfaceView.onMouseUp( e );
 73+ },
 74+ 'keydown.editSurface' : function( e ) {
 75+ return surfaceView.onKeyDown( e );
 76+ },
 77+ 'keyup.editSurface' : function( e ) {
 78+ return surfaceView.onKeyUp( e );
 79+ }
 80+ });
 81+ },
 82+ 'blur': function( e ) {
 83+ $document.unbind('.editSurface');
 84+ surfaceView.hideCursor();
 85+ },
 86+ 'cut': function( e ) {
 87+ return surfaceView.onCut( e );
 88+ },
 89+ 'copy': function( e ) {
 90+ return surfaceView.onCopy( e );
 91+ },
 92+ 'paste': function( e ) {
 93+ return surfaceView.onPaste( e );
 94+ }
 95+ } );
 96+
 97+ $(window).resize( function() {
 98+ surfaceView.view.hideCursor();
 99+ surfaceView.view.renderContent();
 100+ } );
 101+
34102 // First render
35103 this.documentView.renderContent();
36104 };
@@ -111,6 +179,106 @@
112180
113181 };
114182
 183+es.SurfaceView.prototype.onKeyDown = function( e ) {
 184+ switch ( e.keyCode ) {
 185+ case 16: // Shift
 186+ this.keyboard.keys.shift = true;
 187+ break;
 188+ case 17: // Control
 189+ this.keyboard.keys.control = true;
 190+ break;
 191+ case 18: // Alt
 192+ this.keyboard.keys.alt = true;
 193+ break;
 194+ case 91: // Command
 195+ this.keyboard.keys.command = true;
 196+ break;
 197+ case 36: // Home
 198+ break;
 199+ case 35: // End
 200+ break;
 201+ case 37: // Left arrow
 202+ break;
 203+ case 38: // Up arrow
 204+ break;
 205+ case 39: // Right arrow
 206+ break;
 207+ case 40: // Down arrow
 208+ break;
 209+ case 8: // Backspace
 210+ break;
 211+ case 46: // Delete
 212+ break;
 213+ default: // Insert content (maybe)
 214+ break;
 215+ }
 216+ return true;
 217+};
 218+
 219+es.SurfaceView.prototype.onKeyUp = function( e ) {
 220+ switch ( e.keyCode ) {
 221+ case 16: // Shift
 222+ this.keyboard.keys.shift = false;
 223+ if ( this.keyboard.selecting ) {
 224+ this.keyboard.selecting = false;
 225+ }
 226+ break;
 227+ case 17: // Control
 228+ this.keyboard.keys.control = false;
 229+ break;
 230+ case 18: // Alt
 231+ this.keyboard.keys.alt = false;
 232+ break;
 233+ case 91: // Command
 234+ this.keyboard.keys.command = false;
 235+ break;
 236+ default:
 237+ break;
 238+ }
 239+ return true;
 240+};
 241+
 242+es.SurfaceView.prototype.onMouseDown = function( e ) {
 243+ // TODO: Respond to mouse down event, moving cursor and possibly beginning selection painting
 244+ return false;
 245+};
 246+
 247+es.SurfaceView.prototype.onMouseMove = function( e ) {
 248+ // TODO: Respond to mouse move event, updating selection while painting
 249+};
 250+
 251+es.SurfaceView.prototype.onMouseUp = function( e ) {
 252+ // TODO: Respond to mouse up event, possibly ending selection painting
 253+};
 254+
 255+es.SurfaceView.prototype.onCut = function( e ) {
 256+ // TODO: Keep a Content object copy of the selection
 257+};
 258+
 259+es.SurfaceView.prototype.onCopy = function( e ) {
 260+ // TODO: Keep a Content object copy of the selection
 261+};
 262+
 263+es.SurfaceView.prototype.onPaste = function( e ) {
 264+ // TODO: Respond to paste event, using the object copy if possible
 265+};
 266+
 267+es.SurfaceView.prototype.handleBackspace = function() {
 268+ // TODO: Respond to backspace event
 269+};
 270+
 271+es.SurfaceView.prototype.handleDelete = function() {
 272+ // TODO: Respond to delete event
 273+};
 274+
 275+es.SurfaceView.prototype.getInputContent = function() {
 276+ // TODO: Get content from this.$input
 277+};
 278+
 279+es.SurfaceView.prototype.setInputContent = function( content ) {
 280+ // TODO: Set the value of this.$input
 281+};
 282+
115283 /* Inheritance */
116284
117285 es.SurfaceView.prototype.getLocationFromPosition = function( position ) {
Index: trunk/parsers/wikidom/demos/synth/es.js
@@ -259,7 +259,6 @@
260260 }
261261 ] } );
262262 var surfaceView = new es.SurfaceView( $( '#es-editor' ), new es.SurfaceModel( doc ) );
263 - var surfaceController = new es.SurfaceController( surfaceView );
264263 // Use the global space for debugging purposes
265264 window.surfaceView = surfaceView;
266265 } );
Index: trunk/parsers/wikidom/demos/synth/index.html
@@ -66,9 +66,6 @@
6767 <script src="../../lib/synth/bases/es.ViewList.js"></script>
6868 <script src="../../lib/synth/bases/es.ViewListItem.js"></script>
6969
70 - <!-- Controllers -->
71 - <script src="../../lib/synth/controllers/es.SurfaceController.js"></script>
72 -
7370 <!-- Models -->
7471 <script src="../../lib/synth/models/es.SurfaceModel.js"></script>
7572 <script src="../../lib/synth/models/es.DocumentModel.js"></script>

Status & tagging log