4 function CodeMirrorPerspective(options)
6 var old_callback = options.callback;
7 options.callback = function(){
10 this.codemirror = CodeMirror.fromTextArea('codemirror_placeholder', {
11 parserfile: 'parsexml.js',
12 path: STATIC_URL + "js/lib/codemirror-0.8/",
13 stylesheet: STATIC_URL + "css/xmlcolors_20100906.css",
17 iframeClass: 'xml-iframe',
24 readOnly: CurrentDocument.readonly || false,
25 initCallback: function(){
27 self.codemirror.grabKeys(function(event) {
29 $(event.button).trigger('click');
32 }, function(keycode, event) {
36 var c = String.fromCharCode(keycode).toLowerCase();
37 var button = $("#source-editor button[data-ui-accesskey='"+c+"']");
38 if(button.length == 0)
41 /* it doesn't matter which button we pick - all do the same */
42 event.button = button[0];
46 $('#source-editor .toolbar').toolbarize({
47 actionContext: self.codemirror
50 console.log("Initialized CodeMirror");
52 // textarea is no longer needed
53 $('codemirror_placeholder').remove();
55 old_callback.call(self);
60 $.wiki.Perspective.call(this, options);
64 CodeMirrorPerspective.prototype = new $.wiki.Perspective();
66 CodeMirrorPerspective.prototype.freezeState = function() {
67 this.config().position = this.codemirror.win.scrollY || 0;
70 CodeMirrorPerspective.prototype.unfreezeState = function () {
71 this.codemirror.win.scroll(0, this.config().position || 0);
74 CodeMirrorPerspective.prototype.onEnter = function(success, failure) {
75 $.wiki.Perspective.prototype.onEnter.call(this);
77 console.log('Entering', this.doc);
78 this.codemirror.setCode(this.doc.text);
80 /* fix line numbers bar */
81 var $nums = $('.CodeMirror-line-numbers');
82 var barWidth = $nums.width();
84 $(this.codemirror.frame.contentDocument.body).css('padding-left', barWidth);
85 // $nums.css('left', -barWidth);
88 this.unfreezeState(this._uistate);
90 if(success) success();
93 CodeMirrorPerspective.prototype.onExit = function(success, failure) {
96 $.wiki.Perspective.prototype.onExit.call(this);
97 console.log('Exiting', this.doc);
98 this.doc.setText(this.codemirror.getCode());
100 if ($('.vsplitbar').hasClass('active') && $('#SearchPerspective').hasClass('active')) {
101 $.wiki.switchToTab('#ScanGalleryPerspective');
104 if(success) success();
107 $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;