Weryfikacja podczas zapisu XML i DC. TODO: DC jeszcze nie dziaƂa tak jak powinno.
[redakcja.git] / project / templates / explorer / panels / xmleditor.html
1 {% load toolbar_tags %}
2
3 {% toolbar %}
4 <div class="change-font-size" style="">
5     <div class="decrease-font-size">A<sup>-</sup></div>
6     <div class="increase-font-size">A<sup>+</sup></div>
7 </div>
8 <div class="iframe-container" style="position: absolute; top: 48px; left:0px; right:0px; bottom: 0px;">
9         <textarea name="text">{{ text }}</textarea>
10 </div>
11
12 <script type="text/javascript" charset="utf-8">
13
14 panel_hooks = {
15         load: function () {
16                 var self = this;
17                 var panel = self.contentDiv;
18
19         var textareaId = 'xmleditor-' + Math.ceil(Math.random() * 1000000000);
20                 $('textarea', panel).attr('id', textareaId);
21
22                 var texteditor = CodeMirror.fromTextArea(textareaId, {
23             parserfile: 'parsexml.js',
24             path: "/static/js/codemirror/",
25             stylesheet: "/static/css/xmlcolors.css",
26             parserConfig: {useHTMLKludges: false},
27             onChange: function() {
28                                 panel.trigger('panel:contentChanged', self);
29             },
30             initCallback: function(editor) {
31                 // Toolbar
32                 $('.toolbar-tabs li', panel).click(function() {
33                     var id = $(this).attr('p:button-list');
34                     $('.toolbar-tabs li', panel).removeClass('active');
35                     $(this).addClass('active');
36                     if (!$('.' + id, panel).is(':visible')) {
37                         $('.toolbar-buttons ol', panel).not('#' + id).hide();
38                         $('.' + id, panel).show();
39                     }
40                 })
41                 
42                 var keys = {};
43                 $('.toolbar-buttons li', panel).each(function() {
44                     var tag = $(this).attr('p:tag');
45                     var handler = function() {
46                         var text = texteditor.selection();
47                         editor.replaceSelection('<' + tag + '>' + text + '</' + tag + '>');
48                         if (text.length == 0) {
49                             var pos = texteditor.cursorPosition();
50                             texteditor.selectLines(pos.line, pos.character + tag.length + 2);
51                         }
52                         $(document).trigger('panel:contentChanged', self);
53                     }
54                     if ($(this).attr('p:key')) {
55                         keys[$(this).attr('p:key')] = handler;
56                     }
57                     $(this).click(handler)
58                 });
59
60                 texteditor.grabKeys(function(event) { 
61                     if (keys[event.keyCode]) {
62                         keys[event.keyCode]();
63                     }
64                 }, function(event) { return event.altKey && keys[event.keyCode]; });
65             }
66         })
67         
68         $(texteditor.frame).css({width: '100%', height: '100%'});
69         
70         $('#toolbar-buttons li').wTooltip({
71             delay: 1000, 
72             style: {
73                 border: "1px solid #7F7D67",
74                 opacity: 0.9, 
75                 background: "#FBFBC6", 
76                 padding: "1px",
77                 fontSize: "12px",
78             }
79         });
80
81         $('.decrease-font-size', panel).click(function() {
82             var frameBody = $('body', $(texteditor.frame).contents());
83             console.log(frameBody.css('font-size'));
84             frameBody.css('font-size', parseInt(frameBody.css('font-size')) - 2);
85         });
86         
87         $('.increase-font-size', panel).click(function() {
88             var frameBody = $('body', $(texteditor.frame).contents());
89             console.log(frameBody.css('font-size'));
90             frameBody.css('font-size', parseInt(frameBody.css('font-size')) + 2);
91         });
92         
93                 this.texteditor = texteditor;
94     },
95
96         unload: function() { 
97                 this.texteditor = null;
98         },
99
100
101         //refresh: function() { }, // no support for refresh
102
103         saveInfo: function(saveInfo) {
104                 var myInfo = {
105                         url: "{% url file_xml fpath %}", 
106                         postData: {
107                                 content: this.texteditor.getCode()
108                         } 
109                 };
110                 $.extend(saveInfo, myInfo);
111         }               
112 };
113
114 </script>