main.js
72 lines
| 2.1 KiB
| application/javascript
|
JavascriptLexer
Thomas Kluyver
|
r19010 | // Copyright (c) IPython Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||||
require([ | ||||
'jquery', | ||||
'base/js/utils', | ||||
'base/js/page', | ||||
Thomas Kluyver
|
r19012 | 'base/js/events', | ||
Thomas Kluyver
|
r19011 | 'contents', | ||
Thomas Kluyver
|
r19010 | 'codemirror/lib/codemirror', | ||
Thomas Kluyver
|
r19012 | 'texteditor/js/menubar', | ||
Thomas Kluyver
|
r19011 | 'codemirror/mode/meta', | ||
Thomas Kluyver
|
r19010 | 'custom/custom', | ||
], function( | ||||
Thomas Kluyver
|
r19012 | $, | ||
Thomas Kluyver
|
r19010 | utils, | ||
page, | ||||
Thomas Kluyver
|
r19012 | events, | ||
Thomas Kluyver
|
r19011 | contents, | ||
Thomas Kluyver
|
r19012 | CodeMirror, | ||
menubar | ||||
Thomas Kluyver
|
r19010 | ){ | ||
page = new page.Page(); | ||||
var base_url = utils.get_body_data('baseUrl'); | ||||
Thomas Kluyver
|
r19011 | contents = new contents.Contents({base_url: base_url}); | ||
Thomas Kluyver
|
r19010 | |||
Thomas Kluyver
|
r19011 | var file_path = utils.get_body_data('filePath'); | ||
var ix = file_path.lastIndexOf("/"); | ||||
var dir_path, basename; | ||||
if (ix == -1) { | ||||
dir_path = ''; | ||||
basename = file_path; | ||||
} else { | ||||
dir_path = file_path.substring(0, ix); | ||||
Thomas Kluyver
|
r19012 | basename = file_path.substring(ix+1); | ||
Thomas Kluyver
|
r19011 | } | ||
contents.load(dir_path, basename, { | ||||
success: function(model) { | ||||
page.show(); | ||||
if (model.type === "file" && model.format === "text") { | ||||
console.log(modeinfo); | ||||
var cm = CodeMirror($('#texteditor-container')[0], { | ||||
value: model.content, | ||||
}); | ||||
Thomas Kluyver
|
r19012 | var menus = new menubar.MenuBar('#menubar', { | ||
base_url: base_url, | ||||
codemirror: cm, | ||||
contents: contents, | ||||
events: events, | ||||
file_path: file_path | ||||
}); | ||||
Thomas Kluyver
|
r19011 | // Find and load the highlighting mode | ||
var modeinfo = CodeMirror.findModeByMIME(model.mimetype); | ||||
if (modeinfo) { | ||||
utils.requireCodeMirrorMode(modeinfo.mode, function() { | ||||
cm.setOption('mode', modeinfo.mode); | ||||
}); | ||||
} | ||||
// Attach to document for debugging | ||||
document.cm_instance = cm; | ||||
} else { | ||||
$('#texteditor-container').append( | ||||
$('<p/>').text(dir_path + " is not a text file") | ||||
); | ||||
} | ||||
} | ||||
}); | ||||
Thomas Kluyver
|
r19010 | }); | ||