r97587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97586‎ | r97587 | r97588 >
Date:00:27, 20 September 2011
Author:inez
Status:deferred
Tags:
Comment:
Big refactoring to to the code - new it is using new convention for Lists and ListItems
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewList.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewListItem.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/es.Surface.css (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.BlockView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ListBlockItemView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/es.Surface.css
@@ -25,7 +25,9 @@
2626 -webkit-user-select: none;
2727 }
2828
29 -.editSurface-block {
 29+.editSurface-tableBlock,
 30+.editSurface-listBlock,
 31+.editSurface-paragraphBlock {
3032 margin: 1em;
3133 margin-top: 0;
3234 position: relative;
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewListItem.js
@@ -1,27 +1,17 @@
22 /**
33 * Generic synchronized Object/Element container item.
 4+ * This will override this.$ (important in case of multiple inheritance).
45 *
56 * @class
67 * @constructor
78 * @extends {es.EventEmitter}
8 - * @param typeName {String} Name to use in CSS classes and HTML element data
9 - * @param tagName {String} HTML element name to use (optional, default: "div")
 9+ * @param $element {jQuery} jQuery object to use
1010 * @property $ {jQuery} Container element
1111 */
12 -es.ViewListItem = function( model, typeName, tagName ) {
 12+es.ViewListItem = function( model, $element ) {
1313 es.EventEmitter.call( this );
1414 this.model = model;
15 - if ( typeof typeName !== 'string' ) {
16 - typeName = 'viewListItem';
17 - }
18 - if ( typeof tagName !== 'string' ) {
19 - tagName = 'div';
20 - }
21 -
22 - if ( !this.$ ) {
23 - this.$ = $( '<' + tagName + '/>' );
24 - }
25 - this.$.addClass( 'editSurface-' + typeName ).data( typeName, this );
 15+ this.$ = $element || $( '<div/>' );
2616 };
2717
2818 es.ViewListItem.prototype.getModel = function() {
@@ -29,7 +19,7 @@
3020 };
3121
3222 /**
33 - * Gets the index of this item within it's container.
 23+ * Gets the index of this item within it's list.
3424 *
3525 * This method simply delegates to the model.
3626 *
@@ -42,4 +32,4 @@
4333
4434 /* Inheritance */
4535
46 -es.extend( es.ViewListItem, es.EventEmitter );
 36+es.extend( es.ViewListItem, es.EventEmitter );
\ No newline at end of file
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewList.js
@@ -1,8 +1,10 @@
22 /**
33 * Creates an es.ViewList object.
44 *
5 - * View containers follow the operations performed on a model container and keep a list of views,
6 - * each correlating to a model in the model container.
 5+ * View lists follow the operations performed on a model lists and keep a list of views,
 6+ * each correlating to a model in the model list.
 7+ *
 8+ * This will override this.$ (important in case of multiple inheritance).
79 *
810 * @class
911 * @constructor
@@ -13,31 +15,25 @@
1416 * @property $ {jQuery} Container element
1517 * @property items {Array} List of views, correlating to models in the model container
1618 */
17 -es.ViewList = function( model, typeName, tagName ) {
 19+es.ViewList = function( model, $element ) {
1820 es.EventEmitter.call( this );
1921 this.model = model;
2022 if ( !this.model ) {
2123 return;
2224 }
 25+ this.$ = $element || $( '<div/>' );
2326 this.items = new es.AggregateArray();
24 - if ( typeof typeName !== 'string' ) {
25 - typeName = 'viewList';
26 - }
27 - if ( typeof tagName !== 'string' ) {
28 - tagName = 'div';
29 - }
30 - if ( !this.$ ) {
31 - this.$ = $( '<' + tagName + '/>' );
32 - }
33 - this.$.addClass( 'editSurface-' + typeName ).data( typeName, this );
34 - var container = this;
 27+
 28+ var list = this;
 29+
3530 this.relayUpdate = function() {
36 - container.emit( 'update' );
 31+ list.emit( 'update' );
3732 };
38 - function recycleItemView( itemModel, autoCreate ) {
39 - var itemView = container.lookupItemView( itemModel );
 33+
 34+ this.recycleItemView = function( itemModel, autoCreate ) {
 35+ var itemView = list.lookupItemView( itemModel );
4036 if ( itemView ) {
41 - container.views.splice( container.views.indexOf( itemView ), 1 );
 37+ list.items.splice( list.items.indexOf( itemView ), 1 );
4238 itemView.$.detach();
4339 }
4440 if ( autoCreate && itemView === null ) {
@@ -45,61 +41,63 @@
4642 }
4743 return itemView;
4844 }
 45+
4946 this.model.on( 'prepend', function( itemModel ) {
50 - var itemView = recycleItemView( itemModel, true );
51 - itemView.on( 'update', container.relayUpdate );
52 - container.views.unshift( itemView );
53 - container.$.prepend( itemView.$ );
54 - container.emit( 'prepend', itemView );
55 - container.emit( 'update' );
 47+ var itemView = list.recycleItemView( itemModel, true );
 48+ itemView.on( 'update', list.relayUpdate );
 49+ list.items.unshift( itemView );
 50+ list.$.prepend( itemView.$ );
 51+ list.emit( 'prepend', itemView );
 52+ list.emit( 'update' );
5653 } );
5754 this.model.on( 'append', function( itemModel ) {
58 - var itemView = recycleItemView( itemModel, true );
59 - itemView.on( 'update', container.relayUpdate );
60 - container.views.push( itemView );
61 - container.$.append( itemView.$ );
62 - container.emit( 'append', itemView );
63 - container.emit( 'update' );
 55+ var itemView = list.recycleItemView( itemModel, true );
 56+ itemView.on( 'update', list.relayUpdate );
 57+ list.items.push( itemView );
 58+ list.$.append( itemView.$ );
 59+ list.emit( 'append', itemView );
 60+ list.emit( 'update' );
6461 } );
6562 this.model.on( 'insertBefore', function( itemModel, beforeModel ) {
66 - var beforeView = container.lookupItemView( beforeModel ),
67 - itemView = recycleItemView( itemModel, true );
68 - itemView.on( 'update', container.relayUpdate );
 63+ var beforeView = list.lookupItemView( beforeModel ),
 64+ itemView = list.recycleItemView( itemModel, true );
 65+ itemView.on( 'update', list.relayUpdate );
6966 if ( beforeView ) {
70 - container.views.splice( container.views.indexOf( beforeView ), 0, itemView );
 67+ list.items.splice( list.items.indexOf( beforeView ), 0, itemView );
7168 itemView.$.insertBefore( beforeView.$ );
7269 } else {
73 - container.views.unshift( itemView );
74 - container.$.prepend( itemView.$ );
 70+ list.items.unshift( itemView );
 71+ list.$.prepend( itemView.$ );
7572 }
76 - container.emit( 'insertBefore', itemView, beforeView );
77 - container.emit( 'update' );
 73+ list.emit( 'insertBefore', itemView, beforeView );
 74+ list.emit( 'update' );
7875 } );
7976 this.model.on( 'insertAfter', function( itemModel, afterModel ) {
80 - var afterView = container.lookupItemView( afterModel ),
81 - itemView = recycleItemView( itemModel, true );
82 - itemView.on( 'update', container.relayUpdate );
 77+ var afterView = list.lookupItemView( afterModel ),
 78+ itemView = list.recycleItemView( itemModel, true );
 79+ itemView.on( 'update', list.relayUpdate );
8380 if ( afterView ) {
84 - container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView );
 81+ list.items.splice( list.items.indexOf( afterView ) + 1, 0, itemView );
8582 itemView.$.insertAfter( afterView.$ );
8683 } else {
87 - container.views.push( itemView );
88 - container.$.append( itemView.$ );
 84+ list.items.push( itemView );
 85+ list.$.append( itemView.$ );
8986 }
90 - container.emit( 'insertAfter', itemView, afterView );
91 - container.emit( 'update' );
 87+ list.emit( 'insertAfter', itemView, afterView );
 88+ list.emit( 'update' );
9289 } );
9390 this.model.on( 'remove', function( itemModel ) {
94 - var itemView = recycleItemView( itemModel );
95 - itemView.removeListener( 'update', container.relayUpdate );
96 - container.emit( 'remove', itemView );
97 - container.emit( 'update' );
 91+ var itemView = list.recycleItemView( itemModel );
 92+ itemView.removeListener( 'update', list.relayUpdate );
 93+ list.emit( 'remove', itemView );
 94+ list.emit( 'update' );
9895 } );
99 - // Auto-add views for existing items
 96+
 97+ // Auto-add items for existing items
10098 var itemModels = this.model.all();
10199 for ( var i = 0; i < itemModels.length; i++ ) {
102100 var itemView = itemModels[i].createView();
103 - itemView.on( 'update', container.relayUpdate );
 101+ itemView.on( 'update', this.relayUpdate );
104102 this.items.push( itemView );
105103 this.$.append( itemView.$ );
106104 }
@@ -115,5 +113,4 @@
116114 };
117115
118116 /* Inheritance */
119 -
120 -es.extend( es.ViewList, es.EventEmitter );
 117+es.extend( es.ViewList, es.EventEmitter );
\ No newline at end of file
Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockItemView.js
@@ -5,7 +5,8 @@
66 * @constructor
77 */
88 es.ListBlockItemView = function( model ) {
9 - es.ViewListItem.call( this, model, 'listItem' );
 9+ es.ViewListItem.call( this, model );
 10+ this.$.addClass( 'editSurface-listItem' );
1011 this.$icon = $( '<div class="editSurface-listItem-icon"></div>' );
1112 this.$content = $( '<div class="editSurface-listItem-content"></div>' );
1213 this.$
Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js
@@ -5,8 +5,9 @@
66 * @constructor
77 */
88 es.ListBlockView = function( model ) {
9 - es.ViewList.call( this, model, 'list' );
10 - es.BlockView.call( this, model, 'list' );
 9+ es.ViewList.call( this, model );
 10+ es.BlockView.call( this, model, this.$ );
 11+ this.$.addClass( 'editSurface-listBlock' );
1112 var view = this;
1213 this.on( 'update', function() {
1314 view.enumerate();
Index: trunk/parsers/wikidom/lib/synth/views/es.BlockView.js
@@ -8,9 +8,8 @@
99 * @param typeName {String} Name of block type (optional, default: "block")
1010 * @param tagName {String} HTML tag name to use in rendering (optional, default: "div")
1111 */
12 -es.BlockView = function( blockModel, typeName, tagName ) {
13 - es.ViewListItem.call( this, blockModel, typeName || 'block', tagName || 'div' );
14 - this.$.addClass( 'editSurface-block' );
 12+es.BlockView = function( blockModel, $element ) {
 13+ es.ViewListItem.call( this, blockModel, $element );
1514 };
1615
1716 /**
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js
@@ -5,8 +5,8 @@
66 * @constructor
77 */
88 es.TableBlockRowView = function( model ) {
9 - es.ViewList.call( this, model, 'row', 'tr' )
10 - es.ViewListItem.call( this, model, 'tr' );
 9+ es.ViewList.call( this, model, $( '<tr>' ) );
 10+ es.ViewListItem.call( this, model, this.$ );
1111
1212 var classes = this.$.attr('class');
1313 for ( var name in this.model.attributes ) {
Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js
@@ -5,7 +5,8 @@
66 * @constructor
77 */
88 es.DocumentView = function( documentModel ) {
9 - es.ViewList.call( this, documentModel, 'document' );
 9+ es.ViewList.call( this, documentModel );
 10+ this.$.addClass( 'editSurface-document' )
1011 };
1112
1213 /**
Index: trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js
@@ -5,7 +5,10 @@
66 * @constructor
77 */
88 es.ParagraphBlockView = function( model ) {
9 - es.BlockView.call( this, model, 'paragraph' );
 9+ es.BlockView.call( this, model );
 10+
 11+ this.$.addClass( 'editSurface-paragraphBlock' );
 12+
1013 this.contentView = new es.ContentView( this.$, this.model.content );
1114 var view = this;
1215 this.contentView.on( 'update', function() {
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js
@@ -5,7 +5,7 @@
66 * @constructor
77 */
88 es.TableBlockCellView = function( model ) {
9 - es.ViewListItem.call( this, model, 'cell', 'td' );
 9+ es.ViewListItem.call( this, model, $( '<td>' ) );
1010
1111 this.documentView = new es.DocumentView( this.model.documentModel );
1212 this.$.append( this.documentView.$ );
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js
@@ -5,14 +5,12 @@
66 * @constructor
77 */
88 es.TableBlockView = function( model ) {
9 - es.ViewList.call( this, model, 'table', 'table' );
10 - es.BlockView.call( this, model, 'table', 'table' );
11 -
12 - var classes = this.$.attr('class');
 9+ es.ViewList.call( this, model, $( '<table>' ) );
 10+ es.BlockView.call( this, model, this.$ );
1311 for ( var name in this.model.attributes ) {
1412 this.$.attr( name, this.model.attributes[name] );
1513 }
16 - this.$.addClass(classes);
 14+ this.$.addClass( 'editSurface-tableBlock' );
1715 };
1816
1917 /**

Status & tagging log