includes/clientside/static/ajax.js
changeset 76 608dee512bf0
parent 60 71b50f8c8f85
child 78 4df25dfdde63
equal deleted inserted replaced
75:1f85c1c609fd 76:608dee512bf0
    81         <span id="switcher">' + switcher + '</span><br />\
    81         <span id="switcher">' + switcher + '</span><br />\
    82         <form name="mdgAjaxEditor" method="get" action="#" onsubmit="ajaxSavePage(); return false;">\
    82         <form name="mdgAjaxEditor" method="get" action="#" onsubmit="ajaxSavePage(); return false;">\
    83         <textarea id="ajaxEditArea" rows="20" cols="60" style="display: block; margin: 1em 0 1em 1em; width: 96.5%;">'+ajax.responseText+'</textarea><br />\
    83         <textarea id="ajaxEditArea" rows="20" cols="60" style="display: block; margin: 1em 0 1em 1em; width: 96.5%;">'+ajax.responseText+'</textarea><br />\
    84           Edit summary: <input id="ajaxEditSummary" size="40" /><br />\
    84           Edit summary: <input id="ajaxEditSummary" size="40" /><br />\
    85           <input id="ajaxEditMinor" name="minor" type="checkbox" /> <label for="ajaxEditMinor">This is a minor edit</label><br />\
    85           <input id="ajaxEditMinor" name="minor" type="checkbox" /> <label for="ajaxEditMinor">This is a minor edit</label><br />\
    86           <a href="#" onclick="void(ajaxSavePage()); return false;">save changes</a>  |  <a href="#" onclick="void(ajaxShowPreview()); return false;">preview changes</a>  |  <a href="#" onclick="void(ajaxEditor()); return false;">revert changes</a>  |  <a href="#" onclick="void(ajaxDiscard()); return false;">discard changes</a>  |  <a href="#" onclick="ajaxWikiEditHelp(); return false;">formatting help</a>\
    86           <a href="#" onclick="void(ajaxSavePage()); return false;">save changes</a>  |  <a href="#" onclick="void(ajaxShowPreview()); return false;">preview changes</a>  |  <a href="#" onclick="void(ajaxEditor()); return false;">revert changes</a>  |  <a href="#" onclick="void(ajaxDiscard()); return false;">discard changes</a>\
    87           <br />\
    87           <br />\
    88           '+editNotice+'\
    88           '+editNotice+'\
    89         </form>';
    89         </form>';
    90         // initTextareas();
    90         // initTextareas();
    91         if(readCookie('enano_editor_mode') == 'tinymce')
    91         if(readCookie('enano_editor_mode') == 'tinymce')
   758       }
   758       }
   759     }
   759     }
   760   );
   760   );
   761 }
   761 }
   762 
   762 
   763 function ajaxWikiEditHelp()
       
   764 {
       
   765   // IE <6 pseudo-compatibility
       
   766   if ( KILL_SWITCH )
       
   767     return true;
       
   768   jws.openWin('root3', 640, 480);
       
   769   setAjaxLoading();
       
   770   ajaxGet(stdAjaxPrefix+'&_mode=wikihelp', function() {
       
   771       if(ajax.readyState==4)
       
   772       {
       
   773         unsetAjaxLoading();
       
   774         document.getElementById('cn3').innerHTML = ajax.responseText;
       
   775       }
       
   776     });
       
   777 }
       
   778 
       
   779 function ajaxStartLogin()
   763 function ajaxStartLogin()
   780 {
   764 {
   781   // IE <6 pseudo-compatibility
   765   // IE <6 pseudo-compatibility
   782   if ( KILL_SWITCH )
   766   if ( KILL_SWITCH )
   783     return true;
   767     return true;
   865         }
   849         }
   866       }
   850       }
   867     });
   851     });
   868 }
   852 }
   869 
   853 
       
   854 var catHTMLBuf = false;
       
   855 
       
   856 function ajaxCatToTag()
       
   857 {
       
   858   if ( KILL_SWITCH )
       
   859     return false;
       
   860   setAjaxLoading();
       
   861   ajaxGet(stdAjaxPrefix + '&_mode=get_tags', function()
       
   862     {
       
   863       if ( ajax.readyState == 4 )
       
   864       {
       
   865         unsetAjaxLoading();
       
   866         var resptext = String(ajax.responseText + ' ');
       
   867         resptext = resptext.substr(0, resptext.length-1);
       
   868         if ( resptext.substr(0, 1) != '{' )
       
   869         {
       
   870           alert('Invalid JSON response from server:\n' + resptext);
       
   871           return false;
       
   872         }
       
   873         var json = parseJSON(resptext);
       
   874         var catbox = document.getElementById('mdgCatBox');
       
   875         if ( !catbox )
       
   876           return false;
       
   877         var linkbox = catbox.parentNode.firstChild.firstChild.nextSibling;
       
   878         linkbox.firstChild.nodeValue = 'show page categorization';
       
   879         linkbox.onclick = function() { ajaxTagToCat(); return false; };
       
   880         catHTMLBuf = catbox.innerHTML;
       
   881         catbox.innerHTML = '';
       
   882         catbox.appendChild(document.createTextNode('Page tags: '));
       
   883         if ( json.tags.length < 1 )
       
   884         {
       
   885           catbox.appendChild(document.createTextNode('No tags on this page'));
       
   886         }
       
   887         for ( var i = 0; i < json.tags.length; i++ )
       
   888         {
       
   889           catbox.appendChild(document.createTextNode(json.tags[i].name));
       
   890           if ( json.tags[i].can_del )
       
   891           {
       
   892             catbox.appendChild(document.createTextNode(' '));
       
   893             var a = document.createElement('a');
       
   894             a.appendChild(document.createTextNode('[X]'));
       
   895             a.href = '#';
       
   896             a.onclick = function() { return false; }
       
   897             catbox.appendChild(a);
       
   898           }
       
   899           if ( ( i + 1 ) < json.tags.length )
       
   900             catbox.appendChild(document.createTextNode(', '));
       
   901         }
       
   902         if ( json.can_add )
       
   903         {
       
   904           catbox.appendChild(document.createTextNode(' '));
       
   905           var addlink = document.createElement('a');
       
   906           addlink.href = '#';
       
   907           addlink.onclick = function() { try { ajaxAddTagStage1(); } catch(e) { }; return false; };
       
   908           addlink.appendChild(document.createTextNode('(add a tag)'));
       
   909           catbox.appendChild(addlink);
       
   910         }
       
   911       }
       
   912     });
       
   913 }
       
   914 
       
   915 function ajaxAddTagStage1()
       
   916 {
       
   917   var catbox = document.getElementById('mdgCatBox');
       
   918   var adddiv = document.createElement('div');
       
   919   var text = document.createElement('input');
       
   920   var addlink = document.createElement('a');
       
   921   addlink.href = '#';
       
   922   addlink.onclick = function() { return false; };
       
   923   addlink.appendChild(document.createTextNode('+ Add'));
       
   924   text.type = 'text';
       
   925   text.size = '15';
       
   926   
       
   927   adddiv.style.margin = '5px 0 0 0';
       
   928   adddiv.appendChild(document.createTextNode('Add a tag: '));
       
   929   adddiv.appendChild(text);
       
   930   adddiv.appendChild(document.createTextNode(' '));
       
   931   adddiv.appendChild(addlink);
       
   932   catbox.appendChild(adddiv);
       
   933 }
       
   934 
       
   935 function ajaxTagToCat()
       
   936 {
       
   937   if ( !catHTMLBuf )
       
   938     return false;
       
   939   var catbox = document.getElementById('mdgCatBox');
       
   940   if ( !catbox )
       
   941     return false;
       
   942   var linkbox = catbox.parentNode.firstChild.firstChild.nextSibling;
       
   943   linkbox.firstChild.nodeValue = 'show page tags';
       
   944   linkbox.onclick = function() { ajaxCatToTag(); return false; };
       
   945   catbox.innerHTML = catHTMLBuf;
       
   946   catHTMLBuf = false;
       
   947 }
       
   948