X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/3d61fc117d9e5274189d16be83d4489cd4b36d7f..7a243e479fd923d27ed69f2085ea2117d37977b2:/platforma/static/js/xslt.js
diff --git a/platforma/static/js/xslt.js b/platforma/static/js/xslt.js
index f164c5bd..95cc5fc5 100644
--- a/platforma/static/js/xslt.js
+++ b/platforma/static/js/xslt.js
@@ -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';
@@ -132,12 +133,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);
@@ -151,72 +152,55 @@ function withStylesheets(block, onError) {
})
}
-function transform(editor) {
- $.blockUI({message: 'Åadowanie...'});
- withStylesheets(function() {
- setTimeout(function() {
- var doc = null;
- var parser = new DOMParser();
- var serializer = new XMLSerializer();
-
- doc = editor.getCode().replace(/\/\s+/g, '
');
- doc = parser.parseFromString(doc, 'text/xml');
- var error = $('parsererror', doc);
- console.log(error);
- if (error.length == 0) {
- doc = xml2htmlStylesheet.transformToFragment(doc, document);
- error = $('parsererror', doc);
- }
- console.log('xml', doc);
- if (error.length > 0) {
- console.log(error);
- $('#html-view').html('
WystÄ piÅ bÅÄ d:
' + error.text() + ''); - } else { - console.log('after transform', doc); - $('#html-view').html(doc.firstChild); - } - $.unblockUI(); - }, 200); - }, function() { alert('Nie udaÅo siÄ zaÅadowaÄ XSLT!'); }); -}; +function xml2html(options) { + withStylesheets(function() { + var xml = options.xml.replace(/\/\s+/g, '
WystÄ piÅ bÅÄ d:
' + error.text()); + var xml = options.xml; + var parser = new DOMParser(); + var serializer = new XMLSerializer(); + var doc = parser.parseFromString(xml, 'text/xml'); + var error = $('parsererror', doc.documentElement); + + if (error.length == 0) { + doc = html2xmlStylesheet.transformToDocument(doc); + error = $('parsererror', doc.documentElement); + } + + if (error.length > 0 && options.error) { + options.error(error.text()); + } else { + 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 { - doc = serialize(doc.documentElement).join(''); - editor.setCode(doc); + options.success(serialize(doc.documentElement).join('')); } - - console.log('after transform', doc, doc.documentElement); - $.unblockUI(); - }, 200) - }, function() { alert('Nie udaÅo siÄ zaÅadowaÄ XSLT!')}); + } + }, function() { options.error && options.error('Nie udaÅo siÄ zaÅadowaÄ XSLT'); }); };