No regular expressions were active.
|
|
1 |
|
/**
|
|
|
2 |
|
* $Id: ed
itor_plugi
n_src.js 4
25 2007-11
-21 15:17:
39Z spocke
$
|
|
|
3 |
|
*
|
|
|
4 |
|
* @author
Moxiecode
|
|
|
5 |
|
* @copyri
ght Copyri
ght © 2004
-2008, Mox
iecode Sys
tems AB, A
ll rights
reserved.
|
|
|
6 |
|
*/
|
|
|
7 |
|
|
|
|
8 |
|
(function(
) {
|
|
|
9 |
|
var JS
ONRequest
= tinymce.
util.JSONR
equest, ea
ch = tinym
ce.each, D
OM = tinym
ce.DOM;
|
|
|
10 |
|
|
|
|
11 |
|
tinymc
e.create('
tinymce.pl
ugins.Spel
lcheckerPl
ugin', {
|
|
|
12 |
|
ge
tInfo : fu
nction() {
|
|
|
13 |
|
return {
|
|
|
14 |
|
long
name : 'Sp
ellchecker
',
|
|
|
15 |
|
auth
or : 'Moxi
ecode Syst
ems AB',
|
|
|
16 |
|
auth
orurl : 'h
ttp://tiny
mce.moxiec
ode.com',
|
|
|
17 |
|
info
url : 'htt
p://wiki.m
oxiecode.c
om/index.p
hp/TinyMCE
:Plugins/s
pellchecke
r',
|
|
|
18 |
|
vers
ion : tiny
mce.majorV
ersion + "
." + tinym
ce.minorVe
rsion
|
|
|
19 |
|
};
|
|
|
20 |
|
},
|
|
|
21 |
|
|
|
|
22 |
|
in
it : funct
ion(ed, ur
l) {
|
|
|
23 |
|
var t =
this, cm;
|
|
|
24 |
|
|
|
|
25 |
|
t.url =
url;
|
|
|
26 |
|
t.editor
= ed;
|
|
|
27 |
|
|
|
|
28 |
|
// Regis
ter comman
ds
|
|
|
29 |
|
ed.addCo
mmand('mce
SpellCheck
', functio
n() {
|
|
|
30 |
|
if (
!t.active)
{
|
|
|
31 |
|
ed.setProg
ressState(
1);
|
|
|
32 |
|
t._sendRPC
('checkWor
ds', [t.se
lectedLang
, t._getWo
rds()], fu
nction(r)
{
|
|
|
33 |
|
if (r.
length > 0
) {
|
|
|
34 |
|
t.
active = 1
;
|
|
|
35 |
|
t.
_markWords
(r);
|
|
|
36 |
|
ed
.setProgre
ssState(0)
;
|
|
|
37 |
|
ed
.nodeChang
ed();
|
|
|
38 |
|
} else
{
|
|
|
39 |
|
ed
.setProgre
ssState(0)
;
|
|
|
40 |
|
ed
.windowMan
ager.alert
('spellche
cker.no_mp
ell');
|
|
|
41 |
|
}
|
|
|
42 |
|
});
|
|
|
43 |
|
} el
se
|
|
|
44 |
|
t._done();
|
|
|
45 |
|
});
|
|
|
46 |
|
|
|
|
47 |
|
ed.onIni
t.add(func
tion() {
|
|
|
48 |
|
ed.d
om.loadCSS
(url + '/c
ss/content
.css');
|
|
|
49 |
|
});
|
|
|
50 |
|
|
|
|
51 |
|
ed.onCli
ck.add(t._
showMenu,
t);
|
|
|
52 |
|
ed.onCon
textMenu.a
dd(t._show
Menu, t);
|
|
|
53 |
|
ed.onBef
oreGetCont
ent.add(fu
nction() {
|
|
|
54 |
|
if (
t.active)
|
|
|
55 |
|
t._removeW
ords();
|
|
|
56 |
|
});
|
|
|
57 |
|
|
|
|
58 |
|
ed.onNod
eChange.ad
d(function
(ed, cm) {
|
|
|
59 |
|
cm.s
etActive('
spellcheck
er', t.act
ive);
|
|
|
60 |
|
});
|
|
|
61 |
|
|
|
|
62 |
|
ed.onSet
Content.ad
d(function
() {
|
|
|
63 |
|
t._d
one();
|
|
|
64 |
|
});
|
|
|
65 |
|
|
|
|
66 |
|
ed.onBef
oreGetCont
ent.add(fu
nction() {
|
|
|
67 |
|
t._d
one();
|
|
|
68 |
|
});
|
|
|
69 |
|
|
|
|
70 |
|
ed.onBef
oreExecCom
mand.add(f
unction(ed
, cmd) {
|
|
|
71 |
|
if (
cmd == 'mc
eFullScree
n')
|
|
|
72 |
|
t._done();
|
|
|
73 |
|
});
|
|
|
74 |
|
|
|
|
75 |
|
// Find
selected l
anguage
|
|
|
76 |
|
t.langua
ges = {};
|
|
|
77 |
|
each(ed.
getParam('
spellcheck
er_languag
es', '+Eng
lish=en,Da
nish=da,Du
tch=nl,Fin
nish=fi,Fr
ench=fr,Ge
rman=de,It
alian=it,P
olish=pl,P
ortuguese=
pt,Spanish
=es,Swedis
h=sv', 'ha
sh'), func
tion(v, k)
{
|
|
|
78 |
|
if (
k.indexOf(
'+') === 0
) {
|
|
|
79 |
|
k = k.subs
tring(1);
|
|
|
80 |
|
t.selected
Lang = v;
|
|
|
81 |
|
}
|
|
|
82 |
|
|
|
|
83 |
|
t.la
nguages[k]
= v;
|
|
|
84 |
|
});
|
|
|
85 |
|
},
|
|
|
86 |
|
|
|
|
87 |
|
cr
eateContro
l : functi
on(n, cm)
{
|
|
|
88 |
|
var t =
this, c, e
d = t.edit
or;
|
|
|
89 |
|
|
|
|
90 |
|
if (n ==
'spellche
cker') {
|
|
|
91 |
|
c =
cm.createS
plitButton
(n, {title
: 'spellc
hecker.des
c', cmd :
'mceSpellC
heck', sco
pe : t});
|
|
|
92 |
|
|
|
|
93 |
|
c.on
RenderMenu
.add(funct
ion(c, m)
{
|
|
|
94 |
|
m.add({tit
le : 'spel
lchecker.l
angs', 'cl
ass' : 'mc
eMenuItemT
itle'}).se
tDisabled(
1);
|
|
|
95 |
|
each(t.lan
guages, fu
nction(v,
k) {
|
|
|
96 |
|
var o
= {icon :
1}, mi;
|
|
|
97 |
|
|
|
|
98 |
|
o.oncl
ick = func
tion() {
|
|
|
99 |
|
mi
.setSelect
ed(1);
|
|
|
100 |
|
t.
selectedIt
em.setSele
cted(0);
|
|
|
101 |
|
t.
selectedIt
em = mi;
|
|
|
102 |
|
t.
selectedLa
ng = v;
|
|
|
103 |
|
};
|
|
|
104 |
|
|
|
|
105 |
|
o.titl
e = k;
|
|
|
106 |
|
mi = m
.add(o);
|
|
|
107 |
|
mi.set
Selected(v
== t.sele
ctedLang);
|
|
|
108 |
|
|
|
|
109 |
|
if (v
== t.selec
tedLang)
|
|
|
110 |
|
t.
selectedIt
em = mi;
|
|
|
111 |
|
})
|
|
|
112 |
|
});
|
|
|
113 |
|
|
|
|
114 |
|
retu
rn c;
|
|
|
115 |
|
}
|
|
|
116 |
|
},
|
|
|
117 |
|
|
|
|
118 |
|
//
Internal
functions
|
|
|
119 |
|
|
|
|
120 |
|
_w
alk : func
tion(n, f)
{
|
|
|
121 |
|
var d =
this.edito
r.getDoc()
, w;
|
|
|
122 |
|
|
|
|
123 |
|
if (d.cr
eateTreeWa
lker) {
|
|
|
124 |
|
w =
d.createTr
eeWalker(n
, NodeFilt
er.SHOW_TE
XT, null,
false);
|
|
|
125 |
|
|
|
|
126 |
|
whil
e ((n = w.
nextNode()
) != null)
|
|
|
127 |
|
f.call(thi
s, n);
|
|
|
128 |
|
} else
|
|
|
129 |
|
tiny
mce.walk(n
, f, 'chil
dNodes');
|
|
|
130 |
|
},
|
|
|
131 |
|
|
|
|
132 |
|
_g
etSeparato
rs : funct
ion() {
|
|
|
133 |
|
var re =
'', i, st
r = this.e
ditor.getP
aram('spel
lchecker_w
ord_separa
tor_chars'
, '\\s!"#$
%&()*+,-./
:;<=>?@[\]
^_{|}§©«®±
¶·ё»јЅѕїЧч
¤\u201d\u2
01c');
|
|
|
134 |
|
|
|
|
135 |
|
// Build
word sepa
rator rege
xp
|
|
|
136 |
|
for (i=0
; i<str.le
ngth; i++)
|
|
|
137 |
|
re +
= '\\' + s
tr.charAt(
i);
|
|
|
138 |
|
|
|
|
139 |
|
return r
e;
|
|
|
140 |
|
},
|
|
|
141 |
|
|
|
|
142 |
|
_g
etWords :
function()
{
|
|
|
143 |
|
var ed =
this.edit
or, wl = [
], tx = ''
, lo = {};
|
|
|
144 |
|
|
|
|
145 |
|
// Get a
rea text
|
|
|
146 |
|
this._wa
lk(ed.getB
ody(), fun
ction(n) {
|
|
|
147 |
|
if (
n.nodeType
== 3)
|
|
|
148 |
|
tx += n.no
deValue +
' ';
|
|
|
149 |
|
});
|
|
|
150 |
|
|
|
|
151 |
|
// Split
words by
separator
|
|
|
152 |
|
tx = tx.
replace(ne
w RegExp('
([0-9]|['
+ this._ge
tSeparator
s() + '])'
, 'g'), '
');
|
|
|
153 |
|
tx = tin
ymce.trim(
tx.replace
(/(\s+)/g,
' '));
|
|
|
154 |
|
|
|
|
155 |
|
// Build
word arra
y and remo
ve duplica
tes
|
|
|
156 |
|
each(tx.
split(' ')
, function
(v) {
|
|
|
157 |
|
if (
!lo[v]) {
|
|
|
158 |
|
wl.push(v)
;
|
|
|
159 |
|
lo[v] = 1;
|
|
|
160 |
|
}
|
|
|
161 |
|
});
|
|
|
162 |
|
|
|
|
163 |
|
return w
l;
|
|
|
164 |
|
},
|
|
|
165 |
|
|
|
|
166 |
|
_r
emoveWords
: functio
n(w) {
|
|
|
167 |
|
var ed =
this.edit
or, dom =
ed.dom, se
= ed.sele
ction, b =
se.getBoo
kmark();
|
|
|
168 |
|
|
|
|
169 |
|
each(dom
.select('s
pan').reve
rse(), fun
ction(n) {
|
|
|
170 |
|
if (
n && (dom.
hasClass(n
, 'mceItem
HiddenSpel
lWord') ||
dom.hasCl
ass(n, 'mc
eItemHidde
n'))) {
|
|
|
171 |
|
if (!w ||
dom.decode
(n.innerHT
ML) == w)
|
|
|
172 |
|
dom.re
move(n, 1)
;
|
|
|
173 |
|
}
|
|
|
174 |
|
});
|
|
|
175 |
|
|
|
|
176 |
|
se.moveT
oBookmark(
b);
|
|
|
177 |
|
},
|
|
|
178 |
|
|
|
|
179 |
|
_m
arkWords :
function(
wl) {
|
|
|
180 |
|
var r1,
r2, r3, r4
, r5, w =
'', ed = t
his.editor
, re = thi
s._getSepa
rators(),
dom = ed.d
om, nl = [
];
|
|
|
181 |
|
var se =
ed.select
ion, b = s
e.getBookm
ark();
|
|
|
182 |
|
|
|
|
183 |
|
each(wl,
function(
v) {
|
|
|
184 |
|
w +=
(w ? '|'
: '') + v;
|
|
|
185 |
|
});
|
|
|
186 |
|
|
|
|
187 |
|
r1 = new
RegExp('(
[' + re +
'])(' + w
+ ')([' +
re + '])',
'g');
|
|
|
188 |
|
r2 = new
RegExp('^
(' + w + '
)', 'g');
|
|
|
189 |
|
r3 = new
RegExp('(
' + w + ')
([' + re +
']?)$', '
g');
|
|
|
190 |
|
r4 = new
RegExp('^
(' + w + '
)([' + re
+ ']?)$',
'g');
|
|
|
191 |
|
r5 = new
RegExp('(
' + w + ')
([' + re +
'])', 'g'
);
|
|
|
192 |
|
|
|
|
193 |
|
// Colle
ct all tex
t nodes
|
|
|
194 |
|
this._wa
lk(this.ed
itor.getBo
dy(), func
tion(n) {
|
|
|
195 |
|
if (
n.nodeType
== 3) {
|
|
|
196 |
|
nl.push(n)
;
|
|
|
197 |
|
}
|
|
|
198 |
|
});
|
|
|
199 |
|
|
|
|
200 |
|
// Wrap
incorrect
words in s
pans
|
|
|
201 |
|
each(nl,
function(
n) {
|
|
|
202 |
|
var
v;
|
|
|
203 |
|
|
|
|
204 |
|
if (
n.nodeType
== 3) {
|
|
|
205 |
|
v = n.node
Value;
|
|
|
206 |
|
|
|
|
207 |
|
if (r1.tes
t(v) || r2
.test(v) |
| r3.test(
v) || r4.t
est(v)) {
|
|
|
208 |
|
v = do
m.encode(v
);
|
|
|
209 |
|
v = v.
replace(r5
, '<span c
lass="mceI
temHiddenS
pellWord">
$1</span>$
2');
|
|
|
210 |
|
v = v.
replace(r3
, '<span c
lass="mceI
temHiddenS
pellWord">
$1</span>$
2');
|
|
|
211 |
|
|
|
|
212 |
|
dom.re
place(dom.
create('sp
an', {'cla
ss' : 'mce
ItemHidden
'}, v), n)
;
|
|
|
213 |
|
}
|
|
|
214 |
|
}
|
|
|
215 |
|
});
|
|
|
216 |
|
|
|
|
217 |
|
se.moveT
oBookmark(
b);
|
|
|
218 |
|
},
|
|
|
219 |
|
|
|
|
220 |
|
_s
howMenu :
function(e
d, e) {
|
|
|
221 |
|
var t =
this, ed =
t.editor,
m = t._me
nu, p1, do
m = ed.dom
, vp = dom
.getViewPo
rt(ed.getW
in());
|
|
|
222 |
|
|
|
|
223 |
|
if (!m)
{
|
|
|
224 |
|
p1 =
DOM.getPo
s(ed.getCo
ntentAreaC
ontainer()
);
|
|
|
225 |
|
//p2
= DOM.get
Pos(ed.get
Container(
));
|
|
|
226 |
|
|
|
|
227 |
|
m =
ed.control
Manager.cr
eateDropMe
nu('spellc
heckermenu
', {
|
|
|
228 |
|
offset_x :
p1.x,
|
|
|
229 |
|
offset_y :
p1.y,
|
|
|
230 |
|
'class' :
'noIcons'
|
|
|
231 |
|
});
|
|
|
232 |
|
|
|
|
233 |
|
t._m
enu = m;
|
|
|
234 |
|
}
|
|
|
235 |
|
|
|
|
236 |
|
if (dom.
hasClass(e
.target, '
mceItemHid
denSpellWo
rd')) {
|
|
|
237 |
|
m.re
moveAll();
|
|
|
238 |
|
m.ad
d({title :
'spellche
cker.wait'
, 'class'
: 'mceMenu
ItemTitle'
}).setDisa
bled(1);
|
|
|
239 |
|
|
|
|
240 |
|
t._s
endRPC('ge
tSuggestio
ns', [t.se
lectedLang
, dom.deco
de(e.targe
t.innerHTM
L)], funct
ion(r) {
|
|
|
241 |
|
m.removeAl
l();
|
|
|
242 |
|
|
|
|
243 |
|
if (r.leng
th > 0) {
|
|
|
244 |
|
m.add(
{title : '
spellcheck
er.sug', '
class' : '
mceMenuIte
mTitle'}).
setDisable
d(1);
|
|
|
245 |
|
each(r
, function
(v) {
|
|
|
246 |
|
m.
add({title
: v, oncl
ick : func
tion() {
|
|
|
247 |
|
dom.repl
ace(ed.get
Doc().crea
teTextNode
(v), e.tar
get);
|
|
|
248 |
|
t._check
Done();
|
|
|
249 |
|
}}
);
|
|
|
250 |
|
});
|
|
|
251 |
|
|
|
|
252 |
|
m.addS
eparator()
;
|
|
|
253 |
|
} else
|
|
|
254 |
|
m.add(
{title : '
spellcheck
er.no_sug'
, 'class'
: 'mceMenu
ItemTitle'
}).setDisa
bled(1);
|
|
|
255 |
|
|
|
|
256 |
|
m.add({
|
|
|
257 |
|
title
: 'spellch
ecker.igno
re_word',
|
|
|
258 |
|
onclic
k : functi
on() {
|
|
|
259 |
|
do
m.remove(e
.target, 1
);
|
|
|
260 |
|
t.
_checkDone
();
|
|
|
261 |
|
}
|
|
|
262 |
|
});
|
|
|
263 |
|
|
|
|
264 |
|
m.add({
|
|
|
265 |
|
title
: 'spellch
ecker.igno
re_words',
|
|
|
266 |
|
onclic
k : functi
on() {
|
|
|
267 |
|
t.
_removeWor
ds(dom.dec
ode(e.targ
et.innerHT
ML));
|
|
|
268 |
|
t.
_checkDone
();
|
|
|
269 |
|
}
|
|
|
270 |
|
});
|
|
|
271 |
|
|
|
|
272 |
|
m.update()
;
|
|
|
273 |
|
});
|
|
|
274 |
|
|
|
|
275 |
|
ed.s
election.s
elect(e.ta
rget);
|
|
|
276 |
|
p1 =
dom.getPo
s(e.target
);
|
|
|
277 |
|
m.sh
owMenu(p1.
x, p1.y +
e.target.o
ffsetHeigh
t - vp.y);
|
|
|
278 |
|
|
|
|
279 |
|
retu
rn tinymce
.dom.Event
.cancel(e)
;
|
|
|
280 |
|
} else
|
|
|
281 |
|
m.hi
deMenu();
|
|
|
282 |
|
},
|
|
|
283 |
|
|
|
|
284 |
|
_c
heckDone :
function(
) {
|
|
|
285 |
|
var t =
this, ed =
t.editor,
dom = ed.
dom, o;
|
|
|
286 |
|
|
|
|
287 |
|
each(dom
.select('s
pan'), fun
ction(n) {
|
|
|
288 |
|
if (
n && dom.h
asClass(n,
'mceItemH
iddenSpell
Word')) {
|
|
|
289 |
|
o = true;
|
|
|
290 |
|
return fal
se;
|
|
|
291 |
|
}
|
|
|
292 |
|
});
|
|
|
293 |
|
|
|
|
294 |
|
if (!o)
|
|
|
295 |
|
t._d
one();
|
|
|
296 |
|
},
|
|
|
297 |
|
|
|
|
298 |
|
_d
one : func
tion() {
|
|
|
299 |
|
var t =
this, la =
t.active;
|
|
|
300 |
|
|
|
|
301 |
|
if (t.ac
tive) {
|
|
|
302 |
|
t.ac
tive = 0;
|
|
|
303 |
|
t._r
emoveWords
();
|
|
|
304 |
|
|
|
|
305 |
|
if (
t._menu)
|
|
|
306 |
|
t._menu.hi
deMenu();
|
|
|
307 |
|
|
|
|
308 |
|
if (
la)
|
|
|
309 |
|
t.editor.n
odeChanged
();
|
|
|
310 |
|
}
|
|
|
311 |
|
},
|
|
|
312 |
|
|
|
|
313 |
|
_s
endRPC : f
unction(m,
p, cb) {
|
|
|
314 |
|
var t =
this, url
= t.editor
.getParam(
"spellchec
ker_rpc_ur
l", "{back
end}");
|
|
|
315 |
|
|
|
|
316 |
|
if (url
== '{backe
nd}') {
|
|
|
317 |
|
t.ed
itor.setPr
ogressStat
e(0);
|
|
|
318 |
|
aler
t('Please
specify: s
pellchecke
r_rpc_url'
);
|
|
|
319 |
|
retu
rn;
|
|
|
320 |
|
}
|
|
|
321 |
|
|
|
|
322 |
|
JSONRequ
est.sendRP
C({
|
|
|
323 |
|
url
: url,
|
|
|
324 |
|
meth
od : m,
|
|
|
325 |
|
para
ms : p,
|
|
|
326 |
|
succ
ess : cb,
|
|
|
327 |
|
erro
r : functi
on(e, x) {
|
|
|
328 |
|
t.editor.s
etProgress
State(0);
|
|
|
329 |
|
t.editor.w
indowManag
er.alert(e
.errstr ||
('Error r
esponse: '
+ x.respo
nseText));
|
|
|
330 |
|
}
|
|
|
331 |
|
});
|
|
|
332 |
|
}
|
|
|
333 |
|
});
|
|
|
334 |
|
|
|
|
335 |
|
// Reg
ister plug
in
|
|
|
336 |
|
tinymc
e.PluginMa
nager.add(
'spellchec
ker', tiny
mce.plugin
s.Spellche
ckerPlugin
);
|
|
|
337 |
|
})();
|