includes/clientside/static/editor.js
changeset 582 a38876c0793c
parent 572 c196e8f336b9
child 588 20484deb89cd
equal deleted inserted replaced
581:5e8fd89c02ea 582:a38876c0793c
     1 // Javascript routines for the page editor
     1 // Javascript routines for the page editor
     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 var editor_img_path = scriptPath + '/images/editor';
       
    15 
     2 
    16 // Idle time required for autosave, in seconds
     3 // Idle time required for autosave, in seconds
    17 var AUTOSAVE_TIMEOUT = 15;
     4 var AUTOSAVE_TIMEOUT = 15;
    18 var AutosaveTimeoutObj = null;
     5 var AutosaveTimeoutObj = null;
    19 var tinymce_initted = false;
     6 var editor_img_path = scriptPath + '/images/editor';
    20 
     7 
    21 var enano_tinymce_options = {
     8 window.ajaxEditor = function(revid)
    22   mode : "none",
       
    23   plugins : 'table,save,safari,pagebreak,style,layer,advhr,insertdatetime,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras' + do_popups,
       
    24   theme : 'advanced',
       
    25   skin : _skin,
       
    26   theme_advanced_resize_horizontal : false,
       
    27   theme_advanced_resizing : true,
       
    28   theme_advanced_toolbar_location : "top",
       
    29   theme_advanced_toolbar_align : "left",
       
    30   theme_advanced_buttons1 : "save,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,forecolor,backcolor,|,formatselect,|,fontselect,fontsizeselect",
       
    31   theme_advanced_buttons3_add_before : "tablecontrols,separator",
       
    32   theme_advanced_buttons3_add_after : "|,fullscreen",
       
    33   theme_advanced_statusbar_location : 'bottom',
       
    34   noneditable_noneditable_class : 'mce_readonly',
       
    35   content_css : css_url
       
    36 };
       
    37 
       
    38 var enano_tinymce_gz_options = {
       
    39 	plugins : 'table,save,safari,pagebreak,style,layer,advhr,insertdatetime,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras' + do_popups,
       
    40 	themes : 'advanced',
       
    41 	languages : 'en',
       
    42 	disk_cache : true,
       
    43 	debug : false
       
    44 };
       
    45 
       
    46 if ( !KILL_SWITCH && !DISABLE_MCE )
       
    47 {
       
    48   if ( IE )
       
    49   {
       
    50     document.write('<script type="text/javascript" src="' + scriptPath + '/includes/clientside/tinymce/tiny_mce.js"></script>');
       
    51   }
       
    52   else
       
    53   {
       
    54     var script = document.createElement('script');
       
    55     script.type="text/javascript";
       
    56     script.src=scriptPath+"/includes/clientside/tinymce/tiny_mce_gzip.js";
       
    57     script.onload = function(e)
       
    58     {
       
    59       tinyMCE_GZ.init(enano_tinymce_gz_options);
       
    60     }
       
    61     head.appendChild(script);
       
    62   }
       
    63 }
       
    64 
       
    65 // Check tinyMCE to make sure its init is finished
       
    66 function tinymce_preinit_check()
       
    67 {
       
    68   if ( typeof(tinyMCE.init) != 'function' )
       
    69     return false;
       
    70   if ( typeof(tinymce.DOM) != 'object' )
       
    71     return false;
       
    72   if ( typeof(tinymce.DOM.get) != 'function' )
       
    73     return false;
       
    74   if ( typeof(enano_tinymce_gz_options) != 'object' )
       
    75     return false;
       
    76   return true;
       
    77 }
       
    78 
       
    79 var initTinyMCE = function(e)
       
    80 {
       
    81   if ( typeof(tinyMCE) == 'object' )
       
    82   {
       
    83     if ( !KILL_SWITCH && !DISABLE_MCE )
       
    84     {
       
    85       if ( !tinymce_preinit_check() && !force )
       
    86       {
       
    87         setTimeout('initTinyMCE(false);', 200);
       
    88         return false;
       
    89       }
       
    90       tinyMCE.init(enano_tinymce_options);
       
    91       tinymce_initted = true;
       
    92     }
       
    93   }
       
    94 };
       
    95 
       
    96 // Safari doesn't fire the init on demand so call it on page load
       
    97 if ( is_Safari )
       
    98 {
       
    99   addOnloadHook(initTinyMCE);
       
   100 }
       
   101 
       
   102 var editor_open = false;
       
   103 
       
   104 function ajaxEditor(revid)
       
   105 {
     9 {
   106   if ( KILL_SWITCH )
    10   if ( KILL_SWITCH )
   107     return true;
    11     return true;
   108   if ( editor_open )
    12   if ( editor_open )
   109     return true;
    13     return true;
       
    14   load_component('l10n');
       
    15   load_component('template-compiler');
       
    16   load_component('messagebox');
   110   var rev_id_uri = ( revid ) ? '&revid=' + revid : '';
    17   var rev_id_uri = ( revid ) ? '&revid=' + revid : '';
   111   selectButtonMinor('edit');
    18   selectButtonMinor('edit');
   112   selectButtonMajor('article');
    19   selectButtonMajor('article');
   113   setAjaxLoading();
    20   setAjaxLoading();
   114   ajaxGet(stdAjaxPrefix + '&_mode=getsource' + rev_id_uri, function()
    21   ajaxGet(stdAjaxPrefix + '&_mode=getsource' + rev_id_uri, function()
   126         
    33         
   127         response = parseJSON(response);
    34         response = parseJSON(response);
   128         if ( response.mode == 'error' )
    35         if ( response.mode == 'error' )
   129         {
    36         {
   130           unselectAllButtonsMinor();
    37           unselectAllButtonsMinor();
   131           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
    38           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   132           return false;
    39           return false;
   133         }
    40         }
   134         
    41         
   135         if ( !response.auth_view_source )
    42         if ( !response.auth_view_source )
   136         {
    43         {
   137           unselectAllButtonsMinor();
    44           unselectAllButtonsMinor();
   138           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
    45           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
   139           return false;
    46           return false;
   140         }
    47         }
   141         
    48         
   142         // do we need to enter a captcha before saving the page?
    49         // do we need to enter a captcha before saving the page?
   143         var captcha_hash = ( response.require_captcha ) ? response.captcha_id : false;
    50         var captcha_hash = ( response.require_captcha ) ? response.captcha_id : false;
   145         ajaxBuildEditor((!response.auth_edit), response.time, response.allow_wysiwyg, captcha_hash, response.revid, response.undo_info, response);
    52         ajaxBuildEditor((!response.auth_edit), response.time, response.allow_wysiwyg, captcha_hash, response.revid, response.undo_info, response);
   146       }
    53       }
   147     });
    54     });
   148 }
    55 }
   149 
    56 
   150 function ajaxBuildEditor(readonly, timestamp, allow_wysiwyg, captcha_hash, revid, undo_info, response)
    57 window.ajaxBuildEditor = function(readonly, timestamp, allow_wysiwyg, captcha_hash, revid, undo_info, response)
   151 {
    58 {
   152   // Set flags
    59   // Set flags
   153   // We don't want the fancy confirmation framework to trigger if the user is only viewing the page source
    60   // We don't want the fancy confirmation framework to trigger if the user is only viewing the page source
   154   if ( !readonly )
    61   if ( !readonly )
   155   {
    62   {
   592   
   499   
   593   // Autosave every 5 minutes           (m  *  s  *  ms)
   500   // Autosave every 5 minutes           (m  *  s  *  ms)
   594   setInterval('ajaxPerformAutosave();', ( 5 * 60 * 1000 ));
   501   setInterval('ajaxPerformAutosave();', ( 5 * 60 * 1000 ));
   595 }
   502 }
   596 
   503 
   597 function ajaxEditorDestroyModalWindow()
   504 window.ajaxEditorDestroyModalWindow = function()
   598 {
   505 {
   599   if ( editor_use_modal_window )
   506   if ( editor_use_modal_window )
   600   {
   507   {
   601     var edcon = document.getElementById('ajaxEditContainerModal');
   508     var edcon = document.getElementById('ajaxEditContainerModal');
   602     var body = document.getElementsByTagName('body')[0];
   509     var body = document.getElementsByTagName('body')[0];
   606       enlighten(true);
   513       enlighten(true);
   607     }
   514     }
   608   }
   515   }
   609 }
   516 }
   610 
   517 
   611 function ajaxEditorSave(is_draft, text_override)
   518 window.ajaxEditorSave = function(is_draft, text_override)
   612 {
   519 {
   613   if ( !is_draft )
   520   if ( !is_draft )
   614     ajaxSetEditorLoading();
   521     ajaxSetEditorLoading();
   615   var ta_content = ( text_override ) ? text_override : $dynano('ajaxEditArea').getContent();
   522   var ta_content = ( text_override ) ? text_override : $dynano('ajaxEditArea').getContent();
   616   
   523   
   617   if ( !is_draft && ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' ) )
   524   if ( !is_draft && ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' ) )
   618   {
   525   {
   619     new messagebox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body'));
   526     new MessageBox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body'));
   620     ajaxUnSetEditorLoading();
   527     ajaxUnSetEditorLoading();
   621     return false;
   528     return false;
   622   }
   529   }
   623   
   530   
   624   if ( is_draft )
   531   if ( is_draft )
   655   if ( document.getElementById('enano_editor_field_captcha') && !is_draft )
   562   if ( document.getElementById('enano_editor_field_captcha') && !is_draft )
   656   {
   563   {
   657     var captcha_field = document.getElementById('enano_editor_field_captcha');
   564     var captcha_field = document.getElementById('enano_editor_field_captcha');
   658     if ( captcha_field.value == '' )
   565     if ( captcha_field.value == '' )
   659     {
   566     {
   660       new messagebox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_need_captcha_title'), $lang.get('editor_err_need_captcha_body'));
   567       new MessageBox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_need_captcha_title'), $lang.get('editor_err_need_captcha_body'));
   661       ajaxUnSetEditorLoading();
   568       ajaxUnSetEditorLoading();
   662       return false;
   569       return false;
   663     }
   570     }
   664     json_packet.captcha_code = captcha_field.value;
   571     json_packet.captcha_code = captcha_field.value;
   665     json_packet.captcha_id = captcha_field.getAttribute('enano:captcha_hash');
   572     json_packet.captcha_id = captcha_field.getAttribute('enano:captcha_hash');
   680         
   587         
   681         response = parseJSON(response);
   588         response = parseJSON(response);
   682         // This will only be used if there was a lower-level error.
   589         // This will only be used if there was a lower-level error.
   683         if ( response.mode == 'error' )
   590         if ( response.mode == 'error' )
   684         {
   591         {
   685           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   592           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   686           return false;
   593           return false;
   687         }
   594         }
   688         // This will be used if the PageProcessor generated errors (usually security/permissions related)
   595         // This will be used if the PageProcessor generated errors (usually security/permissions related)
   689         if ( response.mode == 'errors' )
   596         if ( response.mode == 'errors' )
   690         {
   597         {
   702               img.src = makeUrlNS('Special', 'Captcha/' + response.new_captcha);
   609               img.src = makeUrlNS('Special', 'Captcha/' + response.new_captcha);
   703               input.value = '';
   610               input.value = '';
   704             }
   611             }
   705           }
   612           }
   706           var errors = '<ul><li>' + implode('</li><li>', response.errors) + '</li></ul>';
   613           var errors = '<ul><li>' + implode('</li><li>', response.errors) + '</li></ul>';
   707           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_save_title'), $lang.get('editor_err_save_body') + errors);
   614           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_save_title'), $lang.get('editor_err_save_body') + errors);
   708           return false;
   615           return false;
   709         }
   616         }
   710         // If someone else got to the page first, warn the user
   617         // If someone else got to the page first, warn the user
   711         if ( response.mode == 'obsolete' )
   618         if ( response.mode == 'obsolete' )
   712         {
   619         {
   713           // Update the local timestamp to allow override
   620           // Update the local timestamp to allow override
   714           $dynano('ajaxEditArea').object._edTimestamp = response.time;
   621           $dynano('ajaxEditArea').object._edTimestamp = response.time;
   715           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) }));
   622           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) }));
   716           return false;
   623           return false;
   717         }
   624         }
   718         if ( response.mode == 'success' )
   625         if ( response.mode == 'success' )
   719         {
   626         {
   720           if ( response.is_draft )
   627           if ( response.is_draft )
   770       }
   677       }
   771     }, true);
   678     }, true);
   772 }
   679 }
   773 
   680 
   774 // Delete the draft (this is a massive server-side hack)
   681 // Delete the draft (this is a massive server-side hack)
   775 function ajaxEditorDeleteDraft()
   682 window.ajaxEditorDeleteDraft = function()
   776 {
   683 {
   777   miniPromptMessage({
   684   miniPromptMessage({
   778       title: $lang.get('editor_msg_confirm_delete_draft_title'),
   685       title: $lang.get('editor_msg_confirm_delete_draft_title'),
   779       message: $lang.get('editor_msg_confirm_delete_draft_body'),
   686       message: $lang.get('editor_msg_confirm_delete_draft_body'),
   780       buttons: [
   687       buttons: [
   797           }
   704           }
   798         ]
   705         ]
   799     });
   706     });
   800 }
   707 }
   801 
   708 
   802 function ajaxEditorDeleteDraftReal()
   709 window.ajaxEditorDeleteDraftReal = function()
   803 {
   710 {
   804   return ajaxEditorSave(true, -1);
   711   return ajaxEditorSave(true, -1);
   805 }
   712 }
   806 
   713 
   807 function ajaxEditorGenPreview()
   714 window.ajaxEditorGenPreview = function()
   808 {
   715 {
   809   ajaxSetEditorLoading();
   716   ajaxSetEditorLoading();
   810   var ta_content = $dynano('ajaxEditArea').getContent();
   717   var ta_content = $dynano('ajaxEditArea').getContent();
   811   ta_content = ajaxEscape(ta_content);
   718   ta_content = ajaxEscape(ta_content);
   812   if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   719   if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   824         opacity('enano_editor_preview', 0, 100, 500);
   731         opacity('enano_editor_preview', 0, 100, 500);
   825       }
   732       }
   826     }, true);
   733     }, true);
   827 }
   734 }
   828 
   735 
   829 function ajaxEditorRevertToLatest()
   736 window.ajaxEditorRevertToLatest = function()
   830 {
   737 {
   831   var mb = new messagebox(MB_YESNO | MB_ICONQUESTION, $lang.get('editor_msg_revert_confirm_title'), $lang.get('editor_msg_revert_confirm_body'));
   738   var mb = new MessageBox(MB_YESNO | MB_ICONQUESTION, $lang.get('editor_msg_revert_confirm_title'), $lang.get('editor_msg_revert_confirm_body'));
   832   mb.onclick['Yes'] = function()
   739   mb.onclick['Yes'] = function()
   833   {
   740   {
   834     setTimeout('ajaxEditorRevertToLatestReal();', 750);
   741     setTimeout('ajaxEditorRevertToLatestReal();', 750);
   835   }
   742   }
   836 }
   743 }
   837 
   744 
   838 function ajaxEditorRevertToLatestReal()
   745 window.ajaxEditorRevertToLatestReal = function()
   839 {
   746 {
   840   ajaxSetEditorLoading();
   747   ajaxSetEditorLoading();
   841   ajaxGet(stdAjaxPrefix + '&_mode=getsource', function()
   748   ajaxGet(stdAjaxPrefix + '&_mode=getsource', function()
   842     {
   749     {
   843       if ( ajax.readyState == 4 && ajax.status == 200 )
   750       if ( ajax.readyState == 4 && ajax.status == 200 )
   853         
   760         
   854         response = parseJSON(response);
   761         response = parseJSON(response);
   855         if ( response.mode == 'error' )
   762         if ( response.mode == 'error' )
   856         {
   763         {
   857           unselectAllButtonsMinor();
   764           unselectAllButtonsMinor();
   858           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   765           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   859           return false;
   766           return false;
   860         }
   767         }
   861         
   768         
   862         if ( !response.auth_view_source )
   769         if ( !response.auth_view_source )
   863         {
   770         {
   864           unselectAllButtonsMinor();
   771           unselectAllButtonsMinor();
   865           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
   772           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
   866           return false;
   773           return false;
   867         }
   774         }
   868         
   775         
   869         $dynano('ajaxEditArea').setContent(response.src);
   776         $dynano('ajaxEditArea').setContent(response.src);
   870       }
   777       }
   871     }, true);
   778     }, true);
   872 }
   779 }
   873 
   780 
   874 function ajaxEditorShowDiffs()
   781 window.ajaxEditorShowDiffs = function()
   875 {
   782 {
   876   ajaxSetEditorLoading();
   783   ajaxSetEditorLoading();
   877   var ta_content = $dynano('ajaxEditArea').getContent();
   784   var ta_content = $dynano('ajaxEditArea').getContent();
   878   ta_content = ajaxEscape(ta_content);
   785   ta_content = ajaxEscape(ta_content);
   879   if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   786   if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   891         opacity('enano_editor_preview', 0, 100, 500);
   798         opacity('enano_editor_preview', 0, 100, 500);
   892       }
   799       }
   893     }, true);
   800     }, true);
   894 }
   801 }
   895 
   802 
   896 function ajaxEditorCancel()
   803 window.ajaxEditorCancel = function()
   897 {
   804 {
   898   var mb = new messagebox(MB_YESNO | MB_ICONQUESTION, $lang.get('editor_msg_cancel_confirm_title'), $lang.get('editor_msg_cancel_confirm_body'));
   805   var mb = new MessageBox(MB_YESNO | MB_ICONQUESTION, $lang.get('editor_msg_cancel_confirm_title'), $lang.get('editor_msg_cancel_confirm_body'));
   899   mb.onclick['Yes'] = function()
   806   mb.onclick['Yes'] = function()
   900   {
   807   {
   901     setAjaxLoading();
   808     setAjaxLoading();
   902     ajaxEditorDestroyModalWindow();
   809     ajaxEditorDestroyModalWindow();
   903     editor_open = false;
   810     editor_open = false;
   904     enableUnload();
   811     enableUnload();
   905     setTimeout('ajaxReset();', 750);
   812     setTimeout('ajaxReset();', 750);
   906   }
   813   }
   907 }
   814 }
   908 
   815 
   909 function ajaxSetEditorMCE()
   816 window.ajaxSetEditorMCE = function()
   910 {
   817 {
   911   if ( editor_loading )
   818   if ( editor_loading )
   912     return false;
   819     return false;
   913   
   820   
   914   // Clear out existing buttons
   821   // Clear out existing buttons
   933   
   840   
   934   // Remember the setting
   841   // Remember the setting
   935   createCookie('enano_editor_mode', 'tinymce', 365);
   842   createCookie('enano_editor_mode', 'tinymce', 365);
   936 }
   843 }
   937 
   844 
   938 function ajaxSetEditorPlain()
   845 window.ajaxSetEditorPlain = function()
   939 {
   846 {
   940   if ( editor_loading )
   847   if ( editor_loading )
   941     return false;
   848     return false;
   942   
   849   
   943   // Clear out existing buttons
   850   // Clear out existing buttons
   964   createCookie('enano_editor_mode', 'text', 365);
   871   createCookie('enano_editor_mode', 'text', 365);
   965 }
   872 }
   966 
   873 
   967 var editor_loading = false;
   874 var editor_loading = false;
   968 
   875 
   969 function ajaxSetEditorLoading()
   876 window.ajaxSetEditorLoading = function()
   970 {
   877 {
   971   var ed = tinyMCE.get('ajaxEditArea');
   878   var ed = tinyMCE.get('ajaxEditArea');
   972   editor_loading = true;
   879   editor_loading = true;
   973   if ( ed )
   880   if ( ed )
   974   {
   881   {
   994     var body = document.getElementsByTagName('body')[0];
   901     var body = document.getElementsByTagName('body')[0];
   995     body.appendChild(blackout);
   902     body.appendChild(blackout);
   996   }
   903   }
   997 }
   904 }
   998 
   905 
   999 function ajaxUnSetEditorLoading()
   906 window.ajaxUnSetEditorLoading = function()
  1000 {
   907 {
  1001   editor_loading = false;
   908   editor_loading = false;
  1002   var ed = tinyMCE.get('ajaxEditArea');
   909   var ed = tinyMCE.get('ajaxEditArea');
  1003   if ( ed )
   910   if ( ed )
  1004   {
   911   {
  1010     var body = document.getElementsByTagName('body')[0];
   917     var body = document.getElementsByTagName('body')[0];
  1011     body.removeChild(blackout);
   918     body.removeChild(blackout);
  1012   }
   919   }
  1013 }
   920 }
  1014 
   921 
  1015 function ajaxAutosaveDraft()
   922 window.ajaxAutosaveDraft = function()
  1016 {
   923 {
  1017   var aed = document.getElementById('ajaxEditArea');
   924   var aed = document.getElementById('ajaxEditArea');
  1018   if ( !aed )
   925   if ( !aed )
  1019     return false;
   926     return false;
  1020   var last_save = aed.as_last_save;
   927   var last_save = aed.as_last_save;
  1023   {
   930   {
  1024     ajaxPerformAutosave();
   931     ajaxPerformAutosave();
  1025   }
   932   }
  1026 }
   933 }
  1027 
   934 
  1028 function ajaxPerformAutosave()
   935 window.ajaxPerformAutosave = function()
  1029 {
   936 {
  1030   var aed = document.getElementById('ajaxEditArea');
   937   var aed = document.getElementById('ajaxEditArea');
  1031   if ( !aed )
   938   if ( !aed )
  1032     return false;
   939     return false;
  1033   var now = unix_time();
   940   var now = unix_time();
  1041   }
   948   }
  1042   
   949   
  1043   ajaxEditorSave(true);
   950   ajaxEditorSave(true);
  1044 }
   951 }
  1045 
   952 
  1046 function ajaxEditorUseDraft()
   953 window.ajaxEditorUseDraft = function()
  1047 {
   954 {
  1048   var aed = document.getElementById('ajaxEditArea');
   955   var aed = document.getElementById('ajaxEditArea');
  1049   if ( !aed )
   956   if ( !aed )
  1050     return false;
   957     return false;
  1051   ajaxSetEditorLoading();
   958   ajaxSetEditorLoading();
  1064         
   971         
  1065         response = parseJSON(response);
   972         response = parseJSON(response);
  1066         if ( response.mode == 'error' )
   973         if ( response.mode == 'error' )
  1067         {
   974         {
  1068           unselectAllButtonsMinor();
   975           unselectAllButtonsMinor();
  1069           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   976           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
  1070           return false;
   977           return false;
  1071         }
   978         }
  1072         
   979         
  1073         $dynano('ajaxEditArea').setContent(response.src);
   980         $dynano('ajaxEditArea').setContent(response.src);
  1074         $dynano('ajaxEditArea').object.used_draft = true;
   981         $dynano('ajaxEditArea').object.used_draft = true;
  1083         dn.parentNode.removeChild(dn);
   990         dn.parentNode.removeChild(dn);
  1084       }
   991       }
  1085     }, true);
   992     }, true);
  1086 }
   993 }
  1087 
   994 
       
   995 /**
       
   996  * Equivalent of PHP's time()
       
   997  * @return int
       
   998  */
       
   999 
       
  1000 function unix_time()
       
  1001 {
       
  1002   return parseInt((new Date()).getTime()/1000);
       
  1003 }