4 function CodeMirrorPerspective(doc, callback)
6 this.perspective_id = 'CodeMirrorPerspective';
7 this.doc = doc; // document model
11 this.codemirror = CodeMirror.fromTextArea('codemirror_placeholder', {
12 parserfile: 'parsexml.js',
13 path: STATIC_URL + "js/lib/codemirror/",
14 stylesheet: STATIC_URL + "css/xmlcolors_15032010.css",
18 iframeClass: 'xml-iframe',
24 initCallback: function() {
25 $('#source-editor .toolbar button').click(function(event){
26 event.preventDefault();
27 var params = eval("(" + $(this).attr('data-ui-action-params') + ")");
28 scriptletCenter.scriptlets[$(this).attr('data-ui-action')](self.codemirror, params);
31 $('.toolbar select').change(function(event){
32 var slug = $(this).val();
34 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
38 $('.toolbar-buttons-container').hide();
39 $('.toolbar select').change();
41 console.log("Initialized CodeMirror");
42 // textarea is no longer needed
43 $('codemirror_placeholder').remove();
50 CodeMirrorPerspective.prototype = new $.wiki.Perspective();
52 CodeMirrorPerspective.prototype.freezeState = function() {
56 CodeMirrorPerspective.prototype.onEnter = function(success, failure) {
57 $.wiki.Perspective.prototype.onEnter.call(this);
59 console.log(this.doc);
60 this.codemirror.setCode(this.doc.text);
61 if(success) success();
64 CodeMirrorPerspective.prototype.onExit = function(success, failure) {
65 $.wiki.Perspective.prototype.onExit.call(this);
67 console.log(this.doc);
68 this.doc.setText(this.codemirror.getCode());
69 if(success) success();
72 $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;