diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:10:59 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:41:44 +0800 |
| commit | fc87c009806dcc98867f6b58efe29b042aa01dee (patch) | |
| tree | 8f59b3f4a5b66e9dfef2d40c8d318e258a521228 /node_modules/swup/src/modules/replaceContent.ts | |
| parent | 3336b2356ee6152d9c6ae59bd9b87ccbc0958407 (diff) | |
node: updatemain
Diffstat (limited to 'node_modules/swup/src/modules/replaceContent.ts')
| -rwxr-xr-x | node_modules/swup/src/modules/replaceContent.ts | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/node_modules/swup/src/modules/replaceContent.ts b/node_modules/swup/src/modules/replaceContent.ts deleted file mode 100755 index 62859acd..00000000 --- a/node_modules/swup/src/modules/replaceContent.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type Swup from '../Swup.js'; -import { query, queryAll } from '../utils.js'; -import type { Visit } from './Visit.js'; - -/** - * Perform the replacement of content after loading a page. - * - * @returns Whether all containers were replaced. - */ -export const replaceContent = function (this: Swup, visit: Visit): boolean { - const incomingDocument = visit.to.document; - if (!incomingDocument) return false; - - // Update browser title - const title = incomingDocument.querySelector('title')?.innerText || ''; - document.title = title; - - // Save persisted elements - const persistedElements = queryAll('[data-swup-persist]:not([data-swup-persist=""])'); - - // Update content containers - const replaced = visit.containers - .map((selector) => { - const currentEl = document.querySelector(selector); - const incomingEl = incomingDocument.querySelector(selector); - if (currentEl && incomingEl) { - currentEl.replaceWith(incomingEl.cloneNode(true)); - return true; - } - if (!currentEl) { - console.warn(`[swup] Container missing in current document: ${selector}`); - } - if (!incomingEl) { - console.warn(`[swup] Container missing in incoming document: ${selector}`); - } - return false; - }) - .filter(Boolean); - - // Restore persisted elements - persistedElements.forEach((existing) => { - const key = existing.getAttribute('data-swup-persist'); - const replacement = query(`[data-swup-persist="${key}"]`); - if (replacement && replacement !== existing) { - replacement.replaceWith(existing); - } - }); - - // Return true if all containers were replaced - return replaced.length === visit.containers.length; -}; |
