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

Commit

Permalink
Ignore elements with display:none properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Tatarintsev committed Feb 25, 2014
1 parent b9f7bcc commit cf9834d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
23 changes: 14 additions & 9 deletions lib/element-rect.js
Expand Up @@ -3,17 +3,22 @@ var q = require('q'),
Rect = require('./geometery/rect'); Rect = require('./geometery/rect');


exports.getMultiple = function getMultiple(elements) { exports.getMultiple = function getMultiple(elements) {
return q.all(Object.keys(elements).map(function(key) { var elementsArray = Object.keys(elements).map(function(key) {
return exports.get(elements[key]); return elements[key];
});
return q.all(elementsArray.map(function(element) {
return element.getCssValue('display');
})) }))
.then(function(displays) {
var visibleElements = elementsArray.filter(function(element, index) {
return displays[index] !== 'none';
});
return q.all(visibleElements.map(exports.get));
})
.then(function(rects) { .then(function(rects) {
return rects return rects.reduce(function(first, second) {
.filter(function(rect) { return first.merge(second);
return !rect.isZero(); });
})
.reduce(function(first, second) {
return first.merge(second);
});
}); });
}; };


Expand Down
4 changes: 0 additions & 4 deletions lib/geometery/rect.js
Expand Up @@ -38,10 +38,6 @@ var Rect = inherit({
Math.max(this.right, other.right) - x, Math.max(this.right, other.right) - x,
Math.max(this.bottom, other.bottom) - y Math.max(this.bottom, other.bottom) - y
); );
},

isZero: function() {
return this.width === 0 || this.height === 0;
} }


}); });
Expand Down

0 comments on commit cf9834d

Please sign in to comment.