Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

viewer.js 2.5 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  1. window.main_viewer_height = 512;
  2. function refresh_grid() {
  3. let gridContainer = document.querySelector('#final_gallery .grid-container');
  4. let final_gallery = document.getElementById('final_gallery');
  5. if (gridContainer) if (final_gallery) {
  6. let rect = final_gallery.getBoundingClientRect();
  7. let cols = Math.ceil((rect.width - 16.0) / rect.height);
  8. if (cols < 2) cols = 2;
  9. gridContainer.style.setProperty('--grid-cols', cols);
  10. }
  11. }
  12. function refresh_grid_delayed() {
  13. refresh_grid();
  14. setTimeout(refresh_grid, 100);
  15. setTimeout(refresh_grid, 500);
  16. setTimeout(refresh_grid, 1000);
  17. }
  18. function resized() {
  19. let windowHeight = window.innerHeight - 260;
  20. let elements = document.getElementsByClassName('main_view');
  21. if (windowHeight > 745) windowHeight = 745;
  22. for (let i = 0; i < elements.length; i++) {
  23. elements[i].style.height = windowHeight + 'px';
  24. }
  25. window.main_viewer_height = windowHeight;
  26. refresh_grid();
  27. }
  28. function viewer_to_top(delay = 100) {
  29. setTimeout(() => window.scrollTo({top: 0, behavior: 'smooth'}), delay);
  30. }
  31. function viewer_to_bottom(delay = 100) {
  32. let element = document.getElementById('positive_prompt');
  33. let yPos = window.main_viewer_height;
  34. if (element) {
  35. yPos = element.getBoundingClientRect().top + window.scrollY;
  36. }
  37. setTimeout(() => window.scrollTo({top: yPos - 8, behavior: 'smooth'}), delay);
  38. }
  39. window.addEventListener('resize', (e) => {
  40. resized();
  41. });
  42. onUiLoaded(async () => {
  43. resized();
  44. });
  45. function on_style_selection_blur() {
  46. let target = document.querySelector("#gradio_receiver_style_selections textarea");
  47. target.value = "on_style_selection_blur " + Math.random();
  48. let e = new Event("input", {bubbles: true})
  49. Object.defineProperty(e, "target", {value: target})
  50. target.dispatchEvent(e);
  51. }
  52. onUiLoaded(async () => {
  53. let spans = document.querySelectorAll('.aspect_ratios span');
  54. spans.forEach(function (span) {
  55. span.innerHTML = span.innerHTML.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
  56. });
  57. document.querySelector('.style_selections').addEventListener('focusout', function (event) {
  58. setTimeout(() => {
  59. if (!this.contains(document.activeElement)) {
  60. on_style_selection_blur();
  61. }
  62. }, 200);
  63. });
  64. let inputs = document.querySelectorAll('.lora_weight input[type="range"]');
  65. inputs.forEach(function (input) {
  66. input.style.marginTop = '12px';
  67. });
  68. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...