@kizmann/pico-js 1.0.10 → 1.0.12
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/dist/pico-js.js +1 -1
- package/dist/pico-js.js.map +1 -1
- package/package.json +1 -1
- package/src/utility/dom.js +57 -22
package/package.json
CHANGED
package/src/utility/dom.js
CHANGED
@@ -133,11 +133,13 @@ export class Dom
|
|
133
133
|
return this.get(0) && this.get(0).is(':visible');
|
134
134
|
}
|
135
135
|
|
136
|
-
inviewHeight()
|
136
|
+
inviewHeight(boundry = window)
|
137
137
|
{
|
138
|
+
let parent = Dom.find(boundry);
|
139
|
+
|
138
140
|
let viewport = {
|
139
|
-
width:
|
140
|
-
height:
|
141
|
+
width: parent.width(),
|
142
|
+
height: parent.height(),
|
141
143
|
};
|
142
144
|
|
143
145
|
let element = {
|
@@ -148,10 +150,12 @@ export class Dom
|
|
148
150
|
let scroll = this.scroll(),
|
149
151
|
offset = this.offset();
|
150
152
|
|
151
|
-
let bottom =
|
153
|
+
let [top, bottom] = [
|
154
|
+
scroll.top + parent.offset('top'), offset.top + element.height
|
155
|
+
];
|
152
156
|
|
153
|
-
return Math.max(0, Math.min(bottom, viewport.height +
|
154
|
-
Math.max(offset.top,
|
157
|
+
return Math.max(0, Math.min(bottom, viewport.height + top) -
|
158
|
+
Math.max(offset.top, top))
|
155
159
|
}
|
156
160
|
|
157
161
|
inviewX(ratio = 0)
|
@@ -202,33 +206,61 @@ export class Dom
|
|
202
206
|
return top <= scroll.top && scroll.top <= bottom;
|
203
207
|
}
|
204
208
|
|
205
|
-
static inviewMaxY(
|
209
|
+
static inviewMaxY(options, callback = null)
|
206
210
|
{
|
207
|
-
let
|
208
|
-
[],
|
209
|
-
|
211
|
+
let defaults = {
|
212
|
+
el: '[data-inview]', parent: document.body, multiple: false, safezone: null,
|
213
|
+
};
|
214
|
+
|
215
|
+
if ( Any.isString(options) ) {
|
216
|
+
options = { el: options };
|
217
|
+
}
|
218
|
+
|
219
|
+
let boundry = Dom.find(options.parent)
|
220
|
+
.closestScrollable(window);
|
221
|
+
|
222
|
+
options = Obj.assign({}, defaults, options);
|
223
|
+
|
224
|
+
let safeback = (item) => {
|
225
|
+
return Math.min(Dom.find(item.el).height() * 0.5, Dom.find(boundry).height() * 0.2);
|
226
|
+
};
|
210
227
|
|
211
|
-
let
|
228
|
+
let safezone = options.safezone;
|
212
229
|
|
213
|
-
if (
|
214
|
-
|
230
|
+
if ( Any.isNull(safezone) ) {
|
231
|
+
safezone = safeback;
|
215
232
|
}
|
216
233
|
|
234
|
+
if ( ! Any.isFunction(safezone) ) {
|
235
|
+
safezone = () => options.safezone;
|
236
|
+
}
|
237
|
+
|
238
|
+
let [items, attr] = [
|
239
|
+
[], options.el.replace(/^\[([^="]+)]$/, '$1')
|
240
|
+
];
|
241
|
+
|
242
|
+
let parent = Dom.find(options.parent).find(options.el);
|
243
|
+
|
217
244
|
parent.each((el) => {
|
218
|
-
items.push({
|
245
|
+
items.push({
|
246
|
+
el, attr: Dom.find(el).attr(attr), height: Dom.find(el).inviewHeight(boundry)
|
247
|
+
});
|
219
248
|
});
|
220
249
|
|
221
|
-
let
|
250
|
+
let results = Arr.filter(items, (item) => {
|
251
|
+
return Math.max(0, item.height - safezone(item)) !== 0;
|
252
|
+
});
|
222
253
|
|
223
|
-
|
224
|
-
return
|
254
|
+
results = Arr.sort(results, (a, b) => {
|
255
|
+
return a.height >= b.height ? -1 : 1;
|
225
256
|
});
|
226
257
|
|
227
|
-
|
228
|
-
callback.call({},
|
229
|
-
}
|
258
|
+
Arr.each(results, (item, index) => {
|
259
|
+
Any.isFunction(callback) && callback.call({}, item, index);
|
260
|
+
});
|
230
261
|
|
231
|
-
return
|
262
|
+
return options.multiple ? Arr.extract(results, 'el') :
|
263
|
+
Obj.get(results, '0.el');
|
232
264
|
}
|
233
265
|
|
234
266
|
is(selector)
|
@@ -332,7 +364,6 @@ export class Dom
|
|
332
364
|
return this.find(selector).get(0) !== null;
|
333
365
|
}
|
334
366
|
|
335
|
-
|
336
367
|
if ( selector instanceof Element === false ) {
|
337
368
|
return false;
|
338
369
|
}
|
@@ -414,6 +445,10 @@ export class Dom
|
|
414
445
|
return Dom.find(null);
|
415
446
|
}
|
416
447
|
|
448
|
+
if ( el instanceof Window ) {
|
449
|
+
el = document;
|
450
|
+
}
|
451
|
+
|
417
452
|
let nodes = el.querySelectorAll(selector);
|
418
453
|
|
419
454
|
nodes = Array.prototype.slice.call(nodes);
|