first approach to wlxml library
[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) {
16     smartxml.ElementNode.call(this, nativeNode);
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                 meta[attr.name.substr(5)] = attr.value;
29         });
30         return toret;
31     },
32     getOtherAttributes: function() {
33         var toret = {};
34         this.getAttrs().forEach(function(attr) {
35             if(attr.name != 'class' && !isMetaAttribute(attr.name))
36                 toret[attr.name] = attr.value;
37         });
38         return toret;
39     }
40 });
41
42
43 var WLXMLDocument = function(xml) {
44     smartxml.Document.call(this, xml);
45 };
46 WLXMLDocument.prototype = Object.create(smartxml.Document.prototype);
47 $.extend(WLXMLDocument.prototype, {
48     ElementNodeFactory: WLXMLElementNode
49 });
50
51
52 return {
53     WLXMLDocumentFromXML: function(xml) {
54         return new WLXMLDocument(xml);
55     }  
56 };
57
58 });