X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/94e3767f1597835ac82361d7d04be1347fe40942..266a16ec421df5bc8f2565884dd410918f1f1df4:/src/wlxml/wlxml.js?ds=sidebyside diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index 820b95f..6c6c40c 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -2,8 +2,9 @@ define([ 'libs/jquery', 'libs/underscore', 'smartxml/smartxml', - 'smartxml/transformations' -], function($, _, smartxml, transformations) { + 'smartxml/transformations', + 'wlxml/extensions/metadata/metadata' +], function($, _, smartxml, transformations, metadataExtension) { 'use strict'; @@ -79,7 +80,8 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, { }, _getXMLDOMToDump: function() { - var DOM = this._$.clone(true, true); + var DOM = this._$.clone(true, true), + doc = this.document; DOM.find('*').addBack().each(function() { var el = $(this), @@ -89,7 +91,7 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, { data = el.data(); - var txt; + var txt, documentNode, metaNode; if(data[formatter_prefix+ 'orig_before']) { txt = idx > 0 && contents[idx-1].nodeType === Node.TEXT_NODE ? contents[idx-1] : null; @@ -119,8 +121,23 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, { el.append(data[formatter_prefix+ 'orig_end']); } } + + + if(this.nodeType === Node.ELEMENT_NODE) { + documentNode = doc.createDocumentNode(this); + metaNode = $(''); + documentNode.getMetadata().forEach(function(row) { + metaNode.append('' + row.value + ''); + }); + if(metaNode.children().length) { + $(this).prepend(metaNode); + } + } + }); + + return DOM; } }); @@ -143,11 +160,10 @@ var WLXMLDocumentNode = function() { WLXMLDocumentNode.prototype = Object.create(smartxml.DocumentNode.prototype); var WLXMLDocument = function(xml, options) { - smartxml.Document.call(this, xml); - this.options = options; - this.classMethods = {}; this.classTransformations = {}; + smartxml.Document.call(this, xml, [metadataExtension]); + this.options = options; }; var formatter_prefix = '_wlxml_formatter_'; @@ -162,6 +178,9 @@ $.extend(WLXMLDocument.prototype, { }, normalizeXML: function(nativeNode) { + var doc = this, + prefixLength = 'dc:'.length; + $(nativeNode).find(':not(iframe)').addBack().contents() .filter(function() {return this.nodeType === Node.TEXT_NODE;}) .each(function() { @@ -244,6 +263,16 @@ $.extend(WLXMLDocument.prototype, { /* globals document */ el.replaceWith(document.createTextNode(text.transformed)); }); + + $(nativeNode).find('metadata').each(function() { + var metadataNode = $(this), + owner = doc.createDocumentNode(metadataNode.parent()[0]); + + metadataNode.children().each(function() { + owner.addMetadataRow({key: (this.tagName).toLowerCase().substr(prefixLength), value: $(this).text()}); + }); + metadataNode.remove(); + }); }, registerClassTransformation: function(Transformation, className) {