1 |
|
var
TinyMCE_BB
CodePlugin
={getInfo:
function()
{
re
t
urn{longna
me:'BBCode
Plug
in
',author:'
Moxi
e
c
od
e
Sys
te
ms
AB
'
,authorurl
:'http://
tinymce.
moxiecode.
com',infou
rl:'htt
p
://wiki.mo
x
i
ecode
.
c
o
m/in
de
x.php/Tiny
MCE:
Plugin
s/bbcode
',
vers
i
o
n
:t
i
nyMCE.majo
rVersion+"
."+
t
inyMCE.min
orVersion}
},cleanup
:function(
typ
e
,
content
){var
dialect=
tinyMCE
.getParam(
'bbcode_di
alect','pu
nbb').toLo
werCase();
switch(typ
e
){case"i
n
s
e
r
t
_t
o
_
e
d
i
t
o
r":
content=t
his
['_'+diale
ct+'_bbcod
e2html'](
content);
b
r
e
a
k;
c
a
se
"g
e
t
_
fr
o
m
_
e
d
i
t
o
r":
content=t
his
['_'+diale
ct+'_html2
bbcode'](
content);
b
re
a
k}
r
e
t
ur
n
co
n
t
e
n
t
},_punbb_h
tml2bbcode
:function(
s){s=tiny
MCE
.trim(s);f
unction
rep(re,str
){s=s.repl
ace(re,str
)
};rep(/<a
href=\"(.*
?)\".*?>(.
*?)<\/a>/g
i,"[url
]
$1
[/url]");r
ep(/<font.
*?color=\"
(.*?)\".*?
class=\"co
deStyle\".
*?>(.*?)<\
/font>/gi,
"[code][co
lor=$1]$2[
/color][/c
ode]");rep
(/<font.*?
color=\"(.
*?)\".*?cl
ass=\"quot
eStyle\".*
?>(.*?)<\/
font>/gi,"
[quote][co
lor=$1]$2[
/color][/q
uote]");re
p(/<font.*
?class=\"c
odeStyle\"
.*?color=\
"(.*?)\".*
?>(.*?)<\/
font>/gi,"
[code][col
or=$1]$2[/
color][/co
de]");rep(
/<font.*?c
lass=\"quo
teStyle\".
*?color=\"
(.*?)\".*?
>(.*?)<\/f
ont>/gi,"[
quote][col
or=$1]$2[/
color][/qu
ote]");rep
(/<
font.*?col
or=\"(.*?)
\".*?>(.*?
)<\/font>/
gi,"[color
=$1]$2[/co
lor]");rep
(/<
font>(.*?)
<\/font>/g
i,"$1");re
p(/<img.*?
src=\"(.*?
)\".*?\/>/
gi,"[img]$
1[/img]");
rep(/<span
class=\"co
deStyle\">
(.*?)<\/sp
an>/gi,"[c
ode]$1[/co
de]");rep(
/<span
class=\"qu
oteStyle\"
>(.*?)<\/s
pan>/gi,"[
quote]$1[/
quote]");r
ep(/<stron
g
class=\"co
deStyle\">
(.*?)<\/st
rong>/gi,"
[code][b]$
1[/b][/cod
e]");rep(/
<strong
class=\"qu
oteStyle\"
>(.*?)<\/s
trong>/gi,
"[quote][b
]$1[/b][/q
uote]");re
p(/<em
class=\"co
deStyle\">
(.*?)<\/em
>/gi,"[cod
e][i]$1[/i
][/code]")
;rep(/<em
class=\"qu
oteStyle\"
>(.*?)<\/e
m>/gi,"[qu
ote][i]$1[
/i][/quote
]");rep(/<
u
class=\"co
deStyle\">
(.*?)<\/u>
/gi,"[code
][u]$1[/u]
[/code]");
rep(/<u
class=\"qu
oteStyle\"
>(.*?)<\/u
>/gi,"[quo
te][u]$1[/
u][/quote]
");rep(/<\
/(strong|b
)>/gi,"[/b
]");rep(/<
(strong|b)
>/gi,"[b]"
);rep(/<\/
(em|i)>/gi
,"[/i]");r
ep(/<(em|i
)>/gi,"[i]
");rep(/<\
/u>/gi,"[/
u]");rep(/
<
u>/gi,"[u]
");rep(/<b
r
\/>/gi,"\n
");rep(/<b
r\/>/gi,"\
n");rep(/<
br>/gi,"\n
");rep(/<p
>/gi,"");r
ep(/<\/p>/
gi,"\n");r
ep(/
/gi,"
");rep(/&q
uot;/gi,"\
"");rep(/&
lt;/gi,"<"
);rep(/>
;/gi,">");
rep(/&
/gi,"&");r
e
p(/&undefi
ned;/gi,"'
");re
turn
s
},_punbb_b
bcode2html
:function(
s){s=tiny
MCE
.trim(s);f
unction
rep(re,str
){s=s.repl
ace(re,str
)
};rep(/\n/
gi,"<br
/>");rep(/
\[b\]/gi,"
<strong>")
;rep(/\[\/
b\]/gi,"</
strong>");
rep(/\[i\]
/gi,"<em>"
);rep(/\[\
/i\]/gi,"<
/em>");rep
(/\[u\]/gi
,"<u>");re
p(/\[\/u\]
/gi,"</u>"
);rep(/\[u
rl
\](.*?)\[\
/url\]/gi,
"<a
href=\"$1\
">$1</a>")
;rep(/\[im
g\](.*?)\[
\/img\]/gi
,"<img
src=\"$1\"
/>");rep(/
\[color=(.
*?)\](.*?)
\[\/color\
]/gi,"<fon
t
color=\"$1
\">$2</fon
t>");rep(/
\[code\](.
*?)\[\/cod
e\]/gi,"<s
pan
class=\"co
deStyle\">
$1</span>&
nbsp;");re
p(/\[quote
.*?\](.*?)
\[\/quote\
]/gi,"<spa
n
class=\"qu
oteStyle\"
>$1</span>
");r
eturn
s
}}
;tiny
MCE
.
add
Plugin
(
"
bbcode
"
,
T
iny
MCE_
BBCodePlug
in);
|
|
1 |
|
(
function()
{
t
in
ymc
e
.
c
r
e
a
te
(
'
tinymce.
p
lug
i
ns
.
BBC
o
de
Plugin
',
{
i
n
i
t
:function(
e
d
,
url
){var
t=this,
dialect=
ed
.getParam(
'bbcode_di
alect','pu
nbb').toLo
werCase();
e
d.o
n
B
e
fo
r
eSe
t
C
o
nt
e
nt.a
d
d(func
t
i
o
n(ed,o){o.
content=t
['_'+diale
ct+'_bbcod
e2html'](
o.
content);
});ed.onPo
stP
r
oc
e
ss.
a
dd(fun
c
tion(ed,o)
{if(o.
se
t)o.cont
e
nt=
t
['
_
'+dialect+
'_bbc
o
de2ht
m
l'](o.cont
e
nt);
i
f(o.ge
t
)
o
.
content=t
['_'+diale
ct+'_html2
bbcode'](
o.
content);
});},getIn
fo:functio
n(){
re
turn{longn
a
me:'BBCode
Plugin',au
tho
r
:'Moxi
e
code
Systems
AB',author
url:'ht
t
p://tinymc
e.moxiecod
e.com',inf
o
ur
l:'http://
wiki.moxie
code.com/i
ndex.php/T
inyMCE:Plu
gi
n
s/bb
co
de',versio
n
:
t
inymc
e
.majorVers
io
n
+"."+
t
inymce.min
orVersion}
;
},_punbb_h
tml2bbcode
:function(
s){s=tiny
mce
.trim(s);f
unction
rep(re,str
){s=s.repl
ace(re,str
)
;
};rep(/<a
.*?
href=\"(.*
?)\".*?>(.
*?)<\/a>/g
i,"[url
=
$1
]$2
[/url]");r
ep(/<font.
*?color=\"
(.*?)\".*?
class=\"co
deStyle\".
*?>(.*?)<\
/font>/gi,
"[code][co
lor=$1]$2[
/color][/c
ode]");rep
(/<font.*?
color=\"(.
*?)\".*?cl
ass=\"quot
eStyle\".*
?>(.*?)<\/
font>/gi,"
[quote][co
lor=$1]$2[
/color][/q
uote]");re
p(/<font.*
?class=\"c
odeStyle\"
.*?color=\
"(.*?)\".*
?>(.*?)<\/
font>/gi,"
[code][col
or=$1]$2[/
color][/co
de]");rep(
/<font.*?c
lass=\"quo
teStyle\".
*?color=\"
(.*?)\".*?
>(.*?)<\/f
ont>/gi,"[
quote][col
or=$1]$2[/
color][/qu
ote]");rep
(/<
span
style=\"co
lor:
?(.*?);\">
(.*?)<\/sp
an>/gi,"[c
olor=$1]$2
[/color]")
;rep(/<
font.*?col
or=\"(.*?)
\".*?>(.*?
)<\/font>/
gi,"[color
=$1]$2[/co
lor]");rep
(/<
span
style=\"fo
nt-size:(.
*?);\">(.*
?)<\/span>
/gi,"[size
=$1]$2[/si
ze]");rep(
/<
font>(.*?)
<\/font>/g
i,"$1");re
p(/<img.*?
src=\"(.*?
)\".*?\/>/
gi,"[img]$
1[/img]");
rep(/<span
class=\"co
deStyle\">
(.*?)<\/sp
an>/gi,"[c
ode]$1[/co
de]");rep(
/<span
class=\"qu
oteStyle\"
>(.*?)<\/s
pan>/gi,"[
quote]$1[/
quote]");r
ep(/<stron
g
class=\"co
deStyle\">
(.*?)<\/st
rong>/gi,"
[code][b]$
1[/b][/cod
e]");rep(/
<strong
class=\"qu
oteStyle\"
>(.*?)<\/s
trong>/gi,
"[quote][b
]$1[/b][/q
uote]");re
p(/<em
class=\"co
deStyle\">
(.*?)<\/em
>/gi,"[cod
e][i]$1[/i
][/code]")
;rep(/<em
class=\"qu
oteStyle\"
>(.*?)<\/e
m>/gi,"[qu
ote][i]$1[
/i][/quote
]");rep(/<
u
class=\"co
deStyle\">
(.*?)<\/u>
/gi,"[code
][u]$1[/u]
[/code]");
rep(/<u
class=\"qu
oteStyle\"
>(.*?)<\/u
>/gi,"[quo
te][u]$1[/
u][/quote]
");rep(/<\
/(strong|b
)>/gi,"[/b
]");rep(/<
(strong|b)
>/gi,"[b]"
);rep(/<\/
(em|i)>/gi
,"[/i]");r
ep(/<(em|i
)>/gi,"[i]
");rep(/<\
/u>/gi,"[/
u]");rep(/
<
span
style=\"te
xt-decorat
ion:
?underline
;\">(.*?)<
\/span>/gi
,"[u]$1[/u
]");rep(/<
u>/gi,"[u]
");rep(/<b
r
\/>/gi,"\n
");rep(/<b
r\/>/gi,"\
n");rep(/<
br>/gi,"\n
");rep(/<p
>/gi,"");r
ep(/<\/p>/
gi,"\n");r
ep(/
/gi,"
");rep(/&q
uot;/gi,"\
"");rep(/&
lt;/gi,"<"
);rep(/>
;/gi,">");
rep(/&
/gi,"&");r
e
turn
s
;
},_punbb_b
bcode2html
:function(
s){s=tiny
mce
.trim(s);f
unction
rep(re,str
){s=s.repl
ace(re,str
)
;
};rep(/\n/
gi,"<br
/>");rep(/
\[b\]/gi,"
<strong>")
;rep(/\[\/
b\]/gi,"</
strong>");
rep(/\[i\]
/gi,"<em>"
);rep(/\[\
/i\]/gi,"<
/em>");rep
(/\[u\]/gi
,"<u>");re
p(/\[\/u\]
/gi,"</u>"
);rep(/\[u
rl
=([^\]]+)\
](.*?)\[\/
url\]/gi,"
<a
href=\"$1\
">$2</a>")
;rep(/\[ur
l
\](.*?)\[\
/url\]/gi,
"<a
href=\"$1\
">$1</a>")
;rep(/\[im
g\](.*?)\[
\/img\]/gi
,"<img
src=\"$1\"
/>");rep(/
\[color=(.
*?)\](.*?)
\[\/color\
]/gi,"<fon
t
color=\"$1
\">$2</fon
t>");rep(/
\[code\](.
*?)\[\/cod
e\]/gi,"<s
pan
class=\"co
deStyle\">
$1</span>&
nbsp;");re
p(/\[quote
.*?\](.*?)
\[\/quote\
]/gi,"<spa
n
class=\"qu
oteStyle\"
>$1</span>
");r
eturn
s
;
}}
)
;tiny
mce
.
Plugin
Manager.ad
d
(
'
bbcode
'
,
t
iny
mce.plugin
s.
BBCodePlug
in);
})();
|