r94837 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94836‎ | r94837 | r94838 >
Date:22:41, 17 August 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Split es.Container into es.Container (just objects) and es.DomContainer (adds DOM synchronization)
Modified paths:
  • /trunk/parsers/wikidom/demos/es/index.html (modified) (history)
  • /trunk/parsers/wikidom/demos/es/index2.html (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Container.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Document.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.DomContainer.js (added) (history)
  • /trunk/parsers/wikidom/lib/es/es.ListBlockList.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Document.js
@@ -9,7 +9,7 @@
1010 * @property width {Integer}
1111 */
1212 es.Document = function( blocks ) {
13 - es.Container.call( this, 'document', 'blocks', blocks );
 13+ es.DomContainer.call( this, 'document', 'blocks', blocks );
1414 this.width = null;
1515 };
1616
@@ -79,4 +79,4 @@
8080
8181 /* Inheritance */
8282
83 -es.extend( es.Document, es.Container );
 83+es.extend( es.Document, es.DomContainer );
Index: trunk/parsers/wikidom/lib/es/es.DomContainer.js
@@ -0,0 +1,58 @@
 2+/**
 3+ * Generic synchronized Object/Element container.
 4+ *
 5+ * Child objects must extend es.EventEmitter.
 6+ *
 7+ * @class
 8+ * @constructor
 9+ * @extends {es.EventEmitter}
 10+ * @param typeName {String} Property name to set references to this object to in child objects
 11+ * @param listName {String} Property name for list of child objects
 12+ * @param items {Array} List of initial items
 13+ * @emits "update" when items argument causes items to be appended
 14+ * @emits "append" when items argument causes items to be appended
 15+ * @property $ {jQuery} Container element
 16+ */
 17+es.DomContainer = function( typeName, listName, items, tagName ) {
 18+ if ( typeof tagName !== 'string' ) {
 19+ tagName = 'div';
 20+ }
 21+ this.$ = $( '<' + tagName + '/>' )
 22+ .addClass( 'editSurface-' + typeName )
 23+ .data( typeName, this );
 24+ es.Container.call( this, typeName, listName );
 25+ this.on( 'prepend', function( item ) {
 26+ this.$.prepend( item.$ );
 27+ } );
 28+ this.on( 'append', function( item ) {
 29+ this.$.append( item.$ );
 30+ } );
 31+ this.on( 'insertBefore', function( item, before ) {
 32+ if ( before ) {
 33+ item.$.insertBefore( before.$ );
 34+ } else {
 35+ this.$.append( item.$ );
 36+ }
 37+ } );
 38+ this.on( 'insertAfter', function( item, after ) {
 39+ if ( after ) {
 40+ item.$.insertAfter( after.$ );
 41+ } else {
 42+ this.$.append( item.$ );
 43+ }
 44+ } );
 45+ this.on( 'remove', function( item ) {
 46+ item.$.detach();
 47+ } );
 48+ // Auto-append - must do our own, not use the one es.Content() give us, so that the events will
 49+ // be called when items are appended
 50+ if ( $.isArray( items ) ) {
 51+ for ( var i = 0; i < items.length; i++ ) {
 52+ this.append( items[i] );
 53+ }
 54+ }
 55+};
 56+
 57+/* Inheritance */
 58+
 59+es.extend( es.DomContainer, es.Container );
Property changes on: trunk/parsers/wikidom/lib/es/es.DomContainer.js
___________________________________________________________________
Added: svn:eol-style
160 + native
Added: svn:mime-type
261 + text/plain
Index: trunk/parsers/wikidom/lib/es/es.Container.js
@@ -1,5 +1,5 @@
22 /**
3 - * Generic synchronized Object/Element container.
 3+ * Generic Object container.
44 *
55 * Child objects must extend es.EventEmitter.
66 *
@@ -9,10 +9,10 @@
1010 * @param typeName {String} Property name to set references to this object to in child objects
1111 * @param listName {String} Property name for list of child objects
1212 * @param items {Array} List of initial items
 13+ * @emits "append" when items argument causes items to be appended
1314 * @emits "update" when items argument causes items to be appended
14 - * @property $ {jQuery} Container element
1515 */
16 -es.Container = function( typeName, listName, items, tagName ) {
 16+es.Container = function( typeName, listName, items ) {
1717 es.EventEmitter.call( this );
1818 if ( typeof typeName !== 'string' ) {
1919 typeName = 'container';
@@ -20,15 +20,9 @@
2121 if ( typeof listName !== 'string' ) {
2222 listName = 'items';
2323 }
24 - if ( typeof tagName !== 'string' ) {
25 - tagName = 'div';
26 - }
2724 this._typeName = typeName;
2825 this._listName = listName;
2926 this._list = this[listName] = [];
30 - this.$ = $( '<' + tagName + '/>' )
31 - .addClass( 'editSurface-' + typeName )
32 - .data( typeName, this );
3327 // Auto-append
3428 if ( $.isArray( items ) ) {
3529 for ( var i = 0; i < items.length; i++ ) {
@@ -92,7 +86,7 @@
9387 container.emit( 'update' );
9488 } );
9589 this._list.push( item );
96 - this.$.append( item.$ );
 90+ this.emit( 'append', item );
9791 this.emit( 'update' );
9892 };
9993
@@ -112,7 +106,7 @@
113107 container.emit( 'update' );
114108 } );
115109 this._list.unshift( item );
116 - this.$.prepend( item.$ );
 110+ this.emit( 'prepend', item );
117111 this.emit( 'update' );
118112 };
119113
@@ -134,11 +128,10 @@
135129 } );
136130 if ( before ) {
137131 this._list.splice( before.getIndex(), 0, item );
138 - item.$.insertBefore( before.$ );
139132 } else {
140133 this._list.push( item );
141 - this.$.append( item.$ );
142134 }
 135+ this.emit( 'insertBefore', item, before );
143136 this.emit( 'update' );
144137 };
145138 /**
@@ -159,11 +152,10 @@
160153 } );
161154 if ( after ) {
162155 this._list.splice( after.getIndex() + 1, 0, item );
163 - item.$.insertAfter( after.$ );
164156 } else {
165157 this._list.push( item );
166 - this.$.append( item.$ );
167158 }
 159+ this.emit( 'insertAfter', item, after );
168160 this.emit( 'update' );
169161 };
170162
@@ -180,7 +172,7 @@
181173 item.removeAllListeners( 'update' );
182174 this._list.splice( item.getIndex(), 1 );
183175 item[this._typeName] = null;
184 - item.$.detach();
 176+ this.emit( 'remove', item );
185177 this.emit( 'update' );
186178 };
187179
Index: trunk/parsers/wikidom/lib/es/es.ListBlockList.js
@@ -1,5 +1,5 @@
22 es.ListBlockList = function( items ) {
3 - es.Container.call( this, 'list', 'items', items );
 3+ es.DomContainer.call( this, 'list', 'items', items );
44 };
55
66 es.ListBlockList.newFromWikiDomList = function( wikidomList ) {
@@ -41,4 +41,4 @@
4242 }
4343 };
4444
45 -es.extend( es.ListBlockList, es.Container );
 45+es.extend( es.ListBlockList, es.DomContainer );
Index: trunk/parsers/wikidom/demos/es/index.html
@@ -60,6 +60,7 @@
6161 <script src="../../lib/es/es.Selection.js"></script>
6262 <script src="../../lib/es/es.Content.js"></script>
6363 <script src="../../lib/es/es.Container.js"></script>
 64+ <script src="../../lib/es/es.DomContainer.js"></script>
6465 <script src="../../lib/es/es.Block.js"></script>
6566 <script src="../../lib/es/es.Document.js"></script>
6667 <script src="../../lib/es/es.AnnotationSerializer.js"></script>
Index: trunk/parsers/wikidom/demos/es/index2.html
@@ -87,6 +87,7 @@
8888 <script src="../../lib/es/es.Selection.js"></script>
8989 <script src="../../lib/es/es.Content.js"></script>
9090 <script src="../../lib/es/es.Container.js"></script>
 91+ <script src="../../lib/es/es.DomContainer.js"></script>
9192 <script src="../../lib/es/es.Block.js"></script>
9293 <script src="../../lib/es/es.Document.js"></script>
9394 <script src="../../lib/es/es.AnnotationSerializer.js"></script>

Status & tagging log