forked from jdubray/sam-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.html
187 lines (142 loc) · 6.46 KB
/
blog.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
<html>
<head>
<title>SAM Sample | Blog Posts</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>Blog Template for Bootstrap Using the SAM Pattern</title>
<!-- Bootstrap core CSS -->
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="http://getbootstrap.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="http://getbootstrap.com/examples/blog/blog.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="http://getbootstrap.com/assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="blog-masthead">
<div class="container">
<nav class="blog-nav">
<a class="blog-nav-item active" href="#">Home</a>
<a class="blog-nav-item" href="http://sam.js.org">About</a>
</nav>
</div>
</div>
<div class="container">
<div class="blog-header">
<h1 class="blog-title">The SAM Pattern Blog</h1>
<p class="lead blog-description">The official blog sample impleting the SAM Pattern</p>
</div>
<div class="row">
<div class="col-sm-8 blog-main">
<div id="representation">
<blockquote>Problem is (follow me closely here, the science is pretty complicated), if I cut a hole in the Hab, the air won't stay inside anymore.</blockquote><br>
- Andy Weir, The Martian
</div>
</div>
</div>
</div>
<footer class="blog-footer">
<p>Blog template built for <a href="http://getbootstrap.com">Bootstrap</a> by <a href="https://twitter.com/mdo">@mdo</a>.</p>
<p>
<a href="#">Back to top</a>
</p>
</footer>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="http://getbootstrap.com/assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="http://getbootstrap.com/assets/js/ie10-viewport-bug-workaround.js"></script>
<!-- The file blog.js is the isomorphic part of the application -->
<script type="text/javascript" src="blog.js"></script>
<script type="text/javascript">
// This sample was inspired from @rajaraodv
// https://medium.com/@rajaraodv/a-guide-for-building-a-react-redux-crud-app-7fe0b8943d0f#.e7501tdde
function travel(data) {
// client side
//model.present(data) ;
// server side
$.get( "http://localhost:5425/dev/v1/timetravel/snapshots/"+data.snapshot)
.done(function( snapshot ) {
$.post( "http://localhost:5425/dev/v1/timetravel/snapshots/"+data.snapshot, snapshot)
.done( function (representation) {
console.log(representation) ;
let m = JSON.parse(representation) ;
let modelProperties = Object.getOwnPropertyNames(model).filter(function (p) {
return typeof model[p] !== 'function';
}) ;
let snapShotProperties = Object.getOwnPropertyNames(m) ;
modelProperties.forEach(function(p) {
delete model[p] ;
});
snapShotProperties.forEach(function(p) {
model[p] = m[p] ;
});
console.log(model) ;
state.render(model,null,false) ;
})
}
);
}
function displayTimeTravelControls(representation) {
return (representation +
' <br>\n<br>\n<hr>\n<div class="mdl-cell mdl-cell--6-col">\n'+
' <input id="__snapshot" type="text" class="form-control"><br>\n'+
' <button id="__travel" onclick="JavaScript:return travel({\'snapshot\':document.getElementById(\'__snapshot\').value});"> TimeTravel </button>\n'+
' </div><br><br>\n') ;
}
function saveSnapshot(model) {
var snapshot = JSON.parse(JSON.stringify(model));
snapshot.__action = "__present" ;
$.post( "http://localhost:5425/app/v1/dispatch/", snapshot) ;
}
function dispatch(data) {
// client side
model.present(data) ;
// server side
// $.post( "http://localhost:5425/app/v1/dispatch", data)
// .done(function( representation ) {
// $( "#representation" ).html( representation );
// }
// );
}
function present(data) {
// client side
model.present(data) ;
// server side
// $.post( "http://localhost:5425/app/v1/present", data)
// .done(function( representation ) {
// $( "#representation" ).html( representation );
//}
//);
}
function init() {
// client side
view.display(view.init(model)) ;
actions.do = dispatch
state.saveSnapshot = saveSnapshot ;
state.displayTimeTravelControls = displayTimeTravelControls ;
// server side
// $.get( "http://localhost:5425/app/v1/init", function( data ) {
// $( "#representation" ).html( data );
//}
//);
}
// Display initial state
init() ;
</script>
</body>
</html>