3 var byteLength
= require( 'mediawiki.String' ).byteLength
,
4 codePointLength
= require( 'mediawiki.String' ).codePointLength
;
11 * Add a visible byte limit label to a TextInputWidget.
13 * Uses jQuery#byteLimit to enforce the limit.
15 * @param {OO.ui.TextInputWidget} textInputWidget Text input widget
16 * @param {number} [limit] Byte limit, defaults to $input's maxlength
18 mw
.widgets
.visibleByteLimit = function ( textInputWidget
, limit
) {
19 limit
= limit
|| +textInputWidget
.$input
.attr( 'maxlength' );
21 function updateCount() {
22 textInputWidget
.setLabel( ( limit
- byteLength( textInputWidget
.getValue() ) ).toString() );
24 textInputWidget
.on( 'change', updateCount
);
28 // Actually enforce limit
29 textInputWidget
.$input
.byteLimit( limit
);
33 * Add a visible codepoint (character) limit label to a TextInputWidget.
35 * Uses jQuery#codePointLimit to enforce the limit.
37 * @param {OO.ui.TextInputWidget} textInputWidget Text input widget
38 * @param {number} [limit] Byte limit, defaults to $input's maxlength
40 mw
.widgets
.visibleCodePointLimit = function ( textInputWidget
, limit
) {
41 limit
= limit
|| +textInputWidget
.$input
.attr( 'maxlength' );
43 function updateCount() {
44 textInputWidget
.setLabel( ( limit
- codePointLength( textInputWidget
.getValue() ) ).toString() );
46 textInputWidget
.on( 'change', updateCount
);
50 // Actually enforce limit
51 textInputWidget
.$input
.codePointLimit( limit
);