Skip to content

Instantly share code, notes, and snippets.

View barneycarroll's full-sized avatar
🛠️
Working on Mithril type stuff

Barney Carroll barneycarroll

🛠️
Working on Mithril type stuff
View GitHub Profile
const css = (...x) =>
m(`style`, `\n@scope to (slot) {${ String.raw(...x) }}\n`)
// Mithril dev harness backend
//
// Exports a `registry` of components, active `instances`, an
// `activeTree` with the hierarchicy of components in vdom structure,
// and a `wrapper` to be used instead of `m` hyperscript.
//
// Intended for use as a backend to a GUI for visual inspection &
// debugging of the Mithril virtual DOM tree.
// Each component called by Mithril needs to be wrapped in a
@barneycarroll
barneycarroll / @scope.polyfill.js
Created July 17, 2024 14:08
A CSS @scope polyfill, extracted from Jon Neals pen here: https://codepen.io/jonneal/pen/xxpqdpJ
/** Return a unique selector for a specific element. */
const getUniqueSelector = (/** @type {Element} */ element) => {
/** Unique selector for this element */
let selector = ''
/** @type {Element} */
let parent
while (parent = element.parentElement) {
/** @type {number} Nth-child order of the element. */
@barneycarroll
barneycarroll / BeforeUnload.js
Created June 15, 2024 12:12
A `beforeonunload` emulator for Mithril
function BeforeUnload(){
const route. = m.route.set
const handler = e => {
if(
e.target.href
&&
e.target != '_blank'
&&
!confirm(message)
){
@barneycarroll
barneycarroll / inline-separators.css
Last active May 2, 2024 19:05
Inline separators
:root {
--separator-text : ' | ';
--separator-size : .45em;
}
.inline-separators {
&:dir(ltr) {
clip-path : inset(-100vh -100vw -100vh 0);
}
@barneycarroll
barneycarroll / rest_spread.js
Created November 24, 2022 19:23
WIP for a little demonstration of the various functions of ... operators in Javascript
const object = {a: 1, b: 2}
const array = [3,4]
// Value expression
const foo = {...object, c: 3} // == {a: 1, b: 2, c: 3}
const bar = [...array, 5, 6] // == [3, 4, 5, 6]
// Destructuring assignment
{
const {a, ...rest} = foo // a == {a: 1}; rest == {b: 2, c: 3}
@barneycarroll
barneycarroll / disable-zoom.js
Created April 3, 2024 06:17
Selectively disable mobile browser zoom on input focus
// Disable mobile zoom on focus
{
// Customise the selector value as necessary
const selector = '[data-nozoom]'
const $viewport =
document.querySelector('meta[name=viewport]')
??
Object.assign(document.createElement('meta'), {name: 'viewport'})
const $scale0 = Object.assign($viewport.cloneNode(), {content: 'user-scalable=0'})
@barneycarroll
barneycarroll / .js
Created July 27, 2022 10:55
Using modules not components for associated functionalities, with state management left to application space
import {ordinals, defaultRange, rangeFromOrdinal, Calendar} from './DateRange.js'
const state = {
...rangeFromOrdinal('Today'),
showCalendar : false,
}
m.mount(document.body, {
view: () => [
m('form',
@barneycarroll
barneycarroll / ordinal-suffix.html
Created March 19, 2014 13:35
Append ordinals via CSS rather than in markup. Requires even more HTML bytes though.
<span
class="ordinal"
data-number="22">
22
</span>
<span
class="ordinal"
data-number="0">
0
</span>
@barneycarroll
barneycarroll / grid-tables-reset.css
Last active March 18, 2024 10:24
Grid tables reset
@property --columns {
syntax: '<integer>';
inherits: false;
initial-value: 1;
}
table {
display: grid;
grid-template-columns: repeat(var(--columns, 1), auto);
}