@ -59,7 +59,7 @@ var IPython = (function (IPython) {
var that = this ;
$ ( document ) . keydown ( function ( event ) {
// console.log(event);
if ( that . read _only ) return ;
if ( that . read _only ) return false ;
if ( event . which === 27 ) {
// Intercept escape at highest level to avoid closing
// websocket connection with firefox
@ -165,6 +165,7 @@ var IPython = (function (IPython) {
that . control _key _active = false ;
return true ;
} ;
return true ;
} ) ;
this . element . bind ( 'collapse_pager' , function ( ) {
@ -203,6 +204,7 @@ var IPython = (function (IPython) {
if ( that . dirty && ! that . read _only ) {
return "You have unsaved changes that will be lost if you leave this page." ;
} ;
return true ;
} ) ;
} ;
@ -266,12 +268,12 @@ var IPython = (function (IPython) {
Notebook . prototype . cell _elements = function ( ) {
return this . element . children ( "div.cell" ) ;
}
} ;
Notebook . prototype . ncells = function ( cell ) {
return this . cell _elements ( ) . length ;
}
} ;
// TODO: we are often calling cells as cells()[i], which we should optimize
@ -280,7 +282,7 @@ var IPython = (function (IPython) {
return this . cell _elements ( ) . toArray ( ) . map ( function ( e ) {
return $ ( e ) . data ( "cell" ) ;
} ) ;
}
} ;
Notebook . prototype . find _cell _index = function ( cell ) {
@ -296,7 +298,7 @@ var IPython = (function (IPython) {
Notebook . prototype . index _or _selected = function ( index ) {
return index || this . selected _index ( ) || 0 ;
}
} ;
Notebook . prototype . select = function ( index ) {
@ -354,7 +356,7 @@ var IPython = (function (IPython) {
Notebook . prototype . selected _cell = function ( ) {
return this . cell _elements ( ) . eq ( this . selected _index ( ) ) . data ( "cell" ) ;
}
} ;
// Cell insertion, deletion and moving.
@ -392,7 +394,7 @@ var IPython = (function (IPython) {
this . cell _elements ( ) . eq ( index ) . after ( cell . element ) ;
} ;
this . dirty = true ;
return this
return this ;
} ;
@ -423,14 +425,14 @@ var IPython = (function (IPython) {
} ;
this . dirty = true ;
return this ;
}
} ;
Notebook . prototype . move _cell _down = function ( index ) {
var i = index || this . selected _index ( ) ;
if ( i !== null && i < ( this . ncells ( ) - 1 ) && i >= 0 ) {
var pivot = this . cell _elements ( ) . eq ( i + 1 )
var tomove = this . cell _elements ( ) . eq ( i )
var pivot = this . cell _elements ( ) . eq ( i + 1 ) ;
var tomove = this . cell _elements ( ) . eq ( i ) ;
if ( pivot !== null && tomove !== null ) {
tomove . detach ( ) ;
pivot . after ( tomove ) ;
@ -439,7 +441,7 @@ var IPython = (function (IPython) {
} ;
this . dirty = true ;
return this ;
}
} ;
Notebook . prototype . sort _cells = function ( ) {
@ -447,7 +449,7 @@ var IPython = (function (IPython) {
var sindex = this . selected _index ( ) ;
var swapped ;
do {
swapped = false
swapped = false ;
for ( var i = 1 ; i < ncells ; i ++ ) {
current = this . cell _elements ( ) . eq ( i ) . data ( "cell" ) ;
previous = this . cell _elements ( ) . eq ( i - 1 ) . data ( "cell" ) ;
@ -470,7 +472,7 @@ var IPython = (function (IPython) {
this . insert _cell _above ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
}
} ;
Notebook . prototype . insert _code _cell _below = function ( index ) {
@ -481,7 +483,7 @@ var IPython = (function (IPython) {
this . insert _cell _below ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
}
} ;
Notebook . prototype . insert _html _cell _above = function ( index ) {
@ -492,7 +494,7 @@ var IPython = (function (IPython) {
this . insert _cell _above ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
}
} ;
Notebook . prototype . insert _html _cell _below = function ( index ) {
@ -503,7 +505,7 @@ var IPython = (function (IPython) {
this . insert _cell _below ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
}
} ;
Notebook . prototype . insert _markdown _cell _above = function ( index ) {
@ -514,7 +516,7 @@ var IPython = (function (IPython) {
this . insert _cell _above ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
}
} ;
Notebook . prototype . insert _markdown _cell _below = function ( index ) {
@ -525,7 +527,7 @@ var IPython = (function (IPython) {
this . insert _cell _below ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
}
} ;
Notebook . prototype . to _code = function ( index ) {
@ -553,11 +555,11 @@ var IPython = (function (IPython) {
var target _cell = null ;
if ( source _cell instanceof IPython . CodeCell ) {
this . insert _markdown _cell _below ( i ) ;
var target _cell = this . cells ( ) [ i + 1 ] ;
target _cell = this . cells ( ) [ i + 1 ] ;
var text = source _cell . get _code ( ) ;
} else if ( source _cell instanceof IPython . HTMLCell ) {
this . insert _markdown _cell _below ( i ) ;
var target _cell = this . cells ( ) [ i + 1 ] ;
target _cell = this . cells ( ) [ i + 1 ] ;
var text = source _cell . get _source ( ) ;
if ( text === source _cell . placeholder ) {
text = target _cell . placeholder ;
@ -581,11 +583,11 @@ var IPython = (function (IPython) {
var target _cell = null ;
if ( source _cell instanceof IPython . CodeCell ) {
this . insert _html _cell _below ( i ) ;
var target _cell = this . cells ( ) [ i + 1 ] ;
target _cell = this . cells ( ) [ i + 1 ] ;
var text = source _cell . get _code ( ) ;
} else if ( source _cell instanceof IPython . MarkdownCell ) {
this . insert _html _cell _below ( i ) ;
var target _cell = this . cells ( ) [ i + 1 ] ;
target _cell = this . cells ( ) [ i + 1 ] ;
var text = source _cell . get _source ( ) ;
if ( text === source _cell . placeholder ) {
text = target _cell . placeholder ;
@ -643,7 +645,7 @@ var IPython = (function (IPython) {
var cells = this . cells ( ) ;
len = cells . length ;
for ( var i = 0 ; i < len ; i ++ ) {
cells [ i ] . set _autoindent ( state )
cells [ i ] . set _autoindent ( state ) ;
} ;
} ;
@ -662,7 +664,7 @@ var IPython = (function (IPython) {
// Other cell functions: line numbers, ...
Notebook . prototype . cell _toggle _line _numbers = function ( ) {
this . selected _cell ( ) . toggle _line _numbers ( )
this . selected _cell ( ) . toggle _line _numbers ( ) ;
} ;
// Kernel related things
@ -864,8 +866,8 @@ var IPython = (function (IPython) {
Notebook . prototype . execute _selected _cell = function ( options ) {
// add_new: should a new cell be added if we are at the end of the nb
// terminal: execute in terminal mode, which stays in the current cell
default _options = { terminal : false , add _new : true }
$ . extend ( default _options , options )
default _options = { terminal : false , add _new : true } ;
$ . extend ( default _options , options ) ;
var that = this ;
var cell = that . selected _cell ( ) ;
var cell _index = that . find _cell _index ( cell ) ;
@ -938,7 +940,8 @@ var IPython = (function (IPython) {
Notebook . prototype . fromJSON = function ( data ) {
var ncells = this . ncells ( ) ;
for ( var i = 0 ; i < ncells ; i ++ ) {
var i ;
for ( i = 0 ; i < ncells ; i ++ ) {
// Always delete cell 0 as they get renumbered as they are deleted.
this . delete _cell ( 0 ) ;
} ;
@ -951,7 +954,7 @@ var IPython = (function (IPython) {
ncells = new _cells . length ;
var cell _data = null ;
var new _cell = null ;
for ( var i = 0 ; i < ncells ; i ++ ) {
for ( i = 0 ; i < ncells ; i ++ ) {
cell _data = new _cells [ i ] ;
if ( cell _data . cell _type == 'code' ) {
new _cell = this . insert _code _cell _below ( ) ;
@ -979,8 +982,8 @@ var IPython = (function (IPython) {
// Only handle 1 worksheet for now.
worksheets : [ { cells : cell _array } ] ,
metadata : this . metadata
}
return data
} ;
return data ;
} ;
Notebook . prototype . save _notebook = function ( ) {
@ -1002,7 +1005,7 @@ var IPython = (function (IPython) {
error : $ . proxy ( this . notebook _save _failed , this )
} ;
IPython . save _widget . status _saving ( ) ;
var url = $ ( 'body' ) . data ( 'baseProjectUrl' ) + 'notebooks/' + notebook _id
var url = $ ( 'body' ) . data ( 'baseProjectUrl' ) + 'notebooks/' + notebook _id ;
$ . ajax ( url , settings ) ;
} ;
} ;
@ -1012,7 +1015,7 @@ var IPython = (function (IPython) {
this . dirty = false ;
IPython . save _widget . notebook _saved ( ) ;
IPython . save _widget . status _save ( ) ;
}
} ;
Notebook . prototype . notebook _save _failed = function ( xhr , status , error _msg ) {
@ -1020,7 +1023,7 @@ var IPython = (function (IPython) {
// TODO: Handle different types of errors (timeout etc.)
alert ( 'An unexpected error occured while saving the notebook.' ) ;
IPython . save _widget . reset _status ( ) ;
}
} ;
Notebook . prototype . load _notebook = function ( callback ) {
@ -1040,9 +1043,9 @@ var IPython = (function (IPython) {
}
} ;
IPython . save _widget . status _loading ( ) ;
var url = $ ( 'body' ) . data ( 'baseProjectUrl' ) + 'notebooks/' + notebook _id
var url = $ ( 'body' ) . data ( 'baseProjectUrl' ) + 'notebooks/' + notebook _id ;
$ . ajax ( url , settings ) ;
}
} ;
Notebook . prototype . notebook _loaded = function ( data , status , xhr ) {