'libs/jquery',
'libs/underscore',
'smartxml/smartxml',
- 'smartxml/transformations'
-], function($, _, smartxml, transformations) {
+ 'smartxml/transformations',
+ 'wlxml/extensions/metadata/metadata'
+], function($, _, smartxml, transformations, metadataExtension) {
'use strict';
/* globals Node */
-var metadataKey = 'wlxml.metadata';
var AttributesList = function() {};
return attrName !== 'class' &&_.contains(_.keys(this.getMetaAttributes()), attrName);
},
- getMetadata: function() {
- return this.getData(metadataKey) || [];
- },
-
- addMetadataRow: function(row) {
- this.setMetadataRow(null, row);
- },
-
- setMetadataRow: function(index, row) {
- var metadata = this.getData(metadataKey) || [];
- if(typeof index !== 'number' || index > metadata.length - 1) {
- metadata.push(row);
- index = metadata.length - 1;
- } else {
- metadata[index] = _.extend(metadata[index], row);
- }
- this.setData(metadataKey, metadata);
- this.triggerChangeEvent('metadataChange', {index: index});
- },
-
_getXMLDOMToDump: function() {
var DOM = this._$.clone(true, true),
doc = this.document;
var WLXMLDocument = function(xml, options) {
this.classMethods = {};
this.classTransformations = {};
- smartxml.Document.call(this, xml);
+ smartxml.Document.call(this, xml, [metadataExtension]);
this.options = options;
};
var doc = this,
prefixLength = 'dc:'.length;
+ $(nativeNode).find('metadata').each(function() {
+ var metadataNode = $(this),
+ owner = doc.createDocumentNode(metadataNode.parent()[0]),
+ metadata = owner.getMetadata();
+
+ metadataNode.children().each(function() {
+ metadata.add({key: (this.tagName).toLowerCase().substr(prefixLength), value: $(this).text()}, {undoable: false});
+ });
+ metadataNode.remove();
+ });
+ nativeNode.normalize();
+
$(nativeNode).find(':not(iframe)').addBack().contents()
.filter(function() {return this.nodeType === Node.TEXT_NODE;})
.each(function() {
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) {