jQuery.IME: Bump to master (b6102fb)

New changes:
9316542 Remove trailing whitespace and superfluous newlines
1db02ed Improve language and method selection API
22ce72a Merge pull request #434 from divec/api
965c94e Update README and example
b6102fb Remove the unused showSelector property of defaultInputMethod

Change-Id: Icc78795fe1ece63b29ea3863ba1902519c818841
This commit is contained in:
James D. Forrester
2016-03-25 11:24:43 -07:00
parent 9ea6f8d6ba
commit ce31c64f84

View File

@@ -1,4 +1,4 @@
/*! jquery.ime - v0.1.0+20160129
/*! jquery.ime - v0.1.0+20160325
* https://github.com/wikimedia/jquery.ime
* Copyright (c) 2016 Santhosh Thottingal; Licensed GPL, MIT */
( function ( $ ) {
@@ -51,12 +51,20 @@
// This needs to be delayed here since extending language list happens at DOM ready
$.ime.defaults.languages = arrayKeys( $.ime.languages );
this.options = $.extend( {}, $.ime.defaults, options );
if ( this.options.imePath ) {
// Set the global IME path from the one specified to the instance
// TODO: remove this functionality and force clients to set the global
// IME path
$.ime.path = this.options.imePath;
}
this.active = false;
this.shifted = false;
this.inputmethod = null;
this.language = null;
this.context = '';
if ( this.options.showSelector ) {
this.selector = this.$element.imeselector( this.options );
}
this.listen();
}
@@ -75,6 +83,61 @@
this.$element.on( 'disable.ime', $.proxy( this.disable, this ) );
},
/**
* Return a list of available language codes
*
* @return {string[]} Available language codes
*/
getLanguageCodes: function () {
return $.ime.defaults.languages;
},
/**
* Return the autonym for an available language code
*
* @param {string} languageCode The language code
* @return {string} The autonym
*/
getAutonym: function ( languageCode ) {
return $.ime.languages[ languageCode ].autonym;
},
/**
* Return a list of available input method ids for a language
*
* @param {string} languageCode An available language code
* @return {string[]} Available input method ids for that language
*/
getInputMethodIds: function ( languageCode ) {
return $.ime.languages[ languageCode ].inputmethods;
},
/**
* Return the name of an input method
*
* @param {string} inputMethodId The id of an input method
* @return {string} The input method's name
* @see IME#load
*/
getInputMethodName: function ( inputMethodId ) {
return $.ime.sources[ inputMethodId ].name;
},
/**
* Return a list of input method info { id: ..., name: ... } for a language.
*
* @param {string} languageCode An available language code
* @return {Object[]} Info object for each available input method
*/
getInputMethods: function ( languageCode ) {
return this.getInputMethodIds( languageCode ).map( function ( inputMethodId ) {
return {
id: inputMethodId,
name: $.ime.sources[ inputMethodId ].name
};
} );
},
/**
* Transliterate a given string input based on context and input method definition.
* If there are no matching rules defined, returns the original string.
@@ -273,15 +336,18 @@
/**
* Set the current input method
* @param {string} inputmethodId
* @fires imeLanguageChange
*/
setIM: function ( inputmethodId ) {
this.inputmethod = $.ime.inputmethods[inputmethodId];
$.ime.preferences.setIM( inputmethodId );
this.$element.trigger( 'imeMethodChange' );
},
/**
* Set the current Language
* @param {string} languageCode
* @fires imeLanguageChange
* @returns {Boolean}
*/
setLanguage: function ( languageCode ) {
@@ -293,6 +359,7 @@
this.language = languageCode;
$.ime.preferences.setLanguage( languageCode );
this.$element.trigger( 'imeLanguageChange' );
return true;
},
@@ -310,43 +377,8 @@
* @return {jQuery.Promise}
*/
load: function ( inputmethodId ) {
var ime = this,
deferred = $.Deferred(),
dependency;
if ( $.ime.inputmethods[inputmethodId] ) {
return deferred.resolve();
return $.ime.load( inputmethodId );
}
// Validate the input method id.
if ( !$.ime.sources[inputmethodId] ) {
return deferred.reject();
}
dependency = $.ime.sources[inputmethodId].depends;
if ( dependency && !$.ime.inputmethods[dependency] ) {
ime.load( dependency ).done( function () {
ime.load( inputmethodId ).done( function () {
deferred.resolve();
} );
} );
return deferred;
}
debug( 'Loading ' + inputmethodId );
deferred = $.ajax( {
url: ime.options.imePath + $.ime.sources[inputmethodId].source,
dataType: 'script',
cache: true
} ).done( function () {
debug( inputmethodId + ' loaded' );
} ).fail( function ( jqxhr, settings, exception ) {
debug( 'Error in loading inputmethod ' + inputmethodId + ' Exception: ' + exception );
} );
return deferred.promise();
},
};
/**
@@ -746,6 +778,10 @@
$.ime.preferences = {};
$.ime.languages = {};
/**
* @property {string} Relative/absolute path for the rules folder of jquery.ime
*/
$.ime.path = '../';
$.ime.textEntryFactory = TextEntryFactory.static.singleton;
$.ime.TextEntry = TextEntry;
$.ime.inheritClass = inheritClass;
@@ -755,15 +791,67 @@
maxKeyLength: 1
};
/**
* load an input method by given id
* @param {string} inputmethodId
* @return {jQuery.Promise}
*/
$.ime.load = function ( inputmethodId ) {
var dependency,
deferred = $.Deferred();
if ( $.ime.inputmethods[inputmethodId] ) {
return deferred.resolve();
}
// Validate the input method id.
if ( !$.ime.sources[inputmethodId] ) {
return deferred.reject();
}
dependency = $.ime.sources[inputmethodId].depends;
if ( dependency && !$.ime.inputmethods[dependency] ) {
$.ime.load( dependency ).done( function () {
$.ime.load( inputmethodId ).done( function () {
deferred.resolve();
} );
} );
return deferred;
}
debug( 'Loading ' + inputmethodId );
deferred = $.ajax( {
url: $.ime.path + $.ime.sources[inputmethodId].source,
dataType: 'script',
cache: true
} ).done( function () {
debug( inputmethodId + ' loaded' );
} ).fail( function ( jqxhr, settings, exception ) {
debug( 'Error in loading inputmethod ' + inputmethodId + ' Exception: ' + exception );
} );
return deferred.promise();
};
$.ime.register = function ( inputMethod ) {
$.ime.inputmethods[inputMethod.id] = $.extend( {}, defaultInputMethod, inputMethod );
};
/**
* Set the relative/absolute path to rules/ (for loading input methods)
*
* @param {string} path The relative/absolute path in which rules/ lies
*/
$.ime.setPath = function ( path ) {
$.ime.path = path;
};
// default options
$.ime.defaults = {
imePath: '../', // Relative/Absolute path for the rules folder of jquery.ime
languages: [], // Languages to be used- by default all languages
helpHandler: null // Called for each ime option in the menu
helpHandler: null, // Called for each ime option in the menu
showSelector: true
};
/**