Minor cleanup.
[redakcja.git] / platforma / static / js / wiki / source_editor.js
1 /* COMMENT */
2 (function($) {
3         
4         function CodeMirrorPerspective(doc, callback) 
5         {
6                 this.perspective_id = 'CodeMirrorPerspective';
7                 this.doc = doc;
8                 
9                 var self = this;
10                 
11                 $('#source-editor .toolbar button').click(function(event){
12             event.preventDefault();
13             var params = eval("(" + $(this).attr('ui:action-params') + ")");
14             scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
15         });
16         
17         $('.toolbar select').change(function(event){
18             var slug = $(this).val();
19             
20             $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
21             $(window).resize();
22         });
23         
24         $('.toolbar-buttons-container').hide();
25         $('.toolbar select').change();
26                 
27                 this.codemirror = CodeMirror.fromTextArea('codemirror_placeholder', {                   
28                         parserfile: 'parsexml.js',
29                         path: STATIC_URL + "js/lib/codemirror/",
30                         stylesheet: STATIC_URL + "css/xmlcolors_15032010.css",
31                         parserConfig: {
32                                 useHTMLKludges: false
33                         },
34                         iframeClass: 'xml-iframe',
35                         textWrapping: true,
36                         lineNumbers: true,
37                         width: "100%",
38                         tabMode: 'spaces',
39                         indentUnit: 0,
40                         initCallback: function() {
41                                 console.log("Initialized CodeMirror");
42                                 callback.call(self);
43                         }       
44                 });
45         };
46         
47         
48         CodeMirrorPerspective.prototype = new $.wiki.Perspective();
49         
50         CodeMirrorPerspective.prototype.freezeState = function() {
51                 
52         };
53         
54         CodeMirrorPerspective.prototype.onEnter = function(success, failure) {
55                 $.wiki.Perspective.prototype.onEnter.call(this);
56         
57                 console.log(this.doc);
58                 this.codemirror.setCode(this.doc.text);
59                 if(success) success();
60         }
61         
62         $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;
63                 
64 })(jQuery);