r112185 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112184‎ | r112185 | r112186 >
Date:03:19, 23 February 2012
Author:inez
Status:deferred
Tags:
Comment:
Input implementation that seems to work in IE, FF and Chrome (all tested on Windows only)
Modified paths:
  • /trunk/extensions/VisualEditor/playground/playground.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/playground/playground.js
@@ -32,6 +32,8 @@
3333 this.$editor.html("<b>Lorem Ipsum is simply dummy text</b> of the printing and typesetting industry. <b>Lorem Ipsum has been the <i>industry's</i> standard</b> dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it <u>to <b>make <i>a type</i> specimen</b> book.</u>");
3434 this.$editor.addClass('leafNode');
3535
 36+ this.keypress = false;
 37+ this.keyup = false;
3638 this.keydown = false;
3739 this.mousedown = false;
3840 this.inime = false;
@@ -44,62 +46,74 @@
4547
4648 app.prototype.onKeyPress = function() {
4749 //console.log("onKeyPress");
 50+ this.keypress = true;
 51+ if ( e.which === 229 ) {
 52+ this.inime = true;
 53+ }
4854 };
4955
5056 app.prototype.onKeyUp = function() {
5157 //console.log("onKeyUp");
 58+ this.keyup = true;
5259 if ( this.inime ) {
5360 this.inime = false;
54 - //console.log("inime = false");
5561 }
5662 };
5763
5864 app.prototype.onKeyDown = function( e ) {
 65+ //console.log("onKeyDown");
5966 this.keydown = true;
60 - //console.log("onKeyDown");
6167 if ( e.which === 229 ) {
6268 this.inime = true;
63 - //console.log("inime = true");
6469 }
6570 };
6671
6772 app.prototype.onMouseDown = function() {
6873 this.mousedown = true;
69 - //console.log("onMouseDown");
 74+
7075 if ( this.inime ) {
7176 this.inime = false;
72 - console.log("inime = false");
73 - }
 77+ }
7478 };
7579
7680 app.prototype.loopFunc = function() {
7781 var text = app.getDOMText(this.$editor[0]);
78 -
 82+
7983 if(text != this.prevText) {
80 - //console.log(text);
81 -
82 - if(this.keydown || this.inime) {
83 - console.log("change from keyboard");
84 - // we are going to need a cursor position
85 - var selection = rangy.getSelection();
86 - var offset = this.getOffset( selection.anchorNode, selection.anchorOffset );
87 - var diffLength = text.length - this.prevText.length;
88 - //console.log("diffLength: " + diffLength);
89 -
90 - if ( diffLength > 0 ) {
91 - //console.log( text.substring(offset - diffLength, offset) );
92 - } else if ( diffLength === 0 ) {
93 - //console.log( text.substring(offset - 1, offset) );
94 - }
9584
96 - } else {
97 - console.log("change not from keyboard");
98 - // find a change and commit to the model
 85+ var selection = rangy.getSelection();
 86+
 87+
 88+
 89+ // keyup in IE
 90+ // keypress and keydown in FF and Chrome
 91+ if ( (($.browser.msie && !this.keyup) || (!$.browser.msie && !this.keypress && !this.mousedown)) && !this.inime ) {
 92+ console.log(this.inime);
 93+ console.log('SPELLCHECK');
 94+ this.prevText = text;
 95+ this.keypress = false;
 96+ this.keyup = false;
 97+ this.mousedown = false;
 98+ return;
9999 }
 100+
 101+ console.log("keyboard");
 102+ // we are going to need a cursor position
 103+ var offset = this.getOffset( selection.anchorNode, selection.anchorOffset );
 104+ var diffLength = text.length - this.prevText.length;
 105+ //console.log("diffLength: " + diffLength);
100106
 107+ if ( diffLength > 0 ) {
 108+ //console.log( text.substring(offset - diffLength, offset) );
 109+ } else if ( diffLength === 0 ) {
 110+ //console.log( text.substring(offset - 1, offset) );
 111+ }
 112+
 113+
101114 this.prevText = text;
102115 }
103 -
 116+ this.keypress = false;
 117+ this.keyup = false;
104118 this.keydown = false;
105119 this.mousedown = false;
106120 };

Status & tagging log