Index: trunk/extensions/VisualEditor/playground/playground.js |
— | — | @@ -32,6 +32,8 @@ |
33 | 33 | 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>");
|
34 | 34 | this.$editor.addClass('leafNode');
|
35 | 35 |
|
| 36 | + this.keypress = false;
|
| 37 | + this.keyup = false;
|
36 | 38 | this.keydown = false;
|
37 | 39 | this.mousedown = false;
|
38 | 40 | this.inime = false;
|
— | — | @@ -44,62 +46,74 @@ |
45 | 47 |
|
46 | 48 | app.prototype.onKeyPress = function() {
|
47 | 49 | //console.log("onKeyPress");
|
| 50 | + this.keypress = true;
|
| 51 | + if ( e.which === 229 ) {
|
| 52 | + this.inime = true;
|
| 53 | + }
|
48 | 54 | };
|
49 | 55 |
|
50 | 56 | app.prototype.onKeyUp = function() {
|
51 | 57 | //console.log("onKeyUp");
|
| 58 | + this.keyup = true;
|
52 | 59 | if ( this.inime ) {
|
53 | 60 | this.inime = false;
|
54 | | - //console.log("inime = false");
|
55 | 61 | }
|
56 | 62 | };
|
57 | 63 |
|
58 | 64 | app.prototype.onKeyDown = function( e ) {
|
| 65 | + //console.log("onKeyDown");
|
59 | 66 | this.keydown = true;
|
60 | | - //console.log("onKeyDown");
|
61 | 67 | if ( e.which === 229 ) {
|
62 | 68 | this.inime = true;
|
63 | | - //console.log("inime = true");
|
64 | 69 | }
|
65 | 70 | };
|
66 | 71 |
|
67 | 72 | app.prototype.onMouseDown = function() {
|
68 | 73 | this.mousedown = true;
|
69 | | - //console.log("onMouseDown");
|
| 74 | +
|
70 | 75 | if ( this.inime ) {
|
71 | 76 | this.inime = false;
|
72 | | - console.log("inime = false");
|
73 | | - }
|
| 77 | + }
|
74 | 78 | };
|
75 | 79 |
|
76 | 80 | app.prototype.loopFunc = function() {
|
77 | 81 | var text = app.getDOMText(this.$editor[0]);
|
78 | | -
|
| 82 | +
|
79 | 83 | 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 | | - }
|
95 | 84 |
|
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;
|
99 | 99 | }
|
| 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);
|
100 | 106 |
|
| 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 | +
|
101 | 114 | this.prevText = text;
|
102 | 115 | }
|
103 | | -
|
| 116 | + this.keypress = false;
|
| 117 | + this.keyup = false;
|
104 | 118 | this.keydown = false;
|
105 | 119 | this.mousedown = false;
|
106 | 120 | };
|