forked from cgallello/UXCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathltxml-extensions.js
More file actions
executable file
·320 lines (280 loc) · 11.7 KB
/
ltxml-extensions.js
File metadata and controls
executable file
·320 lines (280 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/***************************************************************************
Copyright (c) Microsoft Corporation 2013.
This code is licensed using the Microsoft Public License (Ms-PL). You can find the text of the license here:
http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx
Published at http://OpenXmlDeveloper.org
Resource Center and Documentation: http://openxmldeveloper.org/wiki/w/wiki/open-xml-sdk-for-javascript.aspx
Developer: Eric White
Blog: http://www.ericwhite.com
Twitter: @EricWhiteDev
Email: eric@ericwhite.com
***************************************************************************/
(function (root) { // root = global
"use strict";
var XEnumerable;
// Ltxml encapsulation function
function defineXEnumerable(root, Enumerable, Ltxml) {
var ancestors, ancestorsAndSelf, attributes, descendantNodes, descendantNodesAndSelf, descendants,
descendantsAndSelf, elements, inDocumentOrder, nodes, remove, groupAdjacent, XEnumerable;
ancestors = function (xname) {
var source, result;
if (xname && typeof xname === 'string') {
xname = new Ltxml.XName(xname);
}
source = this.source ? this.source : this; //ignore jslint
result = source
.selectMany(
function (e) {
if (e.nodeType &&
(e.nodeType === 'Element' ||
e.nodeType === 'Comment' ||
e.nodeType === 'ProcessingInstruction' ||
e.nodeType === 'Text' ||
e.nodeType === 'CDATA' ||
e.nodeType === 'Entity')) {
return e.ancestors(xname);
}
return Enumerable.empty();
});
return new XEnumerable(result);
};
ancestorsAndSelf = function (xname) {
var source, result;
if (xname && typeof xname === 'string') {
xname = new Ltxml.XName(xname);
}
source = this.source ? this.source : this; //ignore jslint
result = source
.selectMany(
function (e) {
if (e.nodeType && e.nodeType === 'Element') {
return e.ancestorsAndSelf(xname);
}
return Enumerable.empty();
});
return new XEnumerable(result);
};
attributes = function (xname) {
var source, result;
if (xname && typeof xname === 'string') {
xname = new Ltxml.XName(xname);
}
source = this.source ? this.source : this; //ignore jslint
result = source
.selectMany(
function (e) {
if (e.nodeType && e.nodeType === 'Element') {
return e.attributes(xname);
}
return Enumerable.empty();
});
return new XEnumerable(result);
};
descendantNodes = function () {
var source, result;
source = this.source ? this.source : this; //ignore jslint
result = source
.selectMany(
function (e) {
if (e.nodeType &&
(e.nodeType === 'Element' ||
e.nodeType === 'Comment' ||
e.nodeType === 'ProcessingInstruction' ||
e.nodeType === 'Text' ||
e.nodeType === 'CDATA' ||
e.nodeType === 'Entity')) {
return e.descendantNodes();
}
return Enumerable.empty();
});
return new XEnumerable(result);
};
descendantNodesAndSelf = function () {
var source, result;
source = this.source ? this.source : this; //ignore jslint
result = source
.selectMany(
function (e) {
if (e.nodeType &&
(e.nodeType === 'Element' ||
e.nodeType === 'Comment' ||
e.nodeType === 'ProcessingInstruction' ||
e.nodeType === 'Text' ||
e.nodeType === 'CDATA' ||
e.nodeType === 'Entity')) {
return e.descendantNodesAndSelf();
}
return Enumerable.empty();
});
return new XEnumerable(result);
};
descendants = function (xname) {
var source, result;
if (xname && typeof xname === 'string') {
xname = new Ltxml.XName(xname);
}
source = this.source ? this.source : this; //ignore jslint
result = source
.selectMany(
function (e) {
if (e.nodeType && e.nodeType === 'Element') {
return e.descendants(xname);
}
return Enumerable.empty();
});
return new XEnumerable(result);
};
descendantsAndSelf = function (xname) {
var source, result;
if (xname && typeof xname === 'string') {
xname = new Ltxml.XName(xname);
}
source = this.source ? this.source : this; //ignore jslint
result = source
.selectMany(
function (e) {
if (e.nodeType && e.nodeType === 'Element') {
return e.descendantsAndSelf(xname);
}
return Enumerable.empty();
});
return new XEnumerable(result);
};
elements = function (xname) {
var source, result;
if (xname && typeof xname === 'string') {
xname = new Ltxml.XName(xname);
}
source = this.source ? this.source : this; //ignore jslint
result = source
.select(
function (e) {
if (e.nodeType &&
(e.nodeType === 'Element' || e.nodeType === 'Document')) {
return e.elements(xname);
}
return Enumerable.empty();
})
.selectMany("i=>i");
return new XEnumerable(result);
};
inDocumentOrder = function () {
throw "Not implemented";
};
nodes = function () {
var source, result;
source = this.source ? this.source : this; //ignore jslint
result = source
.selectMany(
function (e) {
if (e.nodeType &&
(e.nodeType === 'Element' ||
e.nodeType === 'Document')) {
return e.nodes();
}
return Enumerable.empty();
});
return new XEnumerable(result);
};
remove = function (xname) {
var source, toRemove, i;
if (xname && typeof xname === 'string') {
xname = new Ltxml.XName(xname);
}
source = this.source ? this.source : this; //ignore jslint
toRemove = source.toArray();
for (i = 0; i < toRemove.length; i += 1) {
if (xname === undefined) {
toRemove[i].remove();
}
else {
if (toRemove[i].name && toRemove[i].name === xname) {
toRemove[i].remove();
}
}
}
};
groupAdjacent = function (keySelector) {
var last, haveLast, listOfLists, list, source;
source = this.source ? this.source : this; //ignore jslint
last = null;
haveLast = false;
listOfLists = [];
list = [];
source.forEach(function (s) {
var k;
k = keySelector(s);
if (haveLast) {
if (k !== last) {
listOfLists.push({
Key: last,
Group: Enumerable.from(list)
});
list = [];
list.push(s);
last = k;
}
else {
list.push(s);
last = k;
}
}
else {
list.push(s);
last = k;
haveLast = true;
}
});
if (haveLast) {
listOfLists.push({
Key: last,
Group: Enumerable.from(list)
});
}
return Enumerable.from(listOfLists);
};
XEnumerable = function (source) {
this.source = source;
this.isXEnumerable = true;
};
XEnumerable.prototype = new Enumerable();
XEnumerable.prototype.getEnumerator = function () {
return this.source.getEnumerator();
};
XEnumerable.prototype.asEnumerable = function () {
return this.source;
};
XEnumerable.prototype.ancestors = ancestors;
XEnumerable.prototype.ancestorsAndSelf = ancestorsAndSelf;
XEnumerable.prototype.attributes = attributes;
XEnumerable.prototype.descendantNodes = descendantNodes;
XEnumerable.prototype.descendantNodesAndSelf = descendantNodesAndSelf;
XEnumerable.prototype.descendants = descendants;
XEnumerable.prototype.descendantsAndSelf = descendantsAndSelf;
XEnumerable.prototype.elements = elements;
XEnumerable.prototype.inDocumentOrder = inDocumentOrder;
XEnumerable.prototype.nodes = nodes;
XEnumerable.prototype.remove = remove;
XEnumerable.prototype.groupAdjacent = groupAdjacent;
return XEnumerable;
}
/*ignore jslint start*/
// module export
if (typeof define === typeof function () { } && define.amd) { // AMD
define("ltxml-extensions", ["linq", "ltxml"], function (Enumerable, Ltxml) {
XEnumerable = defineXEnumerable(root, Enumerable, Ltxml);
return XEnumerable;
});
}
else if (typeof module !== typeof undefined && module.exports) { // Node
XEnumerable = defineXEnumerable(root, Enumerable, Ltxml);
module.exports = XEnumerable;
}
else {
// Enumerable must be defined before including ltxml-extensions.js.
// Ltxml must be defined before including ltxml-extensions.js.
XEnumerable = defineXEnumerable(root, Enumerable, Ltxml);
root.XEnumerable = XEnumerable;
}
/*ignore jslint end*/
}(this));