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
|
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="../ga.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../lodash/lodash.js"></script>
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../../hydrolysis/hydrolysis-analyzer.html">
<link rel="import" href="../../iron-doc-viewer/iron-doc-viewer.html">
</head>
<body>
<div id="container" style="display:none">
<div id="viewer" style="width: 60%;left: 20%; position: absolute;">
<iron-doc-viewer></iron-doc-viewer>
</div>
</div>
<script>
window.addEventListener("WebComponentsReady", function() {
var hyd = require('hydrolysis');
function hidePrivateToggle() {
document.querySelector('#togglePrivate').setAttribute('style', 'display:none');
}
function hideCollapsedToggle() {
var collapsed = document.querySelector('#toggleCollapsed');
if(collapsed) {
collapsed.setAttribute('style', 'display:none');
}
}
function getElementTag() {
var elementTag = window.location.search.replace('?', '');
if(elementTag === '') {
elementTag = 'vaadin-grid';
}
return elementTag;
}
function getPropertyType(type) {
return type.textContent.replace('Array.<', '').replace('>', '');
}
function createLinkElement(type) {
var a = document.createElement('a');
a.textContent = type.textContent;
a.setAttribute('href', '?' + getPropertyType(type));
return a;
}
function addLinkElementsForDocumentedTypes(result) {
var types = document.querySelectorAll('.type');
for(var i=0;i < types.length; i++) {
var type = getPropertyType(types[i]);
if(result.elementsByTagName[type] || result.behaviorsByName[type]) {
var a = createLinkElement(types[i]);
types[i].textContent = '';
types[i].appendChild(a);
}
}
return result;
}
function hidePropertySetterMethods() {
var propertyNames = _.map(document.querySelector('#properties').querySelectorAll('.name'), function(p) {
return p.textContent;
});
var methods = document.querySelector('#methods').querySelectorAll('iron-doc-property');
_.forEach(methods, function(m) {
if(_.contains(propertyNames, m.querySelector('.name').textContent)) {
m.setAttribute('style', 'display:none');
}
});
}
function hideDefaultValuesForNonPrimitiveTypes(result) {
function isPrimitiveType(t) {
return /^([Nn]umber|[Bb]oolean|[Ss]tring).*/.test(t);
}
_.forEach(document.querySelector('#properties').querySelectorAll('iron-doc-property'), function(p) {
if(!isPrimitiveType(p.querySelector('#type').textContent)) {
p.querySelector('.annotation').setAttribute('style', 'display:none');
}
});
return result;
}
function showDocViewer() {
document.querySelector('#container').setAttribute('style', 'display:block');
}
//*** Main script starts here. ***//
hidePrivateToggle();
hideCollapsedToggle();
hyd.Analyzer.analyze('../../vaadin-grid/vaadin-grid-doc.html')
.then(function(result) {
var descriptor = result.elementsByTagName[getElementTag()] || result.behaviorsByName[getElementTag()];
document.querySelector('iron-doc-viewer').descriptor = descriptor;
return result;
})
.then(hideDefaultValuesForNonPrimitiveTypes)
.then(addLinkElementsForDocumentedTypes)
.then(hidePropertySetterMethods)
.then(showDocViewer);
});
</script>
</body>
</html>
|