FIX: Skrypt jquery.loggin.js nie działał w Safari 4.
[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
11     function xmleditor_onload(event, panel) {
12         var textareaId = 'xmleditor-' + Math.ceil(Math.random() * 1000000000);
13         $('textarea', panel).attr('id', textareaId);
14         var editor = CodeMirror.fromTextArea(textareaId, {
15             parserfile: 'parsexml.js',
16             path: "/static/js/codemirror/",
17             stylesheet: "/static/css/xmlcolors.css",
18             parserConfig: {useHTMLKludges: false},
19             onChange: function() {
20                 $(document).trigger('panel:contentChanged', panel);
21             },
22             initCallback: function(editor) {
23                 // Toolbar
24                 $('.toolbar-tabs li', panel).click(function() {
25                     var id = $(this).attr('p:button-list');
26                     $('.toolbar-tabs li', panel).removeClass('active');
27                     $(this).addClass('active');
28                     if (!$('.' + id, panel).is(':visible')) {
29                         $('.toolbar-buttons ol', panel).not('#' + id).hide();
30                         $('.' + id, panel).show();
31                     }
32                 })
33                 
34                 var keys = {};
35                 $('.toolbar-buttons li', panel).each(function() {
36                     var tag = $(this).attr('p:tag');
37                     var handler = function() {
38                         var text = editor.selection();
39                         editor.replaceSelection('<' + tag + '>' + text + '</' + tag + '>');
40                         if (text.length == 0) {
41                             var pos = editor.cursorPosition();
42                             editor.selectLines(pos.line, pos.character + tag.length + 2);
43                         }
44                         $(document).trigger('panel:contentChanged', panel);
45                     }
46                     if ($(this).attr('p:key')) {
47                         keys[$(this).attr('p:key')] = handler;
48                     }
49                     $(this).click(handler)
50                 });
51
52                 editor.grabKeys(function(event) { 
53                     if (keys[event.keyCode]) {
54                         keys[event.keyCode]();
55                     }
56                 }, function(event) { return event.altKey && keys[event.keyCode]; });
57             }
58         })
59         
60         $(editor.frame).css({width: '100%', height: '100%'});
61         
62         $('#toolbar-buttons li').wTooltip({
63             delay: 1000, 
64             style: {
65                 border: "1px solid #7F7D67",
66                 opacity: 0.9, 
67                 background: "#FBFBC6", 
68                 padding: "1px",
69                 fontSize: "12px",
70             }
71         });
72     };
73     
74         // define the callback
75         load_callback = xmleditor_onload;
76 })();
77 </script>