From 77485057dc0169798a3fdee6f6b646a1b92bfb8c Mon Sep 17 00:00:00 2001
From: Zog
Date: Wed, 27 Dec 2017 15:19:54 +0100
Subject: Refs #5426; Refactor sticky actions
---
 app/assets/javascripts/main_menu.coffee    | 41 +++++++++++++++++++-----------
 app/views/vehicle_journeys/index.html.slim |  2 +-
 2 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/app/assets/javascripts/main_menu.coffee b/app/assets/javascripts/main_menu.coffee
index 1c39be736..947d8eac1 100644
--- a/app/assets/javascripts/main_menu.coffee
+++ b/app/assets/javascripts/main_menu.coffee
@@ -1,9 +1,9 @@
 $ ->
 
-  link = []
+  stickyActions = []
   ptitleCont = ""
   $(document).on 'page:before-change', ->
-    link = []
+    stickyActions = []
     ptitleCont = ""
 
 
@@ -24,33 +24,44 @@ $ ->
     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)
         ptitleCont = $(".page-title").html()
 
-      stickyContent = '
'
-      stickyContent += '
' + ptitleCont + '
'
-      stickyContent += '
'
-      stickyContent += '
' + ptitleCont + '
')
+      sticyActionsNode = $('')
+      stickyContent.append sticyActionsNode
       $('#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();
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
-- 
cgit v1.2.3
From 823ecf0dbac50fb7696f19e657d91758ebda6f89 Mon Sep 17 00:00:00 2001
From: Alban Peignier
Date: Wed, 27 Dec 2017 23:02:36 +0100
Subject: Small esthetical changes in main_menu.coffee. Refs #5426
---
 app/assets/javascripts/main_menu.coffee | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/app/assets/javascripts/main_menu.coffee b/app/assets/javascripts/main_menu.coffee
index 947d8eac1..e31ff6724 100644
--- a/app/assets/javascripts/main_menu.coffee
+++ b/app/assets/javascripts/main_menu.coffee
@@ -6,7 +6,6 @@ $ ->
     stickyActions = []
     ptitleCont = ""
 
-
   $el = $('#main_nav')
     # Opening/closing left-side menu
   $el.find('.openMenu').on 'click', (e) ->
@@ -39,13 +38,12 @@ $ ->
             content: [$(action)]
             originalParent: $(action).parent()
 
-      if ($(".page-title").length > 0)
+      if $(".page-title").length > 0
         ptitleCont = $(".page-title").html()
 
       stickyContent = $('')
-      stickyContent.append $('' + ptitleCont + '
')
-      sticyActionsNode = $('')
-      stickyContent.append sticyActionsNode
+      stickyContent.append $("#{ptitleCont}
")
+      stickyContent.append $('')
       $('#main_nav').addClass 'sticky'
 
       if $('#menu_top').find('.sticky-content').length == 0
@@ -64,6 +62,6 @@ $ ->
             child.appendTo item.originalParent
         $('.sticky-content').remove()
 
-  sticker();
+  sticker()
   # Sticky behavior
   $(document).on 'scroll', sticker
-- 
cgit v1.2.3