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(){
24 $('#source-editor .toolbar button').click(function(event){
25 event.preventDefault();
26 var params = eval("(" + $(this).attr('data-ui-action-params') + ")");
27 scriptletCenter.scriptlets[$(this).attr('data-ui-action')](self.codemirror, params);
30 $('.toolbar select').change(function(event){
31 var slug = $(this).val();
33 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
37 $('.toolbar-buttons-container').hide();
38 $('.toolbar select').change();
40 console.log("Initialized CodeMirror");
41 // textarea is no longer needed
42 $('codemirror_placeholder').remove();
43 old_callback.call(self);
48 $.wiki.Perspective.call(this, options);
52 CodeMirrorPerspective.prototype = new $.wiki.Perspective();
54 CodeMirrorPerspective.prototype.freezeState = function() {
58 CodeMirrorPerspective.prototype.onEnter = function(success, failure) {
59 $.wiki.Perspective.prototype.onEnter.call(this);
61 console.log('Entering', this.doc);
62 this.codemirror.setCode(this.doc.text);
63 if(success) success();
66 CodeMirrorPerspective.prototype.onExit = function(success, failure) {
67 $.wiki.Perspective.prototype.onExit.call(this);
69 console.log('Exiting', this.doc);
70 this.doc.setText(this.codemirror.getCode());
71 if(success) success();
74 $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;