{"action":"created","comment":{"url":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/comments/23825398","id":23825398,"diff_hunk":"@@ -17,18 +23,55 @@ angular.module('lt.tooltip', [])\n             $tooltipEl = angular.element(el.querySelector('.tooltip')),\n             $transcluded = angular.element(el.querySelector('.transcluded')),\n             rect = el.getBoundingClientRect();\n-\n+        \n         return {\n             top: rect.top,\n             left: rect.left,\n             tooltipHeight: $tooltipEl[0].offsetHeight,\n             tooltipWidth: $tooltipEl[0].offsetWidth,\n             transcludedHeight: $transcluded[0].offsetHeight,\n-            transcludedWidth: $transcluded[0].offsetWidth\n+            transcludedWidth: $transcluded[0].offsetWidth,\n+            windowHeight: $window.innerHeight,\n+            windowWidth: $window.innerWidth\n         };\n     };\n \n-    // Calculate the position of the tooltip. Returns the position as an object.\n+    // Determine from the given position and dimensions if the tooltip will\n+    // end up completely within the window (and be visible).\n+    // Returns true if the tooltip will be visible, false otherwise.\n+    var isWithinVisibleArea = function (position, dimensions) {\n+        var top = position.top;\n+        var right = position.left + dimensions.tooltipWidth;\n+        var bottom = position.top + dimensions.tooltipHeight;\n+        var left = position.left;\n+        return top >= 0 && left >= 0 &&\n+            right < $window.innerWidth && bottom < $window.innerHeight;\n+    };\n+\n+    // Removes a given direction from the given array of directions.\n+    // Returns the updated array.\n+    var removeDirection = function (direction, directions) {\n+        return directions.map(function(dir) {\n+            if (dir === direction) {\n+                return;\n+            }\n+            return dir;\n+        });\n+    };\n+\n+    // Retrieve the next direction in the priority list, as a string.\n+    var nextDirection = function (direction, directionPriorities) {\n+        var directions = directionPriorities || DEFAULT_DIRECTION_PRIORITY;\n+        var index = directions.indexOf(direction);\n+        ++index;","path":"demo/src/lt.tooltip.js","position":67,"original_position":67,"commit_id":"36145e6b61dcc10c29b2134d866549c8e29cf33a","original_commit_id":"36145e6b61dcc10c29b2134d866549c8e29cf33a","user":{"login":"tkayali","id":585453,"avatar_url":"https://avatars.githubusercontent.com/u/585453?v=3","gravatar_id":"","url":"https://api.github.com/users/tkayali","html_url":"https://github.com/tkayali","followers_url":"https://api.github.com/users/tkayali/followers","following_url":"https://api.github.com/users/tkayali/following{/other_user}","gists_url":"https://api.github.com/users/tkayali/gists{/gist_id}","starred_url":"https://api.github.com/users/tkayali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkayali/subscriptions","organizations_url":"https://api.github.com/users/tkayali/orgs","repos_url":"https://api.github.com/users/tkayali/repos","events_url":"https://api.github.com/users/tkayali/events{/privacy}","received_events_url":"https://api.github.com/users/tkayali/received_events","type":"User","site_admin":false},"body":"You can combine 65 + 66 into one line.","created_at":"2015-01-30T05:57:13Z","updated_at":"2015-01-30T05:57:13Z","html_url":"https://github.com/liamitus/lt.tooltip/pull/6#discussion_r23825398","pull_request_url":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/comments/23825398"},"html":{"href":"https://github.com/liamitus/lt.tooltip/pull/6#discussion_r23825398"},"pull_request":{"href":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/6","id":28332593,"html_url":"https://github.com/liamitus/lt.tooltip/pull/6","diff_url":"https://github.com/liamitus/lt.tooltip/pull/6.diff","patch_url":"https://github.com/liamitus/lt.tooltip/pull/6.patch","issue_url":"https://api.github.com/repos/liamitus/lt.tooltip/issues/6","number":6,"state":"open","locked":false,"title":"Tooltips are now aware of their surroundings!","user":{"login":"tkayali","id":585453,"avatar_url":"https://avatars.githubusercontent.com/u/585453?v=3","gravatar_id":"","url":"https://api.github.com/users/tkayali","html_url":"https://github.com/tkayali","followers_url":"https://api.github.com/users/tkayali/followers","following_url":"https://api.github.com/users/tkayali/following{/other_user}","gists_url":"https://api.github.com/users/tkayali/gists{/gist_id}","starred_url":"https://api.github.com/users/tkayali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkayali/subscriptions","organizations_url":"https://api.github.com/users/tkayali/orgs","repos_url":"https://api.github.com/users/tkayali/repos","events_url":"https://api.github.com/users/tkayali/events{/privacy}","received_events_url":"https://api.github.com/users/tkayali/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-30T01:58:39Z","updated_at":"2015-01-30T05:57:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2eed6e4111e779f68b43c2aedeca881e73fcef89","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/6/commits","review_comments_url":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/6/comments","review_comment_url":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/comments/{number}","comments_url":"https://api.github.com/repos/liamitus/lt.tooltip/issues/6/comments","statuses_url":"https://api.github.com/repos/liamitus/lt.tooltip/statuses/36145e6b61dcc10c29b2134d866549c8e29cf33a","head":{"label":"liamitus:spatial_awareness","ref":"spatial_awareness","sha":"36145e6b61dcc10c29b2134d866549c8e29cf33a","user":{"login":"liamitus","id":780354,"avatar_url":"https://avatars.githubusercontent.com/u/780354?v=3","gravatar_id":"","url":"https://api.github.com/users/liamitus","html_url":"https://github.com/liamitus","followers_url":"https://api.github.com/users/liamitus/followers","following_url":"https://api.github.com/users/liamitus/following{/other_user}","gists_url":"https://api.github.com/users/liamitus/gists{/gist_id}","starred_url":"https://api.github.com/users/liamitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liamitus/subscriptions","organizations_url":"https://api.github.com/users/liamitus/orgs","repos_url":"https://api.github.com/users/liamitus/repos","events_url":"https://api.github.com/users/liamitus/events{/privacy}","received_events_url":"https://api.github.com/users/liamitus/received_events","type":"User","site_admin":false},"repo":{"id":29402360,"name":"lt.tooltip","full_name":"liamitus/lt.tooltip","owner":{"login":"liamitus","id":780354,"avatar_url":"https://avatars.githubusercontent.com/u/780354?v=3","gravatar_id":"","url":"https://api.github.com/users/liamitus","html_url":"https://github.com/liamitus","followers_url":"https://api.github.com/users/liamitus/followers","following_url":"https://api.github.com/users/liamitus/following{/other_user}","gists_url":"https://api.github.com/users/liamitus/gists{/gist_id}","starred_url":"https://api.github.com/users/liamitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liamitus/subscriptions","organizations_url":"https://api.github.com/users/liamitus/orgs","repos_url":"https://api.github.com/users/liamitus/repos","events_url":"https://api.github.com/users/liamitus/events{/privacy}","received_events_url":"https://api.github.com/users/liamitus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/liamitus/lt.tooltip","description":"Liam & Tarif's Tooltip, built with Angular.js and designed to be fast and easy to use.","fork":false,"url":"https://api.github.com/repos/liamitus/lt.tooltip","forks_url":"https://api.github.com/repos/liamitus/lt.tooltip/forks","keys_url":"https://api.github.com/repos/liamitus/lt.tooltip/keys{/key_id}","collaborators_url":"https://api.github.com/repos/liamitus/lt.tooltip/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/liamitus/lt.tooltip/teams","hooks_url":"https://api.github.com/repos/liamitus/lt.tooltip/hooks","issue_events_url":"https://api.github.com/repos/liamitus/lt.tooltip/issues/events{/number}","events_url":"https://api.github.com/repos/liamitus/lt.tooltip/events","assignees_url":"https://api.github.com/repos/liamitus/lt.tooltip/assignees{/user}","branches_url":"https://api.github.com/repos/liamitus/lt.tooltip/branches{/branch}","tags_url":"https://api.github.com/repos/liamitus/lt.tooltip/tags","blobs_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/refs{/sha}","trees_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/trees{/sha}","statuses_url":"https://api.github.com/repos/liamitus/lt.tooltip/statuses/{sha}","languages_url":"https://api.github.com/repos/liamitus/lt.tooltip/languages","stargazers_url":"https://api.github.com/repos/liamitus/lt.tooltip/stargazers","contributors_url":"https://api.github.com/repos/liamitus/lt.tooltip/contributors","subscribers_url":"https://api.github.com/repos/liamitus/lt.tooltip/subscribers","subscription_url":"https://api.github.com/repos/liamitus/lt.tooltip/subscription","commits_url":"https://api.github.com/repos/liamitus/lt.tooltip/commits{/sha}","git_commits_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/commits{/sha}","comments_url":"https://api.github.com/repos/liamitus/lt.tooltip/comments{/number}","issue_comment_url":"https://api.github.com/repos/liamitus/lt.tooltip/issues/comments/{number}","contents_url":"https://api.github.com/repos/liamitus/lt.tooltip/contents/{+path}","compare_url":"https://api.github.com/repos/liamitus/lt.tooltip/compare/{base}...{head}","merges_url":"https://api.github.com/repos/liamitus/lt.tooltip/merges","archive_url":"https://api.github.com/repos/liamitus/lt.tooltip/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/liamitus/lt.tooltip/downloads","issues_url":"https://api.github.com/repos/liamitus/lt.tooltip/issues{/number}","pulls_url":"https://api.github.com/repos/liamitus/lt.tooltip/pulls{/number}","milestones_url":"https://api.github.com/repos/liamitus/lt.tooltip/milestones{/number}","notifications_url":"https://api.github.com/repos/liamitus/lt.tooltip/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/liamitus/lt.tooltip/labels{/name}","releases_url":"https://api.github.com/repos/liamitus/lt.tooltip/releases{/id}","created_at":"2015-01-17T19:14:06Z","updated_at":"2015-01-17T19:37:12Z","pushed_at":"2015-01-30T01:57:21Z","git_url":"git://github.com/liamitus/lt.tooltip.git","ssh_url":"git@github.com:liamitus/lt.tooltip.git","clone_url":"https://github.com/liamitus/lt.tooltip.git","svn_url":"https://github.com/liamitus/lt.tooltip","homepage":null,"size":324,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"liamitus:develop","ref":"develop","sha":"0bb591446e06c1902ada70fe79959785ea45e9a5","user":{"login":"liamitus","id":780354,"avatar_url":"https://avatars.githubusercontent.com/u/780354?v=3","gravatar_id":"","url":"https://api.github.com/users/liamitus","html_url":"https://github.com/liamitus","followers_url":"https://api.github.com/users/liamitus/followers","following_url":"https://api.github.com/users/liamitus/following{/other_user}","gists_url":"https://api.github.com/users/liamitus/gists{/gist_id}","starred_url":"https://api.github.com/users/liamitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liamitus/subscriptions","organizations_url":"https://api.github.com/users/liamitus/orgs","repos_url":"https://api.github.com/users/liamitus/repos","events_url":"https://api.github.com/users/liamitus/events{/privacy}","received_events_url":"https://api.github.com/users/liamitus/received_events","type":"User","site_admin":false},"repo":{"id":29402360,"name":"lt.tooltip","full_name":"liamitus/lt.tooltip","owner":{"login":"liamitus","id":780354,"avatar_url":"https://avatars.githubusercontent.com/u/780354?v=3","gravatar_id":"","url":"https://api.github.com/users/liamitus","html_url":"https://github.com/liamitus","followers_url":"https://api.github.com/users/liamitus/followers","following_url":"https://api.github.com/users/liamitus/following{/other_user}","gists_url":"https://api.github.com/users/liamitus/gists{/gist_id}","starred_url":"https://api.github.com/users/liamitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liamitus/subscriptions","organizations_url":"https://api.github.com/users/liamitus/orgs","repos_url":"https://api.github.com/users/liamitus/repos","events_url":"https://api.github.com/users/liamitus/events{/privacy}","received_events_url":"https://api.github.com/users/liamitus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/liamitus/lt.tooltip","description":"Liam & Tarif's Tooltip, built with Angular.js and designed to be fast and easy to use.","fork":false,"url":"https://api.github.com/repos/liamitus/lt.tooltip","forks_url":"https://api.github.com/repos/liamitus/lt.tooltip/forks","keys_url":"https://api.github.com/repos/liamitus/lt.tooltip/keys{/key_id}","collaborators_url":"https://api.github.com/repos/liamitus/lt.tooltip/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/liamitus/lt.tooltip/teams","hooks_url":"https://api.github.com/repos/liamitus/lt.tooltip/hooks","issue_events_url":"https://api.github.com/repos/liamitus/lt.tooltip/issues/events{/number}","events_url":"https://api.github.com/repos/liamitus/lt.tooltip/events","assignees_url":"https://api.github.com/repos/liamitus/lt.tooltip/assignees{/user}","branches_url":"https://api.github.com/repos/liamitus/lt.tooltip/branches{/branch}","tags_url":"https://api.github.com/repos/liamitus/lt.tooltip/tags","blobs_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/refs{/sha}","trees_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/trees{/sha}","statuses_url":"https://api.github.com/repos/liamitus/lt.tooltip/statuses/{sha}","languages_url":"https://api.github.com/repos/liamitus/lt.tooltip/languages","stargazers_url":"https://api.github.com/repos/liamitus/lt.tooltip/stargazers","contributors_url":"https://api.github.com/repos/liamitus/lt.tooltip/contributors","subscribers_url":"https://api.github.com/repos/liamitus/lt.tooltip/subscribers","subscription_url":"https://api.github.com/repos/liamitus/lt.tooltip/subscription","commits_url":"https://api.github.com/repos/liamitus/lt.tooltip/commits{/sha}","git_commits_url":"https://api.github.com/repos/liamitus/lt.tooltip/git/commits{/sha}","comments_url":"https://api.github.com/repos/liamitus/lt.tooltip/comments{/number}","issue_comment_url":"https://api.github.com/repos/liamitus/lt.tooltip/issues/comments/{number}","contents_url":"https://api.github.com/repos/liamitus/lt.tooltip/contents/{+path}","compare_url":"https://api.github.com/repos/liamitus/lt.tooltip/compare/{base}...{head}","merges_url":"https://api.github.com/repos/liamitus/lt.tooltip/merges","archive_url":"https://api.github.com/repos/liamitus/lt.tooltip/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/liamitus/lt.tooltip/downloads","issues_url":"https://api.github.com/repos/liamitus/lt.tooltip/issues{/number}","pulls_url":"https://api.github.com/repos/liamitus/lt.tooltip/pulls{/number}","milestones_url":"https://api.github.com/repos/liamitus/lt.tooltip/milestones{/number}","notifications_url":"https://api.github.com/repos/liamitus/lt.tooltip/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/liamitus/lt.tooltip/labels{/name}","releases_url":"https://api.github.com/repos/liamitus/lt.tooltip/releases{/id}","created_at":"2015-01-17T19:14:06Z","updated_at":"2015-01-17T19:37:12Z","pushed_at":"2015-01-30T01:57:21Z","git_url":"git://github.com/liamitus/lt.tooltip.git","ssh_url":"git@github.com:liamitus/lt.tooltip.git","clone_url":"https://github.com/liamitus/lt.tooltip.git","svn_url":"https://github.com/liamitus/lt.tooltip","homepage":null,"size":324,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/6"},"html":{"href":"https://github.com/liamitus/lt.tooltip/pull/6"},"issue":{"href":"https://api.github.com/repos/liamitus/lt.tooltip/issues/6"},"comments":{"href":"https://api.github.com/repos/liamitus/lt.tooltip/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/liamitus/lt.tooltip/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/liamitus/lt.tooltip/statuses/36145e6b61dcc10c29b2134d866549c8e29cf33a"}}}}