1 |
|
tinyMCE.im
portPlugin
LanguagePa
ck('templa
te');var T
inyMCE_Tem
platePlugi
n={getInfo
:function(
){return{l
ongname:'T
emplate pl
ugin',auth
or:'Moxiec
ode System
s AB',auth
orurl:'htt
p://www.mo
xiecode.co
m',infourl
:'http://w
iki.moxiec
ode.com/in
dex.php/Ti
nyMCE:Plug
ins/templa
te',versio
n:tinyMCE.
majorVersi
on+"."+tin
yMCE.minor
Version}},
initInstan
ce:functio
n(inst){va
r cdate,md
ate,conten
t,x=0,key,
value,rval
s,ds=inst.
getData('t
emplate');
cdate=tiny
MCE.getPar
am("templa
te_cdate_c
lasses",''
).split(/\
s+/);mdate
=tinyMCE.g
etParam("t
emplate_md
ate_classe
s",'').spl
it(/\s+/);
content=ti
nyMCE.getP
aram("temp
late_selec
ted_conten
t_classes"
,'').split
(/\s+/);fo
r(x=0;x<cd
ate.length
;x++)TinyM
CE_Templat
ePlugin.fu
nctions[cd
ate[x]]=Ti
nyMCE_Temp
latePlugin
.functions
['cdate'];
for(x=0;x<
mdate.leng
th;x++)Tin
yMCE_Templ
atePlugin.
functions[
mdate[x]]=
TinyMCE_Te
mplatePlug
in.functio
ns['mdate'
];for(x=0;
x<content.
length;x++
)TinyMCE_T
emplatePlu
gin.functi
ons[conten
t[x]]=Tiny
MCE_Templa
tePlugin.f
unctions['
selectedCo
ntent'];rv
als=tinyMC
E.getParam
("template
_replace_v
alues",fal
se);for(ke
y in rvals
){value=rv
als[key];i
f(typeof v
alue=="fun
ction")Tin
yMCE_Templ
atePlugin.
functions[
key]=value
;else Tiny
MCE_Templa
tePlugin.f
unctions[k
ey]=TinyMC
E_Template
Plugin.fun
ctions['ge
nerateRepl
acer'](val
ue)}rvals=
tinyMCE.ge
tParam("te
mplate_rep
lace_value
s",false);
ds.replace
_items={};
for(key in
rvals)ds.
replace_it
ems[key]=r
vals[key];
inst.addSh
ortcut('ct
rl','t','l
ang_templa
te_desc','
mceTemplat
e');ds.cur
rentAction
="insert";
ds.current
TmplNode=n
ull},getCo
ntrolHTML:
function(c
n){switch(
cn){case"t
emplate":r
eturn tiny
MCE.getBut
tonHTML(cn
,'lang_tem
plate_desc
','{$plugi
nurl}/imag
es/templat
e.gif','mc
eTemplate'
,true)}ret
urn""},exe
cCommand:f
unction(ed
itor_id,el
ement,comm
and,user_i
nterface,v
alue){var
nodeArray,
current,ne
wTmpl,x,in
st=tinyMCE
.getInstan
ceById(edi
tor_id),ds
=inst.getD
ata('templ
ate'),telm
;switch(co
mmand){cas
e"mceTempl
ate":if(us
er_interfa
ce){tinyMC
E.openWind
ow({file:'
../../plug
ins/templa
te/templat
e.htm',wid
th:tinyMCE
.getParam(
'template_
popup_widt
h',750),he
ight:tinyM
CE.getPara
m('templat
e_popup_he
ight',600)
},{editor_
id:editor_
id,resizab
le:"yes",s
crollbars:
"no",plugi
nObj:TinyM
CE_Templat
ePlugin})}
else{telm=
TinyMCE_Te
mplatePlug
in._conver
tToNode(va
lue.body);
nodeArray=
tinyMCE.se
lectElemen
ts(telm,'d
iv',functi
on(n){retu
rn tinyMCE
.hasCSSCla
ss(n,TinyM
CE_Templat
ePlugin.TM
PL)});telm
=nodeArray
.length>0?
nodeArray[
0]:null;no
deArray=[]
;if(ds.cur
rentAction
=="insert"
){if(telm)
{tinyMCE.e
xecCommand
('mceBegin
UndoLevel'
);ds.curre
ntAction="
insert-new
";TinyMCE_
TemplatePl
ugin._inse
rtTemplate
(editor_id
,telm,valu
e.title,va
lue.tsrc,t
rue);ds.cu
rrentActio
n=="insert
";tinyMCE.
execComman
d('mceEndU
ndoLevel')
;tinyMCE.e
xecInstanc
eCommand(e
ditor_id,'
mceCleanup
',false)}e
lse tinyMC
E.execComm
and('mceIn
sertConten
t',false,t
his._repla
ceValues(v
alue.body)
)}else{nod
eArray=Tin
yMCE_Templ
atePlugin.
_collectTe
mplateElem
ents(ds.cu
rrentTmplN
ode);curre
nt=[];newT
mpl=[];tin
yMCE.getNo
deTree(tel
m,newTmpl)
;for(x=0;x
<nodeArray
.length;x+
+)tinyMCE.
getNodeTre
e(nodeArra
y[x],curre
nt);var _t
est=functi
on(elm){va
r replaced
=true;if(e
lm.classNa
me){var na
mes=elm.cl
assName.sp
lit(/\s+/)
,c,n;for(c
=0;c<names
.length;c+
+){if(name
s[c].match
(/^mce/i))
continue;f
or(n=0;n<n
ewTmpl.len
gth;n++){r
eplaced=fa
lse;if(new
Tmpl[n].cl
assName&&n
ewTmpl[n].
className.
match(new
RegExp(nam
es[c],"gi"
))){newTmp
l[n].inner
HTML=elm.i
nnerHTML;r
eplaced=tr
ue;break}}
}}return r
eplaced};v
ar cont=tr
ue;var ask
ed=false;f
or(x=0;x<c
urrent.len
gth;x++){i
f(!_test(c
urrent[x])
){cont=(as
ked||confi
rm("The ne
w template
has less
elements t
han the cu
rrently se
lected con
tent.\nIf
you procee
d you will
loose con
tent.\nAre
you sure
you want t
o proceed?
","Proceed
?"));asked
=true;if(!
cont)break
}};if(cont
){tinyMCE.
execComman
d('mceBegi
nUndoLevel
');TinyMCE
_TemplateP
lugin._rep
laceTempla
teContent(
current[0]
,editor_id
,telm,valu
e.title,va
lue.tsrc);
tinyMCE.ex
ecCommand(
'mceEndUnd
oLevel');t
inyMCE.exe
cInstanceC
ommand(edi
tor_id,'mc
eCleanup',
false)}}ti
nyMCE.trig
gerNodeCha
nge(true)}
return tru
e}return f
alse},hand
leNodeChan
ge:functio
n(editor_i
d,node,und
o_index,un
do_levels,
visual_aid
,any_selec
tion){var
inst=tinyM
CE.getInst
anceById(e
ditor_id),
ds=inst.ge
tData('tem
plate');if
(tinyMCE.h
asCSSClass
(node,Tiny
MCE_Templa
tePlugin.T
MPL_ELEMEN
T)||tinyMC
E.hasCSSCl
ass(node.p
arentNode,
TinyMCE_Te
mplatePlug
in.TMPL_EL
EMENT)){ti
nyMCE.swit
chClass(ed
itor_id+'_
template',
'mceButton
Selected')
;ds.curren
tAction="u
pdate";ds.
currentTmp
lNode=node
;return tr
ue}ds.curr
entAction=
"insert";d
s.currentT
mplNode=nu
ll;tinyMCE
.switchCla
ss(editor_
id+'_templ
ate','mceB
uttonNorma
l');return
false},cl
eanup:func
tion(type,
content,in
st){var no
des=[];swi
tch(type){
case"get_f
rom_editor
":content=
content.re
place(new
RegExp('<d
iv class="
'+TinyMCE_
TemplatePl
ugin.TMPL+
'">','gi')
,'<!-- '+T
inyMCE_Tem
platePlugi
n.TMPL_BEG
INS+' -->'
);content=
content.re
place(new
RegExp('<d
iv class="
'+TinyMCE_
TemplatePl
ugin.TMPL+
'">(\s|&nb
sp;| 
)?(<!-- '+
TinyMCE_Te
mplatePlug
in.TMPL_EN
DS+' -->|\
s)?</div>'
,'gi'),'')
;content=c
ontent.rep
lace(new R
egExp('<!-
- '+TinyMC
E_Template
Plugin.TMP
L_ENDS+' -
-></div>',
'gi'),'<!-
- '+TinyMC
E_Template
Plugin.TMP
L_ENDS+' -
->');break
;case"inse
rt_to_edit
or":conten
t=content.
replace(ne
w RegExp('
<!-- '+Tin
yMCE_Templ
atePlugin.
TMPL_BEGIN
S+' -->','
gi'),'<div
class="'+
TinyMCE_Te
mplatePlug
in.TMPL+'"
>');conten
t=content.
replace(ne
w RegExp('
<!-- '+Tin
yMCE_Templ
atePlugin.
TMPL_ENDS+
' -->','gi
'),'<!-- '
+TinyMCE_T
emplatePlu
gin.TMPL_E
NDS+' --><
/div>');br
eak;case"g
et_from_ed
itor_dom":
nodes=tiny
MCE.select
Nodes(cont
ent,functi
on(n){retu
rn tinyMCE
.hasCSSCla
ss(n,TinyM
CE_Templat
ePlugin.TM
PL_ELEMENT
)});TinyMC
E_Template
Plugin._ap
plyFunctio
ns(nodes,t
ype);break
;case"inse
rt_to_edit
or_dom":no
des=tinyMC
E.selectNo
des(conten
t,function
(n){return
tinyMCE.h
asCSSClass
(n,TinyMCE
_TemplateP
lugin.TMPL
_ELEMENT)}
);TinyMCE_
TemplatePl
ugin._appl
yFunctions
(nodes,typ
e);break}r
eturn cont
ent},_conv
ertToNode:
function(h
tml){var e
lm=documen
t.createEl
ement('div
');elm.inn
erHTML=htm
l;return e
lm},_prepa
reTemplate
Content:fu
nction(elm
s){var x,n
,nodes=[];
if(!elms)r
eturn{};if
(!elms.len
gth)elms=[
elms];for(
x=0;x<elms
.length;x+
+)tinyMCE.
getNodeTre
e(elms[x],
nodes,1);f
or(n=0;n<n
odes.lengt
h;n++){tin
yMCE.addCS
SClass(nod
es[n],Tiny
MCE_Templa
tePlugin.T
MPL_ELEMEN
T);TinyMCE
_TemplateP
lugin._app
lyFunction
s(nodes[n]
,TinyMCE_T
emplatePlu
gin.TMPL_T
EMPLATE_EV
ENT)}retur
n elms},_r
eplaceValu
es:functio
n(s){var t
=this,ds=t
inyMCE.sel
ectedInsta
nce.getDat
a('templat
e');return
s.replace
(/\{\$([^\
}]+)\}/g,f
unction(a,
b){var it=
ds.replace
_items[b];
if(it){if(
typeof(it)
!='functio
n')return
it}return
b})},_appl
yFunctions
:function(
elms,edito
r_event){v
ar x,elm,n
ames,c,f;i
f(!elms)re
turn{};if(
!elms.leng
th)elms=[e
lms];for(x
=0;x<elms.
length;x++
){elm=elms
[x];if(elm
.className
){names=el
m.classNam
e.split(/\
s+/);for(c
=0;c<names
.length;c+
+){if(name
s[c]==Tiny
MCE_Templa
tePlugin.T
MPL_ELEMEN
T)continue
;f=(TinyMC
E_Template
Plugin.fun
ctions[nam
es[c]]?Tin
yMCE_Templ
atePlugin.
functions[
names[c]]:
TinyMCE_Te
mplatePlug
in.functio
ns['blank'
]);f(elm,e
ditor_even
t)}}}retur
n elms},_c
ollectTemp
lateElemen
ts:functio
n(node){va
r nodeArra
y=[],p;p=t
inyMCE.get
ParentElem
ent(node,'
DIV',funct
ion(n){ret
urn tinyMC
E.hasCSSCl
ass(n,Tiny
MCE_Templa
tePlugin.T
MPL)});if(
p)tinyMCE.
getNodeTre
e(p,nodeAr
ray);retur
n nodeArra
y},_replac
eTemplateC
ontent:fun
ction(curr
entNode,ed
itor_id,ne
wTemplate,
title,tsrc
){TinyMCE_
TemplatePl
ugin._dele
teTemplate
Content(cu
rrentNode)
;TinyMCE_T
emplatePlu
gin._inser
tTemplate(
editor_id,
newTemplat
e,title,ts
rc,false)}
,_deleteTe
mplateCont
ent:functi
on(node){v
ar p=tinyM
CE.getPare
ntElement(
node,'DIV'
,function(
n){return
tinyMCE.ha
sCSSClass(
n,TinyMCE_
TemplatePl
ugin.TMPL)
});if(p)p.
parentNode
.removeChi
ld(p,true)
},_insertT
emplate:fu
nction(edi
tor_id,elm
,title,tsr
c,incComme
nts){var h
tml;TinyMC
E_Template
Plugin._pr
epareTempl
ateContent
(elm);html
='<div cla
ss="'+Tiny
MCE_Templa
tePlugin.T
MPL+'">';h
tml+=elm.i
nnerHTML;h
tml+='<!--
'+TinyMCE
_TemplateP
lugin.TMPL
_ENDS+' --
></div>';t
inyMCE.exe
cInstanceC
ommand(edi
tor_id,'mc
eInsertCon
tent',fals
e,html)},f
unctions:{
blank:func
tion(elm,e
ditor_even
t){},cdate
:function(
elm,editor
_event){va
r d,dsrc;i
f(editor_e
vent!=Tiny
MCE_Templa
tePlugin.T
MPL_TEMPLA
TE_EVENT)r
eturn;d=ne
w Date();d
src=elm.in
nerHTML.ma
tch(new Re
gExp("<!--
"+TinyMCE
_TemplateP
lugin.TMPL
_DATE_SRC_
ATTR+":(.*
) -->","g
i"));if(ds
rc)d=new D
ate(RegExp
.$1);elm.i
nnerHTML=T
inyMCE_Tem
platePlugi
n._getDate
Time(d,tin
yMCE.getPa
ram("templ
ate_cdate_
format",ti
nyMCE.getL
ang("lang_
template_d
ef_date_fo
rmat")));e
lm.innerHT
ML+="<!--
"+TinyMCE_
TemplatePl
ugin.TMPL_
DATE_SRC_A
TTR+":"+d.
toUTCStrin
g()+" -->
"},mdate:f
unction(el
m,editor_e
vent){var
d=new Date
();elm.inn
erHTML=Tin
yMCE_Templ
atePlugin.
_getDateTi
me(d,tinyM
CE.getPara
m("templat
e_mdate_fo
rmat",tiny
MCE.getLan
g("lang_te
mplate_def
_date_form
at")))},se
lectedCont
ent:functi
on(elm,edi
tor_event)
{var ds=ti
nyMCE.sele
ctedInstan
ce.getData
('template
');if(edit
or_event!=
TinyMCE_Te
mplatePlug
in.TMPL_TE
MPLATE_EVE
NT)return;
if(ds.curr
entAction=
="insert-n
ew"&&!tiny
MCE.hasCSS
Class(elm,
TinyMCE_Te
mplatePlug
in.TMPL_SE
L_HTML_DON
E)){elm.in
nerHTML=ti
nyMCE.sele
ctedInstan
ce.selecti
on.getSele
ctedHTML()
;tinyMCE.a
ddCSSClass
(elm,TinyM
CE_Templat
ePlugin.TM
PL_SEL_HTM
L_DONE)}},
generateRe
placer:fun
ction(s){r
eturn func
tion(elm,e
ditor_even
t){elm.inn
erHTML=""+
s}}},_getD
ateTime:fu
nction(d,f
mt){if(!fm
t)return""
;function
addZeros(v
alue,len){
var i;valu
e=""+value
;if(value.
length<len
){for(i=0;
i<(len-val
ue.length)
;i++)value
="0"+value
}return va
lue}fmt=fm
t.replace(
"%D","%m/%
d/%y");fmt
=fmt.repla
ce("%r","%
I:%M:%S %p
");fmt=fmt
.replace("
%Y",""+d.g
etFullYear
());fmt=fm
t.replace(
"%y",""+d.
getYear())
;fmt=fmt.r
eplace("%m
",addZeros
(d.getMont
h()+1,2));
fmt=fmt.re
place("%d"
,addZeros(
d.getDate(
),2));fmt=
fmt.replac
e("%H",""+
addZeros(d
.getHours(
),2));fmt=
fmt.replac
e("%M",""+
addZeros(d
.getMinute
s(),2));fm
t=fmt.repl
ace("%S","
"+addZeros
(d.getSeco
nds(),2));
fmt=fmt.re
place("%I"
,""+((d.ge
tHours()+1
1)%12+1));
fmt=fmt.re
place("%p"
,""+(d.get
Hours()<12
?"AM":"PM"
));fmt=fmt
.replace("
%B",""+tin
yMCE.getLa
ng("lang_t
emplate_mo
nths_long"
)[d.getMon
th()]);fmt
=fmt.repla
ce("%b",""
+tinyMCE.g
etLang("la
ng_templat
e_months_s
hort")[d.g
etMonth()]
);fmt=fmt.
replace("%
A",""+tiny
MCE.getLan
g("lang_te
mplate_day
_long")[d.
getDay()])
;fmt=fmt.r
eplace("%a
",""+tinyM
CE.getLang
("lang_tem
plate_day_
short")[d.
getDay()])
;fmt=fmt.r
eplace("%%
","%");ret
urn fmt},T
MPL_ELEMEN
T:'mceTmpl
Elm',TMPL:
'mceTmpl',
TMPL_BEGIN
S:'mceTmpl
Begins',TM
PL_SEL_HTM
L_DONE:'mc
eSelHTMLDo
ne',TMPL_E
NDS:'mceTm
plEnds',TM
PL_DATE_SR
C_ATTR:'mc
etmpldtesr
c',TMPL_TE
MPLATE_EVE
NT:'prepar
e_template
'};tinyMCE
.addPlugin
("template
",TinyMCE_
TemplatePl
ugin);
|
|
1 |
|
(function(
){var each
=tinymce.e
ach;tinymc
e.create('
tinymce.pl
ugins.Temp
latePlugin
',{init:fu
nction(ed,
url){var t
=this;t.ed
itor=ed;ed
.addComman
d('mceTemp
late',func
tion(ui){e
d.windowMa
nager.open
({file:url
+'/templat
e.htm',wid
th:ed.getP
aram('temp
late_popup
_width',75
0),height:
ed.getPara
m('templat
e_popup_he
ight',600)
,inline:1}
,{plugin_u
rl:url});}
);ed.addCo
mmand('mce
InsertTemp
late',t._i
nsertTempl
ate,t);ed.
addButton(
'template'
,{title:'t
emplate.de
sc',cmd:'m
ceTemplate
'});ed.onP
reProcess.
add(functi
on(ed,o){v
ar dom=ed.
dom;each(d
om.select(
'div',o.no
de),functi
on(e){if(d
om.hasClas
s(e,'mceTm
pl')){each
(dom.selec
t('*',e),f
unction(e)
{if(dom.ha
sClass(e,e
d.getParam
('template
_mdate_cla
sses','mda
te').repla
ce(/\s+/g,
'|')))e.in
nerHTML=t.
_getDateTi
me(new Dat
e(),ed.get
Param("tem
plate_mdat
e_format",
ed.getLang
("template
.mdate_for
mat")));})
;t._replac
eVals(e);}
});});},ge
tInfo:func
tion(){ret
urn{longna
me:'Templa
te plugin'
,author:'M
oxiecode S
ystems AB'
,authorurl
:'http://w
ww.moxieco
de.com',in
fourl:'htt
p://wiki.m
oxiecode.c
om/index.p
hp/TinyMCE
:Plugins/t
emplate',v
ersion:tin
ymce.major
Version+".
"+tinymce.
minorVersi
on};},_ins
ertTemplat
e:function
(ui,v){var
t=this,ed
=t.editor,
h,el,dom=e
d.dom,sel=
ed.selecti
on.getCont
ent();h=v.
content;ea
ch(t.edito
r.getParam
('template
_replace_v
alues'),fu
nction(v,k
){if(typeo
f(v)!='fun
ction')h=h
.replace(n
ew RegExp(
'\\{\\$'+k
+'\\}','g'
),v);});el
=dom.creat
e('div',nu
ll,h);func
tion hasCl
ass(n,c){r
eturn new
RegExp('\\
b'+c+'\\b'
,'g').test
(n.classNa
me);};each
(dom.selec
t('*',el),
function(n
){if(hasCl
ass(n,ed.g
etParam('t
emplate_cd
ate_classe
s','cdate'
).replace(
/\s+/g,'|'
)))n.inner
HTML=t._ge
tDateTime(
new Date()
,ed.getPar
am("templa
te_cdate_f
ormat",ed.
getLang("t
emplate.cd
ate_format
")));if(ha
sClass(n,e
d.getParam
('template
_mdate_cla
sses','mda
te').repla
ce(/\s+/g,
'|')))n.in
nerHTML=t.
_getDateTi
me(new Dat
e(),ed.get
Param("tem
plate_mdat
e_format",
ed.getLang
("template
.mdate_for
mat")));if
(hasClass(
n,ed.getPa
ram('templ
ate_select
ed_content
_classes',
'selconten
t').replac
e(/\s+/g,'
|')))n.inn
erHTML=sel
;});t._rep
laceVals(e
l);ed.exec
Command('m
ceInsertCo
ntent',fal
se,el.inne
rHTML);ed.
addVisual(
);},_repla
ceVals:fun
ction(e){v
ar dom=thi
s.editor.d
om,vl=this
.editor.ge
tParam('te
mplate_rep
lace_value
s');each(d
om.select(
'*',e),fun
ction(e){e
ach(vl,fun
ction(v,k)
{if(dom.ha
sClass(e,k
)){if(type
of(vl[k])=
='function
')vl[k](e)
;}});});},
_getDateTi
me:functio
n(d,fmt){i
f(!fmt)ret
urn"";func
tion addZe
ros(value,
len){var i
;value=""+
value;if(v
alue.lengt
h<len){for
(i=0;i<(le
n-value.le
ngth);i++)
value="0"+
value;}ret
urn value;
}fmt=fmt.r
eplace("%D
","%m/%d/%
y");fmt=fm
t.replace(
"%r","%I:%
M:%S %p");
fmt=fmt.re
place("%Y"
,""+d.getF
ullYear())
;fmt=fmt.r
eplace("%y
",""+d.get
Year());fm
t=fmt.repl
ace("%m",a
ddZeros(d.
getMonth()
+1,2));fmt
=fmt.repla
ce("%d",ad
dZeros(d.g
etDate(),2
));fmt=fmt
.replace("
%H",""+add
Zeros(d.ge
tHours(),2
));fmt=fmt
.replace("
%M",""+add
Zeros(d.ge
tMinutes()
,2));fmt=f
mt.replace
("%S",""+a
ddZeros(d.
getSeconds
(),2));fmt
=fmt.repla
ce("%I",""
+((d.getHo
urs()+11)%
12+1));fmt
=fmt.repla
ce("%p",""
+(d.getHou
rs()<12?"A
M":"PM"));
fmt=fmt.re
place("%B"
,""+tinyMC
E.getLang(
"template_
months_lon
g").split(
',')[d.get
Month()]);
fmt=fmt.re
place("%b"
,""+tinyMC
E.getLang(
"template_
months_sho
rt").split
(',')[d.ge
tMonth()])
;fmt=fmt.r
eplace("%A
",""+tinyM
CE.getLang
("template
_day_long"
).split(',
')[d.getDa
y()]);fmt=
fmt.replac
e("%a",""+
tinyMCE.ge
tLang("tem
plate_day_
short").sp
lit(',')[d
.getDay()]
);fmt=fmt.
replace("%
%","%");re
turn fmt;}
});tinymce
.PluginMan
ager.add('
template',
tinymce.pl
ugins.Temp
latePlugin
);})();
|