UNPKG

custom-stories-component

Version:
65 lines (54 loc) 1.7 kB
const timestamp = () => { let timeIndex = 1678166046264 / 1000; let random = Math.floor(Math.random() * 1000); return Math.round(timeIndex - random); }; function getStories(data) { try { const json = data; const slides = json.items?.map(item => ( { id: item.id, photo: item.coverImageUrl, name: '', time: timestamp(), items: item.slides?.map(slide => ( { id: slide.id, type: 'photo', length: 3, src: slide.imageUrl, preview: slide.imageUrl, link: '', linkText: false, time: timestamp() } )) } )) return slides } catch (error) { console.error(error); return [] } } (function (root, factory) { if (typeof define === 'function' && define.amd) { define(["zuck.js"], factory); } else if (typeof exports === 'object') { module.exports = factory(require(Zuck)); } else { root.CustomStories = factory(root.Zuck); } }(this, function (Zuck) { class CustomZuck extends Zuck { constructor(selector, options) { const element = window.document.querySelector(selector); const stories = getStories(options.stories); options.stories = stories super(element, options); } } return CustomZuck; }));