-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
421 lines (406 loc) · 18.2 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=1024">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>Responsive Views with Knockout | DotNetNuke World, 2012 | by Brian Dukes @BrianDukes</title>
<meta name="description" content="Knockout is a JavaScript library for creating incredibly responsive and interactive HTML. It uses a "data-binding" technique to declaratively associate HTML elements with a JavaScript object, so that changes made in one place are automatically made in the other. Change your name on the form, the name is changed in JavaScript. Perform a calculation in JavaScript, its results are automatically displayed on the page. This presentation will show some realistic examples of how to use Knockout in your everyday module development, and go over the pitfalls and gotchas that you may encounter, as well as show off some tips and tricks to use the library to its fullest.">
<meta name="author" content="Brian Dukes">
<link href="http://fonts.googleapis.com/css?family=Open+Sans:regular,semibold,italic,italicsemibold" rel="stylesheet">
<link href="css/combined-styles.css" rel="stylesheet">
</head>
<body class="impress-not-supported">
<div class="fallback-message">
<p>Your browser <strong>doesn't support the features required</strong> by impress.js, so you are presented with a simplified version of this presentation.</p>
<p>For the best experience please use the latest version of one of the following browsers:</p>
<div id="fallback-browsers">
<ul>
<li><a href="http://www.google.com/chrome/">Chrome</a></li>
<li><a href="http://www.apple.com/safari/">Safari</a></li>
<li><a href="http://www.firefox.com/">Firefox</a></li>
</ul>
</div>
</div>
<div id="impress">
<div id="title" class="step slide" data-x="0">
<hgroup>
<h1>Responsive Views with <img src="img/ko-logo.png" alt="Knockout"/></h1>
<h2>Brian Dukes, Engage Software</h2>
</hgroup>
</div>
<div id="agenda" class="step" data-x="1000">
<h3>Agenda</h3>
<ol>
<li><abbr title="Model-View-ViewModel">MVVM</abbr> Pattern</li>
<li>Declarative Bindings</li>
<li>Automatic <abbr title="User Interface">UI</abbr> Refresh</li>
<li>Templating</li>
<li>Dependency Tracking</li>
</ol>
</div>
<div id="mvvm" class="step" data-x="2000">
<h3>Model-View-???</h3>
<dl>
<dt>Model</dt>
<dd>Contains your core data and business logic</dd>
<dd>"Business classes," C#</dd>
<dt>View</dt>
<dd>Displays the model and communicates changes from the user</dd>
<dd>"Front-end," <abbr title="HyperText Markup Language">HTML</abbr></dd>
<dt>View-Model</dt>
<dd>Specific parts of the model needed by the view</dd>
<dd>"Glue," C# and/or JavaScript</dd>
</dl>
</div>
<div id="bindings" class="step code-step first-step" data-x="3100">
<h3>Declarative Bindings</h3>
<dl>
<dt>Declarative</dt>
<dd>What to do, not how to do it</dd>
</dl>
<pre class="brush: html">
<div class="account-wrap">
<p data-bind="text: displayName"></p>
<p class="address">
<span data-bind="text: streetAddress"></span><br />
<span data-bind="text: city"></span>,
<span data-bind="text: region"></span>
<span data-bind="text: postalCode"></span>
</p>
<p class="bio" data-bind="html: bioHtml"></p>
<button data-bind="click: doSomething">Take Action!</button>
</div>
</pre>
</div>
<div id="bindings-js" class="step code-step second-step" data-x="3100" data-rotate-y="180">
<h3>Declarative Bindings</h3>
<h6>View Model:</h6>
<pre class="brush: js">
ko.applyBindings({
displayName: 'Kristine Overland',
streetAddress: '12345 Database Ln',
city: 'Java',
region: 'CS',
postalCode: 'ABC 123',
bioHtml: 'I like <HTML> & JavaScript!',
doSomething: function () { /* ... */ }
});
</pre>
</div>
<div id="bindings-example" class="step" data-x="4200">
<h3>Declarative Bindings</h3>
<h6>Example:</h6>
<div class="account-wrap">
<p data-bind="text: displayName"></p>
<p class="address">
<span data-bind="text: streetAddress"></span><br />
<span data-bind="text: city"></span>,
<span data-bind="text: region"></span>
<span data-bind="text: postalCode"></span>
</p>
<p class="bio" data-bind="html: bioHtml"></p>
<button data-bind="click: doSomething">Take Action!</button>
</div>
</div>
<div id="automatic-ui-refresh-example" class="step" data-x="5200">
<h3>Automatic <abbr title="User Interface">UI</abbr> Refresh</h3>
<h6>Example:</h6>
<div class="preorder-wrap">
Quantity requested:
<em data-bind="text: quantity"></em>
<button data-bind="click: increase">More!</button>
</div>
</div>
<div id="automatic-ui-refresh" class="step code-step" data-x="6300">
<h3>Automatic <abbr title="User Interface">UI</abbr> Refresh</h3>
<pre class="brush: js, html-script: true, highlight: [8,10]">
<div class="preorder-wrap">
Quantity requested:
<em data-bind="text: quantity"></em>
<button data-bind="click: increase">More!</button>
</div>
<script>
ko.applyBindings({
quantity: ko.observable(0),
increase: function () {
this.quantity(this.quantity() + 1);
}
});
</script>
</pre>
</div>
<div id="templating" class="step code-step first-step" data-x="7500">
<h3>Templating</h3>
<pre class="brush: html, highlight: [1,8,12]">
<ul class="products" data-bind="foreach: products">
<li>
<h3 data-bind="text: productName"></h3>
<div data-bind="html: productDescription"></div>
<ul data-bind="foreach: images">
<li>
<img data-bind="attr: {
alt: $parent.productName,
src: src }" />
</li>
</ul>
<!-- ko ifnot: soldOut -->
<button>Order Now!</button>
<!-- /ko -->
</li>
</ul>
</pre>
</div>
<div id="templating-js" class="step code-step second-step" data-x="7500" data-rotate-y="180">
<h3>Templating</h3>
<h6>View Model:</h6>
<pre class="brush: js, highlight: [2]">
ko.applyBindings({
products: ko.observableArray([{
productName: ko.observable('Widget'),
productDescription: ko.observable('<p>High performance widgets</p><p>See <a href="#">specs</a>.</p>'),
soldOut: ko.observable(false),
images: ko.observableArray([ { src: ko.observable('img/widget.png') }, { src: ko.observable('img/widget2.png') } ])
}, {
productName: ko.observable('Sprocket'),
productDescription: ko.observable('<p>Low performance sprockets are our best selling item.</p><p>See <a href="#">specs</a>.</p>'),
soldOut: ko.observable(true),
images: ko.observableArray([ { src: ko.observable('img/sprocket.png') } ])
}])
})
</pre>
</div>
<div id="templating-example" class="step" data-x="8600">
<h3>Templating</h3>
<h6>Example:</h6>
<ul class="products" data-bind="foreach: products">
<li>
<h3 data-bind="text: productName"></h3>
<div data-bind="html: productDescription"></div>
<ul data-bind="foreach: images">
<li>
<img data-bind="attr: {
alt: $parent.productName,
src: src }" />
</li>
</ul>
<!-- ko ifnot: soldOut -->
<button>Order Now!</button>
<!-- /ko -->
<!-- ko if: soldOut -->
<p>Sorry, Sold Out!</p>
<!-- /ko -->
</li>
</ul>
</div>
<div id="templating-2" class="step code-step first-step" data-x="9700">
<h3>Templating - Another Example</h3>
<pre class="brush: html">
<ul data-bind="foreach: products">
<li>
<strong data-bind="text: productName"></strong>
<button data-bind="click: $root.addToCart">Add To Your Cart</button>
</li>
</ul>
<dl>
<!-- ko foreach: cartProducts -->
<dt data-bind="text: productName"></dt>
<dd data-bind="text: quantity"></dd>
<!-- /ko -->
</dl>
</pre>
</div>
<div id="templating-2-js" class="step code-step second-step" data-x="9700" data-rotate-y="180">
<h3>Templating - Another Example</h3>
<h6>View Model:</h6>
<pre class="brush: js">
var ProductsListViewModel = function (products) {
var self = this;
self.products = products;
self.cartProducts = ko.observableArray([]);
self.addToCart = function (product) {
var i, len, cartProduct,
cartProducts = self.cartProducts();
for (i = 0, len = cartProducts.length; i < len; i += 1) {
cartProduct = cartProducts[i];
if (cartProduct.productName === product.productName) {
cartProduct.quantity(cartProduct.quantity() + 1);
return;
}
}
self.cartProducts.push({ productName: product.productName, quantity: ko.observable(1) });
};
};
ko.applyBindings(new ProductsListViewModel([{ productName: 'Widget' }, { productName: 'Sprocket' }, { productName: 'Cog' }, { productName: 'Pinion' }, { productName: 'Spurwheel' }]));
</pre>
</div>
<div id="templating-2-example" class="step" data-x="10800">
<h3>Templating</h3>
<h6>Another Example:</h6>
<ul data-bind="foreach: products">
<li>
<strong data-bind="text: productName"></strong>
<button data-bind="click: $root.addToCart">Add To Your Cart</button>
</li>
</ul>
<dl>
<!-- ko foreach: cartProducts -->
<dt data-bind="text: productName"></dt>
<dd data-bind="text: quantity"></dd>
<!-- /ko -->
</dl>
</div>
<div id="dependency-tracking" class="step" data-x="11800">
<h3>Dependency Tracking</h3>
<ul data-bind="foreach: products">
<li>
<strong data-bind="text: productName"></strong>
$<em data-bind="text:price"></em>
<button data-bind="click: $root.addToCart">Add To Your Cart</button>
</li>
</ul>
<dl>
<!-- ko foreach: cartProducts -->
<dt data-bind="text: productName"></dt>
<dd data-bind="text: quantity"></dd>
<!-- /ko -->
<dt>Totals</dt>
<dd data-bind="text: totalQuantity"></dd>
<dd>$<em data-bind="text:totalPrice"></em></dd>
</dl>
</div>
<div id="dependency-tracking-js" class="step code-step" data-x="12900">
<h3>Dependency Tracking</h3>
<h6>View Model:</h6>
<pre class="brush:js">
self.totalQuantity = ko.computed(function () {
var q = 0;
self.cartProducts().forEach(function (cartItem) {
q += cartItem.quantity();
});
return q;
});
self.totalPrice = ko.computed(function () {
var p = 0;
self.cartProducts().forEach(function (cartItem) {
p += cartItem.price * cartItem.quantity();
});
return p;
});
</pre>
</div>
<div id="review" class="step" data-x="14000">
<h3>Review</h3>
<ol>
<li><abbr title="Model-View-ViewModel">MVVM</abbr> Pattern</li>
<li>Declarative Bindings</li>
<li>Automatic <abbr title="User Interface">UI</abbr> Refresh</li>
<li>Templating</li>
<li>Dependency Tracking</li>
</ol>
<h3>Resources</h3>
<ul>
<li><a href="http://learn.knockoutjs.com/">http://learn.knockoutjs.com/</a></li>
<li><a href="http://knockoutjs.com/examples/">http://knockoutjs.com/examples/</a></li>
<li><a href="http://knockoutjs.com/documentation/introduction.html">http://knockoutjs.com/ - Documentation</a></li>
</ul>
</div>
</div>
<div class="hint">
<p>Use a spacebar or arrow keys to navigate</p>
</div>
<script src="js/LAB.min.js"></script>
<script>
$LAB
.script("js/impress.js")
.script("js/shCore.js").wait()
.script("js/shBrushXml.js")
.script("js/shBrushJScript.js")
.wait(function () {
SyntaxHighlighter.highlight();
}).script("js/knockout.js")
.script("js/Array.forEach.js")
.wait(function () {
ko.applyBindings({
displayName: 'Kristine Overland',
streetAddress: '12345 Database Ln',
city: 'Java',
region: 'CS',
postalCode: 'ABC 123',
bioHtml: 'I like <HTML> & JavaScript!',
doSomething: function () { /* ... */ }
}, document.getElementById('bindings-example'));
ko.applyBindings({
quantity: ko.observable(0),
increase: function () {
this.quantity(this.quantity() + 1);
}
}, document.getElementById('automatic-ui-refresh-example'));
ko.applyBindings({
products: ko.observableArray([{
productName: ko.observable('Widget'),
productDescription: ko.observable('<p>High performance widgets</p><p>See <a href="#">specs</a>.</p>'),
soldOut: ko.observable(false),
images: ko.observableArray([ { src: ko.observable('img/widget.png') }, { src: ko.observable('img/widget2.png') } ])
}, {
productName: ko.observable('Sprocket'),
productDescription: ko.observable('<p>Low performance sprockets are our best selling item.</p><p>See <a href="#">specs</a>.</p>'),
soldOut: ko.observable(true),
images: ko.observableArray([ { src: ko.observable('img/sprocket.png') } ])
}])
}, document.getElementById('templating-example'));
var TemplatingExample2ViewModel = function (products) {
var self = this;
self.products = products;
self.cartProducts = ko.observableArray([]);
self.addToCart = function (product) {
var i, len, cartProduct,
cartProducts = self.cartProducts();
for (i = 0, len = cartProducts.length; i < len; i += 1) {
cartProduct = cartProducts[i];
if (cartProduct.productName === product.productName) {
cartProduct.quantity(cartProduct.quantity() + 1);
return;
}
}
self.cartProducts.push({ productName: product.productName, quantity: ko.observable(1) });
};
};
ko.applyBindings(new TemplatingExample2ViewModel([{ productName: 'Widget' }, { productName: 'Sprocket' }, { productName: 'Cog' }, { productName: 'Pinion' }, { productName: 'Spurwheel' }]), document.getElementById('templating-2-example'));
var DependencyTrackingViewModel = function (products) {
var self = this;
self.products = products;
self.cartProducts = ko.observableArray([]);
self.totalQuantity = ko.computed(function () {
var q = 0;
self.cartProducts().forEach(function (cartItem) {
q += cartItem.quantity();
});
return q;
});
self.totalPrice = ko.computed(function () {
var p = 0;
self.cartProducts().forEach(function (cartItem) {
p += cartItem.price * cartItem.quantity();
});
return p;
});
self.addToCart = function (product) {
var i, len, cartProduct,
cartProducts = self.cartProducts();
for (i = 0, len = cartProducts.length; i < len; i += 1) {
cartProduct = cartProducts[i];
if (cartProduct.productName === product.productName) {
cartProduct.quantity(cartProduct.quantity() + 1);
return;
}
}
self.cartProducts.push({ productName: product.productName, price: product.price, quantity: ko.observable(1) });
};
};
ko.applyBindings(new DependencyTrackingViewModel([{ productName: 'Widget', price: 10.05 }, { productName: 'Sprocket', price: 135.09 }, { productName: 'Cog', price: 19.99 }, { productName: 'Pinion', price: 20.00 }, { productName: 'Spurwheel', price: 75.15 }]), document.getElementById('dependency-tracking'));
window.h5pCaniuse = function(a) { document.getElementById("fallback-browsers").innerHTML=a.html; };
}).script("http://api.html5please.com/csstransforms3d+classlist+dataset.json?callback=h5pCaniuse&texticon&nocss&html");
</script>
</body>
</html>