added REDMINE_URL to document_details_* context
[redakcja.git] / redakcja / static / js / wiki / xslt.js
index dda12a1..2bab378 100644 (file)
@@ -33,32 +33,71 @@ function withStylesheets(code_block, onError)
        }
 }
 
+var canonThemes = null;
 
-function xml2html(options) {
-    withStylesheets(function() {
-        var xml = options.xml.replace(/\/\s+/g, '<br />');
-        var parser = new DOMParser();
-        var serializer = new XMLSerializer();
-        var doc = parser.parseFromString(xml, 'text/xml');
-        var error = $('parsererror', doc);
-
-        if (error.length == 0) {
-            doc = xml2htmlStylesheet.transformToFragment(doc, document);
-                       console.log(doc.firstChild);
-
-                       if(doc.firstChild === null) {
-                               options.error("Błąd w przetwarzaniu XML.");
-                               return;
-                       }
+// Wykonuje block z załadowanymi kanonicznymi motywami
+function withThemes(code_block, onError)
+{
+    if (!canonThemes) {
+        $.blockUI({message: 'Ładowanie motywów...'});
+        $.ajax({
+            url: '/themes',
+            dataType: 'text',
+            success: function(data) {
+                canonThemes = {};
+                themes = data.split('\n');
+                for (i in themes) {
+                    canonThemes[themes[i]] = 1;
+                }
+                $.unblockUI();
+                code_block();
+            },
+            error: onError
+        })
+    }
+    else {
+        code_block();
+    }
+}
 
-            error = $('parsererror', doc);
-        }
 
-        if (error.length > 0 && options.error) {
-            options.error(error.text());
-        } else {
-            options.success(doc.firstChild);
-        }
+
+function xml2html(options) {
+    withStylesheets(function() {
+        withThemes(function() {
+            var xml = options.xml.replace(/\/\s+/g, '<br />');
+            var parser = new DOMParser();
+            var serializer = new XMLSerializer();
+            var doc = parser.parseFromString(xml, 'text/xml');
+            var error = $('parsererror', doc);
+
+            if (error.length == 0) {
+                doc = xml2htmlStylesheet.transformToFragment(doc, document);
+                console.log(doc.firstChild);
+
+                if(doc.firstChild === null) {
+                    options.error("Błąd w przetwarzaniu XML.");
+                    return;
+                }
+
+                error = $('parsererror', doc);
+            }
+
+            if (error.length > 0 && options.error) {
+                options.error(error.text());
+            } else {
+                $('.theme-text-list', doc.firstChild).each(function(){
+                    var themes = $(this).html().split(',');
+                    for (i in themes) {
+                        themes[i] = $.trim(themes[i]);
+                        if (!(themes[i] in canonThemes))
+                            themes[i] = '<span x-pass-thru="true" class="noncanon">' + themes[i] + "</span>"
+                    }
+                    $(this).html(themes.join(', '));
+                });
+                options.success(doc.firstChild);
+            }
+        }, function() { options.error && options.error('Nie udało się załadować motywów'); });
     }, function() { options.error && options.error('Nie udało się załadować XSLT'); });
 }
 
@@ -218,7 +257,8 @@ HTMLSerializer.prototype.serialize = function(rootElement, stripOuter)
 
                switch(token.node.nodeType) {
                        case ELEMENT_NODE:
-                               if(token.node.hasAttribute('x-pass-thru')) {
+                               if(token.node.hasAttribute('x-pass-thru')
+                                || token.node.hasAttribute('data-pass-thru')) {
                                        self._pushChildren(token.node);
                                        break;
                                }