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_15032010.css",
17 iframeClass: 'xml-iframe',
23 readOnly: CurrentDocument.readonly || false,
24 initCallback: function(){
26 self.codemirror.grabKeys(function(event) {
28 $(event.button).trigger('click');
32 /* CM reports characters 2 times - as event and as code */
33 if((typeof event) != "object")
39 var c = String.fromCharCode(event.keyCode).toLowerCase();
40 var button = $("#source-editor button[data-ui-accesskey='"+c+"']");
41 if(button.length == 0)
44 /* it doesn't matter which button we pick - all do the same */
45 event.button = button[0];
49 $('#source-editor .toolbar').toolbarize({
50 actionContext: self.codemirror
53 console.log("Initialized CodeMirror");
55 // textarea is no longer needed
56 $('codemirror_placeholder').remove();
58 old_callback.call(self);
63 $.wiki.Perspective.call(this, options);
67 CodeMirrorPerspective.prototype = new $.wiki.Perspective();
69 CodeMirrorPerspective.prototype.freezeState = function() {
70 this.config().position = this.codemirror.win.scrollY || 0;
73 CodeMirrorPerspective.prototype.unfreezeState = function () {
74 this.codemirror.win.scroll(0, this.config().position || 0);
77 CodeMirrorPerspective.prototype.onEnter = function(success, failure) {
78 $.wiki.Perspective.prototype.onEnter.call(this);
80 console.log('Entering', this.doc);
81 this.codemirror.setCode(this.doc.text);
83 /* fix line numbers bar */
84 var $nums = $('.CodeMirror-line-numbers');
85 var barWidth = $nums.width();
87 $(this.codemirror.frame.contentDocument.body).css('padding-left', barWidth);
88 // $nums.css('left', -barWidth);
91 this.unfreezeState(this._uistate);
93 if(success) success();
96 CodeMirrorPerspective.prototype.onExit = function(success, failure) {
99 $.wiki.Perspective.prototype.onExit.call(this);
100 console.log('Exiting', this.doc);
101 this.doc.setText(this.codemirror.getCode());
103 if(success) success();
106 $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;