Commit 7029e630 authored by Michael Le's avatar Michael Le Committed by David O'Regan

Replace dropdown with collapse; remove unused code

parent 16e7f7a2
import $ from 'jquery'; import $ from 'jquery';
import { hide } from '~/tooltips';
export const addTooltipToEl = (el) => { export const addTooltipToEl = (el) => {
const textEl = el.querySelector('.js-breadcrumb-item-text'); const textEl = el.querySelector('.js-breadcrumb-item-text');
...@@ -19,20 +18,11 @@ export default () => { ...@@ -19,20 +18,11 @@ export default () => {
.filter((el) => !el.classList.contains('dropdown')) .filter((el) => !el.classList.contains('dropdown'))
.map((el) => el.querySelector('a')) .map((el) => el.querySelector('a'))
.filter((el) => el); .filter((el) => el);
const $expander = $('.js-breadcrumbs-collapsed-expander'); const $expanderBtn = $('.js-breadcrumbs-collapsed-expander');
const $expanderInline = $('.js-breadcrumbs-collapsed-expander.inline-list');
topLevelLinks.forEach((el) => addTooltipToEl(el)); topLevelLinks.forEach((el) => addTooltipToEl(el));
$expander.closest('.dropdown').on('show.bs.dropdown hide.bs.dropdown', (e) => { $expanderBtn.on('click', () => {
const $el = $('.js-breadcrumbs-collapsed-expander', e.currentTarget);
$el.toggleClass('open');
hide($el);
});
$expanderInline.on('click', () => {
const detailItems = $('.breadcrumbs-detail-item'); const detailItems = $('.breadcrumbs-detail-item');
const hiddenClass = 'gl-display-none!'; const hiddenClass = 'gl-display-none!';
......
...@@ -27,10 +27,10 @@ module BreadcrumbsHelper ...@@ -27,10 +27,10 @@ module BreadcrumbsHelper
end end
end end
def add_to_breadcrumb_dropdown(link, location: :before) def add_to_breadcrumb_collapsed_links(link, location: :before)
@breadcrumb_dropdown_links ||= {} @breadcrumb_collapsed_links ||= {}
@breadcrumb_dropdown_links[location] ||= [] @breadcrumb_collapsed_links[location] ||= []
@breadcrumb_dropdown_links[location] << link @breadcrumb_collapsed_links[location] << link
end end
def push_to_schema_breadcrumb(text, link) def push_to_schema_breadcrumb(text, link)
......
...@@ -39,7 +39,7 @@ module GroupsHelper ...@@ -39,7 +39,7 @@ module GroupsHelper
sorted_ancestors(group).with_route.reverse_each.with_index do |parent, index| sorted_ancestors(group).with_route.reverse_each.with_index do |parent, index|
if index > 0 if index > 0
add_to_breadcrumb_dropdown(group_title_link(parent, hidable: false, show_avatar: false, for_dropdown: false), location: :before) add_to_breadcrumb_collapsed_links(group_title_link(parent), location: :before)
else else
full_title << breadcrumb_list_item(group_title_link(parent, hidable: false)) full_title << breadcrumb_list_item(group_title_link(parent, hidable: false))
end end
......
...@@ -9,7 +9,7 @@ module WikiHelper ...@@ -9,7 +9,7 @@ module WikiHelper
if page.persisted? if page.persisted?
titles << page.human_title titles << page.human_title
breadcrumb_title(page.human_title) breadcrumb_title(page.human_title)
wiki_breadcrumb_dropdown_links(page.slug) wiki_breadcrumb_collapsed_links(page.slug)
end end
titles << action if action titles << action if action
...@@ -39,14 +39,14 @@ module WikiHelper ...@@ -39,14 +39,14 @@ module WikiHelper
.join(' / ') .join(' / ')
end end
def wiki_breadcrumb_dropdown_links(page_slug) def wiki_breadcrumb_collapsed_links(page_slug)
page_slug_split = page_slug.split('/') page_slug_split = page_slug.split('/')
page_slug_split.pop(1) page_slug_split.pop(1)
current_slug = "" current_slug = ""
page_slug_split page_slug_split
.map do |dir_or_page| .map do |dir_or_page|
current_slug = "#{current_slug}#{dir_or_page}/" current_slug = "#{current_slug}#{dir_or_page}/"
add_to_breadcrumb_dropdown link_to(WikiPage.unhyphenize(dir_or_page).capitalize, wiki_page_path(@wiki, current_slug)), location: :after add_to_breadcrumb_collapsed_links link_to(WikiPage.unhyphenize(dir_or_page).capitalize, wiki_page_path(@wiki, current_slug)), location: :after
end end
end end
......
- dropdown_location = local_assigns.fetch(:location, nil)
- button_tooltip = local_assigns.fetch(:title, _("Show parent pages"))
- if defined?(@breadcrumb_dropdown_links) && @breadcrumb_dropdown_links.key?(dropdown_location)
%li.dropdown
%button.text-expander.has-tooltip.js-breadcrumbs-collapsed-expander{ type: "button", data: { toggle: "dropdown", container: "body" }, "aria-label": button_tooltip, title: button_tooltip }
= sprite_icon("ellipsis_h", size: 12)
= sprite_icon("angle-right", size: 8, css_class: "breadcrumbs-list-angle")
.dropdown-menu
%ul
- @breadcrumb_dropdown_links[dropdown_location].each_with_index do |link, index|
%li{ style: "text-indent: #{[index * 16, 60].min}px;" }= link
- dropdown_location = local_assigns.fetch(:location, nil) - dropdown_location = local_assigns.fetch(:location, nil)
- button_tooltip = local_assigns.fetch(:title, _("Show all breadcrumbs")) - button_tooltip = local_assigns.fetch(:title, _("Show all breadcrumbs"))
- if defined?(@breadcrumb_dropdown_links) && @breadcrumb_dropdown_links.key?(dropdown_location) - if defined?(@breadcrumb_collapsed_links) && @breadcrumb_collapsed_links.key?(dropdown_location)
%li.expander %li.expander
%button.text-expander.has-tooltip.js-breadcrumbs-collapsed-expander.inline-list{ type: "button", data: { container: "body" }, "aria-label": button_tooltip, title: button_tooltip } %button.text-expander.has-tooltip.js-breadcrumbs-collapsed-expander{ type: "button", data: { container: "body" }, "aria-label": button_tooltip, title: button_tooltip }
= sprite_icon("ellipsis_h", size: 12) = sprite_icon("ellipsis_h", size: 12)
= sprite_icon("angle-right", size: 8, css_class: "breadcrumbs-list-angle") = sprite_icon("angle-right", size: 8, css_class: "breadcrumbs-list-angle")
- @breadcrumb_dropdown_links[dropdown_location].each_with_index do |link, index| - @breadcrumb_collapsed_links[dropdown_location].each_with_index do |link, index|
%li{ :class => "gl-display-none! breadcrumbs-detail-item" } %li{ :class => "gl-display-none! breadcrumbs-detail-item" }
= link = link
= sprite_icon("angle-right", size: 8, css_class: "breadcrumbs-list-angle") = sprite_icon("angle-right", size: 8, css_class: "breadcrumbs-list-angle")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment