Merge pull request #4073 from rockandror/javascript_fixes

Javascript fixes
This commit is contained in:
Javier Martín
2020-08-05 14:07:16 +02:00
committed by GitHub
12 changed files with 66 additions and 61 deletions

View File

@@ -5,11 +5,9 @@
$(document).on({
"mouseenter focus": function() {
$(this).find(".js-participation-not-allowed").show();
$(this).find(".js-participation-allowed").hide();
},
mouseleave: function() {
$(this).find(".js-participation-not-allowed").hide();
$(this).find(".js-participation-allowed").show();
}
}, ".js-participation");
}

View File

@@ -170,7 +170,6 @@ $(function() {
"use strict";
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,13 +9,13 @@
});
},
submitOnChange: function() {
$(".js-submit-on-change").off("change").on("change", function() {
$("body").on("change", ".js-submit-on-change", function() {
$(this).closest("form").submit();
return false;
});
},
toggleLink: function() {
$(".js-toggle-link").off("click").on("click", function() {
$("body").on("click", ".js-toggle-link", function() {
var toggle_txt;
$($(this).data("toggle-selector")).toggle("down");
if ($(this).data("toggle-text") !== undefined) {

View File

@@ -1,29 +1,8 @@
(function() {
"use strict";
App.FoundationExtras = {
clearSticky: function() {
if ($("[data-sticky]").length) {
$("[data-sticky]").foundation("destroy");
}
},
mobile_ui_init: function() {
$(window).trigger("load.zf.sticky");
},
desktop_ui_init: function() {
$(window).trigger("init.zf.sticky");
},
initialize: function() {
$(document).foundation();
$(window).trigger("resize");
$(document).on("page:before-unload", this.clearSticky);
window.addEventListener("popstate", this.clearSticky, false);
$(function() {
if ($(window).width() < 620) {
App.FoundationExtras.mobile_ui_init();
} else {
App.FoundationExtras.desktop_ui_init();
}
});
}
};
}).call(this);

View File

@@ -69,14 +69,14 @@
$("#comments-box").html("");
App.LegislationAllegations.show_comments();
$("#comments-box").show();
$.event.trigger({
$("body").trigger({
type: "renderLegislationAnnotation",
annotation_id: target.data("annotation-id"),
annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url"),
offset: target.offset().top
});
parents_ids.each(function(i, pid) {
$.event.trigger({
$("body").trigger({
type: "renderLegislationAnnotation",
annotation_id: pid,
annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
@@ -144,7 +144,7 @@
$("html,body").animate({
scrollTop: el.offset().top
});
$.event.trigger({
$("body").trigger({
type: "renderLegislationAnnotation",
annotation_id: ann_id,
annotation_url: el.closest(".legislation-annotatable").data("legislation-annotatable-base-url"),
@@ -188,9 +188,9 @@
},
initialize: function() {
var current_user_id;
$(document).off("renderLegislationAnnotation").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments);
$(document).off("click", "[data-annotation-id]").on("click", "[data-annotation-id]", App.LegislationAnnotatable.onClick);
$(document).off("click", "[data-cancel-annotation]").on("click", "[data-cancel-annotation]", function(e) {
$("body").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments);
$("body").on("click", "[data-annotation-id]", App.LegislationAnnotatable.onClick);
$("body").on("click", "[data-cancel-annotation]", function(e) {
e.preventDefault();
$("#comments-box").html("");
$("#comments-box").hide();

View File

@@ -2,7 +2,7 @@
"use strict";
App.Map = {
initialize: function() {
$("*[data-map]").each(function() {
$("*[data-map]:visible").each(function() {
App.Map.initializeMap(this);
});
$(".js-toggle-map").on({

View File

@@ -9,10 +9,6 @@ var initialize_stats_modules = function() {
App.Stats.initialize();
};
$(function() {
"use strict";
$(document).ready(initialize_stats_modules);
$(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);

View File

@@ -17,7 +17,7 @@
};
},
initialize: function() {
$("table.sortable th").on("click", function() {
$(".table-sortable th").on("click", function() {
var rows, table;
table = $(this).parents("table").eq(0);
rows = table.find("tbody tr").toArray().sort(App.TableSortable.comparer($(this).index()));

View File

@@ -4,21 +4,17 @@
initialize: function() {
var $tag_input;
$tag_input = $("input.js-tag-list");
$("body .js-add-tag-link").each(function() {
if ($(this).data("initialized") !== "yes") {
$(this).on("click", function() {
var current_tags, name;
name = "\"" + ($(this).text()) + "\"";
current_tags = $tag_input.val().split(",").filter(Boolean);
if (current_tags.indexOf(name) >= 0) {
current_tags.splice(current_tags.indexOf(name), 1);
} else {
current_tags.push(name);
}
$tag_input.val(current_tags.join(","));
return false;
}).data("initialized", "yes");
$("body").on("click", ".js-add-tag-link", function() {
var current_tags, name;
name = "\"" + ($(this).text()) + "\"";
current_tags = $tag_input.val().split(",").filter(Boolean);
if (current_tags.indexOf(name) >= 0) {
current_tags.splice(current_tags.indexOf(name), 1);
} else {
current_tags.push(name);
}
$tag_input.val(current_tags.join(","));
return false;
});
}
};

View File

@@ -25,7 +25,7 @@
</div>
<h2><%= t("admin.stats.polls.all") %></h2>
<table id="polls" class="stack sortable">
<table id="polls" class="stack table-sortable">
<thead>
<tr>
<th><%= t("admin.stats.polls.table.poll_name") %></th>
@@ -52,7 +52,7 @@
<h3 id="<%= dom_id(poll) %>_questions">
<%= t("admin.stats.polls.poll_questions", poll: poll.name) %>
</h3>
<table class="stack sortable">
<table class="stack table-sortable">
<thead>
<tr>
<th><%= t("admin.stats.polls.table.question_name") %></th>

View File

@@ -30,6 +30,30 @@ describe "Admin settings" do
expect(page).to have_content "Value updated"
end
describe "Map settings initialization", :js do
before do
Setting["feature.map"] = true
end
scenario "When `Map settings` tab content is hidden map should not be initialized" do
admin = create(:administrator).user
login_as(admin)
visit admin_settings_path
expect(page).not_to have_css("#admin-map.leaflet-container", visible: false)
end
scenario "When `Map settings` tab content is shown map should be initialized" do
admin = create(:administrator).user
login_as(admin)
visit admin_settings_path
find("#map-tab").click
expect(page).to have_css("#admin-map.leaflet-container", visible: true)
end
end
describe "Update map" do
scenario "Should not be able when map feature deactivated" do
Setting["feature.map"] = false

View File

@@ -200,7 +200,7 @@ describe "Proposals" do
end
end
context "Show on mobile screens" do
describe "Show sticky support button on mobile screens", :js do
let!(:window_size) { Capybara.current_window.size }
before do
@@ -211,7 +211,7 @@ describe "Proposals" do
Capybara.current_window.resize_to(*window_size)
end
scenario "Show support button sticky at bottom", :js do
scenario "On a first visit" do
proposal = create(:proposal)
visit proposal_path(proposal)
@@ -220,6 +220,19 @@ describe "Proposals" do
expect(page).not_to have_css(".is-anchored")
end
end
scenario "After visiting another page" do
proposal = create(:proposal)
visit proposal_path(proposal)
click_link "Go back"
click_link proposal.title
within("#proposal_sticky") do
expect(page).to have_css(".is-stuck")
expect(page).not_to have_css(".is-anchored")
end
end
end
context "Embedded video" do