includes/clientside/static/misc.js
changeset 326 ab66d6d1f1f4
parent 304 e2cb5f1432c8
parent 320 112debff64bd
child 334 c72b545f1304
equal deleted inserted replaced
314:474f8be55943 326:ab66d6d1f1f4
   400       if ( ajax.readyState == 4 )
   400       if ( ajax.readyState == 4 )
   401       {
   401       {
   402         var response = String(ajax.responseText);
   402         var response = String(ajax.responseText);
   403         if ( response.substr(0,1) != '{' )
   403         if ( response.substr(0,1) != '{' )
   404         {
   404         {
   405           alert('Invalid JSON response from server: ' + response);
   405           handle_invalid_json(response);
       
   406           ajax_auth_mb_cache.destroy();
   406           return false;
   407           return false;
   407         }
   408         }
   408         response = parseJSON(response);
   409         response = parseJSON(response);
   409         var disable_controls = false;
   410         var disable_controls = false;
   410         if ( response.locked_out && !ajax_auth_error_string )
   411         if ( response.locked_out && !ajax_auth_error_string )
   445          {
   446          {
   446            var captcha_html = '';
   447            var captcha_html = '';
   447          }
   448          }
   448          var disableme = ( disable_controls ) ? 'disabled="disabled" ' : '';
   449          var disableme = ( disable_controls ) ? 'disabled="disabled" ' : '';
   449         form_html += ' \
   450         form_html += ' \
   450           <table border="0" align="center"> \
   451           <form action="#" onsubmit="ajaxValidateLogin(); return false;" name="ajax_login_form"> \
   451             <tr> \
   452             <table border="0" align="center"> \
   452               <td>' + $lang.get('user_login_field_username') + ':</td><td><input tabindex="1" id="ajaxlogin_user" type="text"     ' + disableme + 'size="25" /> \
   453               <tr> \
   453             </tr> \
   454                 <td>' + $lang.get('user_login_field_username') + ':</td><td><input tabindex="1" id="ajaxlogin_user" type="text"     ' + disableme + 'size="25" /> \
   454             <tr> \
   455               </tr> \
   455               <td>' + $lang.get('user_login_field_password') + ':</td><td><input tabindex="2" id="ajaxlogin_pass" type="password" ' + disableme + 'size="25" /> \
   456               <tr> \
   456             </tr> \
   457                 <td>' + $lang.get('user_login_field_password') + ':</td><td><input tabindex="2" id="ajaxlogin_pass" type="password" ' + disableme + 'size="25" /> \
   457             ' + captcha_html + ' \
   458               </tr> \
   458             <tr> \
   459               ' + captcha_html + ' \
   459               <td colspan="2" style="text-align: center;"> \
   460               <tr> \
       
   461                 <td colspan="2" style="text-align: center;"> \
   460                 <small>' + $lang.get('user_login_ajax_link_fullform', { link_full_form: makeUrlNS('Special', 'Login/' + title, 'level=' + level) }) + '<br />';
   462                 <small>' + $lang.get('user_login_ajax_link_fullform', { link_full_form: makeUrlNS('Special', 'Login/' + title, 'level=' + level) }) + '<br />';
   461        if ( level <= USER_LEVEL_MEMBER )
   463        if ( level <= USER_LEVEL_MEMBER )
   462        {
   464        {
   463          form_html += ' \
   465          form_html += ' \
   464                 ' + $lang.get('user_login_ajax_link_forgotpass', { forgotpass_link: makeUrlNS('Special', 'PasswordReset') }) + '<br /> \
   466                   ' + $lang.get('user_login_ajax_link_forgotpass', { forgotpass_link: makeUrlNS('Special', 'PasswordReset') }) + '<br /> \
   465                 ' + $lang.get('user_login_createaccount_blurb', { reg_link: makeUrlNS('Special', 'Register') });
   467                   ' + $lang.get('user_login_createaccount_blurb', { reg_link: makeUrlNS('Special', 'Register') });
   466        }
   468        }
   467        form_html += '</small> \
   469        form_html += '</small> \
   468               </td> \
   470                 </td> \
   469             </tr> \
   471               </tr> \
   470           </table> \
   472             </table> \
   471           <input type="hidden" id="ajaxlogin_crypt_key"       value="' + response.key + '" /> \
   473             <input type="hidden" id="ajaxlogin_crypt_key"       value="' + response.key + '" /> \
   472           <input type="hidden" id="ajaxlogin_crypt_challenge" value="' + response.challenge + '" /> \
   474             <input type="hidden" id="ajaxlogin_crypt_challenge" value="' + response.challenge + '" /> \
   473         </form>';
   475           </form>';
   474         ajax_auth_mb_cache.updateContent(form_html);
   476         ajax_auth_mb_cache.updateContent(form_html);
   475         $('messageBox').object.nextSibling.firstChild.tabindex = '3';
   477         $('messageBox').object.nextSibling.firstChild.tabindex = '3';
   476         if ( typeof(response.username) == 'string' )
   478         if ( typeof(response.username) == 'string' )
   477         {
   479         {
   478           $('ajaxlogin_user').object.value = response.username;
   480           $('ajaxlogin_user').object.value = response.username;
   479           $('ajaxlogin_pass').object.focus();
   481           if ( IE )
       
   482           {
       
   483             setTimeout("document.forms['ajax_login_form'].password.focus();", 200);
       
   484           }
       
   485           else
       
   486           {
       
   487             $('ajaxlogin_pass').object.focus();
       
   488           }
   480         }
   489         }
   481         else
   490         else
   482         {
   491         {
   483           $('ajaxlogin_user').object.focus();
   492           if ( IE )
   484         }
   493           {
   485         if ( ajax_auth_show_captcha )
   494             setTimeout("document.forms['ajax_login_form'].username.focus();", 200);
   486         {
   495           }
   487           $('ajaxlogin_captcha_code').object.onblur = function(e) { if ( !shift ) $('messageBox').object.nextSibling.firstChild.focus(); };
   496           else
   488           $('ajaxlogin_captcha_code').object.onkeypress = function(e) { if ( !e && IE ) return true; if ( e.keyCode == 13 ) $('messageBox').object.nextSibling.firstChild.click(); };
   497           {
   489         }
   498             $('ajaxlogin_user').object.focus();
   490         else
   499           }
   491         {
   500         }
   492           $('ajaxlogin_pass').object.onblur = function(e) { if ( !shift ) $('messageBox').object.nextSibling.firstChild.focus(); };
   501         var enter_obj = ( ajax_auth_show_captcha ) ? 'ajaxlogin_captcha_code' : 'ajaxlogin_pass';
   493           $('ajaxlogin_pass').object.onkeypress = function(e) { if ( !e && IE ) return true; if ( e.keyCode == 13 ) $('messageBox').object.nextSibling.firstChild.click(); };
   502         $(enter_obj).object.onblur = function(e) { if ( !shift ) $('messageBox').object.nextSibling.firstChild.focus(); };
   494         }
   503         $(enter_obj).object.onkeypress = function(e)
   495         if ( disable_controls )
   504         {
   496         {
   505           // Trigger a form submit when the password field is focused and the user presses enter
   497           var panel = document.getElementById('messageBoxButtons');
   506           
   498           panel.firstChild.disabled = true;
   507           // IE doesn't give us an event object when it should - check window.event. If that
   499         }
   508           // still fails, give up.
       
   509           if ( !e )
       
   510           {
       
   511             e = window.event;
       
   512           }
       
   513           if ( !e && IE )
       
   514           {
       
   515             return true;
       
   516           }
       
   517           if ( e.keyCode == 13 )
       
   518           {
       
   519             ajaxValidateLogin();
       
   520           }
       
   521         };
   500         /*
   522         /*
   501         ## This causes the background image to disappear under Fx 2
   523         ## This causes the background image to disappear under Fx 2
   502         if ( shown_error )
   524         if ( shown_error )
   503         {
   525         {
   504           // fade to #FFF4F4
   526           // fade to #FFF4F4