'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 _.keys(this);
};
+var getClassLists = function(klassName) {
+ var toret = [],
+ classParts = [''].concat(klassName.split('.')),
+ classCurrent;
+
+ classParts.forEach(function(part) {
+ classCurrent = classCurrent ? classCurrent + '.' + part : part;
+ toret.push(classCurrent);
+ });
+ return toret;
+};
+
var installObject = function(instance, klass) {
- var methods = instance.document.classMethods[klass] || {},
- transformations = instance.document.classTransformations[klass] || {};
+ var methods = {},
+ transformations = {};
+ getClassLists(klass).forEach(function(klassName) {
+ _.extend(methods, instance.document.classMethods[klassName] || {});
+ _.extend(methods, instance.document.classTransformations[klassName] || {});
+ });
instance.object = Object.create(_.extend({}, methods, transformations));
_.keys(methods).concat(_.keys(transformations)).forEach(function(key) {
instance.object[key] = _.bind(instance.object[key], instance);
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) {