##// END OF EJS Templates
Saving files works
Saving files works

File last commit:

r19012:08916002
r19012:08916002
Show More
main.js
72 lines | 2.1 KiB | application/javascript | JavascriptLexer
Thomas Kluyver
Basic infrastructure for new texteditor component
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
Saving files works
r19012 'base/js/events',
Thomas Kluyver
Loading a file works
r19011 'contents',
Thomas Kluyver
Basic infrastructure for new texteditor component
r19010 'codemirror/lib/codemirror',
Thomas Kluyver
Saving files works
r19012 'texteditor/js/menubar',
Thomas Kluyver
Loading a file works
r19011 'codemirror/mode/meta',
Thomas Kluyver
Basic infrastructure for new texteditor component
r19010 'custom/custom',
], function(
Thomas Kluyver
Saving files works
r19012 $,
Thomas Kluyver
Basic infrastructure for new texteditor component
r19010 utils,
page,
Thomas Kluyver
Saving files works
r19012 events,
Thomas Kluyver
Loading a file works
r19011 contents,
Thomas Kluyver
Saving files works
r19012 CodeMirror,
menubar
Thomas Kluyver
Basic infrastructure for new texteditor component
r19010 ){
page = new page.Page();
var base_url = utils.get_body_data('baseUrl');
Thomas Kluyver
Loading a file works
r19011 contents = new contents.Contents({base_url: base_url});
Thomas Kluyver
Basic infrastructure for new texteditor component
r19010
Thomas Kluyver
Loading a file works
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
Saving files works
r19012 basename = file_path.substring(ix+1);
Thomas Kluyver
Loading a file works
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
Saving files works
r19012 var menus = new menubar.MenuBar('#menubar', {
base_url: base_url,
codemirror: cm,
contents: contents,
events: events,
file_path: file_path
});
Thomas Kluyver
Loading a file works
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
Basic infrastructure for new texteditor component
r19010 });