mobile.js 976 B

1234567891011121314151617181920212223242526272829303132
  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. var currentlyMobile = isMobile();
  13. if (currentlyMobile == isSetupForMobile) return;
  14. isSetupForMobile = currentlyMobile;
  15. for (var tab of ["txt2img", "img2img"]) {
  16. var button = gradioApp().getElementById(tab + '_generate_box');
  17. var target = gradioApp().getElementById(currentlyMobile ? tab + '_results' : tab + '_actions_column');
  18. target.insertBefore(button, target.firstElementChild);
  19. gradioApp().getElementById(tab + '_results').classList.toggle('mobile', currentlyMobile);
  20. }
  21. }
  22. window.addEventListener("resize", reportWindowSize);
  23. onUiLoaded(function() {
  24. reportWindowSize();
  25. });