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/",
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');
33 /* CM reports characters 2 times - as event and as code */
34 if((typeof event) != "object")
40 var c = String.fromCharCode(event.keyCode).toLowerCase();
41 var button = $("#source-editor button[data-ui-accesskey='"+c+"']");
42 if(button.length == 0)
45 /* it doesn't matter which button we pick - all do the same */
46 event.button = button[0];
50 $('#source-editor .toolbar').toolbarize({
51 actionContext: self.codemirror
54 console.log("Initialized CodeMirror");
56 // textarea is no longer needed
57 $('codemirror_placeholder').remove();
59 old_callback.call(self);
64 $.wiki.Perspective.call(this, options);
68 CodeMirrorPerspective.prototype = new $.wiki.Perspective();
70 CodeMirrorPerspective.prototype.freezeState = function() {
71 this.config().position = this.codemirror.win.scrollY || 0;
74 CodeMirrorPerspective.prototype.unfreezeState = function () {
75 this.codemirror.win.scroll(0, this.config().position || 0);
78 CodeMirrorPerspective.prototype.onEnter = function(success, failure) {
79 $.wiki.Perspective.prototype.onEnter.call(this);
81 console.log('Entering', this.doc);
82 this.codemirror.setCode(this.doc.text);
84 /* fix line numbers bar */
85 var $nums = $('.CodeMirror-line-numbers');
86 var barWidth = $nums.width();
88 $(this.codemirror.frame.contentDocument.body).css('padding-left', barWidth);
89 // $nums.css('left', -barWidth);
92 this.unfreezeState(this._uistate);
94 if(success) success();
97 CodeMirrorPerspective.prototype.onExit = function(success, failure) {
100 $.wiki.Perspective.prototype.onExit.call(this);
101 console.log('Exiting', this.doc);
102 this.doc.setText(this.codemirror.getCode());
104 if ($('.vsplitbar').hasClass('active') && $('#SearchPerspective').hasClass('active')) {
105 $.wiki.switchToTab('#ScanGalleryPerspective');
108 if(success) success();
111 $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;