{"action":"created","comment":{"url":"https://api.github.com/repos/hypothesis/h/pulls/comments/91281218","pull_request_review_id":11788853,"id":91281218,"diff_hunk":"@@ -0,0 +1,211 @@\n+'use strict';\n+\n+const Controller = require('../base/controller');\n+\n+const TEMPLATE_SELECTOR = '.share-widget-template';\n+const CONFIG_ATTR = 'share-widget-config';\n+const TRIGGER_SELECTOR = `[${CONFIG_ATTR}]`;\n+const WIDGET_SELECTOR = '.share-widget';\n+const TARGET_HREF_ATTR = 'share-target-href';\n+const TARGET_HREF_SELECTOR = `[${TARGET_HREF_ATTR}]`;\n+const CLIPBOARD_INPUT_SELECTOR = 'input.share-widget-link__text';\n+const PRIVATE_MSG_SELECTOR = '.share-widget-msg-private';\n+const GROUP_MSG_SELECTOR = '.share-widget-msg-group';\n+\n+const ARROW_PADDING_RIGHT =  16;\n+const ARROW_PADDING_BOTTOM =  5;\n+\n+\n+// Travel up the nodes parents to find a matching\n+// element with the share-widget configuration values\n+const _getParentWithConfig = function(node) {\n+  let configNode = null;\n+  while ((node = node.parentNode)) {\n+    if (node === document.body) {\n+      break;\n+    }\n+    if (node.hasAttribute(CONFIG_ATTR)) {\n+      configNode = node;\n+      break;\n+    }\n+  }\n+  return configNode;\n+};\n+\n+const _getOffset = function (el) {\n+  el = el.getBoundingClientRect();\n+  return {\n+    // adjust for top left of the document\n+    left: el.left + window.scrollX,\n+    top: el.top + window.scrollY,\n+    width: el.width,\n+    height: el.height,\n+  };\n+};\n+\n+\n+class ShareWidget extends Controller {\n+\n+  constructor(element, options = {}) {\n+    super(element, options);\n+\n+    // we are setting up a global listener for\n+    // share widgets. It will only actually run once\n+    // but having a widget at all on the page and all\n+    // other share-widget components will be handled\n+    // through psuedo event delegation.\n+    this._setupGlobalWidget();\n+  }\n+\n+  _setupGlobalWidget() {\n+\n+    if (!window.h || !window.h.shareWidget) {\n+\n+      window.h = Object.assign({}, window.h, {\n+\n+        shareWidget: {\n+\n+          _widgetVisible: false,\n+\n+          _widget: null,\n+\n+          _container: null,\n+\n+          /**\n+           * @typedef {Object} ConfigOptions\n+           * @property {String} url - the url we are enabling to be shared\n+           * @property {Bool} [private] - is the card only visible to this user\n+           * @property {Bool} [group] - is the card posted in a group scope\n+           */\n+\n+          /**\n+           * Update the template based on the config variables passed in\n+           *\n+           * @param  {ConfigOptions} config The details we need to apply update our template\n+           *   with the correct information per card.\n+           */\n+          _renderWidgetTemplate: function(config) {\n+\n+            // copy to clipboard input\n+            this._widget.querySelector(CLIPBOARD_INPUT_SELECTOR).value = config.url;\n+\n+            // social links\n+            Array.from(this._widget.querySelectorAll(TARGET_HREF_SELECTOR)).forEach((target) => {\n+              target.href = target.getAttribute(TARGET_HREF_ATTR).replace('{href}', encodeURI(config.url));\n+            });\n+\n+            // scope access dialog\n+            const privateMessage = this._widget.querySelector(PRIVATE_MSG_SELECTOR);\n+            const groupMessage = this._widget.querySelector(GROUP_MSG_SELECTOR);\n+\n+            privateMessage.style.display = 'none';\n+            groupMessage.style.display = 'none';\n+\n+            if (config.private) {\n+              privateMessage.style.display = 'block';\n+            } else if (config.group) {\n+              groupMessage.style.display = 'block';\n+            }\n+          },\n+\n+\n+          /**\n+           * Given a node, update the template, repostion the widget properly,\n+           *  and make it visible.\n+           *\n+           * @param  {HTMLNode} node The trigger node that we will place the widget\n+           *   next to.\n+           * @param  {ConfigOptions} config Passed through to rendering/interpolation\n+           */\n+          showForNode: function(node, config) {\n+\n+            if (!node || !config) {\n+              return;\n+            }\n+\n+            this._renderWidgetTemplate(config);\n+\n+            // offsets affecting height need to be updated after variable replacement\n+            const widgetOffsets =  _getOffset(this._widget);\n+            const nodeOffset = _getOffset(node);\n+\n+            // console.log(this._widget, nodeOffset.top, widgetOffsets.height, ARROW_PADDING_BOTTOM);\n+\n+            this._widget.style.top = (nodeOffset.top - widgetOffsets.height - ARROW_PADDING_BOTTOM) + 'px';\n+            this._widget.style.left = ((ARROW_PADDING_RIGHT + nodeOffset.left + (nodeOffset.width / 2)) - widgetOffsets.width) + 'px';\n+\n+            this._container.style.visibility = 'visible';\n+\n+            this._widgetVisible = true;\n+          },\n+\n+          hide: function() {\n+            this._container.style.visibility = 'hidden';\n+            this._widgetVisible = false;\n+          },\n+\n+\n+          init: function(containerElement) {\n+\n+            this._container = containerElement;\n+            this._widget = this._container.querySelector(WIDGET_SELECTOR);\n+\n+            // on initialize we need to reset container visbility\n+            this.hide();\n+\n+\n+            window.document.body.addEventListener('click', (event) => {\n+              const target = event.target;\n+\n+              // do nothing if we are clicking inside of the widget\n+              if (containerElement.contains(target) || containerElement === target) {","path":"h/static/scripts/controllers/share-widget-controller.js","position":161,"original_position":161,"commit_id":"3de95ac212bd9fd3183c43658c72b09f07dc6cbf","original_commit_id":"3de95ac212bd9fd3183c43658c72b09f07dc6cbf","user":{"login":"robertknight","id":2458,"avatar_url":"https://avatars.githubusercontent.com/u/2458?v=3","gravatar_id":"","url":"https://api.github.com/users/robertknight","html_url":"https://github.com/robertknight","followers_url":"https://api.github.com/users/robertknight/followers","following_url":"https://api.github.com/users/robertknight/following{/other_user}","gists_url":"https://api.github.com/users/robertknight/gists{/gist_id}","starred_url":"https://api.github.com/users/robertknight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertknight/subscriptions","organizations_url":"https://api.github.com/users/robertknight/orgs","repos_url":"https://api.github.com/users/robertknight/repos","events_url":"https://api.github.com/users/robertknight/events{/privacy}","received_events_url":"https://api.github.com/users/robertknight/received_events","type":"User","site_admin":false},"body":"This surprised me, but [Element#contains](https://dom.spec.whatwg.org/#dom-node-contains) is _inclusive_ so `someElement.contains(someElement)` returns true and you don't need the second branch of the `if` statement here.","created_at":"2016-12-07T12:17:29Z","updated_at":"2016-12-07T12:17:29Z","html_url":"https://github.com/hypothesis/h/pull/4174#discussion_r91281218","pull_request_url":"https://api.github.com/repos/hypothesis/h/pulls/4174","_links":{"self":{"href":"https://api.github.com/repos/hypothesis/h/pulls/comments/91281218"},"html":{"href":"https://github.com/hypothesis/h/pull/4174#discussion_r91281218"},"pull_request":{"href":"https://api.github.com/repos/hypothesis/h/pulls/4174"}}},"pull_request":{"url":"https://api.github.com/repos/hypothesis/h/pulls/4174","id":96768711,"html_url":"https://github.com/hypothesis/h/pull/4174","diff_url":"https://github.com/hypothesis/h/pull/4174.diff","patch_url":"https://github.com/hypothesis/h/pull/4174.patch","issue_url":"https://api.github.com/repos/hypothesis/h/issues/4174","number":4174,"state":"open","locked":false,"title":"Share link on results","user":{"login":"sean-roberts","id":950274,"avatar_url":"https://avatars.githubusercontent.com/u/950274?v=3","gravatar_id":"","url":"https://api.github.com/users/sean-roberts","html_url":"https://github.com/sean-roberts","followers_url":"https://api.github.com/users/sean-roberts/followers","following_url":"https://api.github.com/users/sean-roberts/following{/other_user}","gists_url":"https://api.github.com/users/sean-roberts/gists{/gist_id}","starred_url":"https://api.github.com/users/sean-roberts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sean-roberts/subscriptions","organizations_url":"https://api.github.com/users/sean-roberts/orgs","repos_url":"https://api.github.com/users/sean-roberts/repos","events_url":"https://api.github.com/users/sean-roberts/events{/privacy}","received_events_url":"https://api.github.com/users/sean-roberts/received_events","type":"User","site_admin":false},"body":"Fixes #4113 \r\n\r\nThe intent for my changes was to make it easy for use to extract the share-widget module into it's on encapsulated module that can be used in client, h, etc. It only goes as far as to make the pieces that will be pulled in more isolated from the h app itself.\r\n\r\nThe diff looks large but there were lots of files (icons, importing stuff) that are brand new but largely a carry over from what worked in the client (besides the JS since before it was angular based).","created_at":"2016-12-06T17:26:14Z","updated_at":"2016-12-07T12:17:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a9d26e31e66c151e39bbc9798c162da8c4443564","assignee":{"login":"robertknight","id":2458,"avatar_url":"https://avatars.githubusercontent.com/u/2458?v=3","gravatar_id":"","url":"https://api.github.com/users/robertknight","html_url":"https://github.com/robertknight","followers_url":"https://api.github.com/users/robertknight/followers","following_url":"https://api.github.com/users/robertknight/following{/other_user}","gists_url":"https://api.github.com/users/robertknight/gists{/gist_id}","starred_url":"https://api.github.com/users/robertknight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertknight/subscriptions","organizations_url":"https://api.github.com/users/robertknight/orgs","repos_url":"https://api.github.com/users/robertknight/repos","events_url":"https://api.github.com/users/robertknight/events{/privacy}","received_events_url":"https://api.github.com/users/robertknight/received_events","type":"User","site_admin":false},"assignees":[{"login":"robertknight","id":2458,"avatar_url":"https://avatars.githubusercontent.com/u/2458?v=3","gravatar_id":"","url":"https://api.github.com/users/robertknight","html_url":"https://github.com/robertknight","followers_url":"https://api.github.com/users/robertknight/followers","following_url":"https://api.github.com/users/robertknight/following{/other_user}","gists_url":"https://api.github.com/users/robertknight/gists{/gist_id}","starred_url":"https://api.github.com/users/robertknight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertknight/subscriptions","organizations_url":"https://api.github.com/users/robertknight/orgs","repos_url":"https://api.github.com/users/robertknight/repos","events_url":"https://api.github.com/users/robertknight/events{/privacy}","received_events_url":"https://api.github.com/users/robertknight/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/hypothesis/h/pulls/4174/commits","review_comments_url":"https://api.github.com/repos/hypothesis/h/pulls/4174/comments","review_comment_url":"https://api.github.com/repos/hypothesis/h/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hypothesis/h/issues/4174/comments","statuses_url":"https://api.github.com/repos/hypothesis/h/statuses/3de95ac212bd9fd3183c43658c72b09f07dc6cbf","head":{"label":"hypothesis:share-link-on-results","ref":"share-link-on-results","sha":"3de95ac212bd9fd3183c43658c72b09f07dc6cbf","user":{"login":"hypothesis","id":1243215,"avatar_url":"https://avatars.githubusercontent.com/u/1243215?v=3","gravatar_id":"","url":"https://api.github.com/users/hypothesis","html_url":"https://github.com/hypothesis","followers_url":"https://api.github.com/users/hypothesis/followers","following_url":"https://api.github.com/users/hypothesis/following{/other_user}","gists_url":"https://api.github.com/users/hypothesis/gists{/gist_id}","starred_url":"https://api.github.com/users/hypothesis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hypothesis/subscriptions","organizations_url":"https://api.github.com/users/hypothesis/orgs","repos_url":"https://api.github.com/users/hypothesis/repos","events_url":"https://api.github.com/users/hypothesis/events{/privacy}","received_events_url":"https://api.github.com/users/hypothesis/received_events","type":"Organization","site_admin":false},"repo":{"id":3910945,"name":"h","full_name":"hypothesis/h","owner":{"login":"hypothesis","id":1243215,"avatar_url":"https://avatars.githubusercontent.com/u/1243215?v=3","gravatar_id":"","url":"https://api.github.com/users/hypothesis","html_url":"https://github.com/hypothesis","followers_url":"https://api.github.com/users/hypothesis/followers","following_url":"https://api.github.com/users/hypothesis/following{/other_user}","gists_url":"https://api.github.com/users/hypothesis/gists{/gist_id}","starred_url":"https://api.github.com/users/hypothesis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hypothesis/subscriptions","organizations_url":"https://api.github.com/users/hypothesis/orgs","repos_url":"https://api.github.com/users/hypothesis/repos","events_url":"https://api.github.com/users/hypothesis/events{/privacy}","received_events_url":"https://api.github.com/users/hypothesis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hypothesis/h","description":"Annotate with anyone, anywhere.","fork":false,"url":"https://api.github.com/repos/hypothesis/h","forks_url":"https://api.github.com/repos/hypothesis/h/forks","keys_url":"https://api.github.com/repos/hypothesis/h/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hypothesis/h/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hypothesis/h/teams","hooks_url":"https://api.github.com/repos/hypothesis/h/hooks","issue_events_url":"https://api.github.com/repos/hypothesis/h/issues/events{/number}","events_url":"https://api.github.com/repos/hypothesis/h/events","assignees_url":"https://api.github.com/repos/hypothesis/h/assignees{/user}","branches_url":"https://api.github.com/repos/hypothesis/h/branches{/branch}","tags_url":"https://api.github.com/repos/hypothesis/h/tags","blobs_url":"https://api.github.com/repos/hypothesis/h/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hypothesis/h/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hypothesis/h/git/refs{/sha}","trees_url":"https://api.github.com/repos/hypothesis/h/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hypothesis/h/statuses/{sha}","languages_url":"https://api.github.com/repos/hypothesis/h/languages","stargazers_url":"https://api.github.com/repos/hypothesis/h/stargazers","contributors_url":"https://api.github.com/repos/hypothesis/h/contributors","subscribers_url":"https://api.github.com/repos/hypothesis/h/subscribers","subscription_url":"https://api.github.com/repos/hypothesis/h/subscription","commits_url":"https://api.github.com/repos/hypothesis/h/commits{/sha}","git_commits_url":"https://api.github.com/repos/hypothesis/h/git/commits{/sha}","comments_url":"https://api.github.com/repos/hypothesis/h/comments{/number}","issue_comment_url":"https://api.github.com/repos/hypothesis/h/issues/comments{/number}","contents_url":"https://api.github.com/repos/hypothesis/h/contents/{+path}","compare_url":"https://api.github.com/repos/hypothesis/h/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hypothesis/h/merges","archive_url":"https://api.github.com/repos/hypothesis/h/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hypothesis/h/downloads","issues_url":"https://api.github.com/repos/hypothesis/h/issues{/number}","pulls_url":"https://api.github.com/repos/hypothesis/h/pulls{/number}","milestones_url":"https://api.github.com/repos/hypothesis/h/milestones{/number}","notifications_url":"https://api.github.com/repos/hypothesis/h/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hypothesis/h/labels{/name}","releases_url":"https://api.github.com/repos/hypothesis/h/releases{/id}","deployments_url":"https://api.github.com/repos/hypothesis/h/deployments","created_at":"2012-04-02T19:56:59Z","updated_at":"2016-12-05T20:59:10Z","pushed_at":"2016-12-07T12:00:38Z","git_url":"git://github.com/hypothesis/h.git","ssh_url":"git@github.com:hypothesis/h.git","clone_url":"https://github.com/hypothesis/h.git","svn_url":"https://github.com/hypothesis/h","homepage":"https://hypothes.is/","size":32249,"stargazers_count":746,"watchers_count":746,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":161,"mirror_url":null,"open_issues_count":94,"forks":161,"open_issues":94,"watchers":746,"default_branch":"master"}},"base":{"label":"hypothesis:master","ref":"master","sha":"b1579f4ec09f2318eac05abb9dc3b718b44af3a2","user":{"login":"hypothesis","id":1243215,"avatar_url":"https://avatars.githubusercontent.com/u/1243215?v=3","gravatar_id":"","url":"https://api.github.com/users/hypothesis","html_url":"https://github.com/hypothesis","followers_url":"https://api.github.com/users/hypothesis/followers","following_url":"https://api.github.com/users/hypothesis/following{/other_user}","gists_url":"https://api.github.com/users/hypothesis/gists{/gist_id}","starred_url":"https://api.github.com/users/hypothesis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hypothesis/subscriptions","organizations_url":"https://api.github.com/users/hypothesis/orgs","repos_url":"https://api.github.com/users/hypothesis/repos","events_url":"https://api.github.com/users/hypothesis/events{/privacy}","received_events_url":"https://api.github.com/users/hypothesis/received_events","type":"Organization","site_admin":false},"repo":{"id":3910945,"name":"h","full_name":"hypothesis/h","owner":{"login":"hypothesis","id":1243215,"avatar_url":"https://avatars.githubusercontent.com/u/1243215?v=3","gravatar_id":"","url":"https://api.github.com/users/hypothesis","html_url":"https://github.com/hypothesis","followers_url":"https://api.github.com/users/hypothesis/followers","following_url":"https://api.github.com/users/hypothesis/following{/other_user}","gists_url":"https://api.github.com/users/hypothesis/gists{/gist_id}","starred_url":"https://api.github.com/users/hypothesis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hypothesis/subscriptions","organizations_url":"https://api.github.com/users/hypothesis/orgs","repos_url":"https://api.github.com/users/hypothesis/repos","events_url":"https://api.github.com/users/hypothesis/events{/privacy}","received_events_url":"https://api.github.com/users/hypothesis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hypothesis/h","description":"Annotate with anyone, anywhere.","fork":false,"url":"https://api.github.com/repos/hypothesis/h","forks_url":"https://api.github.com/repos/hypothesis/h/forks","keys_url":"https://api.github.com/repos/hypothesis/h/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hypothesis/h/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hypothesis/h/teams","hooks_url":"https://api.github.com/repos/hypothesis/h/hooks","issue_events_url":"https://api.github.com/repos/hypothesis/h/issues/events{/number}","events_url":"https://api.github.com/repos/hypothesis/h/events","assignees_url":"https://api.github.com/repos/hypothesis/h/assignees{/user}","branches_url":"https://api.github.com/repos/hypothesis/h/branches{/branch}","tags_url":"https://api.github.com/repos/hypothesis/h/tags","blobs_url":"https://api.github.com/repos/hypothesis/h/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hypothesis/h/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hypothesis/h/git/refs{/sha}","trees_url":"https://api.github.com/repos/hypothesis/h/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hypothesis/h/statuses/{sha}","languages_url":"https://api.github.com/repos/hypothesis/h/languages","stargazers_url":"https://api.github.com/repos/hypothesis/h/stargazers","contributors_url":"https://api.github.com/repos/hypothesis/h/contributors","subscribers_url":"https://api.github.com/repos/hypothesis/h/subscribers","subscription_url":"https://api.github.com/repos/hypothesis/h/subscription","commits_url":"https://api.github.com/repos/hypothesis/h/commits{/sha}","git_commits_url":"https://api.github.com/repos/hypothesis/h/git/commits{/sha}","comments_url":"https://api.github.com/repos/hypothesis/h/comments{/number}","issue_comment_url":"https://api.github.com/repos/hypothesis/h/issues/comments{/number}","contents_url":"https://api.github.com/repos/hypothesis/h/contents/{+path}","compare_url":"https://api.github.com/repos/hypothesis/h/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hypothesis/h/merges","archive_url":"https://api.github.com/repos/hypothesis/h/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hypothesis/h/downloads","issues_url":"https://api.github.com/repos/hypothesis/h/issues{/number}","pulls_url":"https://api.github.com/repos/hypothesis/h/pulls{/number}","milestones_url":"https://api.github.com/repos/hypothesis/h/milestones{/number}","notifications_url":"https://api.github.com/repos/hypothesis/h/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hypothesis/h/labels{/name}","releases_url":"https://api.github.com/repos/hypothesis/h/releases{/id}","deployments_url":"https://api.github.com/repos/hypothesis/h/deployments","created_at":"2012-04-02T19:56:59Z","updated_at":"2016-12-05T20:59:10Z","pushed_at":"2016-12-07T12:00:38Z","git_url":"git://github.com/hypothesis/h.git","ssh_url":"git@github.com:hypothesis/h.git","clone_url":"https://github.com/hypothesis/h.git","svn_url":"https://github.com/hypothesis/h","homepage":"https://hypothes.is/","size":32249,"stargazers_count":746,"watchers_count":746,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":161,"mirror_url":null,"open_issues_count":94,"forks":161,"open_issues":94,"watchers":746,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hypothesis/h/pulls/4174"},"html":{"href":"https://github.com/hypothesis/h/pull/4174"},"issue":{"href":"https://api.github.com/repos/hypothesis/h/issues/4174"},"comments":{"href":"https://api.github.com/repos/hypothesis/h/issues/4174/comments"},"review_comments":{"href":"https://api.github.com/repos/hypothesis/h/pulls/4174/comments"},"review_comment":{"href":"https://api.github.com/repos/hypothesis/h/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hypothesis/h/pulls/4174/commits"},"statuses":{"href":"https://api.github.com/repos/hypothesis/h/statuses/3de95ac212bd9fd3183c43658c72b09f07dc6cbf"}}}}
{"actor":{"display_login":"robertknight"}}