-
Notifications
You must be signed in to change notification settings - Fork 1
/
cito.html
256 lines (233 loc) · 6.41 KB
/
cito.html
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='cito.js'></script>
<style type='text/css'>
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
font-family: 'Gotham Book', sans-serif;
background-color: rgb(250,250,250);
padding: 0;
margin: 8em 2em 2em 1em;
line-height: 1.5em;
}
img {
padding-right: 4px;
vertical-align: middle;
}
.canvas {
border: 1px solid rgb(229,229,229);
background: rgb(239,239,239);
margin-bottom: 3px;
color: rgb(131,131,131);
font-size: .75em;
}
.canvas.body {
max-height: 30em; overflow-y: auto;
}
.row {width:100%;display:table;table-layout:fixed; border-spacing: 1px;}
.col {display: table-cell; padding: 0.5em 1em 0.5em 1em; background: #fff; text-align: right; }
.col.nospace {
padding: 0;
}
.col.arrow {
width: 1.2em;text-align: center; padding: 0;
}
.row.header .col {
background: rgb(245,245,245);
}
.row.header .col.arrow {
color: #c0c0c0;
}
.row.header .col.arrow[data-scrollable=true] {
background: #000; color: #fff; cursor: pointer;
}
.row.body .col.name {
color: rgb(35,147,224);
}
*[hidden] {
display: none;
}
input, select, textarea, button{font-family:inherit; font-size: inherit;}
input {
width: 100%; outline: none; text-align: right; border: none; border-bottom: 1px solid #fff; color: rgb(66,66,66);
line-height: 1.5em; padding-bottom: 4px;
}
input.adj {
width: calc(100% - 24px);
}
input[readonly] {
color: inherit;
}
input:not([data-index='0']) {
//font-size: .8em;
}
input:hover:not([readonly]), input:focus:not([readonly]) {
border-bottom: 1px dashed rgb(125,190,238);
cursor: url(pencil.png?1), auto;
}
input:not(:focus) {
}
input[data-state=saved] {
color: #31a354;
}
input[data-state=saved]:after {
content="\2713";
color: #31a354;
}
span.sorter {
padding-left: 2px;
color: rgb(35,147,224);
}
.hand {
cursor: pointer;
}
.north {
cursor: n-resize;
}
.south {
cursor: s-resize;
}
.flexy-row {
display: flexbox;
flex-direction: row;
}
.flexy-col {
display: flexbox;
flex-direction: column;
}
.pop {
position: absolute;
background-color: rgba(254,254,254,.9);
border:1px solid rgb(215,215,215);
-moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.2);
-webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.2);
box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
pointer-events:all;
max-height: 200px;
overflow: auto;
font-size: .75em;
}
.pop .hdr {
background-color: rgb(245,245,245);
padding: 4px 0 4px 10px;
}
</style>
</head>
<body>
<div id='grid'>
<div class='canvas header'>
</div>
<div class='canvas body'>
</div>
</div>
<script type='text/javascript'>
(function() {
'use strict';
function FMGrid(config) {
this.config = config || {};
this.gridHeader = null;
this.gridBody = null;
this.model = null;
}
FMGrid.prototype.init = function() {
this.prepare();
this.renderHeader();
this.renderBody();
}
FMGrid.prototype.prepare = function() {
var items = [], data=[];
for (var i = 0; i < 8; i++) {
items.push({tag: 'div', attrs: {'class': 'col', 'data-col': i}, events: {click: this.sort.bind(this)}, children: 'Header-'+i})
}
for (var r = 0; r < 100; r++) {
var row=[];
for (var i = 0; i < 8; i++) {
row.push({tag: 'div', attrs: {'class': 'col'}, children: ''+Math.random()*1000000})
}
data.push({tag: 'div', attrs: {'class': 'row'}, children: row});
}
this.model = {schema: items, data: data}
}
FMGrid.prototype.renderHeader = function() {
var self = this, _render = function() {
return {tag: 'div', attrs: {'class': 'row header'}, children: self.model.schema }
}
this.gridHeader = cito.vdom.append(document.querySelector(this.config.headerDom), _render);
}
FMGrid.prototype.renderBody = function() {
var self = this, _render = function() {
return {tag: 'div', children: self.model.data }
}
this.gridBody = cito.vdom.append(document.querySelector(this.config.bodyDom), _render);
}
FMGrid.prototype.sort = function(e) {
var col = parseInt(e.target.getAttribute('data-col')||0),
order = parseInt(e.target.getAttribute('data-order')||1);
this.model.data.sort(function(a,b) {
return order*(parseFloat(a.children[col].children) - parseFloat(b.children[col].children));
})
e.target.setAttribute('data-order', order*-1);
cito.vdom.remove(this.gridBody);
this.renderBody();
}
var g = new FMGrid({headerDom: '.canvas.header', bodyDom: '.canvas.body'});
g.init();
})();
/*var items = [], data=[];
for (var i = 0; i < 8; i++) {
items.push({tag: 'div', attrs: {'class': 'col', 'data-col': i}, events: {click: sort}, children: 'Header-'+i})
}
for (var r = 0; r < 1000; r++) {
var row=[];
for (var i = 0; i < 8; i++) {
row.push({tag: 'div', attrs: {'class': 'col'}, children: ''+Math.random()*1000000})
}
data.push({tag: 'div', attrs: {'class': 'row'}, children: row});
}
function doubleList() {
data = data.concat(data);
cito.vdom.update(rootNode, root);
}
function sort(e) {
var col = parseInt(e.target.getAttribute('data-col')||0),
order = parseInt(e.target.getAttribute('data-order')||1);
data.sort(function(a,b) {
return parseFloat(a.children[col].children) - parseFloat(b.children[col].children);
})
cito.vdom.remove(rootNode);
rootNode = cito.vdom.append(document.getElementById('parent'), root);
}
function button() {
return {
tag: 'button',
attrs: {title: 'double the list'},
events: {click: doubleList},
children: 'double'
}
}
function root() {
return {
tag: 'div', children: [
button,
{tag: 'div', attrs: {'class': 'canvas'},
children: [
{tag: 'div', attrs: {'class': 'row header'}, children: items },
{tag: 'div', attrs: {'class': 'canvas'}, children: data }
]
}
]
};
}
var rootNode = cito.vdom.append(document.getElementById('parent'), root);*/
</script>
</body>
</html>