r110733 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110732‎ | r110733 | r110734 >
Date:06:59, 6 February 2012
Author:amire80
Status:ok
Tags:
Comment:
Making some functions public for QUnit testing.
Modified paths:
  • /trunk/extensions/Narayam/resources/ext.narayam.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/resources/ext.narayam.core.js
@@ -39,6 +39,7 @@
4040 var shortcutKey = getShortCutKey();
4141 // Number of recent input methods to be shown
4242 var recentItemsLength = mw.config.get( 'wgNarayamRecentItemsLength' );
 43+
4344 /* Private functions */
4445
4546 /**
@@ -48,7 +49,7 @@
4950 * @param useExtended Whether to use the extended part of the scheme
5051 * @return Transliterated string, or str if no applicable transliteration found.
5152 */
52 - function transliterate( str, keyBuffer, useExtended ) {
 53+ this.transliterate = function( str, keyBuffer, useExtended ) {
5354 var rules = currentScheme.extended_keyboard && useExtended ?
5455 currentScheme.rules_x : currentScheme.rules;
5556 for ( var i = 0; i < rules.length; i++ ) {
@@ -80,7 +81,7 @@
8182 * @param n Number of characters to go back from pos
8283 * @return Substring of str, at most n characters long, immediately preceding pos
8384 */
84 - function lastNChars( str, pos, n ) {
 85+ this.lastNChars = function( str, pos, n ) {
8586 if ( n === 0 ) {
8687 return '';
8788 } else if ( pos <= n ) {
@@ -97,7 +98,7 @@
9899 * @param b String
99100 * @return Position at which a and b diverge, or -1 if a == b
100101 */
101 - function firstDivergence( a, b ) {
 102+ this.firstDivergence = function( a, b ) {
102103 var minLength = a.length < b.length ? a.length : b.length;
103104 for ( var i = 0; i < minLength; i++ ) {
104105 if ( a.charCodeAt( i ) !== b.charCodeAt( i ) ) {
@@ -254,9 +255,9 @@
255256 // Get the last few characters before the one the user just typed,
256257 // to provide context for the transliteration regexes.
257258 // We need to append c because it hasn't been added to $this.val() yet
258 - var input = lastNChars( $this.val(), startPos, currentScheme.lookbackLength ) + c;
 259+ var input = that.lastNChars( $this.val(), startPos, currentScheme.lookbackLength ) + c;
259260 var keyBuffer = $this.data( 'narayamKeyBuffer' );
260 - var replacement = transliterate( input, keyBuffer, e.altKey );
 261+ var replacement = that.transliterate( input, keyBuffer, e.altKey );
261262
262263 // Update the key buffer
263264 keyBuffer += c;
@@ -272,7 +273,7 @@
273274 }
274275 // Drop a common prefix, if any
275276 // TODO: Profile this, see if it's any faster
276 - var divergingPos = firstDivergence( input, replacement );
 277+ var divergingPos = that.firstDivergence( input, replacement );
277278 input = input.substring( divergingPos );
278279 replacement = replacement.substring( divergingPos );
279280
@@ -377,6 +378,10 @@
378379 }
379380 };
380381
 382+ this.enabled = function() {
 383+ return enabled;
 384+ };
 385+
381386 /**
382387 * Add a transliteration scheme. Schemes whose name is not in
383388 * wgNarayamAvailableSchemes will be ignored.

Status & tagging log