Repository navigation
Expand file tree
/
Copy pathtests.js
More file actions
97 lines (75 loc) · 2.26 KB
/
Copy pathtests.js
File metadata and controls
97 lines (75 loc) · 2.26 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
Speed({
require: 'http://ajax.googleapis.com/ajax/libs/mootools/1.2.3/mootools.js',
'Child Selector': {
setup: function(){
var append = function(div, depth){
if (!depth) return;
for (var i = 10; i--; )
append(new Element('div').inject(div), depth - 1);
};
append(this.div = new Element('div'), 2);
},
'getElementsByTagName': function(){
var els = this.div.getElementsByTagName('div');
var children = [];
for (var i = els.length; i--; ){
if (els[i].parentNode === this.div) children.push(els[i]);
}
},
'firstChild': function(){
var children = [];
var child = this.div.firstChild;
do {
if (child.tagName.toLowerCase() == 'div')
children.push(child);
} while (child = child.nextSibling);
}
},
'getElementById in IE': {
iterations: 1000,
setup: function(box){
box.innerHTML = Array(100).join('<div></div>') + '<input name="test" /><div id="TEST"></div><div id="test"></div>';
document._getFromId = document._getFromAll = document.getElementById;
if (!window.ActiveXObject) return;
document._getFromId = function(id){
var el = document.getElementById(id);
if (!el) return null;
if (el.attributes.id.value == id) return el;
var all = document.all[id];
for (var i = 1, l = all.length; i < l; i++){
el = all[i];
if (el.attributes.id.value == id) return el;
}
return null;
};
document._getFromAll = function(id){
var all = document.all[id];
if (all){
if (!all.item) all = [all];
for (var i = 0, l = all.length; i < l; i++){
var el = all[i];
if (el.attributes.id.value == id) return el;
}
}
return null;
};
},
teardown: function(){
document._getFromId = document._getFromAll = null;
},
before: function(){
this.failed = false;
},
after: function(){
if (this.failed) console.warn('FAILED');
},
'native method first': function(){
if (document._getFromId('test').id != 'test') this.failed = true;
//if (document._getFromId('TEST').id != 'TEST') this.failed = true;
},
'only document.all': function(){
if (document._getFromAll('test').id != 'test') this.failed = true;
//if (document._getFromAll('TEST').id != 'TEST') this.failed = true;
}
}
});