|
58 | 58 | formSubmitSelector: 'form', |
59 | 59 |
|
60 | 60 | // Form input elements bound by jquery-ujs |
61 | | - formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])', |
| 61 | + formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not(button[type])', |
62 | 62 |
|
63 | 63 | // Form input elements disabled during form submission |
64 | 64 | disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]', |
|
159 | 159 | handleMethod: function(link) { |
160 | 160 | var href = link.attr('href'), |
161 | 161 | method = link.data('method'), |
| 162 | + target = link.attr('target'), |
162 | 163 | csrf_token = $('meta[name=csrf-token]').attr('content'), |
163 | 164 | csrf_param = $('meta[name=csrf-param]').attr('content'), |
164 | 165 | form = $('<form method="post" action="' + href + '"></form>'), |
|
168 | 169 | metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />'; |
169 | 170 | } |
170 | 171 |
|
| 172 | + if (target) { form.attr('target', target); } |
| 173 | + |
171 | 174 | form.hide().append(metadata_input).appendTo('body'); |
172 | 175 | form.submit(); |
173 | 176 | }, |
174 | 177 |
|
175 | 178 | /* Disables form elements: |
176 | 179 | - Caches element value in 'ujs:enable-with' data store |
177 | 180 | - Replaces element text with value of 'data-disable-with' attribute |
178 | | - - Adds disabled=disabled attribute |
| 181 | + - Sets disabled property to true |
179 | 182 | */ |
180 | 183 | disableFormElements: function(form) { |
181 | 184 | form.find(rails.disableSelector).each(function() { |
182 | 185 | var element = $(this), method = element.is('button') ? 'html' : 'val'; |
183 | 186 | element.data('ujs:enable-with', element[method]()); |
184 | 187 | element[method](element.data('disable-with')); |
185 | | - element.attr('disabled', 'disabled'); |
| 188 | + element.prop('disabled', true); |
186 | 189 | }); |
187 | 190 | }, |
188 | 191 |
|
189 | 192 | /* Re-enables disabled form elements: |
190 | 193 | - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) |
191 | | - - Removes disabled attribute |
| 194 | + - Sets disabled property to false |
192 | 195 | */ |
193 | 196 | enableFormElements: function(form) { |
194 | 197 | form.find(rails.enableSelector).each(function() { |
195 | 198 | var element = $(this), method = element.is('button') ? 'html' : 'val'; |
196 | 199 | if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with')); |
197 | | - element.removeAttr('disabled'); |
| 200 | + element.prop('disabled', false); |
198 | 201 | }); |
199 | 202 | }, |
200 | 203 |
|
|
288 | 291 | }); |
289 | 292 |
|
290 | 293 | $(rails.linkClickSelector).live('click.rails', function(e) { |
291 | | - var link = $(this); |
| 294 | + var link = $(this), method = link.data('method'), data = link.data('params'); |
292 | 295 | if (!rails.allowAction(link)) return rails.stopEverything(e); |
293 | 296 |
|
294 | 297 | if (link.is(rails.linkDisableSelector)) rails.disableElement(link); |
295 | 298 |
|
296 | 299 | if (link.data('remote') !== undefined) { |
| 300 | + if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; } |
297 | 301 | rails.handleRemote(link); |
298 | 302 | return false; |
299 | 303 | } else if (link.data('method')) { |
|
0 commit comments