r104803 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104802‎ | r104803 | r104804 >
Date:00:16, 1 December 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added insertion annotation functionality
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -27,6 +27,7 @@
2828 .appendTo( 'body' );
2929 this.$cursor = $( '<div class="es-surfaceView-cursor"></div>' )
3030 .appendTo( 'body' );
 31+ this.insertionAnnotations = [];
3132 this.updateSelectionTimeout = undefined;
3233 this.emitUpdateTimeout = undefined;
3334
@@ -135,38 +136,55 @@
136137
137138 /* Methods */
138139
 140+es.SurfaceView.prototype.getInsertionAnnotations = function() {
 141+ return this.insertionAnnotations;
 142+};
 143+
 144+es.SurfaceView.prototype.addInsertionAnnotation = function( annotation ) {
 145+ this.insertionAnnotations.push( annotation );
 146+};
 147+
 148+es.SurfaceView.prototype.removeInsertionAnnotation = function( annotation ) {
 149+ var index = es.DocumentView.getIndexOfAnnotation( this.insertionAnnotations, annotation );
 150+ if ( index !== -1 ) {
 151+ this.insertionAnnotations.splice( index, 1 );
 152+ }
 153+};
 154+
 155+es.SurfaceView.prototype.clearInsertionAnnotations = function() {
 156+ this.insertionAnnotations = [];
 157+};
 158+
139159 es.SurfaceView.prototype.getModel = function() {
140160 return this.model;
141161 };
142162
143163 es.SurfaceView.prototype.updateSelection = function( delay ) {
 164+ var _this = this;
 165+ function update() {
 166+ if ( _this.currentSelection.from !== _this.currentSelection.to ) {
 167+ _this.hideCursor();
 168+ _this.documentView.drawSelection( _this.currentSelection );
 169+ // Update the context icon position
 170+ _this.contextView.update();
 171+ // Clear insertion annotations
 172+ _this.insertionAnnotations = [];
 173+ } else {
 174+ _this.showCursor();
 175+ _this.documentView.clearSelection( _this.currentSelection );
 176+ // Load new insertion annotations
 177+ _this.insertionAnnotations =
 178+ _this.model.getDocument().getAnnotationsFromOffset( _this.currentSelection.to );
 179+ }
 180+ _this.updateSelectionTimeout = undefined;
 181+ }
144182 if ( delay ) {
145183 if ( this.updateSelectionTimeout !== undefined ) {
146184 return;
147185 }
148 - var _this = this;
149 - this.updateSelectionTimeout = setTimeout( function() {
150 - if ( _this.currentSelection.from !== _this.currentSelection.to ) {
151 - _this.hideCursor();
152 - _this.documentView.drawSelection( _this.currentSelection );
153 - // Update the context icon position
154 - _this.contextView.update();
155 - } else {
156 - _this.showCursor();
157 - _this.documentView.clearSelection( _this.currentSelection );
158 - }
159 - _this.updateSelectionTimeout = undefined;
160 - }, delay );
 186+ this.updateSelectionTimeout = setTimeout( update, delay );
161187 } else {
162 - if ( this.currentSelection.from !== this.currentSelection.to ) {
163 - this.hideCursor();
164 - this.documentView.drawSelection( this.currentSelection );
165 - // Update the context icon position
166 - this.contextView.update();
167 - } else {
168 - this.showCursor();
169 - this.documentView.clearSelection( this.currentSelection );
170 - }
 188+ update();
171189 }
172190 };
173191

Status & tagging log