Skip to content

Instantly share code, notes, and snippets.

@thomaswrenn
Created September 13, 2017 20:33
Show Gist options
  • Save thomaswrenn/3fbc923ab1f8316a3aeb3f0651d81c53 to your computer and use it in GitHub Desktop.
Save thomaswrenn/3fbc923ab1f8316a3aeb3f0651d81c53 to your computer and use it in GitHub Desktop.
function _pasteText($element, text, { availableFormats }) {
  const pasteEvent = new window.Event('paste');
  pasteEvent.clipboardData = {
    getData: type => (type in availableFormats) ? text || '' : ''
  };
  placeCursorAtStartOfNode($element[0]);
  $element[0].dispatchEvent(pasteEvent);
  $element.closest('.AsMediumEditor').trigger(Ember.$.Event('input'));
}
_pasteText(this.$('.AsMediumEditor'), HTML_WITH_ONCLICK_HANDLER, { availableFormats: ['text/html', 'text/plain'] });
_pasteText(this.$('.AsMediumEditor'), 'Foo\nBar\nBaz', { availableFormats: ['text/plain'] });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment