r113219 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113218‎ | r113219 | r113220 >
Date:08:13, 7 March 2012
Author:christian
Status:deferred
Tags:
Comment:
adding autoRender property to SurfaceView to enable/disable automatic rendering of view when model is updated
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Content.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.LeafNode.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js
@@ -24,6 +24,7 @@
2525 .append( this.documentView.$ );
2626 this.emitUpdateTimeout = undefined;
2727 this.clipboard = {};
 28+ this.autoRender = false;
2829
2930 // Events
3031 this.documentView.$.bind( {
@@ -95,9 +96,11 @@
9697 var tx = this.model.getDocument().prepareContentAnnotation(
9798 range, method, annotation
9899 );
 100+
 101+ this.autoRender = true;
99102 this.model.transact( tx );
100 - // re-render Node
101 - this.renderDomNode ( rangy.getSelection().anchorNode );
 103+ this.autoRender = false;
 104+
102105 } else {
103106 if ( method === 'set' ) {
104107 this.addInsertionAnnotation( annotation );
@@ -160,16 +163,15 @@
161164 setTimeout( function() {
162165 var key = $('#paste').hide().text().replace( /\s/gm, '' );
163166
164 - if ( _this.clipboard[key] ) {
 167+ if ( _this.clipboard[key] ) {
165168 // transact
166169 var tx = _this.documentView.model.prepareInsertion(
167170 insertionPoint, _this.clipboard[key]
168171 );
 172+ _this.autoRender = true;
169173 _this.model.transact( tx );
 174+ _this.autoRender = false;
170175
171 - // re-render
172 - _this.getLeafNode( node ).data( 'view' ).renderContent();
173 -
174176 // clear the prev information from poll object (probably a better way to do this)
175177 _this.poll.prevText =
176178 _this.poll.prevHash =
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Content.js
@@ -1,16 +1,22 @@
2 -ve.ce.Content = function( $container, model ) {
 2+ve.ce.Content = function( model, $container, parent ) {
33 // Inheritance
44 ve.EventEmitter.call( this );
55
66 // Properties
77 this.$ = $container;
88 this.model = model;
 9+ this.parent = parent;
910
1011 if ( model ) {
1112 // Events
1213 var _this = this;
 14+
1315 this.model.on( 'update', function( offset ) {
14 - //_this.render( offset || 0 );
 16+ var surfaceView = _this.getSurfaceView();
 17+
 18+ if (surfaceView.autoRender) {
 19+ _this.render( offset || 0 );
 20+ }
1521 } );
1622 }
1723 };
@@ -236,6 +242,14 @@
237243 return out;
238244 };
239245
 246+ve.ce.Content.prototype.getSurfaceView = function() {
 247+ var view = this;
 248+ while(!view.surfaceView) {
 249+ view = view.parent;
 250+ }
 251+ return view.surfaceView;
 252+}
 253+
240254 /* Inheritance */
241255
242256 ve.extendClass( ve.ce.Content, ve.EventEmitter );
\ No newline at end of file
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.LeafNode.js
@@ -18,7 +18,7 @@
1919 this.$.addClass('ce-leafNode');
2020
2121 // Properties
22 - this.contentView = new ve.ce.Content( this.$, model );
 22+ this.contentView = new ve.ce.Content( model, this.$, this );
2323
2424 // Events
2525 this.contentView.on( 'update', this.emitUpdate );

Status & tagging log