Show More
@@ -31,6 +31,7 b' function($,' | |||
|
31 | 31 | this.file_path = options.file_path; |
|
32 | 32 | this.config = options.config; |
|
33 | 33 | this.codemirror = new CodeMirror($(this.selector)[0]); |
|
34 | this.generation = -1; | |
|
34 | 35 | |
|
35 | 36 | // It appears we have to set commands on the CodeMirror class, not the |
|
36 | 37 | // instance. I'd like to be wrong, but since there should only be one CM |
@@ -79,6 +80,7 b' function($,' | |||
|
79 | 80 | cm.setOption('mode', mode); |
|
80 | 81 | }); |
|
81 | 82 | that.save_enabled = true; |
|
83 | that.generation = cm.changeGeneration(); | |
|
82 | 84 | }, |
|
83 | 85 | function(error) { |
|
84 | 86 | cm.setValue("Error! " + error.message + |
@@ -101,6 +103,8 b' function($,' | |||
|
101 | 103 | content: this.codemirror.getValue(), |
|
102 | 104 | }; |
|
103 | 105 | var that = this; |
|
106 | // record change generation for isClean | |
|
107 | this.generation = this.codemirror.changeGeneration(); | |
|
104 | 108 | return this.contents.save(this.file_path, model).then(function() { |
|
105 | 109 | that.events.trigger("save_succeeded.TextEditor"); |
|
106 | 110 | }); |
@@ -19,7 +19,7 b' require([' | |||
|
19 | 19 | events, |
|
20 | 20 | contents, |
|
21 | 21 | configmod, |
|
22 |
edit |
|
|
22 | editmod, | |
|
23 | 23 | menubar, |
|
24 | 24 | notificationarea |
|
25 | 25 | ){ |
@@ -28,10 +28,10 b' require([' | |||
|
28 | 28 | var base_url = utils.get_body_data('baseUrl'); |
|
29 | 29 | var file_path = utils.get_body_data('filePath'); |
|
30 | 30 | contents = new contents.Contents({base_url: base_url}); |
|
31 | var config = new configmod.ConfigSection('edit', {base_url: base_url}) | |
|
31 | var config = new configmod.ConfigSection('edit', {base_url: base_url}); | |
|
32 | 32 | config.load(); |
|
33 | 33 | |
|
34 |
var editor = new edit |
|
|
34 | var editor = new editmod.Editor('#texteditor-container', { | |
|
35 | 35 | base_url: base_url, |
|
36 | 36 | events: events, |
|
37 | 37 | contents: contents, |
@@ -63,4 +63,11 b' require([' | |||
|
63 | 63 | }); |
|
64 | 64 | editor.load(); |
|
65 | 65 | page.show(); |
|
66 | ||
|
67 | window.onbeforeunload = function () { | |
|
68 | if (!editor.codemirror.isClean(editor.generation)) { | |
|
69 | return "Unsaved changes will be lost. Close anyway?"; | |
|
70 | } | |
|
71 | }; | |
|
72 | ||
|
66 | 73 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now