minko186 commited on
Commit
7c04c25
·
1 Parent(s): eeb907d

update popups to be more centered

Browse files
Files changed (1) hide show
  1. app.py +39 -43
app.py CHANGED
@@ -52,11 +52,11 @@ def generate_cited_html(cited_text, citations: dict):
52
  cited_text = cited_text.replace("\n", "<br>")
53
  html_code = """
54
  <style>
55
- .reference-container {
56
  position: relative;
57
  display: inline-block;
58
- }
59
- .reference-btn {
60
  display: inline-block;
61
  width: 25px;
62
  height: 25px;
@@ -69,12 +69,12 @@ def generate_cited_html(cited_text, citations: dict):
69
  font-weight: bold;
70
  margin-right: 5px;
71
  transition: background-color 0.3s ease, transform 0.3s ease;
72
- }
73
- .reference-btn:hover {
74
  background-color: #1e90ff; /* Lighter blue on hover */
75
  transform: scale(1.1); /* Slightly enlarge on hover */
76
- }
77
- .reference-popup {
78
  display: none;
79
  position: absolute;
80
  z-index: 1;
@@ -85,21 +85,26 @@ def generate_cited_html(cited_text, citations: dict):
85
  padding: 10px;
86
  border-radius: 4px;
87
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
88
- width: calc(min(90vw, 500px));
89
  max-height: calc(min(80vh, 300px));
90
  overflow-y: auto;
91
  transform: translateX(0); /* Default position */
92
- }
93
- .reference-container .reference-popup {
94
  left: 50%;
95
  transform: translateX(-50%); /* Center align popup horizontally by default */
96
  }
97
- .reference-container[data-align="right"] .reference-popup {
98
  left: auto;
99
  right: 0;
100
  transform: translateX(-10%); /* Pull the popup slightly left when near right edge */
101
  }
102
- .reference-popup .close-btn {
 
 
 
 
 
103
  float: right;
104
  cursor: pointer;
105
  font-weight: bold;
@@ -113,61 +118,52 @@ def generate_cited_html(cited_text, citations: dict):
113
  background-color: #ff4c4c;
114
  border-radius: 2px;
115
  transition: transform 0.3s ease, background-color 0.3s ease;
116
- }
117
- .reference-popup .close-btn:hover {
118
  transform: scale(1.2);
119
  background-color: #ff3333;
120
- }
121
- input[type="radio"] {
122
  position: absolute;
123
  opacity: 0;
124
  pointer-events: none;
125
- }
126
- input[type="radio"]:checked + .reference-popup {
127
  display: block;
128
- }
129
- @media (prefers-color-scheme: dark) {
130
  .reference-btn {
131
- background-color: #1e90ff;
132
  }
133
  .reference-popup {
134
- background-color: #2c2c2c;
135
- border-color: #444;
136
- color: #f1f1f1;
137
  }
138
  .reference-popup .close-btn {
139
- background-color: #ff4c4c;
140
  }
141
  .reference-popup .close-btn:hover {
142
- background-color: #ff3333;
143
  }
144
- }
145
  </style>
146
  <script>
147
  document.addEventListener('click', (event) => {
148
  const containers = document.querySelectorAll('.reference-container');
149
  containers.forEach(container => {
150
- const rect = container.getBoundingClientRect();
151
- if (rect.right > window.innerWidth - 50) {
152
  container.setAttribute('data-align', 'right');
153
- } else if (rect.left < 50) {
154
  container.setAttribute('data-align', 'left');
155
- } else {
156
  container.removeAttribute('data-align');
157
- }
158
- });
159
- });
160
-
161
- function closeReferencePanes(event) {
162
- if (!event.target.closest('.reference-container')) {
163
- const checkboxes = document.querySelectorAll('input[type="radio"]');
164
- checkboxes.forEach(checkbox => checkbox.checked = false);
165
  }
166
- }
167
-
168
- document.addEventListener('click', closeReferencePanes);
169
  </script>
170
- <div style="height: 600px; overflow-y: auto;">
171
  """
172
 
173
  # Function to replace each citation with a reference button
 
52
  cited_text = cited_text.replace("\n", "<br>")
53
  html_code = """
54
  <style>
55
+ .reference-container {
56
  position: relative;
57
  display: inline-block;
58
+ }
59
+ .reference-btn {
60
  display: inline-block;
61
  width: 25px;
62
  height: 25px;
 
69
  font-weight: bold;
70
  margin-right: 5px;
71
  transition: background-color 0.3s ease, transform 0.3s ease;
72
+ }
73
+ .reference-btn:hover {
74
  background-color: #1e90ff; /* Lighter blue on hover */
75
  transform: scale(1.1); /* Slightly enlarge on hover */
76
+ }
77
+ .reference-popup {
78
  display: none;
79
  position: absolute;
80
  z-index: 1;
 
85
  padding: 10px;
86
  border-radius: 4px;
87
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
88
+ width: calc(min(90vw, 400px));
89
  max-height: calc(min(80vh, 300px));
90
  overflow-y: auto;
91
  transform: translateX(0); /* Default position */
92
+ }
93
+ .reference-container .reference-popup {
94
  left: 50%;
95
  transform: translateX(-50%); /* Center align popup horizontally by default */
96
  }
97
+ .reference-container[data-align="right"] .reference-popup {
98
  left: auto;
99
  right: 0;
100
  transform: translateX(-10%); /* Pull the popup slightly left when near right edge */
101
  }
102
+ .reference-container[data-align="left"] .reference-popup {
103
+ left: 0;
104
+ right: auto;
105
+ transform: translateX(20%);
106
+ }
107
+ .reference-popup .close-btn {
108
  float: right;
109
  cursor: pointer;
110
  font-weight: bold;
 
118
  background-color: #ff4c4c;
119
  border-radius: 2px;
120
  transition: transform 0.3s ease, background-color 0.3s ease;
121
+ }
122
+ .reference-popup .close-btn:hover {
123
  transform: scale(1.2);
124
  background-color: #ff3333;
125
+ }
126
+ input[type="radio"] {
127
  position: absolute;
128
  opacity: 0;
129
  pointer-events: none;
130
+ }
131
+ input[type="radio"]:checked + .reference-popup {
132
  display: block;
133
+ }
134
+ @media (prefers-color-scheme: dark) {
135
  .reference-btn {
136
+ background-color: #1e90ff;
137
  }
138
  .reference-popup {
139
+ background-color: #2c2c2c;
140
+ border-color: #444;
141
+ color: #f1f1f1;
142
  }
143
  .reference-popup .close-btn {
144
+ background-color: #ff4c4c;
145
  }
146
  .reference-popup .close-btn:hover {
147
+ background-color: #ff3333;
148
  }
149
+ }
150
  </style>
151
  <script>
152
  document.addEventListener('click', (event) => {
153
  const containers = document.querySelectorAll('.reference-container');
154
  containers.forEach(container => {
155
+ const rect = container.getBoundingClientRect();
156
+ if (rect.right > window.innerWidth - 50) {
157
  container.setAttribute('data-align', 'right');
158
+ } else if (rect.left < 50) {
159
  container.setAttribute('data-align', 'left');
160
+ } else {
161
  container.removeAttribute('data-align');
 
 
 
 
 
 
 
 
162
  }
163
+ });
164
+ });
 
165
  </script>
166
+ <div style="height: 600px; overflow-y: auto; overflow-x: auto;">
167
  """
168
 
169
  # Function to replace each citation with a reference button