1 {% extends "base.html" %}
2 {% load toolbar_tags %}
5 <script src="{{STATIC_URL}}js/lib/codemirror/codemirror.js" type="text/javascript" charset="utf-8"></script>
6 <script src="{{STATIC_URL}}js/lib/jquery.splitter.js" type="text/javascript" charset="utf-8"></script>
7 <script src="{{STATIC_URL}}js/lib/jquery.form.js" type="text/javascript" charset="utf-8"></script>
8 <script src="{{STATIC_URL}}js/button_scripts.js" type="text/javascript" charset="utf-8"></script>
9 <script type="text/javascript" charset="utf-8">
11 function serialize(element) {
12 if (element.nodeType == 3) { // tekst
13 return [$.trim(element.nodeValue)];
14 } else if (element.nodeType != 1) { // pomijamy węzły nie będące elementami XML ani tekstem
19 var hasContent = false;
22 result.push(element.tagName);
24 // Mozilla nie uważa deklaracji namespace za atrybuty
25 var ns = element.tagName.indexOf(':');
26 if (ns != -1 && $.browser.mozilla) {
27 result.push(' xmlns:');
28 result.push(element.tagName.substring(0, ns));
30 result.push(element.namespaceURI);
34 if (element.attributes) {
35 for (var i=0; i < element.attributes.length; i++) {
36 var attr = element.attributes[i];
38 result.push(attr.name);
40 result.push(attr.value);
46 if (element.childNodes.length == 0) {
51 for (var i=0; i < element.childNodes.length; i++) {
52 result = result.concat(serialize(element.childNodes[i]));
56 result.push(element.tagName);
60 if (element.tagName == 'akap' || element.tagName == 'akap_dialog') {
61 result.push('\n\n\n');
62 } else if (element.tagName == 'rdf:RDF') {
63 result.push('\n\n\n\n\n');
64 } else if (element.tagName.indexOf('dc:') != -1) {
73 var editor = CodeMirror.fromTextArea('id_text', {
74 parserfile: 'parsexml.js',
75 path: "{{ STATIC_URL }}js/lib/codemirror/",
76 stylesheet: "{{ STATIC_URL }}css/xmlcolors.css",
85 $('#splitter').splitter({
94 $(window).resize(function() {
95 $('iframe').height($(window).height() - $('#tabs').outerHeight());
100 $('.vsplitbar').dblclick(function() {
101 if ($('#sidebar').width() == 0) {
102 $('#splitter').trigger('resize', [$(window).width() - 480]);
104 $('#splitter').trigger('resize', [$(window).width()]);
108 loadSuccess = function() {
109 if (this.get('state') != 'loading') {
110 alert('erroneous state:', this.get('state'));
116 messageCenter.addMessage('success', 'xmlload', 'Wczytałem HTML :-)');
119 function createXSLT(xsl) {
120 var p = new XSLTProcessor();
121 p.importStylesheet(xsl);
125 function transform() {
127 url: '{{ STATIC_URL }}xsl/wl2html_client.xsl',
129 success: function(data) {
131 var parser = new DOMParser();
132 var serializer = new XMLSerializer();
133 var htmlXSL = createXSLT(data);
135 doc = editor.getCode().replace(/\/\s+/g, '<br />');
136 doc = parser.parseFromString(doc, 'text/xml');
137 console.log('xml', doc);
138 doc = htmlXSL.transformToFragment(doc, document);
139 console.log('after transform', doc);
140 $('#simple-editor').html(doc.firstChild);
142 error: function() {alert('Error loading XSL!')}
146 function reverseTransform () {
148 url: '{{ STATIC_URL }}xsl/html2wl_client.xsl',
150 success: function(data) {
152 var parser = new DOMParser();
153 var serializer = new XMLSerializer();
154 var xsl = createXSLT(data);
156 doc = serializer.serializeToString($('#simple-editor div').get(0))
157 doc = parser.parseFromString(doc, 'text/xml');
158 console.log('xml',doc, doc.documentElement);
159 // TODO: Sprawdzenie błędów
160 doc = xsl.transformToDocument(doc);
161 console.log('after transform', doc, doc.documentElement);
162 doc = serialize(doc.documentElement).join('');
163 // doc = serializer.serializeToString(doc.documentElement)
166 error: function() {alert('Error loading XSL!')}
170 $('#save-button').click(function(event) {
171 event.preventDefault();
172 console.log(editor.getCode(), $('form input[name=text]').get(0));
173 $('form textarea[name=text]').val(editor.getCode());
174 $('form').ajaxSubmit(function() {
179 $('#simple-view-tab').click(function() {
180 if ($(this).hasClass('active')) {
183 $(this).addClass('active');
184 $('#source-view-tab').removeClass('active');
185 $('#source-editor').hide();
186 $('#simple-editor').show();
190 $('#source-view-tab').click(function() {
191 if ($(this).hasClass('active')) {
194 $(this).addClass('active');
195 $('#simple-view-tab').removeClass('active');
196 $('#simple-editor').hide();
197 $('#source-editor').show();
201 $('.toolbar button').click(function(event) {
202 event.preventDefault();
203 var params = eval("(" + $(this).attr('ui:action-params') + ")");
204 scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
207 $('.toolbar select').change(function() {
208 var slug = $(this).val();
210 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
213 $('.toolbar-buttons-container').hide();
214 $('.toolbar select').change();
218 <style type="text/css" media="screen">
228 background: #EEE url(/static/img/gallery.png) no-repeat scroll center center;
229 border-left: 1px solid #999;
234 background-color: #DDD;
250 background-color: #C1C1C1;
251 background-image: -webkit-gradient(linear, left top, left bottom, from(#C1C1C1), color-stop(0.9, #A2A2A2));
252 font: 11px Helvetica, Verdana, sans-serif;
259 font: 17px Helvetica, Verdana, sans-serif;
262 padding: 3px 6px 2px 6px;
273 border-bottom: 1px solid #777;
277 -webkit-user-select: none;
281 padding: 5px 12px 3px 12px;
282 border: 1px solid #999;
283 -webkit-border-radius: 4px;
284 -webkit-border-bottom-left-radius: 0;
285 -webkit-border-bottom-right-radius: 0;
288 /* text-shadow: #CCC 1px 1px 1px;*/
290 background-color: #C1C1C1;
291 -webkit-box-shadow: 1px -1px 2px rgba(127, 127, 127, 0.25);
297 background-color: #FEFCDF;
298 background-image: none;
299 /* background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.25, #C1C1C1), to(#FFFFFF)); */
300 border-bottom: 1px solid #FEFCDF;
304 border-bottom: 1px solid #777;
305 background-color: #FEFCDF;
312 margin: 2px 5px 2px 0;
314 border: 1px solid #999;
322 padding: 0 5px 2px 5px;
331 .toolbar button:hover, .toolbar button:active {
334 -webkit-border-radius: 10px;
335 -moz-border-radius: 10px;
343 {% block maincontent %}
344 <form action="{% url wiki.views.document_detail document.name|urlencode %}" method="post" accept-charset="utf-8">
346 <div id="tools" style="float: right;">Wersja: {{ document.revision }}<button style="margin-left: 6px" id="save-button">Zapisz</button></div>
347 <h1>{{ document.name }}</h1>
349 <li id="simple-view-tab">Widok prosty</li>
350 <li id="source-view-tab" class="active">Widok zaawansowany</li>
352 <div style="clear: both"></div>
356 <div id="source-editor">
359 <input type="hidden" name="name" value="{{ document.name }}" />
360 <input type="hidden" name="author" value="annonymous" />
361 <input type="hidden" name="comment" value="no comment" />
362 <input type="hidden" name="revision" value="{{ document.revision }}" />
364 <div id="simple-editor" style="display: none">
368 <div id="sidebar" style="width: 200px">
369 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
370 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>