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.
paste/public/main.js

43 lines
1000 B
JavaScript

/* eslint-env browser */
/* global $ autosize */
$(function() {
$.fn.selectpicker.Constructor.BootstrapVersion = '4';
autosize($('textarea'));
$('select#highlight').selectpicker();
$('textarea').on('keydown', function(e) {
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey && $(this).val()) {
$(this).closest('form').submit();
}
});
$('pre').on('click', function() {
var range = document.createRange();
range.setStart(this.firstChild, 19);
range.setEnd(this.firstChild, this.firstChild.textContent.length);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
});
$('select#highlight').on('change', function() {
location.hash = $(this).val();
});
$(window).on('hashchange', function() {
var value = location.hash.slice(1);
if (value && $('select#highlight option[value=' + value + ']').length) {
$('select#highlight').val(value);
} else {
$('select#highlight').val('');
}
});
$(window).trigger('hashchange');
});