89990a4aa9d230f20f4a8cd0f3406f2cec8535f7
[redakcja.git] / project / templates / explorer / panels / xmleditor.html
1 {% load toolbar_tags %}
2
3 {% toolbar %}
4 <div class="iframe-container" style="position: absolute; top: 48px; left:0px; right:0px; bottom: 0px;">
5         <textarea name="text">{{ text }}</textarea>
6 </div>
7
8 <script type="text/javascript" charset="utf-8">
9 (function() {
10     function xmleditor_onload(event, me) {
11         var textareaId = 'xmleditor-' + Math.ceil(Math.random() * 1000000000);
12         $('textarea', me).attr('id', textareaId);
13         var editor = CodeMirror.fromTextArea(textareaId, {
14             parserfile: 'parsexml.js',
15             path: "/static/js/codemirror/",
16             stylesheet: "/static/css/xmlcolors.css",
17             parserConfig: {useHTMLKludges: false},
18             initCallback: function() {
19                 // Toolbar
20                 $('#toolbar-tabs li', panel).click(function() {
21                     var id = $(this).attr('p:button-list');
22                     $('#toolbar-tabs li', panel).removeClass('active');
23                     $(this).addClass('active');
24                     if (!$('#' + id).is(':visible')) {
25                         $('#toolbar-buttons ol', panel).not('#' + id).hide();
26                         $('#' + id, panel).show();
27                     }
28                 })
29                 
30                 var keys = {};
31                 $('#toolbar-buttons li', panel).each(function() {
32                     var tag = $(this).attr('p:tag');
33                     var handler = function() {
34                         var text = editor.selection();
35                         editor.replaceSelection('<' + tag + '>' + text + '</' + tag + '>');
36                         if (text.length == 0) {
37                             var pos = editor.cursorPosition();
38                             editor.selectLines(pos.line, pos.character + tag.length + 2);
39                         }
40                     }
41                     if ($(this).attr('p:key')) {
42                         keys[$(this).attr('p:key')] = handler;
43                     }
44                     $(this).click(handler)
45                 });
46
47                 editor.grabKeys(function(event) { 
48                     if (keys[event.keyCode]) {
49                         keys[event.keyCode]();
50                     }
51                 }, function(event) { return event.altKey && keys[event.keyCode]; });
52             }
53         })
54         
55         $(editor.frame).css({width: '100%', height: '100%'});
56         
57         $('#toolbar-buttons li').wTooltip({
58             delay: 1000, 
59             style: {
60                 border: "1px solid #7F7D67",
61                 opacity: 0.9, 
62                 background: "#FBFBC6", 
63                 padding: "1px",
64                 fontSize: "12px",
65             }
66         });
67     };
68     
69     function xmleditor_onunload(event, me) {}
70     
71     panel(xmleditor_onload, xmleditor_onunload);
72 })();
73 </script>