From e138bbb04e3ec7c43bebf2f4494daadc12974ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Fri, 19 Jun 2020 10:19:35 +0200 Subject: [PATCH 1/6] Upgrade to jQuery 3.5.1 Latest version of jquery-rails gem includes latest jQuery 3 version with all security patches. See [1]. [1] https://github.com/rails/jquery-rails/blob/v4.4.0/CHANGELOG.md#440 --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/assets/javascripts/application.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 1cc47e28d..ae12ddb0b 100644 --- a/Gemfile +++ b/Gemfile @@ -29,7 +29,7 @@ gem "groupdate", "~> 5.1.0" gem "initialjs-rails", "~> 0.2.0.9" gem "invisible_captcha", "~> 0.10.0" gem "jquery-fileupload-rails" -gem "jquery-rails", "~> 4.3.3" +gem "jquery-rails", "~> 4.4.0" gem "jquery-ui-rails", "~> 6.0.1" gem "kaminari", "~> 1.2.1" gem "newrelic_rpm", "~> 4.1.0.333" diff --git a/Gemfile.lock b/Gemfile.lock index 62abd4917..566735c56 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -292,7 +292,7 @@ GEM actionpack (>= 3.1) railties (>= 3.1) sassc - jquery-rails (4.3.3) + jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -665,7 +665,7 @@ DEPENDENCIES initialjs-rails (~> 0.2.0.9) invisible_captcha (~> 0.10.0) jquery-fileupload-rails - jquery-rails (~> 4.3.3) + jquery-rails (~> 4.4.0) jquery-ui-rails (~> 6.0.1) kaminari (~> 1.2.1) knapsack_pro (~> 1.15.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e5fc6da7c..49bbf8b2b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,7 +10,7 @@ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // -//= require jquery +//= require jquery3 //= require jquery_ujs //= require jquery-ui/widgets/datepicker //= require jquery-ui/i18n/datepicker-ar From f4916a981a93e53171efc2622bd22d49ea7af51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Tue, 23 Jun 2020 15:53:58 +0200 Subject: [PATCH 2/6] Fix `focus` deprecation warning --- app/assets/javascripts/legislation_annotatable.js | 2 +- app/views/legislation/annotations/_comments_box_form.js.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/legislation_annotatable.js b/app/assets/javascripts/legislation_annotatable.js index 1b0c91ca7..3959dc5eb 100644 --- a/app/assets/javascripts/legislation_annotatable.js +++ b/app/assets/javascripts/legislation_annotatable.js @@ -109,7 +109,7 @@ }); if ($("[data-legislation-open-phase]").data("legislation-open-phase") !== false) { App.LegislationAnnotatable.highlight("#7fff9a"); - $("#comments-box textarea").focus(); + $("#comments-box textarea").trigger("focus"); $("#new_legislation_annotation").on("ajax:complete", function(e, data) { if (data.status === 200) { App.LegislationAnnotatable.remove_highlight(); diff --git a/app/views/legislation/annotations/_comments_box_form.js.erb b/app/views/legislation/annotations/_comments_box_form.js.erb index fbfce4c33..f290aff2e 100644 --- a/app/views/legislation/annotations/_comments_box_form.js.erb +++ b/app/views/legislation/annotations/_comments_box_form.js.erb @@ -1,5 +1,5 @@ <% if comment.errors.any? %> $("#comments-box-<%= @annotation.id %> a.publish-comment").hide(); $("#js-comment-form-annotation-<%= annotation.id %>").toggle(); - $("#js-comment-form-annotation-<%= annotation.id %> textarea").focus(); + $("#js-comment-form-annotation-<%= annotation.id %> textarea").trigger("focus"); <% end %> From 996062fa192c28730d8d21c456f00f63903c5052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 12 Aug 2020 21:42:49 +0200 Subject: [PATCH 3/6] Reset language select after adding a language It worked differently after upgrading to jQuery 3. According to the jQuery upgrade guide: > It is almost always a mistake to use .removeAttr("checked") on a DOM > element. The only time it might be useful is if the DOM is later going > to be serialized back to an HTML string. In all other cases, > .prop("checked", false) should be used instead. --- app/assets/javascripts/globalize.js | 2 +- spec/system/admin/translatable_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/globalize.js b/app/assets/javascripts/globalize.js index 8e323ee0c..c396639fe 100644 --- a/app/assets/javascripts/globalize.js +++ b/app/assets/javascripts/globalize.js @@ -7,7 +7,7 @@ display_locale: function(locale) { App.Globalize.enable_locale(locale); App.Globalize.add_language(locale); - $(".js-add-language option:selected").removeAttr("selected"); + $(".js-add-language option:selected").prop("selected", false); }, display_translations: function(locale) { $(".js-select-language option[value=" + locale + "]").prop("selected", true); diff --git a/spec/system/admin/translatable_spec.rb b/spec/system/admin/translatable_spec.rb index 9accfeb98..177a43909 100644 --- a/spec/system/admin/translatable_spec.rb +++ b/spec/system/admin/translatable_spec.rb @@ -493,6 +493,7 @@ describe "Admin edit translatable records" do select "Français", from: :add_language expect_to_have_language_selected "Français" + expect(page).to have_select :add_language, selected: "Add language" expect(page).to have_field "contents_content_#{content.key}values_value_fr" end From b8e352145c9e3662dc0ec8e32944848186494de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 13 Aug 2020 00:20:35 +0200 Subject: [PATCH 4/6] Use prop() instead of removeAttr() According to the jQuery upgrade guide: > It is almost always a mistake to use .removeAttr("checked") on a DOM > element. The only time it might be useful is if the DOM is later going > to be serialized back to an HTML string. In all other cases, > .prop("checked", false) should be used instead. --- app/assets/javascripts/legislation_admin.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/assets/javascripts/legislation_admin.js b/app/assets/javascripts/legislation_admin.js index efc7bf4ff..b63fec903 100644 --- a/app/assets/javascripts/legislation_admin.js +++ b/app/assets/javascripts/legislation_admin.js @@ -8,11 +8,7 @@ checkbox = $(this); checkbox.closest("fieldset").find("input[type='date']").each(function() { - if (checkbox.is(":checked")) { - $(this).removeAttr("disabled"); - } else { - $(this).prop("disabled", true); - } + $(this).prop("disabled", !checkbox.is(":checked")); }); } }).trigger("change"); From b499c0dcddc93dddd202b71b5f7a50ee7ea09d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 17 Aug 2020 13:16:39 +0200 Subject: [PATCH 5/6] Solve `bind`method deprecation warning As mentioned at the jQuery 3.0 upgrade guide [1] the `bind` method is deprecated. Replace with `on` method. [1] https://jquery.com/upgrade-guide/3.0/#deprecated-bind-and-delegate --- .../admin/poll/questions/answers/images/destroy.js.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/admin/poll/questions/answers/images/destroy.js.erb b/app/views/admin/poll/questions/answers/images/destroy.js.erb index 3a10a1cff..137451dda 100644 --- a/app/views/admin/poll/questions/answers/images/destroy.js.erb +++ b/app/views/admin/poll/questions/answers/images/destroy.js.erb @@ -1,3 +1,3 @@ -$(".delete").bind("ajax:success", function () { - $(this).closest("div").fadeOut() -}) +$(".delete").on("ajax:success", function () { + $(this).closest("div").fadeOut(); +}); From d7efd748fabc842457dc5d8e0adfccdf0219bb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 17 Aug 2020 15:48:26 +0200 Subject: [PATCH 6/6] Apply jQuery 3.0 upgrade_guide recommendation Use recommented way to define document-ready handlers. See [1] [1] https://jquery.com/upgrade-guide/3.0/#deprecated-document-ready-handlers-other-than-jquery-function --- app/assets/javascripts/dashboard_graphs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/dashboard_graphs.js b/app/assets/javascripts/dashboard_graphs.js index 3171e4815..5f04d4749 100644 --- a/app/assets/javascripts/dashboard_graphs.js +++ b/app/assets/javascripts/dashboard_graphs.js @@ -286,7 +286,7 @@ return this.groupBy === undefined || this.groupBy === "" || this.groupBy === null; }; - $(document).ready(function() { + $(function() { $("[data-proposal-graph-url]").each(function() { var graph = new ProposalGraph($(this).data("proposal-graph-url")); graph.successfulProposalDataUrl = $(this).data("successful-proposal-graph-url");