This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest-api-header.html
94 lines (83 loc) · 2.21 KB
/
rest-api-header.html
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
<link rel="import" href="../polymer/polymer.html">
<!--
`rest-api-header` declares a header for an endpoint.
Example:
<rest-api-page baseUrl="https://httpbin.org">
<rest-api-doc title="Post request" endpoint="/post" method="POST">
<rest-api-header key="Content-Type" values='["application/json"]'>Explanation for the header</rest-api-header>
</rest-api-doc>
</rest-api-page>
@group REST Elements
@element rest-api-header
@hero hero.svg
-->
<dom-module id="rest-api-header">
<template>
<style>
:host {
display: block;
}
</style>
<content></content>
</template>
<script>
(function () {
'use strict';
Polymer({
is: 'rest-api-header',
hostAttributes: {
hidden: true
},
properties: {
/**
* The key of the header
*/
key: String,
/**
* The type of the header value
*/
type: {
type: String,
value: 'string',
readOnly: true
},
/**
* Possible/Example values
* Set it for a default response
*/
values: Array,
/**
* If this header is optional
*/
optional: Boolean,
/**
* Explanation for the header
*/
explanation: String,
/**
* The DOM observer
*/
_observer: Object
},
ready: function () {
console.log("Called");
// Observer mutations for the DOM
this._observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
// Reset the explanation
this.explanation = this.innerText.trim();
}.bind(this));
}.bind(this));
var config = {characterData: true, subtree: true};
this._observer.observe(this, config);
// Set initial explanation
this.explanation = this.innerText.trim();
},
detached: function () {
// Remove observer
this._observer.disconnect();
}
});
})();
</script>
</dom-module>