import { $$, escape } from './dom'; import { TagsInput } from "./tag_input"; import { DataTable } from "./data_tables"; const setupSite = function() { Array.prototype.forEach.call($$('.js-tag-input'), (el) => { new TagsInput(el).attach(); }); if (document.querySelector('#archive')) { const table = new DataTable(document.querySelector('#archive'), { ajaxCallback: (resolve) => { fetch('/api/ajax_pastes.php') .then(r => r.json()) .then(resolve); }, rowCallback: (rowData) => { const tags = rowData.tags.map((tagData) => { let tagColorClass; if (tagData.name.indexOf('nsfw') !== -1) { tagColorClass = 'is-danger'; } else if (tagData.name.indexOf('safe') !== -1) { tagColorClass = 'is-success'; } else if (tagData.name.indexOf('/') !== -1) { tagColorClass = 'is-primary'; } else { tagColorClass = 'is-info'; } return ` ${escape(tagData.name)} `; }).join(''); return ` ${escape(rowData.title)} ${escape(rowData.author)} ${tags} `; } }); table.attach(); } }; if (document.readyState !== 'loading') { setupSite(); } else { document.addEventListener('DOMContentLoaded', setupSite); }