1- //----------------------------------------------------------------------------
2- // Copyright (C) 2013 The IPython Development Team
3- //
4- // Distributed under the terms of the BSD License. The full license is in
5- // the file COPYING, distributed as part of this software.
6- //----------------------------------------------------------------------------
1+ // Copyright (c) IPython Development Team.
2+ // Distributed under the terms of the Modified BSD License.
73
8- //============================================================================
9- // Utility for modal dialogs with bootstrap
10- //============================================================================
11-
12- IPython . namespace ( 'IPython.dialog' ) ;
13-
14- IPython . dialog = ( function ( IPython ) {
4+ define ( [
5+ 'base/js/namespace' ,
6+ 'jquery' ,
7+ ] , function ( IPython , $ ) {
158 "use strict" ;
169
1710 var modal = function ( options ) {
11+
1812 var modal = $ ( "<div/>" )
1913 . addClass ( "modal" )
2014 . addClass ( "fade" )
@@ -79,34 +73,36 @@ IPython.dialog = (function (IPython) {
7973 } ) ;
8074 }
8175 modal . on ( "hidden.bs.modal" , function ( ) {
82- if ( IPython . notebook ) {
83- var cell = IPython . notebook . get_selected_cell ( ) ;
76+ if ( options . notebook ) {
77+ var cell = options . notebook . get_selected_cell ( ) ;
8478 if ( cell ) cell . select ( ) ;
85- IPython . keyboard_manager . enable ( ) ;
86- IPython . keyboard_manager . command_mode ( ) ;
79+ }
80+ if ( options . keyboard_manager ) {
81+ options . keyboard_manager . enable ( ) ;
82+ options . keyboard_manager . command_mode ( ) ;
8783 }
8884 } ) ;
8985
90- if ( IPython . keyboard_manager ) {
91- IPython . keyboard_manager . disable ( ) ;
86+ if ( options . keyboard_manager ) {
87+ options . keyboard_manager . disable ( ) ;
9288 }
9389
9490 return modal . modal ( options ) ;
9591 } ;
9692
97- var edit_metadata = function ( md , callback , name ) {
98- name = name || "Cell" ;
93+ var edit_metadata = function ( options ) {
94+ options . name = options . name || "Cell" ;
9995 var error_div = $ ( '<div/>' ) . css ( 'color' , 'red' ) ;
10096 var message =
101- "Manually edit the JSON below to manipulate the metadata for this " + name + "." +
97+ "Manually edit the JSON below to manipulate the metadata for this " + options . name + "." +
10298 " We recommend putting custom metadata attributes in an appropriately named sub-structure," +
10399 " so they don't conflict with those of others." ;
104100
105101 var textarea = $ ( '<textarea/>' )
106102 . attr ( 'rows' , '13' )
107103 . attr ( 'cols' , '80' )
108104 . attr ( 'name' , 'metadata' )
109- . text ( JSON . stringify ( md || { } , null , 2 ) ) ;
105+ . text ( JSON . stringify ( options . md || { } , null , 2 ) ) ;
110106
111107 var dialogform = $ ( '<div/>' ) . attr ( 'title' , 'Edit the metadata' )
112108 . append (
@@ -128,8 +124,8 @@ IPython.dialog = (function (IPython) {
128124 autoIndent : true ,
129125 mode : 'application/json' ,
130126 } ) ;
131- var modal = IPython . dialog . modal ( {
132- title : "Edit " + name + " Metadata" ,
127+ var modal = modal ( {
128+ title : "Edit " + options . name + " Metadata" ,
133129 body : dialogform ,
134130 buttons : {
135131 OK : { class : "btn-primary" ,
@@ -143,19 +139,25 @@ IPython.dialog = (function (IPython) {
143139 error_div . text ( 'WARNING: Could not save invalid JSON.' ) ;
144140 return false ;
145141 }
146- callback ( new_md ) ;
142+ options . callback ( new_md ) ;
147143 }
148144 } ,
149145 Cancel : { }
150- }
146+ } ,
147+ notebook : options . notebook ,
148+ keyboard_manager : options . keyboard_manager ,
151149 } ) ;
152150
153151 modal . on ( 'shown.bs.modal' , function ( ) { editor . refresh ( ) ; } ) ;
154152 } ;
155153
156- return {
154+ var dialog = {
157155 modal : modal ,
158156 edit_metadata : edit_metadata ,
159157 } ;
160158
161- } ( IPython ) ) ;
159+ // Backwards compatability.
160+ IPython . dialog = dialog ;
161+
162+ return dialog ;
163+ } ) ;
0 commit comments