Skip to content

Commit

Permalink
issue/1873: inview updated to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Nov 29, 2017
1 parent a77d662 commit fad05f3
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/core/js/libraries/inview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
// jquery.onscreen 2017-07-11 https://github.com/adaptlearning/jquery.onscreen
// jquery.onscreen 2017-11-27 https://github.com/adaptlearning/jquery.onscreen

(function() {

Expand Down Expand Up @@ -504,18 +504,20 @@
var hasNoSize = (height <= 0 && width <= 0);
if (hasNoSize) onscreen = false;

var cssHidden = (el.style.display == "none" || el.style.visibility == "hidden");
var cssHidden = measurements.isElementHidden(el);
if (cssHidden) onscreen = false;

if (onscreen) {

// perform some extra checks to make sure item is onscreen
var parents = measurements.getParents(el);

// go through all the parents except the html tag
for (var i = 0, l = parents.length-1; i < l; i++) {
var parent = parents[i];

cssHidden = (parent.style.display == "none" || parent.style.visibility == "hidden");
cssHidden = measurements.isElementHidden(parent);

// check if parents are visibility hidden or display none
if (cssHidden) {
onscreen = false;
Expand Down Expand Up @@ -564,6 +566,15 @@
return parents;
},

isElementHidden: function(element) {
var cssHidden = (element.style.display == "none" || element.style.visibility == "hidden");
if (cssHidden) return true;

var style = window.getComputedStyle(element, null);
cssHidden = (style.display == "none" || style.visibility == "hidden");
return cssHidden;
},

isOutOfBounds: function(element, parent) {

var isScrollWidthOverflowing = (parent.clientWidth < parent.scrollWidth);
Expand All @@ -586,10 +597,11 @@
var childOffsetBottom = (childOffsetTop + element.clientHeight);
var childOffsetRight = (childOffsetLeft + element.clientWidth);

var isOutOfBounds = (childOffsetTop > parent.clientHeight
|| childOffsetLeft > parent.clientWidth
|| childOffsetBottom < 0
|| childOffsetRight < 0);
// check inclusive of bounding rectangle edges
var isOutOfBounds = (childOffsetTop >= parent.clientHeight
|| childOffsetLeft >= parent.clientWidth
|| childOffsetBottom <= 0
|| childOffsetRight <= 0);

return isOutOfBounds;

Expand Down

0 comments on commit fad05f3

Please sign in to comment.