app/javascript/beyond_canvas/initializers/buttons.js in beyond_canvas-0.21.0.pre vs app/javascript/beyond_canvas/initializers/buttons.js in beyond_canvas-0.22.0.pre
- old
+ new
@@ -1,10 +1,10 @@
const SPINNER_ANIMATION_TIMEOUT = 125;
const BUTTON_SELECTORS = '[class^="button"]';
(function ($) {
- const onDOMReady = function (e) {
+ const onDOMReady = function () {
const inputs = $('input, textarea, select').not(
':input[type=button], :input[type=submit], :input[type=reset]'
);
inputs.each(function () {
@@ -17,45 +17,26 @@
$.restoreActionElements();
});
});
$(BUTTON_SELECTORS).each(function () {
- var button = $(this);
-
- // Add width attribute and save old width
- button.width(button.width());
- button.data('oldWidth', button.width());
-
- // Add the spinner
- if (button.find('.spinner').length == 0) {
- button.prepend(`
- <div class="spinner">
- <div class="bounce1"></div>
- <div class="bounce2"></div>
- <div class="bounce3"></div>
- </div>`);
- }
-
- // Bind ajax:success and ajax:error to the form the button belongs to
- button
- .closest('form')
- .on('ajax:success', function () {
- $.restoreActionElements();
- })
- .on('ajax:error', function () {
- $.restoreActionElements();
- });
+ $(this).buildButton();
});
};
$(document).on('confirm:complete', function () {
$.restoreActionElements();
});
$(document).on('click', BUTTON_SELECTORS, function () {
+ var button = $(this);
+
$.disableActionElements();
- $(this).showSpinner();
+
+ if (!button.hasClass('button--no-spinner')) {
+ $(this).showSpinner();
+ }
});
$(document).on('ready page:load turbolinks:load', onDOMReady);
})(jQuery);
@@ -82,9 +63,40 @@
});
}
});
$.fn.extend({
+ buildButton: function() {
+ var button = $(this);
+
+ if (button.is('[class^=button]')) {
+ if (!button.hasClass('button--no-spinner')) {
+ // Add width attribute and save old width
+ button.width(button.width());
+ button.data('oldWidth', button.width());
+
+ // Add the spinner
+ if (button.find('.spinner').length == 0) {
+ button.prepend(`
+ <div class="spinner">
+ <div class="bounce1"></div>
+ <div class="bounce2"></div>
+ <div class="bounce3"></div>
+ </div>`);
+ }
+ }
+
+ // Bind ajax:success and ajax:error to the form the button belongs to
+ button
+ .closest('form')
+ .on('ajax:success', function () {
+ $.restoreActionElements();
+ })
+ .on('ajax:error', function () {
+ $.restoreActionElements();
+ });
+ }
+ },
showSpinner: function () {
var button = $(this);
// Adjust the width of the button
button.width(