* End of javascript refactoring: both editors, history and gallery work as expected.
[redakcja.git] / platforma / static / js / wiki / source_editor.js
1 /* COMMENT */
2 (function($) {
3         
4         function CodeMirrorPerspective(options) 
5         {
6                 var old_callback = options.callback;        
7         options.callback = function(){          
8                         var self = this;
9                         
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",
14                                 parserConfig: {
15                                         useHTMLKludges: false
16                                 },
17                                 iframeClass: 'xml-iframe',
18                                 textWrapping: true,
19                                 lineNumbers: false,
20                                 width: "100%",
21                                 tabMode: 'spaces',
22                                 indentUnit: 0,
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);
28                                         });
29                                         
30                                         $('.toolbar select').change(function(event){
31                                                 var slug = $(this).val();
32                                                 
33                                                 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
34                                                 $(window).resize();
35                                         });
36                                         
37                                         $('.toolbar-buttons-container').hide();
38                                         $('.toolbar select').change();
39                                         
40                                         console.log("Initialized CodeMirror");
41                                         // textarea is no longer needed
42                                         $('codemirror_placeholder').remove();
43                                         old_callback.call(self);
44                                 }
45                         });     
46                 };
47                 
48                 $.wiki.Perspective.call(this, options);
49         };
50         
51         
52         CodeMirrorPerspective.prototype = new $.wiki.Perspective();
53         
54         CodeMirrorPerspective.prototype.freezeState = function() {
55                 
56         };
57         
58         CodeMirrorPerspective.prototype.onEnter = function(success, failure) {
59                 $.wiki.Perspective.prototype.onEnter.call(this);
60         
61                 console.log('Entering', this.doc);
62                 this.codemirror.setCode(this.doc.text);
63                 if(success) success();
64         }
65         
66         CodeMirrorPerspective.prototype.onExit = function(success, failure) {
67                 $.wiki.Perspective.prototype.onExit.call(this);
68         
69                 console.log('Exiting', this.doc);
70                 this.doc.setText(this.codemirror.getCode());
71                 if(success) success();
72         }
73         
74         $.wiki.CodeMirrorPerspective = CodeMirrorPerspective;
75                 
76 })(jQuery);