Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Javascript code #4073

Merged
merged 7 commits into from
Aug 5, 2020
Merged

Conversation

Senen
Copy link
Member

@Senen Senen commented Aug 5, 2020

References

Related PR: Turbolinks 5 fixes #4071

Objectives

Add some javascript fixes for errors found during manual testing of all application javascript.

Use delegated handlers instead so there is not risk to run method
multiple times.
By using an event delegation handler on document body there is no need
to check if element was already initialized (idempotency) anymore.
There is no elements with class `js-participation-allowed` within all
application code.
TableSortable and Sortable javascripts were using the same CSS
class name to define completely different and separated
behaviours causing unexpected errors. Now `sortable.js` script
will use `.sortable` class and `table_sortable.js` will use
`.table-sortable` instead.
@Senen Senen self-assigned this Aug 5, 2020
@Senen Senen marked this pull request as ready for review August 5, 2020 08:47
@Senen Senen mentioned this pull request Aug 5, 2020
Senen and others added 3 commits August 5, 2020 11:34
Its known that initializing a map when it is inside a hidden element
wont work when hidden element is shown, so its makes sense to
avoid initialization of hidden maps.

When a map lives within a hidden layer we need to initialize the
map after the event of showing that hidden layer, in our case when
admin settings tab is shown.
In the past we had huge problems trying to make it work with Turbolinks.
However, after updating foundation-rails in commit 58071fd, these hacks
aren't necessary anymore.

We're adding a test for the scenario of visiting a page using
Turbolinks, which was missing, so we're sure we aren't breaking
anything.

Note the sticky will still not work after using the browser back button.
We haven't been able to make it work with turbolinks-classic; we'll fix
this issue when upgrading turbolinks.
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>
@javierm javierm added this to Reviewing in Consul Democracy via automation Aug 5, 2020
Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 😄

Consul Democracy automation moved this from Reviewing to Testing Aug 5, 2020
@javierm javierm merged commit a8f261e into consuldemocracy:master Aug 5, 2020
Consul Democracy automation moved this from Testing to Release 1.2.0 Aug 5, 2020
@javierm javierm removed the 1.2 label Aug 5, 2020
@javierm javierm self-assigned this Aug 5, 2020
@javierm javierm changed the title Javascript fixes Simplify Javascript code Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants