Skip to content

Commit 70c64c5

Browse files
authored
staging via meta for the win (#8)
* 79 lines elmo flow help meta reset staff stage state via seed seeded * 77 later darling stage staff * hyperlink staging #8
1 parent f031a1c commit 70c64c5

3 files changed

Lines changed: 69 additions & 18 deletions

File tree

README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,48 @@ writing-mode: var(--mode, horizontal-tb);
5858
<script async src="varam.js"></script>
5959
```
6060

61-
- URL params are read
62-
- CSS var are updated
63-
- async optional
61+
- URL params are read and only read
62+
- CSS var are updated where matching
63+
- async or defer to your desire
6464

65-
### performant updating
65+
### updating
6666

67-
```js
68-
varam(location.search)
69-
```
67+
- performant updating
68+
- we minimize reflow
69+
- [just load the script](#automagic) to go with the flow with real URL
70+
- [updaters](#updaters) return [boolean](#boolean) whether reflow expected
71+
- update if you change dom (otherwise no need)
72+
73+
### updaters
74+
75+
- `varam.flow()` automagic does `varam(location.search)` with real URL
76+
- `varam.reset()` to reset state like `varam("")` but leave URL alone
77+
- `varam.fresh(...)` is how varam performantly interacts with style
7078

71-
### varam returns boolean
79+
### boolean
7280

7381
- `true` when update was made
7482
- `false` when update needless
7583

76-
### [seed carefully](../../pull/2)
84+
### help
85+
86+
`varam.help()` for help in your console
87+
88+
### diagnostic
89+
90+
- `varam.meta` content interpreted
91+
- `varam.state` latest state
92+
- `varam.via` paramethod `"flow"` or `"meta"`
93+
94+
### [staging](../../pull/8)
95+
96+
- default checks `location.search` **not meta**
97+
- staging meta simulates alternate search
98+
- **skip this** unless you're staging
99+
100+
```html
101+
<meta name="varam" content="oil=purple">
102+
```
77103

78104
## technology
79105

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<meta name="author" content="ryanve">
1111
<meta name="description" content="change CSS var via URL param javascript">
1212

13+
<!-- staging -->
14+
<!-- <meta name="varam" content="oil=purple"> -->
15+
1316
<link rel="stylesheet" href="www.css">
1417
<link rel="license" href="LICENSE.txt">
1518
<link rel="help" href="https://github.io/ryanve/varam">

varam.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
!function(web) {
1+
//ryanve.dev/varam
2+
!function(web, dom) {
3+
var empty = ""
24
var dash = "--"
35
var word = /\S+/g
46
var what = "data-varam"
57
var where = "[data-varam]"
6-
var all = "querySelectorAll"
8+
var first = dom.querySelector || no
79
var par = web.URLSearchParams
10+
var api = par ? varam : no
811

912
function varam(search) {
1013
var did = false
1114
var url = new par(search)
12-
var stack = document[all](where)
15+
var stack = dom.querySelectorAll(where)
1316
each(stack, function(scope) {
1417
var keys = scope.getAttribute(what)
1518
keys = keys && keys.match(word)
@@ -20,13 +23,27 @@
2023
did = fresh(style, relay, value) || did
2124
})
2225
})
26+
api.state = url.toString()
2327
return did
2428
}
2529

2630
function no() {
2731
return false
2832
}
2933

34+
function flow() {
35+
return api(location.search)
36+
}
37+
38+
function reset() {
39+
return api(empty)
40+
}
41+
42+
function help() {
43+
console.dir(api)
44+
return api.state
45+
}
46+
3047
function fresh(style, relay, value) {
3148
var prev = style.getPropertyValue(relay)
3249
var next = value
@@ -40,16 +57,21 @@
4057
while(i--) f(stack[i])
4158
}
4259

43-
var api = par ? varam : no
44-
var seed = web.varam
60+
var like = "meta[name=varam][content]"
61+
var elmo = first.call(dom, like)
62+
var seed = elmo && elmo.content
4563
var seeded = typeof seed == "string"
4664
seed = seeded && seed
47-
api.seed = seed
48-
api.seeded = seeded
65+
api.flow = par ? flow : no
4966
api.fresh = fresh
67+
api.help = help
68+
api.reset = par ? reset : no
69+
api.state = empty
70+
par && api(seeded ? seed : location.search)
71+
api.meta = seeded ? api.state : false
72+
api.via = seeded ? "meta" : "flow"
5073
web.varam = api
51-
api(seeded ? seed : location.search)
5274
var common = typeof module != "undefined"
5375
if (common && module.exports)
5476
module.exports = api
55-
}(window)
77+
}(window, document)

0 commit comments

Comments
 (0)