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

issue/1873: inview updated to latest #1882

Merged
merged 1 commit into from
Nov 29, 2017
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
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