X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/7a67ffc356936a4eec4243df03fab2ad1c66c9b9..cb5f162babe577ede5a113b49d072b51a97ecaad:/src/wlxml/wlxml.js diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index 016f793..7f6e931 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -7,13 +7,8 @@ define([ 'use strict'; -// utils +/* globals Node */ -var isMetaAttribute = function(attrName) { - return attrName.substr(0, 5) === 'meta-'; -}; - -// var AttributesList = function() {}; AttributesList.prototype = Object.create({}); @@ -29,7 +24,7 @@ var installObject = function(instance, klass) { _.keys(methods).concat(_.keys(transformations)).forEach(function(key) { instance.object[key] = _.bind(instance.object[key], instance); }); -} +}; var WLXMLElementNode = function(nativeNode, document) { smartxml.ElementNode.call(this, nativeNode, document); @@ -42,7 +37,6 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, { return this.getAttr('class') || ''; }, setClass: function(klass) { - var methods, object; if(klass !== this.klass) { installObject(this, klass); return this.setAttr('class', klass); @@ -61,24 +55,28 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, { classDesc = this.document.options.wlxmlClasses[classCurrent]; if(classDesc) { _.keys(classDesc.attrs).forEach(function(attrName) { - toret[attrName] = _.extend({value: this.getAttr('meta-' + attrName)}, classDesc.attrs[attrName]); + toret[attrName] = _.extend({value: this.getAttr(attrName)}, classDesc.attrs[attrName]); }.bind(this)); } }.bind(this)); return toret; }, setMetaAttribute: function(key, value) { - this.setAttr('meta-'+key, value); + this.setAttr(key, value); }, getOtherAttributes: function() { - var toret = {}; + var toret = {}, + node = this; this.getAttrs().forEach(function(attr) { - if(attr.name !== 'class' && !isMetaAttribute(attr.name)) { - toret[attr.name] = attr.value; + if(attr.name !== 'class' && !node.isMetaAttribute(attr.name)) { + toret[attr.name] = {value: attr.value}; } }); return toret; }, + isMetaAttribute: function(attrName) { + return attrName !== 'class' &&_.contains(_.keys(this.getMetaAttributes()), attrName); + }, _getXMLDOMToDump: function() { var DOM = this._$.clone(true, true); @@ -141,7 +139,7 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, { var WLXMLDocumentNode = function() { smartxml.DocumentNode.apply(this, arguments); -} +}; WLXMLDocumentNode.prototype = Object.create(smartxml.DocumentNode.prototype); var WLXMLDocument = function(xml, options) { @@ -160,7 +158,11 @@ $.extend(WLXMLDocument.prototype, { ElementNodeFactory: WLXMLElementNode, loadXML: function(xml) { smartxml.Document.prototype.loadXML.call(this, xml, {silent: true}); - $(this.dom).find(':not(iframe)').addBack().contents() + this.trigger('contentSet'); + }, + + normalizeXML: function(nativeNode) { + $(nativeNode).find(':not(iframe)').addBack().contents() .filter(function() {return this.nodeType === Node.TEXT_NODE;}) .each(function() { var el = $(this), @@ -239,10 +241,9 @@ $.extend(WLXMLDocument.prototype, { } //} } - + /* globals document */ el.replaceWith(document.createTextNode(text.transformed)); }); - this.trigger('contentSet'); }, registerClassTransformation: function(Transformation, className) { @@ -250,7 +251,7 @@ $.extend(WLXMLDocument.prototype, { thisClassTransformations[Transformation.prototype.name] = function(args) { var nodeInstance = this; return nodeInstance.transform(Transformation, args); - } + }; }, registerClassMethod: function(methodName, method, className) { @@ -277,7 +278,7 @@ $.extend(WLXMLDocument.prototype, { var name = pair[0], desc = pair[1]; doc.registerClassTransformation(transformations.createContextTransformation(desc, name), className); - }); + }); }); }