mirror of https://github.com/JoeBiellik/paste
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.
72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
$(() => {
|
|
if (localStorage.getItem('expire-value') !== null) $('input#expire').val(localStorage.getItem('expire-value'));
|
|
if (localStorage.getItem('expire-multiplier') !== null) $('#multiplier').val(localStorage.getItem('expire-multiplier'));
|
|
|
|
$.fn.selectpicker.Constructor.BootstrapVersion = '4';
|
|
|
|
autosize($('textarea'));
|
|
|
|
$('select#highlight').removeClass('custom-select');
|
|
$('input#expire').removeClass('mr-3');
|
|
|
|
$('select#highlight').selectpicker();
|
|
|
|
$('input#expire').TouchSpin({
|
|
min: 1,
|
|
max: 999,
|
|
buttondown_class: 'btn text-dark border-gray',
|
|
buttonup_class: 'btn text-dark border-gray'
|
|
});
|
|
|
|
$('textarea').on('keydown', function(e) {
|
|
if ((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $(this).val()) {
|
|
$(this).closest('form').submit();
|
|
}
|
|
});
|
|
|
|
$('input#expire').on('change', (e) => {
|
|
var value = $(e.target).val();
|
|
|
|
$('#multiplier option').text((_, t) => {
|
|
var plural = t.slice(Math.max(0, t.length - 1)) === 's';
|
|
|
|
if (value > 1) {
|
|
if (!plural) {
|
|
return t + 's';
|
|
}
|
|
} else if (plural) {
|
|
return t.slice(0, -1);
|
|
}
|
|
|
|
return t;
|
|
});
|
|
|
|
localStorage.setItem('expire-value', value);
|
|
});
|
|
|
|
$('#multiplier').on('change', (e) => {
|
|
localStorage.setItem('expire-multiplier', $(e.target).val());
|
|
});
|
|
|
|
$('select#highlight').on('change', function() {
|
|
if ($(this).val() === '') {
|
|
history.pushState({}, '', '/');
|
|
} else {
|
|
location.hash = $(this).val();
|
|
}
|
|
});
|
|
|
|
$(window).on('hashchange', () => {
|
|
var value = location.hash.slice(1);
|
|
|
|
if (value && $('select#highlight option[value=' + value + ']').length > 0) {
|
|
$('select#highlight').selectpicker('val', value);
|
|
} else {
|
|
$('select#highlight').selectpicker('val', '');
|
|
}
|
|
});
|
|
|
|
$(window).trigger('hashchange');
|
|
$('input#expire').trigger('change');
|
|
});
|