@kizmann/pico-js 1.0.10 → 1.0.11
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 +40 -16
package/package.json
CHANGED
package/src/utility/dom.js
CHANGED
@@ -202,33 +202,58 @@ export class Dom
|
|
202
202
|
return top <= scroll.top && scroll.top <= bottom;
|
203
203
|
}
|
204
204
|
|
205
|
-
static inviewMaxY(
|
205
|
+
static inviewMaxY(options, callback = null)
|
206
206
|
{
|
207
|
-
let
|
208
|
-
[],
|
209
|
-
|
207
|
+
let defaults = {
|
208
|
+
el: '[data-inview]', parent: document.body, multiple: false, safezone: null,
|
209
|
+
};
|
210
|
+
|
211
|
+
if ( Any.isString(options) ) {
|
212
|
+
options = { el: options };
|
213
|
+
}
|
210
214
|
|
211
|
-
|
215
|
+
options = Obj.assign({}, defaults, options);
|
216
|
+
|
217
|
+
let safeback = (item) => {
|
218
|
+
return Math.min(Dom.find(item.el).height() * 0.5, Dom.find(window).height() * 0.2);
|
219
|
+
};
|
220
|
+
|
221
|
+
let safezone = options.safezone;
|
222
|
+
|
223
|
+
if ( Any.isNull(safezone) ) {
|
224
|
+
safezone = safeback;
|
225
|
+
}
|
212
226
|
|
213
|
-
if ( ! Any.
|
214
|
-
|
227
|
+
if ( ! Any.isFunction(safezone) ) {
|
228
|
+
safezone = () => options.safezone;
|
215
229
|
}
|
216
230
|
|
231
|
+
let [items, attr] = [
|
232
|
+
[], options.el.replace(/^\[([^="]+)]$/, '$1')
|
233
|
+
];
|
234
|
+
|
235
|
+
let parent = Dom.find(options.parent).find(options.el);
|
236
|
+
|
217
237
|
parent.each((el) => {
|
218
|
-
items.push({
|
238
|
+
items.push({
|
239
|
+
el, attr: Dom.find(el).attr(attr), height: Dom.find(el).inviewHeight()
|
240
|
+
});
|
219
241
|
});
|
220
242
|
|
221
|
-
let
|
243
|
+
let results = Arr.filter(items, (item) => {
|
244
|
+
return Math.max(0, item.height - safezone(item)) !== 0;
|
245
|
+
});
|
222
246
|
|
223
|
-
|
224
|
-
return
|
247
|
+
results = Arr.sort(results, (a, b) => {
|
248
|
+
return a.height > b.height ? -1 : 1;
|
225
249
|
});
|
226
250
|
|
227
|
-
|
228
|
-
callback.call({},
|
229
|
-
}
|
251
|
+
Arr.each(results, (item, index) => {
|
252
|
+
Any.isFunction(callback) && callback.call({}, item, index);
|
253
|
+
});
|
230
254
|
|
231
|
-
return
|
255
|
+
return options.multiple ? Arr.extract(results, 'el') :
|
256
|
+
Obj.get(results, '0.el');
|
232
257
|
}
|
233
258
|
|
234
259
|
is(selector)
|
@@ -332,7 +357,6 @@ export class Dom
|
|
332
357
|
return this.find(selector).get(0) !== null;
|
333
358
|
}
|
334
359
|
|
335
|
-
|
336
360
|
if ( selector instanceof Element === false ) {
|
337
361
|
return false;
|
338
362
|
}
|