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 var remaining
= limit
- byteLength( textInputWidget
.getValue() );
23 remaining
= mw
.language
.convertNumber( remaining
);
24 textInputWidget
.setLabel( remaining
);
26 textInputWidget
.on( 'change', updateCount
);
30 // Actually enforce limit
31 textInputWidget
.$input
.byteLimit( limit
);
35 * Add a visible codepoint (character) limit label to a TextInputWidget.
37 * Uses jQuery#codePointLimit to enforce the limit.
39 * @param {OO.ui.TextInputWidget} textInputWidget Text input widget
40 * @param {number} [limit] Byte limit, defaults to $input's maxlength
42 mw
.widgets
.visibleCodePointLimit = function ( textInputWidget
, limit
) {
43 limit
= limit
|| +textInputWidget
.$input
.attr( 'maxlength' );
45 function updateCount() {
46 var remaining
= limit
- codePointLength( textInputWidget
.getValue() );
47 remaining
= mw
.language
.convertNumber( remaining
);
48 textInputWidget
.setLabel( remaining
);
50 textInputWidget
.on( 'change', updateCount
);
54 // Actually enforce limit
55 textInputWidget
.$input
.codePointLimit( limit
);