annotate inkscape/firefox/content/jqXMLUtils.js @ 1087:cd34de1a6960 openvg

Fix issue of incorrect color for color paint. It is always black (nearly). It is caused by translate RGBA values from MadButterfly to OpenVG with wrong function.
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 03 Dec 2010 18:18:43 +0800
parents 63aaf96209cd
children
rev   line source
272
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
1 /*
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
2 This program is free software: you can redistribute it and/or modify
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
3 it under the terms of the GNU General Public License as published by
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
4 the Free Software Foundation, either version 3 of the License, or
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
5 (at your option) any later version.
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
6
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
7 This program is distributed in the hope that it will be useful,
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
10 GNU General Public License for more details.
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
11
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
12 You should have received a copy of the GNU General Public License
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
13 along with this program. If not, see <http://www.gnu.org/licenses/>.
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
14 */
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
15 (function($) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
16 //Converts XML DOM to JSON
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
17 $.extend ({
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
18 xmlToJSON: function(xdoc) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
19 try {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
20 if(!xdoc){ return null; }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
21 var tmpObj = {};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
22 tmpObj.typeOf = "JSXBObject";
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
23 var xroot = (xdoc.nodeType == 9)?xdoc.documentElement:xdoc;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
24 tmpObj.RootName = xroot.nodeName || "";
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
25 if(xdoc.nodeType == 3 || xdoc.nodeType == 4) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
26 return xdoc.nodeValue;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
27 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
28 var isNumeric = function(s) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
29 var testStr = "";
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
30 if(s && typeof s == "string") { testStr = s; }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
31 var pattern = /^((-)?([0-9]*)((\.{0,1})([0-9]+))?$)/;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
32 return pattern.test(testStr);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
33 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
34 //Alters attribute and collection names to comply with JS
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
35 function formatName(name) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
36 var regEx = /-/g;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
37 var tName = String(name).replace(regEx,"_");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
38 return tName;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
39 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
40 //Set Attributes of an object
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
41 function setAttributes(obj, node) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
42 if(node.attributes.length > 0) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
43 var a = node.attributes.length-1;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
44 var attName;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
45 obj._attributes = [];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
46 do { //Order is irrelevant (speed-up)
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
47 attName = String(formatName(node.attributes[a].name));
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
48 obj._attributes.push(attName);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
49 obj[attName] = $.trim(node.attributes[a].value);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
50 } while(a--);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
51 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
52 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
53 //Set collections
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
54 function setHelpers(grpObj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
55 //Selects a node withing array where attribute = value
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
56 grpObj.getNodeByAttribute = function(attr, obj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
57 if(this.length > 0) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
58 var cNode;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
59 var maxLen = this.length -1;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
60 try {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
61 do {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
62 cNode = this[maxLen];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
63 if(cNode[attr] == obj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
64 return cNode;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
65 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
66 } while(maxLen--);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
67 } catch(e) {return false;}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
68 return false;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
69 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
70 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
71
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
72 grpObj.contains = function(attr, obj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
73 if(this.length > 0) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
74 var maxLen = this.length -1;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
75 try {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
76 do {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
77 if(this[maxLen][attr] == obj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
78 return true;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
79 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
80 } while(maxLen--);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
81 } catch(e) {return false;}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
82 return false;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
83 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
84 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
85
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
86 grpObj.indexOf = function(attr, obj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
87 var pos = -1;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
88 if(this.length > 0) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
89 var maxLen = this.length -1;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
90 try {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
91 do {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
92 if(this[maxLen][attr] == obj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
93 pos = maxLen;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
94 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
95 } while(maxLen--);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
96 } catch(e) {return -1;}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
97 return pos;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
98 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
99 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
100
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
101 grpObj.SortByAttribute = function(col, dir) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
102 if(this.length) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
103 function getValue(pair, idx) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
104 var out = pair[idx];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
105 out = (isNumeric(out))?parseFloat(out):out;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
106 return out;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
107 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
108 function sortFn(a, b) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
109 var res = 0;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
110 var tA, tB;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
111 tA = getValue(a, col);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
112 tB = getValue(b, col);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
113 if(tA < tB) { res = -1; } else if(tB < tA) { res = 1; }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
114 if(dir) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
115 res = (dir.toUpperCase() == "DESC")?(0 - res):res;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
116 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
117 return res;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
118 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
119 this.sort(sortFn);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
120 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
121 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
122
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
123 grpObj.SortByValue = function(dir) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
124 if(this.length) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
125 function getValue(pair) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
126 var out = pair.Text;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
127 out = (isNumeric(out))?parseFloat(out):out;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
128 return out;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
129 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
130 function sortFn(a, b) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
131 var res = 0;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
132 var tA, tB;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
133 tA = getValue(a);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
134 tB = getValue(b);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
135 if(tA < tB) { res = -1; } else if(tB < tA) { res = 1; }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
136 if(dir) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
137 res = (dir.toUpperCase() == "DESC")?(0 - res):res;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
138 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
139 return res;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
140 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
141 this.sort(sortFn);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
142 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
143 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
144 grpObj.SortByNode = function(node, dir) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
145 if(this.length) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
146 function getValue(pair, node) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
147 var out = pair[node][0].Text;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
148 out = (isNumeric(out))?parseFloat(out):out;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
149 return out;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
150 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
151 function sortFn(a, b) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
152 var res = 0;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
153 var tA, tB;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
154 tA = getValue(a, node);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
155 tB = getValue(b, node);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
156 if(tA < tB) { res = -1; } else if(tB < tA) { res = 1; }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
157 if(dir) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
158 res = (dir.toUpperCase() == "DESC")?(0 - res):res;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
159 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
160 return res;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
161 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
162 this.sort(sortFn);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
163 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
164 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
165 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
166 //Recursive JSON Assembler
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
167 //Set Object Nodes
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
168 function setObjects(obj, node) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
169 var elemName; //Element name
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
170 var cnode; //Current Node
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
171 var tObj; //New subnode
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
172 var cName = "";
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
173 if(!node) { return null; }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
174 //Set node attributes if any
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
175 if(node.attributes.length > 0){setAttributes(obj, node);}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
176 obj.Text = "";
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
177 if(node.hasChildNodes()) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
178 var nodeCount = node.childNodes.length - 1;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
179 var n = 0;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
180 do { //Order is irrelevant (speed-up)
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
181 cnode = node.childNodes[n];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
182 switch(cnode.nodeType) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
183 case 1: //Node
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
184 //Process child nodes
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
185 obj._children = [];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
186 //SOAP XML FIX to remove namespaces (i.e. soapenv:)
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
187 elemName = (cnode.localName)?cnode.localName:cnode.baseName;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
188 elemName = formatName(elemName);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
189 if(cName != elemName) { obj._children.push(elemName); }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
190 //Create sub elemns array
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
191 if(!obj[elemName]) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
192 obj[elemName] = []; //Create Collection
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
193 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
194 tObj = {};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
195 obj[elemName].push(tObj);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
196 if(cnode.attributes.length > 0) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
197 setAttributes(tObj, cnode);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
198 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
199 //Set Helper functions (contains, indexOf, sort, etc);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
200 if(!obj[elemName].contains) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
201 setHelpers(obj[elemName]);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
202 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
203 cName = elemName;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
204 if(cnode.hasChildNodes()) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
205 setObjects(tObj, cnode); //Recursive Call
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
206 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
207 break;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
208 case 3: //Text Value
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
209 obj.Text += $.trim(cnode.nodeValue);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
210 break;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
211 case 4: //CDATA
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
212 obj.Text += (cnode.text)?$.trim(cnode.text):$.trim(cnode.nodeValue);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
213 break;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
214 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
215 } while(n++ < nodeCount);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
216 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
217 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
218 //RUN
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
219 setObjects(tmpObj, xroot);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
220 //Clean-up memmory
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
221 xdoc = null;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
222 xroot = null;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
223 return tmpObj;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
224
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
225 } catch(e) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
226 return null;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
227 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
228 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
229 });
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
230
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
231 //Converts Text to XML DOM
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
232 $.extend({
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
233 textToXML: function(strXML) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
234 var xmlDoc = null;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
235 try {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
236 xmlDoc = ($.browser.msie)?new ActiveXObject("Microsoft.XMLDOM"):new DOMParser();
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
237 xmlDoc.async = false;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
238 } catch(e) {throw new Error("XML Parser could not be instantiated");}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
239 var out;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
240 try {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
241 if($.browser.msie) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
242 out = (xmlDoc.loadXML(strXML))?xmlDoc:false;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
243 } else {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
244 out = xmlDoc.parseFromString(strXML, "text/xml");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
245 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
246 } catch(e) { throw new Error("Error parsing XML string"); }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
247 return out;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
248 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
249 });
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
250 })(jQuery);