@ -19,6 +19,7 @@ var IPython = (function (IPython) {
if ( this . selector !== undefined ) {
this . element = $ ( selector ) ;
}
this . widget _dict = { } ;
} ;
NotificationArea . prototype . temp _message = function ( msg , timeout , css _class ) {
@ -27,7 +28,7 @@ var IPython = (function (IPython) {
if ( css _class == 'warning' ) { css _class = 'ui-state-highlight' }
var tdiv = $ ( '<div>' )
. attr ( 'id' , uuid )
. addClass ( 'notification ui-widget ui-widget-content ui-corner-all')
. addClass ( 'notification _widget ui-widget ui-widget-content ui-corner-all')
. addClass ( 'border-box-sizing' )
. addClass ( css _class )
. hide ( )
@ -42,10 +43,94 @@ var IPython = (function (IPython) {
} , tmout )
} ;
NotificationArea . prototype . widget = function ( name ) {
if ( this . widget _dict [ name ] == undefined ) {
return this . new _notification _widget ( name )
}
return this . get _widget ( name )
}
NotificationArea . prototype . get _widget = function ( name ) {
if ( this . widget _dict [ name ] == undefined ) {
throw ( 'no widgets with this name' ) ;
}
return this . widget _dict [ name ] ;
}
NotificationArea . prototype . new _notification _widget = function ( name ) {
if ( this . widget _dict [ name ] != undefined ) {
throw ( 'widget with that name already exists ! ' ) ;
}
var div = $ ( '<div/>' ) . attr ( 'id' , 'notification_' + name ) ;
$ ( this . selector ) . append ( div )
return new IPython . NotificationWidget ( '#notification_' + name )
this . widget _dict [ name ] = new IPython . NotificationWidget ( '#notification_' + name )
return this . widget _dict [ name ] ;
}
NotificationArea . prototype . init _notification _widgets = function ( ) {
var knw = this . new _notification _widget ( 'kernel' ) ;
// Kernel events
$ ( [ IPython . events ] ) . on ( 'status_idle.Kernel' , function ( ) {
IPython . save _widget . update _document _title ( ) ;
knw . set _message ( 'Kernel Idle' , 200 ) ;
}
) ;
$ ( [ IPython . events ] ) . on ( 'status_busy.Kernel' , function ( ) {
window . document . title = '(Busy) ' + window . document . title ;
knw . set _message ( "Kernel busy" ) ;
} ) ;
$ ( [ IPython . events ] ) . on ( 'status_restarting.Kernel' , function ( ) {
IPython . save _widget . update _document _title ( ) ;
knw . set _message ( "Restarting kernel" , 1000 ) ;
} ) ;
$ ( [ IPython . events ] ) . on ( 'status_interrupting.Kernel' , function ( ) {
knw . set _message ( "Interrupting kernel" ) ;
} ) ;
$ ( [ IPython . events ] ) . on ( 'status_dead.Kernel' , function ( ) {
var dialog = $ ( '<div/>' ) ;
dialog . html ( 'The kernel has died, would you like to restart it? If you do not restart the kernel, you will be able to save the notebook, but running code will not work until the notebook is reopened.' ) ;
$ ( document ) . append ( dialog ) ;
dialog . dialog ( {
resizable : false ,
modal : true ,
title : "Dead kernel" ,
buttons : {
"Restart" : function ( ) {
$ ( [ IPython . events ] ) . trigger ( 'status_restarting.Kernel' ) ;
IPython . notebook . start _kernel ( ) ;
$ ( this ) . dialog ( 'close' ) ;
} ,
"Continue running" : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
}
}
} ) ;
} ) ;
var nnw = this . new _notification _widget ( 'notebook' ) ;
// Notebook events
$ ( [ IPython . events ] ) . on ( 'notebook_loading.Notebook' , function ( ) {
nnw . set _message ( "Loading notebook" , 500 ) ;
} ) ;
$ ( [ IPython . events ] ) . on ( 'notebook_loaded.Notebook' , function ( ) {
nnw . set _message ( "Notebook loaded" , 500 ) ;
} ) ;
$ ( [ IPython . events ] ) . on ( 'notebook_saving.Notebook' , function ( ) {
nnw . set _message ( "Saving notebook" , 500 ) ;
} ) ;
$ ( [ IPython . events ] ) . on ( 'notebook_saved.Notebook' , function ( ) {
nnw . set _message ( "Notebook saved" , 2000 ) ;
} ) ;
$ ( [ IPython . events ] ) . on ( 'notebook_save_failed.Notebook' , function ( ) {
nnw . set _message ( "Notebook save failed" ) ;
} ) ;
}
IPython . NotificationArea = NotificationArea ;