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