1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
| (function() { const HEADER_IMG = [ "/img/header-01.png", "/img/header-02.png", "/img/header-03.png", "/img/header-04.png", "/img/header-05.png", "/img/header-06.png", "/img/header-07.png", "/img/header-08.png", "/img/header-09.png", "/img/header-10.png" ];
const FOOTER_IMG = [ "/img/footer-01.png", "/img/footer-02.png", "/img/footer-03.png", "/img/footer-04.png", "/img/footer-05.png", "/img/footer-06.png", "/img/footer-07.png", "/img/footer-08.png", "/img/footer-09.png", "/img/footer-10.png" ];
let headerObserver = null;
function createDraggableImage(containerId, imgId, imgUrl, storageKey, initMode) { const container = document.getElementById(containerId); if (!container) return;
if (document.getElementById(imgId)) return;
const originalPosition = getComputedStyle(container).position; if (originalPosition === 'static') { container.style.position = 'relative'; }
const img = document.createElement('img'); img.id = imgId; img.className = 'draggable-img entered loaded'; img.draggable = false; img.src = imgUrl; container.appendChild(img);
let isDragging = false; let wasDragged = false; let startX = 0; let startLeft = 0; let currentLeft = 0;
const edgeThreshold = 20; const moveStep = 200; const shouldStore = initMode === 'stored';
const getMaxLeft = () => { const containerWidth = container.clientWidth; const imgWidth = img.clientWidth; return Math.max(0, containerWidth - imgWidth); };
const setPosition = (left, store = shouldStore) => { const maxLeft = getMaxLeft(); const clampedLeft = Math.min(maxLeft, Math.max(0, left)); img.style.left = `${clampedLeft}px`; currentLeft = clampedLeft; if (store) localStorage.setItem(storageKey, clampedLeft); };
const initPosition = () => { const maxLeft = getMaxLeft(); let initLeft; if (initMode === 'random') { initLeft = Math.random() * maxLeft; } else if (initMode === 'left') { initLeft = 0; } else if (initMode === 'right') { initLeft = maxLeft; } else { const storedLeft = parseInt(localStorage.getItem(storageKey)); if (!isNaN(storedLeft) && storedLeft >= 0 && storedLeft <= maxLeft) { initLeft = storedLeft; } else { initLeft = maxLeft; } } setPosition(initLeft, shouldStore); };
if (img.complete) { initPosition(); } else { img.addEventListener('load', initPosition); }
window.addEventListener('resize', () => { if (currentLeft !== undefined) { const maxLeft = getMaxLeft(); if (currentLeft > maxLeft) { setPosition(maxLeft, shouldStore); } else { img.style.left = `${currentLeft}px`; } } });
img.addEventListener('click', (e) => { if (!wasDragged) { const maxLeft = getMaxLeft(); let newLeft = currentLeft; if (currentLeft <= edgeThreshold) { newLeft = Math.min(currentLeft + moveStep, maxLeft); } else if (currentLeft >= maxLeft - edgeThreshold) { newLeft = Math.max(currentLeft - moveStep, 0); } else { newLeft = currentLeft + (Math.random() < 0.5 ? -moveStep : moveStep); newLeft = Math.max(0, Math.min(newLeft, maxLeft)); } if (newLeft !== currentLeft) setPosition(newLeft, shouldStore); } wasDragged = false; });
img.addEventListener('mousedown', (e) => { e.preventDefault(); isDragging = true; wasDragged = false; startX = e.clientX; startLeft = currentLeft; img.style.transition = 'none';
const onMouseMove = (e) => { if (!isDragging) return; wasDragged = true; const offsetX = e.clientX - startX; const maxLeft = getMaxLeft(); let newLeft = startLeft + offsetX; newLeft = Math.min(maxLeft, Math.max(0, newLeft)); requestAnimationFrame(() => { img.style.left = `${newLeft}px`; currentLeft = newLeft; }); };
const onMouseUp = () => { if (!isDragging) return; isDragging = false; img.style.transition = ''; if (shouldStore) localStorage.setItem(storageKey, currentLeft); document.removeEventListener('mousemove', onMouseMove); document.removeEventListener('mouseup', onMouseUp); };
document.addEventListener('mousemove', onMouseMove); document.addEventListener('mouseup', onMouseUp); }); }
function initFooterBar() { if (document.getElementById('footerList')) return; const footerBar = document.getElementById('footer-bar'); if (!footerBar) return; const footerList = document.createElement('div'); footerList.id = 'footerList'; footerList.classList.add('footerList', 'container'); footerBar.insertAdjacentElement('beforebegin', footerList); }
function initHeaderImage() { const HeaderImageUrl = HEADER_IMG[Math.floor(Math.random() * HEADER_IMG.length)];
createDraggableImage( 'bbTimeList', 'new-header-img', HeaderImageUrl, 'headerImgPos', 'random' );
const headerImg = document.getElementById('new-header-img'); const headerElem = document.querySelector('header.full_page'); if (!headerImg || !headerElem) return; const updateImageClass = () => { if (headerElem.classList.contains('nav-fixed')) { headerImg.classList.remove('hidden'); } else { headerImg.classList.add('hidden'); } };
updateImageClass();
if (headerObserver) headerObserver.disconnect(); headerObserver = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if (mutation.type === 'attributes' && mutation.attributeName === 'class') updateImageClass(); }); });
headerObserver.observe(headerElem, { attributes: true }); }
function initFooterImage() { const footerContainer = document.getElementById('footerList'); if (!footerContainer) return;
const existingImages = footerContainer.querySelectorAll('.draggable-img'); existingImages.forEach(img => img.remove());
const imgCount = Math.floor(Math.random() * 3) + 1; const shuffled = [...FOOTER_IMG]; for (let i = shuffled.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; } const footerImgUrls = shuffled.slice(0, imgCount);
for (let i = 0; i < footerImgUrls.length; i++) { createDraggableImage( 'footerList', `new-footer-img-${i+1}`, footerImgUrls[i], `footerImgPos_${i+1}`, 'random' ); } }
function initAll() { initFooterBar(); initHeaderImage(); initFooterImage(); }
document.addEventListener('DOMContentLoaded', initAll); document.addEventListener('pjax:success', initAll); })();
|