|
|
@@ -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
|