diff options
| author | Alban Peignier | 2017-12-28 09:39:21 +0100 |
|---|---|---|
| committer | GitHub | 2017-12-28 09:39:21 +0100 |
| commit | c1cce30d47e179743567abb78c85baec0615d444 (patch) | |
| tree | 5671e6f24fb95c366f16631d0e5f6145df5dc44f | |
| parent | fee41e6002c1a3c6273225befb7be2f06b6b63f9 (diff) | |
| parent | 823ecf0dbac50fb7696f19e657d91758ebda6f89 (diff) | |
| download | chouette-core-c1cce30d47e179743567abb78c85baec0615d444.tar.bz2 | |
Merge pull request #185 from af83/5426-refactor-sticky-actions
Refactor sticky actions. Refs #5426
| -rw-r--r-- | app/assets/javascripts/main_menu.coffee | 45 | ||||
| -rw-r--r-- | app/views/vehicle_journeys/index.html.slim | 2 |
2 files changed, 28 insertions, 19 deletions
diff --git a/app/assets/javascripts/main_menu.coffee b/app/assets/javascripts/main_menu.coffee index 1c39be736..e31ff6724 100644 --- a/app/assets/javascripts/main_menu.coffee +++ b/app/assets/javascripts/main_menu.coffee @@ -1,12 +1,11 @@ $ -> - link = [] + stickyActions = [] ptitleCont = "" $(document).on 'page:before-change', -> - link = [] + stickyActions = [] ptitleCont = "" - $el = $('#main_nav') # Opening/closing left-side menu $el.find('.openMenu').on 'click', (e) -> @@ -24,35 +23,45 @@ $ -> limit = 51 if $(window).scrollTop() >= limit - data = "" - if ($('.page-action .small').length > 0) - data = $('.page-action .small')[0].innerHTML + if stickyActions.length == 0 + if ($('.page-action .small').length > 0) + stickyActions.push + content: [ + $('.page-action .small'), + $('.page-action .small').first().next() + ] + originalParent: $('.page-action .small').parent() + + for action in $(".sticky-action") + stickyActions.push + class: "small", + content: [$(action)] + originalParent: $(action).parent() - if ($(".page-title").length > 0) + if $(".page-title").length > 0 ptitleCont = $(".page-title").html() - stickyContent = '<div class="sticky-content">' - stickyContent += '<div class="sticky-ptitle">' + ptitleCont + '</div>' - stickyContent += '<div class="sticky-paction"><div class="small">' + data + '</div></div>' - stickyContent += '</div>' + stickyContent = $('<div class="sticky-content"></div>') + stickyContent.append $("<div class='sticky-ptitle'>#{ptitleCont}</div>") + stickyContent.append $('<div class="sticky-paction"></div>') $('#main_nav').addClass 'sticky' if $('#menu_top').find('.sticky-content').length == 0 if ptitleCont.length > 0 $('#menu_top').children('.menu-content').after(stickyContent) - if link.length == 0 - link = $('.page-action .small').next() - - $('.sticky-paction .small').after(link) + for item in stickyActions + for child in item.content + child.appendTo $('.sticky-paction') else $('#main_nav').removeClass 'sticky' if $('#menu_top').find('.sticky-content').length > 0 - if !$('.page-action').find('.formSubmitr').length - $('.page-action .small').after(link) + for item in stickyActions + for child in item.content + child.appendTo item.originalParent $('.sticky-content').remove() - sticker(); + sticker() # Sticky behavior $(document).on 'scroll', sticker diff --git a/app/views/vehicle_journeys/index.html.slim b/app/views/vehicle_journeys/index.html.slim index 595646808..ebcac8197 100644 --- a/app/views/vehicle_journeys/index.html.slim +++ b/app/views/vehicle_journeys/index.html.slim @@ -4,7 +4,7 @@ - content_for :page_header_content do .row.mb-sm .col-lg-12.text-right - = link_to(t('routes.actions.opposite_route_timetable'), [@referential, @route.line, @route.opposite_route, :vehicle_journeys], class: 'btn btn-primary') + = link_to(t('routes.actions.opposite_route_timetable'), [@referential, @route.line, @route.opposite_route, :vehicle_journeys], class: 'btn btn-primary sticky-action') .page_content |
