Skip to content

Instantly share code, notes, and snippets.

@mustmodify
Last active September 18, 2018 13:17
Show Gist options
  • Save mustmodify/5fc47b4c628a246b708f18b3e2181537 to your computer and use it in GitHub Desktop.
Save mustmodify/5fc47b4c628a246b708f18b3e2181537 to your computer and use it in GitHub Desktop.
function getMyString(datum)
{
let promise = new Promise(function(resolve, reject)
{
// if readonly mode, reject();
// per https://www.w3.org/TR/html51/editing.html#the-datatransferitem-interface
if datum.kind !== 'string'
reject();
else
// We can't seem to test for 'readonly mode' and don't know about other
// failures, so we still need a timeout to reject.
setTimeout(function(){console.log('timeout reject from getMyString'); reject()}, 1000);
datum.getAsString(resolve);
});
}
}
function getImageURL(data) {
const urlList = data.find(d => (data.kind == 'string') && (data.type.match('^text/uri-list'))
if (urlList)
{
return getMyString(urlList);
} else {
return Promise.resolve();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment