Merge "Update jquery.ime from upstream"
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/*! jquery.ime - v0.1.0+20131111
|
/*! jquery.ime - v0.1.0+20131123
|
||||||
* https://github.com/wikimedia/jquery.ime
|
* https://github.com/wikimedia/jquery.ime
|
||||||
* Copyright (c) 2013 Santhosh Thottingal; Licensed GPL, MIT */
|
* Copyright (c) 2013 Santhosh Thottingal; Licensed GPL, MIT */
|
||||||
( function ( $ ) {
|
( function ( $ ) {
|
||||||
@@ -49,10 +49,12 @@
|
|||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {string} context
|
* @param {string} context
|
||||||
* @param {boolean} altGr whether altGr key is pressed or not
|
* @param {boolean} altGr whether altGr key is pressed or not
|
||||||
* @returns {string} transliterated string
|
* @returns {object} transliteration object
|
||||||
|
* @returns {bool} return.noop Whether to consider input processed or passed through.
|
||||||
|
* @returns {string} return.output the transliterated input or input unmodified.
|
||||||
*/
|
*/
|
||||||
transliterate: function ( input, context, altGr ) {
|
transliterate: function ( input, context, altGr ) {
|
||||||
var patterns, regex, rule, replacement, i;
|
var patterns, regex, rule, replacement, i, retval;
|
||||||
|
|
||||||
if ( altGr ) {
|
if ( altGr ) {
|
||||||
patterns = this.inputmethod.patterns_x || [];
|
patterns = this.inputmethod.patterns_x || [];
|
||||||
@@ -69,7 +71,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( $.isFunction( patterns ) ) {
|
if ( $.isFunction( patterns ) ) {
|
||||||
return patterns.call( this, input, context );
|
// For backwards compatibility, allow the rule functions to return plain
|
||||||
|
// string. Determine noop by checking whether input is different from
|
||||||
|
// output. If the rule function returns object, just return it as-is.
|
||||||
|
retval = patterns.call( this, input, context );
|
||||||
|
if ( typeof retval === 'string' ) {
|
||||||
|
return { noop: input === retval, output: retval };
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0; i < patterns.length; i++ ) {
|
for ( i = 0; i < patterns.length; i++ ) {
|
||||||
@@ -86,17 +96,16 @@
|
|||||||
// Context test required?
|
// Context test required?
|
||||||
if ( rule.length === 3 ) {
|
if ( rule.length === 3 ) {
|
||||||
if ( new RegExp( rule[1] + '$' ).test( context ) ) {
|
if ( new RegExp( rule[1] + '$' ).test( context ) ) {
|
||||||
return input.replace( regex, replacement );
|
return { noop: false, output: input.replace( regex, replacement ) };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No context test required. Just replace.
|
return { noop: false, output: input.replace( regex, replacement ) };
|
||||||
return input.replace( regex, replacement );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No matches, return the input
|
// No matches, return the input
|
||||||
return input;
|
return { noop: true, output: input };
|
||||||
},
|
},
|
||||||
|
|
||||||
keyup: function ( e ) {
|
keyup: function ( e ) {
|
||||||
@@ -180,20 +189,20 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If replacement equals to input, no replacement is made, because
|
// Allow rules to explicitly define whether we match something.
|
||||||
// there's apparently nothing to do. However, there may be something
|
// Otherwise we cannot distinguish between no matching rule and
|
||||||
// to do if AltGr was pressed. For example, if a layout is built in
|
// rule that provides identical output but consumes the event
|
||||||
// a way that allows typing the original character instead of
|
// to prevent normal behavior. See Udmurt layout which uses
|
||||||
// the replacement by pressing it with AltGr.
|
// altgr rules to allow typing the original character.
|
||||||
if ( !altGr && replacement === input ) {
|
if ( replacement.noop ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop a common prefix, if any
|
// Drop a common prefix, if any
|
||||||
divergingPos = this.firstDivergence( input, replacement );
|
divergingPos = this.firstDivergence( input, replacement.output );
|
||||||
input = input.substring( divergingPos );
|
input = input.substring( divergingPos );
|
||||||
replacement = replacement.substring( divergingPos );
|
replacement.output = replacement.output.substring( divergingPos );
|
||||||
replaceText( this.$element, replacement, startPos - input.length + 1, endPos );
|
replaceText( this.$element, replacement.output, startPos - input.length + 1, endPos );
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
@@ -1284,8 +1293,13 @@
|
|||||||
$imeList.empty();
|
$imeList.empty();
|
||||||
|
|
||||||
$.each( language.inputmethods, function ( index, inputmethod ) {
|
$.each( language.inputmethods, function ( index, inputmethod ) {
|
||||||
var $imeItem, $inputMethod,
|
var $imeItem, $inputMethod, source, name;
|
||||||
name = $.ime.sources[inputmethod].name;
|
|
||||||
|
source = $.ime.sources[inputmethod];
|
||||||
|
if ( !source ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
name = source.name;
|
||||||
|
|
||||||
$imeItem = $( '<a>' )
|
$imeItem = $( '<a>' )
|
||||||
.attr( 'href', '#' )
|
.attr( 'href', '#' )
|
||||||
|
|||||||
Reference in New Issue
Block a user