fix
[fnpeditor.git] / src / wlxml / wlxml.js
1 define([
2     'smartxml/smartxml'
3 ], function(smartxml) {
4     
5 'use strict';
6
7 // utils
8
9 var isMetaAttribute = function(attrName) {
10     return attrName.substr(0, 5) === 'meta-';
11 };
12
13 //
14
15 var WLXMLElementNode = function(nativeNode, document) {
16     smartxml.ElementNode.call(this, nativeNode, document);
17 };
18 WLXMLElementNode.prototype = Object.create(smartxml.ElementNode.prototype);
19
20 $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, {
21     getClass: function() {
22         return this.getAttr('class');
23     },
24     getMetaAttributes: function() {
25         var toret = {};
26         this.getAttrs().forEach(function(attr) {
27             if(isMetaAttribute(attr.name)) {
28                 toret[attr.name.substr(5)] = attr.value;
29             }
30         });
31         return toret;
32     },
33     getOtherAttributes: function() {
34         var toret = {};
35         this.getAttrs().forEach(function(attr) {
36             if(attr.name !== 'class' && !isMetaAttribute(attr.name)) {
37                 toret[attr.name] = attr.value;
38             }
39         });
40         return toret;
41     }
42 });
43
44
45 var WLXMLDocument = function(xml) {
46     smartxml.Document.call(this, xml);
47 };
48 WLXMLDocument.prototype = Object.create(smartxml.Document.prototype);
49 $.extend(WLXMLDocument.prototype, {
50     ElementNodeFactory: WLXMLElementNode
51 });
52
53
54 return {
55     WLXMLDocumentFromXML: function(xml) {
56         return new WLXMLDocument(xml);
57     },
58
59     WLXMLElementNodeFromXML: function(xml) {
60         return this.WLXMLDocumentFromXML(xml).root;
61     }
62 };
63
64 });