includes/clientside/static/editor.js
changeset 420 301f546688d1
parent 419 b8b4e38825db
child 461 717e71109645
equal deleted inserted replaced
419:b8b4e38825db 420:301f546688d1
   455   textarea.used_draft = false;
   455   textarea.used_draft = false;
   456   textarea.onkeyup = function()
   456   textarea.onkeyup = function()
   457   {
   457   {
   458     if ( this.needReset )
   458     if ( this.needReset )
   459     {
   459     {
   460       var img = $('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   460       var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   461       var lbl = $('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   461       var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   462       img.src = editor_img_path + '/savedraft.gif';
   462       img.src = editor_img_path + '/savedraft.gif';
   463       lbl.innerHTML = $lang.get('editor_btn_savedraft');
   463       lbl.innerHTML = $lang.get('editor_btn_savedraft');
   464     }
   464     }
   465     if ( AutosaveTimeoutObj )
   465     if ( AutosaveTimeoutObj )
   466       clearTimeout(AutosaveTimeoutObj);
   466       clearTimeout(AutosaveTimeoutObj);
   508 
   508 
   509 function ajaxEditorSave(is_draft)
   509 function ajaxEditorSave(is_draft)
   510 {
   510 {
   511   if ( !is_draft )
   511   if ( !is_draft )
   512     ajaxSetEditorLoading();
   512     ajaxSetEditorLoading();
   513   var ta_content = $('ajaxEditArea').getContent();
   513   var ta_content = $dynano('ajaxEditArea').getContent();
   514   
   514   
   515   if ( !is_draft && ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' ) )
   515   if ( !is_draft && ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' ) )
   516   {
   516   {
   517     new messagebox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body'));
   517     new messagebox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body'));
   518     ajaxUnSetEditorLoading();
   518     ajaxUnSetEditorLoading();
   520   }
   520   }
   521   
   521   
   522   if ( is_draft )
   522   if ( is_draft )
   523   {
   523   {
   524     // ajaxSetEditorLoading();
   524     // ajaxSetEditorLoading();
   525     var img = $('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   525     var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   526     var lbl = $('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   526     var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   527     img.src = scriptPath + '/images/loading.gif';
   527     img.src = scriptPath + '/images/loading.gif';
   528     var d = new Date();
   528     var d = new Date();
   529     var m = String(d.getMinutes());
   529     var m = String(d.getMinutes());
   530     if ( m.length < 2 )
   530     if ( m.length < 2 )
   531       m = '0' + m;
   531       m = '0' + m;
   532     var time = d.getHours() + ':' + m;
   532     var time = d.getHours() + ':' + m;
   533     lbl.innerHTML = $lang.get('editor_msg_draft_saving');
   533     lbl.innerHTML = $lang.get('editor_msg_draft_saving');
   534   }
   534   }
   535   
   535   
   536   var edit_summ = $('enano_editor_field_summary').object.value;
   536   var edit_summ = $dynano('enano_editor_field_summary').object.value;
   537   if ( !edit_summ )
   537   if ( !edit_summ )
   538     edit_summ = '';
   538     edit_summ = '';
   539   var is_minor = ( $('enano_editor_field_minor').object.checked ) ? 1 : 0;
   539   var is_minor = ( $dynano('enano_editor_field_minor').object.checked ) ? 1 : 0;
   540   var timestamp = $('ajaxEditArea').object._edTimestamp;
   540   var timestamp = $dynano('ajaxEditArea').object._edTimestamp;
   541   var used_draft = $('ajaxEditArea').object.used_draft;
   541   var used_draft = $dynano('ajaxEditArea').object.used_draft;
   542   
   542   
   543   var json_packet = {
   543   var json_packet = {
   544     src: ta_content,
   544     src: ta_content,
   545     summary: edit_summ,
   545     summary: edit_summ,
   546     minor_edit: is_minor,
   546     minor_edit: is_minor,
   606         }
   606         }
   607         // If someone else got to the page first, warn the user
   607         // If someone else got to the page first, warn the user
   608         if ( response.mode == 'obsolete' )
   608         if ( response.mode == 'obsolete' )
   609         {
   609         {
   610           // Update the local timestamp to allow override
   610           // Update the local timestamp to allow override
   611           $('ajaxEditArea').object._edTimestamp = response.time;
   611           $dynano('ajaxEditArea').object._edTimestamp = response.time;
   612           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) }));
   612           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) }));
   613           return false;
   613           return false;
   614         }
   614         }
   615         if ( response.mode == 'success' )
   615         if ( response.mode == 'success' )
   616         {
   616         {
   617           if ( response.is_draft )
   617           if ( response.is_draft )
   618           {
   618           {
   619             document.getElementById('ajaxEditArea').used_draft = true;
   619             document.getElementById('ajaxEditArea').used_draft = true;
   620             document.getElementById('ajaxEditArea').needReset = true;
   620             document.getElementById('ajaxEditArea').needReset = true;
   621             var img = $('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   621             var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   622             var lbl = $('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   622             var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   623             img.src = scriptPath + '/images/mini-info.png';
   623             img.src = scriptPath + '/images/mini-info.png';
   624             var d = new Date();
   624             var d = new Date();
   625             var m = String(d.getMinutes());
   625             var m = String(d.getMinutes());
   626             if ( m.length < 2 )
   626             if ( m.length < 2 )
   627               m = '0' + m;
   627               m = '0' + m;
   655 }
   655 }
   656 
   656 
   657 function ajaxEditorGenPreview()
   657 function ajaxEditorGenPreview()
   658 {
   658 {
   659   ajaxSetEditorLoading();
   659   ajaxSetEditorLoading();
   660   var ta_content = $('ajaxEditArea').getContent();
   660   var ta_content = $dynano('ajaxEditArea').getContent();
   661   ta_content = ajaxEscape(ta_content);
   661   ta_content = ajaxEscape(ta_content);
   662   if ( $('enano_editor_preview').object.innerHTML != '' )
   662   if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   663   {
   663   {
   664     opacity('enano_editor_preview', 100, 0, 500);
   664     opacity('enano_editor_preview', 100, 0, 500);
   665   }
   665   }
   666   ajaxPost(stdAjaxPrefix + '&_mode=preview', 'text=' + ta_content, function()
   666   ajaxPost(stdAjaxPrefix + '&_mode=preview', 'text=' + ta_content, function()
   667     {
   667     {
   668       if ( ajax.readyState == 4 && ajax.status == 200 )
   668       if ( ajax.readyState == 4 && ajax.status == 200 )
   669       {
   669       {
   670         ajaxUnSetEditorLoading();
   670         ajaxUnSetEditorLoading();
   671         changeOpac(0, 'enano_editor_preview');
   671         changeOpac(0, 'enano_editor_preview');
   672         $('enano_editor_preview').object.innerHTML = ajax.responseText;
   672         $dynano('enano_editor_preview').object.innerHTML = ajax.responseText;
   673         window.location.hash = '#ajax_preview';
   673         window.location.hash = '#ajax_preview';
   674         opacity('enano_editor_preview', 0, 100, 500);
   674         opacity('enano_editor_preview', 0, 100, 500);
   675       }
   675       }
   676     }, true);
   676     }, true);
   677 }
   677 }
   714           unselectAllButtonsMinor();
   714           unselectAllButtonsMinor();
   715           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
   715           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
   716           return false;
   716           return false;
   717         }
   717         }
   718         
   718         
   719         $('ajaxEditArea').setContent(response.src);
   719         $dynano('ajaxEditArea').setContent(response.src);
   720       }
   720       }
   721     }, true);
   721     }, true);
   722 }
   722 }
   723 
   723 
   724 function ajaxEditorShowDiffs()
   724 function ajaxEditorShowDiffs()
   725 {
   725 {
   726   ajaxSetEditorLoading();
   726   ajaxSetEditorLoading();
   727   var ta_content = $('ajaxEditArea').getContent();
   727   var ta_content = $dynano('ajaxEditArea').getContent();
   728   ta_content = ajaxEscape(ta_content);
   728   ta_content = ajaxEscape(ta_content);
   729   if ( $('enano_editor_preview').object.innerHTML != '' )
   729   if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   730   {
   730   {
   731     opacity('enano_editor_preview', 100, 0, 500);
   731     opacity('enano_editor_preview', 100, 0, 500);
   732   }
   732   }
   733   ajaxPost(stdAjaxPrefix + '&_mode=diff_cur', 'text=' + ta_content, function()
   733   ajaxPost(stdAjaxPrefix + '&_mode=diff_cur', 'text=' + ta_content, function()
   734     {
   734     {
   735       if ( ajax.readyState == 4 && ajax.status == 200 )
   735       if ( ajax.readyState == 4 && ajax.status == 200 )
   736       {
   736       {
   737         ajaxUnSetEditorLoading();
   737         ajaxUnSetEditorLoading();
   738         changeOpac(0, 'enano_editor_preview');
   738         changeOpac(0, 'enano_editor_preview');
   739         $('enano_editor_preview').object.innerHTML = ajax.responseText;
   739         $dynano('enano_editor_preview').object.innerHTML = ajax.responseText;
   740         window.location.hash = '#ajax_preview';
   740         window.location.hash = '#ajax_preview';
   741         opacity('enano_editor_preview', 0, 100, 500);
   741         opacity('enano_editor_preview', 0, 100, 500);
   742       }
   742       }
   743     }, true);
   743     }, true);
   744 }
   744 }
   826   else
   826   else
   827   {
   827   {
   828     ed = document.getElementById('ajaxEditArea');
   828     ed = document.getElementById('ajaxEditArea');
   829     var blackout = document.createElement('div');
   829     var blackout = document.createElement('div');
   830     blackout.style.position = 'absolute';
   830     blackout.style.position = 'absolute';
   831     blackout.style.top = $('ajaxEditArea').Top() + 'px';
   831     blackout.style.top = $dynano('ajaxEditArea').Top() + 'px';
   832     blackout.style.left = $('ajaxEditArea').Left() + 'px';
   832     blackout.style.left = $dynano('ajaxEditArea').Left() + 'px';
   833     blackout.style.width = $('ajaxEditArea').Width() + 'px';
   833     blackout.style.width = $dynano('ajaxEditArea').Width() + 'px';
   834     blackout.style.height = $('ajaxEditArea').Height() + 'px';
   834     blackout.style.height = $dynano('ajaxEditArea').Height() + 'px';
   835     blackout.style.backgroundColor = '#FFFFFF';
   835     blackout.style.backgroundColor = '#FFFFFF';
   836     domObjChangeOpac(60, blackout);
   836     domObjChangeOpac(60, blackout);
   837     blackout.style.backgroundImage = 'url(' + scriptPath + '/includes/clientside/tinymce/themes/advanced/skins/default/img/progress.gif)';
   837     blackout.style.backgroundImage = 'url(' + scriptPath + '/includes/clientside/tinymce/themes/advanced/skins/default/img/progress.gif)';
   838     blackout.style.backgroundPosition = 'center center';
   838     blackout.style.backgroundPosition = 'center center';
   839     blackout.style.backgroundRepeat = 'no-repeat';
   839     blackout.style.backgroundRepeat = 'no-repeat';
   880   if ( !aed )
   880   if ( !aed )
   881     return false;
   881     return false;
   882   var now = unix_time();
   882   var now = unix_time();
   883   aed.as_last_save = now;
   883   aed.as_last_save = now;
   884   
   884   
   885   var ta_content = $('ajaxEditArea').getContent();
   885   var ta_content = $dynano('ajaxEditArea').getContent();
   886   
   886   
   887   if ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' )
   887   if ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' )
   888   {
   888   {
   889     return false;
   889     return false;
   890   }
   890   }
   917           unselectAllButtonsMinor();
   917           unselectAllButtonsMinor();
   918           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   918           new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   919           return false;
   919           return false;
   920         }
   920         }
   921         
   921         
   922         $('ajaxEditArea').setContent(response.src);
   922         $dynano('ajaxEditArea').setContent(response.src);
   923         $('ajaxEditArea').object.used_draft = true;
   923         $dynano('ajaxEditArea').object.used_draft = true;
   924         
   924         
   925         var es = document.getElementById('enano_editor_field_summary');
   925         var es = document.getElementById('enano_editor_field_summary');
   926         if ( es.value == '' )
   926         if ( es.value == '' )
   927         {
   927         {
   928           es.value = response.edit_summary;
   928           es.value = response.edit_summary;
   929         }
   929         }
   930         
   930         
   931         var dn = $('ajax_edit_draft_notice').object;
   931         var dn = $dynano('ajax_edit_draft_notice').object;
   932         dn.parentNode.removeChild(dn);
   932         dn.parentNode.removeChild(dn);
   933       }
   933       }
   934     }, true);
   934     }, true);
   935 }
   935 }
   936 
   936