selfhtml, to programming German
@selfhtml@bildung.social avatar

JS + CSS: Use Case für clientWidth und getBoundingClientRect()

Wir haben ja schon einige Beispiele für die Ermittlung von Elementgrößen mit JS.

Aber alle stellen eigentlich nur vor, wie's geht, nicht, wann und wo man es einsetzen sollte.

Habt ihr eine Idee für ein Praxisbeispiel?

kaiserkiwi,
@kaiserkiwi@corteximplant.com avatar

@selfhtml getBoundingClientRect() wird gerne verwendet, um zu prüfen, ob ein Element bereits existiert oder sichtbar ist.

clientWidth und clientHeight nutze ich heutzutage eigentlich kaum noch. Das meiste lässt sich mit Media-/Container-Queries besser lösen.

jimfl, (edited ) to rust
@jimfl@hachyderm.io avatar

Today I learned about @slint (https://github.com/slint-ui/slint) which takes a UI described in a DSL and compiles it to , , or . Runs across multiple platforms.

I’m wondering if anyone has tried using a Slint-built binary as a NIF in . Seems like a powerful combination.

nebyoolae, (edited ) to random
@nebyoolae@masto.neb.host avatar

Javascript.

ferrata,
@ferrata@hachyderm.io avatar

@nebyoolae my vote is not here 😅

const foo = 'sup';

nebyoolae,
@nebyoolae@masto.neb.host avatar

@ferrata I, too, use const and let, but var is still valid, and I didn't want to litter the poll with too many choices ;P

minioctt, (edited ) to CSS Italian

[⤴️ https://octospacc.altervista.org/2024/02/01/emmebi-telegrammico/]

L’ultimissimo miglioramento che ho in ogni caso poi fatto ad è stato l’aggiunta di una funzione per importare codice e , per modificare come i post possono essere visualizzati. Entrambi funzionano allo stesso modo, con i relativi parametri URL che accettano sia esterni che data URI. Niente di particolare per gli stili, semplicemente importo nella pagina la qualunque cosa venga data lì, ma per gli è stato leggermente più . 😕️

Il punto sta nel voler evitare che essenzialmente non affidabili siano iniettati nel contesto della pagina semplicemente da URL, perché potrebbero fare tante cosine cattive; prima fra tutte, rubare dall’archiviazione del del mio dominio, cosa che è un , perché gli utenti inesperti che aprono la app da non andranno a cercare di investigare cosa accade dietro le quinte (e, molto probabilmente, non lo farei realisticamente nemmeno io, seguendo la logica del “i miei siti sono miei e li conosco, sui siti altrui ho le protezioni del browser attive“). E quindi inizio a scendere in un rabbithole… ☠️

  • ? Hmm… non so, non è il caso, sarebbero insicuri, ci sono alcuni modi in cui una pagina in frame può fare robe fastidiose. Non può essere assolutamente un’idea, proprio mai (foreshadowing). 🪟️
  • Trovo un bel po’ di vecchie che ricompilano codice per rimuovere pericoli, o lo analizzano preventivamente per la presenza di operazioni dannose così che possa non essere mai eseguito… praticamente tutte abbandonate, qualcuna esplicitamente dichiarata insicura e non patchata, e per qualcun’altra lo possiamo dare per scontato. 🐛️
  • Forse questa libreria più recente, jailed, che sfrutta un iframe assieme ad un Web Worker per creare una sandbox forte e bloccare tutte le eccetto alcune che si decidono… No, l’ho provata e non va bene, non si riescono a passare alla sandbox oggetti complessi, tra cui i costruttori, è impossibile far funzionare API tipo quella del DOM. 🚧️
    • Sarebbe stata un’idea usare qualche reimplementazione del per NodeJS tramite browserify, tipo Cheerio, ma farla anche solo girare lì dentro è un altro casino allucinante. 🥴️
  • WASM tecnicamente è una a sua volta, e non accede alle API del browser se non con codice colla, quindi magari… teoricamente ok, ma nella pratica non ho trovato nessuna soluzione già bella e pronta che potessi usare per questo specifico scopo. 🕳️
  • La : PyScript… sarebbe quasi già pronto, ma avrei dovuto comunque modificarlo per bloccare tutte le API insicure (rimuovere ), e poi richiede 15+ MB di dipendenze di runtime… non ideale. 🗿️

Alla fine ci ho pensato meglio, e sono arrivata alla conclusione che è abbastanza sicuro far girare gli script in un iframe con proprietà src="data:[...]" e sandbox="allow-scripts" (che significa, “blocca tutte le proprietà sensibili eccetto gli script”)… voglio dire, nel visualizzare il contenuto dei siti, già permetto eventuali iframe provenienti dai post, e quelli teoricamente possono già fare quello che vogliono eccetto accedere ai dati della finestra root. Nella pratica, i programmini degli utenti quindi hanno accesso a (quasi) l’intera API JavaScript senza poter fare cose bruttissime. 🎉️

https://octospacc.altervista.org/wp-content/uploads/2024/02/image.pngEcco un esempio di tutto, alla fine: questo URL carica il mio MicroBlog, importa un foglio di che mette questo font buffo, e uno script che colora le parole dei in base a come si ripetono man mano (inutile, ma serve giusto per dare idea delle potenzialità)… <a href="https://hub.octt.eu.org/MBViewer/#/siteUrl=https://octospacc.altervista.org|platform=wordpress.org|includeStyle=data:text/css;utf8,@import%20url('https://fonts.googleapis.com/css2?family=Single+Day&display=swap');.MbPost{font-family:'Single%20Day',cursive;}|includeScript=data:text/javascript;utf8,function%20MbViewerFunction(data){const%20dom=new%20DOMParser().parseFromString(data.html,'text/html').body;const%20tokens=dom.textContent.split('%20');const%20words={};for(const%20i%20in%20tokens){const%20word%20=%20tokens[i];if(words[word])words[word]++;else%20words[word]=1;tokens[i]=%60%3Cspan%20style='color:${atob('Iw==')}${[0,'b58900','cb4b16','dc322f','d33682','6c71c4','268bd2','2aa198','859900'][words[word]]};'%3E${word}%3C/span%3E%60}data.html=tokens.join('%20').replaceAll('nn','%3Cbr%3E');for(const%20img%20of%20dom.querySelectorAll('img'))data.html+=img.outerHTML;MbViewerReturn(data)}">https://hub.octt.eu.org/MBViewer/#/siteUrl=https://octospacc.altervista.org|platform=wordpress.org|includeStyle=[...]|includeScript=[...]</a> (il link con tutta quella roba messa inline è una stringa di quasi 1 KB!). Userò tutta la cosa per rendere gli hashtag nel testo meno intrusivi per il mio sito anche lì, oltre che sul dominio originale. 👋️Finisco con dati ancora più tecnici, per chi non ha una vita: con questo , ogni deve provvedere ad esporre una funzione che, tramite la Channel Messaging API, viene richiamata dalla per ogni messaggio appena questo viene aggiunto al documento visibile; questa funzione riceve dati utili (per ora, solo l’HTML del contenuto; oltre a dati come l’id del messaggio nel flusso, che non sono granché utili all’utente ma devono essere restituiti alla app) e può rimandare nuovi dati indietro richiamando una funzione che è invece l’applicazione ad esporre allo script. Tutto questo ambaradan permetterebbe agli script di effettuare anche operazioni asincrone, comunque, non per forza di dover agire immediatamente alla chiamata. 🤓️

https://octospacc.altervista.org/2024/02/01/emmebi-javascriptico/

schizanon, to react
@schizanon@mas.to avatar

If you think react is complicated now, go back to 2015 when you had to configure babel and webpack yourself, you had to do SSR and routing yourself, you had to decide between flow and typescript, you had to learn flux and immutable.js, and you had to choose 1 of 100 boilerplates

yaeunerd,
@yaeunerd@fosstodon.org avatar

@schizanon

> You go to war with the enemy you have, not the one you want.

Quite right.

I just wish that React had some sort of "compile-to-web-components" or something like that.

web-components are...well I've never worked with someone who likes them.

But they're the standard, and they're not that bad.

schizanon,
@schizanon@mas.to avatar

@yaeunerd Totally agree! The least they could do is make their events system compatible with standard custom events so that WCs could communicate with React Components!

kroc, to random
@kroc@mstdn.social avatar

Just wow. The world is designing websites and apps for the iPhone at the top of this graph whilst the majority of users in the world are using hardware at the bottom. As always, JavaScript was a mistake. https://infrequently.org/2024/01/performance-inequality-gap-2024/

schafer, to CSS
@schafer@ohai.social avatar

I have the opportunity to do a redesign of a very large site that I built about 5 years ago and have maintained since. Looking to brush up on the newer #CSS / #JS that’s available to me for #frontend. The current site was built with #JQuery and #flexbox was not even an option at the time. Would love to move to #vanillaJS for most things and get the most out of flexbox that I can.

Looking for good resources, if anyone knows of any.

Jbasoo,
@Jbasoo@mastodon.social avatar

@schafer Layout wise CSS grid and flexbox will make you very happy. https://www.joshwcomeau.com/css/interactive-guide-to-grid/ https://www.joshwcomeau.com/css/interactive-guide-to-flexbox/

On the JS side there's now lots of vanilla js methods that were influenced by jQuery era libraries so they should feel pretty familiar https://javascript30.com/

Also, web components are pretty hot right now https://htmlwithsuperpowers.netlify.app/

boilingsteam, to linux
@boilingsteam@mastodon.cloud avatar
raiderrobert, to programming
@raiderrobert@mastodon.social avatar

GO HOME #JS UR DRUNK!!!!!

raiderrobert,
@raiderrobert@mastodon.social avatar

Someone else: it makes sense if you---

ME: NO IT DOES NOT!!!!

aral, to SmallWeb
@aral@mastodon.ar.al avatar

Is htmx Just Another JavaScript Framework?

https://htmx.org/essays/is-htmx-another-javascript-framework/

PS. Guess what? Kitten has built-in, first-class support for htmx. (To include it in your page, just add <page htmx> to your markup.)

https://codeberg.org/kitten/app

aral, to programming
@aral@mastodon.ar.al avatar

FSX (a new modern file system module for Node.js) looks really nice. Intelligent defaults and support for mocking designed in.

Would love to see this in core.

https://humanwhocodes.com/blog/2024/01/fsx-modern-filesystem-api-javascript/

BryceWrayTX, to webdev
@BryceWrayTX@fosstodon.org avatar

New post >> It’s tri-state switch time • With thanks as always to other, smarter folks, I implement a mode switch that gives you yet another option.

https://www.brycewray.com/posts/2024/01/its-tri-state-switch-time/

#LightDark #WebDev #CSS #JavaScript #JS

craigabbott, to javascript
@craigabbott@a11y.info avatar

I was today years old when I learned about chaining nullish coalescing operators in #javascript as an easy way to check for deep nested properties of an object without having to check each level exists as a separate statement. 🤯

For example: if (user?.details?.name?.first)

#js

joelanman,
@joelanman@hachyderm.io avatar

@craigabbott It's a great feature!

cherrykoda, to programming
@cherrykoda@mas.to avatar

Honestly... it's not exactly anything new that's spurred the realisation that React is overcomplicated for what it tries to do. Glad the light is being found, but yikes that was a long time coming.

"React suggests using a framework to start a project, suggesting to use one of the three main open source frameworks, instead of just React." This itself isn't surprising, as React suffers from the same issues as Framework mania.

#js #webdev #developer

https://dev.to/matfrana/react-where-are-you-going-5284

olvigg, to Ukraine Ukrainian

Ok, last try... If I can’t get some kind of job in the near future, then I’ll just die soon.

NodeJS / React developer from Kyiv 🇺🇦

I'm looking for . Urgently.
CV: https://docs.google.com/document/d/1TpOKEwYG02DZznxPpgixv23XdKkRA2asGQIDfuZlFno/edit?usp=sharing

@ua @rada

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • thenastyranch
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • ngwrru68w68
  • provamag3
  • magazineikmin
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • JUstTest
  • All magazines