ui2.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. var storage = []; //{col:1, row:1, colamount:1, rowamount: 1}];
  2. function doOverlap(l1x, l1y, r1x, r1y, l2x, l2y, r2x, r2y)
  3. {
  4. // If one rectangle is on left side of other
  5. if (l1x > r2x || l2x > r1x)
  6. return false;
  7. // If one rectangle is above other
  8. if (l1y > r2y || l2y > r1y)
  9. return false;
  10. return true;
  11. }
  12. /*
  13. function clearRectangel(l1x, l1y, r1x, r1y){
  14. for(var i = l1x; i <= r1x; ++i)
  15. for(var k = l1y; k <= r1y; ++k){
  16. $(".item" + (i) + "-" + (k)).remove();
  17. //$(".item" + (i) + "-" + (k)).css({"display": "block", "border-style": "none", "border-color": "black", "grid-area": "auto"});
  18. //$(".item" + (i) + "-" + (k)).text("");
  19. }
  20. }
  21. function hideRectangel(l1x, l1y, r1x, r1y){
  22. for(var i = l1x; i <= r1x; ++i)
  23. for(var k = l1y; k <= r1y; ++k)
  24. if(!(i == l1x && k == l1y))
  25. $(".item" + (i) + "-" + (k)).hide(100);
  26. }
  27. */
  28. function makeFrame(lx, ly, rx, ry, content = "") {
  29. //check if rects overlap if they do remove old ones
  30. for (i = 0; i < window.storage.length; i++) {
  31. if(doOverlap(window.storage[i].lx, window.storage[i].ly, window.storage[i].rx, window.storage[i].ry, lx, ly, rx, ry)){
  32. $(".item" + window.storage[i].lx + "-" + window.storage[i].ly).remove();
  33. //clearRectangel(window.storage[i].lx, window.storage[i].ly, window.storage[i].rx, window.storage[i].ry)
  34. window.storage.splice(i,1);
  35. --i;
  36. }
  37. }
  38. //add new ellement to storage
  39. window.storage.push({lx:lx, ly:ly, rx:rx, ry: ry})
  40. const container = document.getElementById("container");
  41. let cell = document.createElement("div");
  42. cell.classList.add("grid-item");
  43. cell.classList.add("item" + lx + "-" + ly);
  44. $(cell).css({"display": "block", "border-style": "solid", "border-color": "blue", "grid-column": (lx+1) + " / span " + (rx-lx+1), "grid-row": ly+1 + " / span " + (ry-ly+1)});
  45. container.appendChild(cell);
  46. //Create new element with width, heigth and content
  47. //$(".item" + lx + "-" + ly).css({"display": "block", "border-style": "solid", "border-color": "blue", "grid-column": (lx+1) + " / span " + (rx-lx+1), "grid-row": ly+1 + " / span " + (ry-ly+1)});
  48. if(content != null && content != ""){
  49. $(".item" + lx + "-" + ly).html("<iframe width=100% height=100% src='" + content + "' title=''></iframe>");
  50. //hideRectangel(lx, ly, rx, ry)
  51. }
  52. else{
  53. $(".item" + lx + "-" + ly).html("No language available.<br> Nicht in der Sprache verfügbar.");
  54. //hideRectangel(lx, ly, rx, ry)
  55. }
  56. };
  57. /*
  58. document.addEventListener('keyup', (event) => {
  59. if (event.key == 'ArrowUp') {
  60. alert("ArrowUp");
  61. makeFrame(0,0,0,0, "a")
  62. }
  63. if (event.key == 'ArrowDown') {
  64. alert("ArrowDown");
  65. makeFrame(0,0,1,1, "b")
  66. }
  67. if (event.key == 'ArrowLeft') {
  68. alert("ArrowLeft");
  69. makeFrame(1,1,2,2, "c")
  70. }
  71. if (event.key == 'ArrowRight') {
  72. alert(JSON.stringify(window.storage));
  73. }
  74. });
  75. */