Advertisement
GauHelldragon

Untitled

Jul 12th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEvent("load",function() {
  2.     $('.ui-keyboard-input').bind('keyboardChange', function(e, keyboard, el){
  3.        
  4.         var currentWord = getSelectedWord(keyboard.$preview.val(),keyboard.preview.selectionStart)
  5.        
  6.         //console.log(currentWord);
  7.        
  8.         var message = getMessage(currentWord);
  9.        
  10.         $("#CurrentWord").text(currentWord);
  11.         $("#SpellMessage").text(message);
  12.        
  13.     });
  14.  
  15. });
  16.  
  17.  
  18. function getMessage(word) {
  19.     if ( word.length < 3 ) { return; }
  20.     if ( word.length > 4 ) { return; }
  21.    
  22.     message = inspectWord(word);
  23.     //console.log(message);
  24.     return message;
  25. }
  26.  
  27. function inspectWord(word) {
  28.     var firstVowel,secondVowel,consonant
  29.     if ( word.length == 3 ) {
  30.         firstVowel = word.charAt(0);
  31.         consonant = word.charAt(1);
  32.         secondVowel = word.charAt(2);
  33.     }
  34.     else if ( word.length == 4 ) {
  35.         firstVowel = word.charAt(0);
  36.         consonant = word.substr(1,2);
  37.         secondVowel = word.charAt(3);
  38.     }
  39.     else {
  40.         return "Unknown wordtype: \"" + word + "\". Word must be vowel-consonant-vowel";
  41.     }
  42.        
  43.     if ( !isVowel(firstVowel) || !isConsonant(consonant) || !isVowel(secondVowel) ) {
  44.         var retString = "Unknown wordtype: \"" + word + "\". Word must be vowel-consonant-vowel\n";
  45.         if ( !isVowel(firstVowel) ) { retString += "Unknown vowel: " + firstVowel + "\n"; }
  46.         if ( !isConsonant(consonant) ) { retString += "Unknown consonant: " + consonant + "\n"; }
  47.         if ( !isVowel(secondVowel) ) { retString += "Unknown vowel: " + secondVowel + "\n"; }
  48.        
  49.         return retString;
  50.     }
  51.  
  52.     if  (( isHardVowel(firstVowel) && !isHardVowel( secondVowel) ) ||
  53.          ( isHardVowel(secondVowel) && !isHardVowel(firstVowel) ) ) {
  54.         return "Vowel types do not match in \"" + word + "\".";
  55.     }
  56.    
  57.    
  58.     return "\"" + word + "\" is a valid word.";
  59.    
  60. }
  61.  
  62. function isVowel(chara) {
  63.     var vowels = "aeiouọịụẹ";
  64.     return vowels.contains(chara.toLowerCase());
  65. }
  66. function isConsonant(chara) {
  67.     //console.log("checking for consonant: " + chara);
  68.    
  69.     if ( chara.length == 1 ) {
  70.         //var consonants = "bcdfghjklmnpqrstvwxyzṣɗƴṅɓƙ";
  71.        
  72.        
  73.         var consonants = "bdfghjklmnṅprstvwyz";
  74.         return consonants.contains(chara.toLowerCase());
  75.     }
  76.     else return (chara.toLowerCase().match(/ch|gb|gh|gw|kp|kw|nw|ny|sh/) )
  77. }
  78. function isHardVowel(chara) {
  79.     var hVowels = "aọịụẹ"; // added ẹ ( is this correct? )
  80.     return hVowels.contains(chara.toLowerCase());
  81. }
  82.  
  83.  
  84. function getSelectedWord(text,cursor) {
  85.     var start = cursor;
  86.     var end = cursor;
  87.    
  88.     //console.log(text,cursor);
  89.    
  90.     while ( start > 0 && isLetter(text.substring(start-1,start)) ) {
  91.         start--;
  92.     }
  93.     while ( end < text.length && isLetter(text.substring(end,end+1)) ) {
  94.         end++;
  95.     }
  96.  
  97.     return text.substring(start,end);
  98. }
  99.  
  100. function isLetter(character) {
  101.     if ( character == '' ) { return false; }
  102.     if ( !isNaN(character) ) { return false; }  // Is it a number?
  103.    
  104.     var punctuations = " .,:;?!()[]@#$%^&*-\"'<>+=_";
  105.    
  106.     if ( punctuations.contains(character) ) { return false; }
  107.  
  108.     return true;
  109.    
  110. }
  111.  
  112.  
  113. //console.log("uwaooo");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement