includes/clientside/static/ajax.js
changeset 335 67bd3121a12e
parent 329 0437a7cf1acc
child 343 eefe9ab7fe7c
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
     1 /*
     1 /*
     2  * AJAX applets
     2  * AJAX applets
     3  */
     3  */
     4  
     4  
     5 function ajaxGet(uri, f) {
     5 function ajaxGet(uri, f, call_editor_safe) {
       
     6   // Is the editor open?
       
     7   if ( editor_open && !call_editor_safe )
       
     8   {
       
     9     // Make sure the user is willing to close the editor
       
    10     var conf = confirm($lang.get('editor_msg_confirm_ajax'));
       
    11     if ( !conf )
       
    12     {
       
    13       // Kill off any "loading" windows, etc. and cancel the request
       
    14       unsetAjaxLoading();
       
    15       return false;
       
    16     }
       
    17     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
       
    18     editor_open = false;
       
    19     enableUnload();
       
    20   }
     6   if (window.XMLHttpRequest) {
    21   if (window.XMLHttpRequest) {
     7     ajax = new XMLHttpRequest();
    22     ajax = new XMLHttpRequest();
     8   } else {
    23   } else {
     9     if (window.ActiveXObject) {           
    24     if (window.ActiveXObject) {           
    10       ajax = new ActiveXObject("Microsoft.XMLHTTP");
    25       ajax = new ActiveXObject("Microsoft.XMLHTTP");
    17   ajax.open('GET', uri, true);
    32   ajax.open('GET', uri, true);
    18   ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
    33   ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
    19   ajax.send(null);
    34   ajax.send(null);
    20 }
    35 }
    21 
    36 
    22 function ajaxPost(uri, parms, f) {
    37 function ajaxPost(uri, parms, f, call_editor_safe) {
       
    38   // Is the editor open?
       
    39   if ( editor_open && !call_editor_safe )
       
    40   {
       
    41     // Make sure the user is willing to close the editor
       
    42     var conf = confirm($lang.get('editor_msg_confirm_ajax'));
       
    43     if ( !conf )
       
    44     {
       
    45       // Kill off any "loading" windows, etc. and cancel the request
       
    46       unsetAjaxLoading();
       
    47       return false;
       
    48     }
       
    49     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
       
    50     editor_open = false;
       
    51     enableUnload();
       
    52   }
    23   if (window.XMLHttpRequest) {
    53   if (window.XMLHttpRequest) {
    24     ajax = new XMLHttpRequest();
    54     ajax = new XMLHttpRequest();
    25   } else {
    55   } else {
    26     if (window.ActiveXObject) {           
    56     if (window.ActiveXObject) {           
    27       ajax = new ActiveXObject("Microsoft.XMLHTTP");
    57       ajax = new ActiveXObject("Microsoft.XMLHTTP");
   132   text = escape(text);
   162   text = escape(text);
   133   text = text.replace(/\+/g, '%2B', text);
   163   text = text.replace(/\+/g, '%2B', text);
   134   return text;
   164   return text;
   135 }
   165 }
   136 
   166 
   137 // Page editor
       
   138 
       
   139 function ajaxEditor()
       
   140 {
       
   141   // IE <6 pseudo-compatibility
       
   142   if ( KILL_SWITCH )
       
   143     return true;
       
   144   setAjaxLoading();
       
   145   ajaxGet(stdAjaxPrefix+'&_mode=getsource', function() {
       
   146       if(ajax.readyState == 4) {
       
   147         unsetAjaxLoading();
       
   148         if(edit_open) {
       
   149           c=confirm($lang.get('editor_msg_revert_confirm'));
       
   150           if(!c) return;
       
   151         }
       
   152         edit_open = true;
       
   153         selectButtonMajor('article');
       
   154         selectButtonMinor('edit');
       
   155         if(in_array('ajaxEditArea', grippied_textareas))
       
   156         {
       
   157           // Allow the textarea grippifier to re-create the resizer control on the textarea
       
   158           grippied_textareas.pop(in_array('ajaxEditArea', grippied_textareas));
       
   159         }
       
   160         disableUnload($lang.get('editor_msg_unload'));
       
   161         var switcher = ( readCookie('enano_editor_mode') == 'tinymce' ) ?
       
   162                         '<a href="#" onclick="setEditorText(); return false;">' + $lang.get('editor_btn_wikitext') + '</a>  |  ' + $lang.get('editor_btn_graphical') :
       
   163                         $lang.get('editor_btn_wikitext') + '  |  <a href="#" onclick="setEditorMCE(); return false;">' + $lang.get('editor_btn_graphical') + '</a>' ;
       
   164         document.getElementById('ajaxEditContainer').innerHTML = '\
       
   165         <div id="mdgPreviewContainer"></div> \
       
   166         <span id="switcher">' + switcher + '</span><br />\
       
   167         <form name="mdgAjaxEditor" method="get" action="#" onsubmit="ajaxSavePage(); return false;">\
       
   168         <textarea id="ajaxEditArea" rows="20" cols="60" style="display: block; margin: 1em 0 1em 1em; width: 96.5%;">'+ajax.responseText+'</textarea><br />\
       
   169           ' + $lang.get('editor_lbl_edit_summary') + ' <input id="ajaxEditSummary" size="40" /><br />\
       
   170           <input id="ajaxEditMinor" name="minor" type="checkbox" /> <label for="ajaxEditMinor">' + $lang.get('editor_lbl_minor_edit') + '</label><br />\
       
   171           <a href="#" onclick="void(ajaxSavePage()); return false;">' + $lang.get('editor_btn_save') + '</a>  |  <a href="#" onclick="void(ajaxShowPreview()); return false;">' + $lang.get('editor_btn_preview') + '</a>  |  <a href="#" onclick="void(ajaxEditor()); return false;">' + $lang.get('editor_btn_revert') + '</a>  |  <a href="#" onclick="void(ajaxDiscard()); return false;">' + $lang.get('editor_btn_cancel') + '</a>\
       
   172           <br />\
       
   173           '+editNotice+'\
       
   174         </form>';
       
   175         // initTextareas();
       
   176         if(readCookie('enano_editor_mode') == 'tinymce')
       
   177         {
       
   178           $('ajaxEditArea').switchToMCE();
       
   179         }
       
   180       }
       
   181   });
       
   182 }
       
   183 
       
   184 function setEditorMCE()
       
   185 {
       
   186   $('ajaxEditArea').switchToMCE();
       
   187   createCookie('enano_editor_mode', 'tinymce', 365);
       
   188   $('switcher').object.innerHTML = '<a href="#" onclick="setEditorText(); return false;">' + $lang.get('editor_btn_wikitext') + '</a>  |  ' + $lang.get('editor_btn_graphical');
       
   189 }
       
   190 
       
   191 function setEditorText()
       
   192 {
       
   193   $('ajaxEditArea').destroyMCE();
       
   194   createCookie('enano_editor_mode', 'text', 365);
       
   195   $('switcher').object.innerHTML = $lang.get('editor_btn_wikitext') + '  |  <a href="#" onclick="setEditorMCE(); return false;">' + $lang.get('editor_btn_graphical') + '</a>';
       
   196 }
       
   197 
       
   198 function ajaxViewSource()
       
   199 {
       
   200   // IE <6 pseudo-compatibility
       
   201   if ( KILL_SWITCH )
       
   202     return true;
       
   203   setAjaxLoading();
       
   204   ajaxGet(stdAjaxPrefix+'&_mode=getsource', function() {
       
   205       if(ajax.readyState == 4) {
       
   206         unsetAjaxLoading();
       
   207         edit_open = false;
       
   208         selectButtonMajor('article');
       
   209         selectButtonMinor('edit');
       
   210         if(in_array('ajaxEditArea', grippied_textareas))
       
   211         {
       
   212           // Allow the textarea grippifier to re-create the resizer control on the textarea
       
   213           grippied_textareas.pop(in_array('ajaxEditArea', grippied_textareas));
       
   214         }
       
   215         document.getElementById('ajaxEditContainer').innerHTML = '\
       
   216           <form method="get" action="#" onsubmit="ajaxSavePage(); return false;">\
       
   217             <textarea readonly="readonly" id="ajaxEditArea" rows="20" cols="60" style="display: block; margin: 1em 0 1em 1em; width: 96.5%;">'+ajax.responseText+'</textarea><br />\
       
   218             <a href="#" onclick="void(ajaxReset()); return false;">' + $lang.get('editor_btn_closeviewer') + '</a>\
       
   219           </form>';
       
   220         initTextareas();
       
   221       }
       
   222   });
       
   223 }
       
   224 
       
   225 function ajaxShowPreview()
       
   226 {
       
   227   // IE <6 pseudo-compatibility
       
   228   if ( KILL_SWITCH )
       
   229     return true;
       
   230   goBusy('Loading preview...');
       
   231   var text = ajaxEscape($('ajaxEditArea').getContent());
       
   232   if(document.mdgAjaxEditor.minor.checked) minor='&minor';
       
   233   else minor='';
       
   234   ajaxPost(stdAjaxPrefix+'&_mode=preview', 'summary='+document.getElementById('ajaxEditSummary').value+minor+'&text='+text, function() {
       
   235     if(ajax.readyState == 4) {
       
   236       unBusy();
       
   237       edit_open = false;
       
   238       document.getElementById('mdgPreviewContainer').innerHTML = ajax.responseText;
       
   239     }
       
   240   });
       
   241 }
       
   242 
       
   243 function ajaxSavePage()
       
   244 {
       
   245   // IE <6 pseudo-compatibility
       
   246   if ( KILL_SWITCH )
       
   247     return true;
       
   248   //goBusy('Saving page...');
       
   249   var text = ajaxEscape($('ajaxEditArea').getContent());
       
   250   if(document.mdgAjaxEditor.minor.checked) minor='&minor';
       
   251   else minor='';
       
   252   ajaxPost(stdAjaxPrefix+'&_mode=savepage', 'summary='+document.getElementById('ajaxEditSummary').value+minor+'&text='+text, function() {
       
   253     if(ajax.readyState == 4) {
       
   254       unBusy();
       
   255       edit_open = false;
       
   256       document.getElementById('ajaxEditContainer').innerHTML = ajax.responseText;
       
   257       enableUnload();
       
   258       unselectAllButtonsMinor();
       
   259     }
       
   260   });
       
   261 }
       
   262 
       
   263 function ajaxDiscard()
   167 function ajaxDiscard()
   264 {
   168 {
   265   // IE <6 pseudo-compatibility
   169   // IE <6 pseudo-compatibility
   266   if ( KILL_SWITCH )
   170   if ( KILL_SWITCH )
   267     return true;
   171     return true;
   281   enableUnload();
   185   enableUnload();
   282   setAjaxLoading();
   186   setAjaxLoading();
   283   ajaxGet(stdAjaxPrefix+'&_mode=getpage&noheaders', function() {
   187   ajaxGet(stdAjaxPrefix+'&_mode=getpage&noheaders', function() {
   284     if(ajax.readyState == 4) {
   188     if(ajax.readyState == 4) {
   285       unsetAjaxLoading();
   189       unsetAjaxLoading();
   286       edit_open = false;
       
   287       document.getElementById('ajaxEditContainer').innerHTML = ajax.responseText;
   190       document.getElementById('ajaxEditContainer').innerHTML = ajax.responseText;
   288       selectButtonMajor('article');
   191       selectButtonMajor('article');
   289       unselectAllButtonsMinor();
   192       unselectAllButtonsMinor();
   290     }
   193     }
   291   });
   194   });
   312     if(ajax.readyState == 4) {
   215     if(ajax.readyState == 4) {
   313       unsetAjaxLoading();
   216       unsetAjaxLoading();
   314       if(ajax.responseText != 'good')
   217       if(ajax.responseText != 'good')
   315         alert(ajax.responseText);
   218         alert(ajax.responseText);
   316     }
   219     }
   317   });
   220   }, true);
   318 }
   221 }
   319 
   222 
   320 function ajaxRename()
   223 function ajaxRename()
   321 {
   224 {
   322   // IE <6 pseudo-compatibility
   225   // IE <6 pseudo-compatibility
   328   ajaxPost(stdAjaxPrefix+'&_mode=rename', 'newtitle='+ajaxEscape(r), function() {
   231   ajaxPost(stdAjaxPrefix+'&_mode=rename', 'newtitle='+ajaxEscape(r), function() {
   329     if(ajax.readyState == 4) {
   232     if(ajax.readyState == 4) {
   330       unsetAjaxLoading();
   233       unsetAjaxLoading();
   331       alert(ajax.responseText);
   234       alert(ajax.responseText);
   332     }
   235     }
   333   });
   236   }, true);
   334 }
   237 }
   335 
   238 
   336 function ajaxMakePage()
   239 function ajaxMakePage()
   337 {
   240 {
   338   // IE <6 pseudo-compatibility
   241   // IE <6 pseudo-compatibility
   383   ajaxGet(stdAjaxPrefix+'&_mode=delvote', function() {
   286   ajaxGet(stdAjaxPrefix+'&_mode=delvote', function() {
   384     if(ajax.readyState == 4) {
   287     if(ajax.readyState == 4) {
   385       unsetAjaxLoading();
   288       unsetAjaxLoading();
   386       alert(ajax.responseText);
   289       alert(ajax.responseText);
   387     }
   290     }
   388   });
   291   }, true);
   389 }
   292 }
   390 
   293 
   391 function ajaxResetDelVotes()
   294 function ajaxResetDelVotes()
   392 {
   295 {
   393   // IE <6 pseudo-compatibility
   296   // IE <6 pseudo-compatibility
   405       {
   308       {
   406         opacity('mdgDeleteVoteNoticeBox', 100, 0, 1000);
   309         opacity('mdgDeleteVoteNoticeBox', 100, 0, 1000);
   407         setTimeout("document.getElementById('mdgDeleteVoteNoticeBox').style.display = 'none';", 1000);
   310         setTimeout("document.getElementById('mdgDeleteVoteNoticeBox').style.display = 'none';", 1000);
   408       }
   311       }
   409     }
   312     }
   410   });
   313   }, true);
   411 }
   314 }
   412 
   315 
   413 function ajaxSetWikiMode(val) {
   316 function ajaxSetWikiMode(val) {
   414   // IE <6 pseudo-compatibility
   317   // IE <6 pseudo-compatibility
   415   if ( KILL_SWITCH )
   318   if ( KILL_SWITCH )
   703         var kid = div.firstChild.nextSibling;
   606         var kid = div.firstChild.nextSibling;
   704         
   607         
   705         kid.appendChild(p_parent);
   608         kid.appendChild(p_parent);
   706         
   609         
   707       }
   610       }
   708     });
   611     }, true);
   709 }
   612 }
   710 
   613 
   711 function ajaxChangeStyleComplete()
   614 function ajaxChangeStyleComplete()
   712 {
   615 {
   713   // IE <6 pseudo-compatibility
   616   // IE <6 pseudo-compatibility
   748         else
   651         else
   749         {
   652         {
   750           alert('Error occurred during attempt to change theme:\n' + ajax.responseText);
   653           alert('Error occurred during attempt to change theme:\n' + ajax.responseText);
   751         }
   654         }
   752       }
   655       }
   753     });
   656     }, true);
   754   
   657   
   755   return false;
   658   return false;
   756   
   659   
   757 }
   660 }
   758 
   661 
   838       unsetAjaxLoading();
   741       unsetAjaxLoading();
   839       if(ajax.readyState==4)
   742       if(ajax.readyState==4)
   840       {
   743       {
   841         alert(ajax.responseText);
   744         alert(ajax.responseText);
   842       }
   745       }
   843     }
   746     }, true);
   844   );
       
   845 }
   747 }
   846 
   748 
   847 function ajaxStartLogin()
   749 function ajaxStartLogin()
   848 {
   750 {
   849   // IE <6 pseudo-compatibility
   751   // IE <6 pseudo-compatibility
  1313           return false;
  1215           return false;
  1314         }
  1216         }
  1315         if ( ajax.responseXML.firstChild.tagName == 'enano' )
  1217         if ( ajax.responseXML.firstChild.tagName == 'enano' )
  1316         {
  1218         {
  1317           var enanotag = ajax.responseXML.firstChild;
  1219           var enanotag = ajax.responseXML.firstChild;
  1318           for ( var i in enanotag.childNodes )
  1220           for ( var i = 0; i < enanotag.childNodes.length; i++ )
  1319           {
  1221           {
  1320             if ( enanotag.childNodes[i].tagName == 'error' )
  1222             if ( enanotag.childNodes[i].tagName == 'error' )
  1321             {
  1223             {
  1322               alert(enanotag.childNodes[i].firstChild.nodeValue);
  1224               alert(enanotag.childNodes[i].firstChild.nodeValue);
  1323             }
  1225             }
  1324             else if ( enanotag.childNodes[i].tagName == 'latest' )
  1226             else if ( enanotag.childNodes[i].tagName == 'latest' )
  1325             {
  1227             {
  1326               // got <latest>
  1228               // got <latest>
  1327               var latesttag = enanotag.childNodes[i];
  1229               var latesttag = enanotag.childNodes[i];
  1328               for ( var i in latesttag.childNodes )
  1230               for ( var i = 0; i < latesttag.childNodes.length; i++ )
  1329               {
  1231               {
  1330                 var node = latesttag.childNodes[i];
  1232                 var node = latesttag.childNodes[i];
  1331                 if ( node.tagName == 'release' )
  1233                 if ( node.tagName == 'release' )
  1332                 {
  1234                 {
  1333                   var releasedata = new Object();
  1235                   var releasedata = new Object();
  1334                   for ( var i in node.attributes )
  1236                   for ( var i = 0; i < node.attributes.length; i++ )
  1335                   {
  1237                   {
  1336                     releasedata[node.attributes[i].nodeName] = node.attributes[i].nodeValue;
  1238                     releasedata[node.attributes[i].nodeName] = node.attributes[i].nodeValue;
  1337                   }
  1239                   }
  1338                   releases.push(releasedata);
  1240                   releases.push(releasedata);
  1339                 }
  1241                 }
  1365           thediv.className = 'tblholder';
  1267           thediv.className = 'tblholder';
  1366           if ( update_available )
  1268           if ( update_available )
  1367           {
  1269           {
  1368             var infobox = document.createElement('div');
  1270             var infobox = document.createElement('div');
  1369             infobox.className = 'info-box-mini';
  1271             infobox.className = 'info-box-mini';
  1370             infobox.appendChild(document.createTextNode('An update for Enano is available.'));
  1272             infobox.appendChild(document.createTextNode('An update for Enano is available. The newest release is highlighted below.'));
  1371             infobox.style.borderWidth = '0';
  1273             infobox.style.borderWidth = '0';
  1372             infobox.style.margin = '0 0 0 0';
  1274             infobox.style.margin = '0 0 0 0';
  1373             thediv.appendChild(infobox);
  1275             thediv.appendChild(infobox);
  1374           }
  1276           }
  1375           else
  1277           else
  1376           {
  1278           {
  1377             var infobox = document.createElement('div');
  1279             var infobox = document.createElement('div');
  1378             infobox.className = 'info-box-mini';
  1280             infobox.className = 'info-box-mini';
  1379             infobox.appendChild(document.createTextNode('No new updates are available.'));
  1281             infobox.appendChild(document.createTextNode('No new updates are available. The latest available releases are shown below.'));
  1380             infobox.style.borderWidth = '0';
  1282             infobox.style.borderWidth = '0';
  1381             infobox.style.margin = '0 0 0 0';
  1283             infobox.style.margin = '0 0 0 0';
  1382             thediv.appendChild(infobox);
  1284             thediv.appendChild(infobox);
  1383           }
  1285           }
  1384           var table = document.createElement('table');
  1286           var table = document.createElement('table');