Added auto-removal of commas in theme edit box, if there was only 1 theme netered...
[redakcja.git] / platforma / static / js / xslt.js
index 7397d34..c3f13d6 100644 (file)
@@ -34,8 +34,9 @@ var MARGIN = {
 MARGIN['rdf:RDF'] = 3;
 MARGIN['rdf:Description'] = 2;
 
+var blockTags = ['akap', 'akap_cd', 'akap_dialog', 'strofa', 'didaskalia', 'wers', 'wers_cd', 'wers_akap', 'wers_wciety', 'autor_utworu', 'nazwa_utworu', 'dzielo_nadrzedne', 'podpis'];
 function elementType(element) {
-    if ($.inArray(element.tagName, ['akap', 'akap_cd', 'akap_dialog', 'strofa', 'didaskalia', 'wers', 'wers_cd', 'wers_akap', 'wers_wciety', 'autor_utworu', 'nazwa_utworu', 'dzielo_nadrzedne', 'podpis'])) {
+    if (blockTags.indexOf(element.tagName) != -1) {
         return 'inline';
     } else {
         return 'block';
@@ -49,11 +50,7 @@ function serialize(element, mode) {
     }
     
     if (element.nodeType == 3) { // tekst
-        if (mode == 'block') {
-            return [$.trim(element.nodeValue)];
-        } else {
-            return [element.nodeValue];
-        }
+       return [element.nodeValue];        
     } else if (element.nodeType != 1) { // pomijamy węzły nie będące elementami XML ani tekstem
         return [];
     }
@@ -61,6 +58,8 @@ function serialize(element, mode) {
     var result = [];
     var hasContent = false;
     
+    
+    
     if (MARGIN[element.tagName]) {
         for (var i=0; i < MARGIN[element.tagName]; i++) {
             result.push('\n');
@@ -132,12 +131,12 @@ function withStylesheets(block, onError) {
     }
     $.blockUI({message: 'Ładowanie arkuszy stylów...'});
     $.ajax({
-        url: '/static/xsl/wl2html_client.xsl',
+        url: STATIC_URL + 'xsl/wl2html_client.xsl',
         dataType: 'xml',
         success: function(data) {
             xml2htmlStylesheet = createXSLT(data);
             $.ajax({
-                url: '/static/xsl/html2wl_client.xsl',
+                url: STATIC_URL + 'xsl/html2wl_client.xsl',
                 dataType: 'xml',
                 success: function(data) {
                     html2xmlStylesheet = createXSLT(data);
@@ -170,7 +169,7 @@ function xml2html(options) {
         } else {
             options.success(doc.firstChild);
         }
-    }, function() { options.error && options.success('Nie udało się załadować XSLT'); });
+    }, function() { options.error && options.error('Nie udało się załadować XSLT'); });
 }
 
 
@@ -181,19 +180,25 @@ function html2xml(options) {
         var serializer = new XMLSerializer();
         var doc = parser.parseFromString(xml, 'text/xml');
         var error = $('parsererror', doc.documentElement);
-        
+
         if (error.length == 0) {
-            doc = html2xmlStylesheet.transformToDocument(doc, document);
+            doc = html2xmlStylesheet.transformToDocument(doc);
             error = $('parsererror', doc.documentElement);
         }
         
         if (error.length > 0 && options.error) {
             options.error(error.text());
-            console.log(error);
-            $('#source-editor').html('<p>Wystąpił błąd:</p>' + error.text());
         } else {
-            options.success(serialize(doc.documentElement).join(''));                              
+            if (options.inner) {
+                var result = [];
+                for (var i = 0; i < doc.documentElement.childNodes.length; i++) {
+                    result.push(serialize(doc.documentElement.childNodes[i]).join(''));
+                };
+                options.success(result.join(''));
+            } else {
+                options.success(serialize(doc.documentElement).join(''));
+            }
         }
-    }, function() { options.error && options.success('Nie udało się załadować XSLT'); });
+    }, function() { options.error && options.error('Nie udało się załadować XSLT'); });
 };