2012-10-03 22:07:04 +02:00
|
|
|
// Miscellaneous early setup.
|
|
|
|
|
2012-11-14 17:31:29 +01:00
|
|
|
var csrf_token;
|
2012-10-03 22:07:04 +02:00
|
|
|
$(function () {
|
|
|
|
// Display loading indicator. This disappears after the first
|
|
|
|
// get_updates completes.
|
2013-03-25 23:26:14 +01:00
|
|
|
if (page_params.have_initial_messages) {
|
2013-07-10 19:33:00 +02:00
|
|
|
util.make_loading_indicator($('#page_loading_indicator'), {text: 'Loading...'});
|
2013-06-27 22:18:28 +02:00
|
|
|
} else if (!page_params.needs_tutorial) {
|
2013-03-12 04:54:17 +01:00
|
|
|
util.show_first_run_message();
|
2012-10-03 23:22:51 +02:00
|
|
|
}
|
2012-10-03 22:07:04 +02:00
|
|
|
|
2012-10-26 21:49:47 +02:00
|
|
|
// This requires that we used Django's {% csrf_token %} somewhere on the page.
|
2012-11-14 17:31:29 +01:00
|
|
|
csrf_token = $('input[name="csrfmiddlewaretoken"]').attr('value');
|
2012-10-26 21:49:47 +02:00
|
|
|
|
|
|
|
$.ajaxSetup({
|
|
|
|
beforeSend: function (xhr, settings) {
|
|
|
|
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
|
|
|
|
// Only send the token to relative URLs i.e. locally.
|
2012-11-14 17:31:29 +01:00
|
|
|
xhr.setRequestHeader("X-CSRFToken", csrf_token);
|
2012-10-03 22:07:04 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-26 21:49:47 +02:00
|
|
|
});
|
2012-11-21 00:16:09 +01:00
|
|
|
|
|
|
|
// For some reason, jQuery wants this to be attached to an element.
|
|
|
|
$('body').ajaxError(function (event, xhr) {
|
|
|
|
if (xhr.status === 401) {
|
|
|
|
// We got logged out somehow, perhaps from another window or a session timeout.
|
|
|
|
// We could display an error message, but jumping right to the login page seems
|
|
|
|
// smoother and conveys the same information.
|
|
|
|
window.location.replace('/accounts/login');
|
|
|
|
}
|
|
|
|
});
|
2013-04-04 00:55:36 +02:00
|
|
|
|
2013-11-04 23:42:31 +01:00
|
|
|
if (page_params.password_auth_enabled !== false) {
|
|
|
|
// zxcvbn.js is pretty big, and is only needed on password change, so load it asynchronously.
|
|
|
|
$.getScript('/static/third/zxcvbn/zxcvbn.js');
|
|
|
|
}
|
2012-10-03 22:07:04 +02:00
|
|
|
});
|