X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/266a16ec421df5bc8f2565884dd410918f1f1df4..e298a4a95de93951eee23d33ba7e8d1387a90a5b:/src/wlxml/extensions/metadata/metadata.js diff --git a/src/wlxml/extensions/metadata/metadata.js b/src/wlxml/extensions/metadata/metadata.js index 4136673..86bd8ee 100644 --- a/src/wlxml/extensions/metadata/metadata.js +++ b/src/wlxml/extensions/metadata/metadata.js @@ -5,6 +5,34 @@ define(function(require) { var _ = require('libs/underscore'), metadataKey = 'wlxml.metadata'; +var Row = function(key, value) { + this.key = key; + this.value = value; +}; +_.extend(Row.prototype, { + setKey: function(key) { + this.key = key; + }, + getKey: function() { + return this.key; + }, + setValue: function(value) { + this.value = value; + }, + getValue: function() { + return this.value; + } +}); + +// var Metadata = function(node) { +// this._rows = []; +// } + +// _.extend(Metadata.prototype, { +// forEach: function(callback) { +// this. +// } +// }) var methods = { getMetadata: function() { @@ -13,20 +41,12 @@ var methods = { }; var transformations = { - 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); - } + addMetadata: function(desc) { + var metadata = this.getData(metadataKey) || [], + row = new Row(desc.key, desc.value); + metadata.push(row); this.setData(metadataKey, metadata); - this.triggerChangeEvent('metadataChange', {index: index}); + return row; } };