forked from nextapps-de/xone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
709 lines (560 loc) · 21.6 KB
/
index.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
<!DOCTYPE html>
<html lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1, maximum-scale=1.0, user-scalable=no">
<title>Xone - Javascript framework for building modern web applications</title>
<meta name="robots" content="index, follow">
<meta name="format-detection" content="telephone=no">
<link rel="icon" type="image/png" href="page/img/favicon.png">
<link rel="stylesheet" href="page/css/fonts.css">
<link rel="stylesheet" href="page/css/reset.css">
<link rel="stylesheet" href="page/css/animate.css">
<link rel="stylesheet" href="page/css/style.css">
<link rel="stylesheet" href="page/css/effect.css">
<link rel="stylesheet" href="page/css/mobile.css">
<link rel="stylesheet" href="page/css/site.css">
<link rel='stylesheet' href='https://cdn.jsdelivr.net/font-hack/2.020/css/hack.min.css'>
<link rel="stylesheet" href="page/lib/highlight/styles/agate.css">
<meta property="og:url" content="https://nextapps-de.github.io/xone/">
<meta property="og:title" content="Xone - Javascript framework for building modern web applications">
<meta property="og:image" content="https://nextapps-de.github.io/xone/page/img/xone.png?rnd=1">
<meta property="og:description" content="Xone provides you a lightweight full stack environment to develop beautiful web-based applications for every use and enables the optimal integration of an universal codebase into a wide range of systems (e.g. mobile devices, tablets, desktops, browser environments).">
</head>
<body>
<a name="top" id="top" class="anchor"></a>
<table id="intro" cellpadding="0" cellspacing="0">
<tr>
<td class="top_spacer"><div style="min-height: 5vmax"></div></td>
</tr>
<tr>
<td style="height: 1%">
<div id="slogan" class="animated fadeIn" style="animation-delay: 0.2s; background-image: url(page/img/xone.svg); background-position: center center; background-repeat: no-repeat; background-size: contain; height: 12vmin; width: 66%; max-width: 66%;"></div>
<br>
<div id="headline" class="animated fadeIn" style="animation-delay: 0.4s; color:#555; text-shadow: none; font-size: 3vh; padding-top: 1vw">Building a todo app with the Xone Javascript framework</div>
</td>
</tr>
<tr>
<td style="height: 40%"> </td>
</tr>
<tr>
<td style="height: 5%">
<a href="#start" class="autoscroll animated fadeInDown" id="btn_more" style="animation-delay: 0.6s; font-size: 1.5vh;"> Start Tutorial </a>
</td>
</tr>
<tr>
<td style="height: 30%"> </td>
</tr>
<tr>
<td style="height: 5em;">
<div id="arrow_bottom" href="#start" class="autoscroll animated fadeInDown" style="animation-delay: 0.8s;"></div>
</td>
</tr>
<tr>
<td style="height: 3%"> </td>
</tr>
</table>
<main style="text-align: left">
<div class="content_wrapper">
<section class="content_section">
<br><br>
<a name="start" id="start" class="anchor"></a>
<p>
The todo app from this tutorial is based on <a href="http://todomvc.com" target="_blank">http://todomvc.com</a>.
</p>
<br>
Open <a href="page/demo/todo/index.html" target="_blank">Demo</a> in new tab
<br><br>
<!--
<input class="toggle-box" id="toggle-box-0" type="checkbox">
<label class="toggle-box-title" for="toggle-box-0">Demo</label>
<div class="toggle-box-content" style="text-align: center">
<br>
<div id="iframe_wrapper" style="width:61vmin; height: 67vmin; padding:0vmin 7.15vmin 0vmin 7.6vmin; overflow: hidden; margin: 0 auto; position: relative">
<div style="width: 100%; height: 100%; margin: 0; background: url(page/img/iphone.svg); background-position: center center; background-size: contain; background-repeat: no-repeat; position: absolute; top:0; left:0; bottom:0; right:0; z-index: 1; pointer-events:none"></div>
<iframe src="page/demo/todo/index.html" style="width: 100%; height: 120%; margin: 0; background: none; background-color: transparent; border: 0; position: relative; top:-9.7%; left:0; bottom:0; right:0; z-index: 0; transform:scale(0.6)" marginwidth="0" marginheight="0" frameborder="0"></iframe>
</div>
<br><br>
<a href="page/demo/todo/index.html" target="_blank">Open Demo in new tab</a>
<br> <br>
</div>
-->
<h2>Installation</h2>
<input class="toggle-box" id="toggle-box-1" type="checkbox">
<label class="toggle-box-title" for="toggle-box-1">Installation (including CLI support)</label>
<div class="toggle-box-content">
<div class="tagline" style="text-align: left">1.) Install Xone</div>
Install Xone via NPM (Node Package Manager, requires <a href="https://nodejs.org" target="_blank">Node.js</a>):
<br>
<pre>
<code class="bash">> npm install -g xone</code>
</pre>
<br>
<div class="tagline">2.) Create New Xone Project</div>
Create a blank project folder and run from there:
<br>
<pre>
<code class="bash">> xone create</code>
</pre>
<!--
<br>
If you have choosen "Create New Xone Project" then you will see the default Xone placeholder screen of a new created project:<br>
<br>
<img src="page/img/screen-1.png" style="width: 100%; max-width: 400px">
-->
<br><br>
</div>
<h2>Implementation (HTML)</h2>
<input class="toggle-box" id="toggle-box-5" type="checkbox">
<label class="toggle-box-title" for="toggle-box-5">app/index.html</label>
<div class="toggle-box-content">
Provide the main <span class="highlight">index.html</span> (single-page application):
<br>
<pre>
<code class="html"><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Template • TodoMVC</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<script src="js/build.js"></script>
</body>
</html></code>
</pre>
<br>
<br>
</div>
<input class="toggle-box" id="toggle-box-7" type="checkbox">
<label class="toggle-box-title" for="toggle-box-7">app/layout/app.shtml</label>
<div class="toggle-box-content">
Define the main app layout:
<br>
<pre>
<code class="handlebars"><section class="todoapp">
{{ include(layout/app/header) }}
{{ include(layout/app/main) }}
{{ include(layout/app/footer) }}
</section>
<footer class="info">
{{ include(layout/app/info) }}
</footer></code>
</pre>
<br>
<div class="note">
Use includes to split views into logically (reusable) components.
</div>
<div class="note">
The template will be compiled into Javascript by <span class="highlight">xone compile</span>.
</div>
<br>
</div>
<input class="toggle-box" id="toggle-box-8" type="checkbox">
<label class="toggle-box-title" for="toggle-box-8">app/layout/app/*.shtml</label>
<div class="toggle-box-content">
app/layout/app/header.shtml:
<br>
<pre>
<code class="html"><header class="header">
<h1>todos</h1>
<input class="new-todo" placeholder="What needs to be done?" autofocus>
</header></code>
</pre>
<br>
app/layout/app/main.shtml:
<br>
<pre>
<code class="html"><section class="main">
<input class="toggle-all" id="toggle-all" type="checkbox">
<label for="toggle-all">Mark all as complete</label>
<ul class="todo-list"></ul>
</section></code>
</pre>
<br>
app/layout/app/footer.shtml:
<br>
<pre>
<code class="html"><footer class="footer">
<span class="todo-count"><strong>0</strong> item left</span>
<ul class="filters">
<li><a href="#/" class="selected">All</a></li>
<li><a href="#/active">Active</a></li>
<li><a href="#/completed">Completed</a></li>
</ul>
<button class="clear-completed">Clear completed</button>
</footer></code>
</pre>
<br>
app/layout/app/info.shtml:
<br>
<pre>
<code class="html"><p>Double-click to edit a todo</p>
<p>Created by <a href="http://todomvc.com">Xone</a></p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p></code>
</pre>
<br>
<br>
</div>
<input class="toggle-box" id="toggle-box-9" type="checkbox">
<label class="toggle-box-title" for="toggle-box-9">app/view/todo/list.shtml</label>
<div class="toggle-box-content">
Define the todo list view (as a dynamic template):
<br>
<pre>
<code class="handlebars"><li {{ if(completed) }}class="completed"{{ endif }} data-id="{{ id }}">
<div class="view">
<input class="toggle" type="checkbox" {{ if(completed) }}checked{{ endif }}>
<label class="title">{{ title }}</label>
<button class="destroy"></button>
</div>
<input class="edit" value="{{ title }}">
</li></code>
</pre>
<br>
<div class="note">
The template will be compiled into Javascript by <span class="highlight">xone compile</span>.
</div>
<div class="note">
The markups {{ ... }} will be resolved during runtime by <span class="highlight">Controller.render()</span> or <span class="highlight">Controller.build()</span>.
</div>
<div class="note">
The template represents the view for one single item and is automatically multiplied by passing an array of item data.
</div>
<br>
</div>
<h2>Implementation (Javascript)</h2>
<input class="toggle-box" id="toggle-box-11" type="checkbox">
<label class="toggle-box-title" for="toggle-box-11">app/js/model.js</label>
<div class="toggle-box-content">
Define a persistent todo model:
<br>
<pre>
<code class="js">goog.provide('APP.MODEL.Todo');
goog.require('APP.MODEL');
/**
* @type _model_helper
*/
APP.MODEL.Todo = (function(){
var Todo = APP.MODEL.register('Todo', [
'id', 'title', 'completed'
]);
// model events (callbacks):
Todo.onCreate =
Todo.onUpdate =
Todo.onDelete = function(){
APP.CONTROLLER.Main();
};
return Todo;
})();</code>
</pre>
<br>
<br>
</div>
<input class="toggle-box" id="toggle-box-12" type="checkbox">
<label class="toggle-box-title" for="toggle-box-12">app/js/handler.js</label>
<div class="toggle-box-content">
Implement all actions by providing an application interface (e.g. used as event handlers):
<br>
<pre>
<code class="js">goog.provide('APP.HANDLER.Event');
goog.require('APP.MODEL.Todo');
APP.HANDLER = (function(Todo){
return {
createTodo: function(event, target){
var value = CORE.trim(this.value);
if(value) Todo.create({
'id': CORE.randomString(8),
'title': value,
'completed': false
});
},
editTodo: function(event, target){
var value = CORE.trim(this.value);
if(value){
Todo.update(target, 'title', value, /* save? */ true);
}
else{
Todo.delete(target);
}
},
cancelCreate: function(event, target){
this.value = '';
},
cancelEdit: function(event, target){
this.value = CORE.getClosest(target, '>.title').textContent;
CORE.removeClass(target, 'editing');
},
updateState: function(event, target){
Todo.find(target)
.update('completed', this.checked)
.save();
},
toggleAllStates: function(event, target){
Todo.updateAll('completed', this.checked, /* save? */ true);
},
deleteCompleted: function(event, target){
Todo.deleteWhere('completed', true);
},
deleteTodo: function(event, target){
Todo.delete(target);
},
enterEditMode: function(event, target){
CORE.addClass(target, 'editing');
CORE.focusInput(CORE.getClosest(target, '>.edit'));
}
};
})(APP.MODEL.Todo);</code>
</pre>
<br>
<br>
</div>
<input class="toggle-box" id="toggle-box-13" type="checkbox">
<label class="toggle-box-title" for="toggle-box-13">app/js/event.js</label>
<div class="toggle-box-content">
Define event delegation and route to handler:
<br>
<pre>
<code class="js">goog.provide('APP.EVENT.App');
goog.require('APP.EVENT');
goog.require('APP.HANDLER.Event');
(function(HANDLER){
APP.EVENT['document'] = [{
on: 'keyup:enter',
if: 'input.new-todo',
do: [HANDLER.createTodo, HANDLER.cancelCreate]
}, {
on: 'keyup:esc',
if: 'input.new-todo',
do: HANDLER.cancelCreate
}, {
on: ['keyup:enter', 'focusout'],
if: 'input.edit',
at: '< li',
do: [HANDLER.editTodo, HANDLER.cancelEdit]
}, {
on: 'keyup:esc',
if: 'input.edit',
at: '< li',
do: HANDLER.cancelEdit
}, {
on: 'change',
if: 'input.toggle',
at: '< li',
do: HANDLER.updateState
}, {
on: 'clickmove',
if: 'button.destroy',
at: '< li',
do: HANDLER.deleteTodo
}, {
on: 'dblclick',
if: 'label.title',
at: '< li',
do: HANDLER.enterEditMode
}, {
on: 'clickmove',
if: 'button.clear-completed',
do: HANDLER.deleteCompleted
}, {
on: 'change',
if: 'input.toggle-all',
do: HANDLER.toggleAllStates
}];
})(APP.HANDLER);</code>
</pre>
<br>
<br>
</div>
<input class="toggle-box" id="toggle-box-14" type="checkbox">
<label class="toggle-box-title" for="toggle-box-14">app/js/controller.js</label>
<div class="toggle-box-content">
Provide a main controller (e.g. a view controller):
<br>
<pre>
<code class="js">goog.provide('APP.CONTROLLER.Main');
goog.require('APP.CONTROLLER');
goog.require('APP.MODEL.Todo');
APP.CONTROLLER.Main = (function(Todo){
var current_filter;
return function MainController(params, target){
// update select state:
if(target){
current_filter = params;
CORE.toggleClass(['a.selected', target], 'selected');
}
// render view:
APP.CONTROLLER.render({
// uses view "app/view/todo/list.shtml"
view: 'view/todo/list',
// models to render
data: filterTodosBy(current_filter),
// destination dom element
target: 'ul.todo-list',
// callback
callback: updateView
});
};
// private helpers:
function filterTodosBy(filter){
return filter ?
Todo.where('completed', filter === 'completed')
:
Todo.all();
}
function updateView(){
var count_all = Todo.count();
var count_active = Todo.count('completed', false);
var count_completed = count_all - count_active;
// update container visibility
CORE.setStyle(['.main', '.footer'], 'display',
count_all ? 'block' : 'none'
);
// update button visibility
CORE.setStyle('.clear-completed', 'display',
count_completed ? 'block' : 'none'
);
// update counter
CORE.setHTML('.todo-count',
'<strong>' + count_active + '</strong> item' + (count_active === 1 ? '' : 's') + ' left'
);
// update checkbox
CORE.getById('toggle-all').checked = !count_active;
}
})(APP.MODEL.Todo);</code>
</pre>
<br>
<div class="note">
The controller is connected/mapped by route and event definitions. When using the controller as a view controller it typically also renders views by data.
</div>
<br>
</div>
<input class="toggle-box" id="toggle-box-15" type="checkbox">
<label class="toggle-box-title" for="toggle-box-15">app/js/route.js</label>
<div class="toggle-box-content">
Define routing:
<br>
<pre>
<code class="js">goog.provide('APP.ROUTE.App');
goog.require('APP.CONTROLLER.Main');
APP.ROUTE = {
'#/': APP.CONTROLLER.Main,
'#/active': {
to: APP.CONTROLLER.Main,
params: 'active'
},
'#/completed': {
to: APP.CONTROLLER.Main,
params: 'completed'
}
};</code>
</pre>
<br>
<br>
</div>
<input class="toggle-box" id="toggle-box-16" type="checkbox">
<label class="toggle-box-title" for="toggle-box-16">app/js/main.js</label>
<div class="toggle-box-content">
Provide a main class (entry point):
<br>
<pre>
<code class="js">goog.provide('APP.MAIN');
goog.require('APP.EVENT.App');
goog.require('APP.ROUTE.App');
// define app layout:
APP.CONFIG.LAYOUT = [
'layout/app' // points to "app/layout/app.shtml"
];
// provide entry point:
APP.MAIN = function(){
APP.CONTROLLER.request(window.location.hash);
};</code>
</pre>
<br>
<br>
</div>
<input class="toggle-box" id="toggle-box-6" type="checkbox">
<label class="toggle-box-title" for="toggle-box-6">app/manifest.js</label>
<div class="toggle-box-content">
Define all app dependencies in <span class="highlight">app/manifest.js</span>:
<br>
<pre>
<code class="json">var MANIFEST = {
"dependencies": {
"calculate": true,
"xone": "lib/xone/",
"copy": [
"index.html"
],
"css": [
"node_modules/todomvc-common/base.css",
"node_modules/todomvc-app-css/index.css"
],
"js_extern": [
"node_modules/todomvc-common/base.js"
],
"js": []
}
};</code>
</pre>
<br>
<br>
</div>
<h2>Build & Run</h2>
<input class="toggle-box" id="toggle-box-17" type="checkbox">
<label class="toggle-box-title" for="toggle-box-17">Installation (Global with CLI support)</label>
<div class="toggle-box-content">
<div class="tagline">1.) Build Xone Project</div>
Compile the project:
<br>
<pre>
<code class="bash">> xone compile</code>
</pre>
<br>
Build the project (also compiles):
<br>
<pre>
<code class="bash">> xone build</code>
</pre>
<br>
<div class="tagline">2.) Run Xone Project</div>
Run <span class="highlight">app/index.html</span> or <span class="highlight">public/www/index.html</span> from your local filesystem in your preferred browser.
<br> <br>
Start local webserver:
<br>
<pre>
<code class="bash">> xone server</code>
</pre>
<br>
Open your browser and goto:<br>
<ul>
<li><a href="http://localhost/app">http://localhost/app/</a> to run development environment</li>
<li><a href="http://localhost/public/www">http://localhost/public/www/</a> to run production build (<span class="highlight">www</span> is the default platform)</li>
</ul>
<!--
<br>
If you have choosen "Create New Xone Project" then you will see the default Xone placeholder screen of a new created project:<br>
<br>
<img src="page/img/screen-1.png" style="width: 100%; max-width: 400px">
-->
<br><br>
</div>
<br><br>
</section>
</div>
</main>
<footer class="content_wrapper invert" style="background-color: #333;">
<section class="content_section">
<div class="clear"></div>
<br>
<br>
</section>
</footer>
<script src="page/lib/highlight/highlight.pack.js"></script>
<script>
hljs.configure({tabReplace: ' '});
hljs.initHighlightingOnLoad();
</script>
</body>
</html>