Merge "Use HTML::hidden to create input fields"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets.visibleByteLimit / mediawiki.widgets.visibleByteLimit.js
1 /**
2 * Add a visible byte limit label to a TextInputWidget
3 *
4 * Uses jQuery.byteLimit to enforce the limit.
5
6 * @param {OO.ui.TextInputWidget} textInputWidget Text input widget
7 * @param {number} [limit] Byte limit, defaults to $input's maxlength
8 */
9 mediaWiki.widgets.visibleByteLimit = function ( textInputWidget, limit ) {
10 limit = limit || +textInputWidget.$input.attr( 'maxlength' );
11
12 function updateCount() {
13 textInputWidget.setLabel( ( limit - $.byteLength( textInputWidget.getValue() ) ).toString() );
14 }
15 textInputWidget.on( 'change', updateCount );
16 // Initialise value
17 updateCount();
18
19 // Actually enforce limit
20 textInputWidget.$input.byteLimit( limit );
21 };