Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50654 views
1
//----------------------------------------------------------------------------
2
// Copyright (C) 2008-2011 The IPython Development Team
3
//
4
// Distributed under the terms of the BSD License. The full license is in
5
// the file COPYING, distributed as part of this software.
6
//----------------------------------------------------------------------------
7
8
//============================================================================
9
// Notification widget
10
//============================================================================
11
12
var IPython = (function (IPython) {
13
"use strict";
14
var utils = IPython.utils;
15
16
17
var NotificationWidget = function (selector) {
18
this.selector = selector;
19
this.timeout = null;
20
this.busy = false;
21
if (this.selector !== undefined) {
22
this.element = $(selector);
23
this.style();
24
}
25
this.element.button();
26
this.element.hide();
27
var that = this;
28
29
this.inner = $('<span/>');
30
this.element.append(this.inner);
31
32
};
33
34
35
NotificationWidget.prototype.style = function () {
36
this.element.addClass('notification_widget pull-right');
37
this.element.addClass('border-box-sizing');
38
};
39
40
// msg : message to display
41
// timeout : time in ms before diseapearing
42
//
43
// if timeout <= 0
44
// click_callback : function called if user click on notification
45
// could return false to prevent the notification to be dismissed
46
NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, opts) {
47
var opts = opts || {};
48
var callback = click_callback || function() {return false;};
49
var that = this;
50
this.inner.attr('class', opts.icon);
51
this.inner.attr('title', opts.title);
52
this.inner.text(msg);
53
this.element.fadeIn(100);
54
if (this.timeout !== null) {
55
clearTimeout(this.timeout);
56
this.timeout = null;
57
}
58
if (timeout !== undefined && timeout >=0) {
59
this.timeout = setTimeout(function () {
60
that.element.fadeOut(100, function () {that.inner.text('');});
61
that.timeout = null;
62
}, timeout);
63
} else {
64
this.element.click(function() {
65
if( callback() != false ) {
66
that.element.fadeOut(100, function () {that.inner.text('');});
67
that.element.unbind('click');
68
}
69
if (that.timeout !== undefined) {
70
that.timeout = undefined;
71
clearTimeout(that.timeout);
72
}
73
});
74
}
75
};
76
77
78
NotificationWidget.prototype.get_message = function () {
79
return this.inner.html();
80
};
81
82
83
IPython.NotificationWidget = NotificationWidget;
84
85
return IPython;
86
87
}(IPython));
88
89
90