本文整理汇总了TypeScript中@ephox/dom-globals.DataTransfer类的典型用法代码示例。如果您正苦于以下问题:TypeScript DataTransfer类的具体用法?TypeScript DataTransfer怎么用?TypeScript DataTransfer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataTransfer类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Files
const getDataTransferItems = (dataTransfer: DataTransfer): ClipboardContents => {
const items = {};
const mceInternalUrlPrefix = 'data:text/mce-internal,';
if (dataTransfer) {
// Use old WebKit/IE API
if (dataTransfer.getData) {
const legacyText = dataTransfer.getData('Text');
if (legacyText && legacyText.length > 0) {
if (legacyText.indexOf(mceInternalUrlPrefix) === -1) {
items['text/plain'] = legacyText;
}
}
}
if (dataTransfer.types) {
for (let i = 0; i < dataTransfer.types.length; i++) {
const contentType = dataTransfer.types[i];
try { // IE11 throws exception when contentType is Files (type is present but data cannot be retrieved via getData())
items[contentType] = dataTransfer.getData(contentType);
} catch (ex) {
items[contentType] = ''; // useless in general, but for consistency across browsers
}
}
}
}
return items;
};
示例2: catch
const setHtml5Clipboard = (clipboardData: DataTransfer, html: string, text: string) => {
if (hasWorkingClipboardApi(clipboardData)) {
try {
clipboardData.clearData();
clipboardData.setData('text/html', html);
clipboardData.setData('text/plain', text);
clipboardData.setData(InternalHtml.internalHtmlMime(), html);
return true;
} catch (e) {
return false;
}
} else {
return false;
}
};