diff --git a/app/assets/javascripts/sdg/related_list_selector.js b/app/assets/javascripts/sdg/related_list_selector.js index 2abaff9f9..3e2817e86 100644 --- a/app/assets/javascripts/sdg/related_list_selector.js +++ b/app/assets/javascripts/sdg/related_list_selector.js @@ -8,13 +8,45 @@ amsify_suggestags._settings({ suggestions: $(".sdg-related-list-selector .input").data("suggestions-list"), whiteList: true, + afterRemove: function(value) { + var keep_goal = $(amsify_suggestags.selector).val().split(",").some(function(selected_value) { + return App.SDGRelatedListSelector.goal_code(value) === App.SDGRelatedListSelector.goal_code(selected_value); + }); + App.SDGRelatedListSelector.goal_element(value).attr("aria-checked", keep_goal); + }, + afterAdd: function(value) { + App.SDGRelatedListSelector.goal_element(value).attr("aria-checked", true); + }, keepLastOnHoverTag: false, checkSimilar: false }); amsify_suggestags.classes.focus = ".sdg-related-list-focus"; amsify_suggestags.classes.sTagsInput = ".sdg-related-list-selector-input"; amsify_suggestags._init(); + App.SDGRelatedListSelector.manage_icons(amsify_suggestags); } + }, + manage_icons: function(amsify_suggestags) { + $("[role='checkbox']").on("click keydown", function(event) { + var goal_id = this.dataset.code; + + if (event.type === "click" || (event.type === "keydown" && [13, 32].indexOf(event.keyCode) >= 0)) { + if (amsify_suggestags.isPresent(goal_id)) { + amsify_suggestags.removeTag(goal_id, false); + } else { + amsify_suggestags.addTag(goal_id, false); + } + + event.preventDefault(); + event.stopPropagation(); + } + }); + }, + goal_element: function(value) { + return $("li[data-code=" + App.SDGRelatedListSelector.goal_code(value) + "]"); + }, + goal_code: function(value) { + return value.toString().split(".")[0]; } }; }).call(this); diff --git a/app/assets/stylesheets/_consul_settings.scss b/app/assets/stylesheets/_consul_settings.scss index 85b754aae..d46b5c516 100644 --- a/app/assets/stylesheets/_consul_settings.scss +++ b/app/assets/stylesheets/_consul_settings.scss @@ -68,6 +68,8 @@ $color-alert: #a94442; $pdf-primary: #0300ff; $pdf-secondary: #ff9e00; +$outline-focus: 3px solid #ffbf47; + // 2. Foundation settings overrides // --------------------------------- diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 3fe00f6be..ccba5e002 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -77,7 +77,7 @@ a { &:focus { color: $link-hover; - outline: 3px solid #ffbf47; + outline: $outline-focus; } } @@ -1075,7 +1075,7 @@ footer { width: auto; &:focus { - outline: 3px solid #ffbf47; + outline: $outline-focus; } } } diff --git a/app/assets/stylesheets/sdg/related_list_selector.scss b/app/assets/stylesheets/sdg/related_list_selector.scss index 6f302919e..7d48a155f 100644 --- a/app/assets/stylesheets/sdg/related_list_selector.scss +++ b/app/assets/stylesheets/sdg/related_list_selector.scss @@ -9,4 +9,26 @@ } } } + + > ul { + list-style: none; + margin-bottom: 0; + margin-left: 0; + + li { + display: inline-block; + + &[aria-checked=true] img { + opacity: 0.15; + } + + &:focus { + outline: $outline-focus; + } + } + } + + .input-section { + margin-top: $line-height / 2; + } } diff --git a/app/components/sdg/related_list_selector_component.html.erb b/app/components/sdg/related_list_selector_component.html.erb index a2035f9ec..48c8d33df 100644 --- a/app/components/sdg/related_list_selector_component.html.erb +++ b/app/components/sdg/related_list_selector_component.html.erb @@ -1,4 +1,12 @@