UNPKG

968 BPlain TextView Raw
1const dataTypes = [
2 "text/plain",
3 "text/html"
4];
5
6// TODO: Dedup with main file?
7var warnOrLog = function() {
8 (console.warn || console.log).call(arguments);
9}; // IE9 workaround (can't bind console functions).
10var warn = warnOrLog.bind(console, "[clipboard-polyfill]");
11var showWarnings = true;
12export function suppressDTWarnings() {
13 showWarnings = false;
14}
15
16export class DT {
17 private m: {[key:string]: string} = {};
18
19 public setData(type: string, value: string): void {
20 if (showWarnings && dataTypes.indexOf(type) === -1) {
21 warn("Unknown data type: " + type, "Call clipboard.suppressWarnings() "+
22 "to suppress this warning.");
23 }
24
25 this.m[type] = value;
26 }
27
28 public getData(type: string): string | undefined {
29 return this.m[type];
30 }
31
32 // TODO: Provide an iterator consistent with DataTransfer.
33 public forEach(f: (value: string, key: string) => void): void {
34 for (var k in this.m) {
35 f(this.m[k], k);
36 }
37 }
38}