Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue/1873 #2268

Merged
merged 3 commits into from
Nov 14, 2018
Merged
Changes from 2 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
27 changes: 19 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,14 @@
return parents;
},

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

cssHidden = $(element).css("display") === "none" || $(element).css("visibility") === "hidden";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth caching $(element)? or am I just being too picky?

return cssHidden;
},

isOutOfBounds: function(element, parent) {

var isScrollWidthOverflowing = (parent.clientWidth < parent.scrollWidth);
Expand All @@ -586,10 +596,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