From 3fb98fcbeab5173acec5222bec7a4adf597e88bb Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 7 Jan 2023 09:53:29 -0400 Subject: extract utility binds, content transform fns towards basic dynamics pt. 1 (#124) --- src/misc-templates.js | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) (limited to 'src/misc-templates.js') diff --git a/src/misc-templates.js b/src/misc-templates.js index a530a3cf..9a1bbf50 100644 --- a/src/misc-templates.js +++ b/src/misc-templates.js @@ -10,6 +10,8 @@ import { unique, } from './util/sugar.js'; +import {thumb} from './util/urls.js'; + import { getTotalDuration, sortAlbumsTracksChronologically, @@ -642,6 +644,107 @@ function unbound_getFlashGridHTML({ }); } +// Images + +function unbound_img({ + html, + + src, + alt, + noSrcText = '', + thumb: thumbKey, + reveal, + id, + class: className, + width, + height, + link = false, + lazy = false, + square = false, +}) { + const willSquare = square; + const willLink = typeof link === 'string' || link; + + const originalSrc = src; + const thumbSrc = src && (thumbKey ? thumb[thumbKey](src) : src); + + const imgAttributes = { + id: link ? '' : id, + class: className, + alt, + width, + height, + }; + + const noSrcHTML = + !src && + wrap( + html.tag('div', + {class: 'image-text-area'}, + noSrcText)); + + const nonlazyHTML = + src && + wrap( + html.tag('img', { + ...imgAttributes, + src: thumbSrc, + })); + + const lazyHTML = + src && + lazy && + wrap( + html.tag('img', + { + ...imgAttributes, + class: [className, 'lazy'], + 'data-original': thumbSrc, + }), + true); + + if (!src) { + return noSrcHTML; + } else if (lazy) { + return html.tag('noscript', nonlazyHTML) + '\n' + lazyHTML; + } else { + return nonlazyHTML; + } + + function wrap(input, hide = false) { + let wrapped = input; + + wrapped = html.tag('div', {class: 'image-inner-area'}, wrapped); + wrapped = html.tag('div', {class: 'image-container'}, wrapped); + + if (reveal) { + wrapped = html.tag('div', {class: 'reveal'}, [ + wrapped, + html.tag('span', {class: 'reveal-text'}, reveal), + ]); + } + + if (willSquare) { + wrapped = html.tag('div', {class: 'square-content'}, wrapped); + wrapped = html.tag('div', + {class: ['square', hide && !willLink && 'js-hide']}, + wrapped); + } + + if (willLink) { + wrapped = html.tag('a', + { + id, + class: ['box', hide && 'js-hide'], + href: typeof link === 'string' ? link : originalSrc, + }, + wrapped); + } + + return wrapped; + } +} + // Carousel reels // Layout constants: @@ -940,6 +1043,8 @@ export { unbound_getCarouselHTML as getCarouselHTML, + unbound_img as img, + unbound_generateInfoGalleryLinks as generateInfoGalleryLinks, unbound_generateNavigationLinks as generateNavigationLinks, -- cgit 1.3.0-6-gf8a5 From 594e8dd46f9e6cc74c680536a1d820eef27133f0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 9 Jan 2023 21:07:16 -0400 Subject: most essential behavior for live-dev-server --- src/misc-templates.js | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'src/misc-templates.js') diff --git a/src/misc-templates.js b/src/misc-templates.js index 9a1bbf50..bccb8831 100644 --- a/src/misc-templates.js +++ b/src/misc-templates.js @@ -971,46 +971,37 @@ function unbound_generateStickyHeadingContainer({ function unbound_getFooterLocalizationLinks(pathname, { html, + defaultLanguage, language, + languages, to, - paths, - defaultLanguage, - languages, + pageSubKey, + urlArgs, }) { - const {urlPath} = paths; - const keySuffix = urlPath[0].replace(/^localized\./, '.'); - const toArgs = urlPath.slice(1); - const links = Object.entries(languages) .filter(([code, language]) => code !== 'default' && !language.hidden) .map(([code, language]) => language) .sort(({name: a}, {name: b}) => (a < b ? -1 : a > b ? 1 : 0)) .map((language) => - html.tag( - 'span', - html.tag( - 'a', + html.tag('span', + html.tag('a', { href: language === defaultLanguage - ? to('localizedDefaultLanguage' + keySuffix, ...toArgs) + ? to( + 'localizedDefaultLanguage.' + pageSubKey, + ...urlArgs) : to( - 'localizedWithBaseDirectory' + keySuffix, - language.code, - ...toArgs - ), + 'localizedWithBaseDirectory.' + pageSubKey, + language.code, ...urlArgs), }, - language.name - ) - ) - ); - - return html.tag( - 'div', - {class: 'footer-localization-links'}, - language.$('misc.uiLanguage', {languages: links.join('\n')}) - ); + language.name))); + + return html.tag('div', {class: 'footer-localization-links'}, + language.$('misc.uiLanguage', { + languages: links.join('\n'), + })); } // Exports -- cgit 1.3.0-6-gf8a5