Move $.byteLength and $.trimByteLength to new module 'mediawiki.String'
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets.visibleByteLimit / mediawiki.widgets.visibleByteLimit.js
index a810c98..03ffca7 100644 (file)
@@ -1,25 +1,31 @@
-/**
- * @class mw.widgets
- */
+( function ( mw ) {
 
-/**
- * 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
- */
-mediaWiki.widgets.visibleByteLimit = function ( textInputWidget, limit ) {
-       limit = limit || +textInputWidget.$input.attr( 'maxlength' );
+       var byteLength = require( 'mediawiki.String' ).byteLength;
 
-       function updateCount() {
-               textInputWidget.setLabel( ( limit - $.byteLength( textInputWidget.getValue() ) ).toString() );
-       }
-       textInputWidget.on( 'change', updateCount );
-       // Initialise value
-       updateCount();
+       /**
+        * @class mw.widgets
+        */
 
-       // Actually enforce limit
-       textInputWidget.$input.byteLimit( limit );
-};
+       /**
+        * 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 );
+       };
+
+}( mediaWiki ) );