forked from lgarron/clipboard-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDT.ts
38 lines (32 loc) · 968 Bytes
/
DT.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
const dataTypes = [
"text/plain",
"text/html"
];
// TODO: Dedup with main file?
var warnOrLog = function() {
(console.warn || console.log).call(arguments);
}; // IE9 workaround (can't bind console functions).
var warn = warnOrLog.bind(console, "[clipboard-polyfill]");
var showWarnings = true;
export function suppressDTWarnings() {
showWarnings = false;
}
export class DT {
private m: {[key:string]: string} = {};
public setData(type: string, value: string): void {
if (showWarnings && dataTypes.indexOf(type) === -1) {
warn("Unknown data type: " + type, "Call clipboard.suppressWarnings() "+
"to suppress this warning.");
}
this.m[type] = value;
}
public getData(type: string): string | undefined {
return this.m[type];
}
// TODO: Provide an iterator consistent with DataTransfer.
public forEach(f: (value: string, key: string) => void): void {
for (var k in this.m) {
f(this.m[k], k);
}
}
}