Remove redundant call to $(document).ready()

The `$()` function is a shortcut for `$(document).ready()`, and we were
attaching events to `$(document).ready()` inside the `$()` function.

In a similar way, we were handling the `page:load` and `ajax:complete`
events inside the `$()` function. But when those events trigger, the DOM
is already ready.

Besides, we don't have to wait for the DOM to be ready before attaching
events to the `document` element. Quoting jQuery's `.on()`
documentation:

> The document element is available in the head of the document before
> loading any other HTML, so it is safe to attach events there without
> waiting for the document to be ready.

Co-Authored-By: Senén Rodero Rodríguez <senenrodero@gmail.com>
This commit is contained in:
Javi Martín
2020-08-04 18:56:01 +02:00
committed by Senén Rodero Rodríguez
parent 983bf49b38
commit 017eeda3d4
2 changed files with 5 additions and 10 deletions

View File

@@ -170,7 +170,6 @@ $(function() {
"use strict"; "use strict";
Turbolinks.enableProgressBar(); Turbolinks.enableProgressBar();
$(document).ready(initialize_modules);
$(document).on("page:load", initialize_modules);
}); });
$(document).ready(initialize_modules);
$(document).on("page:load", initialize_modules);

View File

@@ -9,10 +9,6 @@ var initialize_stats_modules = function() {
App.Stats.initialize(); App.Stats.initialize();
}; };
$(function() { $(document).ready(initialize_stats_modules);
"use strict"; $(document).on("page:load", initialize_stats_modules);
$(document).on("ajax:complete", initialize_stats_modules);
$(document).ready(initialize_stats_modules);
$(document).on("page:load", initialize_stats_modules);
$(document).on("ajax:complete", initialize_stats_modules);
});