includes/clientside/static/editor.js
changeset 693 f21aa64d050a
parent 673 99c617146a34
child 701 dd80cde96a6c
equal deleted inserted replaced
692:78473351a6c9 693:f21aa64d050a
     1 // Javascript routines for the page editor
     1 // Javascript routines for the page editor
     2 
     2 
     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 = scriptPath + '/images/editor';
     6 var editor_img_path = cdnPath + '/images/editor';
     7 
     7 
     8 window.ajaxEditor = function(revid)
     8 window.ajaxEditor = function(revid)
     9 {
     9 {
    10   if ( KILL_SWITCH )
    10   if ( KILL_SWITCH )
    11     return true;
    11     return true;
    66   }
    66   }
    67   
    67   
    68   // Destroy existing contents of page container
    68   // Destroy existing contents of page container
    69   if ( editor_use_modal_window )
    69   if ( editor_use_modal_window )
    70   {
    70   {
    71     darken(true);
    71     darken(true, 70, 'enano_editor_darkener');
    72     // Build a div with 80% width, centered, and 10px from the top of the window
    72     // Build a div with 80% width, centered, and 10px from the top of the window
    73     var edcon = document.createElement('div');
    73     var edcon = document.createElement('div');
    74     edcon.style.position = 'absolute';
    74     edcon.style.position = 'absolute';
    75     edcon.style.backgroundColor = '#FFFFFF';
    75     edcon.style.backgroundColor = '#FFFFFF';
    76     edcon.style.padding = '10px';
    76     edcon.style.padding = '10px';
    77     edcon.style.width = '80%';
    77     edcon.style.width = '80%';
       
    78     edcon.style.zIndex = getHighestZ() + 1;
    78     edcon.id = 'ajaxEditContainerModal';
    79     edcon.id = 'ajaxEditContainerModal';
    79     
    80     
    80     // Positioning
    81     // Positioning
    81     var top = getScrollOffset() + 10;
    82     var top = getScrollOffset() + 10;
    82     var left = ( getWidth() / 10 ) - 10; // 10% of window width on either side - 10px for padding = perfect centering effect
    83     var left = ( getWidth() / 10 ) - 10; // 10% of window width on either side - 10px for padding = perfect centering effect
   449       var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   450       var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   450       var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   451       var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   451       img.src = editor_img_path + '/savedraft.gif';
   452       img.src = editor_img_path + '/savedraft.gif';
   452       lbl.innerHTML = $lang.get('editor_btn_savedraft');
   453       lbl.innerHTML = $lang.get('editor_btn_savedraft');
   453     }
   454     }
   454     if ( AutosaveTimeoutObj )
   455     if ( window.AutosaveTimeoutObj )
   455       clearTimeout(AutosaveTimeoutObj);
   456       clearTimeout(window.AutosaveTimeoutObj);
   456     AutosaveTimeoutObj = setTimeout('ajaxAutosaveDraft();', ( AUTOSAVE_TIMEOUT * 1000 ));
   457     window.AutosaveTimeoutObj = setTimeout('ajaxAutosaveDraft();', ( AUTOSAVE_TIMEOUT * 1000 ));
   457   }
   458   }
   458   
   459   
   459   if ( readonly )
   460   if ( readonly )
   460   {
   461   {
   461     textarea.className = 'mce_readonly';
   462     textarea.className = 'mce_readonly';
   509     var edcon = document.getElementById('ajaxEditContainerModal');
   510     var edcon = document.getElementById('ajaxEditContainerModal');
   510     var body = document.getElementsByTagName('body')[0];
   511     var body = document.getElementsByTagName('body')[0];
   511     if ( edcon )
   512     if ( edcon )
   512     {
   513     {
   513       body.removeChild(edcon);
   514       body.removeChild(edcon);
   514       enlighten(true);
   515       enlighten(true, 'enano_editor_darkener');
   515     }
   516     }
   516   }
   517   }
   517 }
   518 }
   518 
   519 
   519 window.ajaxEditorSave = function(is_draft, text_override)
   520 window.ajaxEditorSave = function(is_draft, text_override)
   625         }
   626         }
   626         if ( response.mode == 'success' )
   627         if ( response.mode == 'success' )
   627         {
   628         {
   628           if ( response.is_draft )
   629           if ( response.is_draft )
   629           {
   630           {
   630             // for some reason this code is throwing "uncaught exception" errors under gecko
   631             document.getElementById('ajaxEditArea').used_draft = true;
   631             // firebug ain't tracing it, it'll be fixed soon enough though
   632             document.getElementById('ajaxEditArea').needReset = true;
   632             // note that the errors still seem to show after adding the try{}catch{} blocks
   633             var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   633             try
   634             var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
       
   635             if ( response.is_draft == 'delete' )
   634             {
   636             {
   635               document.getElementById('ajaxEditArea').used_draft = true;
   637               img.src = scriptPath + '/images/editor/savedraft.gif';
   636               document.getElementById('ajaxEditArea').needReset = true;
   638               lbl.innerHTML = $lang.get('editor_btn_savedraft');
   637               var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   639               
   638               var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   640               var dn = $dynano('ajax_edit_draft_notice').object;
   639               if ( response.is_draft == 'delete' )
   641               if ( dn )
   640               {
   642               {
   641                 img.src = scriptPath + '/images/editor/savedraft.gif';
   643                 dn.parentNode.removeChild(dn);
   642                 lbl.innerHTML = $lang.get('editor_btn_savedraft');
       
   643                 
       
   644                 var dn = $dynano('ajax_edit_draft_notice').object;
       
   645                 if ( dn )
       
   646                 {
       
   647                   dn.parentNode.removeChild(dn);
       
   648                 }
       
   649               }
       
   650               else
       
   651               {
       
   652                 img.src = scriptPath + '/images/mini-info.png';
       
   653                 var d = new Date();
       
   654                 var m = String(d.getMinutes());
       
   655                 if ( m.length < 2 )
       
   656                   m = '0' + m;
       
   657                 var time = d.getHours() + ':' + m;
       
   658                 lbl.innerHTML = $lang.get('editor_msg_draft_saved', { time: time });
       
   659               }
   644               }
   660             }
   645             }
   661             catch(e)
   646             else
   662             {
   647             {
   663               console.warn('Exception thrown during save, error dump follows');
   648               img.src = scriptPath + '/images/mini-info.png';
   664               console.debug(e);
   649               var d = new Date();
       
   650               var m = String(d.getMinutes());
       
   651               if ( m.length < 2 )
       
   652                 m = '0' + m;
       
   653               var time = d.getHours() + ':' + m;
       
   654               lbl.innerHTML = $lang.get('editor_msg_draft_saved', { time: time });
   665             }
   655             }
   666           }
   656           }
   667           else
   657           else
   668           {
   658           {
   669             // The save was successful; reset flags and make another request for the new page content
   659             // The save was successful; reset flags and make another request for the new page content
   939   }
   929   }
   940   else
   930   else
   941   {
   931   {
   942     var blackout = document.getElementById('enano_editor_blackout');
   932     var blackout = document.getElementById('enano_editor_blackout');
   943     var body = document.getElementsByTagName('body')[0];
   933     var body = document.getElementsByTagName('body')[0];
       
   934     if ( !blackout )
       
   935       return false;
   944     body.removeChild(blackout);
   936     body.removeChild(blackout);
   945   }
   937   }
   946 }
   938 }
   947 
   939 
   948 window.ajaxAutosaveDraft = function()
   940 window.ajaxAutosaveDraft = function()