ponepaste/js/archive.js

30 lines
1.1 KiB
JavaScript
Raw Normal View History

import { escape, whenReady } from './dom';
2022-03-12 13:56:32 -05:00
import { DataTable, dumbFilterCallback } from './data_tables';
2022-03-26 23:48:19 -04:00
import { tagsToHtml } from "./utils";
import { globalSetup } from './main';
2021-09-03 08:00:22 -04:00
whenReady(() => {
globalSetup();
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('q');
2022-01-06 07:58:29 -05:00
const apiUrl = /* myParam !== null ? '/api/ajax_pastes.php?q=' + myParam : */ '/api/ajax_pastes.php';
const table = new DataTable(document.getElementById('archive'), {
ajaxCallback: (resolve) => {
fetch(apiUrl)
.then(r => r.json())
.then(resolve);
},
rowCallback: (rowData) => {
return `<tr>
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>
<td><a href="/user/${escape(rowData.author)}">${escape(rowData.author)}</a></td>
2022-03-26 23:48:19 -04:00
<td>${tagsToHtml(rowData.tags)}</td>
</tr>`;
2022-01-06 07:58:29 -05:00
},
2022-03-12 13:56:32 -05:00
filterCallback: dumbFilterCallback,
2022-01-06 07:58:29 -05:00
preFilter: myParam
});
table.attach();
});