1 function serialize(element) {
2 if (element.nodeType == 3) { // tekst
3 return [$.trim(element.nodeValue)];
4 } else if (element.nodeType != 1) { // pomijamy węzły nie będące elementami XML ani tekstem
9 var hasContent = false;
12 result.push(element.tagName);
14 // Mozilla nie uważa deklaracji namespace za atrybuty
15 var ns = element.tagName.indexOf(':');
16 if (ns != -1 && $.browser.mozilla) {
17 result.push(' xmlns:');
18 result.push(element.tagName.substring(0, ns));
20 result.push(element.namespaceURI);
24 if (element.attributes) {
25 for (var i=0; i < element.attributes.length; i++) {
26 var attr = element.attributes[i];
28 result.push(attr.name);
30 result.push(attr.value);
36 if (element.childNodes.length == 0) {
41 for (var i=0; i < element.childNodes.length; i++) {
42 result = result.concat(serialize(element.childNodes[i]));
46 result.push(element.tagName);
50 if (element.tagName == 'akap' || element.tagName == 'akap_dialog' || element.tagName == 'akap_cd') {
51 result.push('\n\n\n');
52 } else if (element.tagName == 'rdf:RDF') {
53 result.push('\n\n\n\n\n');
54 } else if (element.tagName.indexOf('dc:') != -1) {
63 var editor = CodeMirror.fromTextArea('id_text', {
64 parserfile: 'parsexml.js',
65 path: "/static/js/lib/codemirror/",
66 stylesheet: "/static/css/xmlcolors.css",
75 $('#splitter').splitter({
84 $(window).resize(function() {
85 $('iframe').height($(window).height() - $('#tabs').outerHeight());
90 $('.vsplitbar').dblclick(function() {
91 if ($('#sidebar').width() == 0) {
92 $('#splitter').trigger('resize', [$(window).width() - 480]);
94 $('#splitter').trigger('resize', [$(window).width()]);
98 loadSuccess = function() {
99 if (this.get('state') != 'loading') {
100 alert('erroneous state:', this.get('state'));
104 function createXSLT(xsl) {
105 var p = new XSLTProcessor();
106 p.importStylesheet(xsl);
110 function transform() {
112 url: '/static/xsl/wl2html_client.xsl',
114 success: function(data) {
116 var parser = new DOMParser();
117 var serializer = new XMLSerializer();
118 var htmlXSL = createXSLT(data);
120 doc = editor.getCode().replace(/\/\s+/g, '<br />');
121 doc = parser.parseFromString(doc, 'text/xml');
122 console.log('xml', doc);
123 doc = htmlXSL.transformToFragment(doc, document);
124 console.log('after transform', doc);
125 $('#html-view').html(doc.firstChild);
127 error: function() {alert('Error loading XSL!')}
131 function reverseTransform () {
133 url: '/static/xsl/html2wl_client.xsl',
135 success: function(data) {
137 var parser = new DOMParser();
138 var serializer = new XMLSerializer();
139 var xsl = createXSLT(data);
141 doc = serializer.serializeToString($('#html-view div').get(0))
142 doc = parser.parseFromString(doc, 'text/xml');
143 console.log('xml',doc, doc.documentElement);
144 // TODO: Sprawdzenie błędów
145 doc = xsl.transformToDocument(doc);
146 console.log('after transform', doc, doc.documentElement);
147 doc = serialize(doc.documentElement).join('');
148 // doc = serializer.serializeToString(doc.documentElement)
151 error: function() {alert('Error loading XSL!')}
155 $('#save-button').click(function(event) {
156 event.preventDefault();
157 console.log(editor.getCode(), $('form input[name=text]').get(0));
158 $('form textarea[name=text]').val(editor.getCode());
159 $('form').ajaxSubmit(function() {
164 $('#simple-view-tab').click(function() {
165 if ($(this).hasClass('active')) {
168 $(this).addClass('active');
169 $('#source-view-tab').removeClass('active');
170 $('#source-editor').hide();
171 $('#simple-editor').show();
175 $('#source-view-tab').click(function() {
176 if ($(this).hasClass('active')) {
179 $(this).addClass('active');
180 $('#simple-view-tab').removeClass('active');
181 $('#simple-editor').hide();
182 $('#source-editor').show();
186 $('.toolbar button').click(function(event) {
187 event.preventDefault();
188 var params = eval("(" + $(this).attr('ui:action-params') + ")");
189 scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
192 $('.toolbar select').change(function() {
193 var slug = $(this).val();
195 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
198 $('.toolbar-buttons-container').hide();
199 $('.toolbar select').change();
201 // $('#html-view *[x-editable]').live('mouseover', function() {
202 // $(this).css({backgroundColor: 'red', marginLeft: -50, paddingLeft: 50});
203 // $(this).append('<button class="edit-button">Edytuj</button>');
204 // }).live('mouseout', function() {
205 // $(this).css({backgroundColor: null, marginLeft: 0, paddingLeft: 0});
206 // $('.edit-button', this).remove();