Blame view

bower_components/iron-doc-viewer/iron-doc-property.html 6.9 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
6
7
8
9
  <!--
  @license
  Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
  This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
  The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
  The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
  Code distributed by Google as part of the polymer project is also
  subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
  -->
a1a3bc73   Luigi Serra   graphs updates
10
  <link rel="import" href="../marked-element/marked-element.html">
c5169e0e   Renato De Donato   a new hope
11
12
  <link rel="import" href="../paper-styles/typography.html">
  <link rel="import" href="../polymer/polymer.html">
73bcce88   luigser   COMPONENTS
13
14
15
16
17
18
  
  <!--
  Renders documentation describing a specific property of an element.
  
  Give it a hydrolysis `PropertyDescriptor` (via `descriptor`), and watch it go!
  -->
a1a3bc73   Luigi Serra   graphs updates
19
  <dom-module id="iron-doc-property">
a1a3bc73   Luigi Serra   graphs updates
20
  
c5169e0e   Renato De Donato   a new hope
21
22
23
    <link rel="import" type="css" href="iron-doc-property.css">
  
    <template>
73bcce88   luigser   COMPONENTS
24
25
      <div id="transitionMask">
        <div id="signature">
c5169e0e   Renato De Donato   a new hope
26
          <span class="name">{{descriptor.name}}</span><span class="params">(<span>{{_paramText}}</span>)</span>
73bcce88   luigser   COMPONENTS
27
28
29
30
31
          <span class="return" hidden$="{{!descriptor.return}}"><span class="type">{{descriptor.return.type}}</span></span>
        </div>
        <div id="details">
          <div id="meta" hidden$="{{_computeHideMeta(descriptor)}}">
            <span id="type" class="type">{{descriptor.type}}</span>
c5169e0e   Renato De Donato   a new hope
32
33
34
            <span id="default" hidden$="{{_computeHideDefault(descriptor.default)}}">default: <span class="value">{{_computeDefaultDisplay(descriptor.default)}}</span></span>
            <template is="dom-if" if="{{descriptor.readOnly}}"><span>&nbsp;readOnly</span></template>
            <template is="dom-if" if="{{descriptor.notify}}"><span>&nbsp;notify</span></template>
73bcce88   luigser   COMPONENTS
35
36
37
38
39
40
          </div>
          <ol id="params" hidden$="{{_computeHideParams(descriptor,return)}}">
            <template is="dom-repeat" items="{{descriptor.params}}">
              <li hidden$="{{!item.type}}">
                <span class="name">{{item.name}}</span>
                <span class="type">{{item.type}}</span>
e619a3b0   Luigi Serra   Controllet cross ...
41
42
43
                <marked-element markdown="{{item.desc}}">
                  <div class="markdown-html"></div>
                </marked-element>
73bcce88   luigser   COMPONENTS
44
45
46
47
              </li>
            </template>
            <li class="return" hidden$="{{!descriptor.return}}">Returns
              <span class="type">{{descriptor.return.type}}</span>
e619a3b0   Luigi Serra   Controllet cross ...
48
49
50
              <marked-element markdown="{{descriptor.return.desc}}">
                <div class="markdown-html"></div>
              </marked-element>
73bcce88   luigser   COMPONENTS
51
52
            </li>
          </ol>
e619a3b0   Luigi Serra   Controllet cross ...
53
54
55
          <marked-element id="desc" markdown="{{descriptor.desc}}" hidden$="{{!descriptor.desc}}">
            <div class="markdown-html"></div>
          </marked-element>
73bcce88   luigser   COMPONENTS
56
57
58
59
        </div>
      </div>
    </template>
  
a1a3bc73   Luigi Serra   graphs updates
60
  </dom-module>
73bcce88   luigser   COMPONENTS
61
  
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>