576. File Comparison Report

Produced on Mon May 12 13:06:24 2008 UTC. This report uses XHTML and CSS2, and is best viewed with a reasonably standards compliant browser such as the latest version of Firefox or Internet Explorer. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

576.1 Files compared

# Location File Last Modified
1 Dolphin-v.6.0.5\plugins\tiny_mce\plugins\template editor_plugin_src.js Thu Sep 20 08:59:16 2007 UTC
2 Dolphin-v.6.1.0\plugins\tiny_mce\plugins\template editor_plugin_src.js Thu Mar 27 13:53:26 2008 UTC

576.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 32 138
Changed 28 393
Inserted 0 0
Removed 4 169

576.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

576.4 Active regular expressions

No regular expressions were active.

576.5 Comparison detail

1   /**   1   /**
2     *   $Id:   editor_plu gin_src.js   16 2  
2007-0 1 - 03   1 6: 1
6:5 2 Z   spocke   $
  2     *   $Id:   editor_plu gin_src.js  
2 01   2007-0 2 -
1 2   1 5:5 6:5 6 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   tinyMCE.im portPlugin LanguagePa ck('templa te');   8   (function( ) {
    9       var ea ch = tinym ce.each;
9     10  
10   va r   T iny MCE_ TemplatePl ugin   =   {   11        tinymce.c r eate('t iny mce.plugin s. TemplatePl ugin ',   {
11        getI n fo   :   function(
)   {
  12            i n it   :   function( ed,   url )   {
12           re turn {   13                var t =  this;
13                longname  : 'Templa te plugin' ,    
14                author :  'Moxiecod e Systems  AB',    
15                authorur l : 'http: //www.moxi ecode.com' ,    
16                infourl  : 'http:// wiki.moxie code.com/i ndex.php/T inyMCE:Plu gins/templ ate',    
17                version  : tinyMCE. majorVersi on + "." +  tinyMCE.m inorVersio n    
18           };    
19       },    
20      
21       initIn stance : f unction(in st) {    
22           va r cdate, m date, cont ent, x = 0 , key, val ue, rvals,  ds = inst .getData(' template') ;    
23     14  
24           //  ensure th e required  elements  and sttrib utes are a dded   15                t.editor  = ed;
25           // inst.clean up.addRule Str('*[' +  TinyMCE_T emplatePlu gin.TMPL_D ATE_SRC_AT TR + '],di v[title,ts rc]');    
26     16  
27           // setup temp late conte nt functio ns   17                // Regis ter comman ds
28           //  creation  date and m odified da te classes   18                ed.addCo mmand('mce Template',  function( ui) {
29           cd ate = tiny MCE.getPar am("templa te_cdate_c lasses", ' ').split(/ \s+/);   19                    ed.w indowManag er.open({
30           md ate = tiny MCE.getPar am("templa te_mdate_c lasses", ' ').split(/ \s+/);   20                         file : url  + '/templ ate.htm',
31  
  21                         width : ed .getParam( 'template_ popup_widt h', 750),
32           //  classes t hat specif y where se lected con tent shoul d go   22                         height : e d.getParam ('template _popup_hei ght', 600) ,
33           co ntent = ti nyMCE.getP aram("temp late_selec ted_conten t_classes" , '').spli t(/\s+/);   23                         inline : 1
    24                     }, {
    25                         plugin_url  : url
    26                    });
    27                });
34     28  
35           fo r (x = 0;  x < cdate. length; x+ +)   29                ed.addCo mmand('mce InsertTemp late', t._ insertTemp late, t);
36                TinyMCE_ TemplatePl ugin.funct ions[cdate [x]] = Tin yMCE_Templ atePlugin. functions[ 'cdate'];     
37     30  
38           fo r (x = 0;  x < mdate. length; x+ +)   31                // Regis ter button s
39                TinyMCE_ TemplatePl ugin.funct ions[mdate [x]] = Tin yMCE_Templ atePlugin. functions[ 'mdate'];   32                ed.addBu tton('temp late', {ti tle : 'tem plate.desc ', cmd : ' mceTemplat e'});
40     33  
41           fo r (x = 0;  x < conten t.length;  x++)   34                ed.onPre Process.ad d(function (ed, o) {
42                TinyMCE_ TemplatePl ugin.funct ions[conte nt[x]] = T inyMCE_Tem platePlugi n.function s['selecte dContent'] ;   35                    var  dom = ed.d om;
43     36  
44           //  special t emplate fu nctions fo r replacin g template  content   37                    each (dom.selec t('div', o .node), fu nction(e)  {
45           rv als = tiny MCE.getPar am("templa te_replace _values",  false);   38                         if (dom.ha sClass(e,  'mceTmpl') ) {
46           fo r (key in  rvals) {   39                             each(d om.select( '*', e), f unction(e)  {
47                value =  rvals[key] ;   40                                 if  (dom.hasC lass(e, ed .getParam( 'template_ mdate_clas ses', 'mda te').repla ce(/\s+/g,  '|')))
    41                                      e.innerH TML = t._g etDateTime (new Date( ), ed.getP aram("temp late_mdate _format",  ed.getLang ("template .mdate_for mat")));
    42                             });
48     43  
49                if (type of value = = "functio n")   44                             t._rep laceVals(e );
50                    Tiny MCE_Templa tePlugin.f unctions[k ey] = valu e;    
51                else    
52                    Tiny MCE_Templa tePlugin.f unctions[k ey] = Tiny MCE_Templa tePlugin.f unctions[' generateRe placer'](v alue);    
53           }   45                         }
54  
  46                     });
55           //  Setup rep lace_items   47                 });
56           rv als = tiny MCE.getPar am("templa te_replace _values",  false);    
57           ds .replace_i tems = {};    
58      
59           fo r (key in  rvals)    
60                ds.repla ce_items[k ey] = rval s[key];    
61  
   
62           in st.addShor tcut('ctrl ', 't', 'l ang_templa te_desc',  'mceTempla te');    
63      
64           //  Setup dat a storage    
65           ds .currentAc tion = "in sert";    
66           ds .currentTm plNode = n ull;    
67       },   48           },
68     49  
69        get Co n tr o lHTML   :   function( cn )   {   50            get I n f o  
:   function(
)   {
70           sw itch (cn)  {   51                 return   {
71                case "te mplate":   52                    long name : 'Te mplate plu gin',
72                    retu rn tinyMCE .getButton HTML(cn, ' lang_templ ate_desc',  '{$plugin url}/image s/template .gif', 'mc eTemplate' , true);   53                    auth or : 'Moxi ecode Syst ems AB',
73           }   54                    auth orurl : 'h ttp://www. moxiecode. com',
74     55                    info url : 'htt p://wiki.m oxiecode.c om/index.p hp/TinyMCE :Plugins/t emplate',
75            return   "";   56                    vers ion : tiny mce.majorV ersion + " ." + tinym ce.minorVe rsion
    57                };
76       },   58           },
77     59  
78       execCo mmand : fu nction(edi tor_id, el ement, com mand, user _interface , value) {   60           _i nsertTempl ate : func tion(ui, v ) {
79           va r nodeArra y, current , newTmpl,  x, inst =  tinyMCE.g etInstance ById(edito r_id), ds  = inst.get Data('temp late'), te lm;   61                var t =  this, ed =  t.editor,  h, el, do m = ed.dom , sel = ed .selection .getConten t();
80      
81           sw itch (comm and) {    
82                case "mc eTemplate" :    
83                    if ( user_inter face) {    
84                         // called  from toolb ar button  - show the  popup    
85                         tinyMCE.op enWindow({    
86                             file :  '../../pl ugins/temp late/templ ate.htm',  // Relativ e to theme    
87                             width  : tinyMCE. getParam(' template_p opup_width ', 750),    
88                             height  : tinyMCE .getParam( 'template_ popup_heig ht', 600)    
89                         }, {editor _id : edit or_id, res izable : " yes", scro llbars : " no", plugi nObj : Tin yMCE_Templ atePlugin} );    
90                    } el se {    
91                         // interna l command  do the tem plate stuf f    
92     62  
93                         // get the  returned  HTML strin g from the  pop-up an d appened  it to a DI V element   63                h = v.co ntent;
94                         telm = Tin yMCE_Templ atePlugin. _convertTo Node(value .body);    
95     64  
96                         // Find te mplate bod y   65                each(t.e ditor.getP aram('temp late_repla ce_values' ), functio n(v, k) {
97                         nodeArray  = tinyMCE. selectElem ents(telm,  'div', fu nction(n)  {   66                    if ( typeof(v)  != 'functi on')
98                             return  tinyMCE.h asCSSClass (n, TinyMC E_Template Plugin.TMP L);   67                         h = h.repl ace(new Re gExp('\\{\ \$' + k +  '\\}', 'g' ), v);
99                         });   68                });
100     69  
101                         telm = nod eArray.len gth > 0 ?  nodeArray[ 0] : null;   70                el = dom .create('d iv', null,  h);
102                         nodeArray  = [];    
103      
104                         if (ds.cur rentAction  == "inser t") {    
105                             //inse rt new tem plate afte r applying  all the t emplate co ntent func tions    
106      
107                             // Is  it a templ ate or sni ppet    
108                             if (te lm) {    
109                                 ti nyMCE.exec Command('m ceBeginUnd oLevel');    
110                                 ds .currentAc tion = "in sert-new";    
111                                 Ti nyMCE_Temp latePlugin ._insertTe mplate(edi tor_id, te lm, value. title, val ue.tsrc, t rue);    
112                                 ds .currentAc tion == "i nsert";    
113                                 ti nyMCE.exec Command('m ceEndUndoL evel');    
114                                 ti nyMCE.exec InstanceCo mmand(edit or_id, 'mc eCleanup',  false);    
115                             } else    
116                                 ti nyMCE.exec Command('m ceInsertCo ntent', fa lse, this. _replaceVa lues(value .body));    
117                         } else {    
118                             // Fir st collect  the selec ted templa te in the  editor    
119                             nodeAr ray = Tiny MCE_Templa tePlugin._ collectTem plateEleme nts(ds.cur rentTmplNo de);    
120                             curren t = [];    
121                             newTmp l = [];    
122                             tinyMC E.getNodeT ree(telm,  newTmpl);    
123      
124                             for (x =0; x<node Array.leng th; x++)    
125                                 ti nyMCE.getN odeTree(no deArray[x] , current) ;    
126     71  
127                             /**    72                function  hasClass( n, c) {
128                              * inn er functio n used in  the loop b elow.   73                    retu rn new Reg Exp('\\b'  + c + '\\b ', 'g').te st(n.class Name);
129                              * com pares the  supplied H TML elemen t to the n ew templat e to:    
130                              * - f ind a matc h with the  new templ ate and co py the ele ment's con tent over    
131                              * - f ind no mat ch and ind icate cont ent will b e lost    
132                              */    
133                             var _t est = func tion(elm)  {    
134                                 va r replaced  = true;    
135      
136                                 if  (elm.clas sName) {    
137                                      var name s = elm.cl assName.sp lit(/\s+/) , c, n;    
138      
139                                      for (c =  0; c<name s.length;  c++) {    
140                                          if ( names[c].m atch(/^mce /i))    
141                                               continue;  // ignore  all intern al class n ames    
142      
143                                          for  (n=0; n<ne wTmpl.leng th; n++){    
144                                               replaced =  false;    
145      
146                                               if (newTmp l[n].class Name && ne wTmpl[n].c lassName.m atch(new R egExp(name s[c], "gi" ))) {    
147                                                   newTmp l[n].inner HTML = elm .innerHTML ;    
148                                                   //if(t inyMCE.get Attrib(elm ,TinyMCE_T emplatePlu gin.TMPL_D ATE_SRC_AT TR,"") !=  "") {    
149                                                   //  ti nyMCE.setA ttrib(newT mpl[n], Ti nyMCE_Temp latePlugin .TMPL_DATE _SRC_ATTR,  tinyMCE.g etAttrib(e lm,TinyMCE _TemplateP lugin.TMPL _DATE_SRC_ ATTR));     
150                                                   //}    
151                                                   replac ed = true;    
152                                                   break;    
153                                               }    
154      
155                                          }    
156                                      }    
157                                 }    
158           
159                                 re turn repla ced;    
160                             };    
161      
162                             // com parison lo op - first  mis-match  alerts us er for con firmation.    
163                             var co nt = true;    
164                             var as ked = fals e;    
165      
166                             for (x  = 0; x <  current.le ngth; x++)  {    
167                                 if (!_test(cu rrent[x]))  {    
168                                      cont = ( asked || c onfirm("Th e new temp late has l ess elemen ts than th e currentl y selected  content.\ nIf you pr oceed you  will loose  content.\ nAre you s ure you wa nt to proc eed?", "Pr oceed?"));    
169                                      asked =  true;    
170      
171                                      if (!con t)    
172                                          brea k;    
173                                 }    
174                             };   74                };
175     75  
176                             // app ly replace ment if al lowed to   76                each(dom .select('* ', el), fu nction(n)  {
177                             if (co nt) {   77                    // R eplace cda te
178                                 ti nyMCE.exec Command('m ceBeginUnd oLevel');   78                    if ( hasClass(n , ed.getPa ram('templ ate_cdate_ classes',  'cdate').r eplace(/\s +/g, '|')) )
179                                 Ti nyMCE_Temp latePlugin ._replaceT emplateCon tent(curre nt[0], edi tor_id, te lm, value. title, val ue.tsrc);   79                         n.innerHTM L = t._get DateTime(n ew Date(),  ed.getPar am("templa te_cdate_f ormat", ed .getLang(" template.c date_forma t")));
180                                 ti nyMCE.exec Command('m ceEndUndoL evel');    
181                                 ti nyMCE.exec InstanceCo mmand(edit or_id, 'mc eCleanup',  false);    
182                             }    
183                         }    
184      
185                         tinyMCE.tr iggerNodeC hange(true );    
186                    }    
187      
188                    retu rn true;    
189           }    
190      
191           re turn false ;    
192       },    
193      
194       handle NodeChange  : functio n(editor_i d, node, u ndo_index,  undo_leve ls, visual _aid, any_ selection)  {    
195           va r inst = t inyMCE.get InstanceBy Id(editor_ id), ds =  inst.getDa ta('templa te');    
196      
197           if  (tinyMCE. hasCSSClas s(node, Ti nyMCE_Temp latePlugin .TMPL_ELEM ENT) || ti nyMCE.hasC SSClass(no de.parentN ode, TinyM CE_Templat ePlugin.TM PL_ELEMENT )) {    
198                tinyMCE. switchClas s(editor_i d + '_temp late', 'mc eButtonSel ected');    
199                ds.curre ntAction =  "update";    
200                ds.curre ntTmplNode  = node;    
201      
202                return t rue;    
203           }    
204      
205           ds .currentAc tion = "in sert";    
206           ds .currentTm plNode = n ull;    
207           ti nyMCE.swit chClass(ed itor_id +  '_template ', 'mceBut tonNormal' );    
208      
209           re turn false ;    
210       },    
211      
212       cleanu p : functi on(type, c ontent, in st) {    
213           va r nodes =  [];    
214      
215           sw itch (type ) {    
216                case "ge t_from_edi tor":    
217                    // r eplace the  opening w rapper div  tag with  a HTML com ment    
218                    cont ent = cont ent.replac e(    
219                         new RegExp ('<div cla ss="' + Ti nyMCE_Temp latePlugin .TMPL + '" >', 'gi'),    
220                         '<!-- ' +  TinyMCE_Te mplatePlug in.TMPL_BE GINS + ' - ->'    
221                    );    
222      
223                    // d elete any  empty temp late wrapp ers    
224                    cont ent = cont ent.replac e(    
225                         new RegExp ('<div cla ss="' + Ti nyMCE_Temp latePlugin .TMPL + '" >(\s|&nbsp ;|&#160;)? (<!-- ' +  TinyMCE_Te mplatePlug in.TMPL_EN DS + ' --> |\s)?</div >', 'gi'),    
226                         ''    
227                    );    
228      
229                    // r eplace the  closing w rapper tag    
230                    cont ent = cont ent.replac e(    
231                         new RegExp ('<!-- ' +  TinyMCE_T emplatePlu gin.TMPL_E NDS + ' -- ></div>',  'gi'),    
232                         '<!-- ' +  TinyMCE_Te mplatePlug in.TMPL_EN DS + ' --> '    
233                    );    
234      
235                    brea k;    
236      
237                case "in sert_to_ed itor":    
238                    // r eplace HTM L comment  with DIV w rapper    
239                    cont ent = cont ent.replac e(    
240                         new RegExp ('<!-- ' +  TinyMCE_T emplatePlu gin.TMPL_B EGINS + '  -->', 'gi' ),    
241                         '<div clas s="' + Tin yMCE_Templ atePlugin. TMPL + '"> '    
242                    );    
243      
244                    cont ent = cont ent.replac e(    
245                         new RegExp ('<!-- ' +  TinyMCE_T emplatePlu gin.TMPL_E NDS + ' -- >', 'gi'),    
246                         '<!-- ' +  TinyMCE_Te mplatePlug in.TMPL_EN DS + ' --> </div>'    
247                    );    
248      
249                    brea k;    
250      
251                case "ge t_from_edi tor_dom":    
252                    // a pply templ ate conten t replacem ent functi ons    
253                    node s = tinyMC E.selectNo des(conten t, functio n(n) {    
254                             return  tinyMCE.h asCSSClass (n, TinyMC E_Template Plugin.TMP L_ELEMENT) ;    
255                         }    
256                    );    
257      
258                    Tiny MCE_Templa tePlugin._ applyFunct ions(nodes , type);    
259      
260                    brea k;    
261      
262                case "in sert_to_ed itor_dom":    
263                    // a pply templ ate conten t replacem ent functi ons    
264                    node s = tinyMC E.selectNo des(conten t, functio n(n) {    
265                             return  tinyMCE.h asCSSClass (n, TinyMC E_Template Plugin.TMP L_ELEMENT) ;    
266                         }    
267                    );    
268      
269                    Tiny MCE_Templa tePlugin._ applyFunct ions(nodes , type);    
270      
271                    brea k;    
272           }    
273      
274           re turn conte nt;    
275       },    
276      
277       // Pri vate plugi n internal  methods    
278      
279       /**    
280        * Cre ates a HTM L DIV elem ent and se ts the inn erHTML to  equal the  temlate in nerHTML so  that the  template c an be mani pulated as  DOM nodes .    
281        *    
282        * @pa ram {strin g} Templat e innerHTM L    
283        * @re turn a HTM L Element    
284        * @ty pe HTMLEle ment    
285        */    
286       _conve rtToNode :  function( html) {    
287           va r elm = do cument.cre ateElement ('div');    
288      
289           el m.innerHTM L = html;    
290     80  
291           re turn elm;   81                    // R eplace mda te
292       },   82                    if ( hasClass(n , ed.getPa ram('templ ate_mdate_ classes',  'mdate').r eplace(/\s +/g, '|')) )
    83                         n.innerHTM L = t._get DateTime(n ew Date(),  ed.getPar am("templa te_mdate_f ormat", ed .getLang(" template.m date_forma t")));
293     84  
294       /**   85                    // R eplace sel ection
295        * pas s an array  of templa te html el ements and  they will  have the  template c lass name  added and  any templa te functio ns applied   86                    if ( hasClass(n , ed.getPa ram('templ ate_select ed_content _classes',  'selconte nt').repla ce(/\s+/g,  '|')))
296        *   87                         n.innerHTM L = sel;
297        * @pa ram {array } template  HTML elem ents   88                 });
298        * @re turn array  of templa te HTML el ements    
299        * @ty pe array    
300        */    
301       _prepa reTemplate Content :  function(e lms) {    
302           va r x, n, no des = [];    
303      
304           if  (!elms)    
305                return { };    
306      
307           if  (!elms.le ngth)    
308                elms = [ elms];    
309  
   
310           fo r (x = 0;  x<elms.len gth; x++)    
311                tinyMCE. getNodeTre e(elms[x],  nodes, 1) ;    
312     89  
313           fo r (n = 0;  n<nodes.le ngth; n++)  {   90                t._repla ceVals(el) ;
314                tinyMCE. addCSSClas s(nodes[n] , TinyMCE_ TemplatePl ugin.TMPL_ ELEMENT);    
315                TinyMCE_ TemplatePl ugin._appl yFunctions (nodes[n],  TinyMCE_T emplatePlu gin.TMPL_T EMPLATE_EV ENT);    
316           }    
317     91  
318           re turn elms;   92                ed.execC ommand('mc eInsertCon tent', fal se, el.inn erHTML);
    93                ed.addVi sual();
319       },   94           },
320     95  
321        _replaceVa l ue s   :   function( s )   {   96            _replaceVa l
s   :   function( e )   {
322            var   t   =   this ,   d s   =   t i nyMCE . se l ec t
ed Ins t ance .get D a t a
('template
');
  97                 var   dom   =   this .e d
i tor . dom,   v l   =   t his. ed i t or .get P a r a m ('template _replace_v alues ');
323      
324           re turn s.rep lace(/\{\$ ([^\}]+)\} /g, functi on(a, b) {    
325                var it =  ds.replac e_items[b] ;    
326     98  
327                if ( it ) {   99                each(dom .select('* ', e), fun ction(e) {
328                    // O nly suppor ts text fo r now   100                    each (vl, funct ion(v, k)  {
329                     if   (typeof( it )   ! =   'function' )   101                         if ( dom.hasCla ss(e, k) ) {
330                         return it;   102                              if   (typeof( vl[k] )   = =   'function' )
    103                                 vl [k](e);
331                }   104                         }
332      
333                return b ;    
334           }) ;   105                    });
335       },    
336      
337       /**    
338        * App lies any s pecial fun ctions to  the templa te element s    
339        *    
340        * @pa ram {array } template  HTML elem ents    
341        * @re turn array  of templa te HTML el ements    
342        * @ty pe array    
343        */    
344       _apply Functions  : function (elms, edi tor_event)  {    
345           va r x, elm,  names, c,  f;    
346      
347           if  (!elms)    
348                return { };    
349      
350           if  (!elms.le ngth)    
351                elms = [ elms];    
352      
353           fo r(x = 0; x  < elms.le ngth; x++)  {    
354                elm = el ms[x];    
355      
356                if (elm. className) {    
357                    name s = elm.cl assName.sp lit(/\s+/) ;    
358      
359                    for  (c = 0; c  < names.le ngth; c++) {    
360                         if (names[ c] == Tiny MCE_Templa tePlugin.T MPL_ELEMEN T)    
361                             contin ue;    
362      
363                         f = (TinyM CE_Templat ePlugin.fu nctions[na mes[c]] ?  TinyMCE_Te mplatePlug in.functio ns[names[c ]] : TinyM CE_Templat ePlugin.fu nctions['b lank']);    
364                         f(elm, edi tor_event) ;    
365                    }    
366                }    
367           }    
368      
369           re turn elms;    
370       },    
371      
372       /**    
373        * Giv en one nod e referenc e this fun ction will  collect a ll the nod es of the  template t o which it  belongs.    
374        * It  does this  by finding  the paren t template  wrapper D IV and ret urning all  child nod es.    
375        *    
376        * @pa ram {HTMLE lement} a  HTMLElemen t which is  part of a  template    
377        * @re turn array  of templa te HTML el ements    
378        * @ty pe array    
379        */    
380       _colle ctTemplate Elements :  function( node) {    
381           va r nodeArra y = [], p;    
382      
383           p  = tinyMCE. getParentE lement(nod e, 'DIV',  function(n ) {    
384                return t inyMCE.has CSSClass(n , TinyMCE_ TemplatePl ugin.TMPL) ;    
385           }) ;   106                });
386      
387           if  (p)    
388                tinyMCE. getNodeTre e(p, nodeA rray);    
389      
390           re turn nodeA rray;    
391       },   107           },
392     108  
393       /**    
394        * Sim ply calls  TinyMCE_Te mplatePlug in._delete TemplateCo ntent and  then TinyM CE_Templat ePlugin._i nsertTempl ate    
395        *    
396        * @pa ram {HTMLE lement} cu rrently se lected tem plate node  in editor    
397        * @pa ram {strin g} id of e ditor inst ance    
398        * @pa ram {HTMLE lement} te mplate con tents as a  HTMLEleme nt (the pa rent DIV w rapper)    
399        * @pa ram {strin g} title o f template  (unused a s yet)    
400        * @pa ram {strin g} source  URI of the  template  file (unus ed as yet)    
401        * @re turn array  of templa te HTML el ements    
402        * @ty pe array    
403        */    
404       _repla ceTemplate Content :  function(c urrentNode , editor_i d, newTemp late, titl e, tsrc) {    
405           Ti nyMCE_Temp latePlugin ._deleteTe mplateCont ent(curren tNode);    
406           Ti nyMCE_Temp latePlugin ._insertTe mplate(edi tor_id, ne wTemplate,  title, ts rc, false) ;    
407       },    
408      
409       /**    
410        * Del etes a tem plate from  the edito r content    
411        * Fin ds the par ent DIV wr apper and  deletes it  and all c hildren    
412        * @pa ram {HTMLE lement} cu rrently se lected tem plate node  in editor    
413        */    
414       _delet eTemplateC ontent : f unction(no de) {    
415           va r p = tiny MCE.getPar entElement (node, 'DI V', functi on(n) {    
416                return t inyMCE.has CSSClass(n , TinyMCE_ TemplatePl ugin.TMPL) ;    
417           }) ;    
418      
419           if  (p)    
420                p.parent Node.remov eChild(p,  true);    
421       },    
422      
423       /**    
424        *  In serts a te mplate int o the spec ified edit or    
425        *    
426        * @pa ram {strin g} id of e ditor inst ance    
427        * @pa ram {HTMLE lement} te mplate con tents as a  HTMLEleme nt (the pa rent DIV w rapper)    
428        * @pa ram {strin g} title o f template  (unused a s yet)    
429        * @pa ram {strin g} source  URI of the  template  file (unus ed as yet)    
430        */    
431       _inser tTemplate  : function (editor_id , elm, tit le, tsrc,  incComment s) {    
432           va r html;    
433      
434           Ti nyMCE_Temp latePlugin ._prepareT emplateCon tent(elm);    
435      
436           ht ml = '<div  class="'  + TinyMCE_ TemplatePl ugin.TMPL  + '">';    
437           ht ml += elm. innerHTML;    
438           ht ml += '<!- - ' + Tiny MCE_Templa tePlugin.T MPL_ENDS +  ' --></di v>';    
439      
440           ti nyMCE.exec InstanceCo mmand(edit or_id, 'mc eInsertCon tent', fal se, html);    
441       },    
442      
443       /**    
444        * tem plate func tions - fu nctions fo r modifyin g template  content    
445        */    
446       functi ons : {     
447           bl ank : func tion(elm,  editor_eve nt) {},    
448      
449           cd ate : func tion(elm,  editor_eve nt) {    
450                var d, d src;    
451      
452                if (edit or_event ! = TinyMCE_ TemplatePl ugin.TMPL_ TEMPLATE_E VENT)    
453                    retu rn;    
454      
455                d = new  Date();    
456                // find  out if the  creation  date was p reviously  stored    
457                dsrc = e lm.innerHT ML.match(n ew RegExp( "<!-- " +  TinyMCE_Te mplatePlug in.TMPL_DA TE_SRC_ATT R + ":(.*)   -->", "g i"));    
458      
459                if (dsrc )    
460                    d =  new Date(R egExp.$1);    
461      
462                elm.inne rHTML = Ti nyMCE_Temp latePlugin ._getDateT ime(d, tin yMCE.getPa ram("templ ate_cdate_ format", t inyMCE.get Lang("lang _template_ def_date_f ormat")));    
463                //now we  have to s tore the d ate value  in a forma t easily r ead again,  in case a  future te mplate cha nge change s the date  format...    
464                elm.inne rHTML += " <!-- " + T inyMCE_Tem platePlugi n.TMPL_DAT E_SRC_ATTR  + ":" + d .toUTCStri ng() + "   -->";    
465           },    
466      
467           md ate : func tion(elm,  editor_eve nt) {    
468                var d =  new Date() ;    
469                elm.inne rHTML = Ti nyMCE_Temp latePlugin ._getDateT ime(d, tin yMCE.getPa ram("templ ate_mdate_ format", t inyMCE.get Lang("lang _template_ def_date_f ormat")));    
470           },    
471      
472           /* *    
473            *  This will  insert th e currentl y selected  editor co ntent into  the templ ate elemen t.    
474            *  It only d oes this i f the temp late inser ted is a n ew one and  if the el ement does  not have  the specia l class.    
475            *  The speci al class n ame preven ts this fr om happeni ng more th an once.    
476            * /    
477           se lectedCont ent : func tion(elm,  editor_eve nt) {    
478                var ds =  tinyMCE.s electedIns tance.getD ata('templ ate');    
479           
480                if (edit or_event ! = TinyMCE_ TemplatePl ugin.TMPL_ TEMPLATE_E VENT)    
481                    retu rn;    
482      
483                if (ds.c urrentActi on == "ins ert-new" & & !tinyMCE .hasCSSCla ss(elm, Ti nyMCE_Temp latePlugin .TMPL_SEL_ HTML_DONE) ) {    
484                    elm. innerHTML  = tinyMCE. selectedIn stance.sel ection.get SelectedHT ML();    
485                    tiny MCE.addCSS Class(elm,  TinyMCE_T emplatePlu gin.TMPL_S EL_HTML_DO NE);    
486                }    
487           },    
488      
489           /* *    
490            *  When the  plugin is  initialise d this gen erates the  functions  that inse rt configu red string s into tem plate elem ents.    
491            * /    
492           ge nerateRepl acer : fun ction(s) {    
493                return f unction(el m, editor_ event) {el m.innerHTM L = "" + s ;};    
494           }    
495       },    
496      
497       /**    
498        * for mats a dat e accordin g to the f ormat stri ng - strai ght from t he 'insert  date/time ' plugin    
499        *    
500        * @pa ram {Date}  date obje ct    
501        * @pa ram {strin g} format  string    
502        * @re turn forma tted date    
503        * @ty pe string    
504        */    
505       _getDa teTime : f unction(d, fmt) {   109           _g etDateTime  : functio n(d, fmt)  {
506                if (!fmt )   110                    if ( !fmt)
507                    retu rn "";   111                         return "";
508     112  
509                function  addZeros( value, len ) {   113                    func tion addZe ros(value,  len) {
510                    var  i;   114                         var i;
511     115  
512                    valu e = "" + v alue;   116                         value = ""  + value;
513     117  
514                    if ( value.leng th < len)  {   118                         if (value. length < l en) {
515                         for (i=0;  i<(len-val ue.length) ; i++)   119                             for (i =0; i<(len -value.len gth); i++)
516                             value  = "0" + va lue;   120                                 va lue = "0"  + value;
517                    }   121                         }
518     122  
519                    retu rn value;   123                         return val ue;
520                }   124                    }
521     125  
522                fmt = fm t.replace( "%D", "%m/ %d/%y");   126                    fmt  = fmt.repl ace("%D",  "%m/%d/%y" );
523                fmt = fm t.replace( "%r", "%I: %M:%S %p") ;   127                    fmt  = fmt.repl ace("%r",  "%I:%M:%S  %p");
524                fmt = fm t.replace( "%Y", "" +  d.getFull Year());   128                    fmt  = fmt.repl ace("%Y",  "" + d.get FullYear() );
525                fmt = fm t.replace( "%y", "" +  d.getYear ());   129                    fmt  = fmt.repl ace("%y",  "" + d.get Year());
526                fmt = fm t.replace( "%m", addZ eros(d.get Month()+1,  2));   130                    fmt  = fmt.repl ace("%m",  addZeros(d .getMonth( )+1, 2));
527                fmt = fm t.replace( "%d", addZ eros(d.get Date(), 2) );   131                    fmt  = fmt.repl ace("%d",  addZeros(d .getDate() , 2));
528                fmt = fm t.replace( "%H", "" +  addZeros( d.getHours (), 2));   132                    fmt  = fmt.repl ace("%H",  "" + addZe ros(d.getH ours(), 2) );
529                fmt = fm t.replace( "%M", "" +  addZeros( d.getMinut es(), 2));   133                    fmt  = fmt.repl ace("%M",  "" + addZe ros(d.getM inutes(),  2));
530                fmt = fm t.replace( "%S", "" +  addZeros( d.getSecon ds(), 2));   134                    fmt  = fmt.repl ace("%S",  "" + addZe ros(d.getS econds(),  2));
531                fmt = fm t.replace( "%I", "" +  ((d.getHo urs() + 11 ) % 12 + 1 ));   135                    fmt  = fmt.repl ace("%I",  "" + ((d.g etHours()  + 11) % 12  + 1));
532                fmt = fm t.replace( "%p", "" +  (d.getHou rs() < 12  ? "AM" : " PM"));   136                    fmt  = fmt.repl ace("%p",  "" + (d.ge tHours() <  12 ? "AM"  : "PM"));
533                 fmt   =   fmt.replac e("%B",   ""   +   tinyMCE.ge tLang(" lang_ template_m onths_long ")
[d.getMont h()]);
  137                     fmt   =   fmt.replac e("%B",   ""   +   tinyMCE.ge tLang("
template_m onths_long ") .split(',' ) [d.getMont h()]);
534                 fmt   =   fmt.replac e("%b",   ""   +   tinyMCE.ge tLang(" lang_ template_m onths_shor t")
[d.getMont h()]);
  138                     fmt   =   fmt.replac e("%b",   ""   +   tinyMCE.ge tLang("
template_m onths_shor t") .split(',' ) [d.getMont h()]);
535                 fmt   =   fmt.replac e("%A",   ""   +   tinyMCE.ge tLang(" lang_ template_d ay_long")
[d.getDay( )]);
  139                     fmt   =   fmt.replac e("%A",   ""   +   tinyMCE.ge tLang("
template_d ay_long") .split(',' ) [d.getDay( )]);
536                 fmt   =   fmt.replac e("%a",   ""   +   tinyMCE.ge tLang(" lang_ template_d ay_short")
[d.getDay( )]);
  140                     fmt   =   fmt.replac e("%a",   ""   +   tinyMCE.ge tLang("
template_d ay_short") .split(',' ) [d.getDay( )]);
537                fmt = fm t.replace( "%%", "%") ;   141                    fmt  = fmt.repl ace("%%",  "%");
538     142  
539                return f mt;   143                    retu rn fmt;
540        } ,   144            }
541     145        } ) ;
542       TMPL_E LEMENT : ' mceTmplElm ',    
543       TMPL :  'mceTmpl' ,    
544       TMPL_B EGINS : 'm ceTmplBegi ns',    
545       TMPL_S EL_HTML_DO NE : 'mceS elHTMLDone ',    
546       TMPL_E NDS : 'mce TmplEnds',    
547       TMPL_D ATE_SRC_AT TR : 'mcet mpldtesrc' ,    
548       TMPL_T EMPLATE_EV ENT : 'pre pare_templ ate'    
549   }
;
   
550     146  
551   tiny MCE . add Plugin
( " template " ,   T iny MCE_ TemplatePl ugin);
  147       // Reg ister plug in
    148        tiny mce .
Plugin Manager.ad d ( ' template ' ,   t iny mce.plugin s. TemplatePl ugin);
    149   })();