-
Notifications
You must be signed in to change notification settings - Fork 0
/
pmp-help.html
109 lines (96 loc) · 2.75 KB
/
pmp-help.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../marked-element/marked-element.html">
<link rel="import" href="../paper-dialog/paper-dialog.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-dialog-scrollable/paper-dialog-scrollable.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../paper-toast/paper-toast.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../paper-styles/color.html">
<!--
`pmp-help`
pmp-help should show the contents of the file in a paper-dialog
@demo demo/index.html
-->
<dom-module id="pmp-help">
<template>
<style is="custom-style">
: host {
display: block;
width: 100%;
}
#help {
color: var(--pmp-help-icon-color, --paper-indigo-500);
}
#button {
color: var(--pmp-help-paper-button-color);
}
#dialog {
--paper-dialog: {
@apply(--pmp-help-paper-dialog);
}
}
#scrollable {
--paper-dialog-scrollable: {
@apply(--pmp-help-paper-dialog-scrollable);
}
}
</style>
<paper-icon-button icon="help" id="help" title$="[[title]]" on-tap="_toggleDialog"></paper-icon-button>
<paper-dialog id="dialog">
<paper-dialog-scrollable id="scrollable">
<marked-element markdown="{{_fileContent}}">
</marked-element>
</paper-dialog-scrollable>
<div class="buttons">
<paper-button id="button" dialog-dismiss autofocus>Close</paper-button>
</div>
</paper-dialog>
<paper-toast id="toast" duration="[[toastDuration]]" class="fit-bottom" text="Failed to load file."></paper-toast>
</template>
<script>
Polymer({
is: 'pmp-help',
properties: {
_fileContent: {
type: String
},
fileName: {
type: String,
notify: true
},
toastDuration: {
type: Number,
value: 6000
},
title: {
type: String,
value: 'help'
},
},
_getFileContent: function(fileName) {
fetch(fileName).then(response => {
if (response.headers.get("content-type") &&
response.headers.get("content-type").toLowerCase().indexOf("text/x-markdown") >= 0) {
return response.text();
} else {
throw new TypeError();
}
}).then(text => {
this._fileContent = text;
if (this.$.dialog) {
this.$.dialog.open();
}
}).catch(error => {
console.error(error);
if (this.$.toast) {
this.$.toast.open();
}
});
},
_toggleDialog: function() {
this._getFileContent(this.fileName);
}
});
</script>
</dom-module>