GitHub PullRequestReviewCommentEvent at 2014-02-07 21:24:44
Repository: wf-uicomponents
Actor: patkujawa-wf
Payload: {"comment":{"url":"https://api.github.com/repos/WebFilings/wf-uicomponents/pulls/comments/9555765","id":9555765,"diff_hunk":"@@ -267,7 +285,44 @@ define(function(require) {\n \n             // Apply acceleration up to the default animation duration.\n             acceleratedDuration = targetState.duration * Math.min(durationFactorX, durationFactorY);\n-            targetState.duration = Math.max(this._animationDuration, acceleratedDuration);\n+            targetState.duration = Math.max(this._animationDuration / 2, acceleratedDuration);\n+        },\n+\n+        /**\n+         * Allow event translation to move content slightly outside of boundaries\n+         * so that when release event occurs the content will snap back to boundaries.\n+         * @param {InteractionEvent} event\n+         * @param {TransformState} targetState\n+         * @param {string} [axis]\n+         */\n+        _bounceAtBoundaries: function(event, targetState, axis) {\n+            var originalState = targetState.clone();\n+            var viewportSize = this._awesomeMap.getViewportDimensions();\n+\n+            // Enforce the viewport boundaries.\n+            var boundedPosition = this._getBoundedPosition(targetState);\n+            var bounceDistance;\n+            var direction;\n+\n+            // If the targetState ends up out of bounds, allow the translation to carry\n+            // beyond the bounds by 10% of the relevant viewport dimension.\n+            // On release event handling, the content will \"bounce back\".\n+            // Switch the sign of the bounce distance to account for location:\n+            // left/top has the distance added, right/bottom has the distance subtracted.\n+            if (!axis || axis === 'x') {\n+                if (boundedPosition.x !== originalState.translateX) {\n+                    bounceDistance = 0.1 * viewportSize.width;\n+                    direction = boundedPosition.x < originalState.translateX ? 1 : -1;\n+                    targetState.translateX = boundedPosition.x + bounceDistance * direction;\n+                }\n+            }\n+            if (!axis || axis === 'y') {\n+                if (boundedPosition.y !== originalState.translateY) {\n+                    bounceDistance = 0.1 * viewportSize.height;\n+                    direction = boundedPosition.y < originalState.translateY ? 1 : -1;\n+                    targetState.translateY = boundedPosition.y + bounceDistance * direction;\n+                }\n+            }","path":"src/awesome_map/BoundaryInterceptor.js","position":101,"original_position":101,"commit_id":"6dcdb115a35e5188212ed733c8101e3bcde93441","original_commit_id":"6dcdb115a35e5188212ed733c8101e3bcde93441","user":{"login":"patkujawa-wf","id":6391742,"avatar_url":"https://gravatar.com/avatar/532f6c914e49ca676f6f1f891d2bd24c?d=https%3A%2F%2Fidenticons.github.com%2F96ce82f54cf5e6b7562cc49bb276fd6d.png&r=x","gravatar_id":"532f6c914e49ca676f6f1f891d2bd24c","url":"https://api.github.com/users/patkujawa-wf","html_url":"https://github.com/patkujawa-wf","followers_url":"https://api.github.com/users/patkujawa-wf/followers","following_url":"https://api.github.com/users/patkujawa-wf/following{/other_user}","gists_url":"https://api.github.com/users/patkujawa-wf/gists{/gist_id}","starred_url":"https://api.github.com/users/patkujawa-wf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patkujawa-wf/subscriptions","organizations_url":"https://api.github.com/users/patkujawa-wf/orgs","repos_url":"https://api.github.com/users/patkujawa-wf/repos","events_url":"https://api.github.com/users/patkujawa-wf/events{/privacy}","received_events_url":"https://api.github.com/users/patkujawa-wf/received_events","type":"User","site_admin":false},"body":"How about consolidating this near-duplicate code like so\r\n```javascript\r\nfunction fixTargetState (axis) {\r\n    var translateDir = 'translate' + axis.toUpperCase();\r\n    var side = axis === 'x' ? 'width' : 'height';\r\n    if (boundedPosition[axis] !== originalState[translateDir]) {\r\n        bounceDistance = 0.1 * viewportSize[side];\r\n        direction = boundedPosition[axis] < originalState[translateDir] ? 1 : -1;\r\n        targetState[translateDir] = boundedPosition[axis] + bounceDistance * direction;\r\n    }\r\n}\r\nif (!axis) {\r\n    fixTargetState('x');\r\n    fixTargetState('y');\r\n} else {\r\n    fixTargetState(axis);\r\n}\r\n```","created_at":"2014-02-07T21:24:44Z","updated_at":"2014-02-07T21:24:44Z","html_url":"https://github.com/WebFilings/wf-uicomponents/pull/14#discussion_r9555765","pull_request_url":"https://api.github.com/repos/WebFilings/wf-uicomponents/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/WebFilings/wf-uicomponents/pulls/comments/9555765"},"html":{"href":"https://github.com/WebFilings/wf-uicomponents/pull/14#discussion_r9555765"},"pull_request":{"href":"https://api.github.com/repos/WebFilings/wf-uicomponents/pulls/14"}}}}