3     function CodeMirrorPerspective(options) {
 
   4         var old_callback = options.callback;
 
   5         options.callback = function(){
 
   8             this.codemirror = CodeMirror.fromTextArea($(
 
   9                 '#codemirror_placeholder').get(0), {
 
  13                     readOnly: CurrentDocument.readonly || false,
 
  18             $('#source-editor').keydown(function(event) {
 
  23                 var button = $("#source-editor button[data-ui-accesskey='"+c+"']");
 
  24                 if(button.length == 0)
 
  26                 button.get(0).click();
 
  27                 event.preventDefault();
 
  30             $('#source-editor .toolbar').toolbarize({
 
  31                 actionContext: self.codemirror
 
  34             // textarea is no longer needed
 
  35             $('#codemirror_placeholder').remove();
 
  36             old_callback.call(self);
 
  39         $.wiki.Perspective.call(this, options);
 
  43     CodeMirrorPerspective.prototype = new $.wiki.Perspective();
 
  45     CodeMirrorPerspective.prototype.freezeState = function() {
 
  46         this.config().position =  this.codemirror.getScrollInfo().top;
 
  49     CodeMirrorPerspective.prototype.unfreezeState = function () {
 
  50         this.codemirror.scrollTo(0, this.config().position || 0);
 
  53         CodeMirrorPerspective.prototype.onEnter = function(success, failure) {
 
  54                 $.wiki.Perspective.prototype.onEnter.call(this);
 
  56                 this.codemirror.setValue(this.doc.text);
 
  58                 this.unfreezeState(this._uistate);
 
  60                 if(success) success();
 
  63         CodeMirrorPerspective.prototype.onExit = function(success, failure) {
 
  66                 $.wiki.Perspective.prototype.onExit.call(this);
 
  67             this.doc.setText(this.codemirror.getValue());
 
  69             if ($('.vsplitbar').hasClass('active') && $('#SearchPerspective').hasClass('active')) {
 
  70                 $.wiki.switchToTab('#ScanGalleryPerspective');
 
  73             if(success) success();
 
  76         $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;