k96beni commited on
Commit
bc1676d
·
verified ·
1 Parent(s): 91012ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +167 -11
app.py CHANGED
@@ -701,7 +701,7 @@ footer {display: none !important;}
701
  overflow: visible !important;
702
  }
703
 
704
- /* Chatbot med fast höjd för scroll */
705
  #chatbot_conversation {
706
  display: block !important;
707
  height: 300px !important; /* Fast höjd istället för flex */
@@ -716,6 +716,44 @@ footer {display: none !important;}
716
  background-color: #ffffff !important;
717
  -webkit-overflow-scrolling: touch !important;
718
  -ms-overflow-style: -ms-autohiding-scrollbar !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
719
  }
720
 
721
  /* Input och knappar */
@@ -750,19 +788,40 @@ footer {display: none !important;}
750
  outline: none !important;
751
  }
752
 
753
- /* Knappar med block layout */
754
  .gr-button {
755
  display: block !important;
756
  width: 100% !important;
757
- padding: 10px 12px !important;
758
- margin: 4px 0 !important;
759
- font-size: 14px !important;
760
- min-height: 40px !important;
761
- border-radius: 4px !important;
762
  box-sizing: border-box !important;
763
  white-space: nowrap !important;
764
  overflow: hidden !important;
765
  text-overflow: ellipsis !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
766
  }
767
 
768
  /* Knapp-kolumner */
@@ -858,13 +917,104 @@ with gr.Blocks(
858
  title="ChargeNode Kundtjänst",
859
  head='<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">',
860
  js="""
861
- function initScrollFix() {
862
  // Framtvinga scrollning på mobil i iframe
863
  if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
864
  document.body.style.overflow = 'auto';
865
  document.documentElement.style.overflow = 'auto';
866
  document.body.style.webkitOverflowScrolling = 'touch';
867
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
868
  // Skicka meddelande till parent om scrollning
869
  window.addEventListener('scroll', function() {
870
  if (window.parent !== window) {
@@ -882,15 +1032,21 @@ with gr.Blocks(
882
  document.body.scrollTop = 0;
883
  }
884
  });
 
 
885
  }
886
  }
887
 
888
- // Kör när sidan laddas
889
  if (document.readyState === 'loading') {
890
- document.addEventListener('DOMContentLoaded', initScrollFix);
891
  } else {
892
- initScrollFix();
893
  }
 
 
 
 
894
  """
895
  ) as app:
896
  gr.Markdown("Ställ din fråga om ChargeNodes produkter och tjänster nedan. Om du inte gillar botten, så ring oss gärna på 010 – 205 10 55")
 
701
  overflow: visible !important;
702
  }
703
 
704
+ /* Chatbot med fast höjd för scroll och mindre text */
705
  #chatbot_conversation {
706
  display: block !important;
707
  height: 300px !important; /* Fast höjd istället för flex */
 
716
  background-color: #ffffff !important;
717
  -webkit-overflow-scrolling: touch !important;
718
  -ms-overflow-style: -ms-autohiding-scrollbar !important;
719
+ font-size: 13px !important; /* Mindre text för mer innehåll */
720
+ line-height: 1.3 !important; /* Kompaktare rader */
721
+ }
722
+
723
+ /* Specifik styling för meddelanden i chatbot */
724
+ #chatbot_conversation .message,
725
+ #chatbot_conversation .bot,
726
+ #chatbot_conversation .user,
727
+ #chatbot_conversation div,
728
+ #chatbot_conversation p {
729
+ font-size: 13px !important;
730
+ line-height: 1.3 !important;
731
+ margin: 2px 0 !important;
732
+ padding: 3px !important;
733
+ }
734
+
735
+ /* Användarmeddelanden */
736
+ #chatbot_conversation .user {
737
+ background-color: #e3f2fd !important;
738
+ border-radius: 8px 8px 2px 8px !important;
739
+ margin: 2px 0 2px 20px !important;
740
+ padding: 6px 8px !important;
741
+ font-size: 13px !important;
742
+ }
743
+
744
+ /* Bot-meddelanden */
745
+ #chatbot_conversation .bot {
746
+ background-color: #f5f5f5 !important;
747
+ border-radius: 8px 8px 8px 2px !important;
748
+ margin: 2px 20px 2px 0 !important;
749
+ padding: 6px 8px !important;
750
+ font-size: 13px !important;
751
+ }
752
+
753
+ /* Alla text-element i chatbot */
754
+ #chatbot_conversation * {
755
+ font-size: 13px !important;
756
+ line-height: 1.3 !important;
757
  }
758
 
759
  /* Input och knappar */
 
788
  outline: none !important;
789
  }
790
 
791
+ /* Knappar med block layout och bättre touch */
792
  .gr-button {
793
  display: block !important;
794
  width: 100% !important;
795
+ padding: 12px 16px !important; /* Större padding för touch */
796
+ margin: 6px 0 !important; /* Mer utrymme mellan knappar */
797
+ font-size: 16px !important; /* Större text för läsbarhet */
798
+ min-height: 48px !important; /* Minst 48px för touch targets */
799
+ border-radius: 6px !important;
800
  box-sizing: border-box !important;
801
  white-space: nowrap !important;
802
  overflow: hidden !important;
803
  text-overflow: ellipsis !important;
804
+ cursor: pointer !important;
805
+ user-select: none !important; /* Förhindra textmarkering */
806
+ -webkit-user-select: none !important;
807
+ -webkit-tap-highlight-color: rgba(0,0,0,0.1) !important; /* Touch feedback */
808
+ touch-action: manipulation !important; /* Förbättra touch responsiveness */
809
+ }
810
+
811
+ /* Active state för knappar */
812
+ .gr-button:active {
813
+ background-color: #1a7068 !important;
814
+ transform: scale(0.98) !important;
815
+ }
816
+
817
+ /* Support button specifik styling */
818
+ .support-btn {
819
+ background-color: #000000 !important;
820
+ color: #ffffff !important;
821
+ }
822
+
823
+ .support-btn:active {
824
+ background-color: #333333 !important;
825
  }
826
 
827
  /* Knapp-kolumner */
 
917
  title="ChargeNode Kundtjänst",
918
  head='<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">',
919
  js="""
920
+ function initMobileEventFix() {
921
  // Framtvinga scrollning på mobil i iframe
922
  if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
923
  document.body.style.overflow = 'auto';
924
  document.documentElement.style.overflow = 'auto';
925
  document.body.style.webkitOverflowScrolling = 'touch';
926
 
927
+ // Fix för touch events på knappar
928
+ const buttons = document.querySelectorAll('.gr-button, button');
929
+ buttons.forEach(button => {
930
+ // Lägg till touch events för bättre responsiveness
931
+ button.addEventListener('touchstart', function(e) {
932
+ this.style.backgroundColor = '#1a7068';
933
+ }, {passive: true});
934
+
935
+ button.addEventListener('touchend', function(e) {
936
+ this.style.backgroundColor = '';
937
+ // Forcera click event
938
+ setTimeout(() => {
939
+ this.click();
940
+ }, 50);
941
+ }, {passive: true});
942
+
943
+ // Förhindra dubbel-hantering
944
+ button.addEventListener('click', function(e) {
945
+ if (e.isTrusted === false) return; // Skippa syntetiska events
946
+ e.stopPropagation();
947
+ }, true);
948
+ });
949
+
950
+ // Fix för Enter-key på mobil keyboard
951
+ const textareas = document.querySelectorAll('textarea');
952
+ textareas.forEach(textarea => {
953
+ textarea.addEventListener('keydown', function(e) {
954
+ if (e.key === 'Enter' && !e.shiftKey) {
955
+ e.preventDefault();
956
+ // Hitta submit-knappen och trigga den
957
+ const submitBtn = document.querySelector('button[type="submit"], .gr-button');
958
+ if (submitBtn) {
959
+ submitBtn.click();
960
+ }
961
+ }
962
+ });
963
+
964
+ // Lägg till input event för bättre reaktivitet
965
+ textarea.addEventListener('input', function(e) {
966
+ // Trigga Gradio's interna events
967
+ const event = new Event('input', { bubbles: true });
968
+ this.dispatchEvent(event);
969
+ });
970
+ });
971
+
972
+ // Observer för dynamiskt tillagda element
973
+ const observer = new MutationObserver(function(mutations) {
974
+ mutations.forEach(function(mutation) {
975
+ if (mutation.type === 'childList') {
976
+ mutation.addedNodes.forEach(function(node) {
977
+ if (node.nodeType === 1) { // Element node
978
+ // Lägg till event listeners på nya knappar
979
+ const newButtons = node.querySelectorAll('.gr-button, button');
980
+ newButtons.forEach(button => {
981
+ button.addEventListener('touchstart', function(e) {
982
+ this.style.backgroundColor = '#1a7068';
983
+ }, {passive: true});
984
+
985
+ button.addEventListener('touchend', function(e) {
986
+ this.style.backgroundColor = '';
987
+ setTimeout(() => {
988
+ this.click();
989
+ }, 50);
990
+ }, {passive: true});
991
+ });
992
+
993
+ // Lägg till event listeners på nya textareas
994
+ const newTextareas = node.querySelectorAll('textarea');
995
+ newTextareas.forEach(textarea => {
996
+ textarea.addEventListener('keydown', function(e) {
997
+ if (e.key === 'Enter' && !e.shiftKey) {
998
+ e.preventDefault();
999
+ const submitBtn = document.querySelector('button[type="submit"], .gr-button');
1000
+ if (submitBtn) {
1001
+ submitBtn.click();
1002
+ }
1003
+ }
1004
+ });
1005
+ });
1006
+ }
1007
+ });
1008
+ }
1009
+ });
1010
+ });
1011
+
1012
+ // Starta observer
1013
+ observer.observe(document.body, {
1014
+ childList: true,
1015
+ subtree: true
1016
+ });
1017
+
1018
  // Skicka meddelande till parent om scrollning
1019
  window.addEventListener('scroll', function() {
1020
  if (window.parent !== window) {
 
1032
  document.body.scrollTop = 0;
1033
  }
1034
  });
1035
+
1036
+ console.log('Mobile event fixes initialized');
1037
  }
1038
  }
1039
 
1040
+ // Kör när sidan laddas och när DOM uppdateras
1041
  if (document.readyState === 'loading') {
1042
+ document.addEventListener('DOMContentLoaded', initMobileEventFix);
1043
  } else {
1044
+ initMobileEventFix();
1045
  }
1046
+
1047
+ // Kör även efter en kort delay för att fånga Gradio-element
1048
+ setTimeout(initMobileEventFix, 1000);
1049
+ setTimeout(initMobileEventFix, 3000);
1050
  """
1051
  ) as app:
1052
  gr.Markdown("Ställ din fråga om ChargeNodes produkter och tjänster nedan. Om du inte gillar botten, så ring oss gärna på 010 – 205 10 55")