blob: 52ebe7478e0de8372660d7b3a338aee9e801cf0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
( function ( mw ) {
var byteLength = require( 'mediawiki.String' ).byteLength,
codePointLength = require( 'mediawiki.String' ).codePointLength;
/**
* @class mw.widgets
*/
/**
* Add a visible byte limit label to a TextInputWidget.
*
* Uses jQuery#byteLimit to enforce the limit.
*
* @param {OO.ui.TextInputWidget} textInputWidget Text input widget
* @param {number} [limit] Byte limit, defaults to $input's maxlength
*/
mw.widgets.visibleByteLimit = function ( textInputWidget, limit ) {
limit = limit || +textInputWidget.$input.attr( 'maxlength' );
function updateCount() {
textInputWidget.setLabel( ( limit - byteLength( textInputWidget.getValue() ) ).toString() );
}
textInputWidget.on( 'change', updateCount );
// Initialise value
updateCount();
// Actually enforce limit
textInputWidget.$input.byteLimit( limit );
};
/**
* Add a visible codepoint (character) limit label to a TextInputWidget.
*
* Uses jQuery#codePointLimit to enforce the limit.
*
* @param {OO.ui.TextInputWidget} textInputWidget Text input widget
* @param {number} [limit] Byte limit, defaults to $input's maxlength
*/
mw.widgets.visibleCodePointLimit = function ( textInputWidget, limit ) {
limit = limit || +textInputWidget.$input.attr( 'maxlength' );
function updateCount() {
textInputWidget.setLabel( ( limit - codePointLength( textInputWidget.getValue() ) ).toString() );
}
textInputWidget.on( 'change', updateCount );
// Initialise value
updateCount();
// Actually enforce limit
textInputWidget.$input.codePointLimit( limit );
};
}( mediaWiki ) );
|