X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/df341bdd09208d2b0f84060454cc0000df19deba..ae2a8df21e1038038cf898eb5a9d09b9ecc33f8f:/src/redakcja/static/js/wiki/view_editor_source.js diff --git a/src/redakcja/static/js/wiki/view_editor_source.js b/src/redakcja/static/js/wiki/view_editor_source.js index 988d23ca..478cb11b 100644 --- a/src/redakcja/static/js/wiki/view_editor_source.js +++ b/src/redakcja/static/js/wiki/view_editor_source.js @@ -1,78 +1,58 @@ (function($) { - function CodeMirrorPerspective(options) { - var old_callback = options.callback; - options.callback = function(){ - var self = this; + class CodeMirrorPerspective extends $.wiki.Perspective { + constructor(options) { + super(options); + var self = this; - this.codemirror = CodeMirror.fromTextArea($( + this.codemirror = CodeMirror.fromTextArea($( '#codemirror_placeholder').get(0), { mode: 'xml', lineWrapping: true, - lineNumbers: true, - readOnly: CurrentDocument.readonly || false, + lineNumbers: true, + readOnly: CurrentDocument.readonly || false, identUnit: 0, }); + $('#source-editor').keydown(function(event) { + if(!event.altKey) + return; - $('#source-editor').keydown(function(event) { - if(!event.altKey) - return; - - var c = event.key; - var button = $("#source-editor button[data-ui-accesskey='"+c+"']"); - if(button.length == 0) - return; + var c = event.key; + var button = $("#source-editor button[data-ui-accesskey='"+c+"']"); + if(button.length == 0) + return; button.get(0).click(); event.preventDefault(); - }); - - $('#source-editor .toolbar').toolbarize({ - actionContext: self.codemirror - }); - - // textarea is no longer needed - $('#codemirror_placeholder').remove(); - old_callback.call(self); - } - - $.wiki.Perspective.call(this, options); - }; - - - CodeMirrorPerspective.prototype = new $.wiki.Perspective(); - - CodeMirrorPerspective.prototype.freezeState = function() { - this.config().position = this.codemirror.getScrollInfo().top; - }; - - CodeMirrorPerspective.prototype.unfreezeState = function () { - this.codemirror.scrollTo(0, this.config().position || 0); - }; - - CodeMirrorPerspective.prototype.onEnter = function(success, failure) { - $.wiki.Perspective.prototype.onEnter.call(this); + }); - this.codemirror.setValue(this.doc.text); + $('#source-editor .toolbar').toolbarize({ + actionContext: self.codemirror + }); - this.unfreezeState(this._uistate); + // textarea is no longer needed + $('#codemirror_placeholder').remove(); + } - if(success) success(); - } + onEnter(success, failure) { + super.onEnter(); + this.codemirror.setValue(this.doc.text); + this.codemirror.scrollTo(0, this.config().position || 0); - CodeMirrorPerspective.prototype.onExit = function(success, failure) { - this.freezeState(); + if(success) success(); + } - $.wiki.Perspective.prototype.onExit.call(this); - this.doc.setText(this.codemirror.getValue()); + onExit(success, failure) { + super.onExit(); + this.config().position = this.codemirror.getScrollInfo().top; + this.doc.setText(this.codemirror.getValue()); - if ($('.vsplitbar').hasClass('active') && $('#SearchPerspective').hasClass('active')) { - $.wiki.switchToTab('#ScanGalleryPerspective'); - } + $.wiki.exitTab('#SearchPerspective'); - if(success) success(); - } + if(success) success(); + } + } - $.wiki.CodeMirrorPerspective = CodeMirrorPerspective; + $.wiki.CodeMirrorPerspective = CodeMirrorPerspective; })(jQuery);