No regular expressions were active.
1 |
|
/**
|
|
1 |
|
/**
|
2 |
|
*
$Id:
editor_plu
gin_src.js
20
5
200
7
-0
2-
1
2
1
8
:
58
:
2
9
Z
spocke
$
|
|
2 |
|
*
$Id:
editor_plu
gin_src.js
5
20
200
8
-0
1
-07
1
6
:
30
:
3
2
Z
spocke
$
|
3 |
|
*
|
|
3 |
|
*
|
4 |
|
* @author
Moxiecode
|
|
4 |
|
* @author
Moxiecode
|
5 |
|
*
@copyright
Copyright
©
2004-200
7
,
Moxiecode
Systems
AB,
All
rights
reserved.
|
|
5 |
|
*
@copyright
Copyright
©
2004-200
8
,
Moxiecode
Systems
AB,
All
rights
reserved.
|
6 |
|
*/
|
|
6 |
|
*/
|
7 |
|
|
|
7 |
|
|
8 |
|
var TinyMC
E_NonEdita
blePlugin
= {
|
|
8 |
|
(function(
) {
|
|
|
9 |
|
var Ev
ent = tiny
mce.dom.Ev
ent;
|
|
|
10 |
|
|
|
|
11 |
|
tinymc
e.create('
tinymce.pl
ugins.NonE
ditablePlu
gin', {
|
|
|
12 |
|
in
it : funct
ion(ed, ur
l) {
|
|
|
13 |
|
var t =
this, edit
Class, non
EditClass;
|
|
|
14 |
|
|
|
|
15 |
|
t.editor
= ed;
|
|
|
16 |
|
editClas
s = ed.get
Param("non
editable_e
ditable_cl
ass", "mce
Editable")
;
|
|
|
17 |
|
nonEditC
lass = ed.
getParam("
noneditabl
e_nonedita
ble_class"
, "mceNonE
ditable");
|
|
|
18 |
|
|
|
|
19 |
|
ed.onNod
eChange.ad
dToTop(fun
ction(ed,
cm, n) {
|
|
|
20 |
|
var
sc, ec;
|
|
|
21 |
|
|
|
|
22 |
|
// B
lock if st
art or end
is inside
a non edi
table elem
ent
|
|
|
23 |
|
sc =
ed.dom.ge
tParent(ed
.selection
.getStart(
), functio
n(n) {
|
|
|
24 |
|
return ed.
dom.hasCla
ss(n, nonE
ditClass);
|
|
|
25 |
|
});
|
|
|
26 |
|
|
|
|
27 |
|
ec =
ed.dom.ge
tParent(ed
.selection
.getEnd(),
function(
n) {
|
|
|
28 |
|
return ed.
dom.hasCla
ss(n, nonE
ditClass);
|
|
|
29 |
|
});
|
|
|
30 |
|
|
|
|
31 |
|
// B
lock or un
block
|
|
|
32 |
|
if (
sc || ec)
{
|
|
|
33 |
|
t._setDisa
bled(1);
|
|
|
34 |
|
return fal
se;
|
|
|
35 |
|
} el
se
|
|
|
36 |
|
t._setDisa
bled(0);
|
|
|
37 |
|
});
|
|
|
38 |
|
},
|
|
|
39 |
|
|
9 |
|
getInf
o : functi
on() {
|
|
40 |
|
ge
tInfo : fu
nction() {
|
10 |
|
re
turn {
|
|
41 |
|
return {
|
11 |
|
longname
: 'Non ed
itable ele
ments',
|
|
42 |
|
long
name : 'No
n editable
elements'
,
|
12 |
|
author :
'Moxiecod
e Systems
AB',
|
|
43 |
|
auth
or : 'Moxi
ecode Syst
ems AB',
|
13 |
|
authorur
l : 'http:
//tinymce.
moxiecode.
com',
|
|
44 |
|
auth
orurl : 'h
ttp://tiny
mce.moxiec
ode.com',
|
14 |
|
infourl
: 'http://
wiki.moxie
code.com/i
ndex.php/T
inyMCE:Plu
gins/noned
itable',
|
|
45 |
|
info
url : 'htt
p://wiki.m
oxiecode.c
om/index.p
hp/TinyMCE
:Plugins/n
oneditable
',
|
15 |
|
version
:
tiny
MCE
.majorVers
ion
+
"."
+
tiny
MCE
.minorVers
ion
|
|
46 |
|
version
:
tiny
mce
.majorVers
ion
+
"."
+
tiny
mce
.minorVers
ion
|
16 |
|
};
|
|
47 |
|
};
|
17 |
|
},
|
|
48 |
|
},
|
18 |
|
|
|
49 |
|
|
19 |
|
initInstan
c
e
:
function(
inst
)
{
|
|
50 |
|
_blo
c
k
:
function(
ed,
e
)
{
|
20 |
|
ti
nyMCE.impo
rtCSS(inst
.getDoc(),
tinyMCE.b
aseURL + "
/plugins/n
oneditable
/css/noned
itable.css
");
|
|
51 |
|
return E
vent.cance
l(e);
|
21 |
|
|
|
|
22 |
|
//
Ugly hack
|
|
|
23 |
|
if
(tinyMCE.
isMSIE5_0)
|
|
|
24 |
|
tinyMCE.
settings['
plugins']
= tinyMCE.
settings['
plugins'].
replace(/n
oneditable
/gi, 'None
ditable');
|
|
|
25 |
|
},
|
|
|
26 |
|
|
|
|
27 |
|
handle
Event : fu
nction(e)
{
|
|
|
28 |
|
re
turn this.
_moveSelec
tion(e, ti
nyMCE.sele
ctedInstan
ce);
|
|
|
29 |
|
},
|
|
52 |
|
},
|
30 |
|
|
|
53 |
|
|
31 |
|
cleanu
p : functi
on(type, c
ontent, in
st) {
|
|
54 |
|
_s
etDisabled
: functio
n(s) {
|
32 |
|
sw
itch (type
) {
|
|
55 |
|
var t =
this, ed =
t.editor;
|
33 |
|
case "in
sert_to_ed
itor_dom":
|
|
|
34 |
|
var
nodes, i,
editClass,
nonEditCl
ass, edita
ble, elm;
|
|
|
35 |
|
|
|
|
36 |
|
// P
ass throug
h Gecko
|
|
|
37 |
|
if (
tinyMCE.is
Gecko)
|
|
|
38 |
|
return con
tent;
|
|
|
39 |
|
|
|
56 |
|
|
40 |
|
node
s = tinyMC
E.getNodeT
ree(conten
t, [], 1);
|
|
57 |
|
tinymce.
each(ed.co
ntrolManag
er.control
s, functio
n(c) {
|
|
|
58 |
|
c.se
tDisabled(
s);
|
|
|
59 |
|
});
|
41 |
|
|
|
60 |
|
|
42 |
|
edit
Class = ti
nyMCE.getP
aram("none
ditable_ed
itable_cla
ss", "mceE
ditable");
|
|
61 |
|
if
(
s
!==
t
.
d
is
abled
)
{
|
43 |
|
nonE
ditClass =
tinyMCE.g
etParam("n
oneditable
_noneditab
le_class",
"mceNonEd
itable");
|
|
62 |
|
if (
s) {
|
44 |
|
|
|
63 |
|
ed.onKeyDo
wn.addToTo
p(t._block
);
|
45 |
|
for
(i=0; i<no
des.length
; i++) {
|
|
64 |
|
ed.onKeyPr
ess.addToT
op(t._bloc
k);
|
46 |
|
elm = node
s[i];
|
|
65 |
|
ed.onKeyUp
.addToTop(
t._block);
|
47 |
|
|
|
66 |
|
ed.onPaste
.addToTop(
t._block);
|
48 |
|
// Convert
contented
itable to
classes
|
|
67 |
|
} el
se {
|
49 |
|
editable =
tinyMCE.g
etAttrib(e
lm, "conte
nteditable
");
|
|
68 |
|
ed.onKeyDo
wn.remove(
t._block);
|
50 |
|
if (new Re
gExp("true
|false","g
i").test(e
ditable))
|
|
69 |
|
ed.onKeyPr
ess.remove
(t._block)
;
|
51 |
|
TinyMC
E_NonEdita
blePlugin.
_setEditab
le(elm, ed
itable ==
"true");
|
|
70 |
|
ed.onKeyUp
.remove(t.
_block);
|
52 |
|
|
|
71 |
|
ed.onPaste
.remove(t.
_block);
|
53 |
|
if
(
t
inyMCE
.
is
IE
)
{
|
|
|
54 |
|
if (ti
nyMCE.hasC
SSClass(el
m, editCla
ss))
|
|
|
55 |
|
el
m.contentE
ditable =
true;
|
|
|
56 |
|
|
|
|
57 |
|
if (ti
nyMCE.hasC
SSClass(el
m, nonEdit
Class))
|
|
|
58 |
|
el
m.contentE
ditable =
false;
|
|
|
59 |
|
}
|
|
72 |
|
}
|
60 |
|
}
|
|
|
61 |
|
|
|
|
62 |
|
brea
k;
|
|
|
63 |
|
|
|
|
64 |
|
case "in
sert_to_ed
itor":
|
|
|
65 |
|
var
editClass
= tinyMCE.
getParam("
noneditabl
e_editable
_class", "
mceEditabl
e");
|
|
|
66 |
|
var
nonEditCla
ss = tinyM
CE.getPara
m("nonedit
able_noned
itable_cla
ss", "mceN
onEditable
");
|
|
|
67 |
|
|
|
73 |
|
|
68 |
|
// R
eplace mce
Item to ne
w school
|
|
74 |
|
t.di
sabled = s
;
|
69 |
|
cont
ent = cont
ent.replac
e(/mceItem
Editable/g
, editClas
s);
|
|
|
70 |
|
cont
ent = cont
ent.replac
e(/mceItem
NonEditabl
e/g, nonEd
itClass);
|
|
|
71 |
|
|
|
|
72 |
|
if (
tinyMCE.is
IE && (con
tent.index
Of(editCla
ss) != -1
|| content
.indexOf(n
onEditClas
s) != -1))
{
|
|
|
73 |
|
content =
content.re
place(new
RegExp("cl
ass=\"(.+)
(" + editC
lass + ")\
"", "gi"),
'class="$
1$2" conte
nteditable
="true"');
|
|
|
74 |
|
content =
content.re
place(new
RegExp("cl
ass=\"(.+)
(" + nonEd
itClass +
")\"", "gi
"), 'class
="$1$2" co
ntentedita
ble="false
"');
|
|
|
75 |
|
content =
content.re
place(new
RegExp("cl
ass=\"(" +
editClass
+ ")([^\"
]*)\"", "g
i"), 'clas
s="$1$2" c
ontentedit
able="true
"');
|
|
|
76 |
|
content =
content.re
place(new
RegExp("cl
ass=\"(" +
nonEditCl
ass + ")([
^\"]*)\"",
"gi"), 'c
lass="$1$2
" contente
ditable="f
alse"');
|
|
|
77 |
|
content =
content.re
place(new
RegExp("cl
ass=\"(.+)
(" + editC
lass + ")(
[^\"]*)\""
, "gi"), '
class="$1$
2$3" conte
nteditable
="true"');
|
|
|
78 |
|
content =
content.re
place(new
RegExp("cl
ass=\"(.+)
(" + nonEd
itClass +
")([^\"]*)
\"", "gi")
, 'class="
$1$2$3" co
ntentedita
ble="false
"');
|
|
|
79 |
|
}
|
|
75 |
|
}
|
80 |
|
|
|
|
81 |
|
brea
k;
|
|
|
82 |
|
|
|
|
83 |
|
case "ge
t_from_edi
tor_dom":
|
|
|
84 |
|
// P
ass throug
h Gecko
|
|
|
85 |
|
if (
tinyMCE.is
Gecko)
|
|
|
86 |
|
return con
tent;
|
|
|
87 |
|
|
|
|
88 |
|
if (
tinyMCE.ge
tParam("no
neditable_
leave_cont
enteditabl
e", false)
) {
|
|
|
89 |
|
var nodes
= tinyMCE.
getNodeTre
e(content,
new Array
(), 1);
|
|
|
90 |
|
|
|
|
91 |
|
for (var i
=0; i<node
s.length;
i++)
|
|
|
92 |
|
nodes[
i].removeA
ttribute("
contentedi
table");
|
|
|
93 |
|
}
|
|
76 |
|
}
|
|
|
77 |
|
});
|
94 |
|
|
|
78 |
|
|
95 |
|
brea
k;
|
|
79 |
|
// Reg
ister plug
in
|
96 |
|
}
|
|
80 |
|
tinymc
e.PluginMa
nager.add(
'noneditab
le', tinym
ce.plugins
.NonEditab
lePlugin);
|
97 |
|
|
|
81 |
|
})();
|
98 |
|
re
turn conte
nt;
|
|
|
99 |
|
},
|
|
|
100 |
|
|
|
|
101 |
|
_moveS
election :
function(
e, inst) {
|
|
|
102 |
|
va
r s, r, sc
, ec, el,
c = tinyMC
E.getParam
('nonedita
ble_editab
le_class',
'mceNonEd
itable');
|
|
|
103 |
|
|
|
|
104 |
|
if
(!inst)
|
|
|
105 |
|
return t
rue;
|
|
|
106 |
|
|
|
|
107 |
|
//
Always se
lect whole
element
|
|
|
108 |
|
if
(tinyMCE.
isGecko) {
|
|
|
109 |
|
s = inst
.selection
.getSel();
|
|
|
110 |
|
r = s.ge
tRangeAt(0
);
|
|
|
111 |
|
sc = tin
yMCE.getPa
rentNode(r
.startCont
ainer, fun
ction (n)
{return ti
nyMCE.hasC
SSClass(n,
c);});
|
|
|
112 |
|
ec = tin
yMCE.getPa
rentNode(r
.endContai
ner, funct
ion (n) {r
eturn tiny
MCE.hasCSS
Class(n, c
);});
|
|
|
113 |
|
|
|
|
114 |
|
sc && r.
setStartBe
fore(sc);
|
|
|
115 |
|
ec && r.
setEndAfte
r(ec);
|
|
|
116 |
|
|
|
|
117 |
|
if (sc |
| ec) {
|
|
|
118 |
|
if (
e.type ==
'keypress'
&& e.keyC
ode == 39)
{
|
|
|
119 |
|
el = sc ||
ec;
|
|
|
120 |
|
|
|
|
121 |
|
// Try!!
|
|
|
122 |
|
}
|
|
|
123 |
|
|
|
|
124 |
|
s.re
moveAllRan
ges();
|
|
|
125 |
|
s.ad
dRange(r);
|
|
|
126 |
|
|
|
|
127 |
|
retu
rn tinyMCE
.cancelEve
nt(e);
|
|
|
128 |
|
}
|
|
|
129 |
|
}
|
|
|
130 |
|
|
|
|
131 |
|
re
turn true;
|
|
|
132 |
|
},
|
|
|
133 |
|
|
|
|
134 |
|
_setEd
itable : f
unction(el
m, state)
{
|
|
|
135 |
|
va
r editClas
s = tinyMC
E.getParam
("nonedita
ble_editab
le_class",
"mceEdita
ble");
|
|
|
136 |
|
va
r nonEditC
lass = tin
yMCE.getPa
ram("noned
itable_non
editable_c
lass", "mc
eNonEditab
le");
|
|
|
137 |
|
|
|
|
138 |
|
va
r classNam
e = elm.cl
assName ?
elm.classN
ame : "";
|
|
|
139 |
|
|
|
|
140 |
|
if
(classNam
e.indexOf(
editClass)
!= -1 ||
className.
indexOf(no
nEditClass
) != -1)
|
|
|
141 |
|
return;
|
|
|
142 |
|
|
|
|
143 |
|
if
((classNa
me = tinyM
CE.getAttr
ib(elm, "c
lass")) !=
"")
|
|
|
144 |
|
classNam
e += " ";
|
|
|
145 |
|
|
|
|
146 |
|
cl
assName +=
state ? e
ditClass :
nonEditCl
ass;
|
|
|
147 |
|
|
|
|
148 |
|
el
m.setAttri
bute("clas
s", classN
ame);
|
|
|
149 |
|
el
m.classNam
e = classN
ame;
|
|
|
150 |
|
}
|
|
|
151 |
|
};
|
|
|
152 |
|
|
|
|
153 |
|
tinyMCE.ad
dPlugin("n
oneditable
", TinyMCE
_NonEditab
lePlugin);
|
|
|