includes/clientside/static/editor.js
changeset 335 67bd3121a12e
parent 117 7cfdbb2fd17a
child 336 bfa2e9c23f03
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
     1 // Javascript routines for the page editor
     1 // Javascript routines for the page editor
     2 
     2 
       
     3 if ( document.getElementById('mdgCss') )
       
     4 {
       
     5   var css_url = document.getElementById('mdgCss').href;
       
     6 }
       
     7 else
       
     8 {
       
     9   var css_url = scriptPath + '/includes/clientside/css/enano_shared.css';
       
    10 }
       
    11 
       
    12 var do_popups = ( is_Safari ) ? '' : ',inlinepopups';
       
    13 var _skin = ( typeof(tinymce_skin) == 'string' ) ? tinymce_skin : 'default';
       
    14 
     3 var enano_tinymce_options = {
    15 var enano_tinymce_options = {
     4   mode : "exact",
    16   mode : "none",
     5   elements : '',
    17   plugins : 'table,save,safari,pagebreak,style,layer,advhr,insertdatetime,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras' + do_popups,
     6   plugins : 'table',
    18   theme : 'advanced',
       
    19   skin : _skin,
     7   theme_advanced_resize_horizontal : false,
    20   theme_advanced_resize_horizontal : false,
     8   theme_advanced_resizing : true,
    21   theme_advanced_resizing : true,
     9   theme_advanced_toolbar_location : "top",
    22   theme_advanced_toolbar_location : "top",
    10   theme_advanced_toolbar_align : "left",
    23   theme_advanced_toolbar_align : "left",
    11   theme_advanced_buttons1_add : "fontselect,fontsizeselect",
    24   theme_advanced_buttons1 : "save,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,forecolor,backcolor,|,formatselect,|,fontselect,fontsizeselect",
    12   theme_advanced_buttons3_add_before : "tablecontrols,separator",
    25   theme_advanced_buttons3_add_before : "tablecontrols,separator",
    13   theme_advanced_statusbar_location : 'bottom'
    26   theme_advanced_buttons3_add_after : "|,fullscreen",
       
    27   theme_advanced_statusbar_location : 'bottom',
       
    28   noneditable_noneditable_class : 'mce_readonly',
       
    29   content_css : css_url
    14 };
    30 };
    15 
    31 
    16 var initTinyMCE = function(e)
    32 var initTinyMCE = function(e)
    17 {
    33 {
    18   if ( typeof(tinyMCE) == 'object' )
    34   if ( typeof(tinyMCE) == 'object' )
    23     }
    39     }
    24   }
    40   }
    25 }
    41 }
    26 addOnloadHook(initTinyMCE);
    42 addOnloadHook(initTinyMCE);
    27 
    43 
       
    44 var editor_open = false;
       
    45 
       
    46 function ajaxEditor()
       
    47 {
       
    48   if ( KILL_SWITCH )
       
    49     return true;
       
    50   if ( editor_open )
       
    51     return true;
       
    52   selectButtonMinor('edit');
       
    53   selectButtonMajor('article');
       
    54   setAjaxLoading();
       
    55   ajaxGet(stdAjaxPrefix + '&_mode=getsource', function()
       
    56     {
       
    57       if ( ajax.readyState == 4 )
       
    58       {
       
    59         unsetAjaxLoading();
       
    60         
       
    61         var response = String(ajax.responseText + '');
       
    62         if ( response.substr(0, 1) != '{' )
       
    63         {
       
    64           handle_invalid_json(response);
       
    65           return false;
       
    66         }
       
    67         
       
    68         response = parseJSON(response);
       
    69         if ( response.mode == 'error' )
       
    70         {
       
    71           unselectAllButtonsMinor();
       
    72           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
       
    73           return false;
       
    74         }
       
    75         
       
    76         if ( !response.auth_view_source )
       
    77         {
       
    78           unselectAllButtonsMinor();
       
    79           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
       
    80           return false;
       
    81         }
       
    82         
       
    83         ajaxBuildEditor(response.src, (!response.auth_edit), response.time);
       
    84       }
       
    85     });
       
    86 }
       
    87 
       
    88 function ajaxBuildEditor(content, readonly, timestamp)
       
    89 {
       
    90   // Set flags
       
    91   // We don't want the fancy confirmation framework to trigger if the user is only viewing the page source
       
    92   if ( !readonly )
       
    93   {
       
    94     editor_open = true;
       
    95     disableUnload();
       
    96   }  
       
    97   
       
    98   // Destroy existing contents of page container
       
    99   var edcon = document.getElementById('ajaxEditContainer');
       
   100   for ( var i = edcon.childNodes.length - 1; i >= 0; i-- )
       
   101   {
       
   102     edcon.removeChild(edcon.childNodes[i]);
       
   103   }
       
   104   
       
   105   //
       
   106   // BUILD EDITOR
       
   107   //
       
   108   
       
   109   // Plaintext/wikitext toggler
       
   110   
       
   111   var toggler = document.createElement('p');
       
   112   toggler.style.marginLeft = '0';
       
   113   
       
   114   var span_wiki = document.createElement('span');
       
   115   var span_mce  = document.createElement('span');
       
   116   span_wiki.id  = 'enano_edit_btn_pt';
       
   117   span_mce.id   = 'enano_edit_btn_mce';
       
   118   if ( readCookie('enano_editor_mode') == 'tinymce' )
       
   119   {
       
   120     // Current selection is TinyMCE - make span_wiki have the link and span_mce be plaintext
       
   121     var a = document.createElement('a');
       
   122     a.href = '#';
       
   123     a.onclick = function() {
       
   124       ajaxSetEditorPlain();
       
   125       return false;
       
   126     };
       
   127     a.appendChild(document.createTextNode($lang.get('editor_btn_wikitext')));
       
   128     span_wiki.appendChild(a);
       
   129     toggler.appendChild(span_wiki);
       
   130     toggler.appendChild(document.createTextNode(' | '));
       
   131     span_mce.appendChild(document.createTextNode($lang.get('editor_btn_graphical')));
       
   132     toggler.appendChild(span_mce);
       
   133   }
       
   134   else
       
   135   {
       
   136     // Current selection is wikitext - set span_wiki to plaintext and span_mce to link
       
   137     span_wiki.appendChild(document.createTextNode($lang.get('editor_btn_wikitext')));
       
   138     toggler.appendChild(span_wiki);
       
   139     toggler.appendChild(document.createTextNode(' | '));
       
   140     var a = document.createElement('a');
       
   141     a.href = '#';
       
   142     a.onclick = function() {
       
   143       ajaxSetEditorMCE();
       
   144       return false;
       
   145     };
       
   146     a.appendChild(document.createTextNode($lang.get('editor_btn_graphical')));
       
   147     span_mce.appendChild(a);
       
   148     toggler.appendChild(span_mce);
       
   149   }
       
   150   
       
   151   // Form (to allow submits from MCE to trigger a real save)
       
   152   var form = document.createElement('form');
       
   153   form.action = 'javascript:void(0);';
       
   154   form.onsubmit = function()
       
   155   {
       
   156     ajaxEditorSave();
       
   157     return false;
       
   158   }
       
   159   
       
   160   // Preview holder
       
   161   var preview_anchor = document.createElement('a');
       
   162   preview_anchor.name = 'ajax_preview';
       
   163   preview_anchor.id = 'ajax_preview';
       
   164   var preview_container = document.createElement('div');
       
   165   preview_container.id = 'enano_editor_preview';
       
   166   
       
   167   // Textarea containing the content
       
   168   var ta_wrapper = document.createElement('div');
       
   169   ta_wrapper.style.margin = '10px 0';
       
   170   var textarea = document.createElement('textarea');
       
   171   textarea.value = content;
       
   172   textarea._edTimestamp = timestamp;
       
   173   textarea.id = 'ajaxEditArea';
       
   174   textarea.rows = '20';
       
   175   textarea.cols = '60';
       
   176   textarea.style.width = '98.7%';
       
   177   if ( readonly )
       
   178   {
       
   179     textarea.className = 'mce_readonly';
       
   180     textarea.setAttribute('readonly', 'readonly');
       
   181   }
       
   182   ta_wrapper.appendChild(textarea);
       
   183   
       
   184   // Revision metadata controls
       
   185   var tblholder = document.createElement('div');
       
   186   tblholder.className = 'tblholder';
       
   187   var metatable = document.createElement('table');
       
   188   metatable.setAttribute('border', '0');
       
   189   metatable.setAttribute('cellspacing', '1');
       
   190   metatable.setAttribute('cellpadding', '4');
       
   191   
       
   192   if ( readonly )
       
   193   {
       
   194     // Close Viewer button
       
   195     var tr3 = document.createElement('tr');
       
   196     var td3 = document.createElement('th');
       
   197     td3.setAttribute('colspan', '2');
       
   198     td3.className = 'subhead';
       
   199     
       
   200     var btn_cancel = document.createElement('input');
       
   201     btn_cancel.type = 'button';
       
   202     btn_cancel.value = $lang.get('editor_btn_closeviewer');
       
   203     btn_cancel.onclick = function() { ajaxReset(true); return false; };
       
   204     td3.appendChild(btn_cancel);
       
   205     tr3.appendChild(td3);
       
   206     
       
   207     metatable.appendChild(tr3);
       
   208   }
       
   209   else
       
   210   {
       
   211     // First row: edit summary
       
   212     var tr1 = document.createElement('tr');
       
   213     var td1_1 = document.createElement('td');
       
   214     var td1_2 = document.createElement('td');
       
   215     td1_1.className = 'row2';
       
   216     td1_2.className = 'row1';
       
   217     td1_2.style.width = '70%';
       
   218     td1_1.appendChild(document.createTextNode($lang.get('editor_lbl_edit_summary')));
       
   219     td1_1.appendChild(document.createElement('br'));
       
   220     var small = document.createElement('small');
       
   221     small.appendChild(document.createTextNode($lang.get('editor_lbl_edit_summary_explain')));
       
   222     td1_1.appendChild(small);
       
   223     
       
   224     var field_es = document.createElement('input');
       
   225     field_es.id = 'enano_editor_field_summary';
       
   226     field_es.type = 'text';
       
   227     field_es.size = '40';
       
   228     field_es.style.width = '96%';
       
   229     td1_2.appendChild(field_es);
       
   230     
       
   231     tr1.appendChild(td1_1);
       
   232     tr1.appendChild(td1_2);
       
   233     
       
   234     // Second row: minor edit
       
   235     var tr2 = document.createElement('tr');
       
   236     var td2_1 = document.createElement('td');
       
   237     var td2_2 = document.createElement('td');
       
   238     td2_1.className = 'row2';
       
   239     td2_2.className = 'row1';
       
   240     td2_1.appendChild(document.createTextNode($lang.get('editor_lbl_minor_edit')));
       
   241     td2_1.appendChild(document.createElement('br'));
       
   242     var small = document.createElement('small');
       
   243     small.appendChild(document.createTextNode($lang.get('editor_lbl_minor_edit_explain')));
       
   244     td2_1.appendChild(small);
       
   245     
       
   246     var label = document.createElement('label');
       
   247     var field_mi = document.createElement('input');
       
   248     field_mi.id = 'enano_editor_field_minor';
       
   249     field_mi.type = 'checkbox';
       
   250     label.appendChild(field_mi);
       
   251     label.appendChild(document.createTextNode(' '));
       
   252     label.appendChild(document.createTextNode($lang.get('editor_lbl_minor_edit_field')));
       
   253     td2_2.appendChild(label);
       
   254     
       
   255     tr2.appendChild(td2_1);
       
   256     tr2.appendChild(td2_2);
       
   257     
       
   258     // Third row: controls
       
   259     var tr3 = document.createElement('tr');
       
   260     var td3 = document.createElement('th');
       
   261     td3.setAttribute('colspan', '2');
       
   262     td3.className = 'subhead';
       
   263     
       
   264     var btn_save = document.createElement('input');
       
   265     btn_save.type = 'button';
       
   266     btn_save.value = $lang.get('editor_btn_save');
       
   267     btn_save.onclick = function() { ajaxEditorSave(); return false; };
       
   268     td3.appendChild(btn_save);
       
   269     
       
   270     td3.appendChild(document.createTextNode(' '));
       
   271     
       
   272     var btn_preview = document.createElement('input');
       
   273     btn_preview.type = 'button';
       
   274     btn_preview.value = $lang.get('editor_btn_preview');
       
   275     btn_preview.onclick = function() { ajaxEditorGenPreview(); return false; };
       
   276     td3.appendChild(btn_preview);
       
   277     
       
   278     td3.appendChild(document.createTextNode(' '));
       
   279     
       
   280     var btn_revert = document.createElement('input');
       
   281     btn_revert.type = 'button';
       
   282     btn_revert.value = $lang.get('editor_btn_revert');
       
   283     btn_revert.onclick = function() { ajaxEditorRevertToLatest(); return false; };
       
   284     td3.appendChild(btn_revert);
       
   285     
       
   286     td3.appendChild(document.createTextNode(' '));
       
   287     
       
   288     var btn_diff = document.createElement('input');
       
   289     btn_diff.type = 'button';
       
   290     btn_diff.value = $lang.get('editor_btn_diff');
       
   291     btn_diff.onclick = function() { ajaxEditorShowDiffs(); return false; };
       
   292     td3.appendChild(btn_diff);
       
   293     
       
   294     td3.appendChild(document.createTextNode(' '));
       
   295     
       
   296     var btn_cancel = document.createElement('input');
       
   297     btn_cancel.type = 'button';
       
   298     btn_cancel.value = $lang.get('editor_btn_cancel');
       
   299     btn_cancel.onclick = function() { ajaxEditorCancel(); return false; };
       
   300     td3.appendChild(btn_cancel);
       
   301     tr3.appendChild(td3);
       
   302     
       
   303     metatable.appendChild(tr1);
       
   304     metatable.appendChild(tr2);
       
   305     metatable.appendChild(tr3);
       
   306   }
       
   307   tblholder.appendChild(metatable);
       
   308   
       
   309   // Edit disclaimer/notice
       
   310   if ( editNotice ) // This is set globally in {JS_DYNAMIC_VARS}.
       
   311   {
       
   312     var en_div = document.createElement('div');
       
   313     en_div.innerHTML = editNotice;
       
   314     en_div.className = 'usermessage';
       
   315     en_div.style.margin = '10px 0 0 0';
       
   316   }
       
   317   
       
   318   // Put it all together...
       
   319   form.appendChild(toggler);
       
   320   form.appendChild(preview_anchor);
       
   321   form.appendChild(preview_container);
       
   322   form.appendChild(ta_wrapper);
       
   323   form.appendChild(tblholder);
       
   324   edcon.appendChild(form);
       
   325   
       
   326   if ( editNotice && !readonly )
       
   327   {
       
   328     edcon.appendChild(en_div);
       
   329   }
       
   330   
       
   331   // If the editor preference is tinymce, switch the editor to TinyMCE now
       
   332   if ( readCookie('enano_editor_mode') == 'tinymce' )
       
   333   {
       
   334     $dynano('ajaxEditArea').switchToMCE();
       
   335   }
       
   336 }
       
   337 
       
   338 function ajaxEditorSave()
       
   339 {
       
   340   ajaxSetEditorLoading();
       
   341   var ta_content = $('ajaxEditArea').getContent();
       
   342   var edit_summ = $('enano_editor_field_summary').object.value;
       
   343   if ( !edit_summ )
       
   344     edit_summ = '';
       
   345   var is_minor = ( $('enano_editor_field_minor').object.checked ) ? 1 : 0;
       
   346   var timestamp = $('ajaxEditArea').object._edTimestamp;
       
   347   
       
   348   var json_packet = {
       
   349     src: ta_content,
       
   350     summary: edit_summ,
       
   351     minor_edit: is_minor,
       
   352     time: timestamp
       
   353   };
       
   354   json_packet = ajaxEscape(toJSONString(json_packet));
       
   355   ajaxPost(stdAjaxPrefix + '&_mode=savepage_json', 'r=' + json_packet, function()
       
   356     {
       
   357       if ( ajax.readyState == 4 )
       
   358       {
       
   359         ajaxUnSetEditorLoading();
       
   360         var response = String(ajax.responseText + '');
       
   361         if ( response.substr(0, 1) != '{' )
       
   362         {
       
   363           handle_invalid_json(response);
       
   364           return false;
       
   365         }
       
   366         
       
   367         response = parseJSON(response);
       
   368         // This will only be used if there was a lower-level error.
       
   369         if ( response.mode == 'error' )
       
   370         {
       
   371           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
       
   372           return false;
       
   373         }
       
   374         // This will be used if the PageProcessor generated errors (usually security/permissions related)
       
   375         if ( response.mode == 'errors' )
       
   376         {
       
   377           var errors = '<ul><li>' + implode('</li><li>', response.errors) + '</li></ul>';
       
   378           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_save_title'), $lang.get('editor_err_save_body') + errors);
       
   379           return false;
       
   380         }
       
   381         // If someone else got to the page first, warn the user
       
   382         if ( response.mode == 'obsolete' )
       
   383         {
       
   384           // Update the local timestamp to allow override
       
   385           $('ajaxEditArea').object._edTimestamp = response.time;
       
   386           new messagebox(MB_OK | MB_ICONEXCLAMATION, $lang.get('editor_err_obsolete_title'), $lang.get('editor_err_obsolete_body', { author: response.author, timestamp: response.date_string, page_url: makeUrl(title, false, true) }));
       
   387           return false;
       
   388         }
       
   389         if ( response.mode == 'success' )
       
   390         {
       
   391           // The save was successful; reset flags and make another request for the new page content
       
   392           setAjaxLoading();
       
   393           editor_open = false;
       
   394           enableUnload();
       
   395           ajaxGet(stdAjaxPrefix + '&_mode=getpage&noheaders', function()
       
   396             {
       
   397               if ( ajax.readyState == 4 )
       
   398               {
       
   399                 unsetAjaxLoading();
       
   400                 document.getElementById('ajaxEditContainer').innerHTML = '<div class="usermessage">' + $lang.get('editor_msg_saved') + '</div>' + ajax.responseText;
       
   401                 selectButtonMajor('article');
       
   402                 unselectAllButtonsMinor();
       
   403               }
       
   404             });
       
   405         }
       
   406       }
       
   407     }, true);
       
   408   
       
   409 }
       
   410 
       
   411 function ajaxEditorGenPreview()
       
   412 {
       
   413   ajaxSetEditorLoading();
       
   414   var ta_content = $('ajaxEditArea').getContent();
       
   415   ta_content = ajaxEscape(ta_content);
       
   416   if ( $('enano_editor_preview').object.innerHTML != '' )
       
   417   {
       
   418     opacity('enano_editor_preview', 100, 0, 500);
       
   419   }
       
   420   ajaxPost(stdAjaxPrefix + '&_mode=preview', 'text=' + ta_content, function()
       
   421     {
       
   422       if ( ajax.readyState == 4 )
       
   423       {
       
   424         ajaxUnSetEditorLoading();
       
   425         changeOpac(0, 'enano_editor_preview');
       
   426         $('enano_editor_preview').object.innerHTML = ajax.responseText;
       
   427         window.location.hash = '#ajax_preview';
       
   428         opacity('enano_editor_preview', 0, 100, 500);
       
   429       }
       
   430     }, true);
       
   431 }
       
   432 
       
   433 function ajaxEditorRevertToLatest()
       
   434 {
       
   435   var mb = new messagebox(MB_YESNO | MB_ICONQUESTION, $lang.get('editor_msg_revert_confirm_title'), $lang.get('editor_msg_revert_confirm_body'));
       
   436   mb.onclick['Yes'] = function()
       
   437   {
       
   438     setTimeout('ajaxEditorRevertToLatestReal();', 750);
       
   439   }
       
   440 }
       
   441 
       
   442 function ajaxEditorRevertToLatestReal()
       
   443 {
       
   444   ajaxSetEditorLoading();
       
   445   ajaxGet(stdAjaxPrefix + '&_mode=getsource', function()
       
   446     {
       
   447       if ( ajax.readyState == 4 )
       
   448       {
       
   449         ajaxUnSetEditorLoading();
       
   450         
       
   451         var response = String(ajax.responseText + '');
       
   452         if ( response.substr(0, 1) != '{' )
       
   453         {
       
   454           handle_invalid_json(response);
       
   455           return false;
       
   456         }
       
   457         
       
   458         response = parseJSON(response);
       
   459         if ( response.mode == 'error' )
       
   460         {
       
   461           unselectAllButtonsMinor();
       
   462           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
       
   463           return false;
       
   464         }
       
   465         
       
   466         if ( !response.auth_view_source )
       
   467         {
       
   468           unselectAllButtonsMinor();
       
   469           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
       
   470           return false;
       
   471         }
       
   472         
       
   473         var ed = tinyMCE.get('ajaxEditArea');
       
   474         if ( ed )
       
   475         {
       
   476           ed.setContent(response.src);
       
   477         }
       
   478         else
       
   479         {
       
   480           $('ajaxEditArea').object.value = response.src;
       
   481         }
       
   482       }
       
   483     }, true);
       
   484 }
       
   485 
       
   486 function ajaxEditorShowDiffs()
       
   487 {
       
   488   ajaxSetEditorLoading();
       
   489   var ta_content = $('ajaxEditArea').getContent();
       
   490   ta_content = ajaxEscape(ta_content);
       
   491   if ( $('enano_editor_preview').object.innerHTML != '' )
       
   492   {
       
   493     opacity('enano_editor_preview', 100, 0, 500);
       
   494   }
       
   495   ajaxPost(stdAjaxPrefix + '&_mode=diff_cur', 'text=' + ta_content, function()
       
   496     {
       
   497       if ( ajax.readyState == 4 )
       
   498       {
       
   499         ajaxUnSetEditorLoading();
       
   500         changeOpac(0, 'enano_editor_preview');
       
   501         $('enano_editor_preview').object.innerHTML = ajax.responseText;
       
   502         window.location.hash = '#ajax_preview';
       
   503         opacity('enano_editor_preview', 0, 100, 500);
       
   504       }
       
   505     }, true);
       
   506 }
       
   507 
       
   508 function ajaxEditorCancel()
       
   509 {
       
   510   var mb = new messagebox(MB_YESNO | MB_ICONQUESTION, $lang.get('editor_msg_cancel_confirm_title'), $lang.get('editor_msg_cancel_confirm_body'));
       
   511   mb.onclick['Yes'] = function()
       
   512   {
       
   513     setAjaxLoading();
       
   514     editor_open = false;
       
   515     enableUnload();
       
   516     setTimeout('ajaxReset();', 750);
       
   517   }
       
   518 }
       
   519 
       
   520 function ajaxSetEditorMCE()
       
   521 {
       
   522   if ( editor_loading )
       
   523     return false;
       
   524   
       
   525   // Clear out existing buttons
       
   526   var span_wiki = $dynano('enano_edit_btn_pt').object;
       
   527   var span_mce  = $dynano('enano_edit_btn_mce').object;
       
   528   span_wiki.removeChild(span_wiki.firstChild);
       
   529   span_mce.removeChild(span_mce.firstChild);
       
   530   
       
   531   // Rebuild control
       
   532   var a = document.createElement('a');
       
   533   a.href = '#';
       
   534   a.onclick = function() {
       
   535     ajaxSetEditorPlain();
       
   536     return false;
       
   537   };
       
   538   a.appendChild(document.createTextNode($lang.get('editor_btn_wikitext')));
       
   539   span_wiki.appendChild(a);
       
   540   span_mce.appendChild(document.createTextNode($lang.get('editor_btn_graphical')));
       
   541   
       
   542   // Swap editor
       
   543   $dynano('ajaxEditArea').switchToMCE();
       
   544   
       
   545   // Remember the setting
       
   546   createCookie('enano_editor_mode', 'tinymce', 365);
       
   547 }
       
   548 
       
   549 function ajaxSetEditorPlain()
       
   550 {
       
   551   if ( editor_loading )
       
   552     return false;
       
   553   
       
   554   // Clear out existing buttons
       
   555   var span_wiki = $dynano('enano_edit_btn_pt').object;
       
   556   var span_mce  = $dynano('enano_edit_btn_mce').object;
       
   557   span_wiki.removeChild(span_wiki.firstChild);
       
   558   span_mce.removeChild(span_mce.firstChild);
       
   559   
       
   560   // Rebuild control
       
   561   span_wiki.appendChild(document.createTextNode($lang.get('editor_btn_wikitext')));
       
   562   var a = document.createElement('a');
       
   563   a.href = '#';
       
   564   a.onclick = function() {
       
   565     ajaxSetEditorMCE();
       
   566     return false;
       
   567   };
       
   568   a.appendChild(document.createTextNode($lang.get('editor_btn_graphical')));
       
   569   span_mce.appendChild(a);
       
   570   
       
   571   // Swap editor
       
   572   $dynano('ajaxEditArea').destroyMCE();
       
   573   
       
   574   // Remember the setting
       
   575   createCookie('enano_editor_mode', 'text', 365);
       
   576 }
       
   577 
       
   578 var editor_loading = false;
       
   579 
       
   580 function ajaxSetEditorLoading()
       
   581 {
       
   582   var ed = tinyMCE.get('ajaxEditArea');
       
   583   editor_loading = true;
       
   584   if ( ed )
       
   585   {
       
   586     ed.setProgressState(1);
       
   587   }
       
   588   else
       
   589   {
       
   590     ed = document.getElementById('ajaxEditArea');
       
   591     var blackout = document.createElement('div');
       
   592     blackout.style.position = 'absolute';
       
   593     blackout.style.top = $('ajaxEditArea').Top() + 'px';
       
   594     blackout.style.left = $('ajaxEditArea').Left() + 'px';
       
   595     blackout.style.width = $('ajaxEditArea').Width() + 'px';
       
   596     blackout.style.height = $('ajaxEditArea').Height() + 'px';
       
   597     blackout.style.backgroundColor = '#FFFFFF';
       
   598     domObjChangeOpac(60, blackout);
       
   599     blackout.style.backgroundImage = 'url(' + scriptPath + '/includes/clientside/tinymce/themes/advanced/skins/default/img/progress.gif)';
       
   600     blackout.style.backgroundPosition = 'center center';
       
   601     blackout.style.backgroundRepeat = 'no-repeat';
       
   602     blackout.id = 'enano_editor_blackout';
       
   603     blackout.style.zIndex = getHighestZ() + 2;
       
   604     
       
   605     var body = document.getElementsByTagName('body')[0];
       
   606     body.appendChild(blackout);
       
   607   }
       
   608 }
       
   609 
       
   610 function ajaxUnSetEditorLoading()
       
   611 {
       
   612   editor_loading = false;
       
   613   var ed = tinyMCE.get('ajaxEditArea');
       
   614   if ( ed )
       
   615   {
       
   616     ed.setProgressState(0);
       
   617   }
       
   618   else
       
   619   {
       
   620     var blackout = document.getElementById('enano_editor_blackout');
       
   621     var body = document.getElementsByTagName('body')[0];
       
   622     body.removeChild(blackout);
       
   623   }
       
   624 }
       
   625