Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81141 views
1
/*
2
* Copyright (C) 2007-2015 Diego Perini
3
* All rights reserved.
4
*
5
* nwmatcher-base.js - A fast CSS selector engine and matcher
6
*
7
* Author: Diego Perini <diego.perini at gmail com>
8
* Version: 1.3.4
9
* Created: 20070722
10
* Release: 20150101
11
*
12
* License:
13
* http://javascript.nwbox.com/NWMatcher/MIT-LICENSE
14
* Download:
15
* http://javascript.nwbox.com/NWMatcher/nwmatcher.js
16
*/
17
18
(function(global, factory) {
19
20
if (typeof module == 'object' && typeof exports == 'object') {
21
module.exports = function (browserGlobal) {
22
// passed global does not contain
23
// references to native objects
24
browserGlobal.console = console;
25
browserGlobal.parseInt = parseInt;
26
browserGlobal.Function = Function;
27
browserGlobal.Boolean = Boolean;
28
browserGlobal.Number = Number;
29
browserGlobal.RegExp = RegExp;
30
browserGlobal.String = String;
31
browserGlobal.Object = Object;
32
browserGlobal.Array = Array;
33
browserGlobal.Error = Error;
34
browserGlobal.Date = Date;
35
browserGlobal.Math = Math;
36
var exports = browserGlobal.Object();
37
factory(browserGlobal, exports);
38
return exports;
39
};
40
module.factory = factory;
41
} else {
42
factory(global,
43
(global.NW || (global.NW = global.Object())) &&
44
(global.NW.Dom || (global.NW.Dom = global.Object())));
45
global.NW.Dom.factory = factory;
46
}
47
48
})(this, function(global, exports) {
49
50
var version = 'nwmatcher-1.3.4',
51
52
Dom = exports,
53
54
doc = global.document,
55
root = doc.documentElement,
56
57
slice = global.Array.slice,
58
59
isSingleMatch,
60
isSingleSelect,
61
62
lastSlice,
63
lastContext,
64
lastPosition,
65
66
lastMatcher,
67
lastSelector,
68
69
lastPartsMatch,
70
lastPartsSelect,
71
72
prefixes = '[#.:]?',
73
operators = '([~*^$|!]?={1})',
74
whitespace = '[\\x20\\t\\n\\r\\f]*',
75
combinators = '[\\x20]|[>+~][^>+~]',
76
pseudoparms = '(?:[-+]?\\d*n)?[-+]?\\d*',
77
78
quotedvalue = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"' + "|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'",
79
skipgroup = '\\[.*\\]|\\(.*\\)|\\{.*\\}',
80
81
encoding = '(?:[-\\w]|[^\\x00-\\xa0]|\\\\.)',
82
identifier = '(?:-?[_a-zA-Z]{1}[-\\w]*|[^\\x00-\\xa0]+|\\\\.+)+',
83
84
attrcheck = '(' + quotedvalue + '|' + identifier + ')',
85
attributes = whitespace + '(' + encoding + '*:?' + encoding + '+)' +
86
whitespace + '(?:' + operators + whitespace + attrcheck + ')?' + whitespace,
87
88
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'),
89
90
pseudoclass = '((?:' +
91
pseudoparms + '|' + quotedvalue + '|' +
92
prefixes + '|' + encoding + '+|' +
93
'\\[' + attributes + '\\]|' +
94
'\\(.+\\)|' + whitespace + '|' +
95
',)+)',
96
97
extensions = '.+',
98
99
standardValidator =
100
'(?=[\\x20\\t\\n\\r\\f]*[^>+~(){}<>])' +
101
'(' +
102
'\\*' +
103
'|(?:' + prefixes + identifier + ')' +
104
'|' + combinators +
105
'|\\[' + attributes + '\\]' +
106
'|\\(' + pseudoclass + '\\)' +
107
'|\\{' + extensions + '\\}' +
108
'|(?:,|' + whitespace + ')' +
109
')+',
110
111
extendedValidator = standardValidator.replace(pseudoclass, '.*'),
112
113
reValidator = global.RegExp(standardValidator, 'g'),
114
115
reTrimSpaces = global.RegExp('^' +
116
whitespace + '|' + whitespace + '$', 'g'),
117
118
reSplitGroup = global.RegExp('(' +
119
'[^,\\\\()[\\]]+' +
120
'|\\[[^[\\]]*\\]|\\[.*\\]' +
121
'|\\([^()]+\\)|\\(.*\\)' +
122
'|\\{[^{}]+\\}|\\{.*\\}' +
123
'|\\\\.' +
124
')+', 'g'),
125
126
reSplitToken = global.RegExp('(' +
127
'\\[' + attributes + '\\]|' +
128
'\\(' + pseudoclass + '\\)|' +
129
'\\\\.|[^\\x20\\t\\n\\r\\f>+~])+', 'g'),
130
131
reWhiteSpace = /[\x20\t\n\r\f]+/g,
132
133
reOptimizeSelector = global.RegExp(identifier + '|^$'),
134
135
ATTR_BOOLEAN = global.Object({
136
checked: 1, disabled: 1, ismap: 1,
137
multiple: 1, readonly: 1, selected: 1
138
}),
139
140
ATTR_DEFAULT = global.Object({
141
value: 'defaultValue',
142
checked: 'defaultChecked',
143
selected: 'defaultSelected'
144
}),
145
146
ATTR_URIDATA = global.Object({
147
action: 2, cite: 2, codebase: 2, data: 2, href: 2,
148
longdesc: 2, lowsrc: 2, src: 2, usemap: 2
149
}),
150
151
Selectors = global.Object(),
152
153
Operators = global.Object({
154
'=': "n=='%m'",
155
'^=': "n.indexOf('%m')==0",
156
'*=': "n.indexOf('%m')>-1",
157
'|=': "(n+'-').indexOf('%m-')==0",
158
'~=': "(' '+n+' ').indexOf(' %m ')>-1",
159
'$=': "n.substr(n.length-'%m'.length)=='%m'"
160
}),
161
162
Optimize = global.Object({
163
ID: global.RegExp('^\\*?#(' + encoding + '+)|' + skipgroup),
164
TAG: global.RegExp('^(' + encoding + '+)|' + skipgroup),
165
CLASS: global.RegExp('^\\*?\\.(' + encoding + '+$)|' + skipgroup)
166
}),
167
168
Patterns = global.Object({
169
universal: /^\*(.*)/,
170
id: global.RegExp('^#(' + encoding + '+)(.*)'),
171
tagName: global.RegExp('^(' + encoding + '+)(.*)'),
172
className: global.RegExp('^\\.(' + encoding + '+)(.*)'),
173
attribute: global.RegExp('^\\[' + attrmatcher + '\\](.*)'),
174
children: /^[\x20\t\n\r\f]*\>[\x20\t\n\r\f]*(.*)/,
175
adjacent: /^[\x20\t\n\r\f]*\+[\x20\t\n\r\f]*(.*)/,
176
relative: /^[\x20\t\n\r\f]*\~[\x20\t\n\r\f]*(.*)/,
177
ancestor: /^[\x20\t\n\r\f]+(.*)/
178
}),
179
180
QUIRKS_MODE,
181
XML_DOCUMENT,
182
183
GEBTN = 'getElementsByTagName' in doc,
184
GEBCN = 'getElementsByClassName' in doc,
185
186
IE_LT_9 = typeof doc.addEventListener != 'function',
187
188
INSENSITIVE_MAP = global.Object({
189
'href': 1, 'lang': 1, 'src': 1, 'style': 1, 'title': 1,
190
'type': 1, 'xmlns': 1, 'xml:lang': 1, 'xml:space': 1
191
}),
192
193
TO_UPPER_CASE = IE_LT_9 ? '.toUpperCase()' : '',
194
195
ACCEPT_NODE = 'r[r.length]=c[k];if(f&&false===f(c[k]))break main;else continue main;',
196
REJECT_NODE = IE_LT_9 ? 'if(e.nodeName<"A")continue;' : '',
197
198
Config = global.Object({
199
CACHING: false,
200
SIMPLENOT: true,
201
UNIQUE_ID: true,
202
USE_HTML5: true,
203
VERBOSITY: true
204
}),
205
206
configure =
207
function(option) {
208
if (typeof option == 'string') { return Config[option] || Config; }
209
if (typeof option != 'object') { return false; }
210
for (var i in option) {
211
Config[i] = !!option[i];
212
if (i == 'SIMPLENOT') {
213
matchContexts = global.Object();
214
matchResolvers = global.Object();
215
selectContexts = global.Object();
216
selectResolvers = global.Object();
217
}
218
}
219
reValidator = global.RegExp(Config.SIMPLENOT ?
220
standardValidator : extendedValidator, 'g');
221
return true;
222
},
223
224
concatCall =
225
function(data, elements, callback) {
226
var i = -1, element;
227
while ((element = elements[++i])) {
228
if (false === callback(data[data.length] = element)) { break; }
229
}
230
return data;
231
},
232
233
emit =
234
function(message) {
235
if (Config.VERBOSITY) { throw global.Error(message); }
236
if (global.console && global.console.log) {
237
global.console.log(message);
238
}
239
},
240
241
switchContext =
242
function(from, force) {
243
var oldDoc = doc;
244
lastContext = from;
245
doc = from.ownerDocument || from;
246
if (force || oldDoc !== doc) {
247
root = doc.documentElement;
248
XML_DOCUMENT = doc.createElement('DiV').nodeName == 'DiV';
249
QUIRKS_MODE = !XML_DOCUMENT &&
250
typeof doc.compatMode == 'string' ?
251
doc.compatMode.indexOf('CSS') < 0 :
252
(function() {
253
var style = doc.createElement('div').style;
254
return style && (style.width = 1) && style.width == '1px';
255
})();
256
257
Config.CACHING && Dom.setCache(true, doc);
258
}
259
},
260
261
convertEscapes =
262
function(str) {
263
return str.replace(/\\([0-9a-fA-F]{1,6}\x20?|.)|([\x22\x27])/g, function(substring, p1, p2) {
264
var codePoint, highHex, highSurrogate, lowHex, lowSurrogate;
265
266
if (p2) {
267
return '\\' + p2;
268
}
269
270
if (/^[0-9a-fA-F]/.test(p1)) {
271
codePoint = parseInt(p1, 16);
272
273
if (codePoint < 0 || codePoint > 0x10ffff) {
274
return '\\ufffd';
275
}
276
277
if (codePoint <= 0xffff) {
278
lowHex = '000' + codePoint.toString(16);
279
return '\\u' + lowHex.substr(lowHex.length - 4);
280
}
281
282
codePoint -= 0x10000;
283
highSurrogate = (codePoint >> 10) + 0xd800;
284
lowSurrogate = (codePoint % 0x400) + 0xdc00;
285
highHex = '000' + highSurrogate.toString(16);
286
lowHex = '000' + lowSurrogate.toString(16);
287
288
return '\\u' + highHex.substr(highHex.length - 4) +
289
'\\u' + lowHex.substr(lowHex.length - 4);
290
}
291
292
if (/^[\\\x22\x27]/.test(p1)) {
293
return substring;
294
}
295
296
return p1;
297
});
298
},
299
300
byIdRaw =
301
function(id, elements) {
302
var i = 0, element = null;
303
while ((element = elements[i])) {
304
if (element.getAttribute('id') == id) {
305
break;
306
}
307
++i;
308
}
309
return element;
310
},
311
312
_byId = !('fileSize' in doc) ?
313
function(id, from) {
314
id = id.replace(/\\([^\\]{1})/g, '$1');
315
return from.getElementById && from.getElementById(id) ||
316
byIdRaw(id, from.getElementsByTagName('*'));
317
} :
318
function(id, from) {
319
var element = null;
320
id = id.replace(/\\([^\\]{1})/g, '$1');
321
if (XML_DOCUMENT || from.nodeType != 9) {
322
return byIdRaw(id, from.getElementsByTagName('*'));
323
}
324
if ((element = from.getElementById(id)) &&
325
element.name == id && from.getElementsByName) {
326
return byIdRaw(id, from.getElementsByName(id));
327
}
328
return element;
329
},
330
331
byId =
332
function(id, from) {
333
from || (from = doc);
334
if (lastContext !== from) { switchContext(from); }
335
return _byId(id, from);
336
},
337
338
byTagRaw =
339
function(tag, from) {
340
var any = tag == '*', element = from, elements = global.Array(), next = element.firstChild;
341
any || (tag = tag.toUpperCase());
342
while ((element = next)) {
343
if (element.tagName > '@' && (any || element.tagName.toUpperCase() == tag)) {
344
elements[elements.length] = element;
345
}
346
if ((next = element.firstChild || element.nextSibling)) continue;
347
while (!next && (element = element.parentNode) && element !== from) {
348
next = element.nextSibling;
349
}
350
}
351
return elements;
352
},
353
354
getAttribute =
355
function(node, attribute) {
356
attribute = attribute.toLowerCase();
357
if (typeof node[attribute] == 'object') {
358
return node.attributes[attribute] &&
359
node.attributes[attribute].value || '';
360
}
361
return (
362
attribute == 'type' ? node.getAttribute(attribute) || '' :
363
ATTR_URIDATA[attribute] ? node.getAttribute(attribute, 2) || '' :
364
ATTR_BOOLEAN[attribute] ? node.getAttribute(attribute) ? attribute : 'false' :
365
((node = node.getAttributeNode(attribute)) && node.value) || '');
366
},
367
368
hasAttribute = root.hasAttribute ?
369
function(node, attribute) {
370
return node.hasAttribute(attribute);
371
} :
372
function(node, attribute) {
373
attribute = attribute.toLowerCase();
374
if (ATTR_DEFAULT[attribute]) {
375
return !!node[ATTR_DEFAULT[attribute]];
376
}
377
node = node.getAttributeNode(attribute);
378
return !!(node && node.specified);
379
},
380
381
compile =
382
function(selector, source, mode) {
383
384
var parts = typeof selector == 'string' ? selector.match(reSplitGroup) : selector;
385
386
typeof source == 'string' || (source = '');
387
388
if (parts.length == 1) {
389
source += compileSelector(parts[0], mode ? ACCEPT_NODE : 'f&&f(k);return true;', mode);
390
} else {
391
var i = -1, seen = global.Object(), token;
392
while ((token = parts[++i])) {
393
token = token.replace(reTrimSpaces, '');
394
if (!seen[token] && (seen[token] = true)) {
395
source += compileSelector(token, mode ? ACCEPT_NODE : 'f&&f(k);return true;', mode);
396
}
397
}
398
}
399
400
if (mode)
401
return global.Function('c,s,r,d,h,g,f,v',
402
'var N,n,x=0,k=-1,e;main:while((e=c[++k])){' + source + '}return r;');
403
else
404
return global.Function('e,s,r,d,h,g,f,v',
405
'var N,n,x=0,k=e;' + source + 'return false;');
406
},
407
408
FILTER =
409
'var z=v[@]||(v[@]=[]),l=z.length-1;' +
410
'while(l>=0&&z[l]!==e)--l;' +
411
'if(l!==-1){break;}' +
412
'z[z.length]=e;',
413
414
compileSelector =
415
function(selector, source, mode) {
416
417
var k = 0, expr, match, name, result, status, test, type;
418
419
while (selector) {
420
421
k++;
422
423
if ((match = selector.match(Patterns.universal))) {
424
expr = '';
425
}
426
427
else if ((match = selector.match(Patterns.id))) {
428
source = 'if(' + (XML_DOCUMENT ?
429
's.getAttribute(e,"id")' :
430
'(e.submit?s.getAttribute(e,"id"):e.id)') +
431
'=="' + match[1] + '"' +
432
'){' + source + '}';
433
}
434
435
else if ((match = selector.match(Patterns.tagName))) {
436
source = 'if(e.nodeName' + (XML_DOCUMENT ?
437
'=="' + match[1] + '"' : TO_UPPER_CASE +
438
'=="' + match[1].toUpperCase() + '"') +
439
'){' + source + '}';
440
}
441
442
else if ((match = selector.match(Patterns.className))) {
443
source = 'if((n=' + (XML_DOCUMENT ?
444
'e.getAttribute("class")' : 'e.className') +
445
')&&n.length&&(" "+' + (QUIRKS_MODE ? 'n.toLowerCase()' : 'n') +
446
'.replace(' + reWhiteSpace + '," ")+" ").indexOf(" ' +
447
(QUIRKS_MODE ? match[1].toLowerCase() : match[1]) + ' ")>-1' +
448
'){' + source + '}';
449
}
450
451
else if ((match = selector.match(Patterns.attribute))) {
452
if (match[2] && !Operators[match[2]]) {
453
emit('Unsupported operator in attribute selectors "' + selector + '"');
454
return '';
455
}
456
test = 'false';
457
if (match[2] && match[4] && (test = Operators[match[2]])) {
458
match[4] = convertEscapes(match[4]);
459
type = INSENSITIVE_MAP[match[1].toLowerCase()];
460
test = test.replace(/\%m/g, type ? match[4].toLowerCase() : match[4]);
461
} else if (match[2] == '!=' || match[2] == '=') {
462
test = 'n' + match[2] + '=""';
463
}
464
expr = 'n=s.' + (match[2] ? 'get' : 'has') + 'Attribute(e,"' + match[1] + '")' + (type && match[2] ? '.toLowerCase();' : ';');
465
source = expr + 'if(' + (match[2] ? test : 'n') + '){' + source + '}';
466
}
467
468
else if ((match = selector.match(Patterns.adjacent))) {
469
source = (mode ? '' : FILTER.replace(/@/g, k)) + source;
470
source = 'var N' + k + '=e;while(e&&(e=e.previousSibling)){if(e.nodeName>"@"){' + source + 'break;}}e=N' + k + ';';
471
}
472
473
else if ((match = selector.match(Patterns.relative))) {
474
source = (mode ? '' : FILTER.replace(/@/g, k)) + source;
475
source = 'var N' + k + '=e;e=e.parentNode.firstChild;while(e&&e!==N' + k + '){if(e.nodeName>"@"){' + source + '}e=e.nextSibling;}e=N' + k + ';';
476
}
477
478
else if ((match = selector.match(Patterns.children))) {
479
source = (mode ? '' : FILTER.replace(/@/g, k)) + source;
480
source = 'var N' + k + '=e;while(e&&e!==h&&e!==g&&(e=e.parentNode)){' + source + 'break;}e=N' + k + ';';
481
}
482
483
else if ((match = selector.match(Patterns.ancestor))) {
484
source = (mode ? '' : FILTER.replace(/@/g, k)) + source;
485
source = 'var N' + k + '=e;while(e&&e!==h&&e!==g&&(e=e.parentNode)){' + source + '}e=N' + k + ';';
486
}
487
488
else {
489
490
expr = false;
491
status = false;
492
for (expr in Selectors) {
493
if ((match = selector.match(Selectors[expr].Expression)) && match[1]) {
494
result = Selectors[expr].Callback(match, source);
495
source = result.source;
496
status = result.status;
497
if (status) { break; }
498
}
499
}
500
501
if (!status) {
502
emit('Unknown pseudo-class selector "' + selector + '"');
503
return '';
504
}
505
506
if (!expr) {
507
emit('Unknown token in selector "' + selector + '"');
508
return '';
509
}
510
511
}
512
513
if (!match) {
514
emit('Invalid syntax in selector "' + selector + '"');
515
return '';
516
}
517
518
selector = match && match[match.length - 1];
519
}
520
521
return source;
522
},
523
524
match =
525
function(element, selector, from, callback) {
526
527
var parts;
528
529
if (!(element && element.nodeType == 1)) {
530
emit('Invalid element argument');
531
return false;
532
} else if (typeof selector != 'string') {
533
emit('Invalid selector argument');
534
return false;
535
} else if (lastContext !== from) {
536
switchContext(from || (from = element.ownerDocument));
537
}
538
539
selector = selector.replace(reTrimSpaces, '');
540
541
Config.SHORTCUTS && (selector = Dom.shortcuts(selector, element, from));
542
543
if (lastMatcher != selector) {
544
if ((parts = selector.match(reValidator)) && parts[0] == selector) {
545
isSingleMatch = (parts = selector.match(reSplitGroup)).length < 2;
546
lastMatcher = selector;
547
lastPartsMatch = parts;
548
} else {
549
emit('The string "' + selector + '", is not a valid CSS selector');
550
return false;
551
}
552
} else parts = lastPartsMatch;
553
554
if (!matchResolvers[selector] || matchContexts[selector] !== from) {
555
matchResolvers[selector] = compile(isSingleMatch ? [selector] : parts, '', false);
556
matchContexts[selector] = from;
557
}
558
559
return matchResolvers[selector](element, Snapshot, [ ], doc, root, from, callback, { });
560
},
561
562
first =
563
function(selector, from) {
564
return select(selector, from, function() { return false; })[0] || null;
565
},
566
567
select =
568
function(selector, from, callback) {
569
570
var i, changed, element, elements, parts, token, original = selector;
571
572
if (arguments.length === 0) {
573
emit('Not enough arguments');
574
return [ ];
575
} else if (typeof selector != 'string') {
576
return [ ];
577
} else if (from && !(/1|9|11/).test(from.nodeType)) {
578
emit('Invalid or illegal context element');
579
return [ ];
580
} else if (lastContext !== from) {
581
switchContext(from || (from = doc));
582
}
583
584
if (Config.CACHING && (elements = Dom.loadResults(original, from, doc, root))) {
585
return callback ? concatCall([ ], elements, callback) : elements;
586
}
587
588
selector = selector.replace(reTrimSpaces, '');
589
590
Config.SHORTCUTS && (selector = Dom.shortcuts(selector, from));
591
592
if ((changed = lastSelector != selector)) {
593
if ((parts = selector.match(reValidator)) && parts[0] == selector) {
594
isSingleSelect = (parts = selector.match(reSplitGroup)).length < 2;
595
lastSelector = selector;
596
lastPartsSelect = parts;
597
} else {
598
emit('The string "' + selector + '", is not a valid CSS selector');
599
return [ ];
600
}
601
} else parts = lastPartsSelect;
602
603
if (from.nodeType == 11) {
604
605
elements = byTagRaw('*', from);
606
607
} else if (isSingleSelect) {
608
609
if (changed) {
610
parts = selector.match(reSplitToken);
611
token = parts[parts.length - 1];
612
lastSlice = token.split(':not')[0];
613
lastPosition = selector.length - token.length;
614
}
615
616
if (Config.UNIQUE_ID && (parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) {
617
if ((element = _byId(token, from))) {
618
if (match(element, selector)) {
619
callback && callback(element);
620
elements = global.Array(element);
621
} else elements = global.Array();
622
}
623
}
624
625
else if (Config.UNIQUE_ID && (parts = selector.match(Optimize.ID)) && (token = parts[1])) {
626
if ((element = _byId(token, doc))) {
627
if ('#' + token == selector) {
628
callback && callback(element);
629
elements = global.Array(element);
630
} else if (/[>+~]/.test(selector)) {
631
from = element.parentNode;
632
} else {
633
from = element;
634
}
635
} else elements = global.Array();
636
}
637
638
if (elements) {
639
Config.CACHING && Dom.saveResults(original, from, doc, elements);
640
return elements;
641
}
642
643
if (!XML_DOCUMENT && GEBTN && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) {
644
if ((elements = from.getElementsByTagName(token)).length === 0) return [ ];
645
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace(token, '*');
646
}
647
648
else if (!XML_DOCUMENT && GEBCN && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) {
649
if ((elements = from.getElementsByClassName(token.replace(/\\([^\\]{1})/g, '$1'))).length === 0) return [ ];
650
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token,
651
reOptimizeSelector.test(selector.charAt(selector.indexOf(token) - 1)) ? '' : '*');
652
}
653
654
}
655
656
if (!elements) {
657
if (IE_LT_9) {
658
elements = /^(?:applet|object)$/i.test(from.nodeName) ?
659
from.childNodes : from.all;
660
} else {
661
elements = from.getElementsByTagName('*');
662
}
663
}
664
665
if (!selectResolvers[selector] || selectContexts[selector] !== from) {
666
selectResolvers[selector] = compile(isSingleSelect ? [selector] : parts, REJECT_NODE, true);
667
selectContexts[selector] = from;
668
}
669
670
elements = selectResolvers[selector](elements, Snapshot, [ ], doc, root, from, callback, { });
671
672
Config.CACHING && Dom.saveResults(original, from, doc, elements);
673
674
return elements;
675
},
676
677
FN = function(x) { return x; },
678
679
matchContexts = global.Object(),
680
matchResolvers = global.Object(),
681
682
selectContexts = global.Object(),
683
selectResolvers = global.Object(),
684
685
Snapshot = global.Object({
686
byId: _byId,
687
match: match,
688
select: select,
689
getAttribute: getAttribute,
690
hasAttribute: hasAttribute
691
});
692
693
Tokens = global.Object({
694
prefixes: prefixes,
695
encoding: encoding,
696
operators: operators,
697
whitespace: whitespace,
698
identifier: identifier,
699
attributes: attributes,
700
combinators: combinators,
701
pseudoclass: pseudoclass,
702
pseudoparms: pseudoparms,
703
quotedvalue: quotedvalue
704
});
705
706
Dom.ACCEPT_NODE = ACCEPT_NODE;
707
708
Dom.byId = byId;
709
Dom.match = match;
710
Dom.first = first;
711
Dom.select = select;
712
Dom.compile = compile;
713
Dom.configure = configure;
714
715
Dom.setCache = FN;
716
Dom.shortcuts = FN;
717
Dom.loadResults = FN;
718
Dom.saveResults = FN;
719
720
Dom.emit = emit;
721
Dom.Config = Config;
722
Dom.Snapshot = Snapshot;
723
724
Dom.Operators = Operators;
725
Dom.Selectors = Selectors;
726
727
Dom.Tokens = Tokens;
728
Dom.Version = version;
729
730
Dom.registerOperator =
731
function(symbol, resolver) {
732
Operators[symbol] || (Operators[symbol] = resolver);
733
};
734
735
Dom.registerSelector =
736
function(name, rexp, func) {
737
Selectors[name] || (Selectors[name] = global.Object({
738
Expression: rexp,
739
Callback: func
740
}));
741
};
742
743
switchContext(doc, true);
744
745
});
746
747