Sha256: 511676b9dcfb09ce4c4a7875527441b484526c4f1cf669f08b86a004c77eff10
Contents?: true
Size: 1.06 KB
Versions: 31
Compression:
Stored size: 1.06 KB
Contents
$(() => { const $inputs = $("input[data-autojump]"); const DELETE_KEY_CODE = 8; // Initialize $inputs.on("keydown", (event) => { // Don't do anything if there is selected text if (event.target.selectionStart !== event.target.selectionEnd) { return; } if (event.originalEvent.key.length === 1 && event.target.dataset.jumpNext) { if ( event.target.value.length === parseInt(event.target.dataset.maxLength, 10) ) { event.preventDefault(); setTimeout(() => { const next = $(event.target.dataset.jumpNext); next.val(event.originalEvent.key); next.trigger("focus"); }, 1); } } else if ( event.originalEvent.keyCode === DELETE_KEY_CODE && event.target.dataset.jumpPrev ) { if (event.target.value.length === 0) { event.preventDefault(); setTimeout(() => { const prev = $(event.target.dataset.jumpPrev); prev.val(prev.val().slice(0, -1)); prev.trigger("focus"); }, 1); } } }); });
Version data entries
31 entries across 31 versions & 1 rubygems