X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/ae032450627538fabf7df31fbda6cf7bd097b94f..6e641abeaa2fcd8d8f9885db37d127e7d1a34885:/src/wlxml/wlxml.js diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index c3ed84f..fe0636d 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -2,13 +2,13 @@ define([ '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() {}; @@ -79,26 +79,6 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, { 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; @@ -182,7 +162,7 @@ WLXMLDocumentNode.prototype = Object.create(smartxml.DocumentNode.prototype); var WLXMLDocument = function(xml, options) { this.classMethods = {}; this.classTransformations = {}; - smartxml.Document.call(this, xml); + smartxml.Document.call(this, xml, [metadataExtension]); this.options = options; }; @@ -201,6 +181,18 @@ $.extend(WLXMLDocument.prototype, { 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() { @@ -284,15 +276,7 @@ $.extend(WLXMLDocument.prototype, { 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) {