Skip to content

Commit

Permalink
Merge pull request #5 from NextStepWebs/development
Browse files Browse the repository at this point in the history
Load data asynchronously
  • Loading branch information
WesCossick committed Jul 21, 2015
2 parents 95285c9 + 6579226 commit 3aee6e4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
56 changes: 41 additions & 15 deletions source files/spell-checker.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
CodeMirror.defineMode("spell-checker", function(config, parserConfig) {
function _readFile(path, charset) {
if(!charset) charset = "ISO8859-1";
// Initialize data
var num_loaded = 0;
var aff_data = "";
var dic_data = "";
var typo;

var req = new XMLHttpRequest();
req.open("GET", path, false);

if(req.overrideMimeType)
req.overrideMimeType("text/plain; charset=" + charset);
// Load AFF/DIC data
var xhr_aff = new XMLHttpRequest();
xhr_aff.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff", true);
xhr_aff.onload = function (e) {
if (xhr_aff.readyState === 4 && xhr_aff.status === 200) {
aff_data = xhr_aff.responseText;
num_loaded++;

if(num_loaded == 2){
typo = new Typo("en_US", aff_data, dic_data, {
platform: 'any'
});
}
}
};
xhr_aff.send(null);

var xhr_dic = new XMLHttpRequest();
xhr_dic.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic", true);
xhr_dic.onload = function (e) {
if (xhr_dic.readyState === 4 && xhr_dic.status === 200) {
dic_data = xhr_dic.responseText;
num_loaded++;

if(num_loaded == 2){
typo = new Typo("en_US", aff_data, dic_data, {
platform: 'any'
});
}
}
};
xhr_dic.send(null);

req.send(null);

return req.responseText;
}
// Define what separates a word
var rx_word = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ ";

var typo = new Typo("en_US", _readFile("//cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff"), _readFile("//cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic"), {
platform: 'any'
});

var rx_word = "!\"#$%&()*+,-./:;<=>?@[\\\\\\]^_`{|}~ ";

// Create the overlay and such
var overlay = {
token: function(stream, state) {
var ch = stream.peek();
Expand All @@ -35,7 +61,7 @@ CodeMirror.defineMode("spell-checker", function(config, parserConfig) {
}

if(typo && !typo.check(word))
return "spell-error"; //CSS class: cm-spell-error
return "spell-error"; // CSS class: cm-spell-error

return null;
}
Expand Down
2 changes: 1 addition & 1 deletion spell-checker.min.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* SimpleMDE v1.0.2 (https://github.com/NextStepWebs/codemirror-spell-checker)
* SimpleMDE v1.0.3 (https://github.com/NextStepWebs/codemirror-spell-checker)
* Copyright Next Step Webs, Inc.
* Licensed under the MIT license
*/
Expand Down
4 changes: 2 additions & 2 deletions spell-checker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3aee6e4

Please sign in to comment.