|
18 | 18 |
|
19 | 19 | // Shorthand to make it a little easier to call public rails functions from within rails.js |
20 | 20 | var rails; |
| 21 | + var $document = $(document); |
21 | 22 |
|
22 | 23 | $.rails = rails = { |
23 | 24 | // Link elements bound by jquery-ujs |
|
279 | 280 |
|
280 | 281 | }; |
281 | 282 |
|
282 | | - if (rails.fire($(document), 'rails:attachBindings')) { |
| 283 | + if (rails.fire($document, 'rails:attachBindings')) { |
283 | 284 |
|
284 | 285 | $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }}); |
285 | 286 |
|
286 | | - $(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() { |
| 287 | + $document.delegate(rails.linkDisableSelector, 'ajax:complete', function() { |
287 | 288 | rails.enableElement($(this)); |
288 | 289 | }); |
289 | 290 |
|
290 | | - $(document).delegate(rails.linkClickSelector, 'click.rails', function(e) { |
| 291 | + $document.delegate(rails.linkClickSelector, 'click.rails', function(e) { |
291 | 292 | var link = $(this), method = link.data('method'), data = link.data('params'); |
292 | 293 | if (!rails.allowAction(link)) return rails.stopEverything(e); |
293 | 294 |
|
|
311 | 312 | } |
312 | 313 | }); |
313 | 314 |
|
314 | | - $(document).delegate(rails.buttonClickSelector, 'click.rails', function(e) { |
| 315 | + $document.delegate(rails.buttonClickSelector, 'click.rails', function(e) { |
315 | 316 | var button = $(this); |
316 | 317 | if (!rails.allowAction(button)) return rails.stopEverything(e); |
317 | 318 |
|
318 | 319 | rails.handleRemote(button); |
319 | 320 | return false; |
320 | 321 | }); |
321 | 322 |
|
322 | | - $(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) { |
| 323 | + $document.delegate(rails.inputChangeSelector, 'change.rails', function(e) { |
323 | 324 | var link = $(this); |
324 | 325 | if (!rails.allowAction(link)) return rails.stopEverything(e); |
325 | 326 |
|
326 | 327 | rails.handleRemote(link); |
327 | 328 | return false; |
328 | 329 | }); |
329 | 330 |
|
330 | | - $(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) { |
| 331 | + $document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) { |
331 | 332 | var form = $(this), |
332 | 333 | remote = form.data('remote') !== undefined, |
333 | 334 | blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector), |
|
362 | 363 | } |
363 | 364 | }); |
364 | 365 |
|
365 | | - $(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) { |
| 366 | + $document.delegate(rails.formInputClickSelector, 'click.rails', function(event) { |
366 | 367 | var button = $(this); |
367 | 368 |
|
368 | 369 | if (!rails.allowAction(button)) return rails.stopEverything(event); |
|
374 | 375 | button.closest('form').data('ujs:submit-button', data); |
375 | 376 | }); |
376 | 377 |
|
377 | | - $(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) { |
| 378 | + $document.delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) { |
378 | 379 | if (this == event.target) rails.disableFormElements($(this)); |
379 | 380 | }); |
380 | 381 |
|
381 | | - $(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) { |
| 382 | + $document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) { |
382 | 383 | if (this == event.target) rails.enableFormElements($(this)); |
383 | 384 | }); |
384 | 385 |
|
|
0 commit comments