mobile.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. var isSetupForMobile = false;
  2. function isMobile() {
  3. for (var tab of ["txt2img", "img2img"]) {
  4. var imageTab = gradioApp().getElementById(tab + '_results');
  5. if (imageTab && imageTab.offsetParent && imageTab.offsetLeft == 0) {
  6. return true;
  7. }
  8. }
  9. return false;
  10. }
  11. function reportWindowSize() {
  12. if (gradioApp().querySelector('.toprow-compact-tools')) return; // not applicable for compact prompt layout
  13. var currentlyMobile = isMobile();
  14. if (currentlyMobile == isSetupForMobile) return;
  15. isSetupForMobile = currentlyMobile;
  16. for (var tab of ["txt2img", "img2img"]) {
  17. var button = gradioApp().getElementById(tab + '_generate_box');
  18. var target = gradioApp().getElementById(currentlyMobile ? tab + '_results' : tab + '_actions_column');
  19. target.insertBefore(button, target.firstElementChild);
  20. gradioApp().getElementById(tab + '_results').classList.toggle('mobile', currentlyMobile);
  21. }
  22. }
  23. window.addEventListener("resize", reportWindowSize);
  24. onUiLoaded(function() {
  25. reportWindowSize();
  26. });