Jforrester has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/354666 )

Change subject: [WIP] Add a byte counter to the edit page's summary field
......................................................................

[WIP] Add a byte counter to the edit page's summary field

Bug: T165856
Change-Id: I84213e6c134f55597340e77876f69063a37ed0a5
---
M resources/Resources.php
M resources/src/mediawiki.action/mediawiki.action.edit.js
2 files changed, 24 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/66/354666/1

diff --git a/resources/Resources.php b/resources/Resources.php
index 4c9934d..f906cc0 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1416,6 +1416,7 @@
                        'jquery.textSelection',
                        'jquery.byteLimit',
                        'mediawiki.api',
+                       'oojs-ui-core'
                ],
        ],
        'mediawiki.action.edit.styles' => [
diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.js 
b/resources/src/mediawiki.action/mediawiki.action.edit.js
index f6a9c54..40e7341 100644
--- a/resources/src/mediawiki.action/mediawiki.action.edit.js
+++ b/resources/src/mediawiki.action/mediawiki.action.edit.js
@@ -19,10 +19,32 @@
        $( function () {
                var editBox, scrollTop, $editForm;
 
+               this.editSummaryInput = $( 'input#wpSummary, #wpSummary > 
input' );
+
+               // FIXME: Fetch from config
+               this.editSummaryByteLimit = 255;
+
                // Make sure edit summary does not exceed byte limit
                // TODO: Replace with this when $wgOOUIEditPage is removed:
                // OO.ui.infuse( 'wpSummary' ).$input.byteLimit( 255 );
-               $( 'input#wpSummary, #wpSummary > input' ).byteLimit( 255 );
+               this.editSummaryInput.byteLimit( this.editSummaryByteLimit );
+
+               // Add a byte counter
+               this.editSummaryCountLabel = new OO.ui.LabelWidget( {
+                       classes: [ 've-ui-mwSaveDialog-editSummary-count' ],
+                       label: String( this.editSummaryByteLimit ),
+                       title: mw.msg( 'mediawiki-editsummary-bytes-remaining' )
+               } );
+
+               this.editSummaryInput.on( 'change', function () {
+                       // TODO: This looks a bit weird, there is no unit in 
the UI, just numbers
+                       // Users likely assume characters but then it seems to 
count down quicker
+                       // than expected. Facing users with the word "byte" is 
bad? (bug 40035)
+                       this.editSummaryCountLabel.setLabel(
+                               String( this.editSummaryByteLimit - 
$.byteLength( this.editSummaryInput.getValue() ) )
+                       );
+               } );
+               $( '#wpSummaryLabel' ).append( this.editSummaryCountLabel );
 
                // Restore the edit box scroll state following a preview 
operation,
                // and set up a form submission handler to remember this state.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I84213e6c134f55597340e77876f69063a37ed0a5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jforrester <jforres...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to