-
Notifications
You must be signed in to change notification settings - Fork 6
/
json.export.widget.ts
65 lines (62 loc) · 2.09 KB
/
json.export.widget.ts
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
import { LitElement, html, css, PropertyValueMap } from "lit";
import { customElement } from "lit/decorators.js";
import init from "../../es6/shared";
import { SyncMetaWidget } from "../../widget";
import { CONFIG, getWidgetTagName } from "../../es6/config";
import "https://unpkg.com/jquery@3.6.0/dist/jquery.js";
import "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js";
import MFExport from "../../es6/lib/MFExport";
// widget body used by all syncmeta widgets
@customElement(getWidgetTagName(CONFIG.WIDGET.NAME.JSON_EXPORT))
export class JSONExportWidget extends SyncMetaWidget(
LitElement,
getWidgetTagName(CONFIG.WIDGET.NAME.JSON_EXPORT)
) {
protected firstUpdated(
_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>
): void {
super.firstUpdated(_changedProperties);
$("#json").click(function () {
var $this = $(this).addClass("loading_button");
MFExport.getJSON(function (data, title) {
var link = document.createElement("a");
link.download = title + ".json";
link.href = "data:," + encodeURI(JSON.stringify(data, null, 4));
link.click();
$this.removeClass("loading_button");
});
});
$("#png").click(function () {
var $this = $(this).addClass("loading_button");
MFExport.getImageURL(function (url, title) {
var link = document.createElement("a");
link.download = title + ".png";
link.href = url;
link.click();
$this.removeClass("loading_button");
});
});
}
render() {
return html`
<button id="json">Download JSON</button>
<button id="png">Download PNG Image</button>
`;
}
static styles = css`
/*noinspection CssUnknownTarget,CssUnusedSymbol*/
.loading_button {
background-image: url('<%= grunt.config("baseUrl") %>/img/loading_small.gif');
background-repeat: no-repeat;
background-position: right center;
padding-right: 20px;
}
`;
connectedCallback() {
super.connectedCallback();
init();
}
disconnectedCallback() {
super.disconnectedCallback();
}
}