From 3625e110e4844ed232f2a235d34410ba3c3770a8 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Thu, 9 Aug 2012 21:17:32 +0530 Subject: [PATCH] Visual prefix Make sure that suggestion is not only prefix but also visually prefix. Checks the ending character is pre-base vowel. There might be characters with this property in non-indic languages, but I am not aware of now. Change-Id: I91abd4dee6c4349e901777ebd6972731808daf45 --- .../src/jquery.uls.languagefilter.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/jquery.uls/src/jquery.uls.languagefilter.js b/lib/jquery.uls/src/jquery.uls.languagefilter.js index ee28065e..a7809c9c 100644 --- a/lib/jquery.uls/src/jquery.uls.languagefilter.js +++ b/lib/jquery.uls/src/jquery.uls.languagefilter.js @@ -186,6 +186,10 @@ suggestion = ""; } } + // Make sure that it is a visual prefix. + if ( !isVisualPrefix( userInput, suggestion ) ) { + suggestion = ""; + } this.$suggestion.val( suggestion ); }, @@ -355,5 +359,20 @@ }; $.fn.regionselector.Constructor = RegionSelector; + /** + * Check if a prefix is visually prefix of a string + * @param String prefix + * @param String string + */ + function isVisualPrefix( prefix, string ) { + // Pre-base vowel signs of Indic languages. A vowel sign is called pre-base if + // consonant + vowel becomes [vowel][consonant] when rendered. Eg: ക + െ => കെ + var prebases = "െേൈൊോൌெேைொோௌେୈୋୌિਿिিেৈোৌෙේෛොෝෞ"; + if ( prebases.indexOf( string[prefix.length] ) > 0 ) { + return false; + } else { + return true; + } + } } )( jQuery );