You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
5 years ago
|
import Shuffle, { ShuffleOptions, SortOptions } from '../../';
|
||
|
|
||
|
Shuffle.ALL_ITEMS = 'item';
|
||
|
Shuffle.FILTER_ATTRIBUTE_KEY = 'categories';
|
||
|
|
||
|
const mainElement = document.getElementById('grid');
|
||
|
|
||
|
if (!mainElement) {
|
||
|
throw new TypeError('oopsie');
|
||
|
}
|
||
|
|
||
|
console.log(
|
||
|
Shuffle.EventType.LAYOUT,
|
||
|
Shuffle.Classes.SHUFFLE_ITEM,
|
||
|
Shuffle.FilterMode.ALL,
|
||
|
Shuffle.ShuffleItem.Css,
|
||
|
);
|
||
|
|
||
|
const options: ShuffleOptions = {
|
||
|
buffer: 0,
|
||
|
columnThreshold: 0.01,
|
||
|
easing: 'ease-in-out',
|
||
|
itemSelector: '.picture-item',
|
||
|
sizer: '.my-sizer',
|
||
|
filterMode: Shuffle.FilterMode.ALL,
|
||
|
};
|
||
|
const shuffle = new Shuffle(mainElement, options);
|
||
|
shuffle.filter('wallpaper');
|
||
|
shuffle.filter(function filterEachItem(element, shuffle) {
|
||
|
console.log(`shuffle id: ${shuffle.id}, element id: ${element.id}`);
|
||
|
const reviews = this.getAttribute('data-reviews');
|
||
|
return !!reviews && parseInt(reviews, 10) > 2;
|
||
|
});
|
||
|
|
||
|
const sortOptions: SortOptions = {
|
||
|
randomize: true,
|
||
|
reverse: false,
|
||
|
by: (element: Shuffle.ShuffleItem['element']) => element.getAttribute('data-reviews'),
|
||
|
compare(a: Shuffle.ShuffleItem, b: Shuffle.ShuffleItem) {
|
||
|
return 0;
|
||
|
},
|
||
|
};
|
||
|
shuffle.sort(sortOptions);
|
||
|
|
||
|
shuffle.update(true);
|
||
|
Shuffle.getSize(mainElement, true);
|
||
|
|
||
|
const rect1 = new Shuffle.Rect(0, 0, 20, 20);
|
||
|
const rect2 = new Shuffle.Rect(10, 10, 30, 30);
|
||
|
console.log(Shuffle.Rect.intersects(rect1, rect2));
|
||
|
|
||
|
export default shuffle;
|