From 46d59295c84480e7e094af892be18b4c85cd253e Mon Sep 17 00:00:00 2001 From: Abijeet Date: Mon, 22 Jan 2024 14:56:16 +0530 Subject: [PATCH] Update jquery.ime from upstream Update to: https://github.com/wikimedia/jquery.ime/commit/35c7df6049c4aa9920fe087b8d7f4c0fbc6af556 jquery.uls was updated in I245b4dd68151d9d680368d0cc5750cee4a167f50 Bug: T355104 Change-Id: I49d806c8fbfbede0e8071d31eec39099ed63d1d2 --- lib/jquery.ime/jquery.ime.js | 34 +++++++++---------- lib/jquery.ime/rules/README.md | 2 +- .../rules/bbc/bbc-transliteration.js | 4 +-- lib/jquery.ime/rules/bo/bo-sambhota.js | 2 ++ .../rules/btm/btm-transliteration.js | 2 +- lib/jquery.ime/rules/jv/jv-keyboard.js | 4 +-- lib/jquery.ime/rules/su/su-keyboard.js | 4 +-- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/jquery.ime/jquery.ime.js b/lib/jquery.ime/jquery.ime.js index 0ce185ad..8e0feb10 100644 --- a/lib/jquery.ime/jquery.ime.js +++ b/lib/jquery.ime/jquery.ime.js @@ -1,6 +1,6 @@ -/*! jquery.ime - v0.2.0+20231025 +/*! jquery.ime - v0.2.0+20240122 * https://github.com/wikimedia/jquery.ime -* Copyright (c) 2023 Santhosh Thottingal; License: (GPL-2.0-or-later OR MIT) */ +* Copyright (c) 2024 Santhosh Thottingal; License: (GPL-2.0-or-later OR MIT) */ ( function ( $ ) { 'use strict'; @@ -163,12 +163,12 @@ * @param {string} input * @param {string} context * @param {boolean} altGr whether altGr key is pressed or not - * @return {Object} Transliteration object - * @return {boolean} return.noop Whether to consider input processed or passed through. - * @return {string} return.output The transliterated input or input unmodified. + * @return {Object} Transliteration object, with the following fields: + * "noop": boolean, whether to consider input processed or passed through; + * "output": string, the transliterated input or input unmodified. */ transliterate: function ( input, context, altGr ) { - var patterns, regex, rule, replacement, i, retval; + var patterns, regex, contextRegex, rule, replacement, i, retval; if ( altGr ) { patterns = this.inputmethod.patterns_x || []; @@ -198,6 +198,7 @@ for ( i = 0; i < patterns.length; i++ ) { rule = patterns[ i ]; + // eslint-disable-next-line security/detect-non-literal-regexp regex = new RegExp( rule[ 0 ] + '$' ); // Last item in the rules. @@ -209,7 +210,9 @@ if ( regex.test( input ) ) { // Context test required? if ( rule.length === 3 ) { - if ( new RegExp( rule[ 1 ] + '$' ).test( context ) ) { + // eslint-disable-next-line security/detect-non-literal-regexp + contextRegex = new RegExp( rule[ 1 ] + '$' ); + if ( contextRegex.test( context ) ) { return { noop: false, output: input.replace( regex, replacement ) }; } } else { @@ -285,7 +288,7 @@ 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 = this.context.slice( this.context.length - this.inputmethod.contextLength ); } @@ -358,7 +361,6 @@ * Set the current input method * * @param {string} inputmethodId - * @fires imeLanguageChange */ setIM: function ( inputmethodId ) { this.inputmethod = $.ime.inputmethods[ inputmethodId ]; @@ -370,7 +372,6 @@ * Set the current Language * * @param {string} languageCode - * @fires imeLanguageChange * @return {boolean} */ setLanguage: function ( languageCode ) { @@ -534,7 +535,7 @@ */ FormWidgetEntry.prototype.getTextBeforeSelection = function ( maxLength ) { var element = this.$element.get( 0 ); - return this.$element.val().substring( + return this.$element.val().slice( Math.max( 0, element.selectionStart - maxLength ), element.selectionStart ); @@ -554,9 +555,9 @@ // 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 ) + + element.value = element.value.slice( 0, start - precedingCharCount ) + newText + - element.value.substring( element.selectionEnd, element.value.length ); + element.value.slice( element.selectionEnd, element.value.length ); // Emit an event so that input fields that rely on events // work properly @@ -604,7 +605,7 @@ if ( !range || !range.collapsed || range.startContainer.nodeType !== Node.TEXT_NODE ) { return ''; } - return range.startContainer.nodeValue.substring( + return range.startContainer.nodeValue.slice( Math.max( 0, range.startOffset - maxLength ), range.startOffset ); @@ -641,9 +642,9 @@ textNode = range.startContainer; textOffset = range.startOffset; textNode.nodeValue = - textNode.nodeValue.substr( 0, textOffset - precedingCharCount ) + + textNode.nodeValue.slice( 0, Math.max( 0, textOffset - precedingCharCount ) ) + newText + - textNode.nodeValue.substr( textOffset ); + textNode.nodeValue.slice( textOffset ); newOffset = textOffset - precedingCharCount + newText.length; newRange.setStart( range.startContainer, newOffset ); newRange.setEnd( range.startContainer, newOffset ); @@ -1068,7 +1069,6 @@ /** * Keydown event handler. Handles shortcut key presses * - * @this HTMLElement * @param {jQuery.Event} e * @return {boolean} */ diff --git a/lib/jquery.ime/rules/README.md b/lib/jquery.ime/rules/README.md index 0d106c4b..bd8e0d77 100644 --- a/lib/jquery.ime/rules/README.md +++ b/lib/jquery.ime/rules/README.md @@ -74,7 +74,7 @@ Any valid regular expression is possible as first element of each array item. ex: `[ '([ക-ഹ])a', '$1ാ' ]` ex: `[ '(([ൺ-ൿം])\u200c+)?I', '$2ഐ' ]` -In the above example, $1, $1 etc are according to the normal regular expression +In the above example, $1, $2 etc are according to the normal regular expression replace syntax. The second member of the pattern can be a function as well. diff --git a/lib/jquery.ime/rules/bbc/bbc-transliteration.js b/lib/jquery.ime/rules/bbc/bbc-transliteration.js index f77a0538..b4955fa1 100644 --- a/lib/jquery.ime/rules/bbc/bbc-transliteration.js +++ b/lib/jquery.ime/rules/bbc/bbc-transliteration.js @@ -66,7 +66,7 @@ [ 'V', '᯦' ], [ 'B', 'ᯆ' ], [ 'N', 'ᯊ' ], - [ 'M', 'ᯕ' ], + [ 'M', 'ᯕ' ] ], patterns_x: [ [ '4', '᯼' ], @@ -77,4 +77,4 @@ }; $.ime.register( tobaKbd ); -}( jQuery ) ); \ No newline at end of file +}( jQuery ) ); diff --git a/lib/jquery.ime/rules/bo/bo-sambhota.js b/lib/jquery.ime/rules/bo/bo-sambhota.js index 0b2a60a1..b6bbac47 100644 --- a/lib/jquery.ime/rules/bo/bo-sambhota.js +++ b/lib/jquery.ime/rules/bo/bo-sambhota.js @@ -61,6 +61,7 @@ maxKeyLength: 5, patterns: [ /* eslint-disable max-statements-per-line */ + /* eslint-disable brace-style */ [ ' ', function () { reinit(); return '་'; } ], [ '\\.', function () { reinit(); return ' '; } ], [ ',', function () { reinit(); return '།'; } ], @@ -183,6 +184,7 @@ [ '8', function () { reinit(); return '༨'; } ], [ '9', function () { reinit(); return '༩'; } ] /* eslint-enable max-statements-per-line */ + /* eslint-enable brace-style */ ] }; diff --git a/lib/jquery.ime/rules/btm/btm-transliteration.js b/lib/jquery.ime/rules/btm/btm-transliteration.js index bf782aaf..51fc9ba4 100644 --- a/lib/jquery.ime/rules/btm/btm-transliteration.js +++ b/lib/jquery.ime/rules/btm/btm-transliteration.js @@ -1,4 +1,4 @@ -( function ( $ ) { +( function ( $ ) { 'use strict'; var mandailingTransliteration = { diff --git a/lib/jquery.ime/rules/jv/jv-keyboard.js b/lib/jquery.ime/rules/jv/jv-keyboard.js index f2ff99cb..59c01ba0 100644 --- a/lib/jquery.ime/rules/jv/jv-keyboard.js +++ b/lib/jquery.ime/rules/jv/jv-keyboard.js @@ -1,4 +1,4 @@ -( function ( $ ) { +( function ( $ ) { 'use strict'; var jvKeyboard = { @@ -33,4 +33,4 @@ }; $.ime.register( jvKeyboard ); -}( jQuery ) ); \ No newline at end of file +}( jQuery ) ); diff --git a/lib/jquery.ime/rules/su/su-keyboard.js b/lib/jquery.ime/rules/su/su-keyboard.js index f93c4ff2..e986eaef 100644 --- a/lib/jquery.ime/rules/su/su-keyboard.js +++ b/lib/jquery.ime/rules/su/su-keyboard.js @@ -1,4 +1,4 @@ -( function ( $ ) { +( function ( $ ) { 'use strict'; var suKeyboard = { @@ -17,4 +17,4 @@ }; $.ime.register( suKeyboard ); -}( jQuery ) ); \ No newline at end of file +}( jQuery ) );