3 ], function(smartxml) {
9 var isMetaAttribute = function(attrName) {
10 return attrName.substr(0, 5) === 'meta-';
15 var WLXMLElementNode = function(nativeNode, document) {
16 smartxml.ElementNode.call(this, nativeNode, document);
18 WLXMLElementNode.prototype = Object.create(smartxml.ElementNode.prototype);
20 $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, {
21 getClass: function() {
22 return this.getAttr('class');
24 setClass: function(klass) {
25 return this.setAttr('class', klass);
27 getMetaAttributes: function() {
29 this.getAttrs().forEach(function(attr) {
30 if(isMetaAttribute(attr.name)) {
31 toret.push({name: attr.name.substr(5), value: attr.value});
36 getOtherAttributes: function() {
38 this.getAttrs().forEach(function(attr) {
39 if(attr.name !== 'class' && !isMetaAttribute(attr.name)) {
40 toret[attr.name] = attr.value;
48 var WLXMLDocument = function(xml) {
49 smartxml.Document.call(this, xml);
51 $(this.dom).find(':not(iframe)').addBack().contents()
52 .filter(function() {return this.nodeType === Node.TEXT_NODE;})
55 text = {original: el.text(), trimmed: $.trim(el.text())},
56 elParent = el.parent(),
57 hasSpanParent = elParent.prop('tagName') === 'SPAN',
58 hasSpanBefore = el.prev().length && $(el.prev()).prop('tagName') === 'SPAN',
59 hasSpanAfter = el.next().length && $(el.next()).prop('tagName') === 'SPAN';
62 text.transformed = text.trimmed;
64 if(hasSpanParent || hasSpanBefore || hasSpanAfter) {
65 var startSpace = /\s/g.test(text.original.substr(0,1)),
66 endSpace = /\s/g.test(text.original.substr(-1)) && text.original.length > 1;
67 text.transformed = (startSpace && (hasSpanParent || hasSpanBefore) ? ' ' : '');
68 text.transformed += text.trimmed;
69 text.transformed += (endSpace && (hasSpanParent || hasSpanAfter) ? ' ' : '');
71 if(text.trimmed.length === 0 && text.original.length > 0 && elParent.contents().length === 1) {
72 text.transformed = ' ';
76 if(!text.transformed) {
78 return true; // continue
80 el.replaceWith(document.createTextNode(text.transformed));
83 WLXMLDocument.prototype = Object.create(smartxml.Document.prototype);
84 $.extend(WLXMLDocument.prototype, {
85 ElementNodeFactory: WLXMLElementNode
90 WLXMLDocumentFromXML: function(xml) {
91 return new WLXMLDocument(xml);
94 WLXMLElementNodeFromXML: function(xml) {
95 return this.WLXMLDocumentFromXML(xml).root;