2021-11-04 11:35:36 -04:00
|
|
|
import { $, $$, escape, toggleEl } from './dom';
|
2021-08-25 20:02:05 -04:00
|
|
|
import { TagsInput } from "./tag_input";
|
2021-09-03 08:00:22 -04:00
|
|
|
import { DataTable } from "./data_tables";
|
2021-08-25 20:02:05 -04:00
|
|
|
|
|
|
|
const setupSite = function() {
|
|
|
|
Array.prototype.forEach.call($$('.js-tag-input'), (el) => {
|
|
|
|
new TagsInput(el).attach();
|
|
|
|
});
|
2021-09-03 08:00:22 -04:00
|
|
|
|
|
|
|
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 `<a href="/tags/${tagData.slug}">
|
|
|
|
<span class="tag ${tagColorClass}">${escape(tagData.name)}</span>
|
|
|
|
</a>`;
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
return `<tr>
|
|
|
|
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>
|
|
|
|
<td><a href="/user/${escape(rowData.author)}">${escape(rowData.author)}</a></td>
|
|
|
|
<td>${tags}</td>
|
|
|
|
</tr>`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
table.attach();
|
|
|
|
}
|
2021-11-04 11:35:36 -04:00
|
|
|
|
|
|
|
const signupButton = $('[data-target~="#signin"],[data-target~="#signup"]');
|
|
|
|
|
|
|
|
if (signupButton) {
|
|
|
|
signupButton.addEventListener('click', () => {
|
|
|
|
$('.modal').classList.add('is-active');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.modal-button-close').addEventListener('click', () => {
|
|
|
|
$('.modal').classList.remove('is-active');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const embedButton = $('.panel-tools .embed-tool');
|
|
|
|
|
|
|
|
if (embedButton){
|
|
|
|
embedButton.addEventListener('click', (evt) => {
|
|
|
|
if (evt.target && evt.target.closest('.panel-tools')) {
|
|
|
|
toggleEl(evt.target.closest('.panel-tools').querySelector('.panel-embed'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const expandButton = $('.expand-tool');
|
|
|
|
|
|
|
|
if (expandButton) {
|
|
|
|
expandButton.addEventListener('click', (evt) => {
|
|
|
|
if (evt.target && evt.target.closest('.panel')) {
|
|
|
|
const panel = evt.target.closest('.panel');
|
|
|
|
|
|
|
|
if (panel.classList.contains('panel-fullsize')) {
|
|
|
|
panel.classList.remove('panel-fullsize');
|
|
|
|
} else {
|
|
|
|
panel.classList.add('panel-fullsize');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-08-25 20:02:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (document.readyState !== 'loading') {
|
|
|
|
setupSite();
|
|
|
|
} else {
|
|
|
|
document.addEventListener('DOMContentLoaded', setupSite);
|
2021-08-25 02:08:30 -04:00
|
|
|
}
|