-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunderstanding.html
More file actions
136 lines (104 loc) · 3.37 KB
/
understanding.html
File metadata and controls
136 lines (104 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<select name="" id="" onload="console.log('select loaded')"">
<option value=" 1">three</option>
<option value="2" selected>two</option>
</select>
<script>
// this function gets the selected item's dataset - note how "this" is used in the HTML: myFunction(this)
function myFunction(selection) {
console.log(selection)
var opt = selection.options[selection.selectedIndex];
console.log(opt)
var price = opt.dataset.price
console.log(price)
}
</script>
<select id="mySelect" onchange="myFunction(this)">
<option data-price="250" value="Audi">Audi</option>
<option data-price="130" value="BMW">BMW</option>
<option data-price="120" value="Mercedes">Mercedes</option>
<option data-price="400" value="Volvo">Volvo</option>
</select>
<style type="text/css">
.greenText {
color: green;
}
</style>
<script type="text/javascript">
// this function adds an event listener to the select below onload - select dosn't support onload
window.addEventListener("load", function () {
console.log(document.getElementById("my_select"))
}, false);
</script>
<select id="my_select">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="grape">Grape</option>
</select>
</body>
<script>
let componentJSON = [
{ "template": "<div class='${layout} ${border}'></div>" },
{
"layout": "grid",
"border": "primary"
}
];
const template = componentJSON[0].template
const classes = componentJSON[1]
let html = template.replace(/\$\{(.*?)\}/g, (match, key) => classes[key]);
console.log(html);
// this function is showing how to build a new object from an old one
var content = {
"items": [{
"id": "02egnc0eo7qk53e9nh7igq6d48",
"summary": "Learn to code",
"start": {
"dateTime": "2017-03-04T19:00:00+05:30"
}
}]
};
var results = content.items.map(function (item) {
return {
id: item.id,
title: item.summary,
start: item.start.dateTime,
description: ""
};
});
console.log(results);
// global "selected Object"
// loop over all inputs and see what their values are
// when creating the inputs, have them all start with the same ID
// Maybe onload have them all emit their values! (check if onload fires before they are generated?)
// will have to work out how to set defaults (probs loop)
// maybe the selectedObject can kind of exist in the component JSON from the start (cheating?)
const selectors = {
content = "Label",
icon = "",
size = "",
type = ""
}
// can I put the selector/value in an array instead of object: [selector, value]
// this function is showing how to replace template strings with regex to put values in them
let componentJSON = [
{ "template": "<div class='${layout} ${border}'></div>" },
{
"layout": "grid",
"border": "primary"
}
];
const template = componentJSON[0].template
const classes = componentJSON[1]
let html = template.replace(/\$\{(.*?)\}/g, (match, key) => classes[key]);
console.log(html);
</script>
</html>