notificationwidget.js
82 lines
| 2.6 KiB
| application/javascript
|
JavascriptLexer
|
r6047 | //---------------------------------------------------------------------------- | ||
// Copyright (C) 2008-2011 The IPython Development Team | ||||
// | ||||
// Distributed under the terms of the BSD License. The full license is in | ||||
// the file COPYING, distributed as part of this software. | ||||
//---------------------------------------------------------------------------- | ||||
//============================================================================ | ||||
// Notification widget | ||||
//============================================================================ | ||||
var IPython = (function (IPython) { | ||||
var utils = IPython.utils; | ||||
var NotificationWidget = function (selector) { | ||||
this.selector = selector; | ||||
this.timeout = null; | ||||
this.busy = false; | ||||
if (this.selector !== undefined) { | ||||
this.element = $(selector); | ||||
this.style(); | ||||
} | ||||
|
r8025 | this.element.button(); | ||
this.element.hide(); | ||||
var that = this; | ||||
|
r8074 | |||
|
r6047 | }; | ||
NotificationWidget.prototype.style = function () { | ||||
|
r8074 | this.element.addClass('notification_widget ui-widget ui-widget-content ui-corner-all'); | ||
|
r6047 | this.element.addClass('border-box-sizing'); | ||
}; | ||||
|
r8074 | // msg : message to display | ||
// timeout : time in ms before diseapearing | ||||
// | ||||
// if timeout <= 0 | ||||
// click_callback : function called if user click on notification | ||||
// could return false to prevent the notification to be dismissed | ||||
NotificationWidget.prototype.set_message = function (msg, timeout, click_callback) { | ||||
var callback = click_callback || function(){return false}; | ||||
|
r6047 | var that = this; | ||
this.element.html(msg); | ||||
this.element.fadeIn(100); | ||||
if (this.timeout !== null) { | ||||
clearTimeout(this.timeout); | ||||
this.timeout = null; | ||||
}; | ||||
|
r8025 | if (timeout !== undefined && timeout >=0) { | ||
|
r6047 | this.timeout = setTimeout(function () { | ||
that.element.fadeOut(100, function () {that.element.html('');}); | ||||
that.timeout = null; | ||||
|
r8025 | }, timeout); | ||
|
r8074 | } else { | ||
this.element.click(function(){ | ||||
if( callback() != false){ | ||||
that.element.fadeOut(100, function () {that.element.html('');}); | ||||
|
r8203 | that.element.unbind('click') | ||
|
r8074 | } | ||
if (that.timeout !== undefined) { | ||||
that.timeout = undefined | ||||
clearTimeout(that.timeout); | ||||
} | ||||
}); | ||||
} | ||||
|
r6047 | }; | ||
NotificationWidget.prototype.get_message = function () { | ||||
return this.element.html(); | ||||
}; | ||||
IPython.NotificationWidget = NotificationWidget; | ||||
return IPython; | ||||
}(IPython)); | ||||