Show More
@@ -0,0 +1,70 b'' | |||||
|
1 | // Copyright (c) IPython Development Team. | |||
|
2 | // Distributed under the terms of the Modified BSD License. | |||
|
3 | ||||
|
4 | define([ | |||
|
5 | 'base/js/namespace', | |||
|
6 | 'jquery', | |||
|
7 | 'base/js/utils', | |||
|
8 | 'bootstrap', | |||
|
9 | ], function(IPython, $, utils, bootstrap) { | |||
|
10 | "use strict"; | |||
|
11 | ||||
|
12 | var MenuBar = function (selector, options) { | |||
|
13 | // Constructor | |||
|
14 | // | |||
|
15 | // A MenuBar Class to generate the menubar of IPython notebook | |||
|
16 | // | |||
|
17 | // Parameters: | |||
|
18 | // selector: string | |||
|
19 | // options: dictionary | |||
|
20 | // Dictionary of keyword arguments. | |||
|
21 | // codemirror: CodeMirror instance | |||
|
22 | // contents: ContentManager instance | |||
|
23 | // events: $(Events) instance | |||
|
24 | // base_url : string | |||
|
25 | // file_path : string | |||
|
26 | options = options || {}; | |||
|
27 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); | |||
|
28 | this.selector = selector; | |||
|
29 | this.codemirror = options.codemirror; | |||
|
30 | this.contents = options.contents; | |||
|
31 | this.events = options.events; | |||
|
32 | this.file_path = options.file_path; | |||
|
33 | ||||
|
34 | if (this.selector !== undefined) { | |||
|
35 | this.element = $(selector); | |||
|
36 | this.bind_events(); | |||
|
37 | } | |||
|
38 | }; | |||
|
39 | ||||
|
40 | MenuBar.prototype.bind_events = function () { | |||
|
41 | // File | |||
|
42 | var that = this; | |||
|
43 | this.element.find('#save_file').click(function () { | |||
|
44 | var ix = that.file_path.lastIndexOf("/"); | |||
|
45 | var dir_path, basename; | |||
|
46 | if (ix === -1) { | |||
|
47 | dir_path = ''; | |||
|
48 | basename = that.file_path; | |||
|
49 | } else { | |||
|
50 | dir_path = that.file_path.substring(0, ix); | |||
|
51 | basename = that.file_path.substring(ix+1); | |||
|
52 | } | |||
|
53 | var model = { | |||
|
54 | path: dir_path, | |||
|
55 | name: basename, | |||
|
56 | type: 'file', | |||
|
57 | format: 'text', | |||
|
58 | content: that.codemirror.getValue(), | |||
|
59 | }; | |||
|
60 | console.log(model); | |||
|
61 | that.contents.save(dir_path, basename, model, { | |||
|
62 | success: function() { | |||
|
63 | that.events.trigger("save_succeeded.TextEditor"); | |||
|
64 | } | |||
|
65 | }); | |||
|
66 | }); | |||
|
67 | }; | |||
|
68 | ||||
|
69 | return {'MenuBar': MenuBar}; | |||
|
70 | }); |
@@ -5,16 +5,20 b' require([' | |||||
5 | 'jquery', |
|
5 | 'jquery', | |
6 | 'base/js/utils', |
|
6 | 'base/js/utils', | |
7 | 'base/js/page', |
|
7 | 'base/js/page', | |
|
8 | 'base/js/events', | |||
8 | 'contents', |
|
9 | 'contents', | |
9 | 'codemirror/lib/codemirror', |
|
10 | 'codemirror/lib/codemirror', | |
|
11 | 'texteditor/js/menubar', | |||
10 | 'codemirror/mode/meta', |
|
12 | 'codemirror/mode/meta', | |
11 | 'custom/custom', |
|
13 | 'custom/custom', | |
12 | ], function( |
|
14 | ], function( | |
13 |
$, |
|
15 | $, | |
14 | utils, |
|
16 | utils, | |
15 | page, |
|
17 | page, | |
|
18 | events, | |||
16 | contents, |
|
19 | contents, | |
17 | CodeMirror |
|
20 | CodeMirror, | |
|
21 | menubar | |||
18 | ){ |
|
22 | ){ | |
19 | page = new page.Page(); |
|
23 | page = new page.Page(); | |
20 |
|
24 | |||
@@ -29,7 +33,7 b' require([' | |||||
29 | basename = file_path; |
|
33 | basename = file_path; | |
30 | } else { |
|
34 | } else { | |
31 | dir_path = file_path.substring(0, ix); |
|
35 | dir_path = file_path.substring(0, ix); | |
32 | basename = file_path.substring(ix); |
|
36 | basename = file_path.substring(ix+1); | |
33 | } |
|
37 | } | |
34 | contents.load(dir_path, basename, { |
|
38 | contents.load(dir_path, basename, { | |
35 | success: function(model) { |
|
39 | success: function(model) { | |
@@ -40,6 +44,14 b' require([' | |||||
40 | value: model.content, |
|
44 | value: model.content, | |
41 | }); |
|
45 | }); | |
42 |
|
46 | |||
|
47 | var menus = new menubar.MenuBar('#menubar', { | |||
|
48 | base_url: base_url, | |||
|
49 | codemirror: cm, | |||
|
50 | contents: contents, | |||
|
51 | events: events, | |||
|
52 | file_path: file_path | |||
|
53 | }); | |||
|
54 | ||||
43 | // Find and load the highlighting mode |
|
55 | // Find and load the highlighting mode | |
44 | var modeinfo = CodeMirror.findModeByMIME(model.mimetype); |
|
56 | var modeinfo = CodeMirror.findModeByMIME(model.mimetype); | |
45 | if (modeinfo) { |
|
57 | if (modeinfo) { |
@@ -17,6 +17,37 b' data-file-path="{{file_path}}"' | |||||
17 |
|
17 | |||
18 | {% block site %} |
|
18 | {% block site %} | |
19 |
|
19 | |||
|
20 | <div id="menubar-container" class="container"> | |||
|
21 | <div id="menubar"> | |||
|
22 | <div id="menus" class="navbar navbar-default" role="navigation"> | |||
|
23 | <div class="container-fluid"> | |||
|
24 | <button type="button" class="btn btn-default navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | |||
|
25 | <i class="fa fa-bars"></i> | |||
|
26 | <span class="navbar-text">Menu</span> | |||
|
27 | </button> | |||
|
28 | <ul class="nav navbar-nav navbar-right"> | |||
|
29 | <li id="kernel_indicator"> | |||
|
30 | <i id="kernel_indicator_icon"></i> | |||
|
31 | </li> | |||
|
32 | <li id="modal_indicator"> | |||
|
33 | <i id="modal_indicator_icon"></i> | |||
|
34 | </li> | |||
|
35 | <li id="notification_area"></li> | |||
|
36 | </ul> | |||
|
37 | <div class="navbar-collapse collapse"> | |||
|
38 | <ul class="nav navbar-nav"> | |||
|
39 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">File</a> | |||
|
40 | <ul id="file_menu" class="dropdown-menu"> | |||
|
41 | <li id="save_file"><a href="#">Save</a></li> | |||
|
42 | </ul> | |||
|
43 | </li> | |||
|
44 | </ul> | |||
|
45 | </div> | |||
|
46 | </div> | |||
|
47 | </div> | |||
|
48 | </div> | |||
|
49 | </div> | |||
|
50 | ||||
20 | <div id="texteditor-container"></div> |
|
51 | <div id="texteditor-container"></div> | |
21 |
|
52 | |||
22 | {% endblock %} |
|
53 | {% endblock %} |
General Comments 0
You need to be logged in to leave comments.
Login now