2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const render_loader = require("../templates/loader.hbs");
|
2019-07-09 21:24:00 +02:00
|
|
|
|
2014-03-13 15:03:01 +01:00
|
|
|
exports.make_indicator = function (outer_container, opts) {
|
|
|
|
opts = opts || {};
|
2019-11-02 00:06:25 +01:00
|
|
|
let container = outer_container;
|
2017-04-06 02:18:00 +02:00
|
|
|
|
|
|
|
// TODO: We set white-space to 'nowrap' because under some
|
|
|
|
// unknown circumstances (it happens on Keegan's laptop) the text
|
|
|
|
// width calculation, above, returns a result that's a few pixels
|
|
|
|
// too small. The container's div will be slightly too small,
|
|
|
|
// but that's probably OK for our purposes.
|
2020-07-15 01:29:15 +02:00
|
|
|
outer_container.css({"white-space": "nowrap"});
|
2017-04-06 02:18:00 +02:00
|
|
|
|
2014-03-13 15:03:01 +01:00
|
|
|
container.empty();
|
|
|
|
|
|
|
|
if (opts.abs_positioned !== undefined && opts.abs_positioned) {
|
|
|
|
// Create some additional containers to facilitate absolutely
|
|
|
|
// positioned spinners.
|
2020-07-15 01:29:15 +02:00
|
|
|
const container_id = container.attr("id");
|
2019-11-02 00:06:25 +01:00
|
|
|
let inner_container = $('<div id="' + container_id + '_box_container"></div>');
|
2014-03-13 15:03:01 +01:00
|
|
|
container.append(inner_container);
|
|
|
|
container = inner_container;
|
|
|
|
inner_container = $('<div id="' + container_id + '_box"></div>');
|
|
|
|
container.append(inner_container);
|
|
|
|
container = inner_container;
|
|
|
|
}
|
|
|
|
|
2020-08-10 01:47:56 +02:00
|
|
|
const spinner_elem = $('<div class="loading_indicator_spinner" aria-hidden="true"></div>');
|
2020-07-16 22:40:18 +02:00
|
|
|
spinner_elem.html(render_loader({container_id: outer_container.attr("id")}));
|
2014-03-13 15:03:01 +01:00
|
|
|
container.append(spinner_elem);
|
2019-11-02 00:06:25 +01:00
|
|
|
let text_width = 0;
|
2014-03-13 15:03:01 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (opts.text !== undefined && opts.text !== "") {
|
2019-11-02 00:06:25 +01:00
|
|
|
const text_elem = $('<span class="loading_indicator_text"></span>');
|
2014-03-13 15:03:01 +01:00
|
|
|
text_elem.text(opts.text);
|
|
|
|
container.append(text_elem);
|
|
|
|
// See note, below
|
2017-04-05 03:55:28 +02:00
|
|
|
if (!(opts.abs_positioned !== undefined && opts.abs_positioned)) {
|
|
|
|
text_width = 20 + text_elem.width();
|
|
|
|
}
|
2014-03-13 15:03:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// These width calculations are tied to the spinner width and
|
|
|
|
// margins defined via CSS
|
2020-07-15 00:34:28 +02:00
|
|
|
container.css({width: 38 + text_width, height: 0});
|
2014-03-13 15:03:01 +01:00
|
|
|
|
2017-01-05 01:03:14 +01:00
|
|
|
outer_container.data("destroying", false);
|
2014-03-13 15:03:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.destroy_indicator = function (container) {
|
|
|
|
if (container.data("destroying")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
container.data("destroying", true);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const spinner = container.data("spinner_obj");
|
2014-03-13 15:03:01 +01:00
|
|
|
if (spinner !== undefined) {
|
|
|
|
spinner.stop();
|
|
|
|
}
|
|
|
|
container.removeData("spinner_obj");
|
|
|
|
container.empty();
|
2020-07-19 07:22:40 +02:00
|
|
|
container.css({width: 0, height: 0});
|
2014-03-13 15:03:01 +01:00
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.loading = exports;
|