fix
[redakcja.git] / src / redakcja / static / js / wiki / view_editor_source.js
1 (function($) {
2
3     class CodeMirrorPerspective extends $.wiki.Perspective {
4         constructor(options) {
5             super(options);
6             var self = this;
7
8             this.codemirror = CodeMirror.fromTextArea($(
9                 '#codemirror_placeholder').get(0), {
10                     mode: 'xml',
11                     lineWrapping: true,
12                     lineNumbers: true,
13                     readOnly: CurrentDocument.readonly || false,
14                     identUnit: 0,
15                 });
16
17             $('#source-editor').keydown(function(event) {
18                 if(!event.altKey)
19                     return;
20
21                 var c = event.key;
22                 var button = $("#source-editor button[data-ui-accesskey='"+c+"']");
23                 if(button.length == 0)
24                     return;
25                 button.get(0).click();
26                 event.preventDefault();
27             });
28
29             $('#source-editor .toolbar').toolbarize({
30                 actionContext: self.codemirror
31             });
32
33             // textarea is no longer needed
34             $('#codemirror_placeholder').remove();
35         }
36
37         onEnter(success, failure) {
38             super.onEnter();
39             this.codemirror.setValue(this.doc.text);
40             this.codemirror.scrollTo(0, this.config().position || 0);
41
42             if(success) success();
43         }
44
45         onExit(success, failure) {
46             super.onExit();
47             this.config().position =  this.codemirror.getScrollInfo().top;
48             this.doc.setText(this.codemirror.getValue());
49
50             $.wiki.exitTab('#SearchPerspective');
51
52             if(success) success();
53         }
54     }
55
56     $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;
57
58 })(jQuery);