|
157 | 157 | closeviewport.classList.remove('sqlbot-assistant-viewportnone') |
158 | 158 | } |
159 | 159 | } |
160 | | - const drag = (e) => { |
| 160 | + if (data.float_icon_drag) { |
| 161 | + chat_button.setAttribute('draggable', 'true') |
| 162 | + |
| 163 | + let startX = 0 |
| 164 | + let startY = 0 |
| 165 | + const img = new Image() |
| 166 | + img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=' |
| 167 | + chat_button.addEventListener('dragstart', (e) => { |
| 168 | + startX = e.clientX - chat_button.offsetLeft |
| 169 | + startY = e.clientY - chat_button.offsetTop |
| 170 | + e.dataTransfer.setDragImage(img, 0, 0) |
| 171 | + }) |
| 172 | + |
| 173 | + chat_button.addEventListener('drag', (e) => { |
| 174 | + if (e.clientX && e.clientY) { |
| 175 | + const left = e.clientX - startX |
| 176 | + const top = e.clientY - startY |
| 177 | + |
| 178 | + const maxX = window.innerWidth - chat_button.offsetWidth |
| 179 | + const maxY = window.innerHeight - chat_button.offsetHeight |
| 180 | + |
| 181 | + chat_button.style.left = Math.min(Math.max(0, left), maxX) + 'px' |
| 182 | + chat_button.style.top = Math.min(Math.max(0, top), maxY) + 'px' |
| 183 | + } |
| 184 | + }) |
| 185 | + |
| 186 | + let touchStartX = 0 |
| 187 | + let touchStartY = 0 |
| 188 | + |
| 189 | + chat_button.addEventListener('touchstart', (e) => { |
| 190 | + touchStartX = e.touches[0].clientX - chat_button.offsetLeft |
| 191 | + touchStartY = e.touches[0].clientY - chat_button.offsetTop |
| 192 | + e.preventDefault() |
| 193 | + }) |
| 194 | + |
| 195 | + chat_button.addEventListener('touchmove', (e) => { |
| 196 | + const left = e.touches[0].clientX - touchStartX |
| 197 | + const top = e.touches[0].clientY - touchStartY |
| 198 | + |
| 199 | + const maxX = window.innerWidth - chat_button.offsetWidth |
| 200 | + const maxY = window.innerHeight - chat_button.offsetHeight |
| 201 | + |
| 202 | + chat_button.style.left = Math.min(Math.max(0, left), maxX) + 'px' |
| 203 | + chat_button.style.top = Math.min(Math.max(0, top), maxY) + 'px' |
| 204 | + |
| 205 | + e.preventDefault() |
| 206 | + }) |
| 207 | + } |
| 208 | + /* const drag = (e) => { |
161 | 209 | if (['touchmove', 'touchstart'].includes(e.type)) { |
162 | 210 | chat_button.style.top = e.touches[0].clientY - chat_button_img.clientHeight / 2 + 'px' |
163 | 211 | chat_button.style.left = e.touches[0].clientX - chat_button_img.clientHeight / 2 + 'px' |
|
169 | 217 | chat_button.style.height = chat_button_img.clientHeight + 'px' |
170 | 218 | } |
171 | 219 | if (data.float_icon_drag) { |
| 220 | + chat_button.setAttribute('draggable', 'true') |
172 | 221 | chat_button.addEventListener('drag', drag) |
173 | 222 | chat_button.addEventListener('dragover', (e) => { |
174 | 223 | e.preventDefault() |
175 | 224 | }) |
176 | 225 | chat_button.addEventListener('dragend', drag) |
177 | 226 | chat_button.addEventListener('touchstart', drag) |
178 | 227 | chat_button.addEventListener('touchmove', drag) |
179 | | - } |
| 228 | + } */ |
180 | 229 | viewport.onclick = viewport_func |
181 | 230 | closeviewport.onclick = viewport_func |
182 | 231 | } |
|
0 commit comments