domquery-com 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.ko.md +273 -0
- package/README.md +272 -0
- package/domquery.js +6290 -0
- package/domquery.min.js +361 -0
- package/package.json +53 -0
- package/src/Kcolor.js +909 -0
- package/src/ajax.js +1220 -0
- package/src/alert.js +3516 -0
- package/src/animate.js +1775 -0
- package/src/lazyLoadImages.js +202 -0
- package/src/pulling.js +473 -0
- package/src/select.js +3154 -0
- package/src_min/Kcolor.min.js +45 -0
- package/src_min/ajax.min.js +61 -0
- package/src_min/alert.min.js +240 -0
- package/src_min/animate.min.js +118 -0
- package/src_min/lazyLoadImages.min.js +13 -0
- package/src_min/pulling.min.js +23 -0
- package/src_min/select.min.js +186 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
$.lazyLoadImages = function(g, k, p) {
|
|
2
|
+
if (!this.elements || !Array.isArray(this.elements)) throw Error("lazyLoadImages.js requires domquery.js (this.elements is required)");
|
|
3
|
+
if ("object" === typeof g && g.simply) {
|
|
4
|
+
const a = g.selector || "[data-src]";
|
|
5
|
+
if (1 === this.elements.length && this.elements[0] === document) g = document.querySelectorAll(a);
|
|
6
|
+
else {
|
|
7
|
+
const c = new Set;
|
|
8
|
+
this.elements.forEach(b => {
|
|
9
|
+
b.querySelectorAll(a).forEach(e => c.add(e))
|
|
10
|
+
});
|
|
11
|
+
g = Array.from(c)
|
|
12
|
+
}
|
|
13
|
+
const d = new IntersectionObserver((c, b) => {
|
|
14
|
+
c.forEach(e => {
|
|
15
|
+
if (e.isIntersecting) {
|
|
16
|
+
e =
|
|
17
|
+
e.target;
|
|
18
|
+
const l = e.dataset.src;
|
|
19
|
+
"img" === e.tagName.toLowerCase() ? (e.src = l, e.alt = e.alt || "") : e.style.backgroundImage = `url(${l})`;
|
|
20
|
+
e.removeAttribute("data-src");
|
|
21
|
+
b.unobserve(e)
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}, {
|
|
25
|
+
threshold: .1,
|
|
26
|
+
rootMargin: "50px"
|
|
27
|
+
});
|
|
28
|
+
g.forEach(c => d.observe(c));
|
|
29
|
+
this.destroy = function() {
|
|
30
|
+
d.disconnect();
|
|
31
|
+
return this
|
|
32
|
+
};
|
|
33
|
+
return this
|
|
34
|
+
}
|
|
35
|
+
const v = {
|
|
36
|
+
duration: 0,
|
|
37
|
+
threshold: .1,
|
|
38
|
+
rootMargin: "50px",
|
|
39
|
+
callback: null,
|
|
40
|
+
maxRetries: 3,
|
|
41
|
+
retryDelay: 1E3,
|
|
42
|
+
loading: !1,
|
|
43
|
+
removeLoading: !0,
|
|
44
|
+
placeholder: !1
|
|
45
|
+
};
|
|
46
|
+
let f = {
|
|
47
|
+
...v
|
|
48
|
+
},
|
|
49
|
+
q = null;
|
|
50
|
+
"function" === typeof g ? f.callback = g : "number" ===
|
|
51
|
+
typeof g ? (f.duration = g, f.callback = k) : "string" === typeof g ? (q = g, "function" === typeof k ? f.callback = k : "number" === typeof k && (f.duration = k, f.callback = p)) : "object" === typeof g && (f = {
|
|
52
|
+
...v,
|
|
53
|
+
...g
|
|
54
|
+
});
|
|
55
|
+
if (1 === this.elements.length && this.elements[0] === document) g = Array.from(document.querySelectorAll(q || "[data-src]"));
|
|
56
|
+
else {
|
|
57
|
+
const a = new Set;
|
|
58
|
+
this.elements.forEach(d => {
|
|
59
|
+
d.querySelectorAll(q || "[data-src]").forEach(c => a.add(c))
|
|
60
|
+
});
|
|
61
|
+
g = Array.from(a)
|
|
62
|
+
}
|
|
63
|
+
document.getElementById("lazy-loading-styles") || (k = document.createElement("style"),
|
|
64
|
+
k.id = "lazy-loading-styles", k.textContent = "\n .lazy-loading-wrap {\n position: absolute !important;\n top: 0 !important;\n left: 0 !important;\n width: 100% !important;\n height: 100% !important;\n z-index: 9998 !important;\n pointer-events: none !important;\n overflow: visible !important;\n background-color: rgba(255, 255, 255, 0.5) !important;\n backdrop-filter: blur(3px) !important;\n transition: opacity 0.2s ease !important;\n }\n .lazy-loading-indicator {\n position: absolute !important;\n top: 50% !important;\n left: 50% !important;\n transform: translate(-50%, -50%) !important;\n width: 60px !important;\n height: 30px !important;\n z-index: 9999 !important;\n pointer-events: none !important;\n display: flex !important;\n justify-content: center !important;\n align-items: center !important;\n }\n .lazy-loading-dot {\n width: 8px !important;\n height: 8px !important;\n margin: 0 3px !important;\n border-radius: 50% !important;\n background-color: rgba(0, 0, 0, 0.5) !important;\n display: inline-block !important;\n animation: lazyPulse 1.4s infinite ease-in-out !important;\n }\n .lazy-loading-dot:nth-child(1) { animation-delay: 0s !important; }\n .lazy-loading-dot:nth-child(2) { animation-delay: 0.2s !important; }\n .lazy-loading-dot:nth-child(3) { animation-delay: 0.4s !important; }\n @keyframes lazyPulse {\n 0%, 100% { transform: scale(0.6); opacity: 0.6; }\n 50% { transform: scale(1); opacity: 1; }\n }\n .lazy-loading-progress {\n position: absolute !important;\n bottom: 0 !important;\n left: 0 !important;\n height: 3px !important;\n width: 0% !important;\n background: linear-gradient(to right, #4facfe, #00f2fe) !important;\n transition: width 0.3s ease !important;\n z-index: 9999 !important;\n box-shadow: 0 0 5px rgba(79, 172, 254, 0.5) !important;\n }\n .lazy-placeholder {\n background-color: #f0f0f0 !important;\n background-image: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%) !important;\n background-size: 200% 100% !important;\n animation: shimmer 1.5s infinite !important;\n }\n @keyframes shimmer {\n 0% { background-position: 200% 0; }\n 100% { background-position: -200% 0; }\n }\n ",
|
|
65
|
+
document.head.appendChild(k));
|
|
66
|
+
g.forEach(a => {
|
|
67
|
+
"img" === a.tagName.toLowerCase() && a.dataset.src && (f.placeholder && a.classList.add("lazy-placeholder"), a.src && "" !== a.src && a.src !== window.location.href || (a.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'/%3E"), 0 < f.duration && (a.style.opacity = "0"))
|
|
68
|
+
});
|
|
69
|
+
const z = (a, d) => {
|
|
70
|
+
let c;
|
|
71
|
+
return (...b) => {
|
|
72
|
+
clearTimeout(c);
|
|
73
|
+
c = setTimeout(() => a(...b), d)
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
w = a => {
|
|
77
|
+
var d = window.getComputedStyle(a).position,
|
|
78
|
+
c = "img" === a.tagName.toLowerCase();
|
|
79
|
+
const b = document.createElement("div");
|
|
80
|
+
b.className = "lazy-loading-wrap";
|
|
81
|
+
var e = document.createElement("div");
|
|
82
|
+
e.className = "lazy-loading-indicator";
|
|
83
|
+
"string" === typeof f.loading ? (e.innerHTML = f.loading, e.style.color = "rgba(0, 0, 0, 0.7)", e.style.fontSize = "14px", e.style.whiteSpace = "nowrap") : e.innerHTML = '<div class="lazy-loading-dot"></div><div class="lazy-loading-dot"></div><div class="lazy-loading-dot"></div>';
|
|
84
|
+
const l = document.createElement("div");
|
|
85
|
+
l.className = "lazy-loading-progress";
|
|
86
|
+
b.appendChild(e);
|
|
87
|
+
b.appendChild(l);
|
|
88
|
+
let h = 0;
|
|
89
|
+
const m = setInterval(() => {
|
|
90
|
+
h += 5 * Math.random();
|
|
91
|
+
95 < h && (clearInterval(m), h = 95);
|
|
92
|
+
l.style.width = h + "%"
|
|
93
|
+
}, 200);
|
|
94
|
+
e = {
|
|
95
|
+
element: a,
|
|
96
|
+
wrapper: b,
|
|
97
|
+
indicator: e,
|
|
98
|
+
originalPosition: d,
|
|
99
|
+
progressBar: l,
|
|
100
|
+
progressInterval: m
|
|
101
|
+
};
|
|
102
|
+
if (c)
|
|
103
|
+
if (d = a.parentNode, "absolute" === window.getComputedStyle(a).position) "static" === window.getComputedStyle(d).position && (d.style.position = "relative"), d.appendChild(b);
|
|
104
|
+
else {
|
|
105
|
+
c = document.createElement("div");
|
|
106
|
+
const n = a.offsetWidth || d.offsetWidth || "100%",
|
|
107
|
+
r = a.offsetHeight || d.offsetHeight || "auto";
|
|
108
|
+
c.style.cssText = `position: relative; display: inline-block; width: ${"number"===
|
|
109
|
+
typeof n?n+"px":n}; height: ${"number"===typeof r?r+"px":r}; overflow: hidden;`;
|
|
110
|
+
d.insertBefore(c, a);
|
|
111
|
+
c.appendChild(a);
|
|
112
|
+
c.appendChild(b);
|
|
113
|
+
e.container = c
|
|
114
|
+
}
|
|
115
|
+
else "static" === d && (a.style.position = "relative"), a.appendChild(b);
|
|
116
|
+
return e
|
|
117
|
+
},
|
|
118
|
+
t = a => {
|
|
119
|
+
a && (a.progressInterval && (clearInterval(a.progressInterval), a.progressBar && (a.progressBar.style.width = "100%")), a.wrapper?.parentNode && (a.wrapper.style.opacity = "0", setTimeout(() => {
|
|
120
|
+
a.wrapper?.parentNode?.removeChild(a.wrapper)
|
|
121
|
+
}, 200)), a.container?.parentNode && setTimeout(() => {
|
|
122
|
+
const {
|
|
123
|
+
element: d,
|
|
124
|
+
container: c
|
|
125
|
+
} = a;
|
|
126
|
+
c.parentNode.insertBefore(d, c);
|
|
127
|
+
c.parentNode.removeChild(c)
|
|
128
|
+
}, 200), a.element && "static" === a.originalPosition && setTimeout(() => {
|
|
129
|
+
a.element.style.position = "static"
|
|
130
|
+
}, 200), a.element && f.placeholder && a.element.classList.remove("lazy-placeholder"))
|
|
131
|
+
},
|
|
132
|
+
x = a => {
|
|
133
|
+
if ("img" === a.tagName.toLowerCase()) {
|
|
134
|
+
var d = a.getAttribute("width"),
|
|
135
|
+
c = a.getAttribute("height");
|
|
136
|
+
d && c ? a.style.aspectRatio = d / c : (d = a.offsetWidth, c = a.offsetHeight, 0 < d && 0 < c ? a.style.aspectRatio = d / c : a.style.minHeight = 0 < d ? .5625 * d + "px" : "200px");
|
|
137
|
+
f.placeholder &&
|
|
138
|
+
a.classList.add("lazy-placeholder")
|
|
139
|
+
} else 50 > a.offsetHeight && (d = a.offsetWidth, a.style.minHeight = 0 < d ? .5625 * d + "px" : "200px"), !f.placeholder || a.style.backgroundColor && "transparent" !== a.style.backgroundColor || a.classList.add("lazy-placeholder")
|
|
140
|
+
},
|
|
141
|
+
u = (a, d, c = 0, b = null) => {
|
|
142
|
+
const e = new Image;
|
|
143
|
+
a.tagName.toLowerCase();
|
|
144
|
+
e.onload = z(() => {
|
|
145
|
+
0 < f.duration ? (a.style.transition = `opacity ${f.duration}ms ease-in`, requestAnimationFrame(() => {
|
|
146
|
+
requestAnimationFrame(() => {
|
|
147
|
+
a.style.opacity = "1";
|
|
148
|
+
b && setTimeout(() => t(b), f.duration)
|
|
149
|
+
})
|
|
150
|
+
})) : (a.style.opacity =
|
|
151
|
+
"1", b && t(b));
|
|
152
|
+
f.callback && f.callback(d, null, a)
|
|
153
|
+
}, 50);
|
|
154
|
+
e.onerror = () => {
|
|
155
|
+
c < f.maxRetries ? setTimeout(() => u(a, d, c + 1, b), f.retryDelay) : (a.style.opacity = "1", b && t(b), f.callback && f.callback(d, Error("Failed to load image after retries"), a))
|
|
156
|
+
};
|
|
157
|
+
e.src = d
|
|
158
|
+
},
|
|
159
|
+
y = new IntersectionObserver((a, d) => {
|
|
160
|
+
a.forEach(c => {
|
|
161
|
+
if (c.isIntersecting) {
|
|
162
|
+
const b = c.target,
|
|
163
|
+
e = b.dataset.src;
|
|
164
|
+
if ("img" === b.tagName.toLowerCase()) {
|
|
165
|
+
x(b);
|
|
166
|
+
const l = f.loading ? w(b) : null;
|
|
167
|
+
0 < f.duration && (b.style.opacity = "0");
|
|
168
|
+
const h = new Image,
|
|
169
|
+
m = (c = b.parentElement) && 0 < parseFloat(window.getComputedStyle(c).paddingTop);
|
|
170
|
+
c = () => {
|
|
171
|
+
if (h.naturalWidth && h.naturalHeight) {
|
|
172
|
+
const n = window.getComputedStyle(b);
|
|
173
|
+
m || n.aspectRatio || b.style.aspectRatio || b.style.width || b.style.height || b.hasAttribute("width") || b.hasAttribute("height") || (b.style.aspectRatio = `${h.naturalWidth} / ${h.naturalHeight}`);
|
|
174
|
+
m && (b.style.minHeight = "0", b.style.height = "100%", b.style.width = "100%")
|
|
175
|
+
}
|
|
176
|
+
b.src = e;
|
|
177
|
+
b.alt = b.alt || "";
|
|
178
|
+
b.removeAttribute("data-src");
|
|
179
|
+
d.unobserve(b);
|
|
180
|
+
u(b, e, 0, l)
|
|
181
|
+
};
|
|
182
|
+
h.onload = c;
|
|
183
|
+
h.onerror = c;
|
|
184
|
+
h.src = e
|
|
185
|
+
} else x(b), c = f.loading ? w(b) : null, 0 < f.duration && (b.style.opacity =
|
|
186
|
+
"0"), b.style.backgroundImage = `url(${e})`, b.removeAttribute("data-src"), d.unobserve(b), u(b, e, 0, c)
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
}, {
|
|
190
|
+
threshold: f.threshold,
|
|
191
|
+
rootMargin: f.rootMargin
|
|
192
|
+
});
|
|
193
|
+
g.forEach(a => y.observe(a));
|
|
194
|
+
this.destroy = function() {
|
|
195
|
+
y.disconnect();
|
|
196
|
+
return this
|
|
197
|
+
};
|
|
198
|
+
return this
|
|
199
|
+
};
|
|
200
|
+
$.fn.lazyLoadImages = function(g, k, p) {
|
|
201
|
+
return $.lazyLoadImages.call(this, g, k, p)
|
|
202
|
+
};
|