r105461 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105460‎ | r105461 | r105462 >
Date:21:17, 7 December 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Back, by popular demand, the great side-by-side preview!
Modified paths:
  • /trunk/extensions/VisualEditor/demo/index.html (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/serializers/es.HtmlSerializer.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/serializers/es.WikitextSerializer.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/sandbox/sandbox.css (modified) (history)
  • /trunk/extensions/VisualEditor/modules/sandbox/sandbox.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/demo/index.html
@@ -63,19 +63,27 @@
6464 <body>
6565 <div id="es-base">
6666 <div id="es-toolbar" class="es-toolbar">
 67+ <div id="es-modes" class="es-modes">
 68+ <div id="es-mode-wikitext" class="es-modes-button"></div>
 69+ <div id="es-mode-json" class="es-modes-button"></div>
 70+ <div id="es-mode-html" class="es-modes-button"></div>
 71+ <div id="es-mode-render" class="es-modes-button"></div>
 72+ <div id="es-mode-history" class="es-modes-button"></div>
 73+ </div>
6774 <div id="es-toolbar-shadow"></div>
6875 </div>
6976 <div id="es-panes">
7077 <div id="es-visual">
7178 <div id="es-editor"></div>
7279 </div>
73 - <div id="es-previews">
74 - <div id="es-preview-wikitext" class="es-preview es-code"></div>
75 - <div id="es-preview-json" class="es-preview es-code"></div>
76 - <div id="es-preview-html" class="es-preview es-code"></div>
77 - <div id="es-preview-render" class="es-preview es-render"></div>
78 - <div id="es-preview-history" class="es-preview es-history"></div>
 80+ <div id="es-panels">
 81+ <div id="es-panel-wikitext" class="es-panel es-code"></div>
 82+ <div id="es-panel-json" class="es-panel es-code"></div>
 83+ <div id="es-panel-html" class="es-panel es-code"></div>
 84+ <div id="es-panel-render" class="es-panel es-render"></div>
 85+ <div id="es-panel-history" class="es-panel es-code"></div>
7986 </div>
 87+ <div style="clear:both"></div>
8088 </div>
8189 </div>
8290
Index: trunk/extensions/VisualEditor/modules/es/serializers/es.HtmlSerializer.js
@@ -104,13 +104,13 @@
105105 }
106106 }
107107 return i;
108 - };
 108+ }
109109
110110 function popTags( n ) {
111111 for (var i = 0; i < n; i++ ) {
112112 out.push(closeTags.pop());
113113 }
114 - };
 114+ }
115115
116116 function openLists( bs, bn, attribs ) {
117117 var prefix = commonPrefixLength (bs, bn);
@@ -136,7 +136,7 @@
137137 throw("Unknown node prefix " + c);
138138 }
139139 }
140 - };
 140+ }
141141
142142 for (var i = 0, length = node.children.length; i < length; i++) {
143143 var e = node.children[i];
@@ -152,10 +152,7 @@
153153 default:
154154 tag = 'li'; break;
155155 }
156 - out.push( es.Html.makeTag(tag, e.attributes,
157 - this.content(e.content)
158 - )
159 - );
 156+ out.push( es.Html.makeTag(tag, e.attributes, this.document( e ) ) );
160157 bstack = bnext;
161158 }
162159 popTags(closeTags.length);
Index: trunk/extensions/VisualEditor/modules/es/serializers/es.WikitextSerializer.js
@@ -76,6 +76,10 @@
7777 return this.content( node.content );
7878 };
7979
 80+es.WikitextSerializer.prototype.pre = function( node ) {
 81+ return ' ' + this.content( node.content ).replace( '\n', '\n ' );
 82+};
 83+
8084 es.WikitextSerializer.prototype.list = function( node ) {
8185 var symbolTable = {
8286 'bullet': '*',
@@ -95,7 +99,7 @@
96100 var childNode = node.children[i];
97101 lines.push(
98102 convertStyles( childNode.attributes.styles ) + ' ' +
99 - this.content( childNode.content )
 103+ this.document( childNode )
100104 );
101105 }
102106 return lines.join( '\n' );
Index: trunk/extensions/VisualEditor/modules/sandbox/sandbox.css
@@ -37,25 +37,27 @@
3838 #es-toolbar.float #es-toolbar-shadow {
3939 opacity: 0.5;
4040 }
41 -.es-showData #es-visual,
42 -.es-showData #es-previews {
43 - width: 50%;
 41+.es-showData #es-editor {
 42+ border-right: solid 1px #cccccc;
 43+}
 44+.es-showData #es-visual {
4445 float: left;
 46+ width: 48%;
4547 overflow: hidden;
4648 }
47 -.es-showData #es-editor {
48 - border-right: solid 1px #cccccc;
49 -}
50 -
51 -#es-previews {
 49+#es-panels {
5250 display: none;
5351 }
54 -.es-showData #es-previews {
 52+.es-showData #es-panels {
5553 display: block;
 54+ float: right;
 55+ width: 48%;
 56+ overflow: hidden;
5657 }
57 -.es-preview {
 58+.es-panel {
5859 margin: 0;
5960 padding: 1em;
 61+ display: none;
6062 }
6163 .es-code {
6264 white-space: pre-wrap;
@@ -92,4 +94,68 @@
9395
9496 .mediawiki .es-menuView {
9597 font-size: 0.8em;
 98+}
 99+.es-modes {
 100+ position: absolute;
 101+ right: 0;
 102+ top: 0;
 103+ padding: 0.25em;
 104+}
 105+.es-modes-button {
 106+ display: inline-block;
 107+ border: solid 1px transparent;
 108+ border-radius: 0.125em;
 109+ -webkit-border-radius: 0.125em;
 110+ -moz-border-radius: 0.125em;
 111+ -o-border-radius: 0.125em;
 112+ cursor: pointer;
 113+ vertical-align: top;
 114+ padding: 0.25em;
 115+ width: 22px;
 116+ height: 22px;
 117+ margin-right: 0.125em;
 118+}
 119+.es-modes-button:before {
 120+ content: " ";
 121+ position: absolute;
 122+ display: block;
 123+ height: 22px;
 124+ width: 22px;
 125+}
 126+.es-modes-button:hover {
 127+ border-color: #eeeeee;
 128+}
 129+.es-modes-button:active,
 130+.es-modes-button-down {
 131+ border-color: #dddddd;
 132+ background-image: url(../es/images/fade-down.png);
 133+ background-position: top left;
 134+ background-repeat: repeat-x;
 135+ -webkit-box-shadow: inset 0px 1px 4px 0px rgba(0, 0, 0, 0.07);
 136+ -moz-box-shadow: inset 0px 1px 4px 0px rgba(0, 0, 0, 0.07);
 137+ box-shadow: inset 0px 1px 4px 0px rgba(0, 0, 0, 0.07);
 138+}
 139+#es-mode-wikitext:before {
 140+ background-image: url(../es/images/wikitext.png);
 141+}
 142+
 143+#es-mode-json:before {
 144+ background-image: url(../es/images/json.png);
 145+}
 146+
 147+#es-mode-html:before {
 148+ background-image: url(../es/images/html.png);
 149+}
 150+
 151+#es-mode-render:before {
 152+ background-image: url(../es/images/render.png);
 153+}
 154+
 155+#es-mode-history:before {
 156+ background-image: url(../es/images/history.png);
 157+}
 158+
 159+#es-panel-history div {
 160+ border-bottom: solid 1px #dddddd;
 161+ padding: 0.5em 0;
96162 }
\ No newline at end of file
Index: trunk/extensions/VisualEditor/modules/sandbox/sandbox.js
@@ -443,25 +443,111 @@
444444 window.toolbarView = new es.ToolbarView( $( '#es-toolbar' ), window.surfaceView );
445445 window.surfaceModel.select( new es.Range( 1, 1 ) );
446446
447 - /*
448 - var tools = {
449 - 'textStyle/bold': $( '#es-toolbar-bold' ),
450 - 'textStyle/italic': $( '#es-toolbar-italic' ),
451 - 'link/internal': $( '#es-toolbar-link' )
452 - };
453 - surfaceView.on( 'select', function( range ) {
454 - for ( var key in tools ) {
455 - tools[key].removeClass( 'es-toolbarTool-down' );
456 - }
457 - var annotations = range.getLength() ?
458 - doc.getAnnotationsFromRange( range ) : doc.getAnnotationsFromOffset( range.start );
459 - if ( annotations.length ) {
460 - for ( var i = 0; i < annotations.length; i++ ) {
461 - if ( annotations[i].type in tools ) {
462 - tools[annotations[i].type].addClass( 'es-toolbarTool-down' );
 447+ var $modeButtons = $( '.es-modes-button' ),
 448+ $panels = $( '.es-panel' ),
 449+ $base = $( '#es-base' ),
 450+ $window = $(window),
 451+ currentMode = null,
 452+ modes = {
 453+ 'wikitext': {
 454+ '$': $( '#es-mode-wikitext' ),
 455+ '$panel': $( '#es-panel-wikitext' ),
 456+ 'update': function() {
 457+ this.$panel.text( es.WikitextSerializer.stringify( doc.getPlainObject() ) );
463458 }
 459+ },
 460+ 'json': {
 461+ '$': $( '#es-mode-json' ),
 462+ '$panel': $( '#es-panel-json' ),
 463+ 'update': function() {
 464+ this.$panel.text( es.JsonSerializer.stringify( doc.getPlainObject(), {
 465+ 'indentWith': ' '
 466+ } ) );
 467+ }
 468+ },
 469+ 'html': {
 470+ '$': $( '#es-mode-html' ),
 471+ '$panel': $( '#es-panel-html' ),
 472+ 'update': function() {
 473+ this.$panel.text( es.HtmlSerializer.stringify( doc.getPlainObject() ) );
 474+ }
 475+ },
 476+ 'render': {
 477+ '$': $( '#es-mode-render' ),
 478+ '$panel': $( '#es-panel-render' ),
 479+ 'update': function() {
 480+ this.$panel.html( es.HtmlSerializer.stringify( doc.getPlainObject() ) );
 481+ }
 482+ },
 483+ 'history': {
 484+ '$': $( '#es-mode-history' ),
 485+ '$panel': $( '#es-panel-history' ),
 486+ 'update': function() {
 487+ var events = '',
 488+ i = surfaceModel.history.length,
 489+ end = Math.max( 0, i - 25 ),
 490+ action,
 491+ ops,
 492+ data;
 493+ while ( --i >= end ) {
 494+ action = surfaceModel.history[i];
 495+ if ( action instanceof es.Range ) {
 496+ events += '<div>select( ' + action.from + ', ' + action.to + ' )</div>';
 497+ } else {
 498+ ops = action.getOperations().slice( 0 );
 499+ for ( var j = 0; j < ops.length; j++ ) {
 500+ data = ops[j].data || ops[j].length;
 501+ if ( es.isArray( data ) ) {
 502+ data = data[0];
 503+ if ( es.isArray( data ) ) {
 504+ data = data[0];
 505+ }
 506+ }
 507+ if ( typeof data !== 'string' && typeof data !== 'number' ) {
 508+ data = '-';
 509+ }
 510+ ops[j] = ops[j].type + '( ' + data + ' )';
 511+ }
 512+ events += '<div>' + ops.join( ', ' ) + '</div>';
 513+ }
 514+ }
 515+ this.$panel.html( events );
 516+ }
464517 }
 518+ };
 519+ $.each( modes, function( name, mode ) {
 520+ mode.$.click( function() {
 521+ var disable = $(this).hasClass( 'es-modes-button-down' );
 522+ var visible = $base.hasClass( 'es-showData' );
 523+ $modeButtons.removeClass( 'es-modes-button-down' );
 524+ $panels.hide();
 525+ if ( disable ) {
 526+ if ( visible ) {
 527+ $base.removeClass( 'es-showData' );
 528+ $window.resize();
 529+ }
 530+ currentMode = null;
 531+ } else {
 532+ $(this).addClass( 'es-modes-button-down' );
 533+ mode.$panel.show();
 534+ if ( !visible ) {
 535+ $base.addClass( 'es-showData' );
 536+ $window.resize();
 537+ }
 538+ mode.update.call( mode );
 539+ currentMode = mode;
 540+ }
 541+ } );
 542+ } );
 543+
 544+ surfaceModel.on( 'transact', function() {
 545+ if ( currentMode ) {
 546+ currentMode.update.call( currentMode );
465547 }
466548 } );
467 - */
 549+ surfaceModel.on( 'select', function() {
 550+ if ( currentMode === modes.history ) {
 551+ currentMode.update.call( currentMode );
 552+ }
 553+ } );
468554 } );

Status & tagging log