grid.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. setup.uiGridCreate ??= () =>{
  2. //$(document).one(':passagedisplay', function (ev) {
  3. $('#interface').addClass('grid-stack');
  4. const layoutFromStorage = JSON.parse(localStorage.getItem("GridStack") ?? "{}");
  5. $('.grid-stack .grid-stack-item:visible').toArray().forEach((element,index) => {
  6. for(const [key,val] of Object.entries(layoutFromStorage[index] ?? {})){
  7. element.setAttribute(key,val);
  8. }
  9. });
  10. setup.uiGrid = GridStack.init();
  11. let grid_stack = $('.grid-stack');
  12. grid_stack.on('change', function (event, items) {
  13. let r = {};
  14. $('.grid-stack .grid-stack-item:visible').toArray().forEach((element,index) => {
  15. r[index] ??= {};
  16. const attributes = element.attributes;
  17. for (let i = 0; i < attributes.length; i++) {
  18. const attr = attributes[i];
  19. if (attr.name.startsWith('gs')) {
  20. r[index][attr.name] = attr.value;
  21. }
  22. }
  23. });
  24. localStorage.setItem("GridStack", JSON.stringify(r));
  25. });
  26. //});
  27. }
  28. setup.uiGridDestroy = () => {
  29. //$(document).one(':passagedisplay', function (ev) {
  30. if(!setup.uiGrid)
  31. return;
  32. setup.uiGrid.destroy(false);
  33. $('#interface').removeClass('grid-stack');
  34. //});
  35. }