-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert Initializer from Coffeescript to Javascript
Move the initializer also into the Javascript folder. It make sense to move the higher level Javascript first, because this will prevent loading raise conditions.
- Loading branch information
1 parent
c239df1
commit 822f9dd
Showing
4 changed files
with
66 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
app/assets/javascripts/alchemy/alchemy.initializer.js.coffee
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* add change listener to select to redirect the user after selecting another locale or site | ||
* @param {string} selectId | ||
* @param {string} parameterName | ||
*/ | ||
function selectHandler(selectId, parameterName) { | ||
$(`select#${selectId}`).on("change", function (e) { | ||
let url = window.location.pathname | ||
let delimiter = url.match(/\?/) ? "&" : "?" | ||
Turbo.visit(`${url}${delimiter}${parameterName}=${$(this).val()}`, {}) | ||
}) | ||
} | ||
|
||
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, .button_with_label form :submit") | ||
.not("*[data-alchemy-confirm]") | ||
.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") | ||
|
||
// 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 |