Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Redraw via requestAnimationFrame if element has transition / animatio…
Browse files Browse the repository at this point in the history
…n on it.
  • Loading branch information
Worie committed Dec 19, 2016
1 parent 1714336 commit 289cc5b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .brackets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
"es5": true,

This comment has been minimized.

Copy link
@petetnt

petetnt Dec 19, 2016

Collaborator

Whoops, .brackets.json creeped in here.

"predef": [
"brackets",

"require",
"define",
"$",

"window",
"setTimeout",
"clearTimeout",

"ArrayBuffer",
"XMLHttpRequest",
"Uint32Array",
Expand All @@ -28,7 +25,10 @@
"defaultExtension": "js",
"language": {
"javascript": {
"linting.prefer": ["ESLint", "JSLint"],
"linting.prefer": [
"ESLint",
"JSLint"
],
"linting.usePreferredOnly": true
}
},
Expand All @@ -43,5 +43,5 @@
}
},
"spaceUnits": 4,
"useTabChar": false
}
"useTabChar": true
}
25 changes: 23 additions & 2 deletions src/LiveDevelopment/Agents/RemoteFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ function RemoteFunctions(config) {

var experimental = config.experimental;
var lastKeepAliveTime = Date.now();
var req, timeout;
var animateHighlight = function (time) {
if(req) {
cancelAnimationFrame(req);
clearTimeout(timeout);
}
req = requestAnimationFrame(redrawHighlights);

timeout = setTimeout(function () {
cancelAnimationFrame(req);
req = null;
}, time * 1000);
};

/**
* @type {DOMEditHandler}
Expand Down Expand Up @@ -234,11 +247,18 @@ function RemoteFunctions(config) {
}
return false;
},

_makeHighlightDiv: function (element, doAnimation) {
var elementBounds = element.getBoundingClientRect(),
highlight = window.document.createElement("div"),
styles = window.getComputedStyle(element);
var transitionDuration = parseFloat(styles.getPropertyValue('transition-duration'));

var animationDuration = parseFloat(styles.getPropertyValue('animation-duration'));

if (transitionDuration)
animateHighlight(transitionDuration);
if (animationDuration)
animateHighlight(animationDuration);

// Don't highlight elements with 0 width & height
if (elementBounds.width === 0 && elementBounds.height === 0) {
Expand Down Expand Up @@ -433,7 +453,8 @@ function RemoteFunctions(config) {
"border-width": "1px",
"border-color": "#00a2ff",
"box-shadow": "0 0 1px #fff",
"box-sizing": "border-box"
"box-sizing": "border-box",
"transform": styles.getPropertyValue('transform')
};

var mergedStyles = Object.assign({}, stylesToSet, config.remoteHighlight.stylesToSet);
Expand Down

0 comments on commit 289cc5b

Please sign in to comment.