Skip to content

Commit 3e01e12

Browse files
committed
Use animated favicon for kernel busy indicator
1 parent 5f3dbf9 commit 3e01e12

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed
1.12 KB
Binary file not shown.
1.12 KB
Binary file not shown.
1.12 KB
Binary file not shown.
-31.3 KB
Binary file not shown.

notebook/static/base/js/utils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,17 @@ define([
10511051
fn();
10521052
}
10531053
}
1054+
1055+
var change_favicon = function (src) {
1056+
var link = document.createElement('link'),
1057+
oldLink = document.getElementById('favicon');
1058+
link.id = 'favicon';
1059+
link.type = 'image/x-icon';
1060+
link.rel = 'shortcut icon';
1061+
link.href = utils.url_path_join(utils.get_body_data('baseUrl'), src);
1062+
if (oldLink) document.head.removeChild(oldLink);
1063+
document.head.appendChild(link);
1064+
};
10541065

10551066
var utils = {
10561067
throttle: throttle,
@@ -1101,7 +1112,8 @@ define([
11011112
format_datetime: format_datetime,
11021113
datetime_sort_helper: datetime_sort_helper,
11031114
dnd_contain_file: dnd_contain_file,
1104-
_ansispan:_ansispan
1115+
_ansispan:_ansispan,
1116+
change_favicon: change_favicon
11051117
};
11061118

11071119
return utils;

notebook/static/notebook/js/notificationarea.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ define([
4040
var $modal_ind_icon = $("#modal_indicator");
4141
var $readonly_ind_icon = $('#readonly-indicator');
4242
var $body = $('body');
43+
var interval = 0;
44+
45+
var set_busy_favicon = function(on) {
46+
if (on && !interval) {
47+
var i = 0;
48+
var icons = ['favicon-busy-1.ico', 'favicon-busy-3.ico', 'favicon-busy-3.ico'];
49+
interval = setInterval(function() {
50+
var icon = icons[i % 3];
51+
utils.change_favicon('/static/base/images/' + icon);
52+
i += 1;
53+
}, 300);
54+
} else {
55+
clearInterval(interval);
56+
utils.change_favicon('/static/base/images/favicon-notebook.ico');
57+
interval = 0;
58+
}
59+
};
4360

4461
// Listen for the notebook loaded event. Set readonly indicator.
4562
this.events.on('notebook_loaded.Notebook', function() {
@@ -244,41 +261,30 @@ define([
244261
knw.danger(short, undefined, showMsg);
245262
});
246263

247-
var change_favicon = function (src) {
248-
var link = document.createElement('link'),
249-
oldLink = document.getElementById('favicon');
250-
link.id = 'favicon';
251-
link.type = 'image/x-icon';
252-
link.rel = 'shortcut icon';
253-
link.href = utils.url_path_join(utils.get_body_data('baseUrl'), src);
254-
if (oldLink) document.head.removeChild(oldLink);
255-
document.head.appendChild(link);
256-
};
257-
258264
this.events.on('kernel_starting.Kernel kernel_created.Session', function () {
259265
// window.document.title='(Starting) '+window.document.title;
260266
$kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
261267
knw.set_message("Kernel starting, please wait...");
262-
change_favicon('/static/base/images/favicon-busy.ico');
268+
set_busy_favicon(true);
263269
});
264270

265271
this.events.on('kernel_ready.Kernel', function () {
266272
// that.save_widget.update_document_title();
267273
$kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
268274
knw.info("Kernel ready", 500);
269-
change_favicon('/static/base/images/favicon.ico');
275+
set_busy_favicon(false);
270276
});
271277

272278
this.events.on('kernel_idle.Kernel', function () {
273279
// that.save_widget.update_document_title();
274280
$kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
275-
change_favicon('/static/base/images/favicon.ico');
281+
set_busy_favicon(false);
276282
});
277283

278284
this.events.on('kernel_busy.Kernel', function () {
279285
// window.document.title='(Busy) '+window.document.title;
280286
$kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
281-
change_favicon('/static/base/images/favicon-busy.ico');
287+
set_busy_favicon(true);
282288
});
283289

284290
this.events.on('spec_match_found.Kernel', function (evt, data) {

0 commit comments

Comments
 (0)