Sha256: 279ff1a3874566220dc8c13e49cdf455e212be69e1808e187debceac2cebc86b

Contents?: true

Size: 1.79 KB

Versions: 17

Compression:

Stored size: 1.79 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, {})
    }
  })
}

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

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

  // Fade all growl notifications.
  if ($("#flash_notices").length > 0) {
    Alchemy.Growler.fade()
  }

  // 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")
    )
  }
}

export default Initialize

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
alchemy_cms-7.1.13 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.12 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.11 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.10 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.9 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.8 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.7 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.6 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.5 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.4 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.3 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.2 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.1 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.0 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.0.pre.rc1 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.0.pre.b2 app/javascript/alchemy_admin/initializer.js
alchemy_cms-7.1.0.pre.b1 app/javascript/alchemy_admin/initializer.js