r91696 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91695‎ | r91696 | r91697 >
Date:23:14, 7 July 2011
Author:inez
Status:deferred
Tags:
Comment:
Basic support for typing and deleting content
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Surface.js
@@ -24,6 +24,7 @@
2525 this.rendered = false;
2626 this.location = null;
2727 this.selection = null;
 28+ this.keydownInterval = null;
2829 this.render();
2930
3031 this.state = {
@@ -64,6 +65,7 @@
6566 }
6667
6768 Surface.prototype.onKeyDown = function( e ) {
 69+
6870 switch ( e.keyCode ) {
6971 case 37: // Left arrow
7072 this.moveCursorLeft();
@@ -77,11 +79,48 @@
7880 case 40: // Down arrow
7981 this.moveCursorDown();
8082 break;
 83+ case 8: // Backspace
 84+ this.handleBackspace();
 85+ break;
 86+ case 46: // Delete
 87+ this.handleDelete();
 88+ break;
 89+ default:
 90+ this.cursor.hide();
 91+ if ( this.keydownInterval ) {
 92+ clearTimeout( this.keydownInterval );
 93+ }
 94+ this.keydownInterval = setTimeout( function ( surface ) {
 95+ var val = surface.$input.val();
 96+ surface.$input.val( '' );
 97+ if ( val.length > 0 ) {
 98+ var location = surface.getLocation();
 99+ location.block.insertContent( location.offset, val);
 100+ location.offset++;
 101+ }
 102+ }, 0, this );
 103+ break;
 104+ }
 105+ return true;
 106+}
81107
 108+Surface.prototype.handleBackspace = function() {
 109+ var location = this.getLocation();
 110+ if ( location.offset > 0 ) {
 111+ location.block.deleteContent( location.offset - 1, location.offset );
 112+ location.offset--;
 113+ this.cursor.show( location.block.flow.getPosition( location.offset ), location.block.$.offset() );
82114 }
83 - return true;
84115 }
85116
 117+Surface.prototype.handleDelete = function() {
 118+ var location = this.getLocation();
 119+ if ( location.offset < location.block.getLength() - 1 ) {
 120+ location.block.deleteContent( location.offset, location.offset + 1);
 121+ this.cursor.show( location.block.flow.getPosition( location.offset ), location.block.$.offset() );
 122+ }
 123+}
 124+
86125 Surface.prototype.onMouseDown = function( e ) {
87126 var $target = $( e.target );
88127 $block = $target.is( '.editSurface-block' )

Status & tagging log