r105946 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105945‎ | r105946 | r105947 >
Date:22:50, 12 December 2011
Author:inez
Status:deferred
Tags:
Comment:
Pretty dirty, but working implementation of history panel for VisualEditor
Modified paths:
  • /trunk/extensions/VisualEditor/modules/sandbox/sandbox.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/sandbox/sandbox.js
@@ -518,24 +518,17 @@
519519 '$': $( '#es-mode-history' ),
520520 '$panel': $( '#es-panel-history' ),
521521 'update': function() {
522 - var events = '',
523 - i = surfaceModel.history.length,
524 - end = Math.max( 0, i - 25 ),
525 - action,
526 - ops,
527 - data,
528 - attr;
529 - while ( --i >= end ) {
530 - attr = i === surfaceModel.historyIndex ?
531 - ' class="es-panel-history-active"' : '';
532 - action = surfaceModel.history[i];
533 - if ( action instanceof es.Range ) {
534 - events += '<div' + attr + '>sel(' + action.from + ', ' + action.to +
535 - ')</div>';
536 - } else {
537 - ops = action.getOperations().slice( 0 );
538 - for ( var j = 0; j < ops.length; j++ ) {
539 - data = ops[j].data || ops[j].length;
 522+ function oneStack( stack, active ) {
 523+ var operations,
 524+ i,
 525+ j,
 526+ events = [],
 527+ data;
 528+
 529+ for ( i = 0; i < stack.length; i++) {
 530+ operations = stack[i].getOperations().slice(0);
 531+ for ( j = 0; j < operations.length; j++ ) {
 532+ data = operations[j].data || operations[j].length;
540533 if ( es.isArray( data ) ) {
541534 data = data[0];
542535 if ( es.isArray( data ) ) {
@@ -545,12 +538,37 @@
546539 if ( typeof data !== 'string' && typeof data !== 'number' ) {
547540 data = '-';
548541 }
549 - ops[j] = ops[j].type.substr( 0, 3 ) + '(' + data + ')';
 542+ operations[j] = operations[j].type.substr( 0, 3 ) + '(' + data + ')';
550543 }
551 - events += '<div' + attr + '>' + ops.join( ', ' ) + '</div>';
 544+ events.push( '[' + operations.join( ', ' ) + ']' );
552545 }
 546+ if ( active) {
 547+ return '<div class="es-panel-history-active">' + events.join( ', ' ) + '</div>';
 548+ } else {
 549+ return '<div>' + events.join( ', ' ) + '</div>';
 550+ }
553551 }
 552+
 553+ var events = '';
 554+ i = surfaceModel.bigStack.length,
 555+ j = 0,
 556+ end;
 557+
 558+ if ( surfaceModel.smallStack.length > 0 ) {
 559+ events += oneStack( surfaceModel.smallStack );
 560+ end = Math.max( 0, i - 24 );
 561+ } else {
 562+ end = Math.max( 0, i - 25 );
 563+ }
 564+
 565+
 566+ while ( --i >= end ) {
 567+ j++;
 568+ events += oneStack( surfaceModel.bigStack[i].stack, surfaceModel.undoIndex === j);
 569+ }
 570+
554571 this.$panel.html( events );
 572+ return;
555573 }
556574 },
557575 'help': {

Status & tagging log