Created
October 2, 2017 19:42
-
-
Save kascote/c44c0ffc83f472229f22ffca9e254b95 to your computer and use it in GitHub Desktop.
Replace Rails 5 alert dialog
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
promiseBasedConfirmPopup = new Promise((resolve) => { | |
// Show a nice popup and resolve to true/false | |
setTimeout(() => resolve(true), 2000) | |
}) | |
$("a[data-confirm]").on("confirm", function(evt) { | |
// evt.target hold the clicked anchor from where | |
// can be extracted some data to build the popup | |
promiseBasedConfirmPopup().then((res) => { | |
if (res) { | |
// execute default handler if promise resolve true | |
// https://github.com/rails/rails/blob/v5.1.4/actionview/app/assets/javascripts/rails-ujs/features/method.coffee | |
Rails.handleMethod.apply(evt.target, [evt]) | |
} | |
}) | |
// this is key, return false to disable default confirm dialog | |
// https://github.com/rails/rails/blob/v5.1.4/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee#L22 | |
return false | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment