Protect hasFeature call.
Annotate for file /form-to-http-auth.js
2010-10-27 pix 1 (function () {
04:18:01 ' 2 function form2httpAuth () {
' 3 /* Skip if the browser indicates it does this itself. */
2010-10-28 pix 4 if (document.implementation &&
00:01:20 ' 5 document.implementation.hasFeature &&
' 6 document.implementation.hasFeature("HTTPFormAuth", "1.0"))
2010-10-27 pix 7 return true;
2010-10-27 pix 8
2010-10-27 pix 9 /* Attempt login with provided credentials. */
04:18:01 ' 10 var username = this.username.value;
' 11 var password = this.password.value;
' 12 var authed = false;
2010-10-27 pix 13 var form = this;
2010-10-27 pix 14 $.ajax({
04:18:01 ' 15 url: "/ajax-login.php",
2010-10-27 pix 16 /* synchronous hangs some browsers temporarily. :/ */
2010-10-27 pix 17 async: false,
04:18:01 ' 18 global: false,
' 19 username: username,
' 20 password: password,
' 21 dataType: 'text',
' 22 success: function (data, status, xhr) {
' 23 authed = true;
2010-10-27 pix 24 },
22:01:20 ' 25 error: function (xhr, status, err) {
' 26 authed = false;
' 27 },
' 28 complete: function (xhr, status) {
' 29 /* Don't send username and password if we successfully managed to auth via HTTP */
' 30 if (authed) {
' 31 form.username.parentNode.removeChild(form.username);
' 32 form.password.parentNode.removeChild(form.password);
' 33 }
2010-10-27 pix 34 }
04:18:01 ' 35 });
2010-10-27 pix 36
22:01:20 ' 37 /* This is the only way to get browsers to submit the form exactly as
' 38 the user did, which is why we aren't using async above. */
2010-10-27 pix 39 return true;
04:18:01 ' 40 }
' 41
' 42 $("form.http-authentication").submit(form2httpAuth);
' 43 })();