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 initCallback: function(){
25 self.codemirror.grabKeys(function(event) {
27 $(event.button).trigger('click');
31 /* CM reports characters 2 times - as event and as code */
32 if((typeof event) != "object")
38 var c = String.fromCharCode(event.keyCode).toLowerCase();
39 var button = $("#source-editor button[data-ui-accesskey='"+c+"']");
40 if(button.length == 0)
43 /* it doesn't matter which button we pick - all do the same */
44 event.button = button[0];
48 $('#source-editor .toolbar button').click(function(event){
49 event.preventDefault();
50 var params = eval("(" + $(this).attr('data-ui-action-params') + ")");
51 scriptletCenter.scriptlets[$(this).attr('data-ui-action')](self.codemirror, params);
54 $('.toolbar select').change(function(event){
55 var slug = $(this).val();
57 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
61 $('.toolbar-buttons-container').hide();
62 $('.toolbar select').change();
64 console.log("Initialized CodeMirror");
65 // textarea is no longer needed
66 $('codemirror_placeholder').remove();
67 old_callback.call(self);
72 $.wiki.Perspective.call(this, options);
76 CodeMirrorPerspective.prototype = new $.wiki.Perspective();
78 CodeMirrorPerspective.prototype.freezeState = function() {
82 CodeMirrorPerspective.prototype.onEnter = function(success, failure) {
83 $.wiki.Perspective.prototype.onEnter.call(this);
85 console.log('Entering', this.doc);
86 this.codemirror.setCode(this.doc.text);
87 if(success) success();
90 CodeMirrorPerspective.prototype.onExit = function(success, failure) {
91 $.wiki.Perspective.prototype.onExit.call(this);
93 console.log('Exiting', this.doc);
94 this.doc.setText(this.codemirror.getCode());
95 if(success) success();
98 $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;