Przeglądaj źródła

Replace Bootstrap 3 stateful button handling with custom JS for loading state.

master
Samir Shah 5 lat temu
rodzic
commit
73ef2cb3b3

+ 12
- 4
src/oscar/static_src/oscar/js/oscar/dashboard.js Wyświetl plik

@@ -275,14 +275,22 @@ var oscar = (function(o, $) {
275 275
         },
276 276
         initForms: function() {
277 277
             // Disable buttons when they are clicked and show a "loading" message taken from the
278
-            // data-loading-text attribute (http://getbootstrap.com/2.3.2/javascript.html#buttons).
278
+            // data-loading-text attribute.
279 279
             // Do not disable if button is inside a form with invalid fields.
280 280
             // This uses a delegated event so that it keeps working for forms that are reloaded
281 281
             // via AJAX: https://api.jquery.com/on/#direct-and-delegated-events
282 282
             $(document.body).on('click', '[data-loading-text]', function(){
283
-                var form = $(this).parents("form");
284
-                if (!form || $(":invalid", form).length == 0)
285
-                    $(this).button('loading');
283
+                var $btn_or_input = $(this),
284
+                    form = $btn_or_input.parents("form");
285
+                if (!form || $(":invalid", form).length == 0) {
286
+                    var d = 'disabled',
287
+                        val = $btn_or_input.is('input') ? 'val' : 'html';
288
+                    // push to event loop so as not to delay form submission
289
+                    setTimeout(function() {
290
+                        $btn_or_input[val]($btn_or_input.data('loading-text'));
291
+                        $btn_or_input.addClass(d).attr(d, d).prop(d, true);
292
+                    });
293
+                }
286 294
             });
287 295
 
288 296
             // Display tabs that have invalid input fields

+ 13
- 5
src/oscar/static_src/oscar/js/oscar/ui.js Wyświetl plik

@@ -66,14 +66,22 @@ var oscar = (function(o, $) {
66 66
             $('form[data-behaviours~="lock"]').submit(o.forms.submitIfNotLocked);
67 67
 
68 68
             // Disable buttons when they are clicked and show a "loading" message taken from the
69
-            // data-loading-text attribute (http://getbootstrap.com/2.3.2/javascript.html#buttons).
69
+            // data-loading-text attribute.
70 70
             // Do not disable if button is inside a form with invalid fields.
71 71
             // This uses a delegated event so that it keeps working for forms that are reloaded
72 72
             // via AJAX: https://api.jquery.com/on/#direct-and-delegated-events
73
-            $(document.body).on('submit', 'form', function(){
74
-                var form = $(this);
75
-                if ($(":invalid", form).length == 0)
76
-                    $(this).find('button[data-loading-text]').button('loading');
73
+            $(document.body).on('click', '[data-loading-text]', function(){
74
+                var $btn_or_input = $(this),
75
+                    form = $btn_or_input.parents("form");
76
+                if (!form || $(":invalid", form).length == 0) {
77
+                    var d = 'disabled',
78
+                        val = $btn_or_input.is('input') ? 'val' : 'html';
79
+                    // push to event loop so as not to delay form submission
80
+                    setTimeout(function() {
81
+                        $btn_or_input[val]($btn_or_input.data('loading-text'));
82
+                        $btn_or_input.addClass(d).attr(d, d).prop(d, true);
83
+                    });
84
+                }
77 85
             });
78 86
             // stuff for star rating on review page
79 87
             // show clickable stars instead of a select dropdown for product rating

Ładowanie…
Anuluj
Zapisz