Skip to content

Commit d1356e7

Browse files
fix: Fix Typo
1 parent 4aa4956 commit d1356e7

File tree

1 file changed

+17
-38
lines changed

1 file changed

+17
-38
lines changed

addons/van_dml/README.md

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,22 @@ _Author: [Eckehard](https://github.com/efpage)_
55
**van_dml.js** adds a new flavour of composition to VanJS. This is heavily inspired by the [DML](https://github.com/efpage/dml)-framework for dynamic page creation.
66

77
Van_DML extends the core of VanJS. You can enable van_dml like this:
8-
98
```JS
109
<script src="van-latest.nomodule-min.js"></script>
1110
<script src="van_dml.js"></script>
1211

1312
const { h1, h2, div, p, button } = van.tags;
1413
const { begin, end, base, sp, css } = van // new functions of van_dml
1514
```
16-
1715
## How does it work?
18-
1916
`begin(ID)` selects an element "ID" as a base. ID can be a DOM element or a HTML-ID. All elements created after `begin()` are automatically appended as childs to this object.
2017
`end()` finishes the automatic appending.
2118

2219
`begin()` and `end()` can be nested like this:
23-
2420
```JS
2521
const { h1, h2, div, p, button } = van.tags;
2622
const { begin, end, base, sp, css } = van
27-
23+
2824
begin(document.body)
2925
h1("Headline")
3026
begin(div({style: "border: 1px solid black"}))
@@ -33,38 +29,30 @@ Van_DML extends the core of VanJS. You can enable van_dml like this:
3329
end()
3430
end()
3531
```
36-
3732
This is similar to using plain HTML, where a tag create elements directly.
3833

3934
## transparent operation of "begin()"
4035

4136
Van-Tags return a DOM Reference that can be stored in a variable:
42-
4337
```JS
4438
let d = div()
4539
d.style.color = "red"
4640
d.appendChild(h1("Headline");
4741
```
48-
4942
With VAN_DML, this can be rewritten:
50-
5143
```JS
5244
let d = begin(div()) // -> d is the <div>-element
5345
begin(div()).style.color = "red" // Access the style of div
5446
```
55-
5647
`begin()` is "transparent", it just returns the DOM reference of the first child. This let´s you create functions like this:
57-
5848
```JS
5949
const bdiv = (...args) => begin(div(...args))
60-
50+
6151
bdiv() // Create a div and open for append
6252
h1()
6353
end()
6454
```
65-
6655
begin(ID) can also digest Strings:
67-
6856
```JS
6957
<div id="ID"></div>
7058
<script>
@@ -76,57 +64,49 @@ begin(ID) can also digest Strings:
7664
7765
## end(n)
7866
79-
`end()` finishes the append mode and returns to the previous base. For each `begin()` there should be one call of `end()`. You can verify this by checking `SP() === 0` (see below).
80-
If no base is selected (or the calls `begin()` and `end()` are balanced), auto-Append is disabled.
67+
`end()` finishes the append mode and returns to the previous base. For each `begin()` there should be one call of `end()`. You can verify this by checking `SP() === 0` (see below).
68+
If no base is selected (or the calls `begin()` and `end()` are balanced), auto-Append is disabled.
8169
8270
end(n) runs `end()` n times. May be convenient to return from deep nested functions.
8371
8472
## base() and sp()
8573
8674
base() returns the current base:
87-
8875
```JS
89-
begin(div())
76+
begin(div())
9077
let b = base(); // returns the current base (div())
9178
```
9279
9380
sp() is the current Stack-Position. Initially sp() is 0. With each call of `begin()` sp() is incremented, `end()` decrements sp().
9481
To check your code, you can add this line to the end of Javascript:
95-
9682
```JS
97-
begin(document.body)
83+
begin(document.body)
9884
.... some code here
9985
end()
100-
86+
10187
if (sp() !== 0) alert(`baseStack mismatch: stacksize ${sp()} at end of Javascript`)
10288
```
10389
10490
## css(): create CSS-rules dynamically with Javascript
10591
10692
`css(s)` adds new CSS-rules during runtime.
107-
s can be
108-
109-
- a string css(".myClass { color: red; }")
93+
s can be
94+
- a string css(".myClass { color: red; }")
11095
- a template string with multiple rules
111-
11296
```JS
11397
css(`
11498
.myClass { color: red; }
11599
.myClass: hover { color: green }
116100
`)
101+
```
102+
- It can contain template literals:
103+
```JS
104+
let color = [ "red", "green", "blue" ]
105+
css(`
106+
.myClass { color: ${mycolor[1]}; }
107+
`)
117108
```
118-
119-
- It can contain template literals:
120-
121-
```JS
122-
let color = [ "red", "green", "blue" ]
123-
css(`
124-
.myClass { color: ${mycolor[1]}; }
125-
`)
126-
```
127-
128109
If a rule already exists, it will be overwritten by the new definition. Results are immediately shown by the browser. Definitions with css() work like any other CSS you provide with static definitions, they just are added from within Javascript. This makes it easy to control CSS programmatically. css can be used anywhere and anytime in the script. New css-rules will become active immediately and might even be changed as shown in the example below:
129-
130110
```JS
131111
const { button } = van.tags
132112
const { add, css } = van
@@ -135,8 +115,7 @@ If a rule already exists, it will be overwritten by the new definition. Results
135115
button({onclick: () => css(".class1 {background-color: green;}")},"set class1 green")
136116
);
137117
```
138-
139-
**!Attention:**: css() adds new rules to the first stylesheet (`window.document.styleSheets[0]`). If the first stylesheet was loaded from an external source, this may cause CORS errors. For more information see [here](https://davidwalsh.name/add-rules-stylesheets) and [here](https://stackoverflow.com/questions/49088507/cannot-access-rules-in-external-cssstylesheet). Always add a **_local CSS-file_** first, as the dynamic rules are included in the first style sheet.
118+
**!Attention:**: css() adds new rules to the first stylesheet (`window.document.styleSheets[0]`). If the first stylesheet was loaded from an external source, this may cause CORS errors. For more information see [here](https://davidwalsh.name/add-rules-stylesheets) and [here](https://stackoverflow.com/questions/49088507/cannot-access-rules-in-external-cssstylesheet). Always add a ***local CSS-file*** first, as the dynamic rules are included in the first style sheet.
140119
141120
## Support
142121

0 commit comments

Comments
 (0)