X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/df341bdd09208d2b0f84060454cc0000df19deba..cb900d10b9d0d42b0b6aa035be45dcbaa2f61af6:/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..0766acfb 100644 --- a/src/redakcja/static/js/wiki/view_editor_source.js +++ b/src/redakcja/static/js/wiki/view_editor_source.js @@ -1,78 +1,73 @@ (function($) { - function CodeMirrorPerspective(options) { - var old_callback = options.callback; - options.callback = function(){ - var self = this; - - this.codemirror = CodeMirror.fromTextArea($( - '#codemirror_placeholder').get(0), { - mode: 'xml', - lineWrapping: true, - lineNumbers: true, - readOnly: CurrentDocument.readonly || false, - identUnit: 0, + class CodeMirrorPerspective extends $.wiki.Perspective { + constructor(options) { + var old_callback = options.callback; + options.callback = function(){ + var self = this; + + this.codemirror = CodeMirror.fromTextArea($( + '#codemirror_placeholder').get(0), { + mode: 'xml', + lineWrapping: true, + lineNumbers: true, + readOnly: CurrentDocument.readonly || false, + identUnit: 0, + }); + + $('#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; + button.get(0).click(); + event.preventDefault(); }); + $('#source-editor .toolbar').toolbarize({ + actionContext: self.codemirror + }); - $('#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; - 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(); + // textarea is no longer needed + $('#codemirror_placeholder').remove(); + old_callback.call(self); + } + super(options); + } - CodeMirrorPerspective.prototype.freezeState = function() { - this.config().position = this.codemirror.getScrollInfo().top; - }; + freezeState() { + this.config().position = this.codemirror.getScrollInfo().top; + } - CodeMirrorPerspective.prototype.unfreezeState = function () { - this.codemirror.scrollTo(0, this.config().position || 0); - }; + unfreezeState () { + this.codemirror.scrollTo(0, this.config().position || 0); + } - CodeMirrorPerspective.prototype.onEnter = function(success, failure) { - $.wiki.Perspective.prototype.onEnter.call(this); + onEnter(success, failure) { + super.onEnter(); - this.codemirror.setValue(this.doc.text); + this.codemirror.setValue(this.doc.text); - this.unfreezeState(this._uistate); + this.unfreezeState(this._uistate); - if(success) success(); - } + if(success) success(); + } - CodeMirrorPerspective.prototype.onExit = function(success, failure) { - this.freezeState(); + onExit(success, failure) { + this.freezeState(); - $.wiki.Perspective.prototype.onExit.call(this); - this.doc.setText(this.codemirror.getValue()); + super.onExit(); + 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);