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

Version Path
decidim-core-0.27.9 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.8 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.7 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.6 app/packs/src/decidim/input_autojump.js
decidim-core-0.26.10 app/packs/src/decidim/input_autojump.js
decidim-core-0.26.9 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.5 app/packs/src/decidim/input_autojump.js
decidim-core-0.26.8 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.4 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.3 app/packs/src/decidim/input_autojump.js
decidim-core-0.26.7 app/packs/src/decidim/input_autojump.js
decidim-core-0.26.5 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.2 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.1 app/packs/src/decidim/input_autojump.js
decidim-core-0.26.4 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.0 app/packs/src/decidim/input_autojump.js
decidim-core-0.26.3 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.0.rc2 app/packs/src/decidim/input_autojump.js
decidim-core-0.27.0.rc1 app/packs/src/decidim/input_autojump.js
decidim-core-0.26.2 app/packs/src/decidim/input_autojump.js