summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/UniversalLanguageSelector/lib/jquery.ime/jquery.ime.js')
-rw-r--r--MLEB/UniversalLanguageSelector/lib/jquery.ime/jquery.ime.js265
1 files changed, 124 insertions, 141 deletions
diff --git a/MLEB/UniversalLanguageSelector/lib/jquery.ime/jquery.ime.js b/MLEB/UniversalLanguageSelector/lib/jquery.ime/jquery.ime.js
index b4b8d8c0..ac5930e8 100644
--- a/MLEB/UniversalLanguageSelector/lib/jquery.ime/jquery.ime.js
+++ b/MLEB/UniversalLanguageSelector/lib/jquery.ime/jquery.ime.js
@@ -1,17 +1,15 @@
-/*! jquery.ime - v0.2.0+20200614
+/*! jquery.ime - v0.2.0+20210414
* https://github.com/wikimedia/jquery.ime
-* Copyright (c) 2020 Santhosh Thottingal; License: (GPL-2.0-or-later OR MIT) */
+* Copyright (c) 2021 Santhosh Thottingal; License: (GPL-2.0-or-later OR MIT) */
( function ( $ ) {
'use strict';
var TextEntryFactory, TextEntry, FormWidgetEntry, ContentEditableEntry,
defaultInputMethod;
- // rangy is defined in the rangy library
- /* global rangy */
-
/**
* private function for debugging
+ *
* @param {jQuery} [$obj]
*/
function debug( $obj ) {
@@ -48,7 +46,7 @@
/**
* IME Class
*
- * @class
+ * @class IME
* @constructor
* @param {HTMLElement} element Element on which to listen for events
* @param {TextEntry} textEntry Text entry object to use to get/set text
@@ -75,6 +73,10 @@
this.language = null;
this.context = '';
if ( this.options.showSelector ) {
+ this.options.selectorInside = options.selectorInside !== undefined ?
+ options.selectorInside :
+ // eslint-disable-next-line no-jquery/no-class-state
+ this.$element.hasClass( 'ime-position-inside' );
this.selector = this.$element.imeselector( this.options );
}
this.listen();
@@ -405,7 +407,7 @@
/**
* TextEntry factory
*
- * @class
+ * @class TextEntryFactory
* @constructor
*/
TextEntryFactory = function IMETextEntryFactory() {
@@ -431,17 +433,21 @@
* Wrap an editable element with the appropriate TextEntry class
*
* @param {jQuery} $element The element to wrap
- * @return {TextEntry|undefined} A TextEntry, or undefined if no match
+ * @return {TextEntry|null} A TextEntry, or null if no match
*/
TextEntryFactory.prototype.wrap = function ( $element ) {
var i, len, TextEntryClass;
+ // eslint-disable-next-line no-jquery/no-class-state
+ if ( $element.hasClass( 'noime' ) ) {
+ return null;
+ }
for ( i = 0, len = this.TextEntryClasses.length; i < len; i++ ) {
TextEntryClass = this.TextEntryClasses[ i ];
if ( TextEntryClass.static.canWrap( $element ) ) {
return new TextEntryClass( $element );
}
}
- return undefined;
+ return null;
};
/* Initialization */
@@ -451,7 +457,7 @@
/**
* Generic text entry
*
- * @class
+ * @class TextEntry
* @abstract
*/
TextEntry = function IMETextEntry() {
@@ -496,7 +502,7 @@
/**
* TextEntry class for input/textarea widgets
*
- * @class
+ * @class FormWidgetEntry
* @constructor
* @param {jQuery} $element The element to wrap
*/
@@ -516,9 +522,7 @@
FormWidgetEntry.static.canWrap = function ( $element ) {
return $element.is( 'input:not([type]), input[type=text], input[type=search], textarea' ) &&
!$element.prop( 'readonly' ) &&
- !$element.prop( 'disabled' ) &&
- // eslint-disable-next-line no-jquery/no-class-state
- !$element.hasClass( 'noime' );
+ !$element.prop( 'disabled' );
};
/* Instance methods */
@@ -527,10 +531,10 @@
* @inheritdoc TextEntry
*/
FormWidgetEntry.prototype.getTextBeforeSelection = function ( maxLength ) {
- var pos = this.getCaretPosition();
+ var element = this.$element.get( 0 );
return this.$element.val().substring(
- Math.max( 0, pos.start - maxLength ),
- pos.start
+ Math.max( 0, element.selectionStart - maxLength ),
+ element.selectionStart
);
};
@@ -538,112 +542,24 @@
* @inheritdoc TextEntry
*/
FormWidgetEntry.prototype.replaceTextAtSelection = function ( precedingCharCount, newText ) {
- var selection,
- length,
- newLines,
- start,
- scrollTop,
- pos,
- element = this.$element.get( 0 );
-
- if ( typeof element.selectionStart === 'number' && typeof element.selectionEnd === 'number' ) {
- // IE9+ and all other browsers
- start = element.selectionStart;
+ var element = this.$element.get( 0 ),
+ start = element.selectionStart,
scrollTop = element.scrollTop;
- // Replace the whole text of the text area:
- // text before + newText + text after.
- // This could be made better if range selection worked on browsers.
- // But for complex scripts, browsers place cursor in unexpected places
- // and it's not possible to fix cursor programmatically.
- // Ref Bug https://bugs.webkit.org/show_bug.cgi?id=66630
- element.value = element.value.substring( 0, start - precedingCharCount ) +
- newText +
- element.value.substring( element.selectionEnd, element.value.length );
-
- // restore scroll
- element.scrollTop = scrollTop;
- // set selection
- element.selectionStart = element.selectionEnd = start - precedingCharCount + newText.length;
- } else {
- // IE8 and lower
- pos = this.getCaretPosition();
- selection = element.createTextRange();
- length = element.value.length;
- // IE doesn't count \n when computing the offset, so we won't either
- newLines = element.value.match( /\n/g );
-
- if ( newLines ) {
- length = length - newLines.length;
- }
-
- selection.moveStart( 'character', pos.start - precedingCharCount );
- selection.moveEnd( 'character', pos.end - length );
-
- selection.text = newText;
- selection.collapse( false );
- selection.select();
- }
- };
-
- /**
- * Get the current selection offsets inside the widget
- *
- * @return {Object} return Offsets in chars (0 means first offset *or* no selection in widget)
- * @return {number} return.start Selection start
- * @return {number} return.end Selection end
- */
- FormWidgetEntry.prototype.getCaretPosition = function () {
- var el = this.$element.get( 0 ),
- start = 0,
- end = 0,
- normalizedValue,
- range,
- textInputRange,
- len,
- newLines,
- endRange;
-
- if ( typeof el.selectionStart === 'number' && typeof el.selectionEnd === 'number' ) {
- start = el.selectionStart;
- end = el.selectionEnd;
- } else {
- // IE
- range = document.selection.createRange();
-
- if ( range && range.parentElement() === el ) {
- len = el.value.length;
- normalizedValue = el.value.replace( /\r\n/g, '\n' );
- newLines = normalizedValue.match( /\n/g );
-
- // Create a working TextRange that lives only in the input
- textInputRange = el.createTextRange();
- textInputRange.moveToBookmark( range.getBookmark() );
-
- // Check if the start and end of the selection are at the very end
- // of the input, since moveStart/moveEnd doesn't return what we want
- // in those cases
- endRange = el.createTextRange();
- endRange.collapse( false );
-
- if ( textInputRange.compareEndPoints( 'StartToEnd', endRange ) > -1 ) {
- if ( newLines ) {
- start = end = len - newLines.length;
- } else {
- start = end = len;
- }
- } else {
- start = -textInputRange.moveStart( 'character', -len );
-
- if ( textInputRange.compareEndPoints( 'EndToEnd', endRange ) > -1 ) {
- end = len;
- } else {
- end = -textInputRange.moveEnd( 'character', -len );
- }
- }
- }
- }
- return { start: start, end: end };
+ // Replace the whole text of the text area:
+ // text before + newText + text after.
+ // This could be made better if range selection worked on browsers.
+ // But for complex scripts, browsers place cursor in unexpected places
+ // and it's not possible to fix cursor programmatically.
+ // Ref Bug https://bugs.webkit.org/show_bug.cgi?id=66630
+ element.value = element.value.substring( 0, start - precedingCharCount ) +
+ newText +
+ element.value.substring( element.selectionEnd, element.value.length );
+
+ // restore scroll
+ element.scrollTop = scrollTop;
+ // set selection
+ element.selectionStart = element.selectionEnd = start - precedingCharCount + newText.length;
};
TextEntryFactory.static.singleton.register( FormWidgetEntry );
@@ -651,7 +567,7 @@
/**
* TextEntry class for ContentEditable
*
- * @class
+ * @class ContentEditableEntry
* @constructor
* @param {jQuery} $element The element to wrap
*/
@@ -669,8 +585,7 @@
* @inheritdoc TextEntry
*/
ContentEditableEntry.static.canWrap = function ( $element ) {
- // eslint-disable-next-line no-jquery/no-class-state
- return $element.is( '[contenteditable]' ) && !$element.hasClass( 'noime' );
+ return $element.is( '[contenteditable]' );
};
/* Instance methods */
@@ -693,9 +608,11 @@
* @inheritdoc SelectionWrapper
*/
ContentEditableEntry.prototype.replaceTextAtSelection = function ( precedingCharCount, newText ) {
- var range, textNode, textOffset, newOffset, newRange;
+ var textNode, textOffset, newOffset, newRange,
+ sel = window.getSelection(),
+ range = this.getSelectedRange();
- if ( !this.getSelectedRange() ) {
+ if ( !range ) {
return;
}
@@ -705,12 +622,11 @@
// browsers that do not support it.
this.$element.trigger( 'compositionstart' );
- range = this.getSelectedRange();
-
if ( !range.collapsed ) {
range.deleteContents();
}
+ newRange = document.createRange();
if ( range.startContainer.nodeType === Node.TEXT_NODE ) {
// Alter this text node's content and move the cursor
textNode = range.startContainer;
@@ -720,10 +636,8 @@
newText +
textNode.nodeValue.substr( textOffset );
newOffset = textOffset - precedingCharCount + newText.length;
- newRange = rangy.createRange();
newRange.setStart( range.startContainer, newOffset );
newRange.setEnd( range.startContainer, newOffset );
- rangy.getSelection().setSingleRange( newRange );
} else {
// XXX assert precedingCharCount === 0
// Insert a new text node with the new text
@@ -732,11 +646,11 @@
textNode,
range.startContainer.childNodes[ range.startOffset ]
);
- newRange = rangy.createRange();
newRange.setStart( textNode, textNode.length );
newRange.setEnd( textNode, textNode.length );
- rangy.getSelection().setSingleRange( newRange );
}
+ sel.removeAllRanges();
+ sel.addRange( newRange );
// Trigger any externally registered jQuery compositionend / input event listeners.
// TODO: Try node.dispatchEvent( new CompositionEvent(...) ) so listeners not
@@ -752,9 +666,9 @@
* @return {Range|null} The selection range
*/
ContentEditableEntry.prototype.getSelectedRange = function () {
- var sel, range;
- rangy.init();
- sel = rangy.getSelection();
+ var range,
+ sel = window.getSelection();
+
if ( sel.rangeCount === 0 ) {
return null;
}
@@ -784,7 +698,7 @@
data = $this.data( 'ime' );
if ( !data ) {
textEntry = TextEntryFactory.static.singleton.wrap( $this );
- if ( textEntry === undefined ) {
+ if ( !textEntry ) {
return;
}
data = new IME( this, textEntry, options );
@@ -804,7 +718,7 @@
$.ime.languages = {};
/**
- * @property {string} Relative/absolute path for the rules folder of jquery.ime
+ * @property {string} Relative or absolute path for the rules folder of jquery.ime
*/
$.ime.path = '../';
$.ime.textEntryFactory = TextEntryFactory.static.singleton;
@@ -877,7 +791,8 @@
$.ime.defaults = {
languages: [], // Languages to be used- by default all languages
helpHandler: null, // Called for each ime option in the menu
- showSelector: true
+ showSelector: true,
+ selectorInside: undefined // If not set will check if '.ime-position-inside' class is preset
};
}( jQuery ) );
@@ -1144,7 +1059,7 @@
/**
* Keydown event handler. Handles shortcut key presses
*
- * @context {HTMLElement}
+ * @this HTMLElement
* @param {jQuery.Event} e
* @return {boolean}
*/
@@ -1215,6 +1130,10 @@
this.$imeSetting.outerWidth();
}
+ if ( this.options.selectorInside ) {
+ top -= this.$imeSetting.outerHeight();
+ }
+
// While determining whether to place the selector above or below the input box,
// take into account the value of scrollTop, to avoid the selector from always
// getting placed above the input box since window.height would be less than top
@@ -1223,6 +1142,9 @@
if ( verticalRoom < this.$imeSetting.outerHeight() ) {
top = elementPosition.top - this.$imeSetting.outerHeight();
+ if ( this.options.selectorInside ) {
+ top += this.$imeSetting.outerHeight();
+ }
menuTop = this.$menu.outerHeight() +
this.$imeSetting.outerHeight();
@@ -1278,7 +1200,7 @@
* Select a language
*
* @param {string} languageCode
- * @return {string|bool} Selected input method id or false
+ * @return {string|boolean} Selected input method id or false
*/
selectLanguage: function ( languageCode ) {
var ime, imePref, language;
@@ -1341,6 +1263,7 @@
/**
* Decide on initial language to select
+ *
* @return {string}
*/
decideLanguage: function () {
@@ -1654,7 +1577,7 @@
},
getPreviousInputMethods: function () {
- return this.registry.previousInputMethods;
+ return this.registry.previousInputMethods || [];
},
// Set the given IM as the last used for the language
@@ -1722,6 +1645,10 @@
name: 'ትራንስልተራትዖን',
source: 'rules/am/am-transliteration.js'
},
+ 'ann-tilde': {
+ name: 'Obolo tilde',
+ source: 'rules/ann/ann-tilde.js'
+ },
'ar-kbd': {
name: 'لوحة المفاتيح العربية',
source: 'rules/ar/ar-kbd.js'
@@ -1758,6 +1685,10 @@
name: 'تۆرکجه',
source: 'rules/azb/azb-kbd.js'
},
+ 'bas-tilde': {
+ name: 'Ɓasaá tilde',
+ source: 'rules/bas/bas-tilde.js'
+ },
'batak-qwerty': {
name: 'Batak QWERTY',
source: 'rules/bbc/batak-qwerty.js'
@@ -1786,6 +1717,10 @@
name: 'روچ کپتین بلوچی',
source: 'rules/bgn/bgn-kbd.js'
},
+ 'bkm-tilde': {
+ name: 'Kom tilde',
+ source: 'rules/bkm/bkm-tilde.js'
+ },
'bm-alt': {
name: 'Bamanankan Alt',
source: 'rules/bm/bm-alt.js'
@@ -2078,6 +2013,10 @@
name: 'Kabɩyɛ tilde',
source: 'rules/kbp/kbp-tilde.js'
},
+ 'kcg-tilde': {
+ name: 'Tyap tilde',
+ source: 'rules/kcg/kcg-tilde.js'
+ },
'ki-tilde': {
name: 'Gĩkũyũ',
source: 'rules/ki/ki-tilde.js'
@@ -2154,6 +2093,10 @@
name: 'Lushootseed Tulalip',
source: 'rules/lut/lut-tulalip.js'
},
+ 'mad-tilde': {
+ name: 'Madhurâ tilde',
+ source: 'rules/mad/mad-tilde.js'
+ },
'mai-inscript': {
name: 'इनस्क्रिप्ट',
source: 'rules/mai/mai-inscript.js',
@@ -2268,6 +2211,10 @@
name: 'ट्रांस्लितेरेशन',
source: 'rules/ne/ne-transliteration.js'
},
+ 'nia-tilde': {
+ name: 'Li Niha tilde',
+ source: 'rules/nia/nia-tilde.js'
+ },
'nqo-standard-qwerty': {
name: "N'Ko standard QWERTY",
source: 'rules/nqo/nqo-standard-qwerty.js'
@@ -2280,6 +2227,10 @@
name: 'Sesotho sa Leboa tilde',
source: 'rules/nso/nso-tilde.js'
},
+ 'nus-tilde': {
+ name: 'Thok Naath tilde',
+ source: 'rules/nus/nus-tilde.js'
+ },
'or-inscript': {
name: 'ଇନସ୍କ୍ରିପ୍ଟ',
source: 'rules/or/or-inscript.js'
@@ -2568,6 +2519,10 @@
autonym: 'አማርኛ',
inputmethods: [ 'am-transliteration' ]
},
+ ann: {
+ autonym: 'Obolo',
+ inputmethods: [ 'ann-tilde' ]
+ },
ar: {
autonym: 'العربية',
inputmethods: [ 'ar-kbd' ]
@@ -2584,6 +2539,10 @@
autonym: 'تۆرکجه',
inputmethods: [ 'azb-kbd' ]
},
+ bas: {
+ autonym: 'ɓasaá',
+ inputmethods: [ 'bas-tilde' ]
+ },
bbc: {
autonym: 'Batak',
inputmethods: [ 'batak-qwerty' ]
@@ -2612,6 +2571,10 @@
autonym: 'भोजपुरी',
inputmethods: [ 'hi-transliteration' ]
},
+ bkm: {
+ autonym: 'Itaŋikom',
+ inputmethods: [ 'bkm-tilde' ]
+ },
bm: {
autonym: 'Bamanankan',
inputmethods: [ 'bm-alt', 'bm-tilde' ]
@@ -2652,6 +2615,10 @@
autonym: 'Dagbani',
inputmethods: [ 'dag-alt', 'dag-tilde' ]
},
+ dar: {
+ autonym: 'дарган',
+ inputmethods: [ 'cyrl-palochka' ]
+ },
de: {
autonym: 'Deutsch',
inputmethods: [ 'de-transliteration' ]
@@ -2784,6 +2751,10 @@
autonym: 'Kabɩyɛ',
inputmethods: [ 'kbp-tilde' ]
},
+ kcg: {
+ autonym: 'Tyap',
+ inputmethods: [ 'kcg-tilde' ]
+ },
ki: {
autonym: 'Gĩkũyũ',
inputmethods: [ 'ki-tilde' ]
@@ -2848,6 +2819,10 @@
autonym: 'मैथिली',
inputmethods: [ 'mai-inscript', 'mai-inscript2' ]
},
+ mad: {
+ autonym: 'madhurâ',
+ inputmethods: [ 'mad-tilde' ]
+ },
mg: {
autonym: 'Malagasy',
inputmethods: [ 'mg-tilde' ]
@@ -2892,6 +2867,10 @@
autonym: 'नेपाल भाषा',
inputmethods: [ 'hi-transliteration', 'hi-inscript' ]
},
+ nia: {
+ autonym: 'li niha',
+ inputmethods: [ 'nia-tilde' ]
+ },
nn: {
autonym: 'Norsk (nynorsk)',
inputmethods: [ 'nb-normforms', 'nb-tildeforms' ]
@@ -2904,6 +2883,10 @@
autonym: 'Sesotho sa Leboa',
inputmethods: [ 'nso-tilde' ]
},
+ nus: {
+ autonym: 'Thok Naath',
+ inputmethods: [ 'nus-tilde' ]
+ },
or: {
autonym: 'ଓଡ଼ିଆ',
inputmethods: [ 'or-phonetic', 'or-transliteration', 'or-inscript', 'or-inscript2', 'or-lekhani', 'or-OdiScript' ]