Skip to content

Commit

Permalink
Merge pull request #58 from eduNEXT/and/pe-149
Browse files Browse the repository at this point in the history
Remove setTimeOut function
  • Loading branch information
ericfab179 authored Oct 19, 2018
2 parents 255165a + 3a3bda8 commit 9ad3c35
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions rocketc/static/js/src/rocketc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ function RocketChatXBlock(runtime, element) {
loadGroups();
} else {
$("#myframe").on("load", function() {
$("#myframe").hide();
setTimeout(function(){ $("#myframe").show(); }, 2000);
if (!isScrolledIntoView($(".rocketc_block"))) {
$("#myframe").hide();
}
});
window.onscroll = function() {
if (isScrolledIntoView($(".rocketc_block"))) {
$("#myframe").show();
}
};
}

$("#button", element).click(function(eventObject) {
Expand Down Expand Up @@ -154,4 +160,14 @@ function RocketChatXBlock(runtime, element) {
})
};

function isScrolledIntoView(elem){
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();

var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();

return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
};

}

0 comments on commit 9ad3c35

Please sign in to comment.