jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/392680 )

Change subject: NWE: Show temporary wikitext input widget while loading
......................................................................


NWE: Show temporary wikitext input widget while loading

Bug: T184614
Change-Id: I2e4964cb6329660957815dcb9a74d2ad24d5256b
---
M extension.json
M modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-monobook.css
M modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-vector.css
M modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css
M modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-apextheme.css
M 
modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-wikimediatheme.css
M modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init.css
A modules/ve-mw/init/styles/ve.init.mw.TempWikitextEditorWidget.less
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
A modules/ve-mw/init/ve.init.mw.TempWikitextEditorWidget.js
11 files changed, 304 insertions(+), 60 deletions(-)

Approvals:
  DLynch: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index 034b941..d9aa7da 100644
--- a/extension.json
+++ b/extension.json
@@ -255,6 +255,18 @@
                                "mobile"
                        ]
                },
+               "ext.visualEditor.tempWikitextEditorWidget": {
+                       "scripts": 
"modules/ve-mw/init/ve.init.mw.TempWikitextEditorWidget.js",
+                       "styles": 
"modules/ve-mw/init/styles/ve.init.mw.TempWikitextEditorWidget.less",
+                       "dependencies": [
+                               "mediawiki.editfont.styles",
+                               "mediawiki.user"
+                       ],
+                       "targets": [
+                               "desktop",
+                               "mobile"
+                       ]
+               },
                "ext.visualEditor.desktopArticleTarget.init": {
                        "class": "VisualEditorDesktopArticleTargetInitModule",
                        "scripts": 
"modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js",
@@ -281,7 +293,8 @@
                                "mediawiki.util",
                                "mediawiki.api.options",
                                "ext.visualEditor.supportCheck",
-                               "ext.visualEditor.track"
+                               "ext.visualEditor.track",
+                               "ext.visualEditor.tempWikitextEditorWidget"
                        ],
                        "messages": [
                                "accesskey-ca-editsource",
diff --git 
a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-monobook.css 
b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-monobook.css
index e53671e..f144f15 100644
--- a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-monobook.css
+++ b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-monobook.css
@@ -5,19 +5,6 @@
  * @license The MIT License (MIT); see LICENSE.txt
  */
 
-.ve-init-mw-desktopArticleTarget-toolbar {
-       /* Enforce different font-size for all UI elements of VisualEditor. The 
difference is tiny, but
-          enough to make the icon containers 23.813px rather than 24px and 
thus the icons blurry */
-       font-size: 1.00787401575em; /* 0.8em / x-small / 127% */
-       /* 1/ ( 0.8em / x-small / 127% ) */
-       margin: -0.9921875em;
-       margin-bottom: 0;
-}
-
-.ve-active .ve-init-mw-desktopArticleTarget-originalContent {
-       padding-top: 0.9921875em;
-}
-
 /* Main document debug bar */
 .ve-init-mw-desktopArticleTarget .ve-init-mw-target-surface > .ve-ui-debugBar {
        /* 0.8/0.8 */
diff --git 
a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-vector.css 
b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-vector.css
index b2a1a31..c1641da 100644
--- a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-vector.css
+++ b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-vector.css
@@ -23,14 +23,14 @@
        margin: 0 -1.14286em;
 }
 
-.ve-deactivating .ve-init-mw-desktopArticleTarget-originalContent,
-.ve-activated .ve-init-mw-desktopArticleTarget-originalContent {
-       padding-top: 1em;
-}
-
 .ve-init-mw-desktopArticleTarget .ve-init-mw-target-surface 
.ve-ce-documentNode,
 .ve-init-mw-desktopArticleTarget .ve-init-mw-target-surface 
.ve-ui-surface-placeholder {
        padding: 0 1.14286em; /* 1/0.875 */
+}
+
+.ve-init-mw-desktopArticleTarget .ve-ui-mwWikitextSurface .ve-ce-documentNode,
+.ve-init-mw-desktopArticleTarget .ve-ui-mwWikitextSurface 
.ve-ui-surface-placeholder {
+       padding: 0 1.2em; /* 1/ 16/13.3333 */
 }
 
 .mw-body .ve-init-mw-desktopArticleTarget .ve-init-mw-target-surface 
.ve-ui-surface-placeholder > * {
@@ -38,12 +38,6 @@
        margin-top: 0;
        /* Placeholder doesn't need a border as well */
        border: 0;
-}
-
-.ve-init-mw-desktopArticleTarget-toolbar {
-       font-size: 0.8em;
-       /* 1/0.8 */
-       margin: -1.25em -1.25em 0 -1.25em;
 }
 
 /* Main document debug bar */
@@ -61,19 +55,14 @@
                margin: 0 -1.71429em;
        }
 
-       .ve-deactivating .ve-init-mw-desktopArticleTarget-originalContent,
-       .ve-activated .ve-init-mw-desktopArticleTarget-originalContent {
-               padding-top: 1.25em;
-       }
-
        .ve-init-mw-desktopArticleTarget .ve-init-mw-target-surface 
.ve-ce-documentNode,
        .ve-init-mw-desktopArticleTarget .ve-init-mw-target-surface 
.ve-ui-surface-placeholder {
                padding: 0 1.71429em; /* surface-margin-left (1.5em) / 
(mw-body-content font-size) 0.875em */
        }
 
-       .ve-init-mw-desktopArticleTarget-toolbar {
-               /* 1.25/0.8, 1.5/0.8 */
-               margin: -1.5625em -1.875em 0 -1.875em;
+       .ve-init-mw-desktopArticleTarget .ve-ui-mwWikitextSurface 
.ve-ce-documentNode,
+       .ve-init-mw-desktopArticleTarget .ve-ui-mwWikitextSurface 
.ve-ui-surface-placeholder {
+               padding: 0 1.8em; /* surface-margin-left (1.5em) / 16/13.3333 */
        }
 
        /* Main document debug bar */
diff --git a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css 
b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css
index 70b3c76..40191e8 100644
--- a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css
+++ b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css
@@ -23,6 +23,17 @@
 
 .ve-init-mw-desktopArticleTarget-toolbar-open > .oo-ui-toolbar-bar {
        transform: translateY( 0 );
+       opacity: 1;
+}
+
+.ve-tempSourceEditing .ve-init-mw-desktopArticleTarget-toolbar,
+.ve-tempSourceEditing .ve-init-mw-desktopArticleTarget-toolbar > 
.oo-ui-toolbar-bar {
+       transition: none;
+}
+
+.ve-tempSourceEditing .ve-init-mw-desktopArticleTarget-toolbar {
+       margin-bottom: -3.125em;
+       transition: opacity 2s ease;
 }
 
 /*!
diff --git 
a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-apextheme.css 
b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-apextheme.css
index d1e5f2b..c4a5145 100644
--- 
a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-apextheme.css
+++ 
b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-apextheme.css
@@ -21,3 +21,27 @@
        background-image: -moz-linear-gradient( top, #eaf4fa 0%, #b0d9ee 100% );
        background-image: linear-gradient( to bottom, #eaf4fa 0%, #b0d9ee 100% 
);
 }
+
+.ve-init-mw-desktopArticleTarget-toolbar,
+.ve-init-mw-desktopArticleTarget-toolbarPlaceholder {
+       /* Enforce different font-size for all UI elements of VisualEditor. The 
difference is tiny, but
+          enough to make the icon containers 23.813px rather than 24px and 
thus the icons blurry */
+       font-size: 1.00787401575em; /* 0.8em / x-small / 127% */
+       /* 1/ ( 0.8em / x-small / 127% ) */
+       margin: -0.9921875em;
+       margin-bottom: 0.9921875em;
+}
+
+.ve-init-mw-desktopArticleTarget-toolbarPlaceholder {
+       border-bottom: 1px solid #ccc;
+       box-shadow: 0 2px 2px 0 rgba( 0, 0, 0, 0.1 );
+       background-color: #f8fbfd;
+       background-image: -webkit-gradient( linear, right top, right bottom, 
color-stop( 0, #fff ), color-stop( 100%, #f1f7fb ) );
+       background-image: -webkit-linear-gradient( top, #fff 0, #f1f7fb 100% );
+       background-image: -moz-linear-gradient( top, #fff 0, #f1f7fb 100% );
+       background-image: linear-gradient( to bottom, #fff 0, #f1f7fb 100% );
+}
+
+.ve-init-mw-desktopArticleTarget-toolbarPlaceholder-open {
+       height: 44px;
+}
diff --git 
a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-wikimediatheme.css
 
b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-wikimediatheme.css
index 2bc983f..e4ee9ff 100644
--- 
a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-wikimediatheme.css
+++ 
b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init-wikimediatheme.css
@@ -17,3 +17,28 @@
        height: 0.75em;
        background: #36c;
 }
+
+.ve-init-mw-desktopArticleTarget-toolbar,
+.ve-init-mw-desktopArticleTarget-toolbarPlaceholder {
+       font-size: 0.8em;
+       /* 1/0.8 */
+       margin: -1.25em -1.25em 1.25em -1.25em;
+       /* High-definition-specific styles (because Vector adds 1em to the 
leftNav if width is 982px+ */
+}
+
+@media screen and ( min-width: 982px ) {
+       .ve-init-mw-desktopArticleTarget-toolbar,
+       .ve-init-mw-desktopArticleTarget-toolbarPlaceholder {
+               /* 1.25/0.8, 1.5/0.8 */
+               margin: -1.5625em -1.875em 1.5265em -1.875em;
+       }
+}
+
+.ve-init-mw-desktopArticleTarget-toolbarPlaceholder {
+       border-bottom: 1px solid #c8ccd1;
+       box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 );
+}
+
+.ve-init-mw-desktopArticleTarget-toolbarPlaceholder-open {
+       height: 40px;
+}
diff --git a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init.css 
b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init.css
index 253fbbd..090acf1 100644
--- a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init.css
+++ b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.init.css
@@ -27,7 +27,8 @@
 .ve-activated #p-coll-print_export,
 .ve-activated #t-cite,
 .ve-deactivating .ve-ui-surface,
-.ve-active .ve-init-mw-desktopArticleTarget-editableContent {
+.ve-active .ve-init-mw-desktopArticleTarget-editableContent,
+.ve-active .ve-init-mw-tempWikitextEditorWidget {
        display: none;
 }
 
@@ -70,6 +71,7 @@
 
 .ve-init-mw-desktopArticleTarget-loading-overlay {
        position: absolute;
+       top: 1.25em;
        left: 0;
        right: 0;
        z-index: 1;
@@ -87,6 +89,17 @@
        width: 0;
 }
 
+.ve-init-mw-desktopArticleTarget-toolbarPlaceholder {
+       transition: height 250ms ease;
+       height: 0;
+       /* Toolbar placeholder is styled in theme files */
+}
+
+/* OOUI may not have loaded yet */
+.oo-ui-element-hidden {
+       display: none !important; /* stylelint-disable-line 
declaration-no-important */
+}
+
 /* Section edit links */
 
 .mw-editsection {
diff --git a/modules/ve-mw/init/styles/ve.init.mw.TempWikitextEditorWidget.less 
b/modules/ve-mw/init/styles/ve.init.mw.TempWikitextEditorWidget.less
new file mode 100644
index 0000000..e169aa0
--- /dev/null
+++ b/modules/ve-mw/init/styles/ve.init.mw.TempWikitextEditorWidget.less
@@ -0,0 +1,17 @@
+.ve-init-mw-tempWikitextEditorWidget {
+       border: 0;
+       padding: 0;
+       color: inherit;
+       line-height: 1.5em;
+
+       &:focus {
+               outline: 0;
+               padding: 0;
+       }
+
+       /* Mimics ve-ce-documentNode */
+       &::selection {
+               background: rgba( 109, 169, 247, 0.5 ); /* #6da9f7 */
+       }
+}
+
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js 
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
index 285498d..5109a35 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
@@ -21,7 +21,7 @@
        var conf, tabMessages, uri, pageExists, viewUri, veEditUri, 
veEditSourceUri, isViewPage, isEditPage,
                pageCanLoadEditor, init, targetPromise, enable, tempdisable, 
autodisable,
                tabPreference, enabledForUser, initialWikitext, oldId,
-               isLoading,
+               isLoading, tempWikitextEditor, $toolbarPlaceholder,
                editModes = {
                        edit: 'visual'
                },
@@ -35,8 +35,8 @@
                ],
                plugins = [];
 
-       function showLoading() {
-               var $content, contentRect, offsetTop, windowHeight, top, 
bottom, middle;
+       function showLoading( mode ) {
+               var $content, contentRect, offsetTop, windowHeight, top, 
bottom, middle, loadingTop;
 
                if ( isLoading ) {
                        return;
@@ -58,16 +58,18 @@
                // eslint-disable-next-line no-use-before-define
                $( document ).on( 'keydown', onDocumentKeyDown );
 
-               // Center within visible part of the target
                $content = $( '#content' );
-               contentRect = $content[ 0 ].getBoundingClientRect();
-               windowHeight = $( window ).height();
-               top = Math.max( contentRect.top, 0 );
-               bottom = Math.min( contentRect.bottom, windowHeight );
-               middle = ( bottom - top ) / 2;
-               offsetTop = Math.max( -contentRect.top, 0 );
-
-               init.$loading.css( 'top', middle + offsetTop );
+               if ( mode !== 'source' ) {
+                       // Center within visible part of the target
+                       contentRect = $content[ 0 ].getBoundingClientRect();
+                       windowHeight = $( window ).height();
+                       top = Math.max( contentRect.top, 0 );
+                       bottom = Math.min( contentRect.bottom, windowHeight );
+                       middle = ( bottom - top ) / 2;
+                       offsetTop = Math.max( -contentRect.top, 0 );
+                       loadingTop = middle + offsetTop;
+                       init.$loading.css( 'top', loadingTop );
+               }
 
                $content.prepend( init.$loading );
        }
@@ -98,6 +100,66 @@
                if ( init.$loading ) {
                        init.$loading.detach();
                }
+               if ( tempWikitextEditor ) {
+                       // eslint-disable-next-line no-use-before-define
+                       ve.init.target.toolbarSetupDeferred.then( 
teardownTempWikitextEditor );
+               }
+       }
+
+       function setupTempWikitextEditor( data ) {
+               tempWikitextEditor = new mw.libs.ve.MWTempWikitextEditorWidget( 
{
+                       value: data.content,
+                       onChange: function () {
+                               // Write changes back to response data object,
+                               // which will be used to construct the surface.
+                               data.content = tempWikitextEditor.getValue();
+                               // TODO: Consider writing changes using a
+                               // transaction so they can be undone.
+                               // For now, just mark surface as pre-modified
+                               data.fromEditedState = true;
+                       }
+               } );
+
+               // Create an equal-height placeholder for the toolbar to avoid 
vertical jump
+               // when the real toolbar is ready.
+               $toolbarPlaceholder = $( '<div>' ).addClass( 
've-init-mw-desktopArticleTarget-toolbarPlaceholder' );
+               $( '#content' ).prepend( $toolbarPlaceholder );
+
+               // Add class for transition after first render
+               setTimeout( function () {
+                       $toolbarPlaceholder.addClass( 
've-init-mw-desktopArticleTarget-toolbarPlaceholder-open' );
+               } );
+
+               // Bring forward some transformations that show the editor is 
now ready
+               $( '#firstHeading' ).addClass( 
've-init-mw-desktopArticleTarget-uneditableContent' );
+               $( '#mw-content-text' )
+                       .before( tempWikitextEditor.$element )
+                       .addClass( 'oo-ui-element-hidden' );
+               $( 'html' ).addClass( 've-tempSourceEditing' ).removeClass( 
've-loading' );
+
+               // Resize the textarea to fit content. We could do this more 
often (e.g. on change)
+               // but hopefully this temporary textarea won't be visible for 
too long.
+               tempWikitextEditor.adjustSize().focus();
+               ve.track( 'mwedit.ready', { mode: 'source' } );
+       }
+
+       function teardownTempWikitextEditor() {
+               var range,
+                       nativeRange = tempWikitextEditor.getRange(),
+                       surfaceModel = ve.init.target.getSurface().getModel();
+
+               // Transfer the last-seen selection to the VE surface
+               range = surfaceModel.getRangeFromSourceOffsets( 
nativeRange.from, nativeRange.to );
+               surfaceModel.setLinearSelection( range );
+
+               // Destroy widget and placeholder
+               tempWikitextEditor.$element.remove();
+               tempWikitextEditor = null;
+               $toolbarPlaceholder.remove();
+               $toolbarPlaceholder = null;
+
+               $( '#mw-content-text' ).removeClass( 'oo-ui-element-hidden' );
+               $( 'html' ).removeClass( 've-tempSourceEditing' );
        }
 
        function abortLoading() {
@@ -285,10 +347,15 @@
                                                wikitext: mode === 'visual' ? 
$( '#wpTextbox1' ).textSelection( 'getContents' ) : undefined
                                        } );
                                } )
+                               .done( function ( response ) {
+                                       if ( mode === 'source' ) {
+                                               setupTempWikitextEditor( 
response.visualeditor );
+                                       }
+                               } )
                                .done( incrementLoadingProgress );
                }
 
-               showLoading();
+               showLoading( mode );
                incrementLoadingProgress();
                active = true;
 
@@ -310,7 +377,10 @@
                                return activatePromise;
                        } )
                        .then( function () {
-                               ve.track( 'mwedit.ready', { mode: mode } );
+                               if ( mode === 'visual' ) {
+                                       // 'mwedit.ready' has already been 
fired for source mode in setupTempWikitextEditor
+                                       ve.track( 'mwedit.ready', { mode: mode 
} );
+                               }
                                ve.track( 'mwedit.loaded', { mode: mode } );
                        } )
                        .always( clearLoading );
@@ -1003,7 +1073,7 @@
                                                .attr( { accesskey: mw.msg( 
'accesskey-ca-ve-edit' ), href: veEditUri } )
                                                // Accesskey fires a click event
                                                .on( 'click.ve-target', 
init.onEditTabClick.bind( init, 'visual' ) )
-                                               .hide()
+                                               .addClass( 
'oo-ui-element-hidden' )
                                );
                        }
 
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js 
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
index b8dd7cd..230ad29 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
@@ -247,18 +247,26 @@
 
        ve.track( 'trace.setupToolbar.exit', { mode: mode } );
        if ( !wasSetup ) {
-               setTimeout( function () {
+               if ( $( 'html' ).hasClass( 've-tempSourceEditing' ) ) {
                        toolbar.$element
-                               .css( 'height', toolbar.$bar.outerHeight() )
-                               .addClass( 
've-init-mw-desktopArticleTarget-toolbar-open' );
+                               .css( 'height', '' )
+                               .addClass( 
've-init-mw-desktopArticleTarget-toolbar-open' )
+                               .addClass( 
've-init-mw-desktopArticleTarget-toolbar-opened' );
+                       this.toolbarSetupDeferred.resolve();
+               } else {
                        setTimeout( function () {
-                               // Clear to allow growth during use and when 
resizing window
                                toolbar.$element
-                                       .css( 'height', '' )
-                                       .addClass( 
've-init-mw-desktopArticleTarget-toolbar-opened' );
-                               target.toolbarSetupDeferred.resolve();
-                       }, 250 );
-               } );
+                                       .css( 'height', 
toolbar.$bar.outerHeight() )
+                                       .addClass( 
've-init-mw-desktopArticleTarget-toolbar-open' );
+                               setTimeout( function () {
+                                       // Clear to allow growth during use and 
when resizing window
+                                       toolbar.$element
+                                               .css( 'height', '' )
+                                               .addClass( 
've-init-mw-desktopArticleTarget-toolbar-opened' );
+                                       target.toolbarSetupDeferred.resolve();
+                               }, 250 );
+                       } );
+               }
 
                this.toolbarSetupDeferred.done( function () {
                        var surface = target.getSurface();
@@ -1204,8 +1212,8 @@
        // Mark every non-direct ancestor between editableContent and the 
container as uneditable
        $content = this.$editableContent;
        while ( $content && $content.length && !$content.parent().is( 
this.$container ) ) {
-               $content.prevAll().addClass( 
've-init-mw-desktopArticleTarget-uneditableContent' );
-               $content.nextAll().addClass( 
've-init-mw-desktopArticleTarget-uneditableContent' );
+               $content.prevAll( ':not( .ve-init-mw-tempWikitextEditorWidget 
)' ).addClass( 've-init-mw-desktopArticleTarget-uneditableContent' );
+               $content.nextAll( ':not( .ve-init-mw-tempWikitextEditorWidget 
)' ).addClass( 've-init-mw-desktopArticleTarget-uneditableContent' );
                $content = $content.parent();
        }
 
diff --git a/modules/ve-mw/init/ve.init.mw.TempWikitextEditorWidget.js 
b/modules/ve-mw/init/ve.init.mw.TempWikitextEditorWidget.js
new file mode 100644
index 0000000..829ef78
--- /dev/null
+++ b/modules/ve-mw/init/ve.init.mw.TempWikitextEditorWidget.js
@@ -0,0 +1,87 @@
+/*!
+ * VisualEditor MediaWiki temporary wikitext editor widget
+ *
+ * @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+mw.libs.ve = mw.libs.ve || {};
+
+/**
+ * MediaWiki temporary wikitext editor widget
+ *
+ * This widget can be used to show the user a basic editing interface
+ * while VE libraries are still loading.
+ *
+ * It has a similar API to OO.ui.TextInputWidget, but is designed to
+ * be loaded before any core VE code or dependencies, e.g. OOUI.
+ *
+ * @class
+ * @constructor
+ */
+mw.libs.ve.MWTempWikitextEditorWidget = function 
VeUiMwTempWikitextEditorWidget( config ) {
+       var conf = mw.config.get( 'wgVisualEditor' ),
+               dir = conf.pageLanguageDir,
+               lang = conf.pageLanguageCode;
+
+       this.$element = $( '<textarea>' )
+               .addClass( 've-init-mw-tempWikitextEditorWidget ' )
+               .addClass( 'mw-editfont-' + mw.user.options.get( 'editfont' ) )
+               .addClass( 'mw-content-' + dir )
+               .attr( {
+                       lang: lang,
+                       dir: dir
+               } )
+               .val( config.value )
+               .on( 'input', config.onChange );
+
+       // Move cursor to start
+       this.$element[ 0 ].setSelectionRange( 0, 0 );
+};
+
+/**
+ * Expand the height of the text to fit the contents
+ *
+ * @chainable
+ */
+mw.libs.ve.MWTempWikitextEditorWidget.prototype.adjustSize = function () {
+       // Don't bother with reducing height for simplicity
+       this.$element.height( this.$element[ 0 ].scrollHeight );
+       return this;
+};
+
+/**
+ * Focus the input
+ *
+ * @chainable
+ */
+mw.libs.ve.MWTempWikitextEditorWidget.prototype.focus = function () {
+       this.$element[ 0 ].focus();
+       return this;
+};
+
+/**
+ * Get the input value
+ *
+ * @return {string} Value
+ */
+mw.libs.ve.MWTempWikitextEditorWidget.prototype.getValue = function () {
+       return this.$element.val();
+};
+
+/**
+ * Get the selection range
+ *
+ * @return {Object} Object containing numbers 'from' and 'to'
+ */
+mw.libs.ve.MWTempWikitextEditorWidget.prototype.getRange = function () {
+       var input = this.$element[ 0 ],
+               start = input.selectionStart,
+               end = input.selectionEnd,
+               isBackwards = input.selectionDirection === 'backward';
+
+       return {
+               from: isBackwards ? end : start,
+               to: isBackwards ? start : end
+       };
+};

-- 
To view, visit https://gerrit.wikimedia.org/r/392680
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2e4964cb6329660957815dcb9a74d2ad24d5256b
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Bartosz DziewoƄski <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: DLynch <[email protected]>
Gerrit-Reviewer: Deskana <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to