Update jquery.ime from upstream
Change-Id: I1eabfcda79be85c8c28c11472ddc17b2e90c061d
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
/*! jquery.ime - v0.1.0+20130708
|
||||
/*! jquery.ime - v0.1.0+20130715
|
||||
* https://github.com/wikimedia/jquery.ime
|
||||
* Copyright (c) 2013 Santhosh Thottingal; Licensed GPL, MIT */
|
||||
( function ( $ ) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @TODO: document
|
||||
* @param {Function} [options.helpHandler] Called for each input method row in the selector
|
||||
* @param {Object} options.helpHandler.imeSelector
|
||||
* @param {String} options.helpHandler.ime Id of the input method
|
||||
*/
|
||||
function IME( element, options ) {
|
||||
this.$element = $( element );
|
||||
// This needs to be delayed here since extending language list happens at DOM ready
|
||||
@@ -99,9 +105,9 @@
|
||||
altGr = true;
|
||||
}
|
||||
|
||||
// Don't process ASCII control characters (except linefeed),
|
||||
// as well as anything involving
|
||||
// Alt (except for extended keymaps), Ctrl and Meta
|
||||
// Don't process ASCII control characters except linefeed,
|
||||
// as well as anything involving Ctrl, Meta and Alt,
|
||||
// but do process extended keymaps
|
||||
if ( ( e.which < 32 && e.which !== 13 && !altGr ) || e.ctrlKey || e.metaKey ) {
|
||||
// Blank the context
|
||||
this.context = '';
|
||||
@@ -121,9 +127,11 @@
|
||||
// Get the last few characters before the one the user just typed,
|
||||
// to provide context for the transliteration regexes.
|
||||
// We need to append c because it hasn't been added to $this.val() yet
|
||||
input = this.lastNChars( this.$element.val() || this.$element.text(), startPos,
|
||||
this.inputmethod.maxKeyLength )
|
||||
+ c;
|
||||
input = this.lastNChars(
|
||||
this.$element.val() || this.$element.text(),
|
||||
startPos,
|
||||
this.inputmethod.maxKeyLength
|
||||
) + c;
|
||||
|
||||
replacement = this.transliterate( input, this.context, altGr );
|
||||
|
||||
@@ -132,8 +140,9 @@
|
||||
|
||||
if ( this.context.length > this.inputmethod.contextLength ) {
|
||||
// The buffer is longer than needed, truncate it at the front
|
||||
this.context = this.context.substring( this.context.length
|
||||
- this.inputmethod.contextLength );
|
||||
this.context = this.context.substring(
|
||||
this.context.length - this.inputmethod.contextLength
|
||||
);
|
||||
}
|
||||
|
||||
// If replacement equals to input, no replacement is made, because
|
||||
@@ -310,7 +319,8 @@
|
||||
// default options
|
||||
$.ime.defaults = {
|
||||
imePath: '../', // Relative/Absolute path for the rules folder of jquery.ime
|
||||
languages: [] // Languages to be used- by default all languages
|
||||
languages: [], // Languages to be used- by default all languages
|
||||
helpHandler: null // Called for each ime option in the menu
|
||||
};
|
||||
|
||||
// private function for debugging
|
||||
@@ -472,7 +482,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function arrayKeys ( obj ) {
|
||||
function arrayKeys( obj ) {
|
||||
var rv = [];
|
||||
$.each( obj, function ( key ) {
|
||||
rv.push( key );
|
||||
@@ -562,13 +572,13 @@
|
||||
focus: function () {
|
||||
// Hide all other IME settings and collapse open menus
|
||||
$( 'div.imeselector' ).hide();
|
||||
$( 'div.imeselector-menu' ).removeClass( 'open' );
|
||||
$( 'div.imeselector-menu' ).removeClass( 'ime-open' );
|
||||
this.$imeSetting.show();
|
||||
this.resetTimer();
|
||||
},
|
||||
|
||||
show: function () {
|
||||
this.$menu.addClass( 'open' );
|
||||
this.$menu.addClass( 'ime-open' );
|
||||
this.stopTimer();
|
||||
this.$imeSetting.show();
|
||||
|
||||
@@ -576,14 +586,14 @@
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
this.$menu.removeClass( 'open' );
|
||||
this.$menu.removeClass( 'ime-open' );
|
||||
this.resetTimer();
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
toggle: function () {
|
||||
if ( this.$menu.hasClass( 'open' ) ) {
|
||||
if ( this.$menu.hasClass( 'ime-open' ) ) {
|
||||
this.hide();
|
||||
} else {
|
||||
this.show();
|
||||
@@ -607,7 +617,7 @@
|
||||
} );
|
||||
|
||||
imeselector.$element.on( 'blur.ime', function () {
|
||||
if ( !imeselector.$imeSetting.hasClass( 'onfocus' ) ) {
|
||||
if ( !imeselector.$imeSetting.hasClass( 'ime-onfocus' ) ) {
|
||||
imeselector.$imeSetting.hide();
|
||||
imeselector.hide();
|
||||
}
|
||||
@@ -617,10 +627,10 @@
|
||||
// We don't want the selector to disappear
|
||||
// while the user is trying to click it
|
||||
imeselector.stopTimer();
|
||||
imeselector.$imeSetting.addClass( 'onfocus' );
|
||||
imeselector.$imeSetting.addClass( 'ime-onfocus' );
|
||||
} ).mouseleave( function () {
|
||||
imeselector.resetTimer();
|
||||
imeselector.$imeSetting.removeClass( 'onfocus' );
|
||||
imeselector.$imeSetting.removeClass( 'ime-onfocus' );
|
||||
} );
|
||||
|
||||
imeselector.$menu.on( 'click.ime', 'li', function() {
|
||||
@@ -757,7 +767,7 @@
|
||||
// Flip the menu to the top only if it can fit in the space there
|
||||
if ( menutop < top ) {
|
||||
this.$menu
|
||||
.addClass( 'position-top' )
|
||||
.addClass( 'ime-position-top' )
|
||||
.css( 'top', -menutop );
|
||||
}
|
||||
}
|
||||
@@ -780,11 +790,11 @@
|
||||
if ( this.$element.css( 'direction' ) === 'rtl' ) {
|
||||
this.$menu
|
||||
.css( 'left', 0 )
|
||||
.addClass( 'left' );
|
||||
.addClass( 'ime-left' );
|
||||
} else {
|
||||
this.$menu
|
||||
.css( 'left', position.left )
|
||||
.addClass( 'right' );
|
||||
.addClass( 'ime-right' );
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -861,10 +871,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
this.$menu.find( '.checked' ).removeClass( 'checked' );
|
||||
this.$menu.find( 'li.ime-disable' ).removeClass( 'checked' );
|
||||
this.$menu.find( '.ime-checked' ).removeClass( 'ime-checked' );
|
||||
this.$menu.find( 'li.ime-disable' ).removeClass( 'ime-checked' );
|
||||
this.$menu.find( 'li[data-ime-inputmethod=' + inputmethodId + ']' )
|
||||
.addClass( 'checked' );
|
||||
.addClass( 'ime-checked' );
|
||||
ime = this.$element.data( 'ime' );
|
||||
|
||||
if ( inputmethodId === 'system' ) {
|
||||
@@ -893,8 +903,8 @@
|
||||
* Disable the inputmethods (Use the system input method)
|
||||
*/
|
||||
disableIM: function () {
|
||||
this.$menu.find( '.checked' ).removeClass( 'checked' );
|
||||
this.$menu.find( 'div.ime-disable' ).addClass( 'checked' );
|
||||
this.$menu.find( '.ime-checked' ).removeClass( 'ime-checked' );
|
||||
this.$menu.find( 'div.ime-disable' ).addClass( 'ime-checked' );
|
||||
this.$element.data( 'ime' ).disable();
|
||||
this.$imeSetting.find( 'a.ime-name' ).text( '' );
|
||||
this.hide();
|
||||
@@ -936,8 +946,11 @@
|
||||
continue;
|
||||
}
|
||||
|
||||
$languageItem = $( '<a>' ).attr( 'href', '#' ).text( language.autonym );
|
||||
$language = $( '<li class="ime-lang">' ).attr( 'lang', languageCode );
|
||||
$languageItem = $( '<a>' )
|
||||
.attr( 'href', '#' )
|
||||
.text( language.autonym )
|
||||
.addClass( 'selectable-row-item' );
|
||||
$language = $( '<li class="ime-lang selectable-row">' ).attr( 'lang', languageCode );
|
||||
$language.append( $languageItem );
|
||||
$languageList.append( $language );
|
||||
}
|
||||
@@ -953,32 +966,41 @@
|
||||
/**
|
||||
* Prepare input methods in menu for the given language code
|
||||
*
|
||||
* @param languageCode
|
||||
* @param {String} languageCode
|
||||
*/
|
||||
prepareInputMethods: function ( languageCode ) {
|
||||
var language = $.ime.languages[languageCode],
|
||||
$imeList = this.$menu.find( '.ime-list' );
|
||||
$imeList = this.$menu.find( '.ime-list' ),
|
||||
imeSelector = this;
|
||||
|
||||
$imeList.empty();
|
||||
|
||||
$.each( language.inputmethods, function ( index, inputmethod ) {
|
||||
var name = $.ime.sources[inputmethod].name,
|
||||
$imeItem = $( '<a>' ).attr( 'href', '#' ).text( name ),
|
||||
$inputMethod = $( '<li data-ime-inputmethod=' + inputmethod + '>' );
|
||||
var $imeItem, $inputMethod,
|
||||
name = $.ime.sources[inputmethod].name;
|
||||
|
||||
$imeItem = $( '<a>' )
|
||||
.attr( 'href', '#' )
|
||||
.text( name )
|
||||
.addClass( 'selectable-row-item' );
|
||||
|
||||
$inputMethod = $( '<li>' )
|
||||
.attr( 'data-ime-inputmethod', inputmethod )
|
||||
.addClass( 'ime-im selectable-row' )
|
||||
.append( '<span class="ime-im-check"></span>', $imeItem );
|
||||
|
||||
if ( imeSelector.options.helpHandler ) {
|
||||
$inputMethod.append( imeSelector.options.helpHandler.call( imeSelector, inputmethod ) );
|
||||
}
|
||||
|
||||
$inputMethod
|
||||
.append(
|
||||
'<span class="ime-im-check">',
|
||||
$imeItem
|
||||
)
|
||||
.addClass( 'ime-im' );
|
||||
$imeList.append( $inputMethod );
|
||||
} );
|
||||
},
|
||||
|
||||
helpLink: function () {
|
||||
return $( '<div class="ime-help-link">' )
|
||||
return $( '<div class="ime-help-link selectable-row">' )
|
||||
.append( $( '<a>' ).text( 'Help' )
|
||||
.addClass( 'selectable-row-item' )
|
||||
.attr( {
|
||||
'href': 'http://github.com/wikimedia/jquery.ime',
|
||||
'target': '_blank',
|
||||
@@ -1029,7 +1051,7 @@
|
||||
}
|
||||
|
||||
function toggleMenuItem() {
|
||||
return $( '<div class="ime-disable">' ).append(
|
||||
return $( '<div class="ime-disable selectable-row">' ).append(
|
||||
$( '<span>' )
|
||||
.attr( {
|
||||
'class': 'ime-disable-link',
|
||||
@@ -1424,9 +1446,9 @@
|
||||
name: 'ปัตตะโชติ',
|
||||
source: 'rules/th/th-pattachote.js'
|
||||
},
|
||||
'de': {
|
||||
'de-transliteration': {
|
||||
name: 'Deutsch',
|
||||
source: 'rules/de/de.js'
|
||||
source: 'rules/de/de-transliteration.js'
|
||||
},
|
||||
'el-kbd': {
|
||||
name: 'Τυπική πληκτρολόγιο',
|
||||
@@ -1785,7 +1807,7 @@
|
||||
},
|
||||
'de': {
|
||||
autonym: 'Deutsch',
|
||||
inputmethods: [ 'de' ]
|
||||
inputmethods: [ 'de-transliteration' ]
|
||||
},
|
||||
'doi': {
|
||||
autonym: 'डोगरी',
|
||||
|
||||
Reference in New Issue
Block a user