includes/clientside/static/editor.js
changeset 550 685e839d934e
parent 544 81b4499a963e
child 555 ac4c6a7f01d8
equal deleted inserted replaced
549:6894cfd94dfb 550:685e839d934e
    69       }
    69       }
    70       tinyMCE.init(enano_tinymce_options);
    70       tinyMCE.init(enano_tinymce_options);
    71       tinymce_initted = true;
    71       tinymce_initted = true;
    72     }
    72     }
    73   }
    73   }
    74 }
    74 };
       
    75 
    75 // Safari doesn't fire the init on demand so call it on page load
    76 // Safari doesn't fire the init on demand so call it on page load
    76 if ( is_Safari )
    77 if ( is_Safari )
    77 {
    78 {
    78   addOnloadHook(initTinyMCE);
    79   addOnloadHook(initTinyMCE);
    79 }
    80 }
   585       enlighten(true);
   586       enlighten(true);
   586     }
   587     }
   587   }
   588   }
   588 }
   589 }
   589 
   590 
   590 function ajaxEditorSave(is_draft)
   591 function ajaxEditorSave(is_draft, text_override)
   591 {
   592 {
   592   if ( !is_draft )
   593   if ( !is_draft )
   593     ajaxSetEditorLoading();
   594     ajaxSetEditorLoading();
   594   var ta_content = $dynano('ajaxEditArea').getContent();
   595   var ta_content = ( text_override ) ? text_override : $dynano('ajaxEditArea').getContent();
   595   
   596   
   596   if ( !is_draft && ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' ) )
   597   if ( !is_draft && ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' ) )
   597   {
   598   {
   598     new messagebox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body'));
   599     new messagebox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body'));
   599     ajaxUnSetEditorLoading();
   600     ajaxUnSetEditorLoading();
   699           {
   700           {
   700             document.getElementById('ajaxEditArea').used_draft = true;
   701             document.getElementById('ajaxEditArea').used_draft = true;
   701             document.getElementById('ajaxEditArea').needReset = true;
   702             document.getElementById('ajaxEditArea').needReset = true;
   702             var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   703             var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   703             var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   704             var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   704             img.src = scriptPath + '/images/mini-info.png';
   705             if ( response.is_draft == 'delete' )
   705             var d = new Date();
   706             {
   706             var m = String(d.getMinutes());
   707               img.src = scriptPath + '/images/editor/savedraft.gif';
   707             if ( m.length < 2 )
   708               lbl.innerHTML = $lang.get('editor_btn_savedraft');
   708               m = '0' + m;
   709               
   709             var time = d.getHours() + ':' + m;
   710               var dn = $dynano('ajax_edit_draft_notice').object;
   710             lbl.innerHTML = $lang.get('editor_msg_draft_saved', { time: time });
   711               if ( dn )
       
   712               {
       
   713                 dn.parentNode.removeChild(dn);
       
   714               }
       
   715             }
       
   716             else
       
   717             {
       
   718               img.src = scriptPath + '/images/mini-info.png';
       
   719               var d = new Date();
       
   720               var m = String(d.getMinutes());
       
   721               if ( m.length < 2 )
       
   722                 m = '0' + m;
       
   723               var time = d.getHours() + ':' + m;
       
   724               lbl.innerHTML = $lang.get('editor_msg_draft_saved', { time: time });
       
   725             }
   711           }
   726           }
   712           else
   727           else
   713           {
   728           {
   714             // The save was successful; reset flags and make another request for the new page content
   729             // The save was successful; reset flags and make another request for the new page content
   715             ajaxUnSetEditorLoading();
   730             ajaxUnSetEditorLoading();
   734         }
   749         }
   735       }
   750       }
   736     }, true);
   751     }, true);
   737 }
   752 }
   738 
   753 
       
   754 // Delete the draft (this is a massive server-side hack)
       
   755 function ajaxEditorDeleteDraft()
       
   756 {
       
   757   miniPromptMessage({
       
   758       title: $lang.get('editor_msg_confirm_delete_draft_title'),
       
   759       message: $lang.get('editor_msg_confirm_delete_draft_body'),
       
   760       buttons: [
       
   761           {
       
   762             text: $lang.get('editor_btn_delete_draft'),
       
   763             color: 'red',
       
   764             style: {
       
   765               fontWeight: 'bold'
       
   766             },
       
   767             onclick: function() {
       
   768               ajaxEditorDeleteDraftReal();
       
   769               miniPromptDestroy(this);
       
   770             }
       
   771           },
       
   772           {
       
   773             text: $lang.get('etc_cancel'),
       
   774             onclick: function() {
       
   775               miniPromptDestroy(this);
       
   776             }
       
   777           }
       
   778         ]
       
   779     });
       
   780 }
       
   781 
       
   782 function ajaxEditorDeleteDraftReal()
       
   783 {
       
   784   return ajaxEditorSave(true, -1);
       
   785 }
       
   786 
   739 function ajaxEditorGenPreview()
   787 function ajaxEditorGenPreview()
   740 {
   788 {
   741   ajaxSetEditorLoading();
   789   ajaxSetEditorLoading();
   742   var ta_content = $dynano('ajaxEditArea').getContent();
   790   var ta_content = $dynano('ajaxEditArea').getContent();
   743   ta_content = ajaxEscape(ta_content);
   791   ta_content = ajaxEscape(ta_content);