##// END OF EJS Templates
Add comment explaining 1.02 factor
Add comment explaining 1.02 factor

File last commit:

r18009:41b3cd47
r18492:24e963dc
Show More
notificationwidget.js
160 lines | 5.2 KiB | application/javascript | JavascriptLexer
/ IPython / html / static / notebook / js / notificationwidget.js
Jonathan Frederic
MWE,...
r17200 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
Brian Granger
Major refactoring of saving, notification....
r6047
Jonathan Frederic
MWE,...
r17200 define([
'base/js/namespace',
'jquery',
], function(IPython, $) {
Matthias BUSSONNIER
use strict in notificationwidget.js
r8206 "use strict";
Brian Granger
Major refactoring of saving, notification....
r6047
Jessica B. Hamrick
Add documentation to notification area
r18004 /**
* Construct a NotificationWidget object.
*
* @constructor
* @param {string} selector - a jQuery selector string for the
* notification widget element
*/
Brian Granger
Major refactoring of saving, notification....
r6047 var NotificationWidget = function (selector) {
this.selector = selector;
this.timeout = null;
this.busy = false;
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
}
Matthias BUSSONNIER
prototype sticky notification
r8025 this.element.hide();
Matthias BUSSONNIER
more subtle kernel indicator...
r15042 this.inner = $('<span/>');
this.element.append(this.inner);
Brian Granger
Major refactoring of saving, notification....
r6047 };
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 /**
* Add the 'notification_widget' CSS class to the widget element.
*
* @method style
*/
Brian Granger
Major refactoring of saving, notification....
r6047 NotificationWidget.prototype.style = function () {
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 this.element.addClass('notification_widget');
Brian Granger
Major refactoring of saving, notification....
r6047 };
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 /**
* Set the notification widget message to display for a certain
* amount of time (timeout). The widget will be shown forever if
* timeout is <= 0 or undefined. If the widget is clicked while it
* is still displayed, execute an optional callback
* (click_callback). If the callback returns false, it will
* prevent the notification from being dismissed.
*
* Options:
* class - CSS class name for styling
* icon - CSS class name for the widget icon
* title - HTML title attribute for the widget
*
* @method set_message
* @param {string} msg - The notification to display
* @param {integer} [timeout] - The amount of time in milliseconds to display the widget
* @param {function} [click_callback] - The function to run when the widget is clicked
* @param {Object} [options] - Additional options
*/
Jonathan Frederic
More review changes
r17214 NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, options) {
Jessica B. Hamrick
Allow timeout and click callback
r18002 options = options || {};
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 // unbind potential previous callback
this.element.unbind('click');
Jonathan Frederic
More review changes
r17214 this.inner.attr('class', options.icon);
this.inner.attr('title', options.title);
Matthias BUSSONNIER
more subtle kernel indicator...
r15042 this.inner.text(msg);
Brian Granger
Major refactoring of saving, notification....
r6047 this.element.fadeIn(100);
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368
// reset previous set style
Matthias BUSSONNIER
fix missing semicolons
r17391 this.element.removeClass();
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 this.style();
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 if (options.class) {
Jessica B. Hamrick
Allow timeout and click callback
r18002 this.element.addClass(options.class);
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 }
Jessica B. Hamrick
Allow timeout and click callback
r18002
// clear previous timer
Brian Granger
Major refactoring of saving, notification....
r6047 if (this.timeout !== null) {
clearTimeout(this.timeout);
this.timeout = null;
Matthias BUSSONNIER
jslint 2
r8205 }
Jessica B. Hamrick
Allow timeout and click callback
r18002
// set the timer if a timeout is given
var that = this;
if (timeout !== undefined && timeout >= 0) {
Brian Granger
Major refactoring of saving, notification....
r6047 this.timeout = setTimeout(function () {
Matthias BUSSONNIER
more subtle kernel indicator...
r15042 that.element.fadeOut(100, function () {that.inner.text('');});
Jessica B. Hamrick
Allow timeout and click callback
r18002 that.element.unbind('click');
Brian Granger
Major refactoring of saving, notification....
r6047 that.timeout = null;
Matthias BUSSONNIER
prototype sticky notification
r8025 }, timeout);
Jessica B. Hamrick
Allow timeout and click callback
r18002 }
// bind the click callback if it is given
if (click_callback !== undefined) {
Jessica B. Hamrick
Small changes to notification widget
r18005 this.element.click(function () {
Jessica B. Hamrick
Allow timeout and click callback
r18002 if (click_callback() !== false) {
Matthias BUSSONNIER
more subtle kernel indicator...
r15042 that.element.fadeOut(100, function () {that.inner.text('');});
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 }
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 that.element.unbind('click');
Jessica B. Hamrick
Allow timeout and click callback
r18002 if (that.timeout !== null) {
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 clearTimeout(that.timeout);
Jessica B. Hamrick
Allow timeout and click callback
r18002 that.timeout = null;
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 }
});
}
Brian Granger
Major refactoring of saving, notification....
r6047 };
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 /**
* Display an information message (styled with the 'info'
Jessica B. Hamrick
Small changes to notification widget
r18005 * class). Arguments are the same as in set_message. Default
* timeout is 3500 milliseconds.
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 *
* @method info
*/
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 NotificationWidget.prototype.info = function (msg, timeout, click_callback, options) {
Jessica B. Hamrick
Allow timeout and click callback
r18002 options = options || {};
options.class = options.class + ' info';
timeout = timeout || 3500;
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 this.set_message(msg, timeout, click_callback, options);
Jessica B. Hamrick
Allow timeout and click callback
r18002 };
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 /**
* Display a warning message (styled with the 'warning'
Jessica B. Hamrick
Clarify stickiness of warning/danger notifications
r18009 * class). Arguments are the same as in set_message. Messages are
* sticky by default.
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 *
* @method warning
*/
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 NotificationWidget.prototype.warning = function (msg, timeout, click_callback, options) {
Jessica B. Hamrick
Allow timeout and click callback
r18002 options = options || {};
options.class = options.class + ' warning';
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 this.set_message(msg, timeout, click_callback, options);
Jessica B. Hamrick
Allow timeout and click callback
r18002 };
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 /**
* Display a danger message (styled with the 'danger'
Jessica B. Hamrick
Clarify stickiness of warning/danger notifications
r18009 * class). Arguments are the same as in set_message. Messages are
* sticky by default.
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 *
* @method danger
*/
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 NotificationWidget.prototype.danger = function (msg, timeout, click_callback, options) {
Jessica B. Hamrick
Allow timeout and click callback
r18002 options = options || {};
options.class = options.class + ' danger';
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 this.set_message(msg, timeout, click_callback, options);
Jessica B. Hamrick
Allow timeout and click callback
r18002 };
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368
Jessica B. Hamrick
Add documentation to NotificationWidget methods
r18003 /**
* Get the text of the widget message.
*
* @method get_message
* @return {string} - the message text
*/
Brian Granger
Major refactoring of saving, notification....
r6047 NotificationWidget.prototype.get_message = function () {
Matthias BUSSONNIER
more subtle kernel indicator...
r15042 return this.inner.html();
Brian Granger
Major refactoring of saving, notification....
r6047 };
Matthias BUSSONNIER
Introduce info/warning/danger to notification area...
r17368 // For backwards compatibility.
Brian Granger
Major refactoring of saving, notification....
r6047 IPython.NotificationWidget = NotificationWidget;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'NotificationWidget': NotificationWidget};
Jonathan Frederic
MWE,...
r17200 });