@ -47,11 +47,11 @@ var IPython = (function (IPython) {
// ii) to prevent the div from scrolling up when the last cell is being
// edited, but is too low on the page, which browsers will do automatically.
var that = this ;
var end _space = $ ( '<div class="end_space"></div> ') . height ( "30%" ) ;
var end _space = $ ( '<div />') . addClass ( 'end_space ') . height ( "30%" ) ;
end _space . dblclick ( function ( e ) {
if ( that . read _only ) return ;
var ncells = that . ncells ( ) ;
that . insert _c ode_c ell_below ( ncells - 1 ) ;
that . insert _c ell_below ( 'code' , ncells - 1 ) ;
} ) ;
this . element . append ( end _space ) ;
$ ( 'div#notebook' ) . addClass ( 'border-box-sizing' ) ;
@ -69,13 +69,13 @@ var IPython = (function (IPython) {
event . preventDefault ( ) ;
}
if ( event . which === 38 && ! event . shiftKey ) {
var cell = that . selected_cell ( ) ;
var cell = that . get_ selected_cell ( ) ;
if ( cell . at _top ( ) ) {
event . preventDefault ( ) ;
that . select _prev ( ) ;
} ;
} else if ( event . which === 40 && ! event . shiftKey ) {
var cell = that . selected_cell ( ) ;
var cell = that . get_ selected_cell ( ) ;
if ( cell . at _bottom ( ) ) {
event . preventDefault ( ) ;
that . select _next ( ) ;
@ -111,12 +111,12 @@ var IPython = (function (IPython) {
return false ;
} else if ( event . which === 65 && that . control _key _active ) {
// Insert code cell above selected = a
that . insert _c ode_c ell_above ( ) ;
that . insert _c ell_above ( 'code' ) ;
that . control _key _active = false ;
return false ;
} else if ( event . which === 66 && that . control _key _active ) {
// Insert code cell below selected = b
that . insert _c ode_c ell_below ( ) ;
that . insert _c ell_below ( 'code' ) ;
that . control _key _active = false ;
return false ;
} else if ( event . which === 89 && that . control _key _active ) {
@ -234,29 +234,67 @@ var IPython = (function (IPython) {
// Cell indexing, retrieval, etc.
Notebook . prototype . cell _elements = function ( ) {
Notebook . prototype . get _cell _elements = function ( ) {
return this . element . children ( "div.cell" ) ;
} ;
Notebook . prototype . get _cell _element = function ( index ) {
var result = null ;
var e = this . get _cell _elements ( ) . eq ( index ) ;
if ( e . length !== 0 ) {
result = e ;
}
return result ;
} ;
Notebook . prototype . ncells = function ( cell ) {
return this . cell _elements ( ) . length ;
return this . get_ cell_elements ( ) . length ;
} ;
// TODO: we are often calling cells as cells()[i], which we should optimize
// to cells(i) or a new method.
Notebook . prototype . cells = function ( ) {
return this . cell _elements ( ) . toArray ( ) . map ( function ( e ) {
Notebook . prototype . get_ cells = function ( ) {
return this . get_ cell_elements ( ) . toArray ( ) . map ( function ( e ) {
return $ ( e ) . data ( "cell" ) ;
} ) ;
} ;
Notebook . prototype . get _cell = function ( index ) {
var result = null ;
var ce = this . get _cell _element ( index ) ;
if ( ce !== null ) {
result = ce . data ( 'cell' ) ;
}
return result ;
}
Notebook . prototype . get _next _cell = function ( cell ) {
var result = null ;
var index = this . find _cell _index ( cell ) ;
if ( index !== null && index < this . ncells ( ) ) {
result = this . get _cell ( index + 1 ) ;
}
return result ;
}
Notebook . prototype . get _prev _cell = function ( cell ) {
var result = null ;
var index = this . find _cell _index ( cell ) ;
if ( index !== null && index > 1 ) {
result = this . get _cell ( index - 1 ) ;
}
return result ;
}
Notebook . prototype . find _cell _index = function ( cell ) {
var result = null ;
this . cell _elements ( ) . filter ( function ( index ) {
this . get_ cell_elements ( ) . filter ( function ( index ) {
if ( $ ( this ) . data ( "cell" ) === cell ) {
result = index ;
} ;
@ -267,8 +305,8 @@ var IPython = (function (IPython) {
Notebook . prototype . index _or _selected = function ( index ) {
var i ;
if ( index === undefined ) {
i = this . selected_index ( ) ;
if ( index === undefined || index === null ) {
i = this . get_ selected_index ( ) ;
if ( i === null ) {
i = 0 ;
}
@ -279,38 +317,23 @@ var IPython = (function (IPython) {
} ;
Notebook . prototype . select = function ( index ) {
if ( index !== undefined && index >= 0 && index < this . ncells ( ) ) {
if ( this . selected _index ( ) !== null ) {
this . selected _cell ( ) . unselect ( ) ;
} ;
this . cells ( ) [ index ] . select ( ) ;
} ;
return this ;
} ;
Notebook . prototype . select _next = function ( ) {
var index = this . selected _index ( ) ;
if ( index !== null && index >= 0 && ( index + 1 ) < this . ncells ( ) ) {
this . select ( index + 1 ) ;
} ;
return this ;
Notebook . prototype . get _selected _cell = function ( ) {
var index = this . get _selected _index ( ) ;
return this . get _cell ( index ) ;
} ;
Notebook . prototype . select _prev = function ( ) {
var index = this . selected _index ( ) ;
if ( index !== null && index >= 0 && ( index - 1 ) < this . ncells ( ) ) {
this . select ( index - 1 ) ;
Notebook . prototype . is _valid _cell _index = function ( index ) {
if ( index !== null && index >= 0 && index < this . ncells ( ) ) {
return true ;
} else {
return false ;
} ;
return this ;
} ;
}
Notebook . prototype . selected_index = function ( ) {
Notebook . prototype . get _selected _index = function ( ) {
var result = null ;
this . cell_elements ( ) . filter ( function ( index ) {
this . get _cell _elements ( ) . filter ( function ( index ) {
if ( $ ( this ) . data ( "cell" ) . selected === true ) {
result = index ;
} ;
@ -322,7 +345,7 @@ var IPython = (function (IPython) {
Notebook . prototype . cell _for _msg = function ( msg _id ) {
var cell _id = this . msg _cell _map [ msg _id ] ;
var result = null ;
this . cell_elements ( ) . filter ( function ( index ) {
this . get_ cell_elements ( ) . filter ( function ( index ) {
cell = $ ( this ) . data ( "cell" ) ;
if ( cell . cell _id === cell _id ) {
result = cell ;
@ -332,68 +355,45 @@ var IPython = (function (IPython) {
} ;
Notebook . prototype . selected _cell = function ( ) {
return this . cell _elements ( ) . eq ( this . selected _index ( ) ) . data ( "cell" ) ;
} ;
// Cell insertion, deletion and moving.
// Cell selection.
Notebook . prototype . delete _cell = function ( index ) {
var i = this . index _or _selected ( index ) ;
if ( i !== null && i >= 0 && i < this . ncells ( ) ) {
this . cell _elements ( ) . eq ( i ) . remove ( ) ;
if ( i === ( this . ncells ( ) ) ) {
this . select ( i - 1 ) ;
} else {
this . select ( i ) ;
Notebook . prototype . select = function ( index ) {
if ( index !== undefined && index >= 0 && index < this . ncells ( ) ) {
sindex = this . get _selected _index ( )
if ( sindex !== null ) {
this . get _cell ( sindex ) . unselect ( ) ;
} ;
this . get _cell ( index ) . select ( ) ;
} ;
this . dirty = true ;
return this ;
} ;
Notebook . prototype . append _cell = function ( cell ) {
this . element . find ( 'div.end_space' ) . before ( cell . element ) ;
this . dirty = true ;
return this ;
} ;
Notebook . prototype . insert _cell _below = function ( cell , index ) {
var ncells = this . ncells ( ) ;
if ( ncells === 0 ) {
this . append _cell ( cell ) ;
return this ;
} ;
if ( index >= 0 && index < ncells ) {
this . cell _elements ( ) . eq ( index ) . after ( cell . element ) ;
Notebook . prototype . select _next = function ( ) {
var index = this . get _selected _index ( ) ;
if ( index !== null && index >= 0 && ( index + 1 ) < this . ncells ( ) ) {
this . select ( index + 1 ) ;
} ;
this . dirty = true ;
return this ;
} ;
Notebook . prototype . insert _cell _above = function ( cell , index ) {
var ncells = this . ncells ( ) ;
if ( ncells === 0 ) {
this . append _cell ( cell ) ;
return this ;
} ;
if ( index >= 0 && index < ncells ) {
this . cell _elements ( ) . eq ( index ) . before ( cell . element ) ;
Notebook . prototype . select _prev = function ( ) {
var index = this . get _selected _index ( ) ;
if ( index !== null && index >= 0 && ( index - 1 ) < this . ncells ( ) ) {
this . select ( index - 1 ) ;
} ;
this . dirty = true ;
return this ;
} ;
// Cell movement
Notebook . prototype . move _cell _up = function ( index ) {
var i = index || this . selected _index ( ) ;
var i = this . index_or _ selected( ) ;
if ( i !== null && i < this . ncells ( ) && i > 0 ) {
var pivot = this . cell_element s( ) . eq ( i - 1 ) ;
var tomove = this . cell_element s( ) . eq ( i ) ;
var pivot = this . get_ cell_element ( i - 1 ) ;
var tomove = this . get_ cell_element ( i ) ;
if ( pivot !== null && tomove !== null ) {
tomove . detach ( ) ;
pivot . before ( tomove ) ;
@ -406,10 +406,10 @@ var IPython = (function (IPython) {
Notebook . prototype . move _cell _down = function ( index ) {
var i = index || this . selected_index ( ) ;
var i = this . index_or _ selected( ) ;
if ( i !== null && i < ( this . ncells ( ) - 1 ) && i >= 0 ) {
var pivot = this . cell_element s( ) . eq ( i + 1 ) ;
var tomove = this . cell_element s( ) . eq ( i ) ;
var pivot = this . get_ cell_element ( i + 1 ) ;
var tomove = this . get_ cell_element ( i ) ;
if ( pivot !== null && tomove !== null ) {
tomove . detach ( ) ;
pivot . after ( tomove ) ;
@ -422,14 +422,16 @@ var IPython = (function (IPython) {
Notebook . prototype . sort _cells = function ( ) {
// This is not working right now. Calling this will actually crash
// the browser. I think there is an infinite loop in here...
var ncells = this . ncells ( ) ;
var sindex = this . selected _index ( ) ;
var sindex = this . get_ selected_index ( ) ;
var swapped ;
do {
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" ) ;
current = this . get_cell ( i ) ;
previous = this . get_cell ( i - 1 ) ;
if ( previous . input _prompt _number > current . input _prompt _number ) {
this . move _cell _up ( i ) ;
swapped = true ;
@ -440,146 +442,161 @@ var IPython = (function (IPython) {
return this ;
} ;
// Insertion, deletion.
Notebook . prototype . insert _code _cell _above = function ( index ) {
// TODO: Bounds check for i
var i = this . index _or _selected ( index ) ;
var cell = new IPython . CodeCell ( this ) ;
cell . set _input _prompt ( ) ;
this . insert _cell _above ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
} ;
Notebook . prototype . insert _code _cell _below = function ( index ) {
// TODO: Bounds check for i
var i = this . index _or _selected ( index ) ;
var cell = new IPython . CodeCell ( this ) ;
cell . set _input _prompt ( ) ;
this . insert _cell _below ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
} ;
Notebook . prototype . insert _html _cell _above = function ( index ) {
// TODO: Bounds check for i
var i = this . index _or _selected ( index ) ;
var cell = new IPython . HTMLCell ( this ) ;
cell . config _mathjax ( ) ;
this . insert _cell _above ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
} ;
Notebook . prototype . insert _html _cell _below = function ( index ) {
// TODO: Bounds check for i
Notebook . prototype . delete _cell = function ( index ) {
var i = this . index _or _selected ( index ) ;
var cell = new IPython . HTMLCell ( this ) ;
cell . config _mathjax ( ) ;
this . insert _cell _below ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
if ( this . is _valid _cell _index ( i ) ) {
var ce = this . get _cell _element ( i ) ;
ce . remove ( ) ;
if ( i === ( this . ncells ( ) ) ) {
this . select ( i - 1 ) ;
} else {
this . select ( i ) ;
} ;
this . dirty = true ;
} ;
return this ;
} ;
Notebook . prototype . insert _markdown _cell _above = function ( index ) {
// TODO: Bounds check for i
var i = this . index _or _selected ( index ) ;
var cell = new IPython . MarkdownCell ( this ) ;
cell . config _mathjax ( ) ;
this . insert _cell _above ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
Notebook . prototype . insert _cell _below = function ( type , index ) {
// type = ('code','html','markdown')
// index = cell index or undefined to insert below selected
index = this . index _or _selected ( index ) ;
if ( this . ncells ( ) === 0 || this . is _valid _cell _index ( index ) ) {
var cell = null ;
if ( type === 'code' ) {
var cell = new IPython . CodeCell ( this ) ;
cell . set _input _prompt ( ) ;
} else if ( type === 'markdown' ) {
var cell = new IPython . MarkdownCell ( this ) ;
cell . config _mathjax ( ) ;
} else if ( type === 'html' ) {
var cell = new IPython . HTMLCell ( this ) ;
cell . config _mathjax ( ) ;
} ;
if ( cell !== null ) {
if ( this . ncells ( ) === 0 ) {
this . element . find ( 'div.end_space' ) . before ( cell . element ) ;
this . select ( this . find _cell _index ( cell ) ) ;
this . dirty = true ;
} else if ( this . is _valid _cell _index ( index ) ) {
this . get _cell _element ( index ) . after ( cell . element ) ;
this . select ( this . find _cell _index ( cell ) ) ;
this . dirty = true ;
} ;
return cell ;
} ;
} ;
} ;
Notebook . prototype . insert _markdown _cell _below = function ( index ) {
// TODO: Bounds check for i
var i = this . index _or _selected ( index ) ;
var cell = new IPython . MarkdownCell ( this ) ;
cell . config _mathjax ( ) ;
this . insert _cell _below ( cell , i ) ;
this . select ( this . find _cell _index ( cell ) ) ;
return cell ;
Notebook . prototype . insert _cell _above = function ( type , index ) {
// type = ('code','html','markdown')
// index = cell index or undefined to insert above selected
index = this . index _or _selected ( index ) ;
if ( this . ncells ( ) === 0 || this . is _valid _cell _index ( index ) ) {
var cell = null ;
if ( type === 'code' ) {
var cell = new IPython . CodeCell ( this ) ;
cell . set _input _prompt ( ) ;
} else if ( type === 'markdown' ) {
var cell = new IPython . MarkdownCell ( this ) ;
cell . config _mathjax ( ) ;
} else if ( type === 'html' ) {
var cell = new IPython . HTMLCell ( this ) ;
cell . config _mathjax ( ) ;
} ;
if ( cell !== null ) {
if ( this . ncells ( ) === 0 ) {
this . element . find ( 'div.end_space' ) . before ( cell . element ) ;
this . select ( this . find _cell _index ( cell ) ) ;
this . dirty = true ;
} else if ( this . is _valid _cell _index ( index ) ) {
this . get _cell _element ( index ) . before ( cell . element ) ;
this . select ( this . find _cell _index ( cell ) ) ;
this . dirty = true ;
} ;
return cell ;
} ;
} ;
} ;
Notebook . prototype . to _code = function ( index ) {
// TODO: Bounds check for i
var i = this . index _or _selected ( index ) ;
var source _element = this . cell _elements ( ) . eq ( i ) ;
var source _cell = source _element . data ( "cell" ) ;
if ( ! ( source _cell instanceof IPython . CodeCell ) ) {
this . insert _code _cell _below ( i ) ;
var target _cell = this . cells ( ) [ i + 1 ] ;
var text = source _cell . get _text ( ) ;
if ( text === source _cell . placeholder ) {
text = '' ;
}
target _cell . set _text ( text ) ;
source _element . remove ( ) ;
target _cell . select ( ) ;
if ( this . is _valid _cell _index ( i ) ) {
var source _element = this . get _cell _element ( i ) ;
var source _cell = source _element . data ( "cell" ) ;
if ( ! ( source _cell instanceof IPython . CodeCell ) ) {
target _cell = this . insert _cell _below ( 'code' , i ) ;
var text = source _cell . get _text ( ) ;
if ( text === source _cell . placeholder ) {
text = '' ;
}
target _cell . set _text ( text ) ;
source _element . remove ( ) ;
target _cell . select ( ) ;
} ;
this . dirty = true ;
} ;
this . dirty = true ;
} ;
Notebook . prototype . to _markdown = function ( index ) {
// TODO: Bounds check for i
var i = this . index _or _selected ( index ) ;
var source _element = this . cell _elements ( ) . eq ( i ) ;
var source _cell = source _element . data ( "cell" ) ;
var target _cell = null ;
if ( ! ( source _cell instanceof IPython . MarkdownCell ) ) {
this . insert _markdown _cell _below ( i ) ;
target _cell = this . cells ( ) [ i + 1 ] ;
var text = source _cell . get _text ( ) ;
if ( text === source _cell . placeholder ) {
text = target _cell . placeholder ;
if ( this . is _valid _cell _index ( i ) ) {
var source _element = this . get _cell _element ( i ) ;
var source _cell = source _element . data ( "cell" ) ;
var target _cell = null ;
if ( ! ( source _cell instanceof IPython . MarkdownCell ) ) {
target _cell = this . insert _cell _below ( 'markdown' , i ) ;
var text = source _cell . get _text ( ) ;
if ( text === source _cell . placeholder ) {
text = target _cell . placeholder ;
} ;
if ( target _cell !== null ) {
if ( text === "" ) { text = target _cell . placeholder ; } ;
// The edit must come before the set_text.
target _cell . edit ( ) ;
target _cell . set _text ( text ) ;
source _element . remove ( ) ;
target _cell . select ( ) ;
}
this . dirty = true ;
} ;
if ( target _cell !== null ) {
if ( text === "" ) { text = target _cell . placeholder ; } ;
// The edit must come before the set_text.
target _cell . edit ( ) ;
target _cell . set _text ( text ) ;
source _element . remove ( ) ;
target _cell . select ( ) ;
}
this . dirty = true ;
} ;
} ;
Notebook . prototype . to _html = function ( index ) {
// TODO: Bounds check for i
var i = this . index _or _selected ( index ) ;
var source _element = this . cell _elements ( ) . eq ( i ) ;
var source _cell = source _element . data ( "cell" ) ;
var target _cell = null ;
if ( ! ( source _cell instanceof IPython . HTMLCell ) ) {
this . insert _html _cell _below ( i ) ;
target _cell = this . cells ( ) [ i + 1 ] ;
var text = source _cell . get _text ( ) ;
if ( text === source _cell . placeholder ) {
text = target _cell . placeholder ;
if ( this . is _valid _cell _index ( i ) ) {
var source _element = this . get _cell _element ( i ) ;
var source _cell = source _element . data ( "cell" ) ;
var target _cell = null ;
if ( ! ( source _cell instanceof IPython . HTMLCell ) ) {
target _cell = this . insert _cell _below ( 'html' , i ) ;
var text = source _cell . get _text ( ) ;
if ( text === source _cell . placeholder ) {
text = target _cell . placeholder ;
} ;
if ( target _cell !== null ) {
if ( text === "" ) { text = target _cell . placeholder ; } ;
// The edit must come before the set_text.
target _cell . edit ( ) ;
target _cell . set _text ( text ) ;
source _element . remove ( ) ;
target _cell . select ( ) ;
}
this . dirty = true ;
} ;
if ( target _cell !== null ) {
if ( text === "" ) { text = target _cell . placeholder ; } ;
// The edit must come before the set_text.
target _cell . edit ( ) ;
target _cell . set _text ( text ) ;
source _element . remove ( ) ;
target _cell . select ( ) ;
}
this . dirty = true ;
} ;
} ;
// C opy/Paste/Merge/Split
// Cut/Copy/Paste
Notebook . prototype . enable _paste = function ( ) {
var that = this ;
@ -611,7 +628,7 @@ var IPython = (function (IPython) {
}
Notebook . prototype . copy _cell = function ( ) {
var cell = this . selected_cell ( ) ;
var cell = this . get_ selected_cell ( ) ;
this . clipboard = cell . toJSON ( ) ;
this . enable _paste ( ) ;
} ;
@ -620,16 +637,11 @@ var IPython = (function (IPython) {
Notebook . prototype . paste _cell = function ( ) {
if ( this . clipboard !== null && this . paste _enabled ) {
var cell _data = this . clipboard ;
if ( cell _data . cell _type == 'code' ) {
new _cell = this . insert _code _cell _above ( ) ;
} else if ( cell _data . cell _type === 'html' ) {
new _cell = this . insert _html _cell _above ( ) ;
} else if ( cell _data . cell _type === 'markdown' ) {
new _cell = this . insert _markdown _cell _above ( ) ;
} ;
var new _cell = this . insert _cell _above ( cell _data . cell _type ) ;
new _cell . fromJSON ( cell _data ) ;
this . select _next ( ) ;
this . delete _cell ( ) ;
old _cell = this . get _next _cell ( new _cell ) ;
this . delete _cell ( this . find _cell _index ( old _cell ) ) ;
this . select ( this . find _cell _index ( new _cell ) ) ;
} ;
} ;
@ -637,13 +649,7 @@ var IPython = (function (IPython) {
Notebook . prototype . paste _cell _above = function ( ) {
if ( this . clipboard !== null && this . paste _enabled ) {
var cell _data = this . clipboard ;
if ( cell _data . cell _type == 'code' ) {
new _cell = this . insert _code _cell _above ( ) ;
} else if ( cell _data . cell _type === 'html' ) {
new _cell = this . insert _html _cell _above ( ) ;
} else if ( cell _data . cell _type === 'markdown' ) {
new _cell = this . insert _markdown _cell _above ( ) ;
} ;
var new _cell = this . insert _cell _above ( cell _data . cell _type ) ;
new _cell . fromJSON ( cell _data ) ;
} ;
} ;
@ -652,21 +658,17 @@ var IPython = (function (IPython) {
Notebook . prototype . paste _cell _below = function ( ) {
if ( this . clipboard !== null && this . paste _enabled ) {
var cell _data = this . clipboard ;
if ( cell _data . cell _type == 'code' ) {
new _cell = this . insert _code _cell _below ( ) ;
} else if ( cell _data . cell _type === 'html' ) {
new _cell = this . insert _html _cell _below ( ) ;
} else if ( cell _data . cell _type === 'markdown' ) {
new _cell = this . insert _markdown _cell _below ( ) ;
} ;
var new _cell = this . insert _cell _below ( cell _data . cell _type ) ;
new _cell . fromJSON ( cell _data ) ;
} ;
} ;
// Split/merge
Notebook . prototype . split _cell = function ( ) {
// Todo: implement spliting for other cell types.
var cell = this . selected_cell ( ) ;
var cell = this . get_ selected_cell ( ) ;
if ( cell instanceof IPython . CodeCell ) {
var cursor = cell . code _mirror . getCursor ( ) ;
var last _line _num = cell . code _mirror . lineCount ( ) - 1 ;
@ -677,7 +679,7 @@ var IPython = (function (IPython) {
texta = texta . replace ( /^\n+/ , '' ) . replace ( /\n+$/ , '' ) ;
textb = textb . replace ( /^\n+/ , '' ) . replace ( /\n+$/ , '' ) ;
cell . set _text ( texta ) ;
var new _cell = this . insert _c ode_c ell_below ( ) ;
var new _cell = this . insert _c ell_below ( 'code' ) ;
new _cell . set _text ( textb ) ;
} ;
} ;
@ -685,11 +687,11 @@ var IPython = (function (IPython) {
Notebook . prototype . merge _cell _above = function ( ) {
// Todo: implement merging for other cell types.
var cell = this . selected_cell ( ) ;
var index = this . selected_index ( ) ;
var cell = this . get_ selected_cell ( ) ;
var index = this . get_ selected_index ( ) ;
if ( index > 0 ) {
upper _cell = this . cells( ) [ index - 1 ] ;
lower _cell = this . cells( ) [ index ] ;
upper _cell = this . get_cell ( index - 1 ) ;
lower _cell = this . get_cell ( index ) ;
if ( upper _cell instanceof IPython . CodeCell && lower _cell instanceof IPython . CodeCell ) {
upper _text = upper _cell . get _text ( ) ;
lower _text = lower _cell . get _text ( ) ;
@ -702,11 +704,11 @@ var IPython = (function (IPython) {
Notebook . prototype . merge _cell _below = function ( ) {
// Todo: implement merging for other cell types.
var cell = this . selected_cell ( ) ;
var index = this . selected_index ( ) ;
var cell = this . get_ selected_cell ( ) ;
var index = this . get_ selected_index ( ) ;
if ( index < this . ncells ( ) - 1 ) {
upper _cell = this . cells( ) [ index ] ;
lower _cell = this . cells( ) [ index + 1 ] ;
upper _cell = this . get_cell ( index ) ;
lower _cell = this . get_cell ( index + 1 ) ;
if ( upper _cell instanceof IPython . CodeCell && lower _cell instanceof IPython . CodeCell ) {
upper _text = upper _cell . get _text ( ) ;
lower _text = lower _cell . get _text ( ) ;
@ -720,21 +722,21 @@ var IPython = (function (IPython) {
Notebook . prototype . collapse = function ( index ) {
var i = this . index _or _selected ( index ) ;
this . cells( ) [ i ] . collapse ( ) ;
this . get_cell ( i ) . collapse ( ) ;
this . dirty = true ;
} ;
Notebook . prototype . expand = function ( index ) {
var i = this . index _or _selected ( index ) ;
this . cells( ) [ i ] . expand ( ) ;
this . get_cell ( i ) . expand ( ) ;
this . dirty = true ;
} ;
Notebook . prototype . toggle _output = function ( index ) {
var i = this . index _or _selected ( index ) ;
this . cells( ) [ i ] . toggle _output ( ) ;
this . get_cell ( i ) . toggle _output ( ) ;
this . dirty = true ;
} ;
@ -752,7 +754,7 @@ var IPython = (function (IPython) {
} ;
Notebook . prototype . set _autoindent = function ( state ) {
var cells = this . cells( ) ;
var cells = this . get_ cells( ) ;
len = cells . length ;
for ( var i = 0 ; i < len ; i ++ ) {
cells [ i ] . set _autoindent ( state ) ;
@ -762,7 +764,7 @@ var IPython = (function (IPython) {
Notebook . prototype . clear _all _output = function ( ) {
var ncells = this . ncells ( ) ;
var cells = this . cells( ) ;
var cells = this . get_ cells( ) ;
for ( var i = 0 ; i < ncells ; i ++ ) {
if ( cells [ i ] instanceof IPython . CodeCell ) {
cells [ i ] . clear _output ( true , true , true ) ;
@ -774,7 +776,7 @@ var IPython = (function (IPython) {
// Other cell functions: line numbers, ...
Notebook . prototype . cell _toggle _line _numbers = function ( ) {
this . selected_cell ( ) . toggle _line _numbers ( ) ;
this . get_ selected_cell ( ) . toggle _line _numbers ( ) ;
} ;
// Kernel related things
@ -861,7 +863,7 @@ var IPython = (function (IPython) {
}
} else if ( payload [ i ] . source === 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input' ) {
var index = this . find _cell _index ( cell ) ;
var new _cell = this . insert _c ode_c ell_below ( index ) ;
var new _cell = this . insert _c ell_below ( 'code' , index ) ;
new _cell . set _text ( payload [ i ] . text ) ;
this . dirty = true ;
}
@ -981,7 +983,7 @@ var IPython = (function (IPython) {
default _options = { terminal : false , add _new : true } ;
$ . extend ( default _options , options ) ;
var that = this ;
var cell = that . selected_cell ( ) ;
var cell = that . get_ selected_cell ( ) ;
var cell _index = that . find _cell _index ( cell ) ;
if ( cell instanceof IPython . CodeCell ) {
cell . clear _output ( true , true , true ) ;
@ -997,7 +999,7 @@ var IPython = (function (IPython) {
cell . select _all ( ) ;
} else {
if ( ( cell _index === ( that . ncells ( ) - 1 ) ) && default _options . add _new ) {
that . insert _c ode_c ell_below ( ) ;
that . insert _c ell_below ( 'code' ) ;
// If we are adding a new cell at the end, scroll down to show it.
that . scroll _to _bottom ( ) ;
} else {
@ -1012,7 +1014,7 @@ var IPython = (function (IPython) {
var ncells = this . ncells ( ) ;
for ( var i = 0 ; i < ncells ; i ++ ) {
this . select ( i ) ;
this . execute _ selected_cell ( { add _new : false } ) ;
this . execute _ get_ selected_cell ( { add _new : false } ) ;
} ;
this . scroll _to _bottom ( ) ;
} ;
@ -1068,23 +1070,15 @@ var IPython = (function (IPython) {
var new _cell = null ;
for ( i = 0 ; i < ncells ; i ++ ) {
cell _data = new _cells [ i ] ;
if ( cell _data . cell _type == 'code' ) {
new _cell = this . insert _code _cell _below ( ) ;
new _cell . fromJSON ( cell _data ) ;
} else if ( cell _data . cell _type === 'html' ) {
new _cell = this . insert _html _cell _below ( ) ;
new _cell . fromJSON ( cell _data ) ;
} else if ( cell _data . cell _type === 'markdown' ) {
new _cell = this . insert _markdown _cell _below ( ) ;
new _cell . fromJSON ( cell _data ) ;
} ;
new _cell = this . insert _cell _below ( cell _data . cell _type ) ;
new _cell . fromJSON ( cell _data ) ;
} ;
} ;
} ;
Notebook . prototype . toJSON = function ( ) {
var cells = this . cells( ) ;
var cells = this . get _cells ( ) ;
var ncells = cells . length ;
cell _array = new Array ( ncells ) ;
for ( var i = 0 ; i < ncells ; i ++ ) {
@ -1161,7 +1155,7 @@ var IPython = (function (IPython) {
var allowed = xhr . getResponseHeader ( 'Allow' ) ;
this . fromJSON ( data ) ;
if ( this . ncells ( ) === 0 ) {
this . insert _c ode_c ell_below ( ) ;
this . insert _c ell_below ( 'code' ) ;
} ;
IPython . save _widget . status _last _saved ( ) ;
IPython . save _widget . set _notebook _name ( data . metadata . name ) ;