c5169e0e
Renato De Donato
a new hope
|
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
|
<script>
(function() {
Polymer({
is: 'iron-doc-property',
properties: {
/**
* The [Hydrolysis](https://github.com/PolymerLabs/hydrolysis)-generated
* element descriptor to display details for.
*
* Alternatively, the element descriptor can be provided as JSON via the text content
* of this element.
*
* @type {hydrolysis.PropertyDescriptor}
*/
descriptor: {
type: Object,
observer: '_descriptorChanged',
},
/**
* Whether the property should show a one-liner, or full summary.
*
* Note that this property _is_ reflected as an attribute, but we perform
* the reflection manually. In order to support the CSS transitions, we
* must calculate the element height before setting the attribute.
*/
collapsed: {
type: Boolean,
value: false,
observer: '_collapsedChanged',
},
},
listeners: {
'transitionEnd': '_onTransitionEnd',
'webkitTransitionEnd': '_onTransitionEnd',
},
ready: function() {
this._isReady = true;
},
/**
* Resets any state that was set up for transitions.
*
* We are careful to reset our explicit heights after a transition
* completes, so that the property doesn't clip values if the user resizes
* their viewport.
*/
_onTransitionEnd: function(event) {
if (event.path[0] !== this.$.transitionMask) return;
this.$.transitionMask.style.height = '';
},
_descriptorChanged: function() {
this.toggleAttribute('private', this.descriptor.private);
this.toggleAttribute('configuration', this.descriptor.configuration);
this.toggleAttribute('function', this.descriptor.function);
this._paramText = (this.descriptor.params || []).map(function(param) {
return param.name;
}).join(', ');
},
/**
* Reflects `collapsed` as the `_collapsed` attribute.
*
* "Why not use `reflectToAttribute: true`?", you ask? A fine question!
*
* We avoid simple reflection purely because there is no purely declarative
* way of transitioning to/from `height: auto`. This callback manages
* setting explicit heights for the property so that CSS can interpolate it.
*
* @see #_onTransitionEnd
*/
_collapsedChanged: function() {
if (!this._isReady) {
this.toggleAttribute('_collapsed', this.collapsed);
return;
}
var container = this.$.transitionMask;
var collapsed = this.collapsed;
// Measure `height: auto`, which we will need regardless of transition
// direction. We assume that the collapsed state has an explicit height
// set via CSS rules; so we do not bother measuring that.
container.style.height = 'auto';
var fullHeight = container.offsetHeight;
// Then, we reset to the start state. Changing directions mid-transition
// is _not_ supported!
if (this.collapsed) {
container.style.height = fullHeight + 'px'; // Height 'auto'.
} else {
container.style.height = ''; // Height specified by CSS rule.
}
// We must wait a frame so that the transition engine has a chance to know
// that something actually changed.
requestAnimationFrame(function() {
this.toggleAttribute('_collapsed', collapsed);
if (this.collapsed) {
container.style.height = ''; // Height specified by CSS rule.
} else {
container.style.height = fullHeight + 'px'; // Height 'auto'.
}
}.bind(this));
},
// hidden if no type and no defaults
_computeHideMeta: function(descriptor) {
return descriptor.type === undefined && descriptor.default === undefined;
},
// hidden if no params, and no return value
_computeHideParams: function(descriptor,ret) {
return (!descriptor.params || descriptor.params.length === 0) && !ret;
},
_computeHideDefault: function(def) {
return def === undefined;
},
_computeDefaultDisplay: function(def) {
if (def === '')
return "''";
return def;
}
});
})();
</script>
|