studio.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // Studio page — vanilla fade-carousel + tab sync + per-slide choreography.
  2. // Replaces Bootstrap Carousel/Tab, jQuery, and backstretch. Keeps DrawFillSVG
  3. // (window.DrawFillSVG, self-exposed from the v4-script bundle).
  4. // --- shared chrome: navbar hide/show on scroll (ported from jQuery dw_hidenav) ---
  5. (function () {
  6. const navbar = document.querySelector('.navbar');
  7. if (!navbar) return;
  8. const title = document.querySelector('.site-title a');
  9. const headerHeight = navbar.offsetHeight;
  10. let previousTop = 0;
  11. window.addEventListener('scroll', function () {
  12. const currentTop = window.scrollY;
  13. if (currentTop < previousTop) {
  14. if (currentTop > 0 && navbar.classList.contains('fixed')) {
  15. navbar.classList.add('visible');
  16. if (title) title.classList.remove('light');
  17. } else {
  18. navbar.classList.remove('visible', 'fixed');
  19. if (title) title.classList.add('light');
  20. }
  21. } else {
  22. navbar.classList.remove('visible');
  23. if (currentTop > headerHeight && !navbar.classList.contains('fixed')) {
  24. navbar.classList.add('fixed');
  25. }
  26. }
  27. previousTop = currentTop;
  28. }, { passive: true });
  29. })();
  30. document.querySelectorAll('.nav-toggle').forEach(function (el) {
  31. el.addEventListener('click', function (e) {
  32. e.preventDefault();
  33. el.classList.toggle('active');
  34. });
  35. });
  36. // --- studio fade-carousel ---
  37. (function () {
  38. const stage = document.getElementById('studio-caro');
  39. const caro = document.getElementById('caro');
  40. if (!stage || !caro) return;
  41. const slides = Array.from(caro.querySelectorAll('.dw-fade-slide'));
  42. const tabs = Array.from(document.querySelectorAll('.dw-studio-tab'));
  43. const panes = Array.from(document.querySelectorAll('#studio-tab .tab-pane'));
  44. const bg = stage.querySelector('.dw-studio-bg');
  45. const video = stage.querySelector('.dw-studio-video'); // camera → Media slide
  46. const tv = stage.querySelector('.dw-studio-tv'); // grayscale → fact intro
  47. const title = document.querySelector('.site-title a');
  48. const studioTab = tabs.find((t) => t.getAttribute('href') === '#studio') || tabs[0];
  49. const GRADS = ['caro-grad', 'caro-grad2', 'caro-grad3', 'caro-grad5'];
  50. // per slide: gradient class · background image · show video · navbar-title light
  51. // Slides 0-4 are the tabbed sections; 5-7 the fact intro; 8 the Projects hero.
  52. const CONFIG = [
  53. { grad: 'caro-grad5', img: stage.dataset.bg0 || null, video: false, light: true, filter: 'url(#dw-duotone-slate)' }, // 0 Studio (slate-duotone hero)
  54. { grad: 'caro-grad2', img: null, video: false, light: true }, // 1 Web/Dev (was UX)
  55. { grad: 'caro-grad3', img: null, video: false, light: false }, // 2 Graphic
  56. { grad: 'caro-grad5', img: null, video: true, light: true }, // 3 Media
  57. { grad: 'caro-grad5', img: stage.dataset.bg5 || null, video: false, light: true }, // 4 Art
  58. { grad: 'caro-grad5', img: null, video: false, tv: true, light: true }, // 5 fact: web sites
  59. { grad: 'caro-grad5', img: null, video: false, tv: true, light: true }, // 6 fact: stars
  60. { grad: 'caro-grad5', img: null, video: false, tv: true, light: true }, // 7 fact: brain
  61. { grad: 'caro-grad5', img: null, video: false, light: true }, // 8 Projects (cards; transparent stage → body shows around the #dadada slide card)
  62. ];
  63. const INTERVAL = 5000;
  64. let index = 0;
  65. let timer = null;
  66. function drawSVGs(slide) {
  67. if (!window.DrawFillSVG) return;
  68. slide.querySelectorAll('svg[id]').forEach(function (svg) {
  69. try {
  70. new window.DrawFillSVG({ elementId: svg.id }).replay();
  71. } catch (e) {
  72. /* svg not animatable — skip */
  73. }
  74. });
  75. }
  76. // Set the hero carousel slide (slide visibility, gradient, bg image, video/tv,
  77. // navbar-title colour). Does NOT touch the subnav tabs or content panes — those
  78. // are driven by setActiveTab, so the Wonder auto-cycle and the content-only
  79. // Projects tab can move the hero and the active tab independently.
  80. function setHero(i) {
  81. i = (i + slides.length) % slides.length;
  82. index = i;
  83. const cfg = CONFIG[i];
  84. slides.forEach((s, n) => {
  85. const on = n === i;
  86. s.classList.toggle('active', on);
  87. // reveal the active slide's hidden content (.animac.hide-svg, #brain.hide-svg …)
  88. if (on) s.querySelectorAll('.hide-svg').forEach((el) => el.classList.remove('hide-svg'));
  89. });
  90. GRADS.forEach((g) => stage.classList.remove(g));
  91. stage.classList.add(cfg.grad);
  92. if (bg) {
  93. bg.style.backgroundImage = cfg.img ? 'url("' + cfg.img + '")' : '';
  94. bg.style.filter = cfg.filter || ''; // slate duotone on the Studio hero only
  95. }
  96. if (video) {
  97. if (cfg.video) {
  98. video.style.display = 'block';
  99. video.play().catch(function () {});
  100. } else {
  101. video.pause();
  102. video.style.display = 'none';
  103. }
  104. }
  105. if (tv) {
  106. if (cfg.tv) {
  107. tv.style.display = 'block';
  108. tv.play().catch(function () {});
  109. } else {
  110. tv.pause();
  111. tv.style.display = 'none';
  112. }
  113. }
  114. if (title) title.classList.toggle('light', cfg.light);
  115. drawSVGs(slides[i]);
  116. }
  117. // Mark a subnav tab active and show its matching content pane, matched by the
  118. // tab's href hash → pane id (#studio → id="studio", #projects → id="projects").
  119. // Tabs with no pane (Wonder) simply hide every pane.
  120. function setActiveTab(tab) {
  121. tabs.forEach((t) => t.classList.toggle('active', t === tab));
  122. const hash = tab ? tab.getAttribute('href') || '' : '';
  123. const id = hash.charAt(0) === '#' ? hash.slice(1) : '';
  124. panes.forEach((p) => p.classList.toggle('active', p.id === id));
  125. }
  126. // "Wonder" auto-rotates through the fact slides (6,7,8) then returns to Studio (0)
  127. // and stops. Every other tab just switches on click — no autoplay.
  128. const WONDER = [5, 6, 7, 0];
  129. let wonderTimer = null;
  130. function stopWonder() { if (wonderTimer) { window.clearTimeout(wonderTimer); wonderTimer = null; } }
  131. function runWonder() {
  132. stopWonder();
  133. let step = 0;
  134. (function tick() {
  135. setHero(WONDER[step]);
  136. step++;
  137. if (step < WONDER.length) wonderTimer = window.setTimeout(tick, INTERVAL);
  138. else setActiveTab(studioTab); // cycle ends on the Studio hero → settle the tab there
  139. })();
  140. }
  141. tabs.forEach(function (t) {
  142. t.addEventListener('click', function (e) {
  143. e.preventDefault();
  144. stopWonder();
  145. setActiveTab(t);
  146. if (t.classList.contains('dw-studio-wonder')) runWonder();
  147. else setHero(parseInt(t.dataset.slide, 10) || 0);
  148. });
  149. });
  150. // No autoplay — the carousel advances only on subnav clicks (Wonder runs its own set).
  151. setActiveTab(studioTab);
  152. setHero(0);
  153. })();