Skip to content

Commit

Permalink
Merge branch 'feature/issues/35'
Browse files Browse the repository at this point in the history
  • Loading branch information
seanl-adg committed Jul 7, 2017
2 parents 635a91d + 80c183f commit 1bb58c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion lib/extended-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,14 @@ var ExtendedCss = function (styleSheet) { // jshint ignore:line
return;
}

// When DOMMutationEvents are used, applyRules emits DOMAttrModified events,
// so handleDomChangeThrottle will be called in the same execution context.
// We update lastTimeDomChange before applying styles, to enable throttling
// of the mutation events handler.
// see https://github.com/AdguardTeam/ExtendedCss/issues/35#issuecomment-313452395
lastTimeDomChanged = new Date().getTime();
domChanged = false;
applyRules(rules);
lastTimeDomChanged = new Date().getTime();
};

/**
Expand Down
14 changes: 7 additions & 7 deletions test/extended-css/test-extended-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var assertElementStyle = function(id, expectedStyle, assert) {
* relatively short time. (within several seconds)
* We apply rAF in tests as well to postpone test for similar amount of time.
*/
var safeSetTimeout = function(fn, timeout) {
var lazySetTimeout = function(fn, timeout) {
if (window.requestAnimationFrame) {
requestAnimationFrame(function() {
setTimeout(fn, timeout);
Expand Down Expand Up @@ -67,7 +67,7 @@ QUnit.test("Reaction on DOM modification", function(assert) {
var el = document.getElementById("case5-blocked");
document.getElementById("container").appendChild(el);

safeSetTimeout(function() {
lazySetTimeout(function() {
assertElementStyle("case5-blocked", { display: "" }, assert);
done();
}, 100);
Expand All @@ -87,14 +87,14 @@ QUnit.test("Affected elements length (simple)", function(assert) {
banner.setAttribute("class", "banner");
toBeBlocked.appendChild(banner);

safeSetTimeout(function() {
lazySetTimeout(function() {
assertElementStyle("case6-blocked", { "display": "none" }, assert);
affectedLength = extendedCss.getAffectedElements().length
assert.equal(affectedLength, startLength + 1);
assert.ok(1, "Element blocked: " + affectedLength + " elements affected");

toBeBlocked.removeChild(banner);
safeSetTimeout(function() {
lazySetTimeout(function() {
assertElementStyle("case6-blocked", { "display": "" }, assert);
affectedLength = extendedCss.getAffectedElements().length;
assert.equal(affectedLength, startLength);
Expand All @@ -116,7 +116,7 @@ QUnit.test("Affected elements length (root element removal)", function(assert) {
var root = document.getElementById("case7");
root.parentNode.removeChild(root);

safeSetTimeout(function() {
lazySetTimeout(function() {
affectedLength = extendedCss.getAffectedElements().length
assert.equal(affectedLength, startLength - 1);
assert.ok(1, "Element blocked: " + affectedLength + " elements affected");
Expand All @@ -137,10 +137,10 @@ QUnit.test("Test attribute protection", function(assert) {
var done = assert.async();
assertElementStyle("case10-blocked", { "display": "none" }, assert);

safeSetTimeout(function() {
lazySetTimeout(function() {
var node = document.getElementById("case10-blocked");
node.style.display = 'block';
safeSetTimeout(function() {
lazySetTimeout(function() {
assertElementStyle("case10-blocked", { "display": "none" }, assert);
done();
}, 100);
Expand Down

0 comments on commit 1bb58c2

Please sign in to comment.