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

Reorganize comment.js & dragdrop.js Script-Loading #9037

Merged
merged 3 commits into from
Jan 20, 2021

Conversation

noi5e
Copy link
Contributor

@noi5e noi5e commented Jan 19, 2021

Part of an object-oriented refactoring of the Comment Editor. See #9004 for more details.

Currently comment.js and dragdrop.js are loaded once per every comment form on a page:

<%= javascript_include_tag "dragdrop" %>
<script src="/emoji.js" type="text/javascript"></script>
<script src="/assets/atwho_autocomplete.js" type="text/javascript"></script>
<%= javascript_include_tag "comment.js" %>

They really only need to be loaded once per page (not 5 times on a page with 5 comments)!

Both scripts (but particularly dragdrop.js) have eventListeners which can get attached multiple times to the same element if each script is loaded multiple times.

Simplifying the script loading is going to help with refactoring editor.js.


(This issue is part of the larger Comment Editor Overhaul Project with Outreachy. Refer to Planning Issue #9069 for more context)

@noi5e noi5e added JavaScript feature explains that the issue is to add a new feature outreachy labels Jan 19, 2021
@noi5e noi5e requested a review from a team as a code owner January 19, 2021 06:03
@gitpod-io
Copy link

gitpod-io bot commented Jan 19, 2021

@codecov
Copy link

codecov bot commented Jan 19, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@f0be879). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9037   +/-   ##
=======================================
  Coverage        ?   82.05%           
=======================================
  Files           ?      100           
  Lines           ?     5939           
  Branches        ?        0           
=======================================
  Hits            ?     4873           
  Misses          ?     1066           
  Partials        ?        0           

@@ -1,5 +1,4 @@
(function() {

$(function() {
$('.comment-form').each(function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that all along, these eventHandlers weren't being attached on document.load!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great catch 🎉

@codeclimate
Copy link

codeclimate bot commented Jan 19, 2021

Code Climate has analyzed commit 7a1b0f2 and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Collaborator

@cesswairimu cesswairimu left a comment

Choose a reason for hiding this comment

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

🎉

@jywarren
Copy link
Member

Looks great! Shall we merge? Omg event listeners initialization is such a common JS bug!!! 😭😂🎉

@noi5e
Copy link
Contributor Author

noi5e commented Jan 19, 2021

@jywarren Yep, ready to merge!

@jywarren jywarren merged commit 2583a40 into publiclab:main Jan 20, 2021
@jywarren
Copy link
Member

🎉 🎉 🎉 🎉

@noi5e noi5e deleted the feature/revise-comment-javascript-tags branch January 20, 2021 17:38
@noi5e noi5e changed the title Feature: Reorganize comment.js & dragdrop.js Script-Loading Reorganize comment.js & dragdrop.js Script-Loading Jan 23, 2021
manchere pushed a commit to manchere/plots2 that referenced this pull request Feb 13, 2021
…b#9037)

* move comment.js & dragdrop.js to higher-level views publiclab#9004

* attach eventListeners on document.load publiclab#9004

* move dragdrop.js & comment.js to notes/comments partial publiclab#9004
lagunasmel pushed a commit to lagunasmel/plots2 that referenced this pull request Mar 2, 2021
…b#9037)

* move comment.js & dragdrop.js to higher-level views publiclab#9004

* attach eventListeners on document.load publiclab#9004

* move dragdrop.js & comment.js to notes/comments partial publiclab#9004
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
…b#9037)

* move comment.js & dragdrop.js to higher-level views publiclab#9004

* attach eventListeners on document.load publiclab#9004

* move dragdrop.js & comment.js to notes/comments partial publiclab#9004
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
…b#9037)

* move comment.js & dragdrop.js to higher-level views publiclab#9004

* attach eventListeners on document.load publiclab#9004

* move dragdrop.js & comment.js to notes/comments partial publiclab#9004
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature explains that the issue is to add a new feature JavaScript outreachy readytomerge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants