Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.addEvent("load",function() {
- $('.ui-keyboard-input').bind('keyboardChange', function(e, keyboard, el){
- var currentWord = getSelectedWord(keyboard.$preview.val(),keyboard.preview.selectionStart)
- //console.log(currentWord);
- var message = getMessage(currentWord);
- $("#CurrentWord").text(currentWord);
- $("#SpellMessage").text(message);
- });
- });
- function getMessage(word) {
- if ( word.length < 3 ) { return; }
- if ( word.length > 4 ) { return; }
- message = inspectWord(word);
- //console.log(message);
- return message;
- }
- function inspectWord(word) {
- var firstVowel,secondVowel,consonant
- if ( word.length == 3 ) {
- firstVowel = word.charAt(0);
- consonant = word.charAt(1);
- secondVowel = word.charAt(2);
- }
- else if ( word.length == 4 ) {
- firstVowel = word.charAt(0);
- consonant = word.substr(1,2);
- secondVowel = word.charAt(3);
- }
- else {
- return "Unknown wordtype: \"" + word + "\". Word must be vowel-consonant-vowel";
- }
- if ( !isVowel(firstVowel) || !isConsonant(consonant) || !isVowel(secondVowel) ) {
- var retString = "Unknown wordtype: \"" + word + "\". Word must be vowel-consonant-vowel\n";
- if ( !isVowel(firstVowel) ) { retString += "Unknown vowel: " + firstVowel + "\n"; }
- if ( !isConsonant(consonant) ) { retString += "Unknown consonant: " + consonant + "\n"; }
- if ( !isVowel(secondVowel) ) { retString += "Unknown vowel: " + secondVowel + "\n"; }
- return retString;
- }
- if (( isHardVowel(firstVowel) && !isHardVowel( secondVowel) ) ||
- ( isHardVowel(secondVowel) && !isHardVowel(firstVowel) ) ) {
- return "Vowel types do not match in \"" + word + "\".";
- }
- return "\"" + word + "\" is a valid word.";
- }
- function isVowel(chara) {
- var vowels = "aeiouọịụẹ";
- return vowels.contains(chara.toLowerCase());
- }
- function isConsonant(chara) {
- //console.log("checking for consonant: " + chara);
- if ( chara.length == 1 ) {
- //var consonants = "bcdfghjklmnpqrstvwxyzṣɗƴṅɓƙ";
- var consonants = "bdfghjklmnṅprstvwyz";
- return consonants.contains(chara.toLowerCase());
- }
- else return (chara.toLowerCase().match(/ch|gb|gh|gw|kp|kw|nw|ny|sh/) )
- }
- function isHardVowel(chara) {
- var hVowels = "aọịụẹ"; // added ẹ ( is this correct? )
- return hVowels.contains(chara.toLowerCase());
- }
- function getSelectedWord(text,cursor) {
- var start = cursor;
- var end = cursor;
- //console.log(text,cursor);
- while ( start > 0 && isLetter(text.substring(start-1,start)) ) {
- start--;
- }
- while ( end < text.length && isLetter(text.substring(end,end+1)) ) {
- end++;
- }
- return text.substring(start,end);
- }
- function isLetter(character) {
- if ( character == '' ) { return false; }
- if ( !isNaN(character) ) { return false; } // Is it a number?
- var punctuations = " .,:;?!()[]@#$%^&*-\"'<>+=_";
- if ( punctuations.contains(character) ) { return false; }
- return true;
- }
- //console.log("uwaooo");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement