-
Notifications
You must be signed in to change notification settings - Fork 0
/
BJSpell.Jaxer.html
136 lines (136 loc) · 4.78 KB
/
BJSpell.Jaxer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<script runat="server">
/*!
* BJSpell JavaScript Dictionary Creator - Server v0.0.1
* http://code.google.com/p/bjspell/
*
* Copyright (c) 2009 Andrea Giammarchi
* Licensed under the Lesser GPL licenses.
*
* Date: 2009-02-05 23:50:01 +0000 (Wed, 05 Feb 2009)
* Revision: 2
* How To: just browse this page. Put dictionaries in the dictionary folder, choose which one you would like to convert and click it.
* ToDo: documentation
*/
if(Jaxer.request.data.name && Jaxer.request.data.data)(function(data){
var file = new Jaxer.File(Jaxer.request.currentFolder.concat("/dictionary.js/", data.name).replace(/\//g, "\\"));
file.open("wb");
file.write(data.data);
file.close();
})(Jaxer.request.data);
else(function(){
for(var
valid = {},
files = new Jaxer.Dir(Jaxer.request.currentFolder.concat("/dictionary/").replace(/\//g, "\\")).readDir(),
i = 0,
length = files.length;
i < length;
i++
)
valid[files[i].leaf.split(".")[0]] = true;
var ul = document.createElement("ul"),
li = document.createElement("li");
for(var key in valid)
ul.appendChild(li.cloneNode(true)).appendChild(document.createTextNode('Create ' + key + ' Dictionary'));
delete li;
ul.style.cursor = "pointer";
ul.setAttribute("onclick", "return Jaxer.BJSpell.create.apply(Jaxer.BJSpell,arguments);");
onload = function(){
document.body.appendChild(ul);
};
})();
</script>
<script runat="client">
/*!
* BJSpell JavaScript Dictionary Creator - Client v0.0.1
* http://code.google.com/p/bjspell/
*
* Copyright (c) 2009 Andrea Giammarchi
* Licensed under the Lesser GPL licenses.
*
* Date: 2009-02-05 23:50:01 +0000 (Wed, 05 Feb 2009)
* Revision: 1
* ToDo: documentation
*/
Jaxer.BJSpell = {
create:function(event){
var li = event ? event.target : window.event.srcElement,
file = li.firstChild.nodeValue.substring(7).split(" ")[0],
global = this.hunspell(file + ".dic", this.dic),
xhr = new XMLHttpRequest;
xhr.open("post", "?self", false);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("name=".concat(file, ".js&data=BJSpell.", file, "=", encodeURIComponent(
global.substring(0, global.length - 1).concat(",rules:",
this.hunspell(file + ".aff", this.aff), "}")
)
));
return false;
},
aff:function(lines){
for(var
rules = {PFX:[], SFX:[]},
i = 0,
length = lines.length,
line;
i < length;
i++
){
line = lines[i];
switch(line.substr(0, 3)){
case "PFX":
case "SFX":
var type = line.substr(0, 3),
name = line.substr(4, 1),
product = line.substr(6, 1) === "Y",
many = i + (line.substring(8) >> 0),
referer = rules[type],
j = i,
info;
while(j++ < many)
referer[referer.length] = lines[j].substring(8).split(/\s+/).slice(0, 3).concat([name]);
i = j;
break;
}
};
return Jaxer.Serialization.toJSONString(rules);
},
dic:function(lines){
for(var
ignore = String.fromCharCode(65533),
dictionary = {},
alphabet = {},
i = 1,
length = lines.length,
re = "/\\b[",
line, split, key;
i < length;
i++
){
line = lines[i].replace(/^\s+|\s+$/g, "");
if(line.length){
split = line.split("/");
line = split[0].toLowerCase();
if(line !== ignore){
dictionary[line] = split[1] || true;
for(var j = 0, c; j < line.length; j++)
alphabet[line.charAt(j)] = true;
}
}
};
for(key in alphabet){
if(key !== ignore && /[^\.\-\_\,\/\:\;\@\?\=\+\-\*£$^\(\)\[\]\{\}~<>]/.test(key))
re += key;
};
re += "]+\\b/ig";
alphabet = {words:dictionary,alphabet:null};
line = Jaxer.Serialization.toJSONString(alphabet);
return line.substring(0, line.length - 5).concat(re, "}");
},
hunspell:function(file, callback){
var xhr = new XMLHttpRequest;
xhr.open("get", "dictionary/" + file, false);
xhr.send(null);
return callback(xhr.responseText.split(/\r\n|\r|\n/));
}
};
</script>