Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions deep-element-behavior.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<script>
window.deep = window.deep || {};

// TODO: JSDoc
ElementBehaviorImpl = {
properties: {
/* True if the element is visible to the user. False otherwise. */
isVisible: {
isVisibleToUser: {
type: Boolean,
value: false
},
/* Observer monitoring resize events */
__resizeObserver: Object
},
attached() {
this.__resizeObserver = new ResizeObserver(this.__updateVisibility);
this.__resizeObserver = new ResizeObserver(this.__updateVisibility.bind(this));
this.__resizeObserver.observe(this);
},
detached() {

this.__resizeObserver.disconnect();
},
__updateVisibility(resizeEntries) {
if(!Array.isArray(resizeEntries) || !resizeEntries.length) return;
const boundingRectangle = resizeEntries[0].contentRect;
const {height, width} = boundingRectangle;
this.set('isVisible', Boolean(height) || Boolean(width));
this.set('isVisibleToUser', Boolean(height) || Boolean(width));
}
};
deep.ElementBehavior = [ElementBehaviorImpl];
Expand Down