Sha256: da92c4089e66f243e8474ad863a0e3a82110d167de1dbb9e7d837640d4b400c3

Contents?: true

Size: 1.67 KB

Versions: 12

Compression:

Stored size: 1.67 KB

Contents

/**
 * add change listener to select to redirect the user after selecting another locale or site
 * @param {string} selectId
 * @param {string} parameterName
 * @param {boolean} forcedReload
 */
function selectHandler(selectId, parameterName, forcedReload = false) {
  $(`select#${selectId}`).on("change", function (e) {
    let url = window.location.pathname
    let delimiter = url.match(/\?/) ? "&" : "?"
    const location = `${url}${delimiter}${parameterName}=${$(this).val()}`

    if (forcedReload) {
      window.location.href = location
    } else {
      Turbo.visit(location, {})
    }
  })
}

export default function Initializer() {
  // We obviously have javascript enabled.
  $("html").removeClass("no-js")

  // Initialize the GUI.
  Alchemy.GUI.init()

  // Add observer for please wait overlay.
  $(".please_wait")
    .not("*[data-alchemy-confirm]")
    .on("click", Alchemy.pleaseWaitOverlay)

  // Hack for enabling tab focus for <a>'s styled as button.
  $("a.button").attr({ tabindex: 0 })

  // Locale select handler
  selectHandler("change_locale", "admin_locale", true)

  // Site select handler
  selectHandler("change_site", "site_id")

  // Submit forms of selects with `data-autosubmit="true"`
  $('select[data-auto-submit="true"]').on("change", function () {
    $(this.form).submit()
  })

  // Attaches the image loader on all images
  Alchemy.ImageLoader("#main_content")

  // Override the filter of keymaster.js so we can blur the fields on esc key.
  key.filter = function (event) {
    let tagName = (event.target || event.srcElement).tagName
    return (
      key.isPressed("esc") ||
      !(tagName === "INPUT" || tagName === "SELECT" || tagName === "TEXTAREA")
    )
  }
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.3.3 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.3.2 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.2.7 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.3.1 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.3.0 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.2.6 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.2.5 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.2.4 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.2.3 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.2.2 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.2.1 app/javascript/alchemy_admin/initializer.js