本文整理匯總了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;
}
};