-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (42 loc) · 1.71 KB
/
index.js
File metadata and controls
61 lines (42 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { __renderPlaceHolders } from "../index";
const __lazyload = () => {
const __isItVisible = (node) => {
var rect = node.getBoundingClientRect();
return (
(rect.height > 0 || rect.width > 0) &&
rect.bottom >= 0 &&
rect.right >= 0 &&
rect.top <=
(window.innerHeight || document.documentElement.clientHeight) &&
rect.left <=
(window.innerWidth || document.documentElement.clientWidth)
);
};
const __isElementLoaded = (_element) => _element.hasClass(`is--loaded`);
const __renderElement = (_element, placeHolder) => {
const _noscript = _element.find("noscript").html();
_element.find("noscript").remove();
_element.addClass("is--loaded").append(_noscript);
_element.append(window[placeHolder]);
_element.removeAttr("data-template");
};
const __renderVisiblePlaceholder = (placeHolder, _element) => {
if (!__isElementLoaded(_element)) {
__renderElement(_element, placeHolder);
__renderPlaceHolders.render(placeHolder);
}
};
const __getAllPlaceholders = () => {
const placeholders = $(".noscript--container");
function __foundOnePlaceholder(index, element) {
let placeHolder = $(this).attr("data-placeholder");
const _element = $(this);
if (__isItVisible(this)) {
__renderVisiblePlaceholder(placeHolder, _element);
}
}
placeholders.each(__foundOnePlaceholder);
};
$(window).on("scroll", __getAllPlaceholders);
};
export { __lazyload };