Index: trunk/extensions/Narayam/resources/ext.narayam.core.js |
— | — | @@ -39,6 +39,7 @@ |
40 | 40 | var shortcutKey = getShortCutKey(); |
41 | 41 | // Number of recent input methods to be shown |
42 | 42 | var recentItemsLength = mw.config.get( 'wgNarayamRecentItemsLength' ); |
| 43 | + |
43 | 44 | /* Private functions */ |
44 | 45 | |
45 | 46 | /** |
— | — | @@ -48,7 +49,7 @@ |
49 | 50 | * @param useExtended Whether to use the extended part of the scheme |
50 | 51 | * @return Transliterated string, or str if no applicable transliteration found. |
51 | 52 | */ |
52 | | - function transliterate( str, keyBuffer, useExtended ) { |
| 53 | + this.transliterate = function( str, keyBuffer, useExtended ) { |
53 | 54 | var rules = currentScheme.extended_keyboard && useExtended ? |
54 | 55 | currentScheme.rules_x : currentScheme.rules; |
55 | 56 | for ( var i = 0; i < rules.length; i++ ) { |
— | — | @@ -80,7 +81,7 @@ |
81 | 82 | * @param n Number of characters to go back from pos |
82 | 83 | * @return Substring of str, at most n characters long, immediately preceding pos |
83 | 84 | */ |
84 | | - function lastNChars( str, pos, n ) { |
| 85 | + this.lastNChars = function( str, pos, n ) { |
85 | 86 | if ( n === 0 ) { |
86 | 87 | return ''; |
87 | 88 | } else if ( pos <= n ) { |
— | — | @@ -97,7 +98,7 @@ |
98 | 99 | * @param b String |
99 | 100 | * @return Position at which a and b diverge, or -1 if a == b |
100 | 101 | */ |
101 | | - function firstDivergence( a, b ) { |
| 102 | + this.firstDivergence = function( a, b ) { |
102 | 103 | var minLength = a.length < b.length ? a.length : b.length; |
103 | 104 | for ( var i = 0; i < minLength; i++ ) { |
104 | 105 | if ( a.charCodeAt( i ) !== b.charCodeAt( i ) ) { |
— | — | @@ -254,9 +255,9 @@ |
255 | 256 | // Get the last few characters before the one the user just typed, |
256 | 257 | // to provide context for the transliteration regexes. |
257 | 258 | // 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; |
259 | 260 | var keyBuffer = $this.data( 'narayamKeyBuffer' ); |
260 | | - var replacement = transliterate( input, keyBuffer, e.altKey ); |
| 261 | + var replacement = that.transliterate( input, keyBuffer, e.altKey ); |
261 | 262 | |
262 | 263 | // Update the key buffer |
263 | 264 | keyBuffer += c; |
— | — | @@ -272,7 +273,7 @@ |
273 | 274 | } |
274 | 275 | // Drop a common prefix, if any |
275 | 276 | // TODO: Profile this, see if it's any faster |
276 | | - var divergingPos = firstDivergence( input, replacement ); |
| 277 | + var divergingPos = that.firstDivergence( input, replacement ); |
277 | 278 | input = input.substring( divergingPos ); |
278 | 279 | replacement = replacement.substring( divergingPos ); |
279 | 280 | |
— | — | @@ -377,6 +378,10 @@ |
378 | 379 | } |
379 | 380 | }; |
380 | 381 | |
| 382 | + this.enabled = function() { |
| 383 | + return enabled; |
| 384 | + }; |
| 385 | + |
381 | 386 | /** |
382 | 387 | * Add a transliteration scheme. Schemes whose name is not in |
383 | 388 | * wgNarayamAvailableSchemes will be ignored. |