X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/1fbf854ce423d2d56723ff10608267403f4916b0..9b25359a45e5498ac09b51b96919d515c1cd5d15:/redakcja/static/js/wiki/xslt.js
diff --git a/redakcja/static/js/wiki/xslt.js b/redakcja/static/js/wiki/xslt.js
index 2bab378d..86c6d362 100644
--- a/redakcja/static/js/wiki/xslt.js
+++ b/redakcja/static/js/wiki/xslt.js
@@ -19,6 +19,7 @@ function withStylesheets(code_block, onError)
$.ajax({
url: STATIC_URL + 'xsl/wl2html_client.xsl',
dataType: 'xml',
+ timeout: 10000,
success: function(data) {
xml2htmlStylesheet = createXSLT(data);
$.unblockUI();
@@ -33,30 +34,26 @@ function withStylesheets(code_block, onError)
}
}
-var canonThemes = null;
// Wykonuje block z zaÅadowanymi kanonicznymi motywami
function withThemes(code_block, onError)
{
- if (!canonThemes) {
- $.blockUI({message: 'Åadowanie motywów...'});
+ if (typeof withThemes.canon == 'undefined') {
$.ajax({
url: '/themes',
dataType: 'text',
success: function(data) {
- canonThemes = {};
- themes = data.split('\n');
- for (i in themes) {
- canonThemes[themes[i]] = 1;
- }
- $.unblockUI();
- code_block();
+ withThemes.canon = data.split('\n');
+ code_block(withThemes.canon);
},
- error: onError
+ error: function() {
+ withThemes.canon = null;
+ code_block(withThemes.canon);
+ }
})
}
else {
- code_block();
+ code_block(withThemes.canon);
}
}
@@ -64,40 +61,43 @@ function withThemes(code_block, onError)
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);
+ 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;
}
- 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'); });
+ error = $('parsererror', doc);
+ }
+
+ if (error.length > 0 && options.error) {
+ options.error(error.text());
+ } else {
+ options.success(doc.firstChild);
+
+ withThemes(function(canonThemes) {
+ if (canonThemes != null) {
+ $('.theme-text-list').addClass('canon').each(function(){
+ var themes = $(this).html().split(',');
+ for (i in themes) {
+ themes[i] = $.trim(themes[i]);
+ if (canonThemes.indexOf(themes[i]) == -1)
+ themes[i] = '' + themes[i] + ""
+ }
+ $(this).html(themes.join(', '));
+ });
+ }
+ });
+ }
}, function() { options.error && options.error('Nie udaÅo siÄ zaÅadowaÄ XSLT'); });
}
@@ -288,7 +288,11 @@ HTMLSerializer.prototype.serialize = function(rootElement, stripOuter)
self._serializeElement(token.node);
break;
case TEXT_NODE:
- self.result += token.node.nodeValue;
+ // collapse previous element's padding
+ var i = 0;
+ while (token.node.nodeValue[i] == '\n' && self.result[self.result.length - 1] == '\n')
+ i ++;
+ self.result += token.node.nodeValue.substr(i);
break;
};
};
@@ -372,7 +376,9 @@ HTMLSerializer.prototype._serializeElement = function(node) {
};
/* print out */
- if (getPadding(tagName))
+
+ // at least one newline before padded elements
+ if (getPadding(tagName) && self.result[self.result.length - 1] != '\n')
self.result += '\n';
self.result += '<' + tagName;