2012-11-30 18:33:32 +01:00
|
|
|
var util = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
// From MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/random
|
|
|
|
exports.random_int = function random_int(min, max) {
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
};
|
|
|
|
|
2012-12-17 22:55:10 +01:00
|
|
|
// We need to reset the favicon after changing the
|
|
|
|
// window.location.hash or Firefox will drop the favicon. See
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=519028
|
|
|
|
exports.reset_favicon = function () {
|
|
|
|
$('link[rel="shortcut icon"]').detach().appendTo('head');
|
|
|
|
};
|
|
|
|
|
2013-01-16 19:50:18 +01:00
|
|
|
exports.make_loading_indicator = function (container, text) {
|
2013-01-15 21:41:16 +01:00
|
|
|
container.empty();
|
2013-01-16 19:50:18 +01:00
|
|
|
var spinner_elem = $('<div class="loading_indicator_spinner"></div>');
|
2013-01-15 21:41:16 +01:00
|
|
|
container.append(spinner_elem);
|
|
|
|
var text_width = 0;
|
|
|
|
|
|
|
|
if (text !== '' && text !== undefined) {
|
2013-01-16 19:50:18 +01:00
|
|
|
var text_elem = $('<span class="loading_indicator_text"></span>');
|
2013-01-15 21:41:16 +01:00
|
|
|
text_elem.text(text);
|
|
|
|
container.append(text_elem);
|
|
|
|
// See note, below
|
|
|
|
text_width = 20 + text_elem.width();
|
|
|
|
}
|
|
|
|
|
|
|
|
// These width calculations are tied to the spinner width and
|
|
|
|
// margins defined via CSS
|
|
|
|
container.css({width: 38 + text_width,
|
2013-01-16 21:25:38 +01:00
|
|
|
height: 38,
|
|
|
|
display: 'block'});
|
2013-01-15 20:26:49 +01:00
|
|
|
|
|
|
|
var spinner = new Spinner({
|
|
|
|
lines: 8,
|
|
|
|
length: 0,
|
|
|
|
width: 9,
|
|
|
|
radius: 9,
|
|
|
|
speed: 1.25,
|
|
|
|
shadow: false
|
|
|
|
}).spin(spinner_elem[0]);
|
2013-01-16 19:37:50 +01:00
|
|
|
container.data("spinner_obj", spinner);
|
|
|
|
};
|
|
|
|
|
2013-01-16 19:50:18 +01:00
|
|
|
exports.destroy_loading_indicator = function (container) {
|
2013-01-16 19:37:50 +01:00
|
|
|
var spinner = container.data("spinner_obj");
|
|
|
|
if (spinner !== undefined) {
|
|
|
|
spinner.stop();
|
|
|
|
}
|
|
|
|
container.removeData("spinner_obj");
|
|
|
|
container.empty();
|
2013-01-16 21:25:38 +01:00
|
|
|
container.css({width: 0, height: 0, display: 'none'});
|
2013-01-15 20:26:49 +01:00
|
|
|
};
|
|
|
|
|
2012-11-30 18:33:32 +01:00
|
|
|
return exports;
|
|
|
|
}());
|