37 lines
1016 B
JavaScript
37 lines
1016 B
JavaScript
var dictionary = undefined;
|
|
|
|
self.init = function(typoJS, LZString, lang, aff, dic) {
|
|
eval([
|
|
typoJS,
|
|
LZString,
|
|
'aff = LZString.decompressFromUTF16(aff);',
|
|
'dic = LZString.decompressFromUTF16(dic);',
|
|
'dictionary = new Typo(lang, aff, dic);'
|
|
].join('\n'));
|
|
};
|
|
|
|
var timeoutId = undefined;
|
|
self.check = function(words) {
|
|
// Check function has priority over Suggest function
|
|
// This prevents Suggest to run if called just before Check
|
|
timeoutId && clearTimeout(timeoutId);
|
|
for (var i = 0; i < words.length; i++) {
|
|
var word = words[i];
|
|
word.check = dictionary.check(word.value);
|
|
}
|
|
postMessage(JSON.stringify(['check', words]));
|
|
};
|
|
|
|
var word = undefined;
|
|
|
|
function delayedSuggest() {
|
|
timeoutId = undefined;
|
|
var suggestions = dictionary.suggest(word);
|
|
postMessage(JSON.stringify(['suggest', suggestions]));
|
|
}
|
|
|
|
self.suggest = function(wordParam) {
|
|
word = wordParam;
|
|
timeoutId = setTimeout(delayedSuggest, 50);
|
|
};
|