r111173 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111172‎ | r111173 | r111174 >
Date:18:18, 10 February 2012
Author:christian
Status:deferred
Tags:
Comment:
fake cursor demo
Modified paths:
  • /trunk/extensions/VisualEditor/demos/ce/index.php (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/demos/ce/index.php
@@ -158,5 +158,6 @@
159159 <script src="main.js"></script>
160160
161161 <div id="paste" contenteditable="true" style="height: 1px; width: 1px; display: none; opacity: 0; position: absolute;"></div>
 162+ <div id="fake-cursor" style="height: 20px; width: 1px; background: red; position: absolute; top: 0; left: 0;"></div>
162163 </body>
163164 </html>
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js
@@ -42,16 +42,98 @@
4343 _this.onPaste( e );
4444 } );
4545
 46+ this.$.on('mouseup', function( e ) {
 47+ var offset = _this.getSelection().start;
4648
 49+ var $node = _this.documentView.getNodeFromOffset( offset ).$;
 50+ var current = [$node.contents(), 0];
 51+ var stack = [current];
 52+ var node;
 53+ var localOffset;
 54+
 55+ var index = 1 + _this.documentView.getOffsetFromNode( $node.data('view') );
 56+
 57+ console.log(index);
 58+
 59+ while ( stack.length > 0 ) {
 60+ if ( current[1] >= current[0].length ) {
 61+ stack.pop();
 62+ current = stack[ stack.length - 1 ];
 63+ continue;
 64+ }
 65+ var item = current[0][current[1]];
 66+ var $item = current[0].eq( current[1] );
 67+
 68+ if ( item.nodeType === 3 ) {
 69+ var length = item.textContent.length;
 70+ if ( offset >= index && offset <= index + length ) {
 71+ node = item;
 72+ localOffset = offset - index;
 73+ break;
 74+ } else {
 75+ index += length;
 76+ }
 77+ } else if ( item.nodeType === 1 ) {
 78+ if ( $( item ).attr('contentEditable') === "false" ) {
 79+ index += 1;
 80+ } else {
 81+ stack.push( [$item.contents(), 0] );
 82+ current[1]++;
 83+ current = stack[stack.length-1];
 84+ continue;
 85+ }
 86+ }
 87+ current[1]++;
 88+ }
 89+
 90+ console.log(node);
 91+ console.log(localOffset);
 92+
 93+
 94+ setTimeout(function() {
 95+ var sel = rangy.getSelection();
 96+ var range1 = sel.getRangeAt(0);
 97+ var range2 = rangy.createRange();
 98+
 99+ range2.setStart(node, localOffset);
 100+
 101+ sel.setSingleRange(range2);
 102+
 103+ var position = rangy.getSelection().getStartDocumentPos();
 104+ $('#fake-cursor').css('top', position.y).css('left', position.x);
 105+
 106+ sel.setSingleRange(range1);
 107+ }, 3000);
 108+
 109+
 110+
 111+
 112+
 113+ /*
 114+ clearTimeout( _this.cursorTimeout );
 115+ _this.broadcastCursor();
 116+ */
 117+ } );
 118+
47119 // Initialization
48120 this.documentView.renderContent();
49121
50122 this.worker = null;
51123 this.node = null;
 124+
 125+ //this.broadcastCursor();
52126 };
53127
54128 /* Methods */
55129
 130+ve.es.Surface.prototype.broadcastCursor = function() {
 131+ var _this = this;
 132+
 133+ //console.log( rangy.getSelection().getStartDocumentPos() );
 134+
 135+ _this.cursorTimeout = setTimeout($.proxy(arguments.callee, _this), 5000);
 136+};
 137+
56138 ve.es.Surface.prototype.onCutCopy = function( e ) {
57139 var _this = this,
58140 key = rangy.getSelection().getRangeAt(0).toString().replace(/( |\r\n|\n|\r|\t)/gm,"");
@@ -213,8 +295,6 @@
214296 if ( $( item ).attr('contentEditable') === "false" ) {
215297 offset += 1;
216298 } else {
217 - console.log(item);
218 - console.log(localNode);
219299 if ( item === localNode ) {
220300 offset += localOffset;
221301 break;

Status & tagging log