templates/feedback/_widget.html.twig line 1

Open in your IDE?
  1. <div id="feedback-widget" class="position-fixed start-50 translate-middle-x bottom-0 mb-3" style="z-index: 1050;">
  2.   <div class="d-flex align-items-center gap-1">
  3.     <button type="button" 
  4.             class="btn btn-feedback d-flex align-items-center gap-2 shadow-sm" 
  5.             data-bs-toggle="modal" 
  6.             data-bs-target="#feedbackModal"
  7.             id="feedback-open-btn">
  8.       <i class="fa-regular fa-message"></i>
  9.       <span>Feedback ?</span>
  10.     </button>
  11.     <button type="button" 
  12.             class="btn btn-feedback btn-sm shadow-sm" 
  13.             id="feedback-toggle-position"
  14.             title="Changer la position du bouton">
  15.       <i class="fa-solid fa-chevron-up" id="feedback-position-icon"></i>
  16.     </button>
  17.   </div>
  18. </div>
  19. <style>
  20.   .btn-feedback {
  21.     background-color: #e8f0fe;
  22.     border: 1px solid #c5d5fb;
  23.     color: #2e6be5;
  24.     font-weight: 600;
  25.     font-size: 0.875rem;
  26.     padding: 0.5rem 1rem;
  27.     border-radius: 0.5rem;
  28.     transition: all 0.2s ease;
  29.   }
  30.   
  31.   .btn-feedback:hover {
  32.     background-color: #d4e4fd;
  33.     border-color: #a8c4f9;
  34.     color: #1d4ed8;
  35.   }
  36.   
  37.   .btn-feedback:focus {
  38.     box-shadow: 0 0 0 0.25rem rgba(46, 107, 229, 0.25);
  39.   }
  40.   
  41.   .btn-feedback.btn-sm {
  42.     padding: 0.5rem 0.625rem;
  43.   }
  44.   
  45.   #feedback-widget.position-top {
  46.     top: 0 !important;
  47.     bottom: auto !important;
  48.     margin-top: 1rem !important;
  49.     margin-bottom: 0 !important;
  50.   }
  51. </style>
  52. <script>
  53. (function() {
  54.   'use strict';
  55.   
  56.   var widget = document.getElementById('feedback-widget');
  57.   var toggleBtn = document.getElementById('feedback-toggle-position');
  58.   var icon = document.getElementById('feedback-position-icon');
  59.   var STORAGE_KEY = 'feedbackWidgetPosition';
  60.   
  61.   function setPosition(position) {
  62.     if (position === 'top') {
  63.       widget.classList.remove('bottom-0', 'mb-3');
  64.       widget.classList.add('top-0', 'mt-3', 'position-top');
  65.       icon.classList.remove('fa-chevron-up');
  66.       icon.classList.add('fa-chevron-down');
  67.     } else {
  68.       widget.classList.remove('top-0', 'mt-3', 'position-top');
  69.       widget.classList.add('bottom-0', 'mb-3');
  70.       icon.classList.remove('fa-chevron-down');
  71.       icon.classList.add('fa-chevron-up');
  72.     }
  73.     try {
  74.       localStorage.setItem(STORAGE_KEY, position);
  75.     } catch (e) {
  76.       // localStorage non disponible
  77.     }
  78.   }
  79.   
  80.   function getPosition() {
  81.     try {
  82.       return localStorage.getItem(STORAGE_KEY) || 'bottom';
  83.     } catch (e) {
  84.       return 'bottom';
  85.     }
  86.   }
  87.   
  88.   // Initialisation
  89.   setPosition(getPosition());
  90.   
  91.   // Gestion du clic sur le bouton de repositionnement
  92.   toggleBtn.addEventListener('click', function(e) {
  93.     e.stopPropagation();
  94.     var isBottom = widget.classList.contains('bottom-0');
  95.     setPosition(isBottom ? 'top' : 'bottom');
  96.   });
  97.   
  98.   // Masquer le widget quand le modal est ouvert
  99.   var feedbackModal = document.getElementById('feedbackModal');
  100.   if (feedbackModal) {
  101.     feedbackModal.addEventListener('show.bs.modal', function() {
  102.       widget.style.display = 'none';
  103.     });
  104.     feedbackModal.addEventListener('hidden.bs.modal', function() {
  105.       widget.style.display = 'block';
  106.     });
  107.   }
  108. })();
  109. </script>