{"action":"created","comment":{"url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/comments/52762382","id":52762382,"diff_hunk":"@@ -0,0 +1,64 @@\n+// Copyright (c) Jupyter Development Team.\n+// Distributed under the terms of the Modified BSD License.\n+'use strict';\n+\n+/**\n+ * Copy text to the system clipboard.\n+ *\n+ * #### Notes\n+ * This can only be called in response to a user input event.\n+ */\n+export\n+function copyToClipboard(text: string): void {\n+  let node = document.body;\n+  let handler = (event: ClipboardEvent) => {\n+    let data = event.clipboardData || (window as any).clipboardData;\n+    data.setData('text', text);\n+    event.preventDefault();\n+    node.removeEventListener('copy', handler);\n+  };\n+  node.addEventListener('copy', handler);\n+  generateClipboardEvent(node);\n+}\n+\n+\n+/**\n+ * Generate a clipboard event on a node.\n+ *\n+ * @param node - The element on which to generate the event.\n+ *\n+ * @param type - The type of event to generate: `'copy'` or `'cut'`.\n+ *   `'paste'` events cannot be programmatically generated.\n+ *\n+ * #### Notes\n+ * This can only be called in response to a user input event.\n+ */\n+export\n+function generateClipboardEvent(node: HTMLElement, type='copy'): void {\n+  // http://stackoverflow.com/a/5210367\n+\n+  // Identify selected text.\n+  var sel = window.getSelection();\n+\n+  // Save the current selection.\n+  var savedRanges: any[] = [];\n+  for (var i = 0, len = sel.rangeCount; i < len; ++i) {\n+    savedRanges[i] = sel.getRangeAt(i).cloneRange();\n+  }\n+\n+  // Select the node content.\n+  var range = document.createRange();\n+  range.selectNodeContents(node);\n+  sel.removeAllRanges();\n+  sel.addRange(range);\n+\n+  // Execute the command.\n+  document.execCommand(type);\n+\n+  // Restore the previous selection.\n+  sel = window.getSelection();\n+  sel.removeAllRanges();\n+  for (var i = 0, len = savedRanges.length; i < len; ++i) {\n+    sel.addRange(savedRanges[i]);\n+  }","path":"src/clipboard.ts","position":63,"original_position":63,"commit_id":"f2897a65c421e30a2050aa36c7cc3dcd5bbbb659","original_commit_id":"f2897a65c421e30a2050aa36c7cc3dcd5bbbb659","user":{"login":"sccolbert","id":137289,"avatar_url":"https://avatars.githubusercontent.com/u/137289?v=3","gravatar_id":"","url":"https://api.github.com/users/sccolbert","html_url":"https://github.com/sccolbert","followers_url":"https://api.github.com/users/sccolbert/followers","following_url":"https://api.github.com/users/sccolbert/following{/other_user}","gists_url":"https://api.github.com/users/sccolbert/gists{/gist_id}","starred_url":"https://api.github.com/users/sccolbert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sccolbert/subscriptions","organizations_url":"https://api.github.com/users/sccolbert/orgs","repos_url":"https://api.github.com/users/sccolbert/repos","events_url":"https://api.github.com/users/sccolbert/events{/privacy}","received_events_url":"https://api.github.com/users/sccolbert/received_events","type":"User","site_admin":false},"body":"This feels wrong to me. But whatever. We can fix it later if it becomes a problem.","created_at":"2016-02-12T16:23:15Z","updated_at":"2016-02-12T16:23:15Z","html_url":"https://github.com/jupyter/jupyter-js-domutils/pull/7#discussion_r52762382","pull_request_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/comments/52762382"},"html":{"href":"https://github.com/jupyter/jupyter-js-domutils/pull/7#discussion_r52762382"},"pull_request":{"href":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/7","id":58492551,"html_url":"https://github.com/jupyter/jupyter-js-domutils/pull/7","diff_url":"https://github.com/jupyter/jupyter-js-domutils/pull/7.diff","patch_url":"https://github.com/jupyter/jupyter-js-domutils/pull/7.patch","issue_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/issues/7","number":7,"state":"open","locked":false,"title":"Add clipboard handling","user":{"login":"blink1073","id":2096628,"avatar_url":"https://avatars.githubusercontent.com/u/2096628?v=3","gravatar_id":"","url":"https://api.github.com/users/blink1073","html_url":"https://github.com/blink1073","followers_url":"https://api.github.com/users/blink1073/followers","following_url":"https://api.github.com/users/blink1073/following{/other_user}","gists_url":"https://api.github.com/users/blink1073/gists{/gist_id}","starred_url":"https://api.github.com/users/blink1073/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blink1073/subscriptions","organizations_url":"https://api.github.com/users/blink1073/orgs","repos_url":"https://api.github.com/users/blink1073/repos","events_url":"https://api.github.com/users/blink1073/events{/privacy}","received_events_url":"https://api.github.com/users/blink1073/received_events","type":"User","site_admin":false},"body":"Allow for programmatic access to copy and paste events.","created_at":"2016-02-05T22:19:24Z","updated_at":"2016-02-12T16:23:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e069ee5ab9c970fc1c058ecd8f03d115ed57374f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/7/commits","review_comments_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/7/comments","review_comment_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/issues/7/comments","statuses_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/statuses/f2897a65c421e30a2050aa36c7cc3dcd5bbbb659","head":{"label":"blink1073:clipboard-utils","ref":"clipboard-utils","sha":"f2897a65c421e30a2050aa36c7cc3dcd5bbbb659","user":{"login":"blink1073","id":2096628,"avatar_url":"https://avatars.githubusercontent.com/u/2096628?v=3","gravatar_id":"","url":"https://api.github.com/users/blink1073","html_url":"https://github.com/blink1073","followers_url":"https://api.github.com/users/blink1073/followers","following_url":"https://api.github.com/users/blink1073/following{/other_user}","gists_url":"https://api.github.com/users/blink1073/gists{/gist_id}","starred_url":"https://api.github.com/users/blink1073/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blink1073/subscriptions","organizations_url":"https://api.github.com/users/blink1073/orgs","repos_url":"https://api.github.com/users/blink1073/repos","events_url":"https://api.github.com/users/blink1073/events{/privacy}","received_events_url":"https://api.github.com/users/blink1073/received_events","type":"User","site_admin":false},"repo":{"id":49739148,"name":"jupyter-js-domutils","full_name":"blink1073/jupyter-js-domutils","owner":{"login":"blink1073","id":2096628,"avatar_url":"https://avatars.githubusercontent.com/u/2096628?v=3","gravatar_id":"","url":"https://api.github.com/users/blink1073","html_url":"https://github.com/blink1073","followers_url":"https://api.github.com/users/blink1073/followers","following_url":"https://api.github.com/users/blink1073/following{/other_user}","gists_url":"https://api.github.com/users/blink1073/gists{/gist_id}","starred_url":"https://api.github.com/users/blink1073/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blink1073/subscriptions","organizations_url":"https://api.github.com/users/blink1073/orgs","repos_url":"https://api.github.com/users/blink1073/repos","events_url":"https://api.github.com/users/blink1073/events{/privacy}","received_events_url":"https://api.github.com/users/blink1073/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/blink1073/jupyter-js-domutils","description":"","fork":true,"url":"https://api.github.com/repos/blink1073/jupyter-js-domutils","forks_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/forks","keys_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/teams","hooks_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/hooks","issue_events_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/issues/events{/number}","events_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/events","assignees_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/assignees{/user}","branches_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/branches{/branch}","tags_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/tags","blobs_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/git/refs{/sha}","trees_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/statuses/{sha}","languages_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/languages","stargazers_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/stargazers","contributors_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/contributors","subscribers_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/subscribers","subscription_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/subscription","commits_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/commits{/sha}","git_commits_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/git/commits{/sha}","comments_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/comments{/number}","issue_comment_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/issues/comments{/number}","contents_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/contents/{+path}","compare_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/merges","archive_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/downloads","issues_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/issues{/number}","pulls_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/pulls{/number}","milestones_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/milestones{/number}","notifications_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/labels{/name}","releases_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/releases{/id}","deployments_url":"https://api.github.com/repos/blink1073/jupyter-js-domutils/deployments","created_at":"2016-01-15T19:07:05Z","updated_at":"2016-01-29T22:20:54Z","pushed_at":"2016-02-10T17:46:39Z","git_url":"git://github.com/blink1073/jupyter-js-domutils.git","ssh_url":"git@github.com:blink1073/jupyter-js-domutils.git","clone_url":"https://github.com/blink1073/jupyter-js-domutils.git","svn_url":"https://github.com/blink1073/jupyter-js-domutils","homepage":null,"size":42,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jupyter:master","ref":"master","sha":"6e62a9938b3be0a6b1863aa50ab421d8b08ead6d","user":{"login":"jupyter","id":7388996,"avatar_url":"https://avatars.githubusercontent.com/u/7388996?v=3","gravatar_id":"","url":"https://api.github.com/users/jupyter","html_url":"https://github.com/jupyter","followers_url":"https://api.github.com/users/jupyter/followers","following_url":"https://api.github.com/users/jupyter/following{/other_user}","gists_url":"https://api.github.com/users/jupyter/gists{/gist_id}","starred_url":"https://api.github.com/users/jupyter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jupyter/subscriptions","organizations_url":"https://api.github.com/users/jupyter/orgs","repos_url":"https://api.github.com/users/jupyter/repos","events_url":"https://api.github.com/users/jupyter/events{/privacy}","received_events_url":"https://api.github.com/users/jupyter/received_events","type":"Organization","site_admin":false},"repo":{"id":49735752,"name":"jupyter-js-domutils","full_name":"jupyter/jupyter-js-domutils","owner":{"login":"jupyter","id":7388996,"avatar_url":"https://avatars.githubusercontent.com/u/7388996?v=3","gravatar_id":"","url":"https://api.github.com/users/jupyter","html_url":"https://github.com/jupyter","followers_url":"https://api.github.com/users/jupyter/followers","following_url":"https://api.github.com/users/jupyter/following{/other_user}","gists_url":"https://api.github.com/users/jupyter/gists{/gist_id}","starred_url":"https://api.github.com/users/jupyter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jupyter/subscriptions","organizations_url":"https://api.github.com/users/jupyter/orgs","repos_url":"https://api.github.com/users/jupyter/repos","events_url":"https://api.github.com/users/jupyter/events{/privacy}","received_events_url":"https://api.github.com/users/jupyter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jupyter/jupyter-js-domutils","description":"","fork":false,"url":"https://api.github.com/repos/jupyter/jupyter-js-domutils","forks_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/forks","keys_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/teams","hooks_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/hooks","issue_events_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/issues/events{/number}","events_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/events","assignees_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/assignees{/user}","branches_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/branches{/branch}","tags_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/tags","blobs_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/git/refs{/sha}","trees_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/statuses/{sha}","languages_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/languages","stargazers_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/stargazers","contributors_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/contributors","subscribers_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/subscribers","subscription_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/subscription","commits_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/commits{/sha}","git_commits_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/git/commits{/sha}","comments_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/comments{/number}","issue_comment_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/issues/comments{/number}","contents_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/contents/{+path}","compare_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/merges","archive_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/downloads","issues_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/issues{/number}","pulls_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls{/number}","milestones_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/milestones{/number}","notifications_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/labels{/name}","releases_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/releases{/id}","deployments_url":"https://api.github.com/repos/jupyter/jupyter-js-domutils/deployments","created_at":"2016-01-15T18:02:57Z","updated_at":"2016-01-15T19:24:51Z","pushed_at":"2016-02-10T17:51:18Z","git_url":"git://github.com/jupyter/jupyter-js-domutils.git","ssh_url":"git@github.com:jupyter/jupyter-js-domutils.git","clone_url":"https://github.com/jupyter/jupyter-js-domutils.git","svn_url":"https://github.com/jupyter/jupyter-js-domutils","homepage":null,"size":44,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/7"},"html":{"href":"https://github.com/jupyter/jupyter-js-domutils/pull/7"},"issue":{"href":"https://api.github.com/repos/jupyter/jupyter-js-domutils/issues/7"},"comments":{"href":"https://api.github.com/repos/jupyter/jupyter-js-domutils/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jupyter/jupyter-js-domutils/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/jupyter/jupyter-js-domutils/statuses/f2897a65c421e30a2050aa36c7cc3dcd5bbbb659"}}}}