2012-10-03 22:07:04 +02:00
|
|
|
// Miscellaneous early setup.
|
|
|
|
// This is the first of our Javascript files to be included.
|
|
|
|
|
|
|
|
var loading_spinner;
|
|
|
|
var templates = {};
|
|
|
|
$(function () {
|
|
|
|
// Display loading indicator. This disappears after the first
|
|
|
|
// get_updates completes.
|
2012-10-03 23:22:51 +02:00
|
|
|
if (have_initial_messages) {
|
2012-10-03 22:07:04 +02:00
|
|
|
loading_spinner = new Spinner().spin($('#loading_spinner')[0]);
|
2012-10-03 23:22:51 +02:00
|
|
|
} else {
|
2012-10-03 22:07:04 +02:00
|
|
|
$('#loading_indicator').hide();
|
2012-10-03 23:22:51 +02:00
|
|
|
}
|
2012-10-03 22:07:04 +02:00
|
|
|
|
|
|
|
// Compile Handlebars templates.
|
2012-10-31 20:36:03 +01:00
|
|
|
$.each(['message', 'subscription', 'narrowbar',
|
|
|
|
'userinfo_popover_title', 'userinfo_popover_content'],
|
2012-10-26 22:04:01 +02:00
|
|
|
function (index, name) {
|
|
|
|
templates[name] = Handlebars.compile($('#template_'+name).html());
|
|
|
|
}
|
|
|
|
);
|
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.
|
|
|
|
var csrftoken = $('input[name="csrfmiddlewaretoken"]').attr('value');
|
|
|
|
|
|
|
|
$.ajaxSetup({
|
|
|
|
beforeSend: function (xhr, settings) {
|
|
|
|
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
|
|
|
|
// Only send the token to relative URLs i.e. locally.
|
|
|
|
xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
2012-10-03 22:07:04 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-26 21:49:47 +02:00
|
|
|
});
|
2012-10-03 22:07:04 +02:00
|
|
|
});
|