includes/clientside/static/editor.js
changeset 832 7152ca0a0ce9
parent 823 4596c40aaa94
child 880 218b6d4de908
equal deleted inserted replaced
831:45e887f23282 832:7152ca0a0ce9
     3 // Idle time required for autosave, in seconds
     3 // Idle time required for autosave, in seconds
     4 var AUTOSAVE_TIMEOUT = 15;
     4 var AUTOSAVE_TIMEOUT = 15;
     5 var AutosaveTimeoutObj = null;
     5 var AutosaveTimeoutObj = null;
     6 var editor_img_path = cdnPath + '/images/editor';
     6 var editor_img_path = cdnPath + '/images/editor';
     7 var editor_save_lock = false;
     7 var editor_save_lock = false;
       
     8 var editor_wikitext_transform_enable = true;
     8 
     9 
     9 window.ajaxEditor = function(revid)
    10 window.ajaxEditor = function(revid)
    10 {
    11 {
    11   if ( KILL_SWITCH )
    12   if ( KILL_SWITCH )
    12     return true;
    13     return true;
    13   if ( editor_open )
    14   if ( editor_open )
    14     return true;
    15     return true;
    15   load_component(['l10n', 'template-compiler', 'messagebox']);
    16   load_component(['l10n', 'template-compiler', 'messagebox', 'fadefilter', 'flyin']);
    16   selectButtonMinor('edit');
    17   selectButtonMinor('edit');
    17   selectButtonMajor('article');
    18   selectButtonMajor('article');
    18   setAjaxLoading();
    19   setAjaxLoading();
    19   
    20   
    20   var rev_id_uri = ( revid ) ? '&revid=' + revid : '';
    21   var rev_id_uri = ( revid ) ? '&revid=' + revid : '';
   122     
   123     
   123     var span_wiki = document.createElement('span');
   124     var span_wiki = document.createElement('span');
   124     var span_mce  = document.createElement('span');
   125     var span_mce  = document.createElement('span');
   125     span_wiki.id  = 'enano_edit_btn_pt';
   126     span_wiki.id  = 'enano_edit_btn_pt';
   126     span_mce.id   = 'enano_edit_btn_mce';
   127     span_mce.id   = 'enano_edit_btn_mce';
   127     if ( readCookie('enano_editor_mode') == 'tinymce' )
   128     
       
   129     // to-wikitext button
       
   130     var a = document.createElement('a');
       
   131     a.href = '#';
       
   132     a.className = 'abutton image abutton_green';
       
   133     a.appendChild(gen_sprite(scriptPath + '/images/editor/sprite.png', 16, 16, 0, 96));
       
   134     a.appendChild(document.createTextNode(' ' + $lang.get('editor_btn_wikitext')));
       
   135     span_wiki.appendChild(a);
       
   136     toggler.appendChild(span_wiki);
       
   137     
       
   138     // to-HTML button
       
   139     var a = document.createElement('a');
       
   140     a.href = '#';
       
   141     a.className = 'abutton image abutton_blue';
       
   142     a.appendChild(gen_sprite(scriptPath + '/images/editor/sprite.png', 16, 16, 0, 112));
       
   143     a.appendChild(document.createTextNode(' ' + $lang.get('editor_btn_graphical')));
       
   144     span_mce.appendChild(a);
       
   145     toggler.appendChild(span_mce);
       
   146     
       
   147     if ( response.page_format == 'xhtml' )
   128     {
   148     {
   129       // Current selection is TinyMCE - make span_wiki have the link and span_mce be plaintext
   149       // Current selection is TinyMCE - make span_wiki have the link and span_mce be plaintext
   130       var a = document.createElement('a');
   150       span_mce.style.display = 'none';
   131       a.href = '#';
       
   132       a.appendChild(document.createTextNode($lang.get('editor_btn_wikitext')));
       
   133       span_wiki.appendChild(a);
       
   134       toggler.appendChild(span_wiki);
       
   135       toggler.appendChild(document.createTextNode(' | '));
       
   136       span_mce.appendChild(document.createTextNode($lang.get('editor_btn_graphical')));
       
   137       toggler.appendChild(span_mce);
       
   138     }
   151     }
   139     else
   152     else
   140     {
   153     {
   141       // Current selection is wikitext - set span_wiki to plaintext and span_mce to link
   154       // Current selection is wikitext - set span_wiki to plaintext and span_mce to link
   142       span_wiki.appendChild(document.createTextNode($lang.get('editor_btn_wikitext')));
   155       span_wiki.style.display = 'none';
   143       toggler.appendChild(span_wiki);
       
   144       toggler.appendChild(document.createTextNode(' | '));
       
   145       var a = document.createElement('a');
       
   146       a.href = '#';
       
   147       a.appendChild(document.createTextNode($lang.get('editor_btn_graphical')));
       
   148       span_mce.appendChild(a);
       
   149       toggler.appendChild(span_mce);
       
   150     }
   156     }
   151   }
   157   }
   152   
   158   
   153   // Form (to allow submits from MCE to trigger a real save)
   159   // Form (to allow submits from MCE to trigger a real save)
   154   var form = document.createElement('form');
   160   var form = document.createElement('form');
   221     
   227     
   222     // Button: close
   228     // Button: close
   223     button.assign_vars({
   229     button.assign_vars({
   224         TITLE: $lang.get('editor_btn_closeviewer'),
   230         TITLE: $lang.get('editor_btn_closeviewer'),
   225         IMAGE: editor_img_path + '/discard.gif',
   231         IMAGE: editor_img_path + '/discard.gif',
       
   232         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 16),
   226         FLAGS: 'href="#" onclick="ajaxReset(true); return false;"'
   233         FLAGS: 'href="#" onclick="ajaxReset(true); return false;"'
   227       });
   234       });
   228     toolbar += button.run();
   235     toolbar += button.run();
   229     toolbar += tail.run();
   236     toolbar += tail.run();
   230   }
   237   }
   341     
   348     
   342     // Button: Save
   349     // Button: Save
   343     button.assign_vars({
   350     button.assign_vars({
   344         TITLE: $lang.get('editor_btn_save'),
   351         TITLE: $lang.get('editor_btn_save'),
   345         IMAGE: editor_img_path + '/save.gif',
   352         IMAGE: editor_img_path + '/save.gif',
       
   353         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 64),
   346         FLAGS: 'href="#" onclick="ajaxEditorSave(); return false;"'
   354         FLAGS: 'href="#" onclick="ajaxEditorSave(); return false;"'
   347       });
   355       });
   348     toolbar += button.run();
   356     toolbar += button.run();
   349     
   357     
   350     // Button: preview
   358     // Button: preview
   351     button.assign_vars({
   359     button.assign_vars({
   352         TITLE: $lang.get('editor_btn_preview'),
   360         TITLE: $lang.get('editor_btn_preview'),
   353         IMAGE: editor_img_path + '/preview.gif',
   361         IMAGE: editor_img_path + '/preview.gif',
       
   362         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 32),
   354         FLAGS: 'href="#" onclick="ajaxEditorGenPreview(); return false;"'
   363         FLAGS: 'href="#" onclick="ajaxEditorGenPreview(); return false;"'
   355       });
   364       });
   356     toolbar += button.run();
   365     toolbar += button.run();
   357     
   366     
   358     // Button: revert
   367     // Button: revert
   359     button.assign_vars({
   368     button.assign_vars({
   360         TITLE: $lang.get('editor_btn_revert'),
   369         TITLE: $lang.get('editor_btn_revert'),
   361           IMAGE: editor_img_path + '/revert.gif',
   370           IMAGE: editor_img_path + '/revert.gif',
       
   371           SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 48),
   362         FLAGS: 'href="#" onclick="ajaxEditorRevertToLatest(); return false;"'
   372         FLAGS: 'href="#" onclick="ajaxEditorRevertToLatest(); return false;"'
   363       });
   373       });
   364     toolbar += button.run();
   374     toolbar += button.run();
   365     
   375     
   366     // Button: diff
   376     // Button: diff
   367     button.assign_vars({
   377     button.assign_vars({
   368         TITLE: $lang.get('editor_btn_diff'),
   378         TITLE: $lang.get('editor_btn_diff'),
   369         IMAGE: editor_img_path + '/diff.gif',
   379         IMAGE: editor_img_path + '/diff.gif',
       
   380         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 0),
   370         FLAGS: 'href="#" onclick="ajaxEditorShowDiffs(); return false;"'
   381         FLAGS: 'href="#" onclick="ajaxEditorShowDiffs(); return false;"'
   371       });
   382       });
   372     toolbar += button.run();
   383     toolbar += button.run();
   373     
   384     
   374     // Button: cancel
   385     // Button: cancel
   375     button.assign_vars({
   386     button.assign_vars({
   376         TITLE: $lang.get('editor_btn_cancel'),
   387         TITLE: $lang.get('editor_btn_cancel'),
   377         IMAGE: editor_img_path + '/discard.gif',
   388         IMAGE: editor_img_path + '/discard.gif',
       
   389         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 16),
   378         FLAGS: 'href="#" onclick="ajaxEditorCancel(); return false;"'
   390         FLAGS: 'href="#" onclick="ajaxEditorCancel(); return false;"'
   379       });
   391       });
   380     toolbar += button.run();
   392     toolbar += button.run();
   381     
   393     
   382     // Separator
   394     // Separator
   387     
   399     
   388     // Button: Save draft
   400     // Button: Save draft
   389     button.assign_vars({
   401     button.assign_vars({
   390         TITLE: $lang.get('editor_btn_savedraft'),
   402         TITLE: $lang.get('editor_btn_savedraft'),
   391         IMAGE: editor_img_path + '/savedraft.gif',
   403         IMAGE: editor_img_path + '/savedraft.gif',
       
   404         SPRITE: false,
   392         FLAGS: 'href="#" onclick="ajaxPerformAutosave(); return false;" id="ajax_edit_savedraft_btn"'
   405         FLAGS: 'href="#" onclick="ajaxPerformAutosave(); return false;" id="ajax_edit_savedraft_btn"'
   393       });
   406       });
   394     toolbar += button.run();
   407     toolbar += button.run();
   395     
   408     
   396     toolbar += tail.run();
   409     toolbar += tail.run();
   465   $dynano('ajaxEditArea').object.focus();
   478   $dynano('ajaxEditArea').object.focus();
   466   $dynano('ajaxEditArea').object._edTimestamp = timestamp;
   479   $dynano('ajaxEditArea').object._edTimestamp = timestamp;
   467   $dynano('ajaxEditArea').setContent(content);
   480   $dynano('ajaxEditArea').setContent(content);
   468   
   481   
   469   // If the editor preference is tinymce, switch the editor to TinyMCE now
   482   // If the editor preference is tinymce, switch the editor to TinyMCE now
   470   if ( readCookie('enano_editor_mode') == 'tinymce' && allow_wysiwyg )
   483   if ( response.page_format == 'xhtml' && allow_wysiwyg )
   471   {
   484   {
   472     $dynano('ajaxEditArea').switchToMCE();
   485     $dynano('ajaxEditArea').switchToMCE(false);
   473   }
   486   }
   474   
   487   
   475   if ( allow_wysiwyg )
   488   if ( allow_wysiwyg )
   476   {
   489   {
   477     if ( readCookie('enano_editor_mode') == 'tinymce' )
   490     var a = document.getElementById('enano_edit_btn_pt').getElementsByTagName('a')[0];
   478     {
   491     a.onclick = function() {
   479       var a = document.getElementById('enano_edit_btn_pt').getElementsByTagName('a')[0];
   492       ajaxSetEditorPlain();
   480       a.onclick = function() {
   493       return false;
   481         ajaxSetEditorPlain();
   494     };
   482         return false;
   495     var a = document.getElementById('enano_edit_btn_mce').getElementsByTagName('a')[0];
   483       };
   496     a.onclick = function() {
   484     }
   497       ajaxSetEditorMCE();
   485     else
   498       return false;
   486     {
   499     };
   487       var a = document.getElementById('enano_edit_btn_mce').getElementsByTagName('a')[0];
       
   488       a.onclick = function() {
       
   489         ajaxSetEditorMCE();
       
   490         return false;
       
   491       };
       
   492     }
       
   493   }
   500   }
   494   
   501   
   495   // if we're using the modal window, fade it in
   502   // if we're using the modal window, fade it in
   496   if ( editor_use_modal_window )
   503   if ( editor_use_modal_window )
   497   {
   504   {
   561     src: ta_content,
   568     src: ta_content,
   562     summary: edit_summ,
   569     summary: edit_summ,
   563     minor_edit: is_minor,
   570     minor_edit: is_minor,
   564     time: timestamp,
   571     time: timestamp,
   565     draft: ( is_draft == true ),
   572     draft: ( is_draft == true ),
       
   573     format: ( $dynano('ajaxEditArea').isMCE() ) ? 'xhtml' : 'wikitext',
   566     used_draft: used_draft
   574     used_draft: used_draft
   567   };
   575   };
   568   
   576   
   569   // Do we need to add captcha info?
   577   // Do we need to add captcha info?
   570   if ( document.getElementById('enano_editor_field_captcha') && !is_draft )
   578   if ( document.getElementById('enano_editor_field_captcha') && !is_draft )
   595         
   603         
   596         response = parseJSON(response);
   604         response = parseJSON(response);
   597         // This will only be used if there was a lower-level error.
   605         // This will only be used if there was a lower-level error.
   598         if ( response.mode == 'error' )
   606         if ( response.mode == 'error' )
   599         {
   607         {
       
   608           editor_save_lock = false;
   600           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   609           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   601           return false;
   610           return false;
   602         }
   611         }
   603         // This will be used if the PageProcessor generated errors (usually security/permissions related)
   612         // This will be used if the PageProcessor generated errors (usually security/permissions related)
   604         if ( response.mode == 'errors' )
   613         if ( response.mode == 'errors' )
   605         {
   614         {
       
   615           editor_save_lock = false;
   606           // This will be true if the user entered a captcha code incorrectly, thus
   616           // This will be true if the user entered a captcha code incorrectly, thus
   607           // invalidating the code and requiring a new image to be generated.
   617           // invalidating the code and requiring a new image to be generated.
   608           if ( response.new_captcha )
   618           if ( response.new_captcha )
   609           {
   619           {
   610             // Generate the new captcha field
   620             // Generate the new captcha field
   623           return false;
   633           return false;
   624         }
   634         }
   625         // If someone else got to the page first, warn the user
   635         // If someone else got to the page first, warn the user
   626         if ( response.mode == 'obsolete' )
   636         if ( response.mode == 'obsolete' )
   627         {
   637         {
       
   638           editor_save_lock = false;
   628           // Update the local timestamp to allow override
   639           // Update the local timestamp to allow override
   629           $dynano('ajaxEditArea').object._edTimestamp = response.time;
   640           $dynano('ajaxEditArea').object._edTimestamp = response.time;
   630           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) }));
   641           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) }));
   631           return false;
   642           return false;
   632         }
   643         }
   666             // The save was successful; reset flags and make another request for the new page content
   677             // The save was successful; reset flags and make another request for the new page content
   667             setAjaxLoading();
   678             setAjaxLoading();
   668             editor_open = false;
   679             editor_open = false;
   669             editor_save_lock = false;
   680             editor_save_lock = false;
   670             enableUnload();
   681             enableUnload();
       
   682             $dynano('ajaxEditArea').destroyMCE(false);
   671             changeOpac(0, 'ajaxEditContainer');
   683             changeOpac(0, 'ajaxEditContainer');
   672             ajaxGet(stdAjaxPrefix + '&_mode=getpage&noheaders', function(ajax)
   684             ajaxGet(stdAjaxPrefix + '&_mode=getpage&noheaders', function(ajax)
   673               {
   685               {
   674                 if ( ajax.readyState == 4 && ajax.status == 200 )
   686                 if ( ajax.readyState == 4 && ajax.status == 200 )
   675                 {
   687                 {
   749     }, true);
   761     }, true);
   750 }
   762 }
   751 
   763 
   752 window.ajaxEditorRevertToLatest = function()
   764 window.ajaxEditorRevertToLatest = function()
   753 {
   765 {
   754   var mb = new MessageBox(MB_YESNO | MB_ICONQUESTION, $lang.get('editor_msg_revert_confirm_title'), $lang.get('editor_msg_revert_confirm_body'));
   766   miniPromptMessage({
   755   mb.onclick['Yes'] = function()
   767       title: $lang.get('editor_msg_revert_confirm_title'),
   756   {
   768       message: $lang.get('editor_msg_revert_confirm_body'),
   757     setTimeout('ajaxEditorRevertToLatestReal();', 750);
   769       buttons: [
   758   }
   770         {
       
   771           text: $lang.get('editor_btn_revert_confirm'),
       
   772           color: 'red',
       
   773           sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 48 ],
       
   774           style: {
       
   775             fontWeight: 'bold'
       
   776           },
       
   777           onclick: function()
       
   778           {
       
   779             ajaxEditorRevertToLatestReal();
       
   780             miniPromptDestroy(this);
       
   781             return false;
       
   782           }
       
   783         },
       
   784         {
       
   785           text: $lang.get('etc_cancel'),
       
   786           onclick: function()
       
   787           {
       
   788             miniPromptDestroy(this);
       
   789             return false;
       
   790           }
       
   791         }
       
   792       ]
       
   793     });
   759 }
   794 }
   760 
   795 
   761 window.ajaxEditorRevertToLatestReal = function()
   796 window.ajaxEditorRevertToLatestReal = function()
   762 {
   797 {
   763   ajaxSetEditorLoading();
   798   ajaxSetEditorLoading();
   787           unselectAllButtonsMinor();
   822           unselectAllButtonsMinor();
   788           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
   823           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
   789           return false;
   824           return false;
   790         }
   825         }
   791         
   826         
   792         $dynano('ajaxEditArea').setContent(response.src);
   827         setTimeout(function()
       
   828           {
       
   829             editor_convert_if_needed(response.page_format);
       
   830             $dynano('ajaxEditArea').setContent(response.src);
       
   831           }, aclDisableTransitionFX ? 10 : 750);
   793       }
   832       }
   794     }, true);
   833     }, true);
   795 }
   834 }
   796 
   835 
   797 window.ajaxEditorShowDiffs = function()
   836 window.ajaxEditorShowDiffs = function()
   816     }, true);
   855     }, true);
   817 }
   856 }
   818 
   857 
   819 window.ajaxEditorCancel = function()
   858 window.ajaxEditorCancel = function()
   820 {
   859 {
   821   var mb = new MessageBox(MB_YESNO | MB_ICONQUESTION, $lang.get('editor_msg_cancel_confirm_title'), $lang.get('editor_msg_cancel_confirm_body'));
   860   miniPromptMessage({
   822   mb.onclick['Yes'] = function()
   861       title: $lang.get('editor_msg_cancel_confirm_title'),
   823   {
   862       message: $lang.get('editor_msg_cancel_confirm_body'),
   824     setAjaxLoading();
   863       buttons: [
   825     ajaxEditorDestroyModalWindow();
   864         {
   826     editor_open = false;
   865           text: $lang.get('editor_btn_cancel_confirm'),
   827     enableUnload();
   866           color: 'red',
   828     setTimeout('ajaxReset();', 750);
   867           sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 16 ],
   829   }
   868           style: {
   830 }
   869             fontWeight: 'bold'
   831 
   870           },
   832 window.ajaxSetEditorMCE = function()
   871           onclick: function()
       
   872           {
       
   873             setAjaxLoading();
       
   874             ajaxEditorDestroyModalWindow();
       
   875             editor_open = false;
       
   876             enableUnload();
       
   877             $dynano('ajaxEditArea').destroyMCE(false);
       
   878             ajaxReset();
       
   879             miniPromptDestroy(this);
       
   880             return false;
       
   881           }
       
   882         },
       
   883         {
       
   884           text: $lang.get('editor_btn_cancel_cancel'),
       
   885           onclick: function()
       
   886           {
       
   887             miniPromptDestroy(this);
       
   888             return false;
       
   889           }
       
   890         }
       
   891       ]
       
   892     });
       
   893 }
       
   894 
       
   895 window.ajaxSetEditorMCE = function(confirmed)
   833 {
   896 {
   834   if ( editor_loading )
   897   if ( editor_loading )
   835     return false;
   898     return false;
       
   899   
       
   900   if ( !confirmed )
       
   901   {
       
   902     miniPromptMessage({
       
   903         title: $lang.get('editor_msg_convert_confirm_title'),
       
   904         message: $lang.get('editor_msg_convert_confirm_body'),
       
   905         buttons: [
       
   906           {
       
   907             color: 'blue',
       
   908             text: $lang.get('editor_btn_graphical'),
       
   909             style: {
       
   910               fontWeight: 'bold'
       
   911             },
       
   912             sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 112 ],
       
   913             onclick: function()
       
   914             {
       
   915               ajaxSetEditorMCE(true);
       
   916               miniPromptDestroy(this);
       
   917               return false;
       
   918             }
       
   919           },
       
   920           {
       
   921             text: $lang.get('etc_cancel'),
       
   922             onclick: function()
       
   923             {
       
   924               miniPromptDestroy(this);
       
   925               return false;
       
   926             }
       
   927           }
       
   928         ]
       
   929       });
       
   930     return false;
       
   931   }
   836   
   932   
   837   // Clear out existing buttons
   933   // Clear out existing buttons
   838   var span_wiki = $dynano('enano_edit_btn_pt').object;
   934   var span_wiki = $dynano('enano_edit_btn_pt').object;
   839   var span_mce  = $dynano('enano_edit_btn_mce').object;
   935   var span_mce  = $dynano('enano_edit_btn_mce').object;
   840   span_wiki.removeChild(span_wiki.firstChild);
   936   span_wiki.style.display = 'inline';
   841   span_mce.removeChild(span_mce.firstChild);
   937   span_mce.style.display = 'none';
   842   
       
   843   // Rebuild control
       
   844   var a = document.createElement('a');
       
   845   a.href = '#';
       
   846   a.onclick = function() {
       
   847     ajaxSetEditorPlain();
       
   848     return false;
       
   849   };
       
   850   a.appendChild(document.createTextNode($lang.get('editor_btn_wikitext')));
       
   851   span_wiki.appendChild(a);
       
   852   span_mce.appendChild(document.createTextNode($lang.get('editor_btn_graphical')));
       
   853   
   938   
   854   // Swap editor
   939   // Swap editor
   855   $dynano('ajaxEditArea').switchToMCE();
   940   $dynano('ajaxEditArea').switchToMCE(true);
   856   
   941 }
   857   // Remember the setting
   942 
   858   createCookie('enano_editor_mode', 'tinymce', 365);
   943 window.ajaxSetEditorPlain = function(confirmed)
   859 }
       
   860 
       
   861 window.ajaxSetEditorPlain = function()
       
   862 {
   944 {
   863   if ( editor_loading )
   945   if ( editor_loading )
   864     return false;
   946     return false;
       
   947   
       
   948   if ( !confirmed )
       
   949   {
       
   950     miniPromptMessage({
       
   951         title: $lang.get('editor_msg_convert_confirm_title'),
       
   952         message: $lang.get('editor_msg_convert_confirm_body'),
       
   953         buttons: [
       
   954           {
       
   955             color: 'green',
       
   956             text: $lang.get('editor_btn_wikitext'),
       
   957             style: {
       
   958               fontWeight: 'bold'
       
   959             },
       
   960             sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 96 ],
       
   961             onclick: function()
       
   962             {
       
   963               ajaxSetEditorPlain(true);
       
   964               miniPromptDestroy(this);
       
   965               return false;
       
   966             }
       
   967           },
       
   968           {
       
   969             text: $lang.get('etc_cancel'),
       
   970             onclick: function()
       
   971             {
       
   972               miniPromptDestroy(this);
       
   973               return false;
       
   974             }
       
   975           }
       
   976         ]
       
   977       });
       
   978     return false;
       
   979   }
   865   
   980   
   866   // Clear out existing buttons
   981   // Clear out existing buttons
   867   var span_wiki = $dynano('enano_edit_btn_pt').object;
   982   var span_wiki = $dynano('enano_edit_btn_pt').object;
   868   var span_mce  = $dynano('enano_edit_btn_mce').object;
   983   var span_mce  = $dynano('enano_edit_btn_mce').object;
   869   span_wiki.removeChild(span_wiki.firstChild);
   984   span_wiki.style.display = 'none';
   870   span_mce.removeChild(span_mce.firstChild);
   985   span_mce.style.display = 'inline';
   871   
       
   872   // Rebuild control
       
   873   span_wiki.appendChild(document.createTextNode($lang.get('editor_btn_wikitext')));
       
   874   var a = document.createElement('a');
       
   875   a.href = '#';
       
   876   a.onclick = function() {
       
   877     ajaxSetEditorMCE();
       
   878     return false;
       
   879   };
       
   880   a.appendChild(document.createTextNode($lang.get('editor_btn_graphical')));
       
   881   span_mce.appendChild(a);
       
   882   
   986   
   883   // Swap editor
   987   // Swap editor
   884   $dynano('ajaxEditArea').destroyMCE();
   988   $dynano('ajaxEditArea').destroyMCE(true);
   885   
       
   886   // Remember the setting
       
   887   createCookie('enano_editor_mode', 'text', 365);
       
   888 }
   989 }
   889 
   990 
   890 var editor_loading = false;
   991 var editor_loading = false;
   891 
   992 
   892 window.ajaxSetEditorLoading = function()
   993 window.ajaxSetEditorLoading = function()
  1001           unselectAllButtonsMinor();
  1102           unselectAllButtonsMinor();
  1002           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
  1103           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
  1003           return false;
  1104           return false;
  1004         }
  1105         }
  1005         
  1106         
       
  1107         editor_convert_if_needed(response.page_format);
       
  1108         
  1006         $dynano('ajaxEditArea').setContent(response.src);
  1109         $dynano('ajaxEditArea').setContent(response.src);
  1007         $dynano('ajaxEditArea').object.used_draft = true;
  1110         $dynano('ajaxEditArea').object.used_draft = true;
  1008         
  1111         
  1009         var es = document.getElementById('enano_editor_field_summary');
  1112         var es = document.getElementById('enano_editor_field_summary');
  1010         if ( es.value == '' )
  1113         if ( es.value == '' )
  1016         dn.parentNode.removeChild(dn);
  1119         dn.parentNode.removeChild(dn);
  1017       }
  1120       }
  1018     }, true);
  1121     }, true);
  1019 }
  1122 }
  1020 
  1123 
       
  1124 window.editor_convert_if_needed = function(targetformat, noticetitle, noticebody)
       
  1125 {
       
  1126   // Do we need to change the format?
       
  1127   var need_to_mce = ( targetformat == 'xhtml' && !$dynano('ajaxEditArea').isMCE() );
       
  1128   var need_to_wkt = ( targetformat == 'wikitext' && $dynano('ajaxEditArea').isMCE() );
       
  1129   if ( need_to_mce )
       
  1130   {
       
  1131     $dynano('ajaxEditArea').setContent('');
       
  1132     $dynano('ajaxEditArea').switchToMCE(false);
       
  1133     
       
  1134     // Clear out existing buttons
       
  1135     var span_wiki = $dynano('enano_edit_btn_pt').object;
       
  1136     var span_mce  = $dynano('enano_edit_btn_mce').object;
       
  1137     span_wiki.style.display = 'inline';
       
  1138     span_mce.style.display = 'none';
       
  1139   }
       
  1140   else if ( need_to_wkt )
       
  1141   {
       
  1142     $dynano('ajaxEditArea').setContent('');
       
  1143     $dynano('ajaxEditArea').destroyMCE(false);
       
  1144     
       
  1145     // Clear out existing buttons
       
  1146     var span_wiki = $dynano('enano_edit_btn_pt').object;
       
  1147     var span_mce  = $dynano('enano_edit_btn_mce').object;
       
  1148     span_wiki.style.display = 'none';
       
  1149     span_mce.style.display = 'inline';
       
  1150   }
       
  1151   if ( need_to_mce || need_to_wkt )
       
  1152   {
       
  1153     // explain the conversion
       
  1154     if ( !noticetitle )
       
  1155       noticetitle = 'editor_msg_convert_draft_load_title';
       
  1156     if ( !noticebody )
       
  1157       noticebody = 'editor_msg_convert_draft_load_body';
       
  1158     
       
  1159     miniPromptMessage({
       
  1160         title: $lang.get(noticetitle),
       
  1161         message: $lang.get(noticebody),
       
  1162         buttons: [
       
  1163           {
       
  1164             text: $lang.get('etc_ok'),
       
  1165             onclick: function()
       
  1166             {
       
  1167               miniPromptDestroy(this);
       
  1168               return false;
       
  1169             }
       
  1170           }
       
  1171         ]
       
  1172       });
       
  1173   }
       
  1174 }