r91603 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91602‎ | r91603 | r91604 >
Date:21:01, 6 July 2011
Author:inez
Status:deferred
Tags:
Comment:
Basic support for moving cursor left & right and some small refactoring for cursor blinking (works in IE now)
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Surface.js
@@ -1,3 +1,17 @@
 2+/*@cc_on
 3+(function(f) {
 4+ window.setTimeout = f(window.setTimeout); // overwrites the global function!
 5+ window.setInterval = f(window.setInterval); // overwrites the global function!
 6+})(function(f) {
 7+ return function(c, t) {
 8+ var a = [].slice.call(arguments, 2); // gathers the extra args
 9+ return f(function() {
 10+ c.apply(this, a); // passes them to your function
 11+ }, t);
 12+ };
 13+ });
 14+@*/
 15+
216 /**
317 *
418 * @param $container
@@ -8,7 +22,7 @@
923 this.$ = $container;
1024 this.document = document;
1125 this.rendered = false;
12 - this.cursorInitialized = false;
 26+ this.cursorInterval = null;
1327 this.location = null;
1428 this.render();
1529
@@ -19,8 +33,40 @@
2034 return surface.onMouseDown( e );
2135 }
2236 });
 37+
 38+ // Cursor
 39+ this.$cursor = $( '<div class="editSurface-cursor"></div>' );
 40+ this.$.after( this.$cursor );
 41+
 42+ // Hidden input
 43+ this.$input = $( '<input/>' );
 44+ this.$.before( this.$input );
 45+ this.$input.bind({
 46+ 'keydown' : function(e) {
 47+ return surface.onKeyDown( e );
 48+ }
 49+ });
2350 }
2451
 52+Surface.prototype.onKeyDown = function( e ) {
 53+ switch ( e.keyCode ) {
 54+ case 37: // Left arrow
 55+ this.moveCursorLeft();
 56+ break;
 57+ case 38: // Up arrow
 58+ this.moveCursorUp();
 59+ break;
 60+ case 39: // Right arrow
 61+ this.moveCursorRight();
 62+ break;
 63+ case 40: // Down arrow
 64+ this.moveCursorDown();
 65+ break;
 66+
 67+ }
 68+ return true;
 69+}
 70+
2571 Surface.prototype.onMouseDown = function( e ) {
2672 var $target = $( e.target );
2773 $block = $target.is( '.editSurface-block' ) ? $target : $target.closest( '.editSurface-block' ),
@@ -34,6 +80,8 @@
3581 e.pageY - $block.offset().top );
3682 var offset = block.flow.getOffset( position );
3783 this.setCursor( new Location( block, offset ) );
 84+ this.$input.focus();
 85+ return false;
3886 };
3987
4088 /**
@@ -46,22 +94,17 @@
4795
4896 var position = this.location.block.getPosition( this.location.offset );
4997 var offset = this.location.block.$.offset();
50 -
51 - if( !this.cursorInitialized ) {
52 - this.$cursor = $( '<div class="editSurface-cursor"></div>' );
53 - this.$.after( this.$cursor );
54 -
55 - setInterval( function( surface ) {
56 - surface.$cursor.css('display') == 'block' ? surface.$cursor.hide() : surface.$cursor.show();
57 - }, 500, this );
58 -
59 - this.cursorInitialized = true;
60 - }
6198
6299 this.$cursor.css({
63100 'left': position.left + offset.left,
64101 'top': position.top + offset.top
65102 }).show();
 103+
 104+ // Cursor blinking
 105+ if( this.cursorInterval ) {
 106+ clearInterval( this.cursorInterval );
 107+ }
 108+ this.cursorInterval = setInterval( function( surface ) { surface.$cursor.css( 'display' ) == 'block' ? surface.$cursor.hide() : surface.$cursor.show(); }, 500, this );
66109 };
67110
68111 /**
@@ -70,7 +113,7 @@
71114 * @returns {Location}
72115 */
73116 Surface.prototype.getCursor = function() {
74 - // return location
 117+ return this.location;
75118 };
76119
77120 /**
@@ -178,7 +221,7 @@
179222 */
180223 Surface.prototype.moveCursorRight = function() {
181224 var location = this.getCursor();
182 - if ( location.block.length < location.offset + 1 ) {
 225+ if ( 1 || location.block.length > location.offset + 1 ) {
183226 location.offset++;
184227 } else {
185228 var next = location.block.next();

Status & tagging log