diff --git a/src/core/js/libraries/inview.js b/src/core/js/libraries/inview.js index d7299fe80..dfea060e2 100644 --- a/src/core/js/libraries/inview.js +++ b/src/core/js/libraries/inview.js @@ -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() { @@ -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; @@ -564,6 +566,16 @@ return parents; }, + isElementHidden: function(element) { + var cssHidden = (element.style.display === "none" || element.style.visibility === "hidden"); + if (cssHidden) return true; + + var $element = $(element); + + cssHidden = ($element.css("display") === "none" || $element.css("visibility") === "hidden"); + return cssHidden; + }, + isOutOfBounds: function(element, parent) { var isScrollWidthOverflowing = (parent.clientWidth < parent.scrollWidth); @@ -586,10 +598,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;