jqr-helpers 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,12 @@
5
5
  }
6
6
 
7
7
  function hideThrobber(element) {
8
- $(element).next().remove();
8
+ $(element).nextAll('.throbber').remove();
9
9
  $(element).removeAttr('disabled');
10
10
  }
11
11
 
12
12
  var ujsDialogElement = null; // the element that opened the dialog
13
+ var ujsSubmitElement = null; // the element that submitted a form
13
14
 
14
15
  // called from dialog button value
15
16
  function ujsSubmitDialogForm() {
@@ -47,11 +48,13 @@
47
48
  if ($(this).data('close-x')) {
48
49
  dialogElement.prepend('<span class="ujs-dialog-x"></span>');
49
50
  }
51
+ var url = $(this).data('dialog-url');
50
52
  var dialogOptions = $(this).data('dialog-options');
51
53
  var open = dialogOptions['open'];
52
54
  dialogOptions = $.extend(dialogOptions, {
53
55
  'close': function() {
54
56
  $(this).dialog('destroy').addClass('ujs-dialog-hidden');
57
+ if (url) $(this).remove();
55
58
  },
56
59
  'open': function() {
57
60
  ujsDialogOpen.call(this);
@@ -77,7 +80,6 @@
77
80
  }
78
81
  });
79
82
  }
80
- var url = $(this).data('dialog-url');
81
83
  if (url) {
82
84
  $(this).trigger('jqr.beforedialogopen');
83
85
  $(document.body).append('<div class="ui-widget-overlay ui-front">');
@@ -108,6 +110,10 @@
108
110
  return false;
109
111
  }
110
112
 
113
+ function ujsSubmitClick(event) {
114
+ ujsSubmitElement = event.target;
115
+ }
116
+
111
117
  function ujsButtonClick(event) {
112
118
  var element = $(this);
113
119
  element.uniqueId(); // to store for later
@@ -142,19 +148,10 @@
142
148
  if (element.data('real-element')) {
143
149
  element = $('#' + element.data('real-element'));
144
150
  }
145
- if (element.is('form')) {
146
- var submit = $('input[type=submit]', element);
147
- if (submit.length)
148
- showThrobber(submit);
149
- else
150
- showThrobber(element);
151
- }
152
- else {
153
- showThrobber(element);
154
- }
155
- if (element.is('form'))
156
- element = $('button, input[type=submit]', element).first();
157
- element.attr('disabled', 'disabled');
151
+ if (element.is('form') &&
152
+ $(ujsSubmitElement).parents('form').index(element) >= 0)
153
+ element = ujsSubmitElement;
154
+ showThrobber(element);
158
155
  }
159
156
 
160
157
  function ujsAjaxSuccess(evt, data, status, xhr) {
@@ -162,11 +159,11 @@
162
159
  if (element.data('real-element')) {
163
160
  element = $('#' + element.data('real-element'));
164
161
  }
165
- hideThrobber(element);
166
162
  var disableElement = element;
167
- if (element.is('form'))
168
- disableElement = $('button, input[type=submit]', element).first();
169
- disableElement.attr('disabled', false);
163
+ if (element.is('form') &&
164
+ $(ujsSubmitElement).parents('form').index(element) >= 0)
165
+ disableElement = ujsSubmitElement;
166
+ hideThrobber(disableElement);
170
167
  var targetElement = element;
171
168
  // if this was sent from a dialog, close the dialog and look at the
172
169
  // element that opened it for update/append/delete callbacks.
@@ -180,7 +177,7 @@
180
177
  var callback = eval(element.data('callback'));
181
178
  callback.call(targetElement, data);
182
179
  }
183
- if (data && data.trim().charAt(0) != '<' && data != 'success') {
180
+ else if (data && data.trim().charAt(0) != '<' && data != 'success') {
184
181
  alert(data);
185
182
  return;
186
183
  }
@@ -270,6 +267,7 @@
270
267
  $(function() {
271
268
  if ($().on) { // newer jQueries
272
269
  $(document).on('jqr.load', ujsLoadPlugins);
270
+ $(document).on('click', 'input[type=submit]', ujsSubmitClick);
273
271
  $(document).on('click', '.ujs-dialog', ujsDialogClick);
274
272
  $(document).on('click', '.ujs-dialog-close, .ujs-dialog-x',
275
273
  ujsDialogCloseClick);
@@ -281,6 +279,7 @@
281
279
  }
282
280
  else {
283
281
  $('body').live('jqr.load', ujsLoadPlugins);
282
+ $('input[type=submit]').live('click', ujsSubmitClick);
284
283
  $('.ujs-dialog').live('click', ujsDialogClick);
285
284
  $('.ujs-dialog-close, .ujs-dialog-x').live('click', ujsDialogCloseClick);
286
285
  $('.ujs-ajax-button').live('click', ujsButtonClick);
@@ -291,6 +290,13 @@
291
290
  }
292
291
  $('body').trigger('jqr.load');
293
292
 
293
+ // Derived from
294
+ // https://makandracards.com/makandra/3877-re-enable-submit-buttons-disabled-by-the-disabled_with-option
295
+ $(window).unload(function() {
296
+ $.rails.enableFormElements($($.rails.formSubmitSelector));
297
+ $('input[disabled],button[disabled],select[disabled]').prop('disabled', false);
298
+ });
299
+
294
300
  });
295
301
 
296
302
  }(jQuery));
@@ -1,7 +1,3 @@
1
- form.ujs-ajax, form.ujs-ajax div {
2
- display: inline;
3
- }
4
-
5
1
  .ujs-dialog-modal {
6
2
  position: fixed !important;
7
3
  }
data/jqr-helpers.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jqr-helpers'
3
3
  s.require_paths = %w(. lib lib/jqr-helpers)
4
- s.version = '1.0.10'
4
+ s.version = '1.0.11'
5
5
  s.date = '2013-11-19'
6
6
  s.summary = 'Helpers to print unobtrusive jQuery-UI tags.'
7
7
  s.description = <<-EOF
@@ -1,5 +1,5 @@
1
1
  module JqrHelpers
2
2
  module Rails
3
- VERSION = '1.0.10'
3
+ VERSION = '1.0.11'
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jqr-helpers
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.10
5
+ version: 1.0.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel Orner