bluzky / nice-select2

A lightweight vanilla javascript library that replaces native select elements with customizable dropdowns
https://bluzky.github.io/nice-select2/
MIT License
370 stars 61 forks source link

initEvent is deprecated #84

Open Cypaaa opened 4 months ago

Cypaaa commented 4 months ago

Hi, I saw the nice-select2.js file contains a lot of initEvent which is deprecated. You should consider updating the code to keep the support of every browser.

Here is the documentation url in case you cannot click the link above: https://developer.mozilla.org/en-US/docs/Web/API/Event/initEvent

Cypaaa commented 4 months ago

Here is an updated version of the code containing initEvent:

// utility functions
function triggerClick(el) {
  const event = new MouseEvent("click", {
    bubbles: true,
    cancelable: false,
  });
  el.dispatchEvent(event);
}

function triggerChange(el) {
  const event = new Event("change", {
    bubbles: true,
    cancelable: false,
  });
  el.dispatchEvent(event);
}

function triggerFocusIn(el) {
  const event = new FocusEvent("focusin", {
    bubbles: true,
    cancelable: false,
  });
  el.dispatchEvent(event);
}

function triggerFocusOut(el) {
  const event = new FocusEvent("focusout", {
    bubbles: true,
    cancelable: false,
  });
  el.dispatchEvent(event);
}

function triggerModalOpen(el) {
  const event = new UIEvent("modalopen", {
    bubbles: true,
    cancelable: false,
  });
  el.dispatchEvent(event);
}

function triggerModalClose(el) {
  const event = new UIEvent("modalclose", {
    bubbles: true,
    cancelable: false,
  });
  el.dispatchEvent(event);
}