positions.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. var getAbsPosition = function (el) {
  2. var el2 = el;
  3. var curtop = 0;
  4. var curleft = 0;
  5. if (document.getElementById || document.all) {
  6. do {
  7. curleft += el.offsetLeft - el.scrollLeft;
  8. curtop += el.offsetTop - el.scrollTop;
  9. el = el.offsetParent;
  10. el2 = el2.parentNode;
  11. while (el2 != el) {
  12. curleft -= el2.scrollLeft;
  13. curtop -= el2.scrollTop;
  14. el2 = el2.parentNode;
  15. }
  16. } while (el.offsetParent);
  17. } else if (document.layers) {
  18. curtop += el.y;
  19. curleft += el.x;
  20. }
  21. return [curtop, curleft];
  22. };
  23. $(document).ready(function () {
  24. let wrapLoca = document.getElementById('wrap')
  25. $("#wrap").draggable({
  26. drag: function (e, ui) {
  27. let coords = getAbsPosition(wrapLoca)
  28. // console.log("Drag - top", coords[0], "left", coords[1])
  29. localStorage.setItem('playerTop', `${coords[0]}px`);
  30. localStorage.setItem('playerLeft', `${coords[1]}px`);
  31. },
  32. }).resizable({
  33. start: function (e, ui) {
  34. // alert('resizing started');
  35. },
  36. resize: function (e, ui) {
  37. // console.log("resize - width", wrapLoca.style.width, "height", wrapLoca.style.height)
  38. if (window.onWindowResize) window.onWindowResize(true)
  39. localStorage.setItem('playerWidth', wrapLoca.style.width);
  40. localStorage.setItem('playerHeight', wrapLoca.style.height);
  41. },
  42. stop: function (e, ui) {
  43. if (window.onWindowResize) window.onWindowResize(false)
  44. }
  45. });
  46. });
  47. const TABS = [...document.querySelectorAll('#tabs a')];
  48. const CONTENT = [...document.querySelectorAll('#tab-content div')];
  49. const ACTIVE_CLASS = 'is-active';
  50. function initTabs() {
  51. TABS.forEach((tab) => {
  52. tab.addEventListener('click', (e) => {
  53. let selected = tab.getAttribute('data-tab');
  54. updateActiveTab(tab);
  55. updateActiveContent(selected);
  56. })
  57. })
  58. }
  59. function updateActiveTab(selected) {
  60. TABS.forEach((tab) => {
  61. if (tab && tab.classList.contains(ACTIVE_CLASS)) {
  62. tab.classList.remove(ACTIVE_CLASS);
  63. }
  64. });
  65. selected.classList.add(ACTIVE_CLASS);
  66. }
  67. function updateActiveContent(selected) {
  68. CONTENT.forEach((item) => {
  69. if (item && item.classList.contains(ACTIVE_CLASS)) {
  70. item.classList.remove(ACTIVE_CLASS);
  71. }
  72. let data = item.getAttribute('data-content');
  73. if (data === selected) {
  74. item.classList.add(ACTIVE_CLASS);
  75. }
  76. });
  77. }
  78. initTabs();