X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/1a0d01d9cdbffcf9667562502c3d2e36e5a9fa5b..97110072b271210d32acd3e38a13515f48b67c5f:/redakcja/static/js/wiki/xslt.js
diff --git a/redakcja/static/js/wiki/xslt.js b/redakcja/static/js/wiki/xslt.js
index 532b452b..2bab378d 100644
--- a/redakcja/static/js/wiki/xslt.js
+++ b/redakcja/static/js/wiki/xslt.js
@@ -33,32 +33,71 @@ function withStylesheets(code_block, onError)
}
}
+var canonThemes = null;
-function xml2html(options) {
- withStylesheets(function() {
- var xml = options.xml.replace(/\/\s+/g, '
');
- 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, '
');
+ 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] = '' + themes[i] + ""
+ }
+ $(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'); });
}