Skip to content

Commit a8f36f7

Browse files
committed
Cached the jQuery document element.
1 parent 846a91a commit a8f36f7

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/rails.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
// Shorthand to make it a little easier to call public rails functions from within rails.js
2020
var rails;
21+
var $document = $(document);
2122

2223
$.rails = rails = {
2324
// Link elements bound by jquery-ujs
@@ -279,15 +280,15 @@
279280

280281
};
281282

282-
if (rails.fire($(document), 'rails:attachBindings')) {
283+
if (rails.fire($document, 'rails:attachBindings')) {
283284

284285
$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
285286

286-
$(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() {
287+
$document.delegate(rails.linkDisableSelector, 'ajax:complete', function() {
287288
rails.enableElement($(this));
288289
});
289290

290-
$(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {
291+
$document.delegate(rails.linkClickSelector, 'click.rails', function(e) {
291292
var link = $(this), method = link.data('method'), data = link.data('params');
292293
if (!rails.allowAction(link)) return rails.stopEverything(e);
293294

@@ -311,23 +312,23 @@
311312
}
312313
});
313314

314-
$(document).delegate(rails.buttonClickSelector, 'click.rails', function(e) {
315+
$document.delegate(rails.buttonClickSelector, 'click.rails', function(e) {
315316
var button = $(this);
316317
if (!rails.allowAction(button)) return rails.stopEverything(e);
317318

318319
rails.handleRemote(button);
319320
return false;
320321
});
321322

322-
$(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) {
323+
$document.delegate(rails.inputChangeSelector, 'change.rails', function(e) {
323324
var link = $(this);
324325
if (!rails.allowAction(link)) return rails.stopEverything(e);
325326

326327
rails.handleRemote(link);
327328
return false;
328329
});
329330

330-
$(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
331+
$document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
331332
var form = $(this),
332333
remote = form.data('remote') !== undefined,
333334
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
@@ -362,7 +363,7 @@
362363
}
363364
});
364365

365-
$(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
366+
$document.delegate(rails.formInputClickSelector, 'click.rails', function(event) {
366367
var button = $(this);
367368

368369
if (!rails.allowAction(button)) return rails.stopEverything(event);
@@ -374,11 +375,11 @@
374375
button.closest('form').data('ujs:submit-button', data);
375376
});
376377

377-
$(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
378+
$document.delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
378379
if (this == event.target) rails.disableFormElements($(this));
379380
});
380381

381-
$(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
382+
$document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
382383
if (this == event.target) rails.enableFormElements($(this));
383384
});
384385

0 commit comments

Comments
 (0)