Update jquery.ime from upstream
Change-Id: Ieb29f2cb90862a9ffb61309dc5cbc351e79074f1 Version: v0.1.0+20130722 Upstream: http://github.com/wikimedia/jquery.ime Bug: 50939
This commit is contained in:
@@ -168,7 +168,7 @@ span.ime-disable-shortcut {
|
|||||||
|
|
||||||
.imeselector-menu .ime-checked {
|
.imeselector-menu .ime-checked {
|
||||||
/* @embed */
|
/* @embed */
|
||||||
background: url(../images/tick.png) left 4px center no-repeat;
|
background: url(../images/tick.png) no-repeat left 4px center;
|
||||||
background-image: -webkit-linear-gradient(transparent, transparent), url('../images/tick.svg');
|
background-image: -webkit-linear-gradient(transparent, transparent), url('../images/tick.svg');
|
||||||
background-image: -moz-linear-gradient(transparent, transparent), url('../images/tick.svg');
|
background-image: -moz-linear-gradient(transparent, transparent), url('../images/tick.svg');
|
||||||
background-image: linear-gradient(transparent, transparent), url('../images/tick.svg');
|
background-image: linear-gradient(transparent, transparent), url('../images/tick.svg');
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/*! jquery.ime - v0.1.0+20130715
|
/*! jquery.ime - v0.1.0+20130722
|
||||||
* 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 ( $ ) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @TODO: document
|
* IME Class
|
||||||
* @param {Function} [options.helpHandler] Called for each input method row in the selector
|
* @param {Function} [options.helpHandler] Called for each input method row in the selector
|
||||||
* @param {Object} options.helpHandler.imeSelector
|
* @param {Object} options.helpHandler.imeSelector
|
||||||
* @param {String} options.helpHandler.ime Id of the input method
|
* @param {String} options.helpHandler.ime Id of the input method
|
||||||
@@ -26,6 +26,9 @@
|
|||||||
IME.prototype = {
|
IME.prototype = {
|
||||||
constructor: IME,
|
constructor: IME,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listen for events and bind to handlers
|
||||||
|
*/
|
||||||
listen: function () {
|
listen: function () {
|
||||||
this.$element.on( 'keypress.ime', $.proxy( this.keypress, this ) );
|
this.$element.on( 'keypress.ime', $.proxy( this.keypress, this ) );
|
||||||
this.$element.on( 'destroy.ime', $.proxy( this.destroy, this ) );
|
this.$element.on( 'destroy.ime', $.proxy( this.destroy, this ) );
|
||||||
@@ -37,10 +40,10 @@
|
|||||||
* Transliterate a given string input based on context and input method definition.
|
* Transliterate a given string input based on context and input method definition.
|
||||||
* If there are no matching rules defined, returns the original string.
|
* If there are no matching rules defined, returns the original string.
|
||||||
*
|
*
|
||||||
* @param input
|
* @param {string} input
|
||||||
* @param context
|
* @param {string} context
|
||||||
* @param altGr bool whether altGr key is pressed or not
|
* @param {boolean} altGr whether altGr key is pressed or not
|
||||||
* @returns String transliterated string
|
* @returns {string} transliterated string
|
||||||
*/
|
*/
|
||||||
transliterate: function ( input, context, altGr ) {
|
transliterate: function ( input, context, altGr ) {
|
||||||
var patterns, regex, rule, replacement, i;
|
var patterns, regex, rule, replacement, i;
|
||||||
@@ -82,6 +85,11 @@
|
|||||||
return input;
|
return input;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keypress handler
|
||||||
|
* @param {jQuery.Event} e Event
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
keypress: function ( e ) {
|
keypress: function ( e ) {
|
||||||
var altGr = false,
|
var altGr = false,
|
||||||
c, startPos, pos, endPos, divergingPos, input, replacement;
|
c, startPos, pos, endPos, divergingPos, input, replacement;
|
||||||
@@ -164,37 +172,66 @@
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the input method is active or not
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
isActive: function () {
|
isActive: function () {
|
||||||
return this.active;
|
return this.active;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the input method
|
||||||
|
*/
|
||||||
disable: function () {
|
disable: function () {
|
||||||
this.active = false;
|
this.active = false;
|
||||||
$.ime.preferences.setIM( 'system' );
|
$.ime.preferences.setIM( 'system' );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable the input method
|
||||||
|
*/
|
||||||
enable: function () {
|
enable: function () {
|
||||||
this.active = true;
|
this.active = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle the active state of input method
|
||||||
|
*/
|
||||||
toggle: function () {
|
toggle: function () {
|
||||||
this.active = !this.active;
|
this.active = !this.active;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the binding of ime to the editable element
|
||||||
|
*/
|
||||||
destroy: function () {
|
destroy: function () {
|
||||||
$( 'body' ).off( '.ime' );
|
$( 'body' ).off( '.ime' );
|
||||||
this.$element.off( '.ime' ).removeData( 'ime' ).removeData( 'imeselector' );
|
this.$element.off( '.ime' ).removeData( 'ime' ).removeData( 'imeselector' );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current input method
|
||||||
|
* @returns {string} Current input method id
|
||||||
|
*/
|
||||||
getIM: function () {
|
getIM: function () {
|
||||||
return this.inputmethod;
|
return this.inputmethod;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current input method
|
||||||
|
* @param {string} inputmethodId
|
||||||
|
*/
|
||||||
setIM: function ( inputmethodId ) {
|
setIM: function ( inputmethodId ) {
|
||||||
this.inputmethod = $.ime.inputmethods[inputmethodId];
|
this.inputmethod = $.ime.inputmethods[inputmethodId];
|
||||||
$.ime.preferences.setIM( inputmethodId );
|
$.ime.preferences.setIM( inputmethodId );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current Language
|
||||||
|
* @param {string} languageCode
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
setLanguage: function ( languageCode ) {
|
setLanguage: function ( languageCode ) {
|
||||||
if ( !$.ime.languages[languageCode] ) {
|
if ( !$.ime.languages[languageCode] ) {
|
||||||
debug( 'Language ' + languageCode + ' is not known to jquery.ime.' );
|
debug( 'Language ' + languageCode + ' is not known to jquery.ime.' );
|
||||||
@@ -207,43 +244,49 @@
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current language
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
getLanguage: function () {
|
getLanguage: function () {
|
||||||
return this.language;
|
return this.language;
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function ( name, callback ) {
|
/**
|
||||||
|
* load an input method by given id
|
||||||
|
* @param {string} inputmethodId
|
||||||
|
* @return {jQuery.Promise}
|
||||||
|
*/
|
||||||
|
load: function ( inputmethodId ) {
|
||||||
var ime = this,
|
var ime = this,
|
||||||
|
deferred = $.Deferred(),
|
||||||
dependency;
|
dependency;
|
||||||
|
|
||||||
if ( $.ime.inputmethods[name] ) {
|
if ( $.ime.inputmethods[inputmethodId] ) {
|
||||||
if ( callback ) {
|
return deferred.resolve();
|
||||||
callback.call( ime );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependency = $.ime.sources[name].depends;
|
dependency = $.ime.sources[inputmethodId].depends;
|
||||||
if ( dependency ) {
|
if ( dependency ) {
|
||||||
this.load( dependency ) ;
|
return $.when( this.load( dependency ), this.load( inputmethodId ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax( {
|
deferred = $.getScript(
|
||||||
url: ime.options.imePath + $.ime.sources[name].source,
|
ime.options.imePath + $.ime.sources[inputmethodId].source
|
||||||
dataType: 'script'
|
).done( function () {
|
||||||
} ).done( function () {
|
debug( inputmethodId + ' loaded' );
|
||||||
debug( name + ' loaded' );
|
|
||||||
|
|
||||||
if ( callback ) {
|
|
||||||
callback.call( ime );
|
|
||||||
}
|
|
||||||
} ).fail( function ( jqxhr, settings, exception ) {
|
} ).fail( function ( jqxhr, settings, exception ) {
|
||||||
debug( 'Error in loading inputmethod ' + name + ' Exception: ' + exception );
|
debug( 'Error in loading inputmethod ' + inputmethodId + ' Exception: ' + exception );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
return deferred.promise();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns an array [start, end] of the beginning
|
/**
|
||||||
// and the end of the current selection in $element
|
* Returns an array [start, end] of the beginning
|
||||||
|
* and the end of the current selection in $element
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
getCaretPosition: function ( $element ) {
|
getCaretPosition: function ( $element ) {
|
||||||
return getCaretPosition( $element );
|
return getCaretPosition( $element );
|
||||||
},
|
},
|
||||||
@@ -274,6 +317,10 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jQuery plugin ime
|
||||||
|
* @param {Object} option
|
||||||
|
*/
|
||||||
$.fn.ime = function ( option ) {
|
$.fn.ime = function ( option ) {
|
||||||
return this.each( function () {
|
return this.each( function () {
|
||||||
var data,
|
var data,
|
||||||
@@ -323,15 +370,19 @@
|
|||||||
helpHandler: null // Called for each ime option in the menu
|
helpHandler: null // Called for each ime option in the menu
|
||||||
};
|
};
|
||||||
|
|
||||||
// private function for debugging
|
/**
|
||||||
|
* private function for debugging
|
||||||
|
*/
|
||||||
function debug( $obj ) {
|
function debug( $obj ) {
|
||||||
if ( window.console && window.console.log ) {
|
if ( window.console && window.console.log ) {
|
||||||
window.console.log( $obj );
|
window.console.log( $obj );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns an array [start, end] of the beginning
|
/**
|
||||||
// and the end of the current selection in $element
|
* Returns an array [start, end] of the beginning
|
||||||
|
* and the end of the current selection in $element
|
||||||
|
*/
|
||||||
function getCaretPosition( $element ) {
|
function getCaretPosition( $element ) {
|
||||||
var el = $element.get( 0 ),
|
var el = $element.get( 0 ),
|
||||||
start = 0,
|
start = 0,
|
||||||
@@ -883,13 +934,13 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ime.load( inputmethodId, function () {
|
ime.load( inputmethodId ).done( function () {
|
||||||
imeselector.inputmethod = $.ime.inputmethods[inputmethodId];
|
imeselector.inputmethod = $.ime.inputmethods[inputmethodId];
|
||||||
imeselector.hide();
|
imeselector.hide();
|
||||||
ime.enable();
|
ime.enable();
|
||||||
ime.setIM( inputmethodId );
|
ime.setIM( inputmethodId );
|
||||||
imeselector.$imeSetting.find( 'a.ime-name' ).text(
|
imeselector.$imeSetting.find( 'a.ime-name' ).text(
|
||||||
imeselector.inputmethod.name
|
$.ime.sources[inputmethodId].name
|
||||||
);
|
);
|
||||||
|
|
||||||
imeselector.position();
|
imeselector.position();
|
||||||
|
|||||||
Reference in New Issue
Block a user